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.
Input Parameter | Type | Description |
---|---|---|
| bytes calldata | A set of concatenated commands, each 1 byte in length |
| bytes[] calldata | An 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()
.
Input Parameter | Type | Description |
---|---|---|
| bytes calldata | A set of concatenated commands, each 1 byte in length |
| bytes[] calldata | An array of byte strings containing ABI encoded inputs for each command |
| uint256 | The deadline by which the transaction must be executed |
View Methods
previewRate
Simulates encoded commands along with provided inputs, and return the resulting rate.
Input Parameter | Type | Description |
---|---|---|
| bytes calldata | A set of concatenated commands, each 1 byte in length |
| bytes[] calldata | An array of byte strings containing ABI encoded inputs for each command |
| uint256 | The 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.
Input Parameter | Type | Description |
---|---|---|
| bytes calldata | A set of concatenated commands, each 1 byte in length |
| bytes[] calldata | An array of byte strings containing ABI encoded inputs for each command |
outputSpotRate | uint256 | The 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.
Input Parameter | Type | Description |
---|---|---|
| address | The initiator of the loan. |
| address | The loan currency. |
| uint256 | The amount of tokens to borrow. |
| uint256 | The additional amount of tokens to repay. |
| bytes calldata | Arbitrary data structure, intended to contain user-defined parameters. |
Return Parameter | Type | Description |
---|---|---|
bool | If 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
TRANSFER_FROM
CommandTransfers 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 Parameter | Type | Description |
---|---|---|
| address | The address of the token to transfer |
| uint256 | The amount of token to transfer |
TRANSFER_FROM_WITH_PERMIT
Command
TRANSFER_FROM_WITH_PERMIT
CommandTransfers the specified amount of the ERC20 token from the message sender (msgSender
) to the contract itself using the EIP-2612 signed approvals.
Input Parameter | Type | Description |
---|---|---|
| address | The address of the token to transfer |
| uint256 | The amount of token to transfer |
| uint256 | The deadline for the transaction |
| uint8 | Signature |
| bytes32 | Signature |
| bytes32 | Signature |
TRANSFER
Command
TRANSFER
CommandTransfers 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 Parameter | Type | Description |
---|---|---|
| address | The address of the token to transfer |
| address | The address of the transfer receiver |
| uint256 | The amount of token to transfer |
CURVE_SWAP
Command
CURVE_SWAP
CommandExecutes 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 Parameter | Type | Description |
---|---|---|
| address | The address of the pool |
| uint256 | The token index to input from the swap |
| uint256 | The token index to output from the swap |
| uint256 | The amount of token in |
| uint256 | The minimum amount of token out (slippage protection) |
| address | The address of the swap recipient |
WRAP_VAULT_IN_4626_ADAPTER
Command
WRAP_VAULT_IN_4626_ADAPTER
CommandWraps 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 Parameter | Type | Description |
---|---|---|
| address | The address of the Spectra4626Wrapper |
| uint256 | The amount of vaults shares to wrap |
| address | The receiver of wrapper shares |
UNWRAP_VAULT_FROM_4626_ADAPTER
Command
UNWRAP_VAULT_FROM_4626_ADAPTER
CommandUnwraps 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 Parameter | Type | Description |
---|---|---|
| address | The address of the Spectra4626Wrapper |
| uint256 | The amount of wrapper shares to redeem |
| address | The receiver of vault shares |
DEPOSIT_ASSET_IN_IBT
Command
DEPOSIT_ASSET_IN_IBT
CommandDeposits 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 Parameter | Type | Description |
---|---|---|
| address | The address of the IBT token |
| uint256 | The amount of token to deposit |
| address | The address of the transfer receiver |
DEPOSIT_ASSET_IN_PT
Command
DEPOSIT_ASSET_IN_PT
CommandDeposits the specified amount of an underlying ERC20 token in the PT (deposit()
).
Input Parameter | Type | Description |
---|---|---|
| address | The address of the PT token |
| uint256 | The amount of token to deposit |
| address | The address of the receiver of PTs |
| address | The address of the receiver of YTs |
| uint256 | The minimum amount of minted shares from this deposit |
DEPOSIT_IBT_IN_PT
Command
DEPOSIT_IBT_IN_PT
CommandDeposits the specified amount of an IBT token in the PT (depositIBT()
).
Input Parameter | Type | Description |
---|---|---|
| address | The address of the PT token |
| uint256 | The amount of token to deposit |
| address | The address of the receiver of PTs |
| address | The address of the receiver of YTs |
| uint256 | The minimum amount of minted shares from this deposit |
REDEEM_IBT_FOR_ASSET
Command
REDEEM_IBT_FOR_ASSET
CommandRedeems 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 Parameter | Type | Description |
---|---|---|
| address | The address of the token |
| uint256 | The amount of shares to burn |
| address | The address of the transfer receiver |
REDEEM_PT_FOR_ASSET
Command
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 Parameter | Type | Description |
---|---|---|
| address | The address of the PT |
| uint256 | The amount of shares to burn |
| address | The address of the transfer receiver |
| uint256 | The minimum amount of asset to be returned to the user |
REDEEM_PT_FOR_IBT
Command
REDEEM_PT_FOR_IBT
CommandRedeems 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 Parameter | Type | Description |
---|---|---|
| address | The address of the PT |
| uint256 | The amount of shares to burn |
| address | The address of the transfer receiver |
| uint256 | The minimum amount of IBT to be returned to the user |
FLASH_LOAN
Command
FLASH_LOAN
CommandFacilitates 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 Parameter | Type | Description |
---|---|---|
| address | The address of the flash loan lender |
| address | The address of the token to borrow |
| uint256 | The amount of token to borrow |
| bytes | Additional data for the flash loan |
ASSERT_MIN_BALANCE
Command
ASSERT_MIN_BALANCE
CommandChecks 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 Parameter | Type | Description |
---|---|---|
| address | The address of the token |
| address | The address of the token owner to check the balance from |
| uin256 | The minimum amount of token required |
CURVE_SPLIT_IBT_LIQUIDITY
Command
CURVE_SPLIT_IBT_LIQUIDITY
CommandSplit 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 Parameter | Type | Description |
---|---|---|
| address | The address of the Curve pool |
| uint256 | The amount of IBT to deposit |
| address | The address of the LP token recipient |
| address | The address of the YT recipient |
| uint256 | The minimum amount of minted PT/YT shares from the portion of IBT deposited in the PT contract. |
CURVE_ADD_LIQUIDITY
Command
CURVE_ADD_LIQUIDITY
CommandAdd liquidity to the Curve pool
specifying each token amount in input and the minimum amount of LP token to mint (slippage protection).
Input Parameter | Type | Description |
---|---|---|
| address | The address of the Curve pool |
| uint256[2] | The amount of IBT/PT to deposit |
| uint256 | The minimum amount of LP token to mint |
| address | The address of the LP token recipient |
CURVE_REMOVE_LIQUIDITY
Command
CURVE_REMOVE_LIQUIDITY
CommandRemove 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 Parameter | Type | Description |
---|---|---|
| address | The address of the Curve pool |
| uint256 | The amount of LP tokens to burn |
| uint256[2] | The minimum amount of assets to receive |
| address | The address of the tokens recipient |
CURVE_REMOVE_LIQUIDITY_ONE_COIN
Command
CURVE_REMOVE_LIQUIDITY_ONE_COIN
CommandRemove 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 Parameter | Type | Description |
---|---|---|
| address | The address of the Curve pool |
| uint256 | The amount of LP tokens to burn |
| uint256 | The index of the token to withdraw from the pool |
| uint256 | The minimum amount of assets to receive |
| address | The address of the token recipient |
Last updated