@across-protocol/contracts 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (257) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/LICENSE +661 -0
  3. package/README.md +53 -0
  4. package/artifacts/@eth-optimism/contracts/L2/messaging/IL2ERC20Bridge.sol/IL2ERC20Bridge.dbg.json +4 -0
  5. package/artifacts/@eth-optimism/contracts/L2/messaging/IL2ERC20Bridge.sol/IL2ERC20Bridge.json +252 -0
  6. package/artifacts/@eth-optimism/contracts/libraries/bridge/CrossDomainEnabled.sol/CrossDomainEnabled.dbg.json +4 -0
  7. package/artifacts/@eth-optimism/contracts/libraries/bridge/CrossDomainEnabled.sol/CrossDomainEnabled.json +35 -0
  8. package/artifacts/@eth-optimism/contracts/libraries/bridge/ICrossDomainMessenger.sol/ICrossDomainMessenger.dbg.json +4 -0
  9. package/artifacts/@eth-optimism/contracts/libraries/bridge/ICrossDomainMessenger.sol/ICrossDomainMessenger.json +110 -0
  10. package/artifacts/@eth-optimism/contracts/libraries/constants/Lib_PredeployAddresses.sol/Lib_PredeployAddresses.dbg.json +4 -0
  11. package/artifacts/@eth-optimism/contracts/libraries/constants/Lib_PredeployAddresses.sol/Lib_PredeployAddresses.json +10 -0
  12. package/artifacts/@openzeppelin/contracts/access/AccessControl.sol/AccessControl.dbg.json +4 -0
  13. package/artifacts/@openzeppelin/contracts/access/AccessControl.sol/AccessControl.json +215 -0
  14. package/artifacts/@openzeppelin/contracts/access/AccessControl.sol/IAccessControl.dbg.json +4 -0
  15. package/artifacts/@openzeppelin/contracts/access/AccessControl.sol/IAccessControl.json +108 -0
  16. package/artifacts/@openzeppelin/contracts/access/Ownable.sol/Ownable.dbg.json +4 -0
  17. package/artifacts/@openzeppelin/contracts/access/Ownable.sol/Ownable.json +63 -0
  18. package/artifacts/@openzeppelin/contracts/security/Pausable.sol/Pausable.dbg.json +4 -0
  19. package/artifacts/@openzeppelin/contracts/security/Pausable.sol/Pausable.json +50 -0
  20. package/artifacts/@openzeppelin/contracts/token/ERC20/ERC20.sol/ERC20.dbg.json +4 -0
  21. package/artifacts/@openzeppelin/contracts/token/ERC20/ERC20.sol/ERC20.json +297 -0
  22. package/artifacts/@openzeppelin/contracts/token/ERC20/IERC20.sol/IERC20.dbg.json +4 -0
  23. package/artifacts/@openzeppelin/contracts/token/ERC20/IERC20.sol/IERC20.json +194 -0
  24. package/artifacts/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol/IERC20Metadata.dbg.json +4 -0
  25. package/artifacts/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol/IERC20Metadata.json +233 -0
  26. package/artifacts/@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol/SafeERC20.dbg.json +4 -0
  27. package/artifacts/@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol/SafeERC20.json +10 -0
  28. package/artifacts/@openzeppelin/contracts/utils/Address.sol/Address.dbg.json +4 -0
  29. package/artifacts/@openzeppelin/contracts/utils/Address.sol/Address.json +10 -0
  30. package/artifacts/@openzeppelin/contracts/utils/Context.sol/Context.dbg.json +4 -0
  31. package/artifacts/@openzeppelin/contracts/utils/Context.sol/Context.json +10 -0
  32. package/artifacts/@openzeppelin/contracts/utils/Strings.sol/Strings.dbg.json +4 -0
  33. package/artifacts/@openzeppelin/contracts/utils/Strings.sol/Strings.json +10 -0
  34. package/artifacts/@openzeppelin/contracts/utils/introspection/ERC165.sol/ERC165.dbg.json +4 -0
  35. package/artifacts/@openzeppelin/contracts/utils/introspection/ERC165.sol/ERC165.json +30 -0
  36. package/artifacts/@openzeppelin/contracts/utils/introspection/IERC165.sol/IERC165.dbg.json +4 -0
  37. package/artifacts/@openzeppelin/contracts/utils/introspection/IERC165.sol/IERC165.json +30 -0
  38. package/artifacts/@openzeppelin/contracts/utils/math/SafeMath.sol/SafeMath.dbg.json +4 -0
  39. package/artifacts/@openzeppelin/contracts/utils/math/SafeMath.sol/SafeMath.json +10 -0
  40. package/artifacts/@openzeppelin/contracts/utils/math/SignedSafeMath.sol/SignedSafeMath.dbg.json +4 -0
  41. package/artifacts/@openzeppelin/contracts/utils/math/SignedSafeMath.sol/SignedSafeMath.json +10 -0
  42. package/artifacts/@uma/core/contracts/common/implementation/Lockable.sol/Lockable.dbg.json +4 -0
  43. package/artifacts/@uma/core/contracts/common/implementation/Lockable.sol/Lockable.json +16 -0
  44. package/artifacts/@uma/core/contracts/cross-chain-oracle/chain-adapters/Arbitrum_ParentMessenger.sol/Arbitrum_ParentMessenger.dbg.json +4 -0
  45. package/artifacts/@uma/core/contracts/cross-chain-oracle/chain-adapters/Arbitrum_ParentMessenger.sol/Arbitrum_ParentMessenger.json +611 -0
  46. package/artifacts/@uma/core/contracts/cross-chain-oracle/chain-adapters/ParentMessengerBase.sol/ParentMessengerBase.dbg.json +4 -0
  47. package/artifacts/@uma/core/contracts/cross-chain-oracle/chain-adapters/ParentMessengerBase.sol/ParentMessengerBase.json +297 -0
  48. package/artifacts/@uma/core/contracts/cross-chain-oracle/interfaces/ParentMessengerConsumerInterface.sol/ParentMessengerConsumerInterface.dbg.json +4 -0
  49. package/artifacts/@uma/core/contracts/cross-chain-oracle/interfaces/ParentMessengerConsumerInterface.sol/ParentMessengerConsumerInterface.json +29 -0
  50. package/artifacts/@uma/core/contracts/cross-chain-oracle/interfaces/ParentMessengerInterface.sol/ParentMessengerInterface.dbg.json +4 -0
  51. package/artifacts/@uma/core/contracts/cross-chain-oracle/interfaces/ParentMessengerInterface.sol/ParentMessengerInterface.json +37 -0
  52. package/artifacts/@uma/core/contracts/external/avm/interfaces/iArbitrum_Inbox.sol/IBridge.dbg.json +4 -0
  53. package/artifacts/@uma/core/contracts/external/avm/interfaces/iArbitrum_Inbox.sol/IBridge.json +24 -0
  54. package/artifacts/@uma/core/contracts/external/avm/interfaces/iArbitrum_Inbox.sol/iArbitrum_Inbox.dbg.json +4 -0
  55. package/artifacts/@uma/core/contracts/external/avm/interfaces/iArbitrum_Inbox.sol/iArbitrum_Inbox.json +78 -0
  56. package/artifacts/@uma/core/contracts/external/avm/interfaces/iArbitrum_Outbox.sol/iArbitrum_Outbox.dbg.json +4 -0
  57. package/artifacts/@uma/core/contracts/external/avm/interfaces/iArbitrum_Outbox.sol/iArbitrum_Outbox.json +24 -0
  58. package/artifacts/@uma/core/contracts/insured-bridge/avm/Arbitrum_CrossDomainEnabled.sol/Arbitrum_CrossDomainEnabled.dbg.json +4 -0
  59. package/artifacts/@uma/core/contracts/insured-bridge/avm/Arbitrum_CrossDomainEnabled.sol/Arbitrum_CrossDomainEnabled.json +24 -0
  60. package/artifacts/build-info/1cd64db7a8ac0a153df93d26826ad4e9.json +1653 -0
  61. package/artifacts/build-info/1f738b56edd7602183f2f8d2f23f6e90.json +1592 -0
  62. package/artifacts/build-info/343b9221be36acd9ddaca3f3b83d2e75.json +3943 -0
  63. package/artifacts/build-info/622e561692c193f4cd0ff989b5a231e2.json +5661 -0
  64. package/artifacts/build-info/8e408b49e0ff2873bc28d45221a7ff71.json +277715 -0
  65. package/artifacts/build-info/9d1a3182633612bd337d811d567d5d60.json +2072 -0
  66. package/artifacts/build-info/a8cd9c443d245fe513d6650634b60f93.json +23776 -0
  67. package/artifacts/build-info/d302d9d63fbafb5c8d635cc62cb1cc7c.json +167529 -0
  68. package/artifacts/contracts/common/implementation/AncillaryData.sol/AncillaryData.dbg.json +4 -0
  69. package/artifacts/contracts/common/implementation/AncillaryData.sol/AncillaryData.json +10 -0
  70. package/artifacts/contracts/common/implementation/FixedPoint.sol/FixedPoint.dbg.json +4 -0
  71. package/artifacts/contracts/common/implementation/FixedPoint.sol/FixedPoint.json +10 -0
  72. package/artifacts/contracts/common/implementation/Lockable.sol/Lockable.dbg.json +4 -0
  73. package/artifacts/contracts/common/implementation/Lockable.sol/Lockable.json +16 -0
  74. package/artifacts/contracts/common/implementation/MultiCaller.sol/MultiCaller.dbg.json +4 -0
  75. package/artifacts/contracts/common/implementation/MultiCaller.sol/MultiCaller.json +30 -0
  76. package/artifacts/contracts/common/implementation/Testable.sol/Testable.dbg.json +4 -0
  77. package/artifacts/contracts/common/implementation/Testable.sol/Testable.json +50 -0
  78. package/artifacts/contracts/common/implementation/Timer.sol/Timer.dbg.json +4 -0
  79. package/artifacts/contracts/common/implementation/Timer.sol/Timer.json +42 -0
  80. package/artifacts/contracts/common/interfaces/AddressWhitelistInterface.sol/AddressWhitelistInterface.dbg.json +4 -0
  81. package/artifacts/contracts/common/interfaces/AddressWhitelistInterface.sol/AddressWhitelistInterface.json +69 -0
  82. package/artifacts/contracts/external/avm/AVM_CrossDomainEnabled.sol/AVM_CrossDomainEnabled.dbg.json +4 -0
  83. package/artifacts/contracts/external/avm/AVM_CrossDomainEnabled.sol/AVM_CrossDomainEnabled.json +42 -0
  84. package/artifacts/contracts/external/avm/interfaces/ArbSys.sol/ArbSys.dbg.json +4 -0
  85. package/artifacts/contracts/external/avm/interfaces/ArbSys.sol/ArbSys.json +235 -0
  86. package/artifacts/contracts/external/avm/interfaces/iArbitrum_Inbox.sol/IBridge.dbg.json +4 -0
  87. package/artifacts/contracts/external/avm/interfaces/iArbitrum_Inbox.sol/IBridge.json +24 -0
  88. package/artifacts/contracts/external/avm/interfaces/iArbitrum_Inbox.sol/iArbitrum_Inbox.dbg.json +4 -0
  89. package/artifacts/contracts/external/avm/interfaces/iArbitrum_Inbox.sol/iArbitrum_Inbox.json +78 -0
  90. package/artifacts/contracts/external/avm/interfaces/iArbitrum_Outbox.sol/iArbitrum_Outbox.dbg.json +4 -0
  91. package/artifacts/contracts/external/avm/interfaces/iArbitrum_Outbox.sol/iArbitrum_Outbox.json +24 -0
  92. package/artifacts/contracts/external/chainbridge/Bridge.sol/Bridge.dbg.json +4 -0
  93. package/artifacts/contracts/external/chainbridge/Bridge.sol/Bridge.json +1019 -0
  94. package/artifacts/contracts/external/chainbridge/handlers/GenericHandler.sol/GenericHandler.dbg.json +4 -0
  95. package/artifacts/contracts/external/chainbridge/handlers/GenericHandler.sol/GenericHandler.json +314 -0
  96. package/artifacts/contracts/external/chainbridge/interfaces/IBridge.sol/IBridge.dbg.json +4 -0
  97. package/artifacts/contracts/external/chainbridge/interfaces/IBridge.sol/IBridge.json +47 -0
  98. package/artifacts/contracts/external/chainbridge/interfaces/IDepositExecute.sol/IDepositExecute.dbg.json +4 -0
  99. package/artifacts/contracts/external/chainbridge/interfaces/IDepositExecute.sol/IDepositExecute.json +62 -0
  100. package/artifacts/contracts/external/chainbridge/interfaces/IERCHandler.sol/IERCHandler.dbg.json +4 -0
  101. package/artifacts/contracts/external/chainbridge/interfaces/IERCHandler.sol/IERCHandler.json +65 -0
  102. package/artifacts/contracts/external/chainbridge/interfaces/IGenericHandler.sol/IGenericHandler.dbg.json +4 -0
  103. package/artifacts/contracts/external/chainbridge/interfaces/IGenericHandler.sol/IGenericHandler.json +39 -0
  104. package/artifacts/contracts/external/ovm/OVM_CrossDomainEnabled.sol/OVM_CrossDomainEnabled.dbg.json +4 -0
  105. package/artifacts/contracts/external/ovm/OVM_CrossDomainEnabled.sol/OVM_CrossDomainEnabled.json +35 -0
  106. package/artifacts/contracts/external/ovm/OVM_CrossDomainEnabled.sol/iOVM_CrossDomainMessenger.dbg.json +4 -0
  107. package/artifacts/contracts/external/ovm/OVM_CrossDomainEnabled.sol/iOVM_CrossDomainMessenger.json +86 -0
  108. package/artifacts/contracts/external/polygon/lib/Merkle.sol/Merkle.dbg.json +4 -0
  109. package/artifacts/contracts/external/polygon/lib/Merkle.sol/Merkle.json +10 -0
  110. package/artifacts/contracts/external/polygon/lib/MerklePatriciaProof.sol/MerklePatriciaProof.dbg.json +4 -0
  111. package/artifacts/contracts/external/polygon/lib/MerklePatriciaProof.sol/MerklePatriciaProof.json +10 -0
  112. package/artifacts/contracts/external/polygon/lib/RLPReader.sol/RLPReader.dbg.json +4 -0
  113. package/artifacts/contracts/external/polygon/lib/RLPReader.sol/RLPReader.json +10 -0
  114. package/artifacts/contracts/external/polygon/test/FxChildMock.sol/FxChildMock.dbg.json +4 -0
  115. package/artifacts/contracts/external/polygon/test/FxChildMock.sol/FxChildMock.json +104 -0
  116. package/artifacts/contracts/external/polygon/test/FxChildMock.sol/IFxMessageProcessor.dbg.json +4 -0
  117. package/artifacts/contracts/external/polygon/test/FxChildMock.sol/IFxMessageProcessor.json +34 -0
  118. package/artifacts/contracts/external/polygon/test/FxChildMock.sol/IStateReceiver.dbg.json +4 -0
  119. package/artifacts/contracts/external/polygon/test/FxChildMock.sol/IStateReceiver.json +29 -0
  120. package/artifacts/contracts/external/polygon/test/FxRootMock.sol/FxRootMock.dbg.json +4 -0
  121. package/artifacts/contracts/external/polygon/test/FxRootMock.sol/FxRootMock.json +79 -0
  122. package/artifacts/contracts/external/polygon/test/FxRootMock.sol/IFxStateSender.dbg.json +4 -0
  123. package/artifacts/contracts/external/polygon/test/FxRootMock.sol/IFxStateSender.json +29 -0
  124. package/artifacts/contracts/external/polygon/test/FxRootMock.sol/IStateSender.dbg.json +4 -0
  125. package/artifacts/contracts/external/polygon/test/FxRootMock.sol/IStateSender.json +29 -0
  126. package/artifacts/contracts/external/polygon/test/StateSyncMock.sol/StateSyncMock.dbg.json +4 -0
  127. package/artifacts/contracts/external/polygon/test/StateSyncMock.sol/StateSyncMock.json +54 -0
  128. package/artifacts/contracts/external/polygon/tunnel/FxBaseChildTunnel.sol/FxBaseChildTunnel.dbg.json +4 -0
  129. package/artifacts/contracts/external/polygon/tunnel/FxBaseChildTunnel.sol/FxBaseChildTunnel.json +86 -0
  130. package/artifacts/contracts/external/polygon/tunnel/FxBaseChildTunnel.sol/IFxMessageProcessor.dbg.json +4 -0
  131. package/artifacts/contracts/external/polygon/tunnel/FxBaseChildTunnel.sol/IFxMessageProcessor.json +34 -0
  132. package/artifacts/contracts/external/polygon/tunnel/FxBaseRootTunnel.sol/FxBaseRootTunnel.dbg.json +4 -0
  133. package/artifacts/contracts/external/polygon/tunnel/FxBaseRootTunnel.sol/FxBaseRootTunnel.json +108 -0
  134. package/artifacts/contracts/external/polygon/tunnel/FxBaseRootTunnel.sol/ICheckpointManager.dbg.json +4 -0
  135. package/artifacts/contracts/external/polygon/tunnel/FxBaseRootTunnel.sol/ICheckpointManager.json +50 -0
  136. package/artifacts/contracts/external/polygon/tunnel/FxBaseRootTunnel.sol/IFxStateSender.dbg.json +4 -0
  137. package/artifacts/contracts/external/polygon/tunnel/FxBaseRootTunnel.sol/IFxStateSender.json +29 -0
  138. package/artifacts/contracts/insured-bridge/BridgeAdmin.sol/BridgeAdmin.dbg.json +4 -0
  139. package/artifacts/contracts/insured-bridge/BridgeAdmin.sol/BridgeAdmin.json +662 -0
  140. package/artifacts/contracts/insured-bridge/BridgeDepositBox.sol/BridgeDepositBox.dbg.json +4 -0
  141. package/artifacts/contracts/insured-bridge/BridgeDepositBox.sol/BridgeDepositBox.json +391 -0
  142. package/artifacts/contracts/insured-bridge/BridgeDepositBox.sol/TokenLike.dbg.json +4 -0
  143. package/artifacts/contracts/insured-bridge/BridgeDepositBox.sol/TokenLike.json +30 -0
  144. package/artifacts/contracts/insured-bridge/BridgeDepositBox.sol/WETH9Like.dbg.json +4 -0
  145. package/artifacts/contracts/insured-bridge/BridgeDepositBox.sol/WETH9Like.json +31 -0
  146. package/artifacts/contracts/insured-bridge/BridgePool.sol/BridgePool.dbg.json +4 -0
  147. package/artifacts/contracts/insured-bridge/BridgePool.sol/BridgePool.json +1709 -0
  148. package/artifacts/contracts/insured-bridge/BridgePool.sol/BridgePoolProd.dbg.json +4 -0
  149. package/artifacts/contracts/insured-bridge/BridgePool.sol/BridgePoolProd.json +1709 -0
  150. package/artifacts/contracts/insured-bridge/BridgePool.sol/WETH9Like.dbg.json +4 -0
  151. package/artifacts/contracts/insured-bridge/BridgePool.sol/WETH9Like.json +31 -0
  152. package/artifacts/contracts/insured-bridge/avm/AVM_BridgeDepositBox.sol/AVM_BridgeDepositBox.dbg.json +4 -0
  153. package/artifacts/contracts/insured-bridge/avm/AVM_BridgeDepositBox.sol/AVM_BridgeDepositBox.json +564 -0
  154. package/artifacts/contracts/insured-bridge/avm/AVM_BridgeDepositBox.sol/StandardBridgeLike.dbg.json +4 -0
  155. package/artifacts/contracts/insured-bridge/avm/AVM_BridgeDepositBox.sol/StandardBridgeLike.json +45 -0
  156. package/artifacts/contracts/insured-bridge/avm/Arbitrum_CrossDomainEnabled.sol/Arbitrum_CrossDomainEnabled.dbg.json +4 -0
  157. package/artifacts/contracts/insured-bridge/avm/Arbitrum_CrossDomainEnabled.sol/Arbitrum_CrossDomainEnabled.json +24 -0
  158. package/artifacts/contracts/insured-bridge/avm/Arbitrum_Messenger.sol/Arbitrum_Messenger.dbg.json +4 -0
  159. package/artifacts/contracts/insured-bridge/avm/Arbitrum_Messenger.sol/Arbitrum_Messenger.json +191 -0
  160. package/artifacts/contracts/insured-bridge/interfaces/BridgeAdminInterface.sol/BridgeAdminInterface.dbg.json +4 -0
  161. package/artifacts/contracts/insured-bridge/interfaces/BridgeAdminInterface.sol/BridgeAdminInterface.json +319 -0
  162. package/artifacts/contracts/insured-bridge/interfaces/BridgePoolInterface.sol/BridgePoolInterface.dbg.json +4 -0
  163. package/artifacts/contracts/insured-bridge/interfaces/BridgePoolInterface.sol/BridgePoolInterface.json +63 -0
  164. package/artifacts/contracts/insured-bridge/interfaces/MessengerInterface.sol/MessengerInterface.dbg.json +4 -0
  165. package/artifacts/contracts/insured-bridge/interfaces/MessengerInterface.sol/MessengerInterface.json +54 -0
  166. package/artifacts/contracts/insured-bridge/ovm/OVM_BridgeDepositBox.sol/OVM_BridgeDepositBox.dbg.json +4 -0
  167. package/artifacts/contracts/insured-bridge/ovm/OVM_BridgeDepositBox.sol/OVM_BridgeDepositBox.json +528 -0
  168. package/artifacts/contracts/insured-bridge/ovm/OVM_CrossDomainEnabled.sol/OVM_CrossDomainEnabled.dbg.json +4 -0
  169. package/artifacts/contracts/insured-bridge/ovm/OVM_CrossDomainEnabled.sol/OVM_CrossDomainEnabled.json +35 -0
  170. package/artifacts/contracts/insured-bridge/ovm/OVM_OETH_BridgeDepositBox.sol/OVM_OETH_BridgeDepositBox.dbg.json +4 -0
  171. package/artifacts/contracts/insured-bridge/ovm/OVM_OETH_BridgeDepositBox.sol/OVM_OETH_BridgeDepositBox.json +572 -0
  172. package/artifacts/contracts/insured-bridge/ovm/Optimism_Messenger.sol/Optimism_Messenger.dbg.json +4 -0
  173. package/artifacts/contracts/insured-bridge/ovm/Optimism_Messenger.sol/Optimism_Messenger.json +130 -0
  174. package/artifacts/contracts/insured-bridge/ovm/Optimism_Wrapper.sol/Optimism_Wrapper.dbg.json +4 -0
  175. package/artifacts/contracts/insured-bridge/ovm/Optimism_Wrapper.sol/Optimism_Wrapper.json +142 -0
  176. package/artifacts/contracts/insured-bridge/ovm/Optimism_Wrapper.sol/WETH9Like.dbg.json +4 -0
  177. package/artifacts/contracts/insured-bridge/ovm/Optimism_Wrapper.sol/WETH9Like.json +55 -0
  178. package/artifacts/contracts/insured-bridge/ovm/iOVM_CrossDomainMessenger.sol/iOVM_CrossDomainMessenger.dbg.json +4 -0
  179. package/artifacts/contracts/insured-bridge/ovm/iOVM_CrossDomainMessenger.sol/iOVM_CrossDomainMessenger.json +86 -0
  180. package/artifacts/contracts/insured-bridge/test/Arbitrum_InboxMock.sol/Arbitrum_BridgeMock.dbg.json +4 -0
  181. package/artifacts/contracts/insured-bridge/test/Arbitrum_InboxMock.sol/Arbitrum_BridgeMock.json +68 -0
  182. package/artifacts/contracts/insured-bridge/test/Arbitrum_InboxMock.sol/Arbitrum_InboxMock.dbg.json +4 -0
  183. package/artifacts/contracts/insured-bridge/test/Arbitrum_InboxMock.sol/Arbitrum_InboxMock.json +78 -0
  184. package/artifacts/contracts/insured-bridge/test/Arbitrum_InboxMock.sol/Arbitrum_OutboxMock.dbg.json +4 -0
  185. package/artifacts/contracts/insured-bridge/test/Arbitrum_InboxMock.sol/Arbitrum_OutboxMock.json +24 -0
  186. package/artifacts/contracts/insured-bridge/test/BridgeDepositBoxMock.sol/BridgeDepositBoxMock.dbg.json +4 -0
  187. package/artifacts/contracts/insured-bridge/test/BridgeDepositBoxMock.sol/BridgeDepositBoxMock.json +510 -0
  188. package/artifacts/contracts/insured-bridge/test/MessengerMock.sol/MessengerMock.dbg.json +4 -0
  189. package/artifacts/contracts/insured-bridge/test/MessengerMock.sol/MessengerMock.json +85 -0
  190. package/artifacts/contracts/insured-bridge/test/OVM_L1CrossDomainMessengerMock.sol/OVM_L1CrossDomainMessengerMock.dbg.json +4 -0
  191. package/artifacts/contracts/insured-bridge/test/OVM_L1CrossDomainMessengerMock.sol/OVM_L1CrossDomainMessengerMock.json +110 -0
  192. package/artifacts/contracts/oracle/implementation/Constants.sol/OptimisticOracleConstraints.dbg.json +4 -0
  193. package/artifacts/contracts/oracle/implementation/Constants.sol/OptimisticOracleConstraints.json +24 -0
  194. package/artifacts/contracts/oracle/implementation/Constants.sol/OracleInterfaces.dbg.json +4 -0
  195. package/artifacts/contracts/oracle/implementation/Constants.sol/OracleInterfaces.json +141 -0
  196. package/artifacts/contracts/oracle/interfaces/FinderInterface.sol/FinderInterface.dbg.json +4 -0
  197. package/artifacts/contracts/oracle/interfaces/FinderInterface.sol/FinderInterface.json +48 -0
  198. package/artifacts/contracts/oracle/interfaces/IdentifierWhitelistInterface.sol/IdentifierWhitelistInterface.dbg.json +4 -0
  199. package/artifacts/contracts/oracle/interfaces/IdentifierWhitelistInterface.sol/IdentifierWhitelistInterface.json +56 -0
  200. package/artifacts/contracts/oracle/interfaces/OptimisticOracleInterface.sol/OptimisticOracleInterface.dbg.json +4 -0
  201. package/artifacts/contracts/oracle/interfaces/OptimisticOracleInterface.sol/OptimisticOracleInterface.json +555 -0
  202. package/artifacts/contracts/oracle/interfaces/SkinnyOptimisticOracleInterface.sol/SkinnyOptimisticOracleInterface.dbg.json +4 -0
  203. package/artifacts/contracts/oracle/interfaces/SkinnyOptimisticOracleInterface.sol/SkinnyOptimisticOracleInterface.json +853 -0
  204. package/artifacts/contracts/oracle/interfaces/StoreInterface.sol/StoreInterface.dbg.json +4 -0
  205. package/artifacts/contracts/oracle/interfaces/StoreInterface.sol/StoreInterface.json +124 -0
  206. package/contracts/common/implementation/AncillaryData.sol +144 -0
  207. package/contracts/common/implementation/FixedPoint.sol +763 -0
  208. package/contracts/common/implementation/Lockable.sol +61 -0
  209. package/contracts/common/implementation/MultiCaller.sol +27 -0
  210. package/contracts/common/implementation/Testable.sol +52 -0
  211. package/contracts/common/implementation/Timer.sol +30 -0
  212. package/contracts/common/interfaces/AddressWhitelistInterface.sol +12 -0
  213. package/contracts/external/avm/AVM_CrossDomainEnabled.sol +43 -0
  214. package/contracts/external/avm/interfaces/ArbSys.sol +79 -0
  215. package/contracts/external/avm/interfaces/iArbitrum_Inbox.sol +28 -0
  216. package/contracts/external/avm/interfaces/iArbitrum_Outbox.sol +26 -0
  217. package/contracts/external/chainbridge/Bridge.sol +454 -0
  218. package/contracts/external/chainbridge/handlers/GenericHandler.sol +237 -0
  219. package/contracts/external/chainbridge/interfaces/IBridge.sol +20 -0
  220. package/contracts/external/chainbridge/interfaces/IDepositExecute.sol +29 -0
  221. package/contracts/external/chainbridge/interfaces/IERCHandler.sol +33 -0
  222. package/contracts/external/chainbridge/interfaces/IGenericHandler.sol +23 -0
  223. package/contracts/external/ovm/OVM_CrossDomainEnabled.sol +114 -0
  224. package/contracts/external/polygon/lib/Merkle.sol +36 -0
  225. package/contracts/external/polygon/lib/MerklePatriciaProof.sol +139 -0
  226. package/contracts/external/polygon/lib/RLPReader.sol +251 -0
  227. package/contracts/external/polygon/test/FxChildMock.sol +42 -0
  228. package/contracts/external/polygon/test/FxRootMock.sol +32 -0
  229. package/contracts/external/polygon/test/StateSyncMock.sol +26 -0
  230. package/contracts/external/polygon/tunnel/FxBaseChildTunnel.sol +80 -0
  231. package/contracts/external/polygon/tunnel/FxBaseRootTunnel.sol +185 -0
  232. package/contracts/insured-bridge/BridgeAdmin.sol +394 -0
  233. package/contracts/insured-bridge/BridgeDepositBox.sol +245 -0
  234. package/contracts/insured-bridge/BridgePool.sol +980 -0
  235. package/contracts/insured-bridge/avm/AVM_BridgeDepositBox.sol +144 -0
  236. package/contracts/insured-bridge/avm/Arbitrum_CrossDomainEnabled.sol +67 -0
  237. package/contracts/insured-bridge/avm/Arbitrum_Messenger.sol +72 -0
  238. package/contracts/insured-bridge/interfaces/BridgeAdminInterface.sol +44 -0
  239. package/contracts/insured-bridge/interfaces/BridgePoolInterface.sol +14 -0
  240. package/contracts/insured-bridge/interfaces/MessengerInterface.sol +18 -0
  241. package/contracts/insured-bridge/ovm/OVM_BridgeDepositBox.sol +135 -0
  242. package/contracts/insured-bridge/ovm/OVM_CrossDomainEnabled.sol +84 -0
  243. package/contracts/insured-bridge/ovm/OVM_OETH_BridgeDepositBox.sol +89 -0
  244. package/contracts/insured-bridge/ovm/Optimism_Messenger.sol +34 -0
  245. package/contracts/insured-bridge/ovm/Optimism_Wrapper.sol +59 -0
  246. package/contracts/insured-bridge/ovm/iOVM_CrossDomainMessenger.sol +41 -0
  247. package/contracts/insured-bridge/test/Arbitrum_InboxMock.sol +50 -0
  248. package/contracts/insured-bridge/test/BridgeDepositBoxMock.sol +113 -0
  249. package/contracts/insured-bridge/test/MessengerMock.sol +32 -0
  250. package/contracts/insured-bridge/test/OVM_L1CrossDomainMessengerMock.sol +16 -0
  251. package/contracts/oracle/implementation/Constants.sol +29 -0
  252. package/contracts/oracle/interfaces/FinderInterface.sol +22 -0
  253. package/contracts/oracle/interfaces/IdentifierWhitelistInterface.sol +28 -0
  254. package/contracts/oracle/interfaces/OptimisticOracleInterface.sol +263 -0
  255. package/contracts/oracle/interfaces/SkinnyOptimisticOracleInterface.sol +251 -0
  256. package/contracts/oracle/interfaces/StoreInterface.sol +46 -0
  257. package/package.json +60 -0
