Address Contract Verified
Address
0x55902a29B6897a698eaF0d6A6B533cdBAa3c96c3
Balance
0 ETH
Nonce
1
Code Size
11321 bytes
Creator
0x796B0A87...366d at tx 0x8b47d7ae...f1c9ea
Indexed Transactions
0
Contract Bytecode
11321 bytes
0x608060405234801561001057600080fd5b50600436106102265760003560e01c80639f25cde71161012a578063d547741f116100bd578063e73496cd1161008c578063fe2f62da11610071578063fe2f62da146105a6578063fe55932a146105af578063ff395729146105c257600080fd5b8063e73496cd146104dc578063ebb7f415146104fc57600080fd5b8063d547741f14610498578063d853015e146104ab578063e07d5987146104c0578063e37b1be0146104d357600080fd5b8063b3e1e8ec116100f9578063b3e1e8ec1461044c578063b85b99c91461045f578063cc193fb014610472578063d092851b1461048557600080fd5b80639f25cde71461040b578063a17651c01461041e578063a217fddf14610431578063a7db76591461043957600080fd5b80632f2ff15d116101bd57806349af9cdd1161018c578063719ec6b111610171578063719ec6b1146103995780638edb6c69146103c157806391d14854146103d457600080fd5b806349af9cdd146103665780634ea099631461038657600080fd5b80632f2ff15d1461031a57806336568abe1461032d57806341a847be146103405780634716ac661461035357600080fd5b80631753a1f5116101f95780631753a1f5146102ba57806319c89bc2146102d15780631be6dd64146102e4578063248a9ca3146102f757600080fd5b806301f07aa21461022b57806301ffc9a7146102405780631400d1e41461026857806314d670491461027b575b600080fd5b61023e6102393660046121c2565b6105d5565b005b61025361024e3660046121fa565b610969565b60405190151581526020015b60405180910390f35b6102536102763660046122db565b6109a0565b6102a27f00000000000000000000000099f419934192f8de7bf53b490d5bdb88527654bf81565b6040516001600160a01b03909116815260200161025f565b6102c360065481565b60405190815260200161025f565b61023e6102df36600461232f565b610b0a565b6004546102a2906001600160a01b031681565b6102c361030536600461234a565b60009081526020819052604090206001015490565b61023e610328366004612378565b610b5f565b61023e61033b366004612378565b610b89565b61023e61034e36600461234a565b610c1a565b61023e610361366004612439565b610c38565b6102c361037436600461234a565b60086020526000908152604090205481565b61023e61039436600461234a565b610d38565b6004546103ae90600160a01b900461ffff1681565b60405161ffff909116815260200161025f565b61023e6103cf3660046124f5565b610f5c565b6102536103e2366004612378565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b61023e6104193660046125b9565b6111be565b61023e61042c36600461234a565b611211565b6102c3600081565b61023e61044736600461234a565b61122f565b61023e61045a36600461234a565b61124d565b61025361046d3660046122db565b6114c2565b6102c361048036600461234a565b6114ed565b61023e6104933660046125d6565b61155c565b61023e6104a6366004612378565b611587565b6102c3600080516020612be483398151915281565b6103ae6104ce36600461234a565b6115ac565b6102c360055481565b6104ef6104ea36600461234a565b6115e6565b60405161025f9190612648565b61059961050a36600461234a565b6040805160a08101825260008082526020820181905291810182905260608101829052608081019190915250600090815260036020908152604091829020825160a081018452905461ffff80821683526201000082048116938301939093526401000000008104831693820193909352600160301b830482166060820152600160401b90920416608082015290565b60405161025f91906126d9565b6102c360075481565b61023e6105bd366004612720565b611755565b6104ef6105d036600461234a565b611995565b6040516331a9108f60e11b815260048101839052829033906001600160a01b037f00000000000000000000000099f419934192f8de7bf53b490d5bdb88527654bf1690636352211e90602401602060405180830381865afa15801561063e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106629190612767565b6001600160a01b03161461068957604051636617cbc960e11b815260040160405180910390fd5b600083815260026020526040902080548491906106a590612784565b90506000036106c757604051636617cbc960e11b815260040160405180910390fd5b6000848152600260208181526040808420815160a08101835293015461ffff80821685526201000082048116938501939093526401000000008104831691840191909152600160301b810482166060840152600160401b900416608082015261073e90610739368790038701876127be565b611ba2565b905061074a8582611c60565b6107675760405163523016f160e11b815260040160405180910390fd5b6004546001600160a01b031663e0619a203361078287611d74565b6040516001600160e01b031960e085901b1681526001600160a01b039092166004830152602482015260606044820152600d60648201527f656e68616e636553746174757300000000000000000000000000000000000000608482015260a401600060405180830381600087803b1580156107fc57600080fd5b505af1158015610810573d6000803e3d6000fd5b505050600086815260026020818152604092839020835160a08101855292015461ffff80821684526201000082048116928401929092526401000000008104821693830193909352600160301b830481166060830152600160401b909204909116608082015261088a9150610739368790038701876127be565b6000868152600260208181526040808420855193810180549387015187840151606089015160809099015161ffff908116600160401b0269ffff0000000000000000199a8216600160301b0267ffff00000000000019938316640100000000029390931667ffffffff0000000019948316620100000263ffffffff1990991692909916919091179690961791909116959095179490941795909516919091179091555187927f6ea3cc43a0dfa371637b187693d56f122c140683c73a0278a2575ac1e3134e469261095a926127da565b60405180910390a25050505050565b60006001600160e01b03198216637965db0b60e01b148061099a57506301ffc9a760e01b6001600160e01b03198316145b92915050565b805160009081908390600a10156109bb575060009392505050565b8051821015610b0057603060f81b8183815181106109db576109db6128e6565b01602001516001600160f81b03191610801590610a1c5750603960f81b818381518110610a0a57610a0a6128e6565b01602001516001600160f81b03191611155b158015610a7e5750604160f81b818381518110610a3b57610a3b6128e6565b01602001516001600160f81b03191610801590610a7c5750605a60f81b818381518110610a6a57610a6a6128e6565b01602001516001600160f81b03191611155b155b8015610adf5750606160f81b818381518110610a9c57610a9c6128e6565b01602001516001600160f81b03191610801590610add5750607a60f81b818381518110610acb57610acb6128e6565b01602001516001600160f81b03191611155b155b15610aee575060009392505050565b81610af881612912565b9250506109bb565b5060019392505050565b600080516020612be4833981519152610b2281611dfc565b506004805461ffff909216600160a01b027fffffffffffffffffffff0000ffffffffffffffffffffffffffffffffffffffff909216919091179055565b600082815260208190526040902060010154610b7a81611dfc565b610b848383611e09565b505050565b6001600160a01b0381163314610c0c5760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c66000000000000000000000000000000000060648201526084015b60405180910390fd5b610c168282611ea7565b5050565b600080516020612be4833981519152610c3281611dfc565b50600655565b600080516020612be4833981519152610c5081611dfc565b60005b8251811015610d3257828181518110610c6e57610c6e6128e6565b6020026020010151600360008387610c86919061292b565b81526020808201929092526040908101600020835181549385015192850151606086015160809096015161ffff908116600160401b0269ffff000000000000000019978216600160301b0267ffff00000000000019938316640100000000029390931667ffffffff0000000019968316620100000263ffffffff199098169290941691909117959095179390931617919091179290921617905580610d2a81612912565b915050610c53565b50505050565b6040516331a9108f60e11b815260048101829052819033906001600160a01b037f00000000000000000000000099f419934192f8de7bf53b490d5bdb88527654bf1690636352211e90602401602060405180830381865afa158015610da1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610dc59190612767565b6001600160a01b031614610dec57604051636617cbc960e11b815260040160405180910390fd5b60008281526002602052604090208054839190610e0890612784565b9050600003610e2a57604051636617cbc960e11b815260040160405180910390fd5b600480546007546040516307030cd160e51b81523393810193909352602483015260606044830152600b60648301527f726573657446616d696c7900000000000000000000000000000000000000000060848301526001600160a01b03169063e0619a209060a401600060405180830381600087803b158015610eac57600080fd5b505af1158015610ec0573d6000803e3d6000fd5b5050506000848152600260208190526040909120600101805462010000900461ffff16925090610eef8361293e565b91906101000a81548161ffff021916908361ffff16021790555050827f6ea3cc43a0dfa371637b187693d56f122c140683c73a0278a2575ac1e3134e46600260008681526020019081526020016000206001604051610f4f9291906127da565b60405180910390a2505050565b600080516020612be4833981519152610f7481611dfc565b600454602083015161ffff600160a01b909204821691161115610faa57604051635728963560e11b815260040160405180910390fd5b8151610fb5906109a0565b610fd257604051632578ab6960e11b815260040160405180910390fd5b8151604051600191610fe39161295f565b9081526040519081900360200190205460ff161561101457604051630eed3dcb60e31b815260040160405180910390fd5b611022838360600151611c60565b61103f5760405163523016f160e11b815260040160405180910390fd5b600083815260026020526040808220905160019161105c9161297b565b9081526040805160209281900383019020805460ff1916931515939093179092556000858152600290915220825183919081906110999082612a3f565b506020828101516001838101805460408088015161ffff95861663ffffffff19938416176201000091871682021790935560609788015180516002909801805497820151828401519a83015160809093015199881698909416979097179286169093029190911767ffffffff0000000019166401000000009785169790970267ffff000000000000191696909617600160301b918416919091021769ffff00000000000000001916600160401b94909216939093021790558351915190918291611163919061295f565b9081526040805160209281900383018120805460ff19169415159490941790935560008681526002909252812085927f6ea3cc43a0dfa371637b187693d56f122c140683c73a0278a2575ac1e3134e4692610f4f92916127da565b600080516020612be48339815191526111d681611dfc565b50600480547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b0392909216919091179055565b600080516020612be483398151915261122981611dfc565b50600755565b600080516020612be483398151915261124781611dfc565b50600555565b6040516331a9108f60e11b815260048101829052819033906001600160a01b037f00000000000000000000000099f419934192f8de7bf53b490d5bdb88527654bf1690636352211e90602401602060405180830381865afa1580156112b6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112da9190612767565b6001600160a01b03161461130157604051636617cbc960e11b815260040160405180910390fd5b6000828152600260205260409020805483919061131d90612784565b905060000361133f57604051636617cbc960e11b815260040160405180910390fd5b600454600084815260026020526040902060019081015461ffff600160a01b90930483169261137092911690612aff565b61ffff16111561139357604051635728963560e11b815260040160405180910390fd5b6004546001600160a01b031663e0619a20336113ae86611f26565b6040516001600160e01b031960e085901b1681526001600160a01b039092166004830152602482015260606044820152600760648201527f7261697365557000000000000000000000000000000000000000000000000000608482015260a401600060405180830381600087803b15801561142857600080fd5b505af115801561143c573d6000803e3d6000fd5b5050506000848152600260205260408120600101805461ffff169250906114628361293e565b91906101000a81548161ffff021916908361ffff16021790555050827f6ea3cc43a0dfa371637b187693d56f122c140683c73a0278a2575ac1e3134e46600260008681526020019081526020016000206000604051610f4f9291906127da565b60006001826040516114d4919061295f565b9081526040519081900360200190205460ff1692915050565b60008181526002602081905260408220015461ffff600160401b8204811691600160301b810482169164010000000082048116916115349162010000820481169116612aff565b61153e9190612aff565b6115489190612aff565b6115529190612aff565b61ffff1692915050565b600080516020612be483398151915261157481611dfc565b5060009182526008602052604090912055565b6000828152602081905260409020600101546115a281611dfc565b610b848383611ea7565b6000600a82106115be57506064919050565b600382106115ce57506014919050565b600282106115de5750600f919050565b50600a919050565b6040805160808082018352606080835260006020808501829052848601829052855160a081018752828152908101829052948501819052848201819052918401919091528101919091526000828152600260205260409081902081516080810190925280548290829061165890612784565b80601f016020809104026020016040519081016040528092919081815260200182805461168490612784565b80156116d15780601f106116a6576101008083540402835291602001916116d1565b820191906000526020600020905b8154815290600101906020018083116116b457829003601f168201915b5050509183525050600182015461ffff80821660208085019190915262010000928390048216604080860191909152805160a08101825260029096015480841687529384048316918601919091526401000000008304821690850152600160301b82048116606085810191909152600160401b909204166080840152015292915050565b6040516331a9108f60e11b815260048101839052829033906001600160a01b037f00000000000000000000000099f419934192f8de7bf53b490d5bdb88527654bf1690636352211e90602401602060405180830381865afa1580156117be573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117e29190612767565b6001600160a01b03161461180957604051636617cbc960e11b815260040160405180910390fd5b60028251101561182c5760405163209c463160e21b815260040160405180910390fd5b611835826109a0565b61185257604051632578ab6960e11b815260040160405180910390fd5b600182604051611862919061295f565b9081526040519081900360200190205460ff161561189357604051630eed3dcb60e31b815260040160405180910390fd5b600480546005546040516307030cd160e51b81523393810193909352602483015260606044830152600760648301527f7365744e616d650000000000000000000000000000000000000000000000000060848301526001600160a01b03169063e0619a209060a401600060405180830381600087803b15801561191557600080fd5b505af1158015611929573d6000803e3d6000fd5b505050600084815260026020526040808220905191925060019161194d919061297b565b9081526040805160209281900383019020805460ff19169315159390931790925560008581526002909152206119838382612a3f565b5060018083604051611163919061295f565b6040805160808082018352606080835260006020808501829052848601829052855160a0810187528281529081018290529485018190528482018190529184019190915281019190915260008281526002602052604090819020815160808101909252805482908290611a0790612784565b80601f0160208091040260200160405190810160405280929190818152602001828054611a3390612784565b8015611a805780601f10611a5557610100808354040283529160200191611a80565b820191906000526020600020905b815481529060010190602001808311611a6357829003601f168201915b5050509183525050600182015461ffff80821660208085019190915262010000928390048216604080860191909152805160a080820183526002978801548086168352868104861683860152640100000000808204871684860152600160301b8083048816606086810191909152600160401b9384900489166080808801919091529a81019590955260008e815260038852868120875180870189529054808b1682528b81048b16828b01528481048b16828a01528381048b16828901528590048a16818d01528f82528c89529087902087519586018852909b0154808916855298890488169684019690965287048616938201939093529285048416908301529092041691810191909152919250611b9891611ba2565b6060820152919050565b6040805160a081018252600080825260208201819052918101829052606081018290526080810191909152825182518390611bde908390612aff565b61ffff169052506020808401519083018051611bfb908390612aff565b61ffff169052506040808401519083018051611c18908390612aff565b61ffff169052506060808401519083018051611c35908390612aff565b61ffff169052506080808401519083018051611c52908390612aff565b61ffff169052509092915050565b6000828152600360209081526040808320815160a081018352905461ffff80821683526201000082048116948301949094526401000000008104841692820192909252600160301b820483166060820152600160401b90910490911660808201528190611ccd9084611ba2565b60008581526002602052604081206001015491925090611cf09061ffff166115ac565b90508061ffff16826000015161ffff161180611d1757508061ffff16826020015161ffff16115b80611d2d57508061ffff16826040015161ffff16115b80611d4357508061ffff16826060015161ffff16115b80611d5957508061ffff16826080015161ffff16115b15611d695760009250505061099a565b506001949350505050565b6000611d8660a083016080840161232f565b611d96608084016060850161232f565b611da6606085016040860161232f565b611db6604086016020870161232f565b611dc3602087018761232f565b611dcd9190612aff565b611dd79190612aff565b611de19190612aff565b611deb9190612aff565b61ffff1660065461099a9190612b21565b611e068133611f8d565b50565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610c16576000828152602081815260408083206001600160a01b03851684529091529020805460ff19166001179055611e633390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1615610c16576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b600081815260026020819052604082206001015461ffff1690811115611f7857505060026000525060086020527f6add646517a5b0f6793cd5891b7937d28a5b2981a5d88ebc7cd776088fea90415490565b60009081526008602052604090205492915050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610c1657611fbe81612000565b611fc9836020612012565b604051602001611fda929190612b38565b60408051601f198184030181529082905262461bcd60e51b8252610c0391600401612bb9565b606061099a6001600160a01b03831660145b60606000612021836002612b21565b61202c90600261292b565b67ffffffffffffffff81111561204457612044612224565b6040519080825280601f01601f19166020018201604052801561206e576020820181803683370190505b509050600360fc1b81600081518110612089576120896128e6565b60200101906001600160f81b031916908160001a905350600f60fb1b816001815181106120b8576120b86128e6565b60200101906001600160f81b031916908160001a90535060006120dc846002612b21565b6120e790600161292b565b90505b600181111561216c577f303132333435363738396162636465660000000000000000000000000000000085600f1660108110612128576121286128e6565b1a60f81b82828151811061213e5761213e6128e6565b60200101906001600160f81b031916908160001a90535060049490941c9361216581612bcc565b90506120ea565b5083156121bb5760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610c03565b9392505050565b60008082840360c08112156121d657600080fd5b8335925060a0601f19820112156121ec57600080fd5b506020830190509250929050565b60006020828403121561220c57600080fd5b81356001600160e01b0319811681146121bb57600080fd5b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff8111828210171561226357612263612224565b604052919050565b600082601f83011261227c57600080fd5b813567ffffffffffffffff81111561229657612296612224565b6122a9601f8201601f191660200161223a565b8181528460208386010111156122be57600080fd5b816020850160208301376000918101602001919091529392505050565b6000602082840312156122ed57600080fd5b813567ffffffffffffffff81111561230457600080fd5b6123108482850161226b565b949350505050565b803561ffff8116811461232a57600080fd5b919050565b60006020828403121561234157600080fd5b6121bb82612318565b60006020828403121561235c57600080fd5b5035919050565b6001600160a01b0381168114611e0657600080fd5b6000806040838503121561238b57600080fd5b82359150602083013561239d81612363565b809150509250929050565b600060a082840312156123ba57600080fd5b60405160a0810181811067ffffffffffffffff821117156123dd576123dd612224565b6040529050806123ec83612318565b81526123fa60208401612318565b602082015261240b60408401612318565b604082015261241c60608401612318565b606082015261242d60808401612318565b60808201525092915050565b6000806040838503121561244c57600080fd5b8235915060208084013567ffffffffffffffff8082111561246c57600080fd5b818601915086601f83011261248057600080fd5b81358181111561249257612492612224565b6124a0848260051b0161223a565b818152848101925060a09182028401850191898311156124bf57600080fd5b938501935b828510156124e5576124d68a866123a8565b845293840193928501926124c4565b5080955050505050509250929050565b6000806040838503121561250857600080fd5b82359150602083013567ffffffffffffffff8082111561252757600080fd5b90840190610100828703121561253c57600080fd5b60405160808101818110838211171561255757612557612224565b60405282358281111561256957600080fd5b6125758882860161226b565b82525061258460208401612318565b602082015261259560408401612318565b60408201526125a787606085016123a8565b60608201528093505050509250929050565b6000602082840312156125cb57600080fd5b81356121bb81612363565b600080604083850312156125e957600080fd5b50508035926020909101359150565b60005b838110156126135781810151838201526020016125fb565b50506000910152565b600081518084526126348160208601602086016125f8565b601f01601f19169290920160200192915050565b6020815260008251610100602084015261266661012084018261261c565b9050602084015161ffff8082166040860152806040870151166060860152505060608401516126d1608085018261ffff808251168352806020830151166020840152806040830151166040840152806060830151166060840152806080830151166080840152505050565b509392505050565b60a0810161099a828461ffff808251168352806020830151166020840152806040830151166040840152806060830151166060840152806080830151166080840152505050565b6000806040838503121561273357600080fd5b82359150602083013567ffffffffffffffff81111561275157600080fd5b61275d8582860161226b565b9150509250929050565b60006020828403121561277957600080fd5b81516121bb81612363565b600181811c9082168061279857607f821691505b6020821081036127b857634e487b7160e01b600052602260045260246000fd5b50919050565b600060a082840312156127d057600080fd5b6121bb83836123a8565b60408152610100604082015260008084546127f481612784565b80610140860152610160600180841660008114612818576001811461283257612863565b60ff1985168884015283151560051b880183019550612863565b8960005260208060002060005b8681101561285a5781548b820187015290840190820161283f565b8a018501975050505b5088015461ffff8082166060890152909350915061287e9050565b61289360808601828460101c1661ffff169052565b5050600285015461ffff80821660a0860152601082901c811660c0860152602082901c811660e0860152603082901c811661010086015260409190911c16610120840152831515602084015290506121bb565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b600060018201612924576129246128fc565b5060010190565b8082018082111561099a5761099a6128fc565b600061ffff808316818103612955576129556128fc565b6001019392505050565b600082516129718184602087016125f8565b9190910192915050565b600080835461298981612784565b600182811680156129a157600181146129b6576129e5565b60ff19841687528215158302870194506129e5565b8760005260208060002060005b858110156129dc5781548a8201529084019082016129c3565b50505082870194505b50929695505050505050565b601f821115610b8457600081815260208120601f850160051c81016020861015612a185750805b601f850160051c820191505b81811015612a3757828155600101612a24565b505050505050565b815167ffffffffffffffff811115612a5957612a59612224565b612a6d81612a678454612784565b846129f1565b602080601f831160018114612aa25760008415612a8a5750858301515b600019600386901b1c1916600185901b178555612a37565b600085815260208120601f198616915b82811015612ad157888601518255948401946001909101908401612ab2565b5085821015612aef5787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b61ffff818116838216019080821115612b1a57612b1a6128fc565b5092915050565b808202811582820484141761099a5761099a6128fc565b7f416363657373436f6e74726f6c3a206163636f756e7420000000000000000000815260008351612b708160178501602088016125f8565b7f206973206d697373696e6720726f6c65200000000000000000000000000000006017918401918201528351612bad8160288401602088016125f8565b01602801949350505050565b6020815260006121bb602083018461261c565b600081612bdb57612bdb6128fc565b50600019019056fe3b49a237fe2d18fa4d9642b8a0e065923cceb71b797783b619a030a61d848bf0a2646970667358221220e39b3581f63f21b2ad1d5db4b9cb4bb3052084be6ee9f6a28863b7484662be6564736f6c63430008130033
Verified Source Code Full Match
Compiler: v0.8.19+commit.7dd6d404
EVM: paris
Optimization: Yes (800 runs)
TMAsMetadata.sol 211 lines
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;
import './interface/ITMAsMetadata.sol';
import '@openzeppelin/contracts/access/AccessControl.sol';
import '@openzeppelin/contracts/token/ERC721/IERC721.sol';
import 'tma-staking-contracts/contracts/AMTManager/AMTManager.sol';
error NameCheckError();
error NameTooShortError();
error NameAlreadyUsedError();
error NonNameError();
error RaiseLimitError();
error EnhanceCheckError();
contract TMAsMetadata is ITMAsMetadata, AccessControl {
event UpdateMetadata(uint256 indexed id, Metadata metadata, bool updateFamily);
IERC721 public immutable tmas;
bytes32 public constant CONFIGURATOR_ROLE = keccak256('CONFIGURATOR_ROLE');
mapping(string => bool) private _usedNames;
mapping(uint256 => Metadata) private _metadatas;
mapping(uint256 => Status) private _defaultStatus;
IAMTManager public points;
uint16 public maxRaise = 10;
uint256 public nameCost = 10;
uint256 public statusCost = 100;
uint256 public resetFamilyCost = 5000;
mapping(uint256 => uint256) public raiseCost;
modifier onlyNamed(uint256 id) {
if (bytes(_metadatas[id].name).length == 0) revert NonNameError();
_;
}
modifier onlyTMAsOwner(uint256 id) {
if (tmas.ownerOf(id) != msg.sender) revert NonNameError();
_;
}
constructor(IAMTManager _points, IERC721 _tmas) {
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
_grantRole(CONFIGURATOR_ROLE, msg.sender);
raiseCost[0] = 100;
raiseCost[1] = 400;
raiseCost[2] = 1000;
points = _points;
tmas = _tmas;
}
//only CONFIGURATOR
function setPoints(IAMTManager _pointse) external onlyRole(CONFIGURATOR_ROLE) {
points = _pointse;
}
function setMaxRaise(uint16 _maxRaise) external onlyRole(CONFIGURATOR_ROLE) {
maxRaise = _maxRaise;
}
function setStatusCost(uint256 _statusCost) external onlyRole(CONFIGURATOR_ROLE) {
statusCost = _statusCost;
}
function setResetFamilyCost(uint256 _resetFamilyCost) external onlyRole(CONFIGURATOR_ROLE) {
resetFamilyCost = _resetFamilyCost;
}
function setRaiseCost(uint256 index, uint256 cost) external onlyRole(CONFIGURATOR_ROLE) {
raiseCost[index] = cost;
}
function setNameCost(uint256 _nameCost) external onlyRole(CONFIGURATOR_ROLE) {
nameCost = _nameCost;
}
function setDefaultStatus(uint256 startIndex, Status[] memory statuses) external onlyRole(CONFIGURATOR_ROLE) {
uint256 i = 0;
while (i < statuses.length) {
_defaultStatus[startIndex + i] = statuses[i];
i++;
}
}
function setMetadata(uint256 id, Metadata memory metadata) external onlyRole(CONFIGURATOR_ROLE) {
if (metadata.raise > maxRaise) revert RaiseLimitError();
if (!checkName(metadata.name)) revert NameCheckError();
if (_usedNames[metadata.name]) revert NameAlreadyUsedError();
if (!enhanceStatusCheck(id, metadata.status)) revert EnhanceCheckError();
_usedNames[_metadatas[id].name] = false;
_metadatas[id] = metadata;
_usedNames[metadata.name] = true;
emit UpdateMetadata(id, _metadatas[id], false);
}
//only named
function resetFamily(uint256 id) external override onlyTMAsOwner(id) onlyNamed(id) {
points.use(msg.sender, resetFamilyCost, 'resetFamily');
_metadatas[id].familyResetCount++;
emit UpdateMetadata(id, _metadatas[id], true);
}
function raiseUp(uint256 id) external override onlyTMAsOwner(id) onlyNamed(id) {
if (_metadatas[id].raise + 1 > maxRaise) revert RaiseLimitError();
points.use(msg.sender, calcRaiseCost(id), 'raiseUp');
_metadatas[id].raise++;
emit UpdateMetadata(id, _metadatas[id], false);
}
function enhanceStatus(uint256 id, Status calldata status) external override onlyTMAsOwner(id) onlyNamed(id) {
Status memory enhanced = sumStatuses(_metadatas[id].status, status);
if (!enhanceStatusCheck(id, enhanced)) revert EnhanceCheckError();
points.use(msg.sender, calcEnhanceStatusCost(status), 'enhanceStatus');
_metadatas[id].status = sumStatuses(_metadatas[id].status, status);
emit UpdateMetadata(id, _metadatas[id], false);
}
//only TMAsOwner
function setName(uint256 id, string memory name) external override onlyTMAsOwner(id) {
if (bytes(name).length < 2) revert NameTooShortError();
if (!checkName(name)) revert NameCheckError();
if (_usedNames[name]) revert NameAlreadyUsedError();
points.use(msg.sender, nameCost, 'setName');
_usedNames[_metadatas[id].name] = false;
_metadatas[id].name = name;
_usedNames[name] = true;
emit UpdateMetadata(id, _metadatas[id], false);
}
//view
function usedNames(string memory name) external view override returns (bool) {
return _usedNames[name];
}
function metadatas(uint256 id) external view override returns (Metadata memory metadata) {
metadata = _metadatas[id];
}
function calcedMetadatas(uint256 id) external view override returns (Metadata memory metadata) {
metadata = _metadatas[id];
metadata.status = sumStatuses(_defaultStatus[id], _metadatas[id].status);
}
function power(uint256 id) external view override returns (uint256) {
return
_metadatas[id].status.HP +
_metadatas[id].status.ATK +
_metadatas[id].status.DEF +
_metadatas[id].status.INT +
_metadatas[id].status.AGI;
}
function defaultStatus(uint256 id) external view override returns (Status memory) {
return _defaultStatus[id];
}
//internal
function enhanceStatusCheck(uint256 id, Status memory enhance) internal view returns (bool) {
Status memory check = sumStatuses(_defaultStatus[id], enhance);
uint16 max = statusMax(_metadatas[id].raise);
if (check.HP > max || check.ATK > max || check.DEF > max || check.INT > max || check.AGI > max) return false;
return true;
}
function calcRaiseCost(uint256 id) internal view returns (uint256) {
uint256 currentRaise = _metadatas[id].raise;
if (currentRaise > 2) return raiseCost[2];
return raiseCost[currentRaise];
}
function calcEnhanceStatusCost(Status calldata status) internal view returns (uint256 cost) {
return statusCost * (status.HP + status.ATK + status.DEF + status.INT + status.AGI);
}
//pure
function sumStatuses(Status memory source, Status memory destination) internal pure returns (Status memory) {
destination.HP += source.HP;
destination.ATK += source.ATK;
destination.DEF += source.DEF;
destination.INT += source.INT;
destination.AGI += source.AGI;
return destination;
}
function statusMax(uint256 raise) public pure returns (uint16) {
if (raise >= 10) return 100;
if (raise >= 3) return 20;
if (raise >= 2) return 15;
return 10;
}
function checkName(string memory str) public pure returns (bool) {
uint256 i = 0;
bytes memory b = bytes(str);
if (b.length > 10) return false;
while (i < b.length) {
if (
!(b[i] >= 0x30 && b[i] <= 0x39) && //9-0
!(b[i] >= 0x41 && b[i] <= 0x5A) && //A-Z
!(b[i] >= 0x61 && b[i] <= 0x7A) //a-z
) return false;
i++;
}
return true;
}
}
ITMAsMetadata.sol 36 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
interface ITMAsMetadata {
struct Status {
uint16 HP;
uint16 ATK;
uint16 DEF;
uint16 INT;
uint16 AGI;
}
struct Metadata {
string name;
uint16 raise;
uint16 familyResetCount;
Status status;
}
function usedNames(string memory name) external returns (bool);
function metadatas(uint256 id) external returns (Metadata memory);
function calcedMetadatas(uint256 id) external returns (Metadata memory);
function defaultStatus(uint256 id) external returns (Status memory);
function power(uint256 id) external returns (uint256);
function resetFamily(uint256 id) external;
function raiseUp(uint256 id) external;
function enhanceStatus(uint256 id, Status calldata status) external;
function setName(uint256 id, string memory name) external;
}
Context.sol 24 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
Strings.sol 70 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol)
pragma solidity ^0.8.0;
import "./math/Math.sol";
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant _SYMBOLS = "0123456789abcdef";
uint8 private constant _ADDRESS_LENGTH = 20;
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = Math.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
/// @solidity memory-safe-assembly
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
/// @solidity memory-safe-assembly
assembly {
mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, Math.log256(value) + 1);
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
*/
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
}
}
Math.sol 345 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
enum Rounding {
Down, // Toward negative infinity
Up, // Toward infinity
Zero // Toward zero
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds up instead
* of rounding down.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b - 1) / b can overflow on addition, so we distribute.
return a == 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; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
require(denominator > prod1);
///////////////////////////////////////////////
// 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.
// Does not overflow because the denominator cannot be zero at this stage in the function.
uint256 twos = denominator & (~denominator + 1);
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 (rounding == Rounding.Up && 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 down.
*
* 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 + (rounding == Rounding.Up && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2, rounded down, of a positive value.
* 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 + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10, rounded down, of a positive value.
* 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 + (rounding == Rounding.Up && 10**result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256, rounded down, of a positive value.
* 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 10, 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 + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);
}
}
}
AccessControl.sol 247 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (access/AccessControl.sol)
pragma solidity ^0.8.0;
import "./IAccessControl.sol";
import "../utils/Context.sol";
import "../utils/Strings.sol";
import "../utils/introspection/ERC165.sol";
/**
* @dev Contract module that allows children to implement role-based access
* control mechanisms. This is a lightweight version that doesn't allow enumerating role
* members except through off-chain means by accessing the contract event logs. Some
* applications may benefit from on-chain enumerability, for those cases see
* {AccessControlEnumerable}.
*
* Roles are referred to by their `bytes32` identifier. These should be exposed
* in the external API and be unique. The best way to achieve this is by
* using `public constant` hash digests:
*
* ```
* bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
* ```
*
* Roles can be used to represent a set of permissions. To restrict access to a
* function call, use {hasRole}:
*
* ```
* function foo() public {
* require(hasRole(MY_ROLE, msg.sender));
* ...
* }
* ```
*
* Roles can be granted and revoked dynamically via the {grantRole} and
* {revokeRole} functions. Each role has an associated admin role, and only
* accounts that have a role's admin role can call {grantRole} and {revokeRole}.
*
* By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
* that only accounts with this role will be able to grant or revoke other
* roles. More complex role relationships can be created by using
* {_setRoleAdmin}.
*
* WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
* grant and revoke this role. Extra precautions should be taken to secure
* accounts that have been granted it.
*/
abstract contract AccessControl is Context, IAccessControl, ERC165 {
struct RoleData {
mapping(address => bool) members;
bytes32 adminRole;
}
mapping(bytes32 => RoleData) private _roles;
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
/**
* @dev Modifier that checks that an account has a specific role. Reverts
* with a standardized message including the required role.
*
* The format of the revert reason is given by the following regular expression:
*
* /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
*
* _Available since v4.1._
*/
modifier onlyRole(bytes32 role) {
_checkRole(role);
_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) public view virtual override returns (bool) {
return _roles[role].members[account];
}
/**
* @dev Revert with a standard message if `_msgSender()` is missing `role`.
* Overriding this function changes the behavior of the {onlyRole} modifier.
*
* Format of the revert message is described in {_checkRole}.
*
* _Available since v4.6._
*/
function _checkRole(bytes32 role) internal view virtual {
_checkRole(role, _msgSender());
}
/**
* @dev Revert with a standard message if `account` is missing `role`.
*
* The format of the revert reason is given by the following regular expression:
*
* /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
*/
function _checkRole(bytes32 role, address account) internal view virtual {
if (!hasRole(role, account)) {
revert(
string(
abi.encodePacked(
"AccessControl: account ",
Strings.toHexString(account),
" is missing role ",
Strings.toHexString(uint256(role), 32)
)
)
);
}
}
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {
return _roles[role].adminRole;
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*
* May emit a {RoleGranted} event.
*/
function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_grantRole(role, account);
}
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*
* May emit a {RoleRevoked} event.
*/
function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_revokeRole(role, account);
}
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been revoked `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `account`.
*
* May emit a {RoleRevoked} event.
*/
function renounceRole(bytes32 role, address account) public virtual override {
require(account == _msgSender(), "AccessControl: can only renounce roles for self");
_revokeRole(role, account);
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event. Note that unlike {grantRole}, this function doesn't perform any
* checks on the calling account.
*
* May emit a {RoleGranted} event.
*
* [WARNING]
* ====
* This function should only be called from the constructor when setting
* up the initial roles for the system.
*
* Using this function in any other way is effectively circumventing the admin
* system imposed by {AccessControl}.
* ====
*
* NOTE: This function is deprecated in favor of {_grantRole}.
*/
function _setupRole(bytes32 role, address account) internal virtual {
_grantRole(role, account);
}
/**
* @dev Sets `adminRole` as ``role``'s admin role.
*
* Emits a {RoleAdminChanged} event.
*/
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
bytes32 previousAdminRole = getRoleAdmin(role);
_roles[role].adminRole = adminRole;
emit RoleAdminChanged(role, previousAdminRole, adminRole);
}
/**
* @dev Grants `role` to `account`.
*
* Internal function without access restriction.
*
* May emit a {RoleGranted} event.
*/
function _grantRole(bytes32 role, address account) internal virtual {
if (!hasRole(role, account)) {
_roles[role].members[account] = true;
emit RoleGranted(role, account, _msgSender());
}
}
/**
* @dev Revokes `role` from `account`.
*
* Internal function without access restriction.
*
* May emit a {RoleRevoked} event.
*/
function _revokeRole(bytes32 role, address account) internal virtual {
if (hasRole(role, account)) {
_roles[role].members[account] = false;
emit RoleRevoked(role, account, _msgSender());
}
}
}
IERC721.sol 145 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC721/IERC721.sol)
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC721 compliant contract.
*/
interface IERC721 is IERC165 {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes calldata data
) external;
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must have been allowed to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721
* or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
* understand this adds an external call which potentially creates a reentrancy vulnerability.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address from,
address to,
uint256 tokenId
) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function approve(address to, uint256 tokenId) external;
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the caller.
*
* Emits an {ApprovalForAll} event.
*/
function setApprovalForAll(address operator, bool _approved) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/
function isApprovedForAll(address owner, address operator) external view returns (bool);
}
IAccessControl.sol 88 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)
pragma solidity ^0.8.0;
/**
* @dev External interface of AccessControl declared to support ERC165 detection.
*/
interface IAccessControl {
/**
* @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
*
* `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
* {RoleAdminChanged} not being emitted signaling this.
*
* _Available since v3.1._
*/
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
/**
* @dev Emitted when `account` is granted `role`.
*
* `sender` is the account that originated the contract call, an admin role
* bearer except when using {AccessControl-_setupRole}.
*/
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Emitted when `account` is revoked `role`.
*
* `sender` is the account that originated the contract call:
* - if using `revokeRole`, it is the admin role bearer
* - if using `renounceRole`, it is the role bearer (i.e. `account`)
*/
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) external view returns (bool);
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {AccessControl-_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) external view returns (bytes32);
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function grantRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function revokeRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been granted `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `account`.
*/
function renounceRole(bytes32 role, address account) external;
}
ERC165.sol 29 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)
pragma solidity ^0.8.0;
import "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
IERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
AMTManager.sol 47 lines
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.17;
import "./IAMTManager.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
contract AMTManager is IAMTManager, AccessControl {
bytes32 public constant ADMIN = "ADMIN";
bytes32 public constant AMT_ADD_OPERATOR = "AMT_ADD_OPERATOR";
bytes32 public constant AMT_USE_OPERATOR = "AMT_USE_OPERATOR";
event AddedAMT(address indexed user, uint256 amount);
event UsedAMT(address indexed user, string indexed action, uint256 amount);
constructor() {
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
_setRoleAdmin(ADMIN, DEFAULT_ADMIN_ROLE);
_setRoleAdmin(AMT_ADD_OPERATOR, ADMIN);
_setRoleAdmin(AMT_USE_OPERATOR, ADMIN);
_grantRole(ADMIN, msg.sender);
}
mapping(address => uint256) public amt;
function add(
address to,
uint256 value
) external onlyRole(AMT_ADD_OPERATOR) {
amt[to] += value;
emit AddedAMT(to, value);
}
function use(
address from,
uint256 value,
string calldata action
) external onlyRole(AMT_USE_OPERATOR) {
require(
tx.origin == from || hasRole(ADMIN, tx.origin),
"only use myself."
);
require(amt[from] >= value, "not enough AMT.");
amt[from] -= value;
emit UsedAMT(from, action, value);
}
}
IAMTManager.sol 10 lines
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.17;
interface IAMTManager {
function amt(address user) external view returns (uint256);
function add(address to, uint256 value) external;
function use(address from, uint256 value, string calldata action) external;
}
Read Contract
CONFIGURATOR_ROLE 0xd853015e → bytes32
DEFAULT_ADMIN_ROLE 0xa217fddf → bytes32
calcedMetadatas 0xff395729 → tuple
checkName 0x1400d1e4 → bool
defaultStatus 0xebb7f415 → tuple
getRoleAdmin 0x248a9ca3 → bytes32
hasRole 0x91d14854 → bool
maxRaise 0x719ec6b1 → uint16
metadatas 0xe73496cd → tuple
nameCost 0xe37b1be0 → uint256
points 0x1be6dd64 → address
power 0xcc193fb0 → uint256
raiseCost 0x49af9cdd → uint256
resetFamilyCost 0xfe2f62da → uint256
statusCost 0x1753a1f5 → uint256
statusMax 0xe07d5987 → uint16
supportsInterface 0x01ffc9a7 → bool
tmas 0x14d67049 → address
usedNames 0xb85b99c9 → bool
Write Contract 15 functions
These functions modify contract state and require a wallet transaction to execute.
enhanceStatus 0x9128827b
uint256 id
tuple status
grantRole 0x2f2ff15d
bytes32 role
address account
raiseUp 0xb3e1e8ec
uint256 id
renounceRole 0x36568abe
bytes32 role
address account
resetFamily 0x4ea09963
uint256 id
revokeRole 0xd547741f
bytes32 role
address account
setDefaultStatus 0x434af759
uint256 startIndex
tuple[] statuses
setMaxRaise 0x19c89bc2
uint16 _maxRaise
setMetadata 0xdaf70eec
uint256 id
tuple metadata
setName 0xfe55932a
uint256 id
string name
setNameCost 0xa7db7659
uint256 _nameCost
setPoints 0x9f25cde7
address _pointse
setRaiseCost 0xd092851b
uint256 index
uint256 cost
setResetFamilyCost 0xa17651c0
uint256 _resetFamilyCost
setStatusCost 0x41a847be
uint256 _statusCost
Recent Transactions
No transactions found for this address