mAssets (e.g. mUSD) may be deposited into the relevant SAVE contract to earn a yield. Once deposited, mAsset is held on the SAVE contract but may be redeemed at any time. Balances are represented internally through
credits, but these do not have an ERC20 token attached.
To deposit and redeem, interact with the
SAVE contract. You can discover the deployed addresses for the SAVE contract here. A deposit flow would look like:
SAVE address to spend the input mAsset
depositSavings to deposit the mAsset
check balance in mAsset terms using
You may wish to use the ISavingsContract Interface in your contracts.
Estimated gas cost
/*** @dev Deposit mAsset into the SAVE Conract to earn yield* @param _amount Units of underlying bAsset (e.g mUSD) to deposit* @return creditsIssued Units of credits issued internally*/function depositSavings(uint256 _amount)external returns (uint256 creditsIssued);
Note - The redeem call takes the credit amount. You should use the getSaveRedeemInput function on the mStable Helper to get the required credits.
Estimated gas cost
/*** @dev Redeem mAsset from the SAVE contract* @param _credits Amount of credits to redeem* @return massetReturned Units of underlying mAsset paid out*/function redeem(uint256 _amount)external returns (uint256 massetReturned);
The mStable Helper contract provides the
getSaveBalance function to get a users SAVE balance in mAsset terms. Additionally the mStable Helper contract provides the
getSaveRedeemInput function to get the amount of credits to withdraw for a certain amount of mAsset. The deployed contract addresses for the mStable Helper contract can be discovered here.
See Deployed addresses for the current address of the
/*** @dev Gets the users savings balance in mAsset terms* @param _save SAVE contract address* @param _user Address of the user* @return balance in mAsset units*/function getSaveBalance(ISavingsContract _save,address _user)externalviewreturns (uint256);
/*** @dev Returns the 'credit' units required to withdraw a certain* amount of Masset from the SAVE contract* @param _save SAVE contract address* @param _amount Amount of mAsset to redeem from SAVE* @return input for the redeem function (ie. credit units to redeem)*/function getSaveRedeemInput(ISavingsContract _save,uint256 _amount)externalviewreturns (uint256);