Cryo Explorer Ethereum Mainnet

Address Contract Verified

Address 0x84bA4aEcfDe39D69686a841BAb434C32d179a169
Balance 0 ETH
Nonce 1
Code Size 10235 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

10235 bytes
0x608060405234801561001057600080fd5b50600436106102f45760003560e01c806378de7d1911610191578063a9059cbb116100e3578063d795ede111610097578063e879b11811610071578063e879b118146105a4578063ea105ac7146105ac578063fa4e4a37146105b4576102f4565b8063d795ede114610576578063dd62ed3e1461057e578063e531d8c714610591576102f4565b8063beda2483116100c8578063beda248314610548578063d505accf1461055b578063d5a957711461056e576102f4565b8063a9059cbb1461052d578063b7840a9114610540576102f4565b806395d89b4111610145578063a457c2d71161011f578063a457c2d7146104f4578063a65ad63e14610507578063a7d59b591461051a576102f4565b806395d89b41146104c6578063981b24d0146104ce57806398e83051146104e1576102f4565b80637ecebe00116101765780637ecebe00146104985780638233dffb146104ab57806394e90e69146104b3576102f4565b806378de7d191461046557806379cc679014610485576102f4565b806352d567921161024a5780636221a54b116101fe57806370a08231116101d857806370a08231146104425780637526b08a14610455578063757991a81461045d576102f4565b80636221a54b146104125780636dd5b69d1461041a5780636e9960c31461043a576102f4565b80635449b7981161022f5780635449b798146103ef5780635884965f146104025780635d3ea8f11461040a576102f4565b806352d56792146103d457806353adf2cb146103e7576102f4565b806323b872dd116102ac5780633950935111610286578063395093511461039957806342966c68146103ac5780634ee2cd7e146103c1576102f4565b806323b872dd14610369578063313ce5671461037c5780633644e51514610391576102f4565b8063095ea7b3116102dd578063095ea7b31461032c57806318160ddd1461034c578063199ab75d14610354576102f4565b80630389a24e146102f957806306fdde0314610317575b600080fd5b6103016105bc565b60405161030e919061237f565b60405180910390f35b61031f6105e0565b60405161030e9190612396565b61033f61033a36600461224d565b610677565b60405161030e9190612374565b610301610695565b61035c61069b565b60405161030e9190612360565b61033f6103773660046121a1565b6106cf565b610384610756565b60405161030e91906125b9565b61030161075f565b61033f6103a736600461224d565b61076e565b6103bf6103ba366004612276565b6107bc565b005b6103016103cf36600461224d565b6107d0565b6103016103e23660046122af565b610819565b61030161084a565b6103bf6103fd366004612276565b61086e565b61035c610969565b610301610994565b6103016109bf565b61042d610428366004612276565b6109e6565b60405161030e9190612581565b61035c610a3a565b610301610450366004612155565b610a65565b610301610a80565b610301610aa4565b610478610473366004612276565b610aaa565b60405161030e9190612598565b6103bf61049336600461224d565b610b0f565b6103016104a6366004612155565b610b64565b610301610b85565b61033f6104c1366004612276565b610ba9565b61031f610bb6565b6103016104dc366004612276565b610c17565b61042d6104ef366004612276565b610c47565b61033f61050236600461224d565b610c84565b6103bf61051536600461228e565b610cec565b610478610528366004612276565b610de2565b61033f61053b36600461224d565b610e30565b610301610e44565b6103bf610556366004612276565b610e68565b6103bf6105693660046121dc565b610fd4565b61030161118b565b6103016111b6565b61030161058c36600461216f565b6111c2565b61033f61059f366004612276565b6111ed565b6103016111fa565b6103bf611206565b6103016112b0565b7fb71664c254c497a6d50dda0b4c3b34b26d2396ff742c29c0cb39b2d34a37f50781565b60038054604080516020601f600260001961010060018816150201909516949094049384018190048102820181019092528281526060939092909183018282801561066c5780601f106106415761010080835404028352916020019161066c565b820191906000526020600020905b81548152906001019060200180831161064f57829003601f168201915b505050505090505b90565b600061068b610684611515565b8484611519565b5060015b92915050565b60025490565b60006106c67f1ec8dad1d94e8c5a1dcdf6c4745ea3ed8c3f0f424e1b4d4ba2ffa9a9875fc0926109e6565b60200151905090565b60006106dc848484611605565b61074c846106e8611515565b610747856040518060600160405280602881526020016126eb602891396001600160a01b038a16600090815260016020526040812090610726611515565b6001600160a01b031681526020810191909152604001600020549190611760565b611519565b5060019392505050565b60055460ff1690565b60006107696117f7565b905090565b600061068b61077b611515565b84610747856001600061078c611515565b6001600160a01b03908116825260208083019390935260409182016000908120918c16815292529020549061145f565b6107cd6107c7611515565b826118c1565b50565b6001600160a01b0382166000908152600660205260408120819081906107f79085906119bd565b915091508161080e5761080985610a65565b610810565b805b95945050505050565b60008160405160200161082c9190612344565b6040516020818303038152906040528051906020012090505b919050565b7fa729ef4e25027bc652fc8b5c4d1d902947361fa7c8e7b4905e877823f27331b381565b7fa729ef4e25027bc652fc8b5c4d1d902947361fa7c8e7b4905e877823f27331b3600052600b6020527fffc36f802faa194a6d4caed967ce60079d1789b50aaabf942244d6cecbcb9314546001600160a01b031633146108e95760405162461bcd60e51b81526004016108e090612400565b60405180910390fd5b6108f4600f82611ac1565b6109105760405162461bcd60e51b81526004016108e0906124a5565b6000818152600e60205260408082208054838255600190910192909255517f2f6191371f2d30882f348c3fedb0661e7d34da33a44c4d44dc8aaca6d8d379459061095d9084908490612388565b60405180910390a15050565b60006106c67fa19d0db335544d3c3ec35c34b9b35a51bd4861f7162de07d5af409611794db046109e6565b60006106c67f322c05de6115faacfacfbb9e9dba1e2783b1b27705406d17d876122098819d3b6109e6565b60006106c67f8bdc034209cd34465f1fe5127e9f4c5350103200f3bf7dc8daa75003ccf585e05b6109ee612103565b6109f9600c83611acd565b610a155760405162461bcd60e51b81526004016108e0906123c9565b506040805180820182528281526000928352600b602090815291909220549082015290565b60006106c67fa729ef4e25027bc652fc8b5c4d1d902947361fa7c8e7b4905e877823f27331b36109e6565b6001600160a01b031660009081526020819052604090205490565b7fa19d0db335544d3c3ec35c34b9b35a51bd4861f7162de07d5af409611794db0481565b60115490565b610ab261211a565b610abd600f83611acd565b610ad95760405162461bcd60e51b81526004016108e090612437565b50604080516060810182528281526000838152600e60208181528483208054828601529590925290526001909201549082015290565b6000610b418260405180606001604052806024815260200161271360249139610b3a8661058c611515565b9190611760565b9050610b5583610b4f611515565b83611519565b610b5f83836118c1565b505050565b6001600160a01b0381166000908152600a6020526040812061068f90611511565b7f1ec8dad1d94e8c5a1dcdf6c4745ea3ed8c3f0f424e1b4d4ba2ffa9a9875fc09281565b600061068f600c83611acd565b60048054604080516020601f600260001961010060018816150201909516949094049384018190048102820181019092528281526060939092909183018282801561066c5780601f106106415761010080835404028352916020019161066c565b6000806000610c278460076119bd565b9150915081610c3d57610c38610695565b610c3f565b805b949350505050565b610c4f612103565b6000610c5c600c84611ad9565b6040805180820182528281526000928352600b60209081529190922054908201529392505050565b600061068b610c91611515565b84610747856040518060600160405280602581526020016127a16025913960016000610cbb611515565b6001600160a01b03908116825260208083019390935260409182016000908120918d16815292529020549190611760565b7fa729ef4e25027bc652fc8b5c4d1d902947361fa7c8e7b4905e877823f27331b3600052600b6020527fffc36f802faa194a6d4caed967ce60079d1789b50aaabf942244d6cecbcb9314546001600160a01b03163314610d5e5760405162461bcd60e51b81526004016108e090612400565b610d69600f8361144c565b610d855760405162461bcd60e51b81526004016108e0906124dc565b6040805180820182528281524260208083019182526000868152600e9091528390209151825551600190910155517f418d422a38ef786681f03ffea8d9ae04b8cad6da2488f8200a80daddd13b870b9061095d9084908490612388565b610dea61211a565b6000610df7600f84611ad9565b604080516060810182528281526000838152600e6020818152848320805482860152959092529052600190920154908201529392505050565b600061068b610e3d611515565b8484611605565b7f322c05de6115faacfacfbb9e9dba1e2783b1b27705406d17d876122098819d3b81565b7fa729ef4e25027bc652fc8b5c4d1d902947361fa7c8e7b4905e877823f27331b3600052600b6020527fffc36f802faa194a6d4caed967ce60079d1789b50aaabf942244d6cecbcb9314546001600160a01b03163314610eda5760405162461bcd60e51b81526004016108e090612400565b610ee3816111ed565b610eff5760405162461bcd60e51b81526004016108e09061246e565b7f0ddad97eb7f0ed5db6e3a1f3e5e7c4ee24c1c1fbe12f27761684cb8ed620c912546000828152600e602052604090206001015401421015610f535760405162461bcd60e51b81526004016108e09061254a565b6000818152600e6020526040902054610f6d600c8361144c565b506000828152600b60205260409020819055610f8a600f83611ac1565b506000828152600e602052604080822082815560010191909155517fbb7640d9671cd2b6ad67894615875d39f4222b2b047d3dbfe122026796ac36b49061095d9084908490612388565b83421115611029576040805162461bcd60e51b815260206004820152601d60248201527f45524332305065726d69743a206578706972656420646561646c696e65000000604482015290519081900360640190fd5b6001600160a01b0387166000908152600a602052604081207f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c99089908990899061107290611511565b8960405160200180878152602001866001600160a01b03168152602001856001600160a01b03168152602001848152602001838152602001828152602001965050505050505060405160208183030381529060405280519060200120905060006110db82611ae5565b905060006110eb82878787611b4c565b9050896001600160a01b0316816001600160a01b031614611153576040805162461bcd60e51b815260206004820152601e60248201527f45524332305065726d69743a20696e76616c6964207369676e61747572650000604482015290519081900360640190fd5b6001600160a01b038a166000908152600a6020526040902061117490611cc1565b61117f8a8a8a611519565b50505050505050505050565b60006106c67fb71664c254c497a6d50dda0b4c3b34b26d2396ff742c29c0cb39b2d34a37f5076109e6565b6000610769600f611cca565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b600061068f600f83611acd565b6000610769600c611cca565b61120e610994565b601254014210156112315760405162461bcd60e51b81526004016108e090612513565b60118054600101905542601255611246611cd5565b50600061125161118b565b905061126761125e61069b565b6002830461135c565b61127261125e610969565b7fa8eb7e5fda38cf18e907bee8da786b6c9477deefbd4f2a7869f4a12abb68b4c3601154826040516112a5929190612388565b60405180910390a150565b7f8bdc034209cd34465f1fe5127e9f4c5350103200f3bf7dc8daa75003ccf585e081565b6112df600c8361144c565b506000828152600b602052604090819020829055517f418d422a38ef786681f03ffea8d9ae04b8cad6da2488f8200a80daddd13b870b906113239084908490612388565b60405180910390a17fbb7640d9671cd2b6ad67894615875d39f4222b2b047d3dbfe122026796ac36b4828260405161095d929190612388565b6001600160a01b0382166113b7576040805162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015290519081900360640190fd5b6113c360008383611d29565b6002546113d0908261145f565b6002556001600160a01b0382166000908152602081905260409020546113f6908261145f565b6001600160a01b0383166000818152602081815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b60006114588383611d34565b9392505050565b600082820183811015611458576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b6114c4838383610b5f565b6001600160a01b0383166114e8576114db82611d7e565b6114e3611da8565b610b5f565b6001600160a01b0382166114ff576114db83611d7e565b61150883611d7e565b610b5f82611d7e565b5490565b3390565b6001600160a01b03831661155e5760405162461bcd60e51b815260040180806020018281038252602481526020018061277d6024913960400191505060405180910390fd5b6001600160a01b0382166115a35760405162461bcd60e51b815260040180806020018281038252602281526020018061265f6022913960400191505060405180910390fd5b6001600160a01b03808416600081815260016020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b6001600160a01b03831661164a5760405162461bcd60e51b81526004018080602001828103825260258152602001806127586025913960400191505060405180910390fd5b6001600160a01b03821661168f5760405162461bcd60e51b815260040180806020018281038252602381526020018061261a6023913960400191505060405180910390fd5b61169a838383611d29565b6116d781604051806060016040528060268152602001612681602691396001600160a01b0386166000908152602081905260409020549190611760565b6001600160a01b038085166000908152602081905260408082209390935590841681522054611706908261145f565b6001600160a01b038084166000818152602081815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b600081848411156117ef5760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b838110156117b457818101518382015260200161179c565b50505050905090810190601f1680156117e15780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b60007f0000000000000000000000000000000000000000000000000000000000000001611822611db7565b141561184f57507f9bd9f25970a4079fee76aa55a8e631a8187598812a9f6a28aaf13d09a3382726610674565b6118ba7f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f7f770748fd11b3254fddc29387068a739dc890700e2b90b4bd16d84ce4936774c87fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6611dbb565b9050610674565b6001600160a01b0382166119065760405162461bcd60e51b81526004018080602001828103825260218152602001806127376021913960400191505060405180910390fd5b61191282600083611d29565b61194f8160405180606001604052806022815260200161263d602291396001600160a01b0385166000908152602081905260409020549190611760565b6001600160a01b0383166000908152602081905260409020556002546119759082611e1d565b6002556040805182815290516000916001600160a01b038516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9181900360200190a35050565b60008060008411611a15576040805162461bcd60e51b815260206004820152601660248201527f4552433230536e617073686f743a206964206973203000000000000000000000604482015290519081900360640190fd5b611a1f6009611511565b841115611a73576040805162461bcd60e51b815260206004820152601d60248201527f4552433230536e617073686f743a206e6f6e6578697374656e74206964000000604482015290519081900360640190fd5b6000611a7f8486611e7a565b8454909150811415611a98576000809250925050611aba565b6001846001018281548110611aa957fe5b906000526020600020015492509250505b9250929050565b60006114588383611f1b565b60006114588383611fe1565b60006114588383611ff9565b6000611aef6117f7565b8260405160200180807f190100000000000000000000000000000000000000000000000000000000000081525060020183815260200182815260200192505050604051602081830303815290604052805190602001209050919050565b60007f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0821115611bad5760405162461bcd60e51b81526004018080602001828103825260228152602001806126a76022913960400191505060405180910390fd5b8360ff16601b1480611bc257508360ff16601c145b611bfd5760405162461bcd60e51b81526004018080602001828103825260228152602001806126c96022913960400191505060405180910390fd5b600060018686868660405160008152602001604052604051808581526020018460ff1681526020018381526020018281526020019450505050506020604051602081039080840390855afa158015611c59573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b038116610810576040805162461bcd60e51b815260206004820152601860248201527f45434453413a20696e76616c6964207369676e61747572650000000000000000604482015290519081900360640190fd5b80546001019055565b600061068f82611511565b6000611ce16009611cc1565b6000611ced6009611511565b6040805182815290519192507f8030e83b04d87bef53480e26263266d6ca66863aa8506aca6f2559d18aa1cb67919081900360200190a1905090565b610b5f8383836114b9565b6000611d408383611fe1565b611d765750815460018181018455600084815260208082209093018490558454848252828601909352604090209190915561068f565b50600061068f565b6001600160a01b03811660009081526006602052604090206107cd90611da383610a65565b61205d565b611db56007611da3610695565b565b4690565b6000838383611dc8611db7565b3060405160200180868152602001858152602001848152602001838152602001826001600160a01b03168152602001955050505050506040516020818303038152906040528051906020012090509392505050565b600082821115611e74576040805162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b50900390565b8154600090611e8b5750600061068f565b82546000905b80821015611eda576000611ea583836120a9565b905084868281548110611eb457fe5b90600052602060002001541115611ecd57809150611ed4565b8060010192505b50611e91565b600082118015611f02575083856001840381548110611ef557fe5b9060005260206000200154145b15611f13575060001901905061068f565b50905061068f565b60008181526001830160205260408120548015611fd75783546000198083019190810190600090879083908110611f4e57fe5b9060005260206000200154905080876000018481548110611f6b57fe5b600091825260208083209091019290925582815260018981019092526040902090840190558654879080611f9b57fe5b6001900381819060005260206000200160009055905586600101600087815260200190815260200160002060009055600194505050505061068f565b600091505061068f565b60009081526001919091016020526040902054151590565b8154600090821061203b5760405162461bcd60e51b81526004018080602001828103825260228152602001806125f86022913960400191505060405180910390fd5b82600001828154811061204a57fe5b9060005260206000200154905092915050565b60006120696009611511565b905080612075846120ce565b1015610b5f578254600180820185556000858152602080822090930193909355938401805494850181558252902090910155565b600060028083066002850601816120bc57fe5b04600283046002850401019392505050565b80546000906120df57506000610845565b8154829060001981019081106120f157fe5b90600052602060002001549050610845565b604080518082019091526000808252602082015290565b60405180606001604052806000801916815260200160008152602001600081525090565b80356001600160a01b038116811461084557600080fd5b600060208284031215612166578081fd5b6114588261213e565b60008060408385031215612181578081fd5b61218a8361213e565b91506121986020840161213e565b90509250929050565b6000806000606084860312156121b5578081fd5b6121be8461213e565b92506121cc6020850161213e565b9150604084013590509250925092565b600080600080600080600060e0888a0312156121f6578283fd5b6121ff8861213e565b965061220d6020890161213e565b95506040880135945060608801359350608088013560ff81168114612230578384fd5b9699959850939692959460a0840135945060c09093013592915050565b6000806040838503121561225f578182fd5b6122688361213e565b946020939093013593505050565b600060208284031215612287578081fd5b5035919050565b600080604083850312156122a0578182fd5b50508035926020909101359150565b600060208083850312156122c1578182fd5b823567ffffffffffffffff808211156122d8578384fd5b818501915085601f8301126122eb578384fd5b8135818111156122f757fe5b604051601f8201601f191681018501838111828210171561231457fe5b604052818152838201850188101561232a578586fd5b818585018683013790810190930193909352509392505050565b600082516123568184602087016125c7565b9190910192915050565b6001600160a01b0391909116815260200190565b901515815260200190565b90815260200190565b918252602082015260400190565b60006020825282518060208401526123b58160408501602087016125c7565b601f01601f19169190910160400192915050565b6020808252600a908201527f6e6f7420636f6e66696700000000000000000000000000000000000000000000604082015260600190565b6020808252600a908201527f6f6e6c792061646d696e00000000000000000000000000000000000000000000604082015260600190565b6020808252600b908201527f6e6f742070656e64696e67000000000000000000000000000000000000000000604082015260600190565b60208082526019908201527f4e6f2070656e64696e6720636f6e666967494420666f756e6400000000000000604082015260600190565b60208082526012908201527f6e6f2070656e64696e6720726571756573740000000000000000000000000000604082015260600190565b60208082526016908201527f7265717565737420616c72656164792065786973747300000000000000000000604082015260600190565b60208082526014908201527f6e6f7420726561647920746f20616476616e6365000000000000000000000000604082015260600190565b60208082526009908201527f746f6f206561726c790000000000000000000000000000000000000000000000604082015260600190565b815181526020918201519181019190915260400190565b81518152602080830151908201526040918201519181019190915260600190565b60ff91909116815260200190565b60005b838110156125e25781810151838201526020016125ca565b838111156125f1576000848401525b5050505056fe456e756d657261626c655365743a20696e646578206f7574206f6620626f756e647345524332303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a206275726e20616d6f756e7420657863656564732062616c616e636545524332303a20617070726f766520746f20746865207a65726f206164647265737345524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e636545434453413a20696e76616c6964207369676e6174757265202773272076616c756545434453413a20696e76616c6964207369676e6174757265202776272076616c756545524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636545524332303a206275726e20616d6f756e74206578636565647320616c6c6f77616e636545524332303a206275726e2066726f6d20746865207a65726f206164647265737345524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f206164647265737345524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa2646970667358221220269353829848c160ad516ea9f107ffb9c79b2edbc13ba57e1793637535bbe0f764736f6c63430007060033

