Skip to main content

Periphery

The Hifi protocol is architected such that every function does one job and job only. In software engineering parlance, this practice is called separation of concerns, a design principle which makes it easier to reason about how the protocol behaves. Most importantly, it gives the protocol better security guarantees.

Modularization comes with a cost, though. It forces us to "compose" multiple contract calls, if we wish to provide a good user experience in our user interface. This is where DSProxy comes into play - a smart contract wallet designed to address this need.

For brevity, we won't expound on the technical properties of DSProxy here. You can refer to this guide for a detailed explanation. In short:

  1. DSProxy is a smart contract wallet.
  2. There is a so-called "target contract" that contains composite scripts, toward which the DSProxy delegate calls.

Is it the target contract that is documented herein.

Functions

addLiquidity

function addLiquidity(
contract IHifiPool hifiPool,
uint256 underlyingOffered,
uint256 maxHTokenRequired
) external

Adds liquidity to the AMM.

Requirements:

  • The caller must have allowed the DSProxy to spend underlyingAmount and maxHTokenRequired tokens.

Parameters

NameTypeDescription
hifiPoolcontract IHifiPoolThe address of the HifiPool contract.
underlyingOffereduint256The amount of underlying to invest.
maxHTokenRequireduint256The maximum amount of hTokens that the user is willing to accept.

addLiquidityWithSignature

function addLiquidityWithSignature(
contract IHifiPool hifiPool,
uint256 underlyingOffered,
uint256 maxHTokenRequired,
uint256 deadline,
bytes signatureHToken,
bytes signatureUnderlying
) external

Adds liquidity to the AMM using EIP-2612 signatures.

Requirements:

  • The signature must be a valid signed approval given by caller to the DSProxy to spend underlyingAmount and maxHTokenRequired tokens for the given deadline and the caller's current nonce.

Parameters

NameTypeDescription
hifiPoolcontract IHifiPoolThe address of the HifiPool contract.
underlyingOffereduint256The amount of underlying to invest.
maxHTokenRequireduint256The maximum amount of hTokens that the user is willing to accept.
deadlineuint256The deadline beyond which the signatures are not valid anymore.
signatureHTokenbytesThe packed signature for the hToken.
signatureUnderlyingbytesThe packed signature for the underlying.

borrowHToken

function borrowHToken(
contract IBalanceSheetV2 balanceSheet,
contract IHToken hToken,
uint256 borrowAmount
) external

Borrows hTokens.

Parameters

NameTypeDescription
balanceSheetcontract IBalanceSheetV2The address of the BalanceSheet contract.
hTokencontract IHTokenThe address of the HToken contract.
borrowAmountuint256The amount of hTokens to borrow.

borrowHTokenAndAddLiquidity

function borrowHTokenAndAddLiquidity(
contract IBalanceSheetV2 balanceSheet,
contract IHifiPool hifiPool,
uint256 maxBorrowAmount,
uint256 underlyingOffered
) external

Borrows hTokens and adds liquidity to the AMM.

Requirements:

  • The caller must have allowed the DSProxy to spend underlyingAmount tokens.

Parameters

NameTypeDescription
balanceSheetcontract IBalanceSheetV2The address of the BalanceSheet contract.
hifiPoolcontract IHifiPoolThe address of the HifiPool contract.
maxBorrowAmountuint256The amount of hTokens to borrow and the max amount that the user is willing to invest.
underlyingOffereduint256The amount of underlying to invest.

borrowHTokenAndAddLiquidityWithSignature

function borrowHTokenAndAddLiquidityWithSignature(
contract IBalanceSheetV2 balanceSheet,
contract IHifiPool hifiPool,
uint256 maxBorrowAmount,
uint256 underlyingOffered,
uint256 deadline,
bytes signatureUnderlying
) external

Borrows hTokens and adds liquidity to the AMM using EIP-2612 signatures.

Requirements:

  • The signature must be a valid signed approval given by the caller to the DSProxy to spend underlyingOffered tokens for the given deadline and the caller's current nonce.

Parameters

NameTypeDescription
balanceSheetcontract IBalanceSheetV2The address of the BalanceSheet contract.
hifiPoolcontract IHifiPoolThe address of the HifiPool contract.
maxBorrowAmountuint256The amount of hTokens to borrow and the max amount that the user is willing to invest.
underlyingOffereduint256The amount of underlying to invest.
deadlineuint256The deadline beyond which the signature is not valid anymore.
signatureUnderlyingbytesThe packed signature for the underlying.

borrowHTokenAndBuyUnderlying

function borrowHTokenAndBuyUnderlying(
contract IBalanceSheetV2 balanceSheet,
contract IHifiPool hifiPool,
uint256 maxBorrowAmount,
uint256 underlyingOut
) external

Borrows hTokens and buys underlying.

Emits a {BorrowHTokenAndBuyUnderlying} event.

Parameters

NameTypeDescription
balanceSheetcontract IBalanceSheetV2The address of the BalanceSheet contract.
hifiPoolcontract IHifiPoolThe address of the HifiPool contract.
maxBorrowAmountuint256The amount of hTokens to borrow and the max amount that the user is willing to pay.
underlyingOutuint256The exact amount of underlying that the user wants to buy.

