SwiftGate

Git Source

State Variables

_chainId

chain id of swift gate on this chain

uint16 internal _chainId;

_aaveV3LendingPool

Aave v3 lending pool

IPool internal _aaveV3LendingPool;

_aaveV3RewardsController

Aave v3 rewards controller

IRewardsController internal _aaveV3RewardsController;

_governors

Mapping of governor address => is governor

mapping(address => bool) internal _governors;

_feeOfChainId

Mapping of chainId => fee

mapping(uint256 => uint256) internal _feeOfChainId;

_feeIfBatchedOfChainId

Mapping of chainId => fee if batched

mapping(uint256 => uint256) internal _feeIfBatchedOfChainId;

_signedMessages

Mapping of chainId => is chain supported

mapping(bytes32 => bool) internal _signedMessages;

_remoteToWrappedTokens

Mapping of chainId => destination token => wrappedToken

mapping(uint256 => mapping(address => address)) internal _remoteToWrappedTokens;

_wrappedToRemoteTokens

Mapping of token to wrapped token

mapping(address => address) internal _wrappedToRemoteTokens;

_dstTokens

Mapping of chainId => local token => is supported token

mapping(uint256 => mapping(address => bool)) internal _dstTokens;

_tokenFactory

Factory for creating wrapped tokens

TokenFactory internal immutable _tokenFactory;

_minSignatures

Minimum signatures to validate messages

uint256 internal _minSignatures;

Functions

constructor

creates the TokenFactory which is owner by this contract - swift gate

constructor();

initialize

initializes the swift gate contract

function initialize(
    uint16 chainId_,
    address aaveV3,
    address aaveV3RewardsController_,
    address[] memory governors_,
    uint256 minSignatures_
) external;

Parameters

NameTypeDescription
chainId_uint16chain id of the swift gate contract
aaveV3addressaave v3 lending pool address
aaveV3RewardsController_addressaave v3 rewards controller address
governors_address[]array of governor addresses
minSignatures_uint256minimum number of signatures to validate messages

swiftReceive

receives a batch of tokens, mints the wrapped versions and verifies the signatures.

function swiftReceive(SwReceiveParams[] calldata params_, Signature[] calldata signatures_, bytes32 salt_) external;

Parameters

NameTypeDescription
params_SwReceiveParams[]struct with the parameters to sned across bridges - includes token, amount, receiver, srcChain, dstChain
signatures_Signature[]array of signatures from the governors (message hash signed by governors )
salt_bytes32salt used to enable signing the same message more than once

swiftSend

sends a token to another chain.

function swiftSend(address token_, uint256 amount_, address receiver_, uint16 dstChain_, bool isSingle_) external;

Parameters

NameTypeDescription
token_addressthe token to send.
amount_uint256the amount of tokens to send.
receiver_addressthe receiver of the tokens.
dstChain_uint16the destination chain.
isSingle_boolwhether the token is to be batched with other tokens to save gas or not.

addWrappedToken

adds a wrapped token to the respective mapping so it can be used across chains

function addWrappedToken(
    uint16 chainId_,
    address token_,
    string memory name_,
    string memory symbol_,
    Signature[] calldata signatures_,
    bytes32 salt_
) external;

Parameters

NameTypeDescription
chainId_uint16chain id of the wrapped token
token_addresstoken that is being wrapped
name_stringname of the wrapped token
symbol_stringsymbol of the wrapped token
signatures_Signature[]array of signatures from the governors (message hash signed by governors )
salt_bytes32salt used to enable signing the same message more than once

addDstToken

Adds a token to the dstTokens mapping (verified with the signatures). Signals that a token can be bridged to another chain

function addDstToken(uint16 chainId_, address token_, Signature[] calldata signatures_, bytes32 salt_) external;

Parameters

NameTypeDescription
chainId_uint16chain id of the token
token_addresstoken that is being added
signatures_Signature[]array of signatures from the governors (message hash signed by governors )
salt_bytes32salt used to enable signing the same message more than once

depositToAaveV3

deposits a given token in the aave lending pool

function depositToAaveV3(address token_, uint256 amount_, Signature[] calldata signatures_, bytes32 salt_) external;

Parameters

NameTypeDescription
token_addresstoken to be deposited
amount_uint256amount to be deposited
signatures_Signature[]array of signatures from the governors (message hash signed by governors )
salt_bytes32salt used to enable signing the same message more than once

withdrawFromAaveV3

withdraws tokens and rewards from aave to claim the yield for the governors

function withdrawFromAaveV3(
    address token_,
    address aToken_,
    uint256 amount_,
    address receiver_,
    Signature[] calldata signatures_,
    bytes32 salt_
) external;

Parameters

NameTypeDescription
token_addresstoken to be withdrawn
aToken_addresscorresponding aave token. Required for the rewards controller
amount_uint256amount to be withdrawn
receiver_addressaddress to receive the tokens
signatures_Signature[]array of signatures from the governors (message hash signed by governors )
salt_bytes32salt used to enable signing the same message more than once

setFeeOfChainId

sets the fee for a given chain id

function setFeeOfChainId(uint16 chainId_, uint256 fee_, Signature[] calldata signatures_, bytes32 salt_) external;

Parameters

