DstSwapper

Git Source

Inherits: IDstSwapper, ReentrancyGuard

Author: Zeropoint Labs.

SPDX-License-Identifier: Apache-2.0

handles all destination chain swaps.

State Variables

superRegistry

ISuperRegistry public immutable superRegistry;

CHAIN_ID

uint64 public immutable CHAIN_ID;

NATIVE

address constant NATIVE = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;

swappedAmount

mapping(uint256 payloadId => mapping(uint256 index => uint256 amount)) public swappedAmount;

Functions

onlySwapper

modifier onlySwapper();

onlyEmergencyAdmin

modifier onlyEmergencyAdmin();

constructor

constructor(address superRegistry_);

Parameters

NameTypeDescription
superRegistry_addressSuperform registry contract

receive

receive enables processing native token transfers into the smart contract.

liquidity bridge fails without a native receive function.

receive() external payable;

processTx

would interact with liquidity bridge contract to process multi-tx transactions and move the funds into destination contract.

function processTx(
    uint256 payloadId_,
    uint256 index_,
    uint8 bridgeId_,
    bytes calldata txData_
)
    public
    override
    onlySwapper
    nonReentrant;

Parameters

NameTypeDescription
payloadId_uint256represents the id of the payload
index_uint256represents the index of the superformid in the payload
bridgeId_uint8represents the id of liquidity bridge used
txData_bytesrepresents the transaction data generated by liquidity bridge API.

batchProcessTx

validates the bridge data

to enter the if-else case of the bridge validator loop

get the address of the bridge to send the txData to.

approve the bridge to spend the approvalToken_.

execute the txData_.

execute the txData_.

updates swapped amount

emits final event

function batchProcessTx(
    uint256 payloadId_,
    uint256[] calldata indices,
    uint8[] calldata bridgeIds_,
    bytes[] calldata txData_
)
    external
    override
    onlySwapper;

Parameters

NameTypeDescription
payloadId_uint256represents the array of payload ids used
indicesuint256[]
bridgeIds_uint8[]represents the array of ids of liquidity bridges used
txData_bytes[]

_getFormUnderlyingFrom

function _getFormUnderlyingFrom(uint256 payloadId_, uint256 index_) internal view returns (address underlying_);

emergencyWithdrawToken

EMERGENCY_ADMIN ONLY FUNCTION.

allows admin to withdraw lost tokens in the smart contract.

function emergencyWithdrawToken(address tokenContract_, uint256 amount_) external onlyEmergencyAdmin;

Parameters

NameTypeDescription
tokenContract_addressaddress of the token contract
amount_uint256amount of tokens to withdraw

emergencyWithdrawNativeToken

note: transfer the token from address of this contract note: to address of the user (executing the withdrawToken() function)

EMERGENCY_ADMIN ONLY FUNCTION.

allows admin to withdraw lost native tokens in the smart contract.

function emergencyWithdrawNativeToken(uint256 amount_) external onlyEmergencyAdmin;

Parameters

NameTypeDescription
amount_uint256amount of tokens to withdraw

Structs

ProcessTxVars

struct ProcessTxVars {
    address finalDst;
    address to;
    address underlying;
    uint256 expAmount;
}