@@ -0,0 +1,454 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
+ pragma solidity ^0.8.0;
3
+
4
+ import "@openzeppelin/contracts/access/AccessControl.sol";
5
+ import "@openzeppelin/contracts/security/Pausable.sol";
6
+ import "@openzeppelin/contracts/utils/math/SafeMath.sol";
7
+ import "./interfaces/IDepositExecute.sol";
8
+ import "./interfaces/IBridge.sol";
9
+ import "./interfaces/IERCHandler.sol";
10
+ import "./interfaces/IGenericHandler.sol";
11
+
12
+ /**
13
+ @title Facilitates deposits, creation and votiing of deposit proposals, and deposit executions.
14
+ @author ChainSafe Systems.
15
+ */
16
+ contract Bridge is Pausable, AccessControl {
17
+ using SafeMath for uint256;
18
+
19
+ uint8 public _chainID;
20
+ uint256 public _relayerThreshold;
21
+ uint256 public _totalRelayers;
22
+ uint256 public _totalProposals;
23
+ uint256 public _fee;
24
+ uint256 public _expiry;
25
+
26
+ enum Vote { No, Yes }
27
+
28
+ enum ProposalStatus { Inactive, Active, Passed, Executed, Cancelled }
29
+
30
+ struct Proposal {
31
+ bytes32 _resourceID;
32
+ bytes32 _dataHash;
33
+ address[] _yesVotes;
34
+ address[] _noVotes;
35
+ ProposalStatus _status;
36
+ uint256 _proposedBlock;
37
+ }
38
+
39
+ // destinationChainID => number of deposits
40
+ mapping(uint8 => uint64) public _depositCounts;
41
+ // resourceID => handler address
42
+ mapping(bytes32 => address) public _resourceIDToHandlerAddress;
43
+ // depositNonce => destinationChainID => bytes
44
+ mapping(uint64 => mapping(uint8 => bytes)) public _depositRecords;
45
+ // destinationChainID + depositNonce => dataHash => Proposal
46
+ mapping(uint72 => mapping(bytes32 => Proposal)) public _proposals;
47
+ // destinationChainID + depositNonce => dataHash => relayerAddress => bool
48
+ mapping(uint72 => mapping(bytes32 => mapping(address => bool))) public _hasVotedOnProposal;
49
+
50
+ event RelayerThresholdChanged(uint256 indexed newThreshold);
51
+ event RelayerAdded(address indexed relayer);
52
+ event RelayerRemoved(address indexed relayer);
53
+ event Deposit(uint8 indexed destinationChainID, bytes32 indexed resourceID, uint64 indexed depositNonce);
54
+ event ProposalEvent(
55
+ uint8 indexed originChainID,
56
+ uint64 indexed depositNonce,
57
+ ProposalStatus indexed status,
58
+ bytes32 resourceID,
59
+ bytes32 dataHash
60
+ );
61
+
62
+ event ProposalVote(
63
+ uint8 indexed originChainID,
64
+ uint64 indexed depositNonce,
65
+ ProposalStatus indexed status,
66
+ bytes32 resourceID
67
+ );
68
+
69
+ bytes32 public constant RELAYER_ROLE = keccak256("RELAYER_ROLE");
70
+
71
+ modifier onlyAdmin() {
72
+ _onlyAdmin();
73
+ _;
74
+ }
75
+
76
+ modifier onlyAdminOrRelayer() {
77
+ _onlyAdminOrRelayer();
78
+ _;
79
+ }
80
+
81
+ modifier onlyRelayers() {
82
+ _onlyRelayers();
83
+ _;
84
+ }
85
+
86
+ function _onlyAdminOrRelayer() private view {
87
+ require(
88
+ hasRole(DEFAULT_ADMIN_ROLE, msg.sender) || hasRole(RELAYER_ROLE, msg.sender),
89
+ "sender is not relayer or admin"
90
+ );
91
+ }
92
+
93
+ function _onlyAdmin() private view {
94
+ require(hasRole(DEFAULT_ADMIN_ROLE, msg.sender), "sender doesn't have admin role");
95
+ }
96
+
97
+ function _onlyRelayers() private view {
98
+ require(hasRole(RELAYER_ROLE, msg.sender), "sender doesn't have relayer role");
99
+ }
100
+
101
+ /**
102
+ @notice Initializes Bridge, creates and grants {msg.sender} the admin role,
103
+ creates and grants {initialRelayers} the relayer role.
104
+ @param chainID ID of chain the Bridge contract exists on.
105
+ @param initialRelayers Addresses that should be initially granted the relayer role.
106
+ @param initialRelayerThreshold Number of votes needed for a deposit proposal to be considered passed.
107
+ */
108
+ constructor(
109
+ uint8 chainID,
110
+ address[] memory initialRelayers,
111
+ uint256 initialRelayerThreshold,
112
+ uint256 fee,
113
+ uint256 expiry
114
+ ) {
115
+ _chainID = chainID;
116
+ _relayerThreshold = initialRelayerThreshold;
117
+ _fee = fee;
118
+ _expiry = expiry;
119
+
120
+ _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
121
+ _setRoleAdmin(RELAYER_ROLE, DEFAULT_ADMIN_ROLE);
122
+
123
+ for (uint256 i; i < initialRelayers.length; i++) {
124
+ grantRole(RELAYER_ROLE, initialRelayers[i]);
125
+ _totalRelayers++;
126
+ }
127
+ }
128
+
129
+ /**
130
+ @notice Returns true if {relayer} has the relayer role.
131
+ @param relayer Address to check.
132
+ */
133
+ function isRelayer(address relayer) external view returns (bool) {
134
+ return hasRole(RELAYER_ROLE, relayer);
135
+ }
136
+
137
+ /**
138
+ @notice Removes admin role from {msg.sender} and grants it to {newAdmin}.
139
+ @notice Only callable by an address that currently has the admin role.
140
+ @param newAdmin Address that admin role will be granted to.
141
+ */
142
+ function renounceAdmin(address newAdmin) external onlyAdmin {
143
+ grantRole(DEFAULT_ADMIN_ROLE, newAdmin);
144
+ renounceRole(DEFAULT_ADMIN_ROLE, msg.sender);
145
+ }
146
+
147
+ /**
148
+ @notice Pauses deposits, proposal creation and voting, and deposit executions.
149
+ @notice Only callable by an address that currently has the admin role.
150
+ */
151
+ function adminPauseTransfers() external onlyAdmin {
152
+ _pause();
153
+ }
154
+
155
+ /**
156
+ @notice Unpauses deposits, proposal creation and voting, and deposit executions.
157
+ @notice Only callable by an address that currently has the admin role.
158
+ */
159
+ function adminUnpauseTransfers() external onlyAdmin {
160
+ _unpause();
161
+ }
162
+
163
+ /**
164
+ @notice Modifies the number of votes required for a proposal to be considered passed.
165
+ @notice Only callable by an address that currently has the admin role.
166
+ @param newThreshold Value {_relayerThreshold} will be changed to.
167
+ @notice Emits {RelayerThresholdChanged} event.
168
+ */
169
+ function adminChangeRelayerThreshold(uint256 newThreshold) external onlyAdmin {
170
+ _relayerThreshold = newThreshold;
171
+ emit RelayerThresholdChanged(newThreshold);
172
+ }
173
+
174
+ /**
175
+ @notice Grants {relayerAddress} the relayer role and increases {_totalRelayer} count.
176
+ @notice Only callable by an address that currently has the admin role.
177
+ @param relayerAddress Address of relayer to be added.
178
+ @notice Emits {RelayerAdded} event.
179
+ */
180
+ function adminAddRelayer(address relayerAddress) external onlyAdmin {
181
+ require(!hasRole(RELAYER_ROLE, relayerAddress), "addr already has relayer role!");
182
+ grantRole(RELAYER_ROLE, relayerAddress);
183
+ emit RelayerAdded(relayerAddress);
184
+ _totalRelayers++;
185
+ }
186
+
187
+ /**
188
+ @notice Removes relayer role for {relayerAddress} and decreases {_totalRelayer} count.
189
+ @notice Only callable by an address that currently has the admin role.
190
+ @param relayerAddress Address of relayer to be removed.
191
+ @notice Emits {RelayerRemoved} event.
192
+ */
193
+ function adminRemoveRelayer(address relayerAddress) external onlyAdmin {
194
+ require(hasRole(RELAYER_ROLE, relayerAddress), "addr doesn't have relayer role!");
195
+ revokeRole(RELAYER_ROLE, relayerAddress);
196
+ emit RelayerRemoved(relayerAddress);
197
+ _totalRelayers--;
198
+ }
199
+
200
+ /**
201
+ @notice Sets a new resource for handler contracts that use the IERCHandler interface,
202
+ and maps the {handlerAddress} to {resourceID} in {_resourceIDToHandlerAddress}.
203
+ @notice Only callable by an address that currently has the admin role.
204
+ @param handlerAddress Address of handler resource will be set for.
205
+ @param resourceID ResourceID to be used when making deposits.
206
+ @param tokenAddress Address of contract to be called when a deposit is made and a deposited is executed.
207
+ */
208
+ function adminSetResource(
209
+ address handlerAddress,
210
+ bytes32 resourceID,
211
+ address tokenAddress
212
+ ) external onlyAdmin {
213
+ _resourceIDToHandlerAddress[resourceID] = handlerAddress;
214
+ IERCHandler handler = IERCHandler(handlerAddress);
215
+ handler.setResource(resourceID, tokenAddress);
216
+ }
217
+
218
+ /**
219
+ @notice Sets a new resource for handler contracts that use the IGenericHandler interface,
220
+ and maps the {handlerAddress} to {resourceID} in {_resourceIDToHandlerAddress}.
221
+ @notice Only callable by an address that currently has the admin role.
222
+ @param handlerAddress Address of handler resource will be set for.
223
+ @param resourceID ResourceID to be used when making deposits.
224
+ @param contractAddress Address of contract to be called when a deposit is made and a deposited is executed.
225
+ */
226
+ function adminSetGenericResource(
227
+ address handlerAddress,
228
+ bytes32 resourceID,
229
+ address contractAddress,
230
+ bytes4 depositFunctionSig,
231
+ bytes4 executeFunctionSig
232
+ ) external onlyAdmin {
233
+ _resourceIDToHandlerAddress[resourceID] = handlerAddress;
234
+ IGenericHandler handler = IGenericHandler(handlerAddress);
235
+ handler.setResource(resourceID, contractAddress, depositFunctionSig, executeFunctionSig);
236
+ }
237
+
238
+ /**
239
+ @notice Sets a resource as burnable for handler contracts that use the IERCHandler interface.
240
+ @notice Only callable by an address that currently has the admin role.
241
+ @param handlerAddress Address of handler resource will be set for.
242
+ @param tokenAddress Address of contract to be called when a deposit is made and a deposited is executed.
243
+ */
244
+ function adminSetBurnable(address handlerAddress, address tokenAddress) external onlyAdmin {
245
+ IERCHandler handler = IERCHandler(handlerAddress);
246
+ handler.setBurnable(tokenAddress);
247
+ }
248
+
249
+ /**
250
+ @notice Returns a proposal.
251
+ @param originChainID Chain ID deposit originated from.
252
+ @param depositNonce ID of proposal generated by proposal's origin Bridge contract.
253
+ @param dataHash Hash of data to be provided when deposit proposal is executed.
254
+ @return Proposal which consists of:
255
+ - _dataHash Hash of data to be provided when deposit proposal is executed.
256
+ - _yesVotes Number of votes in favor of proposal.
257
+ - _noVotes Number of votes against proposal.
258
+ - _status Current status of proposal.
259
+ */
260
+ function getProposal(
261
+ uint8 originChainID,
262
+ uint64 depositNonce,
263
+ bytes32 dataHash
264
+ ) external view returns (Proposal memory) {
265
+ uint72 nonceAndID = (uint72(depositNonce) << 8) | uint72(originChainID);
266
+ return _proposals[nonceAndID][dataHash];
267
+ }
268
+
269
+ /**
270
+ @notice Changes deposit fee.
271
+ @notice Only callable by admin.
272
+ @param newFee Value {_fee} will be updated to.
273
+ */
274
+ function adminChangeFee(uint256 newFee) external onlyAdmin {
275
+ require(_fee != newFee, "Current fee is equal to new fee");
276
+ _fee = newFee;
277
+ }
278
+
279
+ /**
280
+ @notice Used to manually withdraw funds from ERC safes.
281
+ @param handlerAddress Address of handler to withdraw from.
282
+ @param tokenAddress Address of token to withdraw.
283
+ @param recipient Address to withdraw tokens to.
284
+ @param amountOrTokenID Either the amount of ERC20 tokens or the ERC721 token ID to withdraw.
285
+ */
286
+ function adminWithdraw(
287
+ address handlerAddress,
288
+ address tokenAddress,
289
+ address recipient,
290
+ uint256 amountOrTokenID
291
+ ) external onlyAdmin {
292
+ IERCHandler handler = IERCHandler(handlerAddress);
293
+ handler.withdraw(tokenAddress, recipient, amountOrTokenID);
294
+ }
295
+
296
+ /**
297
+ @notice Initiates a transfer using a specified handler contract.
298
+ @notice Only callable when Bridge is not paused.
299
+ @param destinationChainID ID of chain deposit will be bridged to.
300
+ @param resourceID ResourceID used to find address of handler to be used for deposit.
301
+ @param data Additional data to be passed to specified handler.
302
+ @notice Emits {Deposit} event.
303
+ */
304
+ function deposit(
305
+ uint8 destinationChainID,
306
+ bytes32 resourceID,
307
+ bytes calldata data
308
+ ) external payable whenNotPaused {
309
+ require(msg.value == _fee, "Incorrect fee supplied");
310
+
311
+ address handler = _resourceIDToHandlerAddress[resourceID];
312
+ require(handler != address(0), "resourceID not mapped to handler");
313
+
314
+ uint64 depositNonce = ++_depositCounts[destinationChainID];
315
+ _depositRecords[depositNonce][destinationChainID] = data;
316
+
317
+ IDepositExecute depositHandler = IDepositExecute(handler);
318
+ depositHandler.deposit(resourceID, destinationChainID, depositNonce, msg.sender, data);
319
+
320
+ emit Deposit(destinationChainID, resourceID, depositNonce);
321
+ }
322
+
323
+ /**
324
+ @notice When called, {msg.sender} will be marked as voting in favor of proposal.
325
+ @notice Only callable by relayers when Bridge is not paused.
326
+ @param chainID ID of chain deposit originated from.
327
+ @param depositNonce ID of deposited generated by origin Bridge contract.
328
+ @param dataHash Hash of data provided when deposit was made.
329
+ @notice Proposal must not have already been passed or executed.
330
+ @notice {msg.sender} must not have already voted on proposal.
331
+ @notice Emits {ProposalEvent} event with status indicating the proposal status.
332
+ @notice Emits {ProposalVote} event.
333
+ */
334
+ function voteProposal(
335
+ uint8 chainID,
336
+ uint64 depositNonce,
337
+ bytes32 resourceID,
338
+ bytes32 dataHash
339
+ ) external onlyRelayers whenNotPaused {
340
+ uint72 nonceAndID = (uint72(depositNonce) << 8) | uint72(chainID);
341
+ Proposal storage proposal = _proposals[nonceAndID][dataHash];
342
+
343
+ require(_resourceIDToHandlerAddress[resourceID] != address(0), "no handler for resourceID");
344
+ require(uint256(proposal._status) <= 1, "proposal already passed/executed/cancelled");
345
+ require(!_hasVotedOnProposal[nonceAndID][dataHash][msg.sender], "relayer already voted");
346
+
347
+ if (uint256(proposal._status) == 0) {
348
+ ++_totalProposals;
349
+ _proposals[nonceAndID][dataHash] = Proposal({
350
+ _resourceID: resourceID,
351
+ _dataHash: dataHash,
352
+ _yesVotes: new address[](1),
353
+ _noVotes: new address[](0),
354
+ _status: ProposalStatus.Active,
355
+ _proposedBlock: block.number
356
+ });
357
+
358
+ proposal._yesVotes[0] = msg.sender;
359
+ emit ProposalEvent(chainID, depositNonce, ProposalStatus.Active, resourceID, dataHash);
360
+ } else {
361
+ if (block.number.sub(proposal._proposedBlock) > _expiry) {
362
+ // if the number of blocks that has passed since this proposal was
363
+ // submitted exceeds the expiry threshold set, cancel the proposal
364
+ proposal._status = ProposalStatus.Cancelled;
365
+ emit ProposalEvent(chainID, depositNonce, ProposalStatus.Cancelled, resourceID, dataHash);
366
+ } else {
367
+ require(dataHash == proposal._dataHash, "datahash mismatch");
368
+ proposal._yesVotes.push(msg.sender);
369
+ }
370
+ }
371
+ if (proposal._status != ProposalStatus.Cancelled) {
372
+ _hasVotedOnProposal[nonceAndID][dataHash][msg.sender] = true;
373
+ emit ProposalVote(chainID, depositNonce, proposal._status, resourceID);
374
+
375
+ // If _depositThreshold is set to 1, then auto finalize
376
+ // or if _relayerThreshold has been exceeded
377
+ if (_relayerThreshold <= 1 || proposal._yesVotes.length >= _relayerThreshold) {
378
+ proposal._status = ProposalStatus.Passed;
379
+
380
+ emit ProposalEvent(chainID, depositNonce, ProposalStatus.Passed, resourceID, dataHash);
381
+ }
382
+ }
383
+ }
384
+
385
+ /**
386
+ @notice Executes a deposit proposal that is considered passed using a specified handler contract.
387
+ @notice Only callable by relayers when Bridge is not paused.
388
+ @param chainID ID of chain deposit originated from.
389
+ @param depositNonce ID of deposited generated by origin Bridge contract.
390
+ @param dataHash Hash of data originally provided when deposit was made.
391
+ @notice Proposal must be past expiry threshold.
392
+ @notice Emits {ProposalEvent} event with status {Cancelled}.
393
+ */
394
+ function cancelProposal(
395
+ uint8 chainID,
396
+ uint64 depositNonce,
397
+ bytes32 dataHash
398
+ ) public onlyAdminOrRelayer {
399
+ uint72 nonceAndID = (uint72(depositNonce) << 8) | uint72(chainID);
400
+ Proposal storage proposal = _proposals[nonceAndID][dataHash];
401
+
402
+ require(proposal._status != ProposalStatus.Cancelled, "Proposal already cancelled");
403
+ require(block.number.sub(proposal._proposedBlock) > _expiry, "Proposal not at expiry threshold");
404
+
405
+ proposal._status = ProposalStatus.Cancelled;
406
+ emit ProposalEvent(chainID, depositNonce, ProposalStatus.Cancelled, proposal._resourceID, proposal._dataHash);
407
+ }
408
+
409
+ /**
410
+ @notice Executes a deposit proposal that is considered passed using a specified handler contract.
411
+ @notice Only callable by relayers when Bridge is not paused.
412
+ @param chainID ID of chain deposit originated from.
413
+ @param resourceID ResourceID to be used when making deposits.
414
+ @param depositNonce ID of deposited generated by origin Bridge contract.
415
+ @param data Data originally provided when deposit was made.
416
+ @notice Proposal must have Passed status.
417
+ @notice Hash of {data} must equal proposal's {dataHash}.
418
+ @notice Emits {ProposalEvent} event with status {Executed}.
419
+ */
420
+ function executeProposal(
421
+ uint8 chainID,
422
+ uint64 depositNonce,
423
+ bytes calldata data,
424
+ bytes32 resourceID
425
+ ) external onlyRelayers whenNotPaused {
426
+ address handler = _resourceIDToHandlerAddress[resourceID];
427
+ uint72 nonceAndID = (uint72(depositNonce) << 8) | uint72(chainID);
428
+ bytes32 dataHash = keccak256(abi.encodePacked(handler, data));
429
+ Proposal storage proposal = _proposals[nonceAndID][dataHash];
430
+
431
+ require(proposal._status != ProposalStatus.Inactive, "proposal is not active");
432
+ require(proposal._status == ProposalStatus.Passed, "proposal already transferred");
433
+ require(dataHash == proposal._dataHash, "data doesn't match datahash");
434
+
435
+ proposal._status = ProposalStatus.Executed;
436
+
437
+ IDepositExecute depositHandler = IDepositExecute(_resourceIDToHandlerAddress[proposal._resourceID]);
438
+ depositHandler.executeProposal(proposal._resourceID, data);
439
+
440
+ emit ProposalEvent(chainID, depositNonce, proposal._status, proposal._resourceID, proposal._dataHash);
441
+ }
442
+
443
+ /**
444
+ @notice Transfers eth in the contract to the specified addresses. The parameters addrs and amounts are mapped 1-1.
445
+ This means that the address at index 0 for addrs will receive the amount (in WEI) from amounts at index 0.
446
+ @param addrs Array of addresses to transfer {amounts} to.
447
+ @param amounts Array of amonuts to transfer to {addrs}.
448
+ */
449
+ function transferFunds(address payable[] calldata addrs, uint256[] calldata amounts) external onlyAdmin {
450
+ for (uint256 i = 0; i < addrs.length; i++) {
451
+ addrs[i].transfer(amounts[i]);
452
+ }
453
+ }
454
+ }
@@ -0,0 +1,237 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
+ pragma solidity ^0.8.0;
3
+
4
+ import "../interfaces/IGenericHandler.sol";
5
+
6
+ /**
7
+ @title Handles generic deposits and deposit executions.
8
+ @author ChainSafe Systems.
9
+ @notice This contract is intended to be used with the Bridge contract.
10
+ */
11
+ contract GenericHandler is IGenericHandler {
12
+ address public _bridgeAddress;
13
+
14
+ struct DepositRecord {
15
+ uint8 _destinationChainID;
16
+ address _depositer;
17
+ bytes32 _resourceID;
18
+ bytes _metaData;
19
+ }
20
+
21
+ // depositNonce => Deposit Record
22
+ mapping(uint8 => mapping(uint64 => DepositRecord)) public _depositRecords;
23
+
24
+ // resourceID => contract address
25
+ mapping(bytes32 => address) public _resourceIDToContractAddress;
26
+
27
+ // contract address => resourceID
28
+ mapping(address => bytes32) public _contractAddressToResourceID;
29
+
30
+ // contract address => deposit function signature
31
+ mapping(address => bytes4) public _contractAddressToDepositFunctionSignature;
32
+
33
+ // contract address => execute proposal function signature
34
+ mapping(address => bytes4) public _contractAddressToExecuteFunctionSignature;
35
+
36
+ // token contract address => is whitelisted
37
+ mapping(address => bool) public _contractWhitelist;
38
+
39
+ modifier onlyBridge() {
40
+ _onlyBridge();
41
+ _;
42
+ }
43
+
44
+ function _onlyBridge() private view {
45
+ require(msg.sender == _bridgeAddress, "sender must be bridge contract");
46
+ }
47
+
48
+ /**
49
+ @param bridgeAddress Contract address of previously deployed Bridge.
50
+ @param initialResourceIDs Resource IDs used to identify a specific contract address.
51
+ These are the Resource IDs this contract will initially support.
52
+ @param initialContractAddresses These are the addresses the {initialResourceIDs} will point to, and are the contracts that will be
53
+ called to perform deposit and execution calls.
54
+ @param initialDepositFunctionSignatures These are the function signatures {initialContractAddresses} will point to,
55
+ and are the function that will be called when executing {deposit}
56
+ @param initialExecuteFunctionSignatures These are the function signatures {initialContractAddresses} will point to,
57
+ and are the function that will be called when executing {executeProposal}
58
+
59
+ @dev {initialResourceIDs}, {initialContractAddresses}, {initialDepositFunctionSignatures},
60
+ and {initialExecuteFunctionSignatures} must all have the same length. Also,
61
+ values must be ordered in the way that that index x of any mentioned array
62
+ must be intended for value x of any other array, e.g. {initialContractAddresses}[0]
63
+ is the intended address for {initialDepositFunctionSignatures}[0].
64
+ */
65
+ constructor(
66
+ address bridgeAddress,
67
+ bytes32[] memory initialResourceIDs,
68
+ address[] memory initialContractAddresses,
69
+ bytes4[] memory initialDepositFunctionSignatures,
70
+ bytes4[] memory initialExecuteFunctionSignatures
71
+ ) {
72
+ require(
73
+ initialResourceIDs.length == initialContractAddresses.length,
74
+ "initialResourceIDs and initialContractAddresses len mismatch"
75
+ );
76
+
77
+ require(
78
+ initialContractAddresses.length == initialDepositFunctionSignatures.length,
79
+ "provided contract addresses and function signatures len mismatch"
80
+ );
81
+
82
+ require(
83
+ initialDepositFunctionSignatures.length == initialExecuteFunctionSignatures.length,
84
+ "provided deposit and execute function signatures len mismatch"
85
+ );
86
+
87
+ _bridgeAddress = bridgeAddress;
88
+
89
+ for (uint256 i = 0; i < initialResourceIDs.length; i++) {
90
+ _setResource(
91
+ initialResourceIDs[i],
92
+ initialContractAddresses[i],
93
+ initialDepositFunctionSignatures[i],
94
+ initialExecuteFunctionSignatures[i]
95
+ );
96
+ }
97
+ }
98
+
99
+ /**
100
+ @param depositNonce This ID will have been generated by the Bridge contract.
101
+ @param destId ID of chain deposit will be bridged to.
102
+ @return DepositRecord which consists of:
103
+ - _destinationChainID ChainID deposited tokens are intended to end up on.
104
+ - _resourceID ResourceID used when {deposit} was executed.
105
+ - _depositer Address that initially called {deposit} in the Bridge contract.
106
+ - _metaData Data to be passed to method executed in corresponding {resourceID} contract.
107
+ */
108
+ function getDepositRecord(uint64 depositNonce, uint8 destId) external view returns (DepositRecord memory) {
109
+ return _depositRecords[destId][depositNonce];
110
+ }
111
+
112
+ /**
113
+ @notice First verifies {_resourceIDToContractAddress}[{resourceID}] and
114
+ {_contractAddressToResourceID}[{contractAddress}] are not already set,
115
+ then sets {_resourceIDToContractAddress} with {contractAddress},
116
+ {_contractAddressToResourceID} with {resourceID},
117
+ {_contractAddressToDepositFunctionSignature} with {depositFunctionSig},
118
+ {_contractAddressToExecuteFunctionSignature} with {executeFunctionSig},
119
+ and {_contractWhitelist} to true for {contractAddress}.
120
+ @param resourceID ResourceID to be used when making deposits.
121
+ @param contractAddress Address of contract to be called when a deposit is made and a deposited is executed.
122
+ @param depositFunctionSig Function signature of method to be called in {contractAddress} when a deposit is made.
123
+ @param executeFunctionSig Function signature of method to be called in {contractAddress} when a deposit is executed.
124
+ */
125
+ function setResource(
126
+ bytes32 resourceID,
127
+ address contractAddress,
128
+ bytes4 depositFunctionSig,
129
+ bytes4 executeFunctionSig
130
+ ) external override onlyBridge {
131
+ _setResource(resourceID, contractAddress, depositFunctionSig, executeFunctionSig);
132
+ }
133
+
134
+ /**
135
+ @notice A deposit is initiatied by making a deposit in the Bridge contract.
136
+ @param destinationChainID Chain ID deposit is expected to be bridged to.
137
+ @param depositNonce This value is generated as an ID by the Bridge contract.
138
+ @param depositer Address of account making the deposit in the Bridge contract.
139
+ @notice {contractAddress} is required to be whitelisted
140
+ @notice If {_contractAddressToDepositFunctionSignature}[{contractAddress}] is set,
141
+ {metaData} is expected to consist of needed function arguments.
142
+ */
143
+ function deposit(
144
+ bytes32 resourceID,
145
+ uint8 destinationChainID,
146
+ uint64 depositNonce,
147
+ address depositer,
148
+ bytes calldata
149
+ ) external onlyBridge {
150
+ bytes32 lenMetadata;
151
+ bytes memory metadata;
152
+
153
+ assembly {
154
+ // Load length of metadata from data + 64
155
+ lenMetadata := calldataload(0xC4)
156
+ // Load free memory pointer
157
+ metadata := mload(0x40)
158
+
159
+ mstore(0x40, add(0x20, add(metadata, lenMetadata)))
160
+
161
+ // func sig (4) + destinationChainId (padded to 32) + depositNonce (32) + depositor (32) +
162
+ // bytes length (32) + resourceId (32) + length (32) = 0xC4
163
+
164
+ calldatacopy(
165
+ metadata, // copy to metadata
166
+ 0xC4, // copy from calldata after metadata length declaration @0xC4
167
+ sub(calldatasize(), 0xC4) // copy size (calldatasize - (0xC4 + the space metaData takes up))
168
+ )
169
+ }
170
+
171
+ address contractAddress = _resourceIDToContractAddress[resourceID];
172
+ require(_contractWhitelist[contractAddress], "provided contractAddress is not whitelisted");
173
+
174
+ bytes4 sig = _contractAddressToDepositFunctionSignature[contractAddress];
175
+ if (sig != bytes4(0)) {
176
+ bytes memory callData = abi.encodePacked(sig, metadata);
177
+ (bool success, ) = contractAddress.call(callData);
178
+ require(success, "delegatecall to contractAddress failed");
179
+ }
180
+
181
+ _depositRecords[destinationChainID][depositNonce] = DepositRecord(
182
+ destinationChainID,
183
+ depositer,
184
+ resourceID,
185
+ metadata
186
+ );
187
+ }
188
+
189
+ /**
190
+ @notice Proposal execution should be initiated when a proposal is finalized in the Bridge contract.
191
+ @notice {contractAddress} is required to be whitelisted
192
+ @notice If {_contractAddressToExecuteFunctionSignature}[{contractAddress}] is set,
193
+ {metaData} is expected to consist of needed function arguments.
194
+ */
195
+ function executeProposal(bytes32 resourceID, bytes calldata) external onlyBridge {
196
+ bytes memory metaData;
197
+ assembly {
198
+ // metadata has variable length
199
+ // load free memory pointer to store metadata
200
+ metaData := mload(0x40)
201
+ // first 32 bytes of variable length in storage refer to length
202
+ let lenMeta := calldataload(0x64)
203
+ mstore(0x40, add(0x60, add(metaData, lenMeta)))
204
+
205
+ // in the calldata, metadata is stored @0x64 after accounting for function signature, and 2 previous params
206
+ calldatacopy(
207
+ metaData, // copy to metaData
208
+ 0x64, // copy from calldata after data length declaration at 0x64
209
+ sub(calldatasize(), 0x64) // copy size (calldatasize - 0x64)
210
+ )
211
+ }
212
+
213
+ address contractAddress = _resourceIDToContractAddress[resourceID];
214
+ require(_contractWhitelist[contractAddress], "provided contractAddress is not whitelisted");
215
+
216
+ bytes4 sig = _contractAddressToExecuteFunctionSignature[contractAddress];
217
+ if (sig != bytes4(0)) {
218
+ bytes memory callData = abi.encodePacked(sig, metaData);
219
+ (bool success, ) = contractAddress.call(callData);
220
+ require(success, "delegatecall to contractAddress failed");
221
+ }
222
+ }
223
+
224
+ function _setResource(
225
+ bytes32 resourceID,
226
+ address contractAddress,
227
+ bytes4 depositFunctionSig,
228
+ bytes4 executeFunctionSig
229
+ ) internal {
230
+ _resourceIDToContractAddress[resourceID] = contractAddress;
231
+ _contractAddressToResourceID[contractAddress] = resourceID;
232
+ _contractAddressToDepositFunctionSignature[contractAddress] = depositFunctionSig;
233
+ _contractAddressToExecuteFunctionSignature[contractAddress] = executeFunctionSig;
234
+
235
+ _contractWhitelist[contractAddress] = true;
236
+ }
237
+ }