Verified Source Code Full Match

Compiler: v0.7.6+commit.7338295f EVM: istanbul Optimization: Yes (1000 runs)
Math.sol 31 lines
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    /**
     * @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, so we distribute
        return (a / 2) + (b / 2) + ((a % 2 + b % 2) / 2);
    }
}
MethodToken.sol 144 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.7.6;
pragma abicoder v2;
// pragma experimental SMTChecker;

import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {ERC20Burnable} from "@openzeppelin/contracts/token/ERC20/ERC20Burnable.sol";
import {ERC20Snapshot} from "@openzeppelin/contracts/token/ERC20/ERC20Snapshot.sol";
import {ERC20Permit} from "@openzeppelin/contracts/drafts/ERC20Permit.sol";
import {TimelockConfig} from "./TimelockConfig.sol";

interface IMethodToken {
    /* event */

    event Advanced(uint256 epoch, uint256 supplyMinted);

    /* user functions */

    function advance() external;

    /* view functions */

    function getAdmin() external view returns (address admin);

    function getTreasurer() external view returns (address treasurer);

    function getDistributor() external view returns (address distributor);

    function getTimelock() external view returns (uint256 timelock);

    function getInflation() external view returns (uint256 inflation);

    function getEpochDuration() external view returns (uint256 epochDuration);
}

