Cryo Explorer Ethereum Mainnet

Address Contract Partially Verified

Address 0x06f0b83EaEd9aA9F94a9Bfe1b06b7Ef711f9E632
Balance 0.018360 ETH
Nonce 1
Code Size 12354 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

12354 bytes
0x6080604052600436106102c65760003560e01c80639010d07c11610179578063cb2840c5116100d6578063e177246e1161008a578063ec120a0011610064578063ec120a0014610861578063f72e754114610876578063fb8ec9721461089657600080fd5b8063e177246e146107eb578063e208f4041461080b578063e6227e1d1461082b57600080fd5b8063d70afa96116100bb578063d70afa9614610777578063d823abe1146107ab578063d9facbe0146107cb57600080fd5b8063cb2840c514610737578063d547741f1461075757600080fd5b8063a217fddf1161012d578063a9cf69fa11610112578063a9cf69fa146106ca578063c70bf0b5146106f7578063ca15c8731461071757600080fd5b8063a217fddf14610681578063a819e6121461069657600080fd5b80639593c69c1161015e5780639593c69c146106325780639a8a059214610647578063a194855d1461066157600080fd5b80639010d07c146105b457806391d14854146105ec57600080fd5b806336568abe116102275780635c975abb116101db57806369e15404116101c057806369e154041461056957806369fe0e2d1461057f5780638456cb591461059f57600080fd5b80635c975abb1461053b57806362397e671461055357600080fd5b80633f4ba83a1161020c5780633f4ba83a146104bf578063412e7e48146104d45780634e0df3f6146104f457600080fd5b806336568abe146104895780633803c8ae146104a957600080fd5b80631ffd69c91161027e5780632674c5d2116102635780632674c5d2146104295780632f2ff15d146104495780633268af191461046957600080fd5b80631ffd69c9146103b6578063248a9ca3146103f857600080fd5b80630a55c9eb116102af5780630a55c9eb146103155780630fa14bc4146103655780631c8ad59d1461039657600080fd5b806301ffc9a7146102cb57806305e2ca1714610300575b600080fd5b3480156102d757600080fd5b506102eb6102e6366004612ad8565b6108b6565b60405190151581526020015b60405180910390f35b61031361030e366004612b4b565b6108e1565b005b34801561032157600080fd5b5061034c610330366004612b30565b60066020526000908152604090205467ffffffffffffffff1681565b60405167ffffffffffffffff90911681526020016102f7565b34801561037157600080fd5b5060045461038490610100900460ff1681565b60405160ff90911681526020016102f7565b3480156103a257600080fd5b506103136103b1366004612b99565b610b0e565b3480156103c257600080fd5b506103ea7f7a7f93da7881f25596461ac5224f10aa39a3e886571a91a521f6df78778f864981565b6040519081526020016102f7565b34801561040457600080fd5b506103ea610413366004612a78565b6000908152600160208190526040909120015490565b34801561043557600080fd5b50610313610444366004612b30565b610d35565b34801561045557600080fd5b50610313610464366004612a91565b610de0565b34801561047557600080fd5b50610313610484366004612991565b610e07565b34801561049557600080fd5b506103136104a4366004612a91565b610ec5565b3480156104b557600080fd5b506103ea60055481565b3480156104cb57600080fd5b50610313610ee7565b3480156104e057600080fd5b506103136104ef366004612991565b610f4b565b34801561050057600080fd5b506103ea61050f366004612a91565b60008281526002602090815260408083206001600160a01b038516845260010190915290205492915050565b34801561054757600080fd5b5060005460ff166102eb565b34801561055f57600080fd5b506103ea613f4881565b34801561057557600080fd5b506103ea60035481565b34801561058b57600080fd5b5061031361059a366004612a78565b610fd6565b3480156105ab57600080fd5b506103136110b0565b3480156105c057600080fd5b506105d46105cf366004612ab6565b611112565b6040516001600160a01b0390911681526020016102f7565b3480156105f857600080fd5b506102eb610607366004612a91565b60009182526001602090815260408084206001600160a01b0393909316845291905290205460ff1690565b34801561063e57600080fd5b506103ea611131565b34801561065357600080fd5b506004546103849060ff1681565b34801561066d57600080fd5b5061031361067c3660046129ca565b611161565b34801561068d57600080fd5b506103ea600081565b3480156106a257600080fd5b506103ea7fb874c3e2d372107e47665c12610d24deb8195460c58dbbf5ed49e34e1889cde981565b3480156106d657600080fd5b506106ea6106e5366004612b99565b61125f565b6040516102f79190612e1c565b34801561070357600080fd5b506102eb610712366004612b02565b611310565b34801561072357600080fd5b506103ea610732366004612a78565b6113b5565b34801561074357600080fd5b50610313610752366004612974565b6113cc565b34801561076357600080fd5b50610313610772366004612a91565b61151a565b34801561078357600080fd5b506103ea7fa1496c3abf9cd93b84db10ae569b57fafa04deeeb7ece4167616ad50e35bc56e81565b3480156107b757600080fd5b506103136107c6366004612c17565b611524565b3480156107d757600080fd5b506102eb6107e6366004612974565b61183f565b3480156107f757600080fd5b50610313610806366004612a78565b61187f565b34801561081757600080fd5b50610313610826366004612a0c565b611930565b34801561083757600080fd5b506105d4610846366004612a78565b6007602052600090815260409020546001600160a01b031681565b34801561086d57600080fd5b506103ea608081565b34801561088257600080fd5b50610313610891366004612bd5565b611a4c565b3480156108a257600080fd5b506103136108b1366004612974565b611f1c565b60006001600160e01b03198216635a05180f60e01b14806108db57506108db826122dc565b92915050565b60005460ff161561092c5760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b60448201526064015b60405180910390fd5b6003543481111561097f5760405162461bcd60e51b815260206004820152601d60248201527f48796472614272696467653a2066656520696e73756666696369656e740000006044820152606401610923565b6000848152600760205260409020546001600160a01b0316806109e45760405162461bcd60e51b815260206004820152601c60248201527f48796472614272696467653a207661756c74206e6f7420666f756e64000000006044820152606401610923565b60ff8616600090815260066020526040812080548290610a0d9067ffffffffffffffff16612f47565b91906101000a81548167ffffffffffffffff021916908367ffffffffffffffff160217905590506000829050806001600160a01b031663d01616c08534610a549190612ece565b898b86338c8c6040518863ffffffff1660e01b8152600401610a7b96959493929190612d9b565b6000604051808303818588803b158015610a9457600080fd5b505af1158015610aa8573d6000803e3d6000fd5b50506040805160ff8d168152602081018c905267ffffffffffffffff8716918101919091527fdbb69440df8433824a026ef190652f29929eb64b4d1d5d2a69be8afe3e6eaed893506060019150610afc9050565b60405180910390a15050505050505050565b3360009081527f252a3b06006280692377c43f440dad5c4b19614037f66848503e8cf2c79bc69f602052604090205460ff16610b8c5760405162461bcd60e51b815260206004820152601f60248201527f48796472614272696467653a204f6e6c7920446566656e64657220526f6c65006044820152606401610923565b68ffffffffffffffff00600883811b9190911660ff8516176000818152602092835260408082208583529093529190912060046003820154600160801b900460ff166004811115610bdf57610bdf612f85565b1415610c535760405162461bcd60e51b815260206004820152602760248201527f48796472614272696467653a2050726f706f73616c20616c726561647920636160448201527f6e63656c6c6564000000000000000000000000000000000000000000000000006064820152608401610923565b8060010154431115610ccd5760405162461bcd60e51b815260206004820152602a60248201527f48796472614272696467653a2043616e63656c6c6174696f6e2074696d65206860448201527f61732065787069726564000000000000000000000000000000000000000000006064820152608401610923565b60038101805460ff60801b19167004000000000000000000000000000000001790556040517fd84b8ef9d47d1afd51b62d1b29444ba3720a5a2ed2ade3f3dc079b6621e8fbc490610d2690879087906004908890612e61565b60405180910390a15050505050565b336000908152600080516020612ff6833981519152602052604090205460ff16610d8f5760405162461bcd60e51b815260206004820152601c60248201526000805160206130168339815191526044820152606401610923565b6004805461ff00191661010060ff8416908102919091179091556040519081527f8ca1ece3028ec079deed6ae2cf1021e96d97aefd38c4026f94164cc347f917da906020015b60405180910390a150565b610dea828261210c565b6000828152600260205260409020610e0290826120f7565b505050565b336000908152600080516020612ff6833981519152602052604090205460ff16610e615760405162461bcd60e51b815260206004820152601c60248201526000805160206130168339815191526044820152606401610923565b6040516307b7ed9960e01b81526001600160a01b0382811660048301528391908216906307b7ed99906024015b600060405180830381600087803b158015610ea857600080fd5b505af1158015610ebc573d6000803e3d6000fd5b50505050505050565b610ecf8282612311565b6000828152600260205260409020610e029082612399565b336000908152600080516020612ff6833981519152602052604090205460ff16610f415760405162461bcd60e51b815260206004820152601c60248201526000805160206130168339815191526044820152606401610923565b610f496123ae565b565b336000908152600080516020612ff6833981519152602052604090205460ff16610fa55760405162461bcd60e51b815260206004820152601c60248201526000805160206130168339815191526044820152606401610923565b60405163ed1e256360e01b81526001600160a01b03828116600483015283919082169063ed1e256390602401610e8e565b3360009081527fb430885b2fd8ad5c711883989efa8a81a8244e77d7ee19caf947074a66cbfadf602052604090205460ff166110545760405162461bcd60e51b815260206004820181905260248201527f48796472614272696467653a204f6e6c79204665652041646d696e20526f6c656044820152606401610923565b6706f05b59d3b2000081106110ab5760405162461bcd60e51b815260206004820152601d60248201527f666565206d757374206265206c657373207468616e20302e35206574680000006044820152606401610923565b600355565b336000908152600080516020612ff6833981519152602052604090205460ff1661110a5760405162461bcd60e51b815260206004820152601c60248201526000805160206130168339815191526044820152606401610923565b610f4961244a565b600082815260026020526040812061112a90836124c5565b9392505050565b600061115c7fb874c3e2d372107e47665c12610d24deb8195460c58dbbf5ed49e34e1889cde96113b5565b905090565b336000908152600080516020612ff6833981519152602052604090205460ff166111bb5760405162461bcd60e51b815260206004820152601c60248201526000805160206130168339815191526044820152606401610923565b6000828152600760205260409081902080547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b038681169182179092559151630b08635360e11b8152600481018590529083166024820152849190631610c6a690604401600060405180830381600087803b15801561124157600080fd5b505af1158015611255573d6000803e3d6000fd5b5050505050505050565b611267612870565b60ff848116600885811b68ffffffffffffffff001691909117600081815260209283526040808220878352845290819020815160a0810183528154815260018201549481019490945260028101549184019190915260038101546001600160801b0381166060850152919390916080840191600160801b9091041660048111156112f3576112f3612f85565b600481111561130457611304612f85565b90525095945050505050565b68ffffffffffffffffff831660009081526008602090815260408083208584528252808320815160a0810183528154815260018201549381019390935260028101549183019190915260038101546001600160801b03811660608401526113ad9291906080830190600160801b900460ff16600481111561139357611393612f85565b60048111156113a4576113a4612f85565b905250836124d1565b949350505050565b60008181526002602052604081206108db906124f4565b336000908152600080516020612ff6833981519152602052604090205460ff166114265760405162461bcd60e51b815260206004820152601c60248201526000805160206130168339815191526044820152606401610923565b6001600160a01b03811660009081527f0fb7de52cd1e5f97a6b0bfe11caee4038f434419823a0cd9c94f7883849ecd7b602052604090205460ff166114b75760405162461bcd60e51b815260206004820152602160248201527f48796472614272696467653a2075736572206973206e6f74206f6273657276656044820152603960f91b6064820152608401610923565b6114e17fb874c3e2d372107e47665c12610d24deb8195460c58dbbf5ed49e34e1889cde98261151a565b6040516001600160a01b03821681527fead397c44bfca7a31cf9a5fcbda7c84f8c50275b4d87e7ec8fa05cce3461472f90602001610dd5565b610ecf82826124fe565b3360009081527f0fb7de52cd1e5f97a6b0bfe11caee4038f434419823a0cd9c94f7883849ecd7b602052604090205460ff166115a25760405162461bcd60e51b815260206004820152601f60248201527f48796472614272696467653a204f6e6c79204f6273657276657220526f6c65006044820152606401610923565b60005460ff16156115e85760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610923565b60008181526007602090815260408083205490516001600160a01b0390911692916116199184918891889101612ccb565b60408051601f19818403018152918152815160209283012068ffffffffffffffff0060088a811b9190911660ff8c161760008181529185528382208383529094529190912090925060026003820154600160801b900460ff16600481111561168357611683612f85565b146116f65760405162461bcd60e51b815260206004820152603060248201527f48796472614272696467653a2050726f706f73616c206e6f7420666f756e642060448201527f6f72206e6f7420636f6e6669726d6564000000000000000000000000000000006064820152608401610923565b8060010154431161176f5760405162461bcd60e51b815260206004820152602960248201527f48796472614272696467653a2050726f706f73616c20697320696e2064656c6160448201527f79656420737461746500000000000000000000000000000000000000000000006064820152608401610923565b60038101805460ff60801b191670030000000000000000000000000000000017905560405163e9ae5c5360e01b815284906001600160a01b0382169063e9ae5c53906117c39089908c908c90600401612d78565b600060405180830381600087803b1580156117dd57600080fd5b505af11580156117f1573d6000803e3d6000fd5b505050507fd84b8ef9d47d1afd51b62d1b29444ba3720a5a2ed2ade3f3dc079b6621e8fbc48a8a60038760405161182b9493929190612e61565b60405180910390a150505050505050505050565b6001600160a01b03811660009081527f0fb7de52cd1e5f97a6b0bfe11caee4038f434419823a0cd9c94f7883849ecd7b602052604081205460ff166108db565b336000908152600080516020612ff6833981519152602052604090205460ff166118d95760405162461bcd60e51b815260206004820152601c60248201526000805160206130168339815191526044820152606401610923565b613f4881111561192b5760405162461bcd60e51b815260206004820152601e60248201527f64656c6179206d757374206265206c657373207468616e2033206461797300006044820152606401610923565b600555565b3360009081527fb430885b2fd8ad5c711883989efa8a81a8244e77d7ee19caf947074a66cbfadf602052604090205460ff166119ae5760405162461bcd60e51b815260206004820181905260248201527f48796472614272696467653a204f6e6c79204665652041646d696e20526f6c656044820152606401610923565b8260005b81811015611a44578585828181106119cc576119cc612fb1565b90506020020160208101906119e19190612974565b6001600160a01b03166108fc8585848181106119ff576119ff612fb1565b905060200201359081150290604051600060405180830381858888f19350505050158015611a31573d6000803e3d6000fd5b5080611a3c81612f2c565b9150506119b2565b505050505050565b3360009081527f0fb7de52cd1e5f97a6b0bfe11caee4038f434419823a0cd9c94f7883849ecd7b602052604090205460ff16611aca5760405162461bcd60e51b815260206004820152601f60248201527f48796472614272696467653a204f6e6c79204f6273657276657220526f6c65006044820152606401610923565b60005460ff1615611b105760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610923565b60ff848116600885811b68ffffffffffffffff0016919091176000818152602092835260408082208683528452808220815160a0810183528154815260018201549581019590955260028101549185019190915260038101546001600160801b0381166060860152929491939290916080840191600160801b9004166004811115611b9d57611b9d612f85565b6004811115611bae57611bae612f85565b9052506000858152600760205260409020549091506001600160a01b0316611c185760405162461bcd60e51b815260206004820152601a60248201527f48796472614272696467653a20496e76616c6964205661756c740000000000006044820152606401610923565b600181608001516004811115611c3057611c30612f85565b1115611c8a5760405162461bcd60e51b8152602060048201526024808201527f48796472614272696467653a20496e76616c69642070726f706f73616c2073746044820152636174757360e01b6064820152608401610923565b611c9481336124d1565b15611ced5760405162461bcd60e51b815260206004820152602360248201527f48796472614272696467653a204f6273657276657220616c726561647920766f6044820152621d195960ea1b6064820152608401610923565b600081608001516004811115611d0557611d05612f85565b1415611d91576040518060a00160405280600081526020016000815260200143815260200160006001600160801b0316815260200160016004811115611d4d57611d4d612f85565b81525090507fd84b8ef9d47d1afd51b62d1b29444ba3720a5a2ed2ade3f3dc079b6621e8fbc48686600186604051611d889493929190612e61565b60405180910390a15b611d9a33612525565b606082018051919091176001600160801b03169052805181611dbb82612f2c565b90525060808101516040517f7efa511cdcc215a70d75eb2dd319d00d9b9e4c0d478ab530f1634fc03d09fc7991611df791899189918890612e61565b60405180910390a1600454815161010090910460ff1611611e6b5760026080820152600554611e269043612e97565b60208201526040517fd84b8ef9d47d1afd51b62d1b29444ba3720a5a2ed2ade3f3dc079b6621e8fbc490611e6290889088906002908890612e61565b60405180910390a15b68ffffffffffffffffff821660009081526008602090815260408083208684528252918290208351815590830151600182015590820151600282015560608201516003820180546fffffffffffffffffffffffffffffffff1981166001600160801b039093169283178255608085015185949390929170ffffffffffffffffffffffffffffffffff191617600160801b836004811115611f0d57611f0d612f85565b02179055505050505050505050565b336000908152600080516020612ff6833981519152602052604090205460ff16611f765760405162461bcd60e51b815260206004820152601c60248201526000805160206130168339815191526044820152606401610923565b6001600160a01b03811660009081527f0fb7de52cd1e5f97a6b0bfe11caee4038f434419823a0cd9c94f7883849ecd7b602052604090205460ff16156120245760405162461bcd60e51b815260206004820152602860248201527f48796472614272696467653a207573657220697320616c726561647920616e2060448201527f6f627365727665720000000000000000000000000000000000000000000000006064820152608401610923565b608061202e611131565b106120865760405162461bcd60e51b815260206004820152602260248201527f48796472614272696467653a206d6178206f6273657276657273207265616368604482015261195960f21b6064820152608401610923565b6120b07fb874c3e2d372107e47665c12610d24deb8195460c58dbbf5ed49e34e1889cde982610de0565b6040516001600160a01b03821681527f9e7e83ca24653c9e3f411044ebe8b4556a45c28aea2d89b408c19cb1c57fc05a90602001610dd5565b6120f38282612573565b5050565b600061112a836001600160a01b0384166125fa565b600082815260016020819052604090912001546121298133612649565b610e028383612573565b60606000612142836002612eaf565b61214d906002612e97565b67ffffffffffffffff81111561216557612165612fc7565b6040519080825280601f01601f19166020018201604052801561218f576020820181803683370190505b509050600360fc1b816000815181106121aa576121aa612fb1565b60200101906001600160f81b031916908160001a905350600f60fb1b816001815181106121d9576121d9612fb1565b60200101906001600160f81b031916908160001a90535060006121fd846002612eaf565b612208906001612e97565b90505b600181111561228d577f303132333435363738396162636465660000000000000000000000000000000085600f166010811061224957612249612fb1565b1a60f81b82828151811061225f5761225f612fb1565b60200101906001600160f81b031916908160001a90535060049490941c9361228681612f15565b905061220b565b50831561112a5760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610923565b60006001600160e01b03198216637965db0b60e01b14806108db57506301ffc9a760e01b6001600160e01b03198316146108db565b6001600160a01b038116331461238f5760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c6600000000000000000000000000000000006064820152608401610923565b6120f382826126c9565b600061112a836001600160a01b03841661274c565b60005460ff166124005760405162461bcd60e51b815260206004820152601460248201527f5061757361626c653a206e6f74207061757365640000000000000000000000006044820152606401610923565b6000805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b60005460ff16156124905760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610923565b6000805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a25861242d3390565b600061112a8383612846565b60008083606001516001600160801b03166124eb84612525565b16119392505050565b60006108db825490565b6000828152600160208190526040909120015461251b8133612649565b610e0283836126c9565b6001600160a01b03811660009081527f68469a300b818693b723198bc921fe3194a15afefebd0401c7b13fbcc2307690602052604081205461256990600190612ece565b6001901b92915050565b60008281526001602090815260408083206001600160a01b038516845290915290205460ff166120f35760008281526001602081815260408084206001600160a01b0386168086529252808420805460ff19169093179092559051339285917f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d9190a45050565b6000818152600183016020526040812054612641575081546001818101845560008481526020808220909301849055845484825282860190935260409020919091556108db565b5060006108db565b60008281526001602090815260408083206001600160a01b038516845290915290205460ff166120f357612687816001600160a01b03166014612133565b612692836020612133565b6040516020016126a3929190612cf7565b60408051601f198184030181529082905262461bcd60e51b825261092391600401612de9565b60008281526001602090815260408083206001600160a01b038516845290915290205460ff16156120f35760008281526001602090815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b60008181526001830160205260408120548015612835576000612770600183612ece565b855490915060009061278490600190612ece565b90508181146127e95760008660000182815481106127a4576127a4612fb1565b90600052602060002001549050808760000184815481106127c7576127c7612fb1565b6000918252602080832090910192909255918252600188019052604090208390555b85548690806127fa576127fa612f9b565b6001900381819060005260206000200160009055905585600101600086815260200190815260200160002060009055600193505050506108db565b60009150506108db565b5092915050565b600082600001828154811061285d5761285d612fb1565b9060005260206000200154905092915050565b6040518060a0016040528060008152602001600081526020016000815260200160006001600160801b03168152602001600060048111156128b3576128b3612f85565b905290565b60008083601f8401126128ca57600080fd5b50813567ffffffffffffffff8111156128e257600080fd5b6020830191508360208260051b85010111156128fd57600080fd5b9250929050565b60008083601f84011261291657600080fd5b50813567ffffffffffffffff81111561292e57600080fd5b6020830191508360208285010111156128fd57600080fd5b803567ffffffffffffffff8116811461295e57600080fd5b919050565b803560ff8116811461295e57600080fd5b60006020828403121561298657600080fd5b813561112a81612fdd565b600080604083850312156129a457600080fd5b82356129af81612fdd565b915060208301356129bf81612fdd565b809150509250929050565b6000806000606084860312156129df57600080fd5b83356129ea81612fdd565b9250602084013591506040840135612a0181612fdd565b809150509250925092565b60008060008060408587031215612a2257600080fd5b843567ffffffffffffffff80821115612a3a57600080fd5b612a46888389016128b8565b90965094506020870135915080821115612a5f57600080fd5b50612a6c878288016128b8565b95989497509550505050565b600060208284031215612a8a57600080fd5b5035919050565b60008060408385031215612aa457600080fd5b8235915060208301356129bf81612fdd565b60008060408385031215612ac957600080fd5b50508035926020909101359150565b600060208284031215612aea57600080fd5b81356001600160e01b03198116811461112a57600080fd5b600080600060608486031215612b1757600080fd5b833568ffffffffffffffffff811681146129ea57600080fd5b600060208284031215612b4257600080fd5b61112a82612963565b60008060008060608587031215612b6157600080fd5b612b6a85612963565b935060208501359250604085013567ffffffffffffffff811115612b8d57600080fd5b612a6c87828801612904565b600080600060608486031215612bae57600080fd5b612bb784612963565b9250612bc560208501612946565b9150604084013590509250925092565b60008060008060808587031215612beb57600080fd5b612bf485612963565b9350612c0260208601612946565b93969395505050506040820135916060013590565b600080600080600060808688031215612c2f57600080fd5b612c3886612963565b9450612c4660208701612946565b9350604086013567ffffffffffffffff811115612c6257600080fd5b612c6e88828901612904565b96999598509660600135949350505050565b81835281816020850137506000828201602090810191909152601f909101601f19169091010190565b60058110612cc757634e487b7160e01b600052602160045260246000fd5b9052565b6bffffffffffffffffffffffff198460601b168152818360148301376000910160140190815292915050565b7f416363657373436f6e74726f6c3a206163636f756e7420000000000000000000815260008351612d2f816017850160208801612ee5565b7f206973206d697373696e6720726f6c65200000000000000000000000000000006017918401918201528351612d6c816028840160208801612ee5565b01602801949350505050565b838152604060208201526000612d92604083018486612c80565b95945050505050565b86815260ff8616602082015267ffffffffffffffff851660408201526001600160a01b038416606082015260a060808201526000612ddd60a083018486612c80565b98975050505050505050565b6020815260008251806020840152612e08816040850160208701612ee5565b601f01601f19169190910160400192915050565b600060a0820190508251825260208301516020830152604083015160408301526001600160801b036060840151166060830152608083015161283f6080840182612ca9565b60ff8516815267ffffffffffffffff8416602082015260808101612e886040830185612ca9565b82606083015295945050505050565b60008219821115612eaa57612eaa612f6f565b500190565b6000816000190483118215151615612ec957612ec9612f6f565b500290565b600082821015612ee057612ee0612f6f565b500390565b60005b83811015612f00578181015183820152602001612ee8565b83811115612f0f576000848401525b50505050565b600081612f2457612f24612f6f565b506000190190565b6000600019821415612f4057612f40612f6f565b5060010190565b600067ffffffffffffffff80831681811415612f6557612f65612f6f565b6001019392505050565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052602160045260246000fd5b634e487b7160e01b600052603160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160a01b0381168114612ff257600080fd5b5056fea6eef7e35abe7026729641147f7915573c7e97b47efa546f5f6e3230263bcb4948796472614272696467653a204f6e6c792041646d696e20526f6c6500000000a164736f6c6343000806000a

