Superform v1
  • Introduction
  • Components
    • Protocol
    • Keepers
    • API
    • App
  • E2E Flows
    • Same-chain Deposit
    • Cross-chain Deposit
    • Same-chain Withdrawal
    • Cross-chain Withdrawal
  • Periphery Contracts
    • SuperformRouter
      • SuperformRouterPlus
      • SuperformRouterPlusAsync
    • PayMaster
    • PaymentHelper
    • EmergencyQueue
    • SuperformFactory
    • Forms
      • ERC4626Form
      • ERC5115Form
      • ERC7540Form
    • SuperPositions
      • ERC1155A
    • RewardsDistributor
  • Core Contracts
    • State Registries
      • CoreStateRegistry
      • AsyncStateRegistry
      • PayloadHelper
    • AMB Implementations
      • LayerzeroImplementation
      • LayerzeroV2Implementation
      • WormholeARImplementation
      • HyperlaneImplementation
      • AxelarImplementation
    • Broadcasting
      • BroadcastRegistry
      • WormholeSRImplementation
    • Bridge Validators
      • LiFiValidator
      • SocketValidator
      • SocketOneInchValidator
      • DebridgeValidator (and forwarder)
      • OneInchValidator
    • DstSwapper
    • Settings
      • SuperRBAC
      • SuperRegistry
  • SuperVaults
    • SuperVaults
  • Resources
    • Deployment Addresses
    • Subgraphs
      • Protocol Level Entities
      • Form Related Entities
      • Deposits and Withdrawals
      • SuperPosition Events
      • External Entities
    • Infrastructure Integrations
    • Security & Audits
    • Protocol License
    • Glossary
    • Protocol Multisig
    • Superform Labs Socials
Powered by GitBook
On this page
  • Introduction
  • Core Concepts

Was this helpful?

  1. Core Contracts

DstSwapper

Last updated 6 months ago

Was this helpful?

Introduction

DstSwapper is an access controlled contract which executes transaction data when tokens must be swapped on the destination chain before being deposited into a vault. This typically occurs when the vault being deposited into has little bridge liquidity in the underlying asset. In this case, the more liquid token is sent to the DstSwapper contract rather than going directly to .

The contract also accounts for failed swaps, where the requested output of the swapped token on DstSwapper falls below the user's intended amount they specified via .maxSlippage. If the swapped amount will be lower, the payload is marked as failed and the user can rescue their funds and make the swap themselves on the destination chain.

Core Concepts

There are three stages in which DstSwapper handles actions on the destination chain. It first tries to swap via processTx or batchProcessTx, if not successful, the transaction is marked as failed via updateFailedTx or batchUpdateFailedTx which means the intermediary tokens can be rescued by .

processTx

The core function in DstSwapper is processTx. Used in single vault payloads, after validating that the provided data will send tokens to , processTx calls the designated bridge address with the provided transaction data via the onlySwapper modifier. This secures against txData manipulation by off-chain route generation. processTx will revert if the amount of the vault underlying token to be received was lower than what the user intended.

function processTx(
        uint256 payloadId_,
        uint8 bridgeId_,
        bytes calldata txData_
) external override onlySwapper nonReentrant
Name
Description

payloadId_

uint256 payload id to update

bridgeId_

uint8 bridgeId that is being used for the swap

txData_

bytes txData being executed

batchProcessTx

This function is used to swap tokens in multi vault payloads.

function batchProcessTx(
        uint256 payloadId_,
        uint256[] indices_,
        uint8[] bridgeIds_,
        bytes[] calldata txDatas_
) external override onlySwapper nonReentrant
Name
Description

payloadId_

uint256 payload id to update

indices_

uint256 array of indeces to process

bridgeId_

uint8 bridgeId that is being used for the swap

txData_

bytes txData being executed

updateFailedTx

If processTx doesn't go through successfully within a pre-determined time-frame (30 minutes being the default) transactions will be marked as failed via updateFailedTx in a single vault payload.

function updateFailedTx(
        uint256 payloadId_,
        address interimToken_,
        uint256 amount_
) external override onlySwapper nonReentrant
Name
Description

payloadId_

uint256 payload id to update

index_

uint256 index of the superformId in the payload

interimToken_

address of the intermediary token that needs to be rescued

amount_

uint256 amount of the intermediary token that needs to be rescued

batchUpdateFailedTx

If batchProcessTx doesn't go through successfully within a pre-determined time-frame (30 minutes being the default) transactions will be marked as failed via batchUpdateFailedTx in a multi vault payload.

function batchUpdateFailedTx(
        uint256 payloadId_,
        uint256[] indices_
        address interimToken_,
        uint256 amount_
) external override onlySwapper nonReentrant
Name
Description

payloadId_

uint256 payload id to update

indices_

uint256 index of the superformId in the payload

interimToken_

address of the intermediary token that needs to be rescued

amount_

uint256 amount of the intermediary token that needs to be rescued

processFailedTx

function processFailedTx(
        address user_,
        address interimToken_,
        uint256 amount_
) external override onlyCoreStateRegistry 
Name
Description

user_

address of the user to refund on the destination chain

interimToken_

address of the interim token that wasn't able to be swapped which the user is owed

amount_

uint256 amount of the intermediary token the user is owed

Once transactions are marked as failed by swapper, they can be rescued by the rescue/dispute process conducted in .

CoreStateRegistry
CoreStateRegistry
CoreStateRegistry
CoreStateRegistry
Superform Vault Data