Cryo Explorer Ethereum Mainnet

Address Contract Verified

Address 0x92977dD9c96c24bB4118992E6aCaa5b5Fb5076b9
Balance 0 ETH
Nonce 1
Code Size 9949 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

9949 bytes
0x6080604052600436106101da5760003560e01c806364bcb61e11610101578063aa34daf01161009a578063c34c08e51161006c578063c34c08e5146105b9578063d547741f146105d9578063db11e606146105f9578063dc0f49541461060e578063e6a20ae61461062e57005b8063aa34daf014610532578063ab477f4614610552578063af5e82bd14610579578063b8d1452f1461059957005b80637fcf35da116100d35780637fcf35da146104a857806391d14854146104c857806395b167d8146104e8578063a217fddf1461051d57005b806364bcb61e1461041157806370a0823114610432578063712d007d1461045f578063738037b81461049557005b80633fc8cef31161017357806351ae39031161014557806351ae39031461039d57806359750d55146103b05780635c478efd146103d057806360bc2fac146103f157005b80633fc8cef31461030957806346d708f6146103295780634bc3f0ec146103495780634be40fd11461036957005b8063248a9ca3116101ac578063248a9ca31461028357806324e34443146102c15780632f2ff15d146102c957806336568abe146102e957005b806301ffc9a7146101e35780630cb477dd146102185780630cd4b3f9146102505780631c3c0ea81461026357005b366101e157005b005b3480156101ef57600080fd5b506102036101fe366004611cd0565b610656565b60405190151581526020015b60405180910390f35b34801561022457600080fd5b50600254610238906001600160a01b031681565b6040516001600160a01b03909116815260200161020f565b6101e161025e366004611cfa565b61068d565b34801561026f57600080fd5b506101e161027e366004611d28565b610793565b34801561028f57600080fd5b506102b361029e366004611cfa565b60009081526020819052604090206001015490565b60405190815260200161020f565b6101e16107e5565b3480156102d557600080fd5b506101e16102e4366004611d45565b6108fc565b3480156102f557600080fd5b506101e1610304366004611d45565b610926565b34801561031557600080fd5b50600154610238906001600160a01b031681565b34801561033557600080fd5b506101e1610344366004611d83565b6109a4565b34801561035557600080fd5b506101e1610364366004611cfa565b6109e9565b34801561037557600080fd5b506102b37f7045adfe67d5f94dbfddcdb901e44bef55baacabb398c7cddda1bfd7620b156881565b6101e16103ab366004611dcf565b610bb8565b3480156103bc57600080fd5b506101e16103cb366004611cfa565b610c36565b3480156103dc57600080fd5b5060035461020390600160a81b900460ff1681565b3480156103fd57600080fd5b506101e161040c366004611cfa565b610db2565b34801561041d57600080fd5b5060035461020390600160a01b900460ff1681565b34801561043e57600080fd5b506102b361044d366004611d28565b60056020526000908152604090205481565b34801561046b57600080fd5b5061023861047a366004611e44565b6004602052600090815260409020546001600160a01b031681565b6101e16104a3366004611f24565b610f35565b3480156104b457600080fd5b506101e16104c3366004611fc4565b610fad565b3480156104d457600080fd5b506102036104e3366004611d45565b6113b7565b3480156104f457600080fd5b5061050861050336600461208e565b6113e0565b6040805192835260208301919091520161020f565b34801561052957600080fd5b506102b3600081565b34801561053e57600080fd5b506101e161054d366004612141565b61148e565b34801561055e57600080fd5b50610567600181565b60405160ff909116815260200161020f565b34801561058557600080fd5b506101e1610594366004611d28565b6114e9565b3480156105a557600080fd5b506101e16105b4366004611d28565b611532565b3480156105c557600080fd5b50600354610238906001600160a01b031681565b3480156105e557600080fd5b506101e16105f4366004611d45565b61157b565b34801561060557600080fd5b50610567600081565b34801561061a57600080fd5b506101e1610629366004611cfa565b6115a0565b34801561063a57600080fd5b50610643600181565b60405161ffff909116815260200161020f565b60006001600160e01b03198216637965db0b60e01b148061068757506301ffc9a760e01b6001600160e01b03198316145b92915050565b336000908152600560205260408120805483928392916106ae908490612183565b90915550506001546040516323b872dd60e01b81526001600160a01b03909116906323b872dd906106e790339030908790600401612196565b6020604051808303816000875af1158015610706573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061072a91906121ba565b506002546040516340c10f1960e01b8152306004820152602481018490526001600160a01b03909116906340c10f1990604401600060405180830381600087803b15801561077757600080fd5b505af115801561078b573d6000803e3d6000fd5b505050505050565b61079e6000336113b7565b6107c35760405162461bcd60e51b81526004016107ba906121d7565b60405180910390fd5b600380546001600160a01b0319166001600160a01b0392909216919091179055565b600354600160a01b900460ff1661080f5760405163163f2bb360e01b815260040160405180910390fd5b33600090815260056020526040812080543492839291610830908490612183565b909155505060015460408051630d0e30db60e41b815290516001600160a01b039092169163d0e30db0913491600480830192600092919082900301818588803b15801561087c57600080fd5b505af1158015610890573d6000803e3d6000fd5b50506002546040516340c10f1960e01b81523060048201523460248201526001600160a01b0390911693506340c10f1992506044019050600060405180830381600087803b1580156108e157600080fd5b505af11580156108f5573d6000803e3d6000fd5b5050505050565b600082815260208190526040902060010154610917816116d6565b61092183836116e3565b505050565b6001600160a01b03811633146109965760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b60648201526084016107ba565b6109a08282611767565b5050565b6109af6000336113b7565b6109cb5760405162461bcd60e51b81526004016107ba906121d7565b60038054911515600160a81b0260ff60a81b19909216919091179055565b600354600160a01b900460ff16610a135760405163163f2bb360e01b815260040160405180910390fd5b6001546040516370a0823160e01b8152306004820152829182916001600160a01b03909116906370a0823190602401602060405180830381865afa158015610a5f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a8391906121fb565b1015610aa25760405163c6c13aa760e01b815260040160405180910390fd5b6002546040516323b872dd60e01b81526001600160a01b03909116906323b872dd90610ad690339030908790600401612196565b6020604051808303816000875af1158015610af5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b1991906121ba565b50600154604051632e1a7d4d60e01b8152600481018490526001600160a01b0390911690632e1a7d4d90602401600060405180830381600087803b158015610b6057600080fd5b505af1158015610b74573d6000803e3d6000fd5b5050604051339250849150600081818185875af1925050503d80600081146108f5576040519150601f19603f3d011682016040523d82523d6000602084013e6108f5565b600354600160a81b900460ff168015610bf85750610bf67f7045adfe67d5f94dbfddcdb901e44bef55baacabb398c7cddda1bfd7620b1568336113b7565b155b15610c165760405163156061c360e21b815260040160405180910390fd5b61078b6000878787878760405180602001604052806000815250886117cc565b6001546040516370a0823160e01b8152306004820152829182916001600160a01b03909116906370a0823190602401602060405180830381865afa158015610c82573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ca691906121fb565b1015610cc55760405163c6c13aa760e01b815260040160405180910390fd5b6002546040516323b872dd60e01b81526001600160a01b03909116906323b872dd90610cf990339030908790600401612196565b6020604051808303816000875af1158015610d18573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d3c91906121ba565b5060015460405163a9059cbb60e01b8152336004820152602481018490526001600160a01b039091169063a9059cbb906044016020604051808303816000875af1158015610d8e573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061092191906121ba565b600354600160a01b900460ff16610ddc5760405163163f2bb360e01b815260040160405180910390fd5b33600090815260056020526040902054819081811015610e0f57604051631e9acf1760e31b815260040160405180910390fd5b3360009081526005602052604081208054849290610e2e908490612214565b9091555050600254604051632770a7eb60e21b8152306004820152602481018590526001600160a01b0390911690639dc29fac90604401600060405180830381600087803b158015610e7f57600080fd5b505af1158015610e93573d6000803e3d6000fd5b5050600154604051632e1a7d4d60e01b8152600481018790526001600160a01b039091169250632e1a7d4d9150602401600060405180830381600087803b158015610edd57600080fd5b505af1158015610ef1573d6000803e3d6000fd5b5050604051339250859150600081818185875af1925050503d806000811461078b576040519150601f19603f3d011682016040523d82523d6000602084013e61078b565b600354600160a81b900460ff168015610f755750610f737f7045adfe67d5f94dbfddcdb901e44bef55baacabb398c7cddda1bfd7620b1568336113b7565b155b15610f935760405163156061c360e21b815260040160405180910390fd5b610fa460018888888887878a6117cc565b50505050505050565b6002546001600160a01b03163314610fd85760405163bfdb951b60e01b815260040160405180910390fd5b600080600080600085806020019051810190610ff49190612227565b6040805160208101909152600081529499509297509095509350915060001960ff871601611038578680602001905181019061103091906122c0565b955050505050505b7f741fcf0d51b13214a6d64aa68534a86ddcd76931414a4ef6a76691dca6a55122868e87878c86604051611071969594939291906123c6565b60405180910390a16001546040516370a0823160e01b815230600482015289916001600160a01b0316906370a0823190602401602060405180830381865afa1580156110c1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110e591906121fb565b101561116e5760025460405163a9059cbb60e01b81526001600160a01b038581166004830152602482018b90529091169063a9059cbb906044016020604051808303816000875af115801561113e573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061116291906121ba565b50505050505050610fa4565b60ff86166112c357600354600160a01b900460ff16158061118d575081155b1561120f5760015460405163a9059cbb60e01b81526001600160a01b038681166004830152602482018b90529091169063a9059cbb906044016020604051808303816000875af11580156111e5573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061120991906121ba565b506113a8565b600154604051632e1a7d4d60e01b8152600481018a90526001600160a01b0390911690632e1a7d4d90602401600060405180830381600087803b15801561125557600080fd5b505af1158015611269573d6000803e3d6000fd5b50506040516001600160a01b03871692508a9150600081818185875af1925050503d80600081146112b6576040519150601f19603f3d011682016040523d82523d6000602084013e6112bb565b606091505b5050506113a8565b60015460035460405163095ea7b360e01b81526001600160a01b039182166004820152602481018b905291169063095ea7b3906044016020604051808303816000875af1158015611318573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061133c91906121ba565b506003546040516316d3253b60e11b81526001600160a01b0390911690632da64a7690611375908690889087908e908890600401612418565b600060405180830381600087803b15801561138f57600080fd5b505af11580156113a3573d6000803e3d6000fd5b505050505b50505050505050505050505050565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b60008060008060006113f78d8c8c8f8c8c8c6119a9565b60025460405163a4c51df560e01b815293965091945092506001600160a01b03169063a4c51df59061143a908f9087908e9087908f906000908b9060040161245e565b6040805180830381865afa158015611456573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061147a91906124bf565b945094505050509850989650505050505050565b6114996000336113b7565b6114b55760405162461bcd60e51b81526004016107ba906121d7565b61ffff91909116600090815260046020526040902080546001600160a01b0319166001600160a01b03909216919091179055565b6114f46000336113b7565b6115105760405162461bcd60e51b81526004016107ba906121d7565b600280546001600160a01b0319166001600160a01b0392909216919091179055565b61153d6000336113b7565b6115595760405162461bcd60e51b81526004016107ba906121d7565b600180546001600160a01b0319166001600160a01b0392909216919091179055565b600082815260208190526040902060010154611596816116d6565b6109218383611767565b336000908152600560205260409020548190818110156115d357604051631e9acf1760e31b815260040160405180910390fd5b33600090815260056020526040812080548492906115f2908490612214565b9091555050600254604051632770a7eb60e21b8152306004820152602481018590526001600160a01b0390911690639dc29fac90604401600060405180830381600087803b15801561164357600080fd5b505af1158015611657573d6000803e3d6000fd5b505060015460405163a9059cbb60e01b8152336004820152602481018790526001600160a01b03909116925063a9059cbb91506044016020604051808303816000875af11580156116ac573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116d091906121ba565b50505050565b6116e08133611ac2565b50565b6116ed82826113b7565b6109a0576000828152602081815260408083206001600160a01b03851684529091529020805460ff191660011790556117233390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b61177182826113b7565b156109a0576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b60008060006117e08b8a8a8d8a898b6119a9565b604080516060810182526001600160a01b038d1681526000602082018190529181018490526003549497509295509093509091600160a01b900460ff161561189e57600160009054906101000a90046001600160a01b03166001600160a01b031663d0e30db08a6040518263ffffffff1660e01b81526004016000604051808303818588803b15801561187257600080fd5b505af1158015611886573d6000803e3d6000fd5b505050505088346118979190612214565b905061191a565b6001546040516323b872dd60e01b81526001600160a01b03909116906323b872dd906118d290339030908e90600401612196565b6020604051808303816000875af11580156118f1573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061191591906121ba565b503490505b600260009054906101000a90046001600160a01b03166001600160a01b03166376203b4882308f898e898f8a6040518963ffffffff1660e01b815260040161196897969594939291906124e3565b6000604051808303818588803b15801561198157600080fd5b505af1158015611995573d6000803e3d6000fd5b505050505050505050505050505050505050565b6000606080620186a0836119c767ffffffffffffffff891683612183565b604051600160f01b60208201526022810182905290915060420160408051808303601f1901815282825261ffff8c1660009081526004602090815290839020546001600160a01b031690840152955001604051602081830303815290604052611a2f9061256f565b945060ff8c16611a86576040805160ff8e16602082015233918101919091526001600160a01b03808d1660608301528b16608082015287151560a082015260c0016040516020818303038152906040529250611ab3565b8b338c8c8a8a604051602001611aa196959493929190612596565b60405160208183030381529060405292505b50509750975097945050505050565b611acc82826113b7565b6109a057611ad981611b1b565b611ae4836020611b2d565b604051602001611af59291906125db565b60408051601f198184030181529082905262461bcd60e51b82526107ba91600401612650565b60606106876001600160a01b03831660145b60606000611b3c836002612663565b611b47906002612183565b67ffffffffffffffff811115611b5f57611b5f611e5f565b6040519080825280601f01601f191660200182016040528015611b89576020820181803683370190505b509050600360fc1b81600081518110611ba457611ba461267a565b60200101906001600160f81b031916908160001a905350600f60fb1b81600181518110611bd357611bd361267a565b60200101906001600160f81b031916908160001a9053506000611bf7846002612663565b611c02906001612183565b90505b6001811115611c7a576f181899199a1a9b1b9c1cb0b131b232b360811b85600f1660108110611c3657611c3661267a565b1a60f81b828281518110611c4c57611c4c61267a565b60200101906001600160f81b031916908160001a90535060049490941c93611c7381612690565b9050611c05565b508315611cc95760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e7460448201526064016107ba565b9392505050565b600060208284031215611ce257600080fd5b81356001600160e01b031981168114611cc957600080fd5b600060208284031215611d0c57600080fd5b5035919050565b6001600160a01b03811681146116e057600080fd5b600060208284031215611d3a57600080fd5b8135611cc981611d13565b60008060408385031215611d5857600080fd5b823591506020830135611d6a81611d13565b809150509250929050565b80151581146116e057600080fd5b600060208284031215611d9557600080fd5b8135611cc981611d75565b803561ffff81168114611db257600080fd5b919050565b803567ffffffffffffffff81168114611db257600080fd5b60008060008060008060c08789031215611de857600080fd5b611df187611da0565b95506020870135611e0181611d13565b94506040870135611e1181611d13565b935060608701359250611e2660808801611db7565b915060a0870135611e3681611d75565b809150509295509295509295565b600060208284031215611e5657600080fd5b611cc982611da0565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff81118282101715611e9e57611e9e611e5f565b604052919050565b600067ffffffffffffffff821115611ec057611ec0611e5f565b50601f01601f191660200190565b600082601f830112611edf57600080fd5b8135611ef2611eed82611ea6565b611e75565b818152846020838601011115611f0757600080fd5b816020850160208301376000918101602001919091529392505050565b600080600080600080600060e0888a031215611f3f57600080fd5b611f4888611da0565b96506020880135611f5881611d13565b95506040880135611f6881611d13565b9450606088013593506080880135611f7f81611d75565b9250611f8d60a08901611db7565b915060c088013567ffffffffffffffff811115611fa957600080fd5b611fb58a828b01611ece565b91505092959891949750929550565b600080600080600080600060c0888a031215611fdf57600080fd5b611fe888611da0565b9650602088013567ffffffffffffffff8082111561200557600080fd5b818a0191508a601f83011261201957600080fd5b81358181111561202857600080fd5b8b602082850101111561203a57600080fd5b602083019850965061204e60408b01611db7565b955060608a0135945060808a0135935060a08a013591508082111561207257600080fd5b50611fb58a828b01611ece565b60ff811681146116e057600080fd5b600080600080600080600080610100898b0312156120ab57600080fd5b88356120b68161207f565b97506120c460208a01611da0565b965060408901356120d481611d13565b955060608901356120e481611d13565b9450608089013593506120f960a08a01611db7565b925060c089013561210981611d75565b915060e089013567ffffffffffffffff81111561212557600080fd5b6121318b828c01611ece565b9150509295985092959890939650565b6000806040838503121561215457600080fd5b61215d83611da0565b91506020830135611d6a81611d13565b634e487b7160e01b600052601160045260246000fd5b808201808211156106875761068761216d565b6001600160a01b039384168152919092166020820152604081019190915260600190565b6000602082840312156121cc57600080fd5b8151611cc981611d75565b6020808252600a908201526927b7363c9030b236b4b760b11b604082015260600190565b60006020828403121561220d57600080fd5b5051919050565b818103818111156106875761068761216d565b600080600080600060a0868803121561223f57600080fd5b855161224a8161207f565b602087015190955061225b81611d13565b604087015190945061226c81611d13565b606087015190935061227d81611d13565b608087015190925061228e81611d75565b809150509295509295909350565b60005b838110156122b757818101518382015260200161229f565b50506000910152565b60008060008060008060c087890312156122d957600080fd5b86516122e48161207f565b60208801519096506122f581611d13565b604088015190955061230681611d13565b606088015190945061231781611d13565b608088015190935061232881611d75565b60a088015190925067ffffffffffffffff81111561234557600080fd5b8701601f8101891361235657600080fd5b8051612364611eed82611ea6565b8181528a602083850101111561237957600080fd5b61238a82602083016020860161229c565b8093505050509295509295509295565b600081518084526123b281602086016020860161229c565b601f01601f19169290920160200192915050565b60ff8716815261ffff861660208201526001600160a01b038581166040830152841660608201526080810183905260c060a0820181905260009061240c9083018461239a565b98975050505050505050565b6001600160a01b0386811682528516602082015283151560408201526060810183905260a0608082018190526000906124539083018461239a565b979650505050505050565b61ffff8816815286602082015285604082015260e06060820152600061248760e083018761239a565b67ffffffffffffffff8616608084015284151560a084015282810360c08401526124b1818561239a565b9a9950505050505050505050565b600080604083850312156124d257600080fd5b505080516020909101519092909150565b600060018060a01b03808a16835261ffff8916602084015287604084015286606084015260e0608084015261251b60e084018761239a565b67ffffffffffffffff861660a085015283810360c08501528185511681528160208601511660208201526040850151915060606040820152612560606082018361239a565b9b9a5050505050505050505050565b80516020808301519190811015612590576000198160200360031b1b821691505b50919050565b60ff871681526001600160a01b038681166020830152858116604083015284166060820152821515608082015260c060a0820181905260009061240c9083018461239a565b7f416363657373436f6e74726f6c3a206163636f756e742000000000000000000081526000835161261381601785016020880161229c565b7001034b99036b4b9b9b4b733903937b6329607d1b601791840191820152835161264481602884016020880161229c565b01602801949350505050565b602081526000611cc9602083018461239a565b80820281158282048414176106875761068761216d565b634e487b7160e01b600052603260045260246000fd5b60008161269f5761269f61216d565b50600019019056fea2646970667358221220ddc3416724c21a057af8aa716bd6de9982f7d1c40daee3b117ff4a19842529e164736f6c63430008140033