// ⚗️ MethodToken ⚗️
contract MethodToken is
    IMethodToken,
    ERC20("Method", "MTHD"),
    ERC20Burnable,
    ERC20Snapshot,
    ERC20Permit("Method"),
    TimelockConfig
{
    /* constants */

    bytes32 public constant INFLATION_CONFIG_ID = keccak256("Inflation");
    bytes32 public constant EPOCH_DURATION_CONFIG_ID = keccak256("EpochDuration");
    bytes32 public constant DISTRIBUTOR_CONFIG_ID = keccak256("Distributor");
    bytes32 public constant TREASURER_CONFIG_ID = keccak256("Treasurer");

    /* storage */

    uint256 private _epoch;
    uint256 private _previousEpochTimestamp;

    /* constructor function */

    constructor(
        address admin,
        address distributor,
        address treasurer,
        uint256 inflation,
        uint256 epochDuration,
        uint256 timelock,
        uint256 supply,
        uint256 epochStart
    ) TimelockConfig(admin, timelock) {
        // set config
        TimelockConfig._setRawConfig(DISTRIBUTOR_CONFIG_ID, uint256(distributor));
        TimelockConfig._setRawConfig(TREASURER_CONFIG_ID, uint256(treasurer));
        TimelockConfig._setRawConfig(INFLATION_CONFIG_ID, inflation);
        TimelockConfig._setRawConfig(EPOCH_DURATION_CONFIG_ID, epochDuration);

        // set epoch timestamp
        _previousEpochTimestamp = epochStart;

        // mint initial supply
        ERC20._mint(treasurer, supply);
    }

    /* user functions */

    function advance() external override {
        // require new epoch
        require(
            block.timestamp >= _previousEpochTimestamp + getEpochDuration(),
            "not ready to advance"
        );
        // set epoch
        _epoch++;
        _previousEpochTimestamp = block.timestamp;
        // create snapshot
        ERC20Snapshot._snapshot();
        // calculate inflation amount
        uint256 supplyMinted = getInflation();

        // mint to treasurer and distributor
        ERC20._mint(getTreasurer(), supplyMinted/2);
        ERC20._mint(getDistributor(), supplyMinted/2);
        
        // emit event
        emit Advanced(_epoch, supplyMinted);
    }

    /* hook functions */

    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal override(ERC20, ERC20Snapshot) {
        ERC20Snapshot._beforeTokenTransfer(from, to, amount);
    }

    /* view functions */
    function getEpoch() public view returns (uint256 epoch) {
        return _epoch;
    }

    function getAdmin() public view override returns (address admin) {
        return address(TimelockConfig.getConfig(TimelockConfig.ADMIN_CONFIG_ID).value);
    }

    function getTreasurer() public view override returns (address treasurer) {
        return address(TimelockConfig.getConfig(TREASURER_CONFIG_ID).value);
    }

    function getDistributor() public view override returns (address distributor) {
        return address(TimelockConfig.getConfig(DISTRIBUTOR_CONFIG_ID).value);
    }

    function getTimelock() public view override returns (uint256 timelock) {
        return TimelockConfig.getConfig(TimelockConfig.TIMELOCK_CONFIG_ID).value;
    }

    function getInflation() public view override returns (uint256 inflation) {
        return TimelockConfig.getConfig(INFLATION_CONFIG_ID).value;
    }

    function getEpochDuration() public view override returns (uint256 epochDuration) {
        return TimelockConfig.getConfig(EPOCH_DURATION_CONFIG_ID).value;
    }
}
Arrays.sol 47 lines
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "../math/Math.sol";

