|
| 1 | +# ABridge |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +#### License: MIT |
| 6 | + |
| 7 | +```solidity |
| 8 | +abstract contract ABridge is IBridge, Initializable, AERC20Handler, AERC721Handler, AERC1155Handler, ANativeHandler |
| 9 | +``` |
| 10 | + |
| 11 | +The Bridge module |
| 12 | + |
| 13 | +The Bridge contract facilitates the permissioned transfer of assets (ERC-20, ERC-721, ERC-1155, Native) |
| 14 | +between two (or more) EVM blockchains. |
| 15 | + |
| 16 | +To utilize the Bridge effectively, instances of this contract must be deployed on both base and destination chains, |
| 17 | +accompanied by the setup of trusted back ends to act as signers. |
| 18 | + |
| 19 | +The Bridge contract supports both "liquidity pool" and "mint-and-burn" methods for managing assets. |
| 20 | +The back end signatures are checked only upon token withdrawals. If "mint-and-burn" method is used, |
| 21 | +the ERC-20 tokens are required to support ERC-7802 interface. |
| 22 | + |
| 23 | +The Bridge is also suitable for bridged USDC tokens, utilizing their interface |
| 24 | +(https://github.com/circlefin/stablecoin-evm/blob/master/doc/bridged_USDC_standard.md). |
| 25 | + |
| 26 | +IMPORTANT: |
| 27 | +All signer addresses must differ in their first (most significant) 8 bits in order to pass bloom (uniqueness) filtering. |
| 28 | +## Structs info |
| 29 | + |
| 30 | +### ABridgeStorage |
| 31 | + |
| 32 | +```solidity |
| 33 | +struct ABridgeStorage { |
| 34 | + uint256 signaturesThreshold; |
| 35 | + mapping(bytes32 => bool) usedHashes; |
| 36 | + EnumerableSet.AddressSet signers; |
| 37 | +} |
| 38 | +``` |
| 39 | + |
| 40 | + |
| 41 | +## Functions info |
| 42 | + |
| 43 | +### depositERC20 (0xfacd085f) |
| 44 | + |
| 45 | +```solidity |
| 46 | +function depositERC20( |
| 47 | + address token_, |
| 48 | + uint256 amount_, |
| 49 | + string calldata receiver_, |
| 50 | + string calldata network_, |
| 51 | + IBridge.ERC20BridgingType operationType_ |
| 52 | +) external virtual override |
| 53 | +``` |
| 54 | + |
| 55 | +Deposits ERC20 tokens for bridging, emitting a `DepositedERC20` event. |
| 56 | + |
| 57 | + |
| 58 | +Parameters: |
| 59 | + |
| 60 | +| Name | Type | Description | |
| 61 | +| :------------- | :----------------------------- | :------------------------------------------------------------------------------------------------ | |
| 62 | +| token_ | address | The address of the deposited token. | |
| 63 | +| amount_ | uint256 | The amount of deposited tokens. | |
| 64 | +| receiver_ | string | The receiver's address in the destination network, used as an informational field for the event. | |
| 65 | +| network_ | string | The name of the destination network, used as an informational field for the event. | |
| 66 | +| operationType_ | enum IBridge.ERC20BridgingType | The type of bridging operation being performed. | |
| 67 | + |
| 68 | +### depositERC721 (0x86259187) |
| 69 | + |
| 70 | +```solidity |
| 71 | +function depositERC721( |
| 72 | + address token_, |
| 73 | + uint256 tokenId_, |
| 74 | + string calldata receiver_, |
| 75 | + string calldata network_, |
| 76 | + IBridge.ERC721BridgingType operationType_ |
| 77 | +) external virtual override |
| 78 | +``` |
| 79 | + |
| 80 | +Deposits ERC721 tokens for bridging, emitting a `DepositedERC721` event. |
| 81 | + |
| 82 | + |
| 83 | +Parameters: |
| 84 | + |
| 85 | +| Name | Type | Description | |
| 86 | +| :------------- | :------------------------------ | :------------------------------------------------------------------------------------------------ | |
| 87 | +| token_ | address | The address of the deposited token. | |
| 88 | +| tokenId_ | uint256 | The ID of the deposited token. | |
| 89 | +| receiver_ | string | The receiver's address in the destination network, used as an informational field for the event. | |
| 90 | +| network_ | string | The name of the destination network, used as an informational field for the event. | |
| 91 | +| operationType_ | enum IBridge.ERC721BridgingType | The type of bridging operation being performed. | |
| 92 | + |
| 93 | +### depositERC1155 (0x125f8f88) |
| 94 | + |
| 95 | +```solidity |
| 96 | +function depositERC1155( |
| 97 | + address token_, |
| 98 | + uint256 tokenId_, |
| 99 | + uint256 amount_, |
| 100 | + string calldata receiver_, |
| 101 | + string calldata network_, |
| 102 | + IBridge.ERC1155BridgingType operationType_ |
| 103 | +) external virtual override |
| 104 | +``` |
| 105 | + |
| 106 | +Deposits ERC1155 tokens for bridging, emitting a `DepositedERC1155` event. |
| 107 | + |
| 108 | + |
| 109 | +Parameters: |
| 110 | + |
| 111 | +| Name | Type | Description | |
| 112 | +| :------------- | :------------------------------- | :------------------------------------------------------------------------------------------------ | |
| 113 | +| token_ | address | The address of the deposited tokens. | |
| 114 | +| tokenId_ | uint256 | The ID of the deposited tokens. | |
| 115 | +| amount_ | uint256 | The amount of deposited tokens. | |
| 116 | +| receiver_ | string | The receiver's address in the destination network, used as an informational field for the event. | |
| 117 | +| network_ | string | The name of the destination network, used as an informational field for the event. | |
| 118 | +| operationType_ | enum IBridge.ERC1155BridgingType | The type of bridging operation being performed. | |
| 119 | + |
| 120 | +### depositNative (0x8609d28c) |
| 121 | + |
| 122 | +```solidity |
| 123 | +function depositNative( |
| 124 | + string calldata receiver_, |
| 125 | + string calldata network_ |
| 126 | +) external payable virtual override |
| 127 | +``` |
| 128 | + |
| 129 | +function for depositing native currency, emits event DepositedNative |
| 130 | + |
| 131 | + |
| 132 | +Parameters: |
| 133 | + |
| 134 | +| Name | Type | Description | |
| 135 | +| :-------- | :----- | :------------------------------------------------------------------------ | |
| 136 | +| receiver_ | string | the receiver address in destination network, information field for event | |
| 137 | +| network_ | string | the network name of destination network, information field for event | |
| 138 | + |
| 139 | +### withdrawERC20 (0x0481fd35) |
| 140 | + |
| 141 | +```solidity |
| 142 | +function withdrawERC20( |
| 143 | + address token_, |
| 144 | + uint256 amount_, |
| 145 | + address receiver_, |
| 146 | + bytes32 txHash_, |
| 147 | + uint256 txNonce_, |
| 148 | + IBridge.ERC20BridgingType operationType_, |
| 149 | + bytes[] calldata signatures_ |
| 150 | +) external virtual override |
| 151 | +``` |
| 152 | + |
| 153 | +Withdraws ERC20 tokens. |
| 154 | + |
| 155 | + |
| 156 | +Parameters: |
| 157 | + |
| 158 | +| Name | Type | Description | |
| 159 | +| :------------- | :----------------------------- | :-------------------------------------------------------------------- | |
| 160 | +| token_ | address | The address of the token to withdraw. | |
| 161 | +| amount_ | uint256 | The amount of tokens to withdraw. | |
| 162 | +| receiver_ | address | The address of the withdrawal recipient. | |
| 163 | +| txHash_ | bytes32 | The hash of the deposit transaction. | |
| 164 | +| txNonce_ | uint256 | The nonce of the deposit transaction. | |
| 165 | +| operationType_ | enum IBridge.ERC20BridgingType | The type of bridging operation. | |
| 166 | +| signatures_ | bytes[] | An array of signatures, formed by signing a sign hash by each signer. | |
| 167 | + |
| 168 | +### withdrawERC721 (0xd9efd273) |
| 169 | + |
| 170 | +```solidity |
| 171 | +function withdrawERC721( |
| 172 | + address token_, |
| 173 | + uint256 tokenId_, |
| 174 | + address receiver_, |
| 175 | + bytes32 txHash_, |
| 176 | + uint256 txNonce_, |
| 177 | + string calldata tokenURI_, |
| 178 | + IBridge.ERC721BridgingType operationType_, |
| 179 | + bytes[] calldata signatures_ |
| 180 | +) external virtual override |
| 181 | +``` |
| 182 | + |
| 183 | +Withdraws ERC721 tokens. |
| 184 | + |
| 185 | + |
| 186 | +Parameters: |
| 187 | + |
| 188 | +| Name | Type | Description | |
| 189 | +| :------------- | :------------------------------ | :-------------------------------------------------------------------- | |
| 190 | +| token_ | address | The address of the token to withdraw. | |
| 191 | +| tokenId_ | uint256 | The ID of the token to withdraw. | |
| 192 | +| receiver_ | address | The address of the withdrawal recipient. | |
| 193 | +| txHash_ | bytes32 | The hash of the deposit transaction. | |
| 194 | +| txNonce_ | uint256 | The nonce of the deposit transaction. | |
| 195 | +| tokenURI_ | string | The string URI of the token metadata. | |
| 196 | +| operationType_ | enum IBridge.ERC721BridgingType | The type of bridging operation. | |
| 197 | +| signatures_ | bytes[] | An array of signatures, formed by signing a sign hash by each signer. | |
| 198 | + |
| 199 | +### withdrawERC1155 (0xaeb6f88f) |
| 200 | + |
| 201 | +```solidity |
| 202 | +function withdrawERC1155( |
| 203 | + address token_, |
| 204 | + uint256 tokenId_, |
| 205 | + uint256 amount_, |
| 206 | + address receiver_, |
| 207 | + bytes32 txHash_, |
| 208 | + uint256 txNonce_, |
| 209 | + string calldata tokenURI_, |
| 210 | + IBridge.ERC1155BridgingType operationType_, |
| 211 | + bytes[] calldata signatures_ |
| 212 | +) external virtual override |
| 213 | +``` |
| 214 | + |
| 215 | +Withdraws ERC1155 tokens. |
| 216 | + |
| 217 | + |
| 218 | +Parameters: |
| 219 | + |
| 220 | +| Name | Type | Description | |
| 221 | +| :------------- | :------------------------------- | :-------------------------------------------------------------------- | |
| 222 | +| token_ | address | The address of the token to withdraw. | |
| 223 | +| tokenId_ | uint256 | The ID of the token to withdraw. | |
| 224 | +| amount_ | uint256 | The amount of tokens to withdraw. | |
| 225 | +| receiver_ | address | The address of the withdrawal recipient. | |
| 226 | +| txHash_ | bytes32 | The hash of the deposit transaction. | |
| 227 | +| txNonce_ | uint256 | The nonce of the deposit transaction. | |
| 228 | +| tokenURI_ | string | The string URI of the token metadata. | |
| 229 | +| operationType_ | enum IBridge.ERC1155BridgingType | The type of bridging operation. | |
| 230 | +| signatures_ | bytes[] | An array of signatures, formed by signing a sign hash by each signer. | |
| 231 | + |
| 232 | +### withdrawNative (0x1c3d9c87) |
| 233 | + |
| 234 | +```solidity |
| 235 | +function withdrawNative( |
| 236 | + uint256 amount_, |
| 237 | + address receiver_, |
| 238 | + bytes32 txHash_, |
| 239 | + uint256 txNonce_, |
| 240 | + bytes[] calldata signatures_ |
| 241 | +) external virtual override |
| 242 | +``` |
| 243 | + |
| 244 | +Withdraws native currency. |
| 245 | + |
| 246 | + |
| 247 | +Parameters: |
| 248 | + |
| 249 | +| Name | Type | Description | |
| 250 | +| :---------- | :------ | :-------------------------------------------------------------------- | |
| 251 | +| amount_ | uint256 | The amount of native currency to withdraw. | |
| 252 | +| receiver_ | address | The address of the withdrawal recipient. | |
| 253 | +| txHash_ | bytes32 | The hash of the deposit transaction. | |
| 254 | +| txNonce_ | uint256 | The nonce of the deposit transaction. | |
| 255 | +| signatures_ | bytes[] | An array of signatures, formed by signing a sign hash by each signer. | |
| 256 | + |
| 257 | +### getSigners (0x94cf795e) |
| 258 | + |
| 259 | +```solidity |
| 260 | +function getSigners() external view returns (address[] memory) |
| 261 | +``` |
| 262 | + |
| 263 | +Returns the list of current bridge signers |
| 264 | +### getSignaturesThreshold (0x4f2c65a5) |
| 265 | + |
| 266 | +```solidity |
| 267 | +function getSignaturesThreshold() external view returns (uint256) |
| 268 | +``` |
| 269 | + |
| 270 | +Returns the number of signatures for the withdrawal to be accepted |
| 271 | +### containsHash (0x0430285a) |
| 272 | + |
| 273 | +```solidity |
| 274 | +function containsHash( |
| 275 | + bytes32 txHash_, |
| 276 | + uint256 txNonce_ |
| 277 | +) external view returns (bool) |
| 278 | +``` |
| 279 | + |
| 280 | +Checks if the deposit event exists in the contract |
0 commit comments