Verified Source Code Full Match

Compiler: v0.8.20+commit.a1b79de6 EVM: paris Optimization: Yes (200 runs)
Roles.sol 14 lines
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";

abstract contract Roles is AccessControl {
    constructor(address admin) {
        _grantRole(DEFAULT_ADMIN_ROLE, admin);
    }

    modifier onlyAdmin() {
        require(hasRole(DEFAULT_ADMIN_ROLE, msg.sender), "Only admin");
        _;
    }
}
IERC20.sol 43 lines
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.2;

/// @dev Interface of the ERC20 standard as defined in the EIP.
/// @dev This includes the optional name, symbol, and decimals metadata.
interface IERC20 {
    /// @dev Emitted when `value` tokens are moved from one account (`from`) to another (`to`).
    event Transfer(address indexed from, address indexed to, uint256 value);

    /// @dev Emitted when the allowance of a `spender` for an `owner` is set, where `value`
    /// is the new allowance.
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /// @notice Returns the amount of tokens in existence.
    function totalSupply() external view returns (uint256);

    /// @notice Returns the amount of tokens owned by `account`.
    function balanceOf(address account) external view returns (uint256);

    /// @notice Moves `amount` tokens from the caller's account to `to`.
    function transfer(address to, uint256 amount) external returns (bool);