/**
 * @dev Collection of functions related to array types.
 */
library Arrays {
   /**
     * @dev Searches a sorted `array` and returns the first index that contains
     * a value greater or equal to `element`. If no such index exists (i.e. all
     * values in the array are strictly less than `element`), the array length is
     * returned. Time complexity O(log n).
     *
     * `array` is expected to be sorted in ascending order, and to contain no
     * repeated elements.
     */
    function findUpperBound(uint256[] storage array, uint256 element) internal view returns (uint256) {
        if (array.length == 0) {
            return 0;
        }

        uint256 low = 0;
        uint256 high = array.length;

        while (low < high) {
            uint256 mid = Math.average(low, high);

            // Note that mid will always be strictly less than high (i.e. it will be a valid array index)
            // because Math.average rounds down (it does integer division with truncation).
            if (array[mid] > element) {
                high = mid;
            } else {
                low = mid + 1;
            }
        }

        // At this point `low` is the exclusive upper bound. We will return the inclusive upper bound.
        if (low > 0 && array[low - 1] == element) {
            return low - 1;
        } else {
            return low;
        }
    }
}
EIP712.sol 108 lines
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

/**
 * @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data.
 *
 * The encoding specified in the EIP is very generic, and such a generic implementation in Solidity is not feasible,
 * thus this contract does not implement the encoding itself. Protocols need to implement the type-specific encoding
 * they need in their contracts using a combination of `abi.encode` and `keccak256`.
 *
 * This contract implements the EIP 712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding
 * scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA
 * ({_hashTypedDataV4}).
 *
 * The implementation of the domain separator was designed to be as efficient as possible while still properly updating
 * the chain id to protect against replay attacks on an eventual fork of the chain.
 *
 * NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method
 * https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].
 *
 * _Available since v3.4._
 */
abstract contract EIP712 {
    /* solhint-disable var-name-mixedcase */
    // Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to
    // invalidate the cached domain separator if the chain id changes.
    bytes32 private immutable _CACHED_DOMAIN_SEPARATOR;
    uint256 private immutable _CACHED_CHAIN_ID;

    bytes32 private immutable _HASHED_NAME;
    bytes32 private immutable _HASHED_VERSION;
    bytes32 private immutable _TYPE_HASH;
    /* solhint-enable var-name-mixedcase */

    /**
     * @dev Initializes the domain separator and parameter caches.
     *
     * The meaning of `name` and `version` is specified in
     * https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]:
     *
     * - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.
     * - `version`: the current major version of the signing domain.
     *
     * NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart
     * contract upgrade].
     */
    constructor(string memory name, string memory version) internal {
        bytes32 hashedName = keccak256(bytes(name));
        bytes32 hashedVersion = keccak256(bytes(version));
        bytes32 typeHash = keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");
        _HASHED_NAME = hashedName;
        _HASHED_VERSION = hashedVersion;
        _CACHED_CHAIN_ID = _getChainId();
        _CACHED_DOMAIN_SEPARATOR = _buildDomainSeparator(typeHash, hashedName, hashedVersion);
        _TYPE_HASH = typeHash;
    }

    /**
     * @dev Returns the domain separator for the current chain.
     */
    function _domainSeparatorV4() internal view virtual returns (bytes32) {
        if (_getChainId() == _CACHED_CHAIN_ID) {
            return _CACHED_DOMAIN_SEPARATOR;
        } else {
            return _buildDomainSeparator(_TYPE_HASH, _HASHED_NAME, _HASHED_VERSION);
        }
    }

    function _buildDomainSeparator(bytes32 typeHash, bytes32 name, bytes32 version) private view returns (bytes32) {
        return keccak256(
            abi.encode(
                typeHash,
                name,
                version,
                _getChainId(),
                address(this)
            )
        );
    }

    /**
     * @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this
     * function returns the hash of the fully encoded EIP712 message for this domain.
     *
     * This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example:
     *
     * ```solidity
     * bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(
     *     keccak256("Mail(address to,string contents)"),
     *     mailTo,
     *     keccak256(bytes(mailContents))
     * )));
     * address signer = ECDSA.recover(digest, signature);
     * ```
     */
    function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {
        return keccak256(abi.encodePacked("\x19\x01", _domainSeparatorV4(), structHash));
    }

    function _getChainId() private view returns (uint256 chainId) {
        this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
        // solhint-disable-next-line no-inline-assembly
        assembly {
            chainId := chainid()
        }
    }
}
SafeMath.sol 214 lines
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

/**
 * @dev Wrappers over Solidity's arithmetic operations with added overflow
 * checks.
 *
 * Arithmetic operations in Solidity wrap on overflow. This can easily result
 * in bugs, because programmers usually assume that an overflow raises an
 * error, which is the standard behavior in high level programming languages.
 * `SafeMath` restores this intuition by reverting the transaction when an
 * operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 */
library SafeMath {
    /**
     * @dev Returns the addition of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        uint256 c = a + b;
        if (c < a) return (false, 0);
        return (true, c);
    }

    /**
     * @dev Returns the substraction of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        if (b > a) return (false, 0);
        return (true, a - b);
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
        // benefit is lost if 'b' is also tested.
        // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
        if (a == 0) return (true, 0);
        uint256 c = a * b;
        if (c / a != b) return (false, 0);
        return (true, c);
    }

    /**
     * @dev Returns the division of two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        if (b == 0) return (false, 0);
        return (true, a / b);
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        if (b == 0) return (false, 0);
        return (true, a % b);
    }

    /**
     * @dev Returns the addition of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `+` operator.
     *
     * Requirements:
     *
     * - Addition cannot overflow.
     */
    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        uint256 c = a + b;
        require(c >= a, "SafeMath: addition overflow");
        return c;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting on
     * overflow (when the result is negative).
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b) internal pure returns (uint256) {
        require(b <= a, "SafeMath: subtraction overflow");
        return a - b;
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `*` operator.
     *
     * Requirements:
     *
     * - Multiplication cannot overflow.
     */
    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        if (a == 0) return 0;
        uint256 c = a * b;
        require(c / a == b, "SafeMath: multiplication overflow");
        return c;
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        require(b > 0, "SafeMath: division by zero");
        return a / b;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting when dividing by zero.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b) internal pure returns (uint256) {
        require(b > 0, "SafeMath: modulo by zero");
        return a % b;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
     * overflow (when the result is negative).
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {trySub}.
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        require(b <= a, errorMessage);
        return a - b;
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting with custom message on
     * division by zero. The result is rounded towards zero.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryDiv}.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        require(b > 0, errorMessage);
        return a / b;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting with custom message when dividing by zero.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryMod}.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        require(b > 0, errorMessage);
        return a % b;
    }
}
Context.sol 24 lines
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <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 GSN 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 payable) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes memory) {
        this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
        return msg.data;
    }
}
TimelockConfig.sol 248 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.7.6;
pragma abicoder v2;

import {EnumerableSet} from "@openzeppelin/contracts/utils/EnumerableSet.sol";

interface ITimelockConfig {
    /* data types */

    struct Config {
        bytes32 id;
        uint256 value;
    }

    struct PendingRequest {
        bytes32 id;
        uint256 value;
        uint256 timestamp;
    }

    /* events */

    event ChangeRequested(bytes32 configID, uint256 value);
    event ChangeConfirmed(bytes32 configID, uint256 value);
    event ChangeCanceled(bytes32 configID, uint256 value);

    /* user functions */

    function confirmChange(bytes32 configID) external;

    /* admin functions */

    function requestChange(bytes32 configID, uint256 value) external;

    function cancelChange(bytes32 configID) external;

    /* pure functions */

    function calculateConfigID(string memory name) external pure returns (bytes32 configID);

    /* view functions */

    function getConfig(bytes32 configID) external view returns (Config memory config);

    function isConfig(bytes32 configID) external view returns (bool status);

    function getConfigCount() external view returns (uint256 count);

