Search…
Savings Account

Purpose

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.

Functionality

Deposit Assets

Users can deposit any** ERC20 tokens and invest them into strategies

Function

function depositTo(
uint256 amount,
address asset,
address strategy,
address to
) returns (uint256)

Approvals

Restrictions

Arguments

  • APPROVE: Approve the tokens for the strategy if strategy != address(0) otherwise approve to savingsAccount
  • amount: The number of tokens deposited
  • asset: The address of the asset deposited. address(0) for Ether
  • strategy: 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 made
  • RETURN: Shares received after deposit to strategy
Note: (**) Inflationary/deflationary tokens are not supported.

Transfer

Users can transfer their tokens to others using

Function

function transfer(
uint256 _amount,
address _token,
address _strategy,
address _to
) returns (uint256)

Arguments

  • _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

Withdraw

Users can withdraw the tokens they hold using
function withdraw(
uint256 _amount,
address _token,
address _strategy,
address payable _to,
bool _withdrawShares
) returns (uint256)

Arguments

  • _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 withdrawn

Approve

Users 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.

Increase 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

Decrease Allowance

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

Transfer From

Users can transfer tokens from the allowance they have from someone using

Function

function transferFrom(
uint256 _amount,
address _token,
address _strategy,
address _from,
address _to
)

Restrictions

  • APPROVE: There should be allowance in savingsAccount from _from to _to for the _token for atleast _amount

Arguments

  • _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

Withdraw From

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)

Restrictions

APPROVE: There should be allowance from _from to _to for the _token for atleast _amount

Arguments

  • _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 withdrawn

Withdraw All

Users can use this function to withdraw an asset from all strategies

Function

function withdrawAll(address _token) returns (uint256)

Arguments

  • _token: Token that is to be withdrawn
RETURN: Total tokens received after withdrawal
Note: This function can cross gas limit to run if the number of strategies invested are large. Please use this function with care considering above.

Switch Strategy

Users can switch tokens from one strategy to another using

Function

function switchStrategy(
uint256 _amount,
address _token,
address _currentStrategy,
address _newStrategy
)

Arguments

  • _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

getTotalTokens

Number of tokens of a particular asset, a user holds in savingsAccount can be queried using

Function

function getTotalTokens(address _user, address _token)
external override returns (uint256 _totalTokens) {

Arguments

  • _user: Address for which asset is queried
  • _token: Token for which asset is queried
RETURN: Number of tokens of the asset that user holds