    /// @notice Returns the remaining number of tokens that `spender` is allowed
    /// to spend on behalf of `owner`
    function allowance(address owner, address spender) external view returns (uint256);

    /// @notice Sets `amount` as the allowance of `spender` over the caller's tokens.
    /// @dev Be aware of front-running risks: https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
    function approve(address spender, uint256 amount) external returns (bool);

    /// @notice Moves `amount` tokens from `from` to `to` using the allowance mechanism.
    /// `amount` is then deducted from the caller's allowance.
    function transferFrom(address from, address to, uint256 amount) external returns (bool);

    /// @notice Returns the name of the token.
    function name() external view returns (string memory);

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

    /// @notice Returns the decimals places of the token.
    function decimals() external view returns (uint8);
}
DecentEthRouter.sol 373 lines
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import {IWETH} from "./interfaces/IWETH.sol";
import {IDcntEth} from "./interfaces/IDcntEth.sol";
import {ICommonOFT} from "solidity-examples/token/oft/v2/interfaces/ICommonOFT.sol";
import {IOFTReceiverV2} from "solidity-examples/token/oft/v2/interfaces/IOFTReceiverV2.sol";
import {Roles} from "./utils/Roles.sol";
import {IDecentBridgeExecutor} from "./interfaces/IDecentBridgeExecutor.sol";
import {IDecentEthRouter} from "./interfaces/IDecentEthRouter.sol";

