Technical ReferenceContract Functions

Router

Overview

The Router.sol allows for complex transaction sequences to be executed in a single transaction. It inherits from Dispatcher.sol and IERC3156FlashBorrower. It primarily handles the execution of a sequence of commands, including flash loans within Spectra Principal Tokens.

Router Methods

execute

Handles the execution of command sequence.

function execute(
        bytes calldata commands,
        bytes[] calldata inputs
) external payable
Input ParameterTypeDescription
commandsbytes calldataA set of concatenated commands, each 1 byte in length
inputsbytes[] calldataAn array of byte strings containing ABI encoded inputs for each command

execute

Processes a batch of commands before a specified deadline. This method checks for deadline and then forwards the call to execute().

function execute(
        bytes calldata commands,
        bytes[] calldata inputs,
        uint256 deadline
) external payable
Input ParameterTypeDescription
commandsbytes calldataA set of concatenated commands, each 1 byte in length
inputsbytes[] calldataAn array of byte strings containing ABI encoded inputs for each command
deadlineuint256The deadline by which the transaction must be executed

View Methods

previewRate

Simulates encoded commands along with provided inputs, and return the resulting rate.

function previewRate(
        bytes calldata commands,
        bytes[] calldata inputs
) external view returns (uint256 output)
Input ParameterTypeDescription
commandsbytes calldataA set of concatenated commands, each 1 byte in length
inputsbytes[] calldataAn array of byte strings containing ABI encoded inputs for each command
outputRateuint256The preview rate value, which represents the amount of output token obtained at the end of execution for each wei of input token spent at the start of execution, multiplied by 1 ray unit.

The following commands are not supported by previewRate():

  • FLASH_LOAN
  • CURVE_SPLIT_IBT_LIQUIDITY
  • CURVE_ADD_LIQUIDITY
  • CURVE_REMOVE_LIQUIDITY
  • CURVE_REMOVE_LIQUIDITY_ONE_COIN

previewSpotRate

Simulates encoded commands along with provided inputs, and return the resulting spot rate.

function previewSpotRate(
        bytes calldata commands,
        bytes[] calldata inputs
    ) external view returns (uint256 output)
Input ParameterTypeDescription
commandsbytes calldataA set of concatenated commands, each 1 byte in length
inputsbytes[] calldataAn array of byte strings containing ABI encoded inputs for each command
outputSpotRateuint256The preview spot rate value, which represents the amount of output token obtained at the end of execution for each wei of input token spent at the start of execution, multiplied by 1 ray unit.

As opposed to previewRate, spot exchange rates will be used for swaps. Additionally for all commands, input amounts are disregarded, and one unit of the token of interest is used instead.

Same than for previewRate(), the following commands are not supported by previewSpotRate():

  • FLASH_LOAN
  • CURVE_SPLIT_IBT_LIQUIDITY
  • CURVE_ADD_LIQUIDITY
  • CURVE_REMOVE_LIQUIDITY
  • CURVE_REMOVE_LIQUIDITY_ONE_COIN

onFlashLoan

Implements the flash loan callback, handling the loan repayment and potential shortfall from the original sender.

function onFlashLoan(
        address initiator,
        address token,
        uint256 amount,
        uint256 fee,
        bytes calldata data
    ) external returns (bytes32)
Input ParameterTypeDescription
initiatoraddressThe initiator of the loan.
tokenaddressThe loan currency.
amountuint256The amount of tokens to borrow.
feeuint256The additional amount of tokens to repay.
databytes calldataArbitrary data structure, intended to contain user-defined parameters.
Return ParameterTypeDescription
boolIf successful, onFlashLoan return the keccak256 hash of “ERC3156FlashBorrower.onFlashLoan”.

Conforms to EIP-3156 standards.

Dispatcher

The Dispatcher.sol is an abstract contract that facilitates a variety of financial operations, including token transfers, swaps, and flash loans. Each command has specific input requirements and functionalities.

TRANSFER_FROM Command

Transfers the specified amount of the ERC20 token from the message sender (msgSender) to the contract itself. It's crucial for security that the transfer originates only from the message sender.

Input ParameterTypeDescription
addressaddressThe address of the token to transfer
valueuint256The amount of token to transfer

TRANSFER_FROM_WITH_PERMIT Command

Transfers the specified amount of the ERC20 token from the message sender (msgSender) to the contract itself using the EIP-2612 signed approvals.

Input ParameterTypeDescription
addressaddressThe address of the token to transfer
valueuint256The amount of token to transfer
deadlineuint256The deadline for the transaction
vuint8Signature
rbytes32Signature
sbytes32Signature

TRANSFER Command

Transfers a specified amount of the ERC20 token from the contract to the provided recipient address. If a special value indicating the contract's entire balance is provided, it transfers the entire token balance of the contract to the recipient.

Input ParameterTypeDescription
tokenaddressThe address of the token to transfer
recipientaddressThe address of the transfer receiver
valueuint256The amount of token to transfer

CURVE_SWAP Command

Executes a token swap using a Curve finance pool. The command involves specifying the tokens within the pool to swap, the amount to swap, and the minimum acceptable amount for the output token, ensuring slippage protection.

Input ParameterTypeDescription
pooladdressThe address of the pool
iuint256The token index to input from the swap
juint256The token index to output from the swap
amountInuint256The amount of token in
minAmountOutuint256The minimum amount of token out (slippage protection)
recipientaddressThe address of the swap recipient

WRAP_VAULT_IN_4626_ADAPTER Command

Wraps shares of an interest-bearing vault into an ERC4626 compliant wrapper (Spectra4626Wrapper.wrap()). The operation deposits the interest-bearing vault shares into a Spectra4626Wrapper instance and transfers the resulting wrapper shares to the specified recipient.

