# `ITokenBridge`

### InitializationData

```solidity
struct InitializationData {
  address defaultAdmin;
  address messageService;
  address tokenBeacon;
  uint256 sourceChainId;
  uint256 targetChainId;
  address remoteSender;
  address[] reservedTokens;
  struct IPermissionsManager.RoleAddress[] roleAddresses;
  struct IPauseManager.PauseTypeRole[] pauseTypeRoles;
  struct IPauseManager.PauseTypeRole[] unpauseTypeRoles;
}
```

### TokenReserved

```solidity
event TokenReserved(address token)
```

Emitted when the token address is reserved.

#### Parameters

| Name | Type | Description |
| ---- | ---- | ----------- |
| token | address | The indexed token address. |

### ReservationRemoved

```solidity
event ReservationRemoved(address token)
```

Emitted when the token address reservation is removed.

#### Parameters

| Name | Type | Description |
| ---- | ---- | ----------- |
| token | address | The indexed token address. |

### CustomContractSet

```solidity
event CustomContractSet(address nativeToken, address customContract, address setBy)
```

Emitted when the custom token address is set.

#### Parameters

| Name | Type | Description |
| ---- | ---- | ----------- |
| nativeToken | address | The indexed nativeToken token address. |
| customContract | address | The indexed custom contract address. |
| setBy | address | The indexed address of who set the custom contract. |

### BridgingInitiated

```solidity
event BridgingInitiated(address sender, address recipient, address token, uint256 amount)
```

Emitted when token bridging is initiated.

_DEPRECATED in favor of BridgingInitiatedV2._

#### Parameters

| Name | Type | Description |
| ---- | ---- | ----------- |
| sender | address | The indexed sender address. |
| recipient | address | The recipient address. |
| token | address | The indexed token address. |
| amount | uint256 | The indexed token amount. |

### BridgingInitiatedV2

```solidity
event BridgingInitiatedV2(address sender, address recipient, address token, uint256 amount)
```

Emitted when token bridging is initiated.

#### Parameters

| Name | Type | Description |
| ---- | ---- | ----------- |
| sender | address | The indexed sender address. |
| recipient | address | The indexed recipient address. |
| token | address | The indexed token address. |
| amount | uint256 | The token amount. |

### BridgingFinalized

```solidity
event BridgingFinalized(address nativeToken, address bridgedToken, uint256 amount, address recipient)
```

Emitted when token bridging is finalized.

_DEPRECATED in favor of BridgingFinalizedV2._

#### Parameters

| Name | Type | Description |
| ---- | ---- | ----------- |
| nativeToken | address | The indexed native token address. |
| bridgedToken | address | The indexed bridged token address. |
| amount | uint256 | The indexed token amount. |
| recipient | address | The recipient address. |

### BridgingFinalizedV2

```solidity
event BridgingFinalizedV2(address nativeToken, address bridgedToken, uint256 amount, address recipient)
```

Emitted when token bridging is finalized.

#### Parameters

| Name | Type | Description |
| ---- | ---- | ----------- |
| nativeToken | address | The indexed native token address. |
| bridgedToken | address | The indexed bridged token address. |
| amount | uint256 | The token amount. |
| recipient | address | The indexed recipient address. |

### NewToken

```solidity
event NewToken(address token)
```

Emitted when a new token is seen being bridged on the origin chain for the first time.

#### Parameters

| Name | Type | Description |
| ---- | ---- | ----------- |
| token | address | The indexed token address. |

### NewTokenDeployed

```solidity
event NewTokenDeployed(address bridgedToken, address nativeToken)
```

Emitted when a new token is deployed.

#### Parameters

| Name | Type | Description |
| ---- | ---- | ----------- |
| bridgedToken | address | The indexed bridged token address. |
| nativeToken | address | The indexed native token address. |

### RemoteTokenBridgeSet

```solidity
event RemoteTokenBridgeSet(address remoteTokenBridge, address setBy)
```

Emitted when the remote token bridge is set.

#### Parameters

| Name | Type | Description |
| ---- | ---- | ----------- |
| remoteTokenBridge | address | The indexed remote token bridge address. |
| setBy | address | The indexed address that set the remote token bridge. |

### TokenDeployed

```solidity
event TokenDeployed(address token)
```

Emitted when the token is set as deployed.

_This can be triggered by anyone calling confirmDeployment on the alternate chain._

#### Parameters

| Name | Type | Description |
| ---- | ---- | ----------- |
| token | address | The indexed token address. |

### DeploymentConfirmed

```solidity
event DeploymentConfirmed(address[] tokens, address confirmedBy)
```

Emitted when the token deployment is confirmed.

_This can be triggered by anyone provided there is correctly mapped token data._

#### Parameters

| Name | Type | Description |
| ---- | ---- | ----------- |
| tokens | address[] | The token address list. |
| confirmedBy | address | The indexed address confirming deployment. |

### MessageServiceUpdated

```solidity
event MessageServiceUpdated(address newMessageService, address oldMessageService, address setBy)
```

Emitted when the message service address is set.

#### Parameters

| Name | Type | Description |
| ---- | ---- | ----------- |
| newMessageService | address | The indexed new message service address. |
| oldMessageService | address | The indexed old message service address. |
| setBy | address | The indexed address setting the new message service address. |

### ReservedToken

```solidity
error ReservedToken(address token)
```

_Thrown when attempting to bridge a reserved token._

### RemoteTokenBridgeAlreadySet

```solidity
error RemoteTokenBridgeAlreadySet(address remoteTokenBridge)
```

_Thrown when the remote token bridge is already set._

