DSProxy Target

Introduction

The Hifi protocol is architected it in such a way that every function does one job only, and does it well. This is called separation of concerns - which makes it easier to reason about how the protocol behaves, and it generally gives better security guarantees.

Modularization comes with a cost though. In order to provide a good user experience in our web interface, we ought to batch multiple contract calls into one. This is where DSProxy comes into play - a smart contract wallet designed to solve the issue.

For brevity, we won't expound on the technical properties of DSProxy here. Refer to this post on StackExchange for a detailed explanation. The main takeaways are:

  1. DSProxy is a smart contract wallet

  2. There is a so-called "target contract" that contains composite calls, to which the DSProxy makes delegate calls.

Is it the target contract that we will document in the sections below.

Gas Costs

Gas usage is not deterministic due to requisite calls to third-party Erc20 tokens and special cases whereby the storage properties get set to zero. We provide the table below for guidance only:

Action

Typical Gas Cost

Borrow

<170K

Borrow And Sell FyTokens

<400K

Deposit Collateral

<130K

Deposit And Lock Collateral

<160K

Deposit And Lock Collateral And Borrow

<230K

Deposit And Lock Collateral And Borrow And Sell FyTokens

<420K

Free Collateral

<110K

Free And Withdraw Collateral

<170K

Lock Collateral

<40K

Lock Collateral And Borrow

<330K

Open Vault

<60K

Redeem FyTokens

<110K

Repay Borrow

<100K

Sell Underlying And Repay Borrow

<330K

Supply Underlying

<180K

Supply Underlying And Repay Borrow

<180K

Withdraw Collateral

<80K

Wrap Eth And Deposit Collateral

<90K

Wrap Eth And Deposit And Lock Collateral

<120K

Wrap Eth And Deposit And Lock Collateral And Borrow

<270K

Storage Properties

Exchange Proxy Address

The contract that enables trading on the Balancer Exchange.

address public constant EXCHANGE_PROXY_ADDRESS = 0x3E66B66Fd1d0b02fDa6C811Da9E0547970DB2f21;

Weth Address

The contract that enables wrapping ETH into ERC-20 form.

address public constant WETH_ADDRESS = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;

Non-Constant Functions

Borrow

Borrows fyTokens.

function borrow(FyTokenInterface fyToken, uint256 borrowAmount) external
  • fyToken: The address of the FyToken contract.

  • borrowAmount: The amount of fyTokens to borrow.

Borrow And Sell FyTokens

Borrows fyTokens and sells them on Balancer in exchange for underlying. Emits a "BorrowAndSellFyTokens" event.

function borrowAndSellFyTokens(FyTokenInterface fyToken, uint256 borrowAmount, uint256 underlyingAmount) public payable
  • fyToken: The address of the FyToken contract.

  • borrowAmount: The amount of fyTokens to borrow.

  • underlyingAmount: The amount of underlying to sell fyTokens for.

Deposit Collateral

Deposits collateral into the "BalanceSheet" contract.

function depositCollateral(BalanceSheetInterface balanceSheet, FyTokenInterface fyToken, uint256 collateralAmount) public
  • balanceSheet: The address of the BalanceSheet contract.

  • fyToken: The address of the FyToken contract.

  • collateralAmount: The amount of collateral to deposit.

Requirements:

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

Deposit And Lock Collateral

Deposits and locks collateral into the BalanceSheet contract.

function depositAndLockCollateral(BalanceSheetInterface balanceSheet, FyTokenInterface fyToken, uint256 collateralAmount) public
  • balanceSheet: The address of the BalanceSheet contract.

  • fyToken: The address of the FyToken contract.

  • collateralAmount: The amount of collateral to deposit and lock.

Requirements:

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

Deposit And Lock Collateral and Borrow And Sell FyTokens

Deposits and locks collateral into the vault via the BalanceSheet contract, draws debt via the FyToken contract and sells it on Balancer in exchange for underlying.

function depositAndLockCollateralAndBorrow(BalanceSheetInterface balanceSheet, FyTokenInterface fyToken, uint256 collateralAmount, uint256 borrowAmount, uint256 underlyingAmount) external payable
  • balanceSheet: The address of the BalanceSheet contract.

  • fyToken: The address of the FyToken contract.

  • collateralAmount: The amount of collateral to deposit and lock.

  • borrowAmount: The amount of fyTokens to borrow.

  • underlyingAmountThe amount of underlying to sell fyTokens for.

Requirements:

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

Free Collateral

Frees collateral from the vault in the BalanceSheet contract.

function freeCollateral(BalanceSheetInterface balanceSheet, FyTokenInterface fyToken, uint256 collateralAmount) external
  • balanceSheet: The address of the BalanceSheet contract.

  • fyToken: The address of the FyToken contract.

  • collateralAmount: The amount of collateral to free.

Free And Withdraw Collateral

Frees collateral from the vault and withdraws it from the BalanceSheet contract.

