Comment on page
Swapper - Helper for Liquidations and Auto-Leverage
Swapper - Helper for liquidations and auto-leverage
Swappercontract is an example contract developed by Angle Labs to show how to swap collateral for stablecoins during the liquidation process or to swap stablecoins for collateral during the auto-leverage process in the Borrowing Module. This is a side contract with no specific role in the Borrowing Module.
Documentation here is given as a helper for those who might be interested in building their own contracts or in using Angle Labs' contract.
ISwapperinterface. This contract is not upgradeable (even though upgradeable versions of it could be deployed).
angleRouter: Reference to a router contract of the protocol
core: Reference to the Core contract of the module which handles all Access Control logic
wStETH: Wrapped StETH contract
uniV3Router: Uniswap Router contract
oneInch: 1Inch Router
The contract stores three different mappings to check whether Uniswap, 1Inch and Angle routers have been approved for a given token
Besides a function to change allowance for a given token accessible by governance, there is only one key function available in this contract: it is the
bytes memory data
swapfunction in the
ISwapperinterface notifies a contract that an address should be given
inToken. In this case, this function swaps the
outTokenby either doing mint, or burn from the protocol or/and combining it with a UniV3 or 1Inch swap, or with a StETH wrap.
No slippage checks are performed at the end of each operation, only one slippage check is performed at the end of the call.
inToken: Address of the token received
outToken: Address of the token to obtain
outTokenRecipient: Address to which the outToken should be sent
outTokenOwed: Amount of outToken owed by the
outTokenRecipient. If the
Swapperis called during an interaction with a
VaultManagercontract, for the operation to succeed, the
outTokenbalance should be greater than
outTokenOwedat the end of the call. It does not mean that the swap of
inTokenObtainedshould produce at least
inTokenObtainedAmount of collateral obtained by a related address prior to the call to this function. This
swapperimplementation assumes that the
inTokenhave been obtained on this contract directly (and therefore that there is no need for a
data: Extra data needed (to encode Uniswap swaps for instance). Specifically, in this implementation,
datashould be the abi-encoded version of parameters placed in the following order and of the following type:
address intermediateToken: Optional address that can be given to specify in case of a burn the address of the collateral to get in exchange for the stablecoin or in case of a mint the collateral used to mint. If the
swapcall does not involve any mint/burn, then this parameter can be the zero address
address to: Address to receive the surplus amount of token at the end of the call. This is the address to receive the leftover
outTokenof the swap
uint256 minAmountOut: For slippage protection, it is the min amount of
outTokenschecked at the end of the call
uint128 swapType: Type of the swap to execute: if
swapType == 3, then it is optional to swap.
0corresponds to a
1corresponds to a
2is to wrap
uint128 mintOrBurn: Whether a
burnoperation should be performed beyond the swap:
1corresponds to a burn and
2to a mint. It is optional. If the value is set to 1 or 2 then the value of the
intermediateTokenshould be made non null
bytes data: It's an optional variable to be used either for Uniswap swaps (in which case it is the path), or a 1Inch payload.
When using this contract as a
whocontract in a
VaultManagercall, it is important to make sure that this address is the
toaddress as it needs to receive the