Vault Contract
The FlowDex Vault Contract is the core user-facing implementation of the FlowDex protocol. It manages user deposits, mints FDX tokens as proof of receipt, and facilitates withdrawals. The contract follows the ERC-20 standard, ensuring that FDX tokens are fungible and transferable.
The primary function of the Vault Contract is to direct deposited funds to the relevant staking strategies (e.g., Liquid Staking, Delta Neutral Staking, Leverage Lending). The separation of the Vault and Strategy Contracts ensures that risks in the strategy are isolated from user deposits.
View Functions
1. want()
Returns the address of the underlying token (e.g., ETH, USDT) used in both the FlowDex Vault and Strategy Contracts.
2. balance()
Returns the total amount of the underlying token stored in the Vault, Strategy, and yield sources.
3. available()
Returns the amount of the underlying token stored in the Vault alone.
4. totalSupply()
Returns the total amount of FDX tokens minted. FDX tokens are always displayed as 18-decimal tokens.
5. getPricePerFullShare()
Returns the current price per share of the Vault (i.e., per FDX token) denominated in the underlying token.
Formula: Price per Full Share = balance() / totalSupply()
6. strategy()
Returns the address of the current Strategy Contract used by the Vault to generate yield.
Write Functions
1. deposit(uint _amount)
Executes a transfer of a specified _amount
of the underlying token from the depositor to the Vault and mints a proportional quantity of FDX tokens.
Helper Function:
depositAll()
deposits the entire balance of the underlying token in the user's wallet.
2. withdraw(uint256 _shares)
Burns a specified _shares
of FDX tokens and transfers a proportional quantity of the underlying token to the depositor.
Helper Function:
withdrawAll()
withdraws the entire balance of FDX tokens in the user's wallet.
3. earn()
Transfers the available underlying token from the Vault to the Strategy Contract and triggers the strategy's deposit()
function to deploy funds and begin earning yield.
4. proposeStrat(address _implementation)
Writes the address of an alternate Strategy Contract to the Vault's memory in preparation for an upgrade.
5. upgradeStrat()
Replaces the current Strategy Contract with the alternate strategy specified by proposeStrat()
.
FlowDexVaultV1.sol
The current release of the FlowDex Vault Contract is FlowDexVaultV1.sol, which includes the following improvements:
Upgradeability: Introduced through proxy patterns to facilitate updates without redeployment.
Strategy Interface: Updated to support upgradeable strategies.
Gas Optimization: Removed reliance on the SafeMath library, as its features are now native in Solidity v0.8.
Last updated