borrowHTokenAndSellHToken

function borrowHTokenAndSellHToken(
contract IBalanceSheetV2 balanceSheet,
contract IHifiPool hifiPool,
uint256 borrowAmount,
uint256 minUnderlyingOut
) external

Borrows hTokens and sells them.

Emits a {BorrowHTokenAndSellHToken} event.

Parameters

NameTypeDescription
balanceSheetcontract IBalanceSheetV2The address of the BalanceSheet contract.
hifiPoolcontract IHifiPoolThe address of the HifiPool contract.
borrowAmountuint256The exact amount of hTokens to borrow and sell.
minUnderlyingOutuint256The minimum amount of underlying that the user is willing to accept.

buyHToken

function buyHToken(
contract IHifiPool hifiPool,
uint256 hTokenOut,
uint256 maxUnderlyingIn
) external

Buys hTokens with underlying.

Requirements:

  • The caller must have allowed DSProxy to spend maxUnderlyingIn tokens.

Parameters

NameTypeDescription
hifiPoolcontract IHifiPoolThe address of the HifiPool contract.
hTokenOutuint256The exact amount of hTokens that the user wants to buy.
maxUnderlyingInuint256The maximum amount of underlying that the user is willing to pay.

buyHTokenAndAddLiquidity

function buyHTokenAndAddLiquidity(
contract IHifiPool hifiPool,
uint256 hTokenOut,
uint256 maxUnderlyingAmount
) external

Buys hTokens and adds liquidity to the AMM.

Requirements:

  • The caller must have allowed DSProxy to spend maxUnderlyingIn + underlyingOffered tokens.

Parameters

NameTypeDescription
hifiPoolcontract IHifiPoolThe address of the HifiPool contract.
hTokenOutuint256The amount of hTokens to buy.
maxUnderlyingAmountuint256The maximum amount of underlying that the user is willing to sell and invest.

buyHTokenAndAddLiquidityWithSignature

function buyHTokenAndAddLiquidityWithSignature(
contract IHifiPool hifiPool,
uint256 hTokenOut,
uint256 maxUnderlyingAmount,
uint256 deadline,
bytes signatureUnderlying
) external

Buys hTokens and adds liquidity to the AMM using EIP-2612 signatures.

Requirements:

  • The signature must be a valid signed approval given by the caller to the DSProxy to spend maxUnderlyingIn + underlyingOffered tokens for the given deadline and the caller's current nonce.

Parameters

NameTypeDescription
hifiPoolcontract IHifiPoolThe address of the HifiPool contract.
hTokenOutuint256The amount of hTokens to buy.
maxUnderlyingAmountuint256The maximum amount of underlying that the user is willing to sell and invest.
deadlineuint256The deadline beyond which the signature is not valid anymore.
signatureUnderlyingbytesThe packed signature for the underlying.

buyHTokenAndRepayBorrow

function buyHTokenAndRepayBorrow(
contract IHifiPool hifiPool,
contract IBalanceSheetV2 balanceSheet,
uint256 maxUnderlyingIn,
uint256 hTokenOut
) external

Buys hTokens with underlying and repays the borrow.

Requirements:

  • The caller must have allowed the DSProxy to spend maxUnderlyingIn tokens.

Parameters

NameTypeDescription
hifiPoolcontract IHifiPoolThe address of the HifiPool contract.
balanceSheetcontract IBalanceSheetV2The address of the BalanceSheet contract.
maxUnderlyingInuint256The maximum amount of underlying that the user is willing to pay.
hTokenOutuint256The exact amount of hTokens to buy and the amount to repay and the maximum amount to repay.

buyHTokenAndRepayBorrowWithSignature

function buyHTokenAndRepayBorrowWithSignature(
contract IHifiPool hifiPool,
contract IBalanceSheetV2 balanceSheet,
uint256 maxUnderlyingIn,
uint256 hTokenOut,
uint256 deadline,
bytes signatureUnderlying
) external

Buys hTokens with underlying and repays the borrow.

Requirements:

  • The signature must be a valid signed approval given by the caller to the DSProxy to spend maxUnderlyingIn tokens for the given deadline and the caller's current nonce.

Parameters

NameTypeDescription
hifiPoolcontract IHifiPoolThe address of the HifiPool contract.
balanceSheetcontract IBalanceSheetV2The address of the BalanceSheet contract.
maxUnderlyingInuint256The maximum amount of underlying that the user is willing to pay.
hTokenOutuint256The exact amount of hTokens to buy and the amount to repay and the maximum amount to repay.
deadlineuint256The deadline beyond which the signature is not valid anymore.
signatureUnderlyingbytesThe packed signature for the underlying.

buyHTokenWithSignature

function buyHTokenWithSignature(
contract IHifiPool hifiPool,
uint256 hTokenOut,
uint256 maxUnderlyingIn,
uint256 deadline,
bytes signatureUnderlying
) external

Buys hTokens with underlying using EIP-2612 signatures.

Requirements:

  • The signature must be a valid signed approval given by the caller to the DSProxy to spend maxUnderlyingIn tokens for the given deadline and the caller's current nonce.

Parameters