Input ParameterTypeDescription
wrapperaddressThe address of the Spectra4626Wrapper
vaultSharesuint256The amount of vaults shares to wrap
recipientaddressThe receiver of wrapper shares

UNWRAP_VAULT_FROM_4626_ADAPTER Command

Unwraps shares of an interest-bearing vault from an ERC4626 wrapper (Spectra4626Wrapper.unwrap()). The operation redeems shares of an Spectra4626Wrapper instance and transfers the resulting vault shares to the specified recipient.

Input ParameterTypeDescription
wrapperaddressThe address of the Spectra4626Wrapper
wrapperSharesuint256The amount of wrapper shares to redeem
recipientaddressThe receiver of vault shares

DEPOSIT_ASSET_IN_IBT Command

Deposits the specified amount of an underlying ERC20 token into an ERC4626 compliant tokenized vault (ERC4626.deposit()). The operation deposits the underlying token into the 4626 vault and transfers the resulting vault shares to the specified recipient.

Input ParameterTypeDescription
ibtaddressThe address of the IBT token
assetsuint256The amount of token to deposit
recipientaddressThe address of the transfer receiver

DEPOSIT_ASSET_IN_PT Command

Deposits the specified amount of an underlying ERC20 token in the PT (deposit()).

Input ParameterTypeDescription
ptaddressThe address of the PT token
assetsuint256The amount of token to deposit
ptRecipientaddressThe address of the receiver of PTs
ytRecipientaddressThe address of the receiver of YTs
minSharesuint256The minimum amount of minted shares from this deposit

DEPOSIT_IBT_IN_PT Command

Deposits the specified amount of an IBT token in the PT (depositIBT()).

Input ParameterTypeDescription
ptaddressThe address of the PT token
ibtsuint256The amount of token to deposit
ptRecipientaddressThe address of the receiver of PTs
ytRecipientaddressThe address of the receiver of YTs
minSharesuint256The minimum amount of minted shares from this deposit

REDEEM_IBT_FOR_ASSET Command

Redeems the specified amount of the ERC4626 vault shares for the underlying token (ERC4626.redeem()). The withdrawn tokens are then transferred to the specified recipient.

Input ParameterTypeDescription
tokenaddressThe address of the token
sharesuint256The amount of shares to burn
recipientaddressThe address of the transfer receiver

REDEEM_PT_FOR_ASSET Command

Redeems the specified amount of PT shares for the underlying token (redeem()).

Before expiry, the PT shares amount is both the PT and YT amount. After expiry, only the PT shares are burnt.

Input ParameterTypeDescription
ptaddressThe address of the PT
sharesuint256The amount of shares to burn
recipientaddressThe address of the transfer receiver
minAssetsuint256The minimum amount of asset to be returned to the user

REDEEM_PT_FOR_IBT Command

Redeems the specified amount of PT share for the associated IBT token (redeemForIBT()).

Before expiry, the PT shares amount is both the PT and YT amount. After expiry, only the PT shares are burnt.

Input ParameterTypeDescription
ptaddressThe address of the PT
sharesuint256The amount of shares to burn
recipientaddressThe address of the transfer receiver
minIbtsuint256The minimum amount of IBT to be returned to the user

FLASH_LOAN Command

Facilitates a flash loan transaction. It enables borrowing of a specified amount of an ERC20 token from a lender, with the requirement that it is returned within the same transaction, along with any agreed-upon fees.

Input ParameterTypeDescription
lenderaddressThe address of the flash loan lender
tokenaddressThe address of the token to borrow
amountuint256The amount of token to borrow
databytesAdditional data for the flash loan

ASSERT_MIN_BALANCE Command

Checks if the specified token balance of an owner's address is at least the provided minimum value. If the balance is below the minimum, the command reverts the entire transaction.

Input ParameterTypeDescription
tokenaddressThe address of the token
owneraddressThe address of the token owner to check the balance from
minValueuin256The minimum amount of token required

CURVE_SPLIT_IBT_LIQUIDITY Command

Split the input IBT amount into IBT for the pool and to deposit in the Principal Token. Add liquidity to the pool with the resulting PT and the split IBT amounts.

Input ParameterTypeDescription
pooladdressThe address of the Curve pool
ibtsuint256The amount of IBT to deposit
recipientaddressThe address of the LP token recipient
ytRecipientaddressThe address of the YT recipient
minPTSharesuint256The minimum amount of minted PT/YT shares from the portion of IBT deposited in the PT contract.

CURVE_ADD_LIQUIDITY Command

Add liquidity to the Curve pool specifying each token amount in input and the minimum amount of LP token to mint (slippage protection).

Input ParameterTypeDescription
pooladdressThe address of the Curve pool
amountsuint256[2]The amount of IBT/PT to deposit
min_mint_amountuint256The minimum amount of LP token to mint
recipientaddressThe address of the LP token recipient

CURVE_REMOVE_LIQUIDITY Command

Remove liquidity from Curve pool specifying the amount lps of LP tokens to burn and the minum amount of liquidity to withdraw for each token (slippage protection).

Input ParameterTypeDescription
pooladdressThe address of the Curve pool
lpsuint256The amount of LP tokens to burn
min_amountsuint256[2]The minimum amount of assets to receive
recipientaddressThe address of the tokens recipient

CURVE_REMOVE_LIQUIDITY_ONE_COIN Command

Remove liquidity from Curve pool by withdrawing a single coin. The user specify the amount lps of LP tokens to burn and the minimum amount of liquidity to withdraw for the chosen token (slippage protection).

Input ParameterTypeDescription
pooladdressThe address of the Curve pool
lpsuint256The amount of LP tokens to burn
iuint256The index of the token to withdraw from the pool
min_amountuint256The minimum amount of assets to receive
recipientaddressThe address of the token recipient

On this page