Verified Source Code Partial Match

Compiler: v0.8.6+commit.11564f7e EVM: berlin Optimization: Yes (800 runs)
HydraBridge.sol 283 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.6;

import "@openzeppelin/contracts/security/Pausable.sol";
import "./interfaces/IVault.sol";
import "./HydraAccessControl.sol";

contract HydraBridge is Pausable, HydraAccessControl {
    enum ProposalStatus {
        Inactive,
        Active,
        Confirmed,
        Completed,
        Cancelled
    }

    bytes32 public constant FEE_ADMIN = keccak256("FEE_ADMIN");
    bytes32 public constant OBSERVER_ROLE = keccak256("OBSERVER_ROLE");
    bytes32 public constant DEFENDER = keccak256("DEFENDER");

    uint256 public constant MAX_OBSERVERS = 128;
    uint256 public constant DELAY_LIMIT = 3 * 5400;

    uint256 public feeAmount;
    uint8 public chainId;
    uint8 public votesTreshold;
    uint256 public delayInBlocks;

    struct Proposal {
        uint256 votes;
        uint256 delayUntilBlock;
        uint256 proposedInBlock;
        uint128 hasVotedBitMap;
        ProposalStatus status;
    }

    // destination chain id => number of locks
    mapping(uint8 => uint64) public depositCount;

    // asset id => vault contract address
    mapping(bytes32 => address) public assetIdToVault;

    // destination chain id + lock nonce => data => Proposal
    mapping(uint72 => mapping(bytes32 => Proposal)) private proposals;

    event VotesTresholdChanged(uint256 newThreshold);
    event ObserverAdded(address observer);
    event ObserverRemoved(address observer);
    event Deposit(uint8 destinationChainId, bytes32 assetId, uint64 depositCount);
    event Voted(uint8 originChainId, uint64 depositCount, ProposalStatus status, bytes32 dataHash);
    event StatusChanged(uint8 originChainId, uint64 depositCount, ProposalStatus status, bytes32 dataHash);

    constructor(
        uint8 _chainID,
        uint8 _votesTreshold,
        uint256 _feeAmount,
        uint256 _delayInBlocks,
        address _feeAdmin,
        address _admin,
        address _defender,
        address[] memory _observers
    ) {
        chainId = _chainID;
        votesTreshold = _votesTreshold;
        feeAmount = _feeAmount;
        delayInBlocks = _delayInBlocks;

        _setupRole(DEFAULT_ADMIN_ROLE, _admin);
        _setupRole(FEE_ADMIN, _feeAdmin);
        _setupRole(DEFENDER, _defender);

        uint256 observersCount = _observers.length;
        for (uint256 i; i < observersCount; i++) {
            grantRole(OBSERVER_ROLE, _observers[i]);
        }
    }

    modifier onlyAdmin() {
        require(hasRole(DEFAULT_ADMIN_ROLE, msg.sender), "HydraBridge: Only Admin Role");
        _;
    }

    modifier onlyObservers() {
        require(hasRole(OBSERVER_ROLE, msg.sender), "HydraBridge: Only Observer Role");
        _;
    }

    modifier onlyFeeAdmin() {
        require(hasRole(FEE_ADMIN, msg.sender), "HydraBridge: Only Fee Admin Role");
        _;
    }

    modifier onlyDefender() {
        require(hasRole(DEFENDER, msg.sender), "HydraBridge: Only Defender Role");
        _;
    }

    function hasVotedOnProposal(
        uint72 _destinationChainIdAndNonce,
        bytes32 _dataHash,
        address _observer
    ) public view returns (bool) {
        return hasVoted(proposals[_destinationChainIdAndNonce][_dataHash], _observer);
    }

    function isObserver(address _observer) external view returns (bool) {
        return hasRole(OBSERVER_ROLE, _observer);
    }

    function getProposal(
        uint8 _originChainId,
        uint64 _depositCount,
        bytes32 _dataHash
    ) external view returns (Proposal memory) {
        uint72 key = (uint72(_depositCount) << 8) | uint72(_originChainId);
        return proposals[key][_dataHash];
    }

    function totalObservers() public view returns (uint256) {
        return getRoleMemberCount(OBSERVER_ROLE);
    }

    function pause() external onlyAdmin {
        _pause();
    }

    function unpause() external onlyAdmin {
        _unpause();
    }

    function setFee(uint256 _feeAmount) external onlyFeeAdmin {
        require(_feeAmount < 5e17, "fee must be less than 0.5 eth");
        feeAmount = _feeAmount;
    }

    function setDelay(uint256 _delayInBlocks) external onlyAdmin {
        require(_delayInBlocks <= DELAY_LIMIT, "delay must be less than 3 days");
        delayInBlocks = _delayInBlocks;
    }

    function changeVoteTreshold(uint8 _votesTreshold) external onlyAdmin {
        votesTreshold = _votesTreshold;
        emit VotesTresholdChanged(_votesTreshold);
    }

    function addObserver(address _observer) external onlyAdmin {
        require(!hasRole(OBSERVER_ROLE, _observer), "HydraBridge: user is already an observer");
        require(totalObservers() < MAX_OBSERVERS, "HydraBridge: max observers reached");
        grantRole(OBSERVER_ROLE, _observer);
        emit ObserverAdded(_observer);
    }

    function removeObserver(address _observer) external onlyAdmin {
        require(hasRole(OBSERVER_ROLE, _observer), "HydraBridge: user is not observer");
        revokeRole(OBSERVER_ROLE, _observer);
        emit ObserverRemoved(_observer);
    }

    function setAssetForVault(
        address _vaultAddress,
        bytes32 _assetId,
        address _tokenAddress
    ) external onlyAdmin {
        assetIdToVault[_assetId] = _vaultAddress;
        IVault vault = IVault(_vaultAddress);
        vault.setAsset(_assetId, _tokenAddress);
    }

    function setAssetBurnable(address handlerAddress, address tokenAddress) external onlyAdmin {
        IVault handler = IVault(handlerAddress);
        handler.setBurnable(tokenAddress);
    }

    function setAssetNotBurnable(address handlerAddress, address tokenAddress) external onlyAdmin {
        IVault handler = IVault(handlerAddress);
        handler.setNotBurnable(tokenAddress);
    }

    function deposit(
        uint8 _destinationChainId,
        bytes32 _assetId,
        bytes calldata data
    ) external payable whenNotPaused {
        uint256 _fee = feeAmount;
        require(msg.value >= _fee, "HydraBridge: fee insufficient");
        address vaultAddress = assetIdToVault[_assetId];
        require(vaultAddress != address(0), "HydraBridge: vault not found");

        uint64 nonce = ++depositCount[_destinationChainId];

        IVault vault = IVault(vaultAddress);
        vault.lock{ value: msg.value - _fee }(_assetId, _destinationChainId, nonce, msg.sender, data);

        emit Deposit(_destinationChainId, _assetId, nonce);
    }

    function vote(
        uint8 _originChainId,
        uint64 _depositCount,
        bytes32 _assetId,
        bytes32 _dataHash
    ) external onlyObservers whenNotPaused {
        uint72 nonceAndOriginChainId = (uint72(_depositCount) << 8) | uint72(_originChainId);
        Proposal memory proposal = proposals[nonceAndOriginChainId][_dataHash];

        require(assetIdToVault[_assetId] != address(0), "HydraBridge: Invalid Vault");
        require(uint256(proposal.status) <= 1, "HydraBridge: Invalid proposal status");
        require(!hasVoted(proposal, msg.sender), "HydraBridge: Observer already voted");

        // Inactive -> Active
        if (proposal.status == ProposalStatus.Inactive) {
            proposal = Proposal(0, 0, block.number, 0, ProposalStatus.Active);
            emit StatusChanged(_originChainId, _depositCount, ProposalStatus.Active, _dataHash);
        }

        proposal.hasVotedBitMap = (proposal.hasVotedBitMap | uint128(observerBit(msg.sender)));
        proposal.votes++;

        emit Voted(_originChainId, _depositCount, proposal.status, _dataHash);

        // Confirmed
        if (proposal.votes >= votesTreshold) {
            proposal.status = ProposalStatus.Confirmed;
            proposal.delayUntilBlock = block.number + delayInBlocks;
            emit StatusChanged(_originChainId, _depositCount, ProposalStatus.Confirmed, _dataHash);
        }

        proposals[nonceAndOriginChainId][_dataHash] = proposal;
    }

    function execute(
        uint8 _originChainId,
        uint64 _depositCount,
        bytes calldata _data,
        bytes32 _assetId
    ) external onlyObservers whenNotPaused {
        address vaultAddress = assetIdToVault[_assetId];
        bytes32 dataHash = keccak256(abi.encodePacked(vaultAddress, _data));
        uint72 nonceAndOriginChainId = (uint72(_depositCount) << 8) | uint72(_originChainId);

        Proposal storage proposal = proposals[nonceAndOriginChainId][dataHash];
        require(proposal.status == ProposalStatus.Confirmed, "HydraBridge: Proposal not found or not confirmed");
        require(block.number > proposal.delayUntilBlock, "HydraBridge: Proposal is in delayed state");

        proposal.status = ProposalStatus.Completed;

        IVault vault = IVault(vaultAddress);
        vault.execute(_assetId, _data);

        emit StatusChanged(_originChainId, _depositCount, ProposalStatus.Completed, dataHash);
    }

    function cancel(
        uint8 _originChainId,
        uint64 _depositCount,
        bytes32 _dataHash
    ) external onlyDefender {
        uint72 nonceAndOriginChainId = (uint72(_depositCount) << 8) | uint72(_originChainId);

        Proposal storage proposal = proposals[nonceAndOriginChainId][_dataHash];
        require(proposal.status != ProposalStatus.Cancelled, "HydraBridge: Proposal already cancelled");
        require(block.number <= proposal.delayUntilBlock, "HydraBridge: Cancellation time has expired");

        proposal.status = ProposalStatus.Cancelled;

        emit StatusChanged(_originChainId, _depositCount, ProposalStatus.Cancelled, _dataHash);
    }

    function observerBit(address _observer) private view returns (uint256) {
        return uint256(1) << (getRoleMemberIndex(OBSERVER_ROLE, _observer) - 1);
    }

    function hasVoted(Proposal memory proposal, address _observer) private view returns (bool) {
        return (observerBit(_observer) & uint256(proposal.hasVotedBitMap)) > 0;
    }

    function claimFees(address payable[] calldata addrs, uint256[] calldata amounts) external onlyFeeAdmin {
        uint256 addrCount = addrs.length;
        for (uint256 i = 0; i < addrCount; i++) {
            addrs[i].transfer(amounts[i]);
        }
    }
}
IVault.sol 20 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.6;

