😀
Nexus Market
  • Introduction
    • 👋Hi !
    • Overview
      • Start BUIDLing
  • Links
    • Money Market App
    • Github
    • Telegram
  • Concepts
    • At a Glance
      • Supply
      • Borrow
      • Repay
      • Withdraw
      • Liquidation
      • Flash Loan
      • Risks
    • Protocol
      • Liquidity Pool
      • Reserve
      • Oracle
      • Governance
      • Incentives
      • Safety Module
  • LST as Collateral
  • Coming Soon
  • Guides
    • User Flows
    • Follow-on Steps
  • Developers
    • Smart Contract
      • Pool
      • L2 Pool
      • Wrapped Token Gateway
      • View Contracts
      • Incentives
      • Tokenisation
      • Interest Rate Strategy
      • Access Control Manager
      • Oracles
      • PoolAddressesProvider
      • Pool Configurator
      • Switch Adapters
    • Safety Module
    • Governance
    • Flash Loan
      • Premium Distribution
      • Example Calculation
  • Credit Delegation
  • Resources
    • Web3
    • Glossary
    • Contracts Dashboard
      • Ethereum Sepolia
      • Base Sepolia
      • BSC Chapel
    • Parameters Dashboard
    • Access Control Dashboard
    • FAQ
      • General
      • Risk
      • Supplying and Earning
      • Borrowing
      • Liquidations
      • Governance
      • Safety Module
      • Developers
      • Other Features
      • Brand-related
Powered by GitBook
On this page
  • Repay With Collateral
  • Write Methods
  • Collateral Switch
  • Write Methods
  • Withdraw & Switch
  • Write Methods

Was this helpful?

  1. Developers
  2. Smart Contract

Switch Adapters

PreviousPool ConfiguratorNextSafety Module

Last updated 21 days ago

Was this helpful?

These switch adapters integrate Nexus' Flash Loans and the ParaSwap DEX aggregator smart contracts to facilitate advanced actions such as repaying borrow positions using collateral, switching collateral assets, switching borrow positions, and withdrawing and switching assets. They allow users to perform complex operations in a single transaction, leveraging the liquidity of the Nexus protocol and the atomic switching capabilities of decentralized exchanges.

Market
Repay With Collateral
Collateral Switch
Debt Switch
Withdraw & Switch

Ethereum Sepolia

✔️

✔️

✔️

✔️

Base Sepolia

✔️

✔️

✔️

✔️

BSC Chapel

✔️

✔️

✔️

✔️

Repay With Collateral

The ParaSwapRepayAdapter contract enables users to repay their borrow positions on Nexus using their supplied collateral directly, without the need to unwind their positions or provide additional liquidity. It leverages Nexus' Flash Loans and the ParaSwap DEX aggregator to switch the user's collateral for the borrowed asset and repay the borrow position in a single atomic transaction.

By using this adapter, users can efficiently manage their positions and reduce their borrow positions using their existing collateral, saving on transaction costs and avoiding manual steps.

The source code is available on .

Reference Integration:

Write Methods

executeOperation

function executeOperation(
    address asset,
    uint256 amount,
    uint256 premium,
    address initiator,
    bytes calldata params
) external override nonReentrant returns (bool)

Uses the received funds from the flash loan to repay a borrow position on the protocol on behalf of the user. Then, pulls the collateral from the user and switches it to the debt asset to repay the flash loan.

The user should give this contract allowance to pull the zTokens in order to withdraw the underlying asset, switch it, and repay the flash loan.

Supports only one asset on the flash loan.

The params parameter should be the ABI-encoded values of the following:

  • IERC20Detailed debtAsset — The address of the borrow position asset

  • uint256 debtRepayAmount — The amount of the borrow position to be repaid

  • uint256 buyAllBalanceOffset — Offset in the ParaSwap calldata if switching all balance

  • uint256 rateMode — The rate mode of the borrow position to be repaid

  • bytes paraswapData — Data for the ParaSwap Adapter

  • PermitSignature permitSignature — Struct containing the permit signature, set to zeroes if not used

Input Parameters:

Name
Type
Description

asset

address

The address of the flash-borrowed asset

amount

uint256

The amount of the flash-borrowed asset

premium

uint256

The fee of the flash-borrowed asset

initiator

address

The address of the flash loan initiator

params

bytes

The byte-encoded parameters passed when initiating the flash loan

Return Values:

Type
Description

bool

True if the execution of the operation succeeds, false otherwise

swapAndRepay

function swapAndRepay(
    IERC20Detailed collateralAsset,
    IERC20Detailed debtAsset,
    uint256 collateralAmount,
    uint256 debtRepayAmount,
    uint256 debtRateMode,
    uint256 buyAllBalanceOffset,
    bytes calldata paraswapData,
    PermitSignature calldata permitSignature
) external nonReentrant

Switches the user's collateral for the debt asset and then repays the borrow position on the protocol on behalf of the user without using flash loans. This method can be used when the temporary transfer of the collateral asset to this contract does not affect the user's position.

The user should give this contract allowance to pull the zTokens in order to withdraw the underlying asset.

Input Parameters:

Name
Type
Description

collateralAsset

IERC20Detailed

The address of the collateral asset to be switched

debtAsset

IERC20Detailed

The address of the debt asset

collateralAmount

uint256

The maximum amount of the collateral to be switched

debtRepayAmount

uint256

The amount of the borrow position to be repaid, or maximum amount when repaying all

debtRateMode

uint256

The rate mode of the borrow position to be repaid

buyAllBalanceOffset

uint256

Offset in the ParaSwap calldata if switching all balance, otherwise 0

paraswapData

bytes

Data for the ParaSwap Adapter

permitSignature

PermitSignature

