Skip to content
LogoLogo

BridgeAdapter

Git Source

Inherits: Initializable, ReentrancyGuard, MakinaContext, IBridgeAdapter

Constants

MAX_BPS

Full scale value in basis points

uint256 private constant MAX_BPS = 10_000;

approvalTarget

Address of the external bridge approval target contract.

address public immutable override approvalTarget;

Returns

NameTypeDescription
<none>address

executionTarget

Address of the external bridge execution target contract.

address public immutable override executionTarget;

Returns

NameTypeDescription
<none>address

receiveSource

Address of the external bridge contract responsible for sending output funds.

address public immutable override receiveSource;

Returns

NameTypeDescription
<none>address

BridgeAdapterStorageLocation

bytes32 private constant BridgeAdapterStorageLocation =
        0xe24ea70efbf545f0256b406d064fa196624401f48d56c665b3e8bc995282c700;

Functions

_getBridgeAdapterStorage

function _getBridgeAdapterStorage() internal pure returns (BridgeAdapterStorage storage $);

Returns

NameTypeDescription
$BridgeAdapterStorage

constructor

constructor(address _registry, address _approvalTarget, address _executionTarget, address _receiveSource)
        MakinaContext(_registry);

Parameters

NameTypeDescription
_registryaddress
_approvalTargetaddress
_executionTargetaddress
_receiveSourceaddress

__BridgeAdapter_init

function __BridgeAdapter_init(address _controller, uint16 _bridgeId) internal onlyInitializing;

Parameters

NameTypeDescription
_controlleraddress
_bridgeIduint16

onlyController

modifier onlyController();

controller

Address of the bridge controller contract.

function controller() external view override returns (address);

Returns

NameTypeDescription
<none>address

bridgeId

ID of the adapted external bridge.

function bridgeId() external view override returns (uint16);

Returns

NameTypeDescription
<none>uint16

nextOutTransferId

ID of the next outgoing transfer.

function nextOutTransferId() external view override returns (uint256);

Returns

NameTypeDescription
<none>uint256

nextInTransferId

ID of the next incoming transfer.

function nextInTransferId() external view override returns (uint256);

Returns

NameTypeDescription
<none>uint256

outBridgeTransferCancelDefault

Returns the default amount that must be transferred to the adapter to cancel an outgoing bridge transfer.

If the transfer has not yet been sent, or if the full amount was refunded to this contract by the external bridge, returns 0.

If the bridge retains a fee upon cancellation and only a partial refund was received, the returned value reflects that fee.

In all other cases (e.g. including pending refunds or successful bridge transfers), returns the full amount of the transfer.

function outBridgeTransferCancelDefault(uint256 transferId) external view override returns (uint256);

Parameters

NameTypeDescription
transferIduint256The ID of the transfer to check.

Returns

NameTypeDescription
<none>uint256The amount required to cancel the transfer.

scheduleOutBridgeTransfer

Schedules an outgoing bridge transfer and returns the message hash.

Emits an event containing the id of the transfer and the hash of the bridge transfer message.

function scheduleOutBridgeTransfer(
        uint256 destinationChainId,
        address recipient,
        address inputToken,
        uint256 inputAmount,
        address outputToken,
        uint256 minOutputAmount
    ) external override nonReentrant onlyController;

Parameters

NameTypeDescription
destinationChainIduint256The ID of the destination chain.
recipientaddressThe address of the recipient on the destination chain.
inputTokenaddressThe address of the input token.
inputAmountuint256The amount of the input token to transfer.
outputTokenaddressThe address of the output token on the destination chain.
minOutputAmountuint256The minimum amount of the output token to receive.

authorizeInBridgeTransfer

Registers a message hash as authorized for an incoming bridge transfer.

function authorizeInBridgeTransfer(bytes32 messageHash) external override onlyController;

Parameters

NameTypeDescription
messageHashbytes32The hash of the message to authorize.

sendOutBridgeTransfer

Executes a scheduled outgoing bridge transfer.

function sendOutBridgeTransfer(uint256 transferId, bytes calldata data)
        external
        override
        nonReentrant
        onlyController;

Parameters

NameTypeDescription
transferIduint256The ID of the transfer to execute.
databytesThe optional data needed to execute the transfer.

cancelOutBridgeTransfer

Cancels an outgoing bridge transfer.

function cancelOutBridgeTransfer(uint256 transferId) external override nonReentrant onlyController;

Parameters

NameTypeDescription
transferIduint256The ID of the transfer to cancel.

claimInBridgeTransfer

Transfers a received bridge transfer out of the adapter.

function claimInBridgeTransfer(uint256 transferId) external override nonReentrant onlyController;