NameTypeDescription
hifiPoolcontract IHifiPoolThe address of the HifiPool contract.
hTokenOutuint256The exact amount of hTokens that the user wants to buy.
maxUnderlyingInuint256The maximum amount of underlying that the user is willing to pay.
deadlineuint256The deadline beyond which the signature is not valid anymore.
signatureUnderlyingbytesThe packed signature for the underlying.

buyUnderlying

function buyUnderlying(
contract IHifiPool hifiPool,
uint256 underlyingOut,
uint256 maxHTokenIn
) external

Buys underlying with hTokens.

Requirements:

  • The caller must have allowed DSProxy to spend maxHTokenIn tokens.

Parameters

NameTypeDescription
hifiPoolcontract IHifiPoolThe address of the HifiPool contract.
underlyingOutuint256The exact amount of underlying that the user wants to buy.
maxHTokenInuint256The maximum amount of hTokens that the user is willing to pay.

buyUnderlyingAndAddLiquidity

function buyUnderlyingAndAddLiquidity(
contract IHifiPool hifiPool,
uint256 maxHTokenAmount,
uint256 underlyingOffered
) external

Buys underlying and adds liquidity to the AMM.

  • The caller must have allowed DSProxy to spend maxHTokenAmount tokens.

Parameters

NameTypeDescription
hifiPoolcontract IHifiPoolThe address of the HifiPool contract.
maxHTokenAmountuint256maxHTokenAmount The maximum amount of hTokens that the user is willing to invest.
underlyingOffereduint256The amount of underlying to invest.

buyUnderlyingAndAddLiquidityWithSignature

function buyUnderlyingAndAddLiquidityWithSignature(
contract IHifiPool hifiPool,
uint256 maxHTokenAmount,
uint256 underlyingOffered,
uint256 deadline,
bytes signatureHToken
) external

Buys underlying and adds liquidity to the AMM.

  • The signature must be a valid signed approval given by the caller to the DSProxy to spend maxHTokenAmount tokens for the given deadline and the caller's current nonce.

Parameters

NameTypeDescription
hifiPoolcontract IHifiPoolThe address of the HifiPool contract.
maxHTokenAmountuint256maxHTokenAmount The maximum amount of hTokens that the user is willing to invest.
underlyingOffereduint256The amount of underlying to invest.
deadlineuint256The deadline beyond which the signature is not valid anymore.
signatureHTokenbytesThe packed signature for the hToken.

buyUnderlyingWithSignature

function buyUnderlyingWithSignature(
contract IHifiPool hifiPool,
uint256 underlyingOut,
uint256 maxHTokenIn,
uint256 deadline,
bytes signatureHToken
) external

Buys underlying with hTokens using EIP-2612 signatures.

Requirements:

  • The signature must be a valid signed approval given by the caller to the DSProxy to spend maxHTokenIn tokens for the given deadline and the caller's current nonce.

Parameters

NameTypeDescription
hifiPoolcontract IHifiPoolThe address of the HifiPool contract.
underlyingOutuint256The exact amount of underlying that the user wants to buy.
maxHTokenInuint256The maximum amount of hTokens that the user is willing to pay.
deadlineuint256The deadline beyond which the signature is not valid anymore.
signatureHTokenbytesThe packed signature for the hToken.

depositCollateral

function depositCollateral(
contract IBalanceSheetV2 balanceSheet,
contract IErc20 collateral,
uint256 depositAmount
) external

Deposits collateral into the vault.

Requirements:

  • The caller must have allowed the DSProxy to spend collateralAmount tokens.

Parameters

NameTypeDescription
balanceSheetcontract IBalanceSheetV2The address of the BalanceSheet contract.
collateralcontract IErc20The address of the collateral contract.
depositAmountuint256The amount of collateral to deposit.

depositCollateralAndBorrowHToken

function depositCollateralAndBorrowHToken(
contract IBalanceSheetV2 balanceSheet,
contract IErc20 collateral,
contract IHToken hToken,
uint256 depositAmount,
uint256 borrowAmount
) external

Deposits collateral into the vault and borrows hTokens.

Requirements:

  • The caller must have allowed the DSProxy to spend collateralAmount tokens.

Parameters

NameTypeDescription
balanceSheetcontract IBalanceSheetV2The address of the BalanceSheet contract.
collateralcontract IErc20The address of the collateral contract.
hTokencontract IHTokenThe address of the HToken contract.
depositAmountuint256The amount of collateral to deposit.
borrowAmountuint256The amount of hTokens to borrow.

depositCollateralAndBorrowHTokenAndAddLiquidity

function depositCollateralAndBorrowHTokenAndAddLiquidity(
contract IBalanceSheetV2 balanceSheet,
contract IErc20 collateral,
contract IHifiPool hifiPool,
uint256 depositAmount,
uint256 maxBorrowAmount,
uint256 underlyingOffered
) external

Deposits collateral into the vault, borrows hTokens and adds liquidity to the AMM.

Requirements:

  • The caller must have allowed the DSProxy to spend collateralAmount tokens.

Parameters

NameTypeDescription
balanceSheetcontract IBalanceSheetV2The address of the BalanceSheet contract.
collateralcontract IErc20The address of the collateral contract.
hifiPoolcontract IHifiPoolThe address of the HifiPool contract.
depositAmountuint256The amount of collateral to deposit.
maxBorrowAmountuint256The amount of hTokens to borrow and the max amount that the user is willing to invest.
underlyingOffereduint256The amount of underlying to invest.

