Address Contract Partially Verified
Address
0x892f481BD6E9d7D26aE365211D9B45175d5D00e4
Balance
0 ETH
Nonce
1
Code Size
11868 bytes
Creator
0xdfeE8DC2...a84E at tx 0x6f4a53a2...f4223c
Indexed Transactions
0
Contract Bytecode
11868 bytes
0x608060405234801561001057600080fd5b50600436106101da5760003560e01c806386a5053511610104578063c1ba4e59116100a2578063e981014311610071578063e9810143146105e3578063e9fad8ee14610600578063f2fde38b14610608578063fe0d94c11461062e576101da565b8063c1ba4e5914610500578063d4ee1d901461051d578063d6f0948c14610525578063da35c664146105db576101da565b8063a1bf8824116100de578063a1bf882414610489578063a1e9204e14610491578063a694fc3a146104bd578063ab4f440f146104da576101da565b806386a50535146104475780638da5cb5b146104645780639449a6551461046c576101da565b80634d318b0e1161017c578063750e443a1161014b578063750e443a146103df57806379ba5097146103fc57806379ec5d3a1461040457806382d5f1531461042a576101da565b80634d318b0e14610386578063536af3cf146103a357806356364499146103ab57806373f4596a146103b3576101da565b80630d15fd77116101b85780630d15fd771461031c5780631703a018146103245780631d25b7881461032c5780632e17de7814610367576101da565b8063013cf08b146101df57806305268cff146102de57806308cbfb5814610302575b600080fd5b6101fc600480360360208110156101f557600080fd5b503561064b565b604051808e81526020018d81526020018c81526020018b81526020018a815260200189815260200188815260200187815260200186151581526020018515158152602001846001600160a01b03168152602001836001600160a01b0316815260200180602001828103825283818151815260200191508051906020019080838360005b8381101561029757818101518382015260200161027f565b50505050905090810190601f1680156102c45780820380516001836020036101000a031916815260200191505b509e50505050505050505050505050505060405180910390f35b6102e6610789565b604080516001600160a01b039092168252519081900360200190f35b61030a6107ad565b60408051918252519081900360200190f35b61030a6107b2565b61030a6107b8565b6103496004803603602081101561034257600080fd5b50356107be565b60408051938452602084019290925282820152519081900360600190f35b6103846004803603602081101561037d57600080fd5b5035610981565b005b6103846004803603602081101561039c57600080fd5b5035610ab9565b61030a611015565b61030a61101b565b61030a600480360360408110156103c957600080fd5b506001600160a01b038135169060200135611021565b610384600480360360208110156103f557600080fd5b503561104e565b61038461105c565b61030a6004803603602081101561041a57600080fd5b50356001600160a01b0316611113565b6103846004803603602081101561044057600080fd5b503561112e565b6103846004803603602081101561045d57600080fd5b50356111b9565b6102e66111c4565b6103846004803603602081101561048257600080fd5b50356111d3565b61030a61125e565b61030a600480360360408110156104a757600080fd5b506001600160a01b038135169060200135611264565b610384600480360360208110156104d357600080fd5b503561128f565b61030a600480360360208110156104f057600080fd5b50356001600160a01b03166113c5565b6103846004803603602081101561051657600080fd5b50356113d7565b6102e66114b0565b6103846004803603604081101561053b57600080fd5b6001600160a01b03823516919081019060408101602082013564010000000081111561056657600080fd5b82018360208201111561057857600080fd5b8035906020019184600183028401116401000000008311171561059a57600080fd5b91908080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152509295506114bf945050505050565b61030a611764565b610384600480360360208110156105f957600080fd5b503561176a565b6103846118ce565b6103846004803603602081101561061e57600080fd5b50356001600160a01b03166118e1565b6103846004803603602081101561064457600080fd5b503561195f565b600860205280600052604060002060009150905080600001549080600301549080600401549080600501549080600601549080600701549080600801549080600901549080600a0160009054906101000a900460ff169080600a0160019054906101000a900460ff169080600a0160029054906101000a90046001600160a01b03169080600b0160009054906101000a90046001600160a01b03169080600c018054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561077f5780601f106107545761010080835404028352916020019161077f565b820191906000526020600020905b81548152906001019060200180831161076257829003601f168201915b505050505090508d565b7f00000000000000000000000048fb253446873234f2febbf9bdeaa72d9d387f9481565b600a81565b60065481565b60055481565b60008060006107cb612cca565b60008581526008602081815260409283902083516101a081018552815481526003820154818401526004820154818601526005820154606082015260068201546080820152600782015460a08201529281015460c0840152600981015460e0840152600a81015460ff8082161515610100808701919091528083049091161515610120860152620100009091046001600160a01b03908116610140860152600b83015416610160850152600c820180548651600260018316159094026000190190911692909204601f810185900485028301850190965285825293949193610180860193919290918301828280156109045780601f106108d957610100808354040283529160200191610904565b820191906000526020600020905b8154815290600101906020018083116108e757829003601f168201915b50505091909252505050602081015160408201519192509060006109288383611e71565b90506109418161093b85620f4240611ed2565b90611f2b565b92506109548161093b84620f4240611ed2565b60a08501519092506000906109709061093b84620f4240611ed2565b939992985092965090945050505050565b80600081116109c8576040805162461bcd60e51b815260206004820152600e60248201526d4552525f5a45524f5f56414c554560901b604482015290519081900360640190fd5b336000908152600960205260409020544211610a18576040805162461bcd60e51b815260206004820152600a60248201526911549497d313d0d2d15160b21b604482015290519081900360640190fd5b610a2b82610a2533611113565b90611f6d565b336000908152600a6020526040902055600654610a489083611f6d565b600655610a7f6001600160a01b037f00000000000000000000000048fb253446873234f2febbf9bdeaa72d9d387f94163384611faf565b60408051838152905133917f0f5bb82176feb1b5e747e28471aa92156a04d9f3ab9f45f28e2d704232b93f75919081900360200190a25050565b80610ac2612cca565b60008281526008602081815260409283902083516101a081018552815481526003820154818401526004820154818601526005820154606082015260068201546080820152600782015460a08201529281015460c0840152600981015460e0840152600a81015460ff8082161515610100808701919091528083049091161515610120860152620100009091046001600160a01b03908116610140860152600b83015416610160850152600c820180548651600260018316159094026000190190911692909204601f81018590048502830185019096528582529394919361018086019391929091830182828015610bfb5780601f10610bd057610100808354040283529160200191610bfb565b820191906000526020600020905b815481529060010190602001808311610bde57829003601f168201915b505050505081525050905060008160600151118015610c1d5750428160600151105b610c5f576040805162461bcd60e51b815260206004820152600e60248201526d11549497d253959053125117d25160921b604482015290519081900360640190fd5b82610c68612cca565b60008281526008602081815260409283902083516101a081018552815481526003820154818401526004820154818601526005820154606082015260068201546080820152600782015460a08201529281015460c0840152600981015460e0840152600a81015460ff8082161515610100808701919091528083049091161515610120860152620100009091046001600160a01b03908116610140860152600b83015416610160850152600c820180548651600260018316159094026000190190911692909204601f81018590048502830185019096528582529394919361018086019391929091830182828015610da15780601f10610d7657610100808354040283529160200191610da1565b820191906000526020600020905b815481529060010190602001808311610d8457829003601f168201915b5050505050815250509050806101000151610df2576040805162461bcd60e51b815260206004820152600c60248201526b22a9292fa727aa2fa7a822a760a11b604482015290519081900360640190fd5b84610dfb612cca565b60008281526008602081815260409283902083516101a081018552815481526003820154818401526004820154818601526005820154606082015260068201546080820152600782015460a08201529281015460c0840152600981015460e0840152600a81015460ff8082161515610100808701919091528083049091161515610120860152620100009091046001600160a01b03908116610140860152600b83015416610160850152600c820180548651600260018316159094026000190190911692909204601f81018590048502830185019096528582529394919361018086019391929091830182828015610f345780601f10610f0957610100808354040283529160200191610f34565b820191906000526020600020905b815481529060010190602001808311610f1757829003601f168201915b50505050508152505090504281608001511115610f88576040805162461bcd60e51b815260206004820152600d60248201526c11549497d393d517d153911151609a1b604482015290519081900360640190fd5b600080610f94896107be565b5060008b815260086020818152604092839020600981015492810154600a909101805460ff19169055835186815291820185905291909110158183018190529151939550919350918b917f66ab4d2a1f6db1c01d1d46ab61a9c333b5a4de5e75cc7a68e1495b4badbd009b919081900360600190a250505050505050505050565b60045481565b60025481565b60008181526008602090815260408083206001600160a01b03861684526001019091529020545b92915050565b611059816000612006565b50565b6001546001600160a01b031633146110af576040805162461bcd60e51b815260206004820152601160248201527011549497d050d0d154d4d7d11153925151607a1b604482015290519081900360640190fd5b600154600080546040516001600160a01b0393841693909116917f343765429aea5a34b3ff6a3785a98a5abb2597aca87bfbb58632c173d585373a91a360018054600080546001600160a01b03199081166001600160a01b03841617909155169055565b6001600160a01b03166000908152600a602052604090205490565b611136612809565b806000811161117d576040805162461bcd60e51b815260206004820152600e60248201526d4552525f5a45524f5f56414c554560901b604482015290519081900360640190fd5b60038290556040805183815290517f3973ac49c733d8f25fcd4f7b2a739ec8269c65a63103d940339f18504c209f2e9181900360200190a15050565b611059816001612006565b6000546001600160a01b031681565b6111db612809565b8060008111611222576040805162461bcd60e51b815260206004820152600e60248201526d4552525f5a45524f5f56414c554560901b604482015290519081900360640190fd5b60028290556040805183815290517f86ccc0c36d25c3ac532328f6073994a81f33c9bb7603f847ac8ad67a3732d9889181900360200190a15050565b60035481565b60009081526008602090815260408083206001600160a01b0394909416835260029093019052205490565b80600081116112d6576040805162461bcd60e51b815260206004820152600e60248201526d4552525f5a45524f5f56414c554560901b604482015290519081900360640190fd5b6112e9826112e333611113565b90611e71565b336000908152600a60205260409020556006546113069083611e71565b60065561133e6001600160a01b037f00000000000000000000000048fb253446873234f2febbf9bdeaa72d9d387f941633308561285c565b3360009081526009602052604090205460035461137891906113739042906112e39061136b90600a611f2b565b6102586128bc565b6128bc565b33600081815260096020908152604091829020939093558051858152905191927f9e71bc8eea02a63969f509818f2dafb9254532904319f9dbda79b67bd34a5f3d92918290030190a25050565b60096020526000908152604090205481565b6113df612809565b8060008111611426576040805162461bcd60e51b815260206004820152600e60248201526d4552525f5a45524f5f56414c554560901b604482015290519081900360640190fd5b620f4240821115611474576040805162461bcd60e51b815260206004820152601360248201527208aa4a4bea2aa9ea4aa9abea89e9ebe90928e9606b1b604482015290519081900360640190fd5b60058290556040805183815290517ff18f88786aae85a652aadb99a82462616489a33370c9bcc7b245906812ef7cd19181900360200190a15050565b6001546001600160a01b031681565b6004546114cb33611113565b11611516576040805162461bcd60e51b81526020600482015260166024820152754552525f494e53554646494349454e545f5354414b4560501b604482015290519081900360640190fd5b600754611524816001611e71565b60075561152f612cca565b604051806101a00160405280838152602001600081526020016000815260200142815260200161156a42600254611e7190919063ffffffff16565b81526020016006548152602001600081526020016005548152602001600115158152602001600015158152602001336001600160a01b03168152602001856001600160a01b031681526020018481525090508060086000848152602001908152602001600020600082015181600001556020820151816003015560408201518160040155606082015181600501556080820151816006015560a0820151816007015560c0820151816008015560e0820151816009015561010082015181600a0160006101000a81548160ff02191690831515021790555061012082015181600a0160016101000a81548160ff02191690831515021790555061014082015181600a0160026101000a8154816001600160a01b0302191690836001600160a01b0316021790555061016082015181600b0160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555061018082015181600c0190805190602001906116db929190612d48565b509050506116ec81608001516128d3565b817faad97149b8b82cd8909c3a8b0ce40f8bbf2a93ce54c8bfcfa82aade36c3a0463826060015160025484610140015185610160015160405180858152602001848152602001836001600160a01b03168152602001826001600160a01b0316815260200194505050505060405180910390a250505050565b60075481565b611772612809565b80600081116117b9576040805162461bcd60e51b815260206004820152600e60248201526d4552525f5a45524f5f56414c554560901b604482015290519081900360640190fd5b7f00000000000000000000000048fb253446873234f2febbf9bdeaa72d9d387f946001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b15801561181257600080fd5b505afa158015611826573d6000803e3d6000fd5b505050506040513d602081101561183c57600080fd5b5051821115611892576040805162461bcd60e51b815260206004820152601860248201527f4552525f455843454544535f544f54414c5f535550504c590000000000000000604482015290519081900360640190fd5b60048290556040805183815290517f0c6d5c7d0eb0bad98309d100619d1c205d94b426d761ee9c1d2c29786a0f727e9181900360200190a15050565b6118df6118da33611113565b610981565b565b6118e9612809565b6000546001600160a01b038281169116141561193d576040805162461bcd60e51b815260206004820152600e60248201526d22a9292fa9a0a6a2afa7aba722a960911b604482015290519081900360640190fd5b600180546001600160a01b0319166001600160a01b0392909216919091179055565b80611968612cca565b60008281526008602081815260409283902083516101a081018552815481526003820154818401526004820154818601526005820154606082015260068201546080820152600782015460a08201529281015460c0840152600981015460e0840152600a81015460ff8082161515610100808701919091528083049091161515610120860152620100009091046001600160a01b03908116610140860152600b83015416610160850152600c820180548651600260018316159094026000190190911692909204601f81018590048502830185019096528582529394919361018086019391929091830182828015611aa15780601f10611a7657610100808354040283529160200191611aa1565b820191906000526020600020905b815481529060010190602001808311611a8457829003601f168201915b505050505081525050905060008160600151118015611ac35750428160600151105b611b05576040805162461bcd60e51b815260206004820152600e60248201526d11549497d253959053125117d25160921b604482015290519081900360640190fd5b82611b0e612cca565b60008281526008602081815260409283902083516101a081018552815481526003820154818401526004820154818601526005820154606082015260068201546080820152600782015460a08201529281015460c0840152600981015460e0840152600a81015460ff8082161515610100808701919091528083049091161515610120860152620100009091046001600160a01b03908116610140860152600b83015416610160850152600c820180548651600260018316159094026000190190911692909204601f81018590048502830185019096528582529394919361018086019391929091830182828015611c475780601f10611c1c57610100808354040283529160200191611c47565b820191906000526020600020905b815481529060010190602001808311611c2a57829003601f168201915b50505050508152505090504281608001511115611c9b576040805162461bcd60e51b815260206004820152600d60248201526c11549497d393d517d153911151609a1b604482015290519081900360640190fd5b6000858152600860205260409020600a0154610100900460ff1615611cfe576040805162461bcd60e51b815260206004820152601460248201527311549497d053149150511657d1561150d555115160621b604482015290519081900360640190fd5b6000806000611d0c886107be565b60008b8152600860205260409020600901549295509093509150811015611d6a576040805162461bcd60e51b815260206004820152600d60248201526c4552525f4e4f5f51554f52554d60981b604482015290519081900360640190fd5b6000888152600860205260409020600a015460ff1615611d8d57611d8d88610ab9565b600088815260086020526040808220600a8101805461ff001916610100179055600b01548151636009bfbd60e11b8152600481018c905260248101879052604481018690526064810185905291516001600160a01b039091169263c0137f7a926084808201939182900301818387803b158015611e0957600080fd5b505af1158015611e1d573d6000803e3d6000fd5b505050600089815260086020526040808220600b015490516001600160a01b0390911692508a917f9c85b616f29fca57a17eafe71cf9ff82ffef41766e2cf01ea7f8f7878dd3ec2491a35050505050505050565b600082820183811015611ecb576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b9392505050565b600082611ee157506000611048565b82820282848281611eee57fe5b0414611ecb5760405162461bcd60e51b8152600401808060200182810382526021815260200180612ddc6021913960400191505060405180910390fd5b6000611ecb83836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f00000000000081525061295e565b6000611ecb83836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250612a00565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b179052612001908490612a5a565b505050565b336000908152600a6020526040902054612058576040805162461bcd60e51b815260206004820152600e60248201526d22a9292fa727aa2fa9aa20a5a2a960911b604482015290519081900360640190fd5b81612061612cca565b60008281526008602081815260409283902083516101a081018552815481526003820154818401526004820154818601526005820154606082015260068201546080820152600782015460a08201529281015460c0840152600981015460e0840152600a81015460ff8082161515610100808701919091528083049091161515610120860152620100009091046001600160a01b03908116610140860152600b83015416610160850152600c820180548651600260018316159094026000190190911692909204601f8101859004850283018501909652858252939491936101808601939192909183018282801561219a5780601f1061216f5761010080835404028352916020019161219a565b820191906000526020600020905b81548152906001019060200180831161217d57829003601f168201915b5050505050815250509050600081606001511180156121bc5750428160600151105b6121fe576040805162461bcd60e51b815260206004820152600e60248201526d11549497d253959053125117d25160921b604482015290519081900360640190fd5b83612207612cca565b60008281526008602081815260409283902083516101a081018552815481526003820154818401526004820154818601526005820154606082015260068201546080820152600782015460a08201529281015460c0840152600981015460e0840152600a81015460ff8082161515610100808701919091528083049091161515610120860152620100009091046001600160a01b03908116610140860152600b83015416610160850152600c820180548651600260018316159094026000190190911692909204601f810185900485028301850190965285825293949193610180860193919290918301828280156123405780601f1061231557610100808354040283529160200191612340565b820191906000526020600020905b81548152906001019060200180831161232357829003601f168201915b5050505050815250509050806101000151612391576040805162461bcd60e51b815260206004820152600c60248201526b22a9292fa727aa2fa7a822a760a11b604482015290519081900360640190fd5b8561239a612cca565b60008281526008602081815260409283902083516101a081018552815481526003820154818401526004820154818601526005820154606082015260068201546080820152600782015460a08201529281015460c0840152600981015460e0840152600a81015460ff8082161515610100808701919091528083049091161515610120860152620100009091046001600160a01b03908116610140860152600b83015416610160850152600c820180548651600260018316159094026000190190911692909204601f810185900485028301850190965285825293949193610180860193919290918301828280156124d35780601f106124a8576101008083540402835291602001916124d3565b820191906000526020600020905b8154815290600101906020018083116124b657829003601f168201915b50505050508152505090504281608001511015612523576040805162461bcd60e51b815260206004820152600960248201526811549497d15391115160ba1b604482015290519081900360640190fd5b6000888152600860205260409020871561257c57336000908152600282016020526040902054801561257657600482015461255e9082611f6d565b60048301553360009081526002830160205260408120555b506125bd565b33600090815260018201602052604090205480156125bb5760038201546125a39082611f6d565b60038301553360009081526001830160205260408120555b505b60006125fa896125de573360009081526002840160205260409020546125f1565b3360009081526001840160205260409020545b610a2533611113565b905088156126365760038201546126119082611e71565b600383015561261f33611113565b336000908152600184016020526040902055612666565b60048201546126459082611e71565b600483015561265333611113565b3360009081526002840160205260409020555b6006805460078401819055604080516101a0810182528554815260038601546020808301919091526004870154828401526005870154606083015293860154608082015260a0810192909252600885015460c0830152600985015460e0830152600a85015460ff8082161515610100808601919091528083049091161515610120850152620100009091046001600160a01b03908116610140850152600b87015416610160840152600c860180548351600260018316159094026000190190911692909204601f81018690048602830186019093528282526127ab948793610180860193929183018282801561279d5780601f106127725761010080835404028352916020019161279d565b820191906000526020600020905b81548152906001019060200180831161278057829003601f168201915b505050505081525050612b0b565b600883015560068201546127be906128d3565b8154604080518b151581526020810184905281513393927f88d35328232823f54954b6627e9f732371656f6daa40cb1b01b27dc7875a7b47928290030190a350505050505050505050565b6000546001600160a01b031633146118df576040805162461bcd60e51b815260206004820152601160248201527011549497d050d0d154d4d7d11153925151607a1b604482015290519081900360640190fd5b604080516001600160a01b0380861660248301528416604482015260648082018490528251808303909101815260849091019091526020810180516001600160e01b03166323b872dd60e01b1790526128b6908590612a5a565b50505050565b6000818310156128cc5781611ecb565b5090919050565b336000908152600a6020526040902054612925576040805162461bcd60e51b815260206004820152600e60248201526d22a9292fa727aa2fa9aa20a5a2a960911b604482015290519081900360640190fd5b3360009081526009602052604090205460035461294b9190611373908490829042611e71565b3360009081526009602052604090205550565b600081836129ea5760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b838110156129af578181015183820152602001612997565b50505050905090810190601f1680156129dc5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b5060008385816129f657fe5b0495945050505050565b60008184841115612a525760405162461bcd60e51b81526020600482018181528351602484015283519092839260449091019190850190808383600083156129af578181015183820152602001612997565b505050900390565b6060612aaf826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316612b409092919063ffffffff16565b80519091501561200157808060200190516020811015612ace57600080fd5b50516120015760405162461bcd60e51b815260040180806020018281038252602a815260200180612dfd602a913960400191505060405180910390fd5b600080612b2983604001518460200151611e7190919063ffffffff16565b600654909150611ecb9061093b83620f4240611ed2565b6060612b4f8484600085612b57565b949350505050565b6060612b6285612cc4565b612bb3576040805162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015290519081900360640190fd5b60006060866001600160a01b031685876040518082805190602001908083835b60208310612bf25780518252601f199092019160209182019101612bd3565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d8060008114612c54576040519150601f19603f3d011682016040523d82523d6000602084013e612c59565b606091505b50915091508115612c6d579150612b4f9050565b805115612c7d5780518082602001fd5b60405162461bcd60e51b81526020600482018181528651602484015286518793919283926044019190850190808383600083156129af578181015183820152602001612997565b3b151590565b604051806101a00160405280600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081526020016000815260200160001515815260200160001515815260200160006001600160a01b0316815260200160006001600160a01b03168152602001606081525090565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f10612d8957805160ff1916838001178555612db6565b82800160010185558215612db6579182015b82811115612db6578251825591602001919060010190612d9b565b50612dc2929150612dc6565b5090565b5b80821115612dc25760008155600101612dc756fe536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f775361666545524332303a204552433230206f7065726174696f6e20646964206e6f742073756363656564a264697066735822122075f961ff707cb3123a4b94d224153dab27b564ecfa897baf19732413366b0bf264736f6c634300060c0033
Verified Source Code Partial Match
Compiler: v0.6.12+commit.27d51765
EVM: istanbul
Optimization: Yes (200 runs)
BancorGovernance.sol 1221 lines
// File: @bancor/contracts-solidity/solidity/contracts/utility/interfaces/IOwned.sol
// SPDX-License-Identifier: SEE LICENSE IN LICENSE
pragma solidity 0.6.12;
/*
Owned contract interface
*/
interface IOwned {
// this function isn't since the compiler emits automatically generated getter functions as external
function owner() external view returns (address);
function transferOwnership(address _newOwner) external;
function acceptOwnership() external;
}
// File: @bancor/contracts-solidity/solidity/contracts/utility/Owned.sol
pragma solidity 0.6.12;
/**
* @dev Provides support and utilities for contract ownership
*/
contract Owned is IOwned {
address public override owner;
address public newOwner;
/**
* @dev triggered when the owner is updated
*
* @param _prevOwner previous owner
* @param _newOwner new owner
*/
event OwnerUpdate(address indexed _prevOwner, address indexed _newOwner);
/**
* @dev initializes a new Owned instance
*/
constructor() public {
owner = msg.sender;
}
// allows execution by the owner only
modifier ownerOnly {
_ownerOnly();
_;
}
// error message binary size optimization
function _ownerOnly() internal view {
require(msg.sender == owner, "ERR_ACCESS_DENIED");
}
/**
* @dev allows transferring the contract ownership
* the new owner still needs to accept the transfer
* can only be called by the contract owner
*
* @param _newOwner new contract owner
*/
function transferOwnership(address _newOwner) public override ownerOnly {
require(_newOwner != owner, "ERR_SAME_OWNER");
newOwner = _newOwner;
}
/**
* @dev used by a new owner to accept an ownership transfer
*/
function acceptOwnership() override public {
require(msg.sender == newOwner, "ERR_ACCESS_DENIED");
emit OwnerUpdate(owner, newOwner);
owner = newOwner;
newOwner = address(0);
}
}
// File: @openzeppelin/contracts/math/Math.sol
pragma solidity ^0.6.0;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a >= b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow, so we distribute
return (a / 2) + (b / 2) + ((a % 2 + b % 2) / 2);
}
}
// File: @openzeppelin/contracts/math/SafeMath.sol
pragma solidity ^0.6.0;
/**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/
library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
}
// File: @openzeppelin/contracts/token/ERC20/IERC20.sol
pragma solidity ^0.6.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
// File: @openzeppelin/contracts/utils/Address.sol
pragma solidity ^0.6.2;
/**
* @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
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies in extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
// solhint-disable-next-line no-inline-assembly
assembly { size := extcodesize(account) }
return size > 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");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
// File: @openzeppelin/contracts/token/ERC20/SafeERC20.sol
pragma solidity ^0.6.0;
/**
* @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 SafeMath for uint256;
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'
// solhint-disable-next-line max-line-length
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).add(value);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero");
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
/**
* @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
// solhint-disable-next-line max-line-length
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
// File: contracts/interfaces/IExecutor.sol
pragma solidity 0.6.12;
interface IExecutor {
function execute(
uint256 _id,
uint256 _for,
uint256 _against,
uint256 _quorum
) external;
}
// File: contracts/BancorGovernance.sol
/*
____ __ __ __ _
/ __/__ __ ___ / /_ / / ___ / /_ (_)__ __
_\ \ / // // _ \/ __// _ \/ -_)/ __// / \ \ /
/___/ \_, //_//_/\__//_//_/\__/ \__//_/ /_\_\
/___/
* Synthetix: YFIRewards.sol
*
* Docs: https://docs.synthetix.io/
*
*
* MIT License
* ===========
*
* Copyright (c) 2020 Synthetix
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
*/
pragma solidity 0.6.12;
/**
* @title The Bancor Governance Contract
*
* Big thanks to synthetix / yearn.finance for the initial version!
*/
contract BancorGovernance is Owned {
using SafeMath for uint256;
using SafeERC20 for IERC20;
uint32 internal constant PPM_RESOLUTION = 1000000;
struct Proposal {
uint256 id;
mapping(address => uint256) votesFor;
mapping(address => uint256) votesAgainst;
uint256 totalVotesFor;
uint256 totalVotesAgainst;
uint256 start; // start timestmp;
uint256 end; // start + voteDuration
uint256 totalAvailableVotes;
uint256 quorum;
uint256 quorumRequired;
bool open;
bool executed;
address proposer;
address executor;
string hash;
}
/**
* @notice triggered when a new proposal is created
*
* @param _id proposal id
* @param _start voting start timestamp
* @param _duration voting duration
* @param _proposer proposal creator
* @param _executor contract that will exeecute the proposal once it passes
*/
event NewProposal(
uint256 indexed _id,
uint256 _start,
uint256 _duration,
address _proposer,
address _executor
);
/**
* @notice triggered when voting on a proposal has ended
*
* @param _id proposal id
* @param _for number of votes for the proposal
* @param _against number of votes against the proposal
* @param _quorumReached true if quorum was reached, false otherwise
*/
event ProposalFinished(
uint256 indexed _id,
uint256 _for,
uint256 _against,
bool _quorumReached
);
/**
* @notice triggered when a proposal was successfully executed
*
* @param _id proposal id
* @param _executor contract that will execute the proposal once it passes
*/
event ProposalExecuted(uint256 indexed _id, address indexed _executor);
/**
* @notice triggered when a stake has been added to the contract
*
* @param _user staker address
* @param _amount staked amount
*/
event Staked(address indexed _user, uint256 _amount);
/**
* @notice triggered when a stake has been removed from the contract
*
* @param _user staker address
* @param _amount unstaked amount
*/
event Unstaked(address indexed _user, uint256 _amount);
/**
* @notice triggered when a user votes on a proposal
*
* @param _id proposal id
* @param _voter voter addrerss
* @param _vote true if the vote is for the proposal, false otherwise
* @param _weight number of votes
*/
event Vote(uint256 indexed _id, address indexed _voter, bool _vote, uint256 _weight);
/**
* @notice triggered when the quorum is updated
*
* @param _quorum new quorum
*/
event QuorumUpdated(uint256 _quorum);
/**
* @notice triggered when the minimum stake required to create a new proposal is updated
*
* @param _minimum new minimum
*/
event NewProposalMinimumUpdated(uint256 _minimum);
/**
* @notice triggered when the vote duration is updated
*
* @param _voteDuration new vote duration
*/
event VoteDurationUpdated(uint256 _voteDuration);
/**
* @notice triggered when the vote lock duration is updated
*
* @param _duration new vote lock duration
*/
event VoteLockDurationUpdated(uint256 _duration);
// PROPOSALS
// voting duration in seconds
uint256 public voteDuration = 3 days;
// vote lock in seconds
uint256 public voteLockDuration = 3 days;
// the fraction of vote lock used to lock voter to avoid rapid unstaking
uint256 public constant voteLockFraction = 10;
// minimum stake required to propose
uint256 public newProposalMinimum = 1e18;
// quorum needed for a proposal to pass, default = 20%
uint256 public quorum = 200000;
// sum of current total votes
uint256 public totalVotes;
// number of proposals
uint256 public proposalCount;
// proposals by id
mapping(uint256 => Proposal) public proposals;
// VOTES
// governance token used for votes
IERC20 public immutable govToken;
// lock duration for each voter stake by voter address
mapping(address => uint256) public voteLocks;
// number of votes for each user
mapping(address => uint256) private votes;
/**
* @notice used to initialize a new BancorGovernance contract
*
* @param _govToken token used to represents votes
*/
constructor(IERC20 _govToken) public {
require(address(_govToken) != address(0), "ERR_NO_TOKEN");
govToken = _govToken;
}
/**
* @notice allows execution by staker only
*/
modifier onlyStaker() {
require(votes[msg.sender] > 0, "ERR_NOT_STAKER");
_;
}
/**
* @notice allows execution only when the proposal exists
*
* @param _id proposal id
*/
modifier proposalExists(uint256 _id) {
Proposal memory proposal = proposals[_id];
require(proposal.start > 0 && proposal.start < block.timestamp, "ERR_INVALID_ID");
_;
}
/**
* @notice allows execution only when the proposal is still open
*
* @param _id proposal id
*/
modifier proposalOpen(uint256 _id) {
Proposal memory proposal = proposals[_id];
require(proposal.open, "ERR_NOT_OPEN");
_;
}
/**
* @notice allows execution only when the proposal with given id is open
*
* @param _id proposal id
*/
modifier proposalNotEnded(uint256 _id) {
Proposal memory proposal = proposals[_id];
require(proposal.end >= block.timestamp, "ERR_ENDED");
_;
}
/**
* @notice allows execution only when the proposal with given id has ended
*
* @param _id proposal id
*/
modifier proposalEnded(uint256 _id) {
Proposal memory proposal = proposals[_id];
require(proposal.end <= block.timestamp, "ERR_NOT_ENDED");
_;
}
/**
* @notice verifies that a value is greater than zero
*
* @param _value value to check for zero
*/
modifier greaterThanZero(uint256 _value) {
require(_value > 0, "ERR_ZERO_VALUE");
_;
}
/**
* @notice Updates the vote lock on the sender
*
* @param _proposalEnd proposal end time
*/
function updateVoteLock(uint256 _proposalEnd) private onlyStaker {
voteLocks[msg.sender] = Math.max(
voteLocks[msg.sender],
Math.max(_proposalEnd, voteLockDuration.add(block.timestamp))
);
}
/**
* @notice does the common vote finalization
*
* @param _id the id of the proposal to vote
* @param _for is this vote for or against the proposal
*/
function vote(uint256 _id, bool _for)
private
onlyStaker
proposalExists(_id)
proposalOpen(_id)
proposalNotEnded(_id)
{
Proposal storage proposal = proposals[_id];
if (_for) {
uint256 votesAgainst = proposal.votesAgainst[msg.sender];
// do we have against votes for this sender?
if (votesAgainst > 0) {
// yes, remove the against votes first
proposal.totalVotesAgainst = proposal.totalVotesAgainst.sub(votesAgainst);
proposal.votesAgainst[msg.sender] = 0;
}
} else {
// get against votes for this sender
uint256 votesFor = proposal.votesFor[msg.sender];
// do we have for votes for this sender?
if (votesFor > 0) {
proposal.totalVotesFor = proposal.totalVotesFor.sub(votesFor);
proposal.votesFor[msg.sender] = 0;
}
}
// calculate voting power in case voting against twice
uint256 voteAmount = votesOf(msg.sender).sub(
_for ? proposal.votesFor[msg.sender] : proposal.votesAgainst[msg.sender]
);
if (_for) {
// increase total for votes of the proposal
proposal.totalVotesFor = proposal.totalVotesFor.add(voteAmount);
// set for votes to the votes of the sender
proposal.votesFor[msg.sender] = votesOf(msg.sender);
} else {
// increase total against votes of the proposal
proposal.totalVotesAgainst = proposal.totalVotesAgainst.add(voteAmount);
// set against votes to the votes of the sender
proposal.votesAgainst[msg.sender] = votesOf(msg.sender);
}
// update total votes available on the proposal
proposal.totalAvailableVotes = totalVotes;
// recalculate quorum based on overall votes
proposal.quorum = calculateQuorumRatio(proposal);
// update vote lock
updateVoteLock(proposal.end);
// emit vote event
emit Vote(proposal.id, msg.sender, _for, voteAmount);
}
/**
* @notice returns the quorum ratio of a proposal
*
* @param _proposal proposal
* @return quorum ratio
*/
function calculateQuorumRatio(Proposal memory _proposal) internal view returns (uint256) {
// calculate overall votes
uint256 totalProposalVotes = _proposal.totalVotesFor.add(_proposal.totalVotesAgainst);
return totalProposalVotes.mul(PPM_RESOLUTION).div(totalVotes);
}
/**
* @notice removes the caller's entire stake
*/
function exit() external {
unstake(votesOf(msg.sender));
}
/**
* @notice returns the voting stats of a proposal
*
* @param _id proposal id
* @return votes for ratio
* @return votes against ratio
* @return quorum ratio
*/
function proposalStats(uint256 _id)
public
view
returns (
uint256,
uint256,
uint256
)
{
Proposal memory proposal = proposals[_id];
uint256 forRatio = proposal.totalVotesFor;
uint256 againstRatio = proposal.totalVotesAgainst;
// calculate overall total votes
uint256 totalProposalVotes = forRatio.add(againstRatio);
// calculate for votes ratio
forRatio = forRatio.mul(PPM_RESOLUTION).div(totalProposalVotes);
// calculate against votes ratio
againstRatio = againstRatio.mul(PPM_RESOLUTION).div(totalProposalVotes);
// calculate quorum ratio
uint256 quorumRatio = totalProposalVotes.mul(PPM_RESOLUTION).div(
proposal.totalAvailableVotes
);
return (forRatio, againstRatio, quorumRatio);
}
/**
* @notice returns the voting power of a given address
*
* @param _voter voter address
* @return votes of given address
*/
function votesOf(address _voter) public view returns (uint256) {
return votes[_voter];
}
/**
* @notice returns the voting power of a given address against a given proposal
*
* @param _voter voter address
* @param _id proposal id
* @return votes of given address against given proposal
*/
function votesAgainstOf(address _voter, uint256 _id) public view returns (uint256) {
return proposals[_id].votesAgainst[_voter];
}
/**
* @notice returns the voting power of a given address for a given proposal
*
* @param _voter voter address
* @param _id proposal id
* @return votes of given address for given proposal
*/
function votesForOf(address _voter, uint256 _id) public view returns (uint256) {
return proposals[_id].votesFor[_voter];
}
/**
* @notice updates the quorum needed for proposals to pass
*
* @param _quorum required quorum
*/
function setQuorum(uint256 _quorum) public ownerOnly greaterThanZero(_quorum) {
// check quorum for not being above 100
require(_quorum <= PPM_RESOLUTION, "ERR_QUORUM_TOO_HIGH");
quorum = _quorum;
emit QuorumUpdated(_quorum);
}
/**
* @notice updates the minimum stake required to create a new proposal
*
* @param _minimum minimum stake
*/
function setNewProposalMinimum(uint256 _minimum) public ownerOnly greaterThanZero(_minimum) {
require(_minimum <= govToken.totalSupply(), "ERR_EXCEEDS_TOTAL_SUPPLY");
newProposalMinimum = _minimum;
emit NewProposalMinimumUpdated(_minimum);
}
/**
* @notice updates the proposals voting duration
*
* @param _voteDuration vote duration
*/
function setVoteDuration(uint256 _voteDuration)
public
ownerOnly
greaterThanZero(_voteDuration)
{
voteDuration = _voteDuration;
emit VoteDurationUpdated(_voteDuration);
}
/**
* @notice updates the post vote lock duration
*
* @param _duration new vote lock duration
*/
function setVoteLockDuration(uint256 _duration) public ownerOnly greaterThanZero(_duration) {
voteLockDuration = _duration;
emit VoteLockDurationUpdated(_duration);
}
/**
* @notice creates a new proposal
*
* @param _executor the address of the contract that will execute the proposal after it passes
* @param _hash ipfs hash of the proposal description
*/
function propose(address _executor, string memory _hash) public {
require(votesOf(msg.sender) > newProposalMinimum, "ERR_INSUFFICIENT_STAKE");
uint256 id = proposalCount;
// increment proposal count so next proposal gets the next higher id
proposalCount = proposalCount.add(1);
// create new proposal
Proposal memory proposal = Proposal({
id: id,
proposer: msg.sender,
totalVotesFor: 0,
totalVotesAgainst: 0,
start: block.timestamp,
end: voteDuration.add(block.timestamp),
executor: _executor,
hash: _hash,
totalAvailableVotes: totalVotes,
quorum: 0,
quorumRequired: quorum,
open: true,
executed: false
});
proposals[id] = proposal;
// lock proposer
updateVoteLock(proposal.end);
// emit proposal event
emit NewProposal(id, proposal.start, voteDuration, proposal.proposer, proposal.executor);
}
/**
* @notice executes a proposal
*
* @param _id id of the proposal to execute
*/
function execute(uint256 _id) public proposalExists(_id) proposalEnded(_id) {
// check for executed status
require(!proposals[_id].executed, "ERR_ALREADY_EXECUTED");
// get voting info of proposal
(uint256 forRatio, uint256 againstRatio, uint256 quorumRatio) = proposalStats(_id);
// check proposal state
require(quorumRatio >= proposals[_id].quorumRequired, "ERR_NO_QUORUM");
// if the proposal is still open
if (proposals[_id].open) {
// tally votes
tallyVotes(_id);
}
// set executed
proposals[_id].executed = true;
// do execution on the contract to be executed
// note that this is a safe call as it was part of the proposal that was voted on
IExecutor(proposals[_id].executor).execute(_id, forRatio, againstRatio, quorumRatio);
// emit proposal executed event
emit ProposalExecuted(_id, proposals[_id].executor);
}
/**
* @notice tallies votes of proposal with given id
*
* @param _id id of the proposal to tally votes for
*/
function tallyVotes(uint256 _id)
public
proposalExists(_id)
proposalOpen(_id)
proposalEnded(_id)
{
// get voting info of proposal
(uint256 forRatio, uint256 againstRatio, ) = proposalStats(_id);
// do we have a quorum?
bool quorumReached = proposals[_id].quorum >= proposals[_id].quorumRequired;
// close proposal
proposals[_id].open = false;
// emit proposal finished event
emit ProposalFinished(_id, forRatio, againstRatio, quorumReached);
}
/**
* @notice stakes vote tokens
*
* @param _amount amount of vote tokens to stake
*/
function stake(uint256 _amount) public greaterThanZero(_amount) {
// increase vote power
votes[msg.sender] = votesOf(msg.sender).add(_amount);
// increase total votes
totalVotes = totalVotes.add(_amount);
// transfer tokens to this contract
govToken.safeTransferFrom(msg.sender, address(this), _amount);
// lock staker to avoid flashloans messing around with total votes
voteLocks[msg.sender] = Math.max(
voteLocks[msg.sender],
Math.max(voteLockDuration.div(voteLockFraction), 10 minutes).add(block.timestamp)
);
// emit staked event
emit Staked(msg.sender, _amount);
}
/**
* @notice unstakes vote tokens
*
* @param _amount amount of vote tokens to unstake
*/
function unstake(uint256 _amount) public greaterThanZero(_amount) {
require(voteLocks[msg.sender] < block.timestamp, "ERR_LOCKED");
// reduce votes for user
votes[msg.sender] = votesOf(msg.sender).sub(_amount);
// reduce total votes
totalVotes = totalVotes.sub(_amount);
// transfer tokens back
govToken.safeTransfer(msg.sender, _amount);
// emit unstaked event
emit Unstaked(msg.sender, _amount);
}
/**
* @notice votes for a proposal
*
* @param _id id of the proposal to vote for
*/
function voteFor(uint256 _id) public {
vote(_id, true);
}
/**
* @notice votes against a proposal
*
* @param _id id of the proposal to vote against
*/
function voteAgainst(uint256 _id) public {
vote(_id, false);
}
}
Read Contract
govToken 0x05268cff → address
newOwner 0xd4ee1d90 → address
newProposalMinimum 0x536af3cf → uint256
owner 0x8da5cb5b → address
proposalCount 0xda35c664 → uint256
proposalStats 0x1d25b788 → uint256, uint256, uint256
proposals 0x013cf08b → uint256, uint256, uint256, uint256, uint256, uint256, uint256, uint256, bool, bool, address, address, string
quorum 0x1703a018 → uint256
totalVotes 0x0d15fd77 → uint256
voteDuration 0x56364499 → uint256
voteLockDuration 0xa1bf8824 → uint256
voteLockFraction 0x08cbfb58 → uint256
voteLocks 0xab4f440f → uint256
votesAgainstOf 0xa1e9204e → uint256
votesForOf 0x73f4596a → uint256
votesOf 0x79ec5d3a → uint256
Write Contract 14 functions
These functions modify contract state and require a wallet transaction to execute.
acceptOwnership 0x79ba5097
No parameters
execute 0xfe0d94c1
uint256 _id
exit 0xe9fad8ee
No parameters
propose 0xd6f0948c
address _executor
string _hash
setNewProposalMinimum 0xe9810143
uint256 _minimum
setQuorum 0xc1ba4e59
uint256 _quorum
setVoteDuration 0x9449a655
uint256 _voteDuration
setVoteLockDuration 0x82d5f153
uint256 _duration
stake 0xa694fc3a
uint256 _amount
tallyVotes 0x4d318b0e
uint256 _id
transferOwnership 0xf2fde38b
address _newOwner
unstake 0x2e17de78
uint256 _amount
voteAgainst 0x750e443a
uint256 _id
voteFor 0x86a50535
uint256 _id
Recent Transactions
No transactions found for this address