Address Contract Partially Verified
Address
0xB20217bf3d89667Fa15907971866acD6CcD570C8
Balance
0 ETH
Nonce
1
Code Size
10528 bytes
Creator
0x00d6E103...515B at tx 0xceafa7fd...f65cb4
Indexed Transactions
0
Contract Bytecode
10528 bytes
0x608060405234801561001057600080fd5b50600436106102115760003560e01c80636352211e11610125578063bcd4ddf7116100ad578063c87b56dd1161007c578063c87b56dd14610473578063cea93fc314610486578063cf456ae71461048e578063e985e9c5146104a1578063f46eccc4146104b457610211565b8063bcd4ddf714610420578063bf56ee2614610433578063c1d022cf1461043b578063c1e037281461044e57610211565b806395d89b41116100f457806395d89b41146103cc578063a1cfb5ed146103d4578063a22cb465146103e7578063a6f9dae1146103fa578063b88d4fde1461040d57610211565b80636352211e146103965780636c0360eb146103a957806370a08231146103b1578063893d20e8146103c457610211565b806327c8ee26116101a857806342842e0e1161017757806342842e0e146103375780634db1be941461034a5780634efbce0a1461035d5780634f6ccce71461037057806355f804b31461038357610211565b806327c8ee26146102dc57806327ed628b146102ef5780632f745c591461030257806336ffbc771461031557610211565b80630c4192cf116101e45780630c4192cf146102895780631703b06c1461029e57806318160ddd146102c157806323b872dd146102c957610211565b806301ffc9a71461021657806306fdde031461023f578063081812fc14610254578063095ea7b314610274575b600080fd5b610229610224366004611f98565b6104c7565b60405161023691906121ec565b60405180910390f35b6102476104ea565b60405161023691906121f7565b610267610262366004612002565b61057c565b6040516102369190612165565b610287610282366004611f23565b6105c8565b005b61029161064e565b60405161023691906126cc565b6102b16102ac366004612002565b610654565b6040516102369493929190612720565b610291610719565b6102876102d7366004611e36565b61072a565b6102876102ea366004612088565b61075b565b6102296102fd366004611f4c565b6107c5565b610291610310366004611f23565b6109cc565b610328610323366004612002565b6109f7565b604051610236939291906121b6565b610287610345366004611e36565b610b34565b61028761035836600461201a565b610b4f565b61028761036b3660046120aa565b610be4565b61029161037e366004612002565b610c36565b610287610391366004611fd0565b610c4c565b6102676103a4366004612002565b610c8d565b610247610cb5565b6102916103bf366004611dea565b610cc4565b610267610d0d565b610247610d1c565b6102876103e2366004612002565b610d2b565b6102876103f5366004611ee9565b610d73565b610287610408366004611dea565b610e0b565b61028761041b366004611e71565b610e91565b61028761042e3660046120aa565b610ec3565b610267610f6b565b610287610449366004611dea565b610f7a565b61046161045c366004612002565b610fc6565b604051610236969594939291906126d5565b610247610481366004612002565b6110e7565b61026761116d565b61028761049c366004611ee9565b61117c565b6102296104af366004611e04565b6111d1565b6102296104c2366004611dea565b6111ff565b6001600160e01b0319811660009081526020819052604090205460ff165b919050565b6060600e80546104f9906127fc565b80601f0160208091040260200160405190810160405280929190818152602001828054610525906127fc565b80156105725780601f1061054757610100808354040283529160200191610572565b820191906000526020600020905b81548152906001019060200180831161055557829003601f168201915b5050505050905090565b600061058782611214565b6105ac5760405162461bcd60e51b81526004016105a390612531565b60405180910390fd5b506000908152600760205260409020546001600160a01b031690565b60006105d382610c8d565b9050806001600160a01b0316836001600160a01b031614156106075760405162461bcd60e51b81526004016105a39061263a565b336001600160a01b0382161480610623575061062381336111d1565b61063f5760405162461bcd60e51b81526004016105a390612413565b6106498383611221565b505050565b600d5481565b600a60205260009081526040902080546001820180546001600160401b0380841694600160401b8504821694600160801b9004909116929091610696906127fc565b80601f01602080910402602001604051908101604052809291908181526020018280546106c2906127fc565b801561070f5780601f106106e45761010080835404028352916020019161070f565b820191906000526020600020905b8154815290600101906020018083116106f257829003601f168201915b5050505050905084565b6000610725600561128f565b905090565b610734338261129a565b6107505760405162461bcd60e51b81526004016105a39061267b565b610649838383611317565b3360009081526002602052604090205460ff16151560011461078f5760405162461bcd60e51b81526004016105a39061257d565b6000918252600b6020526040909120600101805463ffffffff909216600160601b0263ffffffff60601b19909216919091179055565b3360009081526002602052604081205460ff1615156001146107f95760405162461bcd60e51b81526004016105a39061257d565b63ffffffff84166000908152600a60205260409020546001600160401b03600160401b8204811691161161083f5760405162461bcd60e51b81526004016105a39061224c565b600061084b6011611479565b9050610857868261147d565b84600b600083815260200190815260200160002060010160086101000a81548163ffffffff021916908363ffffffff16021790555083600b60008381526020019081526020016000206000018190555042600b600083815260200190815260200160002060010160006101000a81548163ffffffff021916908363ffffffff16021790555042600b600083815260200190815260200160002060010160046101000a81548163ffffffff021916908363ffffffff16021790555082600b6000838152602001908152602001600020600101600c6101000a81548163ffffffff021916908363ffffffff1602179055506001600a60008763ffffffff16815260200190815260200160002060000160088282829054906101000a90046001600160401b0316610985919061276c565b92506101000a8154816001600160401b0302191690836001600160401b031602179055506109b36011611541565b6109be86600161154a565b60019150505b949350505050565b6001600160a01b03821660009081526004602052604081206109ee90836115bf565b90505b92915050565b600960205260009081526040902080546001820180546001600160a01b039092169291610a23906127fc565b80601f0160208091040260200160405190810160405280929190818152602001828054610a4f906127fc565b8015610a9c5780601f10610a7157610100808354040283529160200191610a9c565b820191906000526020600020905b815481529060010190602001808311610a7f57829003601f168201915b505050505090806002018054610ab1906127fc565b80601f0160208091040260200160405190810160405280929190818152602001828054610add906127fc565b8015610b2a5780601f10610aff57610100808354040283529160200191610b2a565b820191906000526020600020905b815481529060010190602001808311610b0d57829003601f168201915b5050505050905083565b61064983838360405180602001604052806000815250610e91565b6001546001600160a01b03163314610b795760405162461bcd60e51b81526004016105a39061231f565b600084815260096020908152604090912080546001600160a01b0319166001600160a01b0386161781558351610bb792600190920191850190611c81565b5060008481526009602090815260409091208251610bdd92600290920191840190611c81565b5050505050565b6001546001600160a01b03163314610c0e5760405162461bcd60e51b81526004016105a39061231f565b6000836001600160401b031611610c2457600080fd5b610c30848484846115cb565b50505050565b600080610c44600584611637565b509392505050565b6001546001600160a01b03163314610c765760405162461bcd60e51b81526004016105a39061231f565b8051610c89906010906020840190611c81565b5050565b60006109f1826040518060600160405280602981526020016128c26029913960059190611653565b6060601080546104f9906127fc565b60006001600160a01b038216610cec5760405162461bcd60e51b81526004016105a390612470565b6001600160a01b03821660009081526004602052604090206109f19061128f565b6001546001600160a01b031690565b6060600f80546104f9906127fc565b6003546001600160a01b03163314610d4257600080fd5b6000908152600b60205260409020600101805467ffffffff0000000019166401000000004263ffffffff1602179055565b6001600160a01b038216331415610d9c5760405162461bcd60e51b81526004016105a390612390565b3360008181526008602090815260408083206001600160a01b038716808552925291829020805460ff191685151517905590519091907f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c3190610dff9085906121ec565b60405180910390a35050565b6001546001600160a01b03163314610e355760405162461bcd60e51b81526004016105a39061231f565b6001546040516001600160a01b038084169216907f342827c97908e5e2f71151c08502a66d44b6f758e3ac2f1de95f02eb95f0a73590600090a3600180546001600160a01b0319166001600160a01b0392909216919091179055565b610e9b338361129a565b610eb75760405162461bcd60e51b81526004016105a39061267b565b610c308484848461166a565b6001546001600160a01b03163314610eed5760405162461bcd60e51b81526004016105a39061231f565b6001600160401b0384166000908152600a602090815260409091208251610f1c92600190920191840190611c81565b50506001600160401b039283166000908152600a60205260409020805467ffffffffffffffff19169284169290921767ffffffffffffffff60801b1916600160801b9190931602919091179055565b600c546001600160a01b031681565b6001546001600160a01b03163314610fa45760405162461bcd60e51b81526004016105a39061231f565b600380546001600160a01b0319166001600160a01b0392909216919091179055565b6000818152600b60209081526040808320600180820154600160401b810463ffffffff908116808852600a8752858820549454600160801b9095046001600160401b031680895260099097529487209092018054879687968796879660609693959294600160601b8504821694828116946401000000009091049092169291908190611051906127fc565b80601f016020809104026020016040519081016040528092919081815260200182805461107d906127fc565b80156110ca5780601f1061109f576101008083540402835291602001916110ca565b820191906000526020600020905b8154815290600101906020018083116110ad57829003601f168201915b505050505090509650965096509650965096505091939550919395565b60606110f282611214565b61110e5760405162461bcd60e51b81526004016105a3906125eb565b6000611118610cb5565b6000848152600b6020526040902060010154909150819061114590600160601b900463ffffffff1661169d565b604051602001611156929190612136565b604051602081830303815290604052915050919050565b6003546001600160a01b031681565b6001546001600160a01b031633146111a65760405162461bcd60e51b81526004016105a39061231f565b6001600160a01b03919091166000908152600260205260409020805460ff1916911515919091179055565b6001600160a01b03918216600090815260086020908152604080832093909416825291909152205460ff1690565b60026020526000908152604090205460ff1681565b60006109f16005836117c2565b600081815260076020526040902080546001600160a01b0319166001600160a01b038416908117909155819061125682610c8d565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b60006109f182611479565b60006112a582611214565b6112c15760405162461bcd60e51b81526004016105a3906123c7565b60006112cc83610c8d565b9050806001600160a01b0316846001600160a01b031614806113075750836001600160a01b03166112fc8461057c565b6001600160a01b0316145b806109c457506109c481856111d1565b826001600160a01b031661132a82610c8d565b6001600160a01b0316146113505760405162461bcd60e51b81526004016105a3906125a2565b6001600160a01b0382166113765760405162461bcd60e51b81526004016105a39061234c565b611381838383610649565b61138c600082611221565b6001600160a01b03831660009081526004602052604090206113ae90826117ce565b506001600160a01b03821660009081526004602052604090206113d190826117da565b506113de600582846117e6565b506000818152600b602052604090206001908101805463ffffffff19164263ffffffff1690811767ffffffff0000000019166401000000009190910217905561142890839061154a565b61143383600061154a565b80826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a4505050565b5490565b6001600160a01b0382166114a35760405162461bcd60e51b81526004016105a3906124fc565b6114ac81611214565b156114c95760405162461bcd60e51b81526004016105a3906122e8565b6114d560008383610649565b6001600160a01b03821660009081526004602052604090206114f790826117da565b50611504600582846117e6565b5060405181906001600160a01b038416906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b80546001019055565b6001600160a01b038216600090815260046020526040812061156b9061128f565b905080156115a55760018215151480156115855750806001145b156115a057600d805490600061159a83612837565b91905055505b610649565b600d80549060006115b5836127e5565b9190505550505050565b60006109ee83836117fc565b6001600160401b038481166000908152600a60209081526040909120805467ffffffffffffffff19168684161777ffffffffffffffffffffffffffffffff00000000000000001916600160801b938616939093029290921782558251610bdd9260010191840190611c81565b60008080806116468686611855565b9097909650945050505050565b60006116608484846118c5565b90505b9392505050565b611675848484611317565b6116818484848461193c565b610c305760405162461bcd60e51b81526004016105a390612296565b6060816116c257506040805180820190915260018152600360fc1b60208201526104e5565b8160005b81156116ec57806116d681612837565b91506116e59050600a8361278e565b91506116c6565b6000816001600160401b0381111561171457634e487b7160e01b600052604160045260246000fd5b6040519080825280601f01601f19166020018201604052801561173e576020820181803683370190505b508593509050815b83156117b957611757600a85612852565b611762906030612754565b60f81b8261176f836127e5565b9250828151811061179057634e487b7160e01b600052603260045260246000fd5b60200101906001600160f81b031916908160001a9053506117b2600a8561278e565b9350611746565b50949350505050565b60006109ee8383611a4d565b60006109ee8383611a65565b60006109ee8383611b82565b600061166084846001600160a01b038516611bcc565b8154600090821061181f5760405162461bcd60e51b81526004016105a39061220a565b82600001828154811061184257634e487b7160e01b600052603260045260246000fd5b9060005260206000200154905092915050565b81546000908190831061187a5760405162461bcd60e51b81526004016105a3906124ba565b600084600001848154811061189f57634e487b7160e01b600052603260045260246000fd5b906000526020600020906002020190508060000154816001015492509250509250929050565b600082815260018401602052604081205482816118f55760405162461bcd60e51b81526004016105a391906121f7565b50846119026001836127a2565b8154811061192057634e487b7160e01b600052603260045260246000fd5b9060005260206000209060020201600101549150509392505050565b6000611950846001600160a01b0316611c7b565b15611a4557604051630a85bd0160e11b81526001600160a01b0385169063150b7a0290611987903390899088908890600401612179565b602060405180830381600087803b1580156119a157600080fd5b505af19250505080156119d1575060408051601f3d908101601f191682019092526119ce91810190611fb4565b60015b611a2b573d8080156119ff576040519150601f19603f3d011682016040523d82523d6000602084013e611a04565b606091505b508051611a235760405162461bcd60e51b81526004016105a390612296565b805181602001fd5b6001600160e01b031916630a85bd0160e11b1490506109c4565b5060016109c4565b60009081526001919091016020526040902054151590565b60008181526001830160205260408120548015611b78576000611a896001836127a2565b8554909150600090611a9d906001906127a2565b90506000866000018281548110611ac457634e487b7160e01b600052603260045260246000fd5b9060005260206000200154905080876000018481548110611af557634e487b7160e01b600052603260045260246000fd5b600091825260209091200155611b0c836001612754565b60008281526001890160205260409020558654879080611b3c57634e487b7160e01b600052603160045260246000fd5b600190038181906000526020600020016000905590558660010160008781526020019081526020016000206000905560019450505050506109f1565b60009150506109f1565b6000611b8e8383611a4d565b611bc4575081546001818101845560008481526020808220909301849055845484825282860190935260409020919091556109f1565b5060006109f1565b600082815260018401602052604081205480611c31575050604080518082018252838152602080820184815286546001818101895560008981528481209551600290930290950191825591519082015586548684528188019092529290912055611663565b8285611c3e6001846127a2565b81548110611c5c57634e487b7160e01b600052603260045260246000fd5b9060005260206000209060020201600101819055506000915050611663565b3b151590565b828054611c8d906127fc565b90600052602060002090601f016020900481019282611caf5760008555611cf5565b82601f10611cc857805160ff1916838001178555611cf5565b82800160010185558215611cf5579182015b82811115611cf5578251825591602001919060010190611cda565b50611d01929150611d05565b5090565b5b80821115611d015760008155600101611d06565b60006001600160401b0380841115611d3457611d34612892565b604051601f8501601f191681016020018281118282101715611d5857611d58612892565b604052848152915081838501861015611d7057600080fd5b8484602083013760006020868301015250509392505050565b80356001600160a01b03811681146104e557600080fd5b600082601f830112611db0578081fd5b6109ee83833560208501611d1a565b803563ffffffff811681146104e557600080fd5b80356001600160401b03811681146104e557600080fd5b600060208284031215611dfb578081fd5b6109ee82611d89565b60008060408385031215611e16578081fd5b611e1f83611d89565b9150611e2d60208401611d89565b90509250929050565b600080600060608486031215611e4a578081fd5b611e5384611d89565b9250611e6160208501611d89565b9150604084013590509250925092565b60008060008060808587031215611e86578081fd5b611e8f85611d89565b9350611e9d60208601611d89565b92506040850135915060608501356001600160401b03811115611ebe578182fd5b8501601f81018713611ece578182fd5b611edd87823560208401611d1a565b91505092959194509250565b60008060408385031215611efb578182fd5b611f0483611d89565b915060208301358015158114611f18578182fd5b809150509250929050565b60008060408385031215611f35578182fd5b611f3e83611d89565b946020939093013593505050565b60008060008060808587031215611f61578384fd5b611f6a85611d89565b9350611f7860208601611dbf565b925060408501359150611f8d60608601611dbf565b905092959194509250565b600060208284031215611fa9578081fd5b8135611663816128a8565b600060208284031215611fc5578081fd5b8151611663816128a8565b600060208284031215611fe1578081fd5b81356001600160401b03811115611ff6578182fd5b6109c484828501611da0565b600060208284031215612013578081fd5b5035919050565b6000806000806080858703121561202f578384fd5b8435935061203f60208601611d89565b925060408501356001600160401b038082111561205a578384fd5b61206688838901611da0565b9350606087013591508082111561207b578283fd5b50611edd87828801611da0565b6000806040838503121561209a578182fd5b82359150611e2d60208401611dbf565b600080600080608085870312156120bf578182fd5b6120c885611dd3565b93506120d660208601611dd3565b92506120e460408601611dd3565b915060608501356001600160401b038111156120fe578182fd5b611edd87828801611da0565b600081518084526121228160208601602086016127b9565b601f01601f19169290920160200192915050565b600083516121488184602088016127b9565b83519083019061215c8183602088016127b9565b01949350505050565b6001600160a01b0391909116815260200190565b6001600160a01b03858116825284166020820152604081018390526080606082018190526000906121ac9083018461210a565b9695505050505050565b6001600160a01b03841681526060602082018190526000906121da9083018561210a565b82810360408401526121ac818561210a565b901515815260200190565b6000602082526109ee602083018461210a565b60208082526022908201527f456e756d657261626c655365743a20696e646578206f7574206f6620626f756e604082015261647360f01b606082015260800190565b6020808252602a908201527f4d6178206d696e7461626c6520616d6f756e74207265616368656420666f72206040820152691d1a1a5cc8185cdcd95d60b21b606082015260800190565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b6020808252601c908201527f4552433732313a20746f6b656e20616c7265616479206d696e74656400000000604082015260600190565b60208082526013908201527221b0b63632b91034b9903737ba1037bbb732b960691b604082015260600190565b60208082526024908201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646040820152637265737360e01b606082015260800190565b60208082526019908201527f4552433732313a20617070726f766520746f2063616c6c657200000000000000604082015260600190565b6020808252602c908201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860408201526b34b9ba32b73a103a37b5b2b760a11b606082015260800190565b60208082526038908201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760408201527f6e6572206e6f7220617070726f76656420666f7220616c6c0000000000000000606082015260800190565b6020808252602a908201527f4552433732313a2062616c616e636520717565727920666f7220746865207a65604082015269726f206164647265737360b01b606082015260800190565b60208082526022908201527f456e756d657261626c654d61703a20696e646578206f7574206f6620626f756e604082015261647360f01b606082015260800190565b6020808252818101527f4552433732313a206d696e7420746f20746865207a65726f2061646472657373604082015260600190565b6020808252602c908201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860408201526b34b9ba32b73a103a37b5b2b760a11b606082015260800190565b6020808252600b908201526a139bdd08185b1b1bddd95960aa1b604082015260600190565b60208082526029908201527f4552433732313a207472616e73666572206f6620746f6b656e2074686174206960408201526839903737ba1037bbb760b91b606082015260800190565b6020808252602f908201527f4552433732314d657461646174613a2055524920717565727920666f72206e6f60408201526e3732bc34b9ba32b73a103a37b5b2b760891b606082015260800190565b60208082526021908201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656040820152603960f91b606082015260800190565b60208082526031908201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f6040820152701ddb995c881b9bdc88185c1c1c9bdd9959607a1b606082015260800190565b90815260200190565b600063ffffffff80891683528088166020840152808716604084015280861660608401525083608083015260c060a083015261271460c083018461210a565b98975050505050505050565b60006001600160401b0380871683528086166020840152808516604084015250608060608301526121ac608083018461210a565b6000821982111561276757612767612866565b500190565b60006001600160401b0380831681851680830382111561215c5761215c612866565b60008261279d5761279d61287c565b500490565b6000828210156127b4576127b4612866565b500390565b60005b838110156127d45781810151838201526020016127bc565b83811115610c305750506000910152565b6000816127f4576127f4612866565b506000190190565b60028104600182168061281057607f821691505b6020821081141561283157634e487b7160e01b600052602260045260246000fd5b50919050565b600060001982141561284b5761284b612866565b5060010190565b6000826128615761286161287c565b500690565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160e01b0319811681146128be57600080fd5b5056fe4552433732313a206f776e657220717565727920666f72206e6f6e6578697374656e7420746f6b656ea2646970667358221220611ec779b13f76a38657886d85eb8e111ac6bb2acbe217cfc8c7bedc1c0740d764736f6c63430008000033
Verified Source Code Partial Match
Compiler: v0.8.0+commit.c7dfd78e
EVM: istanbul
Optimization: Yes (200 runs)
ERC721.sol 1487 lines
/**
*Submitted for verification at Etherscan.io on 2021-02-23
*/
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface IERC165 {
/**
* @dev Returns true ifa 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);
}
interface IERC721 is IERC165 {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function approve(address to, uint256 tokenId) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the caller.
*
* Emits an {ApprovalForAll} event.
*/
function setApprovalForAll(address operator, bool _approved) external;
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/
function isApprovedForAll(address owner, address operator) external view returns (bool);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;
}
interface IERC721Metadata is IERC721 {
/**
* @dev Returns the token collection name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the token collection symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
*/
function tokenURI(uint256 tokenId) external view returns (string memory);
}
interface IERC721Enumerable is IERC721 {
/**
* @dev Returns the total amount of tokens stored by the contract.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns a token ID owned by `owner` at a given `index` of its token list.
* Use along with {balanceOf} to enumerate all of ``owner``'s tokens.
*/
function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId);
/**
* @dev Returns a token ID at a given `index` of all the tokens stored by the contract.
* Use along with {totalSupply} to enumerate all tokens.
*/
function tokenByIndex(uint256 index) external view returns (uint256);
}
interface IERC721Receiver {
/**
* @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
* by `operator` from `from`, this function is called.
*
* It must return its Solidity selector to confirm the token transfer.
* If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
*
* The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`.
*/
function onERC721Received(address operator, address from, uint256 tokenId, bytes calldata data) external returns (bytes4);
}
abstract contract ERC165 is IERC165 {
/**
* @dev Mapping of interface ids to whether or not it's supported.
*/
mapping(bytes4 => bool) private _supportedInterfaces;
constructor () {
// Derived contracts need only register support for their own interfaces,
// we register support for ERC165 itself here
_registerInterface(type(IERC165).interfaceId);
}
/**
* @dev See {IERC165-supportsInterface}.
*
* Time complexity O(1), guaranteed to always use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return _supportedInterfaces[interfaceId];
}
/**
* @dev Registers the contract as an implementer of the interface defined by
* `interfaceId`. Support of the actual ERC165 interface is automatic and
* registering its interface id is not required.
*
* See {IERC165-supportsInterface}.
*
* Requirements:
*
* - `interfaceId` cannot be the ERC165 invalid interface (`0xffffffff`).
*/
function _registerInterface(bytes4 interfaceId) internal virtual {
require(interfaceId != 0xffffffff, "ERC165: invalid interface id");
_supportedInterfaces[interfaceId] = true;
}
}
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
// solhint-disable-next-line no-inline-assembly
assembly { size := extcodesize(account) }
return size > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: value }(data);
return _verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.staticcall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.delegatecall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
library EnumerableSet {
// To implement this library for multiple types with as little code
// repetition as possible, we write it in terms of a generic Set type with
// bytes32 values.
// The Set implementation uses private functions, and user-facing
// implementations (such as AddressSet) are just wrappers around the
// underlying Set.
// This means that we can only create new EnumerableSets for types that fit
// in bytes32.
struct Set {
// Storage of set values
bytes32[] _values;
// Position of the value in the `values` array, plus 1 because index 0
// means a value is not in the set.
mapping (bytes32 => uint256) _indexes;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function _add(Set storage set, bytes32 value) private returns (bool) {
if (!_contains(set, value)) {
set._values.push(value);
// The value is stored at length-1, but we add 1 to all indexes
// and use 0 as a sentinel value
set._indexes[value] = set._values.length;
return true;
} else {
return false;
}
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function _remove(Set storage set, bytes32 value) private returns (bool) {
// We read and store the value's index to prevent multiple reads from the same storage slot
uint256 valueIndex = set._indexes[value];
if (valueIndex != 0) { // Equivalent to contains(set, value)
// To delete an element from the _values array in O(1), we swap the element to delete with the last one in
// the array, and then remove the last element (sometimes called as 'swap and pop').
// This modifies the order of the array, as noted in {at}.
uint256 toDeleteIndex = valueIndex - 1;
uint256 lastIndex = set._values.length - 1;
// When the value to delete is the last one, the swap operation is unnecessary. However, since this occurs
// so rarely, we still do the swap anyway to avoid the gas cost of adding an 'if' statement.
bytes32 lastvalue = set._values[lastIndex];
// Move the last value to the index where the value to delete is
set._values[toDeleteIndex] = lastvalue;
// Update the index for the moved value
set._indexes[lastvalue] = toDeleteIndex + 1; // All indexes are 1-based
// Delete the slot where the moved value was stored
set._values.pop();
// Delete the index for the deleted slot
delete set._indexes[value];
return true;
} else {
return false;
}
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function _contains(Set storage set, bytes32 value) private view returns (bool) {
return set._indexes[value] != 0;
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function _length(Set storage set) private view returns (uint256) {
return set._values.length;
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function _at(Set storage set, uint256 index) private view returns (bytes32) {
require(set._values.length > index, "EnumerableSet: index out of bounds");
return set._values[index];
}
// Bytes32Set
struct Bytes32Set {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _add(set._inner, value);
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _remove(set._inner, value);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
return _contains(set._inner, value);
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(Bytes32Set storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
return _at(set._inner, index);
}
// AddressSet
struct AddressSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(AddressSet storage set, address value) internal returns (bool) {
return _add(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(AddressSet storage set, address value) internal returns (bool) {
return _remove(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(AddressSet storage set, address value) internal view returns (bool) {
return _contains(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(AddressSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(AddressSet storage set, uint256 index) internal view returns (address) {
return address(uint160(uint256(_at(set._inner, index))));
}
// UintSet
struct UintSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(UintSet storage set, uint256 value) internal returns (bool) {
return _add(set._inner, bytes32(value));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(UintSet storage set, uint256 value) internal returns (bool) {
return _remove(set._inner, bytes32(value));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(UintSet storage set, uint256 value) internal view returns (bool) {
return _contains(set._inner, bytes32(value));
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function length(UintSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(UintSet storage set, uint256 index) internal view returns (uint256) {
return uint256(_at(set._inner, index));
}
}
library EnumerableMap {
// To implement this library for multiple types with as little code
// repetition as possible, we write it in terms of a generic Map type with
// bytes32 keys and values.
// The Map implementation uses private functions, and user-facing
// implementations (such as Uint256ToAddressMap) are just wrappers around
// the underlying Map.
// This means that we can only create new EnumerableMaps for types that fit
// in bytes32.
struct MapEntry {
bytes32 _key;
bytes32 _value;
}
struct Map {
// Storage of map keys and values
MapEntry[] _entries;
// Position of the entry defined by a key in the `entries` array, plus 1
// because index 0 means a key is not in the map.
mapping (bytes32 => uint256) _indexes;
}
/**
* @dev Adds a key-value pair to a map, or updates the value for an existing
* key. O(1).
*
* Returns true if the key was added to the map, that is if it was not
* already present.
*/
function _set(Map storage map, bytes32 key, bytes32 value) private returns (bool) {
// We read and store the key's index to prevent multiple reads from the same storage slot
uint256 keyIndex = map._indexes[key];
if (keyIndex == 0) { // Equivalent to !contains(map, key)
map._entries.push(MapEntry({ _key: key, _value: value }));
// The entry is stored at length-1, but we add 1 to all indexes
// and use 0 as a sentinel value
map._indexes[key] = map._entries.length;
return true;
} else {
map._entries[keyIndex - 1]._value = value;
return false;
}
}
/**
* @dev Removes a key-value pair from a map. O(1).
*
* Returns true if the key was removed from the map, that is if it was present.
*/
function _remove(Map storage map, bytes32 key) private returns (bool) {
// We read and store the key's index to prevent multiple reads from the same storage slot
uint256 keyIndex = map._indexes[key];
if (keyIndex != 0) { // Equivalent to contains(map, key)
// To delete a key-value pair from the _entries array in O(1), we swap the entry to delete with the last one
// in the array, and then remove the last entry (sometimes called as 'swap and pop').
// This modifies the order of the array, as noted in {at}.
uint256 toDeleteIndex = keyIndex - 1;
uint256 lastIndex = map._entries.length - 1;
// When the entry to delete is the last one, the swap operation is unnecessary. However, since this occurs
// so rarely, we still do the swap anyway to avoid the gas cost of adding an 'if' statement.
MapEntry storage lastEntry = map._entries[lastIndex];
// Move the last entry to the index where the entry to delete is
map._entries[toDeleteIndex] = lastEntry;
// Update the index for the moved entry
map._indexes[lastEntry._key] = toDeleteIndex + 1; // All indexes are 1-based
// Delete the slot where the moved entry was stored
map._entries.pop();
// Delete the index for the deleted slot
delete map._indexes[key];
return true;
} else {
return false;
}
}
/**
* @dev Returns true if the key is in the map. O(1).
*/
function _contains(Map storage map, bytes32 key) private view returns (bool) {
return map._indexes[key] != 0;
}
/**
* @dev Returns the number of key-value pairs in the map. O(1).
*/
function _length(Map storage map) private view returns (uint256) {
return map._entries.length;
}
/**
* @dev Returns the key-value pair stored at position `index` in the map. O(1).
*
* Note that there are no guarantees on the ordering of entries inside the
* array, and it may change when more entries are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function _at(Map storage map, uint256 index) private view returns (bytes32, bytes32) {
require(map._entries.length > index, "EnumerableMap: index out of bounds");
MapEntry storage entry = map._entries[index];
return (entry._key, entry._value);
}
/**
* @dev Tries to returns the value associated with `key`. O(1).
* Does not revert if `key` is not in the map.
*/
function _tryGet(Map storage map, bytes32 key) private view returns (bool, bytes32) {
uint256 keyIndex = map._indexes[key];
if (keyIndex == 0) return (false, 0); // Equivalent to contains(map, key)
return (true, map._entries[keyIndex - 1]._value); // All indexes are 1-based
}
/**
* @dev Returns the value associated with `key`. O(1).
*
* Requirements:
*
* - `key` must be in the map.
*/
function _get(Map storage map, bytes32 key) private view returns (bytes32) {
uint256 keyIndex = map._indexes[key];
require(keyIndex != 0, "EnumerableMap: nonexistent key"); // Equivalent to contains(map, key)
return map._entries[keyIndex - 1]._value; // All indexes are 1-based
}
/**
* @dev Same as {_get}, with a custom error message when `key` is not in the map.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {_tryGet}.
*/
function _get(Map storage map, bytes32 key, string memory errorMessage) private view returns (bytes32) {
uint256 keyIndex = map._indexes[key];
require(keyIndex != 0, errorMessage); // Equivalent to contains(map, key)
return map._entries[keyIndex - 1]._value; // All indexes are 1-based
}
// UintToAddressMap
struct UintToAddressMap {
Map _inner;
}
/**
* @dev Adds a key-value pair to a map, or updates the value for an existing
* key. O(1).
*
* Returns true if the key was added to the map, that is if it was not
* already present.
*/
function set(UintToAddressMap storage map, uint256 key, address value) internal returns (bool) {
return _set(map._inner, bytes32(key), bytes32(uint256(uint160(value))));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the key was removed from the map, that is if it was present.
*/
function remove(UintToAddressMap storage map, uint256 key) internal returns (bool) {
return _remove(map._inner, bytes32(key));
}
/**
* @dev Returns true if the key is in the map. O(1).
*/
function contains(UintToAddressMap storage map, uint256 key) internal view returns (bool) {
return _contains(map._inner, bytes32(key));
}
/**
* @dev Returns the number of elements in the map. O(1).
*/
function length(UintToAddressMap storage map) internal view returns (uint256) {
return _length(map._inner);
}
/**
* @dev Returns the element stored at position `index` in the set. O(1).
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(UintToAddressMap storage map, uint256 index) internal view returns (uint256, address) {
(bytes32 key, bytes32 value) = _at(map._inner, index);
return (uint256(key), address(uint160(uint256(value))));
}
/**
* @dev Tries to returns the value associated with `key`. O(1).
* Does not revert if `key` is not in the map.
*
* _Available since v3.4._
*/
function tryGet(UintToAddressMap storage map, uint256 key) internal view returns (bool, address) {
(bool success, bytes32 value) = _tryGet(map._inner, bytes32(key));
return (success, address(uint160(uint256(value))));
}
/**
* @dev Returns the value associated with `key`. O(1).
*
* Requirements:
*
* - `key` must be in the map.
*/
function get(UintToAddressMap storage map, uint256 key) internal view returns (address) {
return address(uint160(uint256(_get(map._inner, bytes32(key)))));
}
/**
* @dev Same as {get}, with a custom error message when `key` is not in the map.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryGet}.
*/
function get(UintToAddressMap storage map, uint256 key, string memory errorMessage) internal view returns (address) {
return address(uint160(uint256(_get(map._inner, bytes32(key), errorMessage))));
}
}
library Strings {
/**
* @dev Converts a `uint256` to its ASCII `string` representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
// Inspired by OraclizeAPI's implementation - MIT licence
// https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol
if (value == 0) {
return "0";
}
uint256 temp = value;
uint256 digits;
while (temp != 0) {
digits++;
temp /= 10;
}
bytes memory buffer = new bytes(digits);
uint256 index = digits;
temp = value;
while (temp != 0) {
buffer[--index] = bytes1(uint8(48 + uint256(temp % 10)));
temp /= 10;
}
return string(buffer);
}
}
library Counters {
struct Counter {
// This variable should never be directly accessed by users of the library: interactions must be restricted to
// the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add
// this feature: see https://github.com/ethereum/solidity/issues/4637
uint256 _value; // default: 0
}
function current(Counter storage counter) internal view returns (uint256) {
return counter._value;
}
function increment(Counter storage counter) internal {
unchecked {
counter._value += 1;
}
}
function decrement(Counter storage counter) internal {
uint256 value = counter._value;
require(value > 0, "Counter: decrement overflow");
unchecked {
counter._value = value - 1;
}
}
}
contract Ownable {
address private owner;
event OwnerSet(address indexed oldOwner, address indexed newOwner);
modifier onlyOwner() {
require(msg.sender == owner, "Caller is not owner");
_;
}
constructor() {
owner = msg.sender; // 'msg.sender' is sender of current call, contract deployer for a constructor
emit OwnerSet(address(0), owner);
}
function changeOwner(address newOwner) public onlyOwner {
emit OwnerSet(owner, newOwner);
owner = newOwner;
}
function getOwner() external view returns (address) {
return owner;
}
}
contract ERC721 is ERC165, IERC721, IERC721Metadata, IERC721Enumerable, Ownable {
using Address for address;
using EnumerableSet for EnumerableSet.UintSet;
using EnumerableMap for EnumerableMap.UintToAddressMap;
using Strings for uint256;
using Counters for Counters.Counter;
// Map the selling contracts that can mint tokens
mapping (address => bool) public minters;
// Contract that calculates the stake profits
address public profitsContract;
// 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;
struct Coin {
address tokenAddress;
string symbol;
string name;
}
mapping (uint256 => Coin) public tradeCoins;
struct assetType {
uint64 maxAmount;
uint64 mintedAmount;
uint64 coinIndex;
string copyright;
}
mapping (uint256 => assetType) public assetsByType;
struct assetDetail {
uint256 value;
uint32 lastTrade;
uint32 lastPayment;
uint32 typeDetail;
uint32 customDetails;
}
mapping (uint256 => assetDetail) assetsDetails;
address public sellingContract;
uint256 public polkaCitizens = 0;
// Token name
string private _name;
// Token symbol
string private _symbol;
// Base URI
string private _baseURI;
Counters.Counter private _tokenIdTracker;
/**
* @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
*/
constructor () {
_name ="Polka City 3D Asset";
_symbol = "PC3D";
_baseURI = "https://polkacity.app/3dnftassets/";
// include ETH as coin
tradeCoins[1].tokenAddress = address(0x0);
tradeCoins[1].symbol = "ETH";
tradeCoins[1].name = "Ethereum";
// include POLC as coin
tradeCoins[2].tokenAddress = 0x0daD676DA510e71e31464A765a8548b47f47bdad;
tradeCoins[2].symbol = "POLC";
tradeCoins[2].name = "Polka City Token";
// register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(type(IERC721).interfaceId);
_registerInterface(type(IERC721Metadata).interfaceId);
_registerInterface(type(IERC721Enumerable).interfaceId);
}
function initAssets(uint64 _assetType, uint64 _maxAmount, uint64 _coinIndex, string memory _copyright) private {
assetsByType[_assetType].maxAmount = _maxAmount;
assetsByType[_assetType].mintedAmount = 0;
assetsByType[_assetType].coinIndex = _coinIndex;
assetsByType[_assetType].copyright = _copyright;
}
/**
* @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 base = baseURI();
return string(abi.encodePacked(base,( uint256(assetsDetails[tokenId].customDetails).toString())));
}
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);
}
function getTokenDetails(uint256 index) public view returns (uint32 aType, uint32 customDetails, uint32 lastTx, uint32 lastPayment, uint256 initialvalue, string memory coin) {
uint256 coinIndex = uint256(assetsByType[(assetsDetails[index].typeDetail)].coinIndex);
return (
assetsDetails[index].typeDetail,
assetsDetails[index].customDetails,
assetsDetails[index].lastTrade,
assetsDetails[index].lastPayment,
assetsDetails[index].value,
tradeCoins[coinIndex].symbol
);
}
/**
* @dev See {IERC721-approve}.
*/
function approve(address to, uint256 tokenId) public virtual override {
address _owner = ERC721.ownerOf(tokenId);
require(to != _owner, "ERC721: approval to current owner");
require(msg.sender == _owner || ERC721.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 {
require(operator != msg.sender, "ERC721: approve to caller");
_operatorApprovals[msg.sender][operator] = approved;
emit ApprovalForAll(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 _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 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);
assetsDetails[tokenId].lastTrade = uint32(block.timestamp);
assetsDetails[tokenId].lastPayment = uint32(block.timestamp);
checkCitizen(to, true);
checkCitizen(from, false);
emit Transfer(from, to, tokenId);
}
function setBaseURI(string memory baseURI_)...
// [truncated — 55149 bytes total]
Read Contract
assetsByType 0x1703b06c → uint64, uint64, uint64, string
balanceOf 0x70a08231 → uint256
baseURI 0x6c0360eb → string
getApproved 0x081812fc → address
getOwner 0x893d20e8 → address
getTokenDetails 0xc1e03728 → uint32, uint32, uint32, uint32, uint256, string
isApprovedForAll 0xe985e9c5 → bool
minters 0xf46eccc4 → bool
name 0x06fdde03 → string
ownerOf 0x6352211e → address
polkaCitizens 0x0c4192cf → uint256
profitsContract 0xcea93fc3 → address
sellingContract 0xbf56ee26 → address
supportsInterface 0x01ffc9a7 → bool
symbol 0x95d89b41 → string
tokenByIndex 0x4f6ccce7 → uint256
tokenOfOwnerByIndex 0x2f745c59 → uint256
tokenURI 0xc87b56dd → string
totalSupply 0x18160ddd → uint256
tradeCoins 0x36ffbc77 → address, string, string
Write Contract 15 functions
These functions modify contract state and require a wallet transaction to execute.
addAssetType 0x4efbce0a
uint64 _assetType
uint64 _maxAmount
uint64 _coinIndex
string _copyright
addCoin 0x4db1be94
uint256 _coinIndex
address _tokenAddress
string _tokenSymbol
string _tokenName
approve 0x095ea7b3
address to
uint256 tokenId
changeOwner 0xa6f9dae1
address newOwner
fixAsset 0x27c8ee26
uint256 _assetId
uint32 _customDetails
mint 0x27ed628b
address to
uint32 _assetType
uint256 _value
uint32 _customDetails
returns: bool
modifyAssetType 0xbcd4ddf7
uint64 _typeId
uint64 _maxAmount
uint64 _coinIndex
string _copyright
safeTransferFrom 0x42842e0e
address from
address to
uint256 tokenId
safeTransferFrom 0xb88d4fde
address from
address to
uint256 tokenId
bytes _data
setApprovalForAll 0xa22cb465
address operator
bool approved
setBaseURI 0x55f804b3
string baseURI_
setMinter 0xcf456ae7
address _minterAddress
bool _canMint
setPaymentDate 0xa1cfb5ed
uint256 _asset
setProfitsContract 0xc1d022cf
address _contract
transferFrom 0x23b872dd
address from
address to
uint256 tokenId
Recent Transactions
No transactions found for this address