depositCollateralAndBorrowHTokenAndAddLiquidityWithSignature

function depositCollateralAndBorrowHTokenAndAddLiquidityWithSignature(
contract IBalanceSheetV2 balanceSheet,
contract IErc20Permit collateral,
contract IHifiPool hifiPool,
uint256 depositAmount,
uint256 maxBorrowAmount,
uint256 underlyingOffered,
uint256 deadline,
bytes signatureCollateral,
bytes signatureUnderlying
) external

Deposits collateral into the vault, borrows hTokens and adds liquidity to the AMM using EIP-2612 signatures.

Requirements:

  • The signature must be a valid signed approval given by the caller to the DSProxy to spend collateralAmount and underlyingAmount tokens for the given deadline and the caller's current nonce.

Parameters

NameTypeDescription
balanceSheetcontract IBalanceSheetV2The address of the BalanceSheet contract.
collateralcontract IErc20PermitThe address of the collateral contract.
hifiPoolcontract IHifiPoolThe address of the HifiPool contract.
depositAmountuint256The amount of collateral to deposit.
maxBorrowAmountuint256The amount of hTokens to borrow and the max amount that the user is willing to invest.
underlyingOffereduint256The amount of underlying to invest.
deadlineuint256The deadline beyond which the signatures are not valid anymore.
signatureCollateralbytesThe packed signature for the collateral.
signatureUnderlyingbytesThe packed signature for the underlying.

depositCollateralAndBorrowHTokenAndSellHToken

function depositCollateralAndBorrowHTokenAndSellHToken(
contract IBalanceSheetV2 balanceSheet,
contract IErc20 collateral,
contract IHifiPool hifiPool,
uint256 depositAmount,
uint256 borrowAmount,
uint256 minUnderlyingOut
) external

Deposits collateral into the vault, borrows hTokens and sells them.

Requirements:

  • The caller must have allowed the DSProxy to spend collateralAmount tokens.

Parameters

NameTypeDescription
balanceSheetcontract IBalanceSheetV2The address of the BalanceSheet contract.
collateralcontract IErc20The address of the collateral contract.
hifiPoolcontract IHifiPoolThe address of the HifiPool contract.
depositAmountuint256The amount of collateral to deposit.
borrowAmountuint256The exact amount of hTokens to borrow.
minUnderlyingOutuint256The minimum amount of underlying that the user is willing to accept.

depositCollateralAndBorrowHTokenAndSellHTokenWithSignature

function depositCollateralAndBorrowHTokenAndSellHTokenWithSignature(
contract IBalanceSheetV2 balanceSheet,
contract IErc20Permit collateral,
contract IHifiPool hifiPool,
uint256 depositAmount,
uint256 borrowAmount,
uint256 minUnderlyingOut,
uint256 deadline,
bytes signatureCollateral
) external

Deposits collateral into the vault, borrows hTokens and sells them.

Requirements:

  • The signature must be a valid signed approval given by the caller to the DSProxy to spend collateralAmount and underlyingAmount for the given deadline and the caller's current nonce.

Parameters

NameTypeDescription
balanceSheetcontract IBalanceSheetV2The address of the BalanceSheet contract.
collateralcontract IErc20PermitThe address of the collateral contract.
hifiPoolcontract IHifiPoolThe address of the HifiPool contract.
depositAmountuint256The amount of collateral to deposit.
borrowAmountuint256The exact amount of hTokens to borrow.
minUnderlyingOutuint256The minimum amount of underlying that the user is willing to accept.
deadlineuint256The deadline beyond which the signature is not valid anymore.
signatureCollateralbytesThe packed signature for the collateral.

depositCollateralAndBorrowHTokenWithSignature

function depositCollateralAndBorrowHTokenWithSignature(
contract IBalanceSheetV2 balanceSheet,
contract IErc20Permit collateral,
contract IHToken hToken,
uint256 depositAmount,
uint256 borrowAmount,
uint256 deadline,
bytes signatureCollateral
) external

Deposits collateral into the vault and borrows hTokens using EIP-2612 signatures.

Requirements:

  • The signature must be a valid signed approval given by the caller to the DSProxy to spend depositAmount collateral tokens for the given deadline and the caller's current nonce.

Parameters

NameTypeDescription
balanceSheetcontract IBalanceSheetV2The address of the BalanceSheet contract.
collateralcontract IErc20PermitThe address of the collateral contract.
hTokencontract IHTokenThe address of the HToken contract.
depositAmountuint256The amount of collateral to deposit.
borrowAmountuint256The amount of hTokens to borrow.
deadlineuint256The deadline beyond which the signature is not valid anymore.
signatureCollateralbytesThe packed signature for the collateral.

depositCollateralWithSignature

function depositCollateralWithSignature(
contract IBalanceSheetV2 balanceSheet,
contract IErc20Permit collateral,
uint256 depositAmount,
uint256 deadline,
bytes signatureCollateral
) external

Deposits collateral into the vault using EIP-2612 signatures.

Requirements:

  • The signature must be a valid signed approval given by the caller to the DSProxy to spend depositAmount tokens for the given deadline and the caller's current nonce.

