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.
commands
bytes calldata
A set of concatenated commands, each 1 byte in length
inputs
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()
.
commands
bytes calldata
A set of concatenated commands, each 1 byte in length
inputs
bytes[] calldata
An array of byte strings containing ABI encoded inputs for each command
deadline
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.
commands
bytes calldata
A set of concatenated commands, each 1 byte in length
inputs
bytes[] calldata
An array of byte strings containing ABI encoded inputs for each command
outputRate
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.
commands
bytes calldata
A set of concatenated commands, each 1 byte in length
inputs
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.
initiator
address
The initiator of the loan.
token
address
The loan currency.
amount
uint256
The amount of tokens to borrow.
fee
uint256
The additional amount of tokens to repay.
data
bytes calldata
Arbitrary data structure, intended to contain user-defined parameters.
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.
address
address
The address of the token to transfer
value
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.
address
address
The address of the token to transfer
value
uint256
The amount of token to transfer
deadline
uint256
The deadline for the transaction
v
uint8
Signature
r
bytes32
Signature
s
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.
token
address
The address of the token to transfer
recipient
address
The address of the transfer receiver
value
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.
pool
address
The address of the pool
i
uint256
The token index to input from the swap
j
uint256
The token index to output from the swap
amountIn
uint256
The amount of token in
minAmountOut
uint256
The minimum amount of token out (slippage protection)
recipient
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.
wrapper
address
The address of the Spectra4626Wrapper
vaultShares
uint256
The amount of vaults shares to wrap
recipient
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.
wrapper
address
The address of the Spectra4626Wrapper
wrapperShares
uint256
The amount of wrapper shares to redeem
recipient
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.
ibt
address
The address of the IBT token
assets
uint256
The amount of token to deposit
recipient
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()
).
pt
address
The address of the PT token
assets
uint256
The amount of token to deposit
ptRecipient
address
The address of the receiver of PTs
ytRecipient
address
The address of the receiver of YTs
minShares
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()
).
pt
address
The address of the PT token
ibts
uint256
The amount of token to deposit
ptRecipient
address
The address of the receiver of PTs
ytRecipient
address
The address of the receiver of YTs
minShares
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.
token
address
The address of the token
shares
uint256
The amount of shares to burn
recipient
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.
pt
address
The address of the PT
shares
uint256
The amount of shares to burn
recipient
address
The address of the transfer receiver
minAssets
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.
pt
address
The address of the PT
shares
uint256
The amount of shares to burn
recipient
address
The address of the transfer receiver
minIbts
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.
lender
address
The address of the flash loan lender
token
address
The address of the token to borrow
amount
uint256
The amount of token to borrow
data
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.
token
address
The address of the token
owner
address
The address of the token owner to check the balance from
minValue
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.
pool
address
The address of the Curve pool
ibts
uint256
The amount of IBT to deposit
recipient
address
The address of the LP token recipient
ytRecipient
address
The address of the YT recipient
minPTShares
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).
pool
address
The address of the Curve pool
amounts
uint256[2]
The amount of IBT/PT to deposit
min_mint_amount
uint256
The minimum amount of LP token to mint
recipient
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).
pool
address
The address of the Curve pool
lps
uint256
The amount of LP tokens to burn
min_amounts
uint256[2]
The minimum amount of assets to receive
recipient
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).
pool
address
The address of the Curve pool
lps
uint256
The amount of LP tokens to burn
i
uint256
The index of the token to withdraw from the pool
min_amount
uint256
The minimum amount of assets to receive
recipient
address
The address of the token recipient
Last updated