SwiftGate
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
Name | Type | Description |
---|---|---|
chainId_ | uint16 | chain id of the swift gate contract |
aaveV3 | address | aave v3 lending pool address |
aaveV3RewardsController_ | address | aave v3 rewards controller address |
governors_ | address[] | array of governor addresses |
minSignatures_ | uint256 | minimum 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
Name | Type | Description |
---|---|---|
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_ | bytes32 | salt 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
Name | Type | Description |
---|---|---|
token_ | address | the token to send. |
amount_ | uint256 | the amount of tokens to send. |
receiver_ | address | the receiver of the tokens. |
dstChain_ | uint16 | the destination chain. |
isSingle_ | bool | whether 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
Name | Type | Description |
---|---|---|
chainId_ | uint16 | chain id of the wrapped token |
token_ | address | token that is being wrapped |
name_ | string | name of the wrapped token |
symbol_ | string | symbol of the wrapped token |
signatures_ | Signature[] | array of signatures from the governors (message hash signed by governors ) |
salt_ | bytes32 | salt 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
Name | Type | Description |
---|---|---|
chainId_ | uint16 | chain id of the token |
token_ | address | token that is being added |
signatures_ | Signature[] | array of signatures from the governors (message hash signed by governors ) |
salt_ | bytes32 | salt 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
Name | Type | Description |
---|---|---|
token_ | address | token to be deposited |
amount_ | uint256 | amount to be deposited |
signatures_ | Signature[] | array of signatures from the governors (message hash signed by governors ) |
salt_ | bytes32 | salt 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
Name | Type | Description |
---|---|---|
token_ | address | token to be withdrawn |
aToken_ | address | corresponding aave token. Required for the rewards controller |
amount_ | uint256 | amount to be withdrawn |
receiver_ | address | address to receive the tokens |
signatures_ | Signature[] | array of signatures from the governors (message hash signed by governors ) |
salt_ | bytes32 | salt 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
Name | Type | Description |
---|---|---|
chainId_ | uint16 | chain id to set the fee for |
fee_ | uint256 | fee to be set |
signatures_ | Signature[] | array of signatures from the governors (message hash signed by governors ) |
salt_ | bytes32 | salt 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
Name | Type | Description |
---|---|---|
chainId_ | uint16 | chain id to set the fee for |
feeIfBatched_ | uint256 | fee to be set |
signatures_ | Signature[] | array of signatures from the governors (message hash signed by governors ) |
salt_ | bytes32 | salt 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
Name | Type | Description |
---|---|---|
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_ | bytes32 | salt 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
Name | Type | Description |
---|---|---|
minSignatures_ | uint256 | min signatures to be set |
signatures_ | Signature[] | array of signatures from the governors (message hash signed by governors ) |
salt_ | bytes32 | salt 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
Name | Type | Description |
---|---|---|
chainId_ | uint16 | chain 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
Name | Type | Description |
---|---|---|
chainId_ | uint16 | chain 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
Name | Type | Description |
---|---|---|
account_ | address | account to check |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | true 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
Name | Type | Description |
---|---|---|
chainId_ | uint16 | chain id to get the wrapped token for |
token_ | address | token to get the wrapped token for |
Returns
Name | Type | Description |
---|---|---|
<none> | address | wrapped token address |
getTokenFactory
gets the token factory address that creates the wrapped tokens
function getTokenFactory() external view returns (address);
Returns
Name | Type | Description |
---|---|---|
<none> | address | token factory address |
getRemoteTokenOf
gets the remote token of a given wrapped token address
function getRemoteTokenOf(address wrappedToken_) external view returns (address);
Parameters
Name | Type | Description |
---|---|---|
wrappedToken_ | address | wrapped token to get the remote token for |
Returns
Name | Type | Description |
---|---|---|
<none> | address | remote 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
Name | Type | Description |
---|---|---|
chainId_ | uint16 | chain id to check |
token_ | address | token to check |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | true 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;
}