    function getConfigByIndex(uint256 index) external view returns (Config memory config);

    function getPending(bytes32 configID)
        external
        view
        returns (PendingRequest memory pendingRequest);

    function isPending(bytes32 configID) external view returns (bool status);

    function getPendingCount() external view returns (uint256 count);

    function getPendingByIndex(uint256 index)
        external
        view
        returns (PendingRequest memory pendingRequest);
}

contract TimelockConfig is ITimelockConfig {
    using EnumerableSet for EnumerableSet.Bytes32Set;

    /* constants */

    bytes32 public constant ADMIN_CONFIG_ID = keccak256("Admin");
    bytes32 public constant TIMELOCK_CONFIG_ID = keccak256("Timelock");

    /* storage */

    struct InternalPending {
        uint256 value;
        uint256 timestamp;
    }

    mapping(bytes32 => uint256) _config;
    EnumerableSet.Bytes32Set _configSet;

    mapping(bytes32 => InternalPending) _pending;
    EnumerableSet.Bytes32Set _pendingSet;

    /* modifiers */

    modifier onlyAdmin() {
        require(msg.sender == address(_config[ADMIN_CONFIG_ID]), "only admin");
        _;
    }

    /* constructor */

    constructor(address admin, uint256 timelock) {
        _setRawConfig(ADMIN_CONFIG_ID, uint256(admin));
        _setRawConfig(TIMELOCK_CONFIG_ID, timelock);
    }

    /* user functions */

    function confirmChange(bytes32 configID) external override onlyAdmin {
        //require existing pending configID
        require(isPending(configID), "No pending configID found");

        // require sufficient time elapsed
        require(
            block.timestamp >= _pending[configID].timestamp + _config[TIMELOCK_CONFIG_ID],
            "too early"
        );

        // get pending value
        uint256 value = _pending[configID].value;

        // commit change
        _configSet.add(configID);
        _config[configID] = value;

        // delete pending
        _pendingSet.remove(configID);
        delete _pending[configID];

        // emit event
        emit ChangeConfirmed(configID, value);
    }

    /* admin functions */

    function requestChange(bytes32 configID, uint256 value) external override onlyAdmin {
        // add to pending set
        require(_pendingSet.add(configID), "request already exists");

        // lock new value
        _pending[configID] = InternalPending(value, block.timestamp);

        // emit event
        emit ChangeRequested(configID, value);
    }

    function cancelChange(bytes32 configID) external override onlyAdmin {
        // remove from pending set
        require(_pendingSet.remove(configID), "no pending request");

        // get pending value
        uint256 value = _pending[configID].value;

        // delete pending
        delete _pending[configID];

        // emit event
        emit ChangeCanceled(configID, value);
    }

    /* convenience functions */

    function _setRawConfig(bytes32 configID, uint256 value) internal {
        // commit change
        _configSet.add(configID);
        _config[configID] = value;

        // emit event
        emit ChangeRequested(configID, value);
        emit ChangeConfirmed(configID, value);
    }

    /* pure functions */

    function calculateConfigID(string memory name) public pure override returns (bytes32 configID) {
        return keccak256(abi.encodePacked(name));
    }

    /* view functions */

    function isConfig(bytes32 configID) public view override returns (bool status) {
        return _configSet.contains(configID);
    }

    function getConfigCount() public view override returns (uint256 count) {
        return _configSet.length();
    }

    function getConfigByIndex(uint256 index)
        public
        view
        override
        returns (ITimelockConfig.Config memory config)
    {
        // get config ID
        bytes32 configID = _configSet.at(index);
        // return config
        return ITimelockConfig.Config(configID, _config[configID]);
    }

    function getConfig(bytes32 configID)
        public
        view
        override
        returns (ITimelockConfig.Config memory config)
    {
        // check for existance
        require(_configSet.contains(configID), "not config");
        // return config
        return ITimelockConfig.Config(configID, _config[configID]);
    }

    function isPending(bytes32 configID) public view override returns (bool status) {
        return _pendingSet.contains(configID);
    }

    function getPendingCount() public view override returns (uint256 count) {
        return _pendingSet.length();
    }

    function getPendingByIndex(uint256 index)
        public
        view
        override
        returns (ITimelockConfig.PendingRequest memory pendingRequest)
    {
        // get config ID
        bytes32 configID = _pendingSet.at(index);
        // return config
        return
            ITimelockConfig.PendingRequest(
                configID,
                _pending[configID].value,
                _pending[configID].timestamp
            );
    }

    function getPending(bytes32 configID)
        public
        view
        override
        returns (ITimelockConfig.PendingRequest memory pendingRequest)
    {
        // check for existance
        require(_pendingSet.contains(configID), "not pending");
        // return config
        return
            ITimelockConfig.PendingRequest(
                configID,
                _pending[configID].value,
                _pending[configID].timestamp
            );
    }
}
Counters.sol 40 lines
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "../math/SafeMath.sol";

/**
 * @title Counters
 * @author Matt Condon (@shrugs)
 * @dev Provides counters that can only be incremented or decremented by one. This can be used e.g. to track the number
 * of elements in a mapping, issuing ERC721 ids, or counting request ids.
 *
 * Include with `using Counters for Counters.Counter;`
 * Since it is not possible to overflow a 256 bit integer with increments of one, `increment` can skip the {SafeMath}
 * overflow check, thereby saving gas. This does assume however correct usage, in that the underlying `_value` is never
 * directly accessed.
 */
library Counters {
    using SafeMath for uint256;

    struct Counter {
        // This variable should never be directly accessed by users of the library: interactions must be restricted to
        // the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add
        // this feature: see https://github.com/ethereum/solidity/issues/4637
        uint256 _value; // default: 0
    }

    function current(Counter storage counter) internal view returns (uint256) {
        return counter._value;
    }

    function increment(Counter storage counter) internal {
        // The {SafeMath} overflow check can be skipped here, see the comment at the top
        counter._value += 1;
    }

    function decrement(Counter storage counter) internal {
        counter._value = counter._value.sub(1);
    }
}
ERC20.sol 306 lines
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "../../utils/Context.sol";
import "./IERC20.sol";
import "../../math/SafeMath.sol";

/**
 * @dev Implementation of the {IERC20} interface.
 *
 * This implementation is agnostic to the way tokens are created. This means
 * that a supply mechanism has to be added in a derived contract using {_mint}.
 * For a generic mechanism see {ERC20PresetMinterPauser}.
 *
 * TIP: For a detailed writeup see our guide
 * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
 * to implement supply mechanisms].
 *
 * We have followed general OpenZeppelin guidelines: functions revert instead
 * of returning `false` on failure. This behavior is nonetheless conventional
 * and does not conflict with the expectations of ERC20 applications.
 *
 * Additionally, an {Approval} event is emitted on calls to {transferFrom}.
 * This allows applications to reconstruct the allowance for all accounts just
 * by listening to said events. Other implementations of the EIP may not emit
 * these events, as it isn't required by the specification.
 *
 * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
 * functions have been added to mitigate the well-known issues around setting
 * allowances. See {IERC20-approve}.
 */
