Address Contract Verified
Address
0x25CD496D66708166a06DA16ED641dd286CE76815
Balance
0 ETH
Nonce
1
Code Size
14772 bytes
Creator
0xB42fBa3D...6fD5 at tx 0xd27b5975...ed7551
Indexed Transactions
0 (1 on-chain, 0.7% indexed)
Contract Bytecode
14772 bytes
0x60806040526004361061023a5760003560e01c80638da5cb5b1161012e578063c4461834116100ab578063eb8d72b71161006f578063eb8d72b71461067c578063ed629c5c1461069c578063f2fde38b146106b1578063f5ecbdbc146106d1578063fc0c546a146106f15761023a565b8063c4461834146105f4578063cbed8b9c14610609578063d1deba1f14610629578063df2a5b3b1461063c578063eab45d9c1461065c5761023a565b80639f38369a116100f25780639f38369a1461055f578063a6c3d1651461057f578063aa271e1a1461059f578063b353aaa7146105bf578063baf3292d146105d45761023a565b80638da5cb5b146104eb5780638dbb94eb146105005780639358928b14610515578063950c8a741461052a578063983b2d561461053f5761023a565b80633f1f4fa4116101bc5780635b8c41e6116101805780635b8c41e61461044957806366ad5c8a14610469578063715018a6146104895780637533d7881461049e5780638cfd8f5c146104cb5761023a565b80633f1f4fa4146103b257806342d65a8d146103df57806344770515146103ff5780634c42899a1461041457806351905636146104365761023a565b806310ddb1371161020357806310ddb137146102f75780631b955b3f146103175780632a205e3d146103445780633092afd5146103725780633d8b38f6146103925761023a565b80621d35671461023f57806301ffc9a71461026157806307e0db17146102975780630df37483146102b75780631071a290146102d7575b600080fd5b34801561024b57600080fd5b5061025f61025a366004612c6b565b610706565b005b34801561026d57600080fd5b5061028161027c366004612b06565b6108de565b60405161028e91906130a1565b60405180910390f35b3480156102a357600080fd5b5061025f6102b2366004612b60565b610909565b3480156102c357600080fd5b5061025f6102d2366004612f27565b6109c9565b3480156102e357600080fd5b5061025f6102f2366004612f52565b610a1f565b34801561030357600080fd5b5061025f610312366004612b60565b610a64565b34801561032357600080fd5b50610337610332366004612f52565b610aef565b60405161028e9190613050565b34801561035057600080fd5b5061036461035f366004612bce565b610afc565b60405161028e9291906138b3565b34801561037e57600080fd5b5061025f61038d3660046129ec565b610bdf565b34801561039e57600080fd5b506102816103ad366004612b7c565b610c27565b3480156103be57600080fd5b506103d26103cd366004612b60565b610cf4565b60405161028e91906130ac565b3480156103eb57600080fd5b5061025f6103fa366004612b7c565b610d06565b34801561040b57600080fd5b506103d2610dc3565b34801561042057600080fd5b50610429610dc3565b60405161028e9190613629565b61025f610444366004612a08565b610dc8565b34801561045557600080fd5b506103d2610464366004612d55565b610e4d565b34801561047557600080fd5b5061025f610484366004612c6b565b610e81565b34801561049557600080fd5b5061025f610f2e565b3480156104aa57600080fd5b506104be6104b9366004612b60565b610fb7565b60405161028e91906130b5565b3480156104d757600080fd5b506103d26104e6366004612def565b611051565b3480156104f757600080fd5b5061033761106e565b34801561050c57600080fd5b506103d261107d565b34801561052157600080fd5b506103d261108e565b34801561053657600080fd5b506103376111c4565b34801561054b57600080fd5b5061025f61055a3660046129ec565b6111d3565b34801561056b57600080fd5b506104be61057a366004612b60565b61121b565b34801561058b57600080fd5b5061025f61059a366004612b7c565b6112f2565b3480156105ab57600080fd5b506102816105ba3660046129ec565b6113bc565b3480156105cb57600080fd5b506103376113c9565b3480156105e057600080fd5b5061025f6105ef3660046129ec565b6113ed565b34801561060057600080fd5b506103d2611482565b34801561061557600080fd5b5061025f610624366004612eb7565b611488565b61025f610637366004612c6b565b611549565b34801561064857600080fd5b5061025f610657366004612e77565b6116e9565b34801561066857600080fd5b5061025f610677366004612ace565b61179f565b34801561068857600080fd5b5061025f610697366004612b7c565b61181c565b3480156106a857600080fd5b506102816118ad565b3480156106bd57600080fd5b5061025f6106cc3660046129ec565b6118b6565b3480156106dd57600080fd5b506104be6106ec366004612e27565b611976565b3480156106fd57600080fd5b50610337611a28565b7f00000000000000000000000066a71dcef29a0ffbdbe3c6a460a3b5bc225cd6756001600160a01b0316610738611a4c565b6001600160a01b0316146107675760405162461bcd60e51b815260040161075e906134b5565b60405180910390fd5b61ffff861660009081526001602081815260409283902080548451600294821615610100026000190190911693909304601f810183900483028401830190945283835260609390918301828280156108005780601f106107d557610100808354040283529160200191610800565b820191906000526020600020905b8154815290600101906020018083116107e357829003601f168201915b5050505050905080518686905014801561081b575060008151115b80156108435750805160208201206040516108399088908890612ffb565b6040518091039020145b61085f5760405162461bcd60e51b815260040161075e906135ae565b6108d58787878080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525050604080516020601f8a018190048102820181019092528881528a935091508890889081908401838280828437600092019190915250611a5092505050565b50505050505050565b60006001600160e01b03198216630a72677560e11b1480610903575061090382611ade565b92915050565b610911611a4c565b6001600160a01b031661092261106e565b6001600160a01b0316146109485760405162461bcd60e51b815260040161075e90613480565b6040516307e0db1760e01b81526001600160a01b037f00000000000000000000000066a71dcef29a0ffbdbe3c6a460a3b5bc225cd67516906307e0db1790610994908490600401613629565b600060405180830381600087803b1580156109ae57600080fd5b505af11580156109c2573d6000803e3d6000fd5b5050505050565b6109d1611a4c565b6001600160a01b03166109e261106e565b6001600160a01b031614610a085760405162461bcd60e51b815260040161075e90613480565b61ffff909116600090815260036020526040902055565b610a28336113bc565b610a445760405162461bcd60e51b815260040161075e9061338e565b610a613382610a51611a28565b6001600160a01b03169190611afd565b50565b610a6c611a4c565b6001600160a01b0316610a7d61106e565b6001600160a01b031614610aa35760405162461bcd60e51b815260040161075e90613480565b6040516310ddb13760e01b81526001600160a01b037f00000000000000000000000066a71dcef29a0ffbdbe3c6a460a3b5bc225cd67516906310ddb13790610994908490600401613629565b6000610903600883611b58565b60008060606000898989604051602001610b1994939291906136ac565b60408051601f198184030181529082905263040a7bb160e41b825291506001600160a01b037f00000000000000000000000066a71dcef29a0ffbdbe3c6a460a3b5bc225cd67516906340a7bb1090610b7f908d90309086908c908c908c90600401613638565b604080518083038186803b158015610b9657600080fd5b505afa158015610baa573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bce9190612f82565b925092505097509795505050505050565b610be7611a4c565b6001600160a01b0316610bf861106e565b6001600160a01b031614610c1e5760405162461bcd60e51b815260040161075e90613480565b610a6181611b64565b61ffff8316600090815260016020818152604080842080548251600295821615610100026000190190911694909404601f810184900484028501840190925281845260609392909190830182828015610cc15780601f10610c9657610100808354040283529160200191610cc1565b820191906000526020600020905b815481529060010190602001808311610ca457829003601f168201915b505050505090508383604051610cd8929190612ffb565b60405180910390208180519060200120149150505b9392505050565b60036020526000908152604090205481565b610d0e611a4c565b6001600160a01b0316610d1f61106e565b6001600160a01b031614610d455760405162461bcd60e51b815260040161075e90613480565b6040516342d65a8d60e01b81526001600160a01b037f00000000000000000000000066a71dcef29a0ffbdbe3c6a460a3b5bc225cd67516906342d65a8d90610d959086908690869060040161368e565b600060405180830381600087803b158015610daf57600080fd5b505af11580156108d5573d6000803e3d6000fd5b600081565b610e42898989898080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525050604080516020601f8a018190048102820181019092528881528c93508b92508a918a908a9081908401838280828437600092019190915250611bab92505050565b505050505050505050565b6005602090815260009384526040808520845180860184018051928152908401958401959095209452929052825290205481565b30610e8a611a4c565b6001600160a01b031614610eb05760405162461bcd60e51b815260040161075e90613121565b610f268686868080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525050604080516020601f890181900481028201810190925287815289935091508790879081908401838280828437600092019190915250611c5392505050565b505050505050565b610f36611a4c565b6001600160a01b0316610f4761106e565b6001600160a01b031614610f6d5760405162461bcd60e51b815260040161075e90613480565b600080546040516001600160a01b03909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080546001600160a01b0319169055565b60016020818152600092835260409283902080548451600294821615610100026000190190911693909304601f81018390048302840183019094528383529192908301828280156110495780601f1061101e57610100808354040283529160200191611049565b820191906000526020600020905b81548152906001019060200180831161102c57829003601f168201915b505050505081565b600260209081526000928352604080842090915290825290205481565b6000546001600160a01b031690565b60006110896008611c8a565b905090565b6040516370a0823160e01b81526000906001600160a01b037f000000000000000000000000d6123271f980d966b00ca4fca6c2c021f05e2e7316906370a08231906110dd903090600401613050565b60206040518083038186803b1580156110f557600080fd5b505afa158015611109573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061112d9190612f6a565b7f000000000000000000000000d6123271f980d966b00ca4fca6c2c021f05e2e736001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b15801561118657600080fd5b505afa15801561119a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111be9190612f6a565b03905090565b6004546001600160a01b031681565b6111db611a4c565b6001600160a01b03166111ec61106e565b6001600160a01b0316146112125760405162461bcd60e51b815260040161075e90613480565b610a6181611c95565b61ffff811660009081526001602081815260409283902080548451600294821615610100026000190190911693909304601f81018390048302840183019094528383526060938493928301828280156112b55780601f1061128a576101008083540402835291602001916112b5565b820191906000526020600020905b81548152906001019060200180831161129857829003601f168201915b505050505090508051600014156112de5760405162461bcd60e51b815260040161075e906131a9565b8051610ced90829060009060131901611cdc565b6112fa611a4c565b6001600160a01b031661130b61106e565b6001600160a01b0316146113315760405162461bcd60e51b815260040161075e90613480565b8181306040516020016113469392919061300b565b60408051601f1981840301815291815261ffff8516600090815260016020908152919020825161137b9391929091019061285a565b507f8c0400cfe2d1199b1a725c78960bcc2a344d869b80590d0f2bd005db15a572ce8383836040516113af9392919061368e565b60405180910390a1505050565b6000610903600883611d5c565b7f00000000000000000000000066a71dcef29a0ffbdbe3c6a460a3b5bc225cd67581565b6113f5611a4c565b6001600160a01b031661140661106e565b6001600160a01b03161461142c5760405162461bcd60e51b815260040161075e90613480565b600480546001600160a01b0319166001600160a01b0383161790556040517f5db758e995a17ec1ad84bdef7e8c3293a0bd6179bcce400dff5d4c3d87db726b90611477908390613050565b60405180910390a150565b61271081565b611490611a4c565b6001600160a01b03166114a161106e565b6001600160a01b0316146114c75760405162461bcd60e51b815260040161075e90613480565b6040516332fb62e760e21b81526001600160a01b037f00000000000000000000000066a71dcef29a0ffbdbe3c6a460a3b5bc225cd675169063cbed8b9c9061151b9088908890889088908890600401613885565b600060405180830381600087803b15801561153557600080fd5b505af1158015610e42573d6000803e3d6000fd5b61ffff8616600090815260056020526040808220905161156c9088908890612ffb565b90815260408051602092819003830190206001600160401b038716600090815292529020549050806115b05760405162461bcd60e51b815260040161075e906132c3565b8083836040516115c1929190612ffb565b6040518091039020146115e65760405162461bcd60e51b815260040161075e9061356d565b61ffff871660009081526005602052604080822090516116099089908990612ffb565b90815260408051602092819003830181206001600160401b038916600090815290845282902093909355601f880182900482028301820190528682526116a1918991899089908190840183828082843760009201919091525050604080516020601f8a018190048102820181019092528881528a935091508890889081908401838280828437600092019190915250611c5392505050565b7fc264d91f3adc5588250e1551f547752ca0cfa8f6b530d243b9f9f4cab10ea8e587878787856040516116d89594939291906136db565b60405180910390a150505050505050565b6116f1611a4c565b6001600160a01b031661170261106e565b6001600160a01b0316146117285760405162461bcd60e51b815260040161075e90613480565b600081116117485760405162461bcd60e51b815260040161075e90613217565b61ffff80841660009081526002602090815260408083209386168352929052819020829055517f9d5c7c0b934da8fefa9c7760c98383778a12dfbfc0c3b3106518f43fb9508ac0906113af90859085908590613866565b6117a7611a4c565b6001600160a01b03166117b861106e565b6001600160a01b0316146117de5760405162461bcd60e51b815260040161075e90613480565b6007805460ff19168215151790556040517f1584ad594a70cbe1e6515592e1272a987d922b097ead875069cebe8b40c004a4906114779083906130a1565b611824611a4c565b6001600160a01b031661183561106e565b6001600160a01b03161461185b5760405162461bcd60e51b815260040161075e90613480565b61ffff831660009081526001602052604090206118799083836128d8565b507ffa41487ad5d6728f0b19276fa1eddc16558578f5109fc39d2dc33c3230470dab8383836040516113af9392919061368e565b60075460ff1681565b6118be611a4c565b6001600160a01b03166118cf61106e565b6001600160a01b0316146118f55760405162461bcd60e51b815260040161075e90613480565b6001600160a01b03811661191b5760405162461bcd60e51b815260040161075e9061327d565b600080546040516001600160a01b03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b604051633d7b2f6f60e21b81526060906001600160a01b037f00000000000000000000000066a71dcef29a0ffbdbe3c6a460a3b5bc225cd675169063f5ecbdbc906119cb908890889030908890600401613839565b60006040518083038186803b1580156119e357600080fd5b505afa1580156119f7573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611a1f9190810190612b2e565b95945050505050565b7f000000000000000000000000d6123271f980d966b00ca4fca6c2c021f05e2e7390565b3390565b6000606060005a90506175308110611acc57611ac6617530820360966366ad5c8a60e01b8a8a8a8a604051602401611a8b949392919061379d565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b03199093169290921790915230929190611d71565b90935091505b826108d5576108d58787878786611dfa565b6001600160e01b03191660009081526006602052604090205460ff1690565b611b538363a9059cbb60e01b8484604051602401611b1c929190613088565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152611e97565b505050565b6000610ced8383611f26565b611b6f600882611f6b565b15610a61576040516001600160a01b038216907fe94479a9f7e1952cc78f2d6baab678adc1b772d936c6583def489e524cb6669290600090a250565b611bb9866000836000611f80565b6000611bc788888888611fc1565b9050606060008783604051602001611be193929190613770565b6040516020818303038152906040529050611c0088828787873461217a565b886001600160a01b03168861ffff167f39a4c66499bcf4b56d79f0dde8ed7a9d4925a0df55825206b2b8531e202be0d08985604051611c409291906130c8565b60405180910390a3505050505050505050565b602081015161ffff8116611c7257611c6d858585856122d9565b6109c2565b60405162461bcd60e51b815260040161075e906130ea565b600061090382612362565b611ca0600882612366565b15610a61576040516001600160a01b038216907f6ae172837ea30b801fbfcdd4108aa1d5bf8ff775444fd70256b44e6bf3dfc3f690600090a250565b606081830184511015611cee57600080fd5b606082158015611d0957604051915060208201604052611d53565b6040519150601f8416801560200281840101858101878315602002848b0101015b81831015611d42578051835260209283019201611d2a565b5050858452601f01601f1916604052505b50949350505050565b6000610ced836001600160a01b03841661237b565b6000606060008060608661ffff166001600160401b0381118015611d9457600080fd5b506040519080825280601f01601f191660200182016040528015611dbf576020820181803683370190505b50905060008087516020890160008d8df191503d925086831115611de1578692505b828152826000602083013e909890975095505050505050565b8180519060200120600560008761ffff1661ffff16815260200190815260200160002085604051611e2b9190613034565b9081526040805191829003602090810183206001600160401b0388166000908152915220919091557fe183f33de2837795525b4792ca4cd60535bd77c53b7e7030060bfcf5734d6b0c90611e8890879087908790879087906137db565b60405180910390a15050505050565b6060611eec826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166123939092919063ffffffff16565b805190915015611b535780806020019051810190611f0a9190612aea565b611b535760405162461bcd60e51b815260040161075e90613523565b81546000908210611f495760405162461bcd60e51b815260040161075e90613167565b826000018281548110611f5857fe5b9060005260206000200154905092915050565b6000610ced836001600160a01b0384166123aa565b60075460ff1615611f9c57611f9784848484612477565b611fbb565b815115611fbb5760405162461bcd60e51b815260040161075e9061343a565b50505050565b6000611fcb611a4c565b6001600160a01b0316856001600160a01b031614611ffb5760405162461bcd60e51b815260040161075e90613306565b6040516370a0823160e01b81526000906001600160a01b037f000000000000000000000000d6123271f980d966b00ca4fca6c2c021f05e2e7316906370a082319061204a903090600401613050565b60206040518083038186803b15801561206257600080fd5b505afa158015612076573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061209a9190612f6a565b90506120d16001600160a01b037f000000000000000000000000d6123271f980d966b00ca4fca6c2c021f05e2e73168730866124e5565b6040516370a0823160e01b815281906001600160a01b037f000000000000000000000000d6123271f980d966b00ca4fca6c2c021f05e2e7316906370a082319061211f903090600401613050565b60206040518083038186803b15801561213757600080fd5b505afa15801561214b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061216f9190612f6a565b039695505050505050565b61ffff861660009081526001602081815260409283902080548451600294821615610100026000190190911693909304601f810183900483028401830190945283835260609390918301828280156122135780601f106121e857610100808354040283529160200191612213565b820191906000526020600020905b8154815290600101906020018083116121f657829003601f168201915b5050505050905080516000141561223c5760405162461bcd60e51b815260040161075e906133b3565b612247878751612506565b60405162c5803160e81b81526001600160a01b037f00000000000000000000000066a71dcef29a0ffbdbe3c6a460a3b5bc225cd675169063c580310090849061229e908b9086908c908c908c908c90600401613716565b6000604051808303818588803b1580156122b757600080fd5b505af11580156122cb573d6000803e3d6000fd5b505050505050505050505050565b60606000828060200190518101906122f19190612cfe565b9093509150600090506123048382612544565b9050612311878284612567565b9150806001600160a01b03168761ffff167fbf551ec93859b170f9b2141bd9298bf3f64322c6f7beb2543a0cb669834118bf8460405161235191906130ac565b60405180910390a350505050505050565b5490565b6000610ced836001600160a01b0384166126e4565b60009081526001919091016020526040902054151590565b60606123a2848460008561272e565b949350505050565b6000818152600183016020526040812054801561246657835460001980830191908101906000908790839081106123dd57fe5b90600052602060002001549050808760000184815481106123fa57fe5b60009182526020808320909101929092558281526001898101909252604090209084019055865487908061242a57fe5b60019003818190600052602060002001600090559055866001016000878152602001908152602001600020600090556001945050505050610903565b6000915050610903565b5092915050565b6000612482836127ef565b61ffff8087166000908152600260209081526040808320938916835292905220549091508201806124c55760405162461bcd60e51b815260040161075e90613246565b80821015610f265760405162461bcd60e51b815260040161075e906131e0565b611fbb846323b872dd60e01b858585604051602401611b1c93929190613064565b61ffff82166000908152600360205260409020548061252457506127105b80821115611b535760405162461bcd60e51b815260040161075e906135f4565b6000816014018351101561255757600080fd5b500160200151600160601b900490565b6000807f000000000000000000000000d6123271f980d966b00ca4fca6c2c021f05e2e736001600160a01b03166370a08231856040518263ffffffff1660e01b81526004016125b69190613050565b60206040518083038186803b1580156125ce57600080fd5b505afa1580156125e2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126069190612f6a565b905061263c6001600160a01b037f000000000000000000000000d6123271f980d966b00ca4fca6c2c021f05e2e73168585611afd565b6040516370a0823160e01b815281906001600160a01b037f000000000000000000000000d6123271f980d966b00ca4fca6c2c021f05e2e7316906370a082319061268a908890600401613050565b60206040518083038186803b1580156126a257600080fd5b505afa1580156126b6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126da9190612f6a565b0395945050505050565b60006126f0838361237b565b61272657508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155610903565b506000610903565b6060824710156127505760405162461bcd60e51b815260040161075e90613348565b6127598561281b565b6127755760405162461bcd60e51b815260040161075e906134ec565b60006060866001600160a01b031685876040516127929190613034565b60006040518083038185875af1925050503d80600081146127cf576040519150601f19603f3d011682016040523d82523d6000602084013e6127d4565b606091505b50915091506127e4828286612821565b979650505050505050565b60006022825110156128135760405162461bcd60e51b815260040161075e90613403565b506022015190565b3b151590565b60608315612830575081610ced565b8251156128405782518084602001fd5b8160405162461bcd60e51b815260040161075e91906130b5565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061289b57805160ff19168380011785556128c8565b828001600101855582156128c8579182015b828111156128c85782518255916020019190600101906128ad565b506128d4929150612946565b5090565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106129195782800160ff198235161785556128c8565b828001600101855582156128c8579182015b828111156128c857823582559160200191906001019061292b565b5b808211156128d45760008155600101612947565b60008083601f84011261296c578182fd5b5081356001600160401b03811115612982578182fd5b60208301915083602082850101111561299a57600080fd5b9250929050565b600082601f8301126129b1578081fd5b81516129c46129bf826138e7565b6138c1565b91508082528360208285010111156129db57600080fd5b61247081602084016020860161390a565b6000602082840312156129fd578081fd5b8135610ced81613936565b600080600080600080600080600060e08a8c031215612a25578485fd5b8935612a3081613936565b985060208a0135612a4081613959565b975060408a01356001600160401b0380821115612a5b578687fd5b612a678d838e0161295b565b909950975060608c0135965060808c01359150612a8382613936565b90945060a08b013590612a9582613936565b90935060c08b01359080821115612aaa578384fd5b50612ab78c828d0161295b565b915080935050809150509295985092959850929598565b600060208284031215612adf578081fd5b8135610ced8161394b565b600060208284031215612afb578081fd5b8151610ced8161394b565b600060208284031215612b17578081fd5b81356001600160e01b031981168114610ced578182fd5b600060208284031215612b3f578081fd5b81516001600160401b03811115612b54578182fd5b6123a2848285016129a1565b600060208284031215612b71578081fd5b8135610ced81613959565b600080600060408486031215612b90578283fd5b8335612b9b81613959565b925060208401356001600160401b03811115612bb5578283fd5b612bc18682870161295b565b9497909650939450505050565b600080600080600080600060a0888a031215612be8578283fd5b8735612bf381613959565b965060208801356001600160401b0380821115612c0e578485fd5b612c1a8b838c0161295b565b909850965060408a0135955060608a01359150612c368261394b565b90935060808901359080821115612c4b578384fd5b50612c588a828b0161295b565b989b979a50959850939692959293505050565b60008060008060008060808789031215612c83578182fd5b8635612c8e81613959565b955060208701356001600160401b0380821115612ca9578384fd5b612cb58a838b0161295b565b909750955060408901359150612cca82613969565b90935060608801359080821115612cdf578384fd5b50612cec89828a0161295b565b979a9699509497509295939492505050565b600080600060608486031215612d12578081fd5b8351612d1d81613959565b60208501519093506001600160401b03811115612d38578182fd5b612d44868287016129a1565b925050604084015190509250925092565b600080600060608486031215612d69578081fd5b8335612d7481613959565b925060208401356001600160401b03811115612d8e578182fd5b8401601f81018613612d9e578182fd5b8035612dac6129bf826138e7565b818152876020838501011115612dc0578384fd5b816020840160208301379081016020018390529250506040840135612de481613969565b809150509250925092565b60008060408385031215612e01578182fd5b8235612e0c81613959565b91506020830135612e1c81613959565b809150509250929050565b60008060008060808587031215612e3c578182fd5b8435612e4781613959565b93506020850135612e5781613959565b92506040850135612e6781613936565b9396929550929360600135925050565b600080600060608486031215612e8b578081fd5b8335612e9681613959565b92506020840135612ea681613959565b929592945050506040919091013590565b600080600080600060808688031215612ece578283fd5b8535612ed981613959565b94506020860135612ee981613959565b93506040860135925060608601356001600160401b03811115612f0a578182fd5b612f168882890161295b565b969995985093965092949392505050565b60008060408385031215612f39578182fd5b8235612f4481613959565b946020939093013593505050565b600060208284031215612f63578081fd5b5035919050565b600060208284031215612f7b578081fd5b5051919050565b60008060408385031215612f94578182fd5b505080516020909101519092909150565b60008284528282602086013780602084860101526020601f19601f85011685010190509392505050565b60008151808452612fe781602086016020860161390a565b601f01601f19169290920160200192915050565b6000828483379101908152919050565b6000838583375060609190911b6bffffffffffffffffffffffff19169101908152601401919050565b6000825161304681846020870161390a565b9190910192915050565b6001600160a01b0391909116815260200190565b6001600160a01b039384168152919092166020820152604081019190915260600190565b6001600160a01b03929092168252602082015260400190565b901515815260200190565b90815260200190565b600060208252610ced6020830184612fcf565b6000604082526130db6040830185612fcf565b90508260208301529392505050565b6020808252601c908201527f4f4654436f72653a20756e6b6e6f776e207061636b6574207479706500000000604082015260600190565b60208082526026908201527f4e6f6e626c6f636b696e674c7a4170703a2063616c6c6572206d7573742062656040820152650204c7a4170760d41b606082015260800190565b60208082526022908201527f456e756d657261626c655365743a20696e646578206f7574206f6620626f756e604082015261647360f01b606082015260800190565b6020808252601d908201527f4c7a4170703a206e6f20747275737465642070617468207265636f7264000000604082015260600190565b6020808252601b908201527f4c7a4170703a20676173206c696d697420697320746f6f206c6f770000000000604082015260600190565b6020808252601590820152744c7a4170703a20696e76616c6964206d696e47617360581b604082015260600190565b6020808252601a908201527f4c7a4170703a206d696e4761734c696d6974206e6f7420736574000000000000604082015260600190565b60208082526026908201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160408201526564647265737360d01b606082015260800190565b60208082526023908201527f4e6f6e626c6f636b696e674c7a4170703a206e6f2073746f726564206d65737360408201526261676560e81b606082015260800190565b60208082526022908201527f50726f78794f46543a206f776e6572206973206e6f742073656e642063616c6c60408201526132b960f11b606082015260800190565b60208082526026908201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6040820152651c8818d85b1b60d21b606082015260800190565b6020808252600b908201526a27b7363c9036b4b73a32b960a91b604082015260600190565b60208082526030908201527f4c7a4170703a2064657374696e6174696f6e20636861696e206973206e6f742060408201526f61207472757374656420736f7572636560801b606082015260800190565b6020808252601c908201527f4c7a4170703a20696e76616c69642061646170746572506172616d7300000000604082015260600190565b60208082526026908201527f4f4654436f72653a205f61646170746572506172616d73206d7573742062652060408201526532b6b83a3c9760d11b606082015260800190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b6020808252601e908201527f4c7a4170703a20696e76616c696420656e64706f696e742063616c6c65720000604082015260600190565b6020808252601d908201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604082015260600190565b6020808252602a908201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6040820152691bdd081cdd58d8d9595960b21b606082015260800190565b60208082526021908201527f4e6f6e626c6f636b696e674c7a4170703a20696e76616c6964207061796c6f616040820152601960fa1b606082015260800190565b60208082526026908201527f4c7a4170703a20696e76616c696420736f757263652073656e64696e6720636f6040820152651b9d1c9858dd60d21b606082015260800190565b6020808252818101527f4c7a4170703a207061796c6f61642073697a6520697320746f6f206c61726765604082015260600190565b61ffff91909116815260200190565b61ffff871681526001600160a01b038616602082015260a06040820181905260009061366690830187612fcf565b85151560608401528281036080840152613681818587612fa5565b9998505050505050505050565b600061ffff8516825260406020830152611a1f604083018486612fa5565b600061ffff86168252606060208301526136ca606083018587612fa5565b905082604083015295945050505050565b600061ffff87168252608060208301526136f9608083018688612fa5565b6001600160401b0394909416604083015250606001529392505050565b600061ffff8816825260c0602083015261373360c0830188612fcf565b82810360408401526137458188612fcf565b6001600160a01b0387811660608601528616608085015283810360a085015290506136818185612fcf565b600061ffff851682526060602083015261378d6060830185612fcf565b9050826040830152949350505050565b600061ffff86168252608060208301526137ba6080830186612fcf565b6001600160401b038516604084015282810360608401526127e48185612fcf565b600061ffff8716825260a060208301526137f860a0830187612fcf565b6001600160401b038616604084015282810360608401526138198186612fcf565b9050828103608084015261382d8185612fcf565b98975050505050505050565b61ffff94851681529290931660208301526001600160a01b03166040820152606081019190915260800190565b61ffff9384168152919092166020820152604081019190915260600190565b600061ffff8088168352808716602084015250846040830152608060608301526127e4608083018486612fa5565b918252602082015260400190565b6040518181016001600160401b03811182821017156138df57600080fd5b604052919050565b60006001600160401b038211156138fc578081fd5b50601f01601f191660200190565b60005b8381101561392557818101518382015260200161390d565b83811115611fbb5750506000910152565b6001600160a01b0381168114610a6157600080fd5b8015158114610a6157600080fd5b61ffff81168114610a6157600080fd5b6001600160401b0381168114610a6157600080fdfea2646970667358221220ee614c08e2df4abd05ed4d26d2e3b9f05e87a39c3519aedadf3b2690fc053b8664736f6c634300060c0033
Verified Source Code Full Match
Compiler: v0.6.12+commit.27d51765
EVM: istanbul
Optimization: Yes (200 runs)
LzApp.sol 204 lines
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity >=0.6.10 <0.8.0;
pragma experimental ABIEncoderV2;
import "@openzeppelin/contracts/access/Ownable.sol";
import "./interfaces/ILayerZeroReceiver.sol";
import "./interfaces/ILayerZeroUserApplicationConfig.sol";
import "./interfaces/ILayerZeroEndpoint.sol";
import "./utils/BytesLib.sol";
/*
* a generic LzReceiver implementation
*/
abstract contract LzApp is Ownable, ILayerZeroReceiver, ILayerZeroUserApplicationConfig {
using BytesLib for bytes;
// ua can not send payload larger than this by default, but it can be changed by the ua owner
uint256 public constant DEFAULT_PAYLOAD_SIZE_LIMIT = 10000;
ILayerZeroEndpoint public immutable lzEndpoint;
mapping(uint16 => bytes) public trustedRemoteLookup;
mapping(uint16 => mapping(uint16 => uint256)) public minDstGasLookup;
mapping(uint16 => uint256) public payloadSizeLimitLookup;
address public precrime;
event SetPrecrime(address precrime);
event SetTrustedRemote(uint16 _remoteChainId, bytes _path);
event SetTrustedRemoteAddress(uint16 _remoteChainId, bytes _remoteAddress);
event SetMinDstGas(uint16 _dstChainId, uint16 _type, uint256 _minDstGas);
constructor(address _endpoint) public {
lzEndpoint = ILayerZeroEndpoint(_endpoint);
}
function lzReceive(
uint16 _srcChainId,
bytes calldata _srcAddress,
uint64 _nonce,
bytes calldata _payload
) public virtual override {
// lzReceive must be called by the endpoint for security
require(_msgSender() == address(lzEndpoint), "LzApp: invalid endpoint caller");
bytes memory trustedRemote = trustedRemoteLookup[_srcChainId];
// if will still block the message pathway from (srcChainId, srcAddress). should not receive message from untrusted remote.
require(
_srcAddress.length == trustedRemote.length &&
trustedRemote.length > 0 &&
keccak256(_srcAddress) == keccak256(trustedRemote),
"LzApp: invalid source sending contract"
);
_blockingLzReceive(_srcChainId, _srcAddress, _nonce, _payload);
}
// abstract function - the default behaviour of LayerZero is blocking. See: NonblockingLzApp if you dont need to enforce ordered messaging
function _blockingLzReceive(
uint16 _srcChainId,
bytes memory _srcAddress,
uint64 _nonce,
bytes memory _payload
) internal virtual;
function _lzSend(
uint16 _dstChainId,
bytes memory _payload,
address payable _refundAddress,
address _zroPaymentAddress,
bytes memory _adapterParams,
uint256 _nativeFee
) internal virtual {
bytes memory trustedRemote = trustedRemoteLookup[_dstChainId];
require(trustedRemote.length != 0, "LzApp: destination chain is not a trusted source");
_checkPayloadSize(_dstChainId, _payload.length);
lzEndpoint.send{value: _nativeFee}(
_dstChainId,
trustedRemote,
_payload,
_refundAddress,
_zroPaymentAddress,
_adapterParams
);
}
function _checkGasLimit(
uint16 _dstChainId,
uint16 _type,
bytes memory _adapterParams,
uint256 _extraGas
) internal view virtual {
uint256 providedGasLimit = _getGasLimit(_adapterParams);
uint256 minGasLimit = minDstGasLookup[_dstChainId][_type] + _extraGas;
require(minGasLimit > 0, "LzApp: minGasLimit not set");
require(providedGasLimit >= minGasLimit, "LzApp: gas limit is too low");
}
function _getGasLimit(bytes memory _adapterParams)
internal
pure
virtual
returns (uint256 gasLimit)
{
require(_adapterParams.length >= 34, "LzApp: invalid adapterParams");
assembly {
gasLimit := mload(add(_adapterParams, 34))
}
}
function _checkPayloadSize(uint16 _dstChainId, uint256 _payloadSize) internal view virtual {
uint256 payloadSizeLimit = payloadSizeLimitLookup[_dstChainId];
if (payloadSizeLimit == 0) {
// use default if not set
payloadSizeLimit = DEFAULT_PAYLOAD_SIZE_LIMIT;
}
require(_payloadSize <= payloadSizeLimit, "LzApp: payload size is too large");
}
//---------------------------UserApplication config----------------------------------------
function getConfig(
uint16 _version,
uint16 _chainId,
address,
uint256 _configType
) external view returns (bytes memory) {
return lzEndpoint.getConfig(_version, _chainId, address(this), _configType);
}
// generic config for LayerZero user Application
function setConfig(
uint16 _version,
uint16 _chainId,
uint256 _configType,
bytes calldata _config
) external override onlyOwner {
lzEndpoint.setConfig(_version, _chainId, _configType, _config);
}
function setSendVersion(uint16 _version) external override onlyOwner {
lzEndpoint.setSendVersion(_version);
}
function setReceiveVersion(uint16 _version) external override onlyOwner {
lzEndpoint.setReceiveVersion(_version);
}
function forceResumeReceive(uint16 _srcChainId, bytes calldata _srcAddress)
external
override
onlyOwner
{
lzEndpoint.forceResumeReceive(_srcChainId, _srcAddress);
}
// _path = abi.encodePacked(remoteAddress, localAddress)
// this function set the trusted path for the cross-chain communication
function setTrustedRemote(uint16 _remoteChainId, bytes calldata _path) external onlyOwner {
trustedRemoteLookup[_remoteChainId] = _path;
emit SetTrustedRemote(_remoteChainId, _path);
}
function setTrustedRemoteAddress(uint16 _remoteChainId, bytes calldata _remoteAddress)
external
onlyOwner
{
trustedRemoteLookup[_remoteChainId] = abi.encodePacked(_remoteAddress, address(this));
emit SetTrustedRemoteAddress(_remoteChainId, _remoteAddress);
}
function getTrustedRemoteAddress(uint16 _remoteChainId) external view returns (bytes memory) {
bytes memory path = trustedRemoteLookup[_remoteChainId];
require(path.length != 0, "LzApp: no trusted path record");
return path.slice(0, path.length - 20); // the last 20 bytes should be address(this)
}
function setPrecrime(address _precrime) external onlyOwner {
precrime = _precrime;
emit SetPrecrime(_precrime);
}
function setMinDstGas(
uint16 _dstChainId,
uint16 _packetType,
uint256 _minGas
) external onlyOwner {
require(_minGas > 0, "LzApp: invalid minGas");
minDstGasLookup[_dstChainId][_packetType] = _minGas;
emit SetMinDstGas(_dstChainId, _packetType, _minGas);
}
// if the size is 0, it means default size limit
function setPayloadSizeLimit(uint16 _dstChainId, uint256 _size) external onlyOwner {
payloadSizeLimitLookup[_dstChainId] = _size;
}
//--------------------------- VIEW FUNCTION ----------------------------------------
function isTrustedRemote(uint16 _srcChainId, bytes calldata _srcAddress)
external
view
returns (bool)
{
bytes memory trustedSource = trustedRemoteLookup[_srcChainId];
return keccak256(trustedSource) == keccak256(_srcAddress);
}
}
OFTCore.sol 153 lines
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.10 <0.8.0;
import "./NonblockingLzApp.sol";
import "./interfaces/IOFTCore.sol";
import "@openzeppelin/contracts/introspection/ERC165.sol";
abstract contract OFTCore is NonblockingLzApp, ERC165, IOFTCore {
using BytesLib for bytes;
uint256 public constant NO_EXTRA_GAS = 0;
// packet type
uint16 public constant PT_SEND = 0;
bool public useCustomAdapterParams;
constructor(address _lzEndpoint) public NonblockingLzApp(_lzEndpoint) {}
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(ERC165, IERC165)
returns (bool)
{
return interfaceId == type(IOFTCore).interfaceId || super.supportsInterface(interfaceId);
}
function estimateSendFee(
uint16 _dstChainId,
bytes calldata _toAddress,
uint256 _amount,
bool _useZro,
bytes calldata _adapterParams
) public view virtual override returns (uint256 nativeFee, uint256 zroFee) {
// mock the payload for sendFrom()
bytes memory payload = abi.encode(PT_SEND, _toAddress, _amount);
return
lzEndpoint.estimateFees(_dstChainId, address(this), payload, _useZro, _adapterParams);
}
function sendFrom(
address _from,
uint16 _dstChainId,
bytes calldata _toAddress,
uint256 _amount,
address payable _refundAddress,
address _zroPaymentAddress,
bytes calldata _adapterParams
) public payable virtual override {
_send(
_from,
_dstChainId,
_toAddress,
_amount,
_refundAddress,
_zroPaymentAddress,
_adapterParams
);
}
function setUseCustomAdapterParams(bool _useCustomAdapterParams) public virtual onlyOwner {
useCustomAdapterParams = _useCustomAdapterParams;
emit SetUseCustomAdapterParams(_useCustomAdapterParams);
}
function _nonblockingLzReceive(
uint16 _srcChainId,
bytes memory _srcAddress,
uint64 _nonce,
bytes memory _payload
) internal virtual override {
uint16 packetType;
assembly {
packetType := mload(add(_payload, 32))
}
if (packetType == PT_SEND) {
_sendAck(_srcChainId, _srcAddress, _nonce, _payload);
} else {
revert("OFTCore: unknown packet type");
}
}
function _send(
address _from,
uint16 _dstChainId,
bytes memory _toAddress,
uint256 _amount,
address payable _refundAddress,
address _zroPaymentAddress,
bytes memory _adapterParams
) internal virtual {
_checkAdapterParams(_dstChainId, PT_SEND, _adapterParams, NO_EXTRA_GAS);
uint256 amount = _debitFrom(_from, _dstChainId, _toAddress, _amount);
bytes memory lzPayload = abi.encode(PT_SEND, _toAddress, amount);
_lzSend(
_dstChainId,
lzPayload,
_refundAddress,
_zroPaymentAddress,
_adapterParams,
msg.value
);
emit SendToChain(_dstChainId, _from, _toAddress, amount);
}
function _sendAck(
uint16 _srcChainId,
bytes memory,
uint64,
bytes memory _payload
) internal virtual {
(, bytes memory toAddressBytes, uint256 amount) =
abi.decode(_payload, (uint16, bytes, uint256));
address to = toAddressBytes.toAddress(0);
amount = _creditTo(_srcChainId, to, amount);
emit ReceiveFromChain(_srcChainId, to, amount);
}
function _checkAdapterParams(
uint16 _dstChainId,
uint16 _pkType,
bytes memory _adapterParams,
uint256 _extraGas
) internal virtual {
if (useCustomAdapterParams) {
_checkGasLimit(_dstChainId, _pkType, _adapterParams, _extraGas);
} else {
require(_adapterParams.length == 0, "OFTCore: _adapterParams must be empty.");
}
}
function _debitFrom(
address _from,
uint16 _dstChainId,
bytes memory _toAddress,
uint256 _amount
) internal virtual returns (uint256);
function _creditTo(
uint16 _srcChainId,
address _toAddress,
uint256 _amount
) internal virtual returns (uint256);
}
ProxyOFT.sol 47 lines
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.10 <0.8.0;
pragma experimental ABIEncoderV2;
import "./OFTCore.sol";
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
contract ProxyOFT is OFTCore {
using SafeERC20 for IERC20;
IERC20 internal immutable innerToken;
constructor(address _lzEndpoint, address _token) public OFTCore(_lzEndpoint) {
innerToken = IERC20(_token);
}
function circulatingSupply() public view virtual override returns (uint256) {
return innerToken.totalSupply() - innerToken.balanceOf(address(this));
}
function token() public view virtual override returns (address) {
return address(innerToken);
}
function _debitFrom(
address _from,
uint16,
bytes memory,
uint256 _amount
) internal virtual override returns (uint256) {
require(_from == _msgSender(), "ProxyOFT: owner is not send caller");
uint256 before = innerToken.balanceOf(address(this));
innerToken.safeTransferFrom(_from, address(this), _amount);
return innerToken.balanceOf(address(this)) - before;
}
function _creditTo(
uint16,
address _toAddress,
uint256 _amount
) internal virtual override returns (uint256) {
uint256 before = innerToken.balanceOf(_toAddress);
innerToken.safeTransfer(_toAddress, _amount);
return innerToken.balanceOf(_toAddress) - before;
}
}
ChessRoles.sol 42 lines
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity >=0.6.10 <0.8.0;
import "@openzeppelin/contracts/utils/EnumerableSet.sol";
abstract contract ChessRoles {
using EnumerableSet for EnumerableSet.AddressSet;
EnumerableSet.AddressSet private _minterMembers;
event MinterAdded(address indexed minter);
event MinterRemoved(address indexed minter);
modifier onlyMinter() {
require(isMinter(msg.sender), "Only minter");
_;
}
function isMinter(address account) public view returns (bool) {
return _minterMembers.contains(account);
}
function getMinterMember(uint256 index) external view returns (address) {
return _minterMembers.at(index);
}
function getMinterCount() external view returns (uint256) {
return _minterMembers.length();
}
function _addMinter(address minter) internal {
if (_minterMembers.add(minter)) {
emit MinterAdded(minter);
}
}
function _removeMinter(address minter) internal {
if (_minterMembers.remove(minter)) {
emit MinterRemoved(minter);
}
}
}
ProxyOFTPool.sol 26 lines
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity >=0.6.10 <0.8.0;
pragma experimental ABIEncoderV2;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "./ProxyOFT.sol";
import "../governance/ChessRoles.sol";
contract ProxyOFTPool is ProxyOFT, ChessRoles {
constructor(address _lzEndpoint, address _token) public ProxyOFT(_lzEndpoint, _token) {}
function addMinter(address account) external onlyOwner {
_addMinter(account);
}
function removeMinter(address account) external onlyOwner {
_removeMinter(account);
}
function withdrawUnderlying(uint256 amount) external onlyMinter {
IERC20(token()).safeTransfer(msg.sender, amount);
}
}
BytesLib.sol 503 lines
// SPDX-License-Identifier: Unlicense /* * @title Solidity Bytes Arrays Utils * @author Gonçalo Sá <[email protected]> * * @dev Bytes tightly packed arrays utility library for ethereum contracts written in Solidity. * The library lets you concatenate, slice and type cast bytes arrays both in memory and storage. */ pragma solidity >=0.6.10 <0.8.0; library BytesLib { function concat(bytes memory _preBytes, bytes memory _postBytes) internal pure returns (bytes memory) { bytes memory tempBytes; assembly { // Get a location of some free memory and store it in tempBytes as // Solidity does for memory variables. tempBytes := mload(0x40) // Store the length of the first bytes array at the beginning of // the memory for tempBytes. let length := mload(_preBytes) mstore(tempBytes, length) // Maintain a memory counter for the current write location in the // temp bytes array by adding the 32 bytes for the array length to // the starting location. let mc := add(tempBytes, 0x20) // Stop copying when the memory counter reaches the length of the // first bytes array. let end := add(mc, length) for { // Initialize a copy counter to the start of the _preBytes data, // 32 bytes into its memory. let cc := add(_preBytes, 0x20) } lt(mc, end) { // Increase both counters by 32 bytes each iteration. mc := add(mc, 0x20) cc := add(cc, 0x20) } { // Write the _preBytes data into the tempBytes memory 32 bytes // at a time. mstore(mc, mload(cc)) } // Add the length of _postBytes to the current length of tempBytes // and store it as the new length in the first 32 bytes of the // tempBytes memory. length := mload(_postBytes) mstore(tempBytes, add(length, mload(tempBytes))) // Move the memory counter back from a multiple of 0x20 to the // actual end of the _preBytes data. mc := end // Stop copying when the memory counter reaches the new combined // length of the arrays. end := add(mc, length) for { let cc := add(_postBytes, 0x20) } lt(mc, end) { mc := add(mc, 0x20) cc := add(cc, 0x20) } { mstore(mc, mload(cc)) } // Update the free-memory pointer by padding our last write location // to 32 bytes: add 31 bytes to the end of tempBytes to move to the // next 32 byte block, then round down to the nearest multiple of // 32. If the sum of the length of the two arrays is zero then add // one before rounding down to leave a blank 32 bytes (the length block with 0). mstore( 0x40, and( add(add(end, iszero(add(length, mload(_preBytes)))), 31), not(31) // Round down to the nearest 32 bytes. ) ) } return tempBytes; } function concatStorage(bytes storage _preBytes, bytes memory _postBytes) internal { assembly { // Read the first 32 bytes of _preBytes storage, which is the length // of the array. (We don't need to use the offset into the slot // because arrays use the entire slot.) let fslot := sload(_preBytes_slot) // Arrays of 31 bytes or less have an even value in their slot, // while longer arrays have an odd value. The actual length is // the slot divided by two for odd values, and the lowest order // byte divided by two for even values. // If the slot is even, bitwise and the slot with 255 and divide by // two to get the length. If the slot is odd, bitwise and the slot // with -1 and divide by two. let slength := div(and(fslot, sub(mul(0x100, iszero(and(fslot, 1))), 1)), 2) let mlength := mload(_postBytes) let newlength := add(slength, mlength) // slength can contain both the length and contents of the array // if length < 32 bytes so let's prepare for that // v. http://solidity.readthedocs.io/en/latest/miscellaneous.html#layout-of-state-variables-in-storage switch add(lt(slength, 32), lt(newlength, 32)) case 2 { // Since the new array still fits in the slot, we just need to // update the contents of the slot. // uint256(bytes_storage) = uint256(bytes_storage) + uint256(bytes_memory) + new_length sstore( _preBytes_slot, // all the modifications to the slot are inside this // next block add( // we can just add to the slot contents because the // bytes we want to change are the LSBs fslot, add( mul( div( // load the bytes from memory mload(add(_postBytes, 0x20)), // zero all bytes to the right exp(0x100, sub(32, mlength)) ), // and now shift left the number of bytes to // leave space for the length in the slot exp(0x100, sub(32, newlength)) ), // increase length by the double of the memory // bytes length mul(mlength, 2) ) ) ) } case 1 { // The stored value fits in the slot, but the combined value // will exceed it. // get the keccak hash to get the contents of the array mstore(0x0, _preBytes_slot) let sc := add(keccak256(0x0, 0x20), div(slength, 32)) // save new length sstore(_preBytes_slot, add(mul(newlength, 2), 1)) // The contents of the _postBytes array start 32 bytes into // the structure. Our first read should obtain the `submod` // bytes that can fit into the unused space in the last word // of the stored array. To get this, we read 32 bytes starting // from `submod`, so the data we read overlaps with the array // contents by `submod` bytes. Masking the lowest-order // `submod` bytes allows us to add that value directly to the // stored value. let submod := sub(32, slength) let mc := add(_postBytes, submod) let end := add(_postBytes, mlength) let mask := sub(exp(0x100, submod), 1) sstore( sc, add( and( fslot, 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00 ), and(mload(mc), mask) ) ) for { mc := add(mc, 0x20) sc := add(sc, 1) } lt(mc, end) { sc := add(sc, 1) mc := add(mc, 0x20) } { sstore(sc, mload(mc)) } mask := exp(0x100, sub(mc, end)) sstore(sc, mul(div(mload(mc), mask), mask)) } default { // get the keccak hash to get the contents of the array mstore(0x0, _preBytes_slot) // Start copying to the last used word of the stored array. let sc := add(keccak256(0x0, 0x20), div(slength, 32)) // save new length sstore(_preBytes_slot, add(mul(newlength, 2), 1)) // Copy over the first `submod` bytes of the new data as in // case 1 above. let slengthmod := mod(slength, 32) let mlengthmod := mod(mlength, 32) let submod := sub(32, slengthmod) let mc := add(_postBytes, submod) let end := add(_postBytes, mlength) let mask := sub(exp(0x100, submod), 1) sstore(sc, add(sload(sc), and(mload(mc), mask))) for { sc := add(sc, 1) mc := add(mc, 0x20) } lt(mc, end) { sc := add(sc, 1) mc := add(mc, 0x20) } { sstore(sc, mload(mc)) } mask := exp(0x100, sub(mc, end)) sstore(sc, mul(div(mload(mc), mask), mask)) } } } function slice( bytes memory _bytes, uint256 _start, uint256 _length ) internal pure returns (bytes memory) { require(_bytes.length >= (_start + _length)); bytes memory tempBytes; assembly { switch iszero(_length) case 0 { // Get a location of some free memory and store it in tempBytes as // Solidity does for memory variables. tempBytes := mload(0x40) // The first word of the slice result is potentially a partial // word read from the original array. To read it, we calculate // the length of that partial word and start copying that many // bytes into the array. The first word we copy will start with // data we don't care about, but the last `lengthmod` bytes will // land at the beginning of the contents of the new array. When // we're done copying, we overwrite the full first word with // the actual length of the slice. let lengthmod := and(_length, 31) // The multiplication in the next line is necessary // because when slicing multiples of 32 bytes (lengthmod == 0) // the following copy loop was copying the origin's length // and then ending prematurely not copying everything it should. let mc := add(add(tempBytes, lengthmod), mul(0x20, iszero(lengthmod))) let end := add(mc, _length) for { // The multiplication in the next line has the same exact purpose // as the one above. let cc := add( add(add(_bytes, lengthmod), mul(0x20, iszero(lengthmod))), _start ) } lt(mc, end) { mc := add(mc, 0x20) cc := add(cc, 0x20) } { mstore(mc, mload(cc)) } mstore(tempBytes, _length) //update free-memory pointer //allocating the array padded to 32 bytes like the compiler does now mstore(0x40, and(add(mc, 31), not(31))) } //if we want a zero-length slice let's just return a zero-length array default { tempBytes := mload(0x40) mstore(0x40, add(tempBytes, 0x20)) } } return tempBytes; } function toAddress(bytes memory _bytes, uint256 _start) internal pure returns (address) { require(_bytes.length >= (_start + 20)); address tempAddress; assembly { tempAddress := div(mload(add(add(_bytes, 0x20), _start)), 0x1000000000000000000000000) } return tempAddress; } function toUint8(bytes memory _bytes, uint256 _start) internal pure returns (uint8) { require(_bytes.length >= (_start + 1)); uint8 tempUint; assembly { tempUint := mload(add(add(_bytes, 0x1), _start)) } return tempUint; } function toUint16(bytes memory _bytes, uint256 _start) internal pure returns (uint16) { require(_bytes.length >= (_start + 2)); uint16 tempUint; assembly { tempUint := mload(add(add(_bytes, 0x2), _start)) } return tempUint; } function toUint32(bytes memory _bytes, uint256 _start) internal pure returns (uint32) { require(_bytes.length >= (_start + 4)); uint32 tempUint; assembly { tempUint := mload(add(add(_bytes, 0x4), _start)) } return tempUint; } function toUint64(bytes memory _bytes, uint256 _start) internal pure returns (uint64) { require(_bytes.length >= (_start + 8)); uint64 tempUint; assembly { tempUint := mload(add(add(_bytes, 0x8), _start)) } return tempUint; } function toUint96(bytes memory _bytes, uint256 _start) internal pure returns (uint96) { require(_bytes.length >= (_start + 12)); uint96 tempUint; assembly { tempUint := mload(add(add(_bytes, 0xc), _start)) } return tempUint; } function toUint128(bytes memory _bytes, uint256 _start) internal pure returns (uint128) { require(_bytes.length >= (_start + 16)); uint128 tempUint; assembly { tempUint := mload(add(add(_bytes, 0x10), _start)) } return tempUint; } function toUint(bytes memory _bytes, uint256 _start) internal pure returns (uint256) { require(_bytes.length >= (_start + 32)); uint256 tempUint; assembly { tempUint := mload(add(add(_bytes, 0x20), _start)) } return tempUint; } function toBytes32(bytes memory _bytes, uint256 _start) internal pure returns (bytes32) { require(_bytes.length >= (_start + 32)); bytes32 tempBytes32; assembly { tempBytes32 := mload(add(add(_bytes, 0x20), _start)) } return tempBytes32; } function equal(bytes memory _preBytes, bytes memory _postBytes) internal pure returns (bool) { bool success = true; assembly { let length := mload(_preBytes) // if lengths don't match the arrays are not equal switch eq(length, mload(_postBytes)) case 1 { // cb is a circuit breaker in the for loop since there's // no said feature for inline assembly loops // cb = 1 - don't breaker // cb = 0 - break let cb := 1 let mc := add(_preBytes, 0x20) let end := add(mc, length) for { let cc := add(_postBytes, 0x20) // the next line is the loop condition: // while(uint(mc < end) + cb == 2) } eq(add(lt(mc, end), cb), 2) { mc := add(mc, 0x20) cc := add(cc, 0x20) } { // if any of these checks fails then arrays are not equal if iszero(eq(mload(mc), mload(cc))) { // unsuccess: success := 0 cb := 0 } } } default { // unsuccess: success := 0 } } return success; } function equalStorage(bytes storage _preBytes, bytes memory _postBytes) internal view returns (bool) { bool success = true; assembly { // we know _preBytes_offset is 0 let fslot := sload(_preBytes_slot) // Decode the length of the stored array like in concatStorage(). let slength := div(and(fslot, sub(mul(0x100, iszero(and(fslot, 1))), 1)), 2) let mlength := mload(_postBytes) // if lengths don't match the arrays are not equal switch eq(slength, mlength) case 1 { // slength can contain both the length and contents of the array // if length < 32 bytes so let's prepare for that // v. http://solidity.readthedocs.io/en/latest/miscellaneous.html#layout-of-state-variables-in-storage if iszero(iszero(slength)) { switch lt(slength, 32) case 1 { // blank the last byte which is the length fslot := mul(div(fslot, 0x100), 0x100) if iszero(eq(fslot, mload(add(_postBytes, 0x20)))) { // unsuccess: success := 0 } } default { // cb is a circuit breaker in the for loop since there's // no said feature for inline assembly loops // cb = 1 - don't breaker // cb = 0 - break let cb := 1 // get the keccak hash to get the contents of the array mstore(0x0, _preBytes_slot) let sc := keccak256(0x0, 0x20) let mc := add(_postBytes, 0x20) let end := add(mc, mlength) // the next line is the loop condition: // while(uint(mc < end) + cb == 2) for { } eq(add(lt(mc, end), cb), 2) { sc := add(sc, 1) mc := add(mc, 0x20) } { if iszero(eq(sload(sc), mload(mc))) { // unsuccess: success := 0 cb := 0 } } } } } default { // unsuccess: success := 0 } } return success; } }
NonblockingLzApp.sol 110 lines
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.10 <0.8.0;
import "./LzApp.sol";
import "./utils/ExcessivelySafeCall.sol";
/*
* the default LayerZero messaging behaviour is blocking, i.e. any failed message will block the channel
* this abstract class try-catch all fail messages and store locally for future retry. hence, non-blocking
* NOTE: if the srcAddress is not configured properly, it will still block the message pathway from (srcChainId, srcAddress)
*/
abstract contract NonblockingLzApp is LzApp {
using ExcessivelySafeCall for address;
constructor(address _endpoint) public LzApp(_endpoint) {}
mapping(uint16 => mapping(bytes => mapping(uint64 => bytes32))) public failedMessages;
event MessageFailed(
uint16 _srcChainId,
bytes _srcAddress,
uint64 _nonce,
bytes _payload,
bytes _reason
);
event RetryMessageSuccess(
uint16 _srcChainId,
bytes _srcAddress,
uint64 _nonce,
bytes32 _payloadHash
);
// overriding the virtual function in LzReceiver
function _blockingLzReceive(
uint16 _srcChainId,
bytes memory _srcAddress,
uint64 _nonce,
bytes memory _payload
) internal virtual override {
bool success = false;
bytes memory reason;
uint256 gas = gasleft();
if (gas >= 30000) {
(success, reason) = address(this).excessivelySafeCall(
gas - 30000,
150,
abi.encodeWithSelector(
this.nonblockingLzReceive.selector,
_srcChainId,
_srcAddress,
_nonce,
_payload
)
);
}
// try-catch all errors/exceptions
if (!success) {
_storeFailedMessage(_srcChainId, _srcAddress, _nonce, _payload, reason);
}
}
function _storeFailedMessage(
uint16 _srcChainId,
bytes memory _srcAddress,
uint64 _nonce,
bytes memory _payload,
bytes memory _reason
) internal virtual {
failedMessages[_srcChainId][_srcAddress][_nonce] = keccak256(_payload);
emit MessageFailed(_srcChainId, _srcAddress, _nonce, _payload, _reason);
}
function nonblockingLzReceive(
uint16 _srcChainId,
bytes calldata _srcAddress,
uint64 _nonce,
bytes calldata _payload
) public virtual {
// only internal transaction
require(_msgSender() == address(this), "NonblockingLzApp: caller must be LzApp");
_nonblockingLzReceive(_srcChainId, _srcAddress, _nonce, _payload);
}
//@notice override this function
function _nonblockingLzReceive(
uint16 _srcChainId,
bytes memory _srcAddress,
uint64 _nonce,
bytes memory _payload
) internal virtual;
function retryMessage(
uint16 _srcChainId,
bytes calldata _srcAddress,
uint64 _nonce,
bytes calldata _payload
) public payable virtual {
// assert there is message to retry
bytes32 payloadHash = failedMessages[_srcChainId][_srcAddress][_nonce];
require(payloadHash != bytes32(0), "NonblockingLzApp: no stored message");
require(keccak256(_payload) == payloadHash, "NonblockingLzApp: invalid payload");
// clear the stored message
failedMessages[_srcChainId][_srcAddress][_nonce] = bytes32(0);
// execute the message. revert if it fails again
_nonblockingLzReceive(_srcChainId, _srcAddress, _nonce, _payload);
emit RetryMessageSuccess(_srcChainId, _srcAddress, _nonce, payloadHash);
}
}
SafeMath.sol 214 lines
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
/**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/
library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b > a) return (false, 0);
return (true, a - b);
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a / b);
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a % b);
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SafeMath: subtraction overflow");
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) return 0;
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "SafeMath: division by zero");
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "SafeMath: modulo by zero");
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
return a - b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryDiv}.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a % b;
}
}
Address.sol 189 lines
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.2 <0.8.0;
/**
* @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 on 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");
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: value }(data);
return _verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.staticcall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.delegatecall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
Context.sol 24 lines
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
/*
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with GSN meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address payable) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes memory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
}
Ownable.sol 68 lines
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () internal {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
IOFTCore.sol 75 lines
// SPDX-License-Identifier: MIT
pragma solidity >=0.5.0;
import "@openzeppelin/contracts/introspection/IERC165.sol";
/**
* @dev Interface of the IOFT core standard
*/
interface IOFTCore is IERC165 {
/**
* @dev estimate send token `_tokenId` to (`_dstChainId`, `_toAddress`)
* _dstChainId - L0 defined chain id to send tokens too
* _toAddress - dynamic bytes array which contains the address to whom you are sending tokens to on the dstChain
* _amount - amount of the tokens to transfer
* _useZro - indicates to use zro to pay L0 fees
* _adapterParam - flexible bytes array to indicate messaging adapter services in L0
*/
function estimateSendFee(
uint16 _dstChainId,
bytes calldata _toAddress,
uint256 _amount,
bool _useZro,
bytes calldata _adapterParams
) external view returns (uint256 nativeFee, uint256 zroFee);
/**
* @dev send `_amount` amount of token to (`_dstChainId`, `_toAddress`) from `_from`
* `_from` the owner of token
* `_dstChainId` the destination chain identifier
* `_toAddress` can be any size depending on the `dstChainId`.
* `_amount` the quantity of tokens in wei
* `_refundAddress` the address LayerZero refunds if too much message fee is sent
* `_zroPaymentAddress` set to address(0x0) if not paying in ZRO (LayerZero Token)
* `_adapterParams` is a flexible bytes array to indicate messaging adapter services
*/
function sendFrom(
address _from,
uint16 _dstChainId,
bytes calldata _toAddress,
uint256 _amount,
address payable _refundAddress,
address _zroPaymentAddress,
bytes calldata _adapterParams
) external payable;
/**
* @dev returns the circulating amount of tokens on current chain
*/
function circulatingSupply() external view returns (uint256);
/**
* @dev returns the address of the ERC20 token
*/
function token() external view returns (address);
/**
* @dev Emitted when `_amount` tokens are moved from the `_sender` to (`_dstChainId`, `_toAddress`)
* `_nonce` is the outbound nonce
*/
event SendToChain(
uint16 indexed _dstChainId,
address indexed _from,
bytes _toAddress,
uint256 _amount
);
/**
* @dev Emitted when `_amount` tokens are received from `_srcChainId` into the `_toAddress` on the local chain.
* `_nonce` is the inbound nonce.
*/
event ReceiveFromChain(uint16 indexed _srcChainId, address indexed _to, uint256 _amount);
event SetUseCustomAdapterParams(bool _useCustomAdapterParams);
}
IERC20.sol 77 lines
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
EnumerableSet.sol 297 lines
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
/**
* @dev Library for managing
* https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
* types.
*
* Sets have the following properties:
*
* - Elements are added, removed, and checked for existence in constant time
* (O(1)).
* - Elements are enumerated in O(n). No guarantees are made on the ordering.
*
* ```
* contract Example {
* // Add the library methods
* using EnumerableSet for EnumerableSet.AddressSet;
*
* // Declare a set state variable
* EnumerableSet.AddressSet private mySet;
* }
* ```
*
* As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
* and `uint256` (`UintSet`) are supported.
*/
library EnumerableSet {
// To implement this library for multiple types with as little code
// repetition as possible, we write it in terms of a generic Set type with
// bytes32 values.
// The Set implementation uses private functions, and user-facing
// implementations (such as AddressSet) are just wrappers around the
// underlying Set.
// This means that we can only create new EnumerableSets for types that fit
// in bytes32.
struct Set {
// Storage of set values
bytes32[] _values;
// Position of the value in the `values` array, plus 1 because index 0
// means a value is not in the set.
mapping (bytes32 => uint256) _indexes;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function _add(Set storage set, bytes32 value) private returns (bool) {
if (!_contains(set, value)) {
set._values.push(value);
// The value is stored at length-1, but we add 1 to all indexes
// and use 0 as a sentinel value
set._indexes[value] = set._values.length;
return true;
} else {
return false;
}
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function _remove(Set storage set, bytes32 value) private returns (bool) {
// We read and store the value's index to prevent multiple reads from the same storage slot
uint256 valueIndex = set._indexes[value];
if (valueIndex != 0) { // Equivalent to contains(set, value)
// To delete an element from the _values array in O(1), we swap the element to delete with the last one in
// the array, and then remove the last element (sometimes called as 'swap and pop').
// This modifies the order of the array, as noted in {at}.
uint256 toDeleteIndex = valueIndex - 1;
uint256 lastIndex = set._values.length - 1;
// When the value to delete is the last one, the swap operation is unnecessary. However, since this occurs
// so rarely, we still do the swap anyway to avoid the gas cost of adding an 'if' statement.
bytes32 lastvalue = set._values[lastIndex];
// Move the last value to the index where the value to delete is
set._values[toDeleteIndex] = lastvalue;
// Update the index for the moved value
set._indexes[lastvalue] = toDeleteIndex + 1; // All indexes are 1-based
// Delete the slot where the moved value was stored
set._values.pop();
// Delete the index for the deleted slot
delete set._indexes[value];
return true;
} else {
return false;
}
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function _contains(Set storage set, bytes32 value) private view returns (bool) {
return set._indexes[value] != 0;
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function _length(Set storage set) private view returns (uint256) {
return set._values.length;
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function _at(Set storage set, uint256 index) private view returns (bytes32) {
require(set._values.length > index, "EnumerableSet: index out of bounds");
return set._values[index];
}
// Bytes32Set
struct Bytes32Set {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _add(set._inner, value);
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _remove(set._inner, value);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
return _contains(set._inner, value);
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(Bytes32Set storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
return _at(set._inner, index);
}
// AddressSet
struct AddressSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(AddressSet storage set, address value) internal returns (bool) {
return _add(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(AddressSet storage set, address value) internal returns (bool) {
return _remove(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(AddressSet storage set, address value) internal view returns (bool) {
return _contains(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(AddressSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(AddressSet storage set, uint256 index) internal view returns (address) {
return address(uint160(uint256(_at(set._inner, index))));
}
// UintSet
struct UintSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(UintSet storage set, uint256 value) internal returns (bool) {
return _add(set._inner, bytes32(value));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(UintSet storage set, uint256 value) internal returns (bool) {
return _remove(set._inner, bytes32(value));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(UintSet storage set, uint256 value) internal view returns (bool) {
return _contains(set._inner, bytes32(value));
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function length(UintSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(UintSet storage set, uint256 index) internal view returns (uint256) {
return uint256(_at(set._inner, index));
}
}
ERC165.sol 54 lines
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
import "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts may inherit from this and call {_registerInterface} to declare
* their support of an interface.
*/
abstract contract ERC165 is IERC165 {
/*
* bytes4(keccak256('supportsInterface(bytes4)')) == 0x01ffc9a7
*/
bytes4 private constant _INTERFACE_ID_ERC165 = 0x01ffc9a7;
/**
* @dev Mapping of interface ids to whether or not it's supported.
*/
mapping(bytes4 => bool) private _supportedInterfaces;
constructor () internal {
// Derived contracts need only register support for their own interfaces,
// we register support for ERC165 itself here
_registerInterface(_INTERFACE_ID_ERC165);
}
/**
* @dev See {IERC165-supportsInterface}.
*
* Time complexity O(1), guaranteed to always use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return _supportedInterfaces[interfaceId];
}
/**
* @dev Registers the contract as an implementer of the interface defined by
* `interfaceId`. Support of the actual ERC165 interface is automatic and
* registering its interface id is not required.
*
* See {IERC165-supportsInterface}.
*
* Requirements:
*
* - `interfaceId` cannot be the ERC165 invalid interface (`0xffffffff`).
*/
function _registerInterface(bytes4 interfaceId) internal virtual {
require(interfaceId != 0xffffffff, "ERC165: invalid interface id");
_supportedInterfaces[interfaceId] = true;
}
}
IERC165.sol 24 lines
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
SafeERC20.sol 75 lines
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
import "./IERC20.sol";
import "../../math/SafeMath.sol";
import "../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using 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");
}
}
}
ExcessivelySafeCall.sol 133 lines
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.10 <0.8.0;
library ExcessivelySafeCall {
uint256 constant LOW_28_MASK =
0x00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
/// @notice Use when you _really_ really _really_ don't trust the called
/// contract. This prevents the called contract from causing reversion of
/// the caller in as many ways as we can.
/// @dev The main difference between this and a solidity low-level call is
/// that we limit the number of bytes that the callee can cause to be
/// copied to caller memory. This prevents stupid things like malicious
/// contracts returning 10,000,000 bytes causing a local OOG when copying
/// to memory.
/// @param _target The address to call
/// @param _gas The amount of gas to forward to the remote contract
/// @param _maxCopy The maximum number of bytes of returndata to copy
/// to memory.
/// @param _calldata The data to send to the remote contract
/// @return success and returndata, as `.call()`. Returndata is capped to
/// `_maxCopy` bytes.
function excessivelySafeCall(
address _target,
uint256 _gas,
uint16 _maxCopy,
bytes memory _calldata
) internal returns (bool, bytes memory) {
// set up for assembly call
uint256 _toCopy;
bool _success;
bytes memory _returnData = new bytes(_maxCopy);
// dispatch message to recipient
// by assembly calling "handle" function
// we call via assembly to avoid memcopying a very large returndata
// returned by a malicious contract
assembly {
_success := call(
_gas, // gas
_target, // recipient
0, // ether value
add(_calldata, 0x20), // inloc
mload(_calldata), // inlen
0, // outloc
0 // outlen
)
// limit our copy to 256 bytes
_toCopy := returndatasize()
if gt(_toCopy, _maxCopy) {
_toCopy := _maxCopy
}
// Store the length of the copied bytes
mstore(_returnData, _toCopy)
// copy the bytes from returndata[0:_toCopy]
returndatacopy(add(_returnData, 0x20), 0, _toCopy)
}
return (_success, _returnData);
}
/// @notice Use when you _really_ really _really_ don't trust the called
/// contract. This prevents the called contract from causing reversion of
/// the caller in as many ways as we can.
/// @dev The main difference between this and a solidity low-level call is
/// that we limit the number of bytes that the callee can cause to be
/// copied to caller memory. This prevents stupid things like malicious
/// contracts returning 10,000,000 bytes causing a local OOG when copying
/// to memory.
/// @param _target The address to call
/// @param _gas The amount of gas to forward to the remote contract
/// @param _maxCopy The maximum number of bytes of returndata to copy
/// to memory.
/// @param _calldata The data to send to the remote contract
/// @return success and returndata, as `.call()`. Returndata is capped to
/// `_maxCopy` bytes.
function excessivelySafeStaticCall(
address _target,
uint256 _gas,
uint16 _maxCopy,
bytes memory _calldata
) internal view returns (bool, bytes memory) {
// set up for assembly call
uint256 _toCopy;
bool _success;
bytes memory _returnData = new bytes(_maxCopy);
// dispatch message to recipient
// by assembly calling "handle" function
// we call via assembly to avoid memcopying a very large returndata
// returned by a malicious contract
assembly {
_success := staticcall(
_gas, // gas
_target, // recipient
add(_calldata, 0x20), // inloc
mload(_calldata), // inlen
0, // outloc
0 // outlen
)
// limit our copy to 256 bytes
_toCopy := returndatasize()
if gt(_toCopy, _maxCopy) {
_toCopy := _maxCopy
}
// Store the length of the copied bytes
mstore(_returnData, _toCopy)
// copy the bytes from returndata[0:_toCopy]
returndatacopy(add(_returnData, 0x20), 0, _toCopy)
}
return (_success, _returnData);
}
/**
* @notice Swaps function selectors in encoded contract calls
* @dev Allows reuse of encoded calldata for functions with identical
* argument types but different names. It simply swaps out the first 4 bytes
* for the new selector. This function modifies memory in place, and should
* only be used with caution.
* @param _newSelector The new 4-byte selector
* @param _buf The encoded contract args
*/
function swapSelector(bytes4 _newSelector, bytes memory _buf) internal pure {
require(_buf.length >= 4);
uint256 _mask = LOW_28_MASK;
assembly {
// load the first word of
let _word := mload(add(_buf, 0x20))
// mask out the top 4 bytes
// /x
_word := and(_word, _mask)
_word := or(_newSelector, _word)
mstore(add(_buf, 0x20), _word)
}
}
}
ILayerZeroEndpoint.sol 125 lines
// SPDX-License-Identifier: MIT
pragma solidity >=0.5.0;
import "./ILayerZeroUserApplicationConfig.sol";
interface ILayerZeroEndpoint is ILayerZeroUserApplicationConfig {
// @notice send a LayerZero message to the specified address at a LayerZero endpoint.
// @param _dstChainId - the destination chain identifier
// @param _destination - the address on destination chain (in bytes). address length/format may vary by chains
// @param _payload - a custom bytes payload to send to the destination contract
// @param _refundAddress - if the source transaction is cheaper than the amount of value passed, refund the additional amount to this address
// @param _zroPaymentAddress - the address of the ZRO token holder who would pay for the transaction
// @param _adapterParams - parameters for custom functionality. e.g. receive airdropped native gas from the relayer on destination
function send(
uint16 _dstChainId,
bytes calldata _destination,
bytes calldata _payload,
address payable _refundAddress,
address _zroPaymentAddress,
bytes calldata _adapterParams
) external payable;
// @notice used by the messaging library to publish verified payload
// @param _srcChainId - the source chain identifier
// @param _srcAddress - the source contract (as bytes) at the source chain
// @param _dstAddress - the address on destination chain
// @param _nonce - the unbound message ordering nonce
// @param _gasLimit - the gas limit for external contract execution
// @param _payload - verified payload to send to the destination contract
function receivePayload(
uint16 _srcChainId,
bytes calldata _srcAddress,
address _dstAddress,
uint64 _nonce,
uint256 _gasLimit,
bytes calldata _payload
) external;
// @notice get the inboundNonce of a lzApp from a source chain which could be EVM or non-EVM chain
// @param _srcChainId - the source chain identifier
// @param _srcAddress - the source chain contract address
function getInboundNonce(uint16 _srcChainId, bytes calldata _srcAddress)
external
view
returns (uint64);
// @notice get the outboundNonce from this source chain which, consequently, is always an EVM
// @param _srcAddress - the source chain contract address
function getOutboundNonce(uint16 _dstChainId, address _srcAddress)
external
view
returns (uint64);
// @notice gets a quote in source native gas, for the amount that send() requires to pay for message delivery
// @param _dstChainId - the destination chain identifier
// @param _userApplication - the user app address on this EVM chain
// @param _payload - the custom message to send over LayerZero
// @param _payInZRO - if false, user app pays the protocol fee in native token
// @param _adapterParam - parameters for the adapter service, e.g. send some dust native token to dstChain
function estimateFees(
uint16 _dstChainId,
address _userApplication,
bytes calldata _payload,
bool _payInZRO,
bytes calldata _adapterParam
) external view returns (uint256 nativeFee, uint256 zroFee);
// @notice get this Endpoint's immutable source identifier
function getChainId() external view returns (uint16);
// @notice the interface to retry failed message on this Endpoint destination
// @param _srcChainId - the source chain identifier
// @param _srcAddress - the source chain contract address
// @param _payload - the payload to be retried
function retryPayload(
uint16 _srcChainId,
bytes calldata _srcAddress,
bytes calldata _payload
) external;
// @notice query if any STORED payload (message blocking) at the endpoint.
// @param _srcChainId - the source chain identifier
// @param _srcAddress - the source chain contract address
function hasStoredPayload(uint16 _srcChainId, bytes calldata _srcAddress)
external
view
returns (bool);
// @notice query if the _libraryAddress is valid for sending msgs.
// @param _userApplication - the user app address on this EVM chain
function getSendLibraryAddress(address _userApplication) external view returns (address);
// @notice query if the _libraryAddress is valid for receiving msgs.
// @param _userApplication - the user app address on this EVM chain
function getReceiveLibraryAddress(address _userApplication) external view returns (address);
// @notice query if the non-reentrancy guard for send() is on
// @return true if the guard is on. false otherwise
function isSendingPayload() external view returns (bool);
// @notice query if the non-reentrancy guard for receive() is on
// @return true if the guard is on. false otherwise
function isReceivingPayload() external view returns (bool);
// @notice get the configuration of the LayerZero messaging library of the specified version
// @param _version - messaging library version
// @param _chainId - the chainId for the pending config change
// @param _userApplication - the contract address of the user application
// @param _configType - type of configuration. every messaging library has its own convention.
function getConfig(
uint16 _version,
uint16 _chainId,
address _userApplication,
uint256 _configType
) external pure returns (bytes memory);
// @notice get the send() LayerZero messaging library version
// @param _userApplication - the contract address of the user application
function getSendVersion(address _userApplication) external pure returns (uint16);
// @notice get the lzReceive() LayerZero messaging library version
// @param _userApplication - the contract address of the user application
function getReceiveVersion(address _userApplication) external pure returns (uint16);
}
ILayerZeroReceiver.sol 17 lines
// SPDX-License-Identifier: MIT
pragma solidity >=0.5.0;
interface ILayerZeroReceiver {
// @notice LayerZero endpoint will invoke this function to deliver the message on the destination
// @param _srcChainId - the source endpoint identifier
// @param _srcAddress - the source sending contract address from the source chain
// @param _nonce - the ordered message nonce
// @param _payload - the signed payload is the UA bytes has encoded to be sent
function lzReceive(
uint16 _srcChainId,
bytes calldata _srcAddress,
uint64 _nonce,
bytes calldata _payload
) external;
}
ILayerZeroUserApplicationConfig.sol 30 lines
// SPDX-License-Identifier: MIT
pragma solidity >=0.5.0;
interface ILayerZeroUserApplicationConfig {
// @notice set the configuration of the LayerZero messaging library of the specified version
// @param _version - messaging library version
// @param _chainId - the chainId for the pending config change
// @param _configType - type of configuration. every messaging library has its own convention.
// @param _config - configuration in the bytes. can encode arbitrary content.
function setConfig(
uint16 _version,
uint16 _chainId,
uint256 _configType,
bytes calldata _config
) external;
// @notice set the send() LayerZero messaging library version to _version
// @param _version - new messaging library version
function setSendVersion(uint16 _version) external;
// @notice set the lzReceive() LayerZero messaging library version to _version
// @param _version - new messaging library version
function setReceiveVersion(uint16 _version) external;
// @notice Only when the UA needs to resume the message flow in blocking mode and clear the stored payload
// @param _srcChainId - the chainId of the source chain
// @param _srcAddress - the contract address of the source contract at the source chain
function forceResumeReceive(uint16 _srcChainId, bytes calldata _srcAddress) external;
}
Read Contract
DEFAULT_PAYLOAD_SIZE_LIMIT 0xc4461834 → uint256
NO_EXTRA_GAS 0x44770515 → uint256
PT_SEND 0x4c42899a → uint16
circulatingSupply 0x9358928b → uint256
estimateSendFee 0x2a205e3d → uint256, uint256
failedMessages 0x5b8c41e6 → bytes32
getConfig 0xf5ecbdbc → bytes
getMinterCount 0x8dbb94eb → uint256
getMinterMember 0x1b955b3f → address
getTrustedRemoteAddress 0x9f38369a → bytes
isMinter 0xaa271e1a → bool
isTrustedRemote 0x3d8b38f6 → bool
lzEndpoint 0xb353aaa7 → address
minDstGasLookup 0x8cfd8f5c → uint256
owner 0x8da5cb5b → address
payloadSizeLimitLookup 0x3f1f4fa4 → uint256
precrime 0x950c8a74 → address
supportsInterface 0x01ffc9a7 → bool
token 0xfc0c546a → address
trustedRemoteLookup 0x7533d788 → bytes
useCustomAdapterParams 0xed629c5c → bool
Write Contract 19 functions
These functions modify contract state and require a wallet transaction to execute.
addMinter 0x983b2d56
address account
forceResumeReceive 0x42d65a8d
uint16 _srcChainId
bytes _srcAddress
lzReceive 0x001d3567
uint16 _srcChainId
bytes _srcAddress
uint64 _nonce
bytes _payload
nonblockingLzReceive 0x66ad5c8a
uint16 _srcChainId
bytes _srcAddress
uint64 _nonce
bytes _payload
removeMinter 0x3092afd5
address account
renounceOwnership 0x715018a6
No parameters
retryMessage 0xd1deba1f
uint16 _srcChainId
bytes _srcAddress
uint64 _nonce
bytes _payload
sendFrom 0x51905636
address _from
uint16 _dstChainId
bytes _toAddress
uint256 _amount
address _refundAddress
address _zroPaymentAddress
bytes _adapterParams
setConfig 0xcbed8b9c
uint16 _version
uint16 _chainId
uint256 _configType
bytes _config
setMinDstGas 0xdf2a5b3b
uint16 _dstChainId
uint16 _packetType
uint256 _minGas
setPayloadSizeLimit 0x0df37483
uint16 _dstChainId
uint256 _size
setPrecrime 0xbaf3292d
address _precrime
setReceiveVersion 0x10ddb137
uint16 _version
setSendVersion 0x07e0db17
uint16 _version
setTrustedRemote 0xeb8d72b7
uint16 _remoteChainId
bytes _path
setTrustedRemoteAddress 0xa6c3d165
uint16 _remoteChainId
bytes _remoteAddress
setUseCustomAdapterParams 0xeab45d9c
bool _useCustomAdapterParams
transferOwnership 0xf2fde38b
address newOwner
withdrawUnderlying 0x1071a290
uint256 amount
Recent Transactions
This address has 1 on-chain transactions, but only 0.7% of the chain is indexed. Transactions will appear as indexing progresses. View on Etherscan →