Address Contract Verified
Address
0x65b0e4113378CE48BB931A03bbBADF663ba59aDb
Balance
0 ETH
Nonce
1
Code Size
9986 bytes
Creator
0xE7D7696C...5026 at tx 0xc6e76b3d...becdae
Indexed Transactions
0
Contract Bytecode
9986 bytes
0x6080604052600436106101815760003560e01c8063636169d8116100d1578063a1ebf35d1161008a578063bc735d9011610064578063bc735d90146104a6578063d547741f146104c6578063d55ec697146104e6578063d936547e146104fb57600080fd5b8063a1ebf35d1461044f578063a217fddf14610471578063b6363cf21461048657600080fd5b8063636169d81461039757806368aec8e2146103b757806375b238fc146103cd578063860a871f146103ef57806391d148541461040f5780639281aa0b1461042f57600080fd5b80632f2ff15d1161013e578063485cc95511610118578063485cc955146103145780635107f34814610334578063539ac4721461036157806354fd4d501461038157600080fd5b80632f2ff15d146102b257806336568abe146102d25780633a283d7d146102f257600080fd5b806301ffc9a714610186578063070f8f5a146101bb5780630c1ace3b146102015780631f1097e514610216578063248a9ca31461026f5780632cc9d7111461029f575b600080fd5b34801561019257600080fd5b506101a66101a1366004611e1d565b61052b565b60405190151581526020015b60405180910390f35b3480156101c757600080fd5b506101f36101d6366004611f0a565b8051602081830181018051609d8252928201919093012091525481565b6040519081526020016101b2565b61021461020f366004611f87565b610562565b005b34801561022257600080fd5b50610257610231366004611f0a565b80516020818301810180516098825292820191909301209152546001600160a01b031681565b6040516001600160a01b0390911681526020016101b2565b34801561027b57600080fd5b506101f361028a366004611ff7565b60009081526065602052604090206001015490565b6102146102ad366004612010565b610736565b3480156102be57600080fd5b506102146102cd366004612067565b610917565b3480156102de57600080fd5b506102146102ed366004612067565b610941565b3480156102fe57600080fd5b506103076109bf565b6040516101b291906120eb565b34801561032057600080fd5b5061021461032f36600461214d565b610af9565b34801561034057600080fd5b5061035461034f366004611f0a565b610c72565b6040516101b29190612177565b34801561036d57600080fd5b5061021461037c3660046121bb565b610d57565b34801561038d57600080fd5b506101f3609c5481565b3480156103a357600080fd5b506101f36103b23660046121bb565b610ef4565b3480156103c357600080fd5b506101f36127d881565b3480156103d957600080fd5b506101f36000805160206126ad83398151915281565b3480156103fb57600080fd5b5061025761040a3660046121d6565b610f45565b34801561041b57600080fd5b506101a661042a366004612067565b610f83565b34801561043b57600080fd5b5061021461044a36600461222a565b610fae565b34801561045b57600080fd5b506101f360008051602061268d83398151915281565b34801561047d57600080fd5b506101f3600081565b34801561049257600080fd5b506101a66104a136600461214d565b610fd0565b3480156104b257600080fd5b506102146104c1366004612254565b610feb565b3480156104d257600080fd5b506102146104e1366004612067565b611014565b3480156104f257600080fd5b50610214611039565b34801561050757600080fd5b506101a66105163660046121bb565b60996020526000908152604090205460ff1681565b60006001600160e01b03198216637965db0b60e01b148061055c57506301ffc9a760e01b6001600160e01b03198316145b92915050565b6060830161057360808501826121bb565b6001600160a01b0316336001600160a01b0316146105c75760405162461bcd60e51b815260206004820152600c60248201526b2bb937b7339031b0b63632b960a11b60448201526064015b60405180910390fd5b8060200135421061060c5760405162461bcd60e51b815260206004820152600f60248201526e14995c5d595cdd08195e1c1a5c9959608a1b60448201526064016105be565b610615846110a0565b83836000610665610624611146565b8560405161190160f01b6020820152602281018390526042810182905260009060620160405160208183030381529060405280519060200120905092915050565b905060006106a98285858080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152506111eb92505050565b90506106c360008051602061268d83398151915282610f83565b6107075760405162461bcd60e51b815260206004820152601560248201527414da59db995c881b9bdd081c9958dbd9db9a5e9959605a1b60448201526064016105be565b61072b6107148a80612297565b60208c013561072660408e018e612297565b61120f565b505050505050505050565b61074360208401846121bb565b61074d8133610fd0565b6107895760405162461bcd60e51b815260206004820152600d60248201526c1058d8d95cdcc819195b9a5959609a1b60448201526064016105be565b6040840161079a60608601826121bb565b6001600160a01b0316336001600160a01b0316146107e95760405162461bcd60e51b815260206004820152600c60248201526b2bb937b7339031b0b63632b960a11b60448201526064016105be565b8060200135421061082e5760405162461bcd60e51b815260206004820152600f60248201526e14995c5d595cdd08195e1c1a5c9959608a1b60448201526064016105be565b61083785611306565b84846000610846610624611146565b9050600061088a8285858080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152506111eb92505050565b90506108a460008051602061268d83398151915282610f83565b6108e85760405162461bcd60e51b815260206004820152601560248201527414da59db995c881b9bdd081c9958dbd9db9a5e9959605a1b60448201526064016105be565b61090b6108f860208c018c6121bb565b61090560208d018d612297565b34611395565b50505050505050505050565b60008281526065602052604090206001015461093281611427565b61093c8383611434565b505050565b6001600160a01b03811633146109b15760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b60648201526084016105be565b6109bb82826114ba565b5050565b609754606090806001600160401b038111156109dd576109dd611e47565b604051908082528060200260200182016040528015610a1057816020015b60608152602001906001900390816109fb5790505b50915060005b81811015610af45760978181548110610a3157610a316122dd565b906000526020600020018054610a46906122f3565b80601f0160208091040260200160405190810160405280929190818152602001828054610a72906122f3565b8015610abf5780601f10610a9457610100808354040283529160200191610abf565b820191906000526020600020905b815481529060010190602001808311610aa257829003601f168201915b5050505050838281518110610ad657610ad66122dd565b60200260200101819052508080610aec90612343565b915050610a16565b505090565b600054610100900460ff1615808015610b195750600054600160ff909116105b80610b335750303b158015610b33575060005460ff166001145b610b965760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b60648201526084016105be565b6000805460ff191660011790558015610bb9576000805461ff0019166101001790555b610bd16000805160206126ad83398151915284611434565b610be960008051602061268d83398151915283611434565b610c016000805160206126ad83398151915280611521565b610c2760008051602061268d8339815191526000805160206126ad833981519152611521565b801561093c576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb3847402498906020015b60405180910390a1505050565b60606000609e83604051610c86919061235c565b908152604051908190036020019020549050806001600160401b03811115610cb057610cb0611e47565b604051908082528060200260200182016040528015610cd9578160200160208202803683370190505b50915060005b81811015610d5057609e84604051610cf7919061235c565b90815260200160405180910390208181548110610d1657610d166122dd565b9060005260206000200154838281518110610d3357610d336122dd565b602090810291909101015280610d4881612343565b915050610cdf565b5050919050565b6000805160206126ad833981519152610d6f81611427565b6001600160a01b0382163b610dbd5760405162461bcd60e51b8152602060048201526014602482015273139bdd0818481d985b1a590818dbdb9d1c9858dd60621b60448201526064016105be565b60008290506000816001600160a01b031663a3f4df7e6040518163ffffffff1660e01b8152600401600060405180830381865afa158015610e02573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610e2a9190810190612378565b90506000826001600160a01b031663ffa1ad746040518163ffffffff1660e01b8152600401602060405180830381865afa158015610e6c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e9091906123ee565b905060008111610ee25760405162461bcd60e51b815260206004820152601b60248201527f54656d706c6174652076657273696f6e206d757374206265203e30000000000060448201526064016105be565b610eed82828761156c565b5050505050565b6040516bffffffffffffffffffffffff19606083901b1660208201526727a822a920aa27a960c11b6034820152600090603c015b604051602081830303815290604052805190602001209050919050565b6000609f83604051610f57919061235c565b90815260408051602092819003830190206000948552909152909120546001600160a01b031692915050565b60009182526065602090815260408084206001600160a01b0393909316845291905290205460ff1690565b6000805160206126ad833981519152610fc681611427565b61093c8383611796565b6000610fe4610fde84610ef4565b83610f83565b9392505050565b6000805160206126ad83398151915261100381611427565b61100e8484846117c1565b50505050565b60008281526065602052604090206001015461102f81611427565b61093c83836114ba565b6127d8609c541061107f5760405162461bcd60e51b815260206004820152601060248201526f105b1c9958591e481d5c19dc9859195960821b60448201526064016105be565b6000609a819055609b556127d8609c55565b6001600160a01b03163b151590565b60007ff4430ae2760c5d71a4354b544f7b4566d42c89483bac5264a894a119c0fc9bb86110cd8380612297565b6040516110db929190612407565b604051809103902083602001358480604001906110f89190612297565b604051611106929190612407565b604051809103902061111a8660600161183c565b6040805160208101969096528501939093526060840191909152608083015260a082015260c001610f28565b604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f60208201527f992f90ffb92c5ad86f1df6829115f18aaea41d6094dadc8955c35086081a7bb9918101919091527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc660608201524660808201523060a082015260009060c00160405160208183030381529060405280519060200120905090565b60008060006111fa8585611899565b91509150611207816118de565b509392505050565b6000609f8686604051611223929190612407565b9081526040805160209281900383019020600087815292529020546001600160a01b031690508061128f5760405162461bcd60e51b815260206004820152601660248201527526b4b9b9b4b7339034b6b83632b6b2b73a30ba34b7b760511b60448201526064016105be565b600061129a82611a94565b90507f6b8bc6b40a290fd0b18d9df6812353964a8995c6df02f211f088dc23dd07ba15878787846040516112d19493929190612417565b60405180910390a16112e5813360016117c1565b6112f0816001611796565b6112fd8185856000611395565b50505050505050565b60007f27122634acde4146ed66dc745851809d52cf54f18ac4bf92f8c4668d185592a461133660208401846121bb565b6113436020850185612297565b604051611351929190612407565b60405180910390206113658560400161183c565b6040805160208101959095526001600160a01b03909316928401929092526060830152608082015260a001610f28565b6001600160a01b03841660009081526099602052604090205460ff166113fd5760405162461bcd60e51b815260206004820152601860248201527f436f6e7472616374206e6f742077686974656c6973746564000000000000000060448201526064016105be565b60405182848237600080848385895af190506040513d806000833e828015611423578183f35b8183fd5b6114318133611b31565b50565b61143e8282610f83565b6109bb5760008281526065602090815260408083206001600160a01b03851684529091529020805460ff191660011790556114763390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6114c48282610f83565b156109bb5760008281526065602090815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b600082815260656020526040808220600101805490849055905190918391839186917fbd79b86ffe0ab8e8776151514217cd7cacd52c909f66475c3af44e129f0b00ff9190a4505050565b60006001600160a01b0316609f84604051611587919061235c565b9081526040805160209281900383019020600086815292529020546001600160a01b0316146115f15760405162461bcd60e51b815260206004820152601660248201527556657273696f6e20616c72656164792065786973747360501b60448201526064016105be565b80609f84604051611602919061235c565b908152604080516020928190038301812060008781529352912080546001600160a01b0319166001600160a01b039390931692909217909155609e9061164990859061235c565b908152604051602091819003820181208054600181018255600091825292812090920184905560989061167d90869061235c565b908152604051908190036020019020546001600160a01b0316036116d957609780546001810182556000919091527f354a83ed9988f79f6038d4c7a7dadbad8af32f4ad6df893e0e5807a1b1944ff9016116d784826124ae565b505b609d836040516116e9919061235c565b9081526020016040518091039020548211156117635781609d84604051611710919061235c565b90815260200160405180910390208190555080609884604051611733919061235c565b90815260405190819003602001902080546001600160a01b03929092166001600160a01b03199092169190911790555b7f0be5312ff68a803959eec846227697c8b78bd482eb8bdc334b0c9277bf9dc5aa838383604051610c659392919061256d565b6001600160a01b03919091166000908152609960205260409020805460ff1916911515919091179055565b80156117de576117d96117d384610ef4565b83611434565b6117f0565b6117f06117ea84610ef4565b836114ba565b604080516001600160a01b03808616825284166020820152821515918101919091527f360a624a90a46b5efa2724062dd6494f28d0b3afb636c74291727f5ffd160b3f90606001610c65565b60007fa47a666e1dc5980bd5a50371d479f2078c3a60ce07a41d0087841df42d4d475c61186c60208401846121bb565b604080516020818101949094526001600160a01b0390921690820152908301356060820152608001610f28565b60008082516041036118cf5760208301516040840151606085015160001a6118c387828585611b95565b945094505050506118d7565b506000905060025b9250929050565b60008160048111156118f2576118f26125a0565b036118fa5750565b600181600481111561190e5761190e6125a0565b0361195b5760405162461bcd60e51b815260206004820152601860248201527f45434453413a20696e76616c6964207369676e6174757265000000000000000060448201526064016105be565b600281600481111561196f5761196f6125a0565b036119bc5760405162461bcd60e51b815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e6774680060448201526064016105be565b60038160048111156119d0576119d06125a0565b03611a285760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c604482015261756560f01b60648201526084016105be565b6004816004811115611a3c57611a3c6125a0565b036114315760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202776272076616c604482015261756560f01b60648201526084016105be565b6000604051733d602d80600a3d3981f3363d3d373d3d3d363d7360601b81528260601b60148201526e5af43d82803e903d91602b57fd5bf360881b60288201526037816000f09150506001600160a01b038116611b2c5760405162461bcd60e51b8152602060048201526016602482015275115490cc4c4d8dce8818dc99585d194819985a5b195960521b60448201526064016105be565b919050565b611b3b8282610f83565b6109bb57611b53816001600160a01b03166014611c82565b611b5e836020611c82565b604051602001611b6f9291906125b6565b60408051601f198184030181529082905262461bcd60e51b82526105be9160040161262b565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0831115611bcc5750600090506003611c79565b8460ff16601b14158015611be457508460ff16601c14155b15611bf55750600090506004611c79565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa158015611c49573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b038116611c7257600060019250925050611c79565b9150600090505b94509492505050565b60606000611c9183600261263e565b611c9c90600261265d565b6001600160401b03811115611cb357611cb3611e47565b6040519080825280601f01601f191660200182016040528015611cdd576020820181803683370190505b509050600360fc1b81600081518110611cf857611cf86122dd565b60200101906001600160f81b031916908160001a905350600f60fb1b81600181518110611d2757611d276122dd565b60200101906001600160f81b031916908160001a9053506000611d4b84600261263e565b611d5690600161265d565b90505b6001811115611dce576f181899199a1a9b1b9c1cb0b131b232b360811b85600f1660108110611d8a57611d8a6122dd565b1a60f81b828281518110611da057611da06122dd565b60200101906001600160f81b031916908160001a90535060049490941c93611dc781612675565b9050611d59565b508315610fe45760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e7460448201526064016105be565b600060208284031215611e2f57600080fd5b81356001600160e01b031981168114610fe457600080fd5b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b0381118282101715611e8557611e85611e47565b604052919050565b60006001600160401b03821115611ea657611ea6611e47565b50601f01601f191660200190565b600082601f830112611ec557600080fd5b8135611ed8611ed382611e8d565b611e5d565b818152846020838601011115611eed57600080fd5b816020850160208301376000918101602001919091529392505050565b600060208284031215611f1c57600080fd5b81356001600160401b03811115611f3257600080fd5b611f3e84828501611eb4565b949350505050565b60008083601f840112611f5857600080fd5b5081356001600160401b03811115611f6f57600080fd5b6020830191508360208285010111156118d757600080fd5b600080600060408486031215611f9c57600080fd5b83356001600160401b0380821115611fb357600080fd5b9085019060a08288031215611fc757600080fd5b90935060208501359080821115611fdd57600080fd5b50611fea86828701611f46565b9497909650939450505050565b60006020828403121561200957600080fd5b5035919050565b60008060006040848603121561202557600080fd5b83356001600160401b038082111561203c57600080fd5b9085019060808288031215611fc757600080fd5b80356001600160a01b0381168114611b2c57600080fd5b6000806040838503121561207a57600080fd5b8235915061208a60208401612050565b90509250929050565b60005b838110156120ae578181015183820152602001612096565b8381111561100e5750506000910152565b600081518084526120d7816020860160208601612093565b601f01601f19169290920160200192915050565b6000602080830181845280855180835260408601915060408160051b870101925083870160005b8281101561214057603f1988860301845261212e8583516120bf565b94509285019290850190600101612112565b5092979650505050505050565b6000806040838503121561216057600080fd5b61216983612050565b915061208a60208401612050565b6020808252825182820181905260009190848201906040850190845b818110156121af57835183529284019291840191600101612193565b50909695505050505050565b6000602082840312156121cd57600080fd5b610fe482612050565b600080604083850312156121e957600080fd5b82356001600160401b038111156121ff57600080fd5b61220b85828601611eb4565b95602094909401359450505050565b80358015158114611b2c57600080fd5b6000806040838503121561223d57600080fd5b61224683612050565b915061208a6020840161221a565b60008060006060848603121561226957600080fd5b61227284612050565b925061228060208501612050565b915061228e6040850161221a565b90509250925092565b6000808335601e198436030181126122ae57600080fd5b8301803591506001600160401b038211156122c857600080fd5b6020019150368190038213156118d757600080fd5b634e487b7160e01b600052603260045260246000fd5b600181811c9082168061230757607f821691505b60208210810361232757634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052601160045260246000fd5b6000600182016123555761235561232d565b5060010190565b6000825161236e818460208701612093565b9190910192915050565b60006020828403121561238a57600080fd5b81516001600160401b038111156123a057600080fd5b8201601f810184136123b157600080fd5b80516123bf611ed382611e8d565b8181528560208385010111156123d457600080fd5b6123e5826020830160208601612093565b95945050505050565b60006020828403121561240057600080fd5b5051919050565b8183823760009101908152919050565b60608152836060820152838560808301376000608085830181019190915260208201939093526001600160a01b03919091166040820152601f909201601f191690910101919050565b601f82111561093c57600081815260208120601f850160051c810160208610156124875750805b601f850160051c820191505b818110156124a657828155600101612493565b505050505050565b81516001600160401b038111156124c7576124c7611e47565b6124db816124d584546122f3565b84612460565b602080601f83116001811461251057600084156124f85750858301515b600019600386901b1c1916600185901b1785556124a6565b600085815260208120601f198616915b8281101561253f57888601518255948401946001909101908401612520565b508582101561255d5787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b60608152600061258060608301866120bf565b6020830194909452506001600160a01b0391909116604090910152919050565b634e487b7160e01b600052602160045260246000fd5b7f416363657373436f6e74726f6c3a206163636f756e74200000000000000000008152600083516125ee816017850160208801612093565b7001034b99036b4b9b9b4b733903937b6329607d1b601791840191820152835161261f816028840160208801612093565b01602801949350505050565b602081526000610fe460208301846120bf565b60008160001904831182151516156126585761265861232d565b500290565b600082198211156126705761267061232d565b500190565b6000816126845761268461232d565b50600019019056fee2f4eaae4a9751e85a3e4a7b9587827a877f29914755229b07a7b2da98285f70a49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c21775a2646970667358221220357862df3f81c89593e3cf5c361a0a10a51bdc420a12b6636c7045a80e5b4c2964736f6c634300080f0033
Verified Source Code Full Match
Compiler: v0.8.15+commit.e14f2714
EVM: london
Optimization: Yes (200 runs)
AccessControlUpgradeable.sol 260 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/AccessControl.sol)
pragma solidity ^0.8.0;
import "./IAccessControlUpgradeable.sol";
import "../utils/ContextUpgradeable.sol";
import "../utils/StringsUpgradeable.sol";
import "../utils/introspection/ERC165Upgradeable.sol";
import "../proxy/utils/Initializable.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 AccessControlUpgradeable is Initializable, ContextUpgradeable, IAccessControlUpgradeable, ERC165Upgradeable {
function __AccessControl_init() internal onlyInitializing {
}
function __AccessControl_init_unchained() internal onlyInitializing {
}
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(IAccessControlUpgradeable).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 ",
StringsUpgradeable.toHexString(uint160(account), 20),
" is missing role ",
StringsUpgradeable.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());
}
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[49] private __gap;
}
ECDSA.sol 218 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.3) (utils/cryptography/ECDSA.sol)
pragma solidity ^0.8.0;
import "../Strings.sol";
/**
* @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,
InvalidSignatureV
}
function _throwError(RecoverError error) private pure {
if (error == RecoverError.NoError) {
return; // no error: do nothing
} else if (error == RecoverError.InvalidSignature) {
revert("ECDSA: invalid signature");
} else if (error == RecoverError.InvalidSignatureLength) {
revert("ECDSA: invalid signature length");
} else if (error == RecoverError.InvalidSignatureS) {
revert("ECDSA: invalid signature 's' value");
} else if (error == RecoverError.InvalidSignatureV) {
revert("ECDSA: invalid signature 'v' value");
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature` or error string. This address can then be used for verification purposes.
*
* The `ecrecover` EVM opcode 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 {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]
*
* _Available since v4.3._
*/
function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {
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);
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature`. This address can then be used for verification purposes.
*
* The `ecrecover` EVM opcode 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 {toEthSignedMessageHash} on it.
*/
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, signature);
_throwError(error);
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]
*
* _Available since v4.3._
*/
function tryRecover(
bytes32 hash,
bytes32 r,
bytes32 vs
) internal pure returns (address, RecoverError) {
bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
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.
*
* _Available since v4.2._
*/
function recover(
bytes32 hash,
bytes32 r,
bytes32 vs
) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, r, vs);
_throwError(error);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `v`,
* `r` and `s` signature fields separately.
*
* _Available since v4.3._
*/
function tryRecover(
bytes32 hash,
uint8 v,
bytes32 r,
bytes32 s
) internal pure returns (address, RecoverError) {
// 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);
}
if (v != 27 && v != 28) {
return (address(0), RecoverError.InvalidSignatureV);
}
// 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);
}
return (signer, RecoverError.NoError);
}
/**
* @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) = tryRecover(hash, v, r, s);
_throwError(error);
return recovered;
}
/**
* @dev Returns an Ethereum Signed Message, created from a `hash`. This
* produces hash corresponding to the one signed with the
* https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
* JSON-RPC method as part of EIP-191.
*
* See {recover}.
*/
function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) {
// 32 is the length in bytes of hash,
// enforced by the type signature above
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash));
}
/**
* @dev Returns an Ethereum Signed Message, created from `s`. This
* produces hash corresponding to the one signed with the
* https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
* JSON-RPC method as part of EIP-191.
*
* See {recover}.
*/
function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", Strings.toString(s.length), s));
}
/**
* @dev Returns an Ethereum Signed Typed Data, created from a
* `domainSeparator` and a `structHash`. This produces hash corresponding
* to the one signed with the
* https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]
* JSON-RPC method as part of EIP-712.
*
* See {recover}.
*/
function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash));
}
}
Strings.sol 75 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/Strings.sol)
pragma solidity ^0.8.0;
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant _HEX_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) {
// Inspired by OraclizeAPI's implementation - MIT licence
// https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol
if (value == 0) {
return "0";
}
uint256 temp = value;
uint256 digits;
while (temp != 0) {
digits++;
temp /= 10;
}
bytes memory buffer = new bytes(digits);
while (value != 0) {
digits -= 1;
buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
value /= 10;
}
return string(buffer);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
if (value == 0) {
return "0x00";
}
uint256 temp = value;
uint256 length = 0;
while (temp != 0) {
length++;
temp >>= 8;
}
return toHexString(value, length);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _HEX_SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
/**
* @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);
}
}
AddressUpgradeable.sol 195 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library AddressUpgradeable {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
StringsUpgradeable.sol 75 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/Strings.sol)
pragma solidity ^0.8.0;
/**
* @dev String operations.
*/
library StringsUpgradeable {
bytes16 private constant _HEX_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) {
// Inspired by OraclizeAPI's implementation - MIT licence
// https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol
if (value == 0) {
return "0";
}
uint256 temp = value;
uint256 digits;
while (temp != 0) {
digits++;
temp /= 10;
}
bytes memory buffer = new bytes(digits);
while (value != 0) {
digits -= 1;
buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
value /= 10;
}
return string(buffer);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
if (value == 0) {
return "0x00";
}
uint256 temp = value;
uint256 length = 0;
while (temp != 0) {
length++;
temp >>= 8;
}
return toHexString(value, length);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _HEX_SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
/**
* @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);
}
}
ERC165Upgradeable.sol 42 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)
pragma solidity ^0.8.0;
import "./IERC165Upgradeable.sol";
import "../../proxy/utils/Initializable.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 ERC165Upgradeable is Initializable, IERC165Upgradeable {
function __ERC165_init() internal onlyInitializing {
}
function __ERC165_init_unchained() internal onlyInitializing {
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165Upgradeable).interfaceId;
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[50] private __gap;
}
IERC165Upgradeable.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 IERC165Upgradeable {
/**
* @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);
}
Clones.sol 87 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (proxy/Clones.sol)
pragma solidity ^0.8.0;
/**
* @dev https://eips.ethereum.org/EIPS/eip-1167[EIP 1167] is a standard for
* deploying minimal proxy contracts, also known as "clones".
*
* > To simply and cheaply clone contract functionality in an immutable way, this standard specifies
* > a minimal bytecode implementation that delegates all calls to a known, fixed address.
*
* The library includes functions to deploy a proxy using either `create` (traditional deployment) or `create2`
* (salted deterministic deployment). It also includes functions to predict the addresses of clones deployed using the
* deterministic method.
*
* _Available since v3.4._
*/
library Clones {
/**
* @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`.
*
* This function uses the create opcode, which should never revert.
*/
function clone(address implementation) internal returns (address instance) {
/// @solidity memory-safe-assembly
assembly {
let ptr := mload(0x40)
mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
mstore(add(ptr, 0x14), shl(0x60, implementation))
mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)
instance := create(0, ptr, 0x37)
}
require(instance != address(0), "ERC1167: create failed");
}
/**
* @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`.
*
* This function uses the create2 opcode and a `salt` to deterministically deploy
* the clone. Using the same `implementation` and `salt` multiple time will revert, since
* the clones cannot be deployed twice at the same address.
*/
function cloneDeterministic(address implementation, bytes32 salt) internal returns (address instance) {
/// @solidity memory-safe-assembly
assembly {
let ptr := mload(0x40)
mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
mstore(add(ptr, 0x14), shl(0x60, implementation))
mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)
instance := create2(0, ptr, 0x37, salt)
}
require(instance != address(0), "ERC1167: create2 failed");
}
/**
* @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.
*/
function predictDeterministicAddress(
address implementation,
bytes32 salt,
address deployer
) internal pure returns (address predicted) {
/// @solidity memory-safe-assembly
assembly {
let ptr := mload(0x40)
mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
mstore(add(ptr, 0x14), shl(0x60, implementation))
mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf3ff00000000000000000000000000000000)
mstore(add(ptr, 0x38), shl(0x60, deployer))
mstore(add(ptr, 0x4c), salt)
mstore(add(ptr, 0x6c), keccak256(ptr, 0x37))
predicted := keccak256(add(ptr, 0x37), 0x55)
}
}
/**
* @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.
*/
function predictDeterministicAddress(address implementation, bytes32 salt)
internal
view
returns (address predicted)
{
return predictDeterministicAddress(implementation, salt, address(this));
}
}
Address.sol 222 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
ITemplate.sol 12 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/*
* Template interface, used by factory contracts to get the name and version of a contract,
* that extends this interface.
*/
interface ITemplate {
function NAME() external view returns (string memory);
function VERSION() external view returns (uint256);
}
IAccessControlUpgradeable.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 IAccessControlUpgradeable {
/**
* @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;
}
Initializable.sol 138 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.2;
import "../../utils/AddressUpgradeable.sol";
/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
* reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
* case an upgrade adds a module that needs to be initialized.
*
* For example:
*
* [.hljs-theme-light.nopadding]
* ```
* contract MyToken is ERC20Upgradeable {
* function initialize() initializer public {
* __ERC20_init("MyToken", "MTK");
* }
* }
* contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
* function initializeV2() reinitializer(2) public {
* __ERC20Permit_init("MyToken");
* }
* }
* ```
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*
* [CAUTION]
* ====
* Avoid leaving a contract uninitialized.
*
* An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
* contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
* the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
*
* [.hljs-theme-light.nopadding]
* ```
* /// @custom:oz-upgrades-unsafe-allow constructor
* constructor() {
* _disableInitializers();
* }
* ```
* ====
*/
abstract contract Initializable {
/**
* @dev Indicates that the contract has been initialized.
* @custom:oz-retyped-from bool
*/
uint8 private _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool private _initializing;
/**
* @dev Triggered when the contract has been initialized or reinitialized.
*/
event Initialized(uint8 version);
/**
* @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
* `onlyInitializing` functions can be used to initialize parent contracts. Equivalent to `reinitializer(1)`.
*/
modifier initializer() {
bool isTopLevelCall = !_initializing;
require(
(isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),
"Initializable: contract is already initialized"
);
_initialized = 1;
if (isTopLevelCall) {
_initializing = true;
}
_;
if (isTopLevelCall) {
_initializing = false;
emit Initialized(1);
}
}
/**
* @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
* contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
* used to initialize parent contracts.
*
* `initializer` is equivalent to `reinitializer(1)`, so a reinitializer may be used after the original
* initialization step. This is essential to configure modules that are added through upgrades and that require
* initialization.
*
* Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
* a contract, executing them in the right order is up to the developer or operator.
*/
modifier reinitializer(uint8 version) {
require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
_initialized = version;
_initializing = true;
_;
_initializing = false;
emit Initialized(version);
}
/**
* @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
* {initializer} and {reinitializer} modifiers, directly or indirectly.
*/
modifier onlyInitializing() {
require(_initializing, "Initializable: contract is not initializing");
_;
}
/**
* @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
* Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
* to any version. It is recommended to use this to lock implementation contracts that are designed to be called
* through proxies.
*/
function _disableInitializers() internal virtual {
require(!_initializing, "Initializable: contract is initializing");
if (_initialized < type(uint8).max) {
_initialized = type(uint8).max;
emit Initialized(type(uint8).max);
}
}
}
ContextUpgradeable.sol 37 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";
/**
* @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 ContextUpgradeable is Initializable {
function __Context_init() internal onlyInitializing {
}
function __Context_init_unchained() internal onlyInitializing {
}
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[50] private __gap;
}
Factory.sol 583 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/proxy/Clones.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import "./lib/ITemplate.sol";
/**
* @title Factory
* @notice Contract for managing contract templates, their implementations and deploying and calling template instances.
* Uses {Clones} to deploy https://eips.ethereum.org/EIPS/eip-1167[EIP 1167] compliant proxy contracts
*
* Upgradable contract, meaning it does not make use of a constructor but rather uses `initialize` with `initializer`
* modifier, see {Initializable}
*
* Allows for registering new templates and delegating calls to deployed proxies.
* Saves versions and names for each clone that can be deployed using this factory.
*
* Proxies can be deployed with a signature from an address with `SIGNER_ROLE` or by paying `deploymentFee`
* Proxies can be called with a signature from an address with `SIGNER_ROLE` or by paying `callFee`
*/
contract Factory is AccessControlUpgradeable {
/*************
* Constants *
*************/
/// Contract code version
/// @dev Should follow semver-like format of `MAJOR_MINOR_PATCH`
uint256 public constant CODE_VERSION = 1_02_00;
/// Contract administrator role
bytes32 public constant ADMIN_ROLE = keccak256("ADMIN_ROLE");
/// Transaction signer role
bytes32 public constant SIGNER_ROLE = keccak256("SIGNER_ROLE");
/// EIP721Domain typehash
bytes32 private constant _DOMAIN_TYPEHASH =
keccak256(
"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"
);
/// DeploymentRequest typehash
bytes32 private constant _DEPLOYMENT_REQUEST_TYPEHASH =
keccak256(
"DeploymentRequest(string template,uint256 version,bytes initData,RequestMetadata metadata)RequestMetadata(address caller,uint256 expiration)"
);
/// CallRequest typehash
bytes32 private constant _CALL_REQUEST_TYPEHASH =
keccak256(
"CallRequest(address instance,bytes callData,RequestMetadata metadata)RequestMetadata(address caller,uint256 expiration)"
);
/// RequestMetadata typehash
bytes32 private constant _REQUEST_METADATA_TYPEHASH =
keccak256("RequestMetadata(address caller,uint256 expiration)");
/**********
* Events *
**********/
/// A new version of a template implementation has been added to the Factory
event TemplateAdded(string name, uint256 version, address implementation);
/// An instance of a template has been deployed
event TemplateDeployed(string name, uint256 version, address destination);
/// Permissions for address `operator` to operate contract `instance` have changed to `allowed`
event OperatorChanged(address instance, address operator, bool allowed);
/***********
* Structs *
***********/
struct RequestMetadata {
address caller;
uint256 expiration;
}
struct DeploymentRequest {
string template;
uint256 version;
bytes initData;
RequestMetadata metadata;
}
struct CallRequest {
address instance;
bytes callData;
RequestMetadata metadata;
}
/***********
* Storage *
***********/
/// Template names
string[] private _templateNames;
/// Latest template implementations for `_templateNames`
mapping(string => address) public latestImplementation;
/// Contracts that are whitelisted for proxy calls
mapping(address => bool) public whitelisted;
/// Two storage slots that were previously used for fee-related variables.
/// Need to keep them here because Factory is a deployed upgradeable contract
/// so we can't reorder storage layout.
uint256 _unusedSlot1;
uint256 _unusedSlot2;
/// Current contract version
uint256 public version;
/// Latest template versions for `_templateNames`
mapping(string => uint256) public latestVersion;
/// All template versions for `_templateNames`
mapping(string => uint256[]) private _templateVersions;
/// Implementation addresses for all template versions
mapping(string => mapping(uint256 => address))
private _templateImplementations;
/****************************
* Contract init & upgrades *
****************************/
/**
* @dev Empty constructor to disable direct initialization of this contract
*/
constructor() initializer {}
/**
* Initialize the Factory
* @dev Callable only once
* @param factoryOwner The address that should be assigned ADMIN_ROLE
* @param factorySigner The address that should be assigned SIGNER_ROLE
*/
function initialize(address factoryOwner, address factorySigner)
public
initializer
{
_grantRole(ADMIN_ROLE, factoryOwner);
_grantRole(SIGNER_ROLE, factorySigner);
_setRoleAdmin(ADMIN_ROLE, ADMIN_ROLE);
_setRoleAdmin(SIGNER_ROLE, ADMIN_ROLE);
}
/**
* Perform any necessary state migrations between Factory versions
* @dev Callable by anyone but in practice will get called atomically when the Factory implementation is updated.
*/
function upgrade() external {
require(version < CODE_VERSION, "Already upgraded");
/* Start migration code */
delete _unusedSlot1;
delete _unusedSlot2;
/* End migration code */
version = CODE_VERSION;
}
/***********
* Actions *
***********/
/**
* Deploy a specific version of the specified template
* @dev Requires a signature of the deployment payload (caller, template name and initialization data) by a `SIGNER_ROLE` wallet
* @param request The struct containing the deployment request
* @param signature EIP712 signature of the request
*/
function deploy(
DeploymentRequest calldata request,
bytes calldata signature
)
external
payable
validRequestOnly(request.metadata)
signedOnly(_hash(request), signature)
{
_deploy(request.template, request.version, request.initData);
}
/**
* Call a deployed template instance
* @dev Requires a signature of the call payload (caller, instance address and call data) by a `SIGNER_ROLE` wallet
* @param request The struct containing the call request
* @param signature EIP712 signature of the request
*/
function call(CallRequest calldata request, bytes calldata signature)
external
payable
operatorOnly(request.instance)
validRequestOnly(request.metadata)
signedOnly(_hash(request), signature)
{
_call(request.instance, request.callData, msg.value);
}
/******************
* View functions *
******************/
/**
* Get a list of all templates registered with the factory
* @return templateNames List of all template names that have been registered
*/
function templates() external view returns (string[] memory templateNames) {
uint256 count = _templateNames.length;
templateNames = new string[](count);
for (uint256 i = 0; i < count; i++) {
templateNames[i] = _templateNames[i];
}
}
/**
* Get a list of all registered versions of a template
* @param templateName Name of the template
* @return templateVersions List of all version numbers that have been registered for that template
*/
function versions(string memory templateName)
external
view
returns (uint256[] memory templateVersions)
{
uint256 count = _templateVersions[templateName].length;
templateVersions = new uint256[](count);
for (uint256 i = 0; i < count; i++) {
templateVersions[i] = _templateVersions[templateName][i];
}
}
/**
* Get the implementation address of a specific version of a template
* @param templateName Name of the template
* @param templateVersion Version of the implementation
* @return Address of the implementation contract
*/
function implementation(string memory templateName, uint256 templateVersion)
external
view
returns (address)
{
return _templateImplementations[templateName][templateVersion];
}
/**
* Check if the `operator` address is allowed to operate on template instance `instance`
* @param instance Address of the template instance
* @param operator Address of the operator
*/
function isOperator(address instance, address operator)
public
view
returns (bool)
{
return hasRole(OPERATOR_ROLE(instance), operator);
}
/**
* Get the operator role for the specified instance
* @param instance Address of the template instance that the role will be operating on
* @return Operator role identifier
*/
function OPERATOR_ROLE(address instance) public pure returns (bytes32) {
return keccak256(abi.encodePacked(instance, "OPERATOR"));
}
/*******************
* Admin functions *
*******************/
/**
* Register a new implementation with the Factory
* @dev Implementation details will be read and validated on-chain
* @param implementationAddress Address of the template implementation contract
*/
function registerTemplate(address implementationAddress)
public
onlyRole(ADMIN_ROLE)
{
require(
Address.isContract(implementationAddress),
"Not a valid contract"
);
// Read template information from the implementation contract
ITemplate templateImplementation = ITemplate(implementationAddress);
string memory templateName = templateImplementation.NAME();
uint256 templateVersion = templateImplementation.VERSION();
// Template version must be non-zero for correct registration
require(templateVersion > 0, "Template version must be >0");
// Store the template information
_setTemplate(templateName, templateVersion, implementationAddress);
}
/**
* Update contract whitelist status
* @dev For security reasons, we don't allow arbitrary contracts to be called via Factory. Contracts deployed via the Factory will be automatically whitelisted. This function is intended to allow us to disable any contracts that turn out to be vulnerable or malicious.
* @param instance Contract address
* @param newStatus New whitelist status
*/
function setWhitelisted(address instance, bool newStatus)
external
onlyRole(ADMIN_ROLE)
{
_setWhitelisted(instance, newStatus);
}
/**
* Update the operator status of `instance` for `operator`
* @param instance The template instance that will be operated on
* @param operator The address of the operator that we want to update the status of
* @param allowed New operator status
*/
function setOperator(
address instance,
address operator,
bool allowed
) external onlyRole(ADMIN_ROLE) {
_setOperator(instance, operator, allowed);
}
/*************
* Internals *
*************/
/**
* @dev Internal function without access rights checks for storing template implemetation details
* @param templateName Name of the template
* @param templateVersion Template version
* @param implementationAddress Address of the implementation contract
*/
function _setTemplate(
string memory templateName,
uint256 templateVersion,
address implementationAddress
) internal {
require(
_templateImplementations[templateName][templateVersion] ==
address(0),
"Version already exists"
);
// Store the template implementation address
_templateImplementations[templateName][
templateVersion
] = implementationAddress;
// Update the list of available versions for a template
_templateVersions[templateName].push(templateVersion);
// Check if we're adding a new template and update template list if needed
if (latestImplementation[templateName] == address(0)) {
_templateNames.push(templateName);
}
// Update the current implementation version & address if needed
if (templateVersion > latestVersion[templateName]) {
latestVersion[templateName] = templateVersion;
latestImplementation[templateName] = implementationAddress;
}
emit TemplateAdded(
templateName,
templateVersion,
implementationAddress
);
}
/**
* @dev Internal function for updating whitelist status
* @param instance Contract address
* @param newStatus New whitelist status
*/
function _setWhitelisted(address instance, bool newStatus) internal {
whitelisted[instance] = newStatus;
}
/**
* @dev Internal function for granting or revoking contract operator role from an address
* @param instance Contract address
* @param operator Operator address
* @param allowed New operator status
*/
function _setOperator(
address instance,
address operator,
bool allowed
) internal {
if (allowed) {
_grantRole(OPERATOR_ROLE(instance), operator);
} else {
_revokeRole(OPERATOR_ROLE(instance), operator);
}
emit OperatorChanged(instance, operator, allowed);
}
/**
* @dev Internal function for deploying a template instance
* @param templateName Name of the template to be deployed
* @param templateVersion Version of the template implementation
* @param initdata Initialization data for the newly deployed instance
*/
function _deploy(
string calldata templateName,
uint256 templateVersion,
bytes calldata initdata
) internal {
address implementationAddress = _templateImplementations[templateName][
templateVersion
];
require(implementationAddress != address(0), "Missing implementation");
address clone = Clones.clone(implementationAddress);
emit TemplateDeployed(templateName, templateVersion, clone);
_setOperator(clone, msg.sender, true);
_setWhitelisted(clone, true);
_call(clone, initdata, 0);
}
/**
* @dev Internal function for calling a template instance
* @param instance Address of the template instance
* @param data Call data to be forwarded to the instance
* @param value Fees to be forwarded with the call
*/
function _call(
address instance,
bytes calldata data,
uint256 value
) internal {
require(whitelisted[instance], "Contract not whitelisted");
assembly {
let _calldata := mload(0x40)
calldatacopy(_calldata, data.offset, data.length)
let result := call(
gas(),
instance,
value,
_calldata,
data.length,
0,
0
)
let returndata := mload(0x40)
let size := returndatasize()
returndatacopy(returndata, 0, size)
switch result
case 0 {
revert(returndata, size)
}
default {
return(returndata, size)
}
}
}
/**
* @dev Hash function for the EIP712 domain separator
*/
function _eip712domainSeparator() internal view returns (bytes32) {
return
keccak256(
abi.encode(
_DOMAIN_TYPEHASH,
keccak256("Factory"),
keccak256("1"),
block.chainid,
address(this)
)
);
}
/**
* @dev Hash function for DeploymentRequest structs
*/
function _hash(DeploymentRequest calldata request)
internal
pure
returns (bytes32)
{
return
keccak256(
abi.encode(
_DEPLOYMENT_REQUEST_TYPEHASH,
keccak256(bytes(request.template)),
request.version,
keccak256(request.initData),
_hash(request.metadata)
)
);
}
/**
* @dev Hash function for RequestMetadata structs
*/
function _hash(RequestMetadata calldata metadata)
internal
pure
returns (bytes32)
{
return
keccak256(
abi.encode(
_REQUEST_METADATA_TYPEHASH,
metadata.caller,
metadata.expiration
)
);
}
/**
* @dev Hash function for CallRequest structs
*/
function _hash(CallRequest calldata request)
internal
pure
returns (bytes32)
{
return
keccak256(
abi.encode(
_CALL_REQUEST_TYPEHASH,
request.instance,
keccak256(request.callData),
_hash(request.metadata)
)
);
}
/*************
* Modifiers *
*************/
/**
* @dev Modifier for restricting the caller to be an operator of contract at address `instance`
*/
modifier operatorOnly(address instance) {
require(isOperator(instance, msg.sender), "Access denied");
_;
}
/**
* @dev Modifier for checking if `signature` is a valid signature of `message` by a `SIGNER_ROLE` wallet
*/
modifier signedOnly(bytes32 structHash, bytes calldata signature) {
bytes32 digest = ECDSA.toTypedDataHash(
_eip712domainSeparator(),
structHash
);
address signer = ECDSA.recover(digest, signature);
require(hasRole(SIGNER_ROLE, signer), "Signer not recognized");
_;
}
/**
* @dev Modifier for validating request metadata for instance deployments and calls
*/
modifier validRequestOnly(RequestMetadata calldata metadata) {
require(msg.sender == metadata.caller, "Wrong caller");
require(block.timestamp < metadata.expiration, "Request expired");
_;
}
}
Read Contract
ADMIN_ROLE 0x75b238fc → bytes32
CODE_VERSION 0x68aec8e2 → uint256
DEFAULT_ADMIN_ROLE 0xa217fddf → bytes32
OPERATOR_ROLE 0x636169d8 → bytes32
SIGNER_ROLE 0xa1ebf35d → bytes32
getRoleAdmin 0x248a9ca3 → bytes32
hasRole 0x91d14854 → bool
implementation 0x860a871f → address
isOperator 0xb6363cf2 → bool
latestImplementation 0x1f1097e5 → address
latestVersion 0x070f8f5a → uint256
supportsInterface 0x01ffc9a7 → bool
templates 0x3a283d7d → string[]
version 0x54fd4d50 → uint256
versions 0x5107f348 → uint256[]
whitelisted 0xd936547e → bool
Write Contract 10 functions
These functions modify contract state and require a wallet transaction to execute.
call 0xd091fb27
tuple request
bytes signature
deploy 0x06e24fb9
tuple request
bytes signature
grantRole 0x2f2ff15d
bytes32 role
address account
initialize 0x485cc955
address factoryOwner
address factorySigner
registerTemplate 0x539ac472
address implementationAddress
renounceRole 0x36568abe
bytes32 role
address account
revokeRole 0xd547741f
bytes32 role
address account
setOperator 0xbc735d90
address instance
address operator
bool allowed
setWhitelisted 0x9281aa0b
address instance
bool newStatus
upgrade 0xd55ec697
No parameters
Recent Transactions
No transactions found for this address