contract ERC20 is Context, IERC20 {
    using SafeMath for uint256;

    mapping (address => uint256) private _balances;

    mapping (address => mapping (address => uint256)) private _allowances;

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;
    uint8 private _decimals;

    /**
     * @dev Sets the values for {name} and {symbol}, initializes {decimals} with
     * a default value of 18.
     *
     * To select a different value for {decimals}, use {_setupDecimals}.
     *
     * All three of these values are immutable: they can only be set once during
     * construction.
     */
    constructor (string memory name_, string memory symbol_) public {
        _name = name_;
        _symbol = symbol_;
        _decimals = 18;
    }

    /**
     * @dev Returns the name of the token.
     */
    function name() public view virtual returns (string memory) {
        return _name;
    }

    /**
     * @dev Returns the symbol of the token, usually a shorter version of the
     * name.
     */
    function symbol() public view virtual returns (string memory) {
        return _symbol;
    }

    /**
     * @dev Returns the number of decimals used to get its user representation.
     * For example, if `decimals` equals `2`, a balance of `505` tokens should
     * be displayed to a user as `5,05` (`505 / 10 ** 2`).
     *
     * Tokens usually opt for a value of 18, imitating the relationship between
     * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
     * called.
     *
     * NOTE: This information is only used for _display_ purposes: it in
     * no way affects any of the arithmetic of the contract, including
     * {IERC20-balanceOf} and {IERC20-transfer}.
     */
    function decimals() public view virtual returns (uint8) {
        return _decimals;
    }

    /**
     * @dev See {IERC20-totalSupply}.
     */
    function totalSupply() public view virtual override returns (uint256) {
        return _totalSupply;
    }

    /**
     * @dev See {IERC20-balanceOf}.
     */
    function balanceOf(address account) public view virtual override returns (uint256) {
        return _balances[account];
    }

    /**
     * @dev See {IERC20-transfer}.
     *
     * Requirements:
     *
     * - `recipient` cannot be the zero address.
     * - the caller must have a balance of at least `amount`.
     */
    function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
        _transfer(_msgSender(), recipient, amount);
        return true;
    }

    /**
     * @dev See {IERC20-allowance}.
     */
    function allowance(address owner, address spender) public view virtual override returns (uint256) {
        return _allowances[owner][spender];
    }

    /**
     * @dev See {IERC20-approve}.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function approve(address spender, uint256 amount) public virtual override returns (bool) {
        _approve(_msgSender(), spender, amount);
        return true;
    }

    /**
     * @dev See {IERC20-transferFrom}.
     *
     * Emits an {Approval} event indicating the updated allowance. This is not
     * required by the EIP. See the note at the beginning of {ERC20}.
     *
     * Requirements:
     *
     * - `sender` and `recipient` cannot be the zero address.
     * - `sender` must have a balance of at least `amount`.
     * - the caller must have allowance for ``sender``'s tokens of at least
     * `amount`.
     */
    function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
        _transfer(sender, recipient, amount);
        _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
        return true;
    }

    /**
     * @dev Atomically increases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
        _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
        return true;
    }

    /**
     * @dev Atomically decreases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `spender` must have allowance for the caller of at least
     * `subtractedValue`.
     */
    function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
        _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
        return true;
    }

    /**
     * @dev Moves tokens `amount` from `sender` to `recipient`.
     *
     * This is internal function is equivalent to {transfer}, and can be used to
     * e.g. implement automatic token fees, slashing mechanisms, etc.
     *
     * Emits a {Transfer} event.
     *
     * Requirements:
     *
     * - `sender` cannot be the zero address.
     * - `recipient` cannot be the zero address.
     * - `sender` must have a balance of at least `amount`.
     */
    function _transfer(address sender, address recipient, uint256 amount) internal virtual {
        require(sender != address(0), "ERC20: transfer from the zero address");
        require(recipient != address(0), "ERC20: transfer to the zero address");

        _beforeTokenTransfer(sender, recipient, amount);

        _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
        _balances[recipient] = _balances[recipient].add(amount);
        emit Transfer(sender, recipient, amount);
    }

    /** @dev Creates `amount` tokens and assigns them to `account`, increasing
     * the total supply.
     *
     * Emits a {Transfer} event with `from` set to the zero address.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     */
    function _mint(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: mint to the zero address");

        _beforeTokenTransfer(address(0), account, amount);

        _totalSupply = _totalSupply.add(amount);
        _balances[account] = _balances[account].add(amount);
        emit Transfer(address(0), account, amount);
    }

    /**
     * @dev Destroys `amount` tokens from `account`, reducing the
     * total supply.
     *
     * Emits a {Transfer} event with `to` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     * - `account` must have at least `amount` tokens.
     */
    function _burn(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: burn from the zero address");

        _beforeTokenTransfer(account, address(0), amount);

        _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
        _totalSupply = _totalSupply.sub(amount);
        emit Transfer(account, address(0), amount);
    }

    /**
     * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
     *
     * This internal function is equivalent to `approve`, and can be used to
     * e.g. set automatic allowances for certain subsystems, etc.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `owner` cannot be the zero address.
     * - `spender` cannot be the zero address.
     */
    function _approve(address owner, address spender, uint256 amount) internal virtual {
        require(owner != address(0), "ERC20: approve from the zero address");
        require(spender != address(0), "ERC20: approve to the zero address");

        _allowances[owner][spender] = amount;
        emit Approval(owner, spender, amount);
    }

    /**
     * @dev Sets {decimals} to a value other than the default one of 18.
     *
     * WARNING: This function should only be called from the constructor. Most
     * applications that interact with token contracts will not expect
     * {decimals} to ever change, and may work incorrectly if it does.
     */
    function _setupDecimals(uint8 decimals_) internal virtual {
        _decimals = decimals_;
    }

    /**
     * @dev Hook that is called before any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * will be to transferred to `to`.
     * - when `from` is zero, `amount` tokens will be minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens will be burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
}
ECDSA.sol 86 lines
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

/**
 * @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 {
    /**
     * @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) {
        // Check the signature length
        if (signature.length != 65) {
            revert("ECDSA: invalid signature length");
        }

        // Divide the signature in r, s and v variables
        bytes32 r;
        bytes32 s;
        uint8 v;

        // ecrecover takes the signature parameters, and the only way to get them
        // currently is to use assembly.
        // solhint-disable-next-line no-inline-assembly
        assembly {
            r := mload(add(signature, 0x20))
            s := mload(add(signature, 0x40))
            v := byte(0, mload(add(signature, 0x60)))
        }

        return recover(hash, v, r, s);
    }

    /**
     * @dev Overload of {ECDSA-recover-bytes32-bytes-} that receives the `v`,
     * `r` and `s` signature fields separately.
     */
    function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {
        // 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 (281): 0 < s < secp256k1n ÷ 2 + 1, and for v in (282): 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.
        require(uint256(s) <= 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0, "ECDSA: invalid signature 's' value");
        require(v == 27 || v == 28, "ECDSA: invalid signature 'v' value");

        // If the signature is valid (and not malleable), return the signer address
        address signer = ecrecover(hash, v, r, s);
        require(signer != address(0), "ECDSA: invalid signature");

        return signer;
    }

    /**
     * @dev Returns an Ethereum Signed Message, created from a `hash`. This
     * replicates the behavior of the
     * https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign[`eth_sign`]
     * JSON-RPC method.
     *
     * 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));
    }
}
ERC20Permit.sol 78 lines
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.5 <0.8.0;

import "../token/ERC20/ERC20.sol";
import "./IERC20Permit.sol";
import "../cryptography/ECDSA.sol";
import "../utils/Counters.sol";
import "./EIP712.sol";

/**
 * @dev Implementation of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on `{IERC20-approve}`, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 *
 * _Available since v3.4._
 */