NameTypeDescription
chainId_uint16chain id to set the fee for
fee_uint256fee to be set
signatures_Signature[]array of signatures from the governors (message hash signed by governors )
salt_bytes32salt used to enable signing the same message more than once

setFeeIfBatchedOfChainId

sets the fee if the swiftSend call is batched for a given chain id. Much cheaper than single fee

function setFeeIfBatchedOfChainId(
    uint16 chainId_,
    uint256 feeIfBatched_,
    Signature[] calldata signatures_,
    bytes32 salt_
) external;

Parameters

NameTypeDescription
chainId_uint16chain id to set the fee for
feeIfBatched_uint256fee to be set
signatures_Signature[]array of signatures from the governors (message hash signed by governors )
salt_bytes32salt used to enable signing the same message more than once

setGovernors

sets the governors of the swift gate. Useful if governors are not working well and need to be replaced

function setGovernors(
    address[] calldata governors_,
    bool[] calldata set_,
    Signature[] calldata signatures_,
    bytes32 salt_
) external;

Parameters

NameTypeDescription
governors_address[]array of governors to be set
set_bool[]array of booleans to set the governors to true or false
signatures_Signature[]array of signatures from the governors (message hash signed by governors )
salt_bytes32salt used to enable signing the same message more than once

setMinSignatures

sets the min signatures required to execute calls to the swift gate

function setMinSignatures(uint256 minSignatures_, Signature[] calldata signatures_, bytes32 salt_) external;

Parameters

NameTypeDescription
minSignatures_uint256min signatures to be set
signatures_Signature[]array of signatures from the governors (message hash signed by governors )
salt_bytes32salt used to enable signing the same message more than once

getFeeOfChainId

gets the single swift send fee of to a given chain id

function getFeeOfChainId(uint16 chainId_) external view returns (uint256);

Parameters

NameTypeDescription
chainId_uint16chain id to get the fee for

getFeeIfBatchedOfChainId

gets the batched swift send fee of to a given chain id

function getFeeIfBatchedOfChainId(uint16 chainId_) external view returns (uint256);

Parameters

NameTypeDescription
chainId_uint16chain id to get the fee for

getChainId

gets the chain id of the swift gate

function getChainId() external view returns (uint256);

isGovernor

checks if an account is a governor

function isGovernor(address account_) external view returns (bool);

Parameters

NameTypeDescription
account_addressaccount to check

Returns

NameTypeDescription
<none>booltrue if the account is a governor, false otherwise

getWrappedToken

gets the wrapped token of a given chain id and token address

function getWrappedToken(uint16 chainId_, address token_) external view returns (address);

Parameters

NameTypeDescription
chainId_uint16chain id to get the wrapped token for
token_addresstoken to get the wrapped token for

Returns

NameTypeDescription
<none>addresswrapped token address

getTokenFactory

gets the token factory address that creates the wrapped tokens

function getTokenFactory() external view returns (address);

Returns

NameTypeDescription
<none>addresstoken factory address

getRemoteTokenOf

gets the remote token of a given wrapped token address

function getRemoteTokenOf(address wrappedToken_) external view returns (address);

Parameters

NameTypeDescription
wrappedToken_addresswrapped token to get the remote token for

Returns

NameTypeDescription
<none>addressremote token address

isDstToken

checks if a token is allowed to be bridged to a destination chain id

function isDstToken(uint16 chainId_, address token_) external view returns (bool);

Parameters

NameTypeDescription
chainId_uint16chain id to check
token_addresstoken to check

Returns

NameTypeDescription
<none>booltrue if the token is allowed to be bridged, false otherwise

getMinSignatures

gets the min signatures required to execute calls to the swift gate

function getMinSignatures() external view returns (uint256);

getAaveV3LendingPool

gets the aave v3 lending pool address

function getAaveV3LendingPool() external view returns (address);

_verifySignatures

function _verifySignatures(bytes32 messageHash_, Signature[] calldata signatures_) internal;

Events

SwiftSend

emitted when an account calls swiftSend and bridges to the destination chain

event SwiftSend(address token, address remoteToken_, uint256 amount, address receiver, uint16 dstChain, bool isSingle);

Errors

LengthMismatchError

triggered when the lengths of the array arguments don't match

error LengthMismatchError();

NotEnoughSignaturesError

triggered when the number of signatures is less than the minimum

error NotEnoughSignaturesError();

InvalidSignatureError

triggered when the signature is invalid

error InvalidSignatureError();

WrontDstChainError

error WrontDstChainError(uint256 chainId);

UnsupportedTokenError

triggered when the token is not supported on a certain destination chain

error UnsupportedTokenError(uint16 chainId, address token);

ZeroAddressError

triggered on a zero address argument

error ZeroAddressError();

ZeroAmountError

triggered when the amount is zero

error ZeroAmountError();

ChainIdAlreadySetError

triggered when the chain id is already set. Prevents reinitialization

error ChainIdAlreadySetError();

DuplicateSignatureError

triggered when the signature is a duplicate. Prevents message replay

error DuplicateSignatureError();

Structs

Signature

Struct to hold signature data

struct Signature {
    uint8 v;
    bytes32 r;
    bytes32 s;
}

SwReceiveParams

Struct to hold swift receive parameters

struct SwReceiveParams {
    address token;
    uint256 amount;
    address receiver;
    uint16 srcChain;
    uint16 dstChain;
}