Parameters

NameTypeDescription
balanceSheetcontract IBalanceSheetV2The address of the BalanceSheet contract.
collateralcontract IErc20PermitThe address of the collateral contract.
depositAmountuint256The amount of collateral to deposit.
deadlineuint256The deadline beyond which the signature is not valid anymore.
signatureCollateralbytesThe packed signature for the collateral.

depositUnderlying

function depositUnderlying(
contract IHToken hToken,
uint256 underlyingAmount
) external

Deposits the underlying in the HToken contract to mint hTokens.

Requirements:

  • The caller must have allowed the DSProxy to spend underlyingAmount tokens.

Parameters

NameTypeDescription
hTokencontract IHTokenThe address of the HToken contract.
underlyingAmountuint256The amount of underlying to deposit.

depositUnderlyingAndMintHTokenAndAddLiquidity

function depositUnderlyingAndMintHTokenAndAddLiquidity(
contract IHifiPool hifiPool,
uint256 depositAmount,
uint256 underlyingOffered
) external

Deposits underlying in the HToken contract to mint hTokens, and adds liquidity to the AMM.

Requirements:

  • The caller must have allowed the DSProxy to spend depositAmount + underlyingOffered tokens.

Parameters

NameTypeDescription
hifiPoolcontract IHifiPoolThe address of the HifiPool contract.
depositAmountuint256The amount of underlying to deposit to mint equivalent amount of hTokens.
underlyingOffereduint256The amount of underlying to invest.

depositUnderlyingAndMintHTokenAndAddLiquidityWithSignature

function depositUnderlyingAndMintHTokenAndAddLiquidityWithSignature(
contract IHifiPool hifiPool,
uint256 depositAmount,
uint256 underlyingOffered,
uint256 deadline,
bytes signatureUnderlying
) external

Deposits underlying in the HToken contract to mint hTokens, and adds liquidity to the AMM using EIP-2612 signatures.

Requirements:

  • The signature must be a valid signed approval given by the caller to the DSProxy to spend depositAmount + underlyingOffered for the given deadline and the caller's current nonce.

Parameters

NameTypeDescription
hifiPoolcontract IHifiPoolThe address of the HifiPool contract.
depositAmountuint256The amount of underlying to deposit to mint equivalent amount of hTokens.
underlyingOffereduint256The amount of underlying to invest.
deadlineuint256The deadline beyond which the signature is not valid anymore.
signatureUnderlyingbytesThe packed signature for the underlying.

depositUnderlyingAndRepayBorrow

function depositUnderlyingAndRepayBorrow(
contract IHToken hToken,
contract IBalanceSheetV2 balanceSheet,
uint256 underlyingAmount
) external

Deposits underlying in the HToken contract to mint hTokens, and repays the borrow.

Requirements:

  • The caller must have allowed the DSProxy to spend underlyingAmount tokens.

Parameters

NameTypeDescription
hTokencontract IHTokenThe address of the HToken contract.
balanceSheetcontract IBalanceSheetV2The address of the BalanceSheet contract.
underlyingAmountuint256The amount of underlying to deposit.

depositUnderlyingAndRepayBorrowWithSignature

function depositUnderlyingAndRepayBorrowWithSignature(
contract IHToken hToken,
contract IBalanceSheetV2 balanceSheet,
uint256 underlyingAmount,
uint256 deadline,
bytes signatureUnderlying
) external

Supplies underlying to mint hTokens and repay the hToken borrow using EIP-2612 signatures.

Requirements:

  • The signature must be a valid signed approval given by the caller to the DSProxy to spend underlyingAmount for the given deadline and the caller's current nonce.

Parameters

NameTypeDescription
hTokencontract IHTokenThe address of the HToken contract.
balanceSheetcontract IBalanceSheetV2The address of the BalanceSheet contract.
underlyingAmountuint256The amount of underlying to supply.
deadlineuint256The deadline beyond which the signature is not valid anymore.
signatureUnderlyingbytesThe packed signature for the underlying.

depositUnderlyingWithSignature

function depositUnderlyingWithSignature(
contract IHToken hToken,
uint256 underlyingAmount,
uint256 deadline,
bytes signatureUnderlying
) external

Supplies the underlying to mint hTokens using EIP-2612 signatures.

Requirements:

  • The signature must be a valid signed approval given by the caller to the DSProxy to spend underlyingAmount for the given deadline and the caller's current nonce.

Parameters

NameTypeDescription
hTokencontract IHTokenThe address of the HToken contract.
underlyingAmountuint256The amount of underlying to supply.
deadlineuint256The deadline beyond which the signature is not valid anymore.
signatureUnderlyingbytesThe packed signature for the underlying.

redeem

function redeem(
contract IHToken hToken,
uint256 hTokenAmount,
uint256 underlyingAmount
) external

Redeems the underlying in exchange for hTokens.

Requirements:

  • The caller must have allowed the DSProxy to spend hTokenAmount hTokens.

Parameters

NameTypeDescription
hTokencontract IHTokenThe address of the HToken contract.
hTokenAmountuint256The amount of hTokens to provide.
underlyingAmountuint256The amount of underlying to redeem.

redeemWithSignature

