Address Contract Verified
Address
0xAcD8d7E269e533130B322069A699509F8A344D91
Balance
0 ETH
Nonce
1
Code Size
16443 bytes
Creator
0xddb1d1ae...7793 at tx 0x706bf99a...e55e3d
Indexed Transactions
0
Contract Bytecode
16443 bytes
0x60806040526004361061019f5760003560e01c80634f558e79116100ec578063a22cb4651161008a578063e985e9c511610064578063e985e9c5146105fd578063f242432a1461063a578063f2fde38b14610663578063f7c8ae591461068c576101a6565b8063a22cb4651461057b578063bd85b039146105a4578063cf6868d5146105e1576101a6565b8063869f7594116100c6578063869f7594146104ab5780638da5cb5b146104e8578063919956ef1461051357806395d89b4114610550576101a6565b80634f558e791461041a57806362d9e31414610457578063715018a614610494576101a6565b806318160ddd116101595780632eb2c2d6116101335780632eb2c2d61461035b5780634041801d146103845780634915f070146103c15780634e1273f4146103dd576101a6565b806318160ddd146102dc578063238ac93314610307578063238e875f14610332576101a6565b8062fdd58e146101a857806301ffc9a7146101e557806302fe530514610222578063046dc1661461024b57806306fdde03146102745780630e89341c1461029f576101a6565b366101a657005b005b3480156101b457600080fd5b506101cf60048036038101906101ca91906127fe565b6106a8565b6040516101dc919061284d565b60405180910390f35b3480156101f157600080fd5b5061020c600480360381019061020791906128c0565b610702565b6040516102199190612908565b60405180910390f35b34801561022e57600080fd5b5061024960048036038101906102449190612a69565b6107e4565b005b34801561025757600080fd5b50610272600480360381019061026d9190612ab2565b6107f8565b005b34801561028057600080fd5b50610289610844565b6040516102969190612b5e565b60405180910390f35b3480156102ab57600080fd5b506102c660048036038101906102c19190612b80565b610881565b6040516102d39190612b5e565b60405180910390f35b3480156102e857600080fd5b506102f1610915565b6040516102fe919061284d565b60405180910390f35b34801561031357600080fd5b5061031c61091f565b6040516103299190612bbc565b60405180910390f35b34801561033e57600080fd5b5061035960048036038101906103549190612bd7565b610945565b005b34801561036757600080fd5b50610382600480360381019061037d9190612d80565b610969565b005b34801561039057600080fd5b506103ab60048036038101906103a69190612e4f565b610a11565b6040516103b89190612f85565b60405180910390f35b6103db60048036038101906103d69190612fa7565b610b54565b005b3480156103e957600080fd5b5061040460048036038101906103ff91906130ed565b610d37565b6040516104119190613223565b60405180910390f35b34801561042657600080fd5b50610441600480360381019061043c9190612b80565b610e40565b60405161044e9190612908565b60405180910390f35b34801561046357600080fd5b5061047e60048036038101906104799190612bd7565b610e54565b60405161048b9190612908565b60405180910390f35b3480156104a057600080fd5b506104a9610e83565b005b3480156104b757600080fd5b506104d260048036038101906104cd9190612b80565b610e97565b6040516104df919061284d565b60405180910390f35b3480156104f457600080fd5b506104fd610eaf565b60405161050a9190612bbc565b60405180910390f35b34801561051f57600080fd5b5061053a60048036038101906105359190612b80565b610ed9565b604051610547919061284d565b60405180910390f35b34801561055c57600080fd5b50610565610ef1565b6040516105729190612b5e565b60405180910390f35b34801561058757600080fd5b506105a2600480360381019061059d9190613271565b610f2e565b005b3480156105b057600080fd5b506105cb60048036038101906105c69190612b80565b610f44565b6040516105d8919061284d565b60405180910390f35b6105fb60048036038101906105f691906132b1565b610f61565b005b34801561060957600080fd5b50610624600480360381019061061f919061336c565b61123d565b6040516106319190612908565b60405180910390f35b34801561064657600080fd5b50610661600480360381019061065c91906133ac565b6112d1565b005b34801561066f57600080fd5b5061068a60048036038101906106859190612ab2565b611379565b005b6106a660048036038101906106a1919061347c565b6113ff565b005b600080600083815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b60007fd9b67a26000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614806107cd57507f0e89341c000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916145b806107dd57506107dc82611429565b5b9050919050565b6107ec611493565b6107f58161151a565b50565b610800611493565b80600660006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b60606040518060400160405280600c81526020017f4e6f646520426f6f737465720000000000000000000000000000000000000000815250905090565b606060028054610890906134eb565b80601f01602080910402602001604051908101604052809291908181526020018280546108bc906134eb565b80156109095780601f106108de57610100808354040283529160200191610909565b820191906000526020600020905b8154815290600101906020018083116108ec57829003601f168201915b50505050509050919050565b6000600554905090565b600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b61094d611493565b8060076000848152602001908152602001600020819055505050565b600061097361152d565b90508073ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff16141580156109b857506109b6868261123d565b155b156109fc5780866040517fe237d9220000000000000000000000000000000000000000000000000000000081526004016109f392919061351c565b60405180910390fd5b610a098686868686611535565b505050505050565b60608151835114610a57576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a4e90613591565b60405180910390fd5b6000835167ffffffffffffffff811115610a7457610a7361293e565b5b604051908082528060200260200182016040528015610aa25781602001602082028036833780820191505090505b50905060005b8451811015610b495760096000868381518110610ac857610ac76135b1565b5b602002602001015181526020019081526020016000206000858381518110610af357610af26135b1565b5b6020026020010151815260200190815260200160002060009054906101000a900460ff16828281518110610b2a57610b296135b1565b5b6020026020010190151590811515815250508080600101915050610aa8565b508091505092915050565b600033858585604051602001610b6d9493929190613649565b604051602081830303815290604052805190602001209050610b8f818361162d565b610bce576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610bc5906136e3565b60405180910390fd5b6007600086815260200190815260200160002054600860008781526020019081526020016000205410610c36576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610c2d9061374f565b60405180910390fd5b6000151560096000878152602001908152602001600020600086815260200190815260200160002060009054906101000a900460ff16151514610cae576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610ca5906137bb565b60405180910390fd5b600160096000878152602001908152602001600020600086815260200190815260200160002060006101000a81548160ff021916908315150217905550600860008681526020019081526020016000206000815480929190610d0f9061380a565b9190505550610d3033866001604051806020016040528060008152506116c5565b5050505050565b60608151835114610d8357815183516040517f5b059991000000000000000000000000000000000000000000000000000000008152600401610d7a929190613852565b60405180910390fd5b6000835167ffffffffffffffff811115610da057610d9f61293e565b5b604051908082528060200260200182016040528015610dce5781602001602082028036833780820191505090505b50905060005b8451811015610e3557610e0b610df3828761175e90919063ffffffff16565b610e06838761177290919063ffffffff16565b6106a8565b828281518110610e1e57610e1d6135b1565b5b602002602001018181525050806001019050610dd4565b508091505092915050565b600080610e4c83610f44565b119050919050565b60096020528160005260406000206020528060005260406000206000915091509054906101000a900460ff1681565b610e8b611493565b610e956000611786565b565b60076020528060005260406000206000915090505481565b6000600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b60086020528060005260406000206000915090505481565b60606040518060400160405280600381526020017f4253540000000000000000000000000000000000000000000000000000000000815250905090565b610f40610f3961152d565b838361184c565b5050565b600060046000838152602001908152602001600020549050919050565b600033858585604051602001610f7a949392919061390b565b6040516020818303038152906040528051906020012090508351855114610fd6576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610fcd9061399d565b60405180910390fd5b610fe0818361162d565b61101f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611016906136e3565b60405180910390fd5b60008551905060005b81811015611234576000878281518110611045576110446135b1565b5b602002602001015190506000878381518110611064576110636135b1565b5b6020026020010151905060076000838152602001908152602001600020546008600084815260200190815260200160002054106110d6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016110cd9061374f565b60405180910390fd5b6007600083815260200190815260200160002054811061112b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161112290613a09565b60405180910390fd5b6000151560096000848152602001908152602001600020600083815260200190815260200160002060009054906101000a900460ff161515146111a3576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161119a906137bb565b60405180910390fd5b600160096000848152602001908152602001600020600083815260200190815260200160002060006101000a81548160ff0219169083151502179055506008600083815260200190815260200160002060008154809291906112049061380a565b919050555061122533836001604051806020016040528060008152506116c5565b50508080600101915050611028565b50505050505050565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16905092915050565b60006112db61152d565b90508073ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff1614158015611320575061131e868261123d565b155b156113645780866040517fe237d92200000000000000000000000000000000000000000000000000000000815260040161135b92919061351c565b60405180910390fd5b61137186868686866119bc565b505050505050565b611381611493565b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16036113f35760006040517f1e4fbdf70000000000000000000000000000000000000000000000000000000081526004016113ea9190612bbc565b60405180910390fd5b6113fc81611786565b50565b611407611493565b61142533838360ff16604051806020016040528060008152506116c5565b5050565b60007f01ffc9a7000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916149050919050565b61149b61152d565b73ffffffffffffffffffffffffffffffffffffffff166114b9610eaf565b73ffffffffffffffffffffffffffffffffffffffff1614611518576114dc61152d565b6040517f118cdaa700000000000000000000000000000000000000000000000000000000815260040161150f9190612bbc565b60405180910390fd5b565b80600290816115299190613bd5565b5050565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff16036115a75760006040517f57f447ce00000000000000000000000000000000000000000000000000000000815260040161159e9190612bbc565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff16036116195760006040517f01a835140000000000000000000000000000000000000000000000000000000081526004016116109190612bbc565b60405180910390fd5b6116268585858585611ac7565b5050505050565b600080836040516020016116419190613d29565b604051602081830303815290604052805190602001209050600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166116a58483611b7990919063ffffffff16565b73ffffffffffffffffffffffffffffffffffffffff161491505092915050565b600073ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff16036117375760006040517f57f447ce00000000000000000000000000000000000000000000000000000000815260040161172e9190612bbc565b60405180910390fd5b6000806117448585611ba5565b91509150611756600087848487611ac7565b505050505050565b600060208202602084010151905092915050565b600060208202602084010151905092915050565b6000600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905081600360006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16036118be5760006040517fced3e1000000000000000000000000000000000000000000000000000000000081526004016118b59190612bbc565b60405180910390fd5b80600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31836040516119af9190612908565b60405180910390a3505050565b600073ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff1603611a2e5760006040517f57f447ce000000000000000000000000000000000000000000000000000000008152600401611a259190612bbc565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff1603611aa05760006040517f01a83514000000000000000000000000000000000000000000000000000000008152600401611a979190612bbc565b60405180910390fd5b600080611aad8585611ba5565b91509150611abe8787848487611ac7565b50505050505050565b611ad385858585611bd5565b600073ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff1614611b72576000611b1161152d565b90506001845103611b61576000611b3260008661177290919063ffffffff16565b90506000611b4a60008661177290919063ffffffff16565b9050611b5a838989858589611be7565b5050611b70565b611b6f818787878787611d9b565b5b505b5050505050565b600080600080611b898686611f4f565b925092509250611b998282611fab565b82935050505092915050565b60608060405191506001825283602083015260408201905060018152826020820152604081016040529250929050565b611be18484848461210f565b50505050565b60008473ffffffffffffffffffffffffffffffffffffffff163b1115611d93578373ffffffffffffffffffffffffffffffffffffffff1663f23a6e6187878686866040518663ffffffff1660e01b8152600401611c48959493929190613da4565b6020604051808303816000875af1925050508015611c8457506040513d601f19601f82011682018060405250810190611c819190613e13565b60015b611d08573d8060008114611cb4576040519150601f19603f3d011682016040523d82523d6000602084013e611cb9565b606091505b506000815103611d0057846040517f57f447ce000000000000000000000000000000000000000000000000000000008152600401611cf79190612bbc565b60405180910390fd5b805181602001fd5b63f23a6e6160e01b7bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916817bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614611d9157846040517f57f447ce000000000000000000000000000000000000000000000000000000008152600401611d889190612bbc565b60405180910390fd5b505b505050505050565b60008473ffffffffffffffffffffffffffffffffffffffff163b1115611f47578373ffffffffffffffffffffffffffffffffffffffff1663bc197c8187878686866040518663ffffffff1660e01b8152600401611dfc959493929190613e40565b6020604051808303816000875af1925050508015611e3857506040513d601f19601f82011682018060405250810190611e359190613e13565b60015b611ebc573d8060008114611e68576040519150601f19603f3d011682016040523d82523d6000602084013e611e6d565b606091505b506000815103611eb457846040517f57f447ce000000000000000000000000000000000000000000000000000000008152600401611eab9190612bbc565b60405180910390fd5b805181602001fd5b63bc197c8160e01b7bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916817bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614611f4557846040517f57f447ce000000000000000000000000000000000000000000000000000000008152600401611f3c9190612bbc565b60405180910390fd5b505b505050505050565b60008060006041845103611f945760008060006020870151925060408701519150606087015160001a9050611f86888285856122ba565b955095509550505050611fa4565b60006002855160001b9250925092505b9250925092565b60006003811115611fbf57611fbe613ea8565b5b826003811115611fd257611fd1613ea8565b5b031561210b5760016003811115611fec57611feb613ea8565b5b826003811115611fff57611ffe613ea8565b5b03612036576040517ff645eedf00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6002600381111561204a57612049613ea8565b5b82600381111561205d5761205c613ea8565b5b036120a2578060001c6040517ffce698f7000000000000000000000000000000000000000000000000000000008152600401612099919061284d565b60405180910390fd5b6003808111156120b5576120b4613ea8565b5b8260038111156120c8576120c7613ea8565b5b0361210a57806040517fd78bce0c0000000000000000000000000000000000000000000000000000000081526004016121019190613ee6565b60405180910390fd5b5b5050565b61211b848484846123ae565b600073ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff16036121f5576000805b83518110156121d9576000838281518110612171576121706135b1565b5b602002602001015190508060046000878581518110612193576121926135b1565b5b6020026020010151815260200190815260200160002060008282546121b89190613f01565b9250508190555080836121cb9190613f01565b925050806001019050612153565b5080600560008282546121ec9190613f01565b92505081905550505b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16036122b4576000805b83518110156122a157600083828151811061224b5761224a6135b1565b5b60200260200101519050806004600087858151811061226d5761226c6135b1565b5b602002602001015181526020019081526020016000206000828254039250508190555080830192505080600101905061222d565b5080600560008282540392505081905550505b50505050565b60008060007f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08460001c11156122fa5760006003859250925092506123a4565b60006001888888886040516000815260200160405260405161231f9493929190613f44565b6020604051602081039080840390855afa158015612341573d6000803e3d6000fd5b505050602060405103519050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff160361239557600060016000801b935093509350506123a4565b8060008060001b935093509350505b9450945094915050565b80518251146123f857815181516040517f5b0599910000000000000000000000000000000000000000000000000000000081526004016123ef929190613852565b60405180910390fd5b600061240261152d565b905060005b8351811015612611576000612425828661177290919063ffffffff16565b9050600061243c838661177290919063ffffffff16565b9050600073ffffffffffffffffffffffffffffffffffffffff168873ffffffffffffffffffffffffffffffffffffffff161461256957600080600084815260200190815260200160002060008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205490508181101561251157888183856040517f03dee4c50000000000000000000000000000000000000000000000000000000081526004016125089493929190613f89565b60405180910390fd5b81810360008085815260200190815260200160002060008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550505b600073ffffffffffffffffffffffffffffffffffffffff168773ffffffffffffffffffffffffffffffffffffffff1614612604578060008084815260200190815260200160002060008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546125fc9190613f01565b925050819055505b5050806001019050612407565b5060018351036126d057600061263160008561177290919063ffffffff16565b9050600061264960008561177290919063ffffffff16565b90508573ffffffffffffffffffffffffffffffffffffffff168773ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f6285856040516126c1929190613852565b60405180910390a4505061274f565b8373ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff167f4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb8686604051612746929190613fce565b60405180910390a45b5050505050565b6000604051905090565b600080fd5b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006127958261276a565b9050919050565b6127a58161278a565b81146127b057600080fd5b50565b6000813590506127c28161279c565b92915050565b6000819050919050565b6127db816127c8565b81146127e657600080fd5b50565b6000813590506127f8816127d2565b92915050565b6000806040838503121561281557612814612760565b5b6000612823858286016127b3565b9250506020612834858286016127e9565b9150509250929050565b612847816127c8565b82525050565b6000602082019050612862600083018461283e565b92915050565b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b61289d81612868565b81146128a857600080fd5b50565b6000813590506128ba81612894565b92915050565b6000602082840312156128d6576128d5612760565b5b60006128e4848285016128ab565b91505092915050565b60008115159050919050565b612902816128ed565b82525050565b600060208201905061291d60008301846128f9565b92915050565b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6129768261292d565b810181811067ffffffffffffffff821117156129955761299461293e565b5b80604052505050565b60006129a8612756565b90506129b4828261296d565b919050565b600067ffffffffffffffff8211156129d4576129d361293e565b5b6129dd8261292d565b9050602081019050919050565b82818337600083830152505050565b6000612a0c612a07846129b9565b61299e565b905082815260208101848484011115612a2857612a27612928565b5b612a338482856129ea565b509392505050565b600082601f830112612a5057612a4f612923565b5b8135612a608482602086016129f9565b91505092915050565b600060208284031215612a7f57612a7e612760565b5b600082013567ffffffffffffffff811115612a9d57612a9c612765565b5b612aa984828501612a3b565b91505092915050565b600060208284031215612ac857612ac7612760565b5b6000612ad6848285016127b3565b91505092915050565b600081519050919050565b600082825260208201905092915050565b60005b83811015612b19578082015181840152602081019050612afe565b60008484015250505050565b6000612b3082612adf565b612b3a8185612aea565b9350612b4a818560208601612afb565b612b538161292d565b840191505092915050565b60006020820190508181036000830152612b788184612b25565b905092915050565b600060208284031215612b9657612b95612760565b5b6000612ba4848285016127e9565b91505092915050565b612bb68161278a565b82525050565b6000602082019050612bd16000830184612bad565b92915050565b60008060408385031215612bee57612bed612760565b5b6000612bfc858286016127e9565b9250506020612c0d858286016127e9565b9150509250929050565b600067ffffffffffffffff821115612c3257612c3161293e565b5b602082029050602081019050919050565b600080fd5b6000612c5b612c5684612c17565b61299e565b90508083825260208201905060208402830185811115612c7e57612c7d612c43565b5b835b81811015612ca75780612c9388826127e9565b845260208401935050602081019050612c80565b5050509392505050565b600082601f830112612cc657612cc5612923565b5b8135612cd6848260208601612c48565b91505092915050565b600067ffffffffffffffff821115612cfa57612cf961293e565b5b612d038261292d565b9050602081019050919050565b6000612d23612d1e84612cdf565b61299e565b905082815260208101848484011115612d3f57612d3e612928565b5b612d4a8482856129ea565b509392505050565b600082601f830112612d6757612d66612923565b5b8135612d77848260208601612d10565b91505092915050565b600080600080600060a08688031215612d9c57612d9b612760565b5b6000612daa888289016127b3565b9550506020612dbb888289016127b3565b945050604086013567ffffffffffffffff811115612ddc57612ddb612765565b5b612de888828901612cb1565b935050606086013567ffffffffffffffff811115612e0957612e08612765565b5b612e1588828901612cb1565b925050608086013567ffffffffffffffff811115612e3657612e35612765565b5b612e4288828901612d52565b9150509295509295909350565b60008060408385031215612e6657612e65612760565b5b600083013567ffffffffffffffff811115612e8457612e83612765565b5b612e9085828601612cb1565b925050602083013567ffffffffffffffff811115612eb157612eb0612765565b5b612ebd85828601612cb1565b9150509250929050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b612efc816128ed565b82525050565b6000612f0e8383612ef3565b60208301905092915050565b6000602082019050919050565b6000612f3282612ec7565b612f3c8185612ed2565b9350612f4783612ee3565b8060005b83811015612f78578151612f5f8882612f02565b9750612f6a83612f1a565b925050600181019050612f4b565b5085935050505092915050565b60006020820190508181036000830152612f9f8184612f27565b905092915050565b60008060008060808587031215612fc157612fc0612760565b5b6000612fcf878288016127e9565b9450506020612fe0878288016127e9565b9350506040612ff1878288016127e9565b925050606085013567ffffffffffffffff81111561301257613011612765565b5b61301e87828801612d52565b91505092959194509250565b600067ffffffffffffffff8211156130455761304461293e565b5b602082029050602081019050919050565b60006130696130648461302a565b61299e565b9050808382526020820190506020840283018581111561308c5761308b612c43565b5b835b818110156130b557806130a188826127b3565b84526020840193505060208101905061308e565b5050509392505050565b600082601f8301126130d4576130d3612923565b5b81356130e4848260208601613056565b91505092915050565b6000806040838503121561310457613103612760565b5b600083013567ffffffffffffffff81111561312257613121612765565b5b61312e858286016130bf565b925050602083013567ffffffffffffffff81111561314f5761314e612765565b5b61315b85828601612cb1565b9150509250929050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b61319a816127c8565b82525050565b60006131ac8383613191565b60208301905092915050565b6000602082019050919050565b60006131d082613165565b6131da8185613170565b93506131e583613181565b8060005b838110156132165781516131fd88826131a0565b9750613208836131b8565b9250506001810190506131e9565b5085935050505092915050565b6000602082019050818103600083015261323d81846131c5565b905092915050565b61324e816128ed565b811461325957600080fd5b50565b60008135905061326b81613245565b92915050565b6000806040838503121561328857613287612760565b5b6000613296858286016127b3565b92505060206132a78582860161325c565b9150509250929050565b600080600080608085870312156132cb576132ca612760565b5b600085013567ffffffffffffffff8111156132e9576132e8612765565b5b6132f587828801612cb1565b945050602085013567ffffffffffffffff81111561331657613315612765565b5b61332287828801612cb1565b9350506040613333878288016127e9565b925050606085013567ffffffffffffffff81111561335457613353612765565b5b61336087828801612d52565b91505092959194509250565b6000806040838503121561338357613382612760565b5b6000613391858286016127b3565b92505060206133a2858286016127b3565b9150509250929050565b600080600080600060a086880312156133c8576133c7612760565b5b60006133d6888289016127b3565b95505060206133e7888289016127b3565b94505060406133f8888289016127e9565b9350506060613409888289016127e9565b925050608086013567ffffffffffffffff81111561342a57613429612765565b5b61343688828901612d52565b9150509295509295909350565b600060ff82169050919050565b61345981613443565b811461346457600080fd5b50565b60008135905061347681613450565b92915050565b6000806040838503121561349357613492612760565b5b60006134a1858286016127e9565b92505060206134b285828601613467565b9150509250929050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b6000600282049050600182168061350357607f821691505b602082108103613516576135156134bc565b5b50919050565b60006040820190506135316000830185612bad565b61353e6020830184612bad565b9392505050565b7f746f6b656e496420636c61696d4964206d69736d617463680000000000000000600082015250565b600061357b601883612aea565b915061358682613545565b602082019050919050565b600060208201905081810360008301526135aa8161356e565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60008160601b9050919050565b60006135f8826135e0565b9050919050565b600061360a826135ed565b9050919050565b61362261361d8261278a565b6135ff565b82525050565b6000819050919050565b61364361363e826127c8565b613628565b82525050565b60006136558287613611565b6014820191506136658286613632565b6020820191506136758285613632565b6020820191506136858284613632565b60208201915081905095945050505050565b7f496e76616c6964207369676e6174757265000000000000000000000000000000600082015250565b60006136cd601183612aea565b91506136d882613697565b602082019050919050565b600060208201905081810360008301526136fc816136c0565b9050919050565b7f4d617820737570706c7920657863656564656400000000000000000000000000600082015250565b6000613739601383612aea565b915061374482613703565b602082019050919050565b600060208201905081810360008301526137688161372c565b9050919050565b7f426f6f7374657220616c726561647920636c61696d6564000000000000000000600082015250565b60006137a5601783612aea565b91506137b08261376f565b602082019050919050565b600060208201905081810360008301526137d481613798565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000613815826127c8565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8203613847576138466137db565b5b600182019050919050565b6000604082019050613867600083018561283e565b613874602083018461283e565b9392505050565b600081905092915050565b61388f816127c8565b82525050565b60006138a18383613886565b60208301905092915050565b60006138b882613165565b6138c2818561387b565b93506138cd83613181565b8060005b838110156138fe5781516138e58882613895565b97506138f0836131b8565b9250506001810190506138d1565b5085935050505092915050565b60006139178287613611565b60148201915061392782866138ad565b915061393382856138ad565b915061393f8284613632565b60208201915081905095945050505050565b7f6d697373696e6720746f6b656e496473206f7220636c61696d49647300000000600082015250565b6000613987601c83612aea565b915061399282613951565b602082019050919050565b600060208201905081810360008301526139b68161397a565b9050919050565b7f436c61696d206964206578636565646564206d617820737570706c7900000000600082015250565b60006139f3601c83612aea565b91506139fe826139bd565b602082019050919050565b60006020820190508181036000830152613a22816139e6565b9050919050565b60008190508160005260206000209050919050565b60006020601f8301049050919050565b600082821b905092915050565b600060088302613a8b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82613a4e565b613a958683613a4e565b95508019841693508086168417925050509392505050565b6000819050919050565b6000613ad2613acd613ac8846127c8565b613aad565b6127c8565b9050919050565b6000819050919050565b613aec83613ab7565b613b00613af882613ad9565b848454613a5b565b825550505050565b600090565b613b15613b08565b613b20818484613ae3565b505050565b5b81811015613b4457613b39600082613b0d565b600181019050613b26565b5050565b601f821115613b8957613b5a81613a29565b613b6384613a3e565b81016020851015613b72578190505b613b86613b7e85613a3e565b830182613b25565b50505b505050565b600082821c905092915050565b6000613bac60001984600802613b8e565b1980831691505092915050565b6000613bc58383613b9b565b9150826002028217905092915050565b613bde82612adf565b67ffffffffffffffff811115613bf757613bf661293e565b5b613c0182546134eb565b613c0c828285613b48565b600060209050601f831160018114613c3f5760008415613c2d578287015190505b613c378582613bb9565b865550613c9f565b601f198416613c4d86613a29565b60005b82811015613c7557848901518255600182019150602085019450602081019050613c50565b86831015613c925784890151613c8e601f891682613b9b565b8355505b6001600288020188555050505b505050505050565b600081905092915050565b7f19457468657265756d205369676e6564204d6573736167653a0a333200000000600082015250565b6000613ce8601c83613ca7565b9150613cf382613cb2565b601c82019050919050565b6000819050919050565b6000819050919050565b613d23613d1e82613cfe565b613d08565b82525050565b6000613d3482613cdb565b9150613d408284613d12565b60208201915081905092915050565b600081519050919050565b600082825260208201905092915050565b6000613d7682613d4f565b613d808185613d5a565b9350613d90818560208601612afb565b613d998161292d565b840191505092915050565b600060a082019050613db96000830188612bad565b613dc66020830187612bad565b613dd3604083018661283e565b613de0606083018561283e565b8181036080830152613df28184613d6b565b90509695505050505050565b600081519050613e0d81612894565b92915050565b600060208284031215613e2957613e28612760565b5b6000613e3784828501613dfe565b91505092915050565b600060a082019050613e556000830188612bad565b613e626020830187612bad565b8181036040830152613e7481866131c5565b90508181036060830152613e8881856131c5565b90508181036080830152613e9c8184613d6b565b90509695505050505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b613ee081613cfe565b82525050565b6000602082019050613efb6000830184613ed7565b92915050565b6000613f0c826127c8565b9150613f17836127c8565b9250828201905080821115613f2f57613f2e6137db565b5b92915050565b613f3e81613443565b82525050565b6000608082019050613f596000830187613ed7565b613f666020830186613f35565b613f736040830185613ed7565b613f806060830184613ed7565b95945050505050565b6000608082019050613f9e6000830187612bad565b613fab602083018661283e565b613fb8604083018561283e565b613fc5606083018461283e565b95945050505050565b60006040820190508181036000830152613fe881856131c5565b90508181036020830152613ffc81846131c5565b9050939250505056fea2646970667358221220efbfef5d079ebc457ba49b2110e0686595ab9aab06826c9ff13814bf76cb1ee064736f6c63430008180033
Verified Source Code Full Match
Compiler: v0.8.24+commit.e11b9ed9
EVM: paris
Optimization: No
BoosterNFT.sol 153 lines
// SPDX-License-Identifier: MIT
// Compatible with OpenZeppelin Contracts ^5.0.0
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Supply.sol";
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
contract Booster is ERC1155, Ownable, ERC1155Supply {
using ECDSA for bytes32;
address public signer;
mapping(uint256 => uint256) public maxSupply;
mapping(uint256 => uint256) public mintedSupply;
mapping(uint256 => mapping(uint256 => bool)) public claimStatusByID;
function claimStatusByIDByBatch(
uint256[] memory tokenIds,
uint256[] memory claimIds
) public view returns (bool[] memory) {
require(tokenIds.length == claimIds.length, "tokenId claimId mismatch");
bool[] memory results = new bool[](tokenIds.length);
for (uint256 i=0; i<tokenIds.length; i++) {
results[i] = claimStatusByID[tokenIds[i]][claimIds[i]];
}
return results;
}
constructor(
address _signer,
uint256[] memory maxSupplyInit,
string memory uri
)
ERC1155(
uri
)
Ownable(msg.sender)
{
signer = _signer;
uint256 maxSupplyInitLength = maxSupplyInit.length;
for (uint i=0; i< maxSupplyInitLength; i++) {
maxSupply[i] = maxSupplyInit[i];
}
}
function mintNFT(
uint256 tokenId,
uint256 claimId,
uint256 timestamp,
bytes memory signature
) external payable {
bytes32 msgHash = keccak256(
abi.encodePacked(
msg.sender,
tokenId,
claimId,
timestamp
)
);
require(isValidSignature(msgHash, signature), "Invalid signature");
require(mintedSupply[tokenId] < maxSupply[tokenId], "Max supply exceeded");
require(claimStatusByID[tokenId][claimId] == false, "Booster already claimed");
claimStatusByID[tokenId][claimId] = true;
mintedSupply[tokenId]++;
_mint(msg.sender, tokenId, 1, "");
}
function mintNFTs(
uint256[] memory tokenIds,
uint256[] memory claimIds,
uint256 timestamp,
bytes memory signature
) external payable {
bytes32 msgHash = keccak256(
abi.encodePacked(
msg.sender,
tokenIds,
claimIds,
timestamp
)
);
require(tokenIds.length == claimIds.length, "missing tokenIds or claimIds");
require(isValidSignature(msgHash, signature), "Invalid signature");
uint256 boosterLength = tokenIds.length;
for (uint256 i=0; i<boosterLength; i++) {
uint256 currentBoosterId = tokenIds[i];
uint256 currentBoosterClaimId = claimIds[i];
require(mintedSupply[currentBoosterId] < maxSupply[currentBoosterId], "Max supply exceeded");
require(currentBoosterClaimId < maxSupply[currentBoosterId], "Claim id exceeded max supply");
require(claimStatusByID[currentBoosterId][currentBoosterClaimId] == false, "Booster already claimed");
claimStatusByID[currentBoosterId][currentBoosterClaimId] = true;
mintedSupply[currentBoosterId]++;
_mint(msg.sender, currentBoosterId, 1, "");
}
}
function adminMint(
uint256 tokenId,
uint8 nftAmount
) external payable onlyOwner {
_mint(msg.sender, tokenId, nftAmount, "");
}
function updateMaxSupply(uint256 tokenId, uint256 _maxSupply) external onlyOwner {
maxSupply[tokenId] = _maxSupply;
}
function setURI(string memory newuri) public onlyOwner {
_setURI(newuri);
}
function setSignerAddress(address _signer) public onlyOwner {
signer = _signer;
}
function isValidSignature(
bytes32 hash,
bytes memory signature
) internal view returns (bool isValid) {
bytes32 signedHash = keccak256(
abi.encodePacked("\x19Ethereum Signed Message:\n32", hash)
);
return signedHash.recover(signature) == signer;
}
// override required by Solidity.
function _update(
address from,
address to,
uint256[] memory ids,
uint256[] memory values
) internal override(ERC1155, ERC1155Supply) {
super._update(from, to, ids, values);
}
function name() public pure returns (string memory) {
return "Node Booster";
}
function symbol() public pure returns (string memory) {
return "BST";
}
receive() external payable {}
fallback() external payable {}
}
Arrays.sol 127 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Arrays.sol)
pragma solidity ^0.8.20;
import {StorageSlot} from "./StorageSlot.sol";
import {Math} from "./math/Math.sol";
/**
* @dev Collection of functions related to array types.
*/
library Arrays {
using StorageSlot for bytes32;
/**
* @dev Searches a sorted `array` and returns the first index that contains
* a value greater or equal to `element`. If no such index exists (i.e. all
* values in the array are strictly less than `element`), the array length is
* returned. Time complexity O(log n).
*
* `array` is expected to be sorted in ascending order, and to contain no
* repeated elements.
*/
function findUpperBound(uint256[] storage array, uint256 element) internal view returns (uint256) {
uint256 low = 0;
uint256 high = array.length;
if (high == 0) {
return 0;
}
while (low < high) {
uint256 mid = Math.average(low, high);
// Note that mid will always be strictly less than high (i.e. it will be a valid array index)
// because Math.average rounds towards zero (it does integer division with truncation).
if (unsafeAccess(array, mid).value > element) {
high = mid;
} else {
low = mid + 1;
}
}
// At this point `low` is the exclusive upper bound. We will return the inclusive upper bound.
if (low > 0 && unsafeAccess(array, low - 1).value == element) {
return low - 1;
} else {
return low;
}
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeAccess(address[] storage arr, uint256 pos) internal pure returns (StorageSlot.AddressSlot storage) {
bytes32 slot;
// We use assembly to calculate the storage slot of the element at index `pos` of the dynamic array `arr`
// following https://docs.soliditylang.org/en/v0.8.20/internals/layout_in_storage.html#mappings-and-dynamic-arrays.
/// @solidity memory-safe-assembly
assembly {
mstore(0, arr.slot)
slot := add(keccak256(0, 0x20), pos)
}
return slot.getAddressSlot();
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeAccess(bytes32[] storage arr, uint256 pos) internal pure returns (StorageSlot.Bytes32Slot storage) {
bytes32 slot;
// We use assembly to calculate the storage slot of the element at index `pos` of the dynamic array `arr`
// following https://docs.soliditylang.org/en/v0.8.20/internals/layout_in_storage.html#mappings-and-dynamic-arrays.
/// @solidity memory-safe-assembly
assembly {
mstore(0, arr.slot)
slot := add(keccak256(0, 0x20), pos)
}
return slot.getBytes32Slot();
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeAccess(uint256[] storage arr, uint256 pos) internal pure returns (StorageSlot.Uint256Slot storage) {
bytes32 slot;
// We use assembly to calculate the storage slot of the element at index `pos` of the dynamic array `arr`
// following https://docs.soliditylang.org/en/v0.8.20/internals/layout_in_storage.html#mappings-and-dynamic-arrays.
/// @solidity memory-safe-assembly
assembly {
mstore(0, arr.slot)
slot := add(keccak256(0, 0x20), pos)
}
return slot.getUint256Slot();
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeMemoryAccess(uint256[] memory arr, uint256 pos) internal pure returns (uint256 res) {
assembly {
res := mload(add(add(arr, 0x20), mul(pos, 0x20)))
}
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeMemoryAccess(address[] memory arr, uint256 pos) internal pure returns (address res) {
assembly {
res := mload(add(add(arr, 0x20), mul(pos, 0x20)))
}
}
}
Context.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
Ownable.sol 100 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
Math.sol 415 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/Math.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
/**
* @dev Muldiv operation overflow.
*/
error MathOverflowedMulDiv();
enum Rounding {
Floor, // Toward negative infinity
Ceil, // Toward positive infinity
Trunc, // Toward zero
Expand // Away from zero
}
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the subtraction of two unsigned integers, with an overflow flag.
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds towards infinity instead
* of rounding towards zero.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
if (b == 0) {
// Guarantee the same behavior as in a regular Solidity division.
return a / b;
}
// (a + b - 1) / b can overflow on addition, so we distribute.
return a == 0 ? 0 : (a - 1) / b + 1;
}
/**
* @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
* denominator == 0.
* @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by
* Uniswap Labs also under MIT license.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0 = x * y; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
// Solidity will revert if denominator == 0, unlike the div opcode on its own.
// The surrounding unchecked block does not change this fact.
// See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
if (denominator <= prod1) {
revert MathOverflowedMulDiv();
}
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator.
// Always >= 1. See https://cs.stackexchange.com/q/138556/92363.
uint256 twos = denominator & (0 - denominator);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also
// works in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
* towards zero.
*
* Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
*/
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
// For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
//
// We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
// `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
//
// This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
// → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
// → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
//
// Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
uint256 result = 1 << (log2(a) >> 1);
// At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
// since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
// every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
// into the expected uint128 result.
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
/**
* @notice Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (unsignedRoundsUp(rounding) && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (unsignedRoundsUp(rounding) && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10 ** 64) {
value /= 10 ** 64;
result += 64;
}
if (value >= 10 ** 32) {
value /= 10 ** 32;
result += 32;
}
if (value >= 10 ** 16) {
value /= 10 ** 16;
result += 16;
}
if (value >= 10 ** 8) {
value /= 10 ** 8;
result += 8;
}
if (value >= 10 ** 4) {
value /= 10 ** 4;
result += 4;
}
if (value >= 10 ** 2) {
value /= 10 ** 2;
result += 2;
}
if (value >= 10 ** 1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (unsignedRoundsUp(rounding) && 10 ** result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256 of a positive value rounded towards zero.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 256, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (unsignedRoundsUp(rounding) && 1 << (result << 3) < value ? 1 : 0);
}
}
/**
* @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
*/
function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
return uint8(rounding) % 2 == 1;
}
}
StorageSlot.sol 135 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.
pragma solidity ^0.8.20;
/**
* @dev Library for reading and writing primitive types to specific storage slots.
*
* Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
*
* Example usage to set ERC1967 implementation slot:
* ```solidity
* contract ERC1967 {
* bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
*
* function _getImplementation() internal view returns (address) {
* return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
* }
*
* function _setImplementation(address newImplementation) internal {
* require(newImplementation.code.length > 0);
* StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
* }
* }
* ```
*/
library StorageSlot {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
struct StringSlot {
string value;
}
struct BytesSlot {
bytes value;
}
/**
* @dev Returns an `AddressSlot` with member `value` located at `slot`.
*/
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BooleanSlot` with member `value` located at `slot`.
*/
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
*/
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Uint256Slot` with member `value` located at `slot`.
*/
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` with member `value` located at `slot`.
*/
function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` representation of the string storage pointer `store`.
*/
function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := store.slot
}
}
/**
* @dev Returns an `BytesSlot` with member `value` located at `slot`.
*/
function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
*/
function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := store.slot
}
}
}
ERC1155.sol 468 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC1155/ERC1155.sol)
pragma solidity ^0.8.20;
import {IERC1155} from "./IERC1155.sol";
import {IERC1155Receiver} from "./IERC1155Receiver.sol";
import {IERC1155MetadataURI} from "./extensions/IERC1155MetadataURI.sol";
import {Context} from "../../utils/Context.sol";
import {IERC165, ERC165} from "../../utils/introspection/ERC165.sol";
import {Arrays} from "../../utils/Arrays.sol";
import {IERC1155Errors} from "../../interfaces/draft-IERC6093.sol";
/**
* @dev Implementation of the basic standard multi-token.
* See https://eips.ethereum.org/EIPS/eip-1155
* Originally based on code by Enjin: https://github.com/enjin/erc-1155
*/
abstract contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI, IERC1155Errors {
using Arrays for uint256[];
using Arrays for address[];
mapping(uint256 id => mapping(address account => uint256)) private _balances;
mapping(address account => mapping(address operator => bool)) private _operatorApprovals;
// Used as the URI for all token types by relying on ID substitution, e.g. https://token-cdn-domain/{id}.json
string private _uri;
/**
* @dev See {_setURI}.
*/
constructor(string memory uri_) {
_setURI(uri_);
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return
interfaceId == type(IERC1155).interfaceId ||
interfaceId == type(IERC1155MetadataURI).interfaceId ||
super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC1155MetadataURI-uri}.
*
* This implementation returns the same URI for *all* token types. It relies
* on the token type ID substitution mechanism
* https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the EIP].
*
* Clients calling this function must replace the `\{id\}` substring with the
* actual token type ID.
*/
function uri(uint256 /* id */) public view virtual returns (string memory) {
return _uri;
}
/**
* @dev See {IERC1155-balanceOf}.
*/
function balanceOf(address account, uint256 id) public view virtual returns (uint256) {
return _balances[id][account];
}
/**
* @dev See {IERC1155-balanceOfBatch}.
*
* Requirements:
*
* - `accounts` and `ids` must have the same length.
*/
function balanceOfBatch(
address[] memory accounts,
uint256[] memory ids
) public view virtual returns (uint256[] memory) {
if (accounts.length != ids.length) {
revert ERC1155InvalidArrayLength(ids.length, accounts.length);
}
uint256[] memory batchBalances = new uint256[](accounts.length);
for (uint256 i = 0; i < accounts.length; ++i) {
batchBalances[i] = balanceOf(accounts.unsafeMemoryAccess(i), ids.unsafeMemoryAccess(i));
}
return batchBalances;
}
/**
* @dev See {IERC1155-setApprovalForAll}.
*/
function setApprovalForAll(address operator, bool approved) public virtual {
_setApprovalForAll(_msgSender(), operator, approved);
}
/**
* @dev See {IERC1155-isApprovedForAll}.
*/
function isApprovedForAll(address account, address operator) public view virtual returns (bool) {
return _operatorApprovals[account][operator];
}
/**
* @dev See {IERC1155-safeTransferFrom}.
*/
function safeTransferFrom(address from, address to, uint256 id, uint256 value, bytes memory data) public virtual {
address sender = _msgSender();
if (from != sender && !isApprovedForAll(from, sender)) {
revert ERC1155MissingApprovalForAll(sender, from);
}
_safeTransferFrom(from, to, id, value, data);
}
/**
* @dev See {IERC1155-safeBatchTransferFrom}.
*/
function safeBatchTransferFrom(
address from,
address to,
uint256[] memory ids,
uint256[] memory values,
bytes memory data
) public virtual {
address sender = _msgSender();
if (from != sender && !isApprovedForAll(from, sender)) {
revert ERC1155MissingApprovalForAll(sender, from);
}
_safeBatchTransferFrom(from, to, ids, values, data);
}
/**
* @dev Transfers a `value` amount of tokens of type `id` from `from` to `to`. Will mint (or burn) if `from`
* (or `to`) is the zero address.
*
* Emits a {TransferSingle} event if the arrays contain one element, and {TransferBatch} otherwise.
*
* Requirements:
*
* - If `to` refers to a smart contract, it must implement either {IERC1155Receiver-onERC1155Received}
* or {IERC1155Receiver-onERC1155BatchReceived} and return the acceptance magic value.
* - `ids` and `values` must have the same length.
*
* NOTE: The ERC-1155 acceptance check is not performed in this function. See {_updateWithAcceptanceCheck} instead.
*/
function _update(address from, address to, uint256[] memory ids, uint256[] memory values) internal virtual {
if (ids.length != values.length) {
revert ERC1155InvalidArrayLength(ids.length, values.length);
}
address operator = _msgSender();
for (uint256 i = 0; i < ids.length; ++i) {
uint256 id = ids.unsafeMemoryAccess(i);
uint256 value = values.unsafeMemoryAccess(i);
if (from != address(0)) {
uint256 fromBalance = _balances[id][from];
if (fromBalance < value) {
revert ERC1155InsufficientBalance(from, fromBalance, value, id);
}
unchecked {
// Overflow not possible: value <= fromBalance
_balances[id][from] = fromBalance - value;
}
}
if (to != address(0)) {
_balances[id][to] += value;
}
}
if (ids.length == 1) {
uint256 id = ids.unsafeMemoryAccess(0);
uint256 value = values.unsafeMemoryAccess(0);
emit TransferSingle(operator, from, to, id, value);
} else {
emit TransferBatch(operator, from, to, ids, values);
}
}
/**
* @dev Version of {_update} that performs the token acceptance check by calling
* {IERC1155Receiver-onERC1155Received} or {IERC1155Receiver-onERC1155BatchReceived} on the receiver address if it
* contains code (eg. is a smart contract at the moment of execution).
*
* IMPORTANT: Overriding this function is discouraged because it poses a reentrancy risk from the receiver. So any
* update to the contract state after this function would break the check-effect-interaction pattern. Consider
* overriding {_update} instead.
*/
function _updateWithAcceptanceCheck(
address from,
address to,
uint256[] memory ids,
uint256[] memory values,
bytes memory data
) internal virtual {
_update(from, to, ids, values);
if (to != address(0)) {
address operator = _msgSender();
if (ids.length == 1) {
uint256 id = ids.unsafeMemoryAccess(0);
uint256 value = values.unsafeMemoryAccess(0);
_doSafeTransferAcceptanceCheck(operator, from, to, id, value, data);
} else {
_doSafeBatchTransferAcceptanceCheck(operator, from, to, ids, values, data);
}
}
}
/**
* @dev Transfers a `value` tokens of token type `id` from `from` to `to`.
*
* Emits a {TransferSingle} event.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `from` must have a balance of tokens of type `id` of at least `value` amount.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
* acceptance magic value.
*/
function _safeTransferFrom(address from, address to, uint256 id, uint256 value, bytes memory data) internal {
if (to == address(0)) {
revert ERC1155InvalidReceiver(address(0));
}
if (from == address(0)) {
revert ERC1155InvalidSender(address(0));
}
(uint256[] memory ids, uint256[] memory values) = _asSingletonArrays(id, value);
_updateWithAcceptanceCheck(from, to, ids, values, data);
}
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_safeTransferFrom}.
*
* Emits a {TransferBatch} event.
*
* Requirements:
*
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
* acceptance magic value.
* - `ids` and `values` must have the same length.
*/
function _safeBatchTransferFrom(
address from,
address to,
uint256[] memory ids,
uint256[] memory values,
bytes memory data
) internal {
if (to == address(0)) {
revert ERC1155InvalidReceiver(address(0));
}
if (from == address(0)) {
revert ERC1155InvalidSender(address(0));
}
_updateWithAcceptanceCheck(from, to, ids, values, data);
}
/**
* @dev Sets a new URI for all token types, by relying on the token type ID
* substitution mechanism
* https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the EIP].
*
* By this mechanism, any occurrence of the `\{id\}` substring in either the
* URI or any of the values in the JSON file at said URI will be replaced by
* clients with the token type ID.
*
* For example, the `https://token-cdn-domain/\{id\}.json` URI would be
* interpreted by clients as
* `https://token-cdn-domain/000000000000000000000000000000000000000000000000000000000004cce0.json`
* for token type ID 0x4cce0.
*
* See {uri}.
*
* Because these URIs cannot be meaningfully represented by the {URI} event,
* this function emits no events.
*/
function _setURI(string memory newuri) internal virtual {
_uri = newuri;
}
/**
* @dev Creates a `value` amount of tokens of type `id`, and assigns them to `to`.
*
* Emits a {TransferSingle} event.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
* acceptance magic value.
*/
function _mint(address to, uint256 id, uint256 value, bytes memory data) internal {
if (to == address(0)) {
revert ERC1155InvalidReceiver(address(0));
}
(uint256[] memory ids, uint256[] memory values) = _asSingletonArrays(id, value);
_updateWithAcceptanceCheck(address(0), to, ids, values, data);
}
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_mint}.
*
* Emits a {TransferBatch} event.
*
* Requirements:
*
* - `ids` and `values` must have the same length.
* - `to` cannot be the zero address.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
* acceptance magic value.
*/
function _mintBatch(address to, uint256[] memory ids, uint256[] memory values, bytes memory data) internal {
if (to == address(0)) {
revert ERC1155InvalidReceiver(address(0));
}
_updateWithAcceptanceCheck(address(0), to, ids, values, data);
}
/**
* @dev Destroys a `value` amount of tokens of type `id` from `from`
*
* Emits a {TransferSingle} event.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `from` must have at least `value` amount of tokens of type `id`.
*/
function _burn(address from, uint256 id, uint256 value) internal {
if (from == address(0)) {
revert ERC1155InvalidSender(address(0));
}
(uint256[] memory ids, uint256[] memory values) = _asSingletonArrays(id, value);
_updateWithAcceptanceCheck(from, address(0), ids, values, "");
}
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_burn}.
*
* Emits a {TransferBatch} event.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `from` must have at least `value` amount of tokens of type `id`.
* - `ids` and `values` must have the same length.
*/
function _burnBatch(address from, uint256[] memory ids, uint256[] memory values) internal {
if (from == address(0)) {
revert ERC1155InvalidSender(address(0));
}
_updateWithAcceptanceCheck(from, address(0), ids, values, "");
}
/**
* @dev Approve `operator` to operate on all of `owner` tokens
*
* Emits an {ApprovalForAll} event.
*
* Requirements:
*
* - `operator` cannot be the zero address.
*/
function _setApprovalForAll(address owner, address operator, bool approved) internal virtual {
if (operator == address(0)) {
revert ERC1155InvalidOperator(address(0));
}
_operatorApprovals[owner][operator] = approved;
emit ApprovalForAll(owner, operator, approved);
}
/**
* @dev Performs an acceptance check by calling {IERC1155-onERC1155Received} on the `to` address
* if it contains code at the moment of execution.
*/
function _doSafeTransferAcceptanceCheck(
address operator,
address from,
address to,
uint256 id,
uint256 value,
bytes memory data
) private {
if (to.code.length > 0) {
try IERC1155Receiver(to).onERC1155Received(operator, from, id, value, data) returns (bytes4 response) {
if (response != IERC1155Receiver.onERC1155Received.selector) {
// Tokens rejected
revert ERC1155InvalidReceiver(to);
}
} catch (bytes memory reason) {
if (reason.length == 0) {
// non-ERC1155Receiver implementer
revert ERC1155InvalidReceiver(to);
} else {
/// @solidity memory-safe-assembly
assembly {
revert(add(32, reason), mload(reason))
}
}
}
}
}
/**
* @dev Performs a batch acceptance check by calling {IERC1155-onERC1155BatchReceived} on the `to` address
* if it contains code at the moment of execution.
*/
function _doSafeBatchTransferAcceptanceCheck(
address operator,
address from,
address to,
uint256[] memory ids,
uint256[] memory values,
bytes memory data
) private {
if (to.code.length > 0) {
try IERC1155Receiver(to).onERC1155BatchReceived(operator, from, ids, values, data) returns (
bytes4 response
) {
if (response != IERC1155Receiver.onERC1155BatchReceived.selector) {
// Tokens rejected
revert ERC1155InvalidReceiver(to);
}
} catch (bytes memory reason) {
if (reason.length == 0) {
// non-ERC1155Receiver implementer
revert ERC1155InvalidReceiver(to);
} else {
/// @solidity memory-safe-assembly
assembly {
revert(add(32, reason), mload(reason))
}
}
}
}
}
/**
* @dev Creates an array in memory with only one value for each of the elements provided.
*/
function _asSingletonArrays(
uint256 element1,
uint256 element2
) private pure returns (uint256[] memory array1, uint256[] memory array2) {
/// @solidity memory-safe-assembly
assembly {
// Load the free memory pointer
array1 := mload(0x40)
// Set array length to 1
mstore(array1, 1)
// Store the single element at the next word after the length (where content starts)
mstore(add(array1, 0x20), element1)
// Repeat for next array locating it right after the first array
array2 := add(array1, 0x40)
mstore(array2, 1)
mstore(add(array2, 0x20), element2)
// Update the free memory pointer by pointing after the second array
mstore(0x40, add(array2, 0x40))
}
}
}
IERC1155.sol 127 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (token/ERC1155/IERC1155.sol)
pragma solidity ^0.8.20;
import {IERC165} from "../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC1155 compliant contract, as defined in the
* https://eips.ethereum.org/EIPS/eip-1155[EIP].
*/
interface IERC1155 is IERC165 {
/**
* @dev Emitted when `value` amount of tokens of type `id` are transferred from `from` to `to` by `operator`.
*/
event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);
/**
* @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all
* transfers.
*/
event TransferBatch(
address indexed operator,
address indexed from,
address indexed to,
uint256[] ids,
uint256[] values
);
/**
* @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to
* `approved`.
*/
event ApprovalForAll(address indexed account, address indexed operator, bool approved);
/**
* @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI.
*
* If an {URI} event was emitted for `id`, the standard
* https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value
* returned by {IERC1155MetadataURI-uri}.
*/
event URI(string value, uint256 indexed id);
/**
* @dev Returns the value of tokens of token type `id` owned by `account`.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/
function balanceOf(address account, uint256 id) external view returns (uint256);
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}.
*
* Requirements:
*
* - `accounts` and `ids` must have the same length.
*/
function balanceOfBatch(
address[] calldata accounts,
uint256[] calldata ids
) external view returns (uint256[] memory);
/**
* @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`,
*
* Emits an {ApprovalForAll} event.
*
* Requirements:
*
* - `operator` cannot be the caller.
*/
function setApprovalForAll(address operator, bool approved) external;
/**
* @dev Returns true if `operator` is approved to transfer ``account``'s tokens.
*
* See {setApprovalForAll}.
*/
function isApprovedForAll(address account, address operator) external view returns (bool);
/**
* @dev Transfers a `value` amount of tokens of type `id` from `from` to `to`.
*
* WARNING: This function can potentially allow a reentrancy attack when transferring tokens
* to an untrusted contract, when invoking {onERC1155Received} on the receiver.
* Ensure to follow the checks-effects-interactions pattern and consider employing
* reentrancy guards when interacting with untrusted contracts.
*
* Emits a {TransferSingle} event.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - If the caller is not `from`, it must have been approved to spend ``from``'s tokens via {setApprovalForAll}.
* - `from` must have a balance of tokens of type `id` of at least `value` amount.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
* acceptance magic value.
*/
function safeTransferFrom(address from, address to, uint256 id, uint256 value, bytes calldata data) external;
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}.
*
* WARNING: This function can potentially allow a reentrancy attack when transferring tokens
* to an untrusted contract, when invoking {onERC1155BatchReceived} on the receiver.
* Ensure to follow the checks-effects-interactions pattern and consider employing
* reentrancy guards when interacting with untrusted contracts.
*
* Emits either a {TransferSingle} or a {TransferBatch} event, depending on the length of the array arguments.
*
* Requirements:
*
* - `ids` and `values` must have the same length.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
* acceptance magic value.
*/
function safeBatchTransferFrom(
address from,
address to,
uint256[] calldata ids,
uint256[] calldata values,
bytes calldata data
) external;
}
ECDSA.sol 174 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/ECDSA.sol)
pragma solidity ^0.8.20;
/**
* @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
*
* These functions can be used to verify that a message was signed by the holder
* of the private keys of a given address.
*/
library ECDSA {
enum RecoverError {
NoError,
InvalidSignature,
InvalidSignatureLength,
InvalidSignatureS
}
/**
* @dev The signature derives the `address(0)`.
*/
error ECDSAInvalidSignature();
/**
* @dev The signature has an invalid length.
*/
error ECDSAInvalidSignatureLength(uint256 length);
/**
* @dev The signature has an S value that is in the upper half order.
*/
error ECDSAInvalidSignatureS(bytes32 s);
/**
* @dev Returns the address that signed a hashed message (`hash`) with `signature` or an error. This will not
* return address(0) without also returning an error description. Errors are documented using an enum (error type)
* and a bytes32 providing additional information about the error.
*
* If no error is returned, then the address can be used for verification purposes.
*
* The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.
*
* Documentation for signature generation:
* - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
* - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
*/
function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError, bytes32) {
if (signature.length == 65) {
bytes32 r;
bytes32 s;
uint8 v;
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
/// @solidity memory-safe-assembly
assembly {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
v := byte(0, mload(add(signature, 0x60)))
}
return tryRecover(hash, v, r, s);
} else {
return (address(0), RecoverError.InvalidSignatureLength, bytes32(signature.length));
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature`. This address can then be used for verification purposes.
*
* The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.
*/
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
(address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, signature);
_throwError(error, errorArg);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
*
* See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
*/
function tryRecover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address, RecoverError, bytes32) {
unchecked {
bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
// We do not check for an overflow here since the shift operation results in 0 or 1.
uint8 v = uint8((uint256(vs) >> 255) + 27);
return tryRecover(hash, v, r, s);
}
}
/**
* @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
*/
function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {
(address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, r, vs);
_throwError(error, errorArg);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `v`,
* `r` and `s` signature fields separately.
*/
function tryRecover(
bytes32 hash,
uint8 v,
bytes32 r,
bytes32 s
) internal pure returns (address, RecoverError, bytes32) {
// EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
// unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
// the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
// signatures from current libraries generate a unique signature with an s-value in the lower half order.
//
// If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
// with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
// vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
// these malleable signatures as well.
if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
return (address(0), RecoverError.InvalidSignatureS, s);
}
// If the signature is valid (and not malleable), return the signer address
address signer = ecrecover(hash, v, r, s);
if (signer == address(0)) {
return (address(0), RecoverError.InvalidSignature, bytes32(0));
}
return (signer, RecoverError.NoError, bytes32(0));
}
/**
* @dev Overload of {ECDSA-recover} that receives the `v`,
* `r` and `s` signature fields separately.
*/
function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {
(address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, v, r, s);
_throwError(error, errorArg);
return recovered;
}
/**
* @dev Optionally reverts with the corresponding custom error according to the `error` argument provided.
*/
function _throwError(RecoverError error, bytes32 errorArg) private pure {
if (error == RecoverError.NoError) {
return; // no error: do nothing
} else if (error == RecoverError.InvalidSignature) {
revert ECDSAInvalidSignature();
} else if (error == RecoverError.InvalidSignatureLength) {
revert ECDSAInvalidSignatureLength(uint256(errorArg));
} else if (error == RecoverError.InvalidSignatureS) {
revert ECDSAInvalidSignatureS(errorArg);
}
}
}
draft-IERC6093.sol 161 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/draft-IERC6093.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard ERC20 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC20 tokens.
*/
interface IERC20Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC20InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC20InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.
* @param spender Address that may be allowed to operate on tokens without being their owner.
* @param allowance Amount of tokens a `spender` is allowed to operate with.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC20InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `spender` to be approved. Used in approvals.
* @param spender Address that may be allowed to operate on tokens without being their owner.
*/
error ERC20InvalidSpender(address spender);
}
/**
* @dev Standard ERC721 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC721 tokens.
*/
interface IERC721Errors {
/**
* @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in EIP-20.
* Used in balance queries.
* @param owner Address of the current owner of a token.
*/
error ERC721InvalidOwner(address owner);
/**
* @dev Indicates a `tokenId` whose `owner` is the zero address.
* @param tokenId Identifier number of a token.
*/
error ERC721NonexistentToken(uint256 tokenId);
/**
* @dev Indicates an error related to the ownership over a particular token. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param tokenId Identifier number of a token.
* @param owner Address of the current owner of a token.
*/
error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC721InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC721InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param tokenId Identifier number of a token.
*/
error ERC721InsufficientApproval(address operator, uint256 tokenId);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC721InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC721InvalidOperator(address operator);
}
/**
* @dev Standard ERC1155 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC1155 tokens.
*/
interface IERC1155Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
* @param tokenId Identifier number of a token.
*/
error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC1155InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC1155InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param owner Address of the current owner of a token.
*/
error ERC1155MissingApprovalForAll(address operator, address owner);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC1155InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC1155InvalidOperator(address operator);
/**
* @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.
* Used in batch transfers.
* @param idsLength Length of the array of token identifiers
* @param valuesLength Length of the array of token amounts
*/
error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);
}
ERC165.sol 27 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/ERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "./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);
* }
* ```
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
IERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/IERC165.sol)
pragma solidity ^0.8.20;
/**
* @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);
}
IERC1155Receiver.sol 59 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC1155/IERC1155Receiver.sol)
pragma solidity ^0.8.20;
import {IERC165} from "../../utils/introspection/IERC165.sol";
/**
* @dev Interface that must be implemented by smart contracts in order to receive
* ERC-1155 token transfers.
*/
interface IERC1155Receiver is IERC165 {
/**
* @dev Handles the receipt of a single ERC1155 token type. This function is
* called at the end of a `safeTransferFrom` after the balance has been updated.
*
* NOTE: To accept the transfer, this must return
* `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
* (i.e. 0xf23a6e61, or its own function selector).
*
* @param operator The address which initiated the transfer (i.e. msg.sender)
* @param from The address which previously owned the token
* @param id The ID of the token being transferred
* @param value The amount of tokens being transferred
* @param data Additional data with no specified format
* @return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed
*/
function onERC1155Received(
address operator,
address from,
uint256 id,
uint256 value,
bytes calldata data
) external returns (bytes4);
/**
* @dev Handles the receipt of a multiple ERC1155 token types. This function
* is called at the end of a `safeBatchTransferFrom` after the balances have
* been updated.
*
* NOTE: To accept the transfer(s), this must return
* `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
* (i.e. 0xbc197c81, or its own function selector).
*
* @param operator The address which initiated the batch transfer (i.e. msg.sender)
* @param from The address which previously owned the token
* @param ids An array containing ids of each token being transferred (order and length must match values array)
* @param values An array containing amounts of each token being transferred (order and length must match ids array)
* @param data Additional data with no specified format
* @return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed
*/
function onERC1155BatchReceived(
address operator,
address from,
uint256[] calldata ids,
uint256[] calldata values,
bytes calldata data
) external returns (bytes4);
}
ERC1155Supply.sol 87 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC1155/extensions/ERC1155Supply.sol)
pragma solidity ^0.8.20;
import {ERC1155} from "../ERC1155.sol";
/**
* @dev Extension of ERC1155 that adds tracking of total supply per id.
*
* Useful for scenarios where Fungible and Non-fungible tokens have to be
* clearly identified. Note: While a totalSupply of 1 might mean the
* corresponding is an NFT, there is no guarantees that no other token with the
* same id are not going to be minted.
*
* NOTE: This contract implies a global limit of 2**256 - 1 to the number of tokens
* that can be minted.
*
* CAUTION: This extension should not be added in an upgrade to an already deployed contract.
*/
abstract contract ERC1155Supply is ERC1155 {
mapping(uint256 id => uint256) private _totalSupply;
uint256 private _totalSupplyAll;
/**
* @dev Total value of tokens in with a given id.
*/
function totalSupply(uint256 id) public view virtual returns (uint256) {
return _totalSupply[id];
}
/**
* @dev Total value of tokens.
*/
function totalSupply() public view virtual returns (uint256) {
return _totalSupplyAll;
}
/**
* @dev Indicates whether any token exist with a given id, or not.
*/
function exists(uint256 id) public view virtual returns (bool) {
return totalSupply(id) > 0;
}
/**
* @dev See {ERC1155-_update}.
*/
function _update(
address from,
address to,
uint256[] memory ids,
uint256[] memory values
) internal virtual override {
super._update(from, to, ids, values);
if (from == address(0)) {
uint256 totalMintValue = 0;
for (uint256 i = 0; i < ids.length; ++i) {
uint256 value = values[i];
// Overflow check required: The rest of the code assumes that totalSupply never overflows
_totalSupply[ids[i]] += value;
totalMintValue += value;
}
// Overflow check required: The rest of the code assumes that totalSupplyAll never overflows
_totalSupplyAll += totalMintValue;
}
if (to == address(0)) {
uint256 totalBurnValue = 0;
for (uint256 i = 0; i < ids.length; ++i) {
uint256 value = values[i];
unchecked {
// Overflow not possible: values[i] <= balanceOf(from, ids[i]) <= totalSupply(ids[i])
_totalSupply[ids[i]] -= value;
// Overflow not possible: sum_i(values[i]) <= sum_i(totalSupply(ids[i])) <= totalSupplyAll
totalBurnValue += value;
}
}
unchecked {
// Overflow not possible: totalBurnValue = sum_i(values[i]) <= sum_i(totalSupply(ids[i])) <= totalSupplyAll
_totalSupplyAll -= totalBurnValue;
}
}
}
}
IERC1155MetadataURI.sol 20 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC1155/extensions/IERC1155MetadataURI.sol)
pragma solidity ^0.8.20;
import {IERC1155} from "../IERC1155.sol";
/**
* @dev Interface of the optional ERC1155MetadataExtension interface, as defined
* in the https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[EIP].
*/
interface IERC1155MetadataURI is IERC1155 {
/**
* @dev Returns the URI for token type `id`.
*
* If the `\{id\}` substring is present in the URI, it must be replaced by
* clients with the actual token type ID.
*/
function uri(uint256 id) external view returns (string memory);
}
Read Contract
balanceOf 0x00fdd58e → uint256
balanceOfBatch 0x4e1273f4 → uint256[]
claimStatusByID 0x62d9e314 → bool
claimStatusByIDByBatch 0x4041801d → bool[]
exists 0x4f558e79 → bool
isApprovedForAll 0xe985e9c5 → bool
maxSupply 0x869f7594 → uint256
mintedSupply 0x919956ef → uint256
name 0x06fdde03 → string
owner 0x8da5cb5b → address
signer 0x238ac933 → address
supportsInterface 0x01ffc9a7 → bool
symbol 0x95d89b41 → string
totalSupply 0x18160ddd → uint256
totalSupply 0xbd85b039 → uint256
uri 0x0e89341c → string
Write Contract 11 functions
These functions modify contract state and require a wallet transaction to execute.
adminMint 0xf7c8ae59
uint256 tokenId
uint8 nftAmount
mintNFT 0x4915f070
uint256 tokenId
uint256 claimId
uint256 timestamp
bytes signature
mintNFTs 0xcf6868d5
uint256[] tokenIds
uint256[] claimIds
uint256 timestamp
bytes signature
renounceOwnership 0x715018a6
No parameters
safeBatchTransferFrom 0x2eb2c2d6
address from
address to
uint256[] ids
uint256[] values
bytes data
safeTransferFrom 0xf242432a
address from
address to
uint256 id
uint256 value
bytes data
setApprovalForAll 0xa22cb465
address operator
bool approved
setSignerAddress 0x046dc166
address _signer
setURI 0x02fe5305
string newuri
transferOwnership 0xf2fde38b
address newOwner
updateMaxSupply 0x238e875f
uint256 tokenId
uint256 _maxSupply
Recent Transactions
No transactions found for this address