Files
linea-monorepo/contracts/docs/api/tokenBridge/interfaces/ITokenBridge.md
The Dark Jester adb097aff4 [Chore] Export contract ABI and use solidity-docgen export (#323)
* export contract ABI and use solidity-docgen export

* add docgen dependency

* lint fixing
2024-11-21 06:49:31 -08:00

12 KiB

Solidity API

ITokenBridge

InitializationData

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

TokenReserved

event TokenReserved(address token)

Emitted when the token address is reserved.

Parameters

Name Type Description
token address The indexed token address.

ReservationRemoved

event ReservationRemoved(address token)

Emitted when the token address reservation is removed.

Parameters

Name Type Description
token address The indexed token address.

CustomContractSet

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

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

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

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

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

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

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

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

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

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

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

error ReservedToken(address token)

Thrown when attempting to bridge a reserved token.

RemoteTokenBridgeAlreadySet

error RemoteTokenBridgeAlreadySet(address remoteTokenBridge)

Thrown when the remote token bridge is already set.

AlreadyBridgedToken

error AlreadyBridgedToken(address token)

Thrown when attempting to reserve an already bridged token.

InvalidPermitData

error InvalidPermitData(bytes4 permitData, bytes4 permitSelector)

Thrown when the permit data is invalid.

PermitNotFromSender

error PermitNotFromSender(address owner)

Thrown when the permit is not from the sender.

PermitNotAllowingBridge

error PermitNotAllowingBridge(address spender)

Thrown when the permit does not grant spending to the bridge.

ZeroAmountNotAllowed

error ZeroAmountNotAllowed(uint256 amount)

Thrown when the amount being bridged is zero.

NotReserved

error NotReserved(address token)

Thrown when trying to unreserve a non-reserved token.

TokenNotDeployed

error TokenNotDeployed(address token)

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

AlreadyBrigedToNativeTokenSet

error AlreadyBrigedToNativeTokenSet(address token)

Thrown when trying to set a custom contract on a bridged token.

NativeToBridgedTokenAlreadySet

error NativeToBridgedTokenAlreadySet(address token)

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

StatusAddressNotAllowed

error StatusAddressNotAllowed(address token)

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

DecimalsAreUnknown

error DecimalsAreUnknown(address token)

Thrown when the decimals for a token cannot be determined.

TokenListEmpty

error TokenListEmpty()

Thrown when the token list is empty.

bridgeTokenWithPermit

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 ERC20 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

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 postmen 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 chaindId for this token
_tokenMetadata bytes Additional data used to deploy the bridged token if it doesn't exist already.

confirmDeployment

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

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

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

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.

setRemoteTokenBridge

function setRemoteTokenBridge(address _remoteTokenBridge) external

Sets the address of the remote token bridge. Can only be called once.

Parameters

Name Type Description
_remoteTokenBridge address The address of the remote token bridge to be set.

removeReserved

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

function setCustomContract(address _nativeToken, address _targetContract) external

Linea can set a custom ERC20 contract for specific ERC20. For security purpose, 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.