function redeemWithSignature(
contract IHToken hToken,
uint256 hTokenAmount,
uint256 underlyingAmount,
uint256 deadline,
bytes signatureHToken
) external

Redeems hTokens for underlying using EIP-2612 signatures.

Requirements:

  • The signature must be a valid signed approval given by the caller to the DSProxy to spend hTokenAmount for the given deadline and the caller's current nonce.

Parameters

NameTypeDescription
hTokencontract IHTokenThe address of the HToken contract.
hTokenAmountuint256The amount of hTokens to redeem.
underlyingAmountuint256The amount of underlying to redeem.
deadlineuint256The deadline beyond which the signature is not valid anymore.
signatureHTokenbytesThe packed signature for hToken.

removeLiquidity

function removeLiquidity(
contract IHifiPool hifiPool,
uint256 poolTokensBurned
) external

Removes liquidity from the AMM.

Requirements:

  • The caller must have allowed the DSProxy to spend poolTokensBurned tokens.

Parameters

NameTypeDescription
hifiPoolcontract IHifiPoolThe address of the HifiPool contract.
poolTokensBurneduint256The amount of LP tokens to burn.

removeLiquidityAndRedeem

function removeLiquidityAndRedeem(
contract IHifiPool hifiPool,
uint256 poolTokensBurned
) external

Removes liquidity from the AMM and redeems underlying in exchange for all hTokens retrieved from the AMM.

Requirements:

  • The caller must have allowed the DSProxy to spend poolTokensBurned tokens.

Parameters

NameTypeDescription
hifiPoolcontract IHifiPoolThe address of the HifiPool contract.
poolTokensBurneduint256The amount of LP tokens to burn.

removeLiquidityAndRedeemWithSignature

function removeLiquidityAndRedeemWithSignature(
contract IHifiPool hifiPool,
uint256 poolTokensBurned,
uint256 deadline,
bytes signatureLPToken
) external

Removes liquidity from the AMM, and redeems all hTokens for the underlying using EIP-2612 signatures.

Requirements:

  • The signature must be a valid signed approval given by the caller to the DSProxy to spend poolTokensBurned for the given deadline and the caller's current nonce.

Parameters

NameTypeDescription
hifiPoolcontract IHifiPoolThe address of the HifiPool contract.
poolTokensBurneduint256The amount of LP tokens to burn.
deadlineuint256The deadline beyond which the signature is not valid anymore.
signatureLPTokenbytesThe packed signature for LP tokens.

removeLiquidityAndSellHToken

function removeLiquidityAndSellHToken(
contract IHifiPool hifiPool,
uint256 poolTokensBurned,
uint256 minUnderlyingOut
) external

Removes liquidity from the AMM, and sells all hTokens for the underlying.

Requirements:

  • The caller must have allowed the DSProxy to spend poolTokensBurned tokens.

Parameters

NameTypeDescription
hifiPoolcontract IHifiPoolThe address of the HifiPool contract.
poolTokensBurneduint256The amount of LP tokens to burn.
minUnderlyingOutuint256The minimum amount of underlying that the user is willing to accept.

removeLiquidityAndSellHTokenWithSignature

function removeLiquidityAndSellHTokenWithSignature(
contract IHifiPool hifiPool,
uint256 poolTokensBurned,
uint256 minUnderlyingOut,
uint256 deadline,
bytes signatureLPToken
) external

Removes liquidity from the AMM, and sells all hTokens for underlying using EIP-2612 signatures.

Requirements:

  • The signature must be a valid signed approval given by the caller to the DSProxy to spend poolTokensBurned for the given deadline and the caller's current nonce.

Parameters

NameTypeDescription
hifiPoolcontract IHifiPoolThe address of the HifiPool contract.
poolTokensBurneduint256The amount of LP tokens to burn.
minUnderlyingOutuint256The minimum amount of underlying that the user is willing to accept.
deadlineuint256The deadline beyond which the signature is not valid anymore.
signatureLPTokenbytesThe packed signature for LP tokens.

removeLiquidityAndWithdrawUnderlying

function removeLiquidityAndWithdrawUnderlying(
contract IHifiPool hifiPool,
uint256 poolTokensBurned,
uint256 withdrawAmount
) external

Removes liquidity from the AMM, and withdraws underlying in exchange for hTokens.

Requirements:

  • The caller must have allowed the DSProxy to spend poolTokensBurned tokens.
  • Can only be called before maturation.

Parameters

NameTypeDescription
hifiPoolcontract IHifiPoolThe address of the HifiPool contract.
poolTokensBurneduint256The amount of LP tokens to burn.
withdrawAmountuint256The amount of underlying to withdraw in exchange for hTokens.

removeLiquidityAndWithdrawUnderlyingWithSignature

function removeLiquidityAndWithdrawUnderlyingWithSignature(
contract IHifiPool hifiPool,
uint256 poolTokensBurned,
uint256 withdrawAmount,
uint256 deadline,
bytes signatureLPToken
) external

Removes liquidity from the AMM, and withdraws underlying in exchange for hTokens using EIP-2612 signatures.

Requirements:

  • The signature must be a valid signed approval given by the caller to the DSProxy to spend poolTokensBurned for the given deadline and the caller's current nonce.

Parameters

