Address Contract Partially Verified
Address
0x09d05293264eDF390CD3cbd8cc86532207AE30b0
Balance
0 ETH
Nonce
1
Code Size
15637 bytes
Creator
0x46814340...50E4 at tx 0x13ad2386...cfe5f5
Indexed Transactions
0
Contract Bytecode
15637 bytes
0x6080604052600436106103345760003560e01c8063843620ca116101b0578063b88d4fde116100ec578063e23ce48411610095578063e985e9c51161006f578063e985e9c514610953578063f2fde38b1461099c578063f3d6785d146109bc578063f3fef3a3146109cf57600080fd5b8063e23ce484146108d9578063e43bd63d14610906578063e5d6d4c21461093357600080fd5b8063db7fd408116100c6578063db7fd40814610886578063dbbb71e714610899578063dd2ee7fd146108ac57600080fd5b8063b88d4fde14610819578063c87b56dd14610839578063c882dad71461085957600080fd5b806392b3f1e711610159578063a22cb46511610133578063a22cb465146107ae578063a64307a1146107ce578063ac426b0414610672578063acf268041461080657600080fd5b806392b3f1e71461073a57806395d89b41146107675780639c2f82cf1461077c57600080fd5b806389820e981161018a57806389820e98146106f45780638da5cb5b146107075780638ea981171461072757600080fd5b8063843620ca146106875780638462ff87146106b4578063897ed07f146106e157600080fd5b80633270228b1161027f57806357a8202f116102285780636dcc71ef116102025780636dcc71ef1461061257806370a082311461062557806375b072f11461065257806379da7d4f1461067257600080fd5b806357a8202f146105af5780636352211e146105dc57806365f63a47146105fc57600080fd5b80633de8d0ea116102595780633de8d0ea1461054f5780633e7ad6201461057c57806342842e0e1461058f57600080fd5b80633270228b1461043d57806334478e48146105225780633da84ec9146103f857600080fd5b806309e76d05116102e157806317470482116102bb578063174704821461049f57806323b872dd146104cc5780633040c58b146104ec57600080fd5b806309e76d051461043d5780630a00909714610452578063100dc62e1461047257600080fd5b8063081812fc11610312578063081812fc146103c0578063084d299f146103f8578063095ea7b31461041b57600080fd5b806301ffc9a714610339578063068ed12e1461036e57806306fdde031461039e575b600080fd5b34801561034557600080fd5b5061035961035436600461341a565b6109e2565b60405190151581526020015b60405180910390f35b34801561037a57600080fd5b5061035961038936600461343e565b60026020526000908152604090205460ff1681565b3480156103aa57600080fd5b506103b3610ac7565b60405161036591906134cd565b3480156103cc57600080fd5b506103e06103db36600461343e565b610b55565b6040516001600160a01b039091168152602001610365565b34801561040457600080fd5b5061040d600081565b604051908152602001610365565b34801561042757600080fd5b5061043b6104363660046134f5565b610c00565b005b34801561044957600080fd5b5061040d600181565b34801561045e57600080fd5b506001546103e0906001600160a01b031681565b34801561047e57600080fd5b5061040d61048d36600461343e565b60046020526000908152604090205481565b3480156104ab57600080fd5b5061040d6104ba36600461343e565b600e6020526000908152604090205481565b3480156104d857600080fd5b5061043b6104e7366004613521565b610d50565b3480156104f857600080fd5b506103e061050736600461343e565b6013602052600090815260409020546001600160a01b031681565b34801561052e57600080fd5b5061040d61053d36600461343e565b60106020526000908152604090205481565b34801561055b57600080fd5b5061040d61056a36600461343e565b600a6020526000908152604090205481565b61043b61058a366004613562565b610dd7565b34801561059b57600080fd5b5061043b6105aa366004613521565b610f0a565b3480156105bb57600080fd5b5061040d6105ca36600461343e565b600c6020526000908152604090205481565b3480156105e857600080fd5b506103e06105f736600461343e565b610f25565b34801561060857600080fd5b5061040d60005481565b61043b61062036600461363d565b610fb0565b34801561063157600080fd5b5061040d6106403660046136d3565b60146020526000908152604090205481565b34801561065e57600080fd5b506103e061066d3660046136f0565b6112f6565b34801561067e57600080fd5b5061040d600281565b34801561069357600080fd5b5061040d6106a236600461343e565b600b6020526000908152604090205481565b3480156106c057600080fd5b5061040d6106cf36600461343e565b60056020526000908152604090205481565b61043b6106ef36600461363d565b61132e565b61043b610702366004613727565b6115ee565b34801561071357600080fd5b506017546103e0906001600160a01b031681565b61043b6107353660046136d3565b611724565b34801561074657600080fd5b5061040d61075536600461343e565b60076020526000908152604090205481565b34801561077357600080fd5b506103b36117b8565b34801561078857600080fd5b506001546103599074010000000000000000000000000000000000000000900460ff1681565b3480156107ba57600080fd5b5061043b6107c9366004613742565b6117c5565b3480156107da57600080fd5b5061040d6107e9366004613777565b600f60209081526000928352604080842090915290825290205481565b61043b610814366004613835565b6117d4565b34801561082557600080fd5b5061043b610834366004613929565b6119fe565b34801561084557600080fd5b506103b361085436600461343e565b611a86565b34801561086557600080fd5b5061040d61087436600461343e565b600d6020526000908152604090205481565b61043b610894366004613995565b611d0d565b61043b6108a73660046139dc565b611d75565b3480156108b857600080fd5b5061040d6108c736600461343e565b60096020526000908152604090205481565b3480156108e557600080fd5b5061040d6108f436600461343e565b60066020526000908152604090205481565b34801561091257600080fd5b5061092661092136600461343e565b611e9f565b60405161036591906139ff565b34801561093f57600080fd5b506103b361094e36600461343e565b611f0b565b34801561095f57600080fd5b5061035961096e366004613a4c565b6001600160a01b03918216600090815260166020908152604080832093909416825291909152205460ff1690565b3480156109a857600080fd5b5061043b6109b73660046136d3565b611f24565b61043b6109ca366004613995565b612064565b61043b6109dd3660046134f5565b6121bf565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f80ac58cd000000000000000000000000000000000000000000000000000000001480610a7557507fffffffff0000000000000000000000000000000000000000000000000000000082167f5b5e139f00000000000000000000000000000000000000000000000000000000145b80610ac157507f01ffc9a7000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000008316145b92915050565b60118054610ad490613a7a565b80601f0160208091040260200160405190810160405280929190818152602001828054610b0090613a7a565b8015610b4d5780601f10610b2257610100808354040283529160200191610b4d565b820191906000526020600020905b815481529060010190602001808311610b3057829003601f168201915b505050505081565b6000818152601360205260408120546001600160a01b0316610be45760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860448201527f697374656e7420746f6b656e000000000000000000000000000000000000000060648201526084015b60405180910390fd5b506000908152601560205260409020546001600160a01b031690565b6000610c0b82610f25565b9050806001600160a01b0316836001600160a01b03161415610c955760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e6560448201527f72000000000000000000000000000000000000000000000000000000000000006064820152608401610bdb565b336001600160a01b0382161480610ccf57506001600160a01b038116600090815260166020908152604080832033845290915290205460ff165b610d415760405162461bcd60e51b815260206004820152603860248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760448201527f6e6572206e6f7220617070726f76656420666f7220616c6c00000000000000006064820152608401610bdb565b610d4b838361231c565b505050565b610d5a33826123a2565b610dcc5760405162461bcd60e51b815260206004820152603160248201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f60448201527f776e6572206e6f7220617070726f7665640000000000000000000000000000006064820152608401610bdb565b610d4b8383836124aa565b6017546001600160a01b03163314610e315760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610bdb565b60015474010000000000000000000000000000000000000000900460ff1680610e68575060008381526002602052604090205460ff165b610eb45760405162461bcd60e51b815260206004820152600a60248201527f4e6f7420706175736564000000000000000000000000000000000000000000006044820152606401610bdb565b6000838152600860205260409020805482919084908110610ed757610ed7613ace565b9060005260206000200160006101000a8154816001600160a01b0302191690836001600160a01b03160217905550505050565b610d4b838383604051806020016040528060008152506119fe565b6000818152601360205260408120546001600160a01b031680610ac15760405162461bcd60e51b815260206004820152602960248201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460448201527f656e7420746f6b656e00000000000000000000000000000000000000000000006064820152608401610bdb565b306001600160a01b0316638da5cb5b6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610fee573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110129190613afd565b6001600160a01b0316336001600160a01b0316148061105057506001546001600160a01b03161580159061105057506001546001600160a01b031633145b61109c5760405162461bcd60e51b815260206004820152600e60248201527f4e6f7420617574686f72697a65640000000000000000000000000000000000006044820152606401610bdb565b8051806110eb5760405162461bcd60e51b815260206004820152601560248201527f4e6f20746f6b656e204944732070726f766964656400000000000000000000006044820152606401610bdb565b6000806000805b848110156112ee5785818151811061110c5761110c613ace565b60200260200101519350600084116111665760405162461bcd60e51b815260206004820152601060248201527f496e76616c696420746f6b656e204944000000000000000000000000000000006044820152606401610bdb565b6000848152600e602052604090205492506001016002831415611188576110f2565b60018314156111d95760405162461bcd60e51b815260206004820152600e60248201527f416c7265616479206f70656e65640000000000000000000000000000000000006044820152606401610bdb565b6000848152601060205260409020549150816112375760405162461bcd60e51b815260206004820152601260248201527f426f7820646f6573206e6f7420657869737400000000000000000000000000006044820152606401610bdb565b6000828152600a60205260409020544210156112955760405162461bcd60e51b815260206004820152600c60248201527f4e6f742074696d652079657400000000000000000000000000000000000000006044820152606401610bdb565b6000848152600e6020908152604080832060029055601390915280822054905186926001600160a01b039092169133917f15fe15b3df9f0dc255aa3a71b6d3686b777b161f466b8687d08dbd5b2decc0d29190a46110f2565b505050505050565b6008602052816000526040600020818154811061131257600080fd5b6000918252602090912001546001600160a01b03169150829050565b306001600160a01b0316638da5cb5b6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561136c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113909190613afd565b6001600160a01b0316336001600160a01b031614806113ce57506001546001600160a01b0316158015906113ce57506001546001600160a01b031633145b61141a5760405162461bcd60e51b815260206004820152600e60248201527f4e6f7420617574686f72697a65640000000000000000000000000000000000006044820152606401610bdb565b8051806114695760405162461bcd60e51b815260206004820152601560248201527f4e6f20746f6b656e204944732070726f766964656400000000000000000000006044820152606401610bdb565b6000805b828110156115e85783818151811061148757611487613ace565b60200260200101519150600082116114e15760405162461bcd60e51b815260206004820152601060248201527f496e76616c696420746f6b656e204944000000000000000000000000000000006044820152606401610bdb565b60008281526010602052604090205461153c5760405162461bcd60e51b815260206004820152601260248201527f426f7820646f6573206e6f7420657869737400000000000000000000000000006044820152606401610bdb565b6000828152600e602052604090205460021461159a5760405162461bcd60e51b815260206004820152601860248201527f4e6f74207965742070656e64696e672064656c697665727900000000000000006044820152606401610bdb565b6000828152600e6020908152604080832060019055600d9091528082204290555183917f076ee234681125279e2cfc540cc3442961385c988bd343b4081105999f39f5ea91a260010161146d565b50505050565b306001600160a01b0316638da5cb5b6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561162c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116509190613afd565b6001600160a01b0316336001600160a01b0316148061168e57506001546001600160a01b03161580159061168e57506001546001600160a01b031633145b6116da5760405162461bcd60e51b815260206004820152600e60248201527f4e6f7420617574686f72697a65640000000000000000000000000000000000006044820152606401610bdb565b6001805491151574010000000000000000000000000000000000000000027fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff909216919091179055565b6017546001600160a01b0316331461177e5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610bdb565b600180547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b0392909216919091179055565b60128054610ad490613a7a565b6117d033838361269a565b5050565b6017546001600160a01b0316331461182e5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610bdb565b60015474010000000000000000000000000000000000000000900460ff16156118995760405162461bcd60e51b815260206004820152601460248201527f4e657720626f78657320617265207061757365640000000000000000000000006044820152606401610bdb565b8383101561190f5760405162461bcd60e51b815260206004820152602160248201527f4f70656e2074696d65206d7573742062652061667465722073616c652074696d60448201527f65000000000000000000000000000000000000000000000000000000000000006064820152608401610bdb565b600080549061191f826001613b49565b60008381526005602052604090205490915061193c816001613b49565b6000838152600460205260408120805490919061195a908490613b49565b9091555061196a90508982613b49565b600083815260056020908152604080832093909355600681528282208c9055600781528282208b9055600381529190208b516119a8928d01906132e3565b50600082815260086020908152604090912086516119c892880190613367565b5050600081815260096020908152604080832098909855600a815287822096909655600b90955294842091909155505055505050565b611a0833836123a2565b611a7a5760405162461bcd60e51b815260206004820152603160248201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f60448201527f776e6572206e6f7220617070726f7665640000000000000000000000000000006064820152608401610bdb565b6115e884848484612787565b6000818152601360205260409020546060906001600160a01b0316611b135760405162461bcd60e51b815260206004820152602f60248201527f4552433732314d657461646174613a2055524920717565727920666f72206e6f60448201527f6e6578697374656e7420746f6b656e00000000000000000000000000000000006064820152608401610bdb565b600082815260106020908152604080832054808452600390925282208054919291611b3d90613a7a565b80601f0160208091040260200160405190810160405280929190818152602001828054611b6990613a7a565b8015611bb65780601f10611b8b57610100808354040283529160200191611bb6565b820191906000526020600020905b815481529060010190602001808311611b9957829003601f168201915b505050505090506000815111611c0e5760405162461bcd60e51b815260206004820152600b60248201527f555249206e6f74207365740000000000000000000000000000000000000000006044820152606401610bdb565b6000848152600e6020526040902054606081611c5e575060408051808201909152600681527f636c6f73656400000000000000000000000000000000000000000000000000006020820152611ce0565b6001821415611ca1575060408051808201909152600681527f6f70656e656400000000000000000000000000000000000000000000000000006020820152611ce0565b6002821415611ce0575060408051808201909152600781527f70656e64696e670000000000000000000000000000000000000000000000000060208201525b8281604051602001611cf3929190613b61565b604051602081830303815290604052945050505050919050565b6000828152600760205260409020543414611d6a5760405162461bcd60e51b815260206004820152601560248201527f496e636f727265637420616d6f756e742073656e7400000000000000000000006044820152606401610bdb565b6117d0338383612810565b306001600160a01b0316638da5cb5b6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611db3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611dd79190613afd565b6001600160a01b0316336001600160a01b03161480611e1557506001546001600160a01b031615801590611e1557506001546001600160a01b031633145b611e615760405162461bcd60e51b815260206004820152600e60248201527f4e6f7420617574686f72697a65640000000000000000000000000000000000006044820152606401610bdb565b60009182526002602052604090912080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016911515919091179055565b600081815260086020908152604091829020805483518184028101840190945280845260609392830182828015611eff57602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311611ee1575b50505050509050919050565b60036020526000908152604090208054610ad490613a7a565b6017546001600160a01b03163314611f7e5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610bdb565b6001600160a01b038116611ffa5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201527f64647265737300000000000000000000000000000000000000000000000000006064820152608401610bdb565b601780546001600160a01b038381167fffffffffffffffffffffffff0000000000000000000000000000000000000000831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b306001600160a01b0316638da5cb5b6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156120a2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120c69190613afd565b6001600160a01b0316336001600160a01b0316148061210457506001546001600160a01b03161580159061210457506001546001600160a01b031633145b6121505760405162461bcd60e51b815260206004820152600e60248201527f4e6f7420617574686f72697a65640000000000000000000000000000000000006044820152606401610bdb565b600082116121a05760405162461bcd60e51b815260206004820152601260248201527f426f7820646f6573206e6f7420657869737400000000000000000000000000006044820152606401610bdb565b60008281526003602090815260409091208251610d4b928401906132e3565b6017546001600160a01b031633146122195760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610bdb565b6002601854141561226c5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610bdb565b60026018556040516000906001600160a01b0384169083908381818185875af1925050503d80600081146122bc576040519150601f19603f3d011682016040523d82523d6000602084013e6122c1565b606091505b50509050806123125760405162461bcd60e51b815260206004820152600f60248201527f5472616e73666572206661696c656400000000000000000000000000000000006044820152606401610bdb565b5050600160185550565b600081815260156020526040902080547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b038416908117909155819061236982610f25565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6000818152601360205260408120546001600160a01b031661242c5760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860448201527f697374656e7420746f6b656e00000000000000000000000000000000000000006064820152608401610bdb565b600061243783610f25565b9050806001600160a01b0316846001600160a01b031614806124725750836001600160a01b031661246784610b55565b6001600160a01b0316145b806124a257506001600160a01b0380821660009081526016602090815260408083209388168352929052205460ff165b949350505050565b826001600160a01b03166124bd82610f25565b6001600160a01b0316146125395760405162461bcd60e51b815260206004820152602560248201527f4552433732313a207472616e736665722066726f6d20696e636f72726563742060448201527f6f776e65720000000000000000000000000000000000000000000000000000006064820152608401610bdb565b6001600160a01b0382166125b45760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f2061646460448201527f72657373000000000000000000000000000000000000000000000000000000006064820152608401610bdb565b6125bf838383612dc1565b6125ca60008261231c565b6001600160a01b03831660009081526014602052604081208054600192906125f3908490613c0c565b90915550506001600160a01b0382166000908152601460205260408120805460019290612621908490613b49565b909155505060008181526013602052604080822080547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b0386811691821790925591518493918716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b816001600160a01b0316836001600160a01b031614156126fc5760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c6572000000000000006044820152606401610bdb565b6001600160a01b0383811660008181526016602090815260408083209487168084529482529182902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a3505050565b6127928484846124aa565b61279e84848484612f23565b6115e85760405162461bcd60e51b815260206004820152603260248201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560448201527f63656976657220696d706c656d656e74657200000000000000000000000000006064820152608401610bdb565b600260185414156128635760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610bdb565b6002601855816128db5760405162461bcd60e51b815260206004820152602d60248201527f76616c69646174654d696e743a20626f784964206d757374206265206772656160448201527f746572207468616e207a65726f000000000000000000000000000000000000006064820152608401610bdb565b60015474010000000000000000000000000000000000000000900460ff16158015612915575060008281526002602052604090205460ff16155b6129615760405162461bcd60e51b815260206004820152601160248201527f4d696e74696e67206973207061757365640000000000000000000000000000006044820152606401610bdb565b60006002826040516129739190613c23565b602060405180830381855afa158015612990573d6000803e3d6000fd5b5050506040513d601f19601f820116820180604052508101906129b39190613c3f565b6000818152600c602052604090205490915015612a125760405162461bcd60e51b815260206004820152601160248201527f4175746820616c726561647920757365640000000000000000000000000000006044820152606401610bdb565b60008381526006602052604090205480612a6e5760405162461bcd60e51b815260206004820152601660248201527f4e6f206d6f726520666f72207468697320726f756e64000000000000000000006044820152606401610bdb565b6000848152600560205260408120548290612a8a906001613b49565b612a949190613c0c565b6000868152600f602090815260408083206001600160a01b038b16845282528083205489845260049092529091205491925090811080612ae1575060008681526005602052604090205481115b612b2d5760405162461bcd60e51b815260206004820152601f60248201527f4c696d6974656420746f206f6e65206d696e74207065722061646472657373006044820152606401610bdb565b6000868152600860209081526040808320805482518185028101850190935280835284938493929190830182828015612b8f57602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311612b71575b505083519394506000925050505b81811015612cb75760006001600160a01b0316838281518110612bc257612bc2613ace565b60200260200101516001600160a01b03161415612be25760009450612cb7565b828181518110612bf457612bf4613ace565b60200260200101516001600160a01b031663a49615dd8d8d8a8e6040518563ffffffff1660e01b8152600401612c2d9493929190613c58565b602060405180830381865afa158015612c4a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c6e9190613c3f565b935060010183612c7d57612b9d565b6002841415612c8f5760009450612cb7565b600184148015612ca85750612ca5816001613b49565b82145b15612cb257600194505b612b9d565b5083612d1b5760008a815260096020526040902054421015612d1b5760405162461bcd60e51b815260206004820152601a60248201527f506c6561736520776169742074696c6c2073616c652074696d650000000000006044820152606401610bdb565b612d258b876130df565b60008a8152600660205260408120805460019290612d44908490613c0c565b90915550506000888152600c60209081526040808320899055888352601082528083208d90558c8352600f82528083206001600160a01b038f1680855292528083208990555188927f0f6798a560793a54c3bcfe86a93cde1e73087d944c0ea20544137d412139688591a350506001601855505050505050505050565b6001600160a01b038316612dd457505050565b6000818152600e60205260409020546002811415612e345760405162461bcd60e51b815260206004820152601060248201527f50656e64696e672064656c6976657279000000000000000000000000000000006044820152606401610bdb565b6001600160a01b038316612e9257600181146115e85760405162461bcd60e51b815260206004820152601960248201527f43616e6e6f74206275726e20756e2d6f70656e656420426f78000000000000006044820152606401610bdb565b60018114156115e857600082815260106020908152604080832054808452600b835281842054868552600d909352922054612ecd9190613b49565b421015612f1c5760405162461bcd60e51b815260206004820152601c60248201527f4e65656420746f206c6574207468696e677320636f6f6c20646f776e000000006044820152606401610bdb565b5050505050565b60006001600160a01b0384163b156130d4576040517f150b7a020000000000000000000000000000000000000000000000000000000081526001600160a01b0385169063150b7a0290612f80903390899088908890600401613c90565b6020604051808303816000875af1925050508015612fd9575060408051601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0168201909252612fd691810190613cc2565b60015b613089573d808015613007576040519150601f19603f3d011682016040523d82523d6000602084013e61300c565b606091505b5080516130815760405162461bcd60e51b815260206004820152603260248201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560448201527f63656976657220696d706c656d656e74657200000000000000000000000000006064820152608401610bdb565b805181602001fd5b7fffffffff00000000000000000000000000000000000000000000000000000000167f150b7a02000000000000000000000000000000000000000000000000000000001490506124a2565b506001949350505050565b6117d08282604051806020016040528060008152506130fe838361317d565b61310b6000848484612f23565b610d4b5760405162461bcd60e51b815260206004820152603260248201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560448201527f63656976657220696d706c656d656e74657200000000000000000000000000006064820152608401610bdb565b6001600160a01b0382166131d35760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f20616464726573736044820152606401610bdb565b6000818152601360205260409020546001600160a01b0316156132385760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e746564000000006044820152606401610bdb565b61324460008383612dc1565b6001600160a01b038216600090815260146020526040812080546001929061326d908490613b49565b909155505060008181526013602052604080822080547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b03861690811790915590518392907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b8280546132ef90613a7a565b90600052602060002090601f0160209004810192826133115760008555613357565b82601f1061332a57805160ff1916838001178555613357565b82800160010185558215613357579182015b8281111561335757825182559160200191906001019061333c565b506133639291506133d4565b5090565b828054828255906000526020600020908101928215613357579160200282015b8281111561335757825182547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b03909116178255602090920191600190910190613387565b5b8082111561336357600081556001016133d5565b7fffffffff000000000000000000000000000000000000000000000000000000008116811461341757600080fd5b50565b60006020828403121561342c57600080fd5b8135613437816133e9565b9392505050565b60006020828403121561345057600080fd5b5035919050565b60005b8381101561347257818101518382015260200161345a565b838111156115e85750506000910152565b6000815180845261349b816020860160208601613457565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b6020815260006134376020830184613483565b6001600160a01b038116811461341757600080fd5b6000806040838503121561350857600080fd5b8235613513816134e0565b946020939093013593505050565b60008060006060848603121561353657600080fd5b8335613541816134e0565b92506020840135613551816134e0565b929592945050506040919091013590565b60008060006060848603121561357757600080fd5b83359250602084013591506040840135613590816134e0565b809150509250925092565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016810167ffffffffffffffff811182821017156136115761361161359b565b604052919050565b600067ffffffffffffffff8211156136335761363361359b565b5060051b60200190565b6000602080838503121561365057600080fd5b823567ffffffffffffffff81111561366757600080fd5b8301601f8101851361367857600080fd5b803561368b61368682613619565b6135ca565b81815260059190911b820183019083810190878311156136aa57600080fd5b928401925b828410156136c8578335825292840192908401906136af565b979650505050505050565b6000602082840312156136e557600080fd5b8135613437816134e0565b6000806040838503121561370357600080fd5b50508035926020909101359150565b8035801515811461372257600080fd5b919050565b60006020828403121561373957600080fd5b61343782613712565b6000806040838503121561375557600080fd5b8235613760816134e0565b915061376e60208401613712565b90509250929050565b6000806040838503121561378a57600080fd5b82359150602083013561379c816134e0565b809150509250929050565b600082601f8301126137b857600080fd5b813567ffffffffffffffff8111156137d2576137d261359b565b61380360207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f840116016135ca565b81815284602083860101111561381857600080fd5b816020850160208301376000918101602001919091529392505050565b600080600080600080600060e0888a03121561385057600080fd5b873567ffffffffffffffff8082111561386857600080fd5b6138748b838c016137a7565b985060209150818a0135975060408a0135965060608a0135955060808a0135945060a08a0135818111156138a757600080fd5b8a019050601f81018b136138ba57600080fd5b80356138c861368682613619565b81815260059190911b8201830190838101908d8311156138e757600080fd5b928401925b8284101561390e5783356138ff816134e0565b825292840192908401906138ec565b809650505050505060c0880135905092959891949750929550565b6000806000806080858703121561393f57600080fd5b843561394a816134e0565b9350602085013561395a816134e0565b925060408501359150606085013567ffffffffffffffff81111561397d57600080fd5b613989878288016137a7565b91505092959194509250565b600080604083850312156139a857600080fd5b82359150602083013567ffffffffffffffff8111156139c657600080fd5b6139d2858286016137a7565b9150509250929050565b600080604083850312156139ef57600080fd5b8235915061376e60208401613712565b6020808252825182820181905260009190848201906040850190845b81811015613a405783516001600160a01b031683529284019291840191600101613a1b565b50909695505050505050565b60008060408385031215613a5f57600080fd5b8235613a6a816134e0565b9150602083013561379c816134e0565b600181811c90821680613a8e57607f821691505b60208210811415613ac8577f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b50919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b600060208284031215613b0f57600080fd5b8151613437816134e0565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60008219821115613b5c57613b5c613b1a565b500190565b7f697066733a2f2f00000000000000000000000000000000000000000000000000815260008351613b99816007850160208801613457565b7f2f000000000000000000000000000000000000000000000000000000000000006007918401918201528351613bd6816008840160208801613457565b7f2e6a736f6e00000000000000000000000000000000000000000000000000000060089290910191820152600d01949350505050565b600082821015613c1e57613c1e613b1a565b500390565b60008251613c35818460208701613457565b9190910192915050565b600060208284031215613c5157600080fd5b5051919050565b6001600160a01b0385168152836020820152826040820152608060608201526000613c866080830184613483565b9695505050505050565b60006001600160a01b03808716835280861660208401525083604083015260806060830152613c866080830184613483565b600060208284031215613cd457600080fd5b8151613437816133e956fea2646970667358221220166cd9efbd3b9e5aa87ddf173d2f043358af28d4e4490f322d9319d7d4300e9a64736f6c634300080b0033
Verified Source Code Partial Match
Compiler: v0.8.11+commit.d7f03943
EVM: london
Optimization: Yes (10000 runs)
BoredBoxNFT.sol 346 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.11;
// +--------------------------------------------------+
// /| /|
// / | / |
// *--+-----------------------------------------------* |
// | | | |
// | | | |
// | | | |
// | | ██████╗ ██████╗ ██████╗ ███████╗██████╗ | |
// | | ██╔══██╗██╔═══██╗██╔══██╗██╔════╝██╔══██╗ | |
// | | ██████╔╝██║ ██║██████╔╝█████╗ ██║ ██║ | |
// | | ██╔══██╗██║ ██║██╔══██╗██╔══╝ ██║ ██║ | |
// | | ██████╔╝╚██████╔╝██║ ██║███████╗██████╔╝ | |
// | | ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚═════╝ | |
// | | | |
// | | | |
// | | | |
// | +-----------------------------------------------+--+
// | / | /
// |/ |/
// *--------------------------------------------------*
import { BoredBoxStorage } from "@boredbox-solidity-contracts/bored-box-storage/contracts/BoredBoxStorage.sol";
import { IBoredBoxNFT_Functions } from "@boredbox-solidity-contracts/interface-bored-box-nft/contracts/IBoredBoxNFT.sol";
import { IValidateMint } from "@boredbox-solidity-contracts/interface-validate-mint/contracts/IValidateMint.sol";
import { Ownable } from "@boredbox-solidity-contracts/ownable/contracts/Ownable.sol";
import { ReentrancyGuard } from "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import { ERC721 } from "../contracts/token/ERC721/ERC721.sol";
/// @title Tracks BoredBox token ownership and coordinates minting
/// @author S0AndS0
/// @custom:link https://boredbox.io/
contract BoredBoxNFT is IBoredBoxNFT_Functions, BoredBoxStorage, ERC721, Ownable, ReentrancyGuard {
uint256 public constant VALIDATE_STATUS__NA = 0;
uint256 public constant VALIDATE_STATUS__PASS = 1;
uint256 public constant VALIDATE_STATUS__FAIL = 2;
/// Emitted after validateMint checks pass
event Mint(address indexed to, uint256 indexed tokenId);
/// Emitted after assets are fully distributed
// @param tokenId pointer into `token__owner`, `token__opened_timestamp`, `token__status`, `token__generation`
event Opened(uint256 indexed tokenId);
/// Emitted when client requests a Box to be opened
// @param from address of `msg.sender`
// @param to address of `token__owner[tokenId]`
// @param tokenId pointer into storage; `token__owner`, `token__opened_timestamp`, `token__status`, `token__generation`
event RequestOpen(address indexed from, address indexed to, uint256 indexed tokenId);
modifier onlyAuthorized() {
require(
msg.sender == this.owner() || (coordinator != address(0) && msg.sender == coordinator),
"Not authorized"
);
_;
}
/// Called via `new BoredBoxNFT(/* ... */)`
/// @param name_ NFT name to store in `name`
/// @param symbol_ NFT symbol to pass to `ERC721` parent contract
/// @param coordinator_ Address to store in `coordinator`
/// @param uri_root string pointing to IPFS directory of JSON metadata files
/// @param quantity Amount of tokens available for first generation
/// @param price Exact `{ value: _price_ }` required by `mint()` function
/// @param sale_time The `block.timestamp` to allow general requests to `mint()` function
/// @param ref_validators List of addresses referencing `ValidateMint` contracts
/// @param cool_down Time to add to current `block.timestamp` after `token__status` is set to `TOKEN_STATUS__OPENED`
/// @custom:throw "Open time must be after sale time"
constructor(
address owner_,
string memory name_,
string memory symbol_,
address coordinator_,
string memory uri_root,
uint256 quantity,
uint256 price,
uint256 sale_time,
uint256 open_time,
address[] memory ref_validators,
uint256 cool_down
) ERC721(name_, symbol_) Ownable(owner_) {
require(open_time >= sale_time, "Open time must be after sale time");
coordinator = coordinator_;
box__uri_root[1] = uri_root;
box__lower_bound[1] = 1;
box__upper_bound[1] = quantity;
box__quantity[1] = quantity;
box__price[1] = price;
box__sale_time[1] = sale_time;
box__cool_down[1] = cool_down;
box__open_time[1] = open_time;
box__validators[1] = ref_validators;
current_box = 1;
}
/// @dev See {IBoredBoxNFT_Functions-mint}
function mint(uint256 boxId, bytes memory auth) external payable {
require(msg.value == box__price[boxId], "Incorrect amount sent");
return _mintBox(msg.sender, boxId, auth);
}
/// Mutates `token__status` storage if checks pass
/// @dev See {IBoredBoxNFT_Functions-setPending}
function setPending(uint256[] memory tokenIds) external payable onlyAuthorized {
uint256 length = tokenIds.length;
require(length > 0, "No token IDs provided");
uint256 tokenId;
uint256 current__token__status;
uint256 boxId;
for (uint256 i; i < length; ) {
tokenId = tokenIds[i];
require(tokenId > 0, "Invalid token ID");
unchecked {
++i;
}
current__token__status = token__status[tokenId];
if (current__token__status == TOKEN_STATUS__PENDING) {
continue;
}
require(current__token__status != TOKEN_STATUS__OPENED, "Already opened");
boxId = token__generation[tokenId];
require(boxId > 0, "Box does not exist");
require(block.timestamp >= box__open_time[boxId], "Not time yet");
token__status[tokenId] = TOKEN_STATUS__PENDING;
emit RequestOpen(msg.sender, token__owner[tokenId], tokenId);
}
}
/// @dev See {IBoredBoxNFT_Functions-box__allValidators}
function box__allValidators(uint256 boxId) external view virtual returns (address[] memory) {
return box__validators[boxId];
}
/// @dev See {IBoredBoxNFT_Functions-setOpened}
function setOpened(uint256[] memory tokenIds) external payable onlyAuthorized {
uint256 length = tokenIds.length;
require(length > 0, "No token IDs provided");
uint256 tokenId;
for (uint256 i; i < length; ) {
tokenId = tokenIds[i];
require(tokenId > 0, "Invalid token ID");
require(token__generation[tokenId] > 0, "Box does not exist");
require(token__status[tokenId] == TOKEN_STATUS__PENDING, "Not yet pending delivery");
token__status[tokenId] = 1;
token__opened_timestamp[tokenId] = block.timestamp;
emit Opened(tokenId);
unchecked {
++i;
}
}
}
/// @dev See {IBoredBoxNFT_Functions-setOpened}
function setBoxURI(uint256 boxId, string memory uri_root) external payable onlyAuthorized {
require(boxId > 0, "Box does not exist");
box__uri_root[boxId] = uri_root;
}
/// @dev See {IBoredBoxNFT_Functions-setIsPaused}
function setIsPaused(uint256 boxId, bool is_paused) external payable onlyAuthorized {
box__is_paused[boxId] = is_paused;
}
/// @dev See {IBoredBoxNFT_Functions-setAllPaused}
function setAllPaused(bool is_paused) external payable onlyAuthorized {
all_paused = is_paused;
}
/// @dev See {IBoredBoxNFT_Functions-setAllPaused}
function setCoordinator(address coordinator_) external payable onlyOwner {
coordinator = coordinator_;
}
/// @dev See {IBoredBoxNFT_Functions-setValidator}
function setValidator(
uint256 boxId,
uint256 index,
address ref_validator
) external payable onlyOwner {
require(all_paused || box__is_paused[boxId], "Not paused");
box__validators[boxId][index] = ref_validator;
}
/// @dev See {IBoredBoxNFT_Functions-newBox}
function newBox(
string memory uri_root,
uint256 quantity,
uint256 price,
uint256 sale_time,
uint256 open_time,
address[] memory ref_validators,
uint256 cool_down
) external payable onlyOwner {
require(!all_paused, "New boxes are paused");
require(open_time >= sale_time, "Open time must be after sale time");
uint256 last_boxId = current_box;
uint256 next_boxId = 1 + last_boxId;
uint256 last_upper_bound = box__upper_bound[last_boxId];
box__lower_bound[next_boxId] += 1 + last_upper_bound;
box__upper_bound[next_boxId] = last_upper_bound + quantity;
box__quantity[next_boxId] = quantity;
box__price[next_boxId] = price;
box__uri_root[next_boxId] = uri_root;
box__validators[next_boxId] = ref_validators;
box__sale_time[next_boxId] = sale_time;
box__open_time[next_boxId] = open_time;
box__cool_down[next_boxId] = cool_down;
current_box = next_boxId;
}
/// @dev See {IBoredBoxNFT_Functions-withdraw}
function withdraw(address payable to, uint256 amount) external payable onlyOwner nonReentrant {
(bool success, ) = to.call{ value: amount }("");
require(success, "Transfer failed");
}
/// @dev See {IERC721Metadata-tokenURI}
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
require(token__owner[tokenId] != address(0), "ERC721Metadata: URI query for nonexistent token");
uint256 boxId = token__generation[tokenId];
string memory uri_root = box__uri_root[boxId];
require(bytes(uri_root).length > 0, "URI not set");
uint256 current__token__status = token__status[tokenId];
string memory uri_path;
if (current__token__status == TOKEN_STATUS__CLOSED) {
uri_path = "closed";
} else if (current__token__status == TOKEN_STATUS__OPENED) {
uri_path = "opened";
} else if (current__token__status == TOKEN_STATUS__PENDING) {
uri_path = "pending";
}
return string(abi.encodePacked("ipfs://", uri_root, "/", uri_path, ".json"));
}
/// @dev See {ERC721-_beforeTokenTransfer}
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual override {
if (from == address(0)) {
return;
}
uint256 current__token__status = token__status[tokenId];
require(current__token__status != TOKEN_STATUS__PENDING, "Pending delivery");
if (to == address(0)) {
require(current__token__status == TOKEN_STATUS__OPENED, "Cannot burn un-opened Box");
return;
}
if (current__token__status == TOKEN_STATUS__OPENED) {
uint256 boxId = token__generation[tokenId];
require(
block.timestamp >= token__opened_timestamp[tokenId] + box__cool_down[boxId],
"Need to let things cool down"
);
}
}
function _mintBox(
address to,
uint256 boxId,
bytes memory auth
) internal nonReentrant {
require(boxId > 0, "validateMint: boxId must be greater than zero");
require(!all_paused && !box__is_paused[boxId], "Minting is paused");
bytes32 hash_of_auth = sha256(auth);
require(hash__auth_token[hash_of_auth] == 0, "Auth already used");
uint256 quantity = box__quantity[boxId];
require(quantity > 0, "No more for this round");
uint256 tokenId = (box__upper_bound[boxId] + 1) - quantity;
uint256 original_owner = token__original_owner[boxId][to];
require(
original_owner < box__lower_bound[boxId] || original_owner > box__upper_bound[boxId],
"Limited to one mint per address"
);
bool all_validators_passed;
uint256 validate_status;
address[] memory _ref_validators = box__validators[boxId];
uint256 length = _ref_validators.length;
for (uint256 i; i < length; ) {
if (_ref_validators[i] == address(0)) {
all_validators_passed = false;
break;
}
validate_status = IValidateMint(_ref_validators[i]).validate(to, boxId, tokenId, auth);
unchecked {
++i;
}
if (validate_status == VALIDATE_STATUS__NA) {
continue;
} else if (validate_status == VALIDATE_STATUS__FAIL) {
all_validators_passed = false;
break;
} else if (validate_status == VALIDATE_STATUS__PASS && length == i + 1) {
all_validators_passed = true;
}
}
if (!all_validators_passed) {
require(box__sale_time[boxId] <= block.timestamp, "Please wait till sale time");
}
super._safeMint(to, tokenId);
box__quantity[boxId] -= 1;
hash__auth_token[hash_of_auth] = tokenId;
token__generation[tokenId] = boxId;
token__original_owner[boxId][to] = tokenId;
emit Mint(to, tokenId);
}
}
ERC721.sol 427 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC721/ERC721.sol)
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
import "@openzeppelin/contracts/utils/introspection/ERC165.sol";
/**
* @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including
* the Metadata extension, but not including the Enumerable extension, which is available separately as
* {ERC721Enumerable}.
*/
contract ERC721 is ERC165, IERC721, IERC721Metadata {
using Address for address;
using Strings for uint256;
// Collection name
string public name;
// Collection symbol
string public symbol;
// Mapping from token ID to owner address
mapping(uint256 => address) public token__owner;
// Mapping owner address to token count
mapping(address => uint256) public balanceOf;
// Mapping from token ID to approved address
mapping(uint256 => address) private _tokenApprovals;
// Mapping from owner to operator approvals
mapping(address => mapping(address => bool)) private _operatorApprovals;
/**
* @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
*/
constructor(string memory name_, string memory symbol_) {
name = name_;
symbol = symbol_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return
interfaceId == type(IERC721).interfaceId ||
interfaceId == type(IERC721Metadata).interfaceId ||
super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721-ownerOf}.
*/
function ownerOf(uint256 tokenId) public view virtual override returns (address) {
address owner = token__owner[tokenId];
require(owner != address(0), "ERC721: owner query for nonexistent token");
return owner;
}
/**
* @dev See {IERC721Metadata-tokenURI}.
*/
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
string memory baseURI = _baseURI();
return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : "";
}
/**
* @dev Base URI for computing {tokenURI}. If set, the resulting URI for each
* token will be the concatenation of the `baseURI` and the `tokenId`. Empty
* by default, can be overriden in child contracts.
*/
function _baseURI() internal view virtual returns (string memory) {
return "";
}
/**
* @dev See {IERC721-approve}.
*/
function approve(address to, uint256 tokenId) public virtual override {
address owner = ERC721.ownerOf(tokenId);
require(to != owner, "ERC721: approval to current owner");
require(
msg.sender == owner || isApprovedForAll(owner, msg.sender),
"ERC721: approve caller is not owner nor approved for all"
);
_approve(to, tokenId);
}
/**
* @dev See {IERC721-getApproved}.
*/
function getApproved(uint256 tokenId) public view virtual override returns (address) {
require(_exists(tokenId), "ERC721: approved query for nonexistent token");
return _tokenApprovals[tokenId];
}
/**
* @dev See {IERC721-setApprovalForAll}.
*/
function setApprovalForAll(address operator, bool approved) public virtual override {
_setApprovalForAll(msg.sender, 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(msg.sender, 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(msg.sender, 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 token__owner[tokenId] != address(0);
}
/**
* @dev Returns whether `spender` is allowed to manage `tokenId`.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {
require(_exists(tokenId), "ERC721: operator query for nonexistent token");
address owner = ERC721.ownerOf(tokenId);
return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender));
}
/**
* @dev Safely mints `tokenId` and transfers it to `to`.
*
* Requirements:
*
* - `tokenId` must not exist.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeMint(address to, uint256 tokenId) internal virtual {
_safeMint(to, tokenId, "");
}
/**
* @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
* forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
*/
function _safeMint(
address to,
uint256 tokenId,
bytes memory _data
) internal virtual {
_mint(to, tokenId);
require(
_checkOnERC721Received(address(0), to, tokenId, _data),
"ERC721: transfer to non ERC721Receiver implementer"
);
}
/**
* @dev Mints `tokenId` and transfers it to `to`.
*
* WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
*
* Requirements:
*
* - `tokenId` must not exist.
* - `to` cannot be the zero address.
*
* Emits a {Transfer} event.
*/
function _mint(address to, uint256 tokenId) internal virtual {
require(to != address(0), "ERC721: mint to the zero address");
require(!_exists(tokenId), "ERC721: token already minted");
_beforeTokenTransfer(address(0), to, tokenId);
balanceOf[to] += 1;
token__owner[tokenId] = to;
emit Transfer(address(0), to, tokenId);
_afterTokenTransfer(address(0), to, tokenId);
}
/**
* @dev Destroys `tokenId`.
* The approval is cleared when the token is burned.
*
* Requirements:
*
* - `tokenId` must exist.
*
* Emits a {Transfer} event.
*/
function _burn(uint256 tokenId) internal virtual {
address owner = ERC721.ownerOf(tokenId);
_beforeTokenTransfer(owner, address(0), tokenId);
// Clear approvals
_approve(address(0), tokenId);
balanceOf[owner] -= 1;
delete token__owner[tokenId];
emit Transfer(owner, address(0), tokenId);
_afterTokenTransfer(owner, address(0), tokenId);
}
/**
* @dev Transfers `tokenId` from `from` to `to`.
* As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
*
* Emits a {Transfer} event.
*/
function _transfer(
address from,
address to,
uint256 tokenId
) internal virtual {
require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer from incorrect owner");
require(to != address(0), "ERC721: transfer to the zero address");
_beforeTokenTransfer(from, to, tokenId);
// Clear approvals from the previous owner
_approve(address(0), tokenId);
balanceOf[from] -= 1;
balanceOf[to] += 1;
token__owner[tokenId] = to;
emit Transfer(from, to, tokenId);
_afterTokenTransfer(from, to, tokenId);
}
/**
* @dev Approve `to` to operate on `tokenId`
*
* Emits a {Approval} event.
*/
function _approve(address to, uint256 tokenId) internal virtual {
_tokenApprovals[tokenId] = to;
emit Approval(ERC721.ownerOf(tokenId), to, tokenId);
}
/**
* @dev Approve `operator` to operate on all of `owner` tokens
*
* Emits a {ApprovalForAll} event.
*/
function _setApprovalForAll(
address owner,
address operator,
bool approved
) internal virtual {
require(owner != operator, "ERC721: approve to caller");
_operatorApprovals[owner][operator] = approved;
emit ApprovalForAll(owner, operator, approved);
}
/**
* @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.
* The call is not executed if the target address is not a contract.
*
* @param from address representing the previous owner of the given token ID
* @param to target address that will receive the tokens
* @param tokenId uint256 ID of the token to be transferred
* @param _data bytes optional data to send along with the call
* @return bool whether the call correctly returned the expected magic value
*/
function _checkOnERC721Received(
address from,
address to,
uint256 tokenId,
bytes memory _data
) private returns (bool) {
if (to.isContract()) {
try IERC721Receiver(to).onERC721Received(msg.sender, from, tokenId, _data) returns (bytes4 retval) {
return retval == IERC721Receiver.onERC721Received.selector;
} catch (bytes memory reason) {
if (reason.length == 0) {
revert("ERC721: transfer to non ERC721Receiver implementer");
} else {
assembly {
revert(add(32, reason), mload(reason))
}
}
}
} else {
return true;
}
}
/**
* @dev Hook that is called before any token transfer. This includes minting
* and burning.
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
* transferred to `to`.
* - When `from` is zero, `tokenId` will be minted for `to`.
* - When `to` is zero, ``from``'s `tokenId` will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual {}
/**
* @dev Hook that is called after any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _afterTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual {}
}
Address.sol 222 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
Strings.sol 67 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Strings.sol)
pragma solidity ^0.8.0;
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
// Inspired by OraclizeAPI's implementation - MIT licence
// https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol
if (value == 0) {
return "0";
}
uint256 temp = value;
uint256 digits;
while (temp != 0) {
digits++;
temp /= 10;
}
bytes memory buffer = new bytes(digits);
while (value != 0) {
digits -= 1;
buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
value /= 10;
}
return string(buffer);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
if (value == 0) {
return "0x00";
}
uint256 temp = value;
uint256 length = 0;
while (temp != 0) {
length++;
temp >>= 8;
}
return toHexString(value, length);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _HEX_SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
}
IERC721.sol 143 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC721/IERC721.sol)
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC721 compliant contract.
*/
interface IERC721 is IERC165 {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes calldata data
) external;
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address from,
address to,
uint256 tokenId
) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function approve(address to, uint256 tokenId) external;
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the caller.
*
* Emits an {ApprovalForAll} event.
*/
function setApprovalForAll(address operator, bool _approved) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/
function isApprovedForAll(address owner, address operator) external view returns (bool);
}
ReentrancyGuard.sol 63 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol)
pragma solidity ^0.8.0;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
// On the first call to nonReentrant, _notEntered will be true
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
_;
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
}
ERC165.sol 29 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)
pragma solidity ^0.8.0;
import "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
IERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
IERC721Receiver.sol 27 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC721/IERC721Receiver.sol)
pragma solidity ^0.8.0;
/**
* @title ERC721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC721 asset contracts.
*/
interface IERC721Receiver {
/**
* @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
* by `operator` from `from`, this function is called.
*
* It must return its Solidity selector to confirm the token transfer.
* If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
*
* The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.
*/
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}
Ownable.sol 38 lines
// SPDX-License-Identifier: MIT
// Inspired by OpenZeppelin Contracts v4.4.1 (access/Ownable.sol)
pragma solidity ^0.8.0;
import { IOwnable_Functions } from "./interfaces/IOwnable.sol";
abstract contract Ownable is IOwnable_Functions {
address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor(address owner_) {
owner = owner_ == address(0) ? msg.sender : owner_;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(owner == msg.sender, "Ownable: caller is not the owner");
_;
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) external virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
address oldOwner = owner;
owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
IERC721Metadata.sol 27 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol)
pragma solidity ^0.8.0;
import "../IERC721.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional metadata extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Metadata is IERC721 {
/**
* @dev Returns the token collection name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the token collection symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
*/
function tokenURI(uint256 tokenId) external view returns (string memory);
}
IOwnable.sol 12 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.11;
interface IOwnable_Variables {
function owner() external view returns (address);
}
interface IOwnable_Functions {
function transferOwnership(address newOwner) external;
}
interface IOwnable is IOwnable_Functions, IOwnable_Variables {}
BoredBoxStorage.sol 61 lines
// SPDX-License-Identifier: MIT
// vim: textwidth=119
pragma solidity 0.8.11;
/// Define additional data storage for BoredBoxNFT
abstract contract BoredBoxStorage {
uint256 public constant TOKEN_STATUS__CLOSED = 0;
uint256 public constant TOKEN_STATUS__OPENED = 1;
uint256 public constant TOKEN_STATUS__PENDING = 2;
// TODO: rename to something like `box__current_generation`
uint256 public current_box;
// Authorized to preform certain actions
address public coordinator;
bool public all_paused;
// Mapping boxId to is paused state
mapping(uint256 => bool) public box__is_paused;
// Mapping boxId to URI IPFS root
mapping(uint256 => string) public box__uri_root;
// Mapping boxId to tokenId bounds
mapping(uint256 => uint256) public box__lower_bound;
mapping(uint256 => uint256) public box__upper_bound;
// Mapping boxId to quantity
mapping(uint256 => uint256) public box__quantity;
// Mapping boxId to price
mapping(uint256 => uint256) public box__price;
// Mapping boxId to array of Validate contract references
mapping(uint256 => address[]) public box__validators;
// Mapping boxId to open sale
mapping(uint256 => uint256) public box__sale_time;
// Mapping boxId to open time
mapping(uint256 => uint256) public box__open_time;
// Mapping boxId to cool down after mint
mapping(uint256 => uint256) public box__cool_down;
// Mapping hash of auth to tokenId
mapping(bytes32 => uint256) public hash__auth_token;
// Mapping tokenId to opened timestamp
mapping(uint256 => uint256) public token__opened_timestamp;
// Mapping from tokenId to TokenStatus_{Closed,Opened,Pending} states
mapping(uint256 => uint256) public token__status;
// Mapping boxId to owner to tokenId
mapping(uint256 => mapping(address => uint256)) public token__original_owner;
// Mapping from tokenId to boxId
mapping(uint256 => uint256) public token__generation;
}
IBoredBoxNFT.sol 126 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.11;
import { IBoredBoxStorage } from "@boredbox-solidity-contracts/bored-box-storage/contracts/interfaces/IBoredBoxStorage.sol";
import { IOwnable } from "@boredbox-solidity-contracts/ownable/contracts/interfaces/IOwnable.sol";
import { IERC721Metadata } from "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol";
/* Function definitions */
interface IBoredBoxNFT_Functions {
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
/// Attempt to mint new token for `current_box` generation
/// @dev Sets `boxId` to `current_box` before passing execution to `_mintBox()` function
/// @param auth Forwarded to any `ValidateMint` contract references set at `box__validators[boxId]`
/// @custom:throw "Incorrect amount sent"
function mint(
uint256 boxId,
bytes memory auth
) external payable;
/// Bulk request array of `tokenIds` to have assets delivered
/// @dev See {IBoredBoxNFT_Functions-open}
/// @custom:throw "No token IDs provided"
/// @custom:throw "Not authorized" if `msg.sender` is not contract owner
/// @custom:throw "Invalid token ID" if `tokenId` is not greater than `0`
/// @custom:throw "Not time yet" if `block.timestamp` is less than `box__open_time[boxId]`
/// @custom:throw "Already opened"
/// @custom:throw "Pending delivery"
/// @custom:throw "Box does not exist"
function setPending(uint256[] memory tokenIds) external payable;
/// Attempt to set `token__status` and `token__opened_timestamp` storage
/// @dev See {IBoredBoxNFT_Functions-setOpened}
/// @custom:throw "No token IDs provided"
/// @custom:throw "Not authorized"
/// @custom:throw "Invalid token ID"
/// @custom:throw "Box does not exist"
/// @custom:throw "Not yet pending delivery"
/// @custom:emit Opened
/// @custom:emit PermanentURI
function setOpened(uint256[] memory tokenIds) external payable;
/// Set `box__uri_root` for given `tokenId` to `uri_root` value
/// @custom:throw "Not authorized" if `msg.sender` is not contract owner
/// @custom:throw "Box does not exist"
function setBoxURI(uint256 boxId, string memory uri_root) external payable;
/// Attempt to set `all__paused` storage
/// @param is_paused Value to assign to storage
/// @custom:throw "Not authorized"
function setAllPaused(bool is_paused) external payable;
/// Attempt to set `box__is_paused` storage
/// @custom:throw "Not authorized"
function setIsPaused(uint256 boxId, bool is_paused) external payable;
/// Overwrite `coordinator` address
/// @custom:throw "Ownable: caller is not the owner"
function setCoordinator(address coordinator_) external payable;
/// Insert reference address to validat-mint contract
/// @param boxId Generation to insert data within `box__validators` mapping
/// @param index Where in array of `box__validators[boxId]` to set reference
/// @param ref_validator Address for ValidateMint contract
/// @custom:throw "Ownable: caller is not the owner"
/// @dev See {IValidateMint}
function setValidator(
uint256 boxId,
uint256 index,
address ref_validator
) external payable;
/// @param uri_root String pointing to IPFS directory of JSON metadata files
/// @param quantity Amount of tokens available for first generation
/// @param price Exact `{ value: _price_ }` required by `mint()` function
/// @param sale_time The `block.timestamp` to allow general requests to `mint()` function
/// @param open_time The `block.timestamp` to allow `open` requests
/// @param ref_validators List of addresses referencing `ValidateMint` contracts
/// @param cool_down Add time to `block.timestamp` to prevent `transferFrom` after opening
/// @custom:throw "Not authorized"
/// @custom:throw "New boxes are paused"
/// @custom:throw "Open time must be after sale time"
function newBox(
string memory uri_root,
uint256 quantity,
uint256 price,
uint256 sale_time,
uint256 open_time,
address[] memory ref_validators,
uint256 cool_down
) external payable;
/// Helper function to return Array of all validation contract addresses for `boxId`
/// @param boxId Generation key to get array from `box__validators` storage
function box__allValidators(uint256 boxId) external view returns (address[] memory);
/// Send amount of Ether from `this.balance` to some address
/// @custom:throw "Ownable: caller is not the owner"
/// @custom:throw "Transfer failed"
function withdraw(address payable to, uint256 amount) external payable;
}
///
interface IBoredBoxNFT is IBoredBoxNFT_Functions, IBoredBoxStorage, IOwnable, IERC721Metadata {
/* From ERC721 */
// function balanceOf(address owner) external view returns (uint256 balance);
// function ownerOf(uint256 tokenId) external view returns (address);
// function transferFrom(address from, address to, uint256 tokenId) external;
// @dev See {IERC721Metadata-tokenURI}.
// function tokenURI(uint256 tokenId) external view returns (string memory);
/// Attempt to retrieve `name` from storage
/// @return Name for given `boxId` generation
function name() external view returns (string memory);
/* Function definitions from @openzeppelin/contracts/access/Ownable.sol */
// function owner() external view returns (address);
// function transferOwnership(address newOwner) external;
/* Variable getters from contracts/tokens/ERC721/ERC721.sol */
function token__owner(uint256) external view returns (address);
}
IValidateMint.sol 21 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.11;
/// Completely optional contract that customizes mint requirements
interface IValidateMint {
/// Throws `revert` or `require` error message to halt execution
/// Returns 0 VALIDATE_STATUS__NA
/// Returns 1 VALIDATE_STATUS__PASS
/// Returns 2 VALIDATE_STATUS__FAIL
/// It is up to caller to figure out what to do with returned `bool`
/// @param to Address that will receive NFT if operation is valid
/// @param boxId Generation key to possibly use internally or by checking calling contract strage
/// @param tokenId Specific token ID that needs to be minted
/// @param auth Optional extra data to require for validation process
function validate(
address to,
uint256 boxId,
uint256 tokenId,
bytes memory auth
) external view returns (uint256 validate_status);
}
IBoredBoxStorage.sol 57 lines
// SPDX-License-Identifier: MIT
// vim: textwidth=119
pragma solidity 0.8.11;
/* Variable getters */
interface IBoredBoxStorage {
function current_box() external view returns (uint256);
function coordinator() external view returns (address);
function all_paused() external view returns (bool);
/// Get paused state for given `boxId`
function box__is_paused(uint256) external view returns (bool);
/// Get latest URI root/hash for given `boxId`
function box__uri_root(uint256) external view returns (string memory);
/// Get first token ID allowed to be minted for given `boxId`
function box__lower_bound(uint256) external view returns (uint256);
/// Get last token ID allowed to be minted for given `boxId`
function box__upper_bound(uint256) external view returns (uint256);
/// Get remaining quantity of tokens for given `boxId`
function box__quantity(uint256) external view returns (uint256);
/// Get price for given `boxId`
function box__price(uint256) external view returns (uint256);
/// Get address to Validate contract for given `boxId` and array index
function box__validators(uint256, uint256) external view returns (address);
/// Get `block.timestamp` given `boxId` generation allows tokens to be sold
function box__sale_time(uint256) external view returns (uint256);
/// Get `block.timestamp` given `boxId` generation allows tokens to be opened
function box__open_time(uint256) external view returns (uint256);
/// Get amount of time added to `block.timestamp` for `boxId` when token is opened
function box__cool_down(uint256) external view returns (uint256);
/// Get token ID for given hash of auth
function hash__auth_token(bytes32) external view returns (uint256);
/// Get `block.timestamp` a given `tokenId` was opened
function token__opened_timestamp(uint256) external view returns (uint256);
/// Get _TokenStatus_ value for given `tokenId`
function token__status(uint256) external view returns (uint256);
/// Get `boxId` for given `tokenId`
function token__generation(uint256) external view returns (uint256);
/// Get `tokenId` for given `boxId` and owner
function token__original_owner(uint256, address) external view returns (uint256);
}
Read Contract
TOKEN_STATUS__CLOSED 0x3da84ec9 → uint256
TOKEN_STATUS__OPENED 0x09e76d05 → uint256
TOKEN_STATUS__PENDING 0x79da7d4f → uint256
VALIDATE_STATUS__FAIL 0xac426b04 → uint256
VALIDATE_STATUS__NA 0x084d299f → uint256
VALIDATE_STATUS__PASS 0x3270228b → uint256
all_paused 0x9c2f82cf → bool
balanceOf 0x70a08231 → uint256
box__allValidators 0xe43bd63d → address[]
box__cool_down 0x843620ca → uint256
box__is_paused 0x068ed12e → bool
box__lower_bound 0x100dc62e → uint256
box__open_time 0x3de8d0ea → uint256
box__price 0x92b3f1e7 → uint256
box__quantity 0xe23ce484 → uint256
box__sale_time 0xdd2ee7fd → uint256
box__upper_bound 0x8462ff87 → uint256
box__uri_root 0xe5d6d4c2 → string
box__validators 0x75b072f1 → address
coordinator 0x0a009097 → address
current_box 0x65f63a47 → uint256
getApproved 0x081812fc → address
hash__auth_token 0x57a8202f → uint256
isApprovedForAll 0xe985e9c5 → bool
name 0x06fdde03 → string
owner 0x8da5cb5b → address
ownerOf 0x6352211e → address
supportsInterface 0x01ffc9a7 → bool
symbol 0x95d89b41 → string
tokenURI 0xc87b56dd → string
token__generation 0x34478e48 → uint256
token__opened_timestamp 0xc882dad7 → uint256
token__original_owner 0xa64307a1 → uint256
token__owner 0x3040c58b → address
token__status 0x17470482 → uint256
Write Contract 16 functions
These functions modify contract state and require a wallet transaction to execute.
approve 0x095ea7b3
address to
uint256 tokenId
mint 0xdb7fd408
uint256 boxId
bytes auth
newBox 0xacf26804
string uri_root
uint256 quantity
uint256 price
uint256 sale_time
uint256 open_time
address[] ref_validators
uint256 cool_down
safeTransferFrom 0x42842e0e
address from
address to
uint256 tokenId
safeTransferFrom 0xb88d4fde
address from
address to
uint256 tokenId
bytes _data
setAllPaused 0x89820e98
bool is_paused
setApprovalForAll 0xa22cb465
address operator
bool approved
setBoxURI 0xf3d6785d
uint256 boxId
string uri_root
setCoordinator 0x8ea98117
address coordinator_
setIsPaused 0xdbbb71e7
uint256 boxId
bool is_paused
setOpened 0x897ed07f
uint256[] tokenIds
setPending 0x6dcc71ef
uint256[] tokenIds
setValidator 0x3e7ad620
uint256 boxId
uint256 index
address ref_validator
transferFrom 0x23b872dd
address from
address to
uint256 tokenId
transferOwnership 0xf2fde38b
address newOwner
withdraw 0xf3fef3a3
address to
uint256 amount
Recent Transactions
No transactions found for this address