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.
1
address public constant EXCHANGE_PROXY_ADDRESS = 0x3E66B66Fd1d0b02fDa6C811Da9E0547970DB2f21;
Copied!

Weth Address

The contract that enables wrapping ETH into ERC-20 form.
1
address public constant WETH_ADDRESS = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
Copied!

Non-Constant Functions

Borrow

Borrows fyTokens.
1
function borrow(FyTokenInterface fyToken, uint256 borrowAmount) external
Copied!
    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.
1
function borrowAndSellFyTokens(FyTokenInterface fyToken, uint256 borrowAmount, uint256 underlyingAmount) public payable
Copied!
    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.
1
function depositCollateral(BalanceSheetInterface balanceSheet, FyTokenInterface fyToken, uint256 collateralAmount) public
Copied!
    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.
1
function depositAndLockCollateral(BalanceSheetInterface balanceSheet, FyTokenInterface fyToken, uint256 collateralAmount) public
Copied!
    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.
1
function depositAndLockCollateralAndBorrow(BalanceSheetInterface balanceSheet, FyTokenInterface fyToken, uint256 collateralAmount, uint256 borrowAmount, uint256 underlyingAmount) external payable
Copied!
    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.
1
function freeCollateral(BalanceSheetInterface balanceSheet, FyTokenInterface fyToken, uint256 collateralAmount) external
Copied!
    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.
1
function freeAndWithdrawCollateral(BalanceSheetInterface balanceSheet, FyTokenInterface fyToken, uint256 collateralAmount) external
Copied!
    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.
1
function lockCollateral(BalanceSheetInterface balanceSheet, FyTokenInterface fyToken, uint256 collateralAmount) external
Copied!
    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.
1
function lockCollateralAndBorrow(BalanceSheetInterface balanceSheet, FyTokenInterface fyToken, uint256 collateralAmount, uint256 borrowAmount, uint256 underlyingAmount) external
Copied!
    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.
1
function openVault(BalanceSheetInterface balanceSheet, FyTokenInterface fyToken) external
Copied!
    balanceSheet: The address of the BalanceSheet contract.
    fyToken: The address of the FyToken contract.

Redeem FyTokens

Redeems fyTokens in exchange for underlying tokens.
1
function redeemFyTokens(FyTokenInterface fyToken, uint256 fyTokenAmount) public
Copied!
    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.
1
function repayBorrow(FyTokenInterface fyToken, uint256 repayAmount) public
Copied!
    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.
1
function sellUnderlyingAndRepayBorrow(FyTokenInterface fyToken, uint256 underlyingAmount, uint256 repayAmount) external
Copied!
    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

1
function supplyUnderlying(FyTokenInterface fyToken, uint256 underlyingAmount) public
Copied!
    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.
1
function supplyUnderlyingAndRepayBorrow(FyTokenInterface fyToken, uint256 underlyingAmount) external
Copied!
    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.
1
function withdrawCollateral(BalanceSheetInterface balanceSheet, FyTokenInterface fyToken, uint256 collateralAmount) public
Copied!
    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.
1
function wrapEthAndDepositCollateral(BalanceSheetInterface balanceSheet, FyTokenInterface fyToken, uint256 collateralAmount) public payable
Copied!
    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.
1
function wrapEthAndDepositAndLockCollateral(BalanceSheetInterface balanceSheet, FyTokenInterface fyToken, uint256 collateralAmount) public payable
Copied!
    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.
1
function wrapEthAndDepositAndLockCollateralAndBorrow(BalanceSheetInterface balanceSheet, FyTokenInterface fyToken, uint256 collateralAmount, uint256 borrowAmount, uint256 underlyingAmount) external payable
Copied!
    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.
Last modified 9mo ago