contract DecentEthRouter is IDecentEthRouter, IOFTReceiverV2, Roles {
    IWETH public weth;
    IDcntEth public dcntEth;
    IDecentBridgeExecutor public executor;

    uint8 public constant MT_ETH_TRANSFER = 0;
    uint8 public constant MT_ETH_TRANSFER_WITH_PAYLOAD = 1;

    uint16 public constant PT_SEND_AND_CALL = 1;

    bool public gasCurrencyIsEth; // for chains that use ETH as gas currency

    bytes32 public constant BRIDGE_OPERATOR_ROLE = keccak256("BRIDGE_OPERATOR_ROLE");
    bool public requireOperator;

    mapping(uint16 => address) public destinationBridges;
    mapping(address => uint256) public balanceOf;

    constructor(
        address payable _weth,
        bool gasIsEth,
        address _executor
    ) Roles(msg.sender) {
        weth = IWETH(_weth);
        gasCurrencyIsEth = gasIsEth;
        executor = IDecentBridgeExecutor(payable(_executor));
    }

    modifier onlyEthChain() {
        if (!gasCurrencyIsEth) revert OnlyEthChain();
        _;
    }

    modifier onlyLzApp() {
        if (address(dcntEth) != msg.sender) revert OnlyLzApp();
        _;
    }

    modifier onlyOperator() {
        if (requireOperator && !hasRole(BRIDGE_OPERATOR_ROLE, msg.sender)) revert OnlyBridgeOperator();
        _;
    }

    modifier onlyIfWeHaveEnoughReserves(uint256 amount) {
        if (weth.balanceOf(address(this)) < amount) revert NotEnoughReserves();
        _;
    }

    modifier userDepositing(uint256 amount) {
        balanceOf[msg.sender] += amount;
        _;
    }

    modifier userIsWithdrawing(uint256 amount) {
        uint256 balance = balanceOf[msg.sender];
        if (balance < amount) revert InsufficientBalance();
        balanceOf[msg.sender] -= amount;
        _;
    }

    function setWeth(address payable _weth) public onlyAdmin {
        weth = IWETH(_weth);
    }

    function setExecutor(address _executor) public onlyAdmin {
        executor = IDecentBridgeExecutor(payable(_executor));
    }

    /// @inheritdoc IDecentEthRouter
    function registerDcntEth(address _addr) public onlyAdmin {
        dcntEth = IDcntEth(_addr);
    }

    /// @inheritdoc IDecentEthRouter
    function addDestinationBridge(
        uint16 _dstChainId,
        address _routerAddress
    ) public onlyAdmin {
        destinationBridges[_dstChainId] = _routerAddress;
    }

    function _getCallParams(
        uint8 msgType,
        address _toAddress,
        address _refundAddress,
        uint16 _dstChainId,
        uint64 _dstGasForCall,
        bool deliverEth,
        bytes memory additionalPayload
    )
        private
        view
        returns (
            bytes32 destBridge,
            bytes memory adapterParams,
            bytes memory payload
        )
    {
        uint256 GAS_FOR_RELAY = 100000;
        uint256 gasAmount = GAS_FOR_RELAY + _dstGasForCall;
        adapterParams = abi.encodePacked(PT_SEND_AND_CALL, gasAmount);
        destBridge = bytes32(abi.encode(destinationBridges[_dstChainId]));
        if (msgType == MT_ETH_TRANSFER) {
            payload = abi.encode(msgType, msg.sender, _toAddress, _refundAddress, deliverEth);
        } else {
            payload = abi.encode(
                msgType,
                msg.sender,
                _toAddress,
                _refundAddress,
                deliverEth,
                additionalPayload
            );
        }
    }

    function estimateSendAndCallFee(
        uint8 msgType,
        uint16 _dstChainId,
        address _toAddress,
        address _refundAddress,
        uint _amount,
        uint64 _dstGasForCall,
        bool deliverEth,
        bytes memory payload
    ) public view returns (uint nativeFee, uint zroFee) {
        (
            bytes32 destinationBridge,
            bytes memory adapterParams,
            bytes memory _payload
        ) = _getCallParams(
                msgType,
                _toAddress,
                _refundAddress,
                _dstChainId,
                _dstGasForCall,
                deliverEth,
                payload
            );

        return
            dcntEth.estimateSendAndCallFee(
                _dstChainId,
                destinationBridge,
                _amount,
                _payload,
                _dstGasForCall,
                false, // useZero
                adapterParams // Relayer adapter parameters
                // contains packet type (send and call in this case) and gasAmount
            );
    }

    function _bridgeWithPayload(
        uint8 msgType,
        uint16 _dstChainId,
        address _toAddress,
        address _refundAddress,
        uint _amount,
        uint64 _dstGasForCall,
        bytes memory additionalPayload,
        bool deliverEth
    ) internal {
        (
            bytes32 destinationBridge,
            bytes memory adapterParams,
            bytes memory payload
        ) = _getCallParams(
                msgType,
                _toAddress,
                _refundAddress,
                _dstChainId,
                _dstGasForCall,
                deliverEth,
                additionalPayload
            );

        ICommonOFT.LzCallParams memory callParams = ICommonOFT.LzCallParams({
            refundAddress: payable(_refundAddress),
            zroPaymentAddress: address(0x0),
            adapterParams: adapterParams
        });

        uint gasValue;
        if (gasCurrencyIsEth) {
            weth.deposit{value: _amount}();
            gasValue = msg.value - _amount;
        } else {
            weth.transferFrom(msg.sender, address(this), _amount);
            gasValue = msg.value;
        }

        dcntEth.sendAndCall{value: gasValue}(
            address(this), // from address that has dcntEth (so DecentRouter)
            _dstChainId,
            destinationBridge, // toAddress
            _amount, // amount
            payload, //payload (will have recipients address)
            _dstGasForCall, // dstGasForCall
            callParams // refundAddress, zroPaymentAddress, adapterParams
        );
    }

    /// @inheritdoc IDecentEthRouter
    function bridgeWithPayload(
        uint16 _dstChainId,
        address _toAddress,
        address _refundAddress,
        uint _amount,
        bool deliverEth,
        uint64 _dstGasForCall,
        bytes memory additionalPayload
    ) public payable onlyOperator {
        return
            _bridgeWithPayload(
                MT_ETH_TRANSFER_WITH_PAYLOAD,
                _dstChainId,
                _toAddress,
                _refundAddress,
                _amount,
                _dstGasForCall,
                additionalPayload,
                deliverEth
            );
    }

    /// @inheritdoc IDecentEthRouter
    function bridge(
        uint16 _dstChainId,
        address _toAddress,
        address _refundAddress,
        uint _amount,
        uint64 _dstGasForCall,
        bool deliverEth // if false, delivers WETH
    ) public payable onlyOperator {
        _bridgeWithPayload(
            MT_ETH_TRANSFER,
            _dstChainId,
            _toAddress,
            _refundAddress,
            _amount,
            _dstGasForCall,
            bytes(""),
            deliverEth
        );
    }

    /// @inheritdoc IOFTReceiverV2
    function onOFTReceived(
        uint16 _srcChainId,
        bytes calldata,
        uint64,
        bytes32,
        uint _amount,
        bytes memory _payload
    ) external override onlyLzApp {
        (uint8 msgType, address _from, address _to, address _refundAddress, bool deliverEth) = abi
            .decode(_payload, (uint8, address, address, address, bool));

        bytes memory callPayload = "";

        if (msgType == MT_ETH_TRANSFER_WITH_PAYLOAD) {
            (, , , , , callPayload) = abi.decode(
                _payload,
                (uint8, address, address, address, bool, bytes)
            );
        }

        emit ReceivedDecentEth(
            msgType,
            _srcChainId,
            _from,
            _to,
            _amount,
            callPayload
        );

        if (weth.balanceOf(address(this)) < _amount) {
            dcntEth.transfer(_refundAddress, _amount);
            return;
        }

        if (msgType == MT_ETH_TRANSFER) {
            if (!gasCurrencyIsEth || !deliverEth) {
                weth.transfer(_to, _amount);
            } else {
                weth.withdraw(_amount);
                (payable(_to).call{value: _amount}(""));
            }
        } else {
            weth.approve(address(executor), _amount);
            executor.execute(_refundAddress, _to, deliverEth, _amount, callPayload);
        }
    }

    /// @inheritdoc IDecentEthRouter
    function redeemEth(
        uint256 amount
    )
        public
        onlyEthChain
        onlyIfWeHaveEnoughReserves(amount)
    {
        dcntEth.transferFrom(msg.sender, address(this), amount);
        weth.withdraw(amount);
        (payable(msg.sender).call{value: amount}(""));
    }

    /// @inheritdoc IDecentEthRouter
    function redeemWeth(
        uint256 amount
    ) public onlyIfWeHaveEnoughReserves(amount) {
        dcntEth.transferFrom(msg.sender, address(this), amount);
        weth.transfer(msg.sender, amount);
    }

    /// @inheritdoc IDecentEthRouter
    function addLiquidityEth()
        public
        payable
        onlyEthChain
        userDepositing(msg.value)
    {
        weth.deposit{value: msg.value}();
        dcntEth.mint(address(this), msg.value);
    }

    /// @inheritdoc IDecentEthRouter
    function removeLiquidityEth(
        uint256 amount
    ) public onlyEthChain userIsWithdrawing(amount) {
        dcntEth.burn(address(this), amount);
        weth.withdraw(amount);
        (payable(msg.sender).call{value: amount}(""));
    }

    /// @inheritdoc IDecentEthRouter
    function addLiquidityWeth(
        uint256 amount
    ) public payable userDepositing(amount) {
        weth.transferFrom(msg.sender, address(this), amount);
        dcntEth.mint(address(this), amount);
    }

    /// @inheritdoc IDecentEthRouter
    function removeLiquidityWeth(
        uint256 amount
    ) public userIsWithdrawing(amount) {
        dcntEth.burn(address(this), amount);
        weth.transfer(msg.sender, amount);
    }

    function setRequireOperator(
        bool _requireOperator
    ) public onlyAdmin {
        requireOperator = _requireOperator;
    }

    receive() external payable {}

    fallback() external payable {}
}
IWETH.sol 10 lines
pragma solidity ^0.8.0;