Parameters

NameTypeDescription
transferIduint256The ID of the transfer to claim.

withdrawPendingFunds

Resets internal state for a given token address, and transfers token balance to associated controller.

This function is intended to be used by the DAO to unlock funds stuck in the adapter, typically in response to operator deviations or external bridge discrepancies.

function withdrawPendingFunds(address token) external override nonReentrant onlyController;

Parameters

NameTypeDescription
tokenaddressThe address of the token.

_receiveInBridgeTransfer

Updates contract state when receiving an incoming bridge transfer.

function _receiveInBridgeTransfer(bytes memory encodedMessage, address receivedToken, uint256 receivedAmount)
        internal
        virtual;

Parameters

NameTypeDescription
encodedMessagebytes
receivedTokenaddress
receivedAmountuint256

_getSet

Returns a reference to the current active set for this versioned set.

function _getSet(VersionedUintSet storage self) internal view returns (EnumerableSet.UintSet storage);

Parameters

NameTypeDescription
selfVersionedUintSet

Returns

NameTypeDescription
<none>EnumerableSet.UintSet

_clearSet

Virtually clears the set by incrementing the version. All future operations will apply to a fresh, empty set. Previous versions remain in storage and are not deleted.

function _clearSet(VersionedUintSet storage self) internal;

Parameters

NameTypeDescription
selfVersionedUintSet

_checkOutBridgeTransferRouteIsSupported

Checks if an outgoing bridge transfer route is supported.

function _checkOutBridgeTransferRouteIsSupported(
        uint256 destinationChainId,
        address inputToken,
        uint256, /*inputAmount*/
        address outputToken
    ) internal view virtual;

Parameters

NameTypeDescription
destinationChainIduint256
inputTokenaddress
_uint256
outputTokenaddress

_getConfig

Returns the address of the config contract associated with this bridge adapter.

function _getConfig() internal view returns (address);

Returns

NameTypeDescription
<none>address

_checkOutBridgeTransferIsCancellable

Checks if an outgoing bridge transfer is in a cancellable state.

function _checkOutBridgeTransferIsCancellable(uint256 transferId) internal virtual;

Parameters

NameTypeDescription
transferIduint256

_sendOutBridgeTransfer

Handles logic specific to the external bridge protocol for sending out a bridge transfer.

function _sendOutBridgeTransfer(uint256 transferId, bytes calldata data) internal virtual;

Parameters

NameTypeDescription
transferIduint256
databytes

_outBridgeTransferCancelDefault

Internal logic for outgoing bridge transfer cancellation default.

function _outBridgeTransferCancelDefault(uint256 transferId) internal view virtual returns (uint256);

Parameters

NameTypeDescription
transferIduint256

Returns

NameTypeDescription
<none>uint256

Structs

VersionedUintSet

EnumerableSet wrapper supporting efficient clearing by switching to a new version.

struct VersionedUintSet {
        mapping(uint256 => EnumerableSet.UintSet) _sets;
        uint256 _currentVersion;
    }

Properties

NameTypeDescription
_setsmapping(uint256 => EnumerableSet.UintSet)
_currentVersionuint256

BridgeAdapterStorage

Note:

  • storage-location: erc7201:makina.storage.BridgeAdapter
struct BridgeAdapterStorage {
        address _controller;
        uint16 _bridgeId;
        uint256 _nextOutTransferId;
        uint256 _nextInTransferId;
        mapping(uint256 outTransferId => OutBridgeTransfer transfer) _outgoingTransfers;
        mapping(uint256 inTransferId => InBridgeTransfer transfer) _incomingTransfers;
        mapping(address token => VersionedUintSet) _pendingOutTransferIds;
        mapping(address token => VersionedUintSet) _sentOutTransferIds;
        mapping(address token => VersionedUintSet) _pendingInTransferIds;
        mapping(bytes32 messageHash => bool isExpected) _expectedInMessages;
        mapping(address token => uint256 amount) _reservedBalances;
    }

Properties

NameTypeDescription
_controlleraddress
_bridgeIduint16
_nextOutTransferIduint256
_nextInTransferIduint256
_outgoingTransfersmapping(uint256 outTransferId => OutBridgeTransfer transfer)
_incomingTransfersmapping(uint256 inTransferId => InBridgeTransfer transfer)
_pendingOutTransferIdsmapping(address token => VersionedUintSet)
_sentOutTransferIdsmapping(address token => VersionedUintSet)
_pendingInTransferIdsmapping(address token => VersionedUintSet)
_expectedInMessagesmapping(bytes32 messageHash => bool isExpected)
_reservedBalancesmapping(address token => uint256 amount)