NameTypeDescription
hifiPoolcontract IHifiPoolThe address of the HifiPool contract.
poolTokensBurneduint256The amount of LP tokens to burn.
withdrawAmountuint256The amount of underlying to withdraw in exchange for hTokens.
deadlineuint256The deadline beyond which the signature is not valid anymore.
signatureLPTokenbytesThe packed signature for LP tokens.

removeLiquidityWithSignature

function removeLiquidityWithSignature(
contract IHifiPool hifiPool,
uint256 poolTokensBurned,
uint256 deadline,
bytes signatureLPToken
) external

Removes liquidity from the AMM using EIP-2612 signatures.

Requirements:

  • The signature must be a valid signed approval given by the caller to the DSProxy to spend poolTokensBurned for the given deadline and the caller's current nonce.

Parameters

NameTypeDescription
hifiPoolcontract IHifiPoolThe address of the HifiPool contract.
poolTokensBurneduint256The amount of LP tokens to burn.
deadlineuint256The deadline beyond which the signature is not valid anymore.
signatureLPTokenbytesThe packed signature for LP tokens.

repayBorrow

function repayBorrow(
contract IBalanceSheetV2 balanceSheet,
contract IHToken hToken,
uint256 repayAmount
) external

Repays the hToken borrow.

Requirements:

  • The caller must have allowed the DSProxy to spend repayAmount hTokens.

Parameters

NameTypeDescription
balanceSheetcontract IBalanceSheetV2The address of the BalanceSheet contract.
hTokencontract IHTokenThe address of the HToken contract.
repayAmountuint256The amount of hTokens to repay.

repayBorrowWithSignature

function repayBorrowWithSignature(
contract IBalanceSheetV2 balanceSheet,
contract IHToken hToken,
uint256 repayAmount,
uint256 deadline,
bytes signatureHToken
) external

Repays the hToken borrow using EIP-2612 signatures.

Requirements:

  • The signature must be a valid signed approval given by the caller to the DSProxy to spend repayAmount hTokens for the given deadline and the caller's current nonce.

Parameters

NameTypeDescription
balanceSheetcontract IBalanceSheetV2The address of the BalanceSheet contract.
hTokencontract IHTokenThe address of the HToken contract.
repayAmountuint256The amount of hTokens to repay.
deadlineuint256The deadline beyond which the signature is not valid anymore.
signatureHTokenbytesThe packed signature for HTokens.

sellHToken

function sellHToken(
contract IHifiPool hifiPool,
uint256 hTokenIn,
uint256 minUnderlyingOut
) external

Sells hTokens for underlying.

Requirements:

  • The caller must have allowed DSProxy to spend hTokenIn tokens.

Parameters

NameTypeDescription
hifiPoolcontract IHifiPoolThe address of the HifiPool contract.
hTokenInuint256The exact amount of hTokens that the user wants to sell.
minUnderlyingOutuint256The minimum amount of underlying that the user is willing to accept.

sellHTokenWithSignature

function sellHTokenWithSignature(
contract IHifiPool hifiPool,
uint256 hTokenIn,
uint256 minUnderlyingOut,
uint256 deadline,
bytes signatureHToken
) external

Sells hTokens for underlying using EIP-2612 signatures.

Requirements:

  • The signature must be a valid signed approval given by the caller to the DSProxy to spend hTokenIn hTokens for the given deadline and the caller's current nonce.

Parameters

NameTypeDescription
hifiPoolcontract IHifiPoolThe address of the HifiPool contract.
hTokenInuint256The exact amount of hTokens that the user wants to sell.
minUnderlyingOutuint256The minimum amount of underlying that the user is willing to accept.
deadlineuint256The deadline beyond which the signature is not valid anymore.
signatureHTokenbytesThe packed signature for HTokens.

sellUnderlying

function sellUnderlying(
contract IHifiPool hifiPool,
uint256 underlyingIn,
uint256 minHTokenOut
) external

Sells underlying for hTokens.

Requirements:

  • The caller must have allowed DSProxy to spend underlyingIn tokens.

Parameters

NameTypeDescription
hifiPoolcontract IHifiPoolThe address of the HifiPool contract.
underlyingInuint256The exact amount of underlying that the user wants to sell.
minHTokenOutuint256The minimum amount of hTokens that the user is willing to accept.

sellUnderlyingAndRepayBorrow

function sellUnderlyingAndRepayBorrow(
contract IHifiPool hifiPool,
contract IBalanceSheetV2 balanceSheet,
uint256 underlyingIn,
uint256 minHTokenOut
) external

Sells underlying for hTokens, then uses them to repay the hToken borrow.

Requirements:

  • The caller must have allowed the DSProxy to spend underlyingIn tokens.

Parameters

NameTypeDescription
hifiPoolcontract IHifiPoolThe address of the HifiPool contract.
balanceSheetcontract IBalanceSheetV2The address of the BalanceSheet contract.
underlyingInuint256The exact amount of underlying that the user wants to sell.
minHTokenOutuint256The minimum amount of hTokens that the user is willing to accept and the maximum amount to repay.

sellUnderlyingAndRepayBorrowWithSignature

