Address Contract Partially Verified
Address
0x897c27Fa372AA730D4C75B1243E7EA38879194E2
Balance
0 ETH
Nonce
1
Code Size
9388 bytes
Creator
0x70aD4814...53dd at tx 0xbb5d8b4d...909b91
Indexed Transactions
0
Contract Bytecode
9388 bytes
0x60806040526004361061010d5760003560e01c806383b435db11610095578063df97174b11610064578063df97174b146102b9578063e2d7c048146102d9578063e3cb9f62146102ec578063e5a2b5d21461030c578063f2b533071461032157610128565b806383b435db1461024f578063b56561fe1461026f578063bdda81d414610284578063c9d194d51461029957610128565b8063452a9320116100dc578063452a9320146101c35780634f0e0ef3146101e557806373b20547146101fa5780637dfb6f861461020f5780637ecccecc1461022f57610128565b8063011b21741461012d5780630c246c82146101635780631762d25a146101835780632fcb4f04146101a357610128565b36610128576008546001600160a01b0316331461012657fe5b005b600080fd5b34801561013957600080fd5b5061014d610148366004611676565b610336565b60405161015a9190611cb4565b60405180910390f35b34801561016f57600080fd5b5061012661017e3660046119e7565b610351565b34801561018f57600080fd5b5061012661019e3660046116d5565b610668565b3480156101af57600080fd5b506101266101be366004611676565b610755565b3480156101cf57600080fd5b506101d86107a1565b60405161015a9190611c63565b3480156101f157600080fd5b506101d86107b0565b34801561020657600080fd5b5061014d6107bf565b34801561021b57600080fd5b5061014d61022a366004611aff565b6107c5565b34801561023b57600080fd5b5061012661024a366004611692565b6107d7565b34801561025b57600080fd5b5061012661026a36600461184a565b61087e565b34801561027b57600080fd5b5061014d610ba8565b34801561029057600080fd5b5061014d610bae565b3480156102a557600080fd5b5061014d6102b4366004611aff565b610bb4565b3480156102c557600080fd5b5061014d6102d4366004611676565b610bc6565b6101266102e7366004611b17565b610bd8565b3480156102f857600080fd5b50610126610307366004611724565b610cd2565b34801561031857600080fd5b5061014d610e3c565b34801561032d57600080fd5b5061014d610e42565b6001600160a01b031660009081526002602052604090205490565b6002600054141561037d5760405162461bcd60e51b81526004016103749061238b565b60405180910390fd5b600260005560c081015143106103a55760405162461bcd60e51b815260040161037490612070565b61010081015160e0820151600090815260036020526040902054106103dc5760405162461bcd60e51b815260040161037490611fdc565b855187511480156103ee575083518751145b80156103fb575082518751145b8015610408575081518751145b6104245760405162461bcd60e51b815260040161037490612354565b600154610435888888600654610e48565b146104525760405162461bcd60e51b815260040161037490611ef2565b602081015151815151146104785760405162461bcd60e51b815260040161037490612133565b806060015151816040015151146104a15760405162461bcd60e51b815260040161037490611ec2565b6000600654681b1bd9da58d0d85b1b60ba1b836000015184602001518560400151866060015187608001518860a001518960c001518a60e001518b61010001516040516020016104fb9b9a99989796959493929190611d00565b604051602081830303815290604052805190602001209050610524888887878786600754610e9a565b61010082015160e08301516000908152600360205260408120919091555b8251518110156105a45761059c83608001518460000151838151811061056457fe5b60200260200101518560200151848151811061057c57fe5b60200260200101516001600160a01b0316610f919092919063ffffffff16565b600101610542565b5060606105b983608001518460a00151610fe7565b905060005b8360400151518110156105ff576105f733856040015183815181106105df57fe5b60200260200101518660600151848151811061057c57fe5b6001016105be565b5060055461060e906001611032565b600581905560e08401516101008501516040517ff91c95577d70e79c860c20704cbae1beca2045c2e55e466e8a5223f1c0866c93936106509392918690611e47565b60405180910390a15050600160005550505050505050565b6009546001600160a01b031633146106925760405162461bcd60e51b8152600401610374906121ab565b60005b82518110156107505760008382815181106106ac57fe5b6020026020010151905061074783826001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016106e69190611c63565b60206040518083038186803b1580156106fe57600080fd5b505afa158015610712573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107369190611b42565b6001600160a01b0384169190610f91565b50600101610695565b505050565b6009546001600160a01b0316331461077f5760405162461bcd60e51b8152600401610374906121ab565b600980546001600160a01b0319166001600160a01b0392909216919091179055565b6009546001600160a01b031681565b6008546001600160a01b031681565b60055481565b60036020526000908152604090205481565b600260005414156107fa5760405162461bcd60e51b81526004016103749061238b565b60026000556108146001600160a01b038616333085611057565b600554610822906001611032565b6005819055604051859133916001600160a01b038916917f7f4f5725b195c7be189dc38c65df0483114975b57463ac93012ba3ede3b56a959161086a91899189918991611e76565b60405180910390a450506001600055505050565b600260005414156108a15760405162461bcd60e51b81526004016103749061238b565b600260008181556001600160a01b0384168152602091909152604090205483116108dd5760405162461bcd60e51b815260040161037490611f4f565b8043106108fc5760405162461bcd60e51b8152600401610374906120d6565b8a518c5114801561090e575088518c51145b801561091b575087518c51145b8015610928575086518c51145b6109445760405162461bcd60e51b815260040161037490612354565b6001546109558d8d8d600654610e48565b146109725760405162461bcd60e51b815260040161037490611ef2565b84518651148015610984575083518651145b6109a05760405162461bcd60e51b815260040161037490611fa5565b6109fa8c8c8b8b8b6006546f0e8e4c2dce6c2c6e8d2dedc84c2e8c6d60831b8d8d8d8d8d8d6040516020016109dc989796959493929190611da6565b60405160208183030381529060405280519060200120600754610e9a565b6001600160a01b0380831660008181526002602052604090208590556008549091161415610ae55760005b8651811015610adf5760085487516001600160a01b0390911690632e1a7d4d90899084908110610a5157fe5b60200260200101516040518263ffffffff1660e01b8152600401610a759190611cb4565b600060405180830381600087803b158015610a8f57600080fd5b505af1158015610aa3573d6000803e3d6000fd5b50505050610ad7868281518110610ab657fe5b6020026020010151888381518110610aca57fe5b602002602001015161107e565b600101610a25565b50610b3f565b60005b8651811015610b3d57610b35868281518110610b0057fe5b6020026020010151888381518110610b1457fe5b6020026020010151856001600160a01b0316610f919092919063ffffffff16565b600101610ae8565b505b600554610b4d906001611032565b60058190556040516001600160a01b0384169185917f02c7e81975f8edb86e2a0c038b7b86a49c744236abf0f6177ff5afc6986ab70891610b8d91611cb4565b60405180910390a35050600160005550505050505050505050565b60045481565b60065481565b60009081526003602052604090205490565b60026020526000908152604090205481565b60026000541415610bfb5760405162461bcd60e51b81526004016103749061238b565b6002600090815560085460408051630d0e30db60e41b815290516001600160a01b039092169263d0e30db0923492600480820193929182900301818588803b158015610c4657600080fd5b505af1158015610c5a573d6000803e3d6000fd5b5050505050610c75600160055461103290919063ffffffff16565b6005819055600854604051859233926001600160a01b0316917f7f4f5725b195c7be189dc38c65df0483114975b57463ac93012ba3ede3b56a9591610cc09188913491899190611e76565b60405180910390a45050600160005550565b60026000541415610cf55760405162461bcd60e51b81526004016103749061238b565b6002600055838711610d195760405162461bcd60e51b815260040161037490612233565b8751895114610d3a5760405162461bcd60e51b815260040161037490612174565b84518651148015610d4c575082518651145b8015610d59575081518651145b8015610d66575080518651145b610d825760405162461bcd60e51b815260040161037490612354565b600154610d93878787600654610e48565b14610db05760405162461bcd60e51b815260040161037490611ef2565b6000610dc08a8a8a600654610e48565b9050610dd3878786868686600754610e9a565b60018181556004899055600554610de991611032565b600581905560405189917fb119f1f36224601586b5037da909ecf37e83864dddea5d32ad4e32ac1d97e62b91610e2391908e908e906123c2565b60405180910390a2505060016000555050505050505050565b60075481565b60015481565b6040516000906918da1958dadc1bda5b9d60b21b908290610e75908590849088908b908b90602001611cbd565b60408051601f198184030181529190528051602090910120925050505b949350505050565b6000805b8851811015610f6757868181518110610eb357fe5b602002602001015160ff16600014610f5f57610f1e898281518110610ed457fe5b602002602001015185898481518110610ee957fe5b6020026020010151898581518110610efd57fe5b6020026020010151898681518110610f1157fe5b602002602001015161110b565b610f3a5760405162461bcd60e51b815260040161037490612093565b878181518110610f4657fe5b60200260200101518201915082821115610f5f57610f67565b600101610e9e565b50818111610f875760405162461bcd60e51b8152600401610374906121d6565b5050505050505050565b6107508363a9059cbb60e01b8484604051602401610fb0929190611c9b565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526111a6565b606061102983836040518060400160405280601e81526020017f416464726573733a206c6f772d6c6576656c2063616c6c206661696c65640000815250611235565b90505b92915050565b6000828201838110156110295760405162461bcd60e51b815260040161037490612039565b611078846323b872dd60e01b858585604051602401610fb093929190611c77565b50505050565b604080516000808252602082019092526001600160a01b0384169083906040516110a89190611c16565b60006040518083038185875af1925050503d80600081146110e5576040519150601f19603f3d011682016040523d82523d6000602084013e6110ea565b606091505b50509050806107505760405162461bcd60e51b8152600401610374906122c7565b6000808560405160200161111f9190611c32565b6040516020818303038152906040528051906020012090506001818686866040516000815260200160405260405161115a9493929190611e91565b6020604051602081039080840390855afa15801561117c573d6000803e3d6000fd5b505050602060405103516001600160a01b0316876001600160a01b03161491505095945050505050565b60606111fb826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166112359092919063ffffffff16565b80519091501561075057808060200190518101906112199190611adf565b6107505760405162461bcd60e51b81526004016103749061230a565b6060610e928484600085606061124a85611303565b6112665760405162461bcd60e51b815260040161037490612290565b60006060866001600160a01b031685876040516112839190611c16565b60006040518083038185875af1925050503d80600081146112c0576040519150601f19603f3d011682016040523d82523d6000602084013e6112c5565b606091505b509150915081156112d9579150610e929050565b8051156112e95780518082602001fd5b8360405162461bcd60e51b81526004016103749190611eaf565b6000813f7fc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470818114801590610e92575050151592915050565b803561102c8161245e565b600082601f830112611357578081fd5b813561136a61136582612413565b6123ed565b81815291506020808301908481018184028601820187101561138b57600080fd5b60005b848110156113b35781356113a18161245e565b8452928201929082019060010161138e565b505050505092915050565b600082601f8301126113ce578081fd5b81356113dc61136582612413565b8181529150602080830190848101818402860182018710156113fd57600080fd5b60005b848110156113b35781356114138161245e565b84529282019290820190600101611400565b600082601f830112611435578081fd5b813561144361136582612413565b81815291506020808301908481018184028601820187101561146457600080fd5b60005b848110156113b357813584529282019290820190600101611467565b600082601f830112611493578081fd5b81356114a161136582612413565b8181529150602080830190848101818402860182018710156114c257600080fd5b6000805b858110156114f057823560ff811681146114de578283fd5b855293830193918301916001016114c6565b50505050505092915050565b600082601f83011261150c578081fd5b81356001600160401b03811115611521578182fd5b611534601f8201601f19166020016123ed565b915080825283602082850101111561154b57600080fd5b8060208401602084013760009082016020015292915050565b6000610120808385031215611577578182fd5b611580816123ed565b91505081356001600160401b038082111561159a57600080fd5b6115a685838601611425565b835260208401359150808211156115bc57600080fd5b6115c885838601611347565b602084015260408401359150808211156115e157600080fd5b6115ed85838601611425565b6040840152606084013591508082111561160657600080fd5b61161285838601611347565b6060840152611624856080860161133c565b608084015260a084013591508082111561163d57600080fd5b5061164a848285016114fc565b60a08301525060c082013560c082015260e082013560e082015261010080830135818301525092915050565b600060208284031215611687578081fd5b81356110298161245e565b600080600080600060a086880312156116a9578081fd5b85356116b48161245e565b97602087013597506040870135966060810135965060800135945092505050565b600080604083850312156116e7578182fd5b82356001600160401b038111156116fc578283fd5b61170885828601611347565b92505060208301356117198161245e565b809150509250929050565b60008060008060008060008060006101208a8c031215611742578384fd5b89356001600160401b0380821115611758578586fd5b6117648d838e01611347565b9a5060208c0135915080821115611779578586fd5b6117858d838e01611425565b995060408c0135985060608c01359150808211156117a1578586fd5b6117ad8d838e01611347565b975060808c01359150808211156117c2578586fd5b6117ce8d838e01611425565b965060a08c0135955060c08c01359150808211156117ea578485fd5b6117f68d838e01611483565b945060e08c013591508082111561180b578384fd5b6118178d838e01611425565b93506101008c013591508082111561182d578283fd5b5061183a8c828d01611425565b9150509295985092959850929598565b6000806000806000806000806000806000806101808d8f03121561186c578586fd5b6001600160401b038d351115611880578586fd5b61188d8e8e358f01611347565b9b506001600160401b0360208e013511156118a6578586fd5b6118b68e60208f01358f01611425565b9a5060408d013599506001600160401b0360608e013511156118d6578586fd5b6118e68e60608f01358f01611483565b98506001600160401b0360808e013511156118ff578586fd5b61190f8e60808f01358f01611425565b97506001600160401b0360a08e01351115611928578586fd5b6119388e60a08f01358f01611425565b96506001600160401b0360c08e01351115611951578586fd5b6119618e60c08f01358f01611425565b95506001600160401b0360e08e0135111561197a578283fd5b61198a8e60e08f01358f016113be565b94506001600160401b036101008e013511156119a4578283fd5b6119b58e6101008f01358f01611425565b93506101208d013592506119cd8e6101408f0161133c565b91506101608d013590509295989b509295989b509295989b565b600080600080600080600060e0888a031215611a01578081fd5b87356001600160401b0380821115611a17578283fd5b611a238b838c01611347565b985060208a0135915080821115611a38578283fd5b611a448b838c01611425565b975060408a0135965060608a0135915080821115611a60578283fd5b611a6c8b838c01611483565b955060808a0135915080821115611a81578283fd5b611a8d8b838c01611425565b945060a08a0135915080821115611aa2578283fd5b611aae8b838c01611425565b935060c08a0135915080821115611ac3578283fd5b50611ad08a828b01611564565b91505092959891949750929550565b600060208284031215611af0578081fd5b81518015158114611029578182fd5b600060208284031215611b10578081fd5b5035919050565b600080600060608486031215611b2b578081fd5b505081359360208301359350604090920135919050565b600060208284031215611b53578081fd5b5051919050565b6001600160a01b0316815260200190565b6001600160a01b03169052565b6000815180845260208085019450808401835b83811015611bb05781516001600160a01b031687529582019590820190600101611b8b565b509495945050505050565b6000815180845260208085019450808401835b83811015611bb057815187529582019590820190600101611bce565b60008151808452611c02816020860160208601612432565b601f01601f19169290920160200192915050565b60008251611c28818460208701612432565b9190910192915050565b7f19457468657265756d205369676e6564204d6573736167653a0a3332000000008152601c810191909152603c0190565b6001600160a01b0391909116815260200190565b6001600160a01b039384168152919092166020820152604081019190915260600190565b6001600160a01b03929092168252602082015260400190565b90815260200190565b600086825285602083015284604083015260a06060830152611ce260a0830185611b78565b8281036080840152611cf48185611bbb565b98975050505050505050565b60006101608d83528c6020840152806040840152611d208184018d611bbb565b90508281036060840152611d34818c611b78565b90508281036080840152611d48818b611bbb565b905082810360a0840152611d5c818a611b78565b6001600160a01b03891660c085015283810360e08501529050611d7f8188611bea565b61010084019690965250506101208101929092526101409091015298975050505050505050565b60006101008a835260208a81850152816040850152611dc78285018b611bbb565b91508382036060850152818951611dde8185611cb4565b9150828b019350845b81811015611e0857611dfa838651611b5a565b948401949250600101611de7565b50508481036080860152611e1c818a611bbb565b93505050508460a0830152611e3460c0830185611b6b565b8260e08301529998505050505050505050565b600085825284602083015283604083015260806060830152611e6c6080830184611bea565b9695505050505050565b93845260208401929092526040830152606082015260800190565b93845260ff9290921660208401526040830152606082015260800190565b6000602082526110296020830184611bea565b6020808252601690820152754d616c666f726d6564206c697374206f66206665657360501b604082015260600190565b6020808252603f908201527f537570706c6965642063757272656e742076616c696461746f727320616e642060408201527f706f7765727320646f206e6f74206d6174636820636865636b706f696e742e00606082015260800190565b60208082526036908201527f4e6577206261746368206e6f6e6365206d7573742062652067726561746572206040820152757468616e207468652063757272656e74206e6f6e636560501b606082015260800190565b6020808252601f908201527f4d616c666f726d6564206261746368206f66207472616e73616374696f6e7300604082015260600190565b6020808252603d908201527f4e657720696e76616c69646174696f6e206e6f6e6365206d757374206265206760408201527f726561746572207468616e207468652063757272656e74206e6f6e6365000000606082015260800190565b6020808252601b908201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604082015260600190565b602080825260099082015268151a5b5959081bdd5d60ba1b604082015260600190565b60208082526023908201527f56616c696461746f72207369676e617475726520646f6573206e6f74206d617460408201526231b41760e91b606082015260800190565b6020808252603b908201527f42617463682074696d656f7574206d757374206265206772656174657220746860408201527f616e207468652063757272656e7420626c6f636b206865696768740000000000606082015260800190565b60208082526021908201527f4d616c666f726d6564206c697374206f6620746f6b656e207472616e736665726040820152607360f81b606082015260800190565b6020808252601b908201527f4d616c666f726d6564206e65772076616c696461746f72207365740000000000604082015260600190565b6020808252601190820152701c195c9b5a5cdcda5bdb8819195b9a5959607a1b604082015260600190565b6020808252603c908201527f5375626d69747465642076616c696461746f7220736574207369676e6174757260408201527f657320646f206e6f74206861766520656e6f75676820706f7765722e00000000606082015260800190565b60208082526037908201527f4e65772076616c736574206e6f6e6365206d757374206265206772656174657260408201527f207468616e207468652063757272656e74206e6f6e6365000000000000000000606082015260800190565b6020808252601d908201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604082015260600190565b60208082526023908201527f5472616e7366657248656c7065723a204554485f5452414e534645525f46414960408201526213115160ea1b606082015260800190565b6020808252602a908201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6040820152691bdd081cdd58d8d9595960b21b606082015260800190565b6020808252601f908201527f4d616c666f726d65642063757272656e742076616c696461746f722073657400604082015260600190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b6000848252606060208301526123db6060830185611b78565b8281036040840152611e6c8185611bbb565b6040518181016001600160401b038111828210171561240b57600080fd5b604052919050565b60006001600160401b03821115612428578081fd5b5060209081020190565b60005b8381101561244d578181015183820152602001612435565b838111156110785750506000910152565b6001600160a01b038116811461247357600080fd5b5056fea26469706673582212206bc6722725083ade04f749e952f128a0c9a42aa4555f022380d829b5d025845864736f6c634300060c0033
Verified Source Code Partial Match
Compiler: v0.6.12+commit.27d51765
EVM: istanbul
Optimization: Yes (200 runs)
Hub2Eth.sol 1156 lines
// File: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.1.0/contracts/utils/ReentrancyGuard.sol
pragma solidity ^0.6.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].
*/
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 () internal {
_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 make it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
// On the first call to nonReentrant, _notEntered will be true
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
_;
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
}
// File: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.1.0/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) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
/**
* @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: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.1.0/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: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.1.0/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: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.1.0/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: hub2eth.sol
pragma solidity ^0.6.6;
pragma experimental ABIEncoderV2;
// This is being used purely to avoid stack too deep errors
struct LogicCallArgs {
// Transfers out to the logic contract
uint256[] transferAmounts;
address[] transferTokenContracts;
// The fees (transferred to msg.sender)
uint256[] feeAmounts;
address[] feeTokenContracts;
// The arbitrary logic call
address logicContractAddress;
bytes payload;
// Invalidation metadata
uint256 timeOut;
bytes32 invalidationId;
uint256 invalidationNonce;
}
interface IWETH {
function deposit() external payable;
function withdraw(uint) external;
}
contract Hub2Eth is ReentrancyGuard {
using SafeMath for uint256;
using SafeMath for uint;
using SafeERC20 for IERC20;
// These are updated often
bytes32 public state_lastValsetCheckpoint;
mapping(address => uint256) public state_lastBatchNonces;
mapping(bytes32 => uint256) public state_invalidationMapping;
uint256 public state_lastValsetNonce = 0;
// event nonce zero is reserved by the Cosmos module as a special
// value indicating that no events have yet been submitted
uint256 public state_lastEventNonce = 1;
// These are set once at initialization
bytes32 public state_gravityId;
uint256 public state_powerThreshold;
address public wethAddress;
address public guardian;
// TransactionBatchExecutedEvent and TransferToChain both include the field _eventNonce.
// This is incremented every time one of these events is emitted. It is checked by the
// Cosmos module to ensure that all events are received in order, and that none are lost.
//
// ValsetUpdatedEvent does not include the field _eventNonce because it is never submitted to the Cosmos
// module. It is purely for the use of relayers to allow them to successfully submit batches.
event TransactionBatchExecutedEvent(
uint256 indexed _batchNonce,
address indexed _token,
uint256 _eventNonce
);
event TransferToChainEvent(
address indexed _tokenContract,
address indexed _sender,
bytes32 indexed _destinationChain,
bytes32 _destination,
uint256 _amount,
uint256 _fee,
uint256 _eventNonce
);
event ValsetUpdatedEvent(
uint256 indexed _newValsetNonce,
uint256 _eventNonce,
address[] _validators,
uint256[] _powers
);
event LogicCallEvent(
bytes32 _invalidationId,
uint256 _invalidationNonce,
uint256 _eventNonce,
bytes _returnData
);
receive() external payable {
assert(msg.sender == wethAddress); // only accept ETH via fallback from the WETH contract
}
function lastBatchNonce(address _erc20Address) public view returns (uint256) {
return state_lastBatchNonces[_erc20Address];
}
function lastLogicCallNonce(bytes32 _invalidation_id) public view returns (uint256) {
return state_invalidationMapping[_invalidation_id];
}
// Utility function to verify geth style signatures
function verifySig(
address _signer,
bytes32 _theHash,
uint8 _v,
bytes32 _r,
bytes32 _s
) private pure returns (bool) {
bytes32 messageDigest =
keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", _theHash));
return _signer == ecrecover(messageDigest, _v, _r, _s);
}
// Make a new checkpoint from the supplied validator set
// A checkpoint is a hash of all relevant information about the valset. This is stored by the contract,
// instead of storing the information directly. This saves on storage and gas.
// The format of the checkpoint is:
// h(gravityId, "checkpoint", valsetNonce, validators[], powers[])
// Where h is the keccak256 hash function.
// The validator powers must be decreasing or equal. This is important for checking the signatures on the
// next valset, since it allows the caller to stop verifying signatures once a quorum of signatures have been verified.
function makeCheckpoint(
address[] memory _validators,
uint256[] memory _powers,
uint256 _valsetNonce,
bytes32 _gravityId
) private pure returns (bytes32) {
// bytes32 encoding of the string "checkpoint"
bytes32 methodName = 0x636865636b706f696e7400000000000000000000000000000000000000000000;
bytes32 checkpoint =
keccak256(abi.encode(_gravityId, methodName, _valsetNonce, _validators, _powers));
return checkpoint;
}
function checkValidatorSignatures(
// The current validator set and their powers
address[] memory _currentValidators,
uint256[] memory _currentPowers,
// The current validator's signatures
uint8[] memory _v,
bytes32[] memory _r,
bytes32[] memory _s,
// This is what we are checking they have signed
bytes32 _theHash,
uint256 _powerThreshold
) private pure {
uint256 cumulativePower = 0;
for (uint256 i = 0; i < _currentValidators.length; i++) {
// If v is set to 0, this signifies that it was not possible to get a signature from this validator and we skip evaluation
// (In a valid signature, it is either 27 or 28)
if (_v[i] != 0) {
// Check that the current validator has signed off on the hash
require(
verifySig(_currentValidators[i], _theHash, _v[i], _r[i], _s[i]),
"Validator signature does not match."
);
// Sum up cumulative power
cumulativePower = cumulativePower + _currentPowers[i];
// Break early to avoid wasting gas
if (cumulativePower > _powerThreshold) {
break;
}
}
}
// Check that there was enough power
require(
cumulativePower > _powerThreshold,
"Submitted validator set signatures do not have enough power."
);
// Success
}
// This updates the valset by checking that the validators in the current valset have signed off on the
// new valset. The signatures supplied are the signatures of the current valset over the checkpoint hash
// generated from the new valset.
// Anyone can call this function, but they must supply valid signatures of state_powerThreshold of the current valset over
// the new valset.
function updateValset(
// The new version of the validator set
address[] memory _newValidators,
uint256[] memory _newPowers,
uint256 _newValsetNonce,
// The current validators that approve the change
address[] memory _currentValidators,
uint256[] memory _currentPowers,
uint256 _currentValsetNonce,
// These are arrays of the parts of the current validator's signatures
uint8[] memory _v,
bytes32[] memory _r,
bytes32[] memory _s
) public nonReentrant {
// CHECKS
// Check that the valset nonce is greater than the old one
require(
_newValsetNonce > _currentValsetNonce,
"New valset nonce must be greater than the current nonce"
);
// Check that new validators and powers set is well-formed
require(_newValidators.length == _newPowers.length, "Malformed new validator set");
// Check that current validators, powers, and signatures (v,r,s) set is well-formed
require(
_currentValidators.length == _currentPowers.length &&
_currentValidators.length == _v.length &&
_currentValidators.length == _r.length &&
_currentValidators.length == _s.length,
"Malformed current validator set"
);
// Check that the supplied current validator set matches the saved checkpoint
require(
makeCheckpoint(
_currentValidators,
_currentPowers,
_currentValsetNonce,
state_gravityId
) == state_lastValsetCheckpoint,
"Supplied current validators and powers do not match checkpoint."
);
// Check that enough current validators have signed off on the new validator set
bytes32 newCheckpoint =
makeCheckpoint(_newValidators, _newPowers, _newValsetNonce, state_gravityId);
checkValidatorSignatures(
_currentValidators,
_currentPowers,
_v,
_r,
_s,
newCheckpoint,
state_powerThreshold
);
// ACTIONS
// Stored to be used next time to validate that the valset
// supplied by the caller is correct.
state_lastValsetCheckpoint = newCheckpoint;
// Store new nonce
state_lastValsetNonce = _newValsetNonce;
// LOGS
state_lastEventNonce = state_lastEventNonce.add(1);
emit ValsetUpdatedEvent(_newValsetNonce, state_lastEventNonce, _newValidators, _newPowers);
}
// submitBatch processes a batch of Cosmos -> Ethereum transactions by sending the tokens in the transactions
// to the destination addresses. It is approved by the current Cosmos validator set.
// Anyone can call this function, but they must supply valid signatures of state_powerThreshold of the current valset over
// the batch.
function submitBatch(
// The validators that approve the batch
address[] memory _currentValidators,
uint256[] memory _currentPowers,
uint256 _currentValsetNonce,
// These are arrays of the parts of the validators signatures
uint8[] memory _v,
bytes32[] memory _r,
bytes32[] memory _s,
// The batch of transactions
uint256[] memory _amounts,
address payable[] memory _destinations,
uint256[] memory _fees,
uint256 _batchNonce,
address _tokenContract,
// a block height beyond which this batch is not valid
// used to provide a fee-free timeout
uint256 _batchTimeout
) public nonReentrant {
// CHECKS scoped to reduce stack depth
{
// Check that the batch nonce is higher than the last nonce for this token
require(
state_lastBatchNonces[_tokenContract] < _batchNonce,
"New batch nonce must be greater than the current nonce"
);
// Check that the block height is less than the timeout height
require(
block.number < _batchTimeout,
"Batch timeout must be greater than the current block height"
);
// Check that current validators, powers, and signatures (v,r,s) set is well-formed
require(
_currentValidators.length == _currentPowers.length &&
_currentValidators.length == _v.length &&
_currentValidators.length == _r.length &&
_currentValidators.length == _s.length,
"Malformed current validator set"
);
// Check that the supplied current validator set matches the saved checkpoint
require(
makeCheckpoint(
_currentValidators,
_currentPowers,
_currentValsetNonce,
state_gravityId
) == state_lastValsetCheckpoint,
"Supplied current validators and powers do not match checkpoint."
);
// Check that the transaction batch is well-formed
require(
_amounts.length == _destinations.length && _amounts.length == _fees.length,
"Malformed batch of transactions"
);
// Check that enough current validators have signed off on the transaction batch and valset
checkValidatorSignatures(
_currentValidators,
_currentPowers,
_v,
_r,
_s,
// Get hash of the transaction batch and checkpoint
keccak256(
abi.encode(
state_gravityId,
// bytes32 encoding of "transactionBatch"
0x7472616e73616374696f6e426174636800000000000000000000000000000000,
_amounts,
_destinations,
_fees,
_batchNonce,
_tokenContract,
_batchTimeout
)
),
state_powerThreshold
);
// ACTIONS
// Store batch nonce
state_lastBatchNonces[_tokenContract] = _batchNonce;
// Send transaction amounts to destinations
if (_tokenContract == wethAddress) {
for (uint256 i = 0; i < _amounts.length; i++) {
IWETH(wethAddress).withdraw(_amounts[i]);
TransferHelper.safeTransferETH(_destinations[i], _amounts[i]);
}
} else {
for (uint256 i = 0; i < _amounts.length; i++) {
IERC20(_tokenContract).safeTransfer(_destinations[i], _amounts[i]);
}
}
}
// LOGS scoped to reduce stack depth
{
state_lastEventNonce = state_lastEventNonce.add(1);
emit TransactionBatchExecutedEvent(_batchNonce, _tokenContract, state_lastEventNonce);
}
}
// This makes calls to contracts that execute arbitrary logic
// First, it gives the logic contract some tokens
// Then, it gives msg.senders tokens for fees
// Then, it calls an arbitrary function on the logic contract
// invalidationId and invalidationNonce are used for replay prevention.
// They can be used to implement a per-token nonce by setting the token
// address as the invalidationId and incrementing the nonce each call.
// They can be used for nonce-free replay prevention by using a different invalidationId
// for each call.
function submitLogicCall(
// The validators that approve the call
address[] memory _currentValidators,
uint256[] memory _currentPowers,
uint256 _currentValsetNonce,
// These are arrays of the parts of the validators signatures
uint8[] memory _v,
bytes32[] memory _r,
bytes32[] memory _s,
LogicCallArgs memory _args
) public nonReentrant {
// CHECKS scoped to reduce stack depth
{
// Check that the call has not timed out
require(block.number < _args.timeOut, "Timed out");
// Check that the invalidation nonce is higher than the last nonce for this invalidation Id
require(
state_invalidationMapping[_args.invalidationId] < _args.invalidationNonce,
"New invalidation nonce must be greater than the current nonce"
);
// Check that current validators, powers, and signatures (v,r,s) set is well-formed
require(
_currentValidators.length == _currentPowers.length &&
_currentValidators.length == _v.length &&
_currentValidators.length == _r.length &&
_currentValidators.length == _s.length,
"Malformed current validator set"
);
// Check that the supplied current validator set matches the saved checkpoint
require(
makeCheckpoint(
_currentValidators,
_currentPowers,
_currentValsetNonce,
state_gravityId
) == state_lastValsetCheckpoint,
"Supplied current validators and powers do not match checkpoint."
);
// Check that the token transfer list is well-formed
require(
_args.transferAmounts.length == _args.transferTokenContracts.length,
"Malformed list of token transfers"
);
// Check that the fee list is well-formed
require(
_args.feeAmounts.length == _args.feeTokenContracts.length,
"Malformed list of fees"
);
}
bytes32 argsHash =
keccak256(
abi.encode(
state_gravityId,
// bytes32 encoding of "logicCall"
0x6c6f67696343616c6c0000000000000000000000000000000000000000000000,
_args.transferAmounts,
_args.transferTokenContracts,
_args.feeAmounts,
_args.feeTokenContracts,
_args.logicContractAddress,
_args.payload,
_args.timeOut,
_args.invalidationId,
_args.invalidationNonce
)
);
{
// Check that enough current validators have signed off on the transaction batch and valset
checkValidatorSignatures(
_currentValidators,
_currentPowers,
_v,
_r,
_s,
// Get hash of the transaction batch and checkpoint
argsHash,
state_powerThreshold
);
}
// ACTIONS
// Update invaldiation nonce
state_invalidationMapping[_args.invalidationId] = _args.invalidationNonce;
// Send tokens to the logic contract
for (uint256 i = 0; i < _args.transferAmounts.length; i++) {
IERC20(_args.transferTokenContracts[i]).safeTransfer(
_args.logicContractAddress,
_args.transferAmounts[i]
);
}
// Make call to logic contract
bytes memory returnData = Address.functionCall(_args.logicContractAddress, _args.payload);
// Send fees to msg.sender
for (uint256 i = 0; i < _args.feeAmounts.length; i++) {
IERC20(_args.feeTokenContracts[i]).safeTransfer(msg.sender, _args.feeAmounts[i]);
}
// LOGS scoped to reduce stack depth
{
state_lastEventNonce = state_lastEventNonce.add(1);
emit LogicCallEvent(
_args.invalidationId,
_args.invalidationNonce,
state_lastEventNonce,
returnData
);
}
}
function transferToChain(
address _tokenContract,
bytes32 _destinationChain,
bytes32 _destination,
uint256 _amount,
uint256 _fee
) public nonReentrant {
IERC20(_tokenContract).safeTransferFrom(msg.sender, address(this), _amount);
state_lastEventNonce = state_lastEventNonce.add(1);
emit TransferToChainEvent(
_tokenContract,
msg.sender,
_destinationChain,
_destination,
_amount,
_fee,
state_lastEventNonce
);
}
function transferETHToChain(
bytes32 _destinationChain,
bytes32 _destination,
uint256 _fee
) public nonReentrant payable {
IWETH(wethAddress).deposit{value: msg.value}();
state_lastEventNonce = state_lastEventNonce.add(1);
emit TransferToChainEvent(
wethAddress,
msg.sender,
_destinationChain,
_destination,
msg.value,
_fee,
state_lastEventNonce
);
}
function changeGuardian(address _guardian) public {
require(msg.sender == guardian, "permission denied");
guardian = _guardian;
}
function panicHalt(address[] memory _tokenContracts, address _safeAddress) public {
require(msg.sender == guardian, "permission denied");
for (uint256 i = 0; i < _tokenContracts.length; i++) {
IERC20 token = IERC20(_tokenContracts[i]);
token.safeTransfer(_safeAddress, token.balanceOf(address(this)));
}
}
constructor(
// A unique identifier for this gravity instance to use in signatures
bytes32 _gravityId,
// How much voting power is needed to approve operations
uint256 _powerThreshold,
// The validator set
address[] memory _validators,
uint256[] memory _powers,
address[] memory _validators2,
uint256[] memory _powers2,
address _wethAddress,
address _guardian
) public {
// CHECKS
// Check that validators, powers, and signatures (v,r,s) set is well-formed
require(_validators.length == _powers.length, "Malformed current validator set");
// Check cumulative power to ensure the contract has sufficient power to actually
// pass a vote
uint256 cumulativePower = 0;
for (uint256 i = 0; i < _powers.length; i++) {
cumulativePower = cumulativePower + _powers[i];
if (cumulativePower > _powerThreshold) {
break;
}
}
require(
cumulativePower > _powerThreshold,
"Submitted validator set signatures do not have enough power."
);
bytes32 newCheckpoint = makeCheckpoint(_validators2, _powers2, 3, _gravityId);
// ACTIONS
state_gravityId = _gravityId;
state_powerThreshold = _powerThreshold;
state_lastValsetCheckpoint = newCheckpoint;
wethAddress = _wethAddress;
guardian = _guardian;
// LOGS
emit ValsetUpdatedEvent(state_lastValsetNonce, state_lastEventNonce, _validators, _powers);
emit ValsetUpdatedEvent(3, 2, _validators2, _powers2);
state_lastValsetNonce = 3;
state_lastEventNonce = 2;
}
}
library TransferHelper {
function safeApprove(address token, address to, uint value) internal {
// bytes4(keccak256(bytes('approve(address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x095ea7b3, to, value));
require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: APPROVE_FAILED');
}
function safeTransfer(address token, address to, uint value) internal {
// bytes4(keccak256(bytes('transfer(address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value));
require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: TRANSFER_FAILED');
}
function safeTransferFrom(address token, address from, address to, uint value) internal {
// bytes4(keccak256(bytes('transferFrom(address,address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value));
require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: TRANSFER_FROM_FAILED');
}
function safeTransferETH(address to, uint value) internal {
(bool success,) = to.call{value:value}(new bytes(0));
require(success, 'TransferHelper: ETH_TRANSFER_FAILED');
}
}
Read Contract
guardian 0x452a9320 → address
lastBatchNonce 0x011b2174 → uint256
lastLogicCallNonce 0xc9d194d5 → uint256
state_gravityId 0xbdda81d4 → bytes32
state_invalidationMapping 0x7dfb6f86 → uint256
state_lastBatchNonces 0xdf97174b → uint256
state_lastEventNonce 0x73b20547 → uint256
state_lastValsetCheckpoint 0xf2b53307 → bytes32
state_lastValsetNonce 0xb56561fe → uint256
state_powerThreshold 0xe5a2b5d2 → uint256
wethAddress 0x4f0e0ef3 → address
Write Contract 7 functions
These functions modify contract state and require a wallet transaction to execute.
changeGuardian 0x2fcb4f04
address _guardian
panicHalt 0x1762d25a
address[] _tokenContracts
address _safeAddress
submitBatch 0x83b435db
address[] _currentValidators
uint256[] _currentPowers
uint256 _currentValsetNonce
uint8[] _v
bytes32[] _r
bytes32[] _s
uint256[] _amounts
address[] _destinations
uint256[] _fees
uint256 _batchNonce
address _tokenContract
uint256 _batchTimeout
submitLogicCall 0xbdc25619
address[] _currentValidators
uint256[] _currentPowers
uint256 _currentValsetNonce
uint8[] _v
bytes32[] _r
bytes32[] _s
tuple _args
transferETHToChain 0xe2d7c048
bytes32 _destinationChain
bytes32 _destination
uint256 _fee
transferToChain 0x7ecccecc
address _tokenContract
bytes32 _destinationChain
bytes32 _destination
uint256 _amount
uint256 _fee
updateValset 0xe3cb9f62
address[] _newValidators
uint256[] _newPowers
uint256 _newValsetNonce
address[] _currentValidators
uint256[] _currentPowers
uint256 _currentValsetNonce
uint8[] _v
bytes32[] _r
bytes32[] _s
Token Balances (6)
View Transfers →Recent Transactions
No transactions found for this address