function freeAndWithdrawCollateral(BalanceSheetInterface balanceSheet, FyTokenInterface fyToken, uint256 collateralAmount) external
  • balanceSheet: The address of the BalanceSheet contract.

  • fyToken: The address of the FyToken contract.

  • collateralAmount: The amount of collateral to free and withdraw.

Lock Collateral

Locks collateral in the vault in the BalanceSheet contract.

function lockCollateral(BalanceSheetInterface balanceSheet, FyTokenInterface fyToken, uint256 collateralAmount) external
  • balanceSheet: The address of the BalanceSheet contract.

  • fyToken: The address of the FyToken contract.

  • collateralAmount: The amount of collateral to lock.

Lock Collateral And Borrow

Locks collateral into the vault in the BalanceSheet contract and draws debt via the FyToken contract.

function lockCollateralAndBorrow(BalanceSheetInterface balanceSheet, FyTokenInterface fyToken, uint256 collateralAmount, uint256 borrowAmount, uint256 underlyingAmount) external
  • balanceSheet: The address of the BalanceSheet contract.

  • fyToken: The address of the FyToken contract.

  • collateralAmount: The amount of collateral to lock.

  • borrowAmount: The amount of fyTokens to borrow.

  • underlyingAmount: The amount of underlying to sell fyTokens for.

Open Vault

Open the vaults in the BalanceSheet contract for the given fyToken.

function openVault(BalanceSheetInterface balanceSheet, FyTokenInterface fyToken) external
  • balanceSheet: The address of the BalanceSheet contract.

  • fyToken: The address of the FyToken contract.

Redeem FyTokens

Redeems fyTokens in exchange for underlying tokens.

function redeemFyTokens(FyTokenInterface fyToken, uint256 fyTokenAmount) public
  • fyToken: The address of the FyToken contract.

  • fyTokenAmount: The amount of fyTokens to redeem.

Requirements:

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

Repay Borrow

Repays the fyToken borrow.

function repayBorrow(FyTokenInterface fyToken, uint256 repayAmount) public
  • fyToken: The address of the FyToken contract.

  • repayAmount: The amount of fyTokens to repay.

Requirements:

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

Sell Underlying and Repay Borrow

Market sells underlying and repays the borrows via the FyToken contract.

function sellUnderlyingAndRepayBorrow(FyTokenInterface fyToken, uint256 underlyingAmount, uint256 repayAmount) external
  • fyToken: The address of the FyToken contract.

  • underlyingAmount: The amount of underlying to sell.

  • repayAmount: The amount of fyTokens to repay.

Requirements:

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

Supply Underlying

function supplyUnderlying(FyTokenInterface fyToken, uint256 underlyingAmount) public
  • fyToken: The address of the FyToken contract.

  • underlyingAmount: The amount of underlying to supply.

Supply Underlying and Repay Borrow

Supplies the underlying to the RedemptionPool contract, mints fyTokens and repays the borrow.

function supplyUnderlyingAndRepayBorrow(FyTokenInterface fyToken, uint256 underlyingAmount) external
  • fyToken: The address of the FyToken contract.

  • underlyingAmount: The amount of underlying to supply.

Requirements:

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

Withdraw Collateral

Withdraws collateral from the vault in the BalanceSheet contract.

function withdrawCollateral(BalanceSheetInterface balanceSheet, FyTokenInterface fyToken, uint256 collateralAmount) public
  • balanceSheet: The address of the BalanceSheet contract.

  • fyToken: The address of the FyToken contract.

  • collateralAmount: The amount of collateral to withdraw.

Wrap Eth And Deposit Collateral

Wraps ETH into WETH and deposits into the BalanceSheet contract.

function wrapEthAndDepositCollateral(BalanceSheetInterface balanceSheet, FyTokenInterface fyToken, uint256 collateralAmount) public payable
  • balanceSheet: The address of the BalanceSheet contract.

  • fyToken: The address of the FyToken contract.

  • collateralAmount: The amount of collateral to deposit.

Wrap Eth And Deposit And Lock Collateral

Wraps ETH into WETH, deposits and locks collateral into the BalanceSheet contract and draws debt via the FyToken contract.

function wrapEthAndDepositAndLockCollateral(BalanceSheetInterface balanceSheet, FyTokenInterface fyToken, uint256 collateralAmount) public payable
  • balanceSheet: The address of the BalanceSheet contract.

  • fyToken: The address of the FyToken contract.

  • collateralAmount: The amount of collateral to deposit and lock.

Wrap Eth And Deposit And Lock Collateral and Borrow

Wraps ETH into WETH, deposits and locks collateral into the vault in the BalanceSheet contract and draws debt via the FyToken contract.

function wrapEthAndDepositAndLockCollateralAndBorrow(BalanceSheetInterface balanceSheet, FyTokenInterface fyToken, uint256 collateralAmount, uint256 borrowAmount, uint256 underlyingAmount) external payable
  • balanceSheet: The address of the BalanceSheet contract.

  • fyToken: The address of the FyToken contract.

  • collateralAmount: The amount of collateral to deposit and lock.

  • borrowAmount: The amount of fyTokens to borrow.

  • underlyingAmount: The amount of underlying to sell fyTokens for.