import {IERC20} from "forge-std/interfaces/IERC20.sol";

interface IWETH is IERC20 {

    function deposit() external payable;

    function withdraw(uint) external;
}
IDcntEth.sol 17 lines
pragma solidity ^0.8.0;

import {IOFTV2} from "solidity-examples/token/oft/v2/interfaces/IOFTV2.sol";
import {IERC20} from "forge-std/interfaces/IERC20.sol";

interface IDcntEth is IOFTV2, IERC20 {

    function setRouter(address _router) external;

    function mint(address _to, uint256 _amount) external;

    function burn(address _from, uint256 _amount) external;

    function mintByOwner(address _to, uint256 _amount) external;

    function burnByOwner(address _from, uint256 _amount) external;
}
IDecentEthRouter.sol 125 lines
pragma solidity ^0.8.0;

interface IDecentEthRouter {

    event ReceivedDecentEth(
        uint8 msgType,
        uint16 _srcChainId,
        address from,
        address _to,
        uint amount,
        bytes payload
    );
    
    error OnlyLzApp();

    error OnlyEthChain();

    error OnlyBridgeOperator();

    error NotEnoughReserves();

    error InsufficientBalance();

    function MT_ETH_TRANSFER() external view returns (uint8);

    function MT_ETH_TRANSFER_WITH_PAYLOAD() external view returns (uint8);