function sellUnderlyingAndRepayBorrowWithSignature(
contract IHifiPool hifiPool,
contract IBalanceSheetV2 balanceSheet,
uint256 underlyingIn,
uint256 minHTokenOut,
uint256 deadline,
bytes signatureUnderlying
) external

Sells underlying for hTokens, then uses them to repay the hToken borrow using EIP-2612 signatures.

Requirements:

  • The signature must be a valid signed approval given by the caller to the DSProxy to spend underlyingIn for the given deadline and the caller's current nonce.

Parameters

NameTypeDescription
hifiPoolcontract IHifiPoolThe address of the HifiPool contract.
balanceSheetcontract IBalanceSheetV2The address of the BalanceSheet contract.
underlyingInuint256The exact amount of underlying that the user wants to sell.
minHTokenOutuint256The minimum amount of hTokens that the user is willing to accept and the maximum amount to repay.
deadlineuint256The deadline beyond which the signature is not valid anymore.
signatureUnderlyingbytesThe packed signature for the underlying.

sellUnderlyingWithSignature

function sellUnderlyingWithSignature(
contract IHifiPool hifiPool,
uint256 underlyingIn,
uint256 minHTokenOut,
uint256 deadline,
bytes signatureUnderlying
) external

Sells underlying for hTokens using EIP-2612 signatures.

Requirements:

  • The signature must be a valid signed approval given by the caller to the DSProxy to spend underlyingIn for the given deadline and the caller's current nonce.

Parameters

NameTypeDescription
hifiPoolcontract IHifiPoolThe address of the HifiPool contract.
underlyingInuint256The exact amount of underlying that the user wants to sell.
minHTokenOutuint256The minimum amount of hTokens that the user is willing to accept.
deadlineuint256The deadline beyond which the signature is not valid anymore.
signatureUnderlyingbytesThe packed signature for the underlying.

withdrawCollateral

function withdrawCollateral(
contract IBalanceSheetV2 balanceSheet,
contract IErc20 collateral,
uint256 withdrawAmount
) external

Withdraws collateral from the vault.

Parameters

NameTypeDescription
balanceSheetcontract IBalanceSheetV2The address of the BalanceSheet contract.
collateralcontract IErc20The address of the collateral contract.
withdrawAmountuint256The amount of collateral to withdraw.

wrapEthAndDepositCollateral

function wrapEthAndDepositCollateral(
contract WethInterface weth,
contract IBalanceSheetV2 balanceSheet
) external

Wraps ETH into WETH and makes a collateral deposit in the BalanceSheet contract.

This is a payable function so it can receive ETH transfers.

Parameters

NameTypeDescription
wethcontract WethInterfaceThe address of the WETH contract.
balanceSheetcontract IBalanceSheetV2The address of the BalanceSheet contract.

wrapEthAndDepositAndBorrowHTokenAndSellHToken

function wrapEthAndDepositAndBorrowHTokenAndSellHToken(
contract WethInterface weth,
contract IBalanceSheetV2 balanceSheet,
contract IHifiPool hifiPool,
uint256 borrowAmount,
uint256 minUnderlyingOut
) external

Wraps ETH into WETH, deposits collateral into the vault, borrows hTokens and sells them.

This is a payable function so it can receive ETH transfers.

Parameters

NameTypeDescription
wethcontract WethInterfaceThe address of the WETH contract.
balanceSheetcontract IBalanceSheetV2The address of the BalanceSheet contract.
hifiPoolcontract IHifiPoolThe address of the HifiPool contract.
borrowAmountuint256The exact amount of hTokens to borrow and sell for underlying.
minUnderlyingOutuint256The minimum amount of underlying that the user is willing to accept.

Events

BorrowHTokenAndBuyUnderlying

event BorrowHTokenAndBuyUnderlying(
address borrower,
uint256 borrowAmount,
uint256 underlyingAmount
)

Emitted when hTokens are borrowed and used to buy underlying.

Parameters

NameTypeDescription
borroweraddressThe address of the borrower.
borrowAmountuint256The amount of hTokens borrowed and sold.
underlyingAmountuint256The amount of underlying bought.

BorrowHTokenAndSellHToken

event BorrowHTokenAndSellHToken(
address borrower,
uint256 borrowAmount,
uint256 underlyingAmount
)

Emitted when hTokens are borrowed and sold for underlying.

Parameters

NameTypeDescription
borroweraddressThe address of the borrower.
borrowAmountuint256The amount of hTokens borrowed and sold.
underlyingAmountuint256The amount of underlying bought.

Custom Errors

HifiProxyTarget__AddLiquidityHTokenSlippage

error HifiProxyTarget__AddLiquidityHTokenSlippage(uint256 expectedHTokenRequired, uint256 actualHTokenRequired)

Emitted when the hToken slippage is higher than what the user is willing to tolerate.

HifiProxyTarget__AddLiquidityUnderlyingSlippage

error HifiProxyTarget__AddLiquidityUnderlyingSlippage(uint256 expectedUnderlyingRequired, uint256 actualUnderlyingRequired)

Emitted when the underlying slippage is higher than what the user is willing to tolerate.

HifiProxyTarget__TradeSlippage

error HifiProxyTarget__TradeSlippage(uint256 expectedAmount, uint256 actualAmount)

Emitted when the slippage is higher than what the user is willing to tolerate.