-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge the develop branch to the master branch, preparation to v1.1.0-rc0
This update for the `master` branch contains the following set of changes: * [Improvement] Add support on interest earning using Compound (#47) * [Other] Bump package and contracts interfaces version prior to 1.1.0-rc0 (#49)
- Loading branch information
Showing
29 changed files
with
1,036 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,34 @@ | ||
const Web3 = require('web3') | ||
|
||
module.exports = { | ||
mocha: { | ||
timeout: 30000 | ||
}, | ||
forceBackupServer: true, | ||
providerOptions: { | ||
port: 8545, | ||
seed: 'TestRPC is awesome!' | ||
}, | ||
onServerReady: async (config) => { | ||
const web3 = new Web3(config.provider) | ||
const abi = [{ | ||
inputs: [{ name: "", type: "address"}], | ||
outputs: [{ name: "", type: "uint256" }], | ||
name: "balanceOf", | ||
stateMutability: "view", | ||
type: "function" | ||
}] | ||
const cDai = new web3.eth.Contract(abi, '0x615cba17EE82De39162BB87dBA9BcfD6E8BcF298') | ||
const faucet = (await web3.eth.getAccounts())[6] | ||
while (true) { | ||
try { | ||
if (await cDai.methods.balanceOf(faucet).call() !== '0') { | ||
break | ||
} | ||
} catch (e) { | ||
await new Promise(res => setTimeout(res, 1000)) | ||
} | ||
} | ||
}, | ||
skipFiles: ['mocks'] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
pragma solidity 0.7.5; | ||
|
||
import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
|
||
interface ICToken is IERC20 { | ||
function underlying() external returns (address); | ||
|
||
function mint(uint256 mintAmount) external returns (uint256); | ||
|
||
function redeem(uint256 redeemAmount) external returns (uint256); | ||
|
||
function redeemUnderlying(uint256 redeemAmount) external returns (uint256); | ||
|
||
function balanceOfUnderlying(address account) external returns (uint256); | ||
|
||
function borrow(uint256 borrowAmount) external returns (uint256); | ||
|
||
function repayBorrow(uint256 borrowAmount) external returns (uint256); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
pragma solidity 0.7.5; | ||
|
||
interface IComptroller { | ||
function claimComp( | ||
address[] calldata holders, | ||
address[] calldata cTokens, | ||
bool borrowers, | ||
bool suppliers | ||
) external; | ||
|
||
function compAccrued(address holder) external view returns (uint256); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pragma solidity 0.7.5; | ||
|
||
interface IHarnessComptroller { | ||
function fastForward(uint256 blocks) external; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
pragma solidity 0.7.5; | ||
|
||
import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
|
||
interface IInterestImplementation { | ||
function isInterestSupported(address _token) external view returns (bool); | ||
|
||
function invest(address _token, uint256 _amount) external; | ||
|
||
function withdraw(address _token, uint256 _amount) external; | ||
|
||
function investedAmount(address _token) external view returns (uint256); | ||
|
||
function claimCompAndPay(address[] calldata _markets) external; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pragma solidity 0.7.5; | ||
|
||
interface IInterestReceiver { | ||
function onInterestReceived(address _token) external; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pragma solidity 0.7.5; | ||
|
||
interface IOwnable { | ||
function owner() external view returns (address); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
pragma solidity 0.7.5; | ||
|
||
import "../upgradeable_contracts/modules/interest/CompoundInterestERC20.sol"; | ||
|
||
contract CompoundInterestERC20Mock is CompoundInterestERC20 { | ||
constructor( | ||
address _omnibridge, | ||
address _owner, | ||
uint256 _minCompPaid, | ||
address _compReceiver | ||
) CompoundInterestERC20(_omnibridge, _owner, _minCompPaid, _compReceiver) {} | ||
|
||
function comptroller() public pure override returns (IComptroller) { | ||
return IComptroller(0x85e855b22F01BdD33eE194490c7eB16b7EdaC019); | ||
} | ||
|
||
function compToken() public pure override returns (IERC20) { | ||
return IERC20(0x6f51036Ec66B08cBFdb7Bd7Fb7F40b184482d724); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
contracts/upgradeable_contracts/components/common/InterestConnector.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
pragma solidity 0.7.5; | ||
|
||
import "@openzeppelin/contracts/utils/Address.sol"; | ||
import "@openzeppelin/contracts/math/SafeMath.sol"; | ||
import "../../Ownable.sol"; | ||
import "../../../interfaces/IInterestReceiver.sol"; | ||
import "../../../interfaces/IInterestImplementation.sol"; | ||
import "../native/MediatorBalanceStorage.sol"; | ||
|
||
/** | ||
* @title InterestConnector | ||
* @dev This contract gives an abstract way of receiving interest on locked tokens. | ||
*/ | ||
contract InterestConnector is Ownable, MediatorBalanceStorage { | ||
using SafeMath for uint256; | ||
|
||
/** | ||
* @dev Tells address of the interest earning implementation for the specific token contract. | ||
* If interest earning is disabled, will return 0x00..00. | ||
* Can be an address of the deployed CompoundInterestERC20 contract. | ||
* @param _token address of the locked token contract. | ||
* @return address of the implementation contract. | ||
*/ | ||
function interestImplementation(address _token) public view returns (IInterestImplementation) { | ||
return IInterestImplementation(addressStorage[keccak256(abi.encodePacked("interestImpl", _token))]); | ||
} | ||
|
||
/** | ||
* @dev Initializes interest receiving functionality for the particular locked token. | ||
* Only owner can call this method. | ||
* @param _token address of the token for interest earning. | ||
* @param _impl address of the interest earning implementation contract. | ||
* @param _minCashThreshold minimum amount of underlying tokens that are not invested. | ||
*/ | ||
function initializeInterest( | ||
address _token, | ||
address _impl, | ||
uint256 _minCashThreshold | ||
) external onlyOwner { | ||
require(address(interestImplementation(_token)) == address(0)); | ||
_setInterestImplementation(_token, _impl); | ||
_setMinCashThreshold(_token, _minCashThreshold); | ||
} | ||
|
||
/** | ||
* @dev Sets minimum amount of tokens that cannot be invested. | ||
* Only owner can call this method. | ||
* @param _token address of the token contract. | ||
* @param _minCashThreshold minimum amount of underlying tokens that are not invested. | ||
*/ | ||
function setMinCashThreshold(address _token, uint256 _minCashThreshold) external onlyOwner { | ||
_setMinCashThreshold(_token, _minCashThreshold); | ||
} | ||
|
||
/** | ||
* @dev Tells minimum amount of tokens that are not being invested. | ||
* @param _token address of the invested token contract. | ||
* @return amount of tokens. | ||
*/ | ||
function minCashThreshold(address _token) public view returns (uint256) { | ||
return uintStorage[keccak256(abi.encodePacked("minCashThreshold", _token))]; | ||
} | ||
|
||
/** | ||
* @dev Disables interest for locked funds. | ||
* Only owner can call this method. | ||
* Prior to calling this function, consider to call payInterest and claimCompAndPay. | ||
* @param _token of token to disable interest for. | ||
*/ | ||
function disableInterest(address _token) external onlyOwner { | ||
interestImplementation(_token).withdraw(_token, uint256(-1)); | ||
_setInterestImplementation(_token, address(0)); | ||
} | ||
|
||
/** | ||
* @dev Invests all excess tokens. Leaves only minCashThreshold in underlying tokens. | ||
* Requires interest for the given token to be enabled first. | ||
* @param _token address of the token contract considered. | ||
*/ | ||
function invest(address _token) external { | ||
IInterestImplementation impl = interestImplementation(_token); | ||
// less than _token.balanceOf(this), since it does not take into account mistakenly locked tokens that should be processed via fixMediatorBalance. | ||
uint256 balance = mediatorBalance(_token).sub(impl.investedAmount(_token)); | ||
uint256 minCash = minCashThreshold(_token); | ||
|
||
require(balance > minCash); | ||
uint256 amount = balance - minCash; | ||
|
||
IERC20(_token).transfer(address(impl), amount); | ||
impl.invest(_token, amount); | ||
} | ||
|
||
/** | ||
* @dev Internal function for setting interest earning implementation contract for some token. | ||
* Also acts as an interest enabled flag. | ||
* @param _token address of the token contract. | ||
* @param _impl address of the implementation contract. | ||
*/ | ||
function _setInterestImplementation(address _token, address _impl) internal { | ||
require(_impl == address(0) || IInterestImplementation(_impl).isInterestSupported(_token)); | ||
addressStorage[keccak256(abi.encodePacked("interestImpl", _token))] = _impl; | ||
} | ||
|
||
/** | ||
* @dev Internal function for setting minimum amount of tokens that cannot be invested. | ||
* @param _token address of the token contract. | ||
* @param _minCashThreshold minimum amount of underlying tokens that are not invested. | ||
*/ | ||
function _setMinCashThreshold(address _token, uint256 _minCashThreshold) internal { | ||
uintStorage[keccak256(abi.encodePacked("minCashThreshold", _token))] = _minCashThreshold; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.