Struct containing the permit signature, set to zeroes if not used

PermitSignature Struct

struct PermitSignature {
    uint256 deadline;
    uint8 v;
    bytes32 r;
    bytes32 s;
}

Members:

Name
Type
Description

deadline

uint256

The deadline timestamp for the permit signature

v

uint8

The V parameter of the ECDSA signature

r

bytes32

The R parameter of the ECDSA signature

s

bytes32

The S parameter of the ECDSA signature


Collateral Switch

The ParaSwapLiquiditySwapAdapter contract allows users to switch their supplied collateral from one asset to another in a single transaction using Nexus' Flash Loans and the ParaSwap DEX aggregator.

This adapter enables users to rebalance their collateral positions without needing to withdraw and re-supply assets manually. By leveraging flash loans, the user can switch their existing collateral to a new asset and supply it back into the Nexus protocol in a single transaction.

The source code is available on GitHub.

Reference Integration: useCollateralSwap.tsx

Write Methods

executeOperation

function executeOperation(
    address asset,
    uint256 amount,
    uint256 premium,
    address initiator,
    bytes calldata params
) external override nonReentrant returns (bool)

Switches the received amount from the flash loan into the specified asset. The received funds from the switch are then supplied into the protocol on behalf of the user.

The user should give this contract allowance to pull the zTokens in order to withdraw the underlying asset and repay the flash loan.

The params parameter should be the ABI-encoded values of the following:

  • IERC20Detailed assetToSwapTo — The address of the underlying asset to be switched to and supplied

  • uint256 minAmountToReceive — The minimum amount to be received from the switch

  • uint256 swapAllBalanceOffset — Offset in the Augustus calldata if switching all balance, otherwise 0

  • bytes swapCalldata — Calldata for ParaSwap's Augustus Swapper contract

  • IParaSwapAugustus augustus — Address of ParaSwap's Augustus Swapper contract

  • PermitSignature permitParams — Struct containing the permit signature, set to zeroes if not used

Input Parameters:

Name
Type
Description

asset

address

The address of the flash-borrowed asset

amount

uint256

The amount of the flash-borrowed asset

premium

uint256

The fee of the flash-borrowed asset

initiator

address

The address of the flash loan initiator

params

bytes

The byte-encoded parameters passed when initiating the flash loan

Return Values:

Type
Description

bool

True if the execution of the operation succeeds, false otherwise

swapAndDeposit

function swapAndDeposit(
    IERC20Detailed assetToSwapFrom,
    IERC20Detailed assetToSwapTo,
    uint256 amountToSwap,
    uint256 minAmountToReceive,
    uint256 swapAllBalanceOffset,
    bytes calldata swapCalldata,
    IParaSwapAugustus augustus,
    PermitSignature calldata permitParams
) external nonReentrant

Switches an amount of an asset to another and supplies the new asset amount on behalf of the user without using a flash loan. This method can be used when the temporary transfer of the collateral asset to this contract does not affect the user's position.

The user should give this contract allowance to pull the zTokens in order to withdraw the underlying asset and perform the switch.

Input Parameters:

Name
Type
Description

assetToSwapFrom

IERC20Detailed

The address of the underlying asset to be switched from

assetToSwapTo

IERC20Detailed

The address of the underlying asset to be switched to and supplied

amountToSwap

uint256

Amount to be switched, or maximum amount when switching all balance

minAmountToReceive

uint256

Minimum amount to be received from the switch

swapAllBalanceOffset

uint256

Offset in Augustus calldata if switching all balance, otherwise 0

swapCalldata

bytes

Calldata for ParaSwap's Augustus Swapper contract

augustus

IParaSwapAugustus

Address of ParaSwap's Augustus Swapper contract

permitParams

PermitSignature

Struct containing the permit signature, set to zeroes if not used


Withdraw & Switch

The ParaSwapWithdrawSwapAdapter contract allows users to withdraw their supplied assets from Nexus and switch them to another asset in a single transaction using the ParaSwap DEX aggregator.

This adapter enables users to efficiently exit positions and switch their assets without having to perform multiple transactions, reducing gas costs and simplifying the user experience.

The source code is available on GitHub.

Reference Integration: WithdrawAndSwitchActions.tsx

Write Methods

withdrawAndSwap

function withdrawAndSwap(
    IERC20Detailed assetToSwapFrom,
    IERC20Detailed assetToSwapTo,
    uint256 amountToSwap,
    uint256 minAmountToReceive,
    uint256 swapAllBalanceOffset,
    bytes calldata swapCalldata,
    IParaSwapAugustus augustus,
    PermitSignature calldata permitParams
) external nonReentrant

Switches an amount of an asset to another after a withdrawal and transfers the new asset to the user. The user should give this contract allowance to pull the zTokens in order to withdraw the underlying asset and perform the switch.

Input Parameters:

Name
Type
Description

assetToSwapFrom

IERC20Detailed

The address of the underlying asset to be switched from

assetToSwapTo

IERC20Detailed

The address of the underlying asset to be switched to

amountToSwap

uint256

Amount to be switched, or maximum amount when switching all balance

minAmountToReceive

uint256

Minimum amount to be received from the switch

swapAllBalanceOffset

uint256

Offset in Augustus calldata if switching all balance, otherwise 0

swapCalldata

bytes

Calldata for ParaSwap's Augustus Swapper contract

augustus

IParaSwapAugustus

Address of ParaSwap's Augustus Swapper contract

permitParams

PermitSignature

Struct containing the permit signature, set to zeroes if not used

executeOperation

Note that in this contract, the executeOperation method is overridden but simply reverts with NOT_SUPPORTED, so it's not intended to be used.

GitHub
useCollateralRepaySwap.tsx