### AlreadyBridgedToken

```solidity
error AlreadyBridgedToken(address token)
```

_Thrown when attempting to reserve an already bridged token._

### InvalidPermitData

```solidity
error InvalidPermitData(bytes4 permitData, bytes4 permitSelector)
```

_Thrown when the permit data is invalid._

### PermitNotFromSender

```solidity
error PermitNotFromSender(address owner)
```

_Thrown when the permit is not from the sender._

### PermitNotAllowingBridge

```solidity
error PermitNotAllowingBridge(address spender)
```

_Thrown when the permit does not grant spending to the bridge._

### ZeroAmountNotAllowed

```solidity
error ZeroAmountNotAllowed(uint256 amount)
```

_Thrown when the amount being bridged is zero._

### NotReserved

```solidity
error NotReserved(address token)
```

_Thrown when trying to unreserve a non-reserved token._

### TokenNotDeployed

```solidity
error TokenNotDeployed(address token)
```

_Thrown when trying to confirm deployment of a non-deployed token._

### AlreadyBrigedToNativeTokenSet

```solidity
error AlreadyBrigedToNativeTokenSet(address token)
```

_Thrown when trying to set a custom contract on a bridged token._

### NativeToBridgedTokenAlreadySet

```solidity
error NativeToBridgedTokenAlreadySet(address token)
```

_Thrown when trying to set a custom contract on an already set token._

### StatusAddressNotAllowed

```solidity
error StatusAddressNotAllowed(address token)
```

_Thrown when trying to set a token that is already either native, deployed or reserved._

### DecimalsAreUnknown

```solidity
error DecimalsAreUnknown(address token)
```

_Thrown when the decimals for a token cannot be determined._

### TokenListEmpty

```solidity
error TokenListEmpty()
```

_Thrown when the token list is empty._

### ZeroChainIdNotAllowed

```solidity
error ZeroChainIdNotAllowed()
```

_Thrown when a chainId provided during initialization is zero._

### SourceChainSameAsTargetChain

```solidity
error SourceChainSameAsTargetChain()
```

_Thrown when sourceChainId is the same as targetChainId during initialization._

### bridgeTokenWithPermit

```solidity
function bridgeTokenWithPermit(address _token, uint256 _amount, address _recipient, bytes _permitData) external payable
```

Similar to `bridgeToken` function but allows to pass additional
  permit data to do the ERC-20 approval in a single transaction.

#### Parameters

| Name | Type | Description |
| ---- | ---- | ----------- |
| _token | address | The address of the token to be bridged. |
| _amount | uint256 | The amount of the token to be bridged. |
| _recipient | address | The address that will receive the tokens on the other chain. |
| _permitData | bytes | The permit data for the token, if applicable. |

### completeBridging

```solidity
function completeBridging(address _nativeToken, uint256 _amount, address _recipient, uint256 _chainId, bytes _tokenMetadata) external
```

_It can only be called from the Message Service. To finalize the bridging
  process, a user or postman needs to use the `claimMessage` function of the
  Message Service to trigger the transaction._

#### Parameters

| Name | Type | Description |
| ---- | ---- | ----------- |
| _nativeToken | address | The address of the token on its native chain. |
| _amount | uint256 | The amount of the token to be received. |
| _recipient | address | The address that will receive the tokens. |
| _chainId | uint256 | The source chainId or target chainId for this token |
| _tokenMetadata | bytes | Additional data used to deploy the bridged token if it   doesn't exist already. |

### confirmDeployment

```solidity
function confirmDeployment(address[] _tokens) external payable
```

_Change the status to DEPLOYED to the tokens passed in parameter
   Will call the method setDeployed on the other chain using the message Service_

#### Parameters

| Name | Type | Description |
| ---- | ---- | ----------- |
| _tokens | address[] | Array of bridged tokens that have been deployed. |

### setMessageService

```solidity
function setMessageService(address _messageService) external
```

_Change the address of the Message Service._

#### Parameters

| Name | Type | Description |
| ---- | ---- | ----------- |
| _messageService | address | The address of the new Message Service. |

### setDeployed

```solidity
function setDeployed(address[] _nativeTokens) external
```

_It can only be called from the Message Service. To change the status of
  the native tokens to DEPLOYED meaning they have been deployed on the other chain
  a user or postman needs to use the `claimMessage` function of the
  Message Service to trigger the transaction._

#### Parameters

| Name | Type | Description |
| ---- | ---- | ----------- |
| _nativeTokens | address[] | The addresses of the native tokens. |

### setReserved

```solidity
function setReserved(address _token) external
```

Make sure that _token is native to the current chain
  where you are calling this function from

_Linea can reserve tokens. In this case, the token cannot be bridged.
  Linea can only reserve tokens that have not been bridged before._

#### Parameters

| Name | Type | Description |
| ---- | ---- | ----------- |
| _token | address | The address of the token to be set as reserved. |

### removeReserved

```solidity
function removeReserved(address _token) external
```

_Removes a token from the reserved list._

#### Parameters

| Name | Type | Description |
| ---- | ---- | ----------- |
| _token | address | The address of the token to be removed from the reserved list. |

### setCustomContract

```solidity
function setCustomContract(address _nativeToken, address _targetContract) external
```

_Linea can set a custom ERC-20 contract for specific ERC-20.
  For security purposes, Linea can only call this function if the token has
  not been bridged yet._

#### Parameters

| Name | Type | Description |
| ---- | ---- | ----------- |
| _nativeToken | address | address of the token on the source chain. |
| _targetContract | address | address of the custom contract. |

