Savings Account
Savings account enables users to earn yield on their deposits from within the Sublime ecosystem. Users can tap into yield strategies - starting off with Aave, Compound and Yearn, allowing them to switch between protocols, as well as immediately supply capital to borrow pools or for credit lines.
Savings account interface is inspired from ERC20 and all the functions are designed to simulate ERC20 functionalities.
Users can deposit any** ERC20 tokens and invest them into strategies
function depositTo(
uint256 amount,
address asset,
address strategy,
address to
) returns (uint256)
APPROVE
: Approve the tokens for the strategy if strategy != address(0) otherwise approve to savingsAccountamount
: The number of tokens depositedasset
: The address of the asset deposited. address(0) for Etherstrategy
: Strategy into which the tokens should be deposited to. If tokens shouldn't be deposited to any strategy but held in the savings account specify as address(0)to
: Address to which deposit is madeRETURN
: Shares received after deposit to strategy
Note: (**) Inflationary/deflationary tokens are not supported.
Users can transfer their tokens to others using
function transfer(
uint256 _amount,
address _token,
address _strategy,
address _to
) returns (uint256)
_amount
: Number of tokens to transfer_token
: The token that is to be transferred. address(0) for Ether_strategy
: The strategy token is deposited in. If tokens which are held in the savings account are to be use, specify address(0)_to
: The address to which token is to be transferred
Users can withdraw the tokens they hold using
function withdraw(
uint256 _amount,
address _token,
address _strategy,
address payable _to,
bool _withdrawShares
) returns (uint256)
_amount
: Number of tokens to withdraw_token
: The token that is to be withdrawn_strategy
: The strategy tokens are held in_to
: The address to which withdrawn tokens should be sent to_withdrawShares
: Flag that specifies if the shares have to be directly withdraw and sent to user or they are converted back to the tokens
RETURN
: The number of tokens withdrawnUsers can approve tokens in savings account to be used by some other address
function approve(
uint256 _amount,
address _token,
address _to
)
_amount
: Allowance approved_token
: The token to be approved_to
: Address to which approval is done
Note: Approve like any other ERC20 suffers from the race condition when a new approval is made. So consider using Increase/Decrease allowance.
Users can increase the allowance of a token to a user using
function increaseAllowance(
uint256 _amount,
address _token,
address _to
)
_amount
: Amount by which allowance is increased_token
: The token to be approved_to
: Address to which approval is done
Users can decrease the allowance of a token to a user using
function decreaseAllowance(
uint256 _amount,
address _token,
address _to
)
_amount
: Amount by which allowance is decreased_token
: The token to be approved_to
: Address to which approval is done
Users can transfer tokens from the allowance they have from someone using
function transferFrom(
uint256 _amount,
address _token,
address _strategy,
address _from,
address _to
)
APPROVE
: There should be allowance in savingsAccount from_from
to_to
for the_token
for atleast_amount
_amount
: Number of tokens to transfer_token
: The token that is transferred_strategy
: The strategy from which tokens is to be transferred_from
: The address which provided the allowance_to
: The address to which transfer is to be made
Users can withdraw tokens from the allowance they have from someone using
function withdrawFrom(
uint256 _amount,
address _token,
address _strategy,
address _from,
address payable _to,
bool _withdrawShares
) returns (uint256 amountReceived)
APPROVE
: There should be allowance from _from
to _to
for the _token
for atleast _amount
_amount
: Number of tokens to transfer_token
: The token that is withdrawn_strategy
: The strategy from which tokens is to be transferred_from
: The address which provided the allowance_to
: The address to which withdrawal is to be made_withdrawShares
: Flag that specifies if the shares have to be directly withdraw and sent to user or they are converted back to the tokens
RETURN
: The number of tokens withdrawnUsers can use this function to withdraw an asset from all strategies
function withdrawAll(address _token) returns (uint256)
_token
: Token that is to be withdrawn
RETURN
: Total tokens received after withdrawalNote: This function can cross gas limit to run if the number of strategies invested are large. Please use this function with care considering above.
Users can switch tokens from one strategy to another using
function switchStrategy(
uint256 _amount,
address _token,
address _currentStrategy,
address _newStrategy
)
_amount
: Number of tokens to switch to_newStrategy
_token
: Token to the switched strategies_currentStrategy
: Strategy in which the tokens are invested in_newStrategy
: Strategy to which tokens are to be switched
Number of tokens of a particular asset, a user holds in savingsAccount can be queried using
function getTotalTokens(address _user, address _token)
external override returns (uint256 _totalTokens) {
_user
: Address for which asset is queried_token
: Token for which asset is queried
RETURN
: Number of tokens of the asset
that user
holdsLast modified 1yr ago