    /**
     * @dev Sets dcntEth to the router
     * @param _addr The address of the deployed DcntEth token
     */
    function registerDcntEth(address _addr) external;

    /**
     * @dev Adds a destination bridge for the bridge
     * @param _dstChainId The lz chainId
     * @param _routerAddress The router address on the dst chain
     */
    function addDestinationBridge(
        uint16 _dstChainId,
        address _routerAddress
    ) external;

    function estimateSendAndCallFee(
        uint8 msgType,
        uint16 _dstChainId,
        address _toAddress,
        address _refundAddress,
        uint _amount,
        uint64 _dstGasForCall,
        bool deliverEth,
        bytes memory payload
    ) external view returns (uint nativeFee, uint zroFee);

    /**
     * @param _dstChainId lz endpoint
     * @param _toAddress the destination address (i.e. dst bridge)
     * @param _refundAddress the refund address
     * @param _amount the amount being bridged
     * @param deliverEth if false, delivers WETH
     * @param _dstGasForCall the amount of dst gas
     * @param additionalPayload contains the refundAddress, zroPaymentAddress, and adapterParams
     */
    function bridgeWithPayload(
        uint16 _dstChainId,
        address _toAddress,
        address _refundAddress,
        uint _amount,
        bool deliverEth,
        uint64 _dstGasForCall,
        bytes memory additionalPayload
    ) external payable;

    /**
     * @param _dstChainId lz endpoint
     * @param _toAddress destination address
     * @param _refundAddress the address to be refunded
     * @param _amount the amount being bridge
     * @param _dstGasForCall the amount of dst gas
     * @param deliverEth if false, delivers WETH
     */
    function bridge(
        uint16 _dstChainId,
        address _toAddress,
        address _refundAddress,
        uint _amount,
        uint64 _dstGasForCall,
        bool deliverEth // if false, delivers WETH
    ) external payable;

    /**
     * @dev allows users to redeem their dcntEth for ETH
     * @param amount the amount to be redeemed
     */
    function redeemEth(uint256 amount) external;

    /**
     * @dev allows users to redeem their dcntEth for WETH
     * @param amount the amount to be redeemed
     */
    function redeemWeth(uint256 amount) external;

    /**
     * @dev adds bridge liquidity by paying ETH
     */
    function addLiquidityEth() external payable;

    /**
     * @dev withdraws a users bridge liquidity for ETH
     * @param amount the amount to be redeemed
     */
    function removeLiquidityEth(uint256 amount) external;

    /**
     * @dev adds bridge liquidity by providing WETH
     * @param amount the amount to be added
     */
    function addLiquidityWeth(uint256 amount) external payable;

    /**
     * @dev withdraws a users bridge liquidity for WETH
     * @param amount the amount to be redeemed
     */
    function removeLiquidityWeth(uint256 amount) external;
}
IDecentBridgeExecutor.sol 23 lines
pragma solidity ^0.8.0;

import {IOFTV2} from "solidity-examples/token/oft/v2/interfaces/IOFTV2.sol";
import {IERC20} from "forge-std/interfaces/IERC20.sol";

interface IDecentBridgeExecutor {

    /**
     * @dev called upon receiving dcntEth in the DecentEthRouter
     * @param refundAddress the address to send refunds
     * @param target target contract
     * @param deliverEth delivers WETH if false
     * @param amount amount of the transaction
     * @param callPayload payload for the tx
     */
    function execute(
      address refundAddress,
      address target,
      bool deliverEth,
      uint256 amount,
      bytes memory callPayload
    ) external;
}
IOFTV2.sol 25 lines
// SPDX-License-Identifier: MIT

pragma solidity >=0.5.0;

import "./ICommonOFT.sol";

/**
 * @dev Interface of the IOFT core standard
 */
interface IOFTV2 is ICommonOFT {

    /**
     * @dev send `_amount` amount of token to (`_dstChainId`, `_toAddress`) from `_from`
     * `_from` the owner of token
     * `_dstChainId` the destination chain identifier
     * `_toAddress` can be any size depending on the `dstChainId`.
     * `_amount` the quantity of tokens in wei
     * `_refundAddress` the address LayerZero refunds if too much message fee is sent
     * `_zroPaymentAddress` set to address(0x0) if not paying in ZRO (LayerZero Token)
     * `_adapterParams` is a flexible bytes array to indicate messaging adapter services
     */
    function sendFrom(address _from, uint16 _dstChainId, bytes32 _toAddress, uint _amount, LzCallParams calldata _callParams) external payable;

    function sendAndCall(address _from, uint16 _dstChainId, bytes32 _toAddress, uint _amount, bytes calldata _payload, uint64 _dstGasForCall, LzCallParams calldata _callParams) external payable;
}
ICommonOFT.sol 39 lines
// SPDX-License-Identifier: MIT

pragma solidity >=0.5.0;

import "@openzeppelin/contracts/utils/introspection/IERC165.sol";

/**
 * @dev Interface of the IOFT core standard
 */
interface ICommonOFT is IERC165 {

    struct LzCallParams {
        address payable refundAddress;
        address zroPaymentAddress;
        bytes adapterParams;
    }

    /**
     * @dev estimate send token `_tokenId` to (`_dstChainId`, `_toAddress`)
     * _dstChainId - L0 defined chain id to send tokens too
     * _toAddress - dynamic bytes array which contains the address to whom you are sending tokens to on the dstChain
     * _amount - amount of the tokens to transfer
     * _useZro - indicates to use zro to pay L0 fees
     * _adapterParam - flexible bytes array to indicate messaging adapter services in L0
     */
    function estimateSendFee(uint16 _dstChainId, bytes32 _toAddress, uint _amount, bool _useZro, bytes calldata _adapterParams) external view returns (uint nativeFee, uint zroFee);

    function estimateSendAndCallFee(uint16 _dstChainId, bytes32 _toAddress, uint _amount, bytes calldata _payload, uint64 _dstGasForCall, bool _useZro, bytes calldata _adapterParams) external view returns (uint nativeFee, uint zroFee);

    /**
     * @dev returns the circulating amount of tokens on current chain
     */
    function circulatingSupply() external view returns (uint);

    /**
     * @dev returns the address of the ERC20 token
     */
    function token() external view returns (address);
}
Context.sol 24 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;

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

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
}
Strings.sol 85 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Strings.sol)

pragma solidity ^0.8.0;

import "./math/Math.sol";
import "./math/SignedMath.sol";

/**
 * @dev String operations.
 */
