Skip to main content

BridgeAdapter

Git Source

Inherits: ReentrancyGuardUpgradeable, IBridgeAdapter

State Variables

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;

executionTarget

Address of the external bridge execution target contract.

address public immutable override executionTarget;

receiveSource

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

address public immutable override receiveSource;

BridgeAdapterStorageLocation

bytes32 private constant BridgeAdapterStorageLocation =
0xe24ea70efbf545f0256b406d064fa196624401f48d56c665b3e8bc995282c700;

Functions

_getBridgeAdapterStorage

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

constructor

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

__BridgeAdapter_init

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

onlyController

modifier onlyController();

controller

Address of the bridge controller contract.

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

bridgeId

ID of the adapted external bridge.

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

nextOutTransferId

ID of the next outgoing transfer.

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

nextInTransferId

ID of the next incoming transfer.

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

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.

claimInBridgeTransfer

Transfers a received bridge transfer out of the adapter.

function claimInBridgeTransfer(uint256 id) external override nonReentrant onlyController;

Parameters

NameTypeDescription
iduint256

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 nonReentrant onlyController;

Parameters

NameTypeDescription
tokenaddressThe address of the token.

_beforeSendOutBridgeTransfer

Updates contract state before sending out a bridge transfer.

function _beforeSendOutBridgeTransfer(uint256 id) internal;

_cancelOutBridgeTransfer

Cancels an outgoing bridge transfer that is either scheduled or refunded.

function _cancelOutBridgeTransfer(uint256 id) internal;

_receiveInBridgeTransfer

Updates contract state when receiving an incoming bridge transfer.

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

_getSet

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

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

_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;

Structs

VersionedUintSet

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

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

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;
}