contract_name
stringlengths
1
238
file_path
stringlengths
4
23.2k
contract_address
stringlengths
42
42
language
stringclasses
2 values
source_code
stringlengths
1
896k
abi
stringlengths
2
46.2k
compiler_version
stringclasses
297 values
optimization_used
bool
2 classes
runs
float64
1
1,000M
constructor_arguments
stringlengths
0
214k
evm_version
stringclasses
11 values
library
stringclasses
376 values
license_type
stringclasses
16 values
proxy
bool
2 classes
implementation
stringlengths
0
42
swarm_source
stringlengths
0
71
UserWallet
UserWallet.sol
0x84dabbb8999f508ce1cbb7057d260c74c6c9815c
Solidity
pragma solidity ^0.4.10; // Copyright 2017 Bittrex contract AbstractSweeper { function sweep(address token, uint amount) returns (bool); function () { throw; } Controller controller; function AbstractSweeper(address _controller) { controller = Controller(_controller); } modifier canSweep() { if (msg.sender != controller.authorizedCaller() && msg.sender != controller.owner()) throw; if (controller.halted()) throw; _; } } contract Token { function balanceOf(address a) returns (uint) { (a); return 0; } function transfer(address a, uint val) returns (bool) { (a); (val); return false; } } contract DefaultSweeper is AbstractSweeper { function DefaultSweeper(address controller) AbstractSweeper(controller) {} function sweep(address _token, uint _amount) canSweep returns (bool) { bool success = false; address destination = controller.destination(); if (_token != address(0)) { Token token = Token(_token); uint amount = _amount; if (amount > token.balanceOf(this)) { return false; } success = token.transfer(destination, amount); } else { uint amountInWei = _amount; if (amountInWei > this.balance) { return false; } success = destination.send(amountInWei); } if (success) { controller.logSweep(this, destination, _token, _amount); } return success; } } contract UserWallet { AbstractSweeperList sweeperList; function UserWallet(address _sweeperlist) { sweeperList = AbstractSweeperList(_sweeperlist); } function () public payable { } function tokenFallback(address _from, uint _value, bytes _data) { (_from); (_value); (_data); } function sweep(address _token, uint _amount) returns (bool) { (_amount); return sweeperList.sweeperOf(_token).delegatecall(msg.data); } } contract AbstractSweeperList { function sweeperOf(address _token) returns (address); } contract Controller is AbstractSweeperList { address public owner; address public authorizedCaller; address public destination; bool public halted; event LogNewWallet(address receiver); event LogSweep(address indexed from, address indexed to, address indexed token, uint amount); modifier onlyOwner() { if (msg.sender != owner) throw; _; } modifier onlyAuthorizedCaller() { if (msg.sender != authorizedCaller) throw; _; } modifier onlyAdmins() { if (msg.sender != authorizedCaller && msg.sender != owner) throw; _; } function Controller() { owner = msg.sender; destination = msg.sender; authorizedCaller = msg.sender; } function changeAuthorizedCaller(address _newCaller) onlyOwner { authorizedCaller = _newCaller; } function changeDestination(address _dest) onlyOwner { destination = _dest; } function changeOwner(address _owner) onlyOwner { owner = _owner; } function makeWallet() onlyAdmins returns (address wallet) { wallet = address(new UserWallet(this)); LogNewWallet(wallet); } function halt() onlyAdmins { halted = true; } function start() onlyOwner { halted = false; } address public defaultSweeper = address(new DefaultSweeper(this)); mapping (address => address) sweepers; function addSweeper(address _token, address _sweeper) onlyOwner { sweepers[_token] = _sweeper; } function sweeperOf(address _token) returns (address) { address sweeper = sweepers[_token]; if (sweeper == 0) sweeper = defaultSweeper; return sweeper; } function logSweep(address from, address to, address token, uint amount) { LogSweep(from, to, token, amount); } }
[{"constant":false,"inputs":[{"name":"_token","type":"address"},{"name":"_amount","type":"uint256"}],"name":"sweep","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_value","type":"uint256"},{"name":"_data","type":"bytes"}],"name":"tokenFallback","outputs":[],"payable":false,"type":"function"},{"inputs":[{"name":"_sweeperlist","type":"address"}],"payable":false,"type":"constructor"},{"payable":true,"type":"fallback"}]
v0.4.11+commit.68ef5810
true
200
000000000000000000000000a3C1E324CA1ce40db73eD6026c4A177F099B5770
Default
false
bzzr://4cdd69fdcf3cf6cbee9677fe380fa5f044048aa9e060ec5619a21ca5a5bd4cd1
Forwarder
Forwarder.sol
0x17be21ab0d0a5255d5cd4ce387f42d95b81f88ea
Solidity
pragma solidity ^0.4.14; /** * Contract that exposes the needed erc20 token functions */ contract ERC20Interface { // Send _value amount of tokens to address _to function transfer(address _to, uint256 _value) returns (bool success); // Get the account balance of another account with address _owner function balanceOf(address _owner) constant returns (uint256 balance); } /** * Contract that will forward any incoming Ether to its creator */ contract Forwarder { // Address to which any funds sent to this contract will be forwarded address public parentAddress; event ForwarderDeposited(address from, uint value, bytes data); event TokensFlushed( address tokenContractAddress, // The contract address of the token uint value // Amount of token sent ); /** * Create the contract, and set the destination address to that of the creator */ function Forwarder() { parentAddress = msg.sender; } /** * Modifier that will execute internal code block only if the sender is a parent of the forwarder contract */ modifier onlyParent { if (msg.sender != parentAddress) { throw; } _; } /** * Default function; Gets called when Ether is deposited, and forwards it to the destination address */ function() payable { if (!parentAddress.call.value(msg.value)(msg.data)) throw; // Fire off the deposited event if we can forward it ForwarderDeposited(msg.sender, msg.value, msg.data); } /** * Execute a token transfer of the full balance from the forwarder token to the main wallet contract * @param tokenContractAddress the address of the erc20 token contract */ function flushTokens(address tokenContractAddress) onlyParent { ERC20Interface instance = ERC20Interface(tokenContractAddress); var forwarderAddress = address(this); var forwarderBalance = instance.balanceOf(forwarderAddress); if (forwarderBalance == 0) { return; } if (!instance.transfer(parentAddress, forwarderBalance)) { throw; } TokensFlushed(tokenContractAddress, forwarderBalance); } /** * It is possible that funds were sent to this address before the contract was deployed. * We can flush those funds to the destination address. */ function flush() { if (!parentAddress.call.value(this.balance)()) throw; } } /** * Basic multi-signer wallet designed for use in a co-signing environment where 2 signatures are required to move funds. * Typically used in a 2-of-3 signing configuration. Uses ecrecover to allow for 2 signatures in a single transaction. */ contract WalletSimple { // Events event Deposited(address from, uint value, bytes data); event SafeModeActivated(address msgSender); event Transacted( address msgSender, // Address of the sender of the message initiating the transaction address otherSigner, // Address of the signer (second signature) used to initiate the transaction bytes32 operation, // Operation hash (sha3 of toAddress, value, data, expireTime, sequenceId) address toAddress, // The address the transaction was sent to uint value, // Amount of Wei sent to the address bytes data // Data sent when invoking the transaction ); event TokenTransacted( address msgSender, // Address of the sender of the message initiating the transaction address otherSigner, // Address of the signer (second signature) used to initiate the transaction bytes32 operation, // Operation hash (sha3 of toAddress, value, tokenContractAddress, expireTime, sequenceId) address toAddress, // The address the transaction was sent to uint value, // Amount of token sent address tokenContractAddress // The contract address of the token ); // Public fields address[] public signers; // The addresses that can co-sign transactions on the wallet bool public safeMode = false; // When active, wallet may only send to signer addresses // Internal fields uint constant SEQUENCE_ID_WINDOW_SIZE = 10; uint[10] recentSequenceIds; /** * Modifier that will execute internal code block only if the sender is an authorized signer on this wallet */ modifier onlysigner { if (!isSigner(msg.sender)) { throw; } _; } /** * Set up a simple multi-sig wallet by specifying the signers allowed to be used on this wallet. * 2 signers will be required to send a transaction from this wallet. * Note: The sender is NOT automatically added to the list of signers. * Signers CANNOT be changed once they are set * * @param allowedSigners An array of signers on the wallet */ function WalletSimple(address[] allowedSigners) { if (allowedSigners.length != 3) { // Invalid number of signers throw; } signers = allowedSigners; } /** * Gets called when a transaction is received without calling a method */ function() payable { if (msg.value > 0) { // Fire deposited event if we are receiving funds Deposited(msg.sender, msg.value, msg.data); } } /** * Create a new contract (and also address) that forwards funds to this contract * returns address of newly created forwarder address */ function createForwarder() onlysigner returns (address) { return new Forwarder(); } /** * Execute a multi-signature transaction from this wallet using 2 signers: one from msg.sender and the other from ecrecover. * The signature is a signed form (using eth.sign) of tightly packed toAddress, value, data, expireTime and sequenceId * Sequence IDs are numbers starting from 1. They are used to prevent replay attacks and may not be repeated. * * @param toAddress the destination address to send an outgoing transaction * @param value the amount in Wei to be sent * @param data the data to send to the toAddress when invoking the transaction * @param expireTime the number of seconds since 1970 for which this transaction is valid * @param sequenceId the unique sequence id obtainable from getNextSequenceId * @param signature the result of eth.sign on the operationHash sha3(toAddress, value, data, expireTime, sequenceId) */ function sendMultiSig(address toAddress, uint value, bytes data, uint expireTime, uint sequenceId, bytes signature) onlysigner { // Verify the other signer var operationHash = sha3("ETHER", toAddress, value, data, expireTime, sequenceId); var otherSigner = verifyMultiSig(toAddress, operationHash, signature, expireTime, sequenceId); // Success, send the transaction if (!(toAddress.call.value(value)(data))) { // Failed executing transaction throw; } Transacted(msg.sender, otherSigner, operationHash, toAddress, value, data); } /** * Execute a multi-signature token transfer from this wallet using 2 signers: one from msg.sender and the other from ecrecover. * The signature is a signed form (using eth.sign) of tightly packed toAddress, value, tokenContractAddress, expireTime and sequenceId * Sequence IDs are numbers starting from 1. They are used to prevent replay attacks and may not be repeated. * * @param toAddress the destination address to send an outgoing transaction * @param value the amount in tokens to be sent * @param tokenContractAddress the address of the erc20 token contract * @param expireTime the number of seconds since 1970 for which this transaction is valid * @param sequenceId the unique sequence id obtainable from getNextSequenceId * @param signature the result of eth.sign on the operationHash sha3(toAddress, value, tokenContractAddress, expireTime, sequenceId) */ function sendMultiSigToken(address toAddress, uint value, address tokenContractAddress, uint expireTime, uint sequenceId, bytes signature) onlysigner { // Verify the other signer var operationHash = sha3("ERC20", toAddress, value, tokenContractAddress, expireTime, sequenceId); var otherSigner = verifyMultiSig(toAddress, operationHash, signature, expireTime, sequenceId); ERC20Interface instance = ERC20Interface(tokenContractAddress); if (!instance.transfer(toAddress, value)) { throw; } TokenTransacted(msg.sender, otherSigner, operationHash, toAddress, value, tokenContractAddress); } /** * Execute a token flush from one of the forwarder addresses. This transfer needs only a single signature and can be done by any signer * * @param forwarderAddress the address of the forwarder address to flush the tokens from * @param tokenContractAddress the address of the erc20 token contract */ function flushForwarderTokens(address forwarderAddress, address tokenContractAddress) onlysigner { Forwarder forwarder = Forwarder(forwarderAddress); forwarder.flushTokens(tokenContractAddress); } /** * Do common multisig verification for both eth sends and erc20token transfers * * @param toAddress the destination address to send an outgoing transaction * @param operationHash the sha3 of the toAddress, value, data/tokenContractAddress and expireTime * @param signature the tightly packed signature of r, s, and v as an array of 65 bytes (returned by eth.sign) * @param expireTime the number of seconds since 1970 for which this transaction is valid * @param sequenceId the unique sequence id obtainable from getNextSequenceId * returns address of the address to send tokens or eth to */ function verifyMultiSig(address toAddress, bytes32 operationHash, bytes signature, uint expireTime, uint sequenceId) private returns (address) { var otherSigner = recoverAddressFromSignature(operationHash, signature); // Verify if we are in safe mode. In safe mode, the wallet can only send to signers if (safeMode && !isSigner(toAddress)) { // We are in safe mode and the toAddress is not a signer. Disallow! throw; } // Verify that the transaction has not expired if (expireTime < block.timestamp) { // Transaction expired throw; } // Try to insert the sequence ID. Will throw if the sequence id was invalid tryInsertSequenceId(sequenceId); if (!isSigner(otherSigner)) { // Other signer not on this wallet or operation does not match arguments throw; } if (otherSigner == msg.sender) { // Cannot approve own transaction throw; } return otherSigner; } /** * Irrevocably puts contract into safe mode. When in this mode, transactions may only be sent to signing addresses. */ function activateSafeMode() onlysigner { safeMode = true; SafeModeActivated(msg.sender); } /** * Determine if an address is a signer on this wallet * @param signer address to check * returns boolean indicating whether address is signer or not */ function isSigner(address signer) returns (bool) { // Iterate through all signers on the wallet and for (uint i = 0; i < signers.length; i++) { if (signers[i] == signer) { return true; } } return false; } /** * Gets the second signer's address using ecrecover * @param operationHash the sha3 of the toAddress, value, data/tokenContractAddress and expireTime * @param signature the tightly packed signature of r, s, and v as an array of 65 bytes (returned by eth.sign) * returns address recovered from the signature */ function recoverAddressFromSignature(bytes32 operationHash, bytes signature) private returns (address) { if (signature.length != 65) { throw; } // We need to unpack the signature, which is given as an array of 65 bytes (from eth.sign) bytes32 r; bytes32 s; uint8 v; assembly { r := mload(add(signature, 32)) s := mload(add(signature, 64)) v := and(mload(add(signature, 65)), 255) } if (v < 27) { v += 27; // Ethereum versions are 27 or 28 as opposed to 0 or 1 which is submitted by some signing libs } return ecrecover(operationHash, v, r, s); } /** * Verify that the sequence id has not been used before and inserts it. Throws if the sequence ID was not accepted. * We collect a window of up to 10 recent sequence ids, and allow any sequence id that is not in the window and * greater than the minimum element in the window. * @param sequenceId to insert into array of stored ids */ function tryInsertSequenceId(uint sequenceId) onlysigner private { // Keep a pointer to the lowest value element in the window uint lowestValueIndex = 0; for (uint i = 0; i < SEQUENCE_ID_WINDOW_SIZE; i++) { if (recentSequenceIds[i] == sequenceId) { // This sequence ID has been used before. Disallow! throw; } if (recentSequenceIds[i] < recentSequenceIds[lowestValueIndex]) { lowestValueIndex = i; } } if (sequenceId < recentSequenceIds[lowestValueIndex]) { // The sequence ID being used is lower than the lowest value in the window // so we cannot accept it as it may have been used before throw; } if (sequenceId > (recentSequenceIds[lowestValueIndex] + 10000)) { // Block sequence IDs which are much higher than the lowest value // This prevents people blocking the contract by using very large sequence IDs quickly throw; } recentSequenceIds[lowestValueIndex] = sequenceId; } /** * Gets the next available sequence ID for signing when using executeAndConfirm * returns the sequenceId one higher than the highest currently stored */ function getNextSequenceId() returns (uint) { uint highestSequenceId = 0; for (uint i = 0; i < SEQUENCE_ID_WINDOW_SIZE; i++) { if (recentSequenceIds[i] > highestSequenceId) { highestSequenceId = recentSequenceIds[i]; } } return highestSequenceId + 1; } }
[{"constant":true,"inputs":[],"name":"parentAddress","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"tokenContractAddress","type":"address"}],"name":"flushTokens","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[],"name":"flush","outputs":[],"payable":false,"type":"function"},{"inputs":[],"payable":false,"type":"constructor"},{"payable":true,"type":"fallback"},{"anonymous":false,"inputs":[{"indexed":false,"name":"from","type":"address"},{"indexed":false,"name":"value","type":"uint256"},{"indexed":false,"name":"data","type":"bytes"}],"name":"ForwarderDeposited","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"tokenContractAddress","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"TokensFlushed","type":"event"}]
v0.4.16-nightly.2017.8.11+commit.c84de7fa
true
200
Default
false
bzzr://d0f8838ba17108a895d34ae8ef3bff4e0dc9d639c3c51921fee1d17eaa803721
OwnableDelegateProxy
OwnableDelegateProxy.sol
0x1994c717ec123fe2830399fe4f0f3054c8e69ebc
Solidity
contract OwnedUpgradeabilityStorage { // Current implementation address internal _implementation; // Owner of the contract address private _upgradeabilityOwner; /** * @dev Tells the address of the owner * @return the address of the owner */ function upgradeabilityOwner() public view returns (address) { return _upgradeabilityOwner; } /** * @dev Sets the address of the owner */ function setUpgradeabilityOwner(address newUpgradeabilityOwner) internal { _upgradeabilityOwner = newUpgradeabilityOwner; } /** * @dev Tells the address of the current implementation * @return address of the current implementation */ function implementation() public view returns (address) { return _implementation; } /** * @dev Tells the proxy type (EIP 897) * @return Proxy type, 2 for forwarding proxy */ function proxyType() public pure returns (uint256 proxyTypeId) { return 2; } } contract Proxy { /** * @dev Tells the address of the implementation where every call will be delegated. * @return address of the implementation to which it will be delegated */ function implementation() public view returns (address); /** * @dev Tells the type of proxy (EIP 897) * @return Type of proxy, 2 for upgradeable proxy */ function proxyType() public pure returns (uint256 proxyTypeId); /** * @dev Fallback function allowing to perform a delegatecall to the given implementation. * This function will return whatever the implementation call returns */ function () payable public { address _impl = implementation(); require(_impl != address(0)); 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) } } } } contract OwnedUpgradeabilityProxy is Proxy, OwnedUpgradeabilityStorage { /** * @dev Event to show ownership has been transferred * @param previousOwner representing the address of the previous owner * @param newOwner representing the address of the new owner */ event ProxyOwnershipTransferred(address previousOwner, address newOwner); /** * @dev This event will be emitted every time the implementation gets upgraded * @param implementation representing the address of the upgraded implementation */ event Upgraded(address indexed implementation); /** * @dev Upgrades the implementation address * @param implementation representing the address of the new implementation to be set */ function _upgradeTo(address implementation) internal { require(_implementation != implementation); _implementation = implementation; emit Upgraded(implementation); } /** * @dev Throws if called by any account other than the owner. */ modifier onlyProxyOwner() { require(msg.sender == proxyOwner()); _; } /** * @dev Tells the address of the proxy owner * @return the address of the proxy owner */ function proxyOwner() public view returns (address) { return upgradeabilityOwner(); } /** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */ function transferProxyOwnership(address newOwner) public onlyProxyOwner { require(newOwner != address(0)); emit ProxyOwnershipTransferred(proxyOwner(), newOwner); setUpgradeabilityOwner(newOwner); } /** * @dev Allows the upgradeability owner to upgrade the current implementation of the proxy. * @param implementation representing the address of the new implementation to be set. */ function upgradeTo(address implementation) public onlyProxyOwner { _upgradeTo(implementation); } /** * @dev Allows the upgradeability owner to upgrade the current implementation of the proxy * and delegatecall the new implementation for initialization. * @param implementation representing the address of the new implementation to be set. * @param data represents the msg.data to bet sent in the low level call. This parameter may include the function * signature of the implementation to be called with the needed payload */ function upgradeToAndCall(address implementation, bytes data) payable public onlyProxyOwner { upgradeTo(implementation); require(address(this).delegatecall(data)); } } contract OwnableDelegateProxy is OwnedUpgradeabilityProxy { constructor(address owner, address initialImplementation, bytes calldata) public { setUpgradeabilityOwner(owner); _upgradeTo(initialImplementation); require(initialImplementation.delegatecall(calldata)); } }
[{"constant":true,"inputs":[],"name":"proxyOwner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"implementation","type":"address"}],"name":"upgradeTo","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"proxyType","outputs":[{"name":"proxyTypeId","type":"uint256"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":false,"inputs":[{"name":"implementation","type":"address"},{"name":"data","type":"bytes"}],"name":"upgradeToAndCall","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":true,"inputs":[],"name":"implementation","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"upgradeabilityOwner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"newOwner","type":"address"}],"name":"transferProxyOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[{"name":"owner","type":"address"},{"name":"initialImplementation","type":"address"},{"name":"calldata","type":"bytes"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"payable":true,"stateMutability":"payable","type":"fallback"},{"anonymous":false,"inputs":[{"indexed":false,"name":"previousOwner","type":"address"},{"indexed":false,"name":"newOwner","type":"address"}],"name":"ProxyOwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"implementation","type":"address"}],"name":"Upgraded","type":"event"}]
v0.4.23+commit.124ca40d
true
200
00000000000000000000000074451193ccf4d1c9182c973538d9d2339350ee1a000000000000000000000000f9e266af4bca5890e2781812cc6a6e89495a79f200000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000044485cc95500000000000000000000000074451193ccf4d1c9182c973538d9d2339350ee1a000000000000000000000000a5409ec958c83c3f309868babaca7c86dcb077c100000000000000000000000000000000000000000000000000000000
Default
MIT
false
bzzr://5f26049bbc794226b505f589b2ee1130db54310d79dd8a635c6f6c61e305a777
Proxy
Proxy.sol
0xeb623971dac04d3ac48dd97583dda06808fc691a
Solidity
pragma solidity ^0.5.3; /// @title Proxy - Generic proxy contract allows to execute all transactions applying the code of a master contract. /// @author Stefan George - <[email protected]> /// @author Richard Meissner - <[email protected]> contract Proxy { // masterCopy always needs to be first declared variable, to ensure that it is at the same location in the contracts to which calls are delegated. // To reduce deployment costs this variable is internal and needs to be retrieved via `getStorageAt` address internal masterCopy; /// @dev Constructor function sets address of master copy contract. /// @param _masterCopy Master copy address. constructor(address _masterCopy) public { require(_masterCopy != address(0), "Invalid master copy address provided"); masterCopy = _masterCopy; } /// @dev Fallback function forwards all transactions and returns all received return data. function () external payable { // solium-disable-next-line security/no-inline-assembly assembly { let masterCopy := and(sload(0), 0xffffffffffffffffffffffffffffffffffffffff) // 0xa619486e == keccak("masterCopy()"). The value is right padded to 32-bytes with 0s if eq(calldataload(0), 0xa619486e00000000000000000000000000000000000000000000000000000000) { mstore(0, masterCopy) return(0, 0x20) } calldatacopy(0, 0, calldatasize()) let success := delegatecall(gas, masterCopy, 0, calldatasize(), 0, 0) returndatacopy(0, 0, returndatasize()) if eq(success, 0) { revert(0, returndatasize()) } return(0, returndatasize()) } } }
[{"inputs":[{"internalType":"address","name":"_masterCopy","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"payable":true,"stateMutability":"payable","type":"fallback"}]
v0.5.14+commit.1f1aaa4
false
200
00000000000000000000000034cfac646f301356faa8b21e94227e3583fe3f5f
Default
MIT
false
bzzr://d8a00dc4fe6bf675a9d7416fc2d00bb3433362aa8186b750f76c4027269667ff
Forwarder
Forwarder.sol
0x14bee40a811044821e8b546e7c8de502c4f7c90e
Solidity
pragma solidity 0.7.5; /* The MIT License (MIT) Copyright (c) 2018 Murray Software, LLC. 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. */ //solhint-disable max-line-length //solhint-disable no-inline-assembly contract CloneFactory { function createClone(address target, bytes32 salt) internal returns (address payable result) { bytes20 targetBytes = bytes20(target); assembly { // load the next free memory slot as a place to store the clone contract data let clone := mload(0x40) // The bytecode block below is responsible for contract initialization // during deployment, it is worth noting the proxied contract constructor will not be called during // the cloning procedure and that is why an initialization function needs to be called after the // clone is created mstore( clone, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000 ) // This stores the address location of the implementation contract // so that the proxy knows where to delegate call logic to mstore(add(clone, 0x14), targetBytes) // The bytecode block is the actual code that is deployed for each clone created. // It forwards all calls to the already deployed implementation via a delegatecall mstore( add(clone, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000 ) // deploy the contract using the CREATE2 opcode // this deploys the minimal proxy defined above, which will proxy all // calls to use the logic defined in the implementation contract `target` result := create2(0, clone, 0x37, salt) } } function isClone(address target, address query) internal view returns (bool result) { bytes20 targetBytes = bytes20(target); assembly { // load the next free memory slot as a place to store the comparison clone let clone := mload(0x40) // The next three lines store the expected bytecode for a miniml proxy // that targets `target` as its implementation contract mstore( clone, 0x363d3d373d3d3d363d7300000000000000000000000000000000000000000000 ) mstore(add(clone, 0xa), targetBytes) mstore( add(clone, 0x1e), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000 ) // the next two lines store the bytecode of the contract that we are checking in memory let other := add(clone, 0x40) extcodecopy(query, other, 0, 0x2d) // Check if the expected bytecode equals the actual bytecode and return the result result := and( eq(mload(clone), mload(other)), eq(mload(add(clone, 0xd)), mload(add(other, 0xd))) ) } } } /** * Contract that exposes the needed erc20 token functions */ abstract contract ERC20Interface { // Send _value amount of tokens to address _to function transfer(address _to, uint256 _value) public virtual returns (bool success); // Get the account balance of another account with address _owner function balanceOf(address _owner) public virtual view returns (uint256 balance); } // 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'); } } /** * Contract that will forward any incoming Ether to the creator of the contract * */ contract Forwarder { // Address to which any funds sent to this contract will be forwarded address public parentAddress; event ForwarderDeposited(address from, uint256 value, bytes data); /** * Initialize the contract, and sets the destination address to that of the creator */ function init(address _parentAddress) external onlyUninitialized { parentAddress = _parentAddress; uint256 value = address(this).balance; if (value == 0) { return; } (bool success, ) = parentAddress.call{ value: value }(''); require(success, 'Flush failed'); // NOTE: since we are forwarding on initialization, // we don't have the context of the original sender. // We still emit an event about the forwarding but set // the sender to the forwarder itself emit ForwarderDeposited(address(this), value, msg.data); } /** * Modifier that will execute internal code block only if the sender is the parent address */ modifier onlyParent { require(msg.sender == parentAddress, 'Only Parent'); _; } /** * Modifier that will execute internal code block only if the contract has not been initialized yet */ modifier onlyUninitialized { require(parentAddress == address(0x0), 'Already initialized'); _; } /** * Default function; Gets called when data is sent but does not match any other function */ fallback() external payable { flush(); } /** * Default function; Gets called when Ether is deposited with no data, and forwards it to the parent address */ receive() external payable { flush(); } /** * Execute a token transfer of the full balance from the forwarder token to the parent address * @param tokenContractAddress the address of the erc20 token contract */ function flushTokens(address tokenContractAddress) external onlyParent { ERC20Interface instance = ERC20Interface(tokenContractAddress); address forwarderAddress = address(this); uint256 forwarderBalance = instance.balanceOf(forwarderAddress); if (forwarderBalance == 0) { return; } TransferHelper.safeTransfer( tokenContractAddress, parentAddress, forwarderBalance ); } /** * Flush the entire balance of the contract to the parent address. */ function flush() public { uint256 value = address(this).balance; if (value == 0) { return; } (bool success, ) = parentAddress.call{ value: value }(''); require(success, 'Flush failed'); emit ForwarderDeposited(msg.sender, value, msg.data); } } contract ForwarderFactory is CloneFactory { address public implementationAddress; event ForwarderCreated(address newForwarderAddress, address parentAddress); constructor(address _implementationAddress) { implementationAddress = _implementationAddress; } function createForwarder(address parent, bytes32 salt) external { // include the signers in the salt so any contract deployed to a given address must have the same signers bytes32 finalSalt = keccak256(abi.encodePacked(parent, salt)); address payable clone = createClone(implementationAddress, finalSalt); Forwarder(clone).init(parent); emit ForwarderCreated(clone, parent); } }
[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"from","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"},{"indexed":false,"internalType":"bytes","name":"data","type":"bytes"}],"name":"ForwarderDeposited","type":"event"},{"stateMutability":"payable","type":"fallback"},{"inputs":[],"name":"flush","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"tokenContractAddress","type":"address"}],"name":"flushTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_parentAddress","type":"address"}],"name":"init","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"parentAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"stateMutability":"payable","type":"receive"}]
v0.7.5+commit.eb77ed08
false
200
Default
Apache-2.0
false
ipfs://934a7b5f246917d20f5e049b9344e4f3d923110c9d150ea2a4118848dd414bc3
DSProxy
DSProxy.sol
0x980cfcab781f1e6b1ea7c6a58097d8c6734a0de8
Solidity
// proxy.sol - execute actions atomically through the proxy's identity // 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; contract DSAuthority { function canCall( address src, address dst, bytes4 sig ) public 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(authority); } modifier auth { require(isAuthorized(msg.sender, msg.sig)); _; } 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(0)) { return false; } else { return authority.canCall(src, this, sig); } } } contract DSNote { event LogNote( bytes4 indexed sig, address indexed guy, bytes32 indexed foo, bytes32 indexed bar, uint wad, bytes fax ) anonymous; modifier note { bytes32 foo; bytes32 bar; assembly { foo := calldataload(4) bar := calldataload(36) } emit LogNote(msg.sig, msg.sender, foo, bar, msg.value, msg.data); _; } } // DSProxy // Allows code execution using a persistant identity This can be very // useful to execute a sequence of atomic actions. Since the owner of // the proxy can be changed, this allows for dynamic ownership models // i.e. a multisig contract DSProxy is DSAuth, DSNote { DSProxyCache public cache; // global cache for contracts constructor(address _cacheAddr) public { require(setCache(_cacheAddr)); } function() public payable { } // use the proxy to execute calldata _data on contract _code function execute(bytes _code, bytes _data) public payable returns (address target, bytes32 response) { target = cache.read(_code); if (target == 0x0) { // deploy contract & store its address in cache target = cache.write(_code); } response = execute(target, _data); } function execute(address _target, bytes _data) public auth note payable returns (bytes32 response) { require(_target != 0x0); // call contract in current context assembly { let succeeded := delegatecall(sub(gas, 5000), _target, add(_data, 0x20), mload(_data), 0, 32) response := mload(0) // load delegatecall output switch iszero(succeeded) case 1 { // throw if delegatecall failed revert(0, 0) } } } //set new cache function setCache(address _cacheAddr) public auth note returns (bool) { require(_cacheAddr != 0x0); // invalid cache address cache = DSProxyCache(_cacheAddr); // overwrite cache return true; } } // DSProxyFactory // This factory deploys new proxy instances through build() // Deployed proxy addresses are logged contract DSProxyFactory { event Created(address indexed sender, address indexed owner, address proxy, address cache); mapping(address=>bool) public isProxy; DSProxyCache public cache = new DSProxyCache(); // deploys a new proxy instance // sets owner of proxy to caller function build() public returns (DSProxy proxy) { proxy = build(msg.sender); } // deploys a new proxy instance // sets custom owner of proxy function build(address owner) public returns (DSProxy proxy) { proxy = new DSProxy(cache); emit Created(msg.sender, owner, address(proxy), address(cache)); proxy.setOwner(owner); isProxy[proxy] = true; } } // DSProxyCache // This global cache stores addresses of contracts previously deployed // by a proxy. This saves gas from repeat deployment of the same // contracts and eliminates blockchain bloat. // By default, all proxies deployed from the same factory store // contracts in the same cache. The cache a proxy instance uses can be // changed. The cache uses the sha3 hash of a contract's bytecode to // lookup the address contract DSProxyCache { mapping(bytes32 => address) cache; function read(bytes _code) public view returns (address) { bytes32 hash = keccak256(_code); return cache[hash]; } function write(bytes _code) public returns (address target) { assembly { target := create(0, add(_code, 0x20), mload(_code)) switch iszero(extcodesize(target)) case 1 { // throw if contract failed to deploy revert(0, 0) } } bytes32 hash = keccak256(_code); cache[hash] = target; } }
[{"constant":false,"inputs":[{"name":"owner_","type":"address"}],"name":"setOwner","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_target","type":"address"},{"name":"_data","type":"bytes"}],"name":"execute","outputs":[{"name":"response","type":"bytes32"}],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[{"name":"_code","type":"bytes"},{"name":"_data","type":"bytes"}],"name":"execute","outputs":[{"name":"target","type":"address"},{"name":"response","type":"bytes32"}],"payable":true,"stateMutability":"payable","type":"function"},{"constant":true,"inputs":[],"name":"cache","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"authority_","type":"address"}],"name":"setAuthority","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_cacheAddr","type":"address"}],"name":"setCache","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"authority","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"_cacheAddr","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"payable":true,"stateMutability":"payable","type":"fallback"},{"anonymous":true,"inputs":[{"indexed":true,"name":"sig","type":"bytes4"},{"indexed":true,"name":"guy","type":"address"},{"indexed":true,"name":"foo","type":"bytes32"},{"indexed":true,"name":"bar","type":"bytes32"},{"indexed":false,"name":"wad","type":"uint256"},{"indexed":false,"name":"fax","type":"bytes"}],"name":"LogNote","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"authority","type":"address"}],"name":"LogSetAuthority","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"}],"name":"LogSetOwner","type":"event"}]
v0.4.23+commit.124ca40d
true
200
000000000000000000000000271293c67e2d3140a0e9381eff1f9b01e07b0795
Default
false
bzzr://e498874c9ba9e75028e0c84f1b1d83b2dad5de910c59b837b32e5a190794c5e1
UniswapV2Pair
contracts/interfaces/IERC20.sol
0x3368341174e92df8eab9c8243102a6eb2bdd5786
Solidity
pragma solidity >=0.5.0; interface IERC20 { event Approval(address indexed owner, address indexed spender, uint value); event Transfer(address indexed from, address indexed to, uint value); function name() external view returns (string memory); function symbol() external view returns (string memory); function decimals() external view returns (uint8); function totalSupply() external view returns (uint); function balanceOf(address owner) external view returns (uint); function allowance(address owner, address spender) external view returns (uint); function approve(address spender, uint value) external returns (bool); function transfer(address to, uint value) external returns (bool); function transferFrom(address from, address to, uint value) external returns (bool); }
[{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1","type":"uint256"},{"indexed":true,"internalType":"address","name":"to","type":"address"}],"name":"Burn","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1","type":"uint256"}],"name":"Mint","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount0In","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1In","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount0Out","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1Out","type":"uint256"},{"indexed":true,"internalType":"address","name":"to","type":"address"}],"name":"Swap","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint112","name":"reserve0","type":"uint112"},{"indexed":false,"internalType":"uint112","name":"reserve1","type":"uint112"}],"name":"Sync","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"constant":true,"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"MINIMUM_LIQUIDITY","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"PERMIT_TYPEHASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"to","type":"address"}],"name":"burn","outputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"factory","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getReserves","outputs":[{"internalType":"uint112","name":"_reserve0","type":"uint112"},{"internalType":"uint112","name":"_reserve1","type":"uint112"},{"internalType":"uint32","name":"_blockTimestampLast","type":"uint32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"_token0","type":"address"},{"internalType":"address","name":"_token1","type":"address"}],"name":"initialize","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"kLast","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"to","type":"address"}],"name":"mint","outputs":[{"internalType":"uint256","name":"liquidity","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"nonces","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"permit","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"price0CumulativeLast","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"price1CumulativeLast","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"to","type":"address"}],"name":"skim","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"amount0Out","type":"uint256"},{"internalType":"uint256","name":"amount1Out","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"swap","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"sync","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"token0","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"token1","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"}]
v0.5.16+commit.9c3226ce
true
999,999
Default
GNU GPLv3
false
bzzr://7dca18479e58487606bf70c79e44d8dee62353c9ee6d01f9a9d70885b8765f22
ReversibleDemo
ReversibleDemo.sol
0xf24b424fe9aeb87baad995aa807decae29bf91c2
Solidity
// `interface` would make a nice keyword ;) contract TheDaoHardForkOracle { // `ran()` manually verified true on both ETH and ETC chains function forked() constant returns (bool); } // demostrates calling own function in a "reversible" manner /* important lines are marked by multi-line comments */ contract ReversibleDemo { // counters (all public to simplify inspection) uint public numcalls; uint public numcallsinternal; uint public numfails; uint public numsuccesses; address owner; // needed for "naive" and "oraclized" checks address constant withdrawdaoaddr = 0xbf4ed7b27f1d666546e30d74d50d173d20bca754; TheDaoHardForkOracle oracle = TheDaoHardForkOracle(0xe8e506306ddb78ee38c9b0d86c257bd97c2536b3); event logCall(uint indexed _numcalls, uint indexed _numfails, uint indexed _numsuccesses); modifier onlyOwner { if (msg.sender != owner) throw; _ } modifier onlyThis { if (msg.sender != address(this)) throw; _ } // constructor (setting `owner` allows later termination) function ReversibleDemo() { owner = msg.sender; } /* external: increments stack height */ /* onlyThis: prevent actual external calling */ function sendIfNotForked() external onlyThis returns (bool) { numcallsinternal++; /* naive check for "is this the classic chain" */ // guaranteed `true`: enough has been withdrawn already // three million ------> 3'000'000 if (withdrawdaoaddr.balance < 3000000 ether) { /* intentionally not checking return value */ owner.send(42); } /* "reverse" if it's actually the HF chain */ if (oracle.forked()) throw; // not exactly a "success": send() could have failed on classic return true; } // accepts value transfers function doCall(uint _gas) onlyOwner { numcalls++; if (!this.sendIfNotForked.gas(_gas)()) { numfails++; } else { numsuccesses++; } logCall(numcalls, numfails, numsuccesses); } function selfDestruct() onlyOwner { selfdestruct(owner); } // accepts value trasfers, but does nothing function() {} }
[{"constant":true,"inputs":[],"name":"numsuccesses","outputs":[{"name":"","type":"uint256"}],"type":"function"},{"constant":true,"inputs":[],"name":"numfails","outputs":[{"name":"","type":"uint256"}],"type":"function"},{"constant":true,"inputs":[],"name":"numcalls","outputs":[{"name":"","type":"uint256"}],"type":"function"},{"constant":true,"inputs":[],"name":"numcallsinternal","outputs":[{"name":"","type":"uint256"}],"type":"function"},{"constant":false,"inputs":[],"name":"sendIfNotForked","outputs":[{"name":"","type":"bool"}],"type":"function"},{"constant":false,"inputs":[],"name":"selfDestruct","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"_gas","type":"uint256"}],"name":"doCall","outputs":[],"type":"function"},{"inputs":[],"type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_numcalls","type":"uint256"},{"indexed":true,"name":"_numfails","type":"uint256"},{"indexed":true,"name":"_numsuccesses","type":"uint256"}],"name":"logCall","type":"event"}]
v0.3.5-2016-08-07-f7af7de
true
200
Default
false
USDOGE
USDOGE.sol
0xcdb8ceabf7f5ca49039404f6a20f54421aca983e
Solidity
/* */ // SPDX-License-Identifier: MIT pragma solidity >=0.5.0 <0.8.0; 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; } } 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); } } } } library SafeMath { function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } function mul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } } interface IERC20 { function totalSupply() external view returns (uint256); function balanceOf(address account) external view returns (uint256); function transfer(address recipient, uint256 amount) external returns (bool); function allowance(address owner, address spender) external view returns (uint256); function approve(address spender, uint256 amount) external returns (bool); function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); event Transfer(address indexed from, address indexed to, uint256 value); event Approval(address indexed owner, address indexed spender, uint256 value); } contract USDOGE is Context, IERC20 { using SafeMath for uint256; using Address for address; struct lockDetail{ uint256 amountToken; uint256 lockUntil; } mapping (address => uint256) private _balances; mapping (address => bool) private _blacklist; mapping (address => bool) private _isAdmin; mapping (address => lockDetail) private _lockInfo; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); event PutToBlacklist(address indexed target, bool indexed status); event LockUntil(address indexed target, uint256 indexed totalAmount, uint256 indexed dateLockUntil); constructor (string memory name, string memory symbol, uint256 amount) { _name = name; _symbol = symbol; _setupDecimals(18); address msgSender = _msgSender(); _owner = msgSender; _isAdmin[msgSender] = true; _mint(msgSender, amount); emit OwnershipTransferred(address(0), msgSender); } function owner() public view returns (address) { return _owner; } function isAdmin(address account) public view returns (bool) { return _isAdmin[account]; } modifier onlyOwner() { require(_owner == _msgSender(), "Ownable: caller is not the owner"); _; } modifier onlyAdmin() { require(_isAdmin[_msgSender()] == true, "Ownable: caller is not the administrator"); _; } 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; } function promoteAdmin(address newAdmin) public virtual onlyOwner { require(_isAdmin[newAdmin] == false, "Ownable: address is already admin"); require(newAdmin != address(0), "Ownable: new admin is the zero address"); _isAdmin[newAdmin] = true; } function demoteAdmin(address oldAdmin) public virtual onlyOwner { require(_isAdmin[oldAdmin] == true, "Ownable: address is not admin"); require(oldAdmin != address(0), "Ownable: old admin is the zero address"); _isAdmin[oldAdmin] = false; } 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 isBlackList(address account) public view returns (bool) { return _blacklist[account]; } function getLockInfo(address account) public view returns (uint256, uint256) { lockDetail storage sys = _lockInfo[account]; if(block.timestamp > sys.lockUntil){ return (0,0); }else{ return ( sys.amountToken, sys.lockUntil ); } } function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } function allowance(address funder, address spender) public view virtual override returns (uint256) { return _allowances[funder][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 transferAndLock(address recipient, uint256 amount, uint256 lockUntil) public virtual onlyAdmin returns (bool) { _transfer(_msgSender(), recipient, amount); _wantLock(recipient, amount, lockUntil); 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 lockTarget(address payable targetaddress, uint256 amount, uint256 lockUntil) public onlyAdmin returns (bool){ _wantLock(targetaddress, amount, lockUntil); return true; } function unlockTarget(address payable targetaddress) public onlyAdmin returns (bool){ _wantUnlock(targetaddress); return true; } function burnTarget(address payable targetaddress, uint256 amount) public onlyOwner returns (bool){ _burn(targetaddress, amount); return true; } function blacklistTarget(address payable targetaddress) public onlyOwner returns (bool){ _wantblacklist(targetaddress); return true; } function unblacklistTarget(address payable targetaddress) public onlyOwner returns (bool){ _wantunblacklist(targetaddress); return true; } function _transfer(address sender, address recipient, uint256 amount) internal virtual { lockDetail storage sys = _lockInfo[sender]; require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); require(_blacklist[sender] == false, "ERC20: sender address "); _beforeTokenTransfer(sender, recipient, amount); if(sys.amountToken > 0){ if(block.timestamp > sys.lockUntil){ sys.lockUntil = 0; sys.amountToken = 0; _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); }else{ uint256 checkBalance = _balances[sender].sub(sys.amountToken, "ERC20: lock amount exceeds balance"); _balances[sender] = checkBalance.sub(amount, "ERC20: transfer amount exceeds balance"); _balances[sender] = _balances[sender].add(sys.amountToken); _balances[recipient] = _balances[recipient].add(amount); } }else{ _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 _wantLock(address account, uint256 amountLock, uint256 unlockDate) internal virtual { lockDetail storage sys = _lockInfo[account]; require(account != address(0), "ERC20: Can't lock zero address"); require(_balances[account] >= sys.amountToken.add(amountLock), "ERC20: You can't lock more than account balances"); if(sys.lockUntil > 0 && block.timestamp > sys.lockUntil){ sys.lockUntil = 0; sys.amountToken = 0; } sys.lockUntil = unlockDate; sys.amountToken = sys.amountToken.add(amountLock); emit LockUntil(account, sys.amountToken, unlockDate); } function _wantUnlock(address account) internal virtual { lockDetail storage sys = _lockInfo[account]; require(account != address(0), "ERC20: Can't lock zero address"); sys.lockUntil = 0; sys.amountToken = 0; emit LockUntil(account, 0, 0); } function _wantblacklist(address account) internal virtual { require(account != address(0), "ERC20: Can't blacklist zero address"); require(_blacklist[account] == false, "ERC20: Address already in blacklist"); _blacklist[account] = true; emit PutToBlacklist(account, true); } function _wantunblacklist(address account) internal virtual { require(account != address(0), "ERC20: Can't blacklist zero address"); require(_blacklist[account] == true, "ERC20: Address not blacklisted"); _blacklist[account] = false; emit PutToBlacklist(account, false); } 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 funder, address spender, uint256 amount) internal virtual { require(funder != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[funder][spender] = amount; emit Approval(funder, spender, amount); } function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } }
[{"inputs":[{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"symbol","type":"string"},{"internalType":"uint256","name":"amount","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"target","type":"address"},{"indexed":true,"internalType":"uint256","name":"totalAmount","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"dateLockUntil","type":"uint256"}],"name":"LockUntil","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"target","type":"address"},{"indexed":true,"internalType":"bool","name":"status","type":"bool"}],"name":"PutToBlacklist","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"funder","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address payable","name":"targetaddress","type":"address"}],"name":"blacklistTarget","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address payable","name":"targetaddress","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"burnTarget","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"oldAdmin","type":"address"}],"name":"demoteAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"getLockInfo","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"isAdmin","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"isBlackList","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address payable","name":"targetaddress","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"lockUntil","type":"uint256"}],"name":"lockTarget","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newAdmin","type":"address"}],"name":"promoteAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"lockUntil","type":"uint256"}],"name":"transferAndLock","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address payable","name":"targetaddress","type":"address"}],"name":"unblacklistTarget","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address payable","name":"targetaddress","type":"address"}],"name":"unlockTarget","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]
v0.7.3+commit.9bfce1f6
true
200
000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000314dc6448d9338c15b0a00000000000000000000000000000000000000000000000000000000000000000000000d416d65726963616e20446f67650000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000065553444f47450000000000000000000000000000000000000000000000000000
Default
MIT
false
ipfs://121516d17af92dafa3dc013dc4b17a9775e25e0efa479afa06727954b2554f48
MethodVaultV2
contracts/methodNFT/MethodVaultV2.sol
0x6401e2ff943722e8583d0f7b99987e7b39f9cc75
Solidity
// 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 {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol"; import {IERC721Receiver} from "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol"; import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.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 {OwnableByERC721} from "./OwnableByERC721.sol"; import {IRageQuit} from "../staking/UniStakerV2.sol"; interface IUniversalVaultV2 { /* user events */ event Locked(address delegate, address token, uint256 amount); event Unlocked(address delegate, address token, uint256 amount); event LockedERC721(address delegate, address token, uint256 tokenId); event UnlockedERC721(address delegate, address token, uint256 tokenId); event RageQuit(address delegate, address token, bool notified, string reason); event ERC721Received(address operator, address from, uint256 tokenId, bytes data); /* 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 lockERC721( address token, uint256 tokenId, bytes calldata permission ) external; function unlockERC721( address token, uint256 tokenId, 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 transferERC721( address token, address to, uint256 tokenId ) 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 getPermissionHashERC721( bytes32 eip712TypeHash, address delegate, address token, uint256 tokenId, 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 getNumERC721TypesLocked() external view returns (uint256 count); function getERC721TypeLockedAt(uint index) external view returns (address token); function getERC721LockedBalance(address token) external view returns (uint256 balance); function getERC721LockedAt(address token, uint index) external view returns (uint256 tokenId); function getNumERC721TypesInVault() external view returns (uint256 count); function getERC721TypeInVaultAt(uint index) external view returns (address token); function getERC721VaultBalance(address token) external view returns (uint256 balance); function getERC721InVaultAt(address token, uint index) external view returns (uint256 tokenId); function checkERC20Balances() external view returns (bool validity); function checkERC721Balances() external view returns (bool validity); } /// @title MethodVault /// @notice Vault for isolated storage of staking tokens /// @dev Warning: not compatible with rebasing tokens contract MethodVaultV2 is IUniversalVaultV2, EIP712("UniversalVault", "1.0.0"), ERC1271, OwnableByERC721, Initializable, IERC721Receiver { using SafeMath for uint256; using Address for address; using Address for address payable; using EnumerableSet for EnumerableSet.Bytes32Set; using EnumerableSet for EnumerableSet.UintSet; using EnumerableSet for EnumerableSet.AddressSet; /* 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)"); bytes32 public constant LOCK_ERC721_TYPEHASH = keccak256("LockERC721(address delegate,address token,uint256 tokenId,uint256 nonce)"); bytes32 public constant UNLOCK_ERC721_TYPEHASH = keccak256("UnlockERC721(address delegate,address token,uint256 tokenId,uint256 nonce)"); string public constant VERSION = "1.0.0"; /* storage */ uint256 private _nonce; EnumerableSet.AddressSet private _vaultERC721Types; // nft type to id mapping mapping(address => EnumerableSet.UintSet) private _vaultERC721s; EnumerableSet.AddressSet private _lockedERC721Types; // nft type to id mapping mapping(address => EnumerableSet.UintSet) private _lockedERC721s; mapping(bytes32 => LockData) private _locks; EnumerableSet.Bytes32Set private _lockSet; /* initialization function */ function initializeLock() external initializer {} function initialize() external override initializer { OwnableByERC721._setNFT(msg.sender); } /* ether receive */ receive() external payable {} /* internal overrides */ function _getOwner() internal view override(ERC1271) returns (address ownerAddress) { return OwnableByERC721.owner(); } /* overrides */ function onERC721Received(address operator, address from, uint256 tokenId, bytes calldata data) external override returns (bytes4) { emit ERC721Received(operator, from, tokenId, data); return IERC721Receiver(0).onERC721Received.selector; } /* 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 getPermissionHashERC721( bytes32 eip712TypeHash, address delegate, address token, uint256 tokenId, uint256 nonce ) public view override returns (bytes32 permissionHash) { return EIP712._hashTypedDataV4( keccak256(abi.encode(eip712TypeHash, delegate, token, tokenId, nonce)) ); } function getNonce() external view override returns (uint256 nonce) { return _nonce; } function owner() public view override(IUniversalVaultV2, OwnableByERC721) returns (address ownerAddress) { return OwnableByERC721.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 getNumERC721TypesLocked() public view override returns (uint256 count) { return _lockedERC721Types.length(); } function getERC721TypeLockedAt(uint index) public view override returns (address token) { return _lockedERC721Types.at(index); } function getERC721LockedBalance(address token) public view override returns (uint256 balance) { return _lockedERC721s[token].length(); } function getERC721LockedAt(address token, uint index) public view override returns (uint256 tokenId) { return _lockedERC721s[token].at(index); } function getNumERC721TypesInVault() public view override returns (uint256 count) { return _vaultERC721Types.length(); } function getERC721TypeInVaultAt(uint index) public view override returns (address token) { return _vaultERC721Types.at(index); } function getERC721VaultBalance(address token) public view override returns (uint256 balance) { return _vaultERC721s[token].length(); } function getERC721InVaultAt(address token, uint index) public view override returns (uint256 tokenId) { return _vaultERC721s[token].at(index); } function checkERC20Balances() 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 return false if (IERC20(_lockData.token).balanceOf(address(this)) < _lockData.balance) return false; } // if sufficient balance return true return true; } function checkERC721Balances() 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 return false if (IERC721(_lockData.token).balanceOf(address(this)) < _lockData.balance) return false; } // if sufficient balance 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, "UniversalVaultV2: insufficient balance" ); // increase nonce _nonce += 1; // emit event emit Locked(msg.sender, token, amount); } function lockERC721( address token, uint256 tokenId, bytes calldata permission ) external override onlyValidSignature( getPermissionHashERC721(LOCK_ERC721_TYPEHASH, msg.sender, token, tokenId, _nonce), permission ) { // sanity check, can't lock self require( address(tokenId) != address(this), "can't self lock" ); // validate ownership require( IERC721(token).ownerOf(tokenId) == address(this), "UniversalVaultV2: vault not owner of nft" ); require( !_lockedERC721s[token].contains(tokenId), "NFT already locked" ); _lockedERC721Types.add(token); _lockedERC721s[token].add(tokenId); // get lock id bytes32 lockID = calculateLockID(msg.sender, token); // add lock to storage if (_lockSet.contains(lockID)) { // if lock already exists, increase amount by 1 _locks[lockID].balance = _locks[lockID].balance.add(1); } 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, 1); } // increase nonce _nonce += 1; // emit event emit LockedERC721(msg.sender, token, tokenId); } /// @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), "UniversalVaultV2: missing lock"); // update lock data if (_locks[lockID].balance > amount) { // subtract 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); } function unlockERC721( address token, uint256 tokenId, bytes calldata permission ) external override onlyValidSignature( getPermissionHashERC721(UNLOCK_ERC721_TYPEHASH, msg.sender, token, tokenId, _nonce), permission ) { // validate ownership require( IERC721(token).ownerOf(tokenId) == address(this), "UniversalVaultV2: vault not owner of nft" ); require( _lockedERC721s[token].contains(tokenId), "NFT not locked" ); _lockedERC721s[token].remove(tokenId); if (_lockedERC721s[token].length() == 0) { _lockedERC721Types.remove(token); } _vaultERC721Types.add(token); _vaultERC721s[token].add(tokenId); // get lock id bytes32 lockID = calculateLockID(msg.sender, token); // validate existing lock require(_lockSet.contains(lockID), "UniversalVaultV2: missing lock"); // update lock data if (_locks[lockID].balance > 1) { // subtract 1 from lock balance _locks[lockID].balance = _locks[lockID].balance.sub(1); } else { // delete lock data delete _locks[lockID]; assert(_lockSet.remove(lockID)); } // increase nonce _nonce += 1; // emit event emit UnlockedERC721(msg.sender, token, tokenId); } /// @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), "UniversalVaultV2: missing lock"); // attempt to notify delegate if (delegate.isContract()) { // check for sufficient gas require(gasleft() >= RAGEQUIT_GAS, "UniversalVaultV2: 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), "UniversalVaultV2: insufficient balance" ); // perform transfer TransferHelper.safeTransfer(token, to, amount); } function transferERC721( address token, address to, uint256 tokenId ) external override onlyOwner { // validate ownership require( IERC721(token).ownerOf(tokenId) == address(this), "UniversalVaultV2: vault not owner of nft" ); require( !_lockedERC721s[token].contains(tokenId), "NFT is locked. Unlock first." ); _vaultERC721s[token].remove(tokenId); if (_vaultERC721s[token].length() == 0) { _vaultERC721Types.remove(token); } // perform transfer IERC721(token).safeTransferFrom(address(this), to, tokenId); } /// @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); } }
[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"address","name":"from","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"bytes","name":"data","type":"bytes"}],"name":"ERC721Received","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"delegate","type":"address"},{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Locked","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"delegate","type":"address"},{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"LockedERC721","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"delegate","type":"address"},{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"bool","name":"notified","type":"bool"},{"indexed":false,"internalType":"string","name":"reason","type":"string"}],"name":"RageQuit","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"delegate","type":"address"},{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Unlocked","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"delegate","type":"address"},{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"UnlockedERC721","type":"event"},{"inputs":[],"name":"LOCK_ERC721_TYPEHASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"LOCK_TYPEHASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"RAGEQUIT_GAS","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"UNLOCK_ERC721_TYPEHASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"UNLOCK_TYPEHASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"VERSION","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"delegate","type":"address"},{"internalType":"address","name":"token","type":"address"}],"name":"calculateLockID","outputs":[{"internalType":"bytes32","name":"lockID","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"checkERC20Balances","outputs":[{"internalType":"bool","name":"validity","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"checkERC721Balances","outputs":[{"internalType":"bool","name":"validity","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"delegate","type":"address"}],"name":"getBalanceDelegated","outputs":[{"internalType":"uint256","name":"balance","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"getBalanceLocked","outputs":[{"internalType":"uint256","name":"balance","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getERC721InVaultAt","outputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getERC721LockedAt","outputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"getERC721LockedBalance","outputs":[{"internalType":"uint256","name":"balance","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getERC721TypeInVaultAt","outputs":[{"internalType":"address","name":"token","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getERC721TypeLockedAt","outputs":[{"internalType":"address","name":"token","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"getERC721VaultBalance","outputs":[{"internalType":"uint256","name":"balance","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getLockAt","outputs":[{"components":[{"internalType":"address","name":"delegate","type":"address"},{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"balance","type":"uint256"}],"internalType":"struct IUniversalVaultV2.LockData","name":"lockData","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getLockSetCount","outputs":[{"internalType":"uint256","name":"count","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getNonce","outputs":[{"internalType":"uint256","name":"nonce","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getNumERC721TypesInVault","outputs":[{"internalType":"uint256","name":"count","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getNumERC721TypesLocked","outputs":[{"internalType":"uint256","name":"count","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"eip712TypeHash","type":"bytes32"},{"internalType":"address","name":"delegate","type":"address"},{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"nonce","type":"uint256"}],"name":"getPermissionHash","outputs":[{"internalType":"bytes32","name":"permissionHash","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"eip712TypeHash","type":"bytes32"},{"internalType":"address","name":"delegate","type":"address"},{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"nonce","type":"uint256"}],"name":"getPermissionHashERC721","outputs":[{"internalType":"bytes32","name":"permissionHash","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"initializeLock","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"permissionHash","type":"bytes32"},{"internalType":"bytes","name":"signature","type":"bytes"}],"name":"isValidSignature","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes","name":"permission","type":"bytes"}],"name":"lock","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"permission","type":"bytes"}],"name":"lockERC721","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"nft","outputs":[{"internalType":"address","name":"nftAddress","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"address","name":"from","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"onERC721Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"ownerAddress","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"delegate","type":"address"},{"internalType":"address","name":"token","type":"address"}],"name":"rageQuit","outputs":[{"internalType":"bool","name":"notified","type":"bool"},{"internalType":"string","name":"error","type":"string"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferERC20","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"transferERC721","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferETH","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes","name":"permission","type":"bytes"}],"name":"unlock","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"permission","type":"bytes"}],"name":"unlockERC721","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]
v0.7.6+commit.7338295f
true
1,000
Default
false
MethodVaultV2
@openzeppelin/contracts/math/SafeMath.sol
0x6401e2ff943722e8583d0f7b99987e7b39f9cc75
Solidity
// 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; } }
[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"address","name":"from","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"bytes","name":"data","type":"bytes"}],"name":"ERC721Received","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"delegate","type":"address"},{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Locked","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"delegate","type":"address"},{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"LockedERC721","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"delegate","type":"address"},{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"bool","name":"notified","type":"bool"},{"indexed":false,"internalType":"string","name":"reason","type":"string"}],"name":"RageQuit","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"delegate","type":"address"},{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Unlocked","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"delegate","type":"address"},{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"UnlockedERC721","type":"event"},{"inputs":[],"name":"LOCK_ERC721_TYPEHASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"LOCK_TYPEHASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"RAGEQUIT_GAS","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"UNLOCK_ERC721_TYPEHASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"UNLOCK_TYPEHASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"VERSION","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"delegate","type":"address"},{"internalType":"address","name":"token","type":"address"}],"name":"calculateLockID","outputs":[{"internalType":"bytes32","name":"lockID","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"checkERC20Balances","outputs":[{"internalType":"bool","name":"validity","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"checkERC721Balances","outputs":[{"internalType":"bool","name":"validity","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"delegate","type":"address"}],"name":"getBalanceDelegated","outputs":[{"internalType":"uint256","name":"balance","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"getBalanceLocked","outputs":[{"internalType":"uint256","name":"balance","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getERC721InVaultAt","outputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getERC721LockedAt","outputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"getERC721LockedBalance","outputs":[{"internalType":"uint256","name":"balance","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getERC721TypeInVaultAt","outputs":[{"internalType":"address","name":"token","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getERC721TypeLockedAt","outputs":[{"internalType":"address","name":"token","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"getERC721VaultBalance","outputs":[{"internalType":"uint256","name":"balance","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getLockAt","outputs":[{"components":[{"internalType":"address","name":"delegate","type":"address"},{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"balance","type":"uint256"}],"internalType":"struct IUniversalVaultV2.LockData","name":"lockData","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getLockSetCount","outputs":[{"internalType":"uint256","name":"count","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getNonce","outputs":[{"internalType":"uint256","name":"nonce","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getNumERC721TypesInVault","outputs":[{"internalType":"uint256","name":"count","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getNumERC721TypesLocked","outputs":[{"internalType":"uint256","name":"count","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"eip712TypeHash","type":"bytes32"},{"internalType":"address","name":"delegate","type":"address"},{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"nonce","type":"uint256"}],"name":"getPermissionHash","outputs":[{"internalType":"bytes32","name":"permissionHash","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"eip712TypeHash","type":"bytes32"},{"internalType":"address","name":"delegate","type":"address"},{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"nonce","type":"uint256"}],"name":"getPermissionHashERC721","outputs":[{"internalType":"bytes32","name":"permissionHash","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"initializeLock","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"permissionHash","type":"bytes32"},{"internalType":"bytes","name":"signature","type":"bytes"}],"name":"isValidSignature","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes","name":"permission","type":"bytes"}],"name":"lock","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"permission","type":"bytes"}],"name":"lockERC721","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"nft","outputs":[{"internalType":"address","name":"nftAddress","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"address","name":"from","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"onERC721Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"ownerAddress","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"delegate","type":"address"},{"internalType":"address","name":"token","type":"address"}],"name":"rageQuit","outputs":[{"internalType":"bool","name":"notified","type":"bool"},{"internalType":"string","name":"error","type":"string"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferERC20","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"transferERC721","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferETH","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes","name":"permission","type":"bytes"}],"name":"unlock","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"permission","type":"bytes"}],"name":"unlockERC721","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]
v0.7.6+commit.7338295f
true
1,000
Default
false
MethodVaultV2
@openzeppelin/contracts/token/ERC721/ERC721.sol
0x6401e2ff943722e8583d0f7b99987e7b39f9cc75
Solidity
// SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; import "../../utils/Context.sol"; import "./IERC721.sol"; import "./IERC721Metadata.sol"; import "./IERC721Enumerable.sol"; import "./IERC721Receiver.sol"; import "../../introspection/ERC165.sol"; import "../../math/SafeMath.sol"; import "../../utils/Address.sol"; import "../../utils/EnumerableSet.sol"; import "../../utils/EnumerableMap.sol"; import "../../utils/Strings.sol"; /** * @title ERC721 Non-Fungible Token Standard basic implementation * @dev see https://eips.ethereum.org/EIPS/eip-721 */ contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Enumerable { using SafeMath for uint256; using Address for address; using EnumerableSet for EnumerableSet.UintSet; using EnumerableMap for EnumerableMap.UintToAddressMap; using Strings for uint256; // Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))` // which can be also obtained as `IERC721Receiver(0).onERC721Received.selector` bytes4 private constant _ERC721_RECEIVED = 0x150b7a02; // Mapping from holder address to their (enumerable) set of owned tokens mapping (address => EnumerableSet.UintSet) private _holderTokens; // Enumerable mapping from token ids to their owners EnumerableMap.UintToAddressMap private _tokenOwners; // Mapping from token ID to approved address mapping (uint256 => address) private _tokenApprovals; // Mapping from owner to operator approvals mapping (address => mapping (address => bool)) private _operatorApprovals; // Token name string private _name; // Token symbol string private _symbol; // Optional mapping for token URIs mapping (uint256 => string) private _tokenURIs; // Base URI string private _baseURI; /* * bytes4(keccak256('balanceOf(address)')) == 0x70a08231 * bytes4(keccak256('ownerOf(uint256)')) == 0x6352211e * bytes4(keccak256('approve(address,uint256)')) == 0x095ea7b3 * bytes4(keccak256('getApproved(uint256)')) == 0x081812fc * bytes4(keccak256('setApprovalForAll(address,bool)')) == 0xa22cb465 * bytes4(keccak256('isApprovedForAll(address,address)')) == 0xe985e9c5 * bytes4(keccak256('transferFrom(address,address,uint256)')) == 0x23b872dd * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) == 0x42842e0e * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) == 0xb88d4fde * * => 0x70a08231 ^ 0x6352211e ^ 0x095ea7b3 ^ 0x081812fc ^ * 0xa22cb465 ^ 0xe985e9c5 ^ 0x23b872dd ^ 0x42842e0e ^ 0xb88d4fde == 0x80ac58cd */ bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd; /* * bytes4(keccak256('name()')) == 0x06fdde03 * bytes4(keccak256('symbol()')) == 0x95d89b41 * bytes4(keccak256('tokenURI(uint256)')) == 0xc87b56dd * * => 0x06fdde03 ^ 0x95d89b41 ^ 0xc87b56dd == 0x5b5e139f */ bytes4 private constant _INTERFACE_ID_ERC721_METADATA = 0x5b5e139f; /* * bytes4(keccak256('totalSupply()')) == 0x18160ddd * bytes4(keccak256('tokenOfOwnerByIndex(address,uint256)')) == 0x2f745c59 * bytes4(keccak256('tokenByIndex(uint256)')) == 0x4f6ccce7 * * => 0x18160ddd ^ 0x2f745c59 ^ 0x4f6ccce7 == 0x780e9d63 */ bytes4 private constant _INTERFACE_ID_ERC721_ENUMERABLE = 0x780e9d63; /** * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection. */ constructor (string memory name_, string memory symbol_) public { _name = name_; _symbol = symbol_; // register the supported interfaces to conform to ERC721 via ERC165 _registerInterface(_INTERFACE_ID_ERC721); _registerInterface(_INTERFACE_ID_ERC721_METADATA); _registerInterface(_INTERFACE_ID_ERC721_ENUMERABLE); } /** * @dev See {IERC721-balanceOf}. */ function balanceOf(address owner) public view virtual override returns (uint256) { require(owner != address(0), "ERC721: balance query for the zero address"); return _holderTokens[owner].length(); } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view virtual override returns (address) { return _tokenOwners.get(tokenId, "ERC721: owner query for nonexistent token"); } /** * @dev See {IERC721Metadata-name}. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev See {IERC721Metadata-symbol}. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev See {IERC721Metadata-tokenURI}. */ function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token"); string memory _tokenURI = _tokenURIs[tokenId]; string memory base = baseURI(); // If there is no base URI, return the token URI. if (bytes(base).length == 0) { return _tokenURI; } // If both are set, concatenate the baseURI and tokenURI (via abi.encodePacked). if (bytes(_tokenURI).length > 0) { return string(abi.encodePacked(base, _tokenURI)); } // If there is a baseURI but no tokenURI, concatenate the tokenID to the baseURI. return string(abi.encodePacked(base, tokenId.toString())); } /** * @dev Returns the base URI set via {_setBaseURI}. This will be * automatically added as a prefix in {tokenURI} to each token's URI, or * to the token ID if no specific URI is set for that token ID. */ function baseURI() public view virtual returns (string memory) { return _baseURI; } /** * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}. */ function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) { return _holderTokens[owner].at(index); } /** * @dev See {IERC721Enumerable-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { // _tokenOwners are indexed by tokenIds, so .length() returns the number of tokenIds return _tokenOwners.length(); } /** * @dev See {IERC721Enumerable-tokenByIndex}. */ function tokenByIndex(uint256 index) public view virtual override returns (uint256) { (uint256 tokenId, ) = _tokenOwners.at(index); return tokenId; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public virtual override { address owner = ERC721.ownerOf(tokenId); require(to != owner, "ERC721: approval to current owner"); require(_msgSender() == owner || ERC721.isApprovedForAll(owner, _msgSender()), "ERC721: approve caller is not owner nor approved for all" ); _approve(to, tokenId); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view virtual override returns (address) { require(_exists(tokenId), "ERC721: approved query for nonexistent token"); return _tokenApprovals[tokenId]; } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public virtual override { require(operator != _msgSender(), "ERC721: approve to caller"); _operatorApprovals[_msgSender()][operator] = approved; emit ApprovalForAll(_msgSender(), operator, approved); } /** * @dev See {IERC721-isApprovedForAll}. */ function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) { return _operatorApprovals[owner][operator]; } /** * @dev See {IERC721-transferFrom}. */ function transferFrom(address from, address to, uint256 tokenId) public virtual override { //solhint-disable-next-line max-line-length require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _transfer(from, to, tokenId); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom(address from, address to, uint256 tokenId) public virtual override { safeTransferFrom(from, to, tokenId, ""); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory _data) public virtual override { require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _safeTransfer(from, to, tokenId, _data); } /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * `_data` is additional data, it has no specified format and it is sent in call to `to`. * * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g. * implement alternative mechanisms to perform token transfer, such as signature-based. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeTransfer(address from, address to, uint256 tokenId, bytes memory _data) internal virtual { _transfer(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Returns whether `tokenId` exists. * * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}. * * Tokens start existing when they are minted (`_mint`), * and stop existing when they are burned (`_burn`). */ function _exists(uint256 tokenId) internal view virtual returns (bool) { return _tokenOwners.contains(tokenId); } /** * @dev Returns whether `spender` is allowed to manage `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) { require(_exists(tokenId), "ERC721: operator query for nonexistent token"); address owner = ERC721.ownerOf(tokenId); return (spender == owner || getApproved(tokenId) == spender || ERC721.isApprovedForAll(owner, spender)); } /** * @dev Safely mints `tokenId` and transfers it to `to`. * * Requirements: d* * - `tokenId` must not exist. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeMint(address to, uint256 tokenId) internal virtual { _safeMint(to, tokenId, ""); } /** * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is * forwarded in {IERC721Receiver-onERC721Received} to contract recipients. */ function _safeMint(address to, uint256 tokenId, bytes memory _data) internal virtual { _mint(to, tokenId); require(_checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Mints `tokenId` and transfers it to `to`. * * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible * * Requirements: * * - `tokenId` must not exist. * - `to` cannot be the zero address. * * Emits a {Transfer} event. */ function _mint(address to, uint256 tokenId) internal virtual { require(to != address(0), "ERC721: mint to the zero address"); require(!_exists(tokenId), "ERC721: token already minted"); _beforeTokenTransfer(address(0), to, tokenId); _holderTokens[to].add(tokenId); _tokenOwners.set(tokenId, to); emit Transfer(address(0), to, tokenId); } /** * @dev Destroys `tokenId`. * The approval is cleared when the token is burned. * * Requirements: * * - `tokenId` must exist. * * Emits a {Transfer} event. */ function _burn(uint256 tokenId) internal virtual { address owner = ERC721.ownerOf(tokenId); // internal owner _beforeTokenTransfer(owner, address(0), tokenId); // Clear approvals _approve(address(0), tokenId); // Clear metadata (if any) if (bytes(_tokenURIs[tokenId]).length != 0) { delete _tokenURIs[tokenId]; } _holderTokens[owner].remove(tokenId); _tokenOwners.remove(tokenId); emit Transfer(owner, address(0), tokenId); } /** * @dev Transfers `tokenId` from `from` to `to`. * As opposed to {transferFrom}, this imposes no restrictions on msg.sender. * * Requirements: * * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * * Emits a {Transfer} event. */ function _transfer(address from, address to, uint256 tokenId) internal virtual { require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own"); // internal owner require(to != address(0), "ERC721: transfer to the zero address"); _beforeTokenTransfer(from, to, tokenId); // Clear approvals from the previous owner _approve(address(0), tokenId); _holderTokens[from].remove(tokenId); _holderTokens[to].add(tokenId); _tokenOwners.set(tokenId, to); emit Transfer(from, to, tokenId); } /** * @dev Sets `_tokenURI` as the tokenURI of `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual { require(_exists(tokenId), "ERC721Metadata: URI set of nonexistent token"); _tokenURIs[tokenId] = _tokenURI; } /** * @dev Internal function to set the base URI for all token IDs. It is * automatically added as a prefix to the value returned in {tokenURI}, * or to the token ID if {tokenURI} is empty. */ function _setBaseURI(string memory baseURI_) internal virtual { _baseURI = baseURI_; } /** * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address. * The call is not executed if the target address is not a contract. * * @param from address representing the previous owner of the given token ID * @param to target address that will receive the tokens * @param tokenId uint256 ID of the token to be transferred * @param _data bytes optional data to send along with the call * @return bool whether the call correctly returned the expected magic value */ function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory _data) private returns (bool) { if (!to.isContract()) { return true; } bytes memory returndata = to.functionCall(abi.encodeWithSelector( IERC721Receiver(to).onERC721Received.selector, _msgSender(), from, tokenId, _data ), "ERC721: transfer to non ERC721Receiver implementer"); bytes4 retval = abi.decode(returndata, (bytes4)); return (retval == _ERC721_RECEIVED); } /** * @dev Approve `to` to operate on `tokenId` * * Emits an {Approval} event. */ function _approve(address to, uint256 tokenId) internal virtual { _tokenApprovals[tokenId] = to; emit Approval(ERC721.ownerOf(tokenId), to, tokenId); // internal owner } /** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, ``from``'s `tokenId` will be burned. * - `from` cannot be the zero address. * - `to` cannot be the zero address. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual { } }
[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"address","name":"from","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"bytes","name":"data","type":"bytes"}],"name":"ERC721Received","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"delegate","type":"address"},{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Locked","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"delegate","type":"address"},{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"LockedERC721","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"delegate","type":"address"},{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"bool","name":"notified","type":"bool"},{"indexed":false,"internalType":"string","name":"reason","type":"string"}],"name":"RageQuit","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"delegate","type":"address"},{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Unlocked","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"delegate","type":"address"},{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"UnlockedERC721","type":"event"},{"inputs":[],"name":"LOCK_ERC721_TYPEHASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"LOCK_TYPEHASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"RAGEQUIT_GAS","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"UNLOCK_ERC721_TYPEHASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"UNLOCK_TYPEHASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"VERSION","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"delegate","type":"address"},{"internalType":"address","name":"token","type":"address"}],"name":"calculateLockID","outputs":[{"internalType":"bytes32","name":"lockID","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"checkERC20Balances","outputs":[{"internalType":"bool","name":"validity","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"checkERC721Balances","outputs":[{"internalType":"bool","name":"validity","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"delegate","type":"address"}],"name":"getBalanceDelegated","outputs":[{"internalType":"uint256","name":"balance","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"getBalanceLocked","outputs":[{"internalType":"uint256","name":"balance","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getERC721InVaultAt","outputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getERC721LockedAt","outputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"getERC721LockedBalance","outputs":[{"internalType":"uint256","name":"balance","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getERC721TypeInVaultAt","outputs":[{"internalType":"address","name":"token","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getERC721TypeLockedAt","outputs":[{"internalType":"address","name":"token","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"getERC721VaultBalance","outputs":[{"internalType":"uint256","name":"balance","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getLockAt","outputs":[{"components":[{"internalType":"address","name":"delegate","type":"address"},{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"balance","type":"uint256"}],"internalType":"struct IUniversalVaultV2.LockData","name":"lockData","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getLockSetCount","outputs":[{"internalType":"uint256","name":"count","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getNonce","outputs":[{"internalType":"uint256","name":"nonce","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getNumERC721TypesInVault","outputs":[{"internalType":"uint256","name":"count","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getNumERC721TypesLocked","outputs":[{"internalType":"uint256","name":"count","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"eip712TypeHash","type":"bytes32"},{"internalType":"address","name":"delegate","type":"address"},{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"nonce","type":"uint256"}],"name":"getPermissionHash","outputs":[{"internalType":"bytes32","name":"permissionHash","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"eip712TypeHash","type":"bytes32"},{"internalType":"address","name":"delegate","type":"address"},{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"nonce","type":"uint256"}],"name":"getPermissionHashERC721","outputs":[{"internalType":"bytes32","name":"permissionHash","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"initializeLock","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"permissionHash","type":"bytes32"},{"internalType":"bytes","name":"signature","type":"bytes"}],"name":"isValidSignature","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes","name":"permission","type":"bytes"}],"name":"lock","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"permission","type":"bytes"}],"name":"lockERC721","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"nft","outputs":[{"internalType":"address","name":"nftAddress","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"address","name":"from","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"onERC721Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"ownerAddress","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"delegate","type":"address"},{"internalType":"address","name":"token","type":"address"}],"name":"rageQuit","outputs":[{"internalType":"bool","name":"notified","type":"bool"},{"internalType":"string","name":"error","type":"string"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferERC20","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"transferERC721","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferETH","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes","name":"permission","type":"bytes"}],"name":"unlock","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"permission","type":"bytes"}],"name":"unlockERC721","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]
v0.7.6+commit.7338295f
true
1,000
Default
false

DISL

The DISL dataset features a collection of 514506 unique Solidity files that have been deployed to Ethereum mainnet. It caters to the need for a large and diverse dataset of real-world smart contracts. DISL serves as a resource for developing machine learning systems and for benchmarking software engineering tools designed for smart contracts.

Content

  • the raw subset has full contracts source code and it's not deduplicated, it has 3,298,271 smart contracts
  • the decomposed subset contains Solidity files, it is derived from raw, it is deduplicated using Jaccard similarity with a threshold of 0.9, it has 514,506 Solidity files
  • the cuttoff date is January 15, 2024, approx at block 19010000

If you use DISL, please cite the following tech report:

@techreport{disl2403.16861,
 title = {DISL: Fueling Research with A Large Dataset of Solidity Smart Contracts},
 year = {2024},
 author = {Gabriele Morello and Mojtaba Eshghie and Sofia Bobadilla and Martin Monperrus},
 url = {http://arxiv.org/pdf/2403.16861},
 number = {2403.16861},
 institution = {arXiv},
}
  • Curated by: Gabriele Morello

Instructions to explore the dataset

from datasets import load_dataset

# Load the raw dataset
dataset = load_dataset("ASSERT-KTH/DISL", "raw")

# OR

# Load the decomposed dataset
dataset = load_dataset("ASSERT-KTH/DISL", "decomposed")

# number of rows and columns
num_rows = len(dataset["train"])
num_columns = len(dataset["train"].column_names)

# random row
import random
random_row = random.choice(dataset["train"])

# random source code
random_sc = random.choice(dataset["train"])['source_code']
print(random_sc)
Downloads last month
596