abstract contract ERC20Permit is ERC20, IERC20Permit, EIP712 {
    using Counters for Counters.Counter;

    mapping (address => Counters.Counter) private _nonces;

    // solhint-disable-next-line var-name-mixedcase
    bytes32 private immutable _PERMIT_TYPEHASH = keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");

    /**
     * @dev Initializes the {EIP712} domain separator using the `name` parameter, and setting `version` to `"1"`.
     *
     * It's a good idea to use the same `name` that is defined as the ERC20 token name.
     */
    constructor(string memory name) internal EIP712(name, "1") {
    }

    /**
     * @dev See {IERC20Permit-permit}.
     */
    function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public virtual override {
        // solhint-disable-next-line not-rely-on-time
        require(block.timestamp <= deadline, "ERC20Permit: expired deadline");

        bytes32 structHash = keccak256(
            abi.encode(
                _PERMIT_TYPEHASH,
                owner,
                spender,
                value,
                _nonces[owner].current(),
                deadline
            )
        );

        bytes32 hash = _hashTypedDataV4(structHash);

        address signer = ECDSA.recover(hash, v, r, s);
        require(signer == owner, "ERC20Permit: invalid signature");

        _nonces[owner].increment();
        _approve(owner, spender, value);
    }

    /**
     * @dev See {IERC20Permit-nonces}.
     */
    function nonces(address owner) public view override returns (uint256) {
        return _nonces[owner].current();
    }

    /**
     * @dev See {IERC20Permit-DOMAIN_SEPARATOR}.
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view override returns (bytes32) {
        return _domainSeparatorV4();
    }
}
IERC20.sol 77 lines
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the amount of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves `amount` tokens from the caller's account to `recipient`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address recipient, uint256 amount) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `sender` to `recipient` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);

    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);
}
IERC20Permit.sol 51 lines
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on `{IERC20-approve}`, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 */
interface IERC20Permit {
    /**
     * @dev Sets `value` as the allowance of `spender` over `owner`'s tokens,
     * given `owner`'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     */
    function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external;

    /**
     * @dev Returns the current nonce for `owner`. This value must be
     * included whenever a signature is generated for {permit}.
     *
     * Every successful call to {permit} increases ``owner``'s nonce by one. This
     * prevents a signature from being used multiple times.
     */
    function nonces(address owner) external view returns (uint256);

    /**
     * @dev Returns the domain separator used in the encoding of the signature for `permit`, as defined by {EIP712}.
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view returns (bytes32);
}
EnumerableSet.sol 297 lines
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

/**
 * @dev Library for managing
 * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
 * types.
 *
 * Sets have the following properties:
 *
 * - Elements are added, removed, and checked for existence in constant time
 * (O(1)).
 * - Elements are enumerated in O(n). No guarantees are made on the ordering.
 *
 * ```
 * contract Example {
 *     // Add the library methods
 *     using EnumerableSet for EnumerableSet.AddressSet;
 *
 *     // Declare a set state variable
 *     EnumerableSet.AddressSet private mySet;
 * }
 * ```
 *
 * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
 * and `uint256` (`UintSet`) are supported.
 */
library EnumerableSet {
    // To implement this library for multiple types with as little code
    // repetition as possible, we write it in terms of a generic Set type with
    // bytes32 values.
    // The Set implementation uses private functions, and user-facing
    // implementations (such as AddressSet) are just wrappers around the
    // underlying Set.
    // This means that we can only create new EnumerableSets for types that fit
    // in bytes32.

    struct Set {
        // Storage of set values
        bytes32[] _values;

        // Position of the value in the `values` array, plus 1 because index 0
        // means a value is not in the set.
        mapping (bytes32 => uint256) _indexes;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function _add(Set storage set, bytes32 value) private returns (bool) {
        if (!_contains(set, value)) {
            set._values.push(value);
            // The value is stored at length-1, but we add 1 to all indexes
            // and use 0 as a sentinel value
            set._indexes[value] = set._values.length;
            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function _remove(Set storage set, bytes32 value) private returns (bool) {
        // We read and store the value's index to prevent multiple reads from the same storage slot
        uint256 valueIndex = set._indexes[value];

        if (valueIndex != 0) { // Equivalent to contains(set, value)
            // To delete an element from the _values array in O(1), we swap the element to delete with the last one in
            // the array, and then remove the last element (sometimes called as 'swap and pop').
            // This modifies the order of the array, as noted in {at}.

            uint256 toDeleteIndex = valueIndex - 1;
            uint256 lastIndex = set._values.length - 1;

            // When the value to delete is the last one, the swap operation is unnecessary. However, since this occurs
            // so rarely, we still do the swap anyway to avoid the gas cost of adding an 'if' statement.

            bytes32 lastvalue = set._values[lastIndex];

            // Move the last value to the index where the value to delete is
            set._values[toDeleteIndex] = lastvalue;
            // Update the index for the moved value
            set._indexes[lastvalue] = toDeleteIndex + 1; // All indexes are 1-based

            // Delete the slot where the moved value was stored
            set._values.pop();

            // Delete the index for the deleted slot
            delete set._indexes[value];

            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function _contains(Set storage set, bytes32 value) private view returns (bool) {
        return set._indexes[value] != 0;
    }

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function _length(Set storage set) private view returns (uint256) {
        return set._values.length;
    }

   /**
    * @dev Returns the value stored at position `index` in the set. O(1).
    *
    * Note that there are no guarantees on the ordering of values inside the
    * array, and it may change when more values are added or removed.
    *
    * Requirements:
    *
    * - `index` must be strictly less than {length}.
    */
    function _at(Set storage set, uint256 index) private view returns (bytes32) {
        require(set._values.length > index, "EnumerableSet: index out of bounds");
        return set._values[index];
    }

    // Bytes32Set

    struct Bytes32Set {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _add(set._inner, value);
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _remove(set._inner, value);
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
        return _contains(set._inner, value);
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(Bytes32Set storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

   /**
    * @dev Returns the value stored at position `index` in the set. O(1).
    *
    * Note that there are no guarantees on the ordering of values inside the
    * array, and it may change when more values are added or removed.
    *
    * Requirements:
    *
    * - `index` must be strictly less than {length}.
    */
    function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
        return _at(set._inner, index);
    }

    // AddressSet

    struct AddressSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(AddressSet storage set, address value) internal returns (bool) {
        return _add(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(AddressSet storage set, address value) internal returns (bool) {
        return _remove(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(AddressSet storage set, address value) internal view returns (bool) {
        return _contains(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(AddressSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

   /**
    * @dev Returns the value stored at position `index` in the set. O(1).
    *
    * Note that there are no guarantees on the ordering of values inside the
    * array, and it may change when more values are added or removed.
    *
    * Requirements:
    *
    * - `index` must be strictly less than {length}.
    */
    function at(AddressSet storage set, uint256 index) internal view returns (address) {
        return address(uint160(uint256(_at(set._inner, index))));
    }


    // UintSet

    struct UintSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(UintSet storage set, uint256 value) internal returns (bool) {
        return _add(set._inner, bytes32(value));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(UintSet storage set, uint256 value) internal returns (bool) {
        return _remove(set._inner, bytes32(value));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(UintSet storage set, uint256 value) internal view returns (bool) {
        return _contains(set._inner, bytes32(value));
    }

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function length(UintSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

   /**
    * @dev Returns the value stored at position `index` in the set. O(1).
    *
    * Note that there are no guarantees on the ordering of values inside the
    * array, and it may change when more values are added or removed.
    *
    * Requirements:
    *
    * - `index` must be strictly less than {length}.
    */
    function at(UintSet storage set, uint256 index) internal view returns (uint256) {
        return uint256(_at(set._inner, index));
    }
}
ERC20Burnable.sol 42 lines
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "../../utils/Context.sol";
import "./ERC20.sol";

/**
 * @dev Extension of {ERC20} that allows token holders to destroy both their own
 * tokens and those that they have an allowance for, in a way that can be
 * recognized off-chain (via event analysis).
 */
abstract contract ERC20Burnable is Context, ERC20 {
    using SafeMath for uint256;

    /**
     * @dev Destroys `amount` tokens from the caller.
     *
     * See {ERC20-_burn}.
     */
    function burn(uint256 amount) public virtual {
        _burn(_msgSender(), amount);
    }

    /**
     * @dev Destroys `amount` tokens from `account`, deducting from the caller's
     * allowance.
     *
     * See {ERC20-_burn} and {ERC20-allowance}.
     *
     * Requirements:
     *
     * - the caller must have allowance for ``accounts``'s tokens of at least
     * `amount`.
     */
    function burnFrom(address account, uint256 amount) public virtual {
        uint256 decreasedAllowance = allowance(account, _msgSender()).sub(amount, "ERC20: burn amount exceeds allowance");

        _approve(account, _msgSender(), decreasedAllowance);
        _burn(account, amount);
    }
}
ERC20Snapshot.sol 181 lines
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "../../math/SafeMath.sol";
import "../../utils/Arrays.sol";
import "../../utils/Counters.sol";
import "./ERC20.sol";

/**
 * @dev This contract extends an ERC20 token with a snapshot mechanism. When a snapshot is created, the balances and
 * total supply at the time are recorded for later access.
 *
 * This can be used to safely create mechanisms based on token balances such as trustless dividends or weighted voting.
 * In naive implementations it's possible to perform a "double spend" attack by reusing the same balance from different
 * accounts. By using snapshots to calculate dividends or voting power, those attacks no longer apply. It can also be
 * used to create an efficient ERC20 forking mechanism.
 *
 * Snapshots are created by the internal {_snapshot} function, which will emit the {Snapshot} event and return a
 * snapshot id. To get the total supply at the time of a snapshot, call the function {totalSupplyAt} with the snapshot
 * id. To get the balance of an account at the time of a snapshot, call the {balanceOfAt} function with the snapshot id
 * and the account address.
 *
 * ==== Gas Costs
 *
 * Snapshots are efficient. Snapshot creation is _O(1)_. Retrieval of balances or total supply from a snapshot is _O(log
 * n)_ in the number of snapshots that have been created, although _n_ for a specific account will generally be much
 * smaller since identical balances in subsequent snapshots are stored as a single entry.
 *
 * There is a constant overhead for normal ERC20 transfers due to the additional snapshot bookkeeping. This overhead is
 * only significant for the first transfer that immediately follows a snapshot for a particular account. Subsequent
 * transfers will have normal cost until the next snapshot, and so on.
 */
abstract contract ERC20Snapshot is ERC20 {
    // Inspired by Jordi Baylina's MiniMeToken to record historical balances:
    // https://github.com/Giveth/minimd/blob/ea04d950eea153a04c51fa510b068b9dded390cb/contracts/MiniMeToken.sol

    using SafeMath for uint256;
    using Arrays for uint256[];
    using Counters for Counters.Counter;

    // Snapshotted values have arrays of ids and the value corresponding to that id. These could be an array of a
    // Snapshot struct, but that would impede usage of functions that work on an array.
    struct Snapshots {
        uint256[] ids;
        uint256[] values;
    }

    mapping (address => Snapshots) private _accountBalanceSnapshots;
    Snapshots private _totalSupplySnapshots;

    // Snapshot ids increase monotonically, with the first value being 1. An id of 0 is invalid.
    Counters.Counter private _currentSnapshotId;

    /**
     * @dev Emitted by {_snapshot} when a snapshot identified by `id` is created.
     */
    event Snapshot(uint256 id);

    /**
     * @dev Creates a new snapshot and returns its snapshot id.
     *
     * Emits a {Snapshot} event that contains the same id.
     *
     * {_snapshot} is `internal` and you have to decide how to expose it externally. Its usage may be restricted to a
     * set of accounts, for example using {AccessControl}, or it may be open to the public.
     *
     * [WARNING]
     * ====
     * While an open way of calling {_snapshot} is required for certain trust minimization mechanisms such as forking,
     * you must consider that it can potentially be used by attackers in two ways.
     *
     * First, it can be used to increase the cost of retrieval of values from snapshots, although it will grow
     * logarithmically thus rendering this attack ineffective in the long term. Second, it can be used to target
     * specific accounts and increase the cost of ERC20 transfers for them, in the ways specified in the Gas Costs
     * section above.
     *
     * We haven't measured the actual numbers; if this is something you're interested in please reach out to us.
     * ====
     */
    function _snapshot() internal virtual returns (uint256) {
        _currentSnapshotId.increment();

        uint256 currentId = _currentSnapshotId.current();
        emit Snapshot(currentId);
        return currentId;
    }

    /**
     * @dev Retrieves the balance of `account` at the time `snapshotId` was created.
     */
    function balanceOfAt(address account, uint256 snapshotId) public view virtual returns (uint256) {
        (bool snapshotted, uint256 value) = _valueAt(snapshotId, _accountBalanceSnapshots[account]);

        return snapshotted ? value : balanceOf(account);
    }

    /**
     * @dev Retrieves the total supply at the time `snapshotId` was created.
     */
    function totalSupplyAt(uint256 snapshotId) public view virtual returns(uint256) {
        (bool snapshotted, uint256 value) = _valueAt(snapshotId, _totalSupplySnapshots);

        return snapshotted ? value : totalSupply();
    }


    // Update balance and/or total supply snapshots before the values are modified. This is implemented
    // in the _beforeTokenTransfer hook, which is executed for _mint, _burn, and _transfer operations.
    function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual override {
      super._beforeTokenTransfer(from, to, amount);

      if (from == address(0)) {
        // mint
        _updateAccountSnapshot(to);
        _updateTotalSupplySnapshot();
      } else if (to == address(0)) {
        // burn
        _updateAccountSnapshot(from);
        _updateTotalSupplySnapshot();
      } else {
        // transfer
        _updateAccountSnapshot(from);
        _updateAccountSnapshot(to);
      }
    }

    function _valueAt(uint256 snapshotId, Snapshots storage snapshots)
        private view returns (bool, uint256)
    {
        require(snapshotId > 0, "ERC20Snapshot: id is 0");
        // solhint-disable-next-line max-line-length
        require(snapshotId <= _currentSnapshotId.current(), "ERC20Snapshot: nonexistent id");

        // When a valid snapshot is queried, there are three possibilities:
        //  a) The queried value was not modified after the snapshot was taken. Therefore, a snapshot entry was never
        //  created for this id, and all stored snapshot ids are smaller than the requested one. The value that corresponds
        //  to this id is the current one.
        //  b) The queried value was modified after the snapshot was taken. Therefore, there will be an entry with the
        //  requested id, and its value is the one to return.
        //  c) More snapshots were created after the requested one, and the queried value was later modified. There will be
        //  no entry for the requested id: the value that corresponds to it is that of the smallest snapshot id that is
        //  larger than the requested one.
        //
        // In summary, we need to find an element in an array, returning the index of the smallest value that is larger if
        // it is not found, unless said value doesn't exist (e.g. when all values are smaller). Arrays.findUpperBound does
        // exactly this.

        uint256 index = snapshots.ids.findUpperBound(snapshotId);

        if (index == snapshots.ids.length) {
            return (false, 0);
        } else {
            return (true, snapshots.values[index]);
        }
    }

    function _updateAccountSnapshot(address account) private {
        _updateSnapshot(_accountBalanceSnapshots[account], balanceOf(account));
    }

    function _updateTotalSupplySnapshot() private {
        _updateSnapshot(_totalSupplySnapshots, totalSupply());
    }

    function _updateSnapshot(Snapshots storage snapshots, uint256 currentValue) private {
        uint256 currentId = _currentSnapshotId.current();
        if (_lastSnapshotId(snapshots.ids) < currentId) {
            snapshots.ids.push(currentId);
            snapshots.values.push(currentValue);
        }
    }

    function _lastSnapshotId(uint256[] storage ids) private view returns (uint256) {
        if (ids.length == 0) {
            return 0;
        } else {
            return ids[ids.length - 1];
        }
    }
}

Read Contract

ADMIN_CONFIG_ID 0x53adf2cb → bytes32
DISTRIBUTOR_CONFIG_ID 0x7526b08a → bytes32
DOMAIN_SEPARATOR 0x3644e515 → bytes32
EPOCH_DURATION_CONFIG_ID 0xb7840a91 → bytes32
INFLATION_CONFIG_ID 0x0389a24e → bytes32
TIMELOCK_CONFIG_ID 0xfa4e4a37 → bytes32
TREASURER_CONFIG_ID 0x8233dffb → bytes32
allowance 0xdd62ed3e → uint256
balanceOf 0x70a08231 → uint256
balanceOfAt 0x4ee2cd7e → uint256
calculateConfigID 0x52d56792 → bytes32
decimals 0x313ce567 → uint8
getAdmin 0x6e9960c3 → address
getConfig 0x6dd5b69d → tuple
getConfigByIndex 0x98e83051 → tuple
getConfigCount 0xe879b118 → uint256
getDistributor 0x5884965f → address
getEpoch 0x757991a8 → uint256
getEpochDuration 0x5d3ea8f1 → uint256
getInflation 0xd5a95771 → uint256
getPending 0x78de7d19 → tuple
getPendingByIndex 0xa7d59b59 → tuple
getPendingCount 0xd795ede1 → uint256
getTimelock 0x6221a54b → uint256
getTreasurer 0x199ab75d → address
isConfig 0x94e90e69 → bool
isPending 0xe531d8c7 → bool
name 0x06fdde03 → string
nonces 0x7ecebe00 → uint256
symbol 0x95d89b41 → string
totalSupply 0x18160ddd → uint256
totalSupplyAt 0x981b24d0 → uint256

Write Contract 12 functions

These functions modify contract state and require a wallet transaction to execute.

advance 0xea105ac7
No parameters
approve 0x095ea7b3
address spender
uint256 amount
returns: bool
burn 0x42966c68
uint256 amount
burnFrom 0x79cc6790
address account
uint256 amount
cancelChange 0x5449b798
bytes32 configID
confirmChange 0xbeda2483
bytes32 configID
decreaseAllowance 0xa457c2d7
address spender
uint256 subtractedValue
returns: bool
increaseAllowance 0x39509351
address spender
uint256 addedValue
returns: bool
permit 0xd505accf
address owner
address spender
uint256 value
uint256 deadline
uint8 v
bytes32 r
bytes32 s
requestChange 0xa65ad63e
bytes32 configID
uint256 value
transfer 0xa9059cbb
address recipient
uint256 amount
returns: bool
transferFrom 0x23b872dd
address sender
address recipient
uint256 amount
returns: bool

Recent Transactions

No transactions found for this address