interface IVault {
    function lock(
        bytes32 assetId,
        uint8 chainId,
        uint64 nonce,
        address user,
        bytes calldata data
    ) external payable;

    function execute(bytes32 assetId, bytes calldata data) external;

    function setAsset(bytes32 assetId, address tokenAddress) external;

    function setBurnable(address tokenAddress) external;

    function setNotBurnable(address tokenAddress) external;
}
HydraAccessControl.sol 53 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.6;

import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";

interface IAccessControlEnumerable {
    function getRoleMember(bytes32 role, uint256 index) external view returns (address);

    function getRoleMemberCount(bytes32 role) external view returns (uint256);
}

abstract contract HydraAccessControl is AccessControl, IAccessControlEnumerable {
    using EnumerableSet for EnumerableSet.AddressSet;

    mapping(bytes32 => EnumerableSet.AddressSet) private _roleMembers;

    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IAccessControlEnumerable).interfaceId || super.supportsInterface(interfaceId);
    }

    function getRoleMember(bytes32 role, uint256 index) public view override returns (address) {
        return _roleMembers[role].at(index);
    }

    function getRoleMemberCount(bytes32 role) public view override returns (uint256) {
        return _roleMembers[role].length();
    }

    function getRoleMemberIndex(bytes32 role, address account) public view returns (uint256) {
        return _roleMembers[role]._inner._indexes[bytes32(uint256(uint160(account)))];
    }

    function grantRole(bytes32 role, address account) public virtual override {
        super.grantRole(role, account);
        _roleMembers[role].add(account);
    }

    function revokeRole(bytes32 role, address account) public virtual override {
        super.revokeRole(role, account);
        _roleMembers[role].remove(account);
    }

    function renounceRole(bytes32 role, address account) public virtual override {
        super.renounceRole(role, account);
        _roleMembers[role].remove(account);
    }

    function _setupRole(bytes32 role, address account) internal virtual override {
        super._setupRole(role, account);
        _roleMembers[role].add(account);
    }
}
Context.sol 23 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/*
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
}
Strings.sol 66 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev String operations.
 */
