2022-03-22 15:24:40 +00:00
|
|
|
//SPDX-License-Identifier: MIT
|
2021-12-30 10:42:44 +00:00
|
|
|
pragma solidity ^0.7.6;
|
|
|
|
|
2022-01-02 08:28:40 +00:00
|
|
|
import { DSMath } from "../../common/math.sol";
|
|
|
|
import { Basic } from "../../common/basic.sol";
|
2021-12-30 10:42:44 +00:00
|
|
|
|
2022-01-24 15:55:44 +00:00
|
|
|
import { TokenInterface } from "../../common/interfaces.sol";
|
|
|
|
import { ISavingsContractV2, IBoostedSavingsVault } from "./interface.sol";
|
|
|
|
|
2021-12-30 10:42:44 +00:00
|
|
|
abstract contract Helpers is DSMath, Basic {
|
|
|
|
address internal constant mUsdToken =
|
|
|
|
0xe2f2a5C287993345a840Db3B0845fbC70f5935a5;
|
|
|
|
address internal constant imUsdToken =
|
|
|
|
0x30647a72Dc82d7Fbb1123EA74716aB8A317Eac19;
|
|
|
|
address internal constant imUsdVault =
|
|
|
|
0x78BefCa7de27d07DC6e71da295Cc2946681A6c7B;
|
2022-01-24 15:55:44 +00:00
|
|
|
|
|
|
|
/***************************************
|
|
|
|
Internal
|
|
|
|
****************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dev Deposit to Save from any asset
|
|
|
|
* @notice Called internally from deposit functions
|
|
|
|
* @param _token Address of token to deposit
|
|
|
|
* @param _amount Amount of token to deposit
|
|
|
|
* @param _path Path to mint mUSD (only needed for Feeder Pool)
|
2022-01-27 12:34:47 +00:00
|
|
|
* @param _stake stake token in Vault?
|
2022-01-24 15:55:44 +00:00
|
|
|
* @return _eventName Event name
|
|
|
|
* @return _eventParam Event parameters
|
|
|
|
*/
|
|
|
|
|
|
|
|
function _deposit(
|
|
|
|
address _token,
|
|
|
|
uint256 _amount,
|
2022-01-27 12:34:47 +00:00
|
|
|
address _path,
|
|
|
|
bool _stake
|
2022-01-24 15:55:44 +00:00
|
|
|
) internal returns (string memory _eventName, bytes memory _eventParam) {
|
|
|
|
// 1. Deposit mUSD to Save
|
|
|
|
approve(TokenInterface(mUsdToken), imUsdToken, _amount);
|
|
|
|
uint256 credits = ISavingsContractV2(imUsdToken).depositSavings(
|
|
|
|
_amount
|
|
|
|
);
|
|
|
|
|
2022-01-27 12:34:47 +00:00
|
|
|
if (_stake) {
|
|
|
|
// 2. Stake imUSD to Vault
|
|
|
|
approve(TokenInterface(imUsdToken), imUsdVault, credits);
|
|
|
|
IBoostedSavingsVault(imUsdVault).stake(credits);
|
|
|
|
}
|
2022-01-24 15:55:44 +00:00
|
|
|
// 3. Log Events
|
2022-01-27 12:34:47 +00:00
|
|
|
_eventName = "LogDeposit(address,uint256,address,bool)";
|
|
|
|
_eventParam = abi.encode(_token, _amount, _path, _stake);
|
2022-01-24 15:55:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dev Withdraws from Save
|
|
|
|
* @notice Withdraws token supported by mStable from Save
|
|
|
|
* @param _credits Credits to withdraw
|
2022-01-27 12:34:47 +00:00
|
|
|
* @param _unstake unstake from Vault?
|
2022-01-24 15:55:44 +00:00
|
|
|
* @return amountWithdrawn Amount withdrawn in mUSD
|
|
|
|
*/
|
|
|
|
|
2022-01-27 12:34:47 +00:00
|
|
|
function _withdraw(uint256 _credits, bool _unstake)
|
2022-01-24 15:55:44 +00:00
|
|
|
internal
|
|
|
|
returns (uint256 amountWithdrawn)
|
|
|
|
{
|
2022-01-27 12:34:47 +00:00
|
|
|
uint256 credits;
|
2022-01-24 15:55:44 +00:00
|
|
|
// 1. Withdraw from Vault
|
2022-01-27 12:34:47 +00:00
|
|
|
if (_unstake) {
|
|
|
|
credits = _credits == uint256(-1)
|
|
|
|
? TokenInterface(imUsdVault).balanceOf(address(this))
|
|
|
|
: _credits;
|
|
|
|
IBoostedSavingsVault(imUsdVault).withdraw(credits);
|
|
|
|
}
|
2022-01-24 15:55:44 +00:00
|
|
|
|
|
|
|
// 2. Withdraw from Save
|
2022-01-27 12:34:47 +00:00
|
|
|
credits = _credits == uint256(-1)
|
|
|
|
? TokenInterface(imUsdToken).balanceOf(address(this))
|
|
|
|
: _credits;
|
2022-01-24 15:55:44 +00:00
|
|
|
approve(TokenInterface(imUsdToken), imUsdVault, _credits);
|
2022-01-27 12:34:47 +00:00
|
|
|
amountWithdrawn = ISavingsContractV2(imUsdToken).redeemCredits(credits);
|
2022-01-24 15:55:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dev Returns the reward tokens
|
|
|
|
* @notice Gets the reward tokens from the vault contract
|
|
|
|
* @return rewardToken Address of reward token
|
|
|
|
*/
|
|
|
|
|
|
|
|
function _getRewardTokens() internal view returns (address rewardToken) {
|
|
|
|
rewardToken = address(
|
|
|
|
IBoostedSavingsVault(imUsdVault).getRewardToken()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dev Returns the internal balances of the rewardToken and platformToken
|
|
|
|
* @notice Gets current balances of rewardToken and platformToken, used for calculating rewards accrued
|
|
|
|
* @param _rewardToken Address of reward token
|
|
|
|
* @return a Amount of reward token
|
|
|
|
*/
|
|
|
|
|
|
|
|
function _getRewardInternalBal(address _rewardToken)
|
|
|
|
internal
|
|
|
|
view
|
|
|
|
returns (uint256 a)
|
|
|
|
{
|
|
|
|
a = TokenInterface(_rewardToken).balanceOf(address(this));
|
|
|
|
}
|
2021-12-30 10:42:44 +00:00
|
|
|
}
|