library Strings {
    bytes16 private constant _SYMBOLS = "0123456789abcdef";
    uint8 private constant _ADDRESS_LENGTH = 20;

    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        unchecked {
            uint256 length = Math.log10(value) + 1;
            string memory buffer = new string(length);
            uint256 ptr;
            /// @solidity memory-safe-assembly
            assembly {
                ptr := add(buffer, add(32, length))
            }
            while (true) {
                ptr--;
                /// @solidity memory-safe-assembly
                assembly {
                    mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
                }
                value /= 10;
                if (value == 0) break;
            }
            return buffer;
        }
    }

    /**
     * @dev Converts a `int256` to its ASCII `string` decimal representation.
     */
    function toString(int256 value) internal pure returns (string memory) {
        return string(abi.encodePacked(value < 0 ? "-" : "", toString(SignedMath.abs(value))));
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        unchecked {
            return toHexString(value, Math.log256(value) + 1);
        }
    }

    /**
     * @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] = _SYMBOLS[value & 0xf];
            value >>= 4;
        }
        require(value == 0, "Strings: hex length insufficient");
        return string(buffer);
    }

    /**
     * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
     */
    function toHexString(address addr) internal pure returns (string memory) {
        return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
    }

    /**
     * @dev Returns true if the two strings are equal.
     */
    function equal(string memory a, string memory b) internal pure returns (bool) {
        return keccak256(bytes(a)) == keccak256(bytes(b));
    }
}
Math.sol 339 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol)

pragma solidity ^0.8.0;

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    enum Rounding {
        Down, // Toward negative infinity
        Up, // Toward infinity
        Zero // Toward zero
    }

    /**
     * @dev Returns the largest of two numbers.
     */
    function max(uint256 a, uint256 b) internal pure returns (uint256) {
        return a > b ? a : b;
    }

    /**
     * @dev Returns the smallest of two numbers.
     */
    function min(uint256 a, uint256 b) internal pure returns (uint256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two numbers. The result is rounded towards
     * zero.
     */
    function average(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b) / 2 can overflow.
        return (a & b) + (a ^ b) / 2;
    }

    /**
     * @dev Returns the ceiling of the division of two numbers.
     *
     * This differs from standard division with `/` in that it rounds up instead
     * of rounding down.
     */
    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b - 1) / b can overflow on addition, so we distribute.
        return a == 0 ? 0 : (a - 1) / b + 1;
    }

    /**
     * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
     * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
     * with further edits by Uniswap Labs also under MIT license.
     */
    function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
        unchecked {
            // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
            // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
            // variables such that product = prod1 * 2^256 + prod0.
            uint256 prod0; // Least significant 256 bits of the product
            uint256 prod1; // Most significant 256 bits of the product
            assembly {
                let mm := mulmod(x, y, not(0))
                prod0 := mul(x, y)
                prod1 := sub(sub(mm, prod0), lt(mm, prod0))
            }

            // Handle non-overflow cases, 256 by 256 division.
            if (prod1 == 0) {
                // Solidity will revert if denominator == 0, unlike the div opcode on its own.
                // The surrounding unchecked block does not change this fact.
                // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
                return prod0 / denominator;
            }

            // Make sure the result is less than 2^256. Also prevents denominator == 0.
            require(denominator > prod1, "Math: mulDiv overflow");

            ///////////////////////////////////////////////
            // 512 by 256 division.
            ///////////////////////////////////////////////

            // Make division exact by subtracting the remainder from [prod1 prod0].
            uint256 remainder;
            assembly {
                // Compute remainder using mulmod.
                remainder := mulmod(x, y, denominator)

                // Subtract 256 bit number from 512 bit number.
                prod1 := sub(prod1, gt(remainder, prod0))
                prod0 := sub(prod0, remainder)
            }

            // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
            // See https://cs.stackexchange.com/q/138556/92363.

            // Does not overflow because the denominator cannot be zero at this stage in the function.
            uint256 twos = denominator & (~denominator + 1);
            assembly {
                // Divide denominator by twos.
                denominator := div(denominator, twos)

                // Divide [prod1 prod0] by twos.
                prod0 := div(prod0, twos)

                // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
                twos := add(div(sub(0, twos), twos), 1)
            }

            // Shift in bits from prod1 into prod0.
            prod0 |= prod1 * twos;

            // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
            // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
            // four bits. That is, denominator * inv = 1 mod 2^4.
            uint256 inverse = (3 * denominator) ^ 2;

            // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
            // in modular arithmetic, doubling the correct bits in each step.
            inverse *= 2 - denominator * inverse; // inverse mod 2^8
            inverse *= 2 - denominator * inverse; // inverse mod 2^16
            inverse *= 2 - denominator * inverse; // inverse mod 2^32
            inverse *= 2 - denominator * inverse; // inverse mod 2^64
            inverse *= 2 - denominator * inverse; // inverse mod 2^128
            inverse *= 2 - denominator * inverse; // inverse mod 2^256

            // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
            // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
            // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
            // is no longer required.
            result = prod0 * inverse;
            return result;
        }
    }

    /**
     * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
     */
    function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
        uint256 result = mulDiv(x, y, denominator);
        if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
            result += 1;
        }
        return result;
    }

    /**
     * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
     *
     * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
     */
    function sqrt(uint256 a) internal pure returns (uint256) {
        if (a == 0) {
            return 0;
        }

        // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
        //
        // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
        // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
        //
        // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
        // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
        // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
        //
        // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
        uint256 result = 1 << (log2(a) >> 1);

        // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
        // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
        // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
        // into the expected uint128 result.
        unchecked {
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            return min(result, a / result);
        }
    }

    /**
     * @notice Calculates sqrt(a), following the selected rounding direction.
     */
    function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = sqrt(a);
            return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 2, rounded down, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 128;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 64;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 32;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 16;
            }
            if (value >> 8 > 0) {
                value >>= 8;
                result += 8;
            }
            if (value >> 4 > 0) {
                value >>= 4;
                result += 4;
            }
            if (value >> 2 > 0) {
                value >>= 2;
                result += 2;
            }
            if (value >> 1 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 2, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log2(value);
            return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 10, rounded down, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >= 10 ** 64) {
                value /= 10 ** 64;
                result += 64;
            }
            if (value >= 10 ** 32) {
                value /= 10 ** 32;
                result += 32;
            }
            if (value >= 10 ** 16) {
                value /= 10 ** 16;
                result += 16;
            }
            if (value >= 10 ** 8) {
                value /= 10 ** 8;
                result += 8;
            }
            if (value >= 10 ** 4) {
                value /= 10 ** 4;
                result += 4;
            }
            if (value >= 10 ** 2) {
                value /= 10 ** 2;
                result += 2;
            }
            if (value >= 10 ** 1) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log10(value);
            return result + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 256, rounded down, of a positive value.
     * Returns 0 if given 0.
     *
     * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
     */
    function log256(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 16;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 8;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 4;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 2;
            }
            if (value >> 8 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 256, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log256(value);
            return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0);
        }
    }
}
IOFTReceiverV2.sol 16 lines
// SPDX-License-Identifier: BUSL-1.1

pragma solidity >=0.5.0;

