Address Contract Verified
Address
0xbC13Cc31Aa46745982e4DA445Aa32C97c72aaBAc
Balance
0 ETH
Nonce
1
Code Size
22815 bytes
Creator
0x78aBE4Eb...Ef5F at tx 0x163da2eb...d14bfa
Indexed Transactions
0
Contract Bytecode
22815 bytes
0x6080604052600436106102e45760003560e01c80637bafb02911610186578063a4640b82116100d7578063d18df53c11610085578063d18df53c14610914578063e2bbb15814610934578063f2fde38b14610947578063f3aeb31d14610967578063f4ef5ed51461097c578063fac2b9ba1461099c578063ffe8e372146109bc57600080fd5b8063a4640b8214610844578063a5bfd0f214610864578063ae169a501461087e578063bb952cd214610891578063bc6a9e01146108a4578063cbd258b5146108c4578063cd635cce146108f457600080fd5b80638ae39cac116101345780638ae39cac146107505780638b424267146107665780638bdf67f21461077c5780638da5cb5b1461079c57806393f1a40b146107ba5780639abd35721461081c5780639f94e2721461082f57600080fd5b80637bafb0291461066757806383f07ea81461068757806384ed19b51461069d5780638705fcd4146106e5578063876ba4b71461070557806387788782146107255780638aa285501461073b57600080fd5b8063441a3e701161024057806361d027b3116101ee57806361d027b3146105b2578063630b5ba1146105d2578063671882b0146105e75780636c95d09b146105fd57806370897b231461061d578063715018a61461063d578063766e80981461065257600080fd5b8063441a3e70146104f45780634817517f1461050757806348cd4cb11461052757806349f5edde1461053d57806351eb05a61461055d5780635312ea8e1461057d5780635dde4a911461059d57600080fd5b80631a6659551161029d5780631a66595514610405578063249375671461043257806330409c85146104615780634060e25714610481578063412753581461049457806341a2ac70146104b457806341cb8c20146104d457600080fd5b8063015d5238146102f0578063018bcf5c14610307578063081e3eda146103275780630ba84cd21461034b5780631526fe271461036b57806317caf6f1146103ef57600080fd5b366102eb57005b600080fd5b3480156102fc57600080fd5b506103056109d2565b005b34801561031357600080fd5b50610305610322366004615292565b610b07565b34801561033357600080fd5b50600b545b6040519081526020015b60405180910390f35b34801561035757600080fd5b506103056103663660046152af565b610d34565b34801561037757600080fd5b5061038b6103863660046152af565b610d70565b604080516001600160a01b03909c168c5260208c019a909a52988a01979097526060890195909552608088019390935260a087019190915260c086015260e085015261010084015261ffff9081166101208401521661014082015261016001610342565b3480156103fb57600080fd5b50610338600f5481565b34801561041157600080fd5b50600254610425906001600160a01b031681565b60405161034291906152c8565b34801561043e57600080fd5b5060055461045190610100900460ff1681565b6040519015158152602001610342565b34801561046d57600080fd5b5061030561047c3660046152af565b610dec565b61030561048f3660046152af565b610e84565b3480156104a057600080fd5b50600754610425906001600160a01b031681565b3480156104c057600080fd5b506103056104cf3660046152af565b611484565b3480156104e057600080fd5b506103386104ef3660046152af565b611519565b6103056105023660046152dc565b61153a565b34801561051357600080fd5b50610305610522366004615329565b6119d9565b34801561053357600080fd5b5061033860105481565b34801561054957600080fd5b5061030561055836600461538c565b611e55565b34801561056957600080fd5b506103056105783660046152af565b61220c565b34801561058957600080fd5b506103056105983660046152af565b612473565b3480156105a957600080fd5b50610338612543565b3480156105be57600080fd5b50600854610425906001600160a01b031681565b3480156105de57600080fd5b50610305612631565b3480156105f357600080fd5b5061033860045481565b34801561060957600080fd5b50610305610618366004615472565b61265a565b34801561062957600080fd5b506103056106383660046152af565b61271a565b34801561064957600080fd5b506103056127a9565b34801561065e57600080fd5b506103056127bb565b34801561067357600080fd5b5061033861068236600461554a565b6128c3565b34801561069357600080fd5b5061033860165481565b3480156106a957600080fd5b506106bd6106b83660046152af565b61291a565b604080516001600160a01b039485168152939092166020840152151590820152606001610342565b3480156106f157600080fd5b50610305610700366004615292565b61295d565b34801561071157600080fd5b50610338610720366004615576565b6129b1565b34801561073157600080fd5b5061033860095481565b34801561074757600080fd5b50610338600181565b34801561075c57600080fd5b5061033860065481565b34801561077257600080fd5b50610338600a5481565b34801561078857600080fd5b506103056107973660046152af565b612b90565b3480156107a857600080fd5b506000546001600160a01b0316610425565b3480156107c657600080fd5b506108016107d5366004615576565b600e60209081526000928352604080842090915290825290208054600182015460029092015490919083565b60408051938452602084019290925290820152606001610342565b61030561082a3660046152af565b612ccb565b34801561083b57600080fd5b50610338612e53565b34801561085057600080fd5b5061030561085f366004615292565b612f06565b34801561087057600080fd5b506005546104519060ff1681565b61030561088c3660046152af565b612fad565b61030561089f3660046152af565b613133565b3480156108b057600080fd5b50600354610425906001600160a01b031681565b3480156108d057600080fd5b506104516108df366004615292565b60186020526000908152604090205460ff1681565b34801561090057600080fd5b5061030561090f3660046155a6565b613796565b34801561092057600080fd5b5061033861092f366004615576565b6137e7565b6103056109423660046152dc565b613950565b34801561095357600080fd5b50610305610962366004615292565b613e5f565b34801561097357600080fd5b50610338613ed5565b34801561098857600080fd5b506103056109973660046152af565b614094565b3480156109a857600080fd5b506103056109b73660046152af565b614318565b3480156109c857600080fd5b5061033861271081565b6109da6144a2565b6003546001600160a01b0316610a1d576040514790339082156108fc029083906000818181858888f19350505050158015610a19573d6000803e3d6000fd5b5050565b6003546040516370a0823160e01b81526000916001600160a01b0316906370a0823190610a4e9030906004016152c8565b602060405180830381865afa158015610a6b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a8f91906155c3565b60035460405163a9059cbb60e01b81529192506001600160a01b03169063a9059cbb90610ac290339085906004016155dc565b6020604051808303816000875af1158015610ae1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a1991906155f5565b565b610b0f6144a2565b6002546001600160a01b03828116911614801590610b3b57506003546001600160a01b03828116911614155b610ba45760405162461bcd60e51b815260206004820152602f60248201527f63616e6e6f74207265636f7665722072657761726420746f6b656e206f72207260448201526e32b33632b1ba34b7b7103a37b5b2b760891b60648201526084015b60405180910390fd5b6001600160a01b03811660009081526018602052604090205460ff1615610c065760405162461bcd60e51b81526020600482015260166024820152751d1bdad95b881a5cc81d5cda5b99c81bdb881c1bdbdb60521b6044820152606401610b9b565b6001600160a01b038116610c48576040514790339082156108fc029083906000818181858888f19350505050158015610c43573d6000803e3d6000fd5b505050565b6040516370a0823160e01b81526000906001600160a01b038316906370a0823190610c779030906004016152c8565b602060405180830381865afa158015610c94573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cb891906155c3565b90508015610a195760405163a9059cbb60e01b81526001600160a01b0383169063a9059cbb90610cee90339085906004016155dc565b6020604051808303816000875af1158015610d0d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c4391906155f5565b50565b610d3c6144a2565b610d44612631565b600681905560405181815233906000805160206158aa833981519152906020015b60405180910390a250565b600b8181548110610d8057600080fd5b60009182526020909120600a909102018054600182015460028301546003840154600485015460058601546006870154600788015460088901546009909901546001600160a01b039098169950959794969395929491939092919061ffff80821691620100009004168b565b610df46144a2565b80600003610e7a576002546040516370a0823160e01b81526000916001600160a01b0316906370a0823190610e2d9030906004016152c8565b602060405180830381865afa158015610e4a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e6e91906155c3565b9050610a1933826144fc565b610d3133826144fc565b610e8c6146c6565b6000600b8281548110610ea157610ea1615612565b90600052602060002090600a020190506000600c8381548110610ec657610ec6615612565b60009182526020918290206040805160e081018252600790930290910180546001600160a01b039081168452600182015416838501526002810180548351818702810187018552818152949592949386019392830182828015610f5257602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311610f34575b5050505050815260200160038201805480602002602001604051908101604052809291908181526020018280548015610fb457602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311610f96575b505050505081526020016004820180548060200260200160405190810160405280929190818152602001828054801561101657602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311610ff8575b505050505081526020016005820180548060200260200160405190810160405280929190818152602001828054801561107857602002820191906000526020600020905b81546001600160a01b0316815260019091019060200180831161105a575b50505091835250506006919091015460ff1615156020918201526000858152600e8252604080822033835290925290812080549293509190036110bd5750505061147b565b8160c001516110ce5750505061147b565b6110d661471f565b6110df8461220c565b6000816001015464e8d4a5100085600601548460000154611100919061563e565b61110a919061565d565b611114919061567f565b905080156111d95780611125612e53565b10156111435760405162461bcd60e51b8152600401610b9b90615696565b8060165461115191906156cd565b601655600a5461271090611165908261567f565b61116f908361563e565b611179919061565d565b905080601154111561119b5780601154611193919061567f565b6011556111a1565b60006011555b604051818152859033907f0e311a2c6dbfb0153ec3a8a5bdca09070b3e5f60768fdc10a20453f38d1868739060200160405180910390a35b83546002546001600160a01b039081169116146113cf5760006111fd60028361565d565b60025460408601515191925082916001600160a01b039091169015611260576040860151805161122f9060019061567f565b8151811061123f5761123f615612565b6020026020010151905061125d8660200151848860400151306147ea565b91505b60025460608701515184916001600160a01b031690156112be576060880151805161128d9060019061567f565b8151811061129d5761129d615612565b602002602001015190506112bb8860200151868a60600151306147ea565b91505b88546040516370a0823160e01b81526000916001600160a01b0316906370a08231906112ee9030906004016152c8565b602060405180830381865afa15801561130b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061132f91906155c3565b9050611343896020015185848887306149da565b50508a546040516370a0823160e01b8152600092506001600160a01b03909116906370a08231906113789030906004016152c8565b602060405180830381865afa158015611395573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113b991906155c3565b90506113c5828261567f565b9750505050505050505b81546113dc9082906156cd565b808355600685015464e8d4a51000916113f5919061563e565b6113ff919061565d565b6001830155600784015464e8d4a510009061141a908361563e565b611424919061565d565b826002015461143391906156cd565b600283015583546114519086906001600160a01b0316836001614b06565b6040518181528590339060008051602061586a8339815191529060200160405180910390a3505050505b610d3160018055565b61148c6144a2565b61271081106114dd5760405162461bcd60e51b815260206004820181905260248201527f7365745265776172644665653a20696e76616c69642070657263656e746167656044820152606401610b9b565b600a8190556040518181527f8241a79c714425e571a9f1686404d094a6271d36603bfbff7341608c35cba269906020015b60405180910390a150565b600d818154811061152957600080fd5b600091825260209091200154905081565b6115426146c6565b6000600b838154811061155757611557615612565b60009182526020808320868452600e8252604080852033865290925292208054600a90920290920192508311156115c55760405162461bcd60e51b81526020600482015260126024820152711dda5d1a191c985dce881b9bdd0819dbdbd960721b6044820152606401610b9b565b600083116116155760405162461bcd60e51b815260206004820152601f60248201527f416d6f756e742073686f756c642062652067726561746f72207468616e2030006044820152606401610b9b565b61161d61471f565b438260040154101561167c57611631612631565b8160010154600f54611643919061567f565b600f55600060018301819055600681905560405190815233906000805160206158aa8339815191529060200160405180910390a2611685565b6116858461220c565b6000816001015464e8d4a51000846006015484600001546116a6919061563e565b6116b0919061565d565b6116ba919061567f565b9050801561177757806116cb612e53565b10156116e95760405162461bcd60e51b8152600401610b9b90615696565b806016546116f791906156cd565b601655600a546127109061170b908261567f565b611715908361563e565b61171f919061565d565b905061172b33826144fc565b80601154111561174b5780601154611743919061567f565b601155611751565b60006011555b6040518181528590339060008051602061588a8339815191529060200160405180910390a35b6000826002015464e8d4a5100085600701548560000154611798919061563e565b6117a2919061565d565b6117ac919061567f565b90506000811180156117c0575060055460ff165b1561186a5760006117d082614c66565b905081601460008282546117e4919061567f565b90915550506003546001600160a01b031661182c57604051339082156108fc029083906000818181858888f19350505050158015611826573d6000803e3d6000fd5b50611843565b600354611843906001600160a01b03163383614c96565b604051818152879033906000805160206158ca8339815191529060200160405180910390a3505b841561193157825461187d90869061567f565b8355600984015462010000900461ffff1615611902576009840154600090612710906118b39062010000900461ffff168861563e565b6118bd919061565d565b60075486549192506118dc916001600160a01b03908116911683614c96565b6118fc336118ea838961567f565b87546001600160a01b03169190614c96565b50611918565b8354611918906001600160a01b03163387614c96565b83546119319087906001600160a01b0316876000614b06565b6006840154835464e8d4a51000916119489161563e565b611952919061565d565b60018401556007840154835464e8d4a510009161196e9161563e565b611978919061565d565b6002840155604051858152869033907ff279e6a1f5e320cca91135676d9cb6e44ca8a08c0b88342bcdb1144f6511b5689060200160405180910390a3600554610100900460ff16156119cc576119cc614cec565b50505050610a1960018055565b6119e16144a2565b6127108461ffff161115611a455760405162461bcd60e51b815260206004820152602560248201527f7365743a20696e76616c6964206465706f7369742066656520626173697320706044820152646f696e747360d81b6064820152608401610b9b565b6127108361ffff161115611aaa5760405162461bcd60e51b815260206004820152602660248201527f7365743a20696e76616c69642077697468647261772066656520626173697320604482015265706f696e747360d01b6064820152608401610b9b565b43600b8781548110611abe57611abe615612565b90600052602060002090600a0201600401541115611b575743611ae361191a8461563e565b600b8881548110611af657611af6615612565b90600052602060002090600a020160030154611b1291906156cd565b11611b575760405162461bcd60e51b815260206004820152601560248201527439b2ba1d1034b73b30b634b210323ab930ba34b7b760591b6044820152606401610b9b565b8015611b6557611b65612631565b84600b8781548110611b7957611b79615612565b90600052602060002090600a020160010154600f54611b98919061567f565b611ba291906156cd565b600f8190555084600b8781548110611bbc57611bbc615612565b90600052602060002090600a02016001018190555083600b8781548110611be557611be5615612565b90600052602060002090600a020160090160006101000a81548161ffff021916908361ffff16021790555082600b8781548110611c2457611c24615612565b90600052602060002090600a020160090160026101000a81548161ffff021916908361ffff16021790555081600b8781548110611c6357611c63615612565b90600052602060002090600a02016002018190555043600b8781548110611c8c57611c8c615612565b90600052602060002090600a0201600401541015611d1d5780611cb257611cb28661220c565b43600b8781548110611cc657611cc6615612565b600091825260209091206003600a909202010155611ce661191a8361563e565b611cf090436156cd565b600b8781548110611d0357611d03615612565b90600052602060002090600a020160040181905550611d81565b611d2961191a8361563e565b600b8781548110611d3c57611d3c615612565b90600052602060002090600a020160030154611d5891906156cd565b600b8781548110611d6b57611d6b615612565b90600052602060002090600a0201600401819055505b600b8681548110611d9457611d94615612565b90600052602060002090600a020160000160009054906101000a90046001600160a01b03166001600160a01b03167f4375452615ce7668a3ecc4deee77cea5cd0dd9e4e0f6315123a2f1903e70276d8787858888600b8d81548110611dfb57611dfb615612565b90600052602060002090600a020160030154600b8e81548110611e2057611e20615612565b90600052602060002090600a020160040154604051611e4597969594939291906156e5565b60405180910390a2505050505050565b611e5d6144a2565b6001600160a01b038516600090815260186020526040902054859060ff1615611ec45760405162461bcd60e51b81526020600482015260196024820152781b9bdb911d5c1b1a58d85d19590e88191d5c1b1a58d85d1959603a1b6044820152606401610b9b565b6127108561ffff161115611f285760405162461bcd60e51b815260206004820152602560248201527f6164643a20696e76616c6964206465706f7369742066656520626173697320706044820152646f696e747360d81b6064820152608401610b9b565b6127108461ffff161115611f8d5760405162461bcd60e51b815260206004820152602660248201527f6164643a20696e76616c69642077697468647261772066656520626173697320604482015265706f696e747360d01b6064820152608401610b9b565b8115611f9b57611f9b612631565b60006010544311611fae57601054611fb0565b435b905087600f54611fc091906156cd565b600f556001600160a01b038716600081815260186020908152604091829020805460ff1916600117905581516101608101835292835282018a9052810185905260608101829052600b906080810161201a61191a8861563e565b61202490856156cd565b81526020808201859052600060408084018290526060808501839052608080860184905261ffff808f1660a0808901919091528e821660c098890152895460018181018c559a87528787208a51600a9092020180546001600160a01b039092166001600160a01b031990921691909117815596890151878b0155938801516002870155918701516003860155860151600485015590850151600584015592840151600683015560e08401516007830155610100840151600883015561012084015160099092018054610140909501518416620100000263ffffffff199095169290931691909117929092179055600c80548301808255918190528992909161212c919061567f565b8154811061213c5761213c615612565b6000918252602082206007919091020180546001600160a01b0319166001600160a01b03938416179055600d8054600181810183559183527fd7b6990105719101dabeb77144f2a3385c8033acd3af97e9423a695e81ad1eb50191909155600b54918916917f4375452615ce7668a3ecc4deee77cea5cd0dd9e4e0f6315123a2f1903e70276d916121cc9161567f565b8a878a8a876121dd61191a8561563e565b6121e7908a6156cd565b6040516121fa97969594939291906156e5565b60405180910390a25050505050505050565b6000600b828154811061222157612221615612565b90600052602060002090600a0201905080600501544311612240575050565b80546040516370a0823160e01b81526000916001600160a01b0316906370a08231906122709030906004016152c8565b602060405180830381865afa15801561228d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122b191906155c3565b60025483549192506001600160a01b039081169116036122d057506012545b60035482546001600160a01b039182169116036122ec57506013545b8015806122fb57506001820154155b1561230b57504360059091015550565b600061232083600501544385600401546128c3565b90506000600f5484600101546006548461233a919061563e565b612344919061563e565b61234e919061565d565b9050826123608264e8d4a5100061563e565b61236a919061565d565b84600601600082825461237d91906156cd565b909155505060055460ff1615612455576000612397612543565b90506014548111156123b7576014546123b0908261567f565b90506123bb565b5060005b600f546123cd8264e8d4a5100061563e565b6123d7919061565d565b600460008282546123e891906156cd565b9091555050600885015460045485916124009161567f565b866001015461240f919061563e565b612419919061565d565b85600701600082825461242c91906156cd565b909155505060045460088601556014805482919060009061244e9084906156cd565b9091555050505b4360058501556017546124699082906156cd565b6017555050505050565b61247b6146c6565b6000600b828154811061249057612490615612565b60009182526020808320858452600e8252604080852033808752935284208054858255600182018690556002820195909555600a9093020180549094509192916124e7916001600160a01b03919091169083614c96565b82546125009085906001600160a01b0316836000614b06565b604051818152849033907fbb757047c2b5f3974fe26b7c10f732e7bce710b0952a71082702781e62ae05959060200160405180910390a3505050610d3160018055565b60055460009060ff161515810361255a5750600090565b6003546001600160a01b031661256f57504790565b6003546040516370a0823160e01b81526000916001600160a01b0316906370a08231906125a09030906004016152c8565b602060405180830381865afa1580156125bd573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125e191906155c3565b6002546003549192506001600160a01b0390811691160361261e5760115481101561260e57600091505090565b60115461261b908261567f565b90505b60135461262b908261567f565b91505090565b600b5460005b81811015610a19576126488161220c565b8061265281615719565b915050612637565b6126626144a2565b6000600c888154811061267757612677615612565b60009182526020918290206007919091020160068101805460ff19168515151790556001810180546001600160a01b0319166001600160a01b038b1617905587519092506126cd916002840191908901906151f3565b5084516126e390600383019060208801906151f3565b5083516126f990600483019060208701906151f3565b50825161270f90600583019060208601906151f3565b505050505050505050565b6008546001600160a01b031633146127745760405162461bcd60e51b815260206004820152601c60248201527f736574506572666f726d616e63654665653a20464f5242494444454e000000006044820152606401610b9b565b60098190556040518181527f8b940a95968ad5b511f89b01075446a4fe9f614f2dc5fbb9e9a6b227d6d4fd709060200161150e565b6127b16144a2565b610b056000614de2565b6127c36144a2565b60055460ff16806127e457506003546002546001600160a01b039081169116145b610b05576003546001600160a01b0316612831576008546040516001600160a01b03909116904780156108fc02916000818181858888f19350505050158015610d31573d6000803e3d6000fd5b6003546040516370a0823160e01b81526000916001600160a01b0316906370a08231906128629030906004016152c8565b602060405180830381865afa15801561287f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128a391906155c3565b600854600354919250610d31916001600160a01b03908116911683614c96565b6000818411156128d557506000612913565b818311156128fa5760016128e9858461567f565b6128f3919061563e565b9050612913565b6001612906858561567f565b612910919061563e565b90505b9392505050565b600c818154811061292a57600080fd5b60009182526020909120600790910201805460018201546006909201546001600160a01b03918216935091169060ff1683565b6129656144a2565b600780546001600160a01b0319166001600160a01b03831690811790915560405133907fd44190acf9d04bdb5d3a1aafff7e6dee8b40b93dfb8c5d3f0eea4b9f4539c3f790600090a350565b600080600b84815481106129c7576129c7615612565b60009182526020808320878452600e825260408085206001600160a01b03808a16875293528085206007600a90950290920193840154845491516370a0823160e01b815294965091949193919216906370a0823190612a2a9030906004016152c8565b602060405180830381865afa158015612a47573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a6b91906155c3565b84546003549192506001600160a01b03908116911603612a8a57506013545b836005015443118015612a9d5750600081115b8015612aab575060055460ff165b8015612ab957506000600f54115b15612b58576000612ac8612543565b9050601454811115612ae857601454612ae1908261567f565b9050612aec565b5060005b600f54600090612b018364e8d4a5100061563e565b612b0b919061565d565b600454612b1891906156cd565b905082866008015482612b2b919061567f565b8760010154612b3a919061563e565b612b44919061565d565b8660070154612b5391906156cd565b935050505b6002830154835464e8d4a5100090612b7190859061563e565b612b7b919061565d565b612b85919061567f565b979650505050505050565b612b986146c6565b60008111612ba557600080fd5b6002546040516370a0823160e01b81526000916001600160a01b0316906370a0823190612bd69030906004016152c8565b602060405180830381865afa158015612bf3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c1791906155c3565b600254909150612c32906001600160a01b0316333085614e32565b6002546040516370a0823160e01b81526000916001600160a01b0316906370a0823190612c639030906004016152c8565b602060405180830381865afa158015612c80573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ca491906155c3565b90508181601154612cb591906156cd565b612cbf919061567f565b60115550506001805550565b612cd36146c6565b6000600b8281548110612ce857612ce8615612565b60009182526020808320858452600e825260408085203386529092529083208054600a90930290910193509103612d2057505061147b565b60055460ff16612d3157505061147b565b612d3961471f565b612d428361220c565b6000816002015464e8d4a5100084600701548460000154612d63919061563e565b612d6d919061565d565b612d77919061567f565b90508015612e1e576000612d8a82614c66565b905081601454612d9a919061567f565b6014556003546001600160a01b0316612de057604051339082156108fc029083906000818181858888f19350505050158015612dda573d6000803e3d6000fd5b50612df7565b600354612df7906001600160a01b03163383614c96565b604051818152859033906000805160206158ca8339815191529060200160405180910390a3505b6007830154825464e8d4a5100091612e359161563e565b612e3f919061565d565b8260020181905550505050610d3160018055565b6003546002546000916001600160a01b039182169116148015612e78575060055460ff165b15612e84575060115490565b6002546040516370a0823160e01b81526000916001600160a01b0316906370a0823190612eb59030906004016152c8565b602060405180830381865afa158015612ed2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ef691906155c3565b90506012548161262b919061567f565b6008546001600160a01b03163314612f605760405162461bcd60e51b815260206004820152601b60248201527f7365744275794261636b57616c6c65743a20464f5242494444454e00000000006044820152606401610b9b565b600880546001600160a01b0319166001600160a01b03831617905560405133907f5dcc871da1b3d2b6073537b97b4e22ac3dc59199f78de4b24c508f65bb1d99da90610d659084906152c8565b612fb56146c6565b6000600b8281548110612fca57612fca615612565b60009182526020808320858452600e825260408085203386529092529083208054600a9093029091019350910361300257505061147b565b61300a61471f565b6130138361220c565b6000816001015464e8d4a5100084600601548460000154613034919061563e565b61303e919061565d565b613048919061567f565b905080156131055780613059612e53565b10156130775760405162461bcd60e51b8152600401610b9b90615696565b8060165461308591906156cd565b601655600a5461271090613099908261567f565b6130a3908361563e565b6130ad919061565d565b90506130b933826144fc565b8060115411156130d957806011546130d1919061567f565b6011556130df565b60006011555b6040518181528490339060008051602061588a8339815191529060200160405180910390a35b6006830154825464e8d4a510009161311c9161563e565b613126919061565d565b6001928301555080555050565b61313b6146c6565b6000600b828154811061315057613150615612565b90600052602060002090600a020190506000600c838154811061317557613175615612565b60009182526020918290206040805160e081018252600790930290910180546001600160a01b03908116845260018201541683850152600281018054835181870281018701855281815294959294938601939283018282801561320157602002820191906000526020600020905b81546001600160a01b031681526001909101906020018083116131e3575b505050505081526020016003820180548060200260200160405190810160405280929190818152602001828054801561326357602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311613245575b50505050508152602001600482018054806020026020016040519081016040528092919081815260200182805480156132c557602002820191906000526020600020905b81546001600160a01b031681526001909101906020018083116132a7575b505050505081526020016005820180548060200260200160405190810160405280929190818152602001828054801561332757602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311613309575b50505091835250506006919091015460ff1615156020918201526000858152600e82526040808220338352909252908120805492935091900361336c5750505061147b565b60055460ff1661337e5750505061147b565b61338661471f565b61338f8461220c565b6000816002015464e8d4a51000856007015484600001546133b0919061563e565b6133ba919061565d565b6133c4919061567f565b905060006133d182614c66565b9050816014546133e1919061567f565b601455604051818152869033907f58e061a352c6af1903a4622a3148e0e1aff2403c9a25de111e57103c61301fb39060200160405180910390a384546003546001600160a01b039081169116146136e1576003546001600160a01b031661350257600084602001516001600160a01b031663ad5c46486040518163ffffffff1660e01b8152600401602060405180830381865afa158015613486573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906134aa9190615732565b9050806001600160a01b031663d0e30db0836040518263ffffffff1660e01b81526004016000604051808303818588803b1580156134e757600080fd5b505af11580156134fb573d6000803e3d6000fd5b5050505050505b600061350f60028361565d565b60035460808701515191925082916001600160a01b03909116901561357257608087015180516135419060019061567f565b8151811061355157613551615612565b6020026020010151905061356f8760200151848960800151306147ea565b91505b60035460a08801515184916001600160a01b031690156135d05760a0890151805161359f9060019061567f565b815181106135af576135af615612565b602002602001015192506135cd8960200151868b60a00151306147ea565b91505b89546040516370a0823160e01b81526000916001600160a01b0316906370a08231906136009030906004016152c8565b602060405180830381865afa15801561361d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061364191906155c3565b90506136558a6020015185848887306149da565b50508b546040516370a0823160e01b8152600092506001600160a01b03909116906370a082319061368a9030906004016152c8565b602060405180830381865afa1580156136a7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906136cb91906155c3565b90506136d7828261567f565b9750505050505050505b82546136ee9082906156cd565b8355600685015464e8d4a5100090613706908361563e565b613710919061565d565b836001015461371f91906156cd565b60018401556007850154835464e8d4a510009161373b9161563e565b613745919061565d565b600284015584546137639087906001600160a01b0316836001614b06565b6040518181528690339060008051602061586a8339815191529060200160405180910390a35050505050610d3160018055565b61379e6144a2565b600580548215156101000261ff00199091161790556040517f6c55f8d24f45456d49b15692f6cd375689cbbc2cc46a33366288f1061229c1d39061150e90831515815260200190565b600080600b84815481106137fd576137fd615612565b60009182526020808320878452600e825260408085206001600160a01b03808a16875293528085206006600a90950290920193840154845491516370a0823160e01b815294965091949193919216906370a08231906138609030906004016152c8565b602060405180830381865afa15801561387d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906138a191906155c3565b90508360050154431180156138b65750600081115b80156138c457506000600f54115b156139375760006138de85600501544387600401546128c3565b90506000600f548660010154600654846138f8919061563e565b613902919061563e565b61390c919061565d565b90508261391e8264e8d4a5100061563e565b613928919061565d565b61393290856156cd565b935050505b6001830154835464e8d4a5100090612b7190859061563e565b6139586146c6565b6000600b838154811061396d5761396d615612565b60009182526020808320868452600e825260408085203386529092529220600a909102909101915061399d61471f565b6139a5612631565b805415613b94576000816001015464e8d4a51000846006015484600001546139cd919061563e565b6139d7919061565d565b6139e1919061567f565b90508015613a9e57806139f2612e53565b1015613a105760405162461bcd60e51b8152600401610b9b90615696565b80601654613a1e91906156cd565b601655600a5461271090613a32908261567f565b613a3c908361563e565b613a46919061565d565b9050613a5233826144fc565b806011541115613a725780601154613a6a919061567f565b601155613a78565b60006011555b6040518181528590339060008051602061588a8339815191529060200160405180910390a35b6000826002015464e8d4a5100085600701548560000154613abf919061563e565b613ac9919061565d565b613ad3919061567f565b9050600081118015613ae7575060055460ff165b15613b91576000613af782614c66565b90508160146000828254613b0b919061567f565b90915550506003546001600160a01b0316613b5357604051339082156108fc029083906000818181858888f19350505050158015613b4d573d6000803e3d6000fd5b50613b6a565b600354613b6a906001600160a01b03163383614c96565b604051818152879033906000805160206158ca8339815191529060200160405180910390a3505b50505b828015613d5b5782546040516370a0823160e01b81526000916001600160a01b0316906370a0823190613bcb9030906004016152c8565b602060405180830381865afa158015613be8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613c0c91906155c3565b8454909150613c26906001600160a01b0316333088614e32565b83546040516370a0823160e01b81526000916001600160a01b0316906370a0823190613c569030906004016152c8565b602060405180830381865afa158015613c73573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613c9791906155c3565b90506000613ca5838361567f565b600987015490915061ffff1615613d2e57600986015460009061271090613cd09061ffff168461563e565b613cda919061565d565b6007548854919250613cf9916001600160a01b03908116911683614c96565b613d03818361567f565b866000016000828254613d1691906156cd565b90915550613d269050818661567f565b945050613d3e565b8454613d3b9082906156cd565b85555b8554613d579089906001600160a01b0316836001614b06565b5050505b6006830154825464e8d4a5100091613d729161563e565b613d7c919061565d565b60018301556007830154825464e8d4a5100091613d989161563e565b613da2919061565d565b60028301556040518181528590339060008051602061586a8339815191529060200160405180910390a343836004015411613e22578260010154600f54613de9919061567f565b600f55600060018401819055600681905560405190815233906000805160206158aa8339815191529060200160405180910390a2613e53565b6000600a54118015613e345750600084115b80613e465750600554610100900460ff165b15613e5357613e53614cec565b505050610a1960018055565b613e676144a2565b6001600160a01b038116613ecc5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610b9b565b610d3181614de2565b60008060175490506000601654613eea612e53565b613ef491906156cd565b600b5490915060005b81811015614070576000600b8281548110613f1a57613f1a615612565b600091825260208083206040805161016081018252600a90940290910180546001600160a01b031684526001810154928401929092526002820154908301526003810154606083015260048101546080830152600581015460a0830152600681015460c0830152600781015460e083015260088101546101008301526009015461ffff8082166101208401526201000090910416610140820152601054909250900361400c57600f5461191a82604001518360200151600654613fdd919061563e565b613fe7919061563e565b613ff1919061563e565b613ffb919061565d565b61400590866156cd565b945061405d565b60a0810151608082015160009161402391806128c3565b9050600f5482602001516006548361403b919061563e565b614045919061563e565b61404f919061565d565b61405990876156cd565b9550505b508061406881615719565b915050613efd565b50828210614082576000935050505090565b61408c828461567f565b935050505090565b61409c6144a2565b6000601054116140e45760405162461bcd60e51b81526020600482015260136024820152721c1bdbdb081a5cc81b9bdd081cdd185c9d1959606a1b6044820152606401610b9b565b600081116141255760405162461bcd60e51b815260206004820152600e60248201526d1a5b9d985b1a5908185b5bdd5b9d60921b6044820152606401610b9b565b6000805b600b5481101561419957600b818154811061414657614146615612565b90600052602060002090600a02016004015482101561418757600b818154811061417257614172615612565b90600052602060002090600a02016004015491505b8061419181615719565b915050614129565b504381116141e55760405162461bcd60e51b81526020600482015260196024820152781c1bdbdb081dd85cc8185b1c9958591e48199a5b9a5cda1959603a1b6044820152606401610b9b565b6141ed612631565b6002546040516370a0823160e01b81526000916001600160a01b0316906370a082319061421e9030906004016152c8565b602060405180830381865afa15801561423b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061425f91906155c3565b60025490915061427a906001600160a01b0316333086614e32565b6002546040516370a0823160e01b81526000916001600160a01b0316906370a08231906142ab9030906004016152c8565b602060405180830381865afa1580156142c8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906142ec91906155c3565b905081816011546142fd91906156cd565b614307919061567f565b601155614312614cec565b50505050565b6143206144a2565b43601054116143675760405162461bcd60e51b81526020600482015260136024820152726661726d2069732072756e6e696e67206e6f7760681b6044820152606401610b9b565b4381116143c25760405162461bcd60e51b8152602060048201526024808201527f73686f756c642062652067726561746572207468616e2063757272656e7420626044820152636c6f636b60e01b6064820152608401610b9b565b601081905560005b600b54811015610a1957601054600b82815481106143ea576143ea615612565b90600052602060002090600a020160030181905550601054600b828154811061441557614415615612565b90600052602060002090600a02016005018190555061191a600b828154811061444057614440615612565b90600052602060002090600a02016002015461445c919061563e565b60105461446991906156cd565b600b828154811061447c5761447c615612565b600091825260209091206004600a9092020101558061449a81615719565b9150506143ca565b6000546001600160a01b03163314610b055760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610b9b565b6002546040516370a0823160e01b81526000916001600160a01b0316906370a082319061452d9030906004016152c8565b602060405180830381865afa15801561454a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061456e91906155c3565b90506000818311156145f65760025460405163a9059cbb60e01b81526001600160a01b039091169063a9059cbb906145ac90879086906004016155dc565b6020604051808303816000875af11580156145cb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906145ef91906155f5565b905061466e565b60025460405163a9059cbb60e01b81526001600160a01b039091169063a9059cbb9061462890879087906004016155dc565b6020604051808303816000875af1158015614647573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061466b91906155f5565b90505b806143125760405162461bcd60e51b815260206004820152602260248201527f73616665546f6b656e5472616e736665723a207472616e73666572206661696c604482015261195960f21b6064820152608401610b9b565b6002600154036147185760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610b9b565b6002600155565b6009543410156147685760405162461bcd60e51b815260206004820152601460248201527373686f756c642070617920736d616c6c2067617360601b6044820152606401610b9b565b6008546009546040516001600160a01b039092169181156108fc0291906000818181858888f193505050501580156147a4573d6000803e3d6000fd5b50600954341115610b055760095433906108fc906147c2903461567f565b6040518115909202916000818181858888f19350505050158015610d31573d6000803e3d6000fd5b60008083600185516147fc919061567f565b8151811061480c5761480c615612565b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b815260040161483f91906152c8565b602060405180830381865afa15801561485c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061488091906155c3565b90506148ba86868660008151811061489a5761489a615612565b60200260200101516001600160a01b0316614e6a9092919063ffffffff16565b6001600160a01b038616635c11d79586600087876148da426102586156cd565b6040518663ffffffff1660e01b81526004016148fa95949392919061574f565b600060405180830381600087803b15801561491457600080fd5b505af1158015614928573d6000803e3d6000fd5b505050506000846001865161493d919061567f565b8151811061494d5761494d615612565b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b815260040161498091906152c8565b602060405180830381865afa15801561499d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906149c191906155c3565b90506149cd828261567f565b925050505b949350505050565b600080806149f26001600160a01b0389168a88614f6e565b614a066001600160a01b0388168a87614f6e565b6001600160a01b03891663e8e33700898989896000808b614a29426102586156cd565b60405160e08a901b6001600160e01b03191681526001600160a01b039889166004820152968816602488015260448701959095526064860193909352608485019190915260a484015290921660c482015260e4810191909152610104016060604051808303816000875af1158015614aa5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614ac991906157c0565b91945092509050614ae56001600160a01b0389168a6000614e6a565b614afa6001600160a01b0388168a6000614e6a565b96509650969350505050565b8015614ba95781600d8581548110614b2057614b20615612565b9060005260206000200154614b3591906156cd565b600d8581548110614b4857614b48615612565b6000918252602090912001556002546001600160a01b0390811690841603614b7c5781601254614b7891906156cd565b6012555b6003546001600160a01b0390811690841603614ba45781601354614ba091906156cd565b6013555b614312565b81600d8581548110614bbd57614bbd615612565b9060005260206000200154614bd2919061567f565b600d8581548110614be557614be5615612565b6000918252602090912001556002546001600160a01b0390811690841603614c2957816012541015614c175760128290555b81601254614c25919061567f565b6012555b6003546001600160a01b039081169084160361431257816013541015614c4f5760138290555b81601354614c5d919061567f565b60135550505050565b600080614c71612543565b9050601454831115614c835760145492505b80831115614c8f578092505b5090919050565b610c438363a9059cbb60e01b8484604051602401614cb59291906155dc565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b03199093169290921790915261500e565b6000805b600b54811015614d6057600b8181548110614d0d57614d0d615612565b90600052602060002090600a020160040154821015614d4e57600b8181548110614d3957614d39615612565b90600052602060002090600a02016004015491505b80614d5881615719565b915050614cf0565b50438111614d6b5750565b6000601654614d78612e53565b614d8291906156cd565b9050601754811115610a1957601754614d9b908261567f565b90506000614da9438461567f565b9050614db5818361565d565b600681905560405190815233906000805160206158aa8339815191529060200160405180910390a2505050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6040516001600160a01b03808516602483015283166044820152606481018290526143129085906323b872dd60e01b90608401614cb5565b801580614ee45750604051636eb1769f60e11b81523060048201526001600160a01b03838116602483015284169063dd62ed3e90604401602060405180830381865afa158015614ebe573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614ee291906155c3565b155b614f4f5760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b6064820152608401610b9b565b610c438363095ea7b360e01b8484604051602401614cb59291906155dc565b604051636eb1769f60e11b81523060048201526001600160a01b038381166024830152600091839186169063dd62ed3e90604401602060405180830381865afa158015614fbf573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614fe391906155c3565b614fed91906156cd565b90506143128463095ea7b360e01b8584604051602401614cb59291906155dc565b6000615063826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166150e09092919063ffffffff16565b805190915015610c43578080602001905181019061508191906155f5565b610c435760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610b9b565b6060612910848460008585600080866001600160a01b03168587604051615107919061581a565b60006040518083038185875af1925050503d8060008114615144576040519150601f19603f3d011682016040523d82523d6000602084013e615149565b606091505b50915091506149cd87838387606083156151c45782516000036151bd576001600160a01b0385163b6151bd5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610b9b565b50816149d2565b6149d283838151156151d95781518083602001fd5b8060405162461bcd60e51b8152600401610b9b9190615836565b828054828255906000526020600020908101928215615248579160200282015b8281111561524857825182546001600160a01b0319166001600160a01b03909116178255602090920191600190910190615213565b50615254929150615258565b5090565b5b808211156152545760008155600101615259565b6001600160a01b0381168114610d3157600080fd5b803561528d8161526d565b919050565b6000602082840312156152a457600080fd5b81356129138161526d565b6000602082840312156152c157600080fd5b5035919050565b6001600160a01b0391909116815260200190565b600080604083850312156152ef57600080fd5b50508035926020909101359150565b803561ffff8116811461528d57600080fd5b8015158114610d3157600080fd5b803561528d81615310565b60008060008060008060c0878903121561534257600080fd5b8635955060208701359450615359604088016152fe565b9350615367606088016152fe565b92506080870135915060a087013561537e81615310565b809150509295509295509295565b60008060008060008060c087890312156153a557600080fd5b8635955060208701356153b78161526d565b9450615359604088016152fe565b634e487b7160e01b600052604160045260246000fd5b600082601f8301126153ec57600080fd5b8135602067ffffffffffffffff80831115615409576154096153c5565b8260051b604051601f19603f8301168101818110848211171561542e5761542e6153c5565b60405293845285810183019383810192508785111561544c57600080fd5b83870191505b84821015612b855761546382615282565b83529183019190830190615452565b600080600080600080600060e0888a03121561548d57600080fd5b8735965061549d60208901615282565b9550604088013567ffffffffffffffff808211156154ba57600080fd5b6154c68b838c016153db565b965060608a01359150808211156154dc57600080fd5b6154e88b838c016153db565b955060808a01359150808211156154fe57600080fd5b61550a8b838c016153db565b945060a08a013591508082111561552057600080fd5b5061552d8a828b016153db565b92505061553c60c0890161531e565b905092959891949750929550565b60008060006060848603121561555f57600080fd5b505081359360208301359350604090920135919050565b6000806040838503121561558957600080fd5b82359150602083013561559b8161526d565b809150509250929050565b6000602082840312156155b857600080fd5b813561291381615310565b6000602082840312156155d557600080fd5b5051919050565b6001600160a01b03929092168252602082015260400190565b60006020828403121561560757600080fd5b815161291381615310565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b600081600019048311821515161561565857615658615628565b500290565b60008261567a57634e487b7160e01b600052601260045260246000fd5b500490565b60008282101561569157615691615628565b500390565b6020808252601a908201527f496e73756666696369656e742072657761726420746f6b656e73000000000000604082015260600190565b600082198211156156e0576156e0615628565b500190565b9687526020870195909552604086019390935261ffff918216606086015216608084015260a083015260c082015260e00190565b60006001820161572b5761572b615628565b5060010190565b60006020828403121561574457600080fd5b81516129138161526d565b600060a082018783526020878185015260a0604085015281875180845260c086019150828901935060005b8181101561579f5784516001600160a01b03168352938301939183019160010161577a565b50506001600160a01b03969096166060850152505050608001529392505050565b6000806000606084860312156157d557600080fd5b8351925060208401519150604084015190509250925092565b60005b838110156158095781810151838201526020016157f1565b838111156143125750506000910152565b6000825161582c8184602087016157ee565b9190910192915050565b60208152600082518060208401526158558160408501602087016157ee565b601f01601f1916919091016040019291505056fe90890809c654f11d6e72a28fa60149770a0d11ec6c92319d6ceb2bb0a4ea1a1534fcbac0073d7c3d388e51312faf357774904998eeb8fca628b9e6f65ee1cbf7e2492e003bbe8afa53088b406f0c1cb5d9e280370fc72a74cf116ffd343c4053995c9eca1f1b210f792e51b9d7f28c6b110d2573afeb0437ccf7522029c0deb2a2646970667358221220c60528de2ff841a8f7076fcfbcff3cb505bea83c13b5aeeef96ab47a413fb5c664736f6c634300080e0033
Verified Source Code Full Match
Compiler: v0.8.14+commit.80d49f37
EVM: london
Optimization: Yes (100 runs)
Ownable.sol 83 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
ReentrancyGuard.sol 69 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (security/ReentrancyGuard.sol)
pragma solidity ^0.8.0;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be _NOT_ENTERED
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
}
draft-IERC20Permit.sol 60 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)
pragma solidity ^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);
}
IERC20.sol 82 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @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);
/**
* @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 `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, 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 `from` to `to` 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 from,
address to,
uint256 amount
) external returns (bool);
}
SafeERC20.sol 116 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../extensions/draft-IERC20Permit.sol";
import "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
function safeTransfer(
IERC20 token,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(
IERC20 token,
address from,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(
IERC20 token,
address spender,
uint256 value
) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
uint256 newAllowance = token.allowance(address(this), spender) + value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
uint256 newAllowance = oldAllowance - value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
}
function safePermit(
IERC20Permit token,
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
uint256 nonceBefore = token.nonces(owner);
token.permit(owner, spender, value, deadline, v, r, s);
uint256 nonceAfter = token.nonces(owner);
require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
// Return data is optional
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
Address.sol 244 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.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 functionCallWithValue(target, data, 0, "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");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, 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) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, 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) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or 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 {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// 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);
}
}
}
Context.sol 24 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
BrewlabsFarm.sol 951 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {ReentrancyGuard} from "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import {SafeERC20, IERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "../libs/IUniRouter02.sol";
import "../libs/IWETH.sol";
// BrewlabsFarm is the master of brews. He can make brews and he is a fair guy.
//
// Note that it's ownable and the owner wields tremendous power. The ownership
// will be transferred to a governance smart contract once brews is sufficiently
// distributed and the community can show to govern itself.
//
// Have fun reading it. Hopefully it's bug-free. God bless.
contract BrewlabsFarm is Ownable, ReentrancyGuard {
using SafeERC20 for IERC20;
// Info of each user.
struct UserInfo {
uint256 amount; // How many LP tokens the user has provided.
uint256 rewardDebt; // Reward debt. See explanation below.
uint256 reflectionDebt; // Reflection debt. See explanation below.
//
// We do some fancy math here. Basically, any point in time, the amount of brewss
// entitled to a user but is pending to be distributed is:
//
// pending reward = (user.amount * pool.accTokenPerShare) - user.rewardDebt
//
// Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens:
// 1. The pool's `accTokenPerShare` (and `lastRewardBlock`) gets updated.
// 2. User receives the pending reward sent to his/her address.
// 3. User's `amount` gets updated.
// 4. User's `rewardDebt` gets updated.
}
// Info of each pool.
struct PoolInfo {
IERC20 lpToken; // Address of LP token contract.
uint256 allocPoint; // How many allocation points assigned to this pool. brewss to distribute per block.
uint256 duration;
uint256 startBlock;
uint256 bonusEndBlock;
uint256 lastRewardBlock; // Last block number that brewss distribution occurs.
uint256 accTokenPerShare; // Accumulated brewss per share, times 1e12. See below.
uint256 accReflectionPerShare; // Accumulated brewss per share, times 1e12. See below.
uint256 lastReflectionPerPoint;
uint16 depositFee; // Deposit fee in basis points
uint16 withdrawFee; // Deposit fee in basis points
}
struct SwapSetting {
IERC20 lpToken;
address swapRouter;
address[] earnedToToken0;
address[] earnedToToken1;
address[] reflectionToToken0;
address[] reflectionToToken1;
bool enabled;
}
// The brews TOKEN!
IERC20 public brews;
// Reflection Token
address public reflectionToken;
uint256 public accReflectionPerPoint;
bool public hasDividend;
bool public autoAdjustableForRewardRate = false;
// brews tokens created per block.
uint256 public rewardPerBlock;
// Bonus muliplier for early brews makers.
uint256 public constant BONUS_MULTIPLIER = 1;
uint256 public constant PERCENT_PRECISION = 10000;
uint256 private constant BLOCKS_PER_DAY = 6426;
// Deposit Fee address
address public feeAddress;
address public treasury = 0x64961Ffd0d84b2355eC2B5d35B0d8D8825A774dc;
uint256 public performanceFee = 0.00089 ether;
uint256 public rewardFee = 0;
// Info of each pool.
PoolInfo[] public poolInfo;
SwapSetting[] public swapSettings;
uint256[] public totalStaked;
// Info of each user that stakes LP tokens.
mapping(uint256 => mapping(address => UserInfo)) public userInfo;
// Total allocation points. Must be the sum of all allocation points in all pools.
uint256 public totalAllocPoint = 0;
// The block number when brews mining starts.
uint256 public startBlock;
uint256 private totalEarned;
uint256 private totalRewardStaked;
uint256 private totalReflectionStaked;
uint256 private totalReflections;
uint256 private reflectionDebt;
uint256 public paidRewards;
uint256 private shouldTotalPaid;
event Deposit(address indexed user, uint256 indexed pid, uint256 amount);
event Withdraw(address indexed user, uint256 indexed pid, uint256 amount);
event Claim(address indexed user, uint256 indexed pid, uint256 amount);
event ClaimDividend(address indexed user, uint256 indexed pid, uint256 amount);
event Compound(address indexed user, uint256 indexed pid, uint256 amount);
event CompoundDividend(address indexed user, uint256 indexed pid, uint256 amount);
event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount);
event SetPool(
uint256 pid,
address indexed lpToken,
uint256 allocPoint,
uint256 duration,
uint256 depositFee,
uint256 withdrawFee,
uint256 startBlock,
uint256 endBlock
);
event SetFeeAddress(address indexed user, address indexed newAddress);
event SetBuyBackWallet(address indexed user, address newAddress);
event SetPerformanceFee(uint256 fee);
event SetRewardFee(uint256 fee);
event SetAutoAdjustableForRewardRate(bool status);
event UpdateEmissionRate(address indexed user, uint256 rewardPerBlock);
constructor(IERC20 _brews, address _reflectionToken, uint256 _rewardPerBlock, bool _hasDividend) {
brews = _brews;
reflectionToken = _reflectionToken;
rewardPerBlock = _rewardPerBlock;
hasDividend = _hasDividend;
feeAddress = msg.sender;
startBlock = block.number + 30 * BLOCKS_PER_DAY; // after 30 days
}
mapping(IERC20 => bool) public poolExistence;
modifier nonDuplicated(IERC20 _lpToken) {
require(poolExistence[_lpToken] == false, "nonDuplicated: duplicated");
_;
}
function poolLength() external view returns (uint256) {
return poolInfo.length;
}
// Add a new lp to the pool. Can only be called by the owner.
function add(
uint256 _allocPoint,
IERC20 _lpToken,
uint16 _depositFee,
uint16 _withdrawFee,
uint256 _duration,
bool _withUpdate
) external onlyOwner nonDuplicated(_lpToken) {
require(_depositFee <= PERCENT_PRECISION, "add: invalid deposit fee basis points");
require(_withdrawFee <= PERCENT_PRECISION, "add: invalid withdraw fee basis points");
if (_withUpdate) {
massUpdatePools();
}
uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock;
totalAllocPoint = totalAllocPoint + _allocPoint;
poolExistence[_lpToken] = true;
poolInfo.push(
PoolInfo({
lpToken: _lpToken,
allocPoint: _allocPoint,
duration: _duration,
startBlock: lastRewardBlock,
bonusEndBlock: lastRewardBlock + _duration * BLOCKS_PER_DAY,
lastRewardBlock: lastRewardBlock,
accTokenPerShare: 0,
accReflectionPerShare: 0,
lastReflectionPerPoint: 0,
depositFee: _depositFee,
withdrawFee: _withdrawFee
})
);
swapSettings.push();
swapSettings[swapSettings.length - 1].lpToken = _lpToken;
totalStaked.push(0);
emit SetPool(
poolInfo.length - 1,
address(_lpToken),
_allocPoint,
_duration,
_depositFee,
_withdrawFee,
lastRewardBlock,
lastRewardBlock + _duration * BLOCKS_PER_DAY
);
}
// Update the given pool's brews allocation point and deposit fee. Can only be called by the owner.
function set(
uint256 _pid,
uint256 _allocPoint,
uint16 _depositFee,
uint16 _withdrawFee,
uint256 _duration,
bool _withUpdate
) external onlyOwner {
require(_depositFee <= PERCENT_PRECISION, "set: invalid deposit fee basis points");
require(_withdrawFee <= PERCENT_PRECISION, "set: invalid withdraw fee basis points");
if (poolInfo[_pid].bonusEndBlock > block.number) {
require(poolInfo[_pid].startBlock + _duration * BLOCKS_PER_DAY > block.number, "set: invalid duration");
}
if (_withUpdate) {
massUpdatePools();
}
totalAllocPoint = totalAllocPoint - poolInfo[_pid].allocPoint + _allocPoint;
poolInfo[_pid].allocPoint = _allocPoint;
poolInfo[_pid].depositFee = _depositFee;
poolInfo[_pid].withdrawFee = _withdrawFee;
poolInfo[_pid].duration = _duration;
if (poolInfo[_pid].bonusEndBlock < block.number) {
if (!_withUpdate) updatePool(_pid);
poolInfo[_pid].startBlock = block.number;
poolInfo[_pid].bonusEndBlock = block.number + _duration * BLOCKS_PER_DAY;
} else {
poolInfo[_pid].bonusEndBlock = poolInfo[_pid].startBlock + _duration * BLOCKS_PER_DAY;
}
emit SetPool(
_pid,
address(poolInfo[_pid].lpToken),
_allocPoint,
_duration,
_depositFee,
_withdrawFee,
poolInfo[_pid].startBlock,
poolInfo[_pid].bonusEndBlock
);
}
// Update the given pool's compound parameters. Can only be called by the owner.
function setSwapSetting(
uint256 _pid,
address _uniRouter,
address[] memory _earnedToToken0,
address[] memory _earnedToToken1,
address[] memory _reflectionToToken0,
address[] memory _reflectionToToken1,
bool _enabled
) external onlyOwner {
SwapSetting storage swapSetting = swapSettings[_pid];
swapSetting.enabled = _enabled;
swapSetting.swapRouter = _uniRouter;
swapSetting.earnedToToken0 = _earnedToToken0;
swapSetting.earnedToToken1 = _earnedToToken1;
swapSetting.reflectionToToken0 = _reflectionToToken0;
swapSetting.reflectionToToken1 = _reflectionToToken1;
}
// Return reward multiplier over the given _from to _to block.
function getMultiplier(uint256 _from, uint256 _to, uint256 _endBlock) public pure returns (uint256) {
if (_from > _endBlock) return 0;
if (_to > _endBlock) {
return (_endBlock - _from) * BONUS_MULTIPLIER;
}
return (_to - _from) * BONUS_MULTIPLIER;
}
// View function to see pending brews on frontend.
function pendingRewards(uint256 _pid, address _user) external view returns (uint256) {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][_user];
uint256 accTokenPerShare = pool.accTokenPerShare;
uint256 lpSupply = pool.lpToken.balanceOf(address(this));
if (block.number > pool.lastRewardBlock && lpSupply > 0 && totalAllocPoint > 0) {
uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number, pool.bonusEndBlock);
uint256 brewsReward = (multiplier * rewardPerBlock * pool.allocPoint) / totalAllocPoint;
accTokenPerShare += (brewsReward * 1e12) / lpSupply;
}
return (user.amount * accTokenPerShare) / 1e12 - user.rewardDebt;
}
function pendingReflections(uint256 _pid, address _user) external view returns (uint256) {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][_user];
uint256 accReflectionPerShare = pool.accReflectionPerShare;
uint256 lpSupply = pool.lpToken.balanceOf(address(this));
if (reflectionToken == address(pool.lpToken)) lpSupply = totalReflectionStaked;
if (block.number > pool.lastRewardBlock && lpSupply > 0 && hasDividend && totalAllocPoint > 0) {
uint256 reflectionAmt = availableDividendTokens();
if (reflectionAmt > totalReflections) {
reflectionAmt -= totalReflections;
} else {
reflectionAmt = 0;
}
uint256 _accReflectionPerPoint = accReflectionPerPoint + (reflectionAmt * 1e12) / totalAllocPoint;
accReflectionPerShare = pool.accReflectionPerShare
+ ((pool.allocPoint * (_accReflectionPerPoint - pool.lastReflectionPerPoint)) / lpSupply);
}
return (user.amount * accReflectionPerShare) / 1e12 - user.reflectionDebt;
}
// Update reward variables for all pools. Be careful of gas spending!
function massUpdatePools() public {
uint256 length = poolInfo.length;
for (uint256 pid = 0; pid < length; pid++) {
updatePool(pid);
}
}
// Update reward variables of the given pool to be up-to-date.
function updatePool(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
if (block.number <= pool.lastRewardBlock) {
return;
}
uint256 lpSupply = pool.lpToken.balanceOf(address(this));
if (address(pool.lpToken) == address(brews)) lpSupply = totalRewardStaked;
if (address(pool.lpToken) == reflectionToken) lpSupply = totalReflectionStaked;
if (lpSupply == 0 || pool.allocPoint == 0) {
pool.lastRewardBlock = block.number;
return;
}
uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number, pool.bonusEndBlock);
uint256 brewsReward = (multiplier * rewardPerBlock * pool.allocPoint) / totalAllocPoint;
pool.accTokenPerShare += (brewsReward * 1e12) / lpSupply;
if (hasDividend) {
uint256 reflectionAmt = availableDividendTokens();
if (reflectionAmt > totalReflections) {
reflectionAmt -= totalReflections;
} else {
reflectionAmt = 0;
}
accReflectionPerPoint += (reflectionAmt * 1e12) / totalAllocPoint;
pool.accReflectionPerShare +=
(pool.allocPoint * (accReflectionPerPoint - pool.lastReflectionPerPoint)) / (lpSupply);
pool.lastReflectionPerPoint = accReflectionPerPoint;
totalReflections += reflectionAmt;
}
pool.lastRewardBlock = block.number;
shouldTotalPaid = shouldTotalPaid + brewsReward;
}
// Deposit LP tokens to BrewlabsFarm for brews allocation.
function deposit(uint256 _pid, uint256 _amount) external payable nonReentrant {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
_transferPerformanceFee();
massUpdatePools();
if (user.amount > 0) {
uint256 pending = (user.amount * pool.accTokenPerShare) / 1e12 - user.rewardDebt;
if (pending > 0) {
require(availableRewardTokens() >= pending, "Insufficient reward tokens");
paidRewards = paidRewards + pending;
pending = (pending * (PERCENT_PRECISION - rewardFee)) / PERCENT_PRECISION;
safeTokenTransfer(msg.sender, pending);
if (totalEarned > pending) {
totalEarned = totalEarned - pending;
} else {
totalEarned = 0;
}
emit Claim(msg.sender, _pid, pending);
}
uint256 pendingReflection = (user.amount * pool.accReflectionPerShare) / 1e12 - user.reflectionDebt;
if (pendingReflection > 0 && hasDividend) {
uint256 _pendingReflection = _estimateDividendAmount(pendingReflection);
totalReflections -= pendingReflection;
if (address(reflectionToken) == address(0x0)) {
payable(msg.sender).transfer(_pendingReflection);
} else {
IERC20(reflectionToken).safeTransfer(msg.sender, _pendingReflection);
}
emit ClaimDividend(msg.sender, _pid, _pendingReflection);
}
}
uint256 realAmount = _amount;
if (_amount > 0) {
uint256 beforeAmt = pool.lpToken.balanceOf(address(this));
pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amount);
uint256 afterAmt = pool.lpToken.balanceOf(address(this));
uint256 amount = afterAmt - beforeAmt;
if (pool.depositFee > 0) {
uint256 depositFee = (amount * pool.depositFee) / PERCENT_PRECISION;
pool.lpToken.safeTransfer(feeAddress, depositFee);
user.amount += amount - depositFee;
realAmount -= depositFee;
} else {
user.amount = user.amount + amount;
}
_calculateTotalStaked(_pid, pool.lpToken, amount, true);
}
user.rewardDebt = (user.amount * pool.accTokenPerShare) / 1e12;
user.reflectionDebt = (user.amount * pool.accReflectionPerShare) / 1e12;
emit Deposit(msg.sender, _pid, realAmount);
if (pool.bonusEndBlock <= block.number) {
totalAllocPoint = totalAllocPoint - pool.allocPoint;
pool.allocPoint = 0;
rewardPerBlock = 0;
emit UpdateEmissionRate(msg.sender, rewardPerBlock);
} else if ((rewardFee > 0 && _amount > 0) || autoAdjustableForRewardRate) {
_updateRewardRate();
}
}
// Withdraw LP tokens from BrewlabsFarm.
function withdraw(uint256 _pid, uint256 _amount) external payable nonReentrant {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
require(user.amount >= _amount, "withdraw: not good");
require(_amount > 0, "Amount should be greator than 0");
_transferPerformanceFee();
if (pool.bonusEndBlock < block.number) {
massUpdatePools();
totalAllocPoint = totalAllocPoint - pool.allocPoint;
pool.allocPoint = 0;
rewardPerBlock = 0;
emit UpdateEmissionRate(msg.sender, rewardPerBlock);
} else {
updatePool(_pid);
}
uint256 pending = (user.amount * pool.accTokenPerShare) / 1e12 - user.rewardDebt;
if (pending > 0) {
require(availableRewardTokens() >= pending, "Insufficient reward tokens");
paidRewards = paidRewards + pending;
pending = (pending * (PERCENT_PRECISION - rewardFee)) / PERCENT_PRECISION;
safeTokenTransfer(msg.sender, pending);
if (totalEarned > pending) {
totalEarned = totalEarned - pending;
} else {
totalEarned = 0;
}
emit Claim(msg.sender, _pid, pending);
}
uint256 pendingReflection = (user.amount * pool.accReflectionPerShare) / 1e12 - user.reflectionDebt;
if (pendingReflection > 0 && hasDividend) {
uint256 _pendingReflection = _estimateDividendAmount(pendingReflection);
totalReflections -= pendingReflection;
if (address(reflectionToken) == address(0x0)) {
payable(msg.sender).transfer(_pendingReflection);
} else {
IERC20(reflectionToken).safeTransfer(msg.sender, _pendingReflection);
}
emit ClaimDividend(msg.sender, _pid, _pendingReflection);
}
if (_amount > 0) {
user.amount = user.amount - _amount;
if (pool.withdrawFee > 0) {
uint256 withdrawFee = (_amount * pool.withdrawFee) / PERCENT_PRECISION;
pool.lpToken.safeTransfer(feeAddress, withdrawFee);
pool.lpToken.safeTransfer(address(msg.sender), _amount - withdrawFee);
} else {
pool.lpToken.safeTransfer(address(msg.sender), _amount);
}
_calculateTotalStaked(_pid, pool.lpToken, _amount, false);
}
user.rewardDebt = (user.amount * pool.accTokenPerShare) / 1e12;
user.reflectionDebt = (user.amount * pool.accReflectionPerShare) / 1e12;
emit Withdraw(msg.sender, _pid, _amount);
if (autoAdjustableForRewardRate) _updateRewardRate();
}
function claimReward(uint256 _pid) external payable nonReentrant {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
if (user.amount == 0) return;
_transferPerformanceFee();
updatePool(_pid);
uint256 pending = (user.amount * pool.accTokenPerShare) / 1e12 - user.rewardDebt;
if (pending > 0) {
require(availableRewardTokens() >= pending, "Insufficient reward tokens");
paidRewards = paidRewards + pending;
pending = (pending * (PERCENT_PRECISION - rewardFee)) / PERCENT_PRECISION;
safeTokenTransfer(msg.sender, pending);
if (totalEarned > pending) {
totalEarned = totalEarned - pending;
} else {
totalEarned = 0;
}
emit Claim(msg.sender, _pid, pending);
}
user.rewardDebt = (user.amount * pool.accTokenPerShare) / 1e12;
}
function compoundReward(uint256 _pid) external payable nonReentrant {
PoolInfo storage pool = poolInfo[_pid];
SwapSetting memory swapSetting = swapSettings[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
if (user.amount == 0) return;
if (!swapSetting.enabled) return;
_transferPerformanceFee();
updatePool(_pid);
uint256 pending = (user.amount * pool.accTokenPerShare) / 1e12 - user.rewardDebt;
if (pending > 0) {
require(availableRewardTokens() >= pending, "Insufficient reward tokens");
paidRewards = paidRewards + pending;
pending = (pending * (PERCENT_PRECISION - rewardFee)) / PERCENT_PRECISION;
if (totalEarned > pending) {
totalEarned = totalEarned - pending;
} else {
totalEarned = 0;
}
emit Compound(msg.sender, _pid, pending);
}
if (address(brews) != address(pool.lpToken)) {
uint256 tokenAmt = pending / 2;
uint256 tokenAmt0 = tokenAmt;
address token0 = address(brews);
if (swapSetting.earnedToToken0.length > 0) {
token0 = swapSetting.earnedToToken0[swapSetting.earnedToToken0.length - 1];
tokenAmt0 = _safeSwap(swapSetting.swapRouter, tokenAmt, swapSetting.earnedToToken0, address(this));
}
uint256 tokenAmt1 = tokenAmt;
address token1 = address(brews);
if (swapSetting.earnedToToken1.length > 0) {
token1 = swapSetting.earnedToToken1[swapSetting.earnedToToken1.length - 1];
tokenAmt1 = _safeSwap(swapSetting.swapRouter, tokenAmt, swapSetting.earnedToToken1, address(this));
}
uint256 beforeAmt = pool.lpToken.balanceOf(address(this));
_addLiquidity(swapSetting.swapRouter, token0, token1, tokenAmt0, tokenAmt1, address(this));
uint256 afterAmt = pool.lpToken.balanceOf(address(this));
pending = afterAmt - beforeAmt;
}
user.amount = user.amount + pending;
user.rewardDebt = (user.amount * pool.accTokenPerShare) / 1e12;
user.reflectionDebt = user.reflectionDebt + (pending * pool.accReflectionPerShare) / 1e12;
_calculateTotalStaked(_pid, pool.lpToken, pending, true);
emit Deposit(msg.sender, _pid, pending);
}
function claimDividend(uint256 _pid) external payable nonReentrant {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
if (user.amount == 0) return;
if (!hasDividend) return;
_transferPerformanceFee();
updatePool(_pid);
uint256 pendingReflection = (user.amount * pool.accReflectionPerShare) / 1e12 - user.reflectionDebt;
if (pendingReflection > 0) {
uint256 _pendingReflection = _estimateDividendAmount(pendingReflection);
totalReflections = totalReflections - pendingReflection;
if (address(reflectionToken) == address(0x0)) {
payable(msg.sender).transfer(_pendingReflection);
} else {
IERC20(reflectionToken).safeTransfer(msg.sender, _pendingReflection);
}
emit ClaimDividend(msg.sender, _pid, _pendingReflection);
}
user.reflectionDebt = (user.amount * pool.accReflectionPerShare) / 1e12;
}
function compoundDividend(uint256 _pid) external payable nonReentrant {
PoolInfo storage pool = poolInfo[_pid];
SwapSetting memory swapSetting = swapSettings[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
if (user.amount == 0) return;
if (!hasDividend) return;
_transferPerformanceFee();
updatePool(_pid);
uint256 _pending = (user.amount * pool.accReflectionPerShare) / 1e12 - user.reflectionDebt;
uint256 pending = _estimateDividendAmount(_pending);
totalReflections = totalReflections - _pending;
emit CompoundDividend(msg.sender, _pid, pending);
if (reflectionToken != address(pool.lpToken)) {
if (reflectionToken == address(0x0)) {
address wethAddress = IUniRouter02(swapSetting.swapRouter).WETH();
IWETH(wethAddress).deposit{value: pending}();
}
uint256 tokenAmt = pending / 2;
uint256 tokenAmt0 = tokenAmt;
address token0 = reflectionToken;
if (swapSetting.reflectionToToken0.length > 0) {
token0 = swapSetting.reflectionToToken0[swapSetting.reflectionToToken0.length - 1];
tokenAmt0 = _safeSwap(swapSetting.swapRouter, tokenAmt, swapSetting.reflectionToToken0, address(this));
}
uint256 tokenAmt1 = tokenAmt;
address token1 = reflectionToken;
if (swapSetting.reflectionToToken1.length > 0) {
token0 = swapSetting.reflectionToToken1[swapSetting.reflectionToToken1.length - 1];
tokenAmt1 = _safeSwap(swapSetting.swapRouter, tokenAmt, swapSetting.reflectionToToken1, address(this));
}
uint256 beforeAmt = pool.lpToken.balanceOf(address(this));
_addLiquidity(swapSetting.swapRouter, token0, token1, tokenAmt0, tokenAmt1, address(this));
uint256 afterAmt = pool.lpToken.balanceOf(address(this));
pending = afterAmt - beforeAmt;
}
user.amount = user.amount + pending;
user.rewardDebt = user.rewardDebt + (pending * pool.accTokenPerShare) / 1e12;
user.reflectionDebt = (user.amount * pool.accReflectionPerShare) / 1e12;
_calculateTotalStaked(_pid, pool.lpToken, pending, true);
emit Deposit(msg.sender, _pid, pending);
}
// Withdraw without caring about rewards. EMERGENCY ONLY.
function emergencyWithdraw(uint256 _pid) external nonReentrant {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
uint256 amount = user.amount;
user.amount = 0;
user.rewardDebt = 0;
user.reflectionDebt = 0;
pool.lpToken.safeTransfer(address(msg.sender), amount);
_calculateTotalStaked(_pid, pool.lpToken, amount, false);
emit EmergencyWithdraw(msg.sender, _pid, amount);
}
function _transferPerformanceFee() internal {
require(msg.value >= performanceFee, "should pay small gas");
payable(treasury).transfer(performanceFee);
if (msg.value > performanceFee) {
payable(msg.sender).transfer(msg.value - performanceFee);
}
}
function _calculateTotalStaked(uint256 _pid, IERC20 _lpToken, uint256 _amount, bool _deposit) internal {
if (_deposit) {
totalStaked[_pid] = totalStaked[_pid] + _amount;
if (address(_lpToken) == address(brews)) {
totalRewardStaked = totalRewardStaked + _amount;
}
if (address(_lpToken) == reflectionToken) {
totalReflectionStaked = totalReflectionStaked + _amount;
}
} else {
totalStaked[_pid] = totalStaked[_pid] - _amount;
if (address(_lpToken) == address(brews)) {
if (totalRewardStaked < _amount) totalRewardStaked = _amount;
totalRewardStaked = totalRewardStaked - _amount;
}
if (address(_lpToken) == reflectionToken) {
if (totalReflectionStaked < _amount) totalReflectionStaked = _amount;
totalReflectionStaked = totalReflectionStaked - _amount;
}
}
}
function _estimateDividendAmount(uint256 amount) internal view returns (uint256) {
uint256 dTokenBal = availableDividendTokens();
if (amount > totalReflections) amount = totalReflections;
if (amount > dTokenBal) amount = dTokenBal;
return amount;
}
/**
* @notice Available amount of reward token
*/
function availableRewardTokens() public view returns (uint256) {
if (address(brews) == reflectionToken && hasDividend) return totalEarned;
uint256 _amount = brews.balanceOf(address(this));
return _amount - totalRewardStaked;
}
/**
* @notice Available amount of reflection token
*/
function availableDividendTokens() public view returns (uint256) {
if (hasDividend == false) return 0;
if (address(reflectionToken) == address(0x0)) {
return address(this).balance;
}
uint256 _amount = IERC20(reflectionToken).balanceOf(address(this));
if (address(reflectionToken) == address(brews)) {
if (_amount < totalEarned) return 0;
_amount = _amount - totalEarned;
}
return _amount - totalReflectionStaked;
}
function insufficientRewards() external view returns (uint256) {
uint256 adjustedShouldTotalPaid = shouldTotalPaid;
uint256 remainRewards = availableRewardTokens() + paidRewards;
uint256 length = poolInfo.length;
for (uint256 pid = 0; pid < length; pid++) {
PoolInfo memory pool = poolInfo[pid];
if (startBlock == 0) {
adjustedShouldTotalPaid +=
(rewardPerBlock * pool.allocPoint * pool.duration * BLOCKS_PER_DAY) / totalAllocPoint;
} else {
uint256 multiplier = getMultiplier(pool.lastRewardBlock, pool.bonusEndBlock, pool.bonusEndBlock);
adjustedShouldTotalPaid += (multiplier * rewardPerBlock * pool.allocPoint) / totalAllocPoint;
}
}
if (remainRewards >= adjustedShouldTotalPaid) return 0;
return adjustedShouldTotalPaid - remainRewards;
}
// Safe brews transfer function, just in case if rounding error causes pool to not have enough brewss.
function safeTokenTransfer(address _to, uint256 _amount) internal {
uint256 brewsBal = brews.balanceOf(address(this));
bool transferSuccess = false;
if (_amount > brewsBal) {
transferSuccess = brews.transfer(_to, brewsBal);
} else {
transferSuccess = brews.transfer(_to, _amount);
}
require(transferSuccess, "safeTokenTransfer: transfer failed");
}
function setFeeAddress(address _feeAddress) external onlyOwner {
feeAddress = _feeAddress;
emit SetFeeAddress(msg.sender, _feeAddress);
}
function setPerformanceFee(uint256 _fee) external {
require(msg.sender == treasury, "setPerformanceFee: FORBIDDEN");
performanceFee = _fee;
emit SetPerformanceFee(_fee);
}
function setRewardFee(uint256 _fee) external onlyOwner {
require(_fee < PERCENT_PRECISION, "setRewardFee: invalid percentage");
rewardFee = _fee;
emit SetRewardFee(_fee);
}
function setBuyBackWallet(address _addr) external {
require(msg.sender == treasury, "setBuyBackWallet: FORBIDDEN");
treasury = _addr;
emit SetBuyBackWallet(msg.sender, _addr);
}
function setAutoAdjustableForRewardRate(bool _status) external onlyOwner {
autoAdjustableForRewardRate = _status;
emit SetAutoAdjustableForRewardRate(_status);
}
//Brews has to add hidden dummy pools inorder to alter the emission, here we make it simple and transparent to all.
function updateEmissionRate(uint256 _rewardPerBlock) external onlyOwner {
massUpdatePools();
rewardPerBlock = _rewardPerBlock;
emit UpdateEmissionRate(msg.sender, _rewardPerBlock);
}
function updateStartBlock(uint256 _startBlock) external onlyOwner {
require(startBlock > block.number, "farm is running now");
require(_startBlock > block.number, "should be greater than current block");
startBlock = _startBlock;
for (uint256 pid = 0; pid < poolInfo.length; pid++) {
poolInfo[pid].startBlock = startBlock;
poolInfo[pid].lastRewardBlock = startBlock;
poolInfo[pid].bonusEndBlock = startBlock + poolInfo[pid].duration * BLOCKS_PER_DAY;
}
}
/**
* @notice Deposit reward token
* @dev Only call by owner. Needs to be for deposit of reward token when reflection token is same with reward token.
*/
function depositRewards(uint256 _amount) external nonReentrant {
require(_amount > 0);
uint256 beforeAmt = brews.balanceOf(address(this));
brews.safeTransferFrom(msg.sender, address(this), _amount);
uint256 afterAmt = brews.balanceOf(address(this));
totalEarned = totalEarned + afterAmt - beforeAmt;
}
function increaseEmissionRate(uint256 _amount) external onlyOwner {
require(startBlock > 0, "pool is not started");
require(_amount > 0, "invalid amount");
uint256 bonusEndBlock = 0;
for (uint256 i = 0; i < poolInfo.length; i++) {
if (bonusEndBlock < poolInfo[i].bonusEndBlock) {
bonusEndBlock = poolInfo[i].bonusEndBlock;
}
}
require(bonusEndBlock > block.number, "pool was already finished");
massUpdatePools();
uint256 beforeAmt = brews.balanceOf(address(this));
brews.safeTransferFrom(msg.sender, address(this), _amount);
uint256 afterAmt = brews.balanceOf(address(this));
totalEarned = totalEarned + afterAmt - beforeAmt;
_updateRewardRate();
}
function _updateRewardRate() internal {
uint256 bonusEndBlock = 0;
for (uint256 i = 0; i < poolInfo.length; i++) {
if (bonusEndBlock < poolInfo[i].bonusEndBlock) {
bonusEndBlock = poolInfo[i].bonusEndBlock;
}
}
if (bonusEndBlock <= block.number) return;
uint256 remainRewards = availableRewardTokens() + paidRewards;
if (remainRewards > shouldTotalPaid) {
remainRewards = remainRewards - shouldTotalPaid;
uint256 remainBlocks = bonusEndBlock - block.number;
rewardPerBlock = remainRewards / remainBlocks;
emit UpdateEmissionRate(msg.sender, rewardPerBlock);
}
}
function emergencyWithdrawRewards(uint256 _amount) external onlyOwner {
if (_amount == 0) {
uint256 amount = brews.balanceOf(address(this));
safeTokenTransfer(msg.sender, amount);
} else {
safeTokenTransfer(msg.sender, _amount);
}
}
function emergencyWithdrawReflections() external onlyOwner {
if (address(reflectionToken) == address(0x0)) {
uint256 amount = address(this).balance;
payable(address(msg.sender)).transfer(amount);
} else {
uint256 amount = IERC20(reflectionToken).balanceOf(address(this));
IERC20(reflectionToken).transfer(msg.sender, amount);
}
}
function transferToHarvest() external onlyOwner {
if (hasDividend || address(brews) == reflectionToken) return;
if (reflectionToken == address(0x0)) {
payable(treasury).transfer(address(this).balance);
} else {
uint256 _amount = IERC20(reflectionToken).balanceOf(address(this));
IERC20(reflectionToken).safeTransfer(treasury, _amount);
}
}
function recoverWrongToken(address _token) external onlyOwner {
require(
_token != address(brews) && _token != reflectionToken, "cannot recover reward token or reflection token"
);
require(poolExistence[IERC20(_token)] == false, "token is using on pool");
if (_token == address(0x0)) {
uint256 amount = address(this).balance;
payable(address(msg.sender)).transfer(amount);
} else {
uint256 amount = IERC20(_token).balanceOf(address(this));
if (amount > 0) {
IERC20(_token).transfer(msg.sender, amount);
}
}
}
function _safeSwap(address _uniRouter, uint256 _amountIn, address[] memory _path, address _to)
internal
returns (uint256)
{
uint256 beforeAmt = IERC20(_path[_path.length - 1]).balanceOf(address(this));
IERC20(_path[0]).safeApprove(_uniRouter, _amountIn);
IUniRouter02(_uniRouter).swapExactTokensForTokensSupportingFeeOnTransferTokens(
_amountIn, 0, _path, _to, block.timestamp + 600
);
uint256 afterAmt = IERC20(_path[_path.length - 1]).balanceOf(address(this));
return afterAmt - beforeAmt;
}
function _addLiquidity(
address _uniRouter,
address _token0,
address _token1,
uint256 _tokenAmt0,
uint256 _tokenAmt1,
address _to
) internal returns (uint256 amountA, uint256 amountB, uint256 liquidity) {
IERC20(_token0).safeIncreaseAllowance(_uniRouter, _tokenAmt0);
IERC20(_token1).safeIncreaseAllowance(_uniRouter, _tokenAmt1);
(amountA, amountB, liquidity) = IUniRouter02(_uniRouter).addLiquidity(
_token0, _token1, _tokenAmt0, _tokenAmt1, 0, 0, _to, block.timestamp + 600
);
IERC20(_token0).safeApprove(_uniRouter, uint256(0));
IERC20(_token1).safeApprove(_uniRouter, uint256(0));
}
receive() external payable {}
}
IUniRouter01.sol 139 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface IUniRouter01 {
function factory() external pure returns (address);
function WETH() external pure returns (address);
function addLiquidity(
address tokenA,
address tokenB,
uint256 amountADesired,
uint256 amountBDesired,
uint256 amountAMin,
uint256 amountBMin,
address to,
uint256 deadline
) external returns (uint256 amountA, uint256 amountB, uint256 liquidity);
function addLiquidityETH(
address token,
uint256 amountTokenDesired,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline
) external payable returns (uint256 amountToken, uint256 amountETH, uint256 liquidity);
function removeLiquidity(
address tokenA,
address tokenB,
uint256 liquidity,
uint256 amountAMin,
uint256 amountBMin,
address to,
uint256 deadline
) external returns (uint256 amountA, uint256 amountB);
function removeLiquidityETH(
address token,
uint256 liquidity,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline
) external returns (uint256 amountToken, uint256 amountETH);
function removeLiquidityWithPermit(
address tokenA,
address tokenB,
uint256 liquidity,
uint256 amountAMin,
uint256 amountBMin,
address to,
uint256 deadline,
bool approveMax,
uint8 v,
bytes32 r,
bytes32 s
) external returns (uint256 amountA, uint256 amountB);
function removeLiquidityETHWithPermit(
address token,
uint256 liquidity,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline,
bool approveMax,
uint8 v,
bytes32 r,
bytes32 s
) external returns (uint256 amountToken, uint256 amountETH);
function swapExactTokensForTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
function swapTokensForExactTokens(
uint256 amountOut,
uint256 amountInMax,
address[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
function swapExactETHForTokens(uint256 amountOutMin, address[] calldata path, address to, uint256 deadline)
external
payable
returns (uint256[] memory amounts);
function swapTokensForExactETH(
uint256 amountOut,
uint256 amountInMax,
address[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
function swapExactTokensForETH(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
function swapETHForExactTokens(uint256 amountOut, address[] calldata path, address to, uint256 deadline)
external
payable
returns (uint256[] memory amounts);
function quote(uint256 amountA, uint256 reserveA, uint256 reserveB) external pure returns (uint256 amountB);
function getAmountOut(uint256 amountIn, uint256 reserveIn, uint256 reserveOut)
external
pure
returns (uint256 amountOut);
function getAmountIn(uint256 amountOut, uint256 reserveIn, uint256 reserveOut)
external
pure
returns (uint256 amountIn);
function getAmountsOut(uint256 amountIn, address[] calldata path)
external
view
returns (uint256[] memory amounts);
function getAmountsIn(uint256 amountOut, address[] calldata path)
external
view
returns (uint256[] memory amounts);
}
IUniRouter02.sol 52 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./IUniRouter01.sol";
interface IUniRouter02 is IUniRouter01 {
function removeLiquidityETHSupportingFeeOnTransferTokens(
address token,
uint256 liquidity,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline
) external returns (uint256 amountETH);
function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
address token,
uint256 liquidity,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline,
bool approveMax,
uint8 v,
bytes32 r,
bytes32 s
) external returns (uint256 amountETH);
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external;
function swapExactETHForTokensSupportingFeeOnTransferTokens(
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external payable;
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external;
}
IWETH.sol 9 lines
// SPDX-License-Identifier: MIT
pragma solidity >=0.5.0;
interface IWETH {
function deposit() external payable;
function transfer(address to, uint256 value) external returns (bool);
function withdraw(uint256) external;
}
Read Contract
BONUS_MULTIPLIER 0x8aa28550 → uint256
PERCENT_PRECISION 0xffe8e372 → uint256
accReflectionPerPoint 0x671882b0 → uint256
autoAdjustableForRewardRate 0x24937567 → bool
availableDividendTokens 0x5dde4a91 → uint256
availableRewardTokens 0x9f94e272 → uint256
brews 0x1a665955 → address
feeAddress 0x41275358 → address
getMultiplier 0x7bafb029 → uint256
hasDividend 0xa5bfd0f2 → bool
insufficientRewards 0xf3aeb31d → uint256
owner 0x8da5cb5b → address
paidRewards 0x83f07ea8 → uint256
pendingReflections 0x876ba4b7 → uint256
pendingRewards 0xd18df53c → uint256
performanceFee 0x87788782 → uint256
poolExistence 0xcbd258b5 → bool
poolInfo 0x1526fe27 → address, uint256, uint256, uint256, uint256, uint256, uint256, uint256, uint256, uint16, uint16
poolLength 0x081e3eda → uint256
reflectionToken 0xbc6a9e01 → address
rewardFee 0x8b424267 → uint256
rewardPerBlock 0x8ae39cac → uint256
startBlock 0x48cd4cb1 → uint256
swapSettings 0x84ed19b5 → address, address, bool
totalAllocPoint 0x17caf6f1 → uint256
totalStaked 0x41cb8c20 → uint256
treasury 0x61d027b3 → address
userInfo 0x93f1a40b → uint256, uint256, uint256
Write Contract 27 functions
These functions modify contract state and require a wallet transaction to execute.
add 0x49f5edde
uint256 _allocPoint
address _lpToken
uint16 _depositFee
uint16 _withdrawFee
uint256 _duration
bool _withUpdate
claimDividend 0x9abd3572
uint256 _pid
claimReward 0xae169a50
uint256 _pid
compoundDividend 0xbb952cd2
uint256 _pid
compoundReward 0x4060e257
uint256 _pid
deposit 0xe2bbb158
uint256 _pid
uint256 _amount
depositRewards 0x8bdf67f2
uint256 _amount
emergencyWithdraw 0x5312ea8e
uint256 _pid
emergencyWithdrawReflections 0x015d5238
No parameters
emergencyWithdrawRewards 0x30409c85
uint256 _amount
increaseEmissionRate 0xf4ef5ed5
uint256 _amount
massUpdatePools 0x630b5ba1
No parameters
recoverWrongToken 0x018bcf5c
address _token
renounceOwnership 0x715018a6
No parameters
set 0x4817517f
uint256 _pid
uint256 _allocPoint
uint16 _depositFee
uint16 _withdrawFee
uint256 _duration
bool _withUpdate
setAutoAdjustableForRewardRate 0xcd635cce
bool _status
setBuyBackWallet 0xa4640b82
address _addr
setFeeAddress 0x8705fcd4
address _feeAddress
setPerformanceFee 0x70897b23
uint256 _fee
setRewardFee 0x41a2ac70
uint256 _fee
setSwapSetting 0x6c95d09b
uint256 _pid
address _uniRouter
address[] _earnedToToken0
address[] _earnedToToken1
address[] _reflectionToToken0
address[] _reflectionToToken1
bool _enabled
transferOwnership 0xf2fde38b
address newOwner
transferToHarvest 0x766e8098
No parameters
updateEmissionRate 0x0ba84cd2
uint256 _rewardPerBlock
updatePool 0x51eb05a6
uint256 _pid
updateStartBlock 0xfac2b9ba
uint256 _startBlock
withdraw 0x441a3e70
uint256 _pid
uint256 _amount
Recent Transactions
No transactions found for this address