library Strings {
    bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";

    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        // Inspired by OraclizeAPI's implementation - MIT licence
        // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol

        if (value == 0) {
            return "0";
        }
        uint256 temp = value;
        uint256 digits;
        while (temp != 0) {
            digits++;
            temp /= 10;
        }
        bytes memory buffer = new bytes(digits);
        while (value != 0) {
            digits -= 1;
            buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
            value /= 10;
        }
        return string(buffer);
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        if (value == 0) {
            return "0x00";
        }
        uint256 temp = value;
        uint256 length = 0;
        while (temp != 0) {
            length++;
            temp >>= 8;
        }
        return toHexString(value, length);
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
     */
    function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
        bytes memory buffer = new bytes(2 * length + 2);
        buffer[0] = "0";
        buffer[1] = "x";
        for (uint256 i = 2 * length + 1; i > 1; --i) {
            buffer[i] = _HEX_SYMBOLS[value & 0xf];
            value >>= 4;
        }
        require(value == 0, "Strings: hex length insufficient");
        return string(buffer);
    }
}
Pausable.sol 90 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

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

/**
 * @dev Contract module which allows children to implement an emergency stop
 * mechanism that can be triggered by an authorized account.
 *
 * This module is used through inheritance. It will make available the
 * modifiers `whenNotPaused` and `whenPaused`, which can be applied to
 * the functions of your contract. Note that they will not be pausable by
 * simply including this module, only once the modifiers are put in place.
 */
abstract contract Pausable is Context {
    /**
     * @dev Emitted when the pause is triggered by `account`.
     */
    event Paused(address account);

    /**
     * @dev Emitted when the pause is lifted by `account`.
     */
    event Unpaused(address account);

    bool private _paused;

    /**
     * @dev Initializes the contract in unpaused state.
     */
    constructor() {
        _paused = false;
    }

    /**
     * @dev Returns true if the contract is paused, and false otherwise.
     */
    function paused() public view virtual returns (bool) {
        return _paused;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is not paused.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    modifier whenNotPaused() {
        require(!paused(), "Pausable: paused");
        _;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is paused.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    modifier whenPaused() {
        require(paused(), "Pausable: not paused");
        _;
    }

    /**
     * @dev Triggers stopped state.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    function _pause() internal virtual whenNotPaused {
        _paused = true;
        emit Paused(_msgSender());
    }

    /**
     * @dev Returns to normal state.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    function _unpause() internal virtual whenPaused {
        _paused = false;
        emit Unpaused(_msgSender());
    }
}
AccessControl.sol 250 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../utils/Context.sol";
import "../utils/Strings.sol";
import "../utils/introspection/ERC165.sol";

/**
 * @dev External interface of AccessControl declared to support ERC165 detection.
 */
interface IAccessControl {
    function hasRole(bytes32 role, address account) external view returns (bool);

    function getRoleAdmin(bytes32 role) external view returns (bytes32);

    function grantRole(bytes32 role, address account) external;

    function revokeRole(bytes32 role, address account) external;

    function renounceRole(bytes32 role, address account) external;
}

/**
 * @dev Contract module that allows children to implement role-based access
 * control mechanisms. This is a lightweight version that doesn't allow enumerating role
 * members except through off-chain means by accessing the contract event logs. Some
 * applications may benefit from on-chain enumerability, for those cases see
 * {AccessControlEnumerable}.
 *
 * Roles are referred to by their `bytes32` identifier. These should be exposed
 * in the external API and be unique. The best way to achieve this is by
 * using `public constant` hash digests:
 *
 * ```
 * bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
 * ```
 *
 * Roles can be used to represent a set of permissions. To restrict access to a
 * function call, use {hasRole}:
 *
 * ```
 * function foo() public {
 *     require(hasRole(MY_ROLE, msg.sender));
 *     ...
 * }
 * ```
 *
 * Roles can be granted and revoked dynamically via the {grantRole} and
 * {revokeRole} functions. Each role has an associated admin role, and only
 * accounts that have a role's admin role can call {grantRole} and {revokeRole}.
 *
 * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
 * that only accounts with this role will be able to grant or revoke other
 * roles. More complex role relationships can be created by using
 * {_setRoleAdmin}.
 *
 * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
 * grant and revoke this role. Extra precautions should be taken to secure
 * accounts that have been granted it.
 */
abstract contract AccessControl is Context, IAccessControl, ERC165 {
    struct RoleData {
        mapping(address => bool) members;
        bytes32 adminRole;
    }

    mapping(bytes32 => RoleData) private _roles;

    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;

    /**
     * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
     *
     * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
     * {RoleAdminChanged} not being emitted signaling this.
     *
     * _Available since v3.1._
     */
    event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);

    /**
     * @dev Emitted when `account` is granted `role`.
     *
     * `sender` is the account that originated the contract call, an admin role
     * bearer except when using {_setupRole}.
     */
    event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Emitted when `account` is revoked `role`.
     *
     * `sender` is the account that originated the contract call:
     *   - if using `revokeRole`, it is the admin role bearer
     *   - if using `renounceRole`, it is the role bearer (i.e. `account`)
     */
    event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Modifier that checks that an account has a specific role. Reverts
     * with a standardized message including the required role.
     *
     * The format of the revert reason is given by the following regular expression:
     *
     *  /^AccessControl: account (0x[0-9a-f]{20}) is missing role (0x[0-9a-f]{32})$/
     *
     * _Available since v4.1._
     */
    modifier onlyRole(bytes32 role) {
        _checkRole(role, _msgSender());
        _;
    }

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
    }

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) public view override returns (bool) {
        return _roles[role].members[account];
    }

    /**
     * @dev Revert with a standard message if `account` is missing `role`.
     *
     * The format of the revert reason is given by the following regular expression:
     *
     *  /^AccessControl: account (0x[0-9a-f]{20}) is missing role (0x[0-9a-f]{32})$/
     */
    function _checkRole(bytes32 role, address account) internal view {
        if (!hasRole(role, account)) {
            revert(
                string(
                    abi.encodePacked(
                        "AccessControl: account ",
                        Strings.toHexString(uint160(account), 20),
                        " is missing role ",
                        Strings.toHexString(uint256(role), 32)
                    )
                )
            );
        }
    }

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) public view override returns (bytes32) {
        return _roles[role].adminRole;
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
        _grantRole(role, account);
    }

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
        _revokeRole(role, account);
    }

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been granted `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `account`.
     */
    function renounceRole(bytes32 role, address account) public virtual override {
        require(account == _msgSender(), "AccessControl: can only renounce roles for self");

        _revokeRole(role, account);
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event. Note that unlike {grantRole}, this function doesn't perform any
     * checks on the calling account.
     *
     * [WARNING]
     * ====
     * This function should only be called from the constructor when setting
     * up the initial roles for the system.
     *
     * Using this function in any other way is effectively circumventing the admin
     * system imposed by {AccessControl}.
     * ====
     */
    function _setupRole(bytes32 role, address account) internal virtual {
        _grantRole(role, account);
    }

    /**
     * @dev Sets `adminRole` as ``role``'s admin role.
     *
     * Emits a {RoleAdminChanged} event.
     */
    function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
        emit RoleAdminChanged(role, getRoleAdmin(role), adminRole);
        _roles[role].adminRole = adminRole;
    }

    function _grantRole(bytes32 role, address account) private {
        if (!hasRole(role, account)) {
            _roles[role].members[account] = true;
            emit RoleGranted(role, account, _msgSender());
        }
    }

    function _revokeRole(bytes32 role, address account) private {
        if (hasRole(role, account)) {
            _roles[role].members[account] = false;
            emit RoleRevoked(role, account, _msgSender());
        }
    }
}
ERC165.sol 28 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "./IERC165.sol";

/**
 * @dev Implementation of the {IERC165} interface.
 *
 * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
 * for the additional interface id that will be supported. For example:
 *
 * ```solidity
 * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
 *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
 * }
 * ```
 *
 * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
 */
abstract contract ERC165 is IERC165 {
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IERC165).interfaceId;
    }
}
IERC165.sol 24 lines
// SPDX-License-Identifier: MIT

pragma solidity ^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);
}
EnumerableSet.sol 294 lines
// SPDX-License-Identifier: MIT

pragma solidity ^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;

            if (lastIndex != toDeleteIndex) {
                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] = valueIndex; // Replace lastvalue's index to valueIndex
            }

            // 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) {
        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));
    }
}
WETHVault.sol 84 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.6;

import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "./interfaces/IWETH9.sol";
import "./BaseVault.sol";

contract WETHVault is BaseVault {
    address payable public constant WETH = payable(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);

    struct LockRecord {
        address tokenAddress;
        uint8 destinationChainId;
        bytes32 assetId;
        bytes destinationRecipientAddress;
        address user;
        uint256 amount;
    }

    // chain id => lock nonce => Lock Record
    mapping(uint8 => mapping(uint64 => LockRecord)) public lockRecords;

    constructor(address _bridge, bytes32 _assetId) {
        bridge = _bridge;
        _setAsset(_assetId, WETH);
    }

    fallback() external payable {}

    receive() external payable {}

    function getLockRecord(uint8 _destinationChainId, uint64 _depositCount) external view returns (LockRecord memory) {
        return lockRecords[_destinationChainId][_depositCount];
    }

    function lock(
        bytes32 _assetId,
        uint8 _destinationChainId,
        uint64 _depositCount,
        address _user,
        bytes calldata _data
    ) external payable override onlyBridge {
        bytes memory recipientAddress;

        (uint256 amount, uint256 recipientAddressLength) = abi.decode(_data, (uint256, uint256));
        recipientAddress = bytes(_data[64:64 + recipientAddressLength]);

        require(amount == msg.value, "Vault: value send doesn't match data");

        address tokenAddress = assetIdToTokenAddress[_assetId];
        require(tokenAllowlist[tokenAddress], "Vault: token is not in the allowlist");

        IWETH9(WETH).deposit{ value: amount }();

        lockRecords[_destinationChainId][_depositCount] = LockRecord(
            tokenAddress,
            _destinationChainId,
            _assetId,
            recipientAddress,
            _user,
            amount
        );
    }

    function execute(bytes32 _assetId, bytes calldata _data) external override onlyBridge {
        bytes memory destinationRecipientAddress;

        (uint256 amount, uint256 lenDestinationRecipientAddress) = abi.decode(_data, (uint256, uint256));
        destinationRecipientAddress = bytes(_data[64:64 + lenDestinationRecipientAddress]);

        bytes20 recipient;
        address tokenAddress = assetIdToTokenAddress[_assetId];

        // solhint-disable-next-line
        assembly {
            recipient := mload(add(destinationRecipientAddress, 0x20))
        }

        require(tokenAllowlist[tokenAddress], "Vault: token is not in the allowlist");

        IWETH9(WETH).withdraw(amount);
        payable(address(recipient)).transfer(amount);
    }
}
BaseVault.sol 46 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.6;

import "./interfaces/IVault.sol";

abstract contract BaseVault is IVault {
    address public bridge;

    mapping(bytes32 => address) public assetIdToTokenAddress;
    mapping(address => bytes32) public tokenAddressToAssetId;
    mapping(address => bool) public tokenAllowlist;
    mapping(address => bool) public tokenBurnList;

    modifier onlyBridge() {
        require(msg.sender == bridge, "Vault: only bridge");
        _;
    }

    function setAsset(bytes32 _assetId, address _tokenAddress) external override onlyBridge {
        _setAsset(_assetId, _tokenAddress);
    }

    function setBurnable(address contractAddress) external override onlyBridge {
        _setBurnable(contractAddress);
    }

    function setNotBurnable(address contractAddress) external override onlyBridge {
        _setNotBurnable(contractAddress);
    }

    function _setAsset(bytes32 _assetId, address _tokenAddress) internal {
        assetIdToTokenAddress[_assetId] = _tokenAddress;
        tokenAddressToAssetId[_tokenAddress] = _assetId;
        tokenAllowlist[_tokenAddress] = true;
    }

    function _setBurnable(address _tokenAddress) internal {
        require(tokenAllowlist[_tokenAddress], "Vault: token is not in the allowlist");
        tokenBurnList[_tokenAddress] = true;
    }

    function _setNotBurnable(address _tokenAddress) internal {
        require(tokenAllowlist[_tokenAddress], "Vault: token is not in the allowlist");
        tokenBurnList[_tokenAddress] = false;
    }
}
SafeERC20.sol 98 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../IERC20.sol";
import "../../../utils/Address.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    using Address for address;

    function safeTransfer(
        IERC20 token,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    function safeTransferFrom(
        IERC20 token,
        address from,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

    /**
     * @dev Deprecated. This function has issues similar to the ones found in
     * {IERC20-approve}, and its usage is discouraged.
     *
     * Whenever possible, use {safeIncreaseAllowance} and
     * {safeDecreaseAllowance} instead.
     */
    function safeApprove(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        require(
            (value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
    }

    function safeIncreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        uint256 newAllowance = token.allowance(address(this), spender) + value;
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    function safeDecreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            uint256 newAllowance = oldAllowance - value;
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
        if (returndata.length > 0) {
            // Return data is optional
            require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
        }
    }
}
IWETH9.sol 32 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.6;

interface IWETH9 {
    function name() external view returns (string memory);

    function symbol() external view returns (string memory);

    function decimals() external view returns (uint8);

    function balanceOf(address) external view returns (uint256);

    function allowance(address, address) external view returns (uint256);

    receive() external payable;

    function deposit() external payable;

    function withdraw(uint256 wad) external;

    function totalSupply() external view returns (uint256);

    function approve(address guy, uint256 wad) external returns (bool);

    function transfer(address dst, uint256 wad) external returns (bool);

    function transferFrom(
        address src,
        address dst,
        uint256 wad
    ) external returns (bool);
}
IERC20.sol 81 lines
// SPDX-License-Identifier: MIT

pragma solidity ^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);
}
Address.sol 210 lines
// SPDX-License-Identifier: MIT

pragma solidity ^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;
        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");

        (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");

        (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");

        (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");

        (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

                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}
IERC20Metadata.sol 27 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../IERC20.sol";

/**
 * @dev Interface for the optional metadata functions from the ERC20 standard.
 *
 * _Available since v4.1._
 */
interface IERC20Metadata is IERC20 {
    /**
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory);

    /**
     * @dev Returns the symbol of the token.
     */
    function symbol() external view returns (string memory);

    /**
     * @dev Returns the decimals places of the token.
     */
    function decimals() external view returns (uint8);
}
ERC20.sol 354 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.sol";

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

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

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

    /**
     * @dev Sets the values for {name} and {symbol}.
     *
     * The default value of {decimals} is 18. To select a different value for
     * {decimals} you should overload it.
     *
     * All two of these values are immutable: they can only be set once during
     * construction.
     */
    constructor(string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
    }

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

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

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

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

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

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

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

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

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

        uint256 currentAllowance = _allowances[sender][_msgSender()];
        require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance");
        unchecked {
            _approve(sender, _msgSender(), currentAllowance - amount);
        }

        return true;
    }

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

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

        return true;
    }

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

        _beforeTokenTransfer(sender, recipient, amount);

        uint256 senderBalance = _balances[sender];
        require(senderBalance >= amount, "ERC20: transfer amount exceeds balance");
        unchecked {
            _balances[sender] = senderBalance - amount;
        }
        _balances[recipient] += amount;

        emit Transfer(sender, recipient, amount);

        _afterTokenTransfer(sender, recipient, amount);
    }

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

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

        _totalSupply += amount;
        _balances[account] += amount;
        emit Transfer(address(0), account, amount);

        _afterTokenTransfer(address(0), account, amount);
    }

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

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

        uint256 accountBalance = _balances[account];
        require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
        unchecked {
            _balances[account] = accountBalance - amount;
        }
        _totalSupply -= amount;

        emit Transfer(account, address(0), amount);

        _afterTokenTransfer(account, address(0), amount);
    }

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

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

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

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

pragma solidity ^0.8.0;

import "../ERC20.sol";
import "../../../security/Pausable.sol";

/**
 * @dev ERC20 token with pausable token transfers, minting and burning.
 *
 * Useful for scenarios such as preventing trades until the end of an evaluation
 * period, or having an emergency switch for freezing all token transfers in the
 * event of a large bug.
 */
abstract contract ERC20Pausable is ERC20, Pausable {
    /**
     * @dev See {ERC20-_beforeTokenTransfer}.
     *
     * Requirements:
     *
     * - the contract must not be paused.
     */
    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual override {
        super._beforeTokenTransfer(from, to, amount);

        require(!paused(), "ERC20Pausable: token transfer while paused");
    }
}
AccessControlEnumerable.sol 87 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "./AccessControl.sol";
import "../utils/structs/EnumerableSet.sol";

/**
 * @dev External interface of AccessControlEnumerable declared to support ERC165 detection.
 */
interface IAccessControlEnumerable {
    function getRoleMember(bytes32 role, uint256 index) external view returns (address);

    function getRoleMemberCount(bytes32 role) external view returns (uint256);
}

/**
 * @dev Extension of {AccessControl} that allows enumerating the members of each role.
 */
abstract contract AccessControlEnumerable is IAccessControlEnumerable, AccessControl {
    using EnumerableSet for EnumerableSet.AddressSet;

    mapping(bytes32 => EnumerableSet.AddressSet) private _roleMembers;

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IAccessControlEnumerable).interfaceId || super.supportsInterface(interfaceId);
    }

    /**
     * @dev Returns one of the accounts that have `role`. `index` must be a
     * value between 0 and {getRoleMemberCount}, non-inclusive.
     *
     * Role bearers are not sorted in any particular way, and their ordering may
     * change at any point.
     *
     * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure
     * you perform all queries on the same block. See the following
     * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]
     * for more information.
     */
    function getRoleMember(bytes32 role, uint256 index) public view override returns (address) {
        return _roleMembers[role].at(index);
    }

    /**
     * @dev Returns the number of accounts that have `role`. Can be used
     * together with {getRoleMember} to enumerate all bearers of a role.
     */
    function getRoleMemberCount(bytes32 role) public view override returns (uint256) {
        return _roleMembers[role].length();
    }

    /**
     * @dev Overload {grantRole} to track enumerable memberships
     */
    function grantRole(bytes32 role, address account) public virtual override {
        super.grantRole(role, account);
        _roleMembers[role].add(account);
    }

    /**
     * @dev Overload {revokeRole} to track enumerable memberships
     */
    function revokeRole(bytes32 role, address account) public virtual override {
        super.revokeRole(role, account);
        _roleMembers[role].remove(account);
    }

    /**
     * @dev Overload {renounceRole} to track enumerable memberships
     */
    function renounceRole(bytes32 role, address account) public virtual override {
        super.renounceRole(role, account);
        _roleMembers[role].remove(account);
    }

    /**
     * @dev Overload {_setupRole} to track enumerable memberships
     */
    function _setupRole(bytes32 role, address account) internal virtual override {
        super._setupRole(role, account);
        _roleMembers[role].add(account);
    }
}
ERC20PresetMinterPauser.sol 91 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../ERC20.sol";
import "../extensions/ERC20Burnable.sol";
import "../extensions/ERC20Pausable.sol";
import "../../../access/AccessControlEnumerable.sol";
import "../../../utils/Context.sol";

/**
 * @dev {ERC20} token, including:
 *
 *  - ability for holders to burn (destroy) their tokens
 *  - a minter role that allows for token minting (creation)
 *  - a pauser role that allows to stop all token transfers
 *
 * This contract uses {AccessControl} to lock permissioned functions using the
 * different roles - head to its documentation for details.
 *
 * The account that deploys the contract will be granted the minter and pauser
 * roles, as well as the default admin role, which will let it grant both minter
 * and pauser roles to other accounts.
 */
contract ERC20PresetMinterPauser is Context, AccessControlEnumerable, ERC20Burnable, ERC20Pausable {
    bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
    bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");

    /**
     * @dev Grants `DEFAULT_ADMIN_ROLE`, `MINTER_ROLE` and `PAUSER_ROLE` to the
     * account that deploys the contract.
     *
     * See {ERC20-constructor}.
     */
    constructor(string memory name, string memory symbol) ERC20(name, symbol) {
        _setupRole(DEFAULT_ADMIN_ROLE, _msgSender());

        _setupRole(MINTER_ROLE, _msgSender());
        _setupRole(PAUSER_ROLE, _msgSender());
    }

    /**
     * @dev Creates `amount` new tokens for `to`.
     *
     * See {ERC20-_mint}.
     *
     * Requirements:
     *
     * - the caller must have the `MINTER_ROLE`.
     */
    function mint(address to, uint256 amount) public virtual {
        require(hasRole(MINTER_ROLE, _msgSender()), "ERC20PresetMinterPauser: must have minter role to mint");
        _mint(to, amount);
    }

    /**
     * @dev Pauses all token transfers.
     *
     * See {ERC20Pausable} and {Pausable-_pause}.
     *
     * Requirements:
     *
     * - the caller must have the `PAUSER_ROLE`.
     */
    function pause() public virtual {
        require(hasRole(PAUSER_ROLE, _msgSender()), "ERC20PresetMinterPauser: must have pauser role to pause");
        _pause();
    }

    /**
     * @dev Unpauses all token transfers.
     *
     * See {ERC20Pausable} and {Pausable-_unpause}.
     *
     * Requirements:
     *
     * - the caller must have the `PAUSER_ROLE`.
     */
    function unpause() public virtual {
        require(hasRole(PAUSER_ROLE, _msgSender()), "ERC20PresetMinterPauser: must have pauser role to unpause");
        _unpause();
    }

    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual override(ERC20, ERC20Pausable) {
        super._beforeTokenTransfer(from, to, amount);
    }
}
ERC20Burnable.sol 42 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

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

/**
 * @dev Extension of {ERC20} that allows token holders to destroy both their own
 * tokens and those that they have an allowance for, in a way that can be
 * recognized off-chain (via event analysis).
 */
abstract contract ERC20Burnable is Context, ERC20 {
    /**
     * @dev Destroys `amount` tokens from the caller.
     *
     * See {ERC20-_burn}.
     */
    function burn(uint256 amount) public virtual {
        _burn(_msgSender(), amount);
    }

    /**
     * @dev Destroys `amount` tokens from `account`, deducting from the caller's
     * allowance.
     *
     * See {ERC20-_burn} and {ERC20-allowance}.
     *
     * Requirements:
     *
     * - the caller must have allowance for ``accounts``'s tokens of at least
     * `amount`.
     */
    function burnFrom(address account, uint256 amount) public virtual {
        uint256 currentAllowance = allowance(account, _msgSender());
        require(currentAllowance >= amount, "ERC20: burn amount exceeds allowance");
        unchecked {
            _approve(account, _msgSender(), currentAllowance - amount);
        }
        _burn(account, amount);
    }
}
ERC20DefaultVault.sol 107 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.6;

import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
import "@openzeppelin/contracts/token/ERC20/presets/ERC20PresetMinterPauser.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "./BaseVault.sol";

contract ERC20DefaultVault is BaseVault {
    using SafeERC20 for ERC20Burnable;

    struct LockRecord {
        address tokenAddress;
        uint8 destinationChainId;
        bytes32 assetId;
        bytes destinationRecipientAddress;
        address user;
        uint256 amount;
    }

    // chain id => lock nonce => Lock Record
    mapping(uint8 => mapping(uint64 => LockRecord)) public lockRecords;

    constructor(
        address _bridge,
        bytes32[] memory _assetIds,
        address[] memory _tokenAddresses,
        address[] memory _burnListAddresses
    ) {
        uint256 assetIdsLength = _assetIds.length;
        uint256 burnListAddressesLength = _burnListAddresses.length;

        require(assetIdsLength == _tokenAddresses.length, "Vault: _assetIds and _tokenAddresses invalid length");

        bridge = _bridge;

        for (uint256 i = 0; i < assetIdsLength; i++) {
            _setAsset(_assetIds[i], _tokenAddresses[i]);
        }

        for (uint256 i = 0; i < burnListAddressesLength; i++) {
            _setBurnable(_burnListAddresses[i]);
        }
    }

    function getLockRecord(uint8 _destinationChainId, uint64 _depositCount) external view returns (LockRecord memory) {
        return lockRecords[_destinationChainId][_depositCount];
    }

    function lock(
        bytes32 _assetId,
        uint8 _destinationChainId,
        uint64 _depositCount,
        address _user,
        bytes calldata _data
    ) external payable override onlyBridge {
        bytes memory recipientAddress;

        (uint256 amount, uint256 recipientAddressLength) = abi.decode(_data, (uint256, uint256));
        recipientAddress = bytes(_data[64:64 + recipientAddressLength]);

        address tokenAddress = assetIdToTokenAddress[_assetId];
        require(tokenAllowlist[tokenAddress], "Vault: token is not in the allowlist");

        if (tokenBurnList[tokenAddress]) {
            // burn on destination chain
            ERC20Burnable(tokenAddress).burnFrom(_user, amount);
        } else {
            // lock on source chain
            ERC20Burnable(tokenAddress).safeTransferFrom(_user, address(this), amount);
        }

        lockRecords[_destinationChainId][_depositCount] = LockRecord(
            tokenAddress,
            _destinationChainId,
            _assetId,
            recipientAddress,
            _user,
            amount
        );
    }

    function execute(bytes32 _assetId, bytes calldata _data) external override onlyBridge {
        bytes memory destinationRecipientAddress;

        (uint256 amount, uint256 lenDestinationRecipientAddress) = abi.decode(_data, (uint256, uint256));
        destinationRecipientAddress = bytes(_data[64:64 + lenDestinationRecipientAddress]);

        bytes20 recipientAddress;
        address tokenAddress = assetIdToTokenAddress[_assetId];

        // solhint-disable-next-line
        assembly {
            recipientAddress := mload(add(destinationRecipientAddress, 0x20))
        }

        require(tokenAllowlist[tokenAddress], "Vault: token is not in the allowlist");

        if (tokenBurnList[tokenAddress]) {
            // mint on destination chain
            ERC20PresetMinterPauser(tokenAddress).mint(address(recipientAddress), amount);
        } else {
            // release on source chain
            ERC20Burnable(tokenAddress).safeTransfer(address(recipientAddress), amount);
        }
    }
}

Read Contract

DEFAULT_ADMIN_ROLE 0xa217fddf → bytes32
DEFENDER 0x1ffd69c9 → bytes32
DELAY_LIMIT 0x62397e67 → uint256
FEE_ADMIN 0xd70afa96 → bytes32
MAX_OBSERVERS 0xec120a00 → uint256
OBSERVER_ROLE 0xa819e612 → bytes32
assetIdToVault 0xe6227e1d → address
chainId 0x9a8a0592 → uint8
delayInBlocks 0x3803c8ae → uint256
depositCount 0x0a55c9eb → uint64
feeAmount 0x69e15404 → uint256
getProposal 0xa9cf69fa → tuple
getRoleAdmin 0x248a9ca3 → bytes32
getRoleMember 0x9010d07c → address
getRoleMemberCount 0xca15c873 → uint256
getRoleMemberIndex 0x4e0df3f6 → uint256
hasRole 0x91d14854 → bool
hasVotedOnProposal 0xc70bf0b5 → bool
isObserver 0xd9facbe0 → bool
paused 0x5c975abb → bool
supportsInterface 0x01ffc9a7 → bool
totalObservers 0x9593c69c → uint256
votesTreshold 0x0fa14bc4 → uint8

Write Contract 18 functions

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

addObserver 0xfb8ec972
address _observer
cancel 0x1c8ad59d
uint8 _originChainId
uint64 _depositCount
bytes32 _dataHash
changeVoteTreshold 0x2674c5d2
uint8 _votesTreshold
claimFees 0xe208f404
address[] addrs
uint256[] amounts
deposit 0x05e2ca17
uint8 _destinationChainId
bytes32 _assetId
bytes data
execute 0xd823abe1
uint8 _originChainId
uint64 _depositCount
bytes _data
bytes32 _assetId
grantRole 0x2f2ff15d
bytes32 role
address account
pause 0x8456cb59
No parameters
removeObserver 0xcb2840c5
address _observer
renounceRole 0x36568abe
bytes32 role
address account
revokeRole 0xd547741f
bytes32 role
address account
setAssetBurnable 0x3268af19
address handlerAddress
address tokenAddress
setAssetForVault 0xa194855d
address _vaultAddress
bytes32 _assetId
address _tokenAddress
setAssetNotBurnable 0x412e7e48
address handlerAddress
address tokenAddress
setDelay 0xe177246e
uint256 _delayInBlocks
setFee 0x69fe0e2d
uint256 _feeAmount
unpause 0x3f4ba83a
No parameters
vote 0xf72e7541
uint8 _originChainId
uint64 _depositCount
bytes32 _assetId
bytes32 _dataHash

Recent Transactions

No transactions found for this address