interface IOFTReceiverV2 {
    /**
     * @dev Called by the OFT contract when tokens are received from source chain.
     * @param _srcChainId The chain id of the source chain.
     * @param _srcAddress The address of the OFT token contract on the source chain.
     * @param _nonce The nonce of the transaction on the source chain.
     * @param _from The address of the account who calls the sendAndCall() on the source chain.
     * @param _amount The amount of tokens to transfer.
     * @param _payload Additional data with no specified format.
     */
    function onOFTReceived(uint16 _srcChainId, bytes calldata _srcAddress, uint64 _nonce, bytes32 _from, uint _amount, bytes calldata _payload) external;
}
AccessControl.sol 248 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/AccessControl.sol)

pragma solidity ^0.8.0;

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

/**
 * @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:
 *
 * ```solidity
 * 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}:
 *
 * ```solidity
 * 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. We recommend using {AccessControlDefaultAdminRules}
 * to enforce additional security measures for this role.
 */
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 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]{40}) is missing role (0x[0-9a-f]{64})$/
     *
     * _Available since v4.1._
     */
    modifier onlyRole(bytes32 role) {
        _checkRole(role);
        _;
    }

    /**
     * @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 virtual override returns (bool) {
        return _roles[role].members[account];
    }

    /**
     * @dev Revert with a standard message if `_msgSender()` is missing `role`.
     * Overriding this function changes the behavior of the {onlyRole} modifier.
     *
     * Format of the revert message is described in {_checkRole}.
     *
     * _Available since v4.6._
     */
    function _checkRole(bytes32 role) internal view virtual {
        _checkRole(role, _msgSender());
    }

    /**
     * @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]{40}) is missing role (0x[0-9a-f]{64})$/
     */
    function _checkRole(bytes32 role, address account) internal view virtual {
        if (!hasRole(role, account)) {
            revert(
                string(
                    abi.encodePacked(
                        "AccessControl: account ",
                        Strings.toHexString(account),
                        " 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 virtual 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.
     *
     * May emit a {RoleGranted} event.
     */
    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.
     *
     * May emit a {RoleRevoked} event.
     */
    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 revoked `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `account`.
     *
     * May emit a {RoleRevoked} event.
     */
    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.
     *
     * May emit a {RoleGranted} event.
     *
     * [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}.
     * ====
     *
     * NOTE: This function is deprecated in favor of {_grantRole}.
     */
    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 {
        bytes32 previousAdminRole = getRoleAdmin(role);
        _roles[role].adminRole = adminRole;
        emit RoleAdminChanged(role, previousAdminRole, adminRole);
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleGranted} event.
     */
    function _grantRole(bytes32 role, address account) internal virtual {
        if (!hasRole(role, account)) {
            _roles[role].members[account] = true;
            emit RoleGranted(role, account, _msgSender());
        }
    }

    /**
     * @dev Revokes `role` from `account`.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleRevoked} event.
     */
    function _revokeRole(bytes32 role, address account) internal virtual {
        if (hasRole(role, account)) {
            _roles[role].members[account] = false;
            emit RoleRevoked(role, account, _msgSender());
        }
    }
}
IAccessControl.sol 88 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)

pragma solidity ^0.8.0;

/**
 * @dev External interface of AccessControl declared to support ERC165 detection.
 */
interface IAccessControl {
    /**
     * @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 {AccessControl-_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 Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) external view returns (bool);

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {AccessControl-_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) external view returns (bytes32);

    /**
     * @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) external;

    /**
     * @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) external;

    /**
     * @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) external;
}
SignedMath.sol 43 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SignedMath.sol)

pragma solidity ^0.8.0;

/**
 * @dev Standard signed math utilities missing in the Solidity language.
 */
library SignedMath {
    /**
     * @dev Returns the largest of two signed numbers.
     */
    function max(int256 a, int256 b) internal pure returns (int256) {
        return a > b ? a : b;
    }

    /**
     * @dev Returns the smallest of two signed numbers.
     */
    function min(int256 a, int256 b) internal pure returns (int256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two signed numbers without overflow.
     * The result is rounded towards zero.
     */
    function average(int256 a, int256 b) internal pure returns (int256) {
        // Formula from the book "Hacker's Delight"
        int256 x = (a & b) + ((a ^ b) >> 1);
        return x + (int256(uint256(x) >> 255) & (a ^ b));
    }

    /**
     * @dev Returns the absolute unsigned value of a signed value.
     */
    function abs(int256 n) internal pure returns (uint256) {
        unchecked {
            // must be unchecked in order to support `n = type(int256).min`
            return uint256(n >= 0 ? n : -n);
        }
    }
}
ERC165.sol 29 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)

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 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)

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);
}

Read Contract

BRIDGE_OPERATOR_ROLE 0x4be40fd1 → bytes32
DEFAULT_ADMIN_ROLE 0xa217fddf → bytes32
MT_ETH_TRANSFER 0xdb11e606 → uint8
MT_ETH_TRANSFER_WITH_PAYLOAD 0xab477f46 → uint8
PT_SEND_AND_CALL 0xe6a20ae6 → uint16
balanceOf 0x70a08231 → uint256
dcntEth 0x0cb477dd → address
destinationBridges 0x712d007d → address
estimateSendAndCallFee 0x95b167d8 → uint256, uint256
executor 0xc34c08e5 → address
gasCurrencyIsEth 0x64bcb61e → bool
getRoleAdmin 0x248a9ca3 → bytes32
hasRole 0x91d14854 → bool
requireOperator 0x5c478efd → bool
supportsInterface 0x01ffc9a7 → bool
weth 0x3fc8cef3 → address

Write Contract 17 functions

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

addDestinationBridge 0xaa34daf0
uint16 _dstChainId
address _routerAddress
addLiquidityEth 0x24e34443
No parameters
addLiquidityWeth 0x0cd4b3f9
uint256 amount
bridge 0x51ae3903
uint16 _dstChainId
address _toAddress
address _refundAddress
uint256 _amount
uint64 _dstGasForCall
bool deliverEth
bridgeWithPayload 0x738037b8
uint16 _dstChainId
address _toAddress
address _refundAddress
uint256 _amount
bool deliverEth
uint64 _dstGasForCall
bytes additionalPayload
grantRole 0x2f2ff15d
bytes32 role
address account
onOFTReceived 0x7fcf35da
uint16 _srcChainId
bytes
uint64
bytes32
uint256 _amount
bytes _payload
redeemEth 0x4bc3f0ec
uint256 amount
redeemWeth 0x59750d55
uint256 amount
registerDcntEth 0xaf5e82bd
address _addr
removeLiquidityEth 0x60bc2fac
uint256 amount
removeLiquidityWeth 0xdc0f4954
uint256 amount
renounceRole 0x36568abe
bytes32 role
address account
revokeRole 0xd547741f
bytes32 role
address account
setExecutor 0x1c3c0ea8
address _executor
setRequireOperator 0x46d708f6
bool _requireOperator
setWeth 0xb8d1452